LXC version 3 or higher introduced indexes for network interfaces. Libvirt should be able to parse entries like `lxc.net.2.KEY`. This commit adds functions to parse this type of field. That's why array structures are so important this time.
Signed-off-by: Julio Faracco <jcfara...@gmail.com> --- src/lxc/lxc_native.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 1102928705..ae8d3cb85d 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -649,6 +649,49 @@ lxcNetworkParseDataSuffix(const char *entry, } +static lxcNetworkParseDataPtr +lxcNetworkGetParseDataByIndex(lxcNetworkParseDataArray *networks, + unsigned int index) +{ + size_t ndata = networks->ndata; + size_t i; + + for (i = 0; i < ndata; i++) { + if (networks->parseData[i]->index == index) + return networks->parseData[i]; + } + + /* Index was not found. So, it is time to add new * + * interface and return this last position. */ + if (VIR_EXPAND_N(networks->parseData, networks->ndata, 1) < 0) + return NULL; + + networks->parseData[ndata] = g_new0(lxcNetworkParseData, 1); + networks->parseData[ndata]->index = index; + + return networks->parseData[ndata]; +} + + +static int +lxcNetworkParseDataEntry(const char *name, + virConfValuePtr value, + lxcNetworkParseDataArray *networks) +{ + lxcNetworkParseData *parseData; + const char *suffix = STRSKIP(name, "lxc.net."); + size_t index; + + suffix = strchr(suffix, '.') + 1; + sscanf(name, "lxc.net.%zu", &index); + + if (!(parseData = lxcNetworkGetParseDataByIndex(networks, index))) + return -1; + + return lxcNetworkParseDataSuffix(suffix, value, parseData); +} + + static lxcNetworkParseDataPtr lxcNetworkGetParseDataByIndexLegacy(lxcNetworkParseDataArray *networks, const char *entry) @@ -695,6 +738,8 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data) if (STRPREFIX(name, "lxc.network.")) return lxcNetworkParseDataEntryLegacy(name, value, networks); + if (STRPREFIX(name, "lxc.net.")) + return lxcNetworkParseDataEntry(name, value, networks); return 0; } -- 2.20.1