diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2007-11-26 07:12:58 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-28 17:55:04 -0500 |
commit | 82d8a867ffaed7fe58e789103b32c0fc6b79dafd (patch) | |
tree | 091c5c972c97a4a3433b9c291990068115fbdbfd /net/core/dev.c | |
parent | 8d8ad9d7c4bfe79bc91b7fc419ecfb9dcdfe6a51 (diff) |
[NET]: Make macro to specify the ptype_base size
Currently this size is 16, but as the comment says this
is so only because all the chains (except one) has the
length 1. I think, that some day this may change, so
growing this hash will be much easier.
Besides, symbolic names are read better than magic constants.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/dev.c')
-rw-r--r-- | net/core/dev.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index d0e23d8310ff..d0d2675aaed6 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -150,8 +150,11 @@ | |||
150 | * 86DD IPv6 | 150 | * 86DD IPv6 |
151 | */ | 151 | */ |
152 | 152 | ||
153 | #define PTYPE_HASH_SIZE (16) | ||
154 | #define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1) | ||
155 | |||
153 | static DEFINE_SPINLOCK(ptype_lock); | 156 | static DEFINE_SPINLOCK(ptype_lock); |
154 | static struct list_head ptype_base[16] __read_mostly; /* 16 way hashed list */ | 157 | static struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly; |
155 | static struct list_head ptype_all __read_mostly; /* Taps */ | 158 | static struct list_head ptype_all __read_mostly; /* Taps */ |
156 | 159 | ||
157 | #ifdef CONFIG_NET_DMA | 160 | #ifdef CONFIG_NET_DMA |
@@ -362,7 +365,7 @@ void dev_add_pack(struct packet_type *pt) | |||
362 | if (pt->type == htons(ETH_P_ALL)) | 365 | if (pt->type == htons(ETH_P_ALL)) |
363 | list_add_rcu(&pt->list, &ptype_all); | 366 | list_add_rcu(&pt->list, &ptype_all); |
364 | else { | 367 | else { |
365 | hash = ntohs(pt->type) & 15; | 368 | hash = ntohs(pt->type) & PTYPE_HASH_MASK; |
366 | list_add_rcu(&pt->list, &ptype_base[hash]); | 369 | list_add_rcu(&pt->list, &ptype_base[hash]); |
367 | } | 370 | } |
368 | spin_unlock_bh(&ptype_lock); | 371 | spin_unlock_bh(&ptype_lock); |
@@ -391,7 +394,7 @@ void __dev_remove_pack(struct packet_type *pt) | |||
391 | if (pt->type == htons(ETH_P_ALL)) | 394 | if (pt->type == htons(ETH_P_ALL)) |
392 | head = &ptype_all; | 395 | head = &ptype_all; |
393 | else | 396 | else |
394 | head = &ptype_base[ntohs(pt->type) & 15]; | 397 | head = &ptype_base[ntohs(pt->type) & PTYPE_HASH_MASK]; |
395 | 398 | ||
396 | list_for_each_entry(pt1, head, list) { | 399 | list_for_each_entry(pt1, head, list) { |
397 | if (pt == pt1) { | 400 | if (pt == pt1) { |
@@ -1420,7 +1423,8 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features) | |||
1420 | } | 1423 | } |
1421 | 1424 | ||
1422 | rcu_read_lock(); | 1425 | rcu_read_lock(); |
1423 | list_for_each_entry_rcu(ptype, &ptype_base[ntohs(type) & 15], list) { | 1426 | list_for_each_entry_rcu(ptype, |
1427 | &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) { | ||
1424 | if (ptype->type == type && !ptype->dev && ptype->gso_segment) { | 1428 | if (ptype->type == type && !ptype->dev && ptype->gso_segment) { |
1425 | if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) { | 1429 | if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) { |
1426 | err = ptype->gso_send_check(skb); | 1430 | err = ptype->gso_send_check(skb); |
@@ -2077,7 +2081,8 @@ ncls: | |||
2077 | goto out; | 2081 | goto out; |
2078 | 2082 | ||
2079 | type = skb->protocol; | 2083 | type = skb->protocol; |
2080 | list_for_each_entry_rcu(ptype, &ptype_base[ntohs(type)&15], list) { | 2084 | list_for_each_entry_rcu(ptype, |
2085 | &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) { | ||
2081 | if (ptype->type == type && | 2086 | if (ptype->type == type && |
2082 | (!ptype->dev || ptype->dev == skb->dev)) { | 2087 | (!ptype->dev || ptype->dev == skb->dev)) { |
2083 | if (pt_prev) | 2088 | if (pt_prev) |
@@ -2525,7 +2530,7 @@ static void *ptype_get_idx(loff_t pos) | |||
2525 | ++i; | 2530 | ++i; |
2526 | } | 2531 | } |
2527 | 2532 | ||
2528 | for (t = 0; t < 16; t++) { | 2533 | for (t = 0; t < PTYPE_HASH_SIZE; t++) { |
2529 | list_for_each_entry_rcu(pt, &ptype_base[t], list) { | 2534 | list_for_each_entry_rcu(pt, &ptype_base[t], list) { |
2530 | if (i == pos) | 2535 | if (i == pos) |
2531 | return pt; | 2536 | return pt; |
@@ -2559,10 +2564,10 @@ static void *ptype_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
2559 | hash = 0; | 2564 | hash = 0; |
2560 | nxt = ptype_base[0].next; | 2565 | nxt = ptype_base[0].next; |
2561 | } else | 2566 | } else |
2562 | hash = ntohs(pt->type) & 15; | 2567 | hash = ntohs(pt->type) & PTYPE_HASH_MASK; |
2563 | 2568 | ||
2564 | while (nxt == &ptype_base[hash]) { | 2569 | while (nxt == &ptype_base[hash]) { |
2565 | if (++hash >= 16) | 2570 | if (++hash >= PTYPE_HASH_SIZE) |
2566 | return NULL; | 2571 | return NULL; |
2567 | nxt = ptype_base[hash].next; | 2572 | nxt = ptype_base[hash].next; |
2568 | } | 2573 | } |
@@ -4398,7 +4403,7 @@ static int __init net_dev_init(void) | |||
4398 | goto out; | 4403 | goto out; |
4399 | 4404 | ||
4400 | INIT_LIST_HEAD(&ptype_all); | 4405 | INIT_LIST_HEAD(&ptype_all); |
4401 | for (i = 0; i < 16; i++) | 4406 | for (i = 0; i < PTYPE_HASH_SIZE; i++) |
4402 | INIT_LIST_HEAD(&ptype_base[i]); | 4407 | INIT_LIST_HEAD(&ptype_base[i]); |
4403 | 4408 | ||
4404 | if (register_pernet_subsys(&netdev_net_ops)) | 4409 | if (register_pernet_subsys(&netdev_net_ops)) |