Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net bridge: Calculate link state as the best link state ...



details:   https://anonhg.NetBSD.org/src/rev/8ca46b838a19
branches:  trunk
changeset: 944347:8ca46b838a19
user:      roy <roy%NetBSD.org@localhost>
date:      Sun Sep 27 00:32:17 2020 +0000

description:
bridge: Calculate link state as the best link state of any member

If any member is LINK_STATE_UP then it's LINK_STATE_UP.
Otherwise if any member is LINK_STATE_UNKNOWN then it's LINK_STATE_UNKNOWN.
Otherwise it's LINK_STATE_DOWN.

diffstat:

 sys/net/if.c           |   9 +++++++--
 sys/net/if_bridge.c    |  43 +++++++++++++++++++++++++++++++++++++++----
 sys/net/if_bridgevar.h |   3 ++-
 3 files changed, 48 insertions(+), 7 deletions(-)

diffs (140 lines):

diff -r 3e4f8d8ffe15 -r 8ca46b838a19 sys/net/if.c
--- a/sys/net/if.c      Sun Sep 27 00:31:51 2020 +0000
+++ b/sys/net/if.c      Sun Sep 27 00:32:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.481 2020/09/26 18:35:12 roy Exp $     */
+/*     $NetBSD: if.c,v 1.482 2020/09/27 00:32:17 roy Exp $     */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.481 2020/09/26 18:35:12 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.482 2020/09/27 00:32:17 roy Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2420,6 +2420,11 @@
        if (ifp->if_link_state_changed != NULL)
                ifp->if_link_state_changed(ifp, link_state);
 
+#if NBRIDGE > 0
+       if (ifp->if_bridge != NULL)
+               bridge_calc_link_state(ifp->if_bridge);
+#endif
+
        DOMAIN_FOREACH(dp) {
                if (dp->dom_if_link_state_change != NULL)
                        dp->dom_if_link_state_change(ifp, link_state);
diff -r 3e4f8d8ffe15 -r 8ca46b838a19 sys/net/if_bridge.c
--- a/sys/net/if_bridge.c       Sun Sep 27 00:31:51 2020 +0000
+++ b/sys/net/if_bridge.c       Sun Sep 27 00:32:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_bridge.c,v 1.174 2020/08/01 06:50:43 maxv Exp $     */
+/*     $NetBSD: if_bridge.c,v 1.175 2020/09/27 00:32:17 roy Exp $      */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.174 2020/08/01 06:50:43 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.175 2020/09/27 00:32:17 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -438,9 +438,8 @@
 
        if_initname(ifp, ifc->ifc_name, unit);
        ifp->if_softc = sc;
-       ifp->if_extflags = IFEF_NO_LINK_STATE_CHANGE;
 #ifdef NET_MPSAFE
-       ifp->if_extflags |= IFEF_MPSAFE;
+       ifp->if_extflags = IFEF_MPSAFE;
 #endif
        ifp->if_mtu = ETHERMTU;
        ifp->if_ioctl = bridge_ioctl;
@@ -465,6 +464,14 @@
 
                return error;
        }
+
+       /*
+        * Set the link state to down.
+        * When interfaces are added the link state will reflect
+        * the best link state of the combined interfaces.
+        */
+       ifp->if_link_state = LINK_STATE_DOWN;
+
        if_alloc_sadl(ifp);
        if_register(ifp);
 
@@ -796,6 +803,32 @@
        BRIDGE_UNLOCK(sc);
 }
 
+/*
+ * bridge_calc_link_state:
+ *
+ *     Calculate the link state based on each member interface.
+ */
+void
+bridge_calc_link_state(struct bridge_softc *sc)
+{
+       struct bridge_iflist *bif;
+       struct ifnet *ifs;
+       int link_state = LINK_STATE_DOWN;
+
+       BRIDGE_LOCK(sc);
+       BRIDGE_IFLIST_READER_FOREACH(bif, sc) {
+               ifs = bif->bif_ifp;
+               if (ifs->if_link_state == LINK_STATE_UP) {
+                       link_state = LINK_STATE_UP;
+                       break;
+               }
+               if (ifs->if_link_state == LINK_STATE_UNKNOWN)
+                       link_state = LINK_STATE_UNKNOWN;
+       }
+       if_link_state_change(&sc->sc_if, link_state);
+       BRIDGE_UNLOCK(sc);
+}
+
 static int
 bridge_ioctl_add(struct bridge_softc *sc, void *arg)
 {
@@ -881,6 +914,7 @@
        BRIDGE_UNLOCK(sc);
 
        bridge_calc_csum_flags(sc);
+       bridge_calc_link_state(sc);
 
        if (sc->sc_if.if_flags & IFF_RUNNING)
                bstp_initialization(sc);
@@ -927,6 +961,7 @@
 
        bridge_rtdelete(sc, ifs);
        bridge_calc_csum_flags(sc);
+       bridge_calc_link_state(sc);
 
        if (sc->sc_if.if_flags & IFF_RUNNING)
                bstp_initialization(sc);
diff -r 3e4f8d8ffe15 -r 8ca46b838a19 sys/net/if_bridgevar.h
--- a/sys/net/if_bridgevar.h    Sun Sep 27 00:31:51 2020 +0000
+++ b/sys/net/if_bridgevar.h    Sun Sep 27 00:32:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_bridgevar.h,v 1.34 2020/04/30 13:59:50 jdolecek Exp $       */
+/*     $NetBSD: if_bridgevar.h,v 1.35 2020/09/27 00:32:17 roy Exp $    */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -346,6 +346,7 @@
            int);
 
 void   bridge_calc_csum_flags(struct bridge_softc *);
+void   bridge_calc_link_state(struct bridge_softc *);
 
 #define BRIDGE_LOCK(_sc)       mutex_enter(&(_sc)->sc_iflist_psref.bip_lock)
 #define BRIDGE_UNLOCK(_sc)     mutex_exit(&(_sc)->sc_iflist_psref.bip_lock)



Home | Main Index | Thread Index | Old Index