Commit eb14c10a by Daniel Lezcano

set the mtu before attaching to the bridge

"I checked lxc-0.6.1 and your commit 75d09f83 (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: 's avatarRyousei Takano <takano-ryousei@aist.go.jp> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com> Acked-by: 's avatarRyousei Takano <takano-ryousei@aist.go.jp>
parent 497353b6
...@@ -1388,48 +1388,54 @@ static int instanciate_veth(const char *directory, const char *file, pid_t pid) ...@@ -1388,48 +1388,54 @@ static int instanciate_veth(const char *directory, const char *file, pid_t pid)
goto out; 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); lxc_log_error("failed to create %s-%s/%s", veth1, veth2, bridge);
goto out; 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 (!read_info(path, "mtu", strmtu, MAXMTULEN)) {
if (sscanf(strmtu, "%u", &mtu) < 1) { if (sscanf(strmtu, "%u", &mtu) < 1) {
lxc_log_error("invalid mtu size '%d'", mtu); lxc_log_error("invalid mtu size '%d'", mtu);
goto out; goto out_delete;
} }
if (lxc_device_set_mtu(veth1, mtu)) { if (lxc_device_set_mtu(veth1, mtu)) {
lxc_log_error("failed to set mtu for '%s'", veth1); lxc_log_error("failed to set mtu for '%s'", veth1);
goto out; goto out_delete;
} }
if (lxc_device_set_mtu(veth2, mtu)) { if (lxc_device_set_mtu(veth2, mtu)) {
lxc_log_error("failed to set mtu for '%s'", veth2); 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 (!read_info(path, "up", strindex, sizeof(strindex))) {
if (lxc_device_up(veth1)) { if (lxc_device_up(veth1)) {
lxc_log_error("failed to set %s up", veth1); lxc_log_error("failed to set %s up", veth1);
goto out; goto out_delete;
} }
} }
...@@ -1440,6 +1446,10 @@ out: ...@@ -1440,6 +1446,10 @@ out:
free(veth1); free(veth1);
free(veth2); free(veth2);
return ret; return ret;
out_delete:
lxc_device_delete(veth1);
goto out;
} }
static int instanciate_macvlan(const char *directory, const char *file, pid_t pid) 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 ...@@ -1458,8 +1468,9 @@ static int instanciate_macvlan(const char *directory, const char *file, pid_t pi
goto out; goto out;
} }
if (lxc_configure_macvlan(link, peer)) { if (lxc_macvlan_create(link, peer)) {
lxc_log_error("failed to create macvlan interface %s", peer); lxc_log_error("failed to create macvlan interface '%s' on '%s'",
peer, link);
goto out; goto out;
} }
......
...@@ -737,35 +737,3 @@ int lxc_bridge_detach(const char *bridge, const char *ifname) ...@@ -737,35 +737,3 @@ int lxc_bridge_detach(const char *bridge, const char *ifname)
{ {
return bridge_add_del_interface(bridge, ifname, 1); 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;
}
...@@ -24,17 +24,6 @@ ...@@ -24,17 +24,6 @@
#define _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 * Convert a string mac address to a socket structure
*/ */
extern int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr); extern int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment