CVS commit: src/sys/net

2024-04-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Apr 17 18:52:54 UTC 2024

Modified Files:
src/sys/net: if_tap.c

Log Message:
tap(4): Just use mutex_enter.

PR kern/58167


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sys/net/if_tap.c

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

Modified files:

Index: src/sys/net/if_tap.c
diff -u src/sys/net/if_tap.c:1.131 src/sys/net/if_tap.c:1.132
--- src/sys/net/if_tap.c:1.131	Wed Apr 17 18:52:39 2024
+++ src/sys/net/if_tap.c	Wed Apr 17 18:52:54 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.131 2024/04/17 18:52:39 riastradh Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.132 2024/04/17 18:52:54 riastradh Exp $	*/
 
 /*
  *  Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.131 2024/04/17 18:52:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.132 2024/04/17 18:52:54 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 
@@ -857,13 +857,7 @@ tap_dev_read(int unit, struct uio *uio, 
 	if ((ifp->if_flags & IFF_UP) == 0)
 		return EHOSTDOWN;
 
-	/* In the TAP_NBIO case, we have to make sure we won't be sleeping */
-	if ((sc->sc_flags & TAP_NBIO) != 0) {
-		if (!mutex_tryenter(>sc_lock))
-			return EWOULDBLOCK;
-	} else
-		mutex_enter(>sc_lock);
-
+	mutex_enter(>sc_lock);
 	if (IFQ_IS_EMPTY(>if_snd)) {
 		ifp->if_flags &= ~IFF_OACTIVE;
 		if (sc->sc_flags & TAP_NBIO)



CVS commit: src/sys/net

2024-04-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Apr 17 18:52:54 UTC 2024

Modified Files:
src/sys/net: if_tap.c

Log Message:
tap(4): Just use mutex_enter.

PR kern/58167


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sys/net/if_tap.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

2024-04-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Apr 17 18:52:39 UTC 2024

Modified Files:
src/sys/net: if_tap.c

Log Message:
tap(4): Use DETACH_FORCE with config_detach.

It doesn't make a difference here, because tap_detach never fails,
but let's make it more obvious at the call site that failure is
forbidden here.

No functional change intended.

PR kern/58166


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/net/if_tap.c

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

Modified files:

Index: src/sys/net/if_tap.c
diff -u src/sys/net/if_tap.c:1.130 src/sys/net/if_tap.c:1.131
--- src/sys/net/if_tap.c:1.130	Wed Apr 17 18:52:25 2024
+++ src/sys/net/if_tap.c	Wed Apr 17 18:52:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.130 2024/04/17 18:52:25 riastradh Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.131 2024/04/17 18:52:39 riastradh Exp $	*/
 
 /*
  *  Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.130 2024/04/17 18:52:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.131 2024/04/17 18:52:39 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 
@@ -641,7 +641,7 @@ tap_clone_destroyer(device_t dev)
 	cfdata_t cf = device_cfdata(dev);
 	int error;
 
-	error = config_detach(dev, 0);
+	error = config_detach(dev, DETACH_FORCE);
 	KASSERTMSG(error == 0, "error=%d", error);
 	kmem_free(cf, sizeof(*cf));
 }



CVS commit: src/sys/net

2024-04-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Apr 17 18:52:39 UTC 2024

Modified Files:
src/sys/net: if_tap.c

Log Message:
tap(4): Use DETACH_FORCE with config_detach.

It doesn't make a difference here, because tap_detach never fails,
but let's make it more obvious at the call site that failure is
forbidden here.

No functional change intended.

PR kern/58166


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/net/if_tap.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

2024-04-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Apr 17 18:52:25 UTC 2024

Modified Files:
src/sys/net: if_tap.c

Log Message:
tap(4): Prune dead branches around tap_dev_destroyer.

No functional change intended.

PR kern/58166


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/net/if_tap.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

2024-04-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Apr 17 18:52:25 UTC 2024

Modified Files:
src/sys/net: if_tap.c

Log Message:
tap(4): Prune dead branches around tap_dev_destroyer.

No functional change intended.

PR kern/58166


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/net/if_tap.c

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

Modified files:

Index: src/sys/net/if_tap.c
diff -u src/sys/net/if_tap.c:1.129 src/sys/net/if_tap.c:1.130
--- src/sys/net/if_tap.c:1.129	Wed Apr 17 18:32:13 2024
+++ src/sys/net/if_tap.c	Wed Apr 17 18:52:25 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.129 2024/04/17 18:32:13 riastradh Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.130 2024/04/17 18:52:25 riastradh Exp $	*/
 
 /*
  *  Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.129 2024/04/17 18:32:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.130 2024/04/17 18:52:25 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 
@@ -210,7 +210,7 @@ struct if_clone tap_cloners = IF_CLONE_I
 
 /* Helper functions shared by the two cloning code paths */
 static struct tap_softc *	tap_clone_creator(int);
-int	tap_clone_destroyer(device_t);
+static void			tap_clone_destroyer(device_t);
 
 static struct sysctllog *tap_sysctl_clog;
 
@@ -625,33 +625,25 @@ tap_clone_creator(int unit)
 	return device_private(config_attach_pseudo(cf));
 }
 
