Bug#941636: udev: 73-usb-net-by-mac.rules breaks systemd.link(5) network interface renaming for usb network adapters
Benjamin Poirier
benjamin.poirier at gmail.com
Thu Oct 3 23:44:02 BST 2019
On 2019/10/03 13:34, Michael Biebl wrote:
> Hi
>
> Am 03.10.19 um 10:17 schrieb Benjamin Poirier:
> > Package: udev
> > Version: 243-2
> > Severity: normal
> >
> > /lib/udev/rules.d/73-usb-net-by-mac.rules prevents the renaming of network
> > interfaces from usb adapters using the systemd.link(5) mechanism.
> >
> > The latter is implemented using /lib/udev/rules.d/80-net-setup-link.rules
> > which is ineffective because 73-usb-net-by-mac.rules has previously
> > unconditionally set a name (based on the mac address).
>
> Not quite unconditionally. The conditions are
That's right, thanks for correcting me.
> - user has not disabled persistent interface naming via the kernel
> command line (net.ifnames=0)
systemd.link also checks this kernel option:
"NamePolicy= may be disabled by specifying net.ifnames=0 on the kernel
command line."
> - the interface name has not been provided by user space
> ATTR{name_assign_type}=="3"
We can change the 73-usb-net-by-mac.link I gave as an example to add
"keep":
[Link]
NamePolicy=keep mac
> - NAME= is unset
This is also checked by 80-net-setup-link.rules
> - it has a universally administered (stable) MAC address (second bit
> is 0).
net_setup_link implements the same condition:
"ID_NET_NAME_MAC=prefixxAABBCCDDEEFF
[...] It is available if the device has a fixed MAC address. [...]
"
The check is based on addr_assign_type provided by the kernel. See
src/udev/udev-builtin-net_id.c names_mac().
> - the user has no custom /etc/udev/rules.d/80-net-setup-link.rules or
^^^^^^ incorrect
> /etc/systemd/network/99-default.link
This is an incomplete way of reimplementing udev functionality. In
particular, the user will get a different behavior if they do
$ cp /lib/systemd/network/99-default.link /etc/systemd/network/
even though the naming rules are effectively the same.
>
> You are correct though, we do not handle the case where a user has a
> arbitrarily named .link file which is used to rename a USB device.
>
> Fwiw, I've run into this issue myself some time ago, where I created a
> .link file which supposedly was not applied. After some head scratching
> it was then clear that the udev rule file had already renamed the interface.
>
> My solution back then was a
> touch /etc/udev/rules.d/73-usb-net-by-mac.rules (basically what you
> figured out as well)
>
>
> > For example
> > ben at f3:~$ cat /etc/systemd/network/10-dock.link
> > [Match]
> > MACAddress=3c:e1:a1:01:02:03
> >
> > [Link]
> > Name=dock
> > does not work (with the related interface being a usb adapter).
> >
> > I believe that /lib/udev/rules.d/73-usb-net-by-mac.rules should be removed. In
> > fact, the same functionality can be provided by the systemd.link mechanism
> > while also allowing users to override the default rule. I tested this by
> > setting up
> > /etc/udev/rules.d/73-usb-net-by-mac.rules -> /dev/null
> > and adding
> > ben at f3:~$ cat /etc/systemd/network/73-usb-net-by-mac.link
> > [Match]
> > Path=*-usb-*
> >
> > [Link]
> > NamePolicy=mac
> >
> > (Ideally the match would be done using something like Type= but DEVTYPE is not
> > an attribute of the network device. Matching on the ID_BUS udev attribute
> > would work but is not supported by net_setup_link I think.)
I just noticed that 73-usb-net-by-mac.rules matches on
'SUBSYSTEMS=="usb"' which "[searches] the devpath upwards for a matching
device subsystem name." [udev(7)]. I think this is equivalent to the
'Path=*-usb-*' expression in the .link file I suggested.
I still think that match is not ideal, but at least its equivalent in
behavior to 73-usb-net-by-mac.rules.
> >
> > This still used a name based on the mac address by default (instead of based
> > on the slot) and also allowed me to change the name by adding a file like the
> > 10-dock.link example above.
>
>
> Using a .link file is an interesting idea but afaics we can't express
> all the conditions I mentioned above.
> So we would trade one set of corner cases where it doesn't behave as
> expected with another set of corner cases.
> Not sure if we can make everyone happy.
>
> Martin, as main author of 73-usb-net-by-mac.rules, what's your take on this?
>
> Michael
>
> --
> Why is it that all of the instruments seeking intelligent life in the
> universe are pointed away from Earth?
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://alioth-lists.debian.net/pipermail/pkg-systemd-maintainers/attachments/20191004/feeabf9f/attachment.sig>
More information about the Pkg-systemd-maintainers
mailing list