Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx> --- src/conf/network_conf.c | 63 +++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 146c4977..b326ef5f 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -676,21 +676,57 @@ virNetworkDHCPDefParseXML(const char *networkName, static int -virNetworkDNSHostDefParseXML(const char *networkName, - xmlNodePtr node, - virNetworkDNSHostDef *def, - bool partialOkay) +virNetworkDNSHostDefParseHook(xmlNodePtr node G_GNUC_UNUSED, + virNetworkDNSHostDef *def, + const char *networkName, + void *parent G_GNUC_UNUSED, + void *opaque, + const char *ip, + int nHostnameNodes G_GNUC_UNUSED) { - xmlNodePtr cur; - g_autofree char *ip = NULL; + 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, + virNetworkDNSHostDef *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"), @@ -720,19 +756,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 (virNetworkDNSHostDefParseHook(node, def, networkName, def, &partialOkay, + ip, def->nnames) < 0) goto error; - } return 0; -- 2.25.1