-/*
- * The clean design of if_clone and autoconf(9) makes that part
- * really straightforward.  The second argument of config_detach
- * means neither QUIET nor FORCED.
- */
 static int
 tap_clone_destroy(struct ifnet *ifp)
 {
 	struct tap_softc *sc = ifp->if_softc;
-	int error = tap_clone_destroyer(sc->sc_dev);
 
-	if (error == 0)
-		atomic_dec_uint(_count);
-	return error;
+	tap_clone_destroyer(sc->sc_dev);
+	atomic_dec_uint(_count);
+	return 0;
 }
 
-int
+static void
 tap_clone_destroyer(device_t dev)
 {
 	cfdata_t cf = device_cfdata(dev);
 	int error;
 
-	if ((error = config_detach(dev, 0)) != 0)
-		aprint_error_dev(dev, "unable to detach instance\n");
+	error = config_detach(dev, 0);
+	KASSERTMSG(error == 0, "error=%d", error);
 	kmem_free(cf, sizeof(*cf));
-
-	return error;
 }
 
 /*
@@ -774,7 +766,6 @@ tap_fops_close(file_t *fp)
 {
 	struct tap_softc *sc;
 	int unit = fp->f_devunit;
-	int error;
 
 	sc = device_lookup_private(_cd, unit);
 	if (sc == NULL)
@@ -783,16 +774,16 @@ tap_fops_close(file_t *fp)
 	KERNEL_LOCK(1, NULL);
 	tap_dev_close(sc);
 
-	/* Destroy the device now that it is no longer useful,
-	 * unless it's already being destroyed. */
-	if ((sc->sc_flags & TAP_GOING) != 0) {
-		KERNEL_UNLOCK_ONE(NULL);
-		return 0;
-	}
+	/*
+	 * Destroy the device now that it is no longer useful, unless
+	 * it's already being destroyed.
+	 */
+	if ((sc->sc_flags & TAP_GOING) != 0)
+		goto out;
+	tap_clone_destroyer(sc->sc_dev);
 
-	error = tap_clone_destroyer(sc->sc_dev);
-	KERNEL_UNLOCK_ONE(NULL);
-	return error;
+out:	KERNEL_UNLOCK_ONE(NULL);
+	return 0;
 }
 
 static void



CVS commit: src/sys/net

2024-04-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Apr 17 18:32:13 UTC 2024

Modified Files:
src/sys/net: if_tap.c

Log Message:
tap(4): Prune dead branches around tap_dev_close.

No functional change intended.

PR kern/58166


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/net/if_tap.c

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

Modified files:

