]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: fix handling of network interface renaming
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 9 Sep 2021 23:09:56 +0000 (08:09 +0900)
committerLennart Poettering <lennart@poettering.net>
Fri, 10 Sep 2021 18:49:05 +0000 (20:49 +0200)
Fixes #20657.

src/network/networkd-link.c

index 4afd540d201512f97c196341543bef40abc18f18..caad6205ae83bad7f5c193388e719d086fbe9362 100644 (file)
@@ -1470,17 +1470,21 @@ static int link_initialized(Link *link, sd_device *device) {
         assert(link);
         assert(device);
 
-        if (link->state != LINK_STATE_PENDING)
-                return 0;
+        /* Always replace with the new sd_device object. As the sysname (and possibly other properties
+         * or sysattrs) may be outdated. */
+        sd_device_ref(device);
+        sd_device_unref(link->sd_device);
+        link->sd_device = device;
 
-        if (link->sd_device)
+        /* Do not ignore unamanaged state case here. If an interface is renamed after being once
+         * configured, and the corresponding .network file has Name= in [Match] section, then the
+         * interface may be already in unmanaged state. See #20657. */
+        if (!IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_UNMANAGED))
                 return 0;
 
         log_link_debug(link, "udev initialized link");
         link_set_state(link, LINK_STATE_INITIALIZED);
 
-        link->sd_device = sd_device_ref(device);
-
         /* udev has initialized the link, but we don't know if we have yet
          * processed the NEWLINK messages with the latest state. Do a GETLINK,
          * when it returns we know that the pending NEWLINKs have already been