RE: [RFCv3 bluetooth-next 3/4] ipv6: add ipv6_addr_prefix_copy
> -Original Message- > From: Alexander Aring [mailto:alex.ar...@gmail.com] > Sent: Sunday, November 29, 2015 12:35 > To: linux-w...@vger.kernel.org > Cc: linux-blueto...@vger.kernel.org; netdev@vger.kernel.org; > ker...@pengutronix.de; m...@sandelman.ca; Duda, Lukasz; > martin.gergel...@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 > > 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 > --- > 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) > { > -- > 2.6.1 Acked-by: Łukasz Duda -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFCv3 bluetooth-next 3/4] ipv6: add ipv6_addr_prefix_copy
Hello. On 29/11/15 12:34, Alexander Aring wrote: 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 --- 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) { Thanks for taking up the review comments. You can add my r-b now: Reviewed-by: Stefan Schmidt regards Stefan Schmidt -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFCv3 bluetooth-next 3/4] ipv6: add ipv6_addr_prefix_copy
Hannes Frederic Sowa wrote: > > > On Sun, Nov 29, 2015, at 12:34, Alexander Aring wrote: >> 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 >> --- >> 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)); >> + } >> +} >> + > > Acked-by: Hannes Frederic Sowa Acked-by: YOSHIFUJI Hideaki > -- > To unsubscribe from this list: send the line "unsubscribe netdev" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- 吉藤英明 ミラクル・リナックス株式会社 技術本部 サポート部 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFCv3 bluetooth-next 3/4] ipv6: add ipv6_addr_prefix_copy
On Sun, Nov 29, 2015, at 12:34, Alexander Aring wrote: > 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 > --- > 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)); > + } > +} > + Acked-by: Hannes Frederic Sowa -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[RFCv3 bluetooth-next 3/4] ipv6: add ipv6_addr_prefix_copy
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 --- 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) { -- 2.6.1 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html