[lxc-devel] [PATCH 1/2] Add lxc.network.mtu configuration
Ryousei Takano
ryousei at gmail.com
Thu Mar 19 14:49:02 UTC 2009
Hi Daniel,
This is a quick hack to add lxc.network.mtu configuration.
It helps to use jumbo frames for a container.
Signed-off-by: Ryousei Takano <takano-ryousei at aist.go.jp>
---
src/lxc/lxc_conf.c | 35 +++++++++++++++++++++++++++++++----
src/lxc/lxc_conf.h | 1 +
src/lxc/lxc_config.c | 24 ++++++++++++++++++++++++
src/lxc/network.c | 18 ++++++++++++------
src/lxc/network.h | 9 +++++----
5 files changed, 73 insertions(+), 14 deletions(-)
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 68eeaf2..ad92416 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
@@ -255,6 +256,11 @@ static int configure_netdev(const char *path,
struct lxc_netdev *netdev)
goto out_up;
}
+ if (netdev->mtu) {
+ if (write_info(path, "mtu", netdev->mtu))
+ goto out_up;
+ }
+
if (netdev->flags & IFF_UP) {
if (write_info(path, "up", ""))
goto out_hwaddr;
@@ -1364,7 +1370,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, ret = -1;
if (!asprintf(&veth1, "%s_%d", file, pid) ||
!asprintf(&veth2, "%s~%d", file, pid) ||
@@ -1378,7 +1385,16 @@ 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)) {
+ lxc_log_error("failed to read mtu info");
+ goto out;
+ }
+ if (sscanf(strmtu, "%u", &mtu) < 1) {
+ lxc_log_error("invalid mtu size '%u'", 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;
}
@@ -1418,7 +1434,8 @@ static int instanciate_macvlan(const char
*directory, const char *file, pid_t pi
{
char path[MAXPATHLEN], *strindex = NULL, *peer = NULL;
char link[IFNAMSIZ];
- int ifindex, ret = -1;
+ char strmtu[MAXMTULEN];
+ int ifindex, mtu, ret = -1;
if (!asprintf(&peer, "%s~%d", file, pid)) {
lxc_log_syserror("failed to allocate memory");
@@ -1431,7 +1448,17 @@ static int instanciate_macvlan(const char
*directory, const char *file, pid_t pi
goto out;
}
- if (lxc_configure_macvlan(link, peer)) {
+ if (read_info(path, "mtu", strmtu, MAXMTULEN)) {
+ lxc_log_error("failed to read mtu info");
+ goto out;
+ }
+ if (sscanf(strmtu, "%u", &mtu) < 1) {
+ lxc_log_error("invalid mtu size '%d'", mtu);
+ goto out;
+ }
+
+
+ if (lxc_configure_macvlan(link, peer, mtu)) {
lxc_log_error("failed to create macvlan interface %s", peer);
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..cab0048 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,9 @@ int veth_create(const char *name1, const char *name2)
if (nla_put_string(nlmsg, IFLA_IFNAME, name1))
goto out;
+ if (nla_put_u32(nlmsg, IFLA_MTU, mtu))
+ goto out;
+
if (netlink_transaction(&nlh, nlmsg, answer))
goto out;
@@ -355,7 +358,7 @@ out:
return err;
}
-int macvlan_create(const char *master, const char *name)
+int macvlan_create(const char *master, const char *name, const int mtu)
{
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
@@ -408,6 +411,9 @@ int macvlan_create(const char *master, const char *name)
if (nla_put_string(nlmsg, IFLA_IFNAME, name))
goto out;
+ if (nla_put_u32(nlmsg, IFLA_MTU, mtu))
+ goto out;
+
if (netlink_transaction(&nlh, nlmsg, answer))
goto out;
@@ -690,10 +696,10 @@ 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;
@@ -713,9 +719,9 @@ err:
goto out;
}
-int lxc_configure_macvlan(const char *link, const char *peer)
+int lxc_configure_macvlan(const char *link, const char *peer, const int mtu)
{
- if (macvlan_create(link, peer)) {
+ if (macvlan_create(link, peer, mtu)) {
fprintf(stderr, "failed to create %s", peer);
return -1;
}
diff --git a/src/lxc/network.h b/src/lxc/network.h
index 223276e..7d3ce66 100644
--- a/src/lxc/network.h
+++ b/src/lxc/network.h
@@ -26,13 +26,14 @@
/*
* Create a macvlan network device
*/
-extern int lxc_configure_macvlan(const char *link, const char *peer);
+extern int lxc_configure_macvlan(const char *link, const char *peer,
+ const int mtu);
/*
* 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,12 +68,12 @@ 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
*/
-extern int macvlan_create(const char *master, const char *name);
+extern int macvlan_create(const char *master, const char *name, const int mtu);
/*
* Activate forwarding
--
1.5.6.3
More information about the lxc-devel
mailing list