make lxc.network.script.down consistent with lxc.network.script.up

- add missing print in lxc_list_nicconfigs() and in write_config() which
  fixes lxc-clone so it will propagate the script.down config value

- add missing "script.down" to lxc_get_item_nic(). change "upscript" to
  "script.up" to match actual key in config

- refactor to use config_string_item()

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acled-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
Dwight Engen 2013-12-11 16:04:37 -05:00 committed by Stéphane Graber
parent a92f95cdbf
commit 8fc8295a16

View File

@ -80,7 +80,8 @@ static int config_network_vlan_id(const char *, const char *, struct lxc_conf *)
static int config_network_mtu(const char *, const char *, struct lxc_conf *); static int config_network_mtu(const char *, const char *, struct lxc_conf *);
static int config_network_ipv4(const char *, const char *, struct lxc_conf *); static int config_network_ipv4(const char *, const char *, struct lxc_conf *);
static int config_network_ipv4_gateway(const char *, const char *, struct lxc_conf *); static int config_network_ipv4_gateway(const char *, const char *, struct lxc_conf *);
static int config_network_script(const char *, const char *, struct lxc_conf *); static int config_network_script_up(const char *, const char *, struct lxc_conf *);
static int config_network_script_down(const char *, const char *, struct lxc_conf *);
static int config_network_ipv6(const char *, const char *, struct lxc_conf *); static int config_network_ipv6(const char *, const char *, struct lxc_conf *);
static int config_network_ipv6_gateway(const char *, const char *, struct lxc_conf *); static int config_network_ipv6_gateway(const char *, const char *, struct lxc_conf *);
static int config_cap_drop(const char *, const char *, struct lxc_conf *); static int config_cap_drop(const char *, const char *, struct lxc_conf *);
@ -123,8 +124,8 @@ static struct lxc_config_t config[] = {
{ "lxc.network.name", config_network_name }, { "lxc.network.name", config_network_name },
{ "lxc.network.macvlan.mode", config_network_macvlan_mode }, { "lxc.network.macvlan.mode", config_network_macvlan_mode },
{ "lxc.network.veth.pair", config_network_veth_pair }, { "lxc.network.veth.pair", config_network_veth_pair },
{ "lxc.network.script.up", config_network_script }, { "lxc.network.script.up", config_network_script_up },
{ "lxc.network.script.down", config_network_script }, { "lxc.network.script.down", config_network_script_down },
{ "lxc.network.hwaddr", config_network_hwaddr }, { "lxc.network.hwaddr", config_network_hwaddr },
{ "lxc.network.mtu", config_network_mtu }, { "lxc.network.mtu", config_network_mtu },
{ "lxc.network.vlan.id", config_network_vlan_id }, { "lxc.network.vlan.id", config_network_vlan_id },
@ -408,6 +409,7 @@ extern int lxc_list_nicconfigs(struct lxc_conf *c, const char *key,
memset(retv, 0, inlen); memset(retv, 0, inlen);
strprint(retv, inlen, "script.up\n"); strprint(retv, inlen, "script.up\n");
strprint(retv, inlen, "script.down\n");
if (netdev->type != LXC_NET_EMPTY) { if (netdev->type != LXC_NET_EMPTY) {
strprint(retv, inlen, "flags\n"); strprint(retv, inlen, "flags\n");
strprint(retv, inlen, "link\n"); strprint(retv, inlen, "link\n");
@ -824,31 +826,28 @@ static int config_network_ipv6_gateway(const char *key, const char *value,
return 0; return 0;
} }
static int config_network_script(const char *key, const char *value, static int config_network_script_up(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
netdev = network_netdev(key, value, &lxc_conf->network); netdev = network_netdev(key, value, &lxc_conf->network);
if (!netdev) if (!netdev)
return -1; return -1;
char *copy = strdup(value); return config_string_item(&netdev->upscript, value);
if (!copy) { }
SYSERROR("failed to dup string '%s'", value);
return -1; static int config_network_script_down(const char *key, const char *value,
} struct lxc_conf *lxc_conf)
if (strstr(key, "script.up") != NULL) { {
netdev->upscript = copy; struct lxc_netdev *netdev;
return 0;
} netdev = network_netdev(key, value, &lxc_conf->network);
if (strcmp(key, "lxc.network.script.down") == 0) { if (!netdev)
netdev->downscript = copy; return -1;
return 0;
} return config_string_item(&netdev->downscript, value);
SYSERROR("Unknown key: %s", key);
free(copy);
return -1;
} }
static int add_hook(struct lxc_conf *lxc_conf, int which, char *hook) static int add_hook(struct lxc_conf *lxc_conf, int which, char *hook)
@ -1780,7 +1779,7 @@ static int lxc_get_mount_entries(struct lxc_conf *c, char *retv, int inlen)
/* /*
* lxc.network.0.XXX, where XXX can be: name, type, link, flags, type, * lxc.network.0.XXX, where XXX can be: name, type, link, flags, type,
* macvlan.mode, veth.pair, vlan, ipv4, ipv6, upscript, hwaddr, mtu, * macvlan.mode, veth.pair, vlan, ipv4, ipv6, script.up, hwaddr, mtu,
* ipv4_gateway, ipv6_gateway. ipvX_gateway can return 'auto' instead * ipv4_gateway, ipv6_gateway. ipvX_gateway can return 'auto' instead
* of an address. ipv4 and ipv6 return lists (newline-separated). * of an address. ipv4 and ipv6 return lists (newline-separated).
* things like veth.pair return '' if invalid (i.e. if called for vlan * things like veth.pair return '' if invalid (i.e. if called for vlan
@ -1816,9 +1815,12 @@ static int lxc_get_item_nic(struct lxc_conf *c, char *retv, int inlen,
} else if (strcmp(p1, "flags") == 0) { } else if (strcmp(p1, "flags") == 0) {
if (netdev->flags & IFF_UP) if (netdev->flags & IFF_UP)
strprint(retv, inlen, "up"); strprint(retv, inlen, "up");
} else if (strcmp(p1, "upscript") == 0) { } else if (strcmp(p1, "script.up") == 0) {
if (netdev->upscript) if (netdev->upscript)
strprint(retv, inlen, "%s", netdev->upscript); strprint(retv, inlen, "%s", netdev->upscript);
} else if (strcmp(p1, "script.down") == 0) {
if (netdev->downscript)
strprint(retv, inlen, "%s", netdev->downscript);
} else if (strcmp(p1, "hwaddr") == 0) { } else if (strcmp(p1, "hwaddr") == 0) {
if (netdev->hwaddr) if (netdev->hwaddr)
strprint(retv, inlen, "%s", netdev->hwaddr); strprint(retv, inlen, "%s", netdev->hwaddr);
@ -2071,6 +2073,8 @@ void write_config(FILE *fout, struct lxc_conf *c)
} }
if (n->upscript) if (n->upscript)
fprintf(fout, "lxc.network.script.up = %s\n", n->upscript); fprintf(fout, "lxc.network.script.up = %s\n", n->upscript);
if (n->downscript)
fprintf(fout, "lxc.network.script.down = %s\n", n->downscript);
if (n->hwaddr) if (n->hwaddr)
fprintf(fout, "lxc.network.hwaddr = %s\n", n->hwaddr); fprintf(fout, "lxc.network.hwaddr = %s\n", n->hwaddr);
if (n->mtu) if (n->mtu)