]> 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>
Thu, 9 Jan 2020 17:08:48 +0000 (18:08 +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 b3564e1a79ca7ee2797fe8a490d70f48f030591d..5618caea856d25cb4e197b493bd60df0db30310f 100644 (file)
@@ -3323,6 +3323,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);
+
                /* Delete l2proxy entries if enabled and used with a link property */
                if (netdev->l2proxy && netdev->link[0] != '\0') {
                        if (lxc_delete_l2proxy(netdev))
@@ -3361,26 +3367,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;