]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virInterfaceDefParseIfAdressing: Simplify and cleanup
authorTim Wiederhake <twiederh@redhat.com>
Wed, 12 Jan 2022 12:40:00 +0000 (13:40 +0100)
committerTim Wiederhake <twiederh@redhat.com>
Fri, 14 Jan 2022 14:38:50 +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 71da243f6a17b7e2cab390602c533361be78e6e4..26844c14c81be02893c53c75e1388eae5f722e7c 100644 (file)
@@ -348,7 +348,6 @@ virInterfaceDefParseIfAdressing(virInterfaceDef *def,
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     g_autofree xmlNodePtr *protoNodes = NULL;
     int nProtoNodes, pp;
-    char *tmp;
 
     nProtoNodes = virXPathNodeSet("./protocol", ctxt, &protoNodes);
     if (nProtoNodes < 0)
@@ -363,26 +362,24 @@ virInterfaceDefParseIfAdressing(virInterfaceDef *def,
 
     def->nprotos = 0;
     for (pp = 0; pp < nProtoNodes; pp++) {
-
         g_autoptr(virInterfaceProtocolDef) proto = g_new0(virInterfaceProtocolDef, 1);
 
-        ctxt->node = protoNodes[pp];
-        tmp = virXPathString("string(./@family)", ctxt);
-        if (tmp == NULL) {
+        if (!(proto->family = virXMLPropString(protoNodes[pp], "family"))) {
             virReportError(VIR_ERR_XML_ERROR,
                            "%s", _("protocol misses the family attribute"));
             return -1;
         }
-        proto->family = tmp;
-        if (STREQ(tmp, "ipv4")) {
+
+        ctxt->node = protoNodes[pp];
+        if (STREQ(proto->family, "ipv4")) {
             if (virInterfaceDefParseProtoIPv4(proto, ctxt) != 0)
                 return -1;
-        } else if (STREQ(tmp, "ipv6")) {
+        } else if (STREQ(proto->family, "ipv6")) {
             if (virInterfaceDefParseProtoIPv6(proto, ctxt) != 0)
                 return -1;
         } else {
             virReportError(VIR_ERR_XML_ERROR,
-                           _("unsupported protocol family '%s'"), tmp);
+                           _("unsupported protocol family '%s'"), proto->family);
             return -1;
         }
         def->protos[def->nprotos++] = g_steal_pointer(&proto);