Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx> --- src/conf/network_conf.c | 71 ++++------------------------------------- src/conf/network_conf.h | 7 ++-- 2 files changed, 10 insertions(+), 68 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index b326ef5f..90b1e0ee 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -174,15 +174,6 @@ virNetworkIPDefClear(virNetworkIPDef *def) } -static void -virNetworkDNSHostDefClear(virNetworkDNSHostDef *def) -{ - while (def->nnames) - VIR_FREE(def->names[--def->nnames]); - VIR_FREE(def->names); -} - - static void virNetworkDNSForwarderClear(virNetworkDNSForwarder *def) { @@ -675,7 +666,7 @@ virNetworkDHCPDefParseXML(const char *networkName, } -static int +int virNetworkDNSHostDefParseHook(xmlNodePtr node G_GNUC_UNUSED, virNetworkDNSHostDef *def, const char *networkName, @@ -717,58 +708,6 @@ virNetworkDNSHostDefParseHook(xmlNodePtr node G_GNUC_UNUSED, } -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"), - networkName); - goto error; - } - - cur = node->children; - while (cur != NULL) { - if (cur->type == XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "hostname")) { - if (cur->children != NULL) { - g_autofree char *name = virXMLNodeContentString(cur); - - if (!name) - goto error; - - if (!name[0]) { - virReportError(VIR_ERR_XML_DETAIL, - _("Missing hostname in network '%s' DNS HOST record"), - networkName); - goto error; - } - if (VIR_APPEND_ELEMENT(def->names, def->nnames, name) < 0) - goto error; - } - } - cur = cur->next; - } - - if (virNetworkDNSHostDefParseHook(node, def, networkName, def, &partialOkay, - ip, def->nnames) < 0) - goto error; - - return 0; - - error: - virNetworkDNSHostDefClear(def); - return -1; -} - - /* This includes all characters used in the names of current * /etc/services and /etc/protocols files (on Fedora 20), except ".", * which we can't allow because it would conflict with the use of "." @@ -1017,8 +956,8 @@ virNetworkDNSDefParseXML(const char *networkName, def->hosts = g_new0(virNetworkDNSHostDef, nhosts); for (i = 0; i < nhosts; i++) { - if (virNetworkDNSHostDefParseXML(networkName, hostNodes[i], - &def->hosts[def->nhosts], false) < 0) { + if (virNetworkDNSHostDefParseXML(hostNodes[i], &def->hosts[def->nhosts], + networkName, def, NULL) < 0) { return -1; } def->nhosts++; @@ -3398,6 +3337,7 @@ virNetworkDefUpdateDNSHost(virNetworkDef *def, bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); int foundCt = 0; + bool notAdd; memset(&host, 0, sizeof(host)); @@ -3411,7 +3351,8 @@ virNetworkDefUpdateDNSHost(virNetworkDef *def, if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "host") < 0) goto cleanup; - if (virNetworkDNSHostDefParseXML(def->name, ctxt->node, &host, !isAdd) < 0) + notAdd = !isAdd; + if (virNetworkDNSHostDefParseXML(ctxt->node, &host, def->name, def, ¬Add) < 0) goto cleanup; for (i = 0; i < dns->nhosts; i++) { diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 052ccb58..998411be 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -142,10 +142,10 @@ struct _virNetworkDNSSrvDef { /* genparse, genformat */ }; typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef; -struct _virNetworkDNSHostDef { - virSocketAddr ip; +struct _virNetworkDNSHostDef { /* genparse */ + virSocketAddr ip; /* xmlattr */ size_t nnames; - char **names; + char **names; /* xmlelem:hostname, array */ }; @@ -429,6 +429,7 @@ virNetworkDefUpdateSection(virNetworkDef *def, VIR_ENUM_DECL(virNetworkTaint); +#define ENABLE_VIR_NETWORK_DNSHOST_DEF_PARSE_HOOK #define ENABLE_VIR_NETWORK_DNSSRV_DEF_PARSE_HOOK #define ENABLE_VIR_NETWORK_DNSTXT_DEF_PARSE_HOOK #include "network_conf.generated.h" -- 2.25.1