This method has the same idea of the method to parse IPv{4,6} data. The method lxcNetworkParseDataInit() is responsible to initialize network settings outside handler. Signed-off-by: Julio Faracco <jcfaracco@xxxxxxxxx> --- src/lxc/lxc_native.c | 56 +++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 95e08c18f4..25e35e93dd 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -552,6 +552,37 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data) return -1; } +static int +lxcNetworkParseDataInit(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, lxcNetworkParseData *parseData) { @@ -591,32 +622,9 @@ lxcNetworkParseDataIPs(const char *name, virConfValuePtr value, lxcNetworkParseD static int lxcNetworkParseDataSuffix(const char *name, virConfValuePtr value, lxcNetworkParseData *parseData) { - int status; - if (STREQ(name, "type")) { - virDomainDefPtr def = parseData->def; - size_t networks = parseData->networks; - bool privnet = parseData->privnet; - - /* Store the previous NIC */ - status = lxcAddNetworkDefinition(parseData); - - if (status < 0) + if (lxcNetworkParseDataInit(value, parseData) < 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; } else if (STREQ(name, "link")) parseData->link = value->str; -- 2.19.1