udev-event.c: rename interface to <src>-<dest>, if <dest> taken

e.g. if eth0 should be eth3 and eth3 is waiting to be renamed,
eth0 was renamed to eth0_rename. The kernel would take eth0 as the name
for a new interface and this new eth0 could also become eth0_rename, if
the target name is also taken. To prevent this name clash, the
interfaces are now renamed to <src>-<dest> and the rename is logged.
This commit is contained in:
Harald Hoyer
2010-08-10 16:46:48 +02:00
parent c11f89b61a
commit 09c0310302
+5 -1
View File
@@ -465,6 +465,7 @@ static int rename_netif(struct udev_event *event)
int sk;
struct ifreq ifr;
int err;
char *newdup;
info(event->udev, "changing net interface name from '%s' to '%s'\n",
udev_device_get_sysname(dev), event->name);
@@ -492,13 +493,16 @@ static int rename_netif(struct udev_event *event)
}
/* free our own name, another process may wait for us */
util_strscpyl(ifr.ifr_newname, IFNAMSIZ, udev_device_get_sysname(dev), "_rename", NULL);
newdup = strdup(ifr.ifr_newname);
util_strscpyl(ifr.ifr_newname, IFNAMSIZ, udev_device_get_sysname(dev), "-", newdup, NULL);
free(newdup);
err = ioctl(sk, SIOCSIFNAME, &ifr);
if (err != 0) {
err(event->udev, "error changing netif name %s to %s: %m\n",
ifr.ifr_name, ifr.ifr_newname);
goto exit;
}
rename_netif_kernel_log(ifr);
/* wait 90 seconds for our target to become available */
util_strscpy(ifr.ifr_name, IFNAMSIZ, ifr.ifr_newname);