From patchwork Tue Nov 17 22:33:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 545796 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2C6A414141C for ; Wed, 18 Nov 2015 09:37:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=B8YlCQzm; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932465AbbKQWgz (ORCPT ); Tue, 17 Nov 2015 17:36:55 -0500 Received: from mail-wm0-f48.google.com ([74.125.82.48]:38221 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752735AbbKQWgl (ORCPT ); Tue, 17 Nov 2015 17:36:41 -0500 Received: by wmec201 with SMTP id c201so48033694wme.1; Tue, 17 Nov 2015 14:36:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PwERkUB3PhYVVnGuzX/rRU6FeWUDq/3oFQWjqOyMAXI=; b=B8YlCQzmcTdDenjCEaXmUJSnjoigYorY7ILIXljVOP+Ce6d5HuA+OCEX4eDET7Nfd0 2uYN3AYVOYiUe73YDqVJlxWKNfYhZlvNHbvatWv65Lls5XR3dS4OMPFpPpu4zlMIxoNK oOzHYcuc4qqwiDL2kIh26Ahv/+HZZ7yxiukA0LxPln4MuYM4U3R9zMOz8wP1FN7TM0PC 7NQC7oo2dlY6TjW6VnPDVSYwV80oXDqsJSLoykHtSvBEieL4VNvybl/Ce7p77oFOlLO8 AermmLcgwjydPmD/p6hXRU+g/RyqcLZSBxdQwi6P8tY6ho6J0jF9PELqlwSXZlYvfrtq yYag== X-Received: by 10.194.235.230 with SMTP id up6mr2195215wjc.178.1447799800282; Tue, 17 Nov 2015 14:36:40 -0800 (PST) Received: from omega.localdomain (p20030064A95FF6FDE2CB4EFFFE1BB546.dip0.t-ipconnect.de. [2003:64:a95f:f6fd:e2cb:4eff:fe1b:b546]) by smtp.gmail.com with ESMTPSA id it4sm42109746wjb.0.2015.11.17.14.36.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Nov 2015 14:36:39 -0800 (PST) From: Alexander Aring To: linux-wpan@vger.kernel.org Cc: linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, kernel@pengutronix.de, mcr@sandelman.ca, lukasz.duda@nordicsemi.no, martin.gergeleit@hs-rm.de, Alexander Aring , "David S . Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy Subject: [RFCv2 bluetooth-next 2/3] ipv6: add ipv6_addr_prefix_cpy Date: Tue, 17 Nov 2015 23:33:13 +0100 Message-Id: <1447799594-6050-3-git-send-email-alex.aring@gmail.com> X-Mailer: git-send-email 2.6.1 In-Reply-To: <1447799594-6050-1-git-send-email-alex.aring@gmail.com> References: <1447799594-6050-1-git-send-email-alex.aring@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds a static inline function ipv6_addr_prefix_cpy which copies a ipv6 address prefix(argument pfx) into the ipv6 address prefix. The prefix len is given by plen as bits. This function mainly based on ipv6_addr_prefix which copies one address prefix from address into a new ipv6 address destination and zero all other address bits. The difference is that ipv6_addr_prefix_cpy don't get a prefix from an ipv6 address, it sets a prefix to an ipv6 address with keeping other address bits. The use case is for context based address compression inside 6LoWPAN IPHC header which keeping ipv6 prefixes inside a context table to lookup address-bits without sending them. Cc: David S. Miller Cc: Alexey Kuznetsov Cc: James Morris Cc: Hideaki YOSHIFUJI Cc: Patrick McHardy Signed-off-by: Alexander Aring Reviewed-by: Stefan Schmidt --- include/net/ipv6.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/net/ipv6.h b/include/net/ipv6.h index e1a10b0..9d38fc2 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -382,6 +382,21 @@ static inline void ipv6_addr_prefix(struct in6_addr *pfx, pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b); } +static inline void ipv6_addr_prefix_cpy(struct in6_addr *addr, + const struct in6_addr *pfx, + int plen) +{ + /* caller must guarantee 0 <= plen <= 128 */ + int o = plen >> 3, + b = plen & 0x7; + + memcpy(addr->s6_addr, pfx, o); + if (b != 0) { + addr->s6_addr[o] &= ~(0xff00 >> b); + addr->s6_addr[o] |= (pfx->s6_addr[o] & (0xff00 >> b)); + } +} + static inline void __ipv6_addr_set_half(__be32 *addr, __be32 wh, __be32 wl) {