Unverified Commit 3400d77a by Christian Brauner Committed by Stéphane Graber

network: clear ifindeces

We need to clear any ifindeces we recorded so liblxc won't have cached stale data which would cause it to fail on reboot we're we don't re-read the on-disk config file. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 39a01266
...@@ -2334,7 +2334,7 @@ bool lxc_delete_network_unpriv(struct lxc_handler *handler) ...@@ -2334,7 +2334,7 @@ bool lxc_delete_network_unpriv(struct lxc_handler *handler)
TRACE("Renamed interface with index %d to its " TRACE("Renamed interface with index %d to its "
"initial name \"%s\"", "initial name \"%s\"",
netdev->ifindex, netdev->link); netdev->ifindex, netdev->link);
continue; goto clear_ifindices;
} }
ret = netdev_deconf[netdev->type](handler, netdev); ret = netdev_deconf[netdev->type](handler, netdev);
...@@ -2342,17 +2342,17 @@ bool lxc_delete_network_unpriv(struct lxc_handler *handler) ...@@ -2342,17 +2342,17 @@ bool lxc_delete_network_unpriv(struct lxc_handler *handler)
WARN("Failed to deconfigure network device"); WARN("Failed to deconfigure network device");
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
continue; goto clear_ifindices;
if (netdev->link[0] == '\0' || !is_ovs_bridge(netdev->link)) if (netdev->link[0] == '\0' || !is_ovs_bridge(netdev->link))
continue; goto clear_ifindices;
if (netdev->priv.veth_attr.pair[0] != '\0') if (netdev->priv.veth_attr.pair[0] != '\0')
hostveth = netdev->priv.veth_attr.pair; hostveth = netdev->priv.veth_attr.pair;
else else
hostveth = netdev->priv.veth_attr.veth1; hostveth = netdev->priv.veth_attr.veth1;
if (hostveth[0] == '\0') if (hostveth[0] == '\0')
continue; goto clear_ifindices;
ret = lxc_delete_network_unpriv_exec(handler->lxcpath, ret = lxc_delete_network_unpriv_exec(handler->lxcpath,
handler->name, netdev, handler->name, netdev,
...@@ -2360,10 +2360,23 @@ bool lxc_delete_network_unpriv(struct lxc_handler *handler) ...@@ -2360,10 +2360,23 @@ bool lxc_delete_network_unpriv(struct lxc_handler *handler)
if (ret < 0) { if (ret < 0) {
WARN("Failed to remove port \"%s\" from openvswitch " WARN("Failed to remove port \"%s\" from openvswitch "
"bridge \"%s\"", hostveth, netdev->link); "bridge \"%s\"", hostveth, netdev->link);
continue; goto clear_ifindices;
} }
INFO("Removed interface \"%s\" from \"%s\"", hostveth, INFO("Removed interface \"%s\" from \"%s\"", hostveth,
netdev->link); netdev->link);
clear_ifindices:
/* We need to clear any ifindeces we recorded so liblxc won't
* have cached stale data which would cause it to fail on reboot
* we're we don't re-read the on-disk config file.
*/
netdev->ifindex = 0;
if (netdev->type == LXC_NET_PHYS) {
netdev->priv.phys_attr.ifindex = 0;
} else if (netdev->type == LXC_NET_VETH) {
netdev->priv.veth_attr.veth1[0] = '\0';
netdev->priv.veth_attr.ifindex = 0;
}
} }
return true; return true;
...@@ -2496,7 +2509,7 @@ bool lxc_delete_network_priv(struct lxc_handler *handler) ...@@ -2496,7 +2509,7 @@ bool lxc_delete_network_priv(struct lxc_handler *handler)
"\"%s\" to its initial name \"%s\"", "\"%s\" to its initial name \"%s\"",
netdev->ifindex, netdev->name, netdev->ifindex, netdev->name,
netdev->link); netdev->link);
continue; goto clear_ifindices;
} }
ret = netdev_deconf[netdev->type](handler, netdev); ret = netdev_deconf[netdev->type](handler, netdev);
...@@ -2516,18 +2529,17 @@ bool lxc_delete_network_priv(struct lxc_handler *handler) ...@@ -2516,18 +2529,17 @@ bool lxc_delete_network_priv(struct lxc_handler *handler)
netdev->ifindex); netdev->ifindex);
} else if (ret < 0) { } else if (ret < 0) {
WARN("Failed to remove interface \"%s\" with " WARN("Failed to remove interface \"%s\" with "
continue;
"index %d: %s", "index %d: %s",
netdev->name[0] != '\0' ? netdev->name : "(null)", netdev->name[0] != '\0' ? netdev->name : "(null)",
netdev->ifindex, strerror(-ret)); netdev->ifindex, strerror(-ret));
continue; goto clear_ifindices;
} }
INFO("Removed interface \"%s\" with index %d", INFO("Removed interface \"%s\" with index %d",
netdev->name[0] != '\0' ? netdev->name : "(null)", netdev->name[0] != '\0' ? netdev->name : "(null)",
netdev->ifindex); netdev->ifindex);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
continue; goto clear_ifindices;
/* Explicitly delete host veth device to prevent lingering /* Explicitly delete host veth device to prevent lingering
* devices. We had issues in LXD around this. * devices. We had issues in LXD around this.
...@@ -2537,19 +2549,21 @@ bool lxc_delete_network_priv(struct lxc_handler *handler) ...@@ -2537,19 +2549,21 @@ bool lxc_delete_network_priv(struct lxc_handler *handler)
else else
hostveth = netdev->priv.veth_attr.veth1; hostveth = netdev->priv.veth_attr.veth1;
if (hostveth[0] == '\0') if (hostveth[0] == '\0')
continue; goto clear_ifindices;
ret = lxc_netdev_delete_by_name(hostveth); ret = lxc_netdev_delete_by_name(hostveth);
if (ret < 0) { if (ret < 0) {
WARN("Failed to remove interface \"%s\" from \"%s\": %s", WARN("Failed to remove interface \"%s\" from \"%s\": %s",
hostveth, netdev->link, strerror(-ret)); hostveth, netdev->link, strerror(-ret));
continue; goto clear_ifindices;
} }
INFO("Removed interface \"%s\" from \"%s\"", hostveth, netdev->link); INFO("Removed interface \"%s\" from \"%s\"", hostveth, netdev->link);
if (netdev->link[0] == '\0' || !is_ovs_bridge(netdev->link)) { if (netdev->link[0] == '\0' || !is_ovs_bridge(netdev->link)) {
netdev->priv.veth_attr.veth1[0] = '\0'; netdev->priv.veth_attr.veth1[0] = '\0';
continue; netdev->ifindex = 0;
netdev->priv.veth_attr.ifindex = 0;
goto clear_ifindices;
} }
/* Delete the openvswitch port. */ /* Delete the openvswitch port. */
...@@ -2561,7 +2575,18 @@ bool lxc_delete_network_priv(struct lxc_handler *handler) ...@@ -2561,7 +2575,18 @@ bool lxc_delete_network_priv(struct lxc_handler *handler)
INFO("Removed port \"%s\" from openvswitch bridge \"%s\"", INFO("Removed port \"%s\" from openvswitch bridge \"%s\"",
hostveth, netdev->link); hostveth, netdev->link);
netdev->priv.veth_attr.veth1[0] = '\0'; clear_ifindices:
/* We need to clear any ifindeces we recorded so liblxc won't
* have cached stale data which would cause it to fail on reboot
* we're we don't re-read the on-disk config file.
*/
netdev->ifindex = 0;
if (netdev->type == LXC_NET_PHYS) {
netdev->priv.phys_attr.ifindex = 0;
} else if (netdev->type == LXC_NET_VETH) {
netdev->priv.veth_attr.veth1[0] = '\0';
netdev->priv.veth_attr.ifindex = 0;
}
} }
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment