From f7fd10e5f8c471e40bd9e9c7b7b05b95310cbbb7 Mon Sep 17 00:00:00 2001 From: Julio Faracco Date: Mon, 18 Feb 2019 16:09:07 -0300 Subject: [PATCH] lxc: Introduce lxcNetworkParseDataSuffix This commit removes the full network entry setting: "lxc.network.X" to type only. Like "type", "name", "flags", etc. This will handle entries regardless of whether they are prefixed by "lxc.network." (today) or "lxc.net.X." (the future). Signed-off-by: Julio Faracco Reviewed-by: John Ferlan --- src/lxc/lxc_native.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 22b083cc0e..6c0421a06a 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -565,7 +565,7 @@ lxcNetworkParseDataIPs(const char *name, if (VIR_ALLOC(ip) < 0) return -1; - if (STREQ(name, "lxc.network.ipv6")) + if (STREQ(name, "ipv6")) family = AF_INET6; ipparts = virStringSplit(value->str, "/", 2); @@ -593,13 +593,13 @@ lxcNetworkParseDataIPs(const char *name, static int -lxcNetworkParseDataEntry(const char *name, - virConfValuePtr value, - lxcNetworkParseData *parseData) +lxcNetworkParseDataSuffix(const char *name, + virConfValuePtr value, + lxcNetworkParseData *parseData) { int status; - if (STREQ(name, "lxc.network.type")) { + if (STREQ(name, "type")) { virDomainDefPtr def = parseData->def; size_t networks = parseData->networks; bool privnet = parseData->privnet; @@ -624,36 +624,48 @@ lxcNetworkParseDataEntry(const char *name, /* Keep the new value */ parseData->type = value->str; } - else if (STREQ(name, "lxc.network.link")) + else if (STREQ(name, "link")) parseData->link = value->str; - else if (STREQ(name, "lxc.network.hwaddr")) + else if (STREQ(name, "hwaddr")) parseData->mac = value->str; - else if (STREQ(name, "lxc.network.flags")) + else if (STREQ(name, "flags")) parseData->flag = value->str; - else if (STREQ(name, "lxc.network.macvlan.mode")) + else if (STREQ(name, "macvlan.mode")) parseData->macvlanmode = value->str; - else if (STREQ(name, "lxc.network.vlan.id")) + else if (STREQ(name, "vlan.id")) parseData->vlanid = value->str; - else if (STREQ(name, "lxc.network.name")) + else if (STREQ(name, "name")) parseData->name = value->str; - else if (STREQ(name, "lxc.network.ipv4") || - STREQ(name, "lxc.network.ipv6")) { + else if (STREQ(name, "ipv4") || + STREQ(name, "ipv6")) { if (lxcNetworkParseDataIPs(name, value, parseData) < 0) return -1; - } else if (STREQ(name, "lxc.network.ipv4.gateway")) { + } else if (STREQ(name, "ipv4.gateway")) { parseData->gateway_ipv4 = value->str; - } else if (STREQ(name, "lxc.network.ipv6.gateway")) { + } else if (STREQ(name, "ipv6.gateway")) { parseData->gateway_ipv6 = value->str; - } else if (STRPREFIX(name, "lxc.network")) { + } else { VIR_WARN("Unhandled network property: %s = %s", name, value->str); + return -1; } return 0; } +static int +lxcNetworkParseDataEntry(const char *name, + virConfValuePtr value, + lxcNetworkParseData *parseData) +{ + const char *suffix = STRSKIP(name, "lxc.network."); + + return lxcNetworkParseDataSuffix(suffix, value, parseData); +} + + static int lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data) { -- GitLab