network: return negative idx for legacy networks

parent 01aebbc3
...@@ -229,13 +229,18 @@ static int get_network_netdev_idx(const char *key) ...@@ -229,13 +229,18 @@ static int get_network_netdev_idx(const char *key)
int ret, idx; int ret, idx;
if (*key < '0' || *key > '9') if (*key < '0' || *key > '9')
return -1; return EINVAL;
ret = sscanf(key, "%d", &idx); ret = sscanf(key, "%d", &idx);
if (ret != 1) if (ret != 1)
return -1; return EINVAL;
return idx; /* Since we've implemented the new network parser legacy networks are
* recorded using a negative index starting from -1. To preserve the old
* behavior we need this function to return the appropriate negative
* index.
*/
return -(++idx);
} }
/* /*
...@@ -247,21 +252,19 @@ static struct lxc_netdev *get_netdev_from_key(const char *key, ...@@ -247,21 +252,19 @@ static struct lxc_netdev *get_netdev_from_key(const char *key,
{ {
int idx; int idx;
struct lxc_list *it; struct lxc_list *it;
int i = 0;
struct lxc_netdev *netdev = NULL; struct lxc_netdev *netdev = NULL;
idx = get_network_netdev_idx(key); idx = get_network_netdev_idx(key);
if (idx == -1) if (idx == EINVAL)
return NULL; return NULL;
lxc_list_for_each(it, network) { lxc_list_for_each(it, network) {
if (idx == i++) { netdev = it->elem;
netdev = it->elem; if (idx == netdev->idx)
break; return netdev;
}
} }
return netdev; return NULL;
} }
int lxc_list_nicconfigs_legacy(struct lxc_conf *c, const char *key, char *retv, int lxc_list_nicconfigs_legacy(struct lxc_conf *c, const char *key, char *retv,
...@@ -323,7 +326,7 @@ static struct lxc_netdev *network_netdev(const char *key, const char *value, ...@@ -323,7 +326,7 @@ static struct lxc_netdev *network_netdev(const char *key, const char *value,
return NULL; return NULL;
} }
if (get_network_netdev_idx(key + 12) == -1) if (get_network_netdev_idx(key + 12) == EINVAL)
netdev = lxc_list_last_elem(network); netdev = lxc_list_last_elem(network);
else else
netdev = get_netdev_from_key(key + 12, network); netdev = get_netdev_from_key(key + 12, network);
......
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