Fix clearing IPv4/IPv6 addresses

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Stéphane Graber 2015-01-28 10:33:58 +01:00
parent 9f177a0013
commit e088e9267c

View File

@ -787,29 +787,27 @@ static int config_network_ipv4_gateway(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
struct in_addr *gw;
netdev = network_netdev(key, value, &lxc_conf->network); netdev = network_netdev(key, value, &lxc_conf->network);
if (!netdev) if (!netdev)
return -1; return -1;
gw = malloc(sizeof(*gw)); free(netdev->ipv4_gateway);
if (!gw) {
SYSERROR("failed to allocate ipv4 gateway address");
return -1;
}
if (!value) { if (!value || strlen(value) == 0) {
ERROR("no ipv4 gateway address specified"); netdev->ipv4_gateway = NULL;
free(gw); } else if (!strcmp(value, "auto")) {
return -1;
}
if (!strcmp(value, "auto")) {
free(gw);
netdev->ipv4_gateway = NULL; netdev->ipv4_gateway = NULL;
netdev->ipv4_gateway_auto = true; netdev->ipv4_gateway_auto = true;
} else { } else {
struct in_addr *gw;
gw = malloc(sizeof(*gw));
if (!gw) {
SYSERROR("failed to allocate ipv4 gateway address");
return -1;
}
if (!inet_pton(AF_INET, value, gw)) { if (!inet_pton(AF_INET, value, gw)) {
SYSERROR("invalid ipv4 gateway address: %s", value); SYSERROR("invalid ipv4 gateway address: %s", value);
free(gw); free(gw);
@ -892,12 +890,11 @@ static int config_network_ipv6_gateway(const char *key, const char *value,
if (!netdev) if (!netdev)
return -1; return -1;
if (!value) { free(netdev->ipv6_gateway);
ERROR("no ipv6 gateway address specified");
return -1;
}
if (!strcmp(value, "auto")) { if (!value || strlen(value) == 0) {
netdev->ipv4_gateway = NULL;
} else if (!strcmp(value, "auto")) {
netdev->ipv6_gateway = NULL; netdev->ipv6_gateway = NULL;
netdev->ipv6_gateway_auto = true; netdev->ipv6_gateway_auto = true;
} else { } else {