Add lxc.network.mtu configuration (resend)

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>
This commit is contained in:
Takano Ryousei 2009-03-22 04:52:00 +09:00 committed by Daniel Lezcano
parent dfdcea5c4f
commit 442cbbe65b
5 changed files with 58 additions and 11 deletions

View 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;
}

View 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;

View 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;

View 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;

View 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