aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/ipv6.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/ipv6.h')
-rw-r--r--include/net/ipv6.h29
1 files changed, 28 insertions, 1 deletions
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index ed672080c690..ace1113bef85 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -507,7 +507,7 @@ static inline void ipv6_addr_set_v4mapped(const __be32 addr,
507 * find the first different bit between two addresses 507 * find the first different bit between two addresses
508 * length of address must be a multiple of 32bits 508 * length of address must be a multiple of 32bits
509 */ 509 */
510static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen) 510static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
511{ 511{
512 const __be32 *a1 = token1, *a2 = token2; 512 const __be32 *a1 = token1, *a2 = token2;
513 int i; 513 int i;
@@ -539,6 +539,33 @@ static inline int __ipv6_addr_diff(const void *token1, const void *token2, int a
539 return addrlen << 5; 539 return addrlen << 5;
540} 540}
541 541
542#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
543static inline int __ipv6_addr_diff64(const void *token1, const void *token2, int addrlen)
544{
545 const __be64 *a1 = token1, *a2 = token2;
546 int i;
547
548 addrlen >>= 3;
549
550 for (i = 0; i < addrlen; i++) {
551 __be64 xb = a1[i] ^ a2[i];
552 if (xb)
553 return i * 64 + 63 - __fls(be64_to_cpu(xb));
554 }
555
556 return addrlen << 6;
557}
558#endif
559
560static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen)
561{
562#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
563 if (__builtin_constant_p(addrlen) && !(addrlen & 7))
564 return __ipv6_addr_diff64(token1, token2, addrlen);
565#endif
566 return __ipv6_addr_diff32(token1, token2, addrlen);
567}
568
542static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2) 569static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2)
543{ 570{
544 return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr)); 571 return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr));