Commit 33c945e0 by Michael Tokarev Committed by Daniel Lezcano

factor out common config evaluating code

in confile.c we currently have a ton of functions each doing the same thing. Clean them up by providing common routines to do the main work. Signed-off-by: 's avatarMichael Tokarev <mjt@tls.msk.ru> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 9d083402
...@@ -146,133 +146,115 @@ static int config_ip_prefix(struct in_addr *addr) ...@@ -146,133 +146,115 @@ static int config_ip_prefix(struct in_addr *addr)
return 0; return 0;
} }
static int config_network_flags(const char *key, char *value, struct lxc_conf *lxc_conf) static struct lxc_netdev *network_netdev(const char *key, char *value,
struct lxc_conf *lxc_conf)
{ {
struct lxc_list *network = &lxc_conf->network; struct lxc_list *network = &lxc_conf->network;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
if (lxc_list_empty(network)) { if (lxc_list_empty(network)) {
ERROR("network is not created for '%s' option", value); ERROR("network is not created for '%s' option", value);
return -1; return NULL;
} }
netdev = lxc_list_first_elem(network); netdev = lxc_list_first_elem(network);
if (!netdev) { if (!netdev) {
ERROR("no network defined for '%s' option", value); ERROR("no network defined for '%s' option", value);
return -1; return NULL;
} }
netdev->flags |= IFF_UP; return netdev;
return 0;
} }
static int config_network_link(const char *key, char *value, struct lxc_conf *lxc_conf) static int network_ifname(char **valuep, char *value)
{ {
struct lxc_list *network = &lxc_conf->network;
struct lxc_netdev *netdev;
if (lxc_list_empty(network)) {
ERROR("network is not created for %s", value);
return -1;
}
netdev = lxc_list_first_elem(network);
if (!netdev) {
ERROR("no network defined for %s", value);
return -1;
}
if (strlen(value) > IFNAMSIZ) { if (strlen(value) > IFNAMSIZ) {
ERROR("invalid interface name: %s", value); ERROR("invalid interface name: %s", value);
return -1; return -1;
} }
netdev->link = strdup(value); *valuep = strdup(value);
return 0; return 0;
} }
static int config_network_name(const char *key, char *value, struct lxc_conf *lxc_conf) static int config_network_flags(const char *key, char *value,
struct lxc_conf *lxc_conf)
{ {
struct lxc_list *network = &lxc_conf->network;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
if (lxc_list_empty(network)) { netdev = network_netdev(key, value, lxc_conf);
ERROR("network is not created for %s", value); if (!netdev)
return -1; return -1;
}
netdev = lxc_list_first_elem(network); netdev->flags |= IFF_UP;
if (!netdev) {
ERROR("no network defined for %s", value);
return -1;
}
if (strlen(value) > IFNAMSIZ) { return 0;
ERROR("invalid interface name: %s", value); }
static int config_network_link(const char *key, char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
netdev = network_netdev(key, value, lxc_conf);
if (!netdev)
return -1; return -1;
}
netdev->name = strdup(value); return network_ifname(&netdev->link, value);
return 0;
} }
static int config_network_hwaddr(const char *key, char *value, struct lxc_conf *lxc_conf) static int config_network_name(const char *key, char *value,
struct lxc_conf *lxc_conf)
{ {
struct lxc_list *network = &lxc_conf->network;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
if (lxc_list_empty(network)) { netdev = network_netdev(key, value, lxc_conf);
ERROR("network is not created for %s", value); if (!netdev)
return -1; return -1;
}
netdev = lxc_list_first_elem(network); return network_ifname(&netdev->name, value);
if (!netdev) { }
ERROR("no network defined for %s", value);
static int config_network_hwaddr(const char *key, char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
netdev = network_netdev(key, value, lxc_conf);
if (!netdev)
return -1; return -1;
}
netdev->hwaddr = strdup(value); netdev->hwaddr = strdup(value);
return 0; return 0;
} }
static int config_network_mtu(const char *key, char *value, struct lxc_conf *lxc_conf) static int config_network_mtu(const char *key, char *value,
struct lxc_conf *lxc_conf)
{ {
struct lxc_list *network = &lxc_conf->network;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
if (lxc_list_empty(network)) { netdev = network_netdev(key, value, lxc_conf);
ERROR("network is not created for %s", value); if (!netdev)
return -1; return -1;
}
netdev = lxc_list_first_elem(network);
if (!netdev) {
ERROR("no network defined for %s", value);
return -1;
}
netdev->mtu = strdup(value); netdev->mtu = strdup(value);
return 0; return 0;
} }
static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lxc_conf) static int config_network_ipv4(const char *key, char *value,
struct lxc_conf *lxc_conf)
{ {
struct lxc_list *network = &lxc_conf->network;
struct lxc_inetdev *inetdev;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
struct lxc_inetdev *inetdev;
struct lxc_list *list; struct lxc_list *list;
char *cursor, *slash, *addr = NULL, *bcast = NULL, *prefix = NULL; char *cursor, *slash, *addr = NULL, *bcast = NULL, *prefix = NULL;
if (lxc_list_empty(network)) { netdev = network_netdev(key, value, lxc_conf);
ERROR("network is not created for '%s'", value); if (!netdev)
return -1; return -1;
}
netdev = lxc_list_first_elem(network);
if (!netdev) {
ERROR("no netdev defined for '%s'", value);
}
inetdev = malloc(sizeof(*inetdev)); inetdev = malloc(sizeof(*inetdev));
if (!inetdev) { if (!inetdev) {
...@@ -332,23 +314,15 @@ static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lx ...@@ -332,23 +314,15 @@ static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lx
static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lxc_conf) static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lxc_conf)
{ {
struct lxc_list *network = &lxc_conf->network;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
struct lxc_inet6dev *inet6dev; struct lxc_inet6dev *inet6dev;
struct lxc_list *list; struct lxc_list *list;
char *slash; char *slash;
char *netmask; char *netmask;
if (lxc_list_empty(network)) { netdev = network_netdev(key, value, lxc_conf);
ERROR("network is not created for %s", value); if (!netdev)
return -1; return -1;
}
netdev = lxc_list_first_elem(network);
if (!netdev) {
ERROR("no network defined for %s", value);
return -1;
}
inet6dev = malloc(sizeof(*inet6dev)); inet6dev = malloc(sizeof(*inet6dev));
if (!inet6dev) { if (!inet6dev) {
......
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