diff options
-rw-r--r-- | include/linux/udp.h | 3 | ||||
-rw-r--r-- | include/net/inet6_hashtables.h | 3 | ||||
-rw-r--r-- | include/net/inet_hashtables.h | 5 | ||||
-rw-r--r-- | include/net/inet_sock.h | 3 | ||||
-rw-r--r-- | include/net/netns/hash.h | 21 |
5 files changed, 30 insertions, 5 deletions
diff --git a/include/linux/udp.h b/include/linux/udp.h index 3deccac2e815..0cf5c4c0ec81 100644 --- a/include/linux/udp.h +++ b/include/linux/udp.h | |||
@@ -38,6 +38,7 @@ struct udphdr { | |||
38 | #ifdef __KERNEL__ | 38 | #ifdef __KERNEL__ |
39 | #include <net/inet_sock.h> | 39 | #include <net/inet_sock.h> |
40 | #include <linux/skbuff.h> | 40 | #include <linux/skbuff.h> |
41 | #include <net/netns/hash.h> | ||
41 | 42 | ||
42 | static inline struct udphdr *udp_hdr(const struct sk_buff *skb) | 43 | static inline struct udphdr *udp_hdr(const struct sk_buff *skb) |
43 | { | 44 | { |
@@ -48,7 +49,7 @@ static inline struct udphdr *udp_hdr(const struct sk_buff *skb) | |||
48 | 49 | ||
49 | static inline int udp_hashfn(struct net *net, const unsigned num) | 50 | static inline int udp_hashfn(struct net *net, const unsigned num) |
50 | { | 51 | { |
51 | return num & (UDP_HTABLE_SIZE - 1); | 52 | return (num + net_hash_mix(net)) & (UDP_HTABLE_SIZE - 1); |
52 | } | 53 | } |
53 | 54 | ||
54 | struct udp_sock { | 55 | struct udp_sock { |
diff --git a/include/net/inet6_hashtables.h b/include/net/inet6_hashtables.h index 72f13a9928e4..e48989f04c24 100644 --- a/include/net/inet6_hashtables.h +++ b/include/net/inet6_hashtables.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <net/inet_sock.h> | 24 | #include <net/inet_sock.h> |
25 | 25 | ||
26 | #include <net/ipv6.h> | 26 | #include <net/ipv6.h> |
27 | #include <net/netns/hash.h> | ||
27 | 28 | ||
28 | struct inet_hashinfo; | 29 | struct inet_hashinfo; |
29 | 30 | ||
@@ -36,7 +37,7 @@ static inline unsigned int inet6_ehashfn(struct net *net, | |||
36 | 37 | ||
37 | return jhash_3words((__force u32)laddr->s6_addr32[3], | 38 | return jhash_3words((__force u32)laddr->s6_addr32[3], |
38 | (__force u32)faddr->s6_addr32[3], | 39 | (__force u32)faddr->s6_addr32[3], |
39 | ports, inet_ehash_secret); | 40 | ports, inet_ehash_secret + net_hash_mix(net)); |
40 | } | 41 | } |
41 | 42 | ||
42 | static inline int inet6_sk_ehashfn(const struct sock *sk) | 43 | static inline int inet6_sk_ehashfn(const struct sock *sk) |
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index 26336cdcdc11..bb619d80f2e2 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <net/inet_sock.h> | 29 | #include <net/inet_sock.h> |
30 | #include <net/sock.h> | 30 | #include <net/sock.h> |
31 | #include <net/tcp_states.h> | 31 | #include <net/tcp_states.h> |
32 | #include <net/netns/hash.h> | ||
32 | 33 | ||
33 | #include <asm/atomic.h> | 34 | #include <asm/atomic.h> |
34 | #include <asm/byteorder.h> | 35 | #include <asm/byteorder.h> |
@@ -204,7 +205,7 @@ extern void inet_bind_bucket_destroy(struct kmem_cache *cachep, | |||
204 | static inline int inet_bhashfn(struct net *net, | 205 | static inline int inet_bhashfn(struct net *net, |
205 | const __u16 lport, const int bhash_size) | 206 | const __u16 lport, const int bhash_size) |
206 | { | 207 | { |
207 | return lport & (bhash_size - 1); | 208 | return (lport + net_hash_mix(net)) & (bhash_size - 1); |
208 | } | 209 | } |
209 | 210 | ||
210 | extern void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb, | 211 | extern void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb, |
@@ -213,7 +214,7 @@ extern void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb, | |||
213 | /* These can have wildcards, don't try too hard. */ | 214 | /* These can have wildcards, don't try too hard. */ |
214 | static inline int inet_lhashfn(struct net *net, const unsigned short num) | 215 | static inline int inet_lhashfn(struct net *net, const unsigned short num) |
215 | { | 216 | { |
216 | return num & (INET_LHTABLE_SIZE - 1); | 217 | return (num + net_hash_mix(net)) & (INET_LHTABLE_SIZE - 1); |
217 | } | 218 | } |
218 | 219 | ||
219 | static inline int inet_sk_listen_hashfn(const struct sock *sk) | 220 | static inline int inet_sk_listen_hashfn(const struct sock *sk) |
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index 85bb420c5d86..643e26be058e 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <net/sock.h> | 25 | #include <net/sock.h> |
26 | #include <net/request_sock.h> | 26 | #include <net/request_sock.h> |
27 | #include <net/route.h> | 27 | #include <net/route.h> |
28 | #include <net/netns/hash.h> | ||
28 | 29 | ||
29 | /** struct ip_options - IP Options | 30 | /** struct ip_options - IP Options |
30 | * | 31 | * |
@@ -178,7 +179,7 @@ static inline unsigned int inet_ehashfn(struct net *net, | |||
178 | return jhash_3words((__force __u32) laddr, | 179 | return jhash_3words((__force __u32) laddr, |
179 | (__force __u32) faddr, | 180 | (__force __u32) faddr, |
180 | ((__u32) lport) << 16 | (__force __u32)fport, | 181 | ((__u32) lport) << 16 | (__force __u32)fport, |
181 | inet_ehash_secret); | 182 | inet_ehash_secret + net_hash_mix(net)); |
182 | } | 183 | } |
183 | 184 | ||
184 | static inline int inet_sk_ehashfn(const struct sock *sk) | 185 | static inline int inet_sk_ehashfn(const struct sock *sk) |
diff --git a/include/net/netns/hash.h b/include/net/netns/hash.h new file mode 100644 index 000000000000..548d78f2cc47 --- /dev/null +++ b/include/net/netns/hash.h | |||
@@ -0,0 +1,21 @@ | |||
1 | #ifndef __NET_NS_HASH_H__ | ||
2 | #define __NET_NS_HASH_H__ | ||
3 | |||
4 | #include <asm/cache.h> | ||
5 | |||
6 | struct net; | ||
7 | |||
8 | static inline unsigned net_hash_mix(struct net *net) | ||
9 | { | ||
10 | #ifdef CONFIG_NET_NS | ||
11 | /* | ||
12 | * shift this right to eliminate bits, that are | ||
13 | * always zeroed | ||
14 | */ | ||
15 | |||
16 | return (unsigned)(((unsigned long)net) >> L1_CACHE_SHIFT); | ||
17 | #else | ||
18 | return 0; | ||
19 | #endif | ||
20 | } | ||
21 | #endif | ||