Module Name:    src
Committed By:   yamaguchi
Date:           Thu Sep 30 03:15:25 UTC 2021

Modified Files:
        src/sys/net: if.c if.h if_ethersubr.c
        src/sys/net/agr: ieee8023ad_lacp.c ieee8023ad_marker.c if_agr.c

Log Message:
Replace ifnet::if_agriprivate with ifnet::if_lagg

agr(4) and lagg(4) can not be used on the same interface so that
if_agrprivate and if_lagg are not used at the same time.
For resolve this wasteful, if_lagg is used in not only lagg(4)
but also agr(4).

After this modification, if_lagg has 3 states:
1. if_lagg == NULL
   - Both agr(4) and lagg(4) are not running on the interface
2. if_lagg != NULL && ifp->if_type != IFT_IEEE8023ADLAG
   - agr(4) is running on the I/F
3. if_lagg != NULL && ifp->if_type == IFT_IEEE8023ADLAG
   - lagg(4) is running on the I/F


To generate a diff of this commit:
cvs rdiff -u -r1.490 -r1.491 src/sys/net/if.c
cvs rdiff -u -r1.292 -r1.293 src/sys/net/if.h
cvs rdiff -u -r1.293 -r1.294 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.11 -r1.12 src/sys/net/agr/ieee8023ad_lacp.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/agr/ieee8023ad_marker.c
cvs rdiff -u -r1.52 -r1.53 src/sys/net/agr/if_agr.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.c
diff -u src/sys/net/if.c:1.490 src/sys/net/if.c:1.491
--- src/sys/net/if.c:1.490	Tue Sep 21 14:57:26 2021
+++ src/sys/net/if.c	Thu Sep 30 03:15:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.490 2021/09/21 14:57:26 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.491 2021/09/30 03:15:25 yamaguchi Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.490 2021/09/21 14:57:26 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.491 2021/09/30 03:15:25 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2408,7 +2408,7 @@ if_link_state_change_process(struct ifne
 #endif
 
 #if NLAGG > 0
-	if (ifp->if_lagg != NULL)
+	if (ifp->if_type == IFT_IEEE8023ADLAG)
 		lagg_linkstate_changed(ifp);
 #endif
 

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.292 src/sys/net/if.h:1.293
--- src/sys/net/if.h:1.292	Mon Aug  9 20:49:10 2021
+++ src/sys/net/if.h	Thu Sep 30 03:15:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.292 2021/08/09 20:49:10 andvar Exp $	*/
+/*	$NetBSD: if.h,v 1.293 2021/09/30 03:15:25 yamaguchi Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -380,8 +380,7 @@ typedef struct ifnet {
 					/* a: */
 	struct mowner	*if_mowner;	/* ?: who owns mbufs for this interface */
 
-	void		*if_agrprivate;	/* ?: used only when #if NAGR > 0 */
-	void		*if_lagg;	/* ?: used only when #if NLAGG > 0 */
+	void		*if_lagg;	/* :: lagg or agr structure */
 	void		*if_npf_private;/* ?: associated NPF context */
 
 	/*

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.293 src/sys/net/if_ethersubr.c:1.294
--- src/sys/net/if_ethersubr.c:1.293	Mon May 17 04:07:43 2021
+++ src/sys/net/if_ethersubr.c	Thu Sep 30 03:15:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.293 2021/05/17 04:07:43 yamaguchi Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.294 2021/09/30 03:15:25 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.293 2021/05/17 04:07:43 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.294 2021/09/30 03:15:25 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -651,6 +651,9 @@ 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);
@@ -753,7 +756,12 @@ ether_input(struct ifnet *ifp, struct mb
 	}
 
 #if NAGR > 0
-	if (ifp->if_agrprivate &&
+	if (ifp->if_type != IFT_IEEE8023ADLAG) {
+		agrprivate = ifp->if_lagg;
+	} else {
+		agrprivate = NULL;
+	}
+	if (agrprivate != NULL &&
 	    __predict_true(etype != ETHERTYPE_SLOWPROTOCOLS)) {
 		m->m_flags &= ~M_PROMISC;
 		agr_input(ifp, m);
@@ -843,14 +851,14 @@ ether_input(struct ifnet *ifp, struct mb
 		switch (subtype) {
 #if NAGR > 0
 		case SLOWPROTOCOLS_SUBTYPE_LACP:
-			if (ifp->if_agrprivate) {
+			if (agrprivate != NULL) {
 				ieee8023ad_lacp_input(ifp, m);
 				return;
 			}
 			break;
 
 		case SLOWPROTOCOLS_SUBTYPE_MARKER:
-			if (ifp->if_agrprivate) {
+			if (agrprivate != NULL) {
 				ieee8023ad_marker_input(ifp, m);
 				return;
 			}

Index: src/sys/net/agr/ieee8023ad_lacp.c
diff -u src/sys/net/agr/ieee8023ad_lacp.c:1.11 src/sys/net/agr/ieee8023ad_lacp.c:1.12
--- src/sys/net/agr/ieee8023ad_lacp.c:1.11	Wed Jan 29 04:30:41 2020
+++ src/sys/net/agr/ieee8023ad_lacp.c	Thu Sep 30 03:15:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee8023ad_lacp.c,v 1.11 2020/01/29 04:30:41 thorpej Exp $	*/
+/*	$NetBSD: ieee8023ad_lacp.c,v 1.12 2021/09/30 03:15:25 yamaguchi Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ieee8023ad_lacp.c,v 1.11 2020/01/29 04:30:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee8023ad_lacp.c,v 1.12 2021/09/30 03:15:25 yamaguchi Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -97,7 +97,7 @@ ieee8023ad_lacp_input(struct ifnet *ifp,
 	struct lacp_port *lp;
 	int error = 0;
 
-	port = ifp->if_agrprivate; /* XXX race with agr_remport. */
+	port = ifp->if_lagg; /* XXX race with agr_remport. */
 	if (__predict_false(port->port_flags & AGRPORT_DETACHING)) {
 		goto bad;
 	}

Index: src/sys/net/agr/ieee8023ad_marker.c
diff -u src/sys/net/agr/ieee8023ad_marker.c:1.4 src/sys/net/agr/ieee8023ad_marker.c:1.5
--- src/sys/net/agr/ieee8023ad_marker.c:1.4	Thu Feb 22 06:20:16 2007
+++ src/sys/net/agr/ieee8023ad_marker.c	Thu Sep 30 03:15:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee8023ad_marker.c,v 1.4 2007/02/22 06:20:16 thorpej Exp $	*/
+/*	$NetBSD: ieee8023ad_marker.c,v 1.5 2021/09/30 03:15:25 yamaguchi Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ieee8023ad_marker.c,v 1.4 2007/02/22 06:20:16 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee8023ad_marker.c,v 1.5 2021/09/30 03:15:25 yamaguchi Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -60,7 +60,7 @@ ieee8023ad_marker_input(struct ifnet *if
 	struct agr_port *port;
 	int error = 0;
 
-	port = ifp->if_agrprivate; /* XXX race with agr_remport. */
+	port = ifp->if_lagg; /* XXX race with agr_remport. */
 	KASSERT(port);
 	if (__predict_false(port->port_flags & AGRPORT_DETACHING)) {
 		goto bad;

Index: src/sys/net/agr/if_agr.c
diff -u src/sys/net/agr/if_agr.c:1.52 src/sys/net/agr/if_agr.c:1.53
--- src/sys/net/agr/if_agr.c:1.52	Mon Aug  2 12:56:25 2021
+++ src/sys/net/agr/if_agr.c	Thu Sep 30 03:15:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agr.c,v 1.52 2021/08/02 12:56:25 andvar Exp $	*/
+/*	$NetBSD: if_agr.c,v 1.53 2021/09/30 03:15:25 yamaguchi Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.52 2021/08/02 12:56:25 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.53 2021/09/30 03:15:25 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -151,7 +151,7 @@ agr_input(struct ifnet *ifp_port, struct
 	struct agr_port *port;
 	struct ifnet *ifp;
 
-	port = ifp_port->if_agrprivate;
+	port = ifp_port->if_lagg;
 	KASSERT(port);
 	ifp = port->port_agrifp;
 	if ((port->port_flags & AGRPORT_COLLECTING) == 0) {
@@ -234,7 +234,7 @@ agrport_ioctl(struct agr_port *port, u_l
 {
 	struct ifnet *ifp = port->port_ifp;
 
-	KASSERT(ifp->if_agrprivate == (void *)port);
+	KASSERT(ifp->if_lagg == (void *)port);
 	KASSERT(ifp->if_ioctl == agr_ioctl_filter);
 
 	return (*port->port_ioctl)(ifp, cmd, arg);
@@ -542,7 +542,7 @@ agr_addport(struct ifnet *ifp, struct if
 		goto out;
 	}
 
-	if (ifp_port->if_agrprivate) {
+	if (ifp_port->if_lagg) {
 		error = EBUSY;
 		goto out;
 	}
@@ -623,7 +623,7 @@ agr_addport(struct ifnet *ifp, struct if
 	AGR_LOCK(sc);
 
 	port->port_ifp = ifp_port;
-	ifp_port->if_agrprivate = port;
+	ifp_port->if_lagg = port;
 	port->port_agrifp = ifp;
 	TAILQ_INSERT_TAIL(&sc->sc_ports, port, port_q);
 	sc->sc_nports++;
@@ -686,12 +686,12 @@ agr_remport(struct ifnet *ifp, struct if
 	struct agr_port *port;
 	int error = 0;
 
-	if (ifp_port->if_agrprivate == NULL) {
+	if (ifp_port->if_lagg == NULL) {
 		error = ENOENT;
 		return error;
 	}
 
-	port = ifp_port->if_agrprivate;
+	port = ifp_port->if_lagg;
 	if (port->port_agrifp != ifp) {
 		error = EINVAL;
 		return error;
@@ -786,7 +786,7 @@ agrport_cleanup(struct agr_softc *sc, st
 
 	AGR_LOCK(sc);
 	if ((port->port_flags & AGRPORT_ATTACHED)) {
-		ifp_port->if_agrprivate = NULL;
+		ifp_port->if_lagg = NULL;
 
 		TAILQ_REMOVE(&sc->sc_ports, port, port_q);
 		sc->sc_nports--;
@@ -823,7 +823,7 @@ agr_ioctl_multi(struct ifnet *ifp, u_lon
 static int
 agr_ioctl_filter(struct ifnet *ifp, u_long cmd, void *arg)
 {
-	struct agr_port *port = ifp->if_agrprivate;
+	struct agr_port *port = ifp->if_lagg;
 	int error;
 
 	KASSERT(port);

Reply via email to