I would like a NIC with specific MAC address to have a particular name, something I've usually done in the past with a udev rule. I want to avoid eth0 and eth1 coming up in a random order. This is on an x64 virtual machine.
I was going to do something like this:
ETH1_MAC_ADDRESS=$(cat /sys/class/net/eth1/address)
if [ "$ETH1_MAC_ADDRESS" != "<expected mac>" ]; then
echo "Interfaces are in the wrong order"
# Swap the two NICs round.
/usr/sbin/ip link set eth0 name ethtmp0
/usr/sbin/ip link set eth1 name eth0
/usr/sbin/ip link set ethtmp0 name eth1
fi
But it's not very elegant, wondered if there's a better way more in tune with the OpenWrt network config.
random order means there is no guarantee the 'second' nic will be initialized / parsable when this code runs ( unless you detect hotplug complete state and run outside of hotplug )
if you want to update uci... ( at the hotplug stage ) then you may need two handlers ( one for net one of iface to properly handle the logical side of things...
a better approach is to somehow hook into the proto-handlers or similar @ netifd-ubus or something... and implement some sort of "option sys-walk 'XYZ'" || "option deviceid 'ABC'" etc. etc. ... ( aka... there is no cleaner way short of hw-level init tweaks or changes ... well... you could remove the secondary module from modules.d/boot and probe it at runtime I suppose or place it right at the end of the module stack )