Blame view
net/bridge/br_notify.c
2.58 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 |
/* * Device event handling * Linux ethernet bridge * * Authors: * Lennert Buytenhek <buytenh@gnu.org> * |
1da177e4c Linux-2.6.12-rc2 |
8 9 10 11 12 13 14 |
* This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/kernel.h> |
11dc1f36a [BRIDGE]: netlink... |
15 |
#include <linux/rtnetlink.h> |
e9dc86534 [NET]: Make devic... |
16 |
#include <net/net_namespace.h> |
1da177e4c Linux-2.6.12-rc2 |
17 18 19 20 21 22 23 24 25 26 27 |
#include "br_private.h" static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr); struct notifier_block br_device_notifier = { .notifier_call = br_device_event }; /* * Handle changes in state of network devices enslaved to a bridge. |
9d6f229fc [NET] BRIDGE: Fix... |
28 |
* |
1da177e4c Linux-2.6.12-rc2 |
29 30 31 32 33 34 |
* Note: don't care about up/down if bridge itself is down, because * port state is checked when bridge is brought up. */ static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr) { struct net_device *dev = ptr; |
b5ed54e94 bridge: fix RCU r... |
35 |
struct net_bridge_port *p; |
1da177e4c Linux-2.6.12-rc2 |
36 |
struct net_bridge *br; |
9be6dd651 Bridge: Always se... |
37 |
bool changed_addr; |
e0f43752a bridge: update sy... |
38 |
int err; |
1da177e4c Linux-2.6.12-rc2 |
39 |
|
bb900b27a bridge: allow cre... |
40 |
/* register of bridge completed, add sysfs entries */ |
28674b97c bridge: fix accid... |
41 |
if ((dev->priv_flags & IFF_EBRIDGE) && event == NETDEV_REGISTER) { |
bb900b27a bridge: allow cre... |
42 43 44 |
br_sysfs_addbr(dev); return NOTIFY_DONE; } |
1da177e4c Linux-2.6.12-rc2 |
45 |
/* not a port of a bridge */ |
ec1e5610c bridge: add RCU a... |
46 47 |
p = br_port_get_rtnl(dev); if (!p) |
1da177e4c Linux-2.6.12-rc2 |
48 49 50 |
return NOTIFY_DONE; br = p->br; |
1da177e4c Linux-2.6.12-rc2 |
51 52 53 54 55 56 |
switch (event) { case NETDEV_CHANGEMTU: dev_set_mtu(br->dev, br_min_mtu(br)); break; case NETDEV_CHANGEADDR: |
269def7c5 [BRIDGE]: elimina... |
57 |
spin_lock_bh(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
58 |
br_fdb_changeaddr(p, dev->dev_addr); |
9be6dd651 Bridge: Always se... |
59 |
changed_addr = br_stp_recalculate_bridge_id(br); |
269def7c5 [BRIDGE]: elimina... |
60 |
spin_unlock_bh(&br->lock); |
9be6dd651 Bridge: Always se... |
61 62 63 |
if (changed_addr) call_netdevice_notifiers(NETDEV_CHANGEADDR, br->dev); |
1da177e4c Linux-2.6.12-rc2 |
64 |
break; |
4433f420e [BRIDGE]: handle ... |
65 |
case NETDEV_CHANGE: |
269def7c5 [BRIDGE]: elimina... |
66 |
br_port_carrier_check(p); |
1da177e4c Linux-2.6.12-rc2 |
67 |
break; |
81d35307d [BRIDGE]: set fea... |
68 |
case NETDEV_FEAT_CHANGE: |
c4d27ef95 bridge: convert b... |
69 |
netdev_update_features(br->dev); |
81d35307d [BRIDGE]: set fea... |
70 |
break; |
1da177e4c Linux-2.6.12-rc2 |
71 |
case NETDEV_DOWN: |
269def7c5 [BRIDGE]: elimina... |
72 |
spin_lock_bh(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
73 74 |
if (br->dev->flags & IFF_UP) br_stp_disable_port(p); |
269def7c5 [BRIDGE]: elimina... |
75 |
spin_unlock_bh(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
76 77 78 |
break; case NETDEV_UP: |
b86c45035 bridge: change wh... |
79 80 |
if (netif_carrier_ok(dev) && (br->dev->flags & IFF_UP)) { spin_lock_bh(&br->lock); |
1da177e4c Linux-2.6.12-rc2 |
81 |
br_stp_enable_port(p); |
b86c45035 bridge: change wh... |
82 83 |
spin_unlock_bh(&br->lock); } |
1da177e4c Linux-2.6.12-rc2 |
84 85 86 |
break; case NETDEV_UNREGISTER: |
1da177e4c Linux-2.6.12-rc2 |
87 |
br_del_if(br, dev); |
269def7c5 [BRIDGE]: elimina... |
88 |
break; |
1c01fe14a net: forbid under... |
89 |
|
e0f43752a bridge: update sy... |
90 91 92 93 94 |
case NETDEV_CHANGENAME: err = br_sysfs_renameif(p); if (err) return notifier_from_errno(err); break; |
1c01fe14a net: forbid under... |
95 96 97 |
case NETDEV_PRE_TYPE_CHANGE: /* Forbid underlaying device to change its type. */ return NOTIFY_BAD; |
9d6f229fc [NET] BRIDGE: Fix... |
98 |
} |
1da177e4c Linux-2.6.12-rc2 |
99 |
|
b86c45035 bridge: change wh... |
100 101 102 103 |
/* Events that may cause spanning tree to refresh */ if (event == NETDEV_CHANGEADDR || event == NETDEV_UP || event == NETDEV_CHANGE || event == NETDEV_DOWN) br_ifinfo_notify(RTM_NEWLINK, p); |
1da177e4c Linux-2.6.12-rc2 |
104 105 |
return NOTIFY_DONE; } |