From patchwork Sun Nov 29 11:34:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 549730 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 F3BAE140180 for ; Sun, 29 Nov 2015 22:36:17 +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=cqul0i4+; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752570AbbK2LgP (ORCPT ); Sun, 29 Nov 2015 06:36:15 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35539 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752059AbbK2Lfa (ORCPT ); Sun, 29 Nov 2015 06:35:30 -0500 Received: by wmuu63 with SMTP id u63so97908249wmu.0; Sun, 29 Nov 2015 03:35:28 -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=B7pX8B18xZBn9AQshLhjD80+4peGmTQXEaG0acn6lcY=; b=cqul0i4+dbnI3bNX/jGt2hmgi0F/p6EgMcSJN/QcYOeA53LEd/cjHn3bOTuACo/7x5 PhmgfgbvzRgMdD6WqhB70ZxSc6LMXKswy0amcHAbajIBOks6MAcZfExGTTXOrR4ktKLy zSQVs/Lo9zAVvuojQshoAwdX0C6ffSxEhWHSj+nCZTq9qATMRPlL2Z7Sm/9WWst99PWJ 95Ev2QZRfsWzNZ4aa/1mkna3cOsTVoSubCZmyy3kB7ABCLgMJTKnSMPyLq19nTdcg0Cy 3sp3S7QTDRv+SgSzeLtpKuSiHngkv/waYqTep1PxlpwON500ENR709cbTQ3dDxL6vjLw HLKA== X-Received: by 10.28.48.213 with SMTP id w204mr20234442wmw.38.1448796928704; Sun, 29 Nov 2015 03:35:28 -0800 (PST) Received: from omega.localdomain (p20030064A9775FBDE2CB4EFFFE1BB546.dip0.t-ipconnect.de. [2003:64:a977:5fbd:e2cb:4eff:fe1b:b546]) by smtp.gmail.com with ESMTPSA id e83sm16347081wmc.23.2015.11.29.03.35.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 29 Nov 2015 03:35:27 -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: [RFCv3 bluetooth-next 3/4] ipv6: add ipv6_addr_prefix_copy Date: Sun, 29 Nov 2015 12:34:41 +0100 Message-Id: <1448796882-316-4-git-send-email-alex.aring@gmail.com> X-Mailer: git-send-email 2.6.1 In-Reply-To: <1448796882-316-1-git-send-email-alex.aring@gmail.com> References: <1448796882-316-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_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 Signed-off-by: Alexander Aring Acked-by: Hannes Frederic Sowa Acked-by: YOSHIFUJI Hideaki Reviewed-by: Stefan Schmidt Acked-by: Ɓukasz Duda --- include/net/ipv6.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/net/ipv6.h b/include/net/ipv6.h index e1a10b0..cd3881e6 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_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) {