Module Name: src
Committed By: yamaguchi
Date: Mon Apr 4 06:10:00 UTC 2022
Modified Files:
src/sys/net: if_ethersubr.c
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c if_laggproto.h
src/sys/rump/librump/rumpnet: net_stub.c
Removed Files:
src/sys/net/lagg: if_laggvar.h
Log Message:
Move input processing of lagg(4) before ether_input
to get rid of dependence.
This implementation is similar with that of bridge(4).
To generate a diff of this commit:
cvs rdiff -u -r1.310 -r1.311 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.45 -r1.46 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.22 -r1.23 src/sys/net/lagg/if_lagg_lacp.c
cvs rdiff -u -r1.15 -r1.16 src/sys/net/lagg/if_laggproto.h
cvs rdiff -u -r1.5 -r0 src/sys/net/lagg/if_laggvar.h
cvs rdiff -u -r1.48 -r1.49 src/sys/rump/librump/rumpnet/net_stub.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.310 src/sys/net/if_ethersubr.c:1.311
--- src/sys/net/if_ethersubr.c:1.310 Fri Dec 31 14:26:09 2021
+++ src/sys/net/if_ethersubr.c Mon Apr 4 06:10:00 2022
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: if_ethersubr
#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 @@ const uint8_t ethermulticastaddr_slowpro
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 @@ ether_input(struct ifnet *ifp, struct mb
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 @@ ether_input(struct ifnet *ifp, struct mb
}
#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 @@ ether_input(struct ifnet *ifp, struct mb
}
#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 @@ ether_input(struct ifnet *ifp, struct mb
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;
}
Index: src/sys/net/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.45 src/sys/net/lagg/if_lagg.c:1.46
--- src/sys/net/lagg/if_lagg.c:1.45 Fri Apr 1 07:26:51 2022
+++ src/sys/net/lagg/if_lagg.c Mon Apr 4 06:10:00 2022
@@ -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 <[email protected]>
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v
#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 const struct lagg_proto lagg_prot
};
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 @@ lagginit(void)
lagg_protos[i].pr_init();
}
- lagg_input_ethernet_p = lagg_input_ethernet;
if_clone_attach(&lagg_cloner);
}
@@ -351,7 +348,6 @@ laggdetach(void)
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 @@ lagg_proto_input(struct lagg_softc *sc,
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 @@ lagg_input_ethernet(struct ifnet *ifp_po
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 @@ lagg_input_ethernet(struct ifnet *ifp_po
* 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 @@ lagg_input_ethernet(struct ifnet *ifp_po
m_set_rcvif(m, ifp);
m->m_flags &= ~M_PROMISC;
if_input(ifp, m);
- m = NULL;
}
out:
lagg_port_putref(lp, &psref);
+ return;
- return m;
+drop:
+ lagg_port_putref(lp, &psref);
+ m_freem(m);
+ if_statinc(ifp_port, if_iqdrops);
+ return;
}
static int
@@ -2193,6 +2213,7 @@ lagg_port_setup(struct lagg_softc *sc,
/* 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 @@ lagg_port_setup(struct lagg_softc *sc,
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 @@ restore_sadl:
}
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 @@ lagg_port_teardown(struct lagg_softc *sc
(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;
Index: src/sys/net/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.22 src/sys/net/lagg/if_lagg_lacp.c:1.23
--- src/sys/net/lagg/if_lagg_lacp.c:1.22 Fri Apr 1 07:26:51 2022
+++ src/sys/net/lagg/if_lagg_lacp.c Mon Apr 4 06:10:00 2022
@@ -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 @@ lacp_pdu_input(struct lacp_softc *lsc, s
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));
if (m == NULL) {
@@ -1091,7 +1088,8 @@ lacp_marker_reply(struct lacp_softc *lsc
mdu = mtod(m_info, struct markerdu *);
mdu->mdu_tlv_info.tlv_type = MARKER_TYPE_RESPONSE;
- /* ether_dhost is already equals to multicast address */
+ /* ether_dhost is already ethermulticastaddr_slowprotocols */
+ m_info->m_flags |= M_MCAST;
memcpy(mdu->mdu_eh.ether_shost,
CLLADDR(ifp_port->if_sadl), ETHER_ADDR_LEN);
@@ -1178,9 +1176,6 @@ lacp_marker_input(struct lacp_softc *lsc
if (m->m_pkthdr.len != sizeof(*mdu))
goto bad;
- if ((m->m_flags & M_MCAST) == 0)
- goto bad;
-
if (m->m_len < (int)sizeof(*mdu)) {
m = m_pullup(m, sizeof(*mdu));
if (m == NULL) {
Index: src/sys/net/lagg/if_laggproto.h
diff -u src/sys/net/lagg/if_laggproto.h:1.15 src/sys/net/lagg/if_laggproto.h:1.16
--- src/sys/net/lagg/if_laggproto.h:1.15 Thu Mar 31 07:59:05 2022
+++ src/sys/net/lagg/if_laggproto.h Mon Apr 4 06:10:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: if_laggproto.h,v 1.15 2022/03/31 07:59:05 yamaguchi Exp $ */
+/* $NetBSD: if_laggproto.h,v 1.16 2022/04/04 06:10:00 yamaguchi Exp $ */
/*
* Copyright (c) 2021 Internet Initiative Japan Inc.
@@ -82,6 +82,7 @@ struct lagg_port {
uint64_t lp_mtu;
int (*lp_ioctl)(struct ifnet *, u_long, void *);
+ void (*lp_input)(struct ifnet *, struct mbuf *);
int (*lp_output)(struct ifnet *, struct mbuf *,
const struct sockaddr *,
const struct rtentry *);
Index: src/sys/rump/librump/rumpnet/net_stub.c
diff -u src/sys/rump/librump/rumpnet/net_stub.c:1.48 src/sys/rump/librump/rumpnet/net_stub.c:1.49
--- src/sys/rump/librump/rumpnet/net_stub.c:1.48 Thu Sep 30 04:13:42 2021
+++ src/sys/rump/librump/rumpnet/net_stub.c Mon Apr 4 06:10:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: net_stub.c,v 1.48 2021/09/30 04:13:42 yamaguchi Exp $ */
+/* $NetBSD: net_stub.c,v 1.49 2022/04/04 06:10:00 yamaguchi Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.48 2021/09/30 04:13:42 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.49 2022/04/04 06:10:00 yamaguchi Exp $");
#include <sys/mutex.h>
#include <sys/param.h>
@@ -104,10 +104,6 @@ __weak_alias(ipsec_pcbdisconn,rumpnet_st
__weak_alias(key_sa_routechange,rumpnet_stub);
__weak_alias(key_sp_unref,rumpnet_stub);
-/* lagg */
-__weak_alias(lagg_ifdetach,rumpnet_stub);
-__weak_alias(lagg_input_ethernet,rumpnet_stub);
-
/* altq */
int (*altq_input)(struct mbuf *, int);
__weak_alias(in6mask128,rumpnet_stub);