Hello again,
I have a very bad attempt at hashing the components of an tcp session to assign/locate the session in a hash table bucket. I am pretty sure that it has a very high collision rate and when there are a very large number of tcp sessions my application is having to search a long linked list to find the session within the bucket.
All the hashing functions I have found take a single string input where I need to input several integers and hash them into a single result. My guess is that any real hashing function is going to produce better results than what I am currently doing.
Code:
/*
* Calculates the hash of a session provided the IP addresses, and ports.
*/
static inline __u16
sessionhash(__u32 largerIP, __u16 largerIPPort,
__u32 smallerIP, __u16 smallerIPPort){
__u16 hash1 = 0, hash2 = 0, hash3 = 0, hash4 = 0, hash = 0;
hash1 = (largerIP ^ smallerIP) >> 16;
hash2 = (largerIP ^ smallerIP);
hash3 = hash1 ^ hash2;
hash4 = largerIPPort ^ smallerIPPort;
hash = hash3 ^ hash4;
return hash;
}
Thanks.