diff options
author | kay.sievers@vrfy.org <kay.sievers@vrfy.org> | 2004-03-24 23:19:39 -0800 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 21:35:12 -0700 |
commit | f61d732a02c8a5e11c39651a70e3e3fd00529495 (patch) | |
tree | c0d5c08372c1efcb4e668075c796e5b6aa5edb65 /udev-add.c | |
parent | 3e33961b4557f9b709c901b4aa77dfe0220222bd (diff) |
[PATCH] hmm, handle net devices with udev?
Hmm, Arndt Bergmann sent a patch like this one a few weeks ago and
I want to bring the question back, if we want to handle net device
naming with udev.
With this patch it is actually possible to specify something like this
in udev.rules:
KERNEL="dummy*", SYSFS{address}="00:00:00:00:00:00", SYSFS{features}="0x0", NAME="blind%n"
KERNEL="eth*", SYSFS{address}="00:0d:60:77:30:91", NAME="private"
and you will get:
[root@pim udev.kay]# cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 1500 30 0 0 0 0 0 0 1500 30 0 0 0 0 0 0
private: 278393 1114 0 0 0 0 0 0 153204 1468 0 0 0 0 0 0
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
blind0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The udevinfo program is also working:
[root@pim udev.kay]# ./udevinfo -a -p /sys/class/net/private
looking at class device '/sys/class/net/private':
SYSFS{addr_len}="6"
SYSFS{address}="00:0d:60:77:30:91"
SYSFS{broadcast}="ff:ff:ff:ff:ff:ff"
SYSFS{features}="0x3a9"
SYSFS{flags}="0x1003"
SYSFS{ifindex}="2"
SYSFS{iflink}="2"
SYSFS{mtu}="1500"
SYSFS{tx_queue_len}="1000"
SYSFS{type}="1"
follow the class device's "device"
looking at the device chain at '/sys/devices/pci0000:00/0000:00:1e.0/0000:02:01.0':
BUS="pci"
ID="0000:02:01.0"
SYSFS{class}="0x020000"
SYSFS{detach_state}="0"
SYSFS{device}="0x101e"
SYSFS{irq}="11"
SYSFS{subsystem_device}="0x0549"
SYSFS{subsystem_vendor}="0x1014"
SYSFS{vendor}="0x8086"
The matching device will be renamed to the given name. The device name
will not be put into the udev database, cause the kernel renames the
device and the sysfs name disappears.
I like it, cause it plugs in nicely. We have all the naming features
and sysfs queries and walks inside of udev. The sysfs timing races
are already solved and the management tools are working for net devices
too. nameif can only match the MAC address now. udev can match any sysfs
value of the device tree the net device is connected to.
But right, net devices do not have device nodes :)
Diffstat (limited to 'udev-add.c')
-rw-r--r-- | udev-add.c | 86 |
1 files changed, 68 insertions, 18 deletions
diff --git a/udev-add.c b/udev-add.c index aef755442f..4aff06e15f 100644 --- a/udev-add.c +++ b/udev-add.c @@ -30,6 +30,10 @@ #include <sys/stat.h> #include <sys/types.h> #include <grp.h> +#include <net/if.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <linux/sockios.h> #ifndef __KLIBC__ #include <pwd.h> #include <utmp.h> @@ -342,16 +346,16 @@ exit: /* wait for the "dev" file to show up in the directory in sysfs. * If it doesn't happen in about 10 seconds, give up. */ -#define SECONDS_TO_WAIT_FOR_DEV 10 -static int sleep_for_dev(char *path) +#define SECONDS_TO_WAIT_FOR_FILE 10 +static int sleep_for_file(char *path, char* file) { char filename[SYSFS_PATH_MAX + 6]; - int loop = SECONDS_TO_WAIT_FOR_DEV; + int loop = SECONDS_TO_WAIT_FOR_FILE; int retval; strfieldcpy(filename, sysfs_path); strfieldcat(filename, path); - strfieldcat(filename, "/dev"); + strfieldcat(filename, file); while (loop--) { struct stat buf; @@ -369,6 +373,30 @@ exit: return retval; } +static int rename_net_if(struct udevice *dev) +{ + int sk; + struct ifreq ifr; + int retval; + + sk = socket(PF_INET, SOCK_DGRAM, 0); + if (sk < 0) { + dbg("error opening socket"); + return -1; + } + + memset(&ifr, 0x00, sizeof(struct ifreq)); + strfieldcpy(ifr.ifr_name, dev->kernel_name); + strfieldcpy(ifr.ifr_newname, dev->name); + + dbg("changing net interface name from '%s' to '%s'", dev->kernel_name, dev->name); + retval = ioctl(sk, SIOCSIFNAME, &ifr); + if (retval != 0) + dbg("error changing net interface name"); + + return retval; +} + int udev_add_device(char *path, char *subsystem, int fake) { struct sysfs_class_device *class_dev = NULL; @@ -378,39 +406,61 @@ int udev_add_device(char *path, char *subsystem, int fake) memset(&dev, 0x00, sizeof(dev)); /* for now, the block layer is the only place where block devices are */ - if (strcmp(subsystem, "block") == 0) - dev.type = 'b'; - else - dev.type = 'c'; - retval = sleep_for_dev(path); - if (retval != 0) - goto exit; + dev.type = get_device_type(path, subsystem); + + switch (dev.type) { + case 'b': + case 'c': + retval = sleep_for_file(path, "/dev"); + break; + + case 'n': + retval = sleep_for_file(path, "/address"); + break; + + default: + dbg("unknown device type '%c'", dev.type); + retval = -EINVAL; + } class_dev = get_class_dev(path); if (class_dev == NULL) goto exit; - retval = get_major_minor(class_dev, &dev); - if (retval != 0) { - dbg("get_major_minor failed"); - goto exit; + if (dev.type == 'b' || dev.type == 'c') { + retval = get_major_minor(class_dev, &dev); + if (retval != 0) { + dbg("get_major_minor failed"); + goto exit; + } } retval = namedev_name_device(class_dev, &dev); if (retval != 0) goto exit; - if (!fake) { + if (!fake && (dev.type == 'b' || dev.type == 'c')) { retval = udevdb_add_dev(path, &dev); if (retval != 0) dbg("udevdb_add_dev failed, but we are going to try " "to create the node anyway. But remove might not " "work properly for this device."); - } + dbg("name='%s'", dev.name); - retval = create_node(&dev, fake); + switch (dev.type) { + case 'b': + case 'c': + retval = create_node(&dev, fake); + break; + + case 'n': + retval = rename_net_if(&dev); + if (retval != 0) + dbg("net device naming failed"); + break; + } if ((retval == 0) && (!fake)) dev_d_send(&dev, subsystem); |