[lxc-devel] [lxc/master] network: Adds mtu support for phys and macvlan types

tomponline on Github lxc-bot at linuxcontainers.org
Thu May 9 14:35:00 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 361 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190509/bf8ce881/attachment.bin>
-------------- next part --------------
From 3bef7b7b500e4750c97f3c0b2c62738a6f818011 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 9 May 2019 15:34:20 +0100
Subject: [PATCH] network: Adds mtu support for phys and macvlan types

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 src/lxc/network.c | 64 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 51 insertions(+), 13 deletions(-)

diff --git a/src/lxc/network.c b/src/lxc/network.c
index 1dd0d35d4a..74927d8f67 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 @@ static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd
 
 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;
 }


More information about the lxc-devel mailing list