aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHannes Frederic Sowa <hannes@stressinduktion.org>2013-10-19 15:48:51 -0400
committerDavid S. Miller <davem@davemloft.net>2013-10-19 19:45:34 -0400
commit65cd8033ff375b68037df61603ee68070dc48578 (patch)
tree26b34f9ed023dda5a861001118a1ea1227ae252f
parent53481da372851a5506deb5247302f75459b472b4 (diff)
ipv4: split inet_ehashfn to hash functions per compilation unit
This duplicates a bit of code but let's us easily introduce separate secret keys later. The separate compilation units are ipv4/inet_hashtabbles.o, ipv4/udp.o and rds/connection.o. Cc: Eric Dumazet <edumazet@google.com> Cc: "David S. Miller" <davem@davemloft.net> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/inet_sock.h22
-rw-r--r--net/ipv4/inet_hashtables.c21
-rw-r--r--net/ipv4/udp.c16
-rw-r--r--net/rds/connection.c6
4 files changed, 42 insertions, 23 deletions
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index 06da91efbc83..7a6c7f80a8fd 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -208,26 +208,16 @@ extern u32 inet_ehash_secret;
208extern u32 ipv6_hash_secret; 208extern u32 ipv6_hash_secret;
209void build_ehash_secret(void); 209void build_ehash_secret(void);
210 210
211static inline unsigned int inet_ehashfn(struct net *net, 211static inline unsigned int __inet_ehashfn(const __be32 laddr,
212 const __be32 laddr, const __u16 lport, 212 const __u16 lport,
213 const __be32 faddr, const __be16 fport) 213 const __be32 faddr,
214 const __be16 fport,
215 u32 initval)
214{ 216{
215 return jhash_3words((__force __u32) laddr, 217 return jhash_3words((__force __u32) laddr,
216 (__force __u32) faddr, 218 (__force __u32) faddr,
217 ((__u32) lport) << 16 | (__force __u32)fport, 219 ((__u32) lport) << 16 | (__force __u32)fport,
218 inet_ehash_secret + net_hash_mix(net)); 220 initval);
219}
220
221static inline int inet_sk_ehashfn(const struct sock *sk)
222{
223 const struct inet_sock *inet = inet_sk(sk);
224 const __be32 laddr = inet->inet_rcv_saddr;
225 const __u16 lport = inet->inet_num;
226 const __be32 faddr = inet->inet_daddr;
227 const __be16 fport = inet->inet_dport;
228 struct net *net = sock_net(sk);
229
230 return inet_ehashfn(net, laddr, lport, faddr, fport);
231} 221}
232 222
233static inline struct request_sock *inet_reqsk_alloc(struct request_sock_ops *ops) 223static inline struct request_sock *inet_reqsk_alloc(struct request_sock_ops *ops)
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index a4b66bbe4f21..18aa668d0cc9 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -24,6 +24,27 @@
24#include <net/secure_seq.h> 24#include <net/secure_seq.h>
25#include <net/ip.h> 25#include <net/ip.h>
26 26
27static unsigned int inet_ehashfn(struct net *net, const __be32 laddr,
28 const __u16 lport, const __be32 faddr,
29 const __be16 fport)
30{
31 return __inet_ehashfn(laddr, lport, faddr, fport,
32 inet_ehash_secret + net_hash_mix(net));
33}
34
35
36static unsigned int inet_sk_ehashfn(const struct sock *sk)
37{
38 const struct inet_sock *inet = inet_sk(sk);
39 const __be32 laddr = inet->inet_rcv_saddr;
40 const __u16 lport = inet->inet_num;
41 const __be32 faddr = inet->inet_daddr;
42 const __be16 fport = inet->inet_dport;
43 struct net *net = sock_net(sk);
44
45 return inet_ehashfn(net, laddr, lport, faddr, fport);
46}
47
27/* 48/*
28 * Allocate and initialize a new local port bind bucket. 49 * Allocate and initialize a new local port bind bucket.
29 * The bindhash mutex for snum's hash chain must be held here. 50 * The bindhash mutex for snum's hash chain must be held here.
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 9f27bb800607..b4437c7db6ce 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -407,6 +407,14 @@ static inline int compute_score2(struct sock *sk, struct net *net,
407 return score; 407 return score;
408} 408}
409 409
410static unsigned int udp_ehashfn(struct net *net, const __be32 laddr,
411 const __u16 lport, const __be32 faddr,
412 const __be16 fport)
413{
414 return __inet_ehashfn(laddr, lport, faddr, fport,
415 inet_ehash_secret + net_hash_mix(net));
416}
417
410 418
411/* called with read_rcu_lock() */ 419/* called with read_rcu_lock() */
412static struct sock *udp4_lib_lookup2(struct net *net, 420static struct sock *udp4_lib_lookup2(struct net *net,
@@ -430,8 +438,8 @@ begin:
430 badness = score; 438 badness = score;
431 reuseport = sk->sk_reuseport; 439 reuseport = sk->sk_reuseport;
432 if (reuseport) { 440 if (reuseport) {
433 hash = inet_ehashfn(net, daddr, hnum, 441 hash = udp_ehashfn(net, daddr, hnum,
434 saddr, sport); 442 saddr, sport);
435 matches = 1; 443 matches = 1;
436 } 444 }
437 } else if (score == badness && reuseport) { 445 } else if (score == badness && reuseport) {
@@ -511,8 +519,8 @@ begin:
511 badness = score; 519 badness = score;
512 reuseport = sk->sk_reuseport; 520 reuseport = sk->sk_reuseport;
513 if (reuseport) { 521 if (reuseport) {
514 hash = inet_ehashfn(net, daddr, hnum, 522 hash = udp_ehashfn(net, daddr, hnum,
515 saddr, sport); 523 saddr, sport);
516 matches = 1; 524 matches = 1;
517 } 525 }
518 } else if (score == badness && reuseport) { 526 } else if (score == badness && reuseport) {
diff --git a/net/rds/connection.c b/net/rds/connection.c
index 642ad42c416b..45e23660437a 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -52,9 +52,9 @@ static struct kmem_cache *rds_conn_slab;
52static struct hlist_head *rds_conn_bucket(__be32 laddr, __be32 faddr) 52static struct hlist_head *rds_conn_bucket(__be32 laddr, __be32 faddr)
53{ 53{
54 /* Pass NULL, don't need struct net for hash */ 54 /* Pass NULL, don't need struct net for hash */
55 unsigned long hash = inet_ehashfn(NULL, 55 unsigned long hash = __inet_ehashfn(be32_to_cpu(laddr), 0,
56 be32_to_cpu(laddr), 0, 56 be32_to_cpu(faddr), 0,
57 be32_to_cpu(faddr), 0); 57 inet_ehash_secret);
58 return &rds_conn_hash[hash & RDS_CONNECTION_HASH_MASK]; 58 return &rds_conn_hash[hash & RDS_CONNECTION_HASH_MASK];
59} 59}
60 60