CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:51:41 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
lagg(4): Fix missing destroy for list and entry


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/net/lagg/if_laggproto.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/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.14 src/sys/net/lagg/if_laggproto.c:1.15
--- src/sys/net/lagg/if_laggproto.c:1.14	Fri Apr  5 06:37:29 2024
+++ src/sys/net/lagg/if_laggproto.c	Fri Apr  5 06:51:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.c,v 1.14 2024/04/05 06:37:29 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.15 2024/04/05 06:51:41 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.14 2024/04/05 06:37:29 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.15 2024/04/05 06:51:41 yamaguchi Exp $");
 
 #include 
 #include 
@@ -206,6 +206,7 @@ lagg_proto_free(struct lagg_proto_softc 
 	pserialize_destroy(psc->psc_psz);
 	mutex_destroy(>psc_lock);
 	lagg_workq_destroy(psc->psc_workq);
+	PSLIST_DESTROY(>psc_ports);
 
 	if (psc->psc_ctxsiz > 0)
 		kmem_free(psc->psc_ctx, psc->psc_ctxsiz);
@@ -321,6 +322,10 @@ lagg_proto_remove_port(struct lagg_proto
 	PSLIST_WRITER_REMOVE(pport, lpp_entry);
 	LAGG_PROTO_UNLOCK(psc);
 	pserialize_perform(psc->psc_psz);
+
+	/* re-initialize for reuse */
+	PSLIST_ENTRY_DESTROY(pport, lpp_entry);
+	PSLIST_ENTRY_INIT(pport, lpp_entry);
 }
 
 void



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:51:41 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
lagg(4): Fix missing destroy for list and entry


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/net/lagg/if_laggproto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:48:23 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): Added vlan check


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:48:23 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): Added vlan check


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.69 src/sys/net/lagg/if_lagg.c:1.70
--- src/sys/net/lagg/if_lagg.c:1.69	Fri Apr  5 06:37:29 2024
+++ src/sys/net/lagg/if_lagg.c	Fri Apr  5 06:48:22 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.69 2024/04/05 06:37:29 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.70 2024/04/05 06:48:22 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.69 2024/04/05 06:37:29 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.70 2024/04/05 06:48:22 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2267,6 +2267,9 @@ lagg_port_setup(struct lagg_softc *sc,
 	switch (ifp_port->if_type) {
 	case IFT_ETHER:
 	case IFT_L2TP:
+		if (VLAN_ATTACHED((struct ethercom *)ifp_port))
+			return EBUSY;
+
 		if_type = IFT_IEEE8023ADLAG;
 		break;
 	default:



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:37:29 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c if_laggproto.c

Log Message:
lagg(4): release lock before pserialize_perform() if possible


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.13 -r1.14 src/sys/net/lagg/if_laggproto.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.68 src/sys/net/lagg/if_lagg.c:1.69
--- src/sys/net/lagg/if_lagg.c:1.68	Fri Apr  5 06:05:37 2024
+++ src/sys/net/lagg/if_lagg.c	Fri Apr  5 06:37:29 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.68 2024/04/05 06:05:37 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.69 2024/04/05 06:37:29 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.68 2024/04/05 06:05:37 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.69 2024/04/05 06:37:29 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1705,8 +1705,8 @@ lagg_pr_detach(struct lagg_softc *sc)
 	LAGG_LOCK(sc);
 	var = sc->sc_var;
 	atomic_store_release(>sc_var, NULL);
-	pserialize_perform(sc->sc_psz);
 	LAGG_UNLOCK(sc);
+	pserialize_perform(sc->sc_psz);
 
 	if (var != NULL)
 		lagg_proto_detach(var);

Index: src/sys/net/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.13 src/sys/net/lagg/if_laggproto.c:1.14
--- src/sys/net/lagg/if_laggproto.c:1.13	Fri Apr  5 06:23:48 2024
+++ src/sys/net/lagg/if_laggproto.c	Fri Apr  5 06:37:29 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.c,v 1.13 2024/04/05 06:23:48 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.14 2024/04/05 06:37:29 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.13 2024/04/05 06:23:48 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.14 2024/04/05 06:37:29 yamaguchi Exp $");
 
 #include 
 #include 
@@ -319,8 +319,8 @@ lagg_proto_remove_port(struct lagg_proto
 
 	LAGG_PROTO_LOCK(psc);
 	PSLIST_WRITER_REMOVE(pport, lpp_entry);
-	pserialize_perform(psc->psc_psz);
 	LAGG_PROTO_UNLOCK(psc);
+	pserialize_perform(psc->psc_psz);
 }
 
 void
@@ -646,8 +646,8 @@ lagg_lb_startport(struct lagg_proto_soft
 	pm_next->pm_nports = n;
 
 	lagg_portmap_switch(>lb_pmaps);
-	pserialize_perform(psc->psc_psz);
 	LAGG_PROTO_UNLOCK(psc);
+	pserialize_perform(psc->psc_psz);
 }
 
 void
@@ -675,8 +675,8 @@ lagg_lb_stopport(struct lagg_proto_softc
 	pm_next->pm_nports = n;
 
 	lagg_portmap_switch(>lb_pmaps);
-	pserialize_perform(psc->psc_psz);
 	LAGG_PROTO_UNLOCK(psc);
+	pserialize_perform(psc->psc_psz);
 
 	lagg_common_stopport(psc, lp);
 }



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:37:29 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c if_laggproto.c

Log Message:
lagg(4): release lock before pserialize_perform() if possible


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.13 -r1.14 src/sys/net/lagg/if_laggproto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:31:37 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): move reply limitation to recive processing


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.42 src/sys/net/lagg/if_lagg_lacp.c:1.43
--- src/sys/net/lagg/if_lagg_lacp.c:1.42	Fri Apr  5 06:21:02 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Fri Apr  5 06:31:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.42 2024/04/05 06:21:02 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.43 2024/04/05 06:31:37 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.42 2024/04/05 06:21:02 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.43 2024/04/05 06:31:37 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -1360,10 +1360,6 @@ lacp_port_need_to_tell(struct lacp_port 
 	if (!ISSET(lacpp->lp_flags, LACP_PORT_NTT))
 		return false;
 
-	if (ppsratecheck(>lp_last_lacpdu, >lp_lacpdu_sent,
-	(LACP_SENDDU_PPS / LACP_FAST_PERIODIC_TIME)) == 0)
-		return false;
-
 	return true;
 }
 
@@ -1988,8 +1984,14 @@ lacp_sm_rx_update_ntt(struct lacp_softc 
 	if (lacp_compare_peerinfo(, my_pi) != 0 ||
 	!LACP_STATE_EQ(lacpp->lp_actor.lpi_state, my_pi->lpi_state,
 	LACP_STATE_ACTIVITY | LACP_STATE_SYNC | LACP_STATE_AGGREGATION)) {
-		LACP_DPRINTF((lsc, lacpp, "assert ntt\n"));
-		lacp_sm_assert_ntt(lacpp);
+		if (ppsratecheck(>lp_last_lacpdu, >lp_lacpdu_sent,
+		(LACP_SENDDU_PPS / LACP_FAST_PERIODIC_TIME)) == 0) {
+			LACP_DPRINTF((lsc, lacpp,
+			"skip ntt due to rate limit"));
+		} else {
+			LACP_DPRINTF((lsc, lacpp, "assert ntt\n"));
+			lacp_sm_assert_ntt(lacpp);
+		}
 	}
 }
 



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:31:37 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): move reply limitation to recive processing


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:23:48 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
lagg(4): remove unnecessary masking

pointed out by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/net/lagg/if_laggproto.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/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.12 src/sys/net/lagg/if_laggproto.c:1.13
--- src/sys/net/lagg/if_laggproto.c:1.12	Thu Apr  4 07:49:06 2024
+++ src/sys/net/lagg/if_laggproto.c	Fri Apr  5 06:23:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.c,v 1.12 2024/04/04 07:49:06 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.13 2024/04/05 06:23:48 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.12 2024/04/04 07:49:06 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.13 2024/04/05 06:23:48 yamaguchi Exp $");
 
 #include 
 #include 
@@ -132,7 +132,6 @@ lagg_portmap_next(struct lagg_portmaps *
 	size_t i;
 
 	i = atomic_load_consume(>maps_activepmap);
-	i &= 0x1;
 	i ^= 0x1;
 
 	return >maps_pmap[i];



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:23:48 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
lagg(4): remove unnecessary masking

pointed out by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/net/lagg/if_laggproto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:21:02 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): set suppress at the same time with distribution state


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.41 src/sys/net/lagg/if_lagg_lacp.c:1.42
--- src/sys/net/lagg/if_lagg_lacp.c:1.41	Fri Apr  5 06:19:28 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Fri Apr  5 06:21:02 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.41 2024/04/05 06:19:28 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.42 2024/04/05 06:21:02 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.41 2024/04/05 06:19:28 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.42 2024/04/05 06:21:02 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -2560,19 +2560,23 @@ lacp_suppress_distributing(struct lacp_s
 {
 	struct lacp_aggregator *la;
 	struct lacp_port *lacpp;
+	bool marker_scheduled;
 
 	KASSERT(LACP_LOCKED(lsc));
 
 	la = lsc->lsc_aggregator;
+	marker_scheduled = false;
 
 	LIST_FOREACH(lacpp, >la_ports, lp_entry_la) {
 		if (ISSET(lacpp->lp_actor.lpi_state,
 		LACP_STATE_DISTRIBUTING)) {
 			lagg_workq_add(lsc->lsc_workq,
 			>lp_work_marker);
+			marker_scheduled = true;
 		}
 	}
 
+	lsc->lsc_suppress_distributing = marker_scheduled;
 	LACP_PTIMER_ARM(lsc, LACP_PTIMER_DISTRIBUTING,
 	LACP_TRANSIT_DELAY);
 }
@@ -2659,7 +2663,6 @@ lacp_marker_work(struct lagg_work *lw, v
 		return;
 	}
 	SET(lacpp->lp_flags, LACP_PORT_MARK);
-	lsc->lsc_suppress_distributing = true;
 	lp = lacpp->lp_laggport;
 	bound = curlwp_bind();
 	lagg_port_getref(lp, );



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:21:02 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): set suppress at the same time with distribution state


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:19:28 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
added missing workq_wait for lacp_tick_work()


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.40 src/sys/net/lagg/if_lagg_lacp.c:1.41
--- src/sys/net/lagg/if_lagg_lacp.c:1.40	Fri Apr  5 06:16:32 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Fri Apr  5 06:19:28 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.40 2024/04/05 06:16:32 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.41 2024/04/05 06:19:28 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.40 2024/04/05 06:16:32 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.41 2024/04/05 06:19:28 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -544,6 +544,7 @@ lacp_detach(struct lagg_proto_softc *xls
 	LAGG_UNLOCK(lsc->lsc_softc);
 
 	lagg_workq_wait(lsc->lsc_workq, >lsc_work_rcvdu);
+	lagg_workq_wait(lsc->lsc_workq, >lsc_work_tick);
 	evcnt_detach(>lsc_mgethdr_failed);
 	evcnt_detach(>lsc_mpullup_failed);
 	evcnt_detach(>lsc_badlacpdu);



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:19:28 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
added missing workq_wait for lacp_tick_work()


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:16:32 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): added check of LACP running state for safety

When LACP stops, the handler of callout do nothing
because all port is already detached from lacp.
Therefore, the added checks are just for safety.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.39 src/sys/net/lagg/if_lagg_lacp.c:1.40
--- src/sys/net/lagg/if_lagg_lacp.c:1.39	Fri Apr  5 06:11:16 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Fri Apr  5 06:16:32 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.39 2024/04/05 06:11:16 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.40 2024/04/05 06:16:32 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.39 2024/04/05 06:11:16 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.40 2024/04/05 06:16:32 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -1491,10 +1491,16 @@ lacp_tick(void *xlsc)
 
 	lsc = xlsc;
 
-	lagg_workq_add(lsc->lsc_workq, >lsc_work_tick);
-
 	LACP_LOCK(lsc);
+
+	if (!lsc->lsc_running) {
+		LACP_UNLOCK(lsc);
+		return;
+	}
+
+	lagg_workq_add(lsc->lsc_workq, >lsc_work_tick);
 	callout_schedule(>lsc_tick, hz);
+
 	LACP_UNLOCK(lsc);
 }
 
@@ -1548,6 +1554,11 @@ lacp_tick_work(struct lagg_work *lw __un
 	sc = lsc->lsc_softc;
 
 	LACP_LOCK(lsc);
+	if (!lsc->lsc_running) {
+		LACP_UNLOCK(lsc);
+		return;
+	}
+
 	lacp_run_prototimers(lsc);
 	LACP_UNLOCK(lsc);
 



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:16:32 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): added check of LACP running state for safety

