Source-Changes-HG archive

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

[src/trunk]: src/sys/net/lagg lagg(4): reimplement add and delete port



details:   https://anonhg.NetBSD.org/src/rev/dcfdf2b1c5d3
branches:  trunk
changeset: 364624:dcfdf2b1c5d3
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Fri Apr 01 07:26:51 2022 +0000

description:
lagg(4): reimplement add and delete port

The IFNET_LOCK for the adding or deleting port became to
be held the whole time while the ifnet of the port is changed.

diffstat:

 sys/net/lagg/if_lagg.c      |  541 ++++++++++++++++++-------------------------
 sys/net/lagg/if_lagg_lacp.c |   13 +-
 2 files changed, 227 insertions(+), 327 deletions(-)

diffs (truncated from 869 to 300 lines):

diff -r 63d2d0cbd491 -r dcfdf2b1c5d3 sys/net/lagg/if_lagg.c
--- a/sys/net/lagg/if_lagg.c    Fri Apr 01 06:51:12 2022 +0000
+++ b/sys/net/lagg/if_lagg.c    Fri Apr 01 07:26:51 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_lagg.c,v 1.44 2022/03/31 07:59:05 yamaguchi Exp $   */
+/*     $NetBSD: if_lagg.c,v 1.45 2022/04/01 07:26:51 yamaguchi Exp $   */
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter <reyk%openbsd.org@localhost>
@@ -20,7 +20,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.44 2022/03/31 07:59:05 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.45 2022/04/01 07:26:51 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -133,7 +133,7 @@
        },
 };
 
-static int     lagg_chg_sadl(struct ifnet *, uint8_t *, size_t);
+static int     lagg_chg_sadl(struct ifnet *, const uint8_t *, size_t);
 static struct mbuf *
                lagg_input_ethernet(struct ifnet *, struct mbuf *);
 static int     lagg_clone_create(struct if_clone *, int);
@@ -195,10 +195,10 @@
                    bool);
 static void    lagg_port_syncvlan(struct lagg_softc *, struct lagg_port *);
 static void    lagg_port_purgevlan(struct lagg_softc *, struct lagg_port *);
-static void    lagg_lladdr_update(struct lagg_softc *);
 static void    lagg_capabilities_update(struct lagg_softc *);
 static void    lagg_sync_ifcaps(struct lagg_softc *);
 static void    lagg_sync_ethcaps(struct lagg_softc *);
+static void    lagg_sync_sadl(struct lagg_softc *);
 
 static struct if_clone  lagg_cloner =
     IF_CLONE_INITIALIZER("lagg", lagg_clone_create, lagg_clone_destroy);
@@ -212,11 +212,13 @@
                 lagg_iftype = LAGG_IF_TYPE_ETHERNET;
 
 #ifdef LAGG_DEBUG
+#define __LAGGDEBUGUSED
 #define LAGG_DPRINTF(_sc, _fmt, _args...)      do {    \
        printf("%s: " _fmt, (_sc) != NULL ?             \
        (_sc)->sc_if.if_xname : "lagg", ##_args);               \
 } while (0)
 #else
+#define __LAGGDEBUGUSED                                __unused
 #define LAGG_DPRINTF(_sc, _fmt, _args...)      __nothing
 #endif
 
@@ -413,7 +415,7 @@
                sc->sc_lladdr_rand[0] |= 0x02; /* set G/L bit */
                lagg_lladdr_cpy(sc->sc_lladdr, sc->sc_lladdr_rand);
                ether_set_vlan_cb((struct ethercom *)ifp, lagg_vlan_cb);
-               ether_ifattach(ifp, sc->sc_lladdr);
+               ether_ifattach(ifp, sc->sc_lladdr_rand);
                break;
        default:
                panic("unknown if type");
@@ -500,7 +502,7 @@
        if (ISSET(ifp->if_flags, IFF_RUNNING))
                lagg_stop_locked(sc);
 
-       lagg_lladdr_update(sc);
+       lagg_sync_sadl(sc);
 
        SET(ifp->if_flags, IFF_RUNNING);
 
@@ -2009,85 +2011,42 @@
 }
 
 static int
-lagg_setup_mtu(struct lagg_softc *sc, struct lagg_port *lp)
+lagg_setmtu(struct ifnet *ifp, uint64_t mtu)
 {
-       struct ifnet *ifp, *ifp_port;
+       struct lagg_softc *sc __LAGGDEBUGUSED;
+       struct lagg_port *lp;
        struct ifreq ifr;
        int error;
 
-       ifp = &sc->sc_if;
-       ifp_port = lp->lp_ifp;
-
-       KASSERT(IFNET_LOCKED(ifp_port));
-
-       error = 0;
+       KASSERT(IFNET_LOCKED(ifp));
+
        memset(&ifr, 0, sizeof(ifr));
-
-       if (SIMPLEQ_EMPTY(&sc->sc_ports)) {
-               ifr.ifr_mtu = lp->lp_mtu;
-
-               if (ifp->if_mtu != (uint64_t)ifr.ifr_mtu) {
-                       KASSERT(IFNET_LOCKED(ifp));
-                       error = ether_ioctl(ifp, SIOCSIFMTU, &ifr);
-               }
+       ifr.ifr_mtu = mtu;
+       lp = ifp->if_lagg;
+
+       if (lp != NULL) {
+               /* ioctl for port interface */
+               error = lp->lp_ioctl(ifp, SIOCSIFMTU, &ifr);
+               sc = lp->lp_softc;
        } else {
-               ifr.ifr_mtu = sc->sc_if.if_mtu;
-
-               if (lp->lp_mtu != (uint64_t)ifr.ifr_mtu) {
-                       if (lp->lp_ioctl == NULL) {
-                               LAGG_DPRINTF(sc,
-                                   "cannot change MTU for %s\n",
-                                   ifp_port->if_xname);
-                               return EINVAL;
-                       }
-
-                       strlcpy(ifr.ifr_name, ifp_port->if_xname,
-                           sizeof(ifr.ifr_name));
-                       error = lp->lp_ioctl(ifp_port,
-                           SIOCSIFMTU, (void *)&ifr);
-                       if (error != 0) {
-                               LAGG_DPRINTF(sc,
-                                   "invalid MTU %d for %s\n",
-                                   ifr.ifr_mtu, ifp_port->if_xname);
-                       }
-               }
+               /* ioctl for lagg interface */
+               error = ether_ioctl(ifp, SIOCSIFMTU, &ifr);
+               sc = ifp->if_softc;
+       }
+
+       if (error != 0) {
+               LAGG_DPRINTF(sc,
+                   "couldn't change MTU for %s\n",
+                   ifp->if_xname);
        }
 
        return error;
 }
 
 static void
-lagg_teardown_mtu(struct lagg_softc *sc, struct lagg_port *lp)
+lagg_port_setsadl(struct lagg_port *lp, const uint8_t *lladdr)
 {
        struct ifnet *ifp_port;
-       struct ifreq ifr;
-       int error;
-
-       if (lp->lp_ioctl == NULL)
-               return;
-
-       ifp_port = lp->lp_ifp;
-       KASSERT(IFNET_LOCKED(ifp_port));
-
-       if (ifp_port->if_mtu != lp->lp_mtu) {
-               memset(&ifr, 0, sizeof(ifr));
-               strlcpy(ifr.ifr_name, ifp_port->if_xname, sizeof(ifr.ifr_name));
-               ifr.ifr_mtu = lp->lp_mtu;
-               error = lp->lp_ioctl(ifp_port, SIOCSIFMTU, (void *)&ifr);
-               if (error != 0) {
-                       LAGG_LOG(sc, LOG_WARNING,
-                           "failed to reset MTU %d to %s\n",
-                           ifr.ifr_mtu, ifp_port->if_xname);
-               }
-       }
-}
-
-static void
-lagg_port_setsadl(struct lagg_port *lp, uint8_t *lladdr,
-    bool iftype_changed)
-{
-       struct ifnet *ifp_port;
-       bool lladdr_changed;
        int error;
 
        ifp_port = lp->lp_ifp;
@@ -2097,12 +2056,12 @@
 
        switch (lp->lp_iftype) {
        case IFT_ETHER:
-               lladdr_changed = lagg_lladdr_equal(lladdr,
-                   CLLADDR(ifp_port->if_sadl)) ? false : true;
-
-               if (lladdr_changed == false &&
-                   iftype_changed == false) {
-                       break;
+               if (lladdr == NULL) {
+                       lladdr = lp->lp_lladdr;
+               } else {
+                       if (lagg_lladdr_equal(lladdr,
+                           CLLADDR(ifp_port->if_sadl)))
+                               break;
                }
 
                lagg_chg_sadl(ifp_port,
@@ -2118,11 +2077,6 @@
                                    "%s failed to if_init() on %d\n",
                                    ifp_port->if_xname, error);
                        }
-               } else {
-                       if (lp->lp_promisc == false) {
-                               ifpromisc_locked(ifp_port, 1);
-                               lp->lp_promisc = true;
-                       }
                }
                break;
        default:
@@ -2132,157 +2086,65 @@
 }
 
 static void
-lagg_port_unsetsadl(struct lagg_port *lp)
+lagg_if_setsadl(struct lagg_softc *sc, uint8_t *lladdr)
 {
-       struct ifnet *ifp_port;
-       int error;
-
-       ifp_port = lp->lp_ifp;
-
-       KASSERT(LAGG_LOCKED(lp->lp_softc));
-       KASSERT(IFNET_LOCKED(ifp_port));
-
-       switch (lp->lp_iftype) {
-       case IFT_ETHER:
-               /* reset if_type before changing ifp->if_sadl */
-               ifp_port->if_type = lp->lp_iftype;
-
-               lagg_chg_sadl(ifp_port,
-                   lp->lp_lladdr, ETHER_ADDR_LEN);
-
-               if (ifp_port->if_init != NULL) {
-                       error = 0;
-                       if (ISSET(ifp_port->if_flags, IFF_RUNNING))
-                               error = if_init(ifp_port);
-
-                       if (error != 0) {
-                               LAGG_LOG(lp->lp_softc, LOG_WARNING,
-                                   "%s failed to if_init() on %d\n",
-                                   ifp_port->if_xname, error);
-                       }
-               } else {
-                       if (lp->lp_promisc == true) {
-                               ifpromisc_locked(ifp_port, 0);
-                               lp->lp_promisc = false;
-                       }
-               }
-               break;
-
-       default:
-               /* reset if_type before if_alloc_sadl */
-               ifp_port->if_type = lp->lp_iftype;
-               if_alloc_sadl(ifp_port);
-               break;
-       }
-}
-
-static void
-lagg_setup_lladdr(struct lagg_softc *sc, struct lagg_port *lp)
-{
-
-       KASSERT(LAGG_LOCKED(sc));
-
-       if (lagg_lladdr_equal(sc->sc_lladdr, sc->sc_lladdr_rand))
-               lagg_lladdr_cpy(sc->sc_lladdr, lp->lp_lladdr);
-}
-
-static void
-lagg_teardown_lladdr(struct lagg_softc *sc, struct lagg_port *lp)
-{
-       struct lagg_port *lp0;
-       uint8_t *lladdr_next;
+       struct ifnet *ifp;
 
        KASSERT(LAGG_LOCKED(sc));
 
-       if (lagg_lladdr_equal(sc->sc_lladdr,
-           lp->lp_lladdr) == false) {
-               return;
-       }
-
-       lladdr_next = sc->sc_lladdr_rand;
-
-       LAGG_PORTS_FOREACH(sc, lp0) {
-               if (lp0->lp_iftype == IFT_ETHER) {
-                       lladdr_next = lp0->lp_lladdr;
-                       break;
-               }
-       }
-
-       lagg_lladdr_cpy(sc->sc_lladdr, lladdr_next);
-}
-
-static void
-lagg_lladdr_update(struct lagg_softc *sc)
-{
-       struct ifnet *ifp;
-       struct lagg_port *lp;



Home | Main Index | Thread Index | Old Index