aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/dev.c
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-09-01 23:53:46 -0400
committerDavid S. Miller <davem@davemloft.net>2010-09-02 13:12:06 -0400
commitc07b68e841bd737e2ebeb57268d251c89ccc5010 (patch)
treeb27cb3fa27c36ea65897c15fd0f73fed9c9fcdb7 /net/core/dev.c
parentc68839963426d42bdb2c915b435f9860d060e645 (diff)
net: dev_add_pack() & __dev_remove_pack() changes
Add a small helper ptype_head() to get the head to manipulate dev_add_pack() & __dev_remove_pack() can use a spinlock without blocking BH, since softirq use RCU, and these functions are run from process context only. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/dev.c')
-rw-r--r--net/core/dev.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index d8c43e73f0b7..efd318db11ab 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -371,6 +371,14 @@ static inline void netdev_set_addr_lockdep_class(struct net_device *dev)
371 * --ANK (980803) 371 * --ANK (980803)
372 */ 372 */
373 373
374static inline struct list_head *ptype_head(const struct packet_type *pt)
375{
376 if (pt->type == htons(ETH_P_ALL))
377 return &ptype_all;
378 else
379 return &ptype_base[ntohs(pt->type) & PTYPE_HASH_MASK];
380}
381
374/** 382/**
375 * dev_add_pack - add packet handler 383 * dev_add_pack - add packet handler
376 * @pt: packet type declaration 384 * @pt: packet type declaration
@@ -386,16 +394,11 @@ static inline void netdev_set_addr_lockdep_class(struct net_device *dev)
386 394
387void dev_add_pack(struct packet_type *pt) 395void dev_add_pack(struct packet_type *pt)
388{ 396{
389 int hash; 397 struct list_head *head = ptype_head(pt);
390 398
391 spin_lock_bh(&ptype_lock); 399 spin_lock(&ptype_lock);
392 if (pt->type == htons(ETH_P_ALL)) 400 list_add_rcu(&pt->list, head);
393 list_add_rcu(&pt->list, &ptype_all); 401 spin_unlock(&ptype_lock);
394 else {
395 hash = ntohs(pt->type) & PTYPE_HASH_MASK;
396 list_add_rcu(&pt->list, &ptype_base[hash]);
397 }
398 spin_unlock_bh(&ptype_lock);
399} 402}
400EXPORT_SYMBOL(dev_add_pack); 403EXPORT_SYMBOL(dev_add_pack);
401 404
@@ -414,15 +417,10 @@ EXPORT_SYMBOL(dev_add_pack);
414 */ 417 */
415void __dev_remove_pack(struct packet_type *pt) 418void __dev_remove_pack(struct packet_type *pt)
416{ 419{
417 struct list_head *head; 420 struct list_head *head = ptype_head(pt);
418 struct packet_type *pt1; 421 struct packet_type *pt1;
419 422
420 spin_lock_bh(&ptype_lock); 423 spin_lock(&ptype_lock);
421
422 if (pt->type == htons(ETH_P_ALL))
423 head = &ptype_all;
424 else
425 head = &ptype_base[ntohs(pt->type) & PTYPE_HASH_MASK];
426 424
427 list_for_each_entry(pt1, head, list) { 425 list_for_each_entry(pt1, head, list) {
428 if (pt == pt1) { 426 if (pt == pt1) {
@@ -433,7 +431,7 @@ void __dev_remove_pack(struct packet_type *pt)
433 431
434 printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt); 432 printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt);
435out: 433out:
436 spin_unlock_bh(&ptype_lock); 434 spin_unlock(&ptype_lock);
437} 435}
438EXPORT_SYMBOL(__dev_remove_pack); 436EXPORT_SYMBOL(__dev_remove_pack);
439 437