Index: src/sys/net/if_tap.c
diff -u src/sys/net/if_tap.c:1.128 src/sys/net/if_tap.c:1.129
--- src/sys/net/if_tap.c:1.128	Fri Jan  6 01:54:22 2023
+++ src/sys/net/if_tap.c	Wed Apr 17 18:32:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.128 2023/01/06 01:54:22 ozaki-r Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.129 2024/04/17 18:32:13 riastradh Exp $	*/
 
 /*
  *  Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.128 2023/01/06 01:54:22 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.129 2024/04/17 18:32:13 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 
@@ -117,7 +117,7 @@ CFATTACH_DECL_NEW(tap, sizeof(struct tap
 extern struct cfdriver tap_cd;
 
 /* Real device access routines */
-static int	tap_dev_close(struct tap_softc *);
+static void	tap_dev_close(struct tap_softc *);
 static int	tap_dev_read(int, struct uio *, int);
 static int	tap_dev_write(int, struct uio *, int);
 static int	tap_dev_ioctl(int, u_long, void *, struct lwp *);
@@ -759,7 +759,8 @@ tap_cdev_close(dev_t dev, int flags, int
 	if (sc == NULL)
 		return ENXIO;
 
-	return tap_dev_close(sc);
+	tap_dev_close(sc);
+	return 0;
 }
 
 /*
@@ -779,13 +780,8 @@ tap_fops_close(file_t *fp)
 	if (sc == NULL)
 		return ENXIO;
 
-	/* tap_dev_close currently always succeeds, but it might not
-	 * always be the case. */
 	KERNEL_LOCK(1, NULL);
-	if ((error = tap_dev_close(sc)) != 0) {
-		KERNEL_UNLOCK_ONE(NULL);
-		return error;
-	}
+	tap_dev_close(sc);
 
 	/* Destroy the device now that it is no longer useful,
 	 * unless it's already being destroyed. */
@@ -799,7 +795,7 @@ tap_fops_close(file_t *fp)
 	return error;
 }
 
-static int
+static void
 tap_dev_close(struct tap_softc *sc)
 {
 	struct ifnet *ifp;
@@ -832,8 +828,6 @@ tap_dev_close(struct tap_softc *sc)
 	}
 	sc->sc_flags &= ~(TAP_INUSE | TAP_ASYNCIO);
 	if_link_state_change(ifp, LINK_STATE_DOWN);
-
-	return 0;
 }
 
 static int



CVS commit: src/sys/net

2024-04-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Apr 17 18:32:13 UTC 2024

Modified Files:
src/sys/net: if_tap.c

Log Message:
tap(4): Prune dead branches around tap_dev_close.

No functional change intended.

PR kern/58166


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/net/if_tap.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: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

2024-03-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Mar 10 04:21:47 UTC 2024

Modified Files:
src/sys/net: if_wg.c

Log Message:
wg(4): Bind to CPU in wg_handle_packet.

Required by use of psref there.

Assert we're bound up front so we catch mistakes early, rather than
later on if we get unlucky in preemption and scheduling.

PR bin/58021


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/net/if_wg.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

2024-03-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Mar 10 04:21:47 UTC 2024

Modified Files:
src/sys/net: if_wg.c

Log Message:
wg(4): Bind to CPU in wg_handle_packet.

Required by use of psref there.

Assert we're bound up front so we catch mistakes early, rather than
later on if we get unlucky in preemption and scheduling.

PR bin/58021


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/net/if_wg.c

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

Modified files:

Index: src/sys/net/if_wg.c
diff -u src/sys/net/if_wg.c:1.77 src/sys/net/if_wg.c:1.78
--- src/sys/net/if_wg.c:1.77	Tue Aug  1 07:04:16 2023
+++ src/sys/net/if_wg.c	Sun Mar 10 04:21:47 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wg.c,v 1.77 2023/08/01 07:04:16 mrg Exp $	*/
+/*	$NetBSD: if_wg.c,v 1.78 2024/03/10 04:21:47 riastradh Exp $	*/
 
 /*
  * Copyright (C) Ryota Ozaki 
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.77 2023/08/01 07:04:16 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.78 2024/03/10 04:21:47 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq_enabled.h"
@@ -2871,6 +2871,8 @@ wg_handle_packet(struct wg_softc *wg, st
 {
 	struct wg_msg *wgm;
 
+	KASSERT(curlwp->l_pflag & LP_BOUND);
+
 	m = wg_validate_msg_header(wg, m);
 	if (__predict_false(m == NULL))
 		return;
@@ -5040,6 +5042,7 @@ rumpkern_wg_recv_peer(struct wg_softc *w
 {
 	struct mbuf *m;
 	const struct sockaddr *src;
+	int bound;
 
 	WG_TRACE("");
 
@@ -5054,7 +5057,9 @@ rumpkern_wg_recv_peer(struct wg_softc *w
 	WG_DLOG("iov_len=%lu\n", iov[1].iov_len);
 	WG_DUMP_BUF(iov[1].iov_base, iov[1].iov_len);
 
+	bound = curlwp_bind();
 	wg_handle_packet(wg, m, src);
+	curlwp_bindx(bound);
 }
 #endif /* WG_RUMPKERNEL */
 



CVS commit: src/sys/net

2024-03-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar  9 13:55:28 UTC 2024

Modified Files:
src/sys/net: if_tun.c

Log Message:
tun(4): Allow IPv6 packets with TUNSLMODE configured.

PR kern/58013


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/sys/net/if_tun.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

2024-03-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar  9 13:55:28 UTC 2024

Modified Files:
src/sys/net: if_tun.c

Log Message:
tun(4): Allow IPv6 packets with TUNSLMODE configured.

PR kern/58013


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/sys/net/if_tun.c

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

Modified files:

