diff options
author | NeilBrown <neilb@cse.unsw.edu.au> | 2006-01-06 03:09:49 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-06 11:33:21 -0500 |
commit | 1f1e030bf75774b6a283518e1534d598e14147d4 (patch) | |
tree | 8b59e6ed6db756066d2cc18b35d00a753f13e237 /net | |
parent | 4b2f0260c74324abca76ccaa42d426af163125e7 (diff) |
[PATCH] knfsd: fix hash function for IP addresses on 64bit little-endian machines.
The hash.h hash_long function, when used on a 64 bit machine, ignores many
of the middle-order bits. (The prime chosen it too bit-sparse).
IP addresses for clients of an NFS server are very likely to differ only in
the low-order bits. As addresses are stored in network-byte-order, these
bits become middle-order bits in a little-endian 64bit 'long', and so do
not contribute to the hash. Thus you can have the situation where all
clients appear on one hash chain.
So, until hash_long is fixed (or maybe forever), us a hash function that
works well on IP addresses - xor the bytes together.
Thanks to "Iozone" <capps@iozone.org> for identifying this problem.
Cc: "Iozone" <capps@iozone.org>
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'net')
-rw-r--r-- | net/sunrpc/svcauth_unix.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index cac2e774dd81..3e6c694bbad1 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c | |||
@@ -101,10 +101,22 @@ static void ip_map_put(struct cache_head *item, struct cache_detail *cd) | |||
101 | } | 101 | } |
102 | } | 102 | } |
103 | 103 | ||
104 | #if IP_HASHBITS == 8 | ||
105 | /* hash_long on a 64 bit machine is currently REALLY BAD for | ||
106 | * IP addresses in reverse-endian (i.e. on a little-endian machine). | ||
107 | * So use a trivial but reliable hash instead | ||
108 | */ | ||
109 | static inline int hash_ip(unsigned long ip) | ||
110 | { | ||
111 | int hash = ip ^ (ip>>16); | ||
112 | return (hash ^ (hash>>8)) & 0xff; | ||
113 | } | ||
114 | #endif | ||
115 | |||
104 | static inline int ip_map_hash(struct ip_map *item) | 116 | static inline int ip_map_hash(struct ip_map *item) |
105 | { | 117 | { |
106 | return hash_str(item->m_class, IP_HASHBITS) ^ | 118 | return hash_str(item->m_class, IP_HASHBITS) ^ |
107 | hash_long((unsigned long)item->m_addr.s_addr, IP_HASHBITS); | 119 | hash_ip((unsigned long)item->m_addr.s_addr); |
108 | } | 120 | } |
109 | static inline int ip_map_match(struct ip_map *item, struct ip_map *tmp) | 121 | static inline int ip_map_match(struct ip_map *item, struct ip_map *tmp) |
110 | { | 122 | { |