]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
set mtu for netdev
authorDaniel Lezcano <dlezcano@fr.ibm.com>
Sun, 22 Mar 2009 21:52:17 +0000 (22:52 +0100)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Sun, 22 Mar 2009 21:52:17 +0000 (22:52 +0100)
When setting the mtu size at the veth creation, the mtu is only set
on one side of the veth tunnel, the one attached to the bridge.

I changed a little the code and added the device_set_mtu function so
it is called after the veth has been created on both side.

That moves the mtu veth specific code inside the veth function creation.

Hopefully this code could be reused later for different future network
configuration (eg. ip tunnel).

The mtu option will be simply ignored in case of macvlan network configuration
because the macvlan network device inherit the mtu of the physical link.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/lxc_conf.c
src/lxc/network.c
src/lxc/network.h

index c45f232a94183f38f5625b729e4da72362512a6d..058e1ad254a5726a38016dc87418e2600a7b629f 100644 (file)
@@ -1388,14 +1388,7 @@ static int instanciate_veth(const char *directory, const char *file, pid_t pid)
                goto out;
        }
 
-       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)) {
+       if (lxc_configure_veth(veth1, veth2, bridge)) {
                lxc_log_error("failed to create %s-%s/%s", veth1, veth2, bridge);
                goto out;
        }
@@ -1416,6 +1409,23 @@ static int instanciate_veth(const char *directory, const char *file, pid_t pid)
                goto out;
        }
 
+       if (!read_info(path, "mtu", strmtu, MAXMTULEN)) {
+               if (sscanf(strmtu, "%u", &mtu) < 1) {
+                       lxc_log_error("invalid mtu size '%d'", mtu);
+                       goto out;
+               }
+
+               if (device_set_mtu(veth1, mtu)) {
+                       lxc_log_error("failed to set mtu for '%s'", veth1);
+                       goto out;
+               }
+
+               if (device_set_mtu(veth2, mtu)) {
+                       lxc_log_error("failed to set mtu for '%s'", veth1);
+                       goto out;
+               }
+       }
+
        if (!read_info(path, "up", strindex, sizeof(strindex))) {
                if (device_up(veth1)) {
                        lxc_log_error("failed to set %s up", veth1);
@@ -1435,6 +1445,7 @@ static int instanciate_macvlan(const char *directory, const char *file, pid_t pi
 {
        char path[MAXPATHLEN], *strindex = NULL, *peer = NULL;
        char link[IFNAMSIZ]; 
+       char strmtu[MAXMTULEN];
        int ifindex, ret = -1;
                        
        if (!asprintf(&peer, "%s~%d", file, pid)) {
index d987147adc94a3a289f0eff8a57c2604fe11de2f..92b1ef4ccc7154314b7ca227dbbda08bf73fa673 100644 (file)
@@ -220,6 +220,54 @@ out:
        return err;
 }
 
+extern int device_set_mtu(const char *name, int mtu)
+{
+       struct nl_handler nlh;
+       struct nlmsg *nlmsg = NULL, *answer = NULL;
+       struct link_req *link_req;
+       int index, len, err = -1;
+
+       if (netlink_open(&nlh, NETLINK_ROUTE))
+               return -1;
+
+       len = strlen(name);
+       if (len == 1 || len > IFNAMSIZ)
+               goto out;
+
+       nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
+       if (!nlmsg)
+               goto out;
+
+       answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
+       if (!answer)
+               goto out;
+
+       index = if_nametoindex(name);
+       if (!index)
+               goto out;
+
+       link_req = (struct link_req *)nlmsg;
+       link_req->ifinfomsg.ifi_family = AF_UNSPEC;
+       link_req->ifinfomsg.ifi_index = index;
+       nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+       nlmsg->nlmsghdr.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
+       nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
+
+       if (nla_put_u32(nlmsg, IFLA_MTU, mtu))
+               goto out;
+
+       err = netlink_transaction(&nlh, nlmsg, answer);
+       if (err < 0)
+               goto out;
+
+       err = 0;
+out:
+       netlink_close(&nlh);
+       nlmsg_free(nlmsg);
+       nlmsg_free(answer);
+       return err;
+}
+
 int device_up(const char *name)
 {
        return device_set_flag(name, IFF_UP);
@@ -281,7 +329,7 @@ out:
        return err;
 }
 
-int veth_create(const char *name1, const char *name2, const int mtu)
+int veth_create(const char *name1, const char *name2)
 {
        struct nl_handler nlh;
        struct nlmsg *nlmsg = NULL, *answer = NULL;
@@ -344,10 +392,6 @@ int veth_create(const char *name1, const char *name2, const int mtu)
        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;
 
@@ -694,11 +738,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, const int mtu)
+int lxc_configure_veth(const char *veth1, const char *veth2, const char *bridge)
 {
        int err = -1;
-       if (veth_create(veth1, veth2, mtu)) {
+       if (veth_create(veth1, veth2)) {
                fprintf(stderr, "failed to create veth interfaces %s/%s\n",
                        veth1, veth2);
                return -1;
index 86f163b23cb88e9d0387effc8edc4c36e1400cf2..cb65003c08273cd2eddb4e4aa9c7d7116f38cd2b 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 int mtu);
+                             const char *bridge);
 
 /*
  * Convert a string mac address to a socket structure
@@ -64,10 +64,15 @@ extern int device_down(const char *name);
  */
 extern int device_rename(const char *oldname, const char *newname);
 
+/*
+ * Change the mtu size for the specified device
+ */
+extern int device_set_mtu(const char *name, int mtu);
+
 /*
  * Create a veth network device
  */
-extern int veth_create(const char *name1, const char *name2, const int mtu);
+extern int veth_create(const char *name1, const char *name2);
 
 /* 
  * Create a macvlan network device