Re: net device renaming 2-step, IFNAMSIZ limit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matt Domsch wrote:
I see this in the udev debug logs when using biosdevname (which I
finally got working with SR-IOV devices tonight):

renamed network interface eth60 to eth60-pci2#0_60
renamed network interface eth60-pci2#0_60 to pci2#0_60

So, it worked, however, note that the rename happens in 2 steps, the
middle step of which uses a name that's dangerously close to
IFNAMSIZ, in fact it is 15 chars there.

<...>

I need a solution in which the intermediate name doesn't exceed 15
characters, and is guaranteed to be unique, as there may be lots of
udev instances running in parallel trying to do the same thing.

Ideas?

As we talk on #udev, there is a patch that uses hash32 function inside libudev to create the intermediate name. We use the "oldname-newname" to create the hash. With that,
exceeding IFNAMSIZ isn't a problem:

-------cut here--------

diff --git a/udev/udev-event.c b/udev/udev-event.c
index 0648735..fc4aae0 100644
--- a/udev/udev-event.c
+++ b/udev/udev-event.c
@@ -462,6 +462,7 @@ static void rename_netif_kernel_log(struct ifreq ifr)
 static int rename_netif(struct udev_event *event)
 {
        struct udev_device *dev = event->dev;
+       char iftmp[IFNAMSIZ*2+1];
        int sk;
        struct ifreq ifr;
        int loop;
@@ -492,7 +493,8 @@ static int rename_netif(struct udev_event *event)
                goto out;

        /* free our own name, another process may wait for us */
- util_strscpyl(ifr.ifr_newname, IFNAMSIZ, udev_device_get_sysname(dev), "-", event->name, NULL); + util_strscpyl(iftmp, IFNAMSIZ*2+1, udev_device_get_sysname(dev), "-", event->name, NULL); + util_strscpyl(ifr.ifr_newname, IFNAMSIZ, "eth_%X", util_string_hash32(iftmp), NULL);
        err = ioctl(sk, SIOCSIFNAME, &ifr);
        if (err < 0) {
                err = -errno;

-------cut here--------

Ideas and fixes are welcome,

Piter PUNK
--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux