]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: recreate link if its interface name is changed (#8795)
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 26 Apr 2018 19:05:32 +0000 (04:05 +0900)
committerLennart Poettering <lennart@poettering.net>
Thu, 26 Apr 2018 19:05:32 +0000 (21:05 +0200)
If an interface name is changed, then the link state, especially
managed or not, may need to be updated, as its corresponding
.link or .network files may be different. So, let's once drop
the link and recreate a new link object.

Fixes #8794.

src/network/networkd-link.c

index fae750be203d3aedb6392224642afdd58091655c..97c6d21c07fb8c74e365f62690e423de2824e863 100644 (file)
@@ -3215,15 +3215,18 @@ int link_update(Link *link, sd_netlink_message *m) {
         if (r >= 0 && !streq(ifname, link->ifname)) {
                 log_link_info(link, "Interface name change detected, %s has been renamed to %s.", link->ifname, ifname);
 
-                link_free_carrier_maps(link);
-
-                r = free_and_strdup(&link->ifname, ifname);
-                if (r < 0)
-                        return r;
+                if (link->state == LINK_STATE_PENDING) {
+                        r = free_and_strdup(&link->ifname, ifname);
+                        if (r < 0)
+                                return r;
+                } else {
+                        Manager *manager = link->manager;
 
-                r = link_new_carrier_maps(link);
-                if (r < 0)
-                        return r;
+                        link_drop(link);
+                        r = link_add(manager, m, &link);
+                        if (r < 0)
+                                return r;
+                }
         }
 
         r = sd_netlink_message_read_u32(m, IFLA_MTU, &mtu);