Signed-off-by: Shi Lei <shi_lei(a)massclouds.com>
---
src/conf/network_conf.c | 64 ++++++++++++++++++++++++++++-------------
1 file changed, 44 insertions(+), 20 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index e8e7922..7a3dcd4 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -692,29 +692,62 @@ virNetworkDHCPDefParseXML(const char *networkName,
static int
-virNetworkDNSHostDefParseXML(const char *networkName,
- xmlNodePtr node,
- virNetworkDNSHostDefPtr def,
- bool partialOkay)
+virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
+ virNetworkDNSHostDefPtr def,
+ const char *networkName,
+ void *opaque,
+ char *ip,
+ int nHostnameNodes G_GNUC_UNUSED)
{
- xmlNodePtr cur;
- char *ip;
+ bool partialOkay = false;
- if (!(ip = virXMLPropString(node, "ip")) && !partialOkay) {
+ if (opaque)
+ partialOkay = *((bool *) opaque);
+
+ if (!ip && !partialOkay) {
virReportError(VIR_ERR_XML_DETAIL,
_("Missing IP address in network '%s' DNS HOST
record"),
networkName);
goto error;
}
+ if (def->nnames == 0 && !partialOkay) {
+ virReportError(VIR_ERR_XML_DETAIL,
+ _("Missing hostname in network '%s' DNS HOST
record"),
+ networkName);
+ goto error;
+ }
+
+ if (!VIR_SOCKET_ADDR_VALID(&def->ip) && def->nnames == 0) {
+ virReportError(VIR_ERR_XML_DETAIL,
+ _("Missing ip and hostname in network '%s' DNS HOST
record"),
+ networkName);
+ goto error;
+ }
+
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+static int
+virNetworkDNSHostDefParseXML(const char *networkName,
+ xmlNodePtr node,
+ virNetworkDNSHostDefPtr def,
+ bool partialOkay)
+{
+ xmlNodePtr cur;
+ g_autofree char *ip = NULL;
+
+ ip = virXMLPropString(node, "ip");
if (ip && (virSocketAddrParse(&def->ip, ip, AF_UNSPEC) < 0)) {
virReportError(VIR_ERR_XML_DETAIL,
_("Invalid IP address in network '%s' DNS HOST
record"),
networkName);
- VIR_FREE(ip);
goto error;
}
- VIR_FREE(ip);
cur = node->children;
while (cur != NULL) {
@@ -737,19 +770,10 @@ virNetworkDNSHostDefParseXML(const char *networkName,
}
cur = cur->next;
}
- if (def->nnames == 0 && !partialOkay) {
- virReportError(VIR_ERR_XML_DETAIL,
- _("Missing hostname in network '%s' DNS HOST
record"),
- networkName);
- goto error;
- }
- if (!VIR_SOCKET_ADDR_VALID(&def->ip) && def->nnames == 0) {
- virReportError(VIR_ERR_XML_DETAIL,
- _("Missing ip and hostname in network '%s' DNS HOST
record"),
- networkName);
+ if (virNetworkDNSHostDefParseXMLHook(node, def, networkName, &partialOkay,
+ ip, def->nnames) < 0)
goto error;
- }
return 0;
--
2.17.1