Skip to content

Commit 9a17740

Browse files
vincentbernathorms
authored andcommitted
ipvs: fix multiplicative hashing in sh/dh/lblc/lblcr algorithms
The sh/dh/lblc/lblcr algorithms are using Knuth's multiplicative hashing incorrectly. Replace its use by the hash_32() macro, which correctly implements this algorithm. It doesn't use the same constant, but it shouldn't matter. Signed-off-by: Vincent Bernat <[email protected]> Acked-by: Julian Anastasov <[email protected]> Signed-off-by: Simon Horman <[email protected]>
1 parent 30edf80 commit 9a17740

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

net/netfilter/ipvs/ip_vs_dh.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <linux/module.h>
4444
#include <linux/kernel.h>
4545
#include <linux/skbuff.h>
46+
#include <linux/hash.h>
4647

4748
#include <net/ip_vs.h>
4849

@@ -81,7 +82,7 @@ static inline unsigned int ip_vs_dh_hashkey(int af, const union nf_inet_addr *ad
8182
addr_fold = addr->ip6[0]^addr->ip6[1]^
8283
addr->ip6[2]^addr->ip6[3];
8384
#endif
84-
return (ntohl(addr_fold)*2654435761UL) & IP_VS_DH_TAB_MASK;
85+
return hash_32(ntohl(addr_fold), IP_VS_DH_TAB_BITS);
8586
}
8687

8788

net/netfilter/ipvs/ip_vs_lblc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <linux/kernel.h>
4949
#include <linux/skbuff.h>
5050
#include <linux/jiffies.h>
51+
#include <linux/hash.h>
5152

5253
/* for sysctl */
5354
#include <linux/fs.h>
@@ -160,7 +161,7 @@ ip_vs_lblc_hashkey(int af, const union nf_inet_addr *addr)
160161
addr_fold = addr->ip6[0]^addr->ip6[1]^
161162
addr->ip6[2]^addr->ip6[3];
162163
#endif
163-
return (ntohl(addr_fold)*2654435761UL) & IP_VS_LBLC_TAB_MASK;
164+
return hash_32(ntohl(addr_fold), IP_VS_LBLC_TAB_BITS);
164165
}
165166

166167

net/netfilter/ipvs/ip_vs_lblcr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <linux/jiffies.h>
4848
#include <linux/list.h>
4949
#include <linux/slab.h>
50+
#include <linux/hash.h>
5051

5152
/* for sysctl */
5253
#include <linux/fs.h>
@@ -323,7 +324,7 @@ ip_vs_lblcr_hashkey(int af, const union nf_inet_addr *addr)
323324
addr_fold = addr->ip6[0]^addr->ip6[1]^
324325
addr->ip6[2]^addr->ip6[3];
325326
#endif
326-
return (ntohl(addr_fold)*2654435761UL) & IP_VS_LBLCR_TAB_MASK;
327+
return hash_32(ntohl(addr_fold), IP_VS_LBLCR_TAB_BITS);
327328
}
328329

329330

net/netfilter/ipvs/ip_vs_sh.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ ip_vs_sh_hashkey(int af, const union nf_inet_addr *addr,
9696
addr_fold = addr->ip6[0]^addr->ip6[1]^
9797
addr->ip6[2]^addr->ip6[3];
9898
#endif
99-
return (offset + (ntohs(port) + ntohl(addr_fold))*2654435761UL) &
99+
return (offset + hash_32(ntohs(port) + ntohl(addr_fold),
100+
IP_VS_SH_TAB_BITS)) &
100101
IP_VS_SH_TAB_MASK;
101102
}
102103

0 commit comments

Comments
 (0)