Index: ip_vs_conn.c =================================================================== RCS file: /home/wensong/cvsroot/ipvs/ip_vs_conn.c,v retrieving revision 1.31 diff -u -r1.31 ip_vs_conn.c --- ip_vs_conn.c 18 Apr 2003 09:03:16 -0000 1.31 +++ ip_vs_conn.c 17 Jun 2003 12:15:28 -0000 @@ -30,6 +30,7 @@ #include #include #include /* for proc_net_* */ +#include #include "ip_vs.h" //#include @@ -49,6 +50,8 @@ /* counter for no client port connections */ static atomic_t ip_vs_conn_no_cport_cnt = ATOMIC_INIT(0); +/* random value for IPVS connection hash */ +static unsigned int ip_vs_conn_rnd; /* * Fine locking granularity for big connection hash table @@ -113,10 +116,21 @@ static inline unsigned ip_vs_conn_hashkey(unsigned proto, __u32 addr, __u16 port) { +#ifdef CONFIG_IP_VS_HASH_SHIFTXOR unsigned addrh = ntohl(addr); - return (proto^addrh^(addrh>>IP_VS_CONN_TAB_BITS)^ntohs(port)) + return ((proto ^ addrh ^ (addrh >> IP_VS_CONN_TAB_BITS) + ^ ntohs(port)) * ip_vs_conn_rnd) & IP_VS_CONN_TAB_MASK; +#endif +#ifdef CONFIG_IP_VS_HASH_GOLDENRATIO + return ((ip_vs_conn_rnd ^ (proto + addr + port)) * 2654435761UL) + & IP_VS_CONN_TAB_MASK; +#endif +#ifdef CONFIG_IP_VS_HASH_JENKINS + return jhash_3words(addr, port, proto, ip_vs_conn_rnd) + & IP_VS_CONN_TAB_MASK; +#endif } @@ -714,8 +728,8 @@ /* * Randomly scan 1/32 of the whole table every second */ - for (idx=0; idx<(IP_VS_CONN_TAB_SIZE>>5); idx++) { - unsigned hash = net_random()&IP_VS_CONN_TAB_MASK; + for (idx = 0; idx < (IP_VS_CONN_TAB_SIZE>>5); idx++) { + unsigned hash = net_random() & IP_VS_CONN_TAB_MASK; /* * Lock is actually needed in this loop. @@ -850,6 +864,11 @@ } proc_net_create("ip_vs_conn", 0, ip_vs_conn_getinfo); + + /* calculate the random value for connection hash */ + ip_vs_conn_rnd = + jhash_3words((u32) jiffies, (u32) ip_vs_conn_tab, + net_random(), IP_VS_CONN_TAB_SIZE); return 0; } Index: Kconfig =================================================================== RCS file: /home/wensong/cvsroot/ipvs/Kconfig,v retrieving revision 1.3 diff -u -r1.3 Kconfig --- Kconfig 8 Jun 2003 09:31:19 -0000 1.3 +++ Kconfig 15 Jun 2003 14:37:05 -0000 @@ -62,6 +62,24 @@ each hash entry uses 8 bytes, so you can estimate how much memory is needed for your box. +choice + prompt "IPVS connection hash function" + default IP_VS_HASH_GOLDENRATIO + +config IP_VS_HASH_SHIFTXOR + bool "" + ---help--- + +config IP_VS_HASH_GOLDENRATIO + bool "" + ---help--- + + +config IP_VS_HASH_JENKINS + bool "" + ---help--- + + comment "IPVS transport protocol load balancing support" depends on IP_VS