[lxc-devel] [PATCH v2] Add lxc.network.mtu configuration (resend)

Takano Ryousei takano-ryousei at aist.go.jp
Sat Mar 21 19:52:00 UTC 2009


Hi Daniel,

I resent my patch. I hope to fix folding failure.


This patch allows users to specify the MTU size of the veth interface.
 It helps to use jumbo frames on the container.

Changes from v1:
	- Fix failing if the 'mtu' is not specified.
	- Delete the 'mtu' entry at time of lxc-destroy.

Signed-off-by: Ryousei Takano <takano-ryousei at aist.go.jp>
---
 src/lxc/lxc_conf.c   |   29 +++++++++++++++++++++++------
 src/lxc/lxc_conf.h   |    1 +
 src/lxc/lxc_config.c |   24 ++++++++++++++++++++++++
 src/lxc/network.c    |   11 ++++++++---
 src/lxc/network.h    |    4 ++--
 5 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 68eeaf2..c45f232 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -53,6 +53,7 @@
 
 #define MAXHWLEN    18
 #define MAXINDEXLEN 20
+#define MAXMTULEN   16
 #define MAXLINELEN  128
 
 #ifndef MS_REC
@@ -252,12 +253,17 @@ static int configure_netdev(const char *path, struct lxc_netdev *netdev)
 
 	if (netdev->hwaddr) {
 		if (write_info(path, "hwaddr", netdev->hwaddr))
-			goto out_up;
+			goto out_hwaddr;
+	}
+
+	if (netdev->mtu) {
+		if (write_info(path, "mtu", netdev->mtu))
+			goto out_mtu;
 	}
 
 	if (netdev->flags & IFF_UP) {
 		if (write_info(path, "up", ""))
-			goto out_hwaddr;
+			goto out_up;
 	}
 
 	if (!lxc_list_empty(&netdev->ipv4)) {
@@ -278,9 +284,11 @@ out_ipv6:
 	delete_info(path, "ipv4");
 out_ipv4:
 	delete_info(path, "up");
-out_hwaddr:
-	delete_info(path, "hwaddr");
 out_up:
+	delete_info(path, "mtu");
+out_mtu:
+	delete_info(path, "hwaddr");
+out_hwaddr:
 	delete_info(path, "name");
 out_newname:
 	delete_info(path, "link");
@@ -696,6 +704,7 @@ static int unconfigure_network_cb(const char *name, const char *directory,
 	delete_info(path, "addr");
 	delete_info(path, "link");
 	delete_info(path, "hwaddr");
+	delete_info(path, "mtu");
 	delete_info(path, "up");
 	unconfigure_ip_addresses(path);
 	rmdir(path);
@@ -1364,7 +1373,8 @@ static int instanciate_veth(const char *directory, const char *file, pid_t pid)
 {
 	char *path = NULL, *strindex = NULL, *veth1 = NULL, *veth2 = NULL;
 	char bridge[IFNAMSIZ];
-	int ifindex, ret = -1;
+	char strmtu[MAXMTULEN];
+	int ifindex, mtu = 0, ret = -1;
 			
 	if (!asprintf(&veth1, "%s_%d", file, pid) ||
 	    !asprintf(&veth2, "%s~%d", file, pid) ||
@@ -1378,7 +1388,14 @@ static int instanciate_veth(const char *directory, const char *file, pid_t pid)
 		goto out;
 	}
 
-	if (lxc_configure_veth(veth1, veth2, bridge)) {
+	if (!read_info(path, "mtu", strmtu, MAXMTULEN)) {
+		if (sscanf(strmtu, "%u", &mtu) < 1) {
+			lxc_log_error("invalid mtu size '%d'", mtu);
+			goto out;
+		}
+	}
+
+	if (lxc_configure_veth(veth1, veth2, bridge, mtu)) {
 		lxc_log_error("failed to create %s-%s/%s", veth1, veth2, bridge);
 		goto out;
 	}
diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index 6968187..485bd5e 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -79,6 +79,7 @@ struct lxc_netdev {
 	char *ifname;
 	char *newname;
 	char *hwaddr;
+	char *mtu;
 	struct lxc_list ipv4;
 	struct lxc_list ipv6;
 	struct lxc_list route4;
diff --git a/src/lxc/lxc_config.c b/src/lxc/lxc_config.c
index a1ef998..1637f20 100644
--- a/src/lxc/lxc_config.c
+++ b/src/lxc/lxc_config.c
@@ -47,6 +47,7 @@ static int config_network_flags(const char *, char *, struct lxc_conf *);
 static int config_network_link(const char *, char *, struct lxc_conf *);
 static int config_network_name(const char *, char *, struct lxc_conf *);
 static int config_network_hwaddr(const char *, char *, struct lxc_conf *);
+static int config_network_mtu(const char *, char *, struct lxc_conf *);
 static int config_network_ipv4(const char *, char *, struct lxc_conf *);
 static int config_network_ipv6(const char *, char *, struct lxc_conf *);
 
@@ -70,6 +71,7 @@ static struct config config[] = {
 	{ "lxc.network.link",   config_network_link   },
 	{ "lxc.network.name",   config_network_name   },
 	{ "lxc.network.hwaddr", config_network_hwaddr },
+	{ "lxc.network.mtu",    config_network_mtu    },
 	{ "lxc.network.ipv4",   config_network_ipv4   },
 	{ "lxc.network.ipv6",   config_network_ipv6   },
 };
@@ -248,6 +250,28 @@ static int config_network_hwaddr(const char *key, char *value, struct lxc_conf *
 	return 0;
 }
 
+static int config_network_mtu(const char *key, char *value, struct lxc_conf *lxc_conf)
+{
+	struct lxc_list *networks = &lxc_conf->networks;
+	struct lxc_network *network;
+	struct lxc_netdev *netdev;
+
+	if (lxc_list_empty(networks)) {
+		lxc_log_error("network is not created for %s", value);
+		return -1;
+	}
+
+	network = lxc_list_first_elem(networks);
+	if (!network) {
+		lxc_log_error("no network defined for %s", value);
+		return -1;
+	}
+
+	netdev = lxc_list_first_elem(&network->netdev);
+	netdev->mtu = strdup(value);
+	return 0;
+}
+
 static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lxc_conf)
 {
 	struct lxc_list *networks = &lxc_conf->networks;
diff --git a/src/lxc/network.c b/src/lxc/network.c
index 3ae5858..d987147 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -281,7 +281,7 @@ out:
 	return err;
 }
 
-int veth_create(const char *name1, const char *name2)
+int veth_create(const char *name1, const char *name2, const int mtu)
 {
 	struct nl_handler nlh;
 	struct nlmsg *nlmsg = NULL, *answer = NULL;
@@ -344,6 +344,10 @@ int veth_create(const char *name1, const char *name2)
 	if (nla_put_string(nlmsg, IFLA_IFNAME, name1))
 		goto out;
 
+	if (mtu)
+		if (nla_put_u32(nlmsg, IFLA_MTU, mtu))
+			goto out;
+
 	if (netlink_transaction(&nlh, nlmsg, answer))
 		goto out;
 
@@ -690,10 +694,11 @@ int bridge_detach(const char *bridge, const char *ifname)
 	return bridge_add_del_interface(bridge, ifname, 1);
 }
 
-int lxc_configure_veth(const char *veth1, const char *veth2, const char *bridge)
+int lxc_configure_veth(const char *veth1, const char *veth2,
+		       const char *bridge, const int mtu)
 {
 	int err = -1;
-	if (veth_create(veth1, veth2)) {
+	if (veth_create(veth1, veth2, mtu)) {
 		fprintf(stderr, "failed to create veth interfaces %s/%s\n",
 			veth1, veth2);
 		return -1;
diff --git a/src/lxc/network.h b/src/lxc/network.h
index 223276e..86f163b 100644
--- a/src/lxc/network.h
+++ b/src/lxc/network.h
@@ -32,7 +32,7 @@ extern int lxc_configure_macvlan(const char *link, const char *peer);
  * Create a veth pair virtual device
  */
 extern int lxc_configure_veth(const char *veth1, const char *veth2, 
-			      const char *bridge);
+			      const char *bridge, const int mtu);
 
 /*
  * Convert a string mac address to a socket structure
@@ -67,7 +67,7 @@ extern int device_rename(const char *oldname, const char *newname);
 /*
  * Create a veth network device
  */
-extern int veth_create(const char *name1, const char *name2);
+extern int veth_create(const char *name1, const char *name2, const int mtu);
 
 /* 
  * Create a macvlan network device
-- 
1.5.6.3





More information about the lxc-devel mailing list