From patchwork Wed Dec 9 21:46:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 554813 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 1AE581402D6 for ; Thu, 10 Dec 2015 08:47:43 +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=dPaTXVdp; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753605AbbLIVrk (ORCPT ); Wed, 9 Dec 2015 16:47:40 -0500 Received: from mail-wm0-f48.google.com ([74.125.82.48]:37122 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753342AbbLIVrh (ORCPT ); Wed, 9 Dec 2015 16:47:37 -0500 Received: by wmww144 with SMTP id w144so92121818wmw.0; Wed, 09 Dec 2015 13:47:35 -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 :mime-version:content-type:content-transfer-encoding; bh=D/hGbZ7oPaZ44HuhcsQS2xHKUD8hb06nuIKKCyM+d6c=; b=dPaTXVdpqhODPV+p1VXBez7Rnxmh8R3wBDbGVkMs7YTdyIhIOQ0/u0b/uaBAdqwP/M fEzP4NLYcAfby6dD7P90f40bq5OwW6Zpf63+KWJ+R8uabEA+h4Sbjdv4sQJml5oa+PYj DMHkq84ugEhYjPnVHiQPofBkr31u+omt1l8n9Cp+IQuiHojXAOm9is+eSD9hm4MAW2YG Ks9FmPUO3QnzuEnFlQfyQ5xYkkyTxAuKIqTleO075MV01Hutx9jq4hl0MWn+/DH8Joyn PqJ558Wly6EyxncZmMKXfhZ+Lqv08w+E9DIb9ibbJPhkJYEpQx0IMf/7IC+czAj1DFzQ tdqQ== X-Received: by 10.28.68.213 with SMTP id r204mr35669121wma.35.1449697655646; Wed, 09 Dec 2015 13:47:35 -0800 (PST) Received: from omega.localdomain (p20030064A928605CE2CB4EFFFE1BB546.dip0.t-ipconnect.de. [2003:64:a928:605c:e2cb:4eff:fe1b:b546]) by smtp.gmail.com with ESMTPSA id 143sm28074625wmv.18.2015.12.09.13.47.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Dec 2015 13:47:34 -0800 (PST) From: Alexander Aring To: linux-wpan@vger.kernel.org Cc: linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, kernel@pengutronix.de, Alexander Aring , "David S . Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy Subject: [PATCH bluetooth-next 10/10] ipv6: add ipv6_addr_prefix_copy Date: Wed, 9 Dec 2015 22:46:31 +0100 Message-Id: <1449697591-15991-11-git-send-email-alex.aring@gmail.com> X-Mailer: git-send-email 2.6.1 In-Reply-To: <1449697591-15991-1-git-send-email-alex.aring@gmail.com> References: <1449697591-15991-1-git-send-email-alex.aring@gmail.com> MIME-Version: 1.0 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_copy 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_copy 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 Acked-by: Ɓukasz Duda Acked-by: Hannes Frederic Sowa Acked-by: YOSHIFUJI Hideaki Reviewed-by: Stefan Schmidt Signed-off-by: Alexander Aring Acked-by: David S. Miller --- include/net/ipv6.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/net/ipv6.h b/include/net/ipv6.h index 9a5c9f0..6570f37 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -401,6 +401,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_copy(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) {