]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - include/net/ipv6.h
ipv6: add ipv6_addr_prefix_copy
[karo-tx-linux.git] / include / net / ipv6.h
index 9a5c9f01378455c4c8b9eb860b170504c878f1a5..6570f379aba2eb744b0e8522349f0612b01b6814 100644 (file)
@@ -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)
 {