From: Thomas Parrott Date: Thu, 9 May 2019 15:40:08 +0000 (+0100) Subject: network: Restores phys device MTU on container shutdown X-Git-Tag: lxc-3.2.0~60^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b15498976115f4297ba77f94499fc4b8190abf8;p=thirdparty%2Flxc.git 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: Thomas Parrott --- diff --git a/src/lxc/network.c b/src/lxc/network.c index 74927d8f6..954d8b275 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -635,7 +635,7 @@ on_error: static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netdev) { - int err; + int err, mtu_orig = 0; unsigned int mtu = 0; if (netdev->link[0] == '\0') { @@ -661,6 +661,15 @@ static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netd */ 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) { err = lxc_safe_uint(netdev->mtu, &mtu); if (err < 0) { @@ -3159,11 +3168,22 @@ bool lxc_delete_network_priv(struct lxc_handler *handler) WARN("Failed to rename interface with index %d " "from \"%s\" to its initial name \"%s\"", netdev->ifindex, netdev->name, netdev->link); - else + else { TRACE("Renamed interface with index %d from " "\"%s\" to its initial name \"%s\"", netdev->ifindex, netdev->name, 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; } diff --git a/src/lxc/network.h b/src/lxc/network.h index d221b255f..591ecb072 100644 --- a/src/lxc/network.h +++ b/src/lxc/network.h @@ -122,6 +122,7 @@ struct ifla_ipvlan { */ struct ifla_phys { int ifindex; + int mtu; }; union netdev_p {