Commit a059591e by Daniel Lezcano Committed by Daniel Lezcano

Fix network prefix

Fix the missing network prefix. When no network prefix is specified, the prefix is computed from the network class specified. Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent a1511e8d
...@@ -134,6 +134,18 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx ...@@ -134,6 +134,18 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx
return 0; return 0;
} }
static int config_ip_prefix(struct in_addr *addr)
{
if (IN_CLASSA(addr->s_addr))
return 32 - IN_CLASSA_NSHIFT;
if (IN_CLASSB(addr->s_addr))
return 32 - IN_CLASSB_NSHIFT;
if (IN_CLASSC(addr->s_addr))
return 32 - IN_CLASSC_NSHIFT;
return 0;
}
static int config_network_flags(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_list *network = &lxc_conf->network;
...@@ -308,8 +320,10 @@ static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lx ...@@ -308,8 +320,10 @@ static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lx
return -1; return -1;
} }
if (prefix) /* no prefix specified, determine it from the network class */
inetdev->prefix = atoi(prefix); inetdev->prefix = prefix ? atoi(prefix) :
config_ip_prefix(&inetdev->addr);
lxc_list_add(&netdev->ipv4, list); lxc_list_add(&netdev->ipv4, list);
...@@ -352,6 +366,7 @@ static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lx ...@@ -352,6 +366,7 @@ static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lx
lxc_list_init(list); lxc_list_init(list);
list->elem = inet6dev; list->elem = inet6dev;
inet6dev->prefix = 64;
slash = strstr(value, "/"); slash = strstr(value, "/");
if (slash) { if (slash) {
*slash = '\0'; *slash = '\0';
......
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