]> git.neil.brown.name Git - history.git/commitdiff
[BRIDGE]: linkstate handling
authorStephen Hemminger <shemminger@osdl.org>
Thu, 29 Jul 2004 07:40:24 +0000 (00:40 -0700)
committerDavid S. Miller <davem@nuts.davemloft.net>
Thu, 29 Jul 2004 07:40:24 +0000 (00:40 -0700)
This makes bridge port status reflect both the state of the interface
from software (up/down) and the carrier.  It makes STP handle link failure
(cable breakage, etc).  The original concept comes from a
Mark Ruijter <bridge@siennax.com> who implemented it differently.
My way is simpler and requires no polling.

Obviously, this link state detection will only work if the network card
handles the events properly.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: David S. Miller <davem@redhat.com>
net/bridge/br_if.c
net/bridge/br_notify.c
net/bridge/br_stp_if.c

index b81dee96015cae6bf3417d49df37d598250b9fae..588ead0731b0fd5eeba3806cc4baf62d7bc24158 100644 (file)
@@ -344,7 +344,8 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
 
                spin_lock_bh(&br->lock);
                br_stp_recalculate_bridge_id(br);
-               if ((br->dev->flags & IFF_UP) && (dev->flags & IFF_UP))
+               if ((br->dev->flags & IFF_UP) 
+                   && (dev->flags & IFF_UP) && netif_carrier_ok(dev))
                        br_stp_enable_port(p);
                spin_unlock_bh(&br->lock);
 
index dbc86ecbd244c1b66f726caa8fc97505708fea2a..70dc21f0c5ec5020ce0be5031927067b3383c0e7 100644 (file)
 
 static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr);
 
-struct notifier_block br_device_notifier =
-{
+struct notifier_block br_device_notifier = {
        .notifier_call = br_device_event
 };
 
 static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
 {
-       struct net_device *dev;
-       struct net_bridge_port *p;
+       struct net_device *dev = ptr;
+       struct net_bridge_port *p = dev->br_port;
        struct net_bridge *br;
 
-       dev = ptr;
-       p = dev->br_port;
-
        if (p == NULL)
                return NOTIFY_DONE;
 
        br = p->br;
+       if ( !(br->dev->flags & IFF_UP))
+               return NOTIFY_DONE;
+
+       if (event == NETDEV_CHANGEMTU) {
+               dev_set_mtu(br->dev, br_min_mtu(br));
+               return NOTIFY_DONE;
+       }
 
+       spin_lock_bh(&br->lock);
        switch (event) {
        case NETDEV_CHANGEADDR:
-               spin_lock_bh(&br->lock);
                br_fdb_changeaddr(p, dev->dev_addr);
-               if (br->dev->flags & IFF_UP)
-                       br_stp_recalculate_bridge_id(br);
-               spin_unlock_bh(&br->lock);
+               br_stp_recalculate_bridge_id(br);
                break;
 
-       case NETDEV_CHANGEMTU:
-               dev_set_mtu(br->dev, br_min_mtu(br));
+       case NETDEV_CHANGE:     /* device is up but carrier changed */
+               if (netif_carrier_ok(dev)) {
+                       if (p->state == BR_STATE_DISABLED)
+                               br_stp_enable_port(p);
+               } else {
+                       if (p->state != BR_STATE_DISABLED)
+                               br_stp_disable_port(p);
+               }
                break;
 
        case NETDEV_DOWN:
-               if (br->dev->flags & IFF_UP) {
-                       spin_lock_bh(&br->lock);
-                       br_stp_disable_port(p);
-                       spin_unlock_bh(&br->lock);
-               }
+               br_stp_disable_port(p);
                break;
 
        case NETDEV_UP:
-               if (br->dev->flags & IFF_UP) {
-                       spin_lock_bh(&br->lock);
+               if (netif_carrier_ok(dev)) 
                        br_stp_enable_port(p);
-                       spin_unlock_bh(&br->lock);
-               }
                break;
 
        case NETDEV_UNREGISTER:
                br_del_if(br, dev);
                break;
-       }
+       } 
+       spin_unlock_bh(&br->lock);
 
        return NOTIFY_DONE;
 }
index 9e1d296b6e95b49127a4ae1b98a57ce8a19ec2b1..6c08fefcc75d5541ddb07095e61b44f1cf330916 100644 (file)
@@ -52,7 +52,7 @@ void br_stp_enable_bridge(struct net_bridge *br)
        br_config_bpdu_generation(br);
 
        list_for_each_entry(p, &br->port_list, list) {
-               if (p->dev->flags & IFF_UP)
+               if ((p->dev->flags & IFF_UP) && netif_carrier_ok(p->dev))
                        br_stp_enable_port(p);
 
        }