Commit c2dbbbb6 by 0x0916

confile_legacy: fix lxc_clear_nic error

`lxc_clear_nic` can not clear the nic, because it will not found the right `netdev`. testcase from get_item.c ``` 313 if (!c->set_config_item(c, "lxc.network.hwaddr", "00:16:3e:xx:xx:xx")) { 314 fprintf(stderr, "%d: failed to set network.hwaddr\n", __LINE__); 315 goto out; 316 } 317 if (!c->set_config_item(c, "lxc.network.ipv4", "10.2.3.4")) { 318 fprintf(stderr, "%d: failed to set ipv4\n", __LINE__); 319 goto out; 320 } 321 322 ret = c->get_config_item(c, "lxc.network.0.ipv4", v2, 255); 323 if (ret <= 0) { 324 fprintf(stderr, "%d: lxc.network.0.ipv4 returned %d\n", __LINE__, ret); 325 goto out; 326 } 327 if (!c->clear_config_item(c, "lxc.network.0.ipv4")) { 328 fprintf(stderr, "%d: failed clearing all ipv4 entries\n", __LINE__); 329 goto out; 330 } 331 ret = c->get_config_item(c, "lxc.network.0.ipv4", v2, 255); 332 if (ret != 0) { 333 fprintf(stderr, "%d: after clearing ipv4 entries get_item(lxc.network.0.ipv4 returned %d\n", __LINE__, ret); 334 goto out; 335 } ``` line `327` will failed to clear nic, and line `333` give the error. Signed-off-by: 's avatar0x0916 <w@laoqinren.net>
parent 935cfd3e
...@@ -945,34 +945,33 @@ int get_config_network_legacy_item(const char *key, char *retv, int inlen, ...@@ -945,34 +945,33 @@ int get_config_network_legacy_item(const char *key, char *retv, int inlen,
static int lxc_clear_nic(struct lxc_conf *c, const char *key) static int lxc_clear_nic(struct lxc_conf *c, const char *key)
{ {
char *p1; char *p1;
int ret, idx, i; int idx;
struct lxc_list *it; struct lxc_list *it = NULL;
struct lxc_netdev *netdev; struct lxc_netdev *netdev = NULL;
p1 = strchr(key, '.');
if (!p1 || *(p1+1) == '\0')
p1 = NULL;
ret = sscanf(key, "%d", &idx); if (lxc_list_empty(&c->network)) {
if (ret != 1) return -1; ERROR("network is not created for %s", key);
if (idx < 0)
return -1; return -1;
}
i = 0; if ((idx = get_network_netdev_idx(key)) == EINVAL)
netdev = lxc_list_last_elem(&c->network);
else {
lxc_list_for_each(it, &c->network) { lxc_list_for_each(it, &c->network) {
if (i == idx) netdev = it->elem;
if (idx == netdev->idx)
break; break;
i++; netdev = NULL;
} }
if (i < idx) // we don't have that many nics defined }
return -1; if (!netdev)
if (!it || !it->elem)
return -1; return -1;
netdev = it->elem; p1 = strchr(key, '.');
if (!p1 || *(p1+1) == '\0')
p1 = NULL;
if (!p1) { if (!p1 && it) {
lxc_remove_nic(it); lxc_remove_nic(it);
} else if (strcmp(p1, ".ipv4") == 0) { } else if (strcmp(p1, ".ipv4") == 0) {
struct lxc_list *it2,*next; struct lxc_list *it2,*next;
......
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