aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/addrconf.h3
-rw-r--r--include/net/ipv6.h13
-rw-r--r--net/core/flow_dissector.c5
-rw-r--r--net/ipv4/tcp_metrics.c15
-rw-r--r--net/ipv6/addrconf.c21
-rw-r--r--net/ipv6/ip6_tunnel.c20
-rw-r--r--net/sunrpc/svcauth_unix.c22
7 files changed, 45 insertions, 54 deletions
diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index f2b801c4b555..089a09d001d1 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -46,7 +46,8 @@ struct prefix_info {
46#include <net/if_inet6.h> 46#include <net/if_inet6.h>
47#include <net/ipv6.h> 47#include <net/ipv6.h>
48 48
49#define IN6_ADDR_HSIZE 16 49#define IN6_ADDR_HSIZE_SHIFT 4
50#define IN6_ADDR_HSIZE (1 << IN6_ADDR_HSIZE_SHIFT)
50 51
51extern int addrconf_init(void); 52extern int addrconf_init(void);
52extern void addrconf_cleanup(void); 53extern void addrconf_cleanup(void);
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index f695f39e8926..01c34b363a34 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -419,6 +419,19 @@ static inline bool ipv6_addr_any(const struct in6_addr *a)
419#endif 419#endif
420} 420}
421 421
422static inline u32 ipv6_addr_hash(const struct in6_addr *a)
423{
424#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
425 const unsigned long *ul = (const unsigned long *)a;
426 unsigned long x = ul[0] ^ ul[1];
427
428 return (u32)(x ^ (x >> 32));
429#else
430 return (__force u32)(a->s6_addr32[0] ^ a->s6_addr32[1] ^
431 a->s6_addr32[2] ^ a->s6_addr32[3]);
432#endif
433}
434
422static inline bool ipv6_addr_loopback(const struct in6_addr *a) 435static inline bool ipv6_addr_loopback(const struct in6_addr *a)
423{ 436{
424 return (a->s6_addr32[0] | a->s6_addr32[1] | 437 return (a->s6_addr32[0] | a->s6_addr32[1] |
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index a225089df5b6..466820b6e344 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -4,6 +4,7 @@
4#include <linux/ipv6.h> 4#include <linux/ipv6.h>
5#include <linux/if_vlan.h> 5#include <linux/if_vlan.h>
6#include <net/ip.h> 6#include <net/ip.h>
7#include <net/ipv6.h>
7#include <linux/if_tunnel.h> 8#include <linux/if_tunnel.h>
8#include <linux/if_pppox.h> 9#include <linux/if_pppox.h>
9#include <linux/ppp_defs.h> 10#include <linux/ppp_defs.h>
@@ -55,8 +56,8 @@ ipv6:
55 return false; 56 return false;
56 57
57 ip_proto = iph->nexthdr; 58 ip_proto = iph->nexthdr;
58 flow->src = iph->saddr.s6_addr32[3]; 59 flow->src = (__force __be32)ipv6_addr_hash(&iph->saddr);
59 flow->dst = iph->daddr.s6_addr32[3]; 60 flow->dst = (__force __be32)ipv6_addr_hash(&iph->daddr);
60 nhoff += sizeof(struct ipv6hdr); 61 nhoff += sizeof(struct ipv6hdr);
61 break; 62 break;
62 } 63 }
diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
index 5a38a2d5a95b..1a115b665792 100644
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -211,10 +211,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,
211 break; 211 break;
212 case AF_INET6: 212 case AF_INET6:
213 *(struct in6_addr *)addr.addr.a6 = inet6_rsk(req)->rmt_addr; 213 *(struct in6_addr *)addr.addr.a6 = inet6_rsk(req)->rmt_addr;
214 hash = ((__force unsigned int) addr.addr.a6[0] ^ 214 hash = ipv6_addr_hash(&inet6_rsk(req)->rmt_addr);
215 (__force unsigned int) addr.addr.a6[1] ^
216 (__force unsigned int) addr.addr.a6[2] ^
217 (__force unsigned int) addr.addr.a6[3]);
218 break; 215 break;
219 default: 216 default:
220 return NULL; 217 return NULL;
@@ -251,10 +248,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock
251 case AF_INET6: 248 case AF_INET6:
252 tw6 = inet6_twsk((struct sock *)tw); 249 tw6 = inet6_twsk((struct sock *)tw);
253 *(struct in6_addr *)addr.addr.a6 = tw6->tw_v6_daddr; 250 *(struct in6_addr *)addr.addr.a6 = tw6->tw_v6_daddr;
254 hash = ((__force unsigned int) addr.addr.a6[0] ^ 251 hash = ipv6_addr_hash(&tw6->tw_v6_daddr);
255 (__force unsigned int) addr.addr.a6[1] ^
256 (__force unsigned int) addr.addr.a6[2] ^
257 (__force unsigned int) addr.addr.a6[3]);
258 break; 252 break;
259 default: 253 default:
260 return NULL; 254 return NULL;
@@ -291,10 +285,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
291 break; 285 break;
292 case AF_INET6: 286 case AF_INET6:
293 *(struct in6_addr *)addr.addr.a6 = inet6_sk(sk)->daddr; 287 *(struct in6_addr *)addr.addr.a6 = inet6_sk(sk)->daddr;
294 hash = ((__force unsigned int) addr.addr.a6[0] ^ 288 hash = ipv6_addr_hash(&inet6_sk(sk)->daddr);
295 (__force unsigned int) addr.addr.a6[1] ^
296 (__force unsigned int) addr.addr.a6[2] ^
297 (__force unsigned int) addr.addr.a6[3]);
298 break; 289 break;
299 default: 290 default:
300 return NULL; 291 return NULL;
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
582static u32 ipv6_addr_hash(const struct in6_addr *addr) 583static 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);
1293static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, 1288static 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) {
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index db3284667968..9a1d5fe6aef8 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -40,6 +40,7 @@
40#include <linux/rtnetlink.h> 40#include <linux/rtnetlink.h>
41#include <linux/netfilter_ipv6.h> 41#include <linux/netfilter_ipv6.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/hash.h>
43 44
44#include <asm/uaccess.h> 45#include <asm/uaccess.h>
45#include <linux/atomic.h> 46#include <linux/atomic.h>
@@ -70,11 +71,15 @@ MODULE_ALIAS_NETDEV("ip6tnl0");
70#define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK) 71#define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK)
71#define IPV6_TCLASS_SHIFT 20 72#define IPV6_TCLASS_SHIFT 20
72 73
73#define HASH_SIZE 32 74#define HASH_SIZE_SHIFT 5
75#define HASH_SIZE (1 << HASH_SIZE_SHIFT)
74 76
75#define HASH(addr) ((__force u32)((addr)->s6_addr32[0] ^ (addr)->s6_addr32[1] ^ \ 77static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
76 (addr)->s6_addr32[2] ^ (addr)->s6_addr32[3]) & \ 78{
77 (HASH_SIZE - 1)) 79 u32 hash = ipv6_addr_hash(addr1) ^ ipv6_addr_hash(addr2);
80
81 return hash_32(hash, HASH_SIZE_SHIFT);
82}
78 83
79static int ip6_tnl_dev_init(struct net_device *dev); 84static int ip6_tnl_dev_init(struct net_device *dev);
80static void ip6_tnl_dev_setup(struct net_device *dev); 85static void ip6_tnl_dev_setup(struct net_device *dev);
@@ -166,12 +171,11 @@ static inline void ip6_tnl_dst_store(struct ip6_tnl *t, struct dst_entry *dst)
166static struct ip6_tnl * 171static struct ip6_tnl *
167ip6_tnl_lookup(struct net *net, const struct in6_addr *remote, const struct in6_addr *local) 172ip6_tnl_lookup(struct net *net, const struct in6_addr *remote, const struct in6_addr *local)
168{ 173{
169 unsigned int h0 = HASH(remote); 174 unsigned int hash = HASH(remote, local);
170 unsigned int h1 = HASH(local);
171 struct ip6_tnl *t; 175 struct ip6_tnl *t;
172 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id); 176 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
173 177
174 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[h0 ^ h1]) { 178 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
175 if (ipv6_addr_equal(local, &t->parms.laddr) && 179 if (ipv6_addr_equal(local, &t->parms.laddr) &&
176 ipv6_addr_equal(remote, &t->parms.raddr) && 180 ipv6_addr_equal(remote, &t->parms.raddr) &&
177 (t->dev->flags & IFF_UP)) 181 (t->dev->flags & IFF_UP))
@@ -205,7 +209,7 @@ ip6_tnl_bucket(struct ip6_tnl_net *ip6n, const struct ip6_tnl_parm *p)
205 209
206 if (!ipv6_addr_any(remote) || !ipv6_addr_any(local)) { 210 if (!ipv6_addr_any(remote) || !ipv6_addr_any(local)) {
207 prio = 1; 211 prio = 1;
208 h = HASH(remote) ^ HASH(local); 212 h = HASH(remote, local);
209 } 213 }
210 return &ip6n->tnls[prio][h]; 214 return &ip6n->tnls[prio][h];
211} 215}
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 2777fa896645..4d0129203733 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -104,23 +104,9 @@ static void ip_map_put(struct kref *kref)
104 kfree(im); 104 kfree(im);
105} 105}
106 106
107#if IP_HASHBITS == 8 107static inline int hash_ip6(const struct in6_addr *ip)
108/* hash_long on a 64 bit machine is currently REALLY BAD for
109 * IP addresses in reverse-endian (i.e. on a little-endian machine).
110 * So use a trivial but reliable hash instead
111 */
112static inline int hash_ip(__be32 ip)
113{
114 int hash = (__force u32)ip ^ ((__force u32)ip>>16);
115 return (hash ^ (hash>>8)) & 0xff;
116}
117#endif
118static inline int hash_ip6(struct in6_addr ip)
119{ 108{
120 return (hash_ip(ip.s6_addr32[0]) ^ 109 return hash_32(ipv6_addr_hash(ip), IP_HASHBITS);
121 hash_ip(ip.s6_addr32[1]) ^
122 hash_ip(ip.s6_addr32[2]) ^
123 hash_ip(ip.s6_addr32[3]));
124} 110}
125static int ip_map_match(struct cache_head *corig, struct cache_head *cnew) 111static int ip_map_match(struct cache_head *corig, struct cache_head *cnew)
126{ 112{
@@ -301,7 +287,7 @@ static struct ip_map *__ip_map_lookup(struct cache_detail *cd, char *class,
301 ip.m_addr = *addr; 287 ip.m_addr = *addr;
302 ch = sunrpc_cache_lookup(cd, &ip.h, 288 ch = sunrpc_cache_lookup(cd, &ip.h,
303 hash_str(class, IP_HASHBITS) ^ 289 hash_str(class, IP_HASHBITS) ^
304 hash_ip6(*addr)); 290 hash_ip6(addr));
305 291
306 if (ch) 292 if (ch)
307 return container_of(ch, struct ip_map, h); 293 return container_of(ch, struct ip_map, h);
@@ -331,7 +317,7 @@ static int __ip_map_update(struct cache_detail *cd, struct ip_map *ipm,
331 ip.h.expiry_time = expiry; 317 ip.h.expiry_time = expiry;
332 ch = sunrpc_cache_update(cd, &ip.h, &ipm->h, 318 ch = sunrpc_cache_update(cd, &ip.h, &ipm->h,
333 hash_str(ipm->m_class, IP_HASHBITS) ^ 319 hash_str(ipm->m_class, IP_HASHBITS) ^
334 hash_ip6(ipm->m_addr)); 320 hash_ip6(&ipm->m_addr));
335 if (!ch) 321 if (!ch)
336 return -ENOMEM; 322 return -ENOMEM;
337 cache_put(ch, cd); 323 cache_put(ch, cd);