diff options
author | glebius <glebius@FreeBSD.org> | 2006-10-11 12:31:14 +0000 |
---|---|---|
committer | glebius <glebius@FreeBSD.org> | 2006-10-11 12:31:14 +0000 |
commit | c93c44c80d2797311c5b8ad9bbdc8cf346a5ed50 (patch) | |
tree | 5adfe4048ff78bf3f1208a4d5390cd2ef64a862e /sys/netgraph/netflow/netflow.c | |
parent | 3194151ff3ef336e29abfc8e8be6a22bf96c4468 (diff) | |
download | FreeBSD-src-c93c44c80d2797311c5b8ad9bbdc8cf346a5ed50.zip FreeBSD-src-c93c44c80d2797311c5b8ad9bbdc8cf346a5ed50.tar.gz |
Use hash functions with better distribution. Tested on live traffic.
Submitted by: Alexander Motin <mav alkar.net>
Diffstat (limited to 'sys/netgraph/netflow/netflow.c')
-rw-r--r-- | sys/netgraph/netflow/netflow.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/sys/netgraph/netflow/netflow.c b/sys/netgraph/netflow/netflow.c index 6393e1f..659b689 100644 --- a/sys/netgraph/netflow/netflow.c +++ b/sys/netgraph/netflow/netflow.c @@ -56,18 +56,18 @@ static const char rcs_id[] = #define NBUCKETS (65536) /* must be power of 2 */ -/* This hash is for TCP or UDP packets */ -#define FULL_HASH(addr1,addr2,port1,port2)\ - (((addr1 >> 16) ^ \ - (addr2 & 0x00FF) ^ \ - ((port1 ^ port2) << 8) )& \ - (NBUCKETS - 1)) - -/* This hash is for all other IP packets */ -#define ADDR_HASH(addr1,addr2)\ - (((addr1 >> 16) ^ \ - (addr2 & 0x00FF) )& \ - (NBUCKETS - 1)) +/* This hash is for TCP or UDP packets. */ +#define FULL_HASH(addr1, addr2, port1, port2) \ + (((addr1 ^ (addr1 >> 16) ^ \ + htons(addr2 ^ (addr2 >> 16))) ^ \ + srcport ^ htons(dstport)) & \ + (NBUCKETS - 1)) + +/* This hash is for all other IP packets. */ +#define ADDR_HASH(addr1, addr2) \ + ((addr1 ^ (addr1 >> 16) ^ \ + htons(addr2 ^ (addr2 >> 16))) & \ + (NBUCKETS - 1)) /* Macros to shorten logical constructions */ /* XXX: priv must exist in namespace */ |