]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: attempt device rename even if interface is up
authorNick Rosbrook <nick.rosbrook@canonical.com>
Fri, 2 Dec 2022 20:35:25 +0000 (15:35 -0500)
committerNick Rosbrook <nick.rosbrook@canonical.com>
Thu, 15 Dec 2022 14:35:26 +0000 (09:35 -0500)
Currently rename_netif() will not attempt to rename a device if it is
already up, because the kernel will return -EBUSY unless live renaming
is allowed on the device. This restriction will be removed in a future
kernel version [1].

To cover both cases, always attempt to rename the interface and return 0
if we get -EBUSY.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=bd039b5ea2a9

src/udev/udev-event.c

index 30326e4d1cc09a1d558366de54afdbad450c60a5..63be5275e4b418ce83ccce15e55c83bc2335f4ac 100644 (file)
@@ -862,7 +862,6 @@ int udev_event_spawn(
 static int rename_netif(UdevEvent *event) {
         const char *oldname;
         sd_device *dev;
-        unsigned flags;
         int ifindex, r;
 
         assert(event);
@@ -896,16 +895,6 @@ static int rename_netif(UdevEvent *event) {
                 return 0;
         }
 
-        r = rtnl_get_link_info(&event->rtnl, ifindex, NULL, &flags, NULL, NULL, NULL);
-        if (r < 0)
-                return log_device_warning_errno(dev, r, "Failed to get link flags: %m");
-
-        if (FLAGS_SET(flags, IFF_UP)) {
-                log_device_info(dev, "Network interface '%s' is already up, refusing to rename to '%s'.",
-                                oldname, event->name);
-                return 0;
-        }
-
         /* Set ID_RENAMING boolean property here. It will be dropped when the corresponding move uevent is processed. */
         r = device_add_property(dev, "ID_RENAMING", "1");
         if (r < 0)
@@ -927,6 +916,11 @@ static int rename_netif(UdevEvent *event) {
                 return log_device_debug_errno(event->dev_db_clone, r, "Failed to update database under /run/udev/data/: %m");
 
         r = rtnl_set_link_name(&event->rtnl, ifindex, event->name);
+        if (r == -EBUSY) {
+                log_device_info(dev, "Network interface '%s' is already up, cannot rename to '%s'.",
+                                oldname, event->name);
+                return 0;
+        }
         if (r < 0)
                 return log_device_error_errno(dev, r, "Failed to rename network interface %i from '%s' to '%s': %m",
                                               ifindex, oldname, event->name);