[RFCv3 23/25] conf: Extract error-checking code from virNetworkDNSDefParseXML

Shi Lei shi_lei at massclouds.com
Thu Apr 22 07:25:31 UTC 2021


Signed-off-by: Shi Lei <shi_lei at massclouds.com>
---
 src/conf/network_conf.c | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index be639500..19408987 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -883,6 +883,31 @@ virNetworkDNSForwarderParseHook(xmlNodePtr node G_GNUC_UNUSED,
 }
 
 
+static int
+virNetworkDNSDefParseHook(xmlNodePtr node G_GNUC_UNUSED,
+                          virNetworkDNSDef *def,
+                          const char *networkName,
+                          void *parent G_GNUC_UNUSED,
+                          void *opaque G_GNUC_UNUSED,
+                          const char *enable G_GNUC_UNUSED,
+                          const char *forwardPlainNames G_GNUC_UNUSED,
+                          int nfwds,
+                          int ntxts,
+                          int nsrvs,
+                          int nhosts)
+{
+    if (def->enable == VIR_TRISTATE_BOOL_NO &&
+        (nfwds || nhosts || nsrvs || ntxts)) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("Extra data in disabled network '%s'"),
+                       networkName);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 virNetworkDNSDefParseXML(const char *networkName,
                          xmlNodePtr node,
@@ -1004,13 +1029,10 @@ virNetworkDNSDefParseXML(const char *networkName,
         }
     }
 
-    if (def->enable == VIR_TRISTATE_BOOL_NO &&
-        (nfwds || nhosts || nsrvs || ntxts)) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("Extra data in disabled network '%s'"),
-                       networkName);
+    if (virNetworkDNSDefParseHook(node, def, networkName, def, NULL,
+                                  enable, forwardPlainNames,
+                                  nfwds, ntxts, nsrvs, nhosts) < 0)
         return -1;
-    }
 
     return 0;
 }
-- 
2.25.1





More information about the libvir-list mailing list