From: Christian Brauner Date: Thu, 9 Jan 2020 17:08:48 +0000 (+0100) Subject: network: fix network device removal X-Git-Tag: lxc-4.0.0~61^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0104c121a734f63d3304ee0210f7a7dc943ac173;p=thirdparty%2Flxc.git network: fix network device removal 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 --- diff --git a/src/lxc/network.c b/src/lxc/network.c index b3564e1a7..5618caea8 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -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;