LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   correcting udev network persistent-net rules (http://www.linuxquestions.org/questions/linux-networking-3/correcting-udev-network-persistent-net-rules-903203/)

Skaperen 09-15-2011 12:10 PM

correcting udev network persistent-net rules
 
I have been using the following to maintain consistency with udev across MAC address changes (e.g. swapping out NIC cards, etc). By default, udev builds rules the first time to associate an interface name with a MAC address, which works fine until the NIC cards are changed, or the system disk is moved to another box that has different MAC addresses (e.g. even in the motherboard):

Code:

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth0", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth1", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth2", NAME="eth2"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth3", NAME="eth3"

The problem with the above "solution" is it will not attempt to correct a different probe order when that happens during kernel initialization. I've never seen such a thing happen with multiple port NIC cards (like motherboards with 2 or 4 ports). But I'm now working with some machines which have 1 NIC on the motherboard and a dual port card plugged in with a different driver. Sometimes the interfaces come up differently.

So I really do need to implement something that makes things consistent. But the MAC address simply cannot do this because it is too volatile (e.g. it can change with NIC cards or motherboard is changed).

The idea I have is to use the BUS address. In the /sys/devices tree this is known as "device". I could code udev rules to match specific devices to specific interfaces. Still there is a problem with mass deployment in that these device bus addresses are not the same on different machines. I do want the setup to be the same. So merely coding specific device addresses and interface names in a udev rule would not accomplish it universally (e.g. each machine might need a different one).

Potentially I could have my own script generate such a configuration for a specific machine. But my question right now is, is there a way to just tell udev to do what it does, but instead of basing the association it stores on the MAC address, base it instead on the BUS device address.

So instead of ending up with /etc/udev/rules.d/70-persistent-net.rules having:
Code:

# This file maintains persistent names for network interfaces.
# See udev(7) for syntax.
#
# Entries are automatically added by the 75-persistent-net-generator.rules
# file; however you are also free to add your own entries.

# PCI device 0x8086:0x10d3 (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:14:c4:58", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x10d3 (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:14:c4:59", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

I would get something that had "ATTR{device}" instead of "ATTR{address}". If udev can do this (somehow), that would be the "right way" I think. But if not, I guess I would have to generate these myself (probably scripted after testing a couple of them).

cendryon 09-19-2011 02:54 PM

Hi

You can try DEVPATH instead of ATTR{address}
Code:

# ls -l /sys/class/net/
lrwxrwxrwx 1 root root 0 sept. 19 21:41 /sys/class/net/eth0 -> ../../devices/pci0000:00/0000:00:19.0/net/eth0/
lrwxrwxrwx 1 root root 0 sept. 19 21:41 /sys/class/net/eth1 -> ../../devices/pci0000:00/0000:00:1c.7/0000:05:00.0/0000:06:09.0/0000:0e:00.0/net/eth1/
lrwxrwxrwx 1 root root 0 sept. 19 21:41 /sys/class/net/lo -> ../../devices/virtual/net/lo/

Then your DEVPATH conditions would be
Code:

DEVPATH="/devices/pci0000:00/0000:00:19.0/*"
DEVPATH="/devices/pci0000:00/0000:00:1c.7/0000:05:00.0/0000:06:09.0/0000:0e:00.0/*"

This would only work if in each machine the bus (00: or 0e: ), slot (:19 or :00) and maybe function (.0) in the output of lspci is the same, as is it the last part of the devpath
Code:

# lspci | grep Ethernet
00:19.0 Ethernet controller: Intel Corporation 82579V Gigabit Network Connection (rev 05)
0e:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 06)

Cheers

Skaperen 09-19-2011 04:11 PM

I've gone with the approach of having a script scan /sys/devices and look for NICs in bus address order. It generates a udev rules file with interface names numbered according to that order.

That script is in this thread: http://www.linuxquestions.org/questi...-rules-903234/


All times are GMT -5. The time now is 09:38 PM.