aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2014-07-24 10:50:30 -0400
committerDavid S. Miller <davem@davemloft.net>2014-07-28 01:34:35 -0400
commitfb3cfe6e75b9d05c87265e85e67d7caf6e5b44a7 (patch)
tree3dfe9c9ddebc20bd61571db6d23ff660a67a3485
parent36c7778218b93d96d88d68f116a711f6a598b72f (diff)
inet: frag: remove hash size assumptions from callers
hide actual hash size from individual users: The _find function will now fold the given hash value into the required range. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/ieee802154/reassembly.c12
-rw-r--r--net/ipv4/inet_fragment.c13
-rw-r--r--net/ipv4/ip_fragment.c2
-rw-r--r--net/ipv6/netfilter/nf_conntrack_reasm.c7
-rw-r--r--net/ipv6/reassembly.c8
5 files changed, 19 insertions, 23 deletions
diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
index a5588be18024..a707995fd4d7 100644
--- a/net/ieee802154/reassembly.c
+++ b/net/ieee802154/reassembly.c
@@ -50,15 +50,11 @@ static unsigned int lowpan_hash_frag(__be16 tag, u16 d_size,
50 const struct ieee802154_addr *saddr, 50 const struct ieee802154_addr *saddr,
51 const struct ieee802154_addr *daddr) 51 const struct ieee802154_addr *daddr)
52{ 52{
53 u32 c;
54
55 net_get_random_once(&lowpan_frags.rnd, sizeof(lowpan_frags.rnd)); 53 net_get_random_once(&lowpan_frags.rnd, sizeof(lowpan_frags.rnd));
56 c = jhash_3words(ieee802154_addr_hash(saddr), 54 return jhash_3words(ieee802154_addr_hash(saddr),
57 ieee802154_addr_hash(daddr), 55 ieee802154_addr_hash(daddr),
58 (__force u32)(tag + (d_size << 16)), 56 (__force u32)(tag + (d_size << 16)),
59 lowpan_frags.rnd); 57 lowpan_frags.rnd);
60
61 return c & (INETFRAGS_HASHSZ - 1);
62} 58}
63 59
64static unsigned int lowpan_hashfn(const struct inet_frag_queue *q) 60static unsigned int lowpan_hashfn(const struct inet_frag_queue *q)
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index 3b01959bf4bb..930d23870811 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -46,6 +46,12 @@ const u8 ip_frag_ecn_table[16] = {
46}; 46};
47EXPORT_SYMBOL(ip_frag_ecn_table); 47EXPORT_SYMBOL(ip_frag_ecn_table);
48 48
49static unsigned int
50inet_frag_hashfn(const struct inet_frags *f, const struct inet_frag_queue *q)
51{
52 return f->hashfn(q) & (INETFRAGS_HASHSZ - 1);
53}
54
49static void inet_frag_secret_rebuild(unsigned long dummy) 55static void inet_frag_secret_rebuild(unsigned long dummy)
50{ 56{
51 struct inet_frags *f = (struct inet_frags *)dummy; 57 struct inet_frags *f = (struct inet_frags *)dummy;
@@ -63,7 +69,7 @@ static void inet_frag_secret_rebuild(unsigned long dummy)
63 69
64 hb = &f->hash[i]; 70 hb = &f->hash[i];
65 hlist_for_each_entry_safe(q, n, &hb->chain, list) { 71 hlist_for_each_entry_safe(q, n, &hb->chain, list) {
66 unsigned int hval = f->hashfn(q); 72 unsigned int hval = inet_frag_hashfn(f, q);
67 73
68 if (hval != i) { 74 if (hval != i) {
69 struct inet_frag_bucket *hb_dest; 75 struct inet_frag_bucket *hb_dest;
@@ -133,7 +139,7 @@ static inline void fq_unlink(struct inet_frag_queue *fq, struct inet_frags *f)
133 unsigned int hash; 139 unsigned int hash;
134 140
135 read_lock(&f->lock); 141 read_lock(&f->lock);
136 hash = f->hashfn(fq); 142 hash = inet_frag_hashfn(f, fq);
137 hb = &f->hash[hash]; 143 hb = &f->hash[hash];
138 144
139 spin_lock(&hb->chain_lock); 145 spin_lock(&hb->chain_lock);
@@ -252,7 +258,7 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
252 * the rnd seed, so we need to re-calculate the hash 258 * the rnd seed, so we need to re-calculate the hash
253 * chain. Fortunatelly the qp_in can be used to get one. 259 * chain. Fortunatelly the qp_in can be used to get one.
254 */ 260 */
255 hash = f->hashfn(qp_in); 261 hash = inet_frag_hashfn(f, qp_in);
256 hb = &f->hash[hash]; 262 hb = &f->hash[hash];
257 spin_lock(&hb->chain_lock); 263 spin_lock(&hb->chain_lock);
258 264
@@ -326,6 +332,7 @@ struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
326 struct inet_frag_queue *q; 332 struct inet_frag_queue *q;
327 int depth = 0; 333 int depth = 0;
328 334
335 hash &= (INETFRAGS_HASHSZ - 1);
329 hb = &f->hash[hash]; 336 hb = &f->hash[hash];
330 337
331 spin_lock(&hb->chain_lock); 338 spin_lock(&hb->chain_lock);
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index 586e6aaf9e6e..b769eb6c83c0 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -109,7 +109,7 @@ static unsigned int ipqhashfn(__be16 id, __be32 saddr, __be32 daddr, u8 prot)
109 net_get_random_once(&ip4_frags.rnd, sizeof(ip4_frags.rnd)); 109 net_get_random_once(&ip4_frags.rnd, sizeof(ip4_frags.rnd));
110 return jhash_3words((__force u32)id << 16 | prot, 110 return jhash_3words((__force u32)id << 16 | prot,
111 (__force u32)saddr, (__force u32)daddr, 111 (__force u32)saddr, (__force u32)daddr,
112 ip4_frags.rnd) & (INETFRAGS_HASHSZ - 1); 112 ip4_frags.rnd);
113} 113}
114 114
115static unsigned int ip4_hashfn(const struct inet_frag_queue *q) 115static unsigned int ip4_hashfn(const struct inet_frag_queue *q)
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index c2c3f2116bc5..607e4a94ef41 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -147,12 +147,9 @@ static inline u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h)
147static unsigned int nf_hash_frag(__be32 id, const struct in6_addr *saddr, 147static unsigned int nf_hash_frag(__be32 id, const struct in6_addr *saddr,
148 const struct in6_addr *daddr) 148 const struct in6_addr *daddr)
149{ 149{
150 u32 c;
151
152 net_get_random_once(&nf_frags.rnd, sizeof(nf_frags.rnd)); 150 net_get_random_once(&nf_frags.rnd, sizeof(nf_frags.rnd));
153 c = jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr), 151 return jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr),
154 (__force u32)id, nf_frags.rnd); 152 (__force u32)id, nf_frags.rnd);
155 return c & (INETFRAGS_HASHSZ - 1);
156} 153}
157 154
158 155
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
index 0c6932cc08cb..2b76549a1016 100644
--- a/net/ipv6/reassembly.c
+++ b/net/ipv6/reassembly.c
@@ -85,13 +85,9 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
85static unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr, 85static unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr,
86 const struct in6_addr *daddr) 86 const struct in6_addr *daddr)
87{ 87{
88 u32 c;
89
90 net_get_random_once(&ip6_frags.rnd, sizeof(ip6_frags.rnd)); 88 net_get_random_once(&ip6_frags.rnd, sizeof(ip6_frags.rnd));
91 c = jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr), 89 return jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr),
92 (__force u32)id, ip6_frags.rnd); 90 (__force u32)id, ip6_frags.rnd);
93
94 return c & (INETFRAGS_HASHSZ - 1);
95} 91}
96 92
97static unsigned int ip6_hashfn(const struct inet_frag_queue *q) 93static unsigned int ip6_hashfn(const struct inet_frag_queue *q)