Module Name:    src
Committed By:   riastradh
Date:           Mon Oct  9 17:43:01 UTC 2023

Modified Files:
        src/sys/dev/usb: usbnet.c

Log Message:
usbnet(9): On if_init, stop/init if IFF_RUNNING -- not noop.

ether_ioctl(9) relies on this to reinitialize an interface when a
flags change returns ENETRESET.  We can't just reprogram the hardware
multicast filter because some drivers have logic in if_init that's
conditional on IFF_PROMISC; perhaps we can reduce the cost of this if
we can change those drivers to do it in uno_mcast but that requires
some analysis to determine.

PR kern/57645

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/dev/usb/usbnet.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/dev/usb/usbnet.c
diff -u src/sys/dev/usb/usbnet.c:1.116 src/sys/dev/usb/usbnet.c:1.117
--- src/sys/dev/usb/usbnet.c:1.116	Mon Oct  9 17:42:09 2023
+++ src/sys/dev/usb/usbnet.c	Mon Oct  9 17:43:01 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbnet.c,v 1.116 2023/10/09 17:42:09 riastradh Exp $	*/
+/*	$NetBSD: usbnet.c,v 1.117 2023/10/09 17:43:01 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.116 2023/10/09 17:42:09 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.117 2023/10/09 17:43:01 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -1130,6 +1130,7 @@ usbnet_stop(struct usbnet *un, struct if
 	USBNETHIST_FUNC(); USBNETHIST_CALLED();
 
 	KASSERTMSG(IFNET_LOCKED(ifp), "%s", ifp->if_xname);
+	KASSERTMSG(ifp->if_flags & IFF_RUNNING, "%s", ifp->if_xname);
 
 	/*
 	 * For drivers with hardware multicast filter update callbacks:
@@ -1320,14 +1321,17 @@ usbnet_if_init(struct ifnet *ifp)
 		return EIO;
 
 	/*
-	 * If we're already running, nothing to do.
+	 * If we're already running, stop the interface first -- we're
+	 * reinitializing it.
 	 *
-	 * XXX This should be an assertion, but it may require some
-	 * analysis -- and possibly some tweaking -- of sys/net to
-	 * ensure.
+	 * XXX Grody for sys/net to call if_init to reinitialize.  This
+	 * should be an assertion, not a branch, but it will require
+	 * some tweaking of sys/net to avoid.  See also the comment in
+	 * usbnet_ifflags_cb about if_init vs uno_mcast on reinitalize.
 	 */
 	if (ifp->if_flags & IFF_RUNNING)
-		return 0;
+		usbnet_stop(un, ifp, /*disable*/1/*XXX???*/);
+	KASSERTMSG((ifp->if_flags & IFF_RUNNING) == 0, "%s", ifp->if_xname);
 
 	error = uno_init(un, ifp);
 	if (error)

Reply via email to