All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: usbnet: allow overriding of default USB interface naming
@ 2021-06-11 15:23 Jonathan Davies
  2021-06-11 17:16 ` Andrew Lunn
  2021-06-12  7:01 ` Greg KH
  0 siblings, 2 replies; 13+ messages in thread
From: Jonathan Davies @ 2021-06-11 15:23 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: Jonathan Davies, David S. Miller, Jakub Kicinski, netdev,
	linux-usb, linux-kernel

When the predictable device naming scheme for NICs is not in use, it is
common for there to be udev rules to rename interfaces to names with
prefix "eth".

Since the timing at which USB NICs are discovered is unpredictable, it
can be interfere with udev's attempt to rename another interface to
"eth0" if a freshly discovered USB interface is initially given the name
"eth0".

Hence it is useful to be able to override the default name. A new usbnet
module parameter allows this to be configured.

Signed-off-by: Jonathan Davies <jonathan.davies@nutanix.com>
Suggested-by: Prashanth Sreenivasa <prashanth.sreenivasa@nutanix.com>
---
 drivers/net/usb/usbnet.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index ecf6284..55f6230 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -72,6 +72,13 @@ static int msg_level = -1;
 module_param (msg_level, int, 0);
 MODULE_PARM_DESC (msg_level, "Override default message level");
 
+#define DEFAULT_ETH_DEV_NAME "eth%d"
+
+static char *eth_device_name = DEFAULT_ETH_DEV_NAME;
+module_param(eth_device_name, charp, 0644);
+MODULE_PARM_DESC(eth_device_name, "Device name pattern for Ethernet devices"
+				  " (default: \"" DEFAULT_ETH_DEV_NAME "\")");
+
 /*-------------------------------------------------------------------------*/
 
 /* handles CDC Ethernet and many other network "bulk data" interfaces */
@@ -1730,12 +1737,12 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
 			goto out1;
 
 		// heuristic:  "usb%d" for links we know are two-host,
-		// else "eth%d" when there's reasonable doubt.  userspace
-		// can rename the link if it knows better.
+		// else eth_device_name when there's reasonable doubt.
+		// userspace can rename the link if it knows better.
 		if ((dev->driver_info->flags & FLAG_ETHER) != 0 &&
 		    ((dev->driver_info->flags & FLAG_POINTTOPOINT) == 0 ||
 		     (net->dev_addr [0] & 0x02) == 0))
-			strcpy (net->name, "eth%d");
+			strscpy(net->name, eth_device_name, sizeof(net->name));
 		/* WLAN devices should always be named "wlan%d" */
 		if ((dev->driver_info->flags & FLAG_WLAN) != 0)
 			strcpy(net->name, "wlan%d");
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-06-14 19:20 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-11 15:23 [PATCH] net: usbnet: allow overriding of default USB interface naming Jonathan Davies
2021-06-11 17:16 ` Andrew Lunn
2021-06-14  9:32   ` Jonathan Davies
2021-06-14 12:40     ` Oliver Neukum
2021-06-12  7:01 ` Greg KH
2021-06-14  9:32   ` Jonathan Davies
2021-06-14  9:43     ` Greg KH
2021-06-14 10:58       ` Jonathan Davies
2021-06-14 12:23         ` Andrew Lunn
2021-06-14 14:53           ` Jonathan Davies
2021-06-14 13:51         ` Greg KH
2021-06-14 14:53           ` Jonathan Davies
2021-06-14 19:20             ` Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.