]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: Adds mtu support for phys and macvlan types
authorThomas Parrott <thomas.parrott@canonical.com>
Thu, 9 May 2019 14:34:20 +0000 (15:34 +0100)
committerThomas Parrott <thomas.parrott@canonical.com>
Thu, 9 May 2019 14:34:20 +0000 (15:34 +0100)
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
src/lxc/network.c

index 1dd0d35d4a5d7e0ff452cc374a0cc3a9c82940af..74927d8f676c74d6d929befe53554bf188e9e727 100644 (file)
@@ -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;
 }