[PATCH 1/6] lxc: Create a separate method to handle IPv{4, 6} outside parser.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The new method called lxcNetworkParseDataIPs() is responsible to handle
IPv{4,6} settings now. The idea is let lxcNetworkWalkCallback() method
handle all entries related to network definition only.

Signed-off-by: Julio Faracco <jcfaracco@xxxxxxxxx>
---
 src/lxc/lxc_native.c | 65 +++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 28 deletions(-)

diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 1eee3fc2bb..5bbbbf132c 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -552,6 +552,42 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data)
     return -1;
 }
 
+static int
+lxcNetworkParseDataIPs(const char *name, virConfValuePtr value, lxcNetworkParseData *parseData)
+{
+    int family = AF_INET;
+    char **ipparts = NULL;
+    virNetDevIPAddrPtr ip = NULL;
+
+    if (VIR_ALLOC(ip) < 0)
+        return -1;
+
+    if (STREQ(name, "lxc.network.ipv6"))
+        family = AF_INET6;
+
+    ipparts = virStringSplit(value->str, "/", 2);
+    if (virStringListLength((const char * const *)ipparts) != 2 ||
+        virSocketAddrParse(&ip->address, ipparts[0], family) < 0 ||
+        virStrToLong_ui(ipparts[1], NULL, 10, &ip->prefix) < 0) {
+
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("Invalid CIDR address: '%s'"), value->str);
+
+        virStringListFree(ipparts);
+        VIR_FREE(ip);
+        return -1;
+    }
+
+    virStringListFree(ipparts);
+
+    if (VIR_APPEND_ELEMENT(parseData->ips, parseData->nips, ip) < 0) {
+        VIR_FREE(ip);
+        return -1;
+    }
+
+    return 0;
+}
+
 static int
 lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
 {
@@ -597,35 +633,8 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
         parseData->name = value->str;
     else if (STREQ(name, "lxc.network.ipv4") ||
              STREQ(name, "lxc.network.ipv6")) {
-        int family = AF_INET;
-        char **ipparts = NULL;
-        virNetDevIPAddrPtr ip = NULL;
-
-        if (VIR_ALLOC(ip) < 0)
+        if (lxcNetworkParseDataIPs(name, value, parseData) < 0)
             return -1;
-
-        if (STREQ(name, "lxc.network.ipv6"))
-            family = AF_INET6;
-
-        ipparts = virStringSplit(value->str, "/", 2);
-        if (virStringListLength((const char * const *)ipparts) != 2 ||
-            virSocketAddrParse(&ip->address, ipparts[0], family) < 0 ||
-            virStrToLong_ui(ipparts[1], NULL, 10, &ip->prefix) < 0) {
-
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid CIDR address: '%s'"), value->str);
-
-            virStringListFree(ipparts);
-            VIR_FREE(ip);
-            return -1;
-        }
-
-        virStringListFree(ipparts);
-
-        if (VIR_APPEND_ELEMENT(parseData->ips, parseData->nips, ip) < 0) {
-            VIR_FREE(ip);
-            return -1;
-        }
     } else if (STREQ(name, "lxc.network.ipv4.gateway")) {
         parseData->gateway_ipv4 = value->str;
     } else if (STREQ(name, "lxc.network.ipv6.gateway")) {
-- 
2.19.1


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux