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

Julio Faracco posted 6 patches 6 years, 11 months ago
[libvirt] [PATCH 1/6] lxc: Create a separate method to handle IPv{4, 6} outside parser.
Posted by Julio Faracco 6 years, 11 months ago
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@gmail.com>
---
 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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/6] lxc: Create a separate method to handle IPv{4, 6} outside parser.
Posted by John Ferlan 6 years, 11 months ago
FWIW: No need for stop (e.g. '.') at end of each comment message...

On 2/18/19 2:09 PM, Julio Faracco wrote:
> 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@gmail.com>
> ---
>  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)

When adding new functions we like to see 2 blank lines before/after each
method and each argument for the method on it's own line.

I've fixed all of this for you...

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

[...]

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list