From: Daniel Lezcano Date: Thu, 26 Mar 2009 10:32:23 +0000 (+0100) Subject: set the mtu before attaching to the bridge X-Git-Tag: lxc_0_6_2~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb14c10a414bcbb39cc29ebc82f5299aa36b6c30;p=thirdparty%2Flxc.git set the mtu before attaching to the bridge "I checked lxc-0.6.1 and your commit 75d09f83b82f35a610f4922e06ad897692062fab (set mtu for netdev). I found a problem of the MTU size of br0. In the current code, device_set_mtu() is called after bridge_attach(), so the MTU size of br0 is set to the default MTU size of veth0 (i.e., 1500 bytes). This causes performance degradation as I reported. We need to modify to call device_set_mtu() before bridge_attach()" Now that we have the network functions accessible, do not longer use the lxc_configure_veth, lxc_configure_macvlan and split the configuration of the veth in order to create it, configure it and finally attach it to the bridge. Reported-by: Ryousei Takano Signed-off-by: Daniel Lezcano Acked-by: Ryousei Takano --- diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 8e88c831a..ce4a3924d 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -1388,48 +1388,54 @@ static int instanciate_veth(const char *directory, const char *file, pid_t pid) goto out; } - if (lxc_configure_veth(veth1, veth2, bridge)) { + if (lxc_veth_create(veth1, veth2)) { lxc_log_error("failed to create %s-%s/%s", veth1, veth2, bridge); goto out; } - ifindex = if_nametoindex(veth2); - if (!ifindex) { - lxc_log_error("failed to retrieve the index for %s", veth2); - goto out; - } - - if (!asprintf(&strindex, "%d", ifindex)) { - lxc_log_syserror("failed to allocate memory"); - goto out; - } - - if (write_info(path, "ifindex", strindex)) { - lxc_log_error("failed to write interface index to %s", path); - 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; + goto out_delete; } if (lxc_device_set_mtu(veth1, mtu)) { lxc_log_error("failed to set mtu for '%s'", veth1); - goto out; + goto out_delete; } if (lxc_device_set_mtu(veth2, mtu)) { lxc_log_error("failed to set mtu for '%s'", veth2); - goto out; + goto out_delete; } } + if (lxc_bridge_attach(bridge, veth1)) { + lxc_log_error("failed to attach '%s' to the bridge '%s'", + veth1, bridge); + goto out_delete; + } + + ifindex = if_nametoindex(veth2); + if (!ifindex) { + lxc_log_error("failed to retrieve the index for %s", veth2); + goto out_delete; + } + + if (!asprintf(&strindex, "%d", ifindex)) { + lxc_log_syserror("failed to allocate memory"); + goto out_delete; + } + + if (write_info(path, "ifindex", strindex)) { + lxc_log_error("failed to write interface index to %s", path); + goto out_delete; + } + if (!read_info(path, "up", strindex, sizeof(strindex))) { if (lxc_device_up(veth1)) { lxc_log_error("failed to set %s up", veth1); - goto out; + goto out_delete; } } @@ -1440,6 +1446,10 @@ out: free(veth1); free(veth2); return ret; + +out_delete: + lxc_device_delete(veth1); + goto out; } static int instanciate_macvlan(const char *directory, const char *file, pid_t pid) { @@ -1458,8 +1468,9 @@ static int instanciate_macvlan(const char *directory, const char *file, pid_t pi goto out; } - if (lxc_configure_macvlan(link, peer)) { - lxc_log_error("failed to create macvlan interface %s", peer); + if (lxc_macvlan_create(link, peer)) { + lxc_log_error("failed to create macvlan interface '%s' on '%s'", + peer, link); goto out; } diff --git a/src/lxc/network.c b/src/lxc/network.c index d9b09f89a..41dc6994e 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -737,35 +737,3 @@ int lxc_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 err = -1; - if (lxc_veth_create(veth1, veth2)) { - fprintf(stderr, "failed to create veth interfaces %s/%s\n", - veth1, veth2); - return -1; - } - - if (lxc_bridge_attach(bridge, veth1)) { - fprintf(stderr, "failed to attach %s to %s\n", - veth1, bridge); - goto err; - } - - err = 0; -out: - return err; -err: - lxc_device_delete(veth1); - goto out; -} - -int lxc_configure_macvlan(const char *link, const char *peer) -{ - if (lxc_macvlan_create(link, peer)) { - fprintf(stderr, "failed to create %s", peer); - return -1; - } - return 0; -} diff --git a/src/lxc/network.h b/src/lxc/network.h index ffd01071c..aa88c01ab 100644 --- a/src/lxc/network.h +++ b/src/lxc/network.h @@ -23,17 +23,6 @@ #ifndef _network_h #define _network_h -/* - * Create a macvlan network device - */ -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); - /* * Convert a string mac address to a socket structure */