Commit fb3cfe6e authored by Florian Westphal's avatar Florian Westphal Committed by David S. Miller

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: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 36c77782
...@@ -50,15 +50,11 @@ static unsigned int lowpan_hash_frag(__be16 tag, u16 d_size, ...@@ -50,15 +50,11 @@ static unsigned int lowpan_hash_frag(__be16 tag, u16 d_size,
const struct ieee802154_addr *saddr, const struct ieee802154_addr *saddr,
const struct ieee802154_addr *daddr) const struct ieee802154_addr *daddr)
{ {
u32 c;
net_get_random_once(&lowpan_frags.rnd, sizeof(lowpan_frags.rnd)); net_get_random_once(&lowpan_frags.rnd, sizeof(lowpan_frags.rnd));
c = jhash_3words(ieee802154_addr_hash(saddr), return jhash_3words(ieee802154_addr_hash(saddr),
ieee802154_addr_hash(daddr), ieee802154_addr_hash(daddr),
(__force u32)(tag + (d_size << 16)), (__force u32)(tag + (d_size << 16)),
lowpan_frags.rnd); lowpan_frags.rnd);
return c & (INETFRAGS_HASHSZ - 1);
} }
static unsigned int lowpan_hashfn(const struct inet_frag_queue *q) static unsigned int lowpan_hashfn(const struct inet_frag_queue *q)
......
...@@ -46,6 +46,12 @@ const u8 ip_frag_ecn_table[16] = { ...@@ -46,6 +46,12 @@ const u8 ip_frag_ecn_table[16] = {
}; };
EXPORT_SYMBOL(ip_frag_ecn_table); EXPORT_SYMBOL(ip_frag_ecn_table);
static unsigned int
inet_frag_hashfn(const struct inet_frags *f, const struct inet_frag_queue *q)
{
return f->hashfn(q) & (INETFRAGS_HASHSZ - 1);
}
static void inet_frag_secret_rebuild(unsigned long dummy) static void inet_frag_secret_rebuild(unsigned long dummy)
{ {
struct inet_frags *f = (struct inet_frags *)dummy; struct inet_frags *f = (struct inet_frags *)dummy;
...@@ -63,7 +69,7 @@ static void inet_frag_secret_rebuild(unsigned long dummy) ...@@ -63,7 +69,7 @@ static void inet_frag_secret_rebuild(unsigned long dummy)
hb = &f->hash[i]; hb = &f->hash[i];
hlist_for_each_entry_safe(q, n, &hb->chain, list) { hlist_for_each_entry_safe(q, n, &hb->chain, list) {
unsigned int hval = f->hashfn(q); unsigned int hval = inet_frag_hashfn(f, q);
if (hval != i) { if (hval != i) {
struct inet_frag_bucket *hb_dest; 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,7 +139,7 @@ static inline void fq_unlink(struct inet_frag_queue *fq, struct inet_frags *f)
unsigned int hash; unsigned int hash;
read_lock(&f->lock); read_lock(&f->lock);
hash = f->hashfn(fq); hash = inet_frag_hashfn(f, fq);
hb = &f->hash[hash]; hb = &f->hash[hash];
spin_lock(&hb->chain_lock); spin_lock(&hb->chain_lock);
...@@ -252,7 +258,7 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf, ...@@ -252,7 +258,7 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
* the rnd seed, so we need to re-calculate the hash * the rnd seed, so we need to re-calculate the hash
* chain. Fortunatelly the qp_in can be used to get one. * chain. Fortunatelly the qp_in can be used to get one.
*/ */
hash = f->hashfn(qp_in); hash = inet_frag_hashfn(f, qp_in);
hb = &f->hash[hash]; hb = &f->hash[hash];
spin_lock(&hb->chain_lock); spin_lock(&hb->chain_lock);
...@@ -326,6 +332,7 @@ struct inet_frag_queue *inet_frag_find(struct netns_frags *nf, ...@@ -326,6 +332,7 @@ struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
struct inet_frag_queue *q; struct inet_frag_queue *q;
int depth = 0; int depth = 0;
hash &= (INETFRAGS_HASHSZ - 1);
hb = &f->hash[hash]; hb = &f->hash[hash];
spin_lock(&hb->chain_lock); spin_lock(&hb->chain_lock);
......
...@@ -109,7 +109,7 @@ static unsigned int ipqhashfn(__be16 id, __be32 saddr, __be32 daddr, u8 prot) ...@@ -109,7 +109,7 @@ static unsigned int ipqhashfn(__be16 id, __be32 saddr, __be32 daddr, u8 prot)
net_get_random_once(&ip4_frags.rnd, sizeof(ip4_frags.rnd)); net_get_random_once(&ip4_frags.rnd, sizeof(ip4_frags.rnd));
return jhash_3words((__force u32)id << 16 | prot, return jhash_3words((__force u32)id << 16 | prot,
(__force u32)saddr, (__force u32)daddr, (__force u32)saddr, (__force u32)daddr,
ip4_frags.rnd) & (INETFRAGS_HASHSZ - 1); ip4_frags.rnd);
} }
static unsigned int ip4_hashfn(const struct inet_frag_queue *q) static unsigned int ip4_hashfn(const struct inet_frag_queue *q)
......
...@@ -147,12 +147,9 @@ static inline u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h) ...@@ -147,12 +147,9 @@ static inline u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h)
static unsigned int nf_hash_frag(__be32 id, const struct in6_addr *saddr, static unsigned int nf_hash_frag(__be32 id, const struct in6_addr *saddr,
const struct in6_addr *daddr) const struct in6_addr *daddr)
{ {
u32 c;
net_get_random_once(&nf_frags.rnd, sizeof(nf_frags.rnd)); net_get_random_once(&nf_frags.rnd, sizeof(nf_frags.rnd));
c = jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr), return jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr),
(__force u32)id, nf_frags.rnd); (__force u32)id, nf_frags.rnd);
return c & (INETFRAGS_HASHSZ - 1);
} }
......
...@@ -85,13 +85,9 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev, ...@@ -85,13 +85,9 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
static unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr, static unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr,
const struct in6_addr *daddr) const struct in6_addr *daddr)
{ {
u32 c;
net_get_random_once(&ip6_frags.rnd, sizeof(ip6_frags.rnd)); net_get_random_once(&ip6_frags.rnd, sizeof(ip6_frags.rnd));
c = jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr), return jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr),
(__force u32)id, ip6_frags.rnd); (__force u32)id, ip6_frags.rnd);
return c & (INETFRAGS_HASHSZ - 1);
} }
static unsigned int ip6_hashfn(const struct inet_frag_queue *q) static unsigned int ip6_hashfn(const struct inet_frag_queue *q)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment