Weblog entry #2 for Utumno

Udev and its traps
Posted by Utumno on Tue 7 Mar 2006 at 16:57
Tags:
I've got 3 network interfaces and I wanted them to have consistent names across reboots. I read somewhere that this can be achieved with udev by adding a small script

angband:/home/leszek# cat /etc/udev/netinterfaces.rules
KERNEL=="eth*",SYSFS{address}=="00:0E:2E:57:22:23",NAME="eth0"
KERNEL=="eth*",SYSFS{address}=="00:50:BA:01:93:3F",NAME="eth1"
KERNEL=="eth*",SYSFS{address}=="00:13:D4:EF:4B:EC",NAME="eth2"

and a link to it

angband:/etc/udev/rules.d# ls -l /etc/udev/rules.d/ | grep netinterfaces
lrwxrwxrwx 1 root root 22 2006-03-04 23:00 010_netinterfaces.rules -> ../netinterfaces.rules

... turns out the above is not entirely correct.

I took the mac addresses (00:0E:2E:57:22:23) from

angband:/etc/udev/rules.d# ifconfig -a | grep eth
eth0 Link encap:Ethernet HWaddr 00:0E:2E:57:22:23
eth1 Link encap:Ethernet HWaddr 00:50:BA:01:93:3F
eth2 Link encap:Ethernet HWaddr 00:13:D4:EF:4B:EC

which is wrong, because ... ifconfig reports them in uppercase and udev expects them in lowercase!

The correct way to figure out a MAC address of interface eth0 as it is seen by udev is

angband:/etc/udev/rules.d# udevinfo -a -p /sys/class/net/eth0/ | grep address
SYSFS{address}=="00:0e:2e:57:22:23"


 

Comments on this Entry

Posted by dkg (216.254.xx.xx) on Fri 10 Mar 2006 at 16:47
[ Send Message | View dkg's Scratchpad | View Weblogs ]
you can also use ifrename to set up interface names. With ifrename, you just need to set up a simple text file in /etc/iftab.

[ Parent | Reply to this comment ]

Posted by Utumno (211.75.xx.xx) on Fri 10 Mar 2006 at 17:05
[ Send Message | View Utumno's Scratchpad | View Weblogs ]
I know, but that didn't work for me at first, either. Probably it suffers from the same trap. Besides, why adding yet another package if I can do it with an already existing in my system 'udev' ?

[ Parent | Reply to this comment ]

Posted by dkg (216.254.xx.xx) on Fri 10 Mar 2006 at 17:29
[ Send Message | View dkg's Scratchpad | View Weblogs ]
depending on the version of debian you're running, you might need to set up an ifrename initscript to get the interface renaming to work properly. my /etc/iftab contains uppercase hex digits in the MAC address, and it works fine.

however, i've found that if you want to swap around interface names that already exist with ifrename (e.g. if you want "eth0" to be "eth1", and "eth1" to be "eth0"), you need to rename one of them out to an alternate name first, because it can't rename interfaces to an existing name. I get around that particular problem by giving my interfaces nice clean names that aren't auto-assigned names anyway (e.g. "wired" and "wireless", or "lan" and "wan"). This kind of semantic naming is actually pretty useful for scripts which do things to the interfaces as well.

As for doing everything with udev (and no extra packages), i see your point. It feels like a cleaner solution. However, i'm scared of tampering with udev config files because the udev maintainer seems to change them so often. I've only got one simple change to my udev config on a machine running etch (changing the mode of /dev/nvram from 0660 to 0640), and i find myself constantly having to juggle config file changes when udev upgrades come through.

But I haven't tried creating a separate config file that lives outside the shipped config files, like you've done here. i like that because it's a more modular and maintainable arrangment. But reading man udev, i can't figure out which rule takes precedence in the event that two rules match. Is it the first matching rule discovered lexically in /etc/udev/rules.d/ or the last matching rule?

[ Parent | Reply to this comment ]

Posted by Anonymous (87.228.xx.xx) on Tue 18 Apr 2006 at 20:06
The problem with ifrename is that you should run it after each rmmod&&modeprobe (e.g. after hibernate), and, in some cases it make troubles.
You should insert module, then ifrename and after it ifup. if you run ifrename after ifup there possible some problems (with some versions of wpa_supplicant at least).
So, if you don't use 2.4 kernel it would be better to swich to udev.

[ Parent | Reply to this comment ]

Posted by Anonymous (143.121.xx.xx) on Wed 26 Apr 2006 at 09:14
It is the lexical order of the rule files that dictates wich rules take precedence. Because 10-netinterfaces.rules comes before 50-udev.rules (the default udev rule file) the rules in 10-netinterfaces.rules take precedence. I found the "writing udev rules" article ( http://reactivated.net/writing_udev_rules.html ) very clear in explaining the concepts.

[ Parent | Reply to this comment ]

Posted by dkg (216.254.xx.xx) on Wed 26 Apr 2006 at 15:57
[ Send Message | View dkg's Scratchpad | View Weblogs ]
Ah. thanks for the pointer! i understood that the rules were parsed in lexical order, but that didn't tell me whether it was first-match or last-match which took precedence. the following sentence from the linked article shows that it's definitely first-match:
udev will stop processing rules as soon as it finds a matching rule in a file for the new item of hardware that has been detected.
Thanks again!

[ Parent | Reply to this comment ]

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search