2014-03-04 11:38:55 +01:00
|
|
|
From: Robert Milasan <rmilasan@suse.com>
|
|
|
|
Cc: Werner Fink <werner@suse.de>
|
|
|
|
Subject: udev always rename network
|
|
|
|
|
|
|
|
Date: Thu, 28 Mar 2013 09:24:43 +0000
|
|
|
|
udev: ensure that the network interfaces are renamed even if they exist (bnc#809843).
|
|
|
|
|
|
|
|
Date: Tue, 4 Mar 2014 10:29:21 +0000
|
|
|
|
Port the patch of Robert to systemd v210 and test it out.
|
|
|
|
|
|
|
|
---
|
2014-03-28 09:34:59 +01:00
|
|
|
udev-event.c | 42 ++++++++++++++++++++++++++++++++++++++----
|
|
|
|
1 file changed, 38 insertions(+), 4 deletions(-)
|
|
|
|
|
2014-03-04 11:38:55 +01:00
|
|
|
|
2014-03-28 09:17:23 +01:00
|
|
|
--- systemd-210/src/udev/udev-event.c
|
|
|
|
+++ systemd-210/src/udev/udev-event.c 2014-03-27 13:19:06.727748307 +0000
|
2014-03-28 09:34:59 +01:00
|
|
|
@@ -750,8 +750,9 @@ static int rename_netif(struct udev_even
|
2014-03-28 09:11:51 +01:00
|
|
|
struct udev_device *dev = event->dev;
|
|
|
|
_cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
|
|
|
|
char name[IFNAMSIZ];
|
|
|
|
+ char interim[IFNAMSIZ], *ptr = &interim[0];
|
|
|
|
const char *oldname;
|
|
|
|
- int r;
|
|
|
|
+ int r, loop;
|
|
|
|
|
|
|
|
oldname = udev_device_get_sysname(dev);
|
|
|
|
|
2014-03-28 09:34:59 +01:00
|
|
|
@@ -765,12 +766,45 @@ static int rename_netif(struct udev_even
|
2014-03-04 11:38:55 +01:00
|
|
|
return r;
|
|
|
|
|
|
|
|
r = rtnl_set_link_name(rtnl, udev_device_get_ifindex(dev), name);
|
|
|
|
- if (r < 0)
|
2014-03-28 09:11:51 +01:00
|
|
|
+ if (r == 0) {
|
|
|
|
+ print_kmsg("renamed network interface %s to %s\n", oldname, name);
|
|
|
|
+ return r;
|
|
|
|
+ } else if (r != -EEXIST) {
|
|
|
|
log_error("error changing net interface name %s to %s: %s",
|
|
|
|
oldname, name, strerror(-r));
|
2014-03-04 11:38:55 +01:00
|
|
|
- else
|
2014-03-28 09:11:51 +01:00
|
|
|
- print_kmsg("renamed network interface %s to %s", oldname, name);
|
|
|
|
+ return r;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* free our own name, another process may wait for us */
|
|
|
|
+ strpcpyf(&ptr, IFNAMSIZ, "rename%u", udev_device_get_ifindex(dev));
|
|
|
|
+
|
|
|
|
+ r = rtnl_set_link_name(rtnl, udev_device_get_ifindex(dev), interim);
|
2014-03-04 11:38:55 +01:00
|
|
|
+ if (r < 0) {
|
2014-03-28 09:11:51 +01:00
|
|
|
+ log_error("error changing net interface name %s to %s: %s",
|
|
|
|
+ oldname, interim, strerror(-r));
|
|
|
|
+ return r;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /* log temporary name */
|
|
|
|
+ print_kmsg("renamed network interface %s to %s\n", oldname, interim);
|
2014-03-04 11:38:55 +01:00
|
|
|
+
|
2014-03-28 09:11:51 +01:00
|
|
|
+ loop = 90 * 20;
|
|
|
|
+ while (loop--) {
|
|
|
|
+ const struct timespec duration = { 0, 1000 * 1000 * 1000 / 20 };
|
|
|
|
+ nanosleep(&duration, NULL);
|
2014-03-04 11:38:55 +01:00
|
|
|
+
|
2014-03-28 09:11:51 +01:00
|
|
|
+ r = rtnl_set_link_name(rtnl, udev_device_get_ifindex(dev), name);
|
|
|
|
+ if (r == 0) {
|
|
|
|
+ print_kmsg("renamed network interface %s to %s\n", interim, name);
|
|
|
|
+ break;
|
|
|
|
+ }
|
2014-03-04 11:38:55 +01:00
|
|
|
+
|
2014-03-28 09:11:51 +01:00
|
|
|
+ if (r != -EEXIST) {
|
2014-03-04 11:38:55 +01:00
|
|
|
+ log_error("error changing net interface name %s to %s: %s",
|
2014-03-28 09:11:51 +01:00
|
|
|
+ interim, name, strerror(-r));
|
|
|
|
+ break;
|
2014-03-04 11:38:55 +01:00
|
|
|
+ }
|
2014-03-28 09:11:51 +01:00
|
|
|
+ }
|
2014-03-04 11:38:55 +01:00
|
|
|
return r;
|
2014-03-28 09:11:51 +01:00
|
|
|
}
|
|
|
|
|