USB ethernet interface rename

Hello,
I have a problem renaming 2 USB ethernet interfaces using udev rule. We developed custom Verdin motherboard that is equiped with two ethernet to USB ICs connected to USB hub. After booting the system, two new ethernet interfaces are discovered and enumerated:

Booth interfaces seems stable, but the problem arises after rebooting. Interfaces are enumerated randomly. I wrote /etc/udev/rules.d/70-persistent-net.rules that should enumerate the interfaces and rename them to uppercase basing on interface MAC addresses:

70-persistent-net.rules:

SUBSYSTEM=="net", ACTION=="add|change", DRIVERS=="?*", ATTR{address}=="46:38:02:53:81:ab",ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="ETH0"

SUBSYSTEM=="net", ACTION=="add|change", DRIVERS=="?*", ATTR{address}=="66:ab:54:b6:f2:4d",ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="ETH1

I reload rules:

sudo udevadm control --reload-rules
sudo udevadm trigger

But interface names stay the same, even after reboot. Has anyone encountered this ?

Hi @spasoye ,

Can you try removing the KERNEL part of the udev rule, as indicated here: linux - Udev : renaming my network interface - Unix & Linux Stack Exchange

With this I was able to successfully rename the network interface on an Apalis iMX6 with a TorizonCore 6.3 nightly release, but it should work on other releases as well.

torizon@apalis-imx6-05229115:~$ cat /etc/udev/rules.d/70-persistent-net.rules 
SUBSYSTEM=="net", ACTION=="add|change", DRIVERS=="?*", ATTR{address}=="<MAC_ADDRESS_HERE>",ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="ETH0"
torizon@apalis-imx6-05229115:~$ sudo reboot
[...]
torizon@apalis-imx6-05229115:~$ ifconfig
ETH0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.22.1.126  netmask 255.255.255.0  broadcast 10.22.1.255
[...]

See if this helps you.

Best regards,
Lucas Akira

It doesn’t help. However I’m running version 5.4. I forgot to post image version:

$ uname -a
Linux verdin-imx8mm-07213994 5.4.193-5.7.2+git.b60d3160fd04 #1-TorizonCore SMP PREEMPT Fri Dec 23 15:47:24 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

Hi @spasoye ,

Maybe the udev rules are being executed after NetworkManager is already using the interfaces, so udev can’t change the interface names. I was able to rename an external USB WLAN interface on a Verdin iMX8M Plus with TorizonCore 5.7.2 (it has the same kernel version you’re using) by doing the following:

[keyfile]
unmanaged-devices=interface-name:eth0;interface-name:eth1
[Match]
MACAddress=aa:bb:cc:dd:ee:ff

[Link]
Name=ETH0

  • Reboot the OS. The interfaces should have the newer names.

Best regards,
Lucas Akira

No luck,
interface names are still unchanged after the reboot.
These are the permissions, is this okay:

-rw-r--r-- 1 root root 73 Jul 31 13:10 /etc/systemd/network/10-persistent-eth0.link
...
-rw-r--r-- 1 root root 81 Jul 31 13:35 /etc/NetworkManager/conf.d/99-unmanaged-devices.conf

Hi @spasoye ,

The permissions are the same as I have on my files, so this shouldn’t be a problem.

I think this issue is more of a udev/systemd/general Linux problem rather than one specifically related to TorizonCore.
Can you try renaming other network devices on the Verdin and see if this last method works with them?

Best regards,
Lucas Akira

This is udev rule I use to handle the same, random enumeration, issue with 2 CAN interfaces we implemented on our board, however both interfaces are implemented via SPI interface:

SUBSYSTEM!="net", GOTO="my_can_end"
ACTION!="add", GOTO="my_can_end"

# enumerate external CAN as CAN1
DEVPATH=="/devices/platform/soc@0/soc@0:bus@30800000/30820000.spi/spi_master/spi0/spi0.0/net/can?", NAME="CAN1"

# enumerate internal CAN as CAN0
DEVPATH=="/devices/platform/soc@0/soc@0:bus@30800000/30840000.spi/spi_master/spi2/spi2.0/net/can?", NAME="CAN0"

LABEL="my_can_end"

I had no problems running this rule.

Hi @spasoye ,

You can try to use another identifier to differentiate between the USB interfaces, such as the udev property ID_PATH, which I think is unique to each USB physical path. You can get this property for each interface by executing

sudo udevadm info /sys/class/net/eth0
sudo udevadm info /sys/class/net/eth1

With this you can put the ID_PATH in the Path property of the .link files in /etc/systemd/network/ e.g.

  • 10-ETH0.link :
[Match]
Path=platform-xhci-hcd.1.auto-usb-0:1.2:1.0
[Link]
Name=ETH0
  • 10-ETH1.link :
[Match]
Path=platform-xhci-hcd.1.auto-usb-0:1.1:1.0
[Link]
Name=ETH1

Best regards,
Lucas Akira

I tried this, but still no luck. But I wrote this .rules :

SUBSYSTEM!="net", GOTO="my_can_end"
ACTION!="add", GOTO="my_can_end"

# enumerate eth to ETH1
DEVPATH=="/devices/platform/soc@0/soc@0:bus@32c00000/32e50000.usb/ci_hdrc.1/usb2/2-1/2-1.1/2-1.1:1.0/net/eth?", NAME="ETH1"

# enumerate eth as ETH0
DEVPATH=="/devices/platform/soc@0/soc@0:bus@32c00000/32e50000.usb/ci_hdrc.1/usb2/2-1/2-1.2/2-1.2:1.0/net/eth?", NAME="ETH0"

LABEL="my_can_end"

As I can see ID_PATH is analogous to DEVPATH and I managed to apply CAN IF rules using DEVPATH variable. After applying this rules, ethernet interfaces are renamed and after multiple reboots I havent noticed that interfaces switched theirs enumeration.

Hi @spasoye ,

So, if I understood correctly you managed to solve your issue, is this correct?

Best regards,
Lucas Akira

Sorry for late reply, but for now, I think that this solved my issue.

Glad you found a solution!

Best regards,
Lucas Akira