netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] neigh: always use hash_mask under tbl lock
@ 2006-10-03  0:05 Julian Anastasov
  2006-10-03 22:50 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Julian Anastasov @ 2006-10-03  0:05 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev


	Make sure hash_mask is protected with tbl->lock in all
cases just like the hash_buckets.

Signed-off-by: Julian Anastasov <ja@ssi.bg>
---
	I just noticed this in sources. Let me know if such change
is valid and desired for 2.4 or stable tree. Compiles on 2.6.18 and
2.6.18-git18.

diff -urp v2.6.18-git18/linux/net/core/neighbour.c linux/net/core/neighbour.c
--- v2.6.18-git18/linux/net/core/neighbour.c	2006-10-03 01:50:15.000000000 +0300
+++ linux/net/core/neighbour.c	2006-10-03 01:50:32.000000000 +0300
@@ -344,12 +344,12 @@ struct neighbour *neigh_lookup(struct ne
 {
 	struct neighbour *n;
 	int key_len = tbl->key_len;
-	u32 hash_val = tbl->hash(pkey, dev) & tbl->hash_mask;
+	u32 hash_val = tbl->hash(pkey, dev);

 	NEIGH_CACHE_STAT_INC(tbl, lookups);

 	read_lock_bh(&tbl->lock);
-	for (n = tbl->hash_buckets[hash_val]; n; n = n->next) {
+	for (n = tbl->hash_buckets[hash_val & tbl->hash_mask]; n; n = n->next) {
 		if (dev == n->dev && !memcmp(n->primary_key, pkey, key_len)) {
 			neigh_hold(n);
 			NEIGH_CACHE_STAT_INC(tbl, hits);
@@ -364,12 +364,12 @@ struct neighbour *neigh_lookup_nodev(str
 {
 	struct neighbour *n;
 	int key_len = tbl->key_len;
-	u32 hash_val = tbl->hash(pkey, NULL) & tbl->hash_mask;
+	u32 hash_val = tbl->hash(pkey, NULL);

 	NEIGH_CACHE_STAT_INC(tbl, lookups);

 	read_lock_bh(&tbl->lock);
-	for (n = tbl->hash_buckets[hash_val]; n; n = n->next) {
+	for (n = tbl->hash_buckets[hash_val & tbl->hash_mask]; n; n = n->next) {
 		if (!memcmp(n->primary_key, pkey, key_len)) {
 			neigh_hold(n);
 			NEIGH_CACHE_STAT_INC(tbl, hits);
@@ -1998,12 +1998,12 @@ static int neigh_dump_table(struct neigh
 	int rc, h, s_h = cb->args[1];
 	int idx, s_idx = idx = cb->args[2];

+	read_lock_bh(&tbl->lock);
 	for (h = 0; h <= tbl->hash_mask; h++) {
 		if (h < s_h)
 			continue;
 		if (h > s_h)
 			s_idx = 0;
-		read_lock_bh(&tbl->lock);
 		for (n = tbl->hash_buckets[h], idx = 0; n; n = n->next, idx++) {
 			if (idx < s_idx)
 				continue;
@@ -2016,8 +2016,8 @@ static int neigh_dump_table(struct neigh
 				goto out;
 			}
 		}
-		read_unlock_bh(&tbl->lock);
 	}
+	read_unlock_bh(&tbl->lock);
 	rc = skb->len;
 out:
 	cb->args[1] = h;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-10-03 22:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-03  0:05 [PATCH] neigh: always use hash_mask under tbl lock Julian Anastasov
2006-10-03 22:50 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).