]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: fix network device removal
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 9 Jan 2020 17:08:48 +0000 (18:08 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 2 Mar 2020 10:01:37 +0000 (11:01 +0100)
We can't delete by netdev->ifindex since that's the ifindex of the device in
the container, not on the host. The correct thing is done below.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/network.c

index ada1eecc64fe5ba3c102fc973863aa8f7022b458..e718a903e704e7853d7d198dbc0d5cf2a82749c9 100644 (file)
@@ -2653,6 +2653,12 @@ bool lxc_delete_network_priv(struct lxc_handler *handler)
                if (!netdev->ifindex)
                        continue;
 
+               /*
+                * If the network device has been moved back from the
+                * containers network namespace, update the ifindex.
+                */
+               netdev->ifindex = if_nametoindex(netdev->name);
+
                if (netdev->type == LXC_NET_PHYS) {
                        ret = lxc_netdev_rename_by_index(netdev->ifindex, netdev->link);
                        if (ret < 0)
@@ -2684,26 +2690,6 @@ bool lxc_delete_network_priv(struct lxc_handler *handler)
                if (ret < 0)
                        WARN("Failed to deconfigure network device");
 
-               /* Recent kernels remove the virtual interfaces when the network
-                * namespace is destroyed but in case we did not move the
-                * interface to the network namespace, we have to destroy it.
-                */
-               ret = lxc_netdev_delete_by_index(netdev->ifindex);
-               if (ret < 0) {
-                       if (errno != ENODEV) {
-                               WARN("Failed to remove interface \"%s\" with index %d",
-                                    netdev->name[0] != '\0' ? netdev->name : "(null)",
-                                    netdev->ifindex);
-                               goto clear_ifindices;
-                       }
-                       INFO("Interface \"%s\" with index %d already deleted or existing in different network namespace",
-                            netdev->name[0] != '\0' ? netdev->name : "(null)",
-                            netdev->ifindex);
-               }
-               INFO("Removed interface \"%s\" with index %d",
-                    netdev->name[0] != '\0' ? netdev->name : "(null)",
-                    netdev->ifindex);
-
                if (netdev->type != LXC_NET_VETH)
                        goto clear_ifindices;