diff options
author | Eric Dumazet <edumazet@google.com> | 2012-07-18 04:11:12 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-07-18 14:28:46 -0400 |
commit | ddbe503203855939946430e39bae58de11b70b69 (patch) | |
tree | 1605a8d3b14a92819eb8ed47ae5a84c1b66e12f8 /net/ipv6/addrconf.c | |
parent | dc9059512c09d09b99de6cd3a8bc842507934cbb (diff) |
ipv6: add ipv6_addr_hash() helper
Introduce ipv6_addr_hash() helper doing a XOR on all bits
of an IPv6 address, with an optimized x86_64 version.
Use it in flow dissector, as suggested by Andrew McGregor,
to reduce hash collision probabilities in fq_codel (and other
users of flow dissector)
Use it in ip6_tunnel.c and use more bit shuffling, as suggested
by David Laight, as existing hash was ignoring most of them.
Use it in sunrpc and use more bit shuffling, using hash_32().
Use it in net/ipv6/addrconf.c, using hash_32() as well.
As a cleanup, use it in net/ipv4/tcp_metrics.c
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Andrew McGregor <andrewmcgr@gmail.com>
Cc: Dave Taht <dave.taht@gmail.com>
Cc: Tom Herbert <therbert@google.com>
Cc: David Laight <David.Laight@ACULAB.COM>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/addrconf.c')
-rw-r--r-- | net/ipv6/addrconf.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 8f6411c97189..79181819a24f 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c | |||
@@ -63,6 +63,7 @@ | |||
63 | #include <linux/delay.h> | 63 | #include <linux/delay.h> |
64 | #include <linux/notifier.h> | 64 | #include <linux/notifier.h> |
65 | #include <linux/string.h> | 65 | #include <linux/string.h> |
66 | #include <linux/hash.h> | ||
66 | 67 | ||
67 | #include <net/net_namespace.h> | 68 | #include <net/net_namespace.h> |
68 | #include <net/sock.h> | 69 | #include <net/sock.h> |
@@ -579,15 +580,9 @@ ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) | |||
579 | list_add_tail(&ifp->if_list, p); | 580 | list_add_tail(&ifp->if_list, p); |
580 | } | 581 | } |
581 | 582 | ||
582 | static u32 ipv6_addr_hash(const struct in6_addr *addr) | 583 | static u32 inet6_addr_hash(const struct in6_addr *addr) |
583 | { | 584 | { |
584 | /* | 585 | return hash_32(ipv6_addr_hash(addr), IN6_ADDR_HSIZE_SHIFT); |
585 | * We perform the hash function over the last 64 bits of the address | ||
586 | * This will include the IEEE address token on links that support it. | ||
587 | */ | ||
588 | return jhash_2words((__force u32)addr->s6_addr32[2], | ||
589 | (__force u32)addr->s6_addr32[3], 0) | ||
590 | & (IN6_ADDR_HSIZE - 1); | ||
591 | } | 586 | } |
592 | 587 | ||
593 | /* On success it returns ifp with increased reference count */ | 588 | /* On success it returns ifp with increased reference count */ |
@@ -662,7 +657,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
662 | in6_ifa_hold(ifa); | 657 | in6_ifa_hold(ifa); |
663 | 658 | ||
664 | /* Add to big hash table */ | 659 | /* Add to big hash table */ |
665 | hash = ipv6_addr_hash(addr); | 660 | hash = inet6_addr_hash(addr); |
666 | 661 | ||
667 | hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]); | 662 | hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]); |
668 | spin_unlock(&addrconf_hash_lock); | 663 | spin_unlock(&addrconf_hash_lock); |
@@ -1270,7 +1265,7 @@ int ipv6_chk_addr(struct net *net, const struct in6_addr *addr, | |||
1270 | { | 1265 | { |
1271 | struct inet6_ifaddr *ifp; | 1266 | struct inet6_ifaddr *ifp; |
1272 | struct hlist_node *node; | 1267 | struct hlist_node *node; |
1273 | unsigned int hash = ipv6_addr_hash(addr); | 1268 | unsigned int hash = inet6_addr_hash(addr); |
1274 | 1269 | ||
1275 | rcu_read_lock_bh(); | 1270 | rcu_read_lock_bh(); |
1276 | hlist_for_each_entry_rcu(ifp, node, &inet6_addr_lst[hash], addr_lst) { | 1271 | hlist_for_each_entry_rcu(ifp, node, &inet6_addr_lst[hash], addr_lst) { |
@@ -1293,7 +1288,7 @@ EXPORT_SYMBOL(ipv6_chk_addr); | |||
1293 | static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, | 1288 | static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, |
1294 | struct net_device *dev) | 1289 | struct net_device *dev) |
1295 | { | 1290 | { |
1296 | unsigned int hash = ipv6_addr_hash(addr); | 1291 | unsigned int hash = inet6_addr_hash(addr); |
1297 | struct inet6_ifaddr *ifp; | 1292 | struct inet6_ifaddr *ifp; |
1298 | struct hlist_node *node; | 1293 | struct hlist_node *node; |
1299 | 1294 | ||
@@ -1336,7 +1331,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *add | |||
1336 | struct net_device *dev, int strict) | 1331 | struct net_device *dev, int strict) |
1337 | { | 1332 | { |
1338 | struct inet6_ifaddr *ifp, *result = NULL; | 1333 | struct inet6_ifaddr *ifp, *result = NULL; |
1339 | unsigned int hash = ipv6_addr_hash(addr); | 1334 | unsigned int hash = inet6_addr_hash(addr); |
1340 | struct hlist_node *node; | 1335 | struct hlist_node *node; |
1341 | 1336 | ||
1342 | rcu_read_lock_bh(); | 1337 | rcu_read_lock_bh(); |
@@ -3223,7 +3218,7 @@ int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr) | |||
3223 | int ret = 0; | 3218 | int ret = 0; |
3224 | struct inet6_ifaddr *ifp = NULL; | 3219 | struct inet6_ifaddr *ifp = NULL; |
3225 | struct hlist_node *n; | 3220 | struct hlist_node *n; |
3226 | unsigned int hash = ipv6_addr_hash(addr); | 3221 | unsigned int hash = inet6_addr_hash(addr); |
3227 | 3222 | ||
3228 | rcu_read_lock_bh(); | 3223 | rcu_read_lock_bh(); |
3229 | hlist_for_each_entry_rcu_bh(ifp, n, &inet6_addr_lst[hash], addr_lst) { | 3224 | hlist_for_each_entry_rcu_bh(ifp, n, &inet6_addr_lst[hash], addr_lst) { |