From: Thomas Parrott Date: Thu, 9 May 2019 14:34:20 +0000 (+0100) Subject: network: Adds mtu support for phys and macvlan types X-Git-Tag: lxc-3.2.0~60^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bef7b7b500e4750c97f3c0b2c62738a6f818011;p=thirdparty%2Flxc.git network: Adds mtu support for phys and macvlan types Signed-off-by: Thomas Parrott --- diff --git a/src/lxc/network.c b/src/lxc/network.c index 1dd0d35d4..74927d8f6 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -334,6 +334,7 @@ static int instantiate_macvlan(struct lxc_handler *handler, struct lxc_netdev *n { char peerbuf[IFNAMSIZ], *peer; int err; + unsigned int mtu = 0; if (netdev->link[0] == '\0') { ERROR("No link for macvlan network device specified"); @@ -363,6 +364,22 @@ static int instantiate_macvlan(struct lxc_handler *handler, struct lxc_netdev *n goto on_error; } + if (netdev->mtu) { + err = lxc_safe_uint(netdev->mtu, &mtu); + if (err < 0) { + errno = -err; + SYSERROR("Failed to parse mtu \"%s\" for interface \"%s\"", netdev->mtu, peer); + goto on_error; + } + + err = lxc_netdev_set_mtu(peer, mtu); + if (err < 0) { + errno = -err; + SYSERROR("Failed to set mtu \"%s\" for interface \"%s\"", netdev->mtu, peer); + goto on_error; + } + } + if (netdev->upscript) { char *argv[] = { "macvlan", @@ -606,7 +623,7 @@ static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd } } - DEBUG("Instantiated vlan \"%s\" with ifindex is \"%d\" (vlan1000)", + DEBUG("Instantiated vlan \"%s\" with ifindex is \"%d\"", peer, netdev->ifindex); return 0; @@ -618,12 +635,8 @@ on_error: static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netdev) { - int ret; - char *argv[] = { - "phys", - netdev->link, - NULL, - }; + int err; + unsigned int mtu = 0; if (netdev->link[0] == '\0') { ERROR("No link for physical interface specified"); @@ -648,13 +661,38 @@ static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netd */ netdev->priv.phys_attr.ifindex = netdev->ifindex; - if (!netdev->upscript) - return 0; + if (netdev->mtu) { + err = lxc_safe_uint(netdev->mtu, &mtu); + if (err < 0) { + errno = -err; + SYSERROR("Failed to parse mtu \"%s\" for interface \"%s\"", netdev->mtu, netdev->link); + return -1; + } - ret = run_script_argv(handler->name, handler->conf->hooks_version, - "net", netdev->upscript, "up", argv); - if (ret < 0) - return -1; + err = lxc_netdev_set_mtu(netdev->link, mtu); + if (err < 0) { + errno = -err; + SYSERROR("Failed to set mtu \"%s\" for interface \"%s\"", netdev->mtu, netdev->link); + return -1; + } + } + + if (netdev->upscript) { + char *argv[] = { + "phys", + netdev->link, + NULL, + }; + + err = run_script_argv(handler->name, + handler->conf->hooks_version, "net", + netdev->upscript, "up", argv); + if (err < 0) { + return -1; + } + } + + DEBUG("Instantiated phys \"%s\" with ifindex is \"%d\"", netdev->link, netdev->ifindex); return 0; }