|
| 1 | +From linux-netdev Tue Dec 03 13:04:55 2024 |
| 2 | +From: Dominique Martinet <asmadeus () codewreck ! org> |
| 3 | +Date: Tue, 03 Dec 2024 13:04:55 +0000 |
| 4 | +To: linux-netdev |
| 5 | +Subject: [PATCH] net: usb: usbnet: restore usb%d name exception for local mac addresses |
| 6 | +Message-Id: <20241203130457.904325-1-asmadeus () codewreck ! org> |
| 7 | +X-MARC-Message: https://marc.info/?l=linux-netdev&m=173323431631309 |
| 8 | + |
| 9 | +From: Dominique Martinet < [email protected]> |
| 10 | + |
| 11 | +The previous commit assumed that local addresses always came from the |
| 12 | +kernel, but some devices hand out local mac addresses so we ended up |
| 13 | +with point-to-point devices with a mac set by the driver, renaming to |
| 14 | +eth%d when they used to be named usb%d. |
| 15 | + |
| 16 | +Userspace should not rely on device name, but for the sake of stability |
| 17 | +restore the local mac address check portion of the naming exception: |
| 18 | +point to point devices which either have no mac set by the driver or |
| 19 | +have a local mac handed out by the driver will keep the usb%d name. |
| 20 | + |
| 21 | +Fixes: 8a7d12d674ac ("net: usb: usbnet: fix name regression") |
| 22 | +Signed-off-by: Dominique Martinet < [email protected]> |
| 23 | +--- |
| 24 | + drivers/net/usb/usbnet.c | 20 ++++++++++++++------ |
| 25 | + 1 file changed, 14 insertions(+), 6 deletions(-) |
| 26 | + |
| 27 | +--- a/drivers/net/usb/usbnet.c |
| 28 | ++++ b/drivers/net/usb/usbnet.c |
| 29 | +@@ -178,6 +178,17 @@ int usbnet_get_ethernet_addr(struct usbn |
| 30 | + } |
| 31 | + EXPORT_SYMBOL_GPL(usbnet_get_ethernet_addr); |
| 32 | + |
| 33 | ++static bool usbnet_needs_usb_name_format(struct usbnet *dev, struct net_device *net) |
| 34 | ++{ |
| 35 | ++ /* Point to point devices which don't have a real MAC address |
| 36 | ++ * (or report a fake local one) have historically used the usb%d |
| 37 | ++ * naming. Preserve this.. |
| 38 | ++ */ |
| 39 | ++ return (dev->driver_info->flags & FLAG_POINTTOPOINT) != 0 && |
| 40 | ++ (is_zero_ether_addr(net->dev_addr) || |
| 41 | ++ is_local_ether_addr(net->dev_addr)); |
| 42 | ++} |
| 43 | ++ |
| 44 | + static void intr_complete (struct urb *urb) |
| 45 | + { |
| 46 | + struct usbnet *dev = urb->context; |
| 47 | +@@ -1766,13 +1777,10 @@ usbnet_probe (struct usb_interface *udev |
| 48 | + if (status < 0) |
| 49 | + goto out1; |
| 50 | + |
| 51 | +- // heuristic: "usb%d" for links we know are two-host, |
| 52 | +- // else "eth%d" when there's reasonable doubt. userspace |
| 53 | +- // can rename the link if it knows better. |
| 54 | ++ /* heuristic: rename to "eth%d" if we are not sure this link |
| 55 | ++ * is two-host (these links keep "usb%d") */ |
| 56 | + if ((dev->driver_info->flags & FLAG_ETHER) != 0 && |
| 57 | +- ((dev->driver_info->flags & FLAG_POINTTOPOINT) == 0 || |
| 58 | +- /* somebody touched it*/ |
| 59 | +- !is_zero_ether_addr(net->dev_addr))) |
| 60 | ++ !usbnet_needs_usb_name_format(dev, net)) |
| 61 | + strscpy(net->name, "eth%d", sizeof(net->name)); |
| 62 | + /* WLAN devices should always be named "wlan%d" */ |
| 63 | + if ((dev->driver_info->flags & FLAG_WLAN) != 0) |
0 commit comments