Signed-off-by: Shi Lei <shi_lei(a)massclouds.com>
---
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 0ed2332..2af537c 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -870,6 +870,52 @@ virNetworkDNSTxtDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
}
+static int
+virNetworkDNSForwarderParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
+ virNetworkDNSForwarderPtr 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,
+ virNetworkDNSForwarderPtr 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 (virNetworkDNSForwarderParseXMLHook(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,
return -1;
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