Source-Changes-HG archive

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

[src/trunk]: src/sys/net/lagg added log when ifpromisc is failed



details:   https://anonhg.NetBSD.org/src/rev/487693932454
branches:  trunk
changeset: 364604:487693932454
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Thu Mar 31 03:10:59 2022 +0000

description:
added log when ifpromisc is failed

diffstat:

 sys/net/lagg/if_lagg.c      |  81 +++++++++++++++++++++++++++-----------------
 sys/net/lagg/if_laggproto.h |   3 +-
 2 files changed, 50 insertions(+), 34 deletions(-)

diffs (153 lines):

diff -r 183725b3794e -r 487693932454 sys/net/lagg/if_lagg.c
--- a/sys/net/lagg/if_lagg.c    Thu Mar 31 03:09:03 2022 +0000
+++ b/sys/net/lagg/if_lagg.c    Thu Mar 31 03:10:59 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_lagg.c,v 1.39 2022/03/31 03:07:05 yamaguchi Exp $   */
+/*     $NetBSD: if_lagg.c,v 1.40 2022/03/31 03:10:59 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.39 2022/03/31 03:07:05 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.40 2022/03/31 03:10:59 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -181,7 +181,7 @@
 static int     lagg_port_ioctl(struct ifnet *, u_long, void *);
 static int     lagg_port_output(struct ifnet *, struct mbuf *,
                    const struct sockaddr *, const struct rtentry *);
-static int     lagg_config_promisc(struct lagg_softc *, struct lagg_port *);
+static void    lagg_config_promisc(struct lagg_softc *, struct lagg_port *);
 static void    lagg_unconfig_promisc(struct lagg_softc *, struct lagg_port *);
 static struct lagg_variant *
                lagg_variant_getref(struct lagg_softc *, struct psref *);
@@ -2130,10 +2130,6 @@
                break;
        default:
                if_alloc_sadl(ifp_port);
-               if (lp->lp_promisc == false) {
-                       ifpromisc_locked(ifp_port, 1);
-                       lp->lp_promisc = true;
-               }
                break;
        }
 }
@@ -2179,11 +2175,6 @@
                /* reset if_type before if_alloc_sadl */
                ifp_port->if_type = lp->lp_iftype;
                if_alloc_sadl(ifp_port);
-
-               if (lp->lp_promisc == true) {
-                       ifpromisc_locked(ifp_port, 0);
-                       lp->lp_promisc = false;
-               }
                break;
        }
 }
@@ -2647,39 +2638,65 @@
        return 0;
 }
 
-static int
+static void
 lagg_config_promisc(struct lagg_softc *sc, struct lagg_port *lp)
 {
-       struct ifnet *ifp;
-       uint64_t chg_flags;
+       struct ifnet *ifp, *ifp_port;
        int error;
-
-       error = 0;
+       bool promisc;
+
+       KASSERT(LAGG_LOCKED(sc));
+
        ifp = &sc->sc_if;
-       chg_flags = ifp->if_flags ^ lp->lp_ifflags;
-
-       if (ISSET(chg_flags, IFF_PROMISC)) {
-               error = ifpromisc(lp->lp_ifp,
-                   ISSET(ifp->if_flags, IFF_PROMISC) ? 1 : 0);
-               if (error == 0) {
-                       lp->lp_ifflags ^= IFF_PROMISC;
-               }
+       ifp_port = lp->lp_ifp;
+
+       if (lp->lp_iftype == IFT_ETHER) {
+               promisc = ISSET(ifp->if_flags, IFF_PROMISC) ?
+                   true : false;
+       } else {
+               promisc = true;
        }
 
-       return error;
+       if (lp->lp_promisc == promisc)
+               return;
+
+       error = ifpromisc(ifp_port, promisc ? 1 : 0);
+       if (error == ENETRESET) {
+               error = ifp_port->if_init(ifp_port);
+       }
+
+       if (error == 0) {
+               lp->lp_promisc = promisc;
+       } else {
+               lagg_log(sc, LOG_WARNING,
+                   "couldn't %s promisc on %s\n",
+                   promisc ? "set" : "unset",
+                   ifp_port->if_xname);
+       }
 }
 
 static void
 lagg_unconfig_promisc(struct lagg_softc *sc, struct lagg_port *lp)
 {
+       struct ifnet *ifp_port;
        int error;
 
-       if (ISSET(lp->lp_ifflags, IFF_PROMISC)) {
-               error = ifpromisc(lp->lp_ifp, 0);
-               if (error != 0) {
-                       lagg_log(sc, LOG_DEBUG,
-                           "couldn't unset promiscuous mode");
-               }
+       KASSERT(LAGG_LOCKED(sc));
+
+       ifp_port = lp->lp_ifp;
+
+       if (lp->lp_promisc == false)
+               return;
+
+       error = ifpromisc(ifp_port, 0);
+       if (error == ENETRESET) {
+               error = ifp_port->if_init(ifp_port);
+       }
+
+       if (error != 0) {
+               lagg_log(sc, LOG_WARNING,
+                   "couldn't unset promisc on %s\n",
+                   ifp_port->if_xname);
        }
 }
 
diff -r 183725b3794e -r 487693932454 sys/net/lagg/if_laggproto.h
--- a/sys/net/lagg/if_laggproto.h       Thu Mar 31 03:09:03 2022 +0000
+++ b/sys/net/lagg/if_laggproto.h       Thu Mar 31 03:10:59 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_laggproto.h,v 1.11 2022/03/31 02:00:27 yamaguchi Exp $      */
+/*     $NetBSD: if_laggproto.h,v 1.12 2022/03/31 03:10:59 yamaguchi Exp $      */
 
 /*
  * Copyright (c) 2021 Internet Initiative Japan Inc.
@@ -77,7 +77,6 @@
 
        u_char                   lp_iftype;
        uint8_t                  lp_lladdr[ETHER_ADDR_LEN];
-       unsigned short           lp_ifflags;
        int                      lp_eccapenable;
        uint64_t                 lp_ifcapenable;
        uint64_t                 lp_mtu;



Home | Main Index | Thread Index | Old Index