Index: src/sys/net/if_tun.c
diff -u src/sys/net/if_tun.c:1.174 src/sys/net/if_tun.c:1.175
--- src/sys/net/if_tun.c:1.174	Fri Dec 29 23:01:02 2023
+++ src/sys/net/if_tun.c	Sat Mar  9 13:55:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tun.c,v 1.174 2023/12/29 23:01:02 chs Exp $	*/
+/*	$NetBSD: if_tun.c,v 1.175 2024/03/09 13:55:27 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988, Julian Onions 
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.174 2023/12/29 23:01:02 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.175 2024/03/09 13:55:27 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -604,9 +604,7 @@ tun_output(struct ifnet *ifp, struct mbu
 goto out;
 			}
 			memcpy(mtod(m0, char *), dst, dst->sa_len);
-		}
-
-		if (tp->tun_flags & TUN_IFHEAD) {
+		} else if (tp->tun_flags & TUN_IFHEAD) {
 			/* Prepend the address family */
 			M_PREPEND(m0, sizeof(*af), M_DONTWAIT);
 			if (m0 == NULL) {



CVS commit: src/sys/net/agr

2024-03-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  8 19:45:59 UTC 2024

Modified Files:
src/sys/net/agr: if_agrioctl.h

Log Message:
ifconfig: fix agr status

Previously, when the interface was collecting, its status was reported
as '', even when it was not distributing.

sbin/ifconfig/agr.c(170): warning: 'b\0DISTRIBUTING\0' overlaps earlier
'b\0COLLECTING\0' on bit 0 [376]


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/agr/if_agrioctl.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/agr

2024-03-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  8 19:45:59 UTC 2024

Modified Files:
src/sys/net/agr: if_agrioctl.h

Log Message:
ifconfig: fix agr status

Previously, when the interface was collecting, its status was reported
as '', even when it was not distributing.

sbin/ifconfig/agr.c(170): warning: 'b\0DISTRIBUTING\0' overlaps earlier
'b\0COLLECTING\0' on bit 0 [376]


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/agr/if_agrioctl.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/agr/if_agrioctl.h
diff -u src/sys/net/agr/if_agrioctl.h:1.2 src/sys/net/agr/if_agrioctl.h:1.3
--- src/sys/net/agr/if_agrioctl.h:1.2	Sat Dec 10 23:21:39 2005
+++ src/sys/net/agr/if_agrioctl.h	Fri Mar  8 19:45:59 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agrioctl.h,v 1.2 2005/12/10 23:21:39 elad Exp $	*/
+/*	$NetBSD: if_agrioctl.h,v 1.3 2024/03/08 19:45:59 rillig Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -64,7 +64,7 @@ struct agrportinfo {
 #define	AGRPORTINFO_BITS \
 	"\177\020" \
 	"b\0COLLECTING\0" \
-	"b\0DISTRIBUTING\0"
+	"b\1DISTRIBUTING\0"
 
 struct agrportlist {
 	int apl_nports;



CVS commit: src/sys/net

2024-02-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Feb 17 15:47:39 UTC 2024

Modified Files:
src/sys/net: if_spppsubr.c

Log Message:
PR 57941: remove duplciate declaration (copy+pasto)


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.267 src/sys/net/if_spppsubr.c:1.268
--- src/sys/net/if_spppsubr.c:1.267	Sat Mar 25 21:35:49 2023
+++ src/sys/net/if_spppsubr.c	Sat Feb 17 15:47:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.267 2023/03/25 21:35:49 andvar Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.268 2024/02/17 15:47:39 martin Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.267 2023/03/25 21:35:49 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.268 2024/02/17 15:47:39 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -445,7 +445,6 @@ static void sppp_pap_input(struct sppp *
 static void sppp_pap_init(struct sppp *);
 static void sppp_pap_tlu(struct sppp *);
 static void sppp_pap_scr(struct sppp *);
-static void sppp_pap_scr(struct sppp *);
 
 static void sppp_chap_input(struct sppp *, struct mbuf *);
 static void sppp_chap_init(struct sppp *);



CVS commit: src/sys/net

2024-02-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Feb 17 15:47:39 UTC 2024

Modified Files:
src/sys/net: if_spppsubr.c

Log Message:
PR 57941: remove duplciate declaration (copy+pasto)


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/sys/net/if_spppsubr.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

2023-12-29 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Fri Dec 29 23:01:02 UTC 2023

Modified Files:
src/sys/net: if_tun.c

Log Message:
tun: add missing kpreempt_enable() if pktq_enqueue() fails


To generate a diff of this commit:
cvs rdiff -u -r1.173 -r1.174 src/sys/net/if_tun.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

2023-12-29 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Fri Dec 29 23:01:02 UTC 2023

Modified Files:
src/sys/net: if_tun.c

Log Message:
tun: add missing kpreempt_enable() if pktq_enqueue() fails


To generate a diff of this commit:
cvs rdiff -u -r1.173 -r1.174 src/sys/net/if_tun.c

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

Modified files:

Index: src/sys/net/if_tun.c
diff -u src/sys/net/if_tun.c:1.173 src/sys/net/if_tun.c:1.174
--- src/sys/net/if_tun.c:1.173	Mon Mar 28 12:33:22 2022
+++ src/sys/net/if_tun.c	Fri Dec 29 23:01:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tun.c,v 1.173 2022/03/28 12:33:22 riastradh Exp $	*/
+/*	$NetBSD: if_tun.c,v 1.174 2023/12/29 23:01:02 chs Exp $	*/
 
 /*
  * Copyright (c) 1988, Julian Onions 
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.173 2022/03/28 12:33:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.174 2023/12/29 23:01:02 chs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -982,6 +982,7 @@ tunwrite(dev_t dev, struct uio *uio, int
 	}
 	kpreempt_disable();
 	if (__predict_false(!pktq_enqueue(pktq, top, 0))) {
+		kpreempt_enable();
 		if_statinc(ifp, if_collisions);
 		mutex_exit(>tun_lock);
 		error = ENOBUFS;



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

2023-11-02 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Nov  2 09:48:29 UTC 2023

Modified Files:
src/sys/net: if_vlan.c

Log Message:
Support vlan(4) over l2tp(4)


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/net/if_vlan.c

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

Modified files:

Index: src/sys/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.170 src/sys/net/if_vlan.c:1.171
--- src/sys/net/if_vlan.c:1.170	Mon Jun 20 08:14:48 2022
+++ src/sys/net/if_vlan.c	Thu Nov  2 09:48:29 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.170 2022/06/20 08:14:48 yamaguchi Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.171 2023/11/02 09:48:29 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.170 2022/06/20 08:14:48 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.171 2023/11/02 09:48:29 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -97,6 +97,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -149,6 +150,7 @@ struct ifvlan_linkmib {
 
 struct ifvlan {
 	struct ethercom ifv_ec;
+	uint8_t ifv_lladdr[ETHER_ADDR_LEN];
 	struct ifvlan_linkmib *ifv_mib;	/*
 	 * reader must use vlan_getref_linkmib()
 	 * instead of direct dereference
@@ -189,6 +191,15 @@ const struct vlan_multisw vlan_ether_mul
 	.vmsw_purgemulti = vlan_ether_purgemulti,
 };
 
+static void	vlan_multi_nothing(struct ifvlan *);
+static int	vlan_multi_nothing_ifreq(struct ifvlan *, struct ifreq *);
+
+const struct vlan_multisw vlan_nothing_multisw = {
+	.vmsw_addmulti = vlan_multi_nothing_ifreq,
+	.vmsw_delmulti = vlan_multi_nothing_ifreq,
+	.vmsw_purgemulti = vlan_multi_nothing,
+};
+
 static int	vlan_clone_create(struct if_clone *, int);
 static int	vlan_clone_destroy(struct ifnet *);
 static int	vlan_config(struct ifvlan *, struct ifnet *, uint16_t);
@@ -327,6 +338,9 @@ vlan_clone_create(struct if_clone *ifc, 
 	mib = kmem_zalloc(sizeof(struct ifvlan_linkmib), KM_SLEEP);
 	ifp = >ifv_if;
 	LIST_INIT(>ifv_mc_listhead);
+	cprng_fast(ifv->ifv_lladdr, sizeof(ifv->ifv_lladdr));
+	ifv->ifv_lladdr[0] &= 0xFE; /* clear I/G bit */
+	ifv->ifv_lladdr[0] |= 0x02; /* set G/L bit */
 
 	mib->ifvm_ifvlan = ifv;
 	mib->ifvm_p = NULL;
@@ -394,7 +408,10 @@ vlan_config(struct ifvlan *ifv, struct i
 	struct ifvlan_linkmib *omib = NULL;
 	struct ifvlan_linkmib *checkmib;
 	struct psref_target *nmib_psref = NULL;
+	struct ethercom *ec;
 	const uint16_t vid = EVL_VLANOFTAG(tag);
+	const uint8_t *lla;
+	u_char ifv_iftype;
 	int error = 0;
 	int idx;
 	bool omib_cleanup = false;
@@ -428,69 +445,79 @@ vlan_config(struct ifvlan *ifv, struct i
 
 	switch (p->if_type) {
 	case IFT_ETHER:
-	{
-		struct ethercom *ec = (void *)p;
-
 		nmib->ifvm_msw = _ether_multisw;
 		nmib->ifvm_mintu = ETHERMIN;
 
-		error = ether_add_vlantag(p, tag, NULL);
-		if (error != 0)
-			goto done;
-
-		if (ec->ec_capenable & ETHERCAP_VLAN_MTU) {
-			nmib->ifvm_mtufudge = 0;
-		} else {
-			/*
-			 * Fudge the MTU by the encapsulation size. This
-			 * makes us incompatible with strictly compliant
-			 * 802.1Q implementations, but allows us to use
-			 * the feature with other NetBSD
-			 * implementations, which might still be useful.
-			 */
-			nmib->ifvm_mtufudge = ETHER_VLAN_ENCAP_LEN;
-		}
-
 		/*
-		 * If the parent interface can do hardware-assisted
-		 * VLAN encapsulation, then propagate its hardware-
-		 * assisted checksumming flags and tcp segmentation
-		 * offload.
+		 * We inherit the parent's Ethernet address.
 		 */
-		if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) {
-			ifp->if_capabilities = p->if_capabilities &
-			(IFCAP_TSOv4 | IFCAP_TSOv6 |
-IFCAP_CSUM_IPv4_Tx  | IFCAP_CSUM_IPv4_Rx |
-IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx |
-IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx |
-IFCAP_CSUM_TCPv6_Tx | IFCAP_CSUM_TCPv6_Rx |
-IFCAP_CSUM_UDPv6_Tx | IFCAP_CSUM_UDPv6_Rx);
-		}
+		lla = CLLADDR(p->if_sadl);
 
 		/*
-		 * We inherit the parent's Ethernet address.
+		 * Inherit the if_type from the parent.  This allows us
+		 * to participate in bridges of that type.
 		 */
-		ether_ifattach(ifp, CLLADDR(p->if_sadl));
-		ifp->if_hdrlen = sizeof(struct ether_vlan_header); /* XXX? */
+		ifv_iftype = p->if_type;
+		break;
+
+	case IFT_L2TP:
+		nmib->ifvm_msw = _nothing_multisw;
+		nmib->ifvm_mintu = ETHERMIN;
+		/* use random Ethernet address. */
+		lla = ifv->ifv_lladdr;
+		ifv_iftype = IFT_ETHER;
 		break;
-	}
 
 	default:
 		error = EPROTONOSUPPORT;
 		goto done;
 	}
 
+	error = ether_add_vlantag(p, tag, NULL);
+	if (error != 0)
+		goto done;
+
+	ec = (struct ethercom *)p;
+	if (ec->ec_capenable & ETHERCAP_VLAN_MTU) {
+		nmib->ifvm_mtufudge = 0;
+	} else {
+		/*
+		 * Fudge the MTU by the encapsulation size. This
+		 * makes us incompatible with 

CVS commit: src/sys/net

2023-11-02 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Nov  2 09:48:29 UTC 2023

Modified Files:
src/sys/net: if_vlan.c

Log Message:
Support vlan(4) over l2tp(4)


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/net/if_vlan.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

2023-11-02 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Nov  2 09:43:46 UTC 2023

Modified Files:
src/sys/net: if_l2tp.c

Log Message:
l2tp(4): use ether_ifattach() to initialize ethercom


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

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

Modified files:

Index: src/sys/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.48 src/sys/net/if_l2tp.c:1.49
--- src/sys/net/if_l2tp.c:1.48	Sat Sep  3 02:47:59 2022
+++ src/sys/net/if_l2tp.c	Thu Nov  2 09:43:46 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.48 2022/09/03 02:47:59 thorpej Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.49 2023/11/02 09:43:46 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.48 2022/09/03 02:47:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.49 2023/11/02 09:43:46 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -281,6 +281,12 @@ int
 l2tpattach0(struct l2tp_softc *sc)
 {
 
+	sc->l2tp_ec.ec_capabilities = 0;
+	sc->l2tp_ec.ec_capabilities |= ETHERCAP_VLAN_MTU;
+	sc->l2tp_ec.ec_capabilities |= ETHERCAP_JUMBO_MTU;
+
+	ether_ifattach(>l2tp_ec.ec_if, NULL);
+
 	sc->l2tp_ec.ec_if.if_addrlen = 0;
 	sc->l2tp_ec.ec_if.if_mtu= L2TP_MTU;
 	sc->l2tp_ec.ec_if.if_flags  = IFF_POINTOPOINT|IFF_MULTICAST|IFF_SIMPLEX;
@@ -296,23 +302,6 @@ l2tpattach0(struct l2tp_softc *sc)
 	sc->l2tp_ec.ec_if._if_input = ether_input;
 	IFQ_SET_READY(>l2tp_ec.ec_if.if_snd);
 
-#ifdef MBUFTRACE
-	struct ethercom *ec = >l2tp_ec;
-	struct ifnet *ifp = >l2tp_ec.ec_if;
-
-	strlcpy(ec->ec_tx_mowner.mo_name, ifp->if_xname,
-	sizeof(ec->ec_tx_mowner.mo_name));
-	strlcpy(ec->ec_tx_mowner.mo_descr, "tx",
-	sizeof(ec->ec_tx_mowner.mo_descr));
-	strlcpy(ec->ec_rx_mowner.mo_name, ifp->if_xname,
-	sizeof(ec->ec_rx_mowner.mo_name));
-	strlcpy(ec->ec_rx_mowner.mo_descr, "rx",
-	sizeof(ec->ec_rx_mowner.mo_descr));
-	MOWNER_ATTACH(>ec_tx_mowner);
-	MOWNER_ATTACH(>ec_rx_mowner);
-	ifp->if_mowner = >ec_tx_mowner;
-#endif
-
 	/* XXX
 	 * It may improve performance to use if_initialize()/if_register()
 	 * so that l2tp_input() calls if_input() instead of
@@ -322,7 +311,6 @@ l2tpattach0(struct l2tp_softc *sc)
 	if_attach(>l2tp_ec.ec_if);
 	if_link_state_change(>l2tp_ec.ec_if, LINK_STATE_DOWN);
 	if_alloc_sadl(>l2tp_ec.ec_if);
-	bpf_attach(>l2tp_ec.ec_if, DLT_EN10MB, sizeof(struct ether_header));
 
 	return 0;
 }
@@ -351,6 +339,8 @@ l2tp_clone_destroy(struct ifnet *ifp)
 	struct l2tp_softc *sc = container_of(ifp, struct l2tp_softc,
 	l2tp_ec.ec_if);
 
+	ether_ifdetach(ifp);
+
 	l2tp_clear_session(sc);
 	l2tp_delete_tunnel(>l2tp_ec.ec_if);
 	/*
@@ -369,8 +359,6 @@ l2tp_clone_destroy(struct ifnet *ifp)
 	LIST_REMOVE(sc, l2tp_list);
 	mutex_exit(_softcs.lock);
 
-	bpf_detach(ifp);
-
 	if_detach(ifp);
 
 	if_tunnel_free_ro_percpu(sc->l2tp_ro_percpu);



CVS commit: src/sys/net

2023-11-02 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Nov  2 09:43:46 UTC 2023

Modified Files:
src/sys/net: if_l2tp.c

Log Message:
l2tp(4): use ether_ifattach() to initialize ethercom


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/net/if_l2tp.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

2023-11-02 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Nov  2 09:36:28 UTC 2023

Modified Files:
src/sys/net: if_ethersubr.c

Log Message:
Added NULL check


To generate a diff of this commit:
cvs rdiff -u -r1.324 -r1.325 src/sys/net/if_ethersubr.c

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

Modified files:

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.324 src/sys/net/if_ethersubr.c:1.325
--- src/sys/net/if_ethersubr.c:1.324	Fri Oct 20 08:35:09 2023
+++ src/sys/net/if_ethersubr.c	Thu Nov  2 09:36:27 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.324 2023/10/20 08:35:09 msaitoh Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.325 2023/11/02 09:36:27 yamaguchi Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.324 2023/10/20 08:35:09 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.325 2023/11/02 09:36:27 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1041,7 +1041,7 @@ ether_ifattach(struct ifnet *ifp, const 
 	struct ethercom *ec = (struct ethercom *)ifp;
 	char xnamebuf[HOOKNAMSIZ];
 
-	if (ETHER_IS_MULTICAST(lla))
+	if (lla != NULL && ETHER_IS_MULTICAST(lla))
 		aprint_error("The multicast bit is set in the MAC address. "
 			"It's wrong.\n");
 	



CVS commit: src/sys/net

2023-11-02 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Nov  2 09:36:28 UTC 2023

Modified Files:
src/sys/net: if_ethersubr.c

Log Message:
Added NULL check


To generate a diff of this commit:
cvs rdiff -u -r1.324 -r1.325 src/sys/net/if_ethersubr.c

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



  1   2   3   4   5   6   7   8   >