The structure used to handle network entries was based on 'if,else' conditions. This commit converts this ugly structure into a switch to clearify each option of the handler. Signed-off-by: Julio Faracco <jcfaracco@xxxxxxxxx> --- src/lxc/lxc_native.c | 58 ++++++++++++++++++++++++++++++++------------ src/lxc/lxc_native.h | 17 +++++++++++++ 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 25e35e93dd..c746c443da 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -35,6 +35,20 @@ VIR_LOG_INIT("lxc.lxc_native"); +VIR_ENUM_IMPL(virLXCNetworkConfigEntry, VIR_LXC_NETWORK_CONFIG_LAST, + "name", + "type", + "link", + "hwaddr", + "flags", + "macvlan.mode", + "vlan.id", + "ipv4", + "ipv4.gateway", + "ipv6", + "ipv6.gateway" +); + static virDomainFSDefPtr lxcCreateFSDef(int type, const char *src, @@ -620,35 +634,47 @@ lxcNetworkParseDataIPs(const char *name, virConfValuePtr value, lxcNetworkParseD } static int -lxcNetworkParseDataSuffix(const char *name, virConfValuePtr value, lxcNetworkParseData *parseData) +lxcNetworkParseDataSuffix(const char *entry, virConfValuePtr value, lxcNetworkParseData *parseData) { - if (STREQ(name, "type")) { + int type = virLXCNetworkConfigEntryTypeFromString(entry); + + switch (type) { + case VIR_LXC_NETWORK_CONFIG_TYPE: if (lxcNetworkParseDataInit(value, parseData) < 0) return -1; - } - else if (STREQ(name, "link")) + break; + case VIR_LXC_NETWORK_CONFIG_LINK: parseData->link = value->str; - else if (STREQ(name, "hwaddr")) + break; + case VIR_LXC_NETWORK_CONFIG_HWADDR: parseData->mac = value->str; - else if (STREQ(name, "flags")) + break; + case VIR_LXC_NETWORK_CONFIG_FLAGS: parseData->flag = value->str; - else if (STREQ(name, "macvlan.mode")) + break; + case VIR_LXC_NETWORK_CONFIG_MACVLAN_MODE: parseData->macvlanmode = value->str; - else if (STREQ(name, "vlan.id")) + break; + case VIR_LXC_NETWORK_CONFIG_VLAN_ID: parseData->vlanid = value->str; - else if (STREQ(name, "name")) + break; + case VIR_LXC_NETWORK_CONFIG_NAME: parseData->name = value->str; - else if (STREQ(name, "ipv4") || - STREQ(name, "ipv6")) { - if (lxcNetworkParseDataIPs(name, value, parseData) < 0) + break; + case VIR_LXC_NETWORK_CONFIG_IPV4: + case VIR_LXC_NETWORK_CONFIG_IPV6: + if (lxcNetworkParseDataIPs(entry, value, parseData) < 0) return -1; - } else if (STREQ(name, "ipv4.gateway")) { + break; + case VIR_LXC_NETWORK_CONFIG_IPV4_GATEWAY: parseData->gateway_ipv4 = value->str; - } else if (STREQ(name, "ipv6.gateway")) { + break; + case VIR_LXC_NETWORK_CONFIG_IPV6_GATEWAY: parseData->gateway_ipv6 = value->str; - } else { + break; + default: VIR_WARN("Unhandled network property: %s = %s", - name, + entry, value->str); return -1; } diff --git a/src/lxc/lxc_native.h b/src/lxc/lxc_native.h index 86f5163e12..0939be346d 100644 --- a/src/lxc/lxc_native.h +++ b/src/lxc/lxc_native.h @@ -25,6 +25,23 @@ # define LXC_CONFIG_FORMAT "lxc-tools" +typedef enum { + VIR_LXC_NETWORK_CONFIG_NAME, + VIR_LXC_NETWORK_CONFIG_TYPE, + VIR_LXC_NETWORK_CONFIG_LINK, + VIR_LXC_NETWORK_CONFIG_HWADDR, + VIR_LXC_NETWORK_CONFIG_FLAGS, + VIR_LXC_NETWORK_CONFIG_MACVLAN_MODE, + VIR_LXC_NETWORK_CONFIG_VLAN_ID, + VIR_LXC_NETWORK_CONFIG_IPV4, + VIR_LXC_NETWORK_CONFIG_IPV4_GATEWAY, + VIR_LXC_NETWORK_CONFIG_IPV6, + VIR_LXC_NETWORK_CONFIG_IPV6_GATEWAY, + VIR_LXC_NETWORK_CONFIG_LAST, +} virLXCNetworkConfigEntry; + +VIR_ENUM_DECL(virLXCNetworkConfigEntry); + virDomainDefPtr lxcParseConfigString(const char *config, virCapsPtr caps, virDomainXMLOptionPtr xmlopt); -- 2.19.1