confile: improve get_network_config_ops()

- handle lxc.net.<idx> keys without any subkey - allow caller to pass NULL if caller doesn't need to retrieve deindexed key Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent e45d7204
......@@ -3572,10 +3572,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
/* end of index string */
idx_end = strchr((copy + 8), '.');
if (!idx_end) {
ERROR("Failed to detect \".\" in string \"%s\"", (copy + 8));
goto on_error;
}
if (idx_end)
*idx_end = '\0';
/* parse current index */
......@@ -3602,6 +3599,9 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
/* repair configuration key */
*idx_start = '.';
/* lxc.net.<idx>.<subkey> */
if (idx_end) {
*idx_end = '.';
memmove(copy + 8, idx_end + 1, strlen(idx_end + 1));
......@@ -3612,8 +3612,11 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
ERROR("unknown network configuration key %s", key);
goto on_error;
}
}
if (deindexed_key)
*deindexed_key = copy;
return config;
on_error:
......@@ -4451,22 +4454,19 @@ int lxc_list_net(struct lxc_conf *c, const char *key, char *retv, int inlen)
{
int len;
const char *idxstring;
struct lxc_config_t *config;
struct lxc_netdev *netdev;
int fulllen = 0;
ssize_t idx = -1;
char *deindexed_key = NULL;
idxstring = key + 8;
if (!isdigit(*idxstring))
return -1;
config = get_network_config_ops(key, c, &idx, &deindexed_key);
if (!config || idx < 0)
(void)get_network_config_ops(key, c, &idx, NULL);
if (idx < 0)
return -1;
netdev = lxc_get_netdev_by_idx(c, (unsigned int)idx, false);
free(deindexed_key);
if (!netdev)
return -1;
......
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