提交 ab297bec 编写于 作者: L Laine Stump

conf: clear and parse functions for dns host/srv/txt records

Since there is only a single virNetworkDNSDef for any virNetworkDef,
and it's trivial to determine whether or not it contains any real
data, it's much simpler (and fits more uniformly with the parse
function calling sequence of the parsers for many other objects that
are subordinates of virNetworkDef) if virNetworkDef *contains* an
virNetworkDNSDef rather than pointing to one.

Since it is now just a part of another object rather than its own
object, it no longer makes sense to have a *Free() function, so that
is changed to a *Clear() function.

More importantly though, ParseXML and Clear functions are needed for
the individual items contained in a virNetworkDNSDef (srv, txt, and
host records), but none of them have a *Clear(), and only two of the
three had *ParseXML() functions (both of which used a non-uniform
arglist). Those problems are cleared up by this patch - it splits the
higher-level Clear function into separate functions for each of the
three, creates a parse for txt records, and cleans up the srv and host
parsers, so we now have all the utility functions necessary to
implement virNetworkDefUpdateDNS(Host|Srv|Txt).
上级 8b7d1874
...@@ -133,34 +133,47 @@ static void virNetworkIpDefClear(virNetworkIpDefPtr def) ...@@ -133,34 +133,47 @@ static void virNetworkIpDefClear(virNetworkIpDefPtr def)
VIR_FREE(def->bootfile); VIR_FREE(def->bootfile);
} }
static void virNetworkDNSDefFree(virNetworkDNSDefPtr def) static void
virNetworkDNSTxtDefClear(virNetworkDNSTxtDefPtr def)
{ {
if (def) { VIR_FREE(def->name);
if (def->txts) { VIR_FREE(def->value);
while (def->ntxts--) { }
VIR_FREE(def->txts[def->ntxts].name);
VIR_FREE(def->txts[def->ntxts].value); static void
} virNetworkDNSHostDefClear(virNetworkDNSHostDefPtr def)
} {
while (def->nnames--)
VIR_FREE(def->names[def->nnames]);
VIR_FREE(def->names);
}
static void
virNetworkDNSSrvDefClear(virNetworkDNSSrvDefPtr def)
{
VIR_FREE(def->domain);
VIR_FREE(def->service);
VIR_FREE(def->protocol);
VIR_FREE(def->target);
}
static void
virNetworkDNSDefClear(virNetworkDNSDefPtr def)
{
if (def->txts) {
while (def->ntxts--)
virNetworkDNSTxtDefClear(&def->txts[def->ntxts]);
VIR_FREE(def->txts); VIR_FREE(def->txts);
if (def->nhosts) { }
while (def->nhosts--) { if (def->hosts) {
while (def->hosts[def->nhosts].nnames--) while (def->nhosts--)
VIR_FREE(def->hosts[def->nhosts].names[def->hosts[def->nhosts].nnames]); virNetworkDNSHostDefClear(&def->hosts[def->nhosts]);
VIR_FREE(def->hosts[def->nhosts].names);
}
}
VIR_FREE(def->hosts); VIR_FREE(def->hosts);
if (def->nsrvs) { }
while (def->nsrvs--) { if (def->srvs) {
VIR_FREE(def->srvs[def->nsrvs].domain); while (def->nsrvs--)
VIR_FREE(def->srvs[def->nsrvs].service); virNetworkDNSSrvDefClear(&def->srvs[def->nsrvs]);
VIR_FREE(def->srvs[def->nsrvs].protocol);
VIR_FREE(def->srvs[def->nsrvs].target);
}
}
VIR_FREE(def->srvs); VIR_FREE(def->srvs);
VIR_FREE(def);
} }
} }
...@@ -195,7 +208,7 @@ void virNetworkDefFree(virNetworkDefPtr def) ...@@ -195,7 +208,7 @@ void virNetworkDefFree(virNetworkDefPtr def)
} }
VIR_FREE(def->portGroups); VIR_FREE(def->portGroups);
virNetworkDNSDefFree(def->dns); virNetworkDNSDefClear(&def->dns);
VIR_FREE(def->virtPortProfile); VIR_FREE(def->virtPortProfile);
...@@ -787,224 +800,279 @@ virNetworkDHCPDefParse(const char *networkName, ...@@ -787,224 +800,279 @@ virNetworkDHCPDefParse(const char *networkName,
} }
static int static int
virNetworkDNSHostsDefParseXML(virNetworkDNSDefPtr def, virNetworkDNSHostDefParseXML(const char *networkName,
xmlNodePtr node) xmlNodePtr node,
virNetworkDNSHostDefPtr def,
bool partialOkay)
{ {
xmlNodePtr cur; xmlNodePtr cur;
char *ip; char *ip;
virSocketAddr inaddr;
int ret = -1;
if (!(ip = virXMLPropString(node, "ip")) || if (!(ip = virXMLPropString(node, "ip")) && !partialOkay) {
(virSocketAddrParse(&inaddr, ip, AF_UNSPEC) < 0)) { virReportError(VIR_ERR_XML_DETAIL,
virReportError(VIR_ERR_XML_DETAIL, "%s", _("Missing IP address in network '%s' DNS HOST record"),
_("Missing IP address in DNS host definition")); networkName);
VIR_FREE(ip); VIR_FREE(ip);
goto error; goto error;
} }
VIR_FREE(ip);
if (VIR_REALLOC_N(def->hosts, def->nhosts + 1) < 0) {
virReportOOMError();
goto error;
}
def->hosts[def->nhosts].ip = inaddr;
def->hosts[def->nhosts].nnames = 0;
if (VIR_ALLOC(def->hosts[def->nhosts].names) < 0) { if (ip && (virSocketAddrParse(&def->ip, ip, AF_UNSPEC) < 0)) {
virReportOOMError(); virReportError(VIR_ERR_XML_DETAIL,
_("Invalid IP address in network '%s' DNS HOST record"),
networkName);
VIR_FREE(ip);
goto error; goto error;
} }
VIR_FREE(ip);
cur = node->children; cur = node->children;
while (cur != NULL) { while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE && if (cur->type == XML_ELEMENT_NODE &&
xmlStrEqual(cur->name, BAD_CAST "hostname")) { xmlStrEqual(cur->name, BAD_CAST "hostname")) {
if (cur->children != NULL) { if (cur->children != NULL) {
if (VIR_REALLOC_N(def->hosts[def->nhosts].names, def->hosts[def->nhosts].nnames + 1) < 0) { if (VIR_REALLOC_N(def->names, def->nnames + 1) < 0) {
virReportOOMError(); virReportOOMError();
goto error; goto error;
} }
def->names[def->nnames++] = (char *)xmlNodeGetContent(cur);
def->hosts[def->nhosts].names[def->hosts[def->nhosts].nnames] = strdup((char *)cur->children->content); if (!def->names[def->nnames - 1]) {
def->hosts[def->nhosts].nnames++; virReportError(VIR_ERR_XML_DETAIL,
_("Missing hostname in network '%s' DNS HOST record"),
networkName);
}
} }
} }
cur = cur->next; cur = cur->next;
} }
if (def->nnames == 0 && !partialOkay) {
virReportError(VIR_ERR_XML_DETAIL,
_("Missing hostname in network '%s' DNS HOST record"),
networkName);
goto error;
}
def->nhosts++; 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;
}
ret = 0; return 0;
error: error:
return ret; virNetworkDNSHostDefClear(def);
return -1;
} }
static int static int
virNetworkDNSSrvDefParseXML(virNetworkDNSDefPtr def, virNetworkDNSSrvDefParseXML(const char *networkName,
xmlNodePtr cur, xmlNodePtr node,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt,
virNetworkDNSSrvDefPtr def,
bool partialOkay)
{ {
char *domain = NULL; if (!(def->service = virXMLPropString(node, "service")) && !partialOkay) {
char *service = NULL;
char *protocol = NULL;
char *target = NULL;
int port;
int priority;
int weight;
int ret = 0;
if (!(service = virXMLPropString(cur, "service"))) {
virReportError(VIR_ERR_XML_DETAIL, virReportError(VIR_ERR_XML_DETAIL,
"%s", _("Missing required service attribute in dns srv record")); _("Missing required service attribute in DNS SRV record "
" of network %s"), networkName);
goto error; goto error;
} }
if (strlen(def->service) > DNS_RECORD_LENGTH_SRV) {
if (strlen(service) > DNS_RECORD_LENGTH_SRV) {
virReportError(VIR_ERR_XML_DETAIL, virReportError(VIR_ERR_XML_DETAIL,
_("Service name is too long, limit is %d bytes"), _("Service name '%s' in network %s is too long, limit is %d bytes"),
DNS_RECORD_LENGTH_SRV); def->service, networkName, DNS_RECORD_LENGTH_SRV);
goto error; goto error;
} }
if (!(protocol = virXMLPropString(cur, "protocol"))) { if (!(def->protocol = virXMLPropString(node, "protocol")) && !partialOkay) {
virReportError(VIR_ERR_XML_DETAIL, virReportError(VIR_ERR_XML_DETAIL,
_("Missing required protocol attribute in dns srv record '%s'"), service); _("Missing required protocol attribute "
"in dns srv record '%s' of network %s"),
def->service, networkName);
goto error; goto error;
} }
/* Check whether protocol value is the supported one */ /* Check whether protocol value is the supported one */
if (STRNEQ(protocol, "tcp") && (STRNEQ(protocol, "udp"))) { if (STRNEQ(def->protocol, "tcp") && (STRNEQ(def->protocol, "udp"))) {
virReportError(VIR_ERR_XML_DETAIL, virReportError(VIR_ERR_XML_DETAIL,
_("Invalid protocol attribute value '%s'"), protocol); _("Invalid protocol attribute value '%s' "
" in DNS SRV record of network %s"),
def->protocol, networkName);
goto error; goto error;
} }
if (VIR_REALLOC_N(def->srvs, def->nsrvs + 1) < 0) { /* Following attributes are optional */
virReportOOMError(); if ((def->target = virXMLPropString(node, "target")) &&
goto error; (def->domain = virXMLPropString(node, "domain"))) {
}
def->srvs[def->nsrvs].service = service;
def->srvs[def->nsrvs].protocol = protocol;
def->srvs[def->nsrvs].domain = NULL;
def->srvs[def->nsrvs].target = NULL;
def->srvs[def->nsrvs].port = 0;
def->srvs[def->nsrvs].priority = 0;
def->srvs[def->nsrvs].weight = 0;
/* Following attributes are optional but we had to make sure they're NULL above */
if ((target = virXMLPropString(cur, "target")) && (domain = virXMLPropString(cur, "domain"))) {
xmlNodePtr save_ctxt = ctxt->node; xmlNodePtr save_ctxt = ctxt->node;
ctxt->node = cur; ctxt->node = node;
if (virXPathInt("string(./@port)", ctxt, &port)) if (virXPathUInt("string(./@port)", ctxt, &def->port) < 0 ||
def->srvs[def->nsrvs].port = port; def->port > 65535) {
virReportError(VIR_ERR_XML_DETAIL,
_("Missing or invalid port attribute "
"in network %s"), networkName);
goto error;
}
if (virXPathInt("string(./@priority)", ctxt, &priority)) if (virXPathUInt("string(./@priority)", ctxt, &def->priority) < 0 ||
def->srvs[def->nsrvs].priority = priority; def->priority > 65535) {
virReportError(VIR_ERR_XML_DETAIL,
_("Missing or invalid priority attribute "
"in network %s"), networkName);
goto error;
}
if (virXPathInt("string(./@weight)", ctxt, &weight)) if (virXPathUInt("string(./@weight)", ctxt, &def->weight) < 0 ||
def->srvs[def->nsrvs].weight = weight; def->weight > 65535) {
ctxt->node = save_ctxt; virReportError(VIR_ERR_XML_DETAIL,
_("Missing or invalid weight attribute "
"in network %s"), networkName);
goto error;
}
def->srvs[def->nsrvs].domain = domain; ctxt->node = save_ctxt;
def->srvs[def->nsrvs].target = target;
def->srvs[def->nsrvs].port = port;
def->srvs[def->nsrvs].priority = priority;
def->srvs[def->nsrvs].weight = weight;
} }
def->nsrvs++; if (!(def->service || def->protocol)) {
virReportError(VIR_ERR_XML_DETAIL,
goto cleanup; _("Missing required service attribute or protocol "
"in DNS SRV record of network %s"), networkName);
goto error;
}
return 0;
error: error:
VIR_FREE(domain); virNetworkDNSSrvDefClear(def);
VIR_FREE(service); return -1;
VIR_FREE(protocol); }
VIR_FREE(target);
ret = -1; static int
virNetworkDNSTxtDefParseXML(const char *networkName,
xmlNodePtr node,
virNetworkDNSTxtDefPtr def,
bool partialOkay)
{
if (!(def->name = virXMLPropString(node, "name"))) {
virReportError(VIR_ERR_XML_DETAIL,
_("missing required name attribute in DNS TXT record "
"of network %s"), networkName);
goto error;
}
if (strchr(def->name, ' ') != NULL) {
virReportError(VIR_ERR_XML_DETAIL,
_("prohibited space character in DNS TXT record "
"name '%s' of network %s"), def->name, networkName);
goto error;
}
if (!(def->value = virXMLPropString(node, "value")) && !partialOkay) {
virReportError(VIR_ERR_XML_DETAIL,
_("missing required value attribute in DNS TXT record "
"named '%s' of network %s"), def->name, networkName);
goto error;
}
cleanup: if (!(def->name || def->value)) {
return ret; virReportError(VIR_ERR_XML_DETAIL,
_("Missing required name or value "
"in DNS TXT record of network %s"), networkName);
goto error;
}
return 0;
error:
virNetworkDNSTxtDefClear(def);
return -1;
} }
static int static int
virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef, virNetworkDNSDefParseXML(const char *networkName,
xmlNodePtr node, xmlNodePtr node,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt,
virNetworkDNSDefPtr def)
{ {
xmlNodePtr cur; xmlNodePtr *hostNodes = NULL;
int ret = -1; xmlNodePtr *srvNodes = NULL;
char *name = NULL; xmlNodePtr *txtNodes = NULL;
char *value = NULL; int nhosts, nsrvs, ntxts;
virNetworkDNSDefPtr def = NULL; int ii, ret = -1;
xmlNodePtr save = ctxt->node;
if (VIR_ALLOC(def) < 0) { ctxt->node = node;
virReportOOMError();
goto error; nhosts = virXPathNodeSet("./host", ctxt, &hostNodes);
if (nhosts < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid <host> element found in <dns> of network %s"),
networkName);
goto cleanup;
} }
if (nhosts > 0) {
if (VIR_ALLOC_N(def->hosts, nhosts) < 0) {
virReportOOMError();
goto cleanup;
}
cur = node->children; for (ii = 0; ii < nhosts; ii++) {
while (cur != NULL) { if (virNetworkDNSHostDefParseXML(networkName, hostNodes[ii],
if (cur->type == XML_ELEMENT_NODE && &def->hosts[def->nhosts], false) < 0) {
xmlStrEqual(cur->name, BAD_CAST "txt")) { goto cleanup;
if (!(name = virXMLPropString(cur, "name"))) {
virReportError(VIR_ERR_XML_DETAIL,
"%s", _("Missing required name attribute in dns txt record"));
goto error;
}
if (!(value = virXMLPropString(cur, "value"))) {
virReportError(VIR_ERR_XML_DETAIL,
_("Missing required value attribute in dns txt record '%s'"), name);
goto error;
} }
def->nhosts++;
}
}
if (strchr(name, ' ') != NULL) { nsrvs = virXPathNodeSet("./srv", ctxt, &srvNodes);
virReportError(VIR_ERR_XML_DETAIL, if (nsrvs < 0) {
_("spaces are not allowed in DNS TXT record names (name is '%s')"), name); virReportError(VIR_ERR_XML_ERROR,
goto error; _("invalid <srv> element found in <dns> of network %s"),
} networkName);
goto cleanup;
}
if (nsrvs > 0) {
if (VIR_ALLOC_N(def->srvs, nsrvs) < 0) {
virReportOOMError();
goto cleanup;
}
if (VIR_REALLOC_N(def->txts, def->ntxts + 1) < 0) { for (ii = 0; ii < nsrvs; ii++) {
virReportOOMError(); if (virNetworkDNSSrvDefParseXML(networkName, srvNodes[ii], ctxt,
goto error; &def->srvs[def->nsrvs], false) < 0) {
goto cleanup;
} }
def->nsrvs++;
}
}
def->txts[def->ntxts].name = name; ntxts = virXPathNodeSet("./txt", ctxt, &txtNodes);
def->txts[def->ntxts].value = value; if (ntxts < 0) {
def->ntxts++; virReportError(VIR_ERR_XML_ERROR,
name = NULL; _("invalid <txt> element found in <dns> of network %s"),
value = NULL; networkName);
} else if (cur->type == XML_ELEMENT_NODE && goto cleanup;
xmlStrEqual(cur->name, BAD_CAST "srv")) { }
ret = virNetworkDNSSrvDefParseXML(def, cur, ctxt); if (ntxts > 0) {
if (ret < 0) if (VIR_ALLOC_N(def->txts, ntxts) < 0) {
goto error; virReportOOMError();
} else if (cur->type == XML_ELEMENT_NODE && goto cleanup;
xmlStrEqual(cur->name, BAD_CAST "host")) {
ret = virNetworkDNSHostsDefParseXML(def, cur);
if (ret < 0)
goto error;
} }
cur = cur->next; for (ii = 0; ii < ntxts; ii++) {
if (virNetworkDNSTxtDefParseXML(networkName, txtNodes[ii],
&def->txts[def->ntxts], false) < 0) {
goto cleanup;
}
def->ntxts++;
}
} }
ret = 0; ret = 0;
error: cleanup:
if (ret < 0) { VIR_FREE(hostNodes);
VIR_FREE(name); VIR_FREE(srvNodes);
VIR_FREE(value); VIR_FREE(txtNodes);
virNetworkDNSDefFree(def); ctxt->node = save;
} else {
*dnsdef = def;
}
return ret; return ret;
} }
...@@ -1320,9 +1388,9 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) ...@@ -1320,9 +1388,9 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
} }
dnsNode = virXPathNode("./dns", ctxt); dnsNode = virXPathNode("./dns", ctxt);
if (dnsNode != NULL) { if (dnsNode != NULL &&
if (virNetworkDNSDefParseXML(&def->dns, dnsNode, ctxt) < 0) virNetworkDNSDefParseXML(def->name, dnsNode, ctxt, &def->dns) < 0) {
goto error; goto error;
} }
virtPortNode = virXPathNode("./virtualport", ctxt); virtPortNode = virXPathNode("./virtualport", ctxt);
...@@ -1684,7 +1752,7 @@ virNetworkDNSDefFormat(virBufferPtr buf, ...@@ -1684,7 +1752,7 @@ virNetworkDNSDefFormat(virBufferPtr buf,
int result = 0; int result = 0;
int i; int i;
if (def == NULL) if (!(def->nhosts || def->nsrvs || def->ntxts))
goto out; goto out;
virBufferAddLit(buf, "<dns>\n"); virBufferAddLit(buf, "<dns>\n");
...@@ -1959,7 +2027,7 @@ char *virNetworkDefFormat(const virNetworkDefPtr def, unsigned int flags) ...@@ -1959,7 +2027,7 @@ char *virNetworkDefFormat(const virNetworkDefPtr def, unsigned int flags)
if (def->domain) if (def->domain)
virBufferAsprintf(&buf, "<domain name='%s'/>\n", def->domain); virBufferAsprintf(&buf, "<domain name='%s'/>\n", def->domain);
if (virNetworkDNSDefFormat(&buf, def->dns) < 0) if (virNetworkDNSDefFormat(&buf, &def->dns) < 0)
goto error; goto error;
if (virNetDevVlanFormat(&def->vlan, &buf) < 0) if (virNetDevVlanFormat(&def->vlan, &buf) < 0)
......
...@@ -90,9 +90,9 @@ struct _virNetworkDNSSrvDef { ...@@ -90,9 +90,9 @@ struct _virNetworkDNSSrvDef {
char *service; char *service;
char *protocol; char *protocol;
char *target; char *target;
int port; unsigned int port;
int priority; unsigned int priority;
int weight; unsigned int weight;
}; };
typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef; typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef;
...@@ -206,7 +206,7 @@ struct _virNetworkDef { ...@@ -206,7 +206,7 @@ struct _virNetworkDef {
size_t nips; size_t nips;
virNetworkIpDefPtr ips; /* ptr to array of IP addresses on this network */ virNetworkIpDefPtr ips; /* ptr to array of IP addresses on this network */
virNetworkDNSDefPtr dns; /* ptr to dns related configuration */ virNetworkDNSDef dns; /* dns related configuration */
virNetDevVPortProfilePtr virtPortProfile; virNetDevVPortProfilePtr virtPortProfile;
size_t nPortGroups; size_t nPortGroups;
......
...@@ -608,6 +608,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network, ...@@ -608,6 +608,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
char *recordPort = NULL; char *recordPort = NULL;
char *recordWeight = NULL; char *recordWeight = NULL;
char *recordPriority = NULL; char *recordPriority = NULL;
virNetworkDNSDefPtr dns = &network->def->dns;
virNetworkIpDefPtr tmpipdef; virNetworkIpDefPtr tmpipdef;
/* /*
...@@ -715,55 +716,50 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network, ...@@ -715,55 +716,50 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
"--no-resolv", NULL); "--no-resolv", NULL);
} }
if (network->def->dns != NULL) { for (ii = 0; ii < dns->ntxts; ii++) {
virNetworkDNSDefPtr dns = network->def->dns; virCommandAddArgFormat(cmd, "--txt-record=%s,%s",
int i; dns->txts[ii].name,
dns->txts[ii].value);
for (i = 0; i < dns->ntxts; i++) { }
virCommandAddArgFormat(cmd, "--txt-record=%s,%s",
dns->txts[i].name,
dns->txts[i].value);
}
for (i = 0; i < dns->nsrvs; i++) { for (ii = 0; ii < dns->nsrvs; ii++) {
if (dns->srvs[i].service && dns->srvs[i].protocol) { if (dns->srvs[ii].service && dns->srvs[ii].protocol) {
if (dns->srvs[i].port) { if (dns->srvs[ii].port) {
if (virAsprintf(&recordPort, "%d", dns->srvs[i].port) < 0) { if (virAsprintf(&recordPort, "%d", dns->srvs[ii].port) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
}
}
if (dns->srvs[i].priority) {
if (virAsprintf(&recordPriority, "%d", dns->srvs[i].priority) < 0) {
virReportOOMError();
goto cleanup;
}
} }
if (dns->srvs[i].weight) { }
if (virAsprintf(&recordWeight, "%d", dns->srvs[i].weight) < 0) { if (dns->srvs[ii].priority) {
virReportOOMError(); if (virAsprintf(&recordPriority, "%d", dns->srvs[ii].priority) < 0) {
goto cleanup; virReportOOMError();
} goto cleanup;
} }
}
if (virAsprintf(&record, "%s.%s.%s,%s,%s,%s,%s", if (dns->srvs[ii].weight) {
dns->srvs[i].service, if (virAsprintf(&recordWeight, "%d", dns->srvs[ii].weight) < 0) {
dns->srvs[i].protocol,
dns->srvs[i].domain ? dns->srvs[i].domain : "",
dns->srvs[i].target ? dns->srvs[i].target : "",
recordPort ? recordPort : "",
recordPriority ? recordPriority : "",
recordWeight ? recordWeight : "") < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
}
virCommandAddArgPair(cmd, "--srv-host", record); if (virAsprintf(&record, "%s.%s.%s,%s,%s,%s,%s",
VIR_FREE(record); dns->srvs[ii].service,
VIR_FREE(recordPort); dns->srvs[ii].protocol,
VIR_FREE(recordWeight); dns->srvs[ii].domain ? dns->srvs[ii].domain : "",
VIR_FREE(recordPriority); dns->srvs[ii].target ? dns->srvs[ii].target : "",
recordPort ? recordPort : "",
recordPriority ? recordPriority : "",
recordWeight ? recordWeight : "") < 0) {
virReportOOMError();
goto cleanup;
} }
virCommandAddArgPair(cmd, "--srv-host", record);
VIR_FREE(record);
VIR_FREE(recordPort);
VIR_FREE(recordWeight);
VIR_FREE(recordPriority);
} }
} }
...@@ -813,9 +809,9 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network, ...@@ -813,9 +809,9 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
/* add domain to any non-qualified hostnames in /etc/hosts or addn-hosts */ /* add domain to any non-qualified hostnames in /etc/hosts or addn-hosts */
if (network->def->domain) if (network->def->domain)
virCommandAddArg(cmd, "--expand-hosts"); virCommandAddArg(cmd, "--expand-hosts");
if (networkBuildDnsmasqHostsfile(dctx, ipdef, network->def->dns) < 0) if (networkBuildDnsmasqHostsfile(dctx, ipdef, &network->def->dns) < 0)
goto cleanup; goto cleanup;
/* Even if there are currently no static hosts, if we're /* Even if there are currently no static hosts, if we're
...@@ -965,7 +961,7 @@ networkStartDhcpDaemon(struct network_driver *driver, ...@@ -965,7 +961,7 @@ networkStartDhcpDaemon(struct network_driver *driver,
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET) && if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET) &&
(ipdef->nranges || ipdef->nhosts)) { (ipdef->nranges || ipdef->nhosts)) {
if (networkBuildDnsmasqHostsfile(dctx, ipdef, if (networkBuildDnsmasqHostsfile(dctx, ipdef,
network->def->dns) < 0) &network->def->dns) < 0)
goto cleanup; goto cleanup;
break; break;
...@@ -1040,7 +1036,7 @@ networkRefreshDhcpDaemon(struct network_driver *driver, ...@@ -1040,7 +1036,7 @@ networkRefreshDhcpDaemon(struct network_driver *driver,
if (!(dctx = dnsmasqContextNew(network->def->name, DNSMASQ_STATE_DIR))) if (!(dctx = dnsmasqContextNew(network->def->name, DNSMASQ_STATE_DIR)))
goto cleanup; goto cleanup;
if (networkBuildDnsmasqHostsfile(dctx, ipdef, network->def->dns) < 0) if (networkBuildDnsmasqHostsfile(dctx, ipdef, &network->def->dns) < 0)
goto cleanup; goto cleanup;
if ((ret = dnsmasqSave(dctx)) < 0) if ((ret = dnsmasqSave(dctx)) < 0)
...@@ -2763,8 +2759,7 @@ networkValidate(struct network_driver *driver, ...@@ -2763,8 +2759,7 @@ networkValidate(struct network_driver *driver,
virNetworkForwardTypeToString(def->forwardType)); virNetworkForwardTypeToString(def->forwardType));
return -1; return -1;
} }
if (def->dns && if (def->dns.ntxts || def->dns.nhosts || def->dns.nsrvs) {
(def->dns->ntxts || def->dns->nhosts || def->dns->nsrvs)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported <dns> element in network %s " _("Unsupported <dns> element in network %s "
"with forward mode='%s'"), "with forward mode='%s'"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册