Source-Changes-HG archive

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

[src/trunk]: src/sys Move input processing of lagg(4) before ether_input



details:   https://anonhg.NetBSD.org/src/rev/6463e025e48d
branches:  trunk
changeset: 364662:6463e025e48d
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Mon Apr 04 06:10:00 2022 +0000

description:
Move input processing of lagg(4) before ether_input
to get rid of dependence.

This implementation is similar with that of bridge(4).

diffstat:

 sys/net/if_ethersubr.c              |  31 ++--------------
 sys/net/lagg/if_lagg.c              |  68 +++++++++++++++++++++++++-----------
 sys/net/lagg/if_lagg_lacp.c         |  13 ++----
 sys/net/lagg/if_laggproto.h         |   3 +-
 sys/net/lagg/if_laggvar.h           |  36 -------------------
 sys/rump/librump/rumpnet/net_stub.c |   8 +---
 6 files changed, 59 insertions(+), 100 deletions(-)

diffs (truncated from 407 to 300 lines):

diff -r 5d33eee3e277 -r 6463e025e48d sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Sun Apr 03 14:17:53 2022 +0000
+++ b/sys/net/if_ethersubr.c    Mon Apr 04 06:10:00 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.310 2021/12/31 14:26:09 riastradh Exp $     */
+/*     $NetBSD: if_ethersubr.c,v 1.311 2022/04/04 06:10:00 yamaguchi Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.310 2021/12/31 14:26:09 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.311 2022/04/04 06:10:00 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -125,8 +125,6 @@
 #include <net/agr/if_agrvar.h>
 #endif
 
-#include <net/lagg/if_laggvar.h>
-
 #if NBRIDGE > 0
 #include <net/if_bridgevar.h>
 #endif
@@ -185,9 +183,6 @@
 
 static pktq_rps_hash_func_t ether_pktq_rps_hash_p;
 
-/* if_lagg(4) support */
-struct mbuf *(*lagg_input_ethernet_p)(struct ifnet *, struct mbuf *);
-
 static int ether_output(struct ifnet *, struct mbuf *,
     const struct sockaddr *, const struct rtentry *);
 
@@ -657,9 +652,6 @@
        size_t ehlen;
        static int earlypkts;
        int isr = 0;
-#if NAGR > 0
-       void *agrprivate;
-#endif
 
        KASSERT(!cpu_intr_p());
        KASSERT((m->m_flags & M_PKTHDR) != 0);
@@ -764,12 +756,7 @@
        }
 
 #if NAGR > 0
-       if (ifp->if_type != IFT_IEEE8023ADLAG) {
-               agrprivate = ifp->if_lagg;
-       } else {
-               agrprivate = NULL;
-       }
-       if (agrprivate != NULL &&
+       if (ifp->if_lagg != NULL &&
            __predict_true(etype != ETHERTYPE_SLOWPROTOCOLS)) {
                m->m_flags &= ~M_PROMISC;
                agr_input(ifp, m);
@@ -777,14 +764,6 @@
        }
 #endif
 
-       /* Handle input from a lagg(4) port */
-       if (ifp->if_type == IFT_IEEE8023ADLAG) {
-               KASSERT(lagg_input_ethernet_p != NULL);
-               m = (*lagg_input_ethernet_p)(ifp, m);
-               if (m == NULL)
-                       return;
-       }
-
        /*
         * If VLANs are configured on the interface, check to
         * see if the device performed the decapsulation and
@@ -859,14 +838,14 @@
                switch (subtype) {
 #if NAGR > 0
                case SLOWPROTOCOLS_SUBTYPE_LACP:
-                       if (agrprivate != NULL) {
+                       if (ifp->if_lagg != NULL) {
                                ieee8023ad_lacp_input(ifp, m);
                                return;
                        }
                        break;
 
                case SLOWPROTOCOLS_SUBTYPE_MARKER:
-                       if (agrprivate != NULL) {
+                       if (ifp->if_lagg != NULL) {
                                ieee8023ad_marker_input(ifp, m);
                                return;
                        }
diff -r 5d33eee3e277 -r 6463e025e48d sys/net/lagg/if_lagg.c
--- a/sys/net/lagg/if_lagg.c    Sun Apr 03 14:17:53 2022 +0000
+++ b/sys/net/lagg/if_lagg.c    Mon Apr 04 06:10:00 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_lagg.c,v 1.45 2022/04/01 07:26:51 yamaguchi Exp $   */
+/*     $NetBSD: if_lagg.c,v 1.46 2022/04/04 06:10:00 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.45 2022/04/01 07:26:51 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.46 2022/04/04 06:10:00 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -66,7 +66,6 @@
 #endif
 
 #include <net/lagg/if_lagg.h>
-#include <net/lagg/if_laggvar.h>
 #include <net/lagg/if_laggproto.h>
 
 #include "ioconf.h"
@@ -134,8 +133,7 @@
 };
 
 static int     lagg_chg_sadl(struct ifnet *, const uint8_t *, size_t);
-static struct mbuf *
-               lagg_input_ethernet(struct ifnet *, struct mbuf *);
+static void    lagg_input_ethernet(struct ifnet *, struct mbuf *);
 static int     lagg_clone_create(struct if_clone *, int);
 static int     lagg_clone_destroy(struct ifnet *);
 static int     lagg_init(struct ifnet *);
@@ -338,7 +336,6 @@
                        lagg_protos[i].pr_init();
        }
 
-       lagg_input_ethernet_p = lagg_input_ethernet;
        if_clone_attach(&lagg_cloner);
 }
 
@@ -351,7 +348,6 @@
                return EBUSY;
 
        if_clone_detach(&lagg_cloner);
-       lagg_input_ethernet_p = NULL;
 
        for (i = 0; i < LAGG_PROTO_MAX; i++) {
                if (lagg_protos[i].pr_fini != NULL)
@@ -1096,12 +1092,13 @@
        return m;
 }
 
-static struct mbuf *
+static void
 lagg_input_ethernet(struct ifnet *ifp_port, struct mbuf *m)
 {
        struct ifnet *ifp;
        struct psref psref;
        struct lagg_port *lp;
+       struct ether_header *eh;
        int s;
 
        /* sanity check */
@@ -1110,7 +1107,9 @@
        if (lp == NULL) {
                /* This interface is not a member of lagg */
                pserialize_read_exit(s);
-               return m;
+               m_freem(m);
+               if_statinc(ifp_port, if_ierrors);
+               return;
        }
        lagg_port_getref(lp, &psref);
        pserialize_read_exit(s);
@@ -1121,21 +1120,38 @@
         * Drop promiscuously received packets
         * if we are not in promiscuous mode.
         */
-       if ((m->m_flags & (M_BCAST | M_MCAST)) == 0 &&
-           (ifp_port->if_flags & IFF_PROMISC) != 0 &&
-           (ifp->if_flags & IFF_PROMISC) == 0) {
-               struct ether_header *eh;
-
-               eh = mtod(m, struct ether_header *);
-               if (memcmp(CLLADDR(ifp->if_sadl),
-                   eh->ether_dhost, ETHER_ADDR_LEN) != 0) {
-                       m_freem(m);
-                       m = NULL;
+
+       if (__predict_false(m->m_len < sizeof(*eh))) {
+               if ((m = m_pullup(m, sizeof(*eh))) == NULL) {
                        if_statinc(ifp, if_ierrors);
                        goto out;
                }
        }
 
+       eh = mtod(m, struct ether_header *);
+
+       if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
+               /*
+                * If this is not a simplex interface, drop the packet
+                * if it came from us.
+                */
+               if ((ifp->if_flags & IFF_SIMPLEX) == 0 &&
+                   memcmp(CLLADDR(ifp->if_sadl), eh->ether_shost,
+                   ETHER_ADDR_LEN) == 0) {
+                       goto drop;
+               }
+
+               if_statinc(ifp_port, if_imcasts);
+       } else {
+               if ((ifp->if_flags & IFF_PROMISC) == 0 &&
+                   (ifp_port->if_flags & IFF_PROMISC) != 0 &&
+                   memcmp(CLLADDR(ifp->if_sadl), eh->ether_dhost,
+                   ETHER_ADDR_LEN) != 0)
+                       goto drop;
+       }
+
+       if_statadd(ifp_port, if_ibytes, m->m_pkthdr.len);
+
        if (pfil_run_hooks(ifp_port->if_pfil, &m,
            ifp_port, PFIL_IN) != 0)
                goto out;
@@ -1145,13 +1161,17 @@
                m_set_rcvif(m, ifp);
                m->m_flags &= ~M_PROMISC;
                if_input(ifp, m);
-               m = NULL;
        }
 
 out:
        lagg_port_putref(lp, &psref);
-
-       return m;
+       return;
+
+drop:
+       lagg_port_putref(lp, &psref);
+       m_freem(m);
+       if_statinc(ifp_port, if_iqdrops);
+       return;
 }
 
 static int
@@ -2193,6 +2213,7 @@
        /* backup members */
        lp->lp_iftype = ifp_port->if_type;
        lp->lp_ioctl = ifp_port->if_ioctl;
+       lp->lp_input = ifp_port->_if_input;
        lp->lp_output = ifp_port->if_output;
        lp->lp_ifcapenable = ifp_port->if_capenable;
        lp->lp_mtu = ifp_port->if_mtu;
@@ -2208,6 +2229,7 @@
        atomic_store_release(&ifp_port->if_lagg, (void *)lp);
        ifp_port->if_type = if_type;
        ifp_port->if_ioctl = lagg_port_ioctl;
+       ifp_port->_if_input = lagg_input_ethernet;
        ifp_port->if_output = lagg_port_output;
        if (is_1st_port) {
                if (lp->lp_iftype != ifp_port->if_type)
@@ -2292,6 +2314,7 @@
        }
 
        ifp_port->if_ioctl = lp->lp_ioctl;
+       ifp_port->_if_input = lp->lp_input;
        ifp_port->if_output = lp->lp_output;
        atomic_store_release(&ifp_port->if_lagg, NULL);
        IFNET_UNLOCK(ifp_port);
@@ -2390,6 +2413,7 @@
                (void)lagg_setmtu(ifp_port, lp->lp_mtu);
        }
 
+       ifp_port->_if_input = lp->lp_input;
        ifp_port->if_output = lp->lp_output;
        if (ifp_port->if_ioctl == lagg_port_ioctl)
                ifp_port->if_ioctl = lp->lp_ioctl;
diff -r 5d33eee3e277 -r 6463e025e48d sys/net/lagg/if_lagg_lacp.c
--- a/sys/net/lagg/if_lagg_lacp.c       Sun Apr 03 14:17:53 2022 +0000
+++ b/sys/net/lagg/if_lagg_lacp.c       Mon Apr 04 06:10:00 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_lagg_lacp.c,v 1.22 2022/04/01 07:26:51 yamaguchi Exp $      */
+/*     $NetBSD: if_lagg_lacp.c,v 1.23 2022/04/04 06:10:00 yamaguchi Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.22 2022/04/01 07:26:51 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.23 2022/04/04 06:10:00 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -1012,9 +1012,6 @@
        if (m->m_pkthdr.len != sizeof(*du))
                goto bad;
 
-       if ((m->m_flags & M_MCAST) == 0)
-               goto bad;
-
        if (m->m_len < (int)sizeof(*du)) {
                m = m_pullup(m, sizeof(*du));



Home | Main Index | Thread Index | Old Index