[RFCv3 20/25] conf: Extract virNetworkDNSForwarderParseXML from virNetworkDNSParseXML

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

 



Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx>
---
 src/conf/network_conf.c | 68 +++++++++++++++++++++++++++++++----------
 1 file changed, 52 insertions(+), 16 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index ba67eab1..cf9e77d3 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -871,6 +871,52 @@ virNetworkDNSTxtDefParseHook(xmlNodePtr node G_GNUC_UNUSED,
 }
 
 
+static int
+virNetworkDNSForwarderParseHook(xmlNodePtr node G_GNUC_UNUSED,
+                                virNetworkDNSForwarder *def,
+                                const char *instname G_GNUC_UNUSED,
+                                void *parent G_GNUC_UNUSED,
+                                void *opaque G_GNUC_UNUSED,
+                                const char *addr)
+{
+    if (!(addr || def->domain)) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("Invalid forwarder element, must contain "
+                         "at least one of addr or domain"));
+        return -1;
+    }
+
+    return 0;
+}
+
+
+static int
+virNetworkDNSForwarderParseXML(xmlNodePtr node,
+                               virNetworkDNSForwarder *def,
+                               const char *networkName,
+                               void *parent G_GNUC_UNUSED,
+                               void *opaque)
+{
+    g_autofree char *addr = virXMLPropString(node, "addr");
+
+    if (addr && virSocketAddrParse(&def->addr, addr, AF_UNSPEC) < 0) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("Invalid forwarder IP address '%s' "
+                         "in network '%s'"),
+                       addr, networkName);
+        return -1;
+    }
+
+    def->domain = virXMLPropString(node, "domain");
+
+    if (virNetworkDNSForwarderParseHook(node, def, networkName, def, opaque,
+                                        addr) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 virNetworkDNSDefParseXML(const char *networkName,
                          xmlNodePtr node,
@@ -924,23 +970,13 @@ virNetworkDNSDefParseXML(const char *networkName,
         def->forwarders = g_new0(virNetworkDNSForwarder, nfwds);
 
         for (i = 0; i < nfwds; i++) {
-            g_autofree char *addr = virXMLPropString(fwdNodes[i], "addr");
-
-            if (addr && virSocketAddrParse(&def->forwarders[i].addr,
-                                           addr, AF_UNSPEC) < 0) {
-                virReportError(VIR_ERR_XML_ERROR,
-                               _("Invalid forwarder IP address '%s' "
-                                 "in network '%s'"),
-                               addr, networkName);
+            if (virNetworkDNSForwarderParseXML(fwdNodes[i],
+                                               &def->forwarders[i],
+                                               networkName,
+                                               def,
+                                               NULL) < 0)
                 return -1;
-            }
-            def->forwarders[i].domain = virXMLPropString(fwdNodes[i], "domain");
-            if (!(addr || def->forwarders[i].domain)) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("Invalid forwarder element, must contain "
-                                 "at least one of addr or domain"));
-                return -1;
-            }
+
             def->nfwds++;
         }
     }
-- 
2.25.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