Source-Changes-HG archive

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

[src/trunk]: src/sys/net/lagg Use ether_ioctl to change mtu of lagg(4)



details:   https://anonhg.NetBSD.org/src/rev/a1f9dd59bca7
branches:  trunk
changeset: 364607:a1f9dd59bca7
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Thu Mar 31 03:21:33 2022 +0000

description:
Use ether_ioctl to change mtu of lagg(4)

diffstat:

 sys/net/lagg/if_lagg.c |  68 +++++++++++++++++++++++++++----------------------
 1 files changed, 38 insertions(+), 30 deletions(-)

diffs (140 lines):

diff -r df8cc892e980 -r a1f9dd59bca7 sys/net/lagg/if_lagg.c
--- a/sys/net/lagg/if_lagg.c    Thu Mar 31 03:15:15 2022 +0000
+++ b/sys/net/lagg/if_lagg.c    Thu Mar 31 03:21:33 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_lagg.c,v 1.42 2022/03/31 03:15:15 yamaguchi Exp $   */
+/*     $NetBSD: if_lagg.c,v 1.43 2022/03/31 03:21:33 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.42 2022/03/31 03:15:15 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.43 2022/03/31 03:21:33 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -730,6 +730,7 @@
                break;
        case SIOCSIFMTU:
                LAGG_LOCK(sc);
+               /* set the MTU to each port */
                LAGG_PORTS_FOREACH(sc, lp) {
                        error = lagg_lp_ioctl(lp, cmd, (void *)ifr);
 
@@ -744,10 +745,12 @@
                        }
                }
 
-               if (error == 0) {
-                       ifp->if_mtu = ifr->ifr_mtu;
-               } else {
-                       /* set every port back to the original MTU */
+               /* set the MTU to the lagg interface */
+               if (error == 0)
+                       error = ether_ioctl(ifp, cmd, data);
+
+               if (error != 0) {
+                       /* undo the changed MTU */
                        ifr->ifr_mtu = ifp->if_mtu;
                        LAGG_PORTS_FOREACH(sc, lp) {
                                if (lp->lp_ioctl != NULL)
@@ -2008,11 +2011,13 @@
 static int
 lagg_setup_mtu(struct lagg_softc *sc, struct lagg_port *lp)
 {
-       struct ifnet *ifp_port;
+       struct ifnet *ifp, *ifp_port;
        struct ifreq ifr;
        int error;
 
+       ifp = &sc->sc_if;
        ifp_port = lp->lp_ifp;
+
        KASSERT(IFNET_LOCKED(ifp_port));
 
        error = 0;
@@ -2020,30 +2025,35 @@
 
        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);
+               }
        } else {
                ifr.ifr_mtu = sc->sc_if.if_mtu;
-       }
-
-       if (sc->sc_if.if_mtu != (uint64_t)ifr.ifr_mtu)
-               sc->sc_if.if_mtu = ifr.ifr_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);
-                       return error;
+
+               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);
+                       }
                }
        }
 
-       return 0;
+       return error;
 }
 
 static void
@@ -2059,9 +2069,6 @@
        ifp_port = lp->lp_ifp;
        KASSERT(IFNET_LOCKED(ifp_port));
 
-       if (SIMPLEQ_EMPTY(&sc->sc_ports))
-               sc->sc_if.if_mtu = 0;
-
        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));
@@ -2338,6 +2345,8 @@
        /* to delete ipv6 link local address */
        lagg_in6_ifdetach(ifp_port);
 
+       lagg_capabilities_update(sc);
+
        error = lagg_setup_mtu(sc, lp);
        if (error != 0)
                goto restore_ipv6lla;
@@ -2373,7 +2382,6 @@
 
        lagg_config_promisc(sc, lp);
        lagg_proto_startport(sc, lp);
-       lagg_capabilities_update(sc);
 
        return 0;
 



Home | Main Index | Thread Index | Old Index