]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add lxc.network.mtu configuration (resend)
authorTakano Ryousei <takano-ryousei@aist.go.jp>
Sat, 21 Mar 2009 19:52:00 +0000 (04:52 +0900)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Sun, 22 Mar 2009 08:47:30 +0000 (09:47 +0100)
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@aist.go.jp>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/lxc_conf.c
src/lxc/lxc_conf.h
src/lxc/lxc_config.c
src/lxc/network.c
src/lxc/network.h

index 68eeaf20533539de4b0a12f7fd38e5ffa5dc60ad..c45f232a94183f38f5625b729e4da72362512a6d 100644 (file)
@@ -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;
        }
index 69681872cb66d19890ffbf4085d813357b0e2abd..485bd5eccda2c6c67fce44eba56135185aff867d 100644 (file)
@@ -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;
index a1ef9981a35745fac5cf7b238f04396da76c5f0e..1637f20686bdcf40920e6b65a487c36e6fede86d 100644 (file)
@@ -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;
index 3ae5858848e779c779d1b1fe55445a3d0ec963c6..d987147adc94a3a289f0eff8a57c2604fe11de2f 100644 (file)
@@ -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;
index 223276ef71f5f2accf7dd4425389c4f5e4f4eb0a..86f163b23cb88e9d0387effc8edc4c36e1400cf2 100644 (file)
@@ -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