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.
|
|
|
|
|
|
|
|
---
|
2015-02-13 10:43:21 +01:00
|
|
|
src/udev/udev-event.c | 41 +++++++++++++++++++++++++++++++++++++----
|
|
|
|
1 file changed, 37 insertions(+), 4 deletions(-)
|
2014-03-28 09:34:59 +01:00
|
|
|
|
2014-03-04 11:38:55 +01:00
|
|
|
|
2015-02-13 10:43:21 +01:00
|
|
|
Index: systemd-218/src/udev/udev-event.c
|
|
|
|
===================================================================
|
|
|
|
--- systemd-218.orig/src/udev/udev-event.c
|
|
|
|
+++ systemd-218/src/udev/udev-event.c
|
|
|
|
@@ -767,20 +767,53 @@ out:
|
|
|
|
static int rename_netif(struct udev_event *event) {
|
2014-03-28 09:11:51 +01:00
|
|
|
struct udev_device *dev = event->dev;
|
|
|
|
char name[IFNAMSIZ];
|
|
|
|
+ char interim[IFNAMSIZ], *ptr = &interim[0];
|
|
|
|
const char *oldname;
|
|
|
|
- int r;
|
|
|
|
+ int r, loop;
|
|
|
|
|
|
|
|
oldname = udev_device_get_sysname(dev);
|
|
|
|
|
2015-02-13 10:43:21 +01:00
|
|
|
strscpy(name, IFNAMSIZ, event->name);
|
2014-03-04 11:38:55 +01:00
|
|
|
|
2015-02-13 10:43:21 +01:00
|
|
|
r = rtnl_set_link_name(&event->rtnl, udev_device_get_ifindex(dev), name);
|
2014-03-04 11:38:55 +01:00
|
|
|
- if (r < 0)
|
2014-03-28 09:11:51 +01:00
|
|
|
+ if (r == 0) {
|
2015-02-13 10:43:21 +01:00
|
|
|
+ log_info("renamed network interface %s to %s\n", oldname, name);
|
2014-03-28 09:11:51 +01:00
|
|
|
+ return r;
|
|
|
|
+ } else if (r != -EEXIST) {
|
2015-02-13 10:43:21 +01:00
|
|
|
return log_error_errno(r, "Error changing net interface name '%s' to '%s': %m", oldname, name);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- log_debug("renamed network interface '%s' to '%s'", oldname, name);
|
2014-03-28 09:11:51 +01:00
|
|
|
+ /* free our own name, another process may wait for us */
|
|
|
|
+ strpcpyf(&ptr, IFNAMSIZ, "rename%u", udev_device_get_ifindex(dev));
|
2015-02-13 10:43:21 +01:00
|
|
|
|
|
|
|
- return 0;
|
|
|
|
+ r = rtnl_set_link_name(&event->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;
|
|
|
|
+ }
|
2015-02-13 10:43:21 +01:00
|
|
|
+
|
2014-03-28 09:11:51 +01:00
|
|
|
+ /* log temporary name */
|
2015-02-13 10:43:21 +01:00
|
|
|
+ log_info("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
|
|
|
+
|
2015-02-13 10:43:21 +01:00
|
|
|
+ r = rtnl_set_link_name(&event->rtnl, udev_device_get_ifindex(dev), name);
|
2014-03-28 09:11:51 +01:00
|
|
|
+ if (r == 0) {
|
2015-02-13 10:43:21 +01:00
|
|
|
+ log_info("renamed network interface %s to %s\n", interim, name);
|
2014-03-28 09:11:51 +01:00
|
|
|
+ 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
|
|
|
+ }
|
2015-02-13 10:43:21 +01:00
|
|
|
+ return r;
|
2014-03-28 09:11:51 +01:00
|
|
|
}
|
|
|
|
|
2015-02-13 10:43:21 +01:00
|
|
|
void udev_event_execute_rules(struct udev_event *event,
|