diff options
author | Eric Dumazet <edumazet@google.com> | 2013-02-21 07:18:52 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-02-21 18:15:58 -0500 |
commit | 08dcdbf6a7b9d14c2302c5bd0c5390ddf122f664 (patch) | |
tree | fc1d00005fda323296b93064416d255b81fdab73 /net | |
parent | 0ab8a9f5fa94ac625c1f19acc48db299416c6d49 (diff) |
ipv6: use a stronger hash for tcp
It looks like its possible to open thousands of TCP IPv6
sessions on a server, all landing in a single slot of TCP hash
table. Incoming packets have to lookup sockets in a very
long list.
We should hash all bits from foreign IPv6 addresses, using
a salt and hash mix, not a simple XOR.
inet6_ehashfn() can also separately use the ports, instead
of xoring them.
Reported-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/af_inet.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index e225a4e5b572..9cbcb94a4c6d 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c | |||
@@ -248,8 +248,12 @@ EXPORT_SYMBOL(inet_listen); | |||
248 | u32 inet_ehash_secret __read_mostly; | 248 | u32 inet_ehash_secret __read_mostly; |
249 | EXPORT_SYMBOL(inet_ehash_secret); | 249 | EXPORT_SYMBOL(inet_ehash_secret); |
250 | 250 | ||
251 | u32 ipv6_hash_secret __read_mostly; | ||
252 | EXPORT_SYMBOL(ipv6_hash_secret); | ||
253 | |||
251 | /* | 254 | /* |
252 | * inet_ehash_secret must be set exactly once | 255 | * inet_ehash_secret must be set exactly once, and to a non nul value |
256 | * ipv6_hash_secret must be set exactly once. | ||
253 | */ | 257 | */ |
254 | void build_ehash_secret(void) | 258 | void build_ehash_secret(void) |
255 | { | 259 | { |
@@ -259,7 +263,8 @@ void build_ehash_secret(void) | |||
259 | get_random_bytes(&rnd, sizeof(rnd)); | 263 | get_random_bytes(&rnd, sizeof(rnd)); |
260 | } while (rnd == 0); | 264 | } while (rnd == 0); |
261 | 265 | ||
262 | cmpxchg(&inet_ehash_secret, 0, rnd); | 266 | if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0) |
267 | get_random_bytes(&ipv6_hash_secret, sizeof(ipv6_hash_secret)); | ||
263 | } | 268 | } |
264 | EXPORT_SYMBOL(build_ehash_secret); | 269 | EXPORT_SYMBOL(build_ehash_secret); |
265 | 270 | ||