From 087a7c9a88657bb50a1077c351de7948ac1b5cce Mon Sep 17 00:00:00 2001 From: Julio Faracco Date: Mon, 18 Feb 2019 16:09:09 -0300 Subject: [PATCH] lxc: Introduce lxcNetworkParseDataType Extract out the network "type" processing into it's own method rather than inline within lxcNetworkParseDataSuffix. Signed-off-by: Julio Faracco Reviewed-by: John Ferlan --- src/lxc/lxc_native.c | 58 ++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 6c0421a06a..5df05b6b55 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -553,6 +553,39 @@ 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, @@ -597,32 +630,9 @@ 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 (lxcNetworkParseDataType(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;