]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virInterfaceDefParseIP: Simplify and cleanup
authorTim Wiederhake <twiederh@redhat.com>
Wed, 12 Jan 2022 11:49:38 +0000 (12:49 +0100)
committerTim Wiederhake <twiederh@redhat.com>
Fri, 14 Jan 2022 14:38:49 +0000 (15:38 +0100)
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/interface_conf.c

index 91fe54e9a5ab953fe80b32477de5e01cb9302f16..8a53b1d5c2b3d49eec4bb86007ced20c6c6f3f7c 100644 (file)
@@ -252,24 +252,13 @@ virInterfaceDefParseDhcp(virInterfaceProtocolDef *def,
 
 static int
 virInterfaceDefParseIP(virInterfaceIPDef *def,
-                       xmlXPathContextPtr ctxt)
+                       xmlNodePtr node)
 {
-    int ret = 0;
-    char *tmp;
-    long l;
-
-    tmp = virXPathString("string(./@address)", ctxt);
-    def->address = tmp;
-    if (tmp != NULL) {
-        ret = virXPathLong("string(./@prefix)", ctxt, &l);
-        if (ret == 0) {
-            def->prefix = (int) l;
-        } else if (ret == -2) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           "%s", _("Invalid ip address prefix value"));
-            return -1;
-        }
-    }
+    if (!(def->address = virXMLPropString(node, "address")))
+        return 0;
+
+    if (virXMLPropInt(node, "prefix", 0, VIR_XML_PROP_NONE, &def->prefix, 0) < 0)
+        return -1;
 
     return 0;
 }
@@ -309,8 +298,7 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDef *def,
 
         ip = g_new0(virInterfaceIPDef, 1);
 
-        ctxt->node = ipNodes[i];
-        if (virInterfaceDefParseIP(ip, ctxt) < 0) {
+        if (virInterfaceDefParseIP(ip, ipNodes[i]) < 0) {
             virInterfaceIPDefFree(ip);
             return -1;
         }
@@ -359,8 +347,7 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDef *def,
 
         ip = g_new0(virInterfaceIPDef, 1);
 
-        ctxt->node = ipNodes[i];
-        if (virInterfaceDefParseIP(ip, ctxt) < 0) {
+        if (virInterfaceDefParseIP(ip, ipNodes[i]) < 0) {
             virInterfaceIPDefFree(ip);
             return -1;
         }