When LACP stops, the handler of callout do nothing
because all port is already detached from lacp.
Therefore, the added checks are just for safety.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:11:16 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
fix missing LACP_LOCK


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.38 src/sys/net/lagg/if_lagg_lacp.c:1.39
--- src/sys/net/lagg/if_lagg_lacp.c:1.38	Fri Apr  5 06:07:36 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Fri Apr  5 06:11:16 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.38 2024/04/05 06:07:36 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.39 2024/04/05 06:11:16 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.38 2024/04/05 06:07:36 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.39 2024/04/05 06:11:16 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -1444,10 +1444,13 @@ lacp_sm_tx_work(struct lagg_work *lw, vo
 	lsc = xlsc;
 	lacpp = container_of(lw, struct lacp_port, lp_work_smtx);
 
-	if (lsc->lsc_stop_lacpdu)
+	LACP_LOCK(lsc);
+
+	if (lsc->lsc_stop_lacpdu) {
+		LACP_UNLOCK(lsc);
 		return;
+	}
 
-	LACP_LOCK(lsc);
 	m = lacp_lacpdu_mbuf(lsc, lacpp);
 	if (m == NULL) {
 		LACP_UNLOCK(lsc);



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:11:16 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
fix missing LACP_LOCK


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:07:37 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): added missing pserialize_read_enter


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:07:37 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): added missing pserialize_read_enter


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.37 src/sys/net/lagg/if_lagg_lacp.c:1.38
--- src/sys/net/lagg/if_lagg_lacp.c:1.37	Thu Apr  4 09:19:42 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Fri Apr  5 06:07:36 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.37 2024/04/04 09:19:42 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.38 2024/04/05 06:07:36 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.37 2024/04/04 09:19:42 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.38 2024/04/05 06:07:36 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -1290,7 +1290,7 @@ lacp_rcvdu_work(struct lagg_work *lw __u
 	struct lagg_port *lp;
 	struct mbuf *m;
 	uint8_t subtype;
-	int bound, s;
+	int bound, s0, s1;
 
 	bound = curlwp_bind();
 
@@ -1299,23 +1299,26 @@ lacp_rcvdu_work(struct lagg_work *lw __u
 		if (m == NULL)
 			break;
 
-		ifp = m_get_rcvif(m, );
+		ifp = m_get_rcvif(m, );
 		if (ifp == NULL) {
 			m_freem(m);
 			lsc->lsc_norcvif.ev_count++;
 			continue;
 		}
 
+		s1 = pserialize_read_enter();
 		lp = atomic_load_consume(>if_lagg);
 		if (lp == NULL) {
-			m_put_rcvif(ifp, );
+			pserialize_read_exit(s1);
+			m_put_rcvif(ifp, );
 			m_freem(m);
 			lsc->lsc_norcvif.ev_count++;
 			continue;
 		}
 
 		lagg_port_getref(lp, _lp);
-		m_put_rcvif(ifp, );
+		pserialize_read_exit(s1);
+		m_put_rcvif(ifp, );
 
 		m_copydata(m, sizeof(struct ether_header),
 		sizeof(subtype), );



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:05:37 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): added __predict_true


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.67 src/sys/net/lagg/if_lagg.c:1.68
--- src/sys/net/lagg/if_lagg.c:1.67	Thu Apr  4 09:19:42 2024
+++ src/sys/net/lagg/if_lagg.c	Fri Apr  5 06:05:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.67 2024/04/04 09:19:42 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.68 2024/04/05 06:05:37 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.67 2024/04/04 09:19:42 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.68 2024/04/05 06:05:37 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -3010,7 +3010,7 @@ lagg_chg_sadl(struct ifnet *ifp, const u
 	}
 
 	/* Activate the next Link-Level address */
-	if (ifa_next != ifp->if_dl) {
+	if (__predict_true(ifa_next != ifp->if_dl)) {
 		/* save the current address */
 		ifa_cur = ifp->if_dl;
 		if (ifa_cur != NULL)



CVS commit: src/sys/net/lagg

2024-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  5 06:05:37 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): added __predict_true


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 09:19:43 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c

Log Message:
Added comments to lagg(4)


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.36 -r1.37 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.66 src/sys/net/lagg/if_lagg.c:1.67
--- src/sys/net/lagg/if_lagg.c:1.66	Thu Apr  4 08:50:58 2024
+++ src/sys/net/lagg/if_lagg.c	Thu Apr  4 09:19:42 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.66 2024/04/04 08:50:58 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.67 2024/04/04 09:19:42 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.66 2024/04/04 08:50:58 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.67 2024/04/04 09:19:42 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2165,6 +2165,7 @@ lagg_port_setsadl(struct lagg_port *lp, 
 
 		if (ifp_port->if_init != NULL) {
 			error = 0;
+			/* Apply updated ifp_port->if_sadl to the device */
 			if (ISSET(ifp_port->if_flags, IFF_RUNNING))
 error = if_init(ifp_port);
 
@@ -2929,7 +2930,9 @@ lagg_chg_sadl(struct ifnet *ifp, const u
 	error = 0;
 	ifa_lla = NULL;
 
+	/* Renew all AF_LINK address to update sdl_type */
 	while (1) {
+		/* find a Link-Level address that has the previous sdl_type */
 		s = pserialize_read_enter();
 		IFADDR_READER_FOREACH(ifa_cur, ifp) {
 			sdl = satocsdl(ifa_cur->ifa_addr);
@@ -2945,7 +2948,10 @@ lagg_chg_sadl(struct ifnet *ifp, const u
 
 		if (ifa_cur == NULL)
 			break;
-
+		/*
+		 * create a new address that has new sdl_type,
+		 * and copy address from the previous.
+		 */
 		ifa_next = if_dl_create(ifp, );
 		if (ifa_next == NULL) {
 			error = ENOMEM;
@@ -2957,6 +2963,7 @@ lagg_chg_sadl(struct ifnet *ifp, const u
 		CLLADDR(sdl), ifp->if_addrlen);
 		ifa_insert(ifp, ifa_next);
 
+		/* the next Link-Level address is already set */
 		if (ifa_lla == NULL &&
 		memcmp(CLLADDR(sdl), lla, lla_len) == 0) {
 			ifa_lla = ifa_next;
@@ -2972,6 +2979,7 @@ lagg_chg_sadl(struct ifnet *ifp, const u
 			ifafree(ifa_cur);
 		}
 
+		/* remove the old address */
 		ifaref(ifa_cur);
 		ifa_release(ifa_cur, _cur);
 		ifa_remove(ifp, ifa_cur);
@@ -2981,6 +2989,7 @@ lagg_chg_sadl(struct ifnet *ifp, const u
 		ifa_release(ifa_next, _next);
 	}
 
+	/* acquire or create the next Link-Level address */
 	if (ifa_lla != NULL) {
 		ifa_next = ifa_lla;
 
@@ -3000,13 +3009,19 @@ lagg_chg_sadl(struct ifnet *ifp, const u
 		ifa_insert(ifp, ifa_next);
 	}
 
+	/* Activate the next Link-Level address */
 	if (ifa_next != ifp->if_dl) {
+		/* save the current address */
 		ifa_cur = ifp->if_dl;
 		if (ifa_cur != NULL)
 			ifa_acquire(ifa_cur, _cur);
 
 		if_activate_sadl(ifp, ifa_next, nsdl);
 
+		/*
+		 * free the saved address after switching,
+		 * if the address is not if_hwdl.
+		 */
 		if (ifa_cur != NULL) {
 			if (ifa_cur != ifp->if_hwdl) {
 ifaref(ifa_cur);

Index: src/sys/net/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.36 src/sys/net/lagg/if_lagg_lacp.c:1.37
--- src/sys/net/lagg/if_lagg_lacp.c:1.36	Thu Apr  4 09:09:24 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Thu Apr  4 09:19:42 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.36 2024/04/04 09:09:24 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.37 2024/04/04 09:19:42 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.36 2024/04/04 09:09:24 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.37 2024/04/04 09:19:42 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -2718,6 +2718,12 @@ lacp_dump_markertlv(const struct markerd
 	}
 }
 
+/*
+ * lacp_linkstate:
+ *   callback on link state changed.
+ *   enable, disable or reset LACP processing on the physical port.
+ */
+
 static void
 lacp_linkstate(struct lagg_proto_softc *xlsc, struct lagg_port *lp)
 {



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 09:19:43 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c

Log Message:
Added comments to lagg(4)


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.36 -r1.37 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 09:09:24 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): move allocate memory before ioctl


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.35 src/sys/net/lagg/if_lagg_lacp.c:1.36
--- src/sys/net/lagg/if_lagg_lacp.c:1.35	Thu Apr  4 08:54:52 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Thu Apr  4 09:09:24 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.35 2024/04/04 08:54:52 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.36 2024/04/04 09:09:24 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.35 2024/04/04 08:54:52 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.36 2024/04/04 09:09:24 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -674,6 +674,10 @@ lacp_allocport(struct lagg_proto_softc *
 	KASSERT(LAGG_LOCKED(sc));
 	KASSERT(IFNET_LOCKED(lp->lp_ifp));
 
+	lacpp = kmem_zalloc(sizeof(*lacpp), KM_NOSLEEP);
+	if (lacpp == NULL)
+		return ENOMEM;
+
 	lacp_mcastaddr(, lp->lp_ifp->if_xname);
 	error = lp->lp_ioctl(lp->lp_ifp, SIOCADDMULTI, (void *));
 
@@ -687,13 +691,10 @@ lacp_allocport(struct lagg_proto_softc *
 	default:
 		LAGG_LOG(sc, LOG_ERR, "SIOCADDMULTI failed on %s\n",
 		lp->lp_ifp->if_xname);
+		kmem_free(lacpp, sizeof(*lacpp));
 		return error;
 	}
 
-	lacpp = kmem_zalloc(sizeof(*lacpp), KM_NOSLEEP);
-	if (lacpp == NULL)
-		return ENOMEM;
-
 	lacpp->lp_added_multi = added_multi;
 	lagg_work_set(>lp_work_smtx, lacp_sm_tx_work, lsc);
 	lagg_work_set(>lp_work_marker, lacp_marker_work, lsc);



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 09:09:24 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): move allocate memory before ioctl


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:54:52 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
Added KASSERT for LACP_LOCK


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.34 src/sys/net/lagg/if_lagg_lacp.c:1.35
--- src/sys/net/lagg/if_lagg_lacp.c:1.34	Thu Apr  4 08:53:14 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Thu Apr  4 08:54:52 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.34 2024/04/04 08:53:14 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.35 2024/04/04 08:54:52 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.34 2024/04/04 08:53:14 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.35 2024/04/04 08:54:52 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -1496,6 +1496,8 @@ lacp_run_timers(struct lacp_softc *lsc, 
 {
 	size_t i;
 
+	KASSERT(LACP_LOCKED(lsc));
+
 	for (i = 0; i < LACP_NTIMER; i++) {
 		KASSERT(lacpp->lp_timer[i] >= 0);
 
@@ -1814,6 +1816,8 @@ static void
 lacp_port_disable(struct lacp_softc *lsc, struct lacp_port *lacpp)
 {
 
+	KASSERT(LACP_LOCKED(lsc));
+
 	if (ISSET(lacpp->lp_actor.lpi_state, LACP_STATE_AGGREGATION))
 		LACP_DPRINTF((lsc, lacpp, "enable -> disable\n"));
 
@@ -1829,6 +1833,8 @@ lacp_port_enable(struct lacp_softc *lsc 
 struct lacp_port *lacpp)
 {
 
+	KASSERT(LACP_LOCKED(lsc));
+
 	if (!ISSET(lacpp->lp_actor.lpi_state, LACP_STATE_AGGREGATION))
 		LACP_DPRINTF((lsc, lacpp, "disable -> enable\n"));
 
@@ -1840,6 +1846,8 @@ static void
 lacp_sm_rx_timer(struct lacp_softc *lsc, struct lacp_port *lacpp)
 {
 
+	KASSERT(LACP_LOCKED(lsc));
+
 	if (!ISSET(lacpp->lp_actor.lpi_state, LACP_STATE_EXPIRED)) {
 		/* CURRENT -> EXPIRED */
 		LACP_DPRINTF((lsc, lacpp, "CURRENT -> EXPIRED\n"));
@@ -1855,6 +1863,7 @@ static void
 lacp_sm_ptx_timer(struct lacp_softc *lsc __unused, struct lacp_port *lacpp)
 {
 
+	KASSERT(LACP_LOCKED(lsc));
 	lacp_sm_assert_ntt(lacpp);
 }
 
@@ -1902,6 +1911,7 @@ lacp_sm_mux_timer(struct lacp_softc *lsc
 {
 	char buf[LACP_SYSTEMIDSTR_LEN] __LACPDEBUGUSED;
 
+	KASSERT(LACP_LOCKED(lsc));
 	KASSERT(lacpp->lp_pending > 0);
 
 	LACP_AGGREGATOR_STR(lacpp->lp_aggregator, buf, sizeof(buf));



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:54:52 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
Added KASSERT for LACP_LOCK


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:53:14 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): Use CTASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.33 src/sys/net/lagg/if_lagg_lacp.c:1.34
--- src/sys/net/lagg/if_lagg_lacp.c:1.33	Thu Apr  4 08:36:03 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Thu Apr  4 08:53:14 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.33 2024/04/04 08:36:03 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.34 2024/04/04 08:53:14 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.33 2024/04/04 08:36:03 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.34 2024/04/04 08:53:14 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -380,7 +380,7 @@ lacp_mcastaddr(struct ifreq *ifr, const 
 	ifr->ifr_addr.sa_len = sizeof(ifr->ifr_addr);
 	ifr->ifr_addr.sa_family = AF_UNSPEC;
 
-	KASSERT(sizeof(ifr->ifr_addr) >= sizeof(addr));
+	CTASSERT(sizeof(ifr->ifr_addr) >= sizeof(addr));
 	memcpy(>ifr_addr.sa_data, addr, sizeof(addr));
 }
 



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:53:14 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): Use CTASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:50:58 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): replace NULL check with KASSERT because lp_softc is always non-NULL


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:50:58 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): replace NULL check with KASSERT because lp_softc is always non-NULL


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.65 src/sys/net/lagg/if_lagg.c:1.66
--- src/sys/net/lagg/if_lagg.c:1.65	Thu Apr  4 08:38:22 2024
+++ src/sys/net/lagg/if_lagg.c	Thu Apr  4 08:50:58 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.65 2024/04/04 08:38:22 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.66 2024/04/04 08:50:58 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.65 2024/04/04 08:38:22 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.66 2024/04/04 08:50:58 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2711,10 +2711,11 @@ lagg_port_ioctl(struct ifnet *ifp, u_lon
 	int error = 0;
 	u_int ifflags;
 
-	if ((lp = ifp->if_lagg) == NULL ||
-	(sc = lp->lp_softc) == NULL) {
+	if ((lp = ifp->if_lagg) == NULL)
 		goto fallback;
-	}
+
+	sc = lp->lp_softc;
+	KASSERT(sc != NULL);
 
 	KASSERT(IFNET_LOCKED(lp->lp_ifp));
 
@@ -2786,12 +2787,9 @@ lagg_ifdetach(void *xifp_port)
 	if (lp == NULL) {
 		pserialize_read_exit(s);
 		return;
-	}
-
-	sc = lp->lp_softc;
-	if (sc == NULL) {
-		pserialize_read_exit(s);
-		return;
+	} else {
+		sc = lp->lp_softc;
+		KASSERT(sc != NULL);
 	}
 	pserialize_read_exit(s);
 



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:38:22 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): increase output packets and bytes only if no error occurred

pointed out by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.64 src/sys/net/lagg/if_lagg.c:1.65
--- src/sys/net/lagg/if_lagg.c:1.64	Thu Apr  4 08:36:03 2024
+++ src/sys/net/lagg/if_lagg.c	Thu Apr  4 08:38:22 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.64 2024/04/04 08:36:03 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.65 2024/04/04 08:38:22 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.64 2024/04/04 08:36:03 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.65 2024/04/04 08:38:22 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1080,14 +1080,14 @@ lagg_output(struct lagg_softc *sc, struc
 	if (error) {
 		/* mbuf is already freed */
 		if_statinc(ifp, if_oerrors);
+	} else {
+		net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
+		if_statinc_ref(nsr, if_opackets);
+		if_statadd_ref(nsr, if_obytes, len);
+		if (mflags & M_MCAST)
+			if_statinc_ref(nsr, if_omcasts);
+		IF_STAT_PUTREF(ifp);
 	}
-
-	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
-	if_statinc_ref(nsr, if_opackets);
-	if_statadd_ref(nsr, if_obytes, len);
-	if (mflags & M_MCAST)
-		if_statinc_ref(nsr, if_omcasts);
-	IF_STAT_PUTREF(ifp);
 }
 
 static struct mbuf *



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:38:22 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): increase output packets and bytes only if no error occurred

pointed out by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:36:03 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c

Log Message:
lagg(4): change errno

suggested by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.32 -r1.33 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:36:03 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c

Log Message:
lagg(4): change errno

suggested by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.32 -r1.33 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.63 src/sys/net/lagg/if_lagg.c:1.64
--- src/sys/net/lagg/if_lagg.c:1.63	Thu Apr  4 08:31:58 2024
+++ src/sys/net/lagg/if_lagg.c	Thu Apr  4 08:36:03 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.63 2024/04/04 08:31:58 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.64 2024/04/04 08:36:03 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.63 2024/04/04 08:31:58 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.64 2024/04/04 08:36:03 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1027,7 +1027,7 @@ lagg_tx_common(struct ifnet *ifp, struct
 	} else {
 		m_freem(m);
 		if_statinc(ifp, if_oerrors);
-		error = ENOBUFS;
+		error = EIO;
 	}
 
 	lagg_variant_putref(var, );

Index: src/sys/net/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.32 src/sys/net/lagg/if_lagg_lacp.c:1.33
--- src/sys/net/lagg/if_lagg_lacp.c:1.32	Thu Apr  4 08:20:20 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Thu Apr  4 08:36:03 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.32 2024/04/04 08:20:20 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.33 2024/04/04 08:36:03 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.32 2024/04/04 08:20:20 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.33 2024/04/04 08:36:03 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -640,7 +640,7 @@ lacp_transmit(struct lagg_proto_softc *x
 	if (__predict_false(lsc->lsc_suppress_distributing)) {
 		LACP_DPRINTF((lsc, NULL, "waiting transit\n"));
 		m_freem(m);
-		return ENOBUFS;
+		return EBUSY;
 	}
 
 	lp = lacp_select_tx_port(lsc, m, );



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:31:58 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): added NULL check for pfil_run_hooks

pointed out by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.62 src/sys/net/lagg/if_lagg.c:1.63
--- src/sys/net/lagg/if_lagg.c:1.62	Thu Apr  4 08:29:25 2024
+++ src/sys/net/lagg/if_lagg.c	Thu Apr  4 08:31:58 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.62 2024/04/04 08:29:25 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.63 2024/04/04 08:31:58 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.62 2024/04/04 08:29:25 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.63 2024/04/04 08:31:58 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1068,8 +1068,12 @@ lagg_output(struct lagg_softc *sc, struc
 	mflags = m->m_flags;
 
 	error = pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_OUT);
-	if (error != 0)
+	if (error != 0) {
+		if (m != NULL) {
+			m_freem(m);
+		}
 		return;
+	}
 	bpf_mtap(ifp, m, BPF_D_OUT);
 
 	error = lagg_port_xmit(lp, m);
@@ -1175,8 +1179,13 @@ lagg_input_ethernet(struct ifnet *ifp_po
 	if_statadd(ifp_port, if_ibytes, m->m_pkthdr.len);
 
 	if (pfil_run_hooks(ifp_port->if_pfil, ,
-	ifp_port, PFIL_IN) != 0)
+	ifp_port, PFIL_IN) != 0) {
+		if (m != NULL) {
+			m_freem(m);
+			m = NULL;
+		}
 		goto out;
+	}
 
 	m = lagg_proto_input(lp->lp_softc, lp, m);
 	if (m != NULL) {



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:31:58 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): added NULL check for pfil_run_hooks

pointed out by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:29:25 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): move comment about IFF_PROMISC

pointed out by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.61 src/sys/net/lagg/if_lagg.c:1.62
--- src/sys/net/lagg/if_lagg.c:1.61	Thu Apr  4 08:26:32 2024
+++ src/sys/net/lagg/if_lagg.c	Thu Apr  4 08:29:25 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.61 2024/04/04 08:26:32 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.62 2024/04/04 08:29:25 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.61 2024/04/04 08:26:32 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.62 2024/04/04 08:29:25 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1139,11 +1139,6 @@ lagg_input_ethernet(struct ifnet *ifp_po
 
 	ifp = >lp_softc->sc_if;
 
-	/*
-	 * Drop promiscuously received packets
-	 * if we are not in promiscuous mode.
-	 */
-
 	if (__predict_false(m->m_len < (int)sizeof(*eh))) {
 		if ((m = m_pullup(m, sizeof(*eh))) == NULL) {
 			if_statinc(ifp, if_ierrors);
@@ -1166,6 +1161,10 @@ lagg_input_ethernet(struct ifnet *ifp_po
 
 		if_statinc(ifp_port, if_imcasts);
 	} else {
+		/*
+		 * Drop promiscuously received packets
+		 * if we are not in promiscuous mode.
+		 */
 		if ((ifp->if_flags & IFF_PROMISC) == 0 &&
 		(ifp_port->if_flags & IFF_PROMISC) != 0 &&
 		memcmp(CLLADDR(ifp->if_sadl), eh->ether_dhost,



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:29:25 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): move comment about IFF_PROMISC

pointed out by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:26:32 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): added size check to SIOCSLAGG

pointed out by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:26:32 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): added size check to SIOCSLAGG

pointed out by ozaki-r@, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.60 src/sys/net/lagg/if_lagg.c:1.61
--- src/sys/net/lagg/if_lagg.c:1.60	Thu Apr  4 08:22:17 2024
+++ src/sys/net/lagg/if_lagg.c	Thu Apr  4 08:26:32 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.60 2024/04/04 08:22:17 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.61 2024/04/04 08:26:32 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.60 2024/04/04 08:22:17 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.61 2024/04/04 08:26:32 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -693,7 +693,10 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 			break;
 
 		nports = laggreq.lrq_nports;
-		if (nports > 0) {
+		if (nports > LAGG_MAX_PORTS) {
+			error = ENOMEM;
+			break;
+		} else if (nports > 0) {
 			allocsiz = sizeof(struct lagg_req)
 			+ sizeof(struct laggreqport) * nports;
 			buf = kmem_alloc(allocsiz, KM_SLEEP);



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:22:17 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
added missing LAGG_UNLOCK()


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.59 src/sys/net/lagg/if_lagg.c:1.60
--- src/sys/net/lagg/if_lagg.c:1.59	Thu Apr  4 08:20:20 2024
+++ src/sys/net/lagg/if_lagg.c	Thu Apr  4 08:22:17 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.59 2024/04/04 08:20:20 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.60 2024/04/04 08:22:17 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.59 2024/04/04 08:20:20 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.60 2024/04/04 08:22:17 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1680,6 +1680,7 @@ lagg_pr_attach(struct lagg_softc *sc, la
 	return 0;
 
 failed:
+	LAGG_UNLOCK(sc);
 	kmem_free(newvar, sizeof(*newvar));
 
 	return error;



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:22:17 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
added missing LAGG_UNLOCK()


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:20:20 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c

Log Message:
lagg(4): Remove unnecessary LAGG_LOCK holding while lagg_proto_detach()
to avoid deadlock in workqueue_wait due to LAGG_LOCK holding

lagg_proto_detach dose not need to hold LAGG_LOCK because only one
context can access to a detaching protocol after sc->sc_var is updated.
But it was held without any reason. And it had caused a deadlock by
holding LAGG_LOCK in caller of workqueue_wait
and waiting for the lock in worker.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.31 -r1.32 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.58 src/sys/net/lagg/if_lagg.c:1.59
--- src/sys/net/lagg/if_lagg.c:1.58	Thu Apr  4 07:55:32 2024
+++ src/sys/net/lagg/if_lagg.c	Thu Apr  4 08:20:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.58 2024/04/04 07:55:32 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.59 2024/04/04 08:20:20 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.58 2024/04/04 07:55:32 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.59 2024/04/04 08:20:20 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1649,11 +1649,9 @@ lagg_pr_attach(struct lagg_softc *sc, la
 {
 	struct lagg_variant *newvar, *oldvar;
 	struct lagg_proto_softc *psc;
-	bool cleanup_oldvar;
 	int error;
 
 	error = 0;
-	cleanup_oldvar = false;
 	newvar = kmem_alloc(sizeof(*newvar), KM_SLEEP);
 
 	LAGG_LOCK(sc);
@@ -1661,32 +1659,28 @@ lagg_pr_attach(struct lagg_softc *sc, la
 
 	if (oldvar != NULL && oldvar->lv_proto == pr) {
 		error = 0;
-		goto done;
+		goto failed;
 	}
 
 	error = lagg_proto_attach(sc, pr, );
 	if (error != 0)
-		goto done;
+		goto failed;
 
 	newvar->lv_proto = pr;
 	newvar->lv_psc = psc;
-
 	lagg_variant_update(sc, newvar);
-	newvar = NULL;
+	lagg_set_linkspeed(sc, 0);
+	LAGG_UNLOCK(sc);
 
 	if (oldvar != NULL) {
 		lagg_proto_detach(oldvar);
-		cleanup_oldvar = true;
+		kmem_free(oldvar, sizeof(*oldvar));
 	}
 
-	lagg_set_linkspeed(sc, 0);
-done:
-	LAGG_UNLOCK(sc);
+	return 0;
 
-	if (newvar != NULL)
-		kmem_free(newvar, sizeof(*newvar));
-	if (cleanup_oldvar)
-		kmem_free(oldvar, sizeof(*oldvar));
+failed:
+	kmem_free(newvar, sizeof(*newvar));
 
 	return error;
 }
@@ -1697,15 +1691,14 @@ lagg_pr_detach(struct lagg_softc *sc)
 	struct lagg_variant *var;
 
 	LAGG_LOCK(sc);
-
 	var = sc->sc_var;
 	atomic_store_release(>sc_var, NULL);
 	pserialize_perform(sc->sc_psz);
+	LAGG_UNLOCK(sc);
 
 	if (var != NULL)
 		lagg_proto_detach(var);
 
-	LAGG_UNLOCK(sc);
 
 	if (var != NULL)
 		kmem_free(var, sizeof(*var));

Index: src/sys/net/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.31 src/sys/net/lagg/if_lagg_lacp.c:1.32
--- src/sys/net/lagg/if_lagg_lacp.c:1.31	Thu Apr  4 07:45:57 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Thu Apr  4 08:20:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.31 2024/04/04 07:45:57 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.32 2024/04/04 08:20:20 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.31 2024/04/04 07:45:57 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.32 2024/04/04 08:20:20 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -536,11 +536,12 @@ lacp_detach(struct lagg_proto_softc *xls
 	struct lacp_softc *lsc = (struct lacp_softc *)xlsc;
 	struct lagg_softc *sc __diagused = lsc->lsc_softc;
 
-	KASSERT(LAGG_LOCKED(lsc->lsc_softc));
 	KASSERT(TAILQ_EMPTY(>lsc_aggregators));
 	KASSERT(SIMPLEQ_EMPTY(>sc_ports));
 
+	LAGG_LOCK(lsc->lsc_softc);
 	lacp_down(xlsc);
+	LAGG_UNLOCK(lsc->lsc_softc);
 
 	lagg_workq_wait(lsc->lsc_workq, >lsc_work_rcvdu);
 	evcnt_detach(>lsc_mgethdr_failed);



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 08:20:20 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c

Log Message:
lagg(4): Remove unnecessary LAGG_LOCK holding while lagg_proto_detach()
to avoid deadlock in workqueue_wait due to LAGG_LOCK holding

lagg_proto_detach dose not need to hold LAGG_LOCK because only one
context can access to a detaching protocol after sc->sc_var is updated.
But it was held without any reason. And it had caused a deadlock by
holding LAGG_LOCK in caller of workqueue_wait
and waiting for the lock in worker.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.31 -r1.32 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:49:06 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
acquire LAGG_PROTO_LOCK instead of pserialize read section


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/net/lagg/if_laggproto.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/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.11 src/sys/net/lagg/if_laggproto.c:1.12
--- src/sys/net/lagg/if_laggproto.c:1.11	Thu Apr  4 07:35:01 2024
+++ src/sys/net/lagg/if_laggproto.c	Thu Apr  4 07:49:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.c,v 1.11 2024/04/04 07:35:01 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.12 2024/04/04 07:49:06 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.11 2024/04/04 07:35:01 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.12 2024/04/04 07:49:06 yamaguchi Exp $");
 
 #include 
 #include 
@@ -65,9 +65,8 @@ struct lagg_proto_softc {
  * Locking notes:
  * - Items of struct lagg_proto_softc is protected by
  *   psc_lock (an adaptive mutex)
- * - psc_ports is protected by pserialize (psc_psz)
- *   - Updates of psc_ports is serialized by sc_lock in
- * struct lagg_softc
+ * - psc_ports is protected by pselialize (psc_psz) and
+ *   it updates exclusively by LAGG_PROTO_LOCK.
  * - Other locking notes are described in if_laggproto.h
  */
 
@@ -751,21 +750,18 @@ lagg_lb_linkspeed_work(struct lagg_work 
 	struct lagg_proto_softc *psc = xpsc;
 	struct lagg_proto_port *pport;
 	uint64_t linkspeed, l;
-	int s;
 
 	linkspeed = 0;
 
-	s = pserialize_read_enter();
+	LAGG_PROTO_LOCK(psc); /* acquired to refer lpp_linkspeed */
 	PSLIST_READER_FOREACH(pport, >psc_ports,
 	struct lagg_proto_port, lpp_entry) {
 		if (pport->lpp_active) {
-			LAGG_PROTO_LOCK(psc);
 			l = pport->lpp_linkspeed;
-			LAGG_PROTO_UNLOCK(psc);
 			linkspeed = MAX(linkspeed, l);
 		}
 	}
-	pserialize_read_exit(s);
+	LAGG_PROTO_UNLOCK(psc);
 
 	LAGG_LOCK(psc->psc_softc);
 	lagg_set_linkspeed(psc->psc_softc, linkspeed);



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:49:06 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
acquire LAGG_PROTO_LOCK instead of pserialize read section


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/net/lagg/if_laggproto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:45:57 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): added log on detaching a port from SELECTED state to STANDBY


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.30 src/sys/net/lagg/if_lagg_lacp.c:1.31
--- src/sys/net/lagg/if_lagg_lacp.c:1.30	Thu Apr  4 07:40:38 2024
+++ src/sys/net/lagg/if_lagg_lacp.c	Thu Apr  4 07:45:57 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.30 2024/04/04 07:40:38 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.31 2024/04/04 07:45:57 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.30 2024/04/04 07:40:38 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.31 2024/04/04 07:45:57 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -2317,6 +2317,10 @@ lacp_sm_mux(struct lacp_softc *lsc, stru
 			break;
 		case LACP_MUX_ATTACHED:
 			if (selected != LACP_SELECTED) {
+if (selected == LACP_STANDBY)
+	LAGG_LOG(lsc->lsc_softc, LOG_INFO,
+	"detaching %s\n",
+	LACP_PORT_XNAME(lacpp));
 next_state = LACP_MUX_DETACHED;
 			} else if (lacp_isactive(lsc, lacpp) && p_sync) {
 next_state = LACP_MUX_COLLECTING;



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:45:57 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): added log on detaching a port from SELECTED state to STANDBY


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:40:39 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): Added LACP_READY state for logging
when a port turns SELECTED or UNSELECTED


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.29 src/sys/net/lagg/if_lagg_lacp.c:1.30
--- src/sys/net/lagg/if_lagg_lacp.c:1.29	Wed Nov 22 03:52:58 2023
+++ src/sys/net/lagg/if_lagg_lacp.c	Thu Apr  4 07:40:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.29 2023/11/22 03:52:58 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.30 2024/04/04 07:40:38 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.29 2023/11/22 03:52:58 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.30 2024/04/04 07:40:38 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -75,6 +75,7 @@ enum {
 
 enum lacp_selected {
 	LACP_UNSELECTED,
+	LACP_READY,
 	LACP_STANDBY,
 	LACP_SELECTED,
 };
@@ -2457,7 +2458,7 @@ lacp_select(struct lacp_softc *lsc, stru
 	LACP_DPRINTF((lsc, lacpp, "aggregator lagid=%s\n", buf));
 
 	lacpp->lp_aggregator = la;
-	lacpp->lp_selected = LACP_STANDBY;
+	lacpp->lp_selected = LACP_READY;
 
 	LIST_FOREACH(lacpp0, >la_ports, lp_entry_la) {
 		if (lacp_port_priority_max(lacpp0, lacpp) == lacpp) {



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:40:39 UTC 2024

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): Added LACP_READY state for logging
when a port turns SELECTED or UNSELECTED


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:35:01 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
lagg(4): Added 0 length check


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/net/lagg/if_laggproto.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/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.10 src/sys/net/lagg/if_laggproto.c:1.11
--- src/sys/net/lagg/if_laggproto.c:1.10	Thu Apr  4 07:31:10 2024
+++ src/sys/net/lagg/if_laggproto.c	Thu Apr  4 07:35:01 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.c,v 1.10 2024/04/04 07:31:10 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.11 2024/04/04 07:35:01 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.10 2024/04/04 07:31:10 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.11 2024/04/04 07:35:01 yamaguchi Exp $");
 
 #include 
 #include 
@@ -695,14 +695,18 @@ lagg_lb_transmit(struct lagg_proto_softc
 	int s;
 
 	lb = psc->psc_ctx;
-	hash  = lagg_hashmbuf(psc->psc_softc, m);
+	hash = lagg_hashmbuf(psc->psc_softc, m);
 
 	s = pserialize_read_enter();
 
 	pm = lagg_portmap_active(>lb_pmaps);
-	hash %= pm->pm_nports;
-	lp0 = pm->pm_ports[hash];
-	lp = lagg_link_active(psc, lp0->lp_proto_ctx, );
+	if (__predict_true(pm->pm_nports != 0)) {
+		hash %= pm->pm_nports;
+		lp0 = pm->pm_ports[hash];
+		lp = lagg_link_active(psc, lp0->lp_proto_ctx, );
+	} else {
+		lp = NULL;
+	}
 
 	pserialize_read_exit(s);
 



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:35:01 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
lagg(4): Added 0 length check


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/net/lagg/if_laggproto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:31:10 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
lagg(4): fix missing update of the number of active ports


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/net/lagg/if_laggproto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:31:10 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
lagg(4): fix missing update of the number of active ports


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/net/lagg/if_laggproto.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/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.9 src/sys/net/lagg/if_laggproto.c:1.10
--- src/sys/net/lagg/if_laggproto.c:1.9	Thu Apr  4 07:29:35 2024
+++ src/sys/net/lagg/if_laggproto.c	Thu Apr  4 07:31:10 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.c,v 1.9 2024/04/04 07:29:35 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.10 2024/04/04 07:31:10 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.9 2024/04/04 07:29:35 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.10 2024/04/04 07:31:10 yamaguchi Exp $");
 
 #include 
 #include 
@@ -674,6 +674,8 @@ lagg_lb_stopport(struct lagg_proto_softc
 		n++;
 	}
 
+	pm_next->pm_nports = n;
+
 	lagg_portmap_switch(>lb_pmaps);
 	pserialize_perform(psc->psc_psz);
 	LAGG_PROTO_UNLOCK(psc);



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:29:35 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
lagg(4): update link speed when a physical interface is removed


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/net/lagg/if_laggproto.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/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.8 src/sys/net/lagg/if_laggproto.c:1.9
--- src/sys/net/lagg/if_laggproto.c:1.8	Tue Nov 28 05:28:37 2023
+++ src/sys/net/lagg/if_laggproto.c	Thu Apr  4 07:29:35 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.c,v 1.8 2023/11/28 05:28:37 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.9 2024/04/04 07:29:35 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.8 2023/11/28 05:28:37 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.9 2024/04/04 07:29:35 yamaguchi Exp $");
 
 #include 
 #include 
@@ -365,6 +365,8 @@ lagg_common_stopport(struct lagg_proto_s
 
 		pport->lpp_active = false;
 	}
+
+	lagg_workq_add(psc->psc_workq, >psc_work_linkspeed);
 }
 static void
 lagg_common_linkstate(struct lagg_proto_softc *psc, struct lagg_port *lp)



CVS commit: src/sys/net/lagg

2024-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr  4 07:29:35 UTC 2024

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
lagg(4): update link speed when a physical interface is removed


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/net/lagg/if_laggproto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-12-01 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Dec  1 09:27:18 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): eliminate unnecessary reset by the change of if_flags


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-12-01 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Dec  1 09:27:18 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): eliminate unnecessary reset by the change of if_flags


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.56 src/sys/net/lagg/if_lagg.c:1.57
--- src/sys/net/lagg/if_lagg.c:1.56	Fri Dec  1 06:18:02 2023
+++ src/sys/net/lagg/if_lagg.c	Fri Dec  1 09:27:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.56 2023/12/01 06:18:02 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.57 2023/12/01 09:27:17 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.56 2023/12/01 06:18:02 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.57 2023/12/01 09:27:17 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -722,7 +722,6 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 			if_stop(ifp, 1);
 			break;
 		case IFF_UP:
-		case IFF_UP | IFF_RUNNING:
 			error = if_init(ifp);
 			break;
 		}



CVS commit: src/sys/net/lagg

2023-11-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Dec  1 06:18:02 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): use sadl for lagg(4) configured by a user


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.55 src/sys/net/lagg/if_lagg.c:1.56
--- src/sys/net/lagg/if_lagg.c:1.55	Tue Nov 28 05:28:37 2023
+++ src/sys/net/lagg/if_lagg.c	Fri Dec  1 06:18:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.55 2023/11/28 05:28:37 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.56 2023/12/01 06:18:02 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.55 2023/11/28 05:28:37 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.56 2023/12/01 06:18:02 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2229,13 +2229,20 @@ lagg_port_setup(struct lagg_softc *sc,
 	struct ifnet *ifp;
 	u_char if_type;
 	int error;
-	bool stopped, is_1st_port;
+	bool stopped, use_lagg_sadl;
 
 	KASSERT(LAGG_LOCKED(sc));
 	IFNET_ASSERT_UNLOCKED(ifp_port);
 
 	ifp = >sc_if;
-	is_1st_port = SIMPLEQ_EMPTY(>sc_ports);
+
+	use_lagg_sadl = true;
+	if (SIMPLEQ_EMPTY(>sc_ports) &&
+	ifp_port->if_type == IFT_ETHER) {
+		if (lagg_lladdr_equal(CLLADDR(ifp->if_sadl),
+		sc->sc_lladdr_rand))
+			use_lagg_sadl = false;
+	}
 
 	if (>sc_if == ifp_port) {
 		LAGG_DPRINTF(sc, "cannot add a lagg to itself as a port\n");
@@ -2303,11 +2310,14 @@ lagg_port_setup(struct lagg_softc *sc,
 	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) {
+
+	/* update Link address */
+	if (use_lagg_sadl) {
+		lagg_port_setsadl(lp, CLLADDR(ifp->if_sadl));
+	} else {
+		/* update if_type in if_sadl */
 		if (lp->lp_iftype != ifp_port->if_type)
 			lagg_port_setsadl(lp, NULL);
-	} else {
-		lagg_port_setsadl(lp, CLLADDR(ifp->if_sadl));
 	}
 
 	error = lagg_setmtu(ifp_port, ifp->if_mtu);
@@ -2328,13 +2338,9 @@ lagg_port_setup(struct lagg_softc *sc,
 	/* setup of ifp_port is complete */
 	IFNET_UNLOCK(ifp_port);
 
-	if (is_1st_port) {
-		if (lp->lp_iftype == IFT_ETHER &&
-		lagg_lladdr_equal(sc->sc_lladdr_rand,
-		CLLADDR(ifp->if_sadl))) {
-			lagg_if_setsadl(sc, lp->lp_lladdr);
-		}
-	}
+	/* copy sadl from added port to lagg */
+	if (!use_lagg_sadl)
+		lagg_if_setsadl(sc, lp->lp_lladdr);
 
 	SIMPLEQ_INSERT_TAIL(>sc_ports, lp, lp_entry);
 	sc->sc_nports++;



CVS commit: src/sys/net/lagg

2023-11-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Dec  1 06:18:02 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): use sadl for lagg(4) configured by a user


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-11-27 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Nov 28 05:28:37 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c if_laggproto.c if_laggproto.h

Log Message:
lagg(4): Fix missing IFNET_LOCK acquirement


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.7 -r1.8 src/sys/net/lagg/if_laggproto.c
cvs rdiff -u -r1.19 -r1.20 src/sys/net/lagg/if_laggproto.h

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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.54 src/sys/net/lagg/if_lagg.c:1.55
--- src/sys/net/lagg/if_lagg.c:1.54	Wed Nov 22 03:49:13 2023
+++ src/sys/net/lagg/if_lagg.c	Tue Nov 28 05:28:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.54 2023/11/22 03:49:13 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.55 2023/11/28 05:28:37 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.54 2023/11/22 03:49:13 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.55 2023/11/28 05:28:37 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -114,7 +114,7 @@ static const struct lagg_proto lagg_prot
 		.pr_startport = lagg_common_startport,
 		.pr_stopport = lagg_common_stopport,
 		.pr_portstat = lagg_fail_portstat,
-		.pr_linkstate = lagg_common_linkstate,
+		.pr_linkstate = lagg_common_linkstate_ifnet_locked,
 		.pr_ioctl = lagg_fail_ioctl,
 	},
 	[LAGG_PROTO_LOADBALANCE] = {
@@ -128,7 +128,7 @@ static const struct lagg_proto lagg_prot
 		.pr_startport = lagg_lb_startport,
 		.pr_stopport = lagg_lb_stopport,
 		.pr_portstat = lagg_lb_portstat,
-		.pr_linkstate = lagg_common_linkstate,
+		.pr_linkstate = lagg_common_linkstate_ifnet_locked,
 	},
 };
 

Index: src/sys/net/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.7 src/sys/net/lagg/if_laggproto.c:1.8
--- src/sys/net/lagg/if_laggproto.c:1.7	Wed Nov 22 03:49:13 2023
+++ src/sys/net/lagg/if_laggproto.c	Tue Nov 28 05:28:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.c,v 1.7 2023/11/22 03:49:13 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.8 2023/11/28 05:28:37 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.7 2023/11/22 03:49:13 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.8 2023/11/28 05:28:37 yamaguchi Exp $");
 
 #include 
 #include 
@@ -114,6 +114,8 @@ static struct lagg_port *
 static void	lagg_fail_linkspeed_work(struct lagg_work *, void *);
 static void	lagg_lb_linkspeed_work(struct lagg_work*,
 		void *);
+static void	lagg_common_linkstate(struct lagg_proto_softc *,
+		struct lagg_port *);
 
 static inline struct lagg_portmap *
 lagg_portmap_active(struct lagg_portmaps *maps)
@@ -364,9 +366,19 @@ lagg_common_stopport(struct lagg_proto_s
 		pport->lpp_active = false;
 	}
 }
+static void
+lagg_common_linkstate(struct lagg_proto_softc *psc, struct lagg_port *lp)
+{
+
+	IFNET_ASSERT_UNLOCKED(lp->lp_ifp);
+
+	IFNET_LOCK(lp->lp_ifp);
+	lagg_common_linkstate_ifnet_locked(psc, lp);
+	IFNET_UNLOCK(lp->lp_ifp);
+}
 
 void
-lagg_common_linkstate(struct lagg_proto_softc *psc, struct lagg_port *lp)
+lagg_common_linkstate_ifnet_locked(struct lagg_proto_softc *psc, struct lagg_port *lp)
 {
 	struct lagg_proto_port *pport;
 	struct ifnet *ifp, *ifp_port;
@@ -379,6 +391,8 @@ lagg_common_linkstate(struct lagg_proto_
 	is_active = lagg_portactive(lp);
 	ifp_port = lp->lp_ifp;
 
+	KASSERT(IFNET_LOCKED(ifp_port));
+
 	LAGG_PROTO_LOCK(psc);
 	if (!pport->lpp_running ||
 	pport->lpp_active == is_active) {

Index: src/sys/net/lagg/if_laggproto.h
diff -u src/sys/net/lagg/if_laggproto.h:1.19 src/sys/net/lagg/if_laggproto.h:1.20
--- src/sys/net/lagg/if_laggproto.h:1.19	Wed Nov 22 03:49:13 2023
+++ src/sys/net/lagg/if_laggproto.h	Tue Nov 28 05:28:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.h,v 1.19 2023/11/22 03:49:13 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.h,v 1.20 2023/11/28 05:28:37 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2021 Internet Initiative Japan Inc.
@@ -298,7 +298,7 @@ void		lagg_common_startport(struct lagg_
 		struct lagg_port *);
 void		lagg_common_stopport(struct lagg_proto_softc *,
 		struct lagg_port *);
-void		lagg_common_linkstate(struct lagg_proto_softc *,
+void		lagg_common_linkstate_ifnet_locked(struct lagg_proto_softc *,
 		struct lagg_port *);
 
 int		lagg_none_attach(struct lagg_softc *,



CVS commit: src/sys/net/lagg

2023-11-27 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Nov 28 05:28:37 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c if_laggproto.c if_laggproto.h

Log Message:
lagg(4): Fix missing IFNET_LOCK acquirement


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.7 -r1.8 src/sys/net/lagg/if_laggproto.c
cvs rdiff -u -r1.19 -r1.20 src/sys/net/lagg/if_laggproto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:52:58 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): Added logs about LACP processing


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.28 src/sys/net/lagg/if_lagg_lacp.c:1.29
--- src/sys/net/lagg/if_lagg_lacp.c:1.28	Wed Nov 22 03:49:13 2023
+++ src/sys/net/lagg/if_lagg_lacp.c	Wed Nov 22 03:52:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.28 2023/11/22 03:49:13 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.29 2023/11/22 03:52:58 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.28 2023/11/22 03:49:13 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.29 2023/11/22 03:52:58 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -2077,8 +2077,11 @@ lacp_disable_distributing(struct lacp_so
 
 	KASSERT(LACP_LOCKED(lsc));
 
-	LACP_DPRINTF((lsc, lacpp, "distributing disabled\n"));
-	CLR(lacpp->lp_actor.lpi_state, LACP_STATE_DISTRIBUTING);
+	if (ISSET(lacpp->lp_actor.lpi_state, LACP_STATE_DISTRIBUTING)) {
+		LAGG_LOG(lsc->lsc_softc, LOG_INFO,
+		"disable distributing on %s\n", LACP_PORT_XNAME(lacpp));
+		CLR(lacpp->lp_actor.lpi_state, LACP_STATE_DISTRIBUTING);
+	}
 
 	s = pserialize_read_enter();
 	act = LACP_PORTMAP_ACTIVE(lsc);
@@ -2105,7 +2108,8 @@ lacp_enable_distributing(struct lacp_sof
 
 	KASSERT(lacp_isactive(lsc, lacpp));
 
-	LACP_DPRINTF((lsc, lacpp, "distributing enabled\n"));
+	LAGG_LOG(lsc->lsc_softc, LOG_INFO,
+	"enable distributing on %s\n", LACP_PORT_XNAME(lacpp));
 	SET(lacpp->lp_actor.lpi_state, LACP_STATE_DISTRIBUTING);
 	lacp_suppress_distributing(lsc);
 	lacp_update_portmap(lsc);
@@ -2365,6 +2369,8 @@ static void
 lacp_selected_update(struct lacp_softc *lsc, struct lacp_aggregator *la)
 {
 	struct lacp_port *lacpp;
+	enum lacp_selected next_selected;
+	const char *msg;
 	size_t nselected;
 	uint64_t linkspeed;
 
@@ -2377,23 +2383,31 @@ lacp_selected_update(struct lacp_softc *
 	linkspeed = lacpp->lp_linkspeed;
 	nselected = 0;
 	LIST_FOREACH(lacpp, >la_ports, lp_entry_la) {
-		if (nselected >= lsc->lsc_max_ports ||
-		(!lsc->lsc_multi_linkspeed && linkspeed != lacpp->lp_linkspeed)) {
-			if (lacpp->lp_selected == LACP_SELECTED)
-lacpp->lp_selected = LACP_STANDBY;
+		if (lacpp->lp_selected == LACP_UNSELECTED)
+			continue;
+
+		next_selected = LACP_SELECTED;
+		msg = " is selected";
+
+		if (nselected >= lsc->lsc_max_ports) {
+			next_selected = LACP_STANDBY;
+			msg = " is standby because of too many active ports";
 		}
 
-		switch (lacpp->lp_selected) {
-		case LACP_STANDBY:
-			lacpp->lp_selected = LACP_SELECTED;
-			/* fall through */
-		case LACP_SELECTED:
-			nselected++;
-			break;
-		default:
-			/* do nothing */
-			break;
+		if (!lsc->lsc_multi_linkspeed &&
+		linkspeed != lacpp->lp_linkspeed) {
+			next_selected = LACP_STANDBY;
+			msg = " is standby because of link speed mismatch";
+		}
+
+		if (lacpp->lp_selected != next_selected) {
+			lacpp->lp_selected = next_selected;
+			LAGG_LOG(lsc->lsc_softc, LOG_INFO,
+			"%s%s\n", LACP_PORT_XNAME(lacpp), msg);
 		}
+
+		if (lacpp->lp_selected == LACP_SELECTED)
+			nselected++;
 	}
 }
 



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:52:58 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg(4): Added logs about LACP processing


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:49:13 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c if_lagg_lacp.h
if_laggproto.c if_laggproto.h

Log Message:
Set the fastest linkspeed in each physical interface to lagg(4)


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.27 -r1.28 src/sys/net/lagg/if_lagg_lacp.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/lagg/if_lagg_lacp.h
cvs rdiff -u -r1.6 -r1.7 src/sys/net/lagg/if_laggproto.c
cvs rdiff -u -r1.18 -r1.19 src/sys/net/lagg/if_laggproto.h

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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.53 src/sys/net/lagg/if_lagg.c:1.54
--- src/sys/net/lagg/if_lagg.c:1.53	Wed Nov 22 03:30:57 2023
+++ src/sys/net/lagg/if_lagg.c	Wed Nov 22 03:49:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.53 2023/11/22 03:30:57 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.54 2023/11/22 03:49:13 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.53 2023/11/22 03:30:57 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.54 2023/11/22 03:49:13 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1217,6 +1217,9 @@ lagg_media_status(struct ifnet *ifp, str
 	imr->ifm_active = IFM_ETHER | IFM_AUTO;
 
 	LAGG_LOCK(sc);
+
+	imr->ifm_active |= sc->sc_media_active;
+
 	LAGG_PORTS_FOREACH(sc, lp) {
 		if (lagg_portactive(lp))
 			imr->ifm_status |= IFM_ACTIVE;
@@ -1224,6 +1227,52 @@ lagg_media_status(struct ifnet *ifp, str
 	LAGG_UNLOCK(sc);
 }
 
+static uint64_t
+lagg_search_media_type(uint64_t linkspeed)
+{
+
+	if (linkspeed == IF_Gbps(40))
+		return IFM_40G_T | IFM_FDX;
+
+	if (linkspeed == IF_Gbps(25))
+		return IFM_25G_T | IFM_FDX;
+
+	if (linkspeed == IF_Gbps(10))
+		return IFM_10G_T | IFM_FDX;
+
+	if (linkspeed == IF_Gbps(5))
+		return IFM_5000_T | IFM_FDX;
+
+	if (linkspeed == IF_Mbps(2500))
+		return IFM_2500_T | IFM_FDX;
+
+	if (linkspeed == IF_Gbps(1))
+		return IFM_1000_T | IFM_FDX;
+
+	if (linkspeed == IF_Mbps(100))
+		return IFM_100_TX | IFM_FDX;
+
+	if (linkspeed == IF_Mbps(10))
+		return IFM_10_T | IFM_FDX;
+
+	return 0;
+}
+
+void
+lagg_set_linkspeed(struct lagg_softc *sc, uint64_t linkspeed)
+{
+	struct ifnet *ifp;
+
+	ifp = >sc_if;
+
+	KASSERT(LAGG_LOCKED(sc));
+
+	ifp->if_baudrate = linkspeed;
+
+	sc->sc_media_active =
+	lagg_search_media_type(linkspeed);
+}
+
 static int
 lagg_port_vlan_cb(struct lagg_port *lp,
 struct lagg_vlantag *lvt, bool set)
@@ -1630,6 +1679,8 @@ lagg_pr_attach(struct lagg_softc *sc, la
 		lagg_proto_detach(oldvar);
 		cleanup_oldvar = true;
 	}
+
+	lagg_set_linkspeed(sc, 0);
 done:
 	LAGG_UNLOCK(sc);
 

Index: src/sys/net/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.27 src/sys/net/lagg/if_lagg_lacp.c:1.28
--- src/sys/net/lagg/if_lagg_lacp.c:1.27	Wed Nov 22 03:27:00 2023
+++ src/sys/net/lagg/if_lagg_lacp.c	Wed Nov 22 03:49:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.27 2023/11/22 03:27:00 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.28 2023/11/22 03:49:13 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.27 2023/11/22 03:27:00 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.28 2023/11/22 03:49:13 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -126,7 +126,7 @@ struct lacp_port {
 	struct lacp_aggregator	*lp_aggregator;
 	struct lacp_aggregator_systemid
  lp_aggregator_sidbuf;
-	uint32_t		 lp_media;
+	uint64_t		 lp_linkspeed;
 	int			 lp_pending;
 	LIST_ENTRY(lacp_port)	 lp_entry_la;
 	struct timeval		 lp_last_lacpdu;
@@ -165,6 +165,7 @@ struct lacp_softc {
 	struct workqueue	*lsc_workq;
 	struct lagg_work	 lsc_work_tick;
 	struct lagg_work	 lsc_work_rcvdu;
+	struct lagg_work	 lsc_work_linkspeed;
 	callout_t		 lsc_tick;
 	pcq_t			*lsc_du_q;
 
@@ -247,7 +248,6 @@ static void	lacp_dprintf(const struct la
 static void	lacp_tick(void *);
 static void	lacp_tick_work(struct lagg_work *, void *);
 static void	lacp_linkstate(struct lagg_proto_softc *, struct lagg_port *);
-static uint32_t	lacp_ifmedia2lacpmedia(u_int);
 static void	lacp_port_disable(struct lacp_softc *, struct lacp_port *);
 static void	lacp_port_enable(struct lacp_softc *, struct lacp_port *);
 static void	lacp_peerinfo_actor(struct lacp_softc *, struct lacp_port *,
@@ -285,6 +285,7 @@ static void	lacp_sm_ptx_update_timeout(s
 
 static void	lacp_rcvdu_work(struct lagg_work *, void *);
 static void	lacp_marker_work(struct lagg_work *, void *);
+static void	lacp_linkspeed_work(struct lagg_work *, void *);
 static void	lacp_dump_lacpdutlv(const struct lacpdu_peerinfo *,
 		const struct lacpdu_peerinfo *,
 		

CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:49:13 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c if_lagg_lacp.h
if_laggproto.c if_laggproto.h

Log Message:
Set the fastest linkspeed in each physical interface to lagg(4)


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.27 -r1.28 src/sys/net/lagg/if_lagg_lacp.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/lagg/if_lagg_lacp.h
cvs rdiff -u -r1.6 -r1.7 src/sys/net/lagg/if_laggproto.c
cvs rdiff -u -r1.18 -r1.19 src/sys/net/lagg/if_laggproto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:30:57 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
Set ETHERCAP_VLAN_HWTAGGING on lagg(4)
that doesn't has physical interfaces


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:30:57 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
Set ETHERCAP_VLAN_HWTAGGING on lagg(4)
that doesn't has physical interfaces


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.52 src/sys/net/lagg/if_lagg.c:1.53
--- src/sys/net/lagg/if_lagg.c:1.52	Wed Nov 22 03:28:57 2023
+++ src/sys/net/lagg/if_lagg.c	Wed Nov 22 03:30:57 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.52 2023/11/22 03:28:57 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.53 2023/11/22 03:30:57 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.52 2023/11/22 03:28:57 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.53 2023/11/22 03:30:57 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -365,6 +365,7 @@ lagg_clone_create(struct if_clone *ifc, 
 {
 	struct lagg_softc *sc;
 	struct ifnet *ifp;
+	struct ethercom *ec;
 	int error;
 
 	sc = lagg_softc_alloc(lagg_iftype);
@@ -406,11 +407,19 @@ lagg_clone_create(struct if_clone *ifc, 
 
 	switch (lagg_iftype) {
 	case LAGG_IF_TYPE_ETHERNET:
+		ec = (struct ethercom *)ifp;
 		cprng_fast(sc->sc_lladdr_rand, sizeof(sc->sc_lladdr_rand));
 		sc->sc_lladdr_rand[0] &= 0xFE; /* clear I/G bit */
 		sc->sc_lladdr_rand[0] |= 0x02; /* set G/L bit */
 		lagg_lladdr_cpy(sc->sc_lladdr, sc->sc_lladdr_rand);
-		ether_set_vlan_cb((struct ethercom *)ifp, lagg_vlan_cb);
+		ether_set_vlan_cb(ec, lagg_vlan_cb);
+
+		/*
+		 * notify ETHERCAP_VLAN_HWTAGGING to ether_ifattach
+		 * to handle VLAN tag, stripped by hardware, in bpf(4)
+		 */
+		ec->ec_capabilities = ETHERCAP_VLAN_HWTAGGING;
+
 		ether_ifattach(ifp, sc->sc_lladdr_rand);
 		break;
 	default:
@@ -1972,31 +1981,31 @@ lagg_ethercap_update(struct lagg_softc *
 	if (sc->sc_if.if_type != IFT_ETHER)
 		return;
 
-	/* Get common enabled capabilities for the lagg ports */
-	ena = ~0;
-	cap = ~0;
-	LAGG_PORTS_FOREACH(sc, lp) {
-		switch (lp->lp_iftype) {
-		case IFT_ETHER:
-			ec = (struct ethercom *)lp->lp_ifp;
-			ena &= ec->ec_capenable;
-			cap &= ec->ec_capabilities;
-			break;
-		case IFT_L2TP:
-			ena &= (ETHERCAP_VLAN_MTU | ETHERCAP_JUMBO_MTU);
-			cap &= (ETHERCAP_VLAN_MTU | ETHERCAP_JUMBO_MTU);
-			break;
-		default:
-			ena = 0;
-			cap = 0;
+	if (SIMPLEQ_EMPTY(>sc_ports)) {
+		ena = 0;
+		cap = ETHERCAP_VLAN_HWTAGGING;
+	} else {
+		/* Get common enabled capabilities for the lagg ports */
+		ena = ~0;
+		cap = ~0;
+		LAGG_PORTS_FOREACH(sc, lp) {
+			switch (lp->lp_iftype) {
+			case IFT_ETHER:
+ec = (struct ethercom *)lp->lp_ifp;
+ena &= ec->ec_capenable;
+cap &= ec->ec_capabilities;
+break;
+			case IFT_L2TP:
+ena &= (ETHERCAP_VLAN_MTU | ETHERCAP_JUMBO_MTU);
+cap &= (ETHERCAP_VLAN_MTU | ETHERCAP_JUMBO_MTU);
+break;
+			default:
+ena = 0;
+cap = 0;
+			}
 		}
 	}
 
-	if (ena == ~0)
-		ena = 0;
-	if (cap == ~0)
-		cap = 0;
-
 	/*
 	 * Apply common enabled capabilities back to the lagg ports.
 	 * May require several iterations if they are dependent.



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:28:57 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): Fix missing pfil_run_hooks() and bpf_mtap()


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.51 src/sys/net/lagg/if_lagg.c:1.52
--- src/sys/net/lagg/if_lagg.c:1.51	Wed Oct 18 06:37:08 2023
+++ src/sys/net/lagg/if_lagg.c	Wed Nov 22 03:28:57 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.51 2023/10/18 06:37:08 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.52 2023/11/22 03:28:57 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.51 2023/10/18 06:37:08 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.52 2023/11/22 03:28:57 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1056,6 +1056,11 @@ lagg_output(struct lagg_softc *sc, struc
 	len = m->m_pkthdr.len;
 	mflags = m->m_flags;
 
+	error = pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_OUT);
+	if (error != 0)
+		return;
+	bpf_mtap(ifp, m, BPF_D_OUT);
+
 	error = lagg_port_xmit(lp, m);
 	if (error) {
 		/* mbuf is already freed */



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:28:57 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): Fix missing pfil_run_hooks() and bpf_mtap()


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:27:00 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
Update sending interval when the partner's state is changed


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.26 src/sys/net/lagg/if_lagg_lacp.c:1.27
--- src/sys/net/lagg/if_lagg_lacp.c:1.26	Wed Nov 22 03:23:54 2023
+++ src/sys/net/lagg/if_lagg_lacp.c	Wed Nov 22 03:27:00 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.26 2023/11/22 03:23:54 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.27 2023/11/22 03:27:00 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.26 2023/11/22 03:23:54 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.27 2023/11/22 03:27:00 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -1689,6 +1689,8 @@ lacp_sm_rx_record_default(struct lacp_so
 		LACP_STATE_STR(pi->lpi_state, buf, sizeof(buf));
 		LACP_DPRINTF((lsc, lacpp, "newpstate %s\n", buf));
 	}
+
+	lacp_sm_ptx_update_timeout(lacpp, oldpstate);
 }
 
 static inline bool
@@ -1764,12 +1766,17 @@ lacp_sm_rx_record_peerinfo(struct lacp_s
 static void
 lacp_sm_rx_set_expired(struct lacp_port *lacpp)
 {
+	uint8_t oldpstate;
+
+	oldpstate = lacpp->lp_partner.lpi_state;
 
 	CLR(lacpp->lp_partner.lpi_state, LACP_STATE_SYNC);
 	SET(lacpp->lp_partner.lpi_state, LACP_STATE_TIMEOUT);
 	LACP_TIMER_ARM(lacpp, LACP_TIMER_CURRENT_WHILE,
 	LACP_SHORT_TIMEOUT_TIME);
 	SET(lacpp->lp_actor.lpi_state, LACP_STATE_EXPIRED);
+
+	lacp_sm_ptx_update_timeout(lacpp, oldpstate);
 }
 
 static void



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:27:00 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
Update sending interval when the partner's state is changed


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:23:54 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
Change LACPDU sending interval by TIMEOUT bit in partner's state


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.25 src/sys/net/lagg/if_lagg_lacp.c:1.26
--- src/sys/net/lagg/if_lagg_lacp.c:1.25	Sun Apr 10 09:50:46 2022
+++ src/sys/net/lagg/if_lagg_lacp.c	Wed Nov 22 03:23:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.25 2022/04/10 09:50:46 andvar Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.26 2023/11/22 03:23:54 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.25 2022/04/10 09:50:46 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.26 2023/11/22 03:23:54 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -1855,7 +1855,7 @@ lacp_sm_ptx_schedule(struct lacp_port *l
 	if (LACP_TIMER_ISARMED(lacpp, LACP_TIMER_PERIODIC))
 		return;
 
-	timeout = ISSET(lacpp->lp_actor.lpi_state, LACP_STATE_TIMEOUT) ?
+	timeout = ISSET(lacpp->lp_partner.lpi_state, LACP_STATE_TIMEOUT) ?
 		LACP_FAST_PERIODIC_TIME : LACP_SLOW_PERIODIC_TIME;
 
 	LACP_TIMER_ARM(lacpp, LACP_TIMER_PERIODIC, timeout);



CVS commit: src/sys/net/lagg

2023-11-21 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 22 03:23:54 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
Change LACPDU sending interval by TIMEOUT bit in partner's state


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-10-18 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Oct 18 06:37:08 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
copy MTU of lagg to a interface added to lagg
even if the interface is the first member of the lagg

This change breaks ATF test case for lagg MTU


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.50 src/sys/net/lagg/if_lagg.c:1.51
--- src/sys/net/lagg/if_lagg.c:1.50	Mon Oct 16 08:25:57 2023
+++ src/sys/net/lagg/if_lagg.c	Wed Oct 18 06:37:08 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.50 2023/10/16 08:25:57 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.51 2023/10/18 06:37:08 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.50 2023/10/16 08:25:57 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.51 2023/10/18 06:37:08 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2243,11 +2243,12 @@ lagg_port_setup(struct lagg_softc *sc,
 			lagg_port_setsadl(lp, NULL);
 	} else {
 		lagg_port_setsadl(lp, CLLADDR(ifp->if_sadl));
-		error = lagg_setmtu(ifp_port, ifp->if_mtu);
-		if (error != 0)
-			goto restore_sadl;
 	}
 
+	error = lagg_setmtu(ifp_port, ifp->if_mtu);
+	if (error != 0)
+		goto restore_sadl;
+
 	error = lagg_proto_allocport(sc, lp);
 	if (error != 0)
 		goto restore_mtu;
@@ -2263,9 +2264,6 @@ lagg_port_setup(struct lagg_softc *sc,
 	IFNET_UNLOCK(ifp_port);
 
 	if (is_1st_port) {
-		error = lagg_setmtu(ifp, lp->lp_mtu);
-		if (error != 0)
-			goto restore_ifp_port;
 		if (lp->lp_iftype == IFT_ETHER &&
 		lagg_lladdr_equal(sc->sc_lladdr_rand,
 		CLLADDR(ifp->if_sadl))) {
@@ -2285,11 +2283,6 @@ lagg_port_setup(struct lagg_softc *sc,
 
 	return 0;
 
-restore_ifp_port:
-	IFNET_LOCK(ifp_port);
-	if (stopped) {
-		if_stop(ifp_port, 0);
-	}
 free_port:
 	KASSERT(IFNET_LOCKED(ifp_port));
 	lagg_proto_freeport(sc, lp);



CVS commit: src/sys/net/lagg

2023-10-18 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Oct 18 06:37:08 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
copy MTU of lagg to a interface added to lagg
even if the interface is the first member of the lagg

This change breaks ATF test case for lagg MTU


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-10-16 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Oct 16 08:25:57 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
Fix missing IFNET_LOCK holding while destroy the lagg interface


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.49 src/sys/net/lagg/if_lagg.c:1.50
--- src/sys/net/lagg/if_lagg.c:1.49	Mon Oct 16 07:49:01 2023
+++ src/sys/net/lagg/if_lagg.c	Mon Oct 16 08:25:57 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.49 2023/10/16 07:49:01 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.50 2023/10/16 08:25:57 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.49 2023/10/16 07:49:01 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.50 2023/10/16 08:25:57 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -444,11 +444,13 @@ lagg_clone_destroy(struct ifnet *ifp)
 
 	lagg_stop(ifp, 1);
 
+	IFNET_LOCK(ifp);
 	LAGG_LOCK(sc);
 	while ((lp = LAGG_PORTS_FIRST(sc)) != NULL) {
 		lagg_port_teardown(sc, lp, false);
 	}
 	LAGG_UNLOCK(sc);
+	IFNET_UNLOCK(ifp);
 
 	switch (ifp->if_type) {
 	case IFT_ETHER:



CVS commit: src/sys/net/lagg

2023-10-16 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Oct 16 08:25:57 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
Fix missing IFNET_LOCK holding while destroy the lagg interface


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-10-16 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Oct 16 07:49:01 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): release LAGG_LOCK before mtu changing

PR kern/57650


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2023-10-16 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Oct 16 07:49:01 UTC 2023

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg(4): release LAGG_LOCK before mtu changing

PR kern/57650


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.48 src/sys/net/lagg/if_lagg.c:1.49
--- src/sys/net/lagg/if_lagg.c:1.48	Sun Jun 26 17:55:24 2022
+++ src/sys/net/lagg/if_lagg.c	Mon Oct 16 07:49:01 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.48 2022/06/26 17:55:24 riastradh Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.49 2023/10/16 07:49:01 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.48 2022/06/26 17:55:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.49 2023/10/16 07:49:01 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -727,8 +727,8 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 		LAGG_UNLOCK(sc);
 		break;
 	case SIOCSIFMTU:
-		LAGG_LOCK(sc);
 		/* set the MTU to each port */
+		LAGG_LOCK(sc);
 		LAGG_PORTS_FOREACH(sc, lp) {
 			error = lagg_lp_ioctl(lp, cmd, (void *)ifr);
 
@@ -742,6 +742,7 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 break;
 			}
 		}
+		LAGG_UNLOCK(sc);
 
 		/* set the MTU to the lagg interface */
 		if (error == 0)
@@ -750,12 +751,14 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 		if (error != 0) {
 			/* undo the changed MTU */
 			ifr->ifr_mtu = ifp->if_mtu;
+
+			LAGG_LOCK(sc);
 			LAGG_PORTS_FOREACH(sc, lp) {
 if (lp->lp_ioctl != NULL)
 	lagg_lp_ioctl(lp, cmd, (void *)ifr);
 			}
+			LAGG_UNLOCK(sc);
 		}
-		LAGG_UNLOCK(sc);
 		break;
 	case SIOCADDMULTI:
 		if (sc->sc_if.if_type == IFT_ETHER) {



CVS commit: src/sys/net/lagg

2022-06-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 26 17:55:24 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_laggproto.h

Log Message:
lagg(4): Safely handle misaligned mbufs.

Optimizing for non-strict-alignment architectures -- without falling
afoul of alignment sanitizers or overeager compilers -- is left as an
exercise for the reader.

PR kern/56894


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.17 -r1.18 src/sys/net/lagg/if_laggproto.h

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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.47 src/sys/net/lagg/if_lagg.c:1.48
--- src/sys/net/lagg/if_lagg.c:1.47	Mon Apr  4 09:59:41 2022
+++ src/sys/net/lagg/if_lagg.c	Sun Jun 26 17:55:24 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.47 2022/04/04 09:59:41 martin Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.48 2022/06/26 17:55:24 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.47 2022/04/04 09:59:41 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.48 2022/06/26 17:55:24 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -895,7 +895,7 @@ lagg_hashmbuf(struct lagg_softc *sc, str
 	*(hp) = hash32_buf(&(v), sizeof(v), *(hp));	\
 } while(0)
 
-	eh = lagg_m_extract(m, 0, sizeof(*eh), );
+	eh = lagg_m_extract(m, 0, sizeof(*eh), __alignof(*eh), );
 	if (eh == NULL)
 		goto out;
 
@@ -903,7 +903,8 @@ lagg_hashmbuf(struct lagg_softc *sc, str
 	etype = ntohs(eh->ether_type);
 
 	if (etype == ETHERTYPE_VLAN) {
-		evl = lagg_m_extract(m, 0, sizeof(*evl), );
+		evl = lagg_m_extract(m, 0, sizeof(*evl), __alignof(*evl),
+		);
 		if (evl == NULL)
 			goto out;
 
@@ -924,7 +925,7 @@ lagg_hashmbuf(struct lagg_softc *sc, str
 
 	switch (etype) {
 	case ETHERTYPE_IP:
-		ip = lagg_m_extract(m, off, sizeof(*ip), );
+		ip = lagg_m_extract(m, off, sizeof(*ip), __alignof(*ip), );
 		if (ip == NULL)
 			goto out;
 
@@ -937,7 +938,8 @@ lagg_hashmbuf(struct lagg_softc *sc, str
 		proto = ip->ip_p;
 		break;
 	case ETHERTYPE_IPV6:
-		ip6 = lagg_m_extract(m, off, sizeof(*ip6), );
+		ip6 = lagg_m_extract(m, off, sizeof(*ip6), __alignof(*ip6),
+		);
 		if (ip6 == NULL)
 			goto out;
 
@@ -957,7 +959,7 @@ lagg_hashmbuf(struct lagg_softc *sc, str
 
 	switch (proto) {
 	case IPPROTO_TCP:
-		th = lagg_m_extract(m, off, sizeof(*th), );
+		th = lagg_m_extract(m, off, sizeof(*th), __alignof(*th), );
 		if (th == NULL)
 			goto out;
 
@@ -967,7 +969,7 @@ lagg_hashmbuf(struct lagg_softc *sc, str
 		}
 		break;
 	case IPPROTO_UDP:
-		uh = lagg_m_extract(m, off, sizeof(*uh), );
+		uh = lagg_m_extract(m, off, sizeof(*uh), __alignof(*uh), );
 		if (uh == NULL)
 			goto out;
 

Index: src/sys/net/lagg/if_laggproto.h
diff -u src/sys/net/lagg/if_laggproto.h:1.17 src/sys/net/lagg/if_laggproto.h:1.18
--- src/sys/net/lagg/if_laggproto.h:1.17	Tue May 24 20:50:20 2022
+++ src/sys/net/lagg/if_laggproto.h	Sun Jun 26 17:55:24 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.h,v 1.17 2022/05/24 20:50:20 andvar Exp $	*/
+/*	$NetBSD: if_laggproto.h,v 1.18 2022/06/26 17:55:24 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2021 Internet Initiative Japan Inc.
@@ -217,7 +217,8 @@ struct lagg_softc {
 	(_lp)->lp_ioctl((_lp)->lp_ifp, (_cmd), (_data))
 
 static inline const void *
-lagg_m_extract(struct mbuf *m, size_t off, size_t reqlen, void *buf)
+lagg_m_extract(struct mbuf *m, size_t off, size_t reqlen, size_t align,
+void *buf)
 {
 	ssize_t len;
 	const void *rv;
@@ -229,7 +230,8 @@ lagg_m_extract(struct mbuf *m, size_t of
 		return NULL;
 	}
 
-	if (m->m_len >= len) {
+	if (m->m_len >= len &&
+	((uintptr_t)(mtod(m, uint8_t *) + off) % align) == 0) {
 		rv = mtod(m, uint8_t *) + off;
 	} else {
 		m_copydata(m, off, reqlen, buf);



CVS commit: src/sys/net/lagg

2022-06-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 26 17:55:24 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_laggproto.h

Log Message:
lagg(4): Safely handle misaligned mbufs.

Optimizing for non-strict-alignment architectures -- without falling
afoul of alignment sanitizers or overeager compilers -- is left as an
exercise for the reader.

PR kern/56894


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.17 -r1.18 src/sys/net/lagg/if_laggproto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2022-04-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Apr  4 09:59:42 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
Avoid signed/unsigned comparision by casting the sizeof expression.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.46 src/sys/net/lagg/if_lagg.c:1.47
--- src/sys/net/lagg/if_lagg.c:1.46	Mon Apr  4 06:10:00 2022
+++ src/sys/net/lagg/if_lagg.c	Mon Apr  4 09:59:41 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.46 2022/04/04 06:10:00 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.47 2022/04/04 09:59:41 martin Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.46 2022/04/04 06:10:00 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.47 2022/04/04 09:59:41 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1121,7 +1121,7 @@ lagg_input_ethernet(struct ifnet *ifp_po
 	 * if we are not in promiscuous mode.
 	 */
 
-	if (__predict_false(m->m_len < sizeof(*eh))) {
+	if (__predict_false(m->m_len < (int)sizeof(*eh))) {
 		if ((m = m_pullup(m, sizeof(*eh))) == NULL) {
 			if_statinc(ifp, if_ierrors);
 			goto out;



CVS commit: src/sys/net/lagg

2022-04-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Apr  4 09:59:42 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
Avoid signed/unsigned comparision by casting the sizeof expression.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2022-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Apr  4 06:12:27 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
Fix missing m_reset_rcvif for allocated mbuf


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.23 src/sys/net/lagg/if_lagg_lacp.c:1.24
--- src/sys/net/lagg/if_lagg_lacp.c:1.23	Mon Apr  4 06:10:00 2022
+++ src/sys/net/lagg/if_lagg_lacp.c	Mon Apr  4 06:12:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.23 2022/04/04 06:10:00 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.24 2022/04/04 06:12:27 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.23 2022/04/04 06:10:00 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.24 2022/04/04 06:12:27 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -1383,6 +1383,7 @@ lacp_lacpdu_mbuf(struct lacp_softc *lsc,
 	}
 
 	m->m_pkthdr.len = m->m_len = sizeof(*du);
+	m_reset_rcvif(m);
 
 	du = mtod(m, struct lacpdu *);
 	memset(du, 0, sizeof(*du));
@@ -2542,6 +2543,7 @@ lacp_markerdu_mbuf(struct lacp_softc *ls
 	}
 
 	m->m_pkthdr.len = m->m_len = sizeof(*mdu);
+	m_reset_rcvif(m);
 
 	mdu = mtod(m, struct markerdu *);
 



CVS commit: src/sys/net/lagg

2022-04-04 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Apr  4 06:12:27 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
Fix missing m_reset_rcvif for allocated mbuf


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2022-04-01 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  1 07:26:51 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c

Log Message:
lagg(4): reimplement add and delete port

The IFNET_LOCK for the adding or deleting port became to
be held the whole time while the ifnet of the port is changed.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.21 -r1.22 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.44 src/sys/net/lagg/if_lagg.c:1.45
--- src/sys/net/lagg/if_lagg.c:1.44	Thu Mar 31 07:59:05 2022
+++ src/sys/net/lagg/if_lagg.c	Fri Apr  1 07:26:51 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.44 2022/03/31 07:59:05 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.45 2022/04/01 07:26:51 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.44 2022/03/31 07:59:05 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.45 2022/04/01 07:26:51 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -133,7 +133,7 @@ static const struct lagg_proto lagg_prot
 	},
 };
 
-static int	lagg_chg_sadl(struct ifnet *, uint8_t *, size_t);
+static int	lagg_chg_sadl(struct ifnet *, const uint8_t *, size_t);
 static struct mbuf *
 		lagg_input_ethernet(struct ifnet *, struct mbuf *);
 static int	lagg_clone_create(struct if_clone *, int);
@@ -195,10 +195,10 @@ static void	lagg_port_teardown(struct la
 		bool);
 static void	lagg_port_syncvlan(struct lagg_softc *, struct lagg_port *);
 static void	lagg_port_purgevlan(struct lagg_softc *, struct lagg_port *);
-static void	lagg_lladdr_update(struct lagg_softc *);
 static void	lagg_capabilities_update(struct lagg_softc *);
 static void	lagg_sync_ifcaps(struct lagg_softc *);
 static void	lagg_sync_ethcaps(struct lagg_softc *);
+static void	lagg_sync_sadl(struct lagg_softc *);
 
 static struct if_clone	 lagg_cloner =
 IF_CLONE_INITIALIZER("lagg", lagg_clone_create, lagg_clone_destroy);
@@ -212,11 +212,13 @@ static enum lagg_iftypes
 		 lagg_iftype = LAGG_IF_TYPE_ETHERNET;
 
 #ifdef LAGG_DEBUG
+#define __LAGGDEBUGUSED
 #define LAGG_DPRINTF(_sc, _fmt, _args...)	do {	\
 	printf("%s: " _fmt, (_sc) != NULL ?		\
 	(_sc)->sc_if.if_xname : "lagg", ##_args);		\
 } while (0)
 #else
+#define __LAGGDEBUGUSED__unused
 #define LAGG_DPRINTF(_sc, _fmt, _args...)	__nothing
 #endif
 
@@ -413,7 +415,7 @@ lagg_clone_create(struct if_clone *ifc, 
 		sc->sc_lladdr_rand[0] |= 0x02; /* set G/L bit */
 		lagg_lladdr_cpy(sc->sc_lladdr, sc->sc_lladdr_rand);
 		ether_set_vlan_cb((struct ethercom *)ifp, lagg_vlan_cb);
-		ether_ifattach(ifp, sc->sc_lladdr);
+		ether_ifattach(ifp, sc->sc_lladdr_rand);
 		break;
 	default:
 		panic("unknown if type");
@@ -500,7 +502,7 @@ lagg_init_locked(struct lagg_softc *sc)
 	if (ISSET(ifp->if_flags, IFF_RUNNING))
 		lagg_stop_locked(sc);
 
-	lagg_lladdr_update(sc);
+	lagg_sync_sadl(sc);
 
 	SET(ifp->if_flags, IFF_RUNNING);
 
@@ -2009,85 +2011,42 @@ lagg_capabilities_update(struct lagg_sof
 }
 
 static int
-lagg_setup_mtu(struct lagg_softc *sc, struct lagg_port *lp)
+lagg_setmtu(struct ifnet *ifp, uint64_t mtu)
 {
-	struct ifnet *ifp, *ifp_port;
+	struct lagg_softc *sc __LAGGDEBUGUSED;
+	struct lagg_port *lp;
 	struct ifreq ifr;
 	int error;
 
-	ifp = >sc_if;
-	ifp_port = lp->lp_ifp;
-
-	KASSERT(IFNET_LOCKED(ifp_port));
+	KASSERT(IFNET_LOCKED(ifp));
 
-	error = 0;
 	memset(, 0, sizeof(ifr));
+	ifr.ifr_mtu = mtu;
+	lp = ifp->if_lagg;
 
-	if (SIMPLEQ_EMPTY(>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, );
-		}
+	if (lp != NULL) {
+		/* ioctl for port interface */
+		error = lp->lp_ioctl(ifp, SIOCSIFMTU, );
+		sc = lp->lp_softc;
 	} else {
-		ifr.ifr_mtu = sc->sc_if.if_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;
-			}
+		/* ioctl for lagg interface */
+		error = ether_ioctl(ifp, SIOCSIFMTU, );
+		sc = ifp->if_softc;
+	}
 
-			strlcpy(ifr.ifr_name, ifp_port->if_xname,
-			sizeof(ifr.ifr_name));
-			error = lp->lp_ioctl(ifp_port,
-			SIOCSIFMTU, (void *));
-			if (error != 0) {
-LAGG_DPRINTF(sc,
-"invalid MTU %d for %s\n",
-ifr.ifr_mtu, ifp_port->if_xname);
-			}
-		}
+	if (error != 0) {
+		LAGG_DPRINTF(sc,
+		"couldn't change MTU for %s\n",
+		ifp->if_xname);
 	}
 
 	return error;
 }
 
 static void
-lagg_teardown_mtu(struct lagg_softc *sc, struct lagg_port *lp)
-{
-	struct ifnet *ifp_port;
-	struct ifreq ifr;
-	int error;
-
-	if (lp->lp_ioctl == NULL)
-		return;
-
-	ifp_port = lp->lp_ifp;

CVS commit: src/sys/net/lagg

2022-04-01 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr  1 07:26:51 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c

Log Message:
lagg(4): reimplement add and delete port

The IFNET_LOCK for the adding or deleting port became to
be held the whole time while the ifnet of the port is changed.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.21 -r1.22 src/sys/net/lagg/if_lagg_lacp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2022-03-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Mar 31 07:59:05 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c if_laggproto.c
if_laggproto.h

Log Message:
rename lagg_enqueue to lagg_output

NFC


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.20 -r1.21 src/sys/net/lagg/if_lagg_lacp.c
cvs rdiff -u -r1.5 -r1.6 src/sys/net/lagg/if_laggproto.c
cvs rdiff -u -r1.14 -r1.15 src/sys/net/lagg/if_laggproto.h

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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.43 src/sys/net/lagg/if_lagg.c:1.44
--- src/sys/net/lagg/if_lagg.c:1.43	Thu Mar 31 03:21:33 2022
+++ src/sys/net/lagg/if_lagg.c	Thu Mar 31 07:59:05 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.43 2022/03/31 03:21:33 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.44 2022/03/31 07:59:05 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.43 2022/03/31 03:21:33 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.44 2022/03/31 07:59:05 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1041,7 +1041,7 @@ lagg_start(struct ifnet *ifp)
 }
 
 void
-lagg_enqueue(struct lagg_softc *sc, struct lagg_port *lp, struct mbuf *m)
+lagg_output(struct lagg_softc *sc, struct lagg_port *lp, struct mbuf *m)
 {
 	struct ifnet *ifp;
 	int len, error;

Index: src/sys/net/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.20 src/sys/net/lagg/if_lagg_lacp.c:1.21
--- src/sys/net/lagg/if_lagg_lacp.c:1.20	Thu Mar 31 03:15:15 2022
+++ src/sys/net/lagg/if_lagg_lacp.c	Thu Mar 31 07:59:05 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.20 2022/03/31 03:15:15 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.21 2022/03/31 07:59:05 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.20 2022/03/31 03:15:15 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.21 2022/03/31 07:59:05 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -647,7 +647,7 @@ lacp_transmit(struct lagg_proto_softc *x
 		return ENOENT;
 	}
 
-	lagg_enqueue(lsc->lsc_softc, lp, m);
+	lagg_output(lsc->lsc_softc, lp, m);
 	lagg_port_putref(lp, );
 
 	return 0;

Index: src/sys/net/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.5 src/sys/net/lagg/if_laggproto.c:1.6
--- src/sys/net/lagg/if_laggproto.c:1.5	Thu Mar 31 03:12:31 2022
+++ src/sys/net/lagg/if_laggproto.c	Thu Mar 31 07:59:05 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.c,v 1.5 2022/03/31 03:12:31 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.6 2022/03/31 07:59:05 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.5 2022/03/31 03:12:31 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.6 2022/03/31 07:59:05 yamaguchi Exp $");
 
 #include 
 #include 
@@ -412,7 +412,7 @@ lagg_fail_transmit(struct lagg_proto_sof
 		return ENOENT;
 	}
 
-	lagg_enqueue(psc->psc_softc, lp, m);
+	lagg_output(psc->psc_softc, lp, m);
 	lagg_port_putref(lp, );
 	return 0;
 }
@@ -613,7 +613,7 @@ lagg_lb_transmit(struct lagg_proto_softc
 		return ENOENT;
 	}
 
-	lagg_enqueue(psc->psc_softc, lp, m);
+	lagg_output(psc->psc_softc, lp, m);
 	lagg_port_putref(lp, );
 
 	return 0;

Index: src/sys/net/lagg/if_laggproto.h
diff -u src/sys/net/lagg/if_laggproto.h:1.14 src/sys/net/lagg/if_laggproto.h:1.15
--- src/sys/net/lagg/if_laggproto.h:1.14	Thu Mar 31 03:15:15 2022
+++ src/sys/net/lagg/if_laggproto.h	Thu Mar 31 07:59:05 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.h,v 1.14 2022/03/31 03:15:15 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.h,v 1.15 2022/03/31 07:59:05 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2021 Internet Initiative Japan Inc.
@@ -280,7 +280,7 @@ lagg_debug_enable(struct lagg_softc *sc)
 
 void		lagg_port_getref(struct lagg_port *, struct psref *);
 void		lagg_port_putref(struct lagg_port *, struct psref *);
-void		lagg_enqueue(struct lagg_softc *,
+void		lagg_output(struct lagg_softc *,
 		struct lagg_port *, struct mbuf *);
 uint32_t	lagg_hashmbuf(struct lagg_softc *, struct mbuf *);
 



CVS commit: src/sys/net/lagg

2022-03-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Mar 31 07:59:05 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c if_laggproto.c
if_laggproto.h

Log Message:
rename lagg_enqueue to lagg_output

NFC


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.20 -r1.21 src/sys/net/lagg/if_lagg_lacp.c
cvs rdiff -u -r1.5 -r1.6 src/sys/net/lagg/if_laggproto.c
cvs rdiff -u -r1.14 -r1.15 src/sys/net/lagg/if_laggproto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2022-03-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Mar 31 03:21:33 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
Use ether_ioctl to change mtu of lagg(4)


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.42 src/sys/net/lagg/if_lagg.c:1.43
--- src/sys/net/lagg/if_lagg.c:1.42	Thu Mar 31 03:15:15 2022
+++ src/sys/net/lagg/if_lagg.c	Thu Mar 31 03:21:33 2022
@@ -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 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__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 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 		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 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 			}
 		}
 
-		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 @@ lagg_capabilities_update(struct lagg_sof
 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_if;
 	ifp_port = lp->lp_ifp;
+
 	KASSERT(IFNET_LOCKED(ifp_port));
 
 	error = 0;
@@ -2020,30 +2025,35 @@ lagg_setup_mtu(struct lagg_softc *sc, st
 
 	if (SIMPLEQ_EMPTY(>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, );
+		}
 	} 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;
-		}
+		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 *));
-		if (error != 0) {
-			LAGG_DPRINTF(sc, "invalid MTU %d for %s\n",
-			ifr.ifr_mtu, ifp_port->if_xname);
-			return error;
+			strlcpy(ifr.ifr_name, ifp_port->if_xname,
+			sizeof(ifr.ifr_name));
+			error = lp->lp_ioctl(ifp_port,
+			SIOCSIFMTU, (void *));
+			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 @@ lagg_teardown_mtu(struct lagg_softc *sc,
 	ifp_port = lp->lp_ifp;
 	KASSERT(IFNET_LOCKED(ifp_port));
 
-	if (SIMPLEQ_EMPTY(>sc_ports))
-		sc->sc_if.if_mtu = 0;
-
 	if (ifp_port->if_mtu != lp->lp_mtu) {
 		memset(, 0, sizeof(ifr));
 		strlcpy(ifr.ifr_name, ifp_port->if_xname, sizeof(ifr.ifr_name));
@@ -2338,6 +2345,8 @@ lagg_port_setup(struct lagg_softc *sc,
 	/* 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_port_setup(struct lagg_softc *sc,
 
 	lagg_config_promisc(sc, lp);
 	lagg_proto_startport(sc, lp);
-	lagg_capabilities_update(sc);
 
 	return 0;
 



CVS commit: src/sys/net/lagg

2022-03-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Mar 31 03:21:33 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
Use ether_ioctl to change mtu of lagg(4)


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/net/lagg/if_lagg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2022-03-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Mar 31 03:15:15 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c if_laggproto.h

Log Message:
Use addlog(4) for putting 2 messages to one line


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.19 -r1.20 src/sys/net/lagg/if_lagg_lacp.c
cvs rdiff -u -r1.13 -r1.14 src/sys/net/lagg/if_laggproto.h

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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.41 src/sys/net/lagg/if_lagg.c:1.42
--- src/sys/net/lagg/if_lagg.c:1.41	Thu Mar 31 03:12:31 2022
+++ src/sys/net/lagg/if_lagg.c	Thu Mar 31 03:15:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.41 2022/03/31 03:12:31 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.42 2022/03/31 03:15:15 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.41 2022/03/31 03:12:31 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.42 2022/03/31 03:15:15 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -244,15 +244,6 @@ lagg_sizeof_softc(enum lagg_iftypes ift)
 	return s;
 }
 
-static bool
-lagg_debug_enable(struct lagg_softc *sc)
-{
-	if (__predict_false(ISSET(sc->sc_if.if_flags, IFF_DEBUG)))
-		return true;
-
-	return false;
-}
-
 static void
 lagg_evcnt_attach(struct lagg_softc *sc,
 struct evcnt *ev, const char *name)
@@ -743,7 +734,7 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 			error = lagg_lp_ioctl(lp, cmd, (void *)ifr);
 
 			if (error != 0) {
-lagg_log(sc, LOG_ERR,
+LAGG_LOG(sc, LOG_ERR,
 "failed to change MTU to %d on port %s, "
 "reverting all ports to original "
 "MTU(%" PRIu64 ")\n",
@@ -798,65 +789,65 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 static int
 lagg_setup_sysctls(struct lagg_softc *sc)
 {
-	struct sysctllog **log;
+	struct sysctllog **slog;
 	const struct sysctlnode **rnode, *hashnode;
 	const char *ifname;
 	int error;
 
-	log = >sc_sysctllog;
+	slog = >sc_sysctllog;
 	rnode = >sc_sysctlnode;
 	ifname = sc->sc_if.if_xname;
 
-	error = sysctl_createv(log, 0, NULL, rnode,
+	error = sysctl_createv(slog, 0, NULL, rnode,
 	CTLFLAG_PERMANENT, CTLTYPE_NODE, ifname,
 	SYSCTL_DESCR("lagg information and settings"),
 	NULL, 0, NULL, 0, CTL_NET, CTL_CREATE, CTL_EOL);
 	if (error != 0)
 		goto done;
 
-	error = sysctl_createv(log, 0, rnode, ,
+	error = sysctl_createv(slog, 0, rnode, ,
 	CTLFLAG_PERMANENT, CTLTYPE_NODE, "hash",
 	SYSCTL_DESCR("hash calculation settings"),
 	NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
 	if (error != 0)
 		goto done;
 
-	error = sysctl_createv(log, 0, , NULL,
+	error = sysctl_createv(slog, 0, , NULL,
 	CTLFLAG_READWRITE, CTLTYPE_BOOL, "macaddr",
 	SYSCTL_DESCR("use src/dst mac addresses"),
 	NULL, 0, >sc_hash_mac, 0, CTL_CREATE, CTL_EOL);
 	if (error != 0)
 		goto done;
 
-	error = sysctl_createv(log, 0, , NULL,
+	error = sysctl_createv(slog, 0, , NULL,
 	CTLFLAG_READWRITE, CTLTYPE_BOOL, "ipaddr",
 	SYSCTL_DESCR("use src/dst IPv4 addresses"),
 	NULL, 0, >sc_hash_ipaddr, 0, CTL_CREATE, CTL_EOL);
 	if (error != 0)
 		goto done;
 
-	error = sysctl_createv(log, 0, , NULL,
+	error = sysctl_createv(slog, 0, , NULL,
 	CTLFLAG_READWRITE, CTLTYPE_BOOL, "ip6addr",
 	SYSCTL_DESCR("use src/dst IPv6 addresses"),
 	NULL, 0, >sc_hash_ip6addr, 0, CTL_CREATE, CTL_EOL);
 	if (error != 0)
 		goto done;
 
-	error = sysctl_createv(log, 0, , NULL,
+	error = sysctl_createv(slog, 0, , NULL,
 	CTLFLAG_READWRITE, CTLTYPE_BOOL, "tcp",
 	SYSCTL_DESCR("use TCP src/dst port"),
 	NULL, 0, >sc_hash_tcp, 0, CTL_CREATE, CTL_EOL);
 	if (error != 0)
 		goto done;
 
-	error = sysctl_createv(log, 0, , NULL,
+	error = sysctl_createv(slog, 0, , NULL,
 	   CTLFLAG_READWRITE, CTLTYPE_BOOL, "udp",
 	   SYSCTL_DESCR("use UDP src/dst port"),
 	   NULL, 0, >sc_hash_udp, 0, CTL_CREATE, CTL_EOL);
 done:
 	if (error != 0) {
-		lagg_log(sc, LOG_ERR, "unable to create sysctl node\n");
-		sysctl_teardown(log);
+		LAGG_LOG(sc, LOG_ERR, "unable to create sysctl node\n");
+		sysctl_teardown(slog);
 	}
 
 	return error;
@@ -1243,7 +1234,7 @@ lagg_vlan_cb(struct ethercom *ec, uint16
 	LAGG_PORTS_FOREACH(sc, lp) {
 		error = lagg_port_vlan_cb(lp, lvt, set);
 		if (error != 0) {
-			lagg_log(sc, LOG_WARNING,
+			LAGG_LOG(sc, LOG_WARNING,
 			"%s failed to configure vlan on %d\n",
 			lp->lp_ifp->if_xname, error);
 		}
@@ -1763,7 +1754,7 @@ lagg_port_vlan(struct lagg_softc *sc, st
 	TAILQ_FOREACH(lvt, >sc_vtags, lvt_entry) {
 		error = lagg_port_vlan_cb(lp, lvt, set);
 		if (error != 0) {
-			lagg_log(sc, LOG_WARNING,
+			LAGG_LOG(sc, LOG_WARNING,
 			"%s failed to configure vlan on %d\n",
 			lp->lp_ifp->if_xname, error);
 		}
@@ -1817,9 +1808,9 @@ 

CVS commit: src/sys/net/lagg

2022-03-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Mar 31 03:15:15 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg_lacp.c if_laggproto.h

Log Message:
Use addlog(4) for putting 2 messages to one line


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.19 -r1.20 src/sys/net/lagg/if_lagg_lacp.c
cvs rdiff -u -r1.13 -r1.14 src/sys/net/lagg/if_laggproto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2022-03-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Mar 31 03:12:31 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_laggproto.c if_laggproto.h

Log Message:
Make lagg interface specified "laggproto none" able to up


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/lagg/if_laggproto.c
cvs rdiff -u -r1.12 -r1.13 src/sys/net/lagg/if_laggproto.h

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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.40 src/sys/net/lagg/if_lagg.c:1.41
--- src/sys/net/lagg/if_lagg.c:1.40	Thu Mar 31 03:10:59 2022
+++ src/sys/net/lagg/if_lagg.c	Thu Mar 31 03:12:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.40 2022/03/31 03:10:59 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.41 2022/03/31 03:12:31 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.40 2022/03/31 03:10:59 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.41 2022/03/31 03:12:31 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -86,7 +86,6 @@ static const struct lagg_proto lagg_prot
 	[LAGG_PROTO_NONE] = {
 		.pr_num = LAGG_PROTO_NONE,
 		.pr_attach = lagg_none_attach,
-		.pr_up = lagg_none_up,
 	},
 	[LAGG_PROTO_LACP] = {
 		.pr_num = LAGG_PROTO_LACP,

Index: src/sys/net/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.4 src/sys/net/lagg/if_laggproto.c:1.5
--- src/sys/net/lagg/if_laggproto.c:1.4	Thu Mar 31 03:05:41 2022
+++ src/sys/net/lagg/if_laggproto.c	Thu Mar 31 03:12:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.c,v 1.4 2022/03/31 03:05:41 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.5 2022/03/31 03:12:31 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.4 2022/03/31 03:05:41 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.5 2022/03/31 03:12:31 yamaguchi Exp $");
 
 #include 
 #include 
@@ -381,13 +381,6 @@ lagg_none_attach(struct lagg_softc *sc, 
 }
 
 int
-lagg_none_up(struct lagg_proto_softc *psc __unused)
-{
-
-	return EBUSY;
-}
-
-int
 lagg_fail_attach(struct lagg_softc *sc, struct lagg_proto_softc **xpsc)
 {
 	struct lagg_proto_softc *psc;

Index: src/sys/net/lagg/if_laggproto.h
diff -u src/sys/net/lagg/if_laggproto.h:1.12 src/sys/net/lagg/if_laggproto.h:1.13
--- src/sys/net/lagg/if_laggproto.h:1.12	Thu Mar 31 03:10:59 2022
+++ src/sys/net/lagg/if_laggproto.h	Thu Mar 31 03:12:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.h,v 1.12 2022/03/31 03:10:59 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.h,v 1.13 2022/03/31 03:12:31 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2021 Internet Initiative Japan Inc.
@@ -282,7 +282,6 @@ void		lagg_common_linkstate(struct lagg_
 
 int		lagg_none_attach(struct lagg_softc *,
 		struct lagg_proto_softc **);
-int		lagg_none_up(struct lagg_proto_softc *);
 
 int		lagg_fail_attach(struct lagg_softc *,
 		struct lagg_proto_softc **);



CVS commit: src/sys/net/lagg

2022-03-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Mar 31 03:12:31 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_laggproto.c if_laggproto.h

Log Message:
Make lagg interface specified "laggproto none" able to up


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/lagg/if_laggproto.c
cvs rdiff -u -r1.12 -r1.13 src/sys/net/lagg/if_laggproto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net/lagg

2022-03-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Mar 31 03:10:59 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_laggproto.h

Log Message:
added log when ifpromisc is failed


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.11 -r1.12 src/sys/net/lagg/if_laggproto.h

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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.39 src/sys/net/lagg/if_lagg.c:1.40
--- src/sys/net/lagg/if_lagg.c:1.39	Thu Mar 31 03:07:05 2022
+++ src/sys/net/lagg/if_lagg.c	Thu Mar 31 03:10:59 2022
@@ -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 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__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_delport_all(struct lagg_
 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 @@ lagg_port_setsadl(struct lagg_port *lp, 
 		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 @@ lagg_port_unsetsadl(struct lagg_port *lp
 		/* 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 @@ lagg_get_stats(struct lagg_softc *sc, st
 	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;
+	bool promisc;
+
+	KASSERT(LAGG_LOCKED(sc));
 
-	error = 0;
 	ifp = >sc_if;
-	chg_flags = ifp->if_flags ^ lp->lp_ifflags;
+	ifp_port = lp->lp_ifp;
 
-	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;
-		}
+	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);
 	}
 }
 

Index: src/sys/net/lagg/if_laggproto.h
diff -u src/sys/net/lagg/if_laggproto.h:1.11 src/sys/net/lagg/if_laggproto.h:1.12
--- src/sys/net/lagg/if_laggproto.h:1.11	Thu Mar 31 02:00:27 2022
+++ src/sys/net/lagg/if_laggproto.h	Thu Mar 31 03:10:59 2022
@@ -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 @@ struct lagg_port {
 
 	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;



CVS commit: src/sys/net/lagg

2022-03-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Mar 31 03:10:59 UTC 2022

Modified Files:
src/sys/net/lagg: if_lagg.c if_laggproto.h

Log Message:
added log when ifpromisc is failed


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.11 -r1.12 src/sys/net/lagg/if_laggproto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



  1   2   >