Skip to content

Commit

Permalink
Fixed mismatch on ipvX gateway
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Jimenez <tripledes@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
  • Loading branch information
tripledes authored and stgraber committed Oct 27, 2014
1 parent df7216f commit 9eaf8a5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/lxc/conf.c
Expand Up @@ -4318,12 +4318,12 @@ int lxc_clear_nic(struct lxc_conf *c, const char *key)
free(netdev->mtu);
netdev->mtu = NULL;
}
} else if (strcmp(p1, ".ipv4_gateway") == 0) {
} else if (strcmp(p1, ".ipv4.gateway") == 0) {
if (netdev->ipv4_gateway) {
free(netdev->ipv4_gateway);
netdev->ipv4_gateway = NULL;
}
} else if (strcmp(p1, ".ipv6_gateway") == 0) {
} else if (strcmp(p1, ".ipv6.gateway") == 0) {
if (netdev->ipv6_gateway) {
free(netdev->ipv6_gateway);
netdev->ipv6_gateway = NULL;
Expand Down
10 changes: 5 additions & 5 deletions src/lxc/confile.c
Expand Up @@ -452,9 +452,9 @@ extern int lxc_list_nicconfigs(struct lxc_conf *c, const char *key,
strprint(retv, inlen, "hwaddr\n");
strprint(retv, inlen, "mtu\n");
strprint(retv, inlen, "ipv6\n");
strprint(retv, inlen, "ipv6_gateway\n");
strprint(retv, inlen, "ipv6.gateway\n");
strprint(retv, inlen, "ipv4\n");
strprint(retv, inlen, "ipv4_gateway\n");
strprint(retv, inlen, "ipv4.gateway\n");
}
switch(netdev->type) {
case LXC_NET_VETH:
Expand Down Expand Up @@ -2135,7 +2135,7 @@ static int lxc_get_auto_mounts(struct lxc_conf *c, char *retv, int inlen)
/*
* lxc.network.0.XXX, where XXX can be: name, type, link, flags, type,
* 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).
* things like veth.pair return '' if invalid (i.e. if called for vlan
* type).
Expand Down Expand Up @@ -2204,7 +2204,7 @@ static int lxc_get_item_nic(struct lxc_conf *c, char *retv, int inlen,
if (netdev->type == LXC_NET_VLAN) {
strprint(retv, inlen, "%d", netdev->priv.vlan_attr.vid);
}
} else if (strcmp(p1, "ipv4_gateway") == 0) {
} else if (strcmp(p1, "ipv4.gateway") == 0) {
if (netdev->ipv4_gateway_auto) {
strprint(retv, inlen, "auto");
} else if (netdev->ipv4_gateway) {
Expand All @@ -2220,7 +2220,7 @@ static int lxc_get_item_nic(struct lxc_conf *c, char *retv, int inlen,
inet_ntop(AF_INET, &i->addr, buf, sizeof(buf));
strprint(retv, inlen, "%s/%d\n", buf, i->prefix);
}
} else if (strcmp(p1, "ipv6_gateway") == 0) {
} else if (strcmp(p1, "ipv6.gateway") == 0) {
if (netdev->ipv6_gateway_auto) {
strprint(retv, inlen, "auto");
} else if (netdev->ipv6_gateway) {
Expand Down
24 changes: 24 additions & 0 deletions src/tests/get_item.c
Expand Up @@ -237,6 +237,30 @@ int main(int argc, char *argv[])
goto out;
}

if (!c->set_config_item(c, "lxc.network.ipv4.gateway", "10.2.3.254")) {
fprintf(stderr, "%d: failed to set ipv4.gateway\n", __LINE__);
ret = 1;
goto out;
}

ret = c->get_config_item(c, "lxc.network.0.ipv4.gateway", v2, 255);
if (ret <= 0) {
fprintf(stderr, "%d: lxc.network.0.ipv4.gateway returned %d\n", __LINE__, ret);
ret = 1;
goto out;
}
if (!c->clear_config_item(c, "lxc.network.0.ipv4.gateway")) {
fprintf(stderr, "%d: failed clearing ipv4.gateway\n", __LINE__);
ret = 1;
goto out;
}
ret = c->get_config_item(c, "lxc.network.0.ipv4.gateway", v2, 255);
if (ret != 0) {
fprintf(stderr, "%d: after clearing ipv4.gateway get_item(lxc.network.0.ipv4.gateway returned %d\n", __LINE__, ret);
ret = 1;
goto out;
}

ret = c->get_config_item(c, "lxc.network.0.link", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item returned %d\n", __LINE__, ret);
Expand Down

0 comments on commit 9eaf8a5

Please sign in to comment.