Title: hash_oroute() / hash_iroute()


hash_oroute() and hash_oroute() are identical.

hash_oroute()is #define'd in ipr.c:

#define hash_oroute(port_nr, ipaddr, hash_tmp) (hash_tmp= (ipaddr), \
hash_tmp= (hash_tmp >> 20) ^ hash_tmp, \
hash_tmp= (hash_tmp >> 10) ^ hash_tmp, \
hash_tmp= (hash_tmp >> 5) ^ hash_tmp, \
(hash_tmp + (port_nr)) & OROUTE_HASH_MASK)

where OROUTE_HASH_MASK is #define'd as the following:

#define OROUTE_HASH_NR 32
#define OROUTE_HASH_MASK (OROUTE_HASH_NR-1)

For an address of 192.160.1.1 on ip port 0:

hash_tmp = 192.160.1.1 = 11000000 10100000 00000001 00000001 (binary)

hash_tmp = (192.160.1.1 >> 20) ^ 192.170.1.1
= 00000000 00000000 00001100 00001010 ^ 11000000 10100000 00000001 00000001
= 11000000 10100000 00001101 00001011 = 192.168.13.11

hash_tmp = (192.168.13.11 >> 10) ^ 192.168.13.11
= 00000000 00110000 00101000 00000011 ^ 11000000 10100000 00001101 00001011
= 11000000 10010000 00100101 00001000 = 192.144.37.8

hash_tmp = (192.144.37.8 >> 5) ^ 192.144.37.8
= 00000110 00000100 10000001 00101000 ^ 11000000 10010000 00100101 00001000
= 11000110 10010100 10100100 00100000 = 198.148.164.32

return value: hash_tmp + port_nr & OROUTE_HASH_MASK
= hash_tmp + port_nr & (OROUTE_HASH_NR - 1)
= 198.148.164.32 + 0 & (32-1)
= 11000110 10010100 10100100 00100000 + 0 & 00011111
= 0

Therefore, hash_iroute(0, 192.160.1.1, 0) equals 0.

As mentioned earlier, hash_oroute() and hash_iroute() are identical. Furthermore, OROUTE_HASH_NR and IROUTE_HASH_NR are both 32 and OROUTE_HASH_MASK and IROUTE_HASH_MASK are both 31 (0001 1111 binary).

Note that the initial value of hash_tmp is meaningless.