ipv4: Use universal hash for ARP.
authorDavid S. Miller <davem@davemloft.net>
Mon, 11 Jul 2011 08:37:28 +0000 (01:37 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 11 Jul 2011 08:37:28 +0000 (01:37 -0700)
We need to make sure the multiplier is odd.

Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/arp.h
net/core/neighbour.c
net/ipv4/arp.c

index 91f0568a04ef2b85be4aa417abd7a1eb1ae1055d..723bde501c648459ccf7bef70217492696252a51 100644 (file)
@@ -8,6 +8,13 @@
 
 extern struct neigh_table arp_tbl;
 
+static inline u32 arp_hashfn(u32 key, const struct net_device *dev, u32 hash_rnd)
+{
+       u32 val = key ^ dev->ifindex;
+
+       return val * hash_rnd;
+}
+
 extern void    arp_init(void);
 extern int     arp_find(unsigned char *haddr, struct sk_buff *skb);
 extern int     arp_ioctl(struct net *net, unsigned int cmd, void __user *arg);
index 4d5fc9433fd917e6b201e4d01c3162087420a16b..50bd960983e0e23d196b6ab50775cfcd7844acf7 100644 (file)
@@ -334,6 +334,7 @@ static struct neigh_hash_table *neigh_hash_alloc(unsigned int shift)
        ret->hash_buckets = buckets;
        ret->hash_shift = shift;
        get_random_bytes(&ret->hash_rnd, sizeof(ret->hash_rnd));
+       ret->hash_rnd |= 1;
        return ret;
 }
 
index 1b74d3b643712ad94ed3bd2fd6d2aab6d6cd1d96..4412b57f6ff608791e3bdba7f5ff6b02e7f91abb 100644 (file)
@@ -97,7 +97,6 @@
 #include <linux/init.h>
 #include <linux/net.h>
 #include <linux/rcupdate.h>
-#include <linux/jhash.h>
 #include <linux/slab.h>
 #ifdef CONFIG_SYSCTL
 #include <linux/sysctl.h>
@@ -232,7 +231,7 @@ static u32 arp_hash(const void *pkey,
                    const struct net_device *dev,
                    __u32 hash_rnd)
 {
-       return jhash_2words(*(u32 *)pkey, dev->ifindex, hash_rnd);
+       return arp_hashfn(*(u32 *)pkey, dev, hash_rnd);
 }
 
 static int arp_constructor(struct neighbour *neigh)