>From 99a4d33ae4bab241872d4a018020f32fa40df56a Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Thu, 23 Jun 2011 00:53:01 -0400 Subject: [PATCH] squash into 5/5 --- src/conf/network_conf.c | 45 ++++++++++++++++++--------------------------- src/conf/network_conf.h | 2 +- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index d4f6912..4bc486e 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -115,10 +115,8 @@ static void virNetworkDNSDefFree(virNetworkDNSDefPtr def) VIR_FREE(def->txtrecords); } if (def->nhosts) { - while (def->nhosts--) { + while (def->nhosts--) VIR_FREE(def->hosts[def->nhosts].name); - VIR_FREE(def->hosts[def->nhosts].ip); - } VIR_FREE(def->hosts); } VIR_FREE(def); @@ -459,20 +457,30 @@ virNetworkDHCPRangeDefParseXML(const char *networkName, static int virNetworkDNSHostsDefParseXML(virNetworkDNSDefPtr def, - xmlNodePtr node, - virSocketAddr ip) + xmlNodePtr node) { xmlNodePtr cur; + char *ip; + virSocketAddr inaddr; int ret = -1; if (def->hosts == NULL) { if (VIR_ALLOC(def->hosts) < 0) { virReportOOMError(); - goto out; + goto error; } def->nhosts = 0; } + if (!(ip = virXMLPropString(node, "ip")) || + (virSocketParseAddr(ip, &inaddr, AF_UNSPEC) < 0)) { + virNetworkReportError(VIR_ERR_XML_DETAIL, + _("Missing IP address in DNS host definition")); + VIR_FREE(ip); + goto error; + } + VIR_FREE(ip); + cur = node->children; while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE && @@ -484,13 +492,12 @@ virNetworkDNSHostsDefParseXML(virNetworkDNSDefPtr def, if (VIR_REALLOC_N(def->hosts, def->nhosts + 1) < 0) { VIR_FREE(hostname); - ret = -1; virReportOOMError(); - goto out; + goto error; } def->hosts[def->nhosts].name = hostname; - def->hosts[def->nhosts].ip = ip; + def->hosts[def->nhosts].ip = inaddr; def->nhosts++; } } @@ -500,7 +507,7 @@ virNetworkDNSHostsDefParseXML(virNetworkDNSDefPtr def, ret = 0; -out: +error: return ret; } @@ -552,23 +559,7 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef, value = NULL; } else if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "host")) { - char *ip; - virSocketAddr inaddr; - memset(&inaddr, 0, sizeof(inaddr)); - - if (!(ip = virXMLPropString(cur, "ip"))) { - cur = cur->next; - continue; - } - if ((ip == NULL) || - (virSocketParseAddr(ip, &inaddr, AF_UNSPEC) < 0)) { - virNetworkReportError(VIR_ERR_XML_DETAIL, - _("Missing IP address in DNS host definition")); - VIR_FREE(ip); - goto error; - } - VIR_FREE(ip); - ret = virNetworkDNSHostsDefParseXML(def, cur, inaddr); + ret = virNetworkDNSHostsDefParseXML(def, cur); if (ret < 0) goto error; } diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 50b3713..2341df4 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -73,8 +73,8 @@ typedef struct virNetworkDNSHostsDef *virNetworkDNSHostsDefPtr; struct virNetworkDNSDef { unsigned int ntxtrecords; - unsigned int nhosts; virNetworkDNSTxtRecordsDefPtr txtrecords; + unsigned int nhosts; virNetworkDNSHostsDefPtr hosts; } virNetworkDNSDef; -- 1.7.3.4