diff options
author | stephen hemminger <shemminger@vyatta.com> | 2010-03-17 16:31:12 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-03-20 18:44:35 -0400 |
commit | 3a88a81d89c20be312b3b219b185bbdde24b8fb8 (patch) | |
tree | 2610b2b8b47deb4e4d5db0968af21911306442b3 /net | |
parent | 5c578aedcb21d79eeb4e9cf04ca5b276ac82614c (diff) |
ipv6: user better hash for addrconf
The existing hash function has a couple of issues:
* it is hardwired to 16 for IN6_ADDR_HSIZE
* limited to 256 and callers using int
* use jhash2 rather than some old BSD algorithm
No need for random seed since this is local only (based on assigned
addresses) table.
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv6/addrconf.c | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 7ffd5eeab967..1e5e41fe92bc 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c | |||
@@ -573,23 +573,14 @@ ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) | |||
573 | *ifap = ifp; | 573 | *ifap = ifp; |
574 | } | 574 | } |
575 | 575 | ||
576 | /* | 576 | static u32 ipv6_addr_hash(const struct in6_addr *addr) |
577 | * Hash function taken from net_alias.c | ||
578 | */ | ||
579 | static u8 ipv6_addr_hash(const struct in6_addr *addr) | ||
580 | { | 577 | { |
581 | __u32 word; | ||
582 | |||
583 | /* | 578 | /* |
584 | * We perform the hash function over the last 64 bits of the address | 579 | * We perform the hash function over the last 64 bits of the address |
585 | * This will include the IEEE address token on links that support it. | 580 | * This will include the IEEE address token on links that support it. |
586 | */ | 581 | */ |
587 | 582 | return jhash_2words(addr->s6_addr32[2], addr->s6_addr32[3], 0) | |
588 | word = (__force u32)(addr->s6_addr32[2] ^ addr->s6_addr32[3]); | 583 | & (IN6_ADDR_HSIZE - 1); |
589 | word ^= (word >> 16); | ||
590 | word ^= (word >> 8); | ||
591 | |||
592 | return ((word ^ (word >> 4)) & 0x0f); | ||
593 | } | 584 | } |
594 | 585 | ||
595 | /* On success it returns ifp with increased reference count */ | 586 | /* On success it returns ifp with increased reference count */ |
@@ -600,7 +591,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
600 | { | 591 | { |
601 | struct inet6_ifaddr *ifa = NULL; | 592 | struct inet6_ifaddr *ifa = NULL; |
602 | struct rt6_info *rt; | 593 | struct rt6_info *rt; |
603 | int hash; | 594 | unsigned int hash; |
604 | int err = 0; | 595 | int err = 0; |
605 | int addr_type = ipv6_addr_type(addr); | 596 | int addr_type = ipv6_addr_type(addr); |
606 | 597 | ||
@@ -1277,7 +1268,7 @@ int ipv6_chk_addr(struct net *net, struct in6_addr *addr, | |||
1277 | { | 1268 | { |
1278 | struct inet6_ifaddr *ifp = NULL; | 1269 | struct inet6_ifaddr *ifp = NULL; |
1279 | struct hlist_node *node; | 1270 | struct hlist_node *node; |
1280 | u8 hash = ipv6_addr_hash(addr); | 1271 | unsigned int hash = ipv6_addr_hash(addr); |
1281 | 1272 | ||
1282 | rcu_read_lock_bh(); | 1273 | rcu_read_lock_bh(); |
1283 | hlist_for_each_entry_rcu(ifp, node, &inet6_addr_lst[hash], addr_lst) { | 1274 | hlist_for_each_entry_rcu(ifp, node, &inet6_addr_lst[hash], addr_lst) { |
@@ -1302,7 +1293,7 @@ int ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, | |||
1302 | { | 1293 | { |
1303 | struct inet6_ifaddr *ifp; | 1294 | struct inet6_ifaddr *ifp; |
1304 | struct hlist_node *node; | 1295 | struct hlist_node *node; |
1305 | u8 hash = ipv6_addr_hash(addr); | 1296 | unsigned int hash = ipv6_addr_hash(addr); |
1306 | 1297 | ||
1307 | hlist_for_each_entry(ifp, node, &inet6_addr_lst[hash], addr_lst) { | 1298 | hlist_for_each_entry(ifp, node, &inet6_addr_lst[hash], addr_lst) { |
1308 | if (!net_eq(dev_net(ifp->idev->dev), net)) | 1299 | if (!net_eq(dev_net(ifp->idev->dev), net)) |
@@ -1345,7 +1336,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *add | |||
1345 | { | 1336 | { |
1346 | struct inet6_ifaddr *ifp = NULL; | 1337 | struct inet6_ifaddr *ifp = NULL; |
1347 | struct hlist_node *node; | 1338 | struct hlist_node *node; |
1348 | u8 hash = ipv6_addr_hash(addr); | 1339 | unsigned int hash = ipv6_addr_hash(addr); |
1349 | 1340 | ||
1350 | rcu_read_lock_bh(); | 1341 | rcu_read_lock_bh(); |
1351 | hlist_for_each_entry_rcu(ifp, node, &inet6_addr_lst[hash], addr_lst) { | 1342 | hlist_for_each_entry_rcu(ifp, node, &inet6_addr_lst[hash], addr_lst) { |
@@ -3083,7 +3074,7 @@ int ipv6_chk_home_addr(struct net *net, struct in6_addr *addr) | |||
3083 | int ret = 0; | 3074 | int ret = 0; |
3084 | struct inet6_ifaddr *ifp = NULL; | 3075 | struct inet6_ifaddr *ifp = NULL; |
3085 | struct hlist_node *n; | 3076 | struct hlist_node *n; |
3086 | u8 hash = ipv6_addr_hash(addr); | 3077 | unsigned int hash = ipv6_addr_hash(addr); |
3087 | 3078 | ||
3088 | rcu_read_lock_bh(); | 3079 | rcu_read_lock_bh(); |
3089 | hlist_for_each_entry_rcu(ifp, n, &inet6_addr_lst[hash], addr_lst) { | 3080 | hlist_for_each_entry_rcu(ifp, n, &inet6_addr_lst[hash], addr_lst) { |