[PATCH v4 0/4] This series implement support for network syntax settings for LXC 3.X.

Old: lxc.network.type = veth lxc.network.flags = up lxc.network.link = virbr0 New: lxc.net.0.type = veth lxc.net.0.flags = up lxc.net.0.link = virbr0 v1-v2: Moving sscanf to virStrToLong_ull according Daniel's suggestion. v2-v3: Adding missing g_autofree from `suffix` variable. v2-v4: Removing g_autofree inserted above and adding some missing free functions. See Daniel's test results/comments. Julio Faracco (4): lxc: refactor lxcNetworkParseData pointers to use new structures lxc: add LXC version 3 network parser lxc: remove domain definition from lxc network struct tests: update LXC config dataset to support V3 indexes src/lxc/lxc_native.c | 200 ++++++++++++------ .../lxcconf2xml-ethernet-v3.config | 16 +- .../lxcconf2xml-fstab-v3.config | 10 +- .../lxcconf2xml-macvlannetwork-v3.config | 10 +- .../lxcconf2xml-miscnetwork-v3.config | 34 +-- .../lxcconf2xml-nonenetwork-v3.config | 2 +- .../lxcconf2xml-physnetwork-v3.config | 14 +- .../lxcconf2xml-simple-v3.config | 18 +- .../lxcconf2xml-vlannetwork-v3.config | 10 +- 9 files changed, 190 insertions(+), 124 deletions(-) -- 2.20.1

Struct lxcNetworkParseData is being used as a single pointer which iterates through LXC config lines. It means that it will be applied as a network each time that a new type appears. After, the same struct is used to populate a new network interface. This commit changes this logic to multiple lxcNetworkParseData to move this strcuture to an array. It makes more sense if we are using indexes to fill interface settings. This is better to improve code clarity. This commit still introduces *Legacy() functions to keep support of network old style definitions. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 140 ++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 63 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index dd2345c324..31aa666e38 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -411,7 +411,9 @@ lxcCreateHostdevDef(int mode, int type, const char *data) return hostdev; } -typedef struct { +typedef struct _lxcNetworkParseData lxcNetworkParseData; +typedef lxcNetworkParseData *lxcNetworkParseDataPtr; +struct _lxcNetworkParseData { virDomainDefPtr def; char *type; char *link; @@ -424,9 +426,14 @@ typedef struct { size_t nips; char *gateway_ipv4; char *gateway_ipv6; - bool privnet; - size_t networks; -} lxcNetworkParseData; + size_t index; +}; + +typedef struct { + size_t ndata; + lxcNetworkParseDataPtr *parseData; +} lxcNetworkParseDataArray; + static int lxcAddNetworkRouteDefinition(const char *address, @@ -552,39 +559,6 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data) } -static int -lxcNetworkParseDataType(virConfValuePtr value, - lxcNetworkParseData *parseData) -{ - virDomainDefPtr def = parseData->def; - size_t networks = parseData->networks; - bool privnet = parseData->privnet; - int status; - - /* Store the previous NIC */ - status = lxcAddNetworkDefinition(parseData); - - if (status < 0) - return -1; - else if (status > 0) - networks++; - else if (parseData->type != NULL && STREQ(parseData->type, "none")) - privnet = false; - - /* clean NIC to store a new one */ - memset(parseData, 0, sizeof(*parseData)); - - parseData->def = def; - parseData->networks = networks; - parseData->privnet = privnet; - - /* Keep the new value */ - parseData->type = value->str; - - return 0; -} - - static int lxcNetworkParseDataIPs(const char *name, virConfValuePtr value, @@ -633,8 +607,7 @@ lxcNetworkParseDataSuffix(const char *entry, switch (elem) { case VIR_LXC_NETWORK_CONFIG_TYPE: - if (lxcNetworkParseDataType(value, parseData) < 0) - return -1; + parseData->type = value->str; break; case VIR_LXC_NETWORK_CONFIG_LINK: parseData->link = value->str; @@ -676,12 +649,40 @@ lxcNetworkParseDataSuffix(const char *entry, } +static lxcNetworkParseDataPtr +lxcNetworkGetParseDataByIndexLegacy(lxcNetworkParseDataArray *networks, + const char *entry) +{ + int elem = virLXCNetworkConfigEntryTypeFromString(entry); + size_t ndata = networks->ndata; + + if (elem == VIR_LXC_NETWORK_CONFIG_TYPE) { + /* 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 = networks->ndata; + + return networks->parseData[ndata]; + } + + /* Return last element added like a stack. */ + return networks->parseData[ndata - 1]; +} + + static int -lxcNetworkParseDataEntry(const char *name, - virConfValuePtr value, - lxcNetworkParseData *parseData) +lxcNetworkParseDataEntryLegacy(const char *name, + virConfValuePtr value, + lxcNetworkParseDataArray *networks) { const char *suffix = STRSKIP(name, "lxc.network."); + lxcNetworkParseData *parseData; + + if (!(parseData = lxcNetworkGetParseDataByIndexLegacy(networks, suffix))) + return -1; return lxcNetworkParseDataSuffix(suffix, value, parseData); } @@ -690,10 +691,10 @@ lxcNetworkParseDataEntry(const char *name, static int lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data) { - lxcNetworkParseData *parseData = data; + lxcNetworkParseDataArray *networks = data; if (STRPREFIX(name, "lxc.network.")) - return lxcNetworkParseDataEntry(name, value, parseData); + return lxcNetworkParseDataEntryLegacy(name, value, networks); return 0; } @@ -702,36 +703,49 @@ static int lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties) { int status; - size_t i; - lxcNetworkParseData data = {def, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, 0, - NULL, NULL, true, 0}; + bool privnet = true; + size_t i, j; + lxcNetworkParseDataArray networks = {0, NULL}; + int ret = -1; + + networks.parseData = g_new0(lxcNetworkParseDataPtr, 1); - if (virConfWalk(properties, lxcNetworkWalkCallback, &data) < 0) + if (virConfWalk(properties, lxcNetworkWalkCallback, &networks) < 0) goto error; + for (i = 0; i < networks.ndata; i++) { + lxcNetworkParseDataPtr data = networks.parseData[i]; + data->def = def; - /* Add the last network definition found */ - status = lxcAddNetworkDefinition(&data); + status = lxcAddNetworkDefinition(data); - if (status < 0) - goto error; - else if (status > 0) - data.networks++; - else if (data.type != NULL && STREQ(data.type, "none")) - data.privnet = false; + if (status < 0) + goto error; + else if (data->type != NULL && STREQ(data->type, "none")) + privnet = false; + } - if (data.networks == 0 && data.privnet) { + if (networks.ndata == 0 && privnet) { /* When no network type is provided LXC only adds loopback */ def->features[VIR_DOMAIN_FEATURE_PRIVNET] = VIR_TRISTATE_SWITCH_ON; } - return 0; + + ret = 0; + + cleanup: + for (i = 0; i < networks.ndata; i++) + VIR_FREE(networks.parseData[i]); + VIR_FREE(networks.parseData); + return ret; error: - for (i = 0; i < data.nips; i++) - VIR_FREE(data.ips[i]); - VIR_FREE(data.ips); - return -1; + for (i = 0; i < networks.ndata; i++) { + lxcNetworkParseDataPtr data = networks.parseData[i]; + for (j = 0; j < data->nips; j++) + VIR_FREE(data->ips[j]); + VIR_FREE(data->ips); + } + goto cleanup; } static int -- 2.20.1

Em dom., 2 de fev. de 2020 às 22:28, Julio Faracco <jcfaracco@gmail.com> escreveu:
Struct lxcNetworkParseData is being used as a single pointer which iterates through LXC config lines. It means that it will be applied as a network each time that a new type appears. After, the same struct is used to populate a new network interface. This commit changes this logic to multiple lxcNetworkParseData to move this strcuture to an array. It makes more sense if we are using indexes to fill interface settings. This is better to improve code clarity.
This commit still introduces *Legacy() functions to keep support of network old style definitions.
Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 140 ++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 63 deletions(-)
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index dd2345c324..31aa666e38 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -411,7 +411,9 @@ lxcCreateHostdevDef(int mode, int type, const char *data) return hostdev; }
-typedef struct { +typedef struct _lxcNetworkParseData lxcNetworkParseData; +typedef lxcNetworkParseData *lxcNetworkParseDataPtr; +struct _lxcNetworkParseData { virDomainDefPtr def; char *type; char *link; @@ -424,9 +426,14 @@ typedef struct { size_t nips; char *gateway_ipv4; char *gateway_ipv6; - bool privnet; - size_t networks; -} lxcNetworkParseData; + size_t index; +}; + +typedef struct { + size_t ndata; + lxcNetworkParseDataPtr *parseData; +} lxcNetworkParseDataArray; +
static int lxcAddNetworkRouteDefinition(const char *address, @@ -552,39 +559,6 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data) }
-static int -lxcNetworkParseDataType(virConfValuePtr value, - lxcNetworkParseData *parseData) -{ - virDomainDefPtr def = parseData->def; - size_t networks = parseData->networks; - bool privnet = parseData->privnet; - int status; - - /* Store the previous NIC */ - status = lxcAddNetworkDefinition(parseData); - - if (status < 0) - return -1; - else if (status > 0) - networks++; - else if (parseData->type != NULL && STREQ(parseData->type, "none")) - privnet = false; - - /* clean NIC to store a new one */ - memset(parseData, 0, sizeof(*parseData)); - - parseData->def = def; - parseData->networks = networks; - parseData->privnet = privnet; - - /* Keep the new value */ - parseData->type = value->str; - - return 0; -} - - static int lxcNetworkParseDataIPs(const char *name, virConfValuePtr value, @@ -633,8 +607,7 @@ lxcNetworkParseDataSuffix(const char *entry,
switch (elem) { case VIR_LXC_NETWORK_CONFIG_TYPE: - if (lxcNetworkParseDataType(value, parseData) < 0) - return -1; + parseData->type = value->str; break; case VIR_LXC_NETWORK_CONFIG_LINK: parseData->link = value->str; @@ -676,12 +649,40 @@ lxcNetworkParseDataSuffix(const char *entry, }
+static lxcNetworkParseDataPtr +lxcNetworkGetParseDataByIndexLegacy(lxcNetworkParseDataArray *networks, + const char *entry) +{ + int elem = virLXCNetworkConfigEntryTypeFromString(entry); + size_t ndata = networks->ndata; + + if (elem == VIR_LXC_NETWORK_CONFIG_TYPE) { + /* 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 = networks->ndata; + + return networks->parseData[ndata]; + } + + /* Return last element added like a stack. */ + return networks->parseData[ndata - 1];
There is an issue here: If someone accidentally inverts network settings sequence, libvirt will crash with segfault due to invalid memory access. Variable @ndata will be 0, so this function would return a pointer from index -1 (which is invalid obviously). This example, `link` appears first instead of `type` lxc.network.link = eth0 lxc.network.type = phys lxc.network.name = eth1 lxc.network.ipv4 = 192.168.122.2/24 lxc.network.ipv4.gateway = 192.168.122.1 The funniest part, this issue is happening before patches. Let me submit a fix/patch.
+} + + static int -lxcNetworkParseDataEntry(const char *name, - virConfValuePtr value, - lxcNetworkParseData *parseData) +lxcNetworkParseDataEntryLegacy(const char *name, + virConfValuePtr value, + lxcNetworkParseDataArray *networks) { const char *suffix = STRSKIP(name, "lxc.network."); + lxcNetworkParseData *parseData; + + if (!(parseData = lxcNetworkGetParseDataByIndexLegacy(networks, suffix))) + return -1;
return lxcNetworkParseDataSuffix(suffix, value, parseData); } @@ -690,10 +691,10 @@ lxcNetworkParseDataEntry(const char *name, static int lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data) { - lxcNetworkParseData *parseData = data; + lxcNetworkParseDataArray *networks = data;
if (STRPREFIX(name, "lxc.network.")) - return lxcNetworkParseDataEntry(name, value, parseData); + return lxcNetworkParseDataEntryLegacy(name, value, networks);
return 0; } @@ -702,36 +703,49 @@ static int lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties) { int status; - size_t i; - lxcNetworkParseData data = {def, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, 0, - NULL, NULL, true, 0}; + bool privnet = true; + size_t i, j; + lxcNetworkParseDataArray networks = {0, NULL}; + int ret = -1; + + networks.parseData = g_new0(lxcNetworkParseDataPtr, 1);
- if (virConfWalk(properties, lxcNetworkWalkCallback, &data) < 0) + if (virConfWalk(properties, lxcNetworkWalkCallback, &networks) < 0) goto error;
+ for (i = 0; i < networks.ndata; i++) { + lxcNetworkParseDataPtr data = networks.parseData[i]; + data->def = def;
- /* Add the last network definition found */ - status = lxcAddNetworkDefinition(&data); + status = lxcAddNetworkDefinition(data);
- if (status < 0) - goto error; - else if (status > 0) - data.networks++; - else if (data.type != NULL && STREQ(data.type, "none")) - data.privnet = false; + if (status < 0) + goto error; + else if (data->type != NULL && STREQ(data->type, "none")) + privnet = false; + }
- if (data.networks == 0 && data.privnet) { + if (networks.ndata == 0 && privnet) { /* When no network type is provided LXC only adds loopback */ def->features[VIR_DOMAIN_FEATURE_PRIVNET] = VIR_TRISTATE_SWITCH_ON; } - return 0; + + ret = 0; + + cleanup: + for (i = 0; i < networks.ndata; i++) + VIR_FREE(networks.parseData[i]); + VIR_FREE(networks.parseData); + return ret;
error: - for (i = 0; i < data.nips; i++) - VIR_FREE(data.ips[i]); - VIR_FREE(data.ips); - return -1; + for (i = 0; i < networks.ndata; i++) { + lxcNetworkParseDataPtr data = networks.parseData[i]; + for (j = 0; j < data->nips; j++) + VIR_FREE(data->ips[j]); + VIR_FREE(data->ips); + } + goto cleanup; }
static int -- 2.20.1

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 <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 31aa666e38..8bbe205659 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -649,6 +649,55 @@ 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_tmp = STRSKIP(name, "lxc.net."); + char *suffix = NULL; + unsigned long long index; + + if (virStrToLong_ull(suffix_tmp, &suffix, 10, &index) < 0) + return -1; + + if (suffix[0] != '.') + return -1; + + suffix++; + + if (!(parseData = lxcNetworkGetParseDataByIndex(networks, index))) + return -1; + + return lxcNetworkParseDataSuffix(suffix, value, parseData); +} + + static lxcNetworkParseDataPtr lxcNetworkGetParseDataByIndexLegacy(lxcNetworkParseDataArray *networks, const char *entry) @@ -695,6 +744,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

Domain definition is useless now inside network structure. This pointer was required because new network definition was being added each time that a new network type appeared. So, this should be processed into old function `lxcNetworkParseDataType()`. Now, as it was moved to an array, it can be handle together each interface pointer. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 8bbe205659..99539a0205 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -414,7 +414,6 @@ lxcCreateHostdevDef(int mode, int type, const char *data) typedef struct _lxcNetworkParseData lxcNetworkParseData; typedef lxcNetworkParseData *lxcNetworkParseDataPtr; struct _lxcNetworkParseData { - virDomainDefPtr def; char *type; char *link; char *mac; @@ -470,13 +469,16 @@ lxcAddNetworkRouteDefinition(const char *address, } static int -lxcAddNetworkDefinition(lxcNetworkParseData *data) +lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetworkParseData *data) { virDomainNetDefPtr net = NULL; virDomainHostdevDefPtr hostdev = NULL; bool isPhys, isVlan = false; size_t i; + if (!data) + return -1; + if ((data->type == NULL) || STREQ(data->type, "empty") || STREQ(data->type, "") || STREQ(data->type, "none")) return 0; @@ -518,9 +520,9 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data) &hostdev->source.caps.u.net.ip.nroutes) < 0) goto error; - if (VIR_EXPAND_N(data->def->hostdevs, data->def->nhostdevs, 1) < 0) + if (VIR_EXPAND_N(def->hostdevs, def->nhostdevs, 1) < 0) goto error; - data->def->hostdevs[data->def->nhostdevs - 1] = hostdev; + def->hostdevs[def->nhostdevs - 1] = hostdev; } else { if (!(net = lxcCreateNetDef(data->type, data->link, data->mac, data->flag, data->macvlanmode, @@ -542,9 +544,9 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data) &net->guestIP.nroutes) < 0) goto error; - if (VIR_EXPAND_N(data->def->nets, data->def->nnets, 1) < 0) + if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0) goto error; - data->def->nets[data->def->nnets - 1] = net; + def->nets[def->nnets - 1] = net; } return 1; @@ -766,9 +768,8 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties) for (i = 0; i < networks.ndata; i++) { lxcNetworkParseDataPtr data = networks.parseData[i]; - data->def = def; - status = lxcAddNetworkDefinition(data); + status = lxcAddNetworkDefinition(def, data); if (status < 0) goto error; -- 2.20.1

On 2/3/20 2:28 AM, Julio Faracco wrote:
Domain definition is useless now inside network structure. This pointer was required because new network definition was being added each time that a new network type appeared. So, this should be processed into old function `lxcNetworkParseDataType()`. Now, as it was moved to an array, it can be handle together each interface pointer.
Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 8bbe205659..99539a0205 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -414,7 +414,6 @@ lxcCreateHostdevDef(int mode, int type, const char *data) typedef struct _lxcNetworkParseData lxcNetworkParseData; typedef lxcNetworkParseData *lxcNetworkParseDataPtr; struct _lxcNetworkParseData { - virDomainDefPtr def; char *type; char *link; char *mac; @@ -470,13 +469,16 @@ lxcAddNetworkRouteDefinition(const char *address, }
static int -lxcAddNetworkDefinition(lxcNetworkParseData *data) +lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetworkParseData *data) { virDomainNetDefPtr net = NULL; virDomainHostdevDefPtr hostdev = NULL; bool isPhys, isVlan = false; size_t i;
+ if (!data) + return -1;
Is this check really necessary? I mean, can @data be NULL? Because from my understanding of the code it can not. But even if it can, we need to report an error here because the caller doesn't. You don't need to resend, I can fix it before pushing. The rest looks good. Michal

I agree, Michal. I reviewed the logic and it is impossible to get a NULL pointer using both approaches. Thanks! -- Julio Cesar Faracco Em seg., 3 de fev. de 2020 às 07:06, Michal Privoznik <mprivozn@redhat.com> escreveu:
On 2/3/20 2:28 AM, Julio Faracco wrote:
Domain definition is useless now inside network structure. This pointer was required because new network definition was being added each time that a new network type appeared. So, this should be processed into old function `lxcNetworkParseDataType()`. Now, as it was moved to an array, it can be handle together each interface pointer.
Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 8bbe205659..99539a0205 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -414,7 +414,6 @@ lxcCreateHostdevDef(int mode, int type, const char *data) typedef struct _lxcNetworkParseData lxcNetworkParseData; typedef lxcNetworkParseData *lxcNetworkParseDataPtr; struct _lxcNetworkParseData { - virDomainDefPtr def; char *type; char *link; char *mac; @@ -470,13 +469,16 @@ lxcAddNetworkRouteDefinition(const char *address, }
static int -lxcAddNetworkDefinition(lxcNetworkParseData *data) +lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetworkParseData *data) { virDomainNetDefPtr net = NULL; virDomainHostdevDefPtr hostdev = NULL; bool isPhys, isVlan = false; size_t i;
+ if (!data) + return -1;
Is this check really necessary? I mean, can @data be NULL? Because from my understanding of the code it can not. But even if it can, we need to report an error here because the caller doesn't.
You don't need to resend, I can fix it before pushing. The rest looks good.
Michal

On 2/3/20 3:34 PM, Julio Faracco wrote:
I agree, Michal. I reviewed the logic and it is impossible to get a NULL pointer using both approaches. Thanks!
Alright, I've removed the check and pushed. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal

LXC version 3 config files are still using network old style definition. So, as LXC supports it now, they can be converted to use this new definition. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- .../lxcconf2xml-ethernet-v3.config | 16 ++++----- .../lxcconf2xml-fstab-v3.config | 10 +++--- .../lxcconf2xml-macvlannetwork-v3.config | 10 +++--- .../lxcconf2xml-miscnetwork-v3.config | 34 +++++++++---------- .../lxcconf2xml-nonenetwork-v3.config | 2 +- .../lxcconf2xml-physnetwork-v3.config | 14 ++++---- .../lxcconf2xml-simple-v3.config | 18 +++++----- .../lxcconf2xml-vlannetwork-v3.config | 10 +++--- 8 files changed, 57 insertions(+), 57 deletions(-) diff --git a/tests/lxcconf2xmldata/lxcconf2xml-ethernet-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-ethernet-v3.config index 630cb2ebb6..0a641549f3 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-ethernet-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-ethernet-v3.config @@ -1,14 +1,14 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = veth -lxc.network.flags = up -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.name = eth0 -lxc.network.ipv4 = 192.168.122.2/24 -lxc.network.ipv4.gateway = 192.168.122.1 -lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 -lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 +lxc.net.0.type = veth +lxc.net.0.flags = up +lxc.net.0.hwaddr = 02:00:15:8f:05:c1 +lxc.net.0.name = eth0 +lxc.net.0.ipv4 = 192.168.122.2/24 +lxc.net.0.ipv4.gateway = 192.168.122.1 +lxc.net.0.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.net.0.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 #remove next line if host DNS configuration should not be available to container lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-fstab-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-fstab-v3.config index 8b62818657..79bcfa1bd1 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-fstab-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-fstab-v3.config @@ -1,11 +1,11 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = veth -lxc.network.flags = up -lxc.network.link = virbr0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.name = eth0 +lxc.net.0.type = veth +lxc.net.0.flags = up +lxc.net.0.link = virbr0 +lxc.net.0.hwaddr = 02:00:15:8f:05:c1 +lxc.net.0.name = eth0 #remove next line if host DNS configuration should not be available to container lxc.mount.fstab = /var/lib/lxc/migrate_test/fstab diff --git a/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork-v3.config index 631f07ecca..ab8d85361f 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork-v3.config @@ -1,11 +1,11 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = macvlan -lxc.network.flags = up -lxc.network.link = eth0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.macvlan.mode = vepa +lxc.net.0.type = macvlan +lxc.net.0.flags = up +lxc.net.0.link = eth0 +lxc.net.0.hwaddr = 02:00:15:8f:05:c1 +lxc.net.0.macvlan.mode = vepa #remove next line if host DNS configuration should not be available to container lxc.rootfs.path = /var/lib/lxc/migrate_test/rootfs diff --git a/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config index b46cb3ee7d..537da64592 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config @@ -1,22 +1,22 @@ -lxc.network.type = phys -lxc.network.link = eth0 -lxc.network.name = eth1 -lxc.network.ipv4 = 192.168.122.2/24 -lxc.network.ipv4.gateway = 192.168.122.1 -lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 -lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 +lxc.net.0.type = phys +lxc.net.0.link = eth0 +lxc.net.0.name = eth1 +lxc.net.0.ipv4 = 192.168.122.2/24 +lxc.net.0.ipv4.gateway = 192.168.122.1 +lxc.net.0.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.net.0.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 -lxc.network.type = vlan -lxc.network.flags = up -lxc.network.link = eth0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.vlan.id = 2 +lxc.net.1.type = vlan +lxc.net.1.flags = up +lxc.net.1.link = eth0 +lxc.net.1.hwaddr = 02:00:15:8f:05:c1 +lxc.net.1.vlan.id = 2 -lxc.network.type = macvlan -lxc.network.flags = up -lxc.network.link = eth0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.macvlan.mode = vepa +lxc.net.2.type = macvlan +lxc.net.2.flags = up +lxc.net.2.link = eth0 +lxc.net.2.hwaddr = 02:00:15:8f:05:c1 +lxc.net.2.macvlan.mode = vepa lxc.rootfs = /var/lib/lxc/migrate_test/rootfs lxc.utsname = migrate_test diff --git a/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork-v3.config index f81a786f1e..2402723d9e 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork-v3.config @@ -1,4 +1,4 @@ lxc.rootfs.path = /var/lib/lxc/migrate_test/rootfs lxc.uts.name = migrate_test lxc.autodev=1 -lxc.network.type = none +lxc.net.0.type = none diff --git a/tests/lxcconf2xmldata/lxcconf2xml-physnetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork-v3.config index 92729841d7..9cf96163b3 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-physnetwork-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork-v3.config @@ -1,10 +1,10 @@ -lxc.network.type = phys -lxc.network.link = eth0 -lxc.network.name = eth1 -lxc.network.ipv4 = 192.168.122.2/24 -lxc.network.ipv4.gateway = 192.168.122.1 -lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 -lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 +lxc.net.0.type = phys +lxc.net.0.link = eth0 +lxc.net.0.name = eth1 +lxc.net.0.ipv4 = 192.168.122.2/24 +lxc.net.0.ipv4.gateway = 192.168.122.1 +lxc.net.0.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.net.0.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 lxc.rootfs.path = /var/lib/lxc/migrate_test/rootfs lxc.uts.name = migrate_test diff --git a/tests/lxcconf2xmldata/lxcconf2xml-simple-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-simple-v3.config index a0036a482e..b0656571b2 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-simple-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-simple-v3.config @@ -1,15 +1,15 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = veth -lxc.network.flags = up -lxc.network.link = virbr0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.name = eth0 -lxc.network.ipv4 = 192.168.122.2/24 -lxc.network.ipv4.gateway = 192.168.122.1 -lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 -lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 +lxc.net.0.type = veth +lxc.net.0.flags = up +lxc.net.0.link = virbr0 +lxc.net.0.hwaddr = 02:00:15:8f:05:c1 +lxc.net.0.name = eth0 +lxc.net.0.ipv4 = 192.168.122.2/24 +lxc.net.0.ipv4.gateway = 192.168.122.1 +lxc.net.0.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.net.0.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 #remove next line if host DNS configuration should not be available to container lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork-v3.config index 31e26997dd..fb4539261f 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork-v3.config @@ -1,11 +1,11 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = vlan -lxc.network.flags = up -lxc.network.link = eth0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.vlan.id = 2 +lxc.net.1.type = vlan +lxc.net.1.flags = up +lxc.net.1.link = eth0 +lxc.net.1.hwaddr = 02:00:15:8f:05:c1 +lxc.net.1.vlan.id = 2 lxc.rootfs.path = /var/lib/lxc/migrate_test/rootfs lxc.uts.name = migrate_test -- 2.20.1
participants (2)
-
Julio Faracco
-
Michal Privoznik