Signed-off-by: Shi Lei <shi_lei(a)massclouds.com>
---
src/conf/network_conf.c | 71 ++++-------------------------------------
src/conf/network_conf.h | 6 ++--
2 files changed, 9 insertions(+), 68 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 44032e6..e2d0297 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -174,15 +174,6 @@ virNetworkIPDefClear(virNetworkIPDefPtr def)
}
-static void
-virNetworkDNSHostDefClear(virNetworkDNSHostDefPtr def)
-{
- while (def->nnames)
- VIR_FREE(def->names[--def->nnames]);
- VIR_FREE(def->names);
-}
-
-
static void
virNetworkDNSForwarderClear(virNetworkDNSForwarderPtr def)
{
@@ -674,7 +665,7 @@ virNetworkDHCPDefParseXML(const char *networkName,
}
-static int
+int
virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
virNetworkDNSHostDefPtr def,
const char *networkName,
@@ -716,58 +707,6 @@ virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
}
-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);
- 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 (virNetworkDNSHostDefParseXMLHook(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 "."
@@ -1018,8 +957,8 @@ virNetworkDNSDefParseXML(const char *networkName,
return -1;
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++;
@@ -3421,6 +3360,7 @@ virNetworkDefUpdateDNSHost(virNetworkDefPtr 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));
@@ -3434,7 +3374,8 @@ virNetworkDefUpdateDNSHost(virNetworkDefPtr 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 041119e..c30fd4f 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -149,10 +149,10 @@ struct _virNetworkDNSSrvDef { /* genparse:withhook, genformat */
typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef;
typedef virNetworkDNSHostDef *virNetworkDNSHostDefPtr;
-struct _virNetworkDNSHostDef {
- virSocketAddr ip;
+struct _virNetworkDNSHostDef { /* genparse:withhook */
+ virSocketAddr ip; /* xmlattr */
size_t nnames;
- char **names;
+ char **names; /* xmlelem:hostname, array */
};
--
2.25.1