patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / net / bridge / br_notify.c
1 /*
2  *      Device event handling
3  *      Linux ethernet bridge
4  *
5  *      Authors:
6  *      Lennert Buytenhek               <buytenh@gnu.org>
7  *
8  *      $Id: br_notify.c,v 1.2 2000/02/21 15:51:34 davem Exp $
9  *
10  *      This program is free software; you can redistribute it and/or
11  *      modify it under the terms of the GNU General Public License
12  *      as published by the Free Software Foundation; either version
13  *      2 of the License, or (at your option) any later version.
14  */
15
16 #include <linux/kernel.h>
17
18 #include "br_private.h"
19
20 static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr);
21
22 struct notifier_block br_device_notifier =
23 {
24         .notifier_call = br_device_event
25 };
26
27 static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
28 {
29         struct net_device *dev;
30         struct net_bridge_port *p;
31         struct net_bridge *br;
32
33         dev = ptr;
34         p = dev->br_port;
35
36         if (p == NULL)
37                 return NOTIFY_DONE;
38
39         br = p->br;
40
41         switch (event) {
42         case NETDEV_CHANGEADDR:
43                 spin_lock_bh(&br->lock);
44                 br_fdb_changeaddr(p, dev->dev_addr);
45                 if (br->dev->flags & IFF_UP)
46                         br_stp_recalculate_bridge_id(br);
47                 spin_unlock_bh(&br->lock);
48                 break;
49
50         case NETDEV_DOWN:
51                 if (br->dev->flags & IFF_UP) {
52                         spin_lock_bh(&br->lock);
53                         br_stp_disable_port(p);
54                         spin_unlock_bh(&br->lock);
55                 }
56                 break;
57
58         case NETDEV_UP:
59                 if (br->dev->flags & IFF_UP) {
60                         spin_lock_bh(&br->lock);
61                         br_stp_enable_port(p);
62                         spin_unlock_bh(&br->lock);
63                 }
64                 break;
65
66         case NETDEV_UNREGISTER:
67                 br_del_if(br, dev);
68                 break;
69         }
70
71         return NOTIFY_DONE;
72 }