Unverified Commit 3ef7f2c0 by Thomas Parrott Committed by Christian Brauner

network: Restores phys device MTU on container shutdown

The phys devices will now have their original MTUs recorded at start and restored at shutdown. This is to protect the original phys device from having any container level MTU customisation being applied to the device once it is restored to the host. Signed-off-by: 's avatarThomas Parrott <thomas.parrott@canonical.com>
parent 463334b7
...@@ -355,7 +355,7 @@ static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -355,7 +355,7 @@ static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd
static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netdev) static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netdev)
{ {
int err; int err, mtu_orig = 0;
unsigned int mtu = 0; unsigned int mtu = 0;
if (netdev->link[0] == '\0') { if (netdev->link[0] == '\0') {
...@@ -381,6 +381,15 @@ static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -381,6 +381,15 @@ static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netd
*/ */
netdev->priv.phys_attr.ifindex = netdev->ifindex; netdev->priv.phys_attr.ifindex = netdev->ifindex;
/* Get original device MTU setting and store for restoration after container shutdown. */
mtu_orig = netdev_get_mtu(netdev->ifindex);
if (mtu_orig < 0) {
SYSERROR("Failed to get original mtu for interface \"%s\"", netdev->link);
return minus_one_set_errno(-mtu_orig);
}
netdev->priv.phys_attr.mtu = mtu_orig;
if (netdev->mtu) { if (netdev->mtu) {
err = lxc_safe_uint(netdev->mtu, &mtu); err = lxc_safe_uint(netdev->mtu, &mtu);
if (err < 0) { if (err < 0) {
...@@ -2626,11 +2635,22 @@ bool lxc_delete_network_priv(struct lxc_handler *handler) ...@@ -2626,11 +2635,22 @@ bool lxc_delete_network_priv(struct lxc_handler *handler)
WARN("Failed to rename interface with index %d " WARN("Failed to rename interface with index %d "
"from \"%s\" to its initial name \"%s\"", "from \"%s\" to its initial name \"%s\"",
netdev->ifindex, netdev->name, netdev->link); netdev->ifindex, netdev->name, netdev->link);
else else {
TRACE("Renamed interface with index %d from " TRACE("Renamed interface with index %d from "
"\"%s\" to its initial name \"%s\"", "\"%s\" to its initial name \"%s\"",
netdev->ifindex, netdev->name, netdev->ifindex, netdev->name,
netdev->link); netdev->link);
/* Restore original MTU */
ret = lxc_netdev_set_mtu(netdev->link, netdev->priv.phys_attr.mtu);
if (ret < 0) {
WARN("Failed to set interface \"%s\" to its initial mtu \"%d\"",
netdev->link, netdev->priv.phys_attr.mtu);
} else {
TRACE("Restored interface \"%s\" to its initial mtu \"%d\"",
netdev->link, netdev->priv.phys_attr.mtu);
}
}
goto clear_ifindices; goto clear_ifindices;
} }
......
...@@ -114,6 +114,7 @@ struct ifla_macvlan { ...@@ -114,6 +114,7 @@ struct ifla_macvlan {
*/ */
struct ifla_phys { struct ifla_phys {
int ifindex; int ifindex;
int mtu;
}; };
union netdev_p { union netdev_p {
......
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