conf: rename network dns host/srv/txt arrays

This shortens the name of the structs for srv and txt, and their
instances in virNetworkDNSDef, to be more compact and uniform with the
naming of the dns host array. It also changes the type of ntxts, etc
from unsigned int to size_t, so that they can be used directly as args
to VIR_*_ELEMENT.
This commit is contained in:
Laine Stump 2012-11-11 18:59:28 -05:00
parent 2dc5839a16
commit 8b7d187417
3 changed files with 84 additions and 82 deletions

View File

@ -136,13 +136,13 @@ static void virNetworkIpDefClear(virNetworkIpDefPtr def)
static void virNetworkDNSDefFree(virNetworkDNSDefPtr def) static void virNetworkDNSDefFree(virNetworkDNSDefPtr def)
{ {
if (def) { if (def) {
if (def->txtrecords) { if (def->txts) {
while (def->ntxtrecords--) { while (def->ntxts--) {
VIR_FREE(def->txtrecords[def->ntxtrecords].name); VIR_FREE(def->txts[def->ntxts].name);
VIR_FREE(def->txtrecords[def->ntxtrecords].value); VIR_FREE(def->txts[def->ntxts].value);
} }
} }
VIR_FREE(def->txtrecords); VIR_FREE(def->txts);
if (def->nhosts) { if (def->nhosts) {
while (def->nhosts--) { while (def->nhosts--) {
while (def->hosts[def->nhosts].nnames--) while (def->hosts[def->nhosts].nnames--)
@ -151,15 +151,15 @@ static void virNetworkDNSDefFree(virNetworkDNSDefPtr def)
} }
} }
VIR_FREE(def->hosts); VIR_FREE(def->hosts);
if (def->nsrvrecords) { if (def->nsrvs) {
while (def->nsrvrecords--) { while (def->nsrvs--) {
VIR_FREE(def->srvrecords[def->nsrvrecords].domain); VIR_FREE(def->srvs[def->nsrvs].domain);
VIR_FREE(def->srvrecords[def->nsrvrecords].service); VIR_FREE(def->srvs[def->nsrvs].service);
VIR_FREE(def->srvrecords[def->nsrvrecords].protocol); VIR_FREE(def->srvs[def->nsrvs].protocol);
VIR_FREE(def->srvrecords[def->nsrvrecords].target); VIR_FREE(def->srvs[def->nsrvs].target);
} }
} }
VIR_FREE(def->srvrecords); VIR_FREE(def->srvs);
VIR_FREE(def); VIR_FREE(def);
} }
} }
@ -883,18 +883,18 @@ virNetworkDNSSrvDefParseXML(virNetworkDNSDefPtr def,
goto error; goto error;
} }
if (VIR_REALLOC_N(def->srvrecords, def->nsrvrecords + 1) < 0) { if (VIR_REALLOC_N(def->srvs, def->nsrvs + 1) < 0) {
virReportOOMError(); virReportOOMError();
goto error; goto error;
} }
def->srvrecords[def->nsrvrecords].service = service; def->srvs[def->nsrvs].service = service;
def->srvrecords[def->nsrvrecords].protocol = protocol; def->srvs[def->nsrvs].protocol = protocol;
def->srvrecords[def->nsrvrecords].domain = NULL; def->srvs[def->nsrvs].domain = NULL;
def->srvrecords[def->nsrvrecords].target = NULL; def->srvs[def->nsrvs].target = NULL;
def->srvrecords[def->nsrvrecords].port = 0; def->srvs[def->nsrvs].port = 0;
def->srvrecords[def->nsrvrecords].priority = 0; def->srvs[def->nsrvs].priority = 0;
def->srvrecords[def->nsrvrecords].weight = 0; def->srvs[def->nsrvs].weight = 0;
/* Following attributes are optional but we had to make sure they're NULL above */ /* Following attributes are optional but we had to make sure they're NULL above */
if ((target = virXMLPropString(cur, "target")) && (domain = virXMLPropString(cur, "domain"))) { if ((target = virXMLPropString(cur, "target")) && (domain = virXMLPropString(cur, "domain"))) {
@ -902,23 +902,23 @@ virNetworkDNSSrvDefParseXML(virNetworkDNSDefPtr def,
ctxt->node = cur; ctxt->node = cur;
if (virXPathInt("string(./@port)", ctxt, &port)) if (virXPathInt("string(./@port)", ctxt, &port))
def->srvrecords[def->nsrvrecords].port = port; def->srvs[def->nsrvs].port = port;
if (virXPathInt("string(./@priority)", ctxt, &priority)) if (virXPathInt("string(./@priority)", ctxt, &priority))
def->srvrecords[def->nsrvrecords].priority = priority; def->srvs[def->nsrvs].priority = priority;
if (virXPathInt("string(./@weight)", ctxt, &weight)) if (virXPathInt("string(./@weight)", ctxt, &weight))
def->srvrecords[def->nsrvrecords].weight = weight; def->srvs[def->nsrvs].weight = weight;
ctxt->node = save_ctxt; ctxt->node = save_ctxt;
def->srvrecords[def->nsrvrecords].domain = domain; def->srvs[def->nsrvs].domain = domain;
def->srvrecords[def->nsrvrecords].target = target; def->srvs[def->nsrvs].target = target;
def->srvrecords[def->nsrvrecords].port = port; def->srvs[def->nsrvs].port = port;
def->srvrecords[def->nsrvrecords].priority = priority; def->srvs[def->nsrvs].priority = priority;
def->srvrecords[def->nsrvrecords].weight = weight; def->srvs[def->nsrvs].weight = weight;
} }
def->nsrvrecords++; def->nsrvs++;
goto cleanup; goto cleanup;
@ -971,14 +971,14 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
goto error; goto error;
} }
if (VIR_REALLOC_N(def->txtrecords, def->ntxtrecords + 1) < 0) { if (VIR_REALLOC_N(def->txts, def->ntxts + 1) < 0) {
virReportOOMError(); virReportOOMError();
goto error; goto error;
} }
def->txtrecords[def->ntxtrecords].name = name; def->txts[def->ntxts].name = name;
def->txtrecords[def->ntxtrecords].value = value; def->txts[def->ntxts].value = value;
def->ntxtrecords++; def->ntxts++;
name = NULL; name = NULL;
value = NULL; value = NULL;
} else if (cur->type == XML_ELEMENT_NODE && } else if (cur->type == XML_ELEMENT_NODE &&
@ -1690,28 +1690,28 @@ virNetworkDNSDefFormat(virBufferPtr buf,
virBufferAddLit(buf, "<dns>\n"); virBufferAddLit(buf, "<dns>\n");
virBufferAdjustIndent(buf, 2); virBufferAdjustIndent(buf, 2);
for (i = 0 ; i < def->ntxtrecords ; i++) { for (i = 0 ; i < def->ntxts ; i++) {
virBufferAsprintf(buf, "<txt name='%s' value='%s' />\n", virBufferAsprintf(buf, "<txt name='%s' value='%s' />\n",
def->txtrecords[i].name, def->txts[i].name,
def->txtrecords[i].value); def->txts[i].value);
} }
for (i = 0 ; i < def->nsrvrecords ; i++) { for (i = 0 ; i < def->nsrvs ; i++) {
if (def->srvrecords[i].service && def->srvrecords[i].protocol) { if (def->srvs[i].service && def->srvs[i].protocol) {
virBufferAsprintf(buf, "<srv service='%s' protocol='%s'", virBufferAsprintf(buf, "<srv service='%s' protocol='%s'",
def->srvrecords[i].service, def->srvs[i].service,
def->srvrecords[i].protocol); def->srvs[i].protocol);
if (def->srvrecords[i].domain) if (def->srvs[i].domain)
virBufferAsprintf(buf, " domain='%s'", def->srvrecords[i].domain); virBufferAsprintf(buf, " domain='%s'", def->srvs[i].domain);
if (def->srvrecords[i].target) if (def->srvs[i].target)
virBufferAsprintf(buf, " target='%s'", def->srvrecords[i].target); virBufferAsprintf(buf, " target='%s'", def->srvs[i].target);
if (def->srvrecords[i].port) if (def->srvs[i].port)
virBufferAsprintf(buf, " port='%d'", def->srvrecords[i].port); virBufferAsprintf(buf, " port='%d'", def->srvs[i].port);
if (def->srvrecords[i].priority) if (def->srvs[i].priority)
virBufferAsprintf(buf, " priority='%d'", def->srvrecords[i].priority); virBufferAsprintf(buf, " priority='%d'", def->srvs[i].priority);
if (def->srvrecords[i].weight) if (def->srvs[i].weight)
virBufferAsprintf(buf, " weight='%d'", def->srvrecords[i].weight); virBufferAsprintf(buf, " weight='%d'", def->srvs[i].weight);
virBufferAsprintf(buf, "/>\n"); virBufferAsprintf(buf, "/>\n");
} }

View File

@ -76,16 +76,16 @@ struct _virNetworkDHCPHostDef {
virSocketAddr ip; virSocketAddr ip;
}; };
typedef struct _virNetworkDNSTxtRecordsDef virNetworkDNSTxtRecordsDef; typedef struct _virNetworkDNSTxtDef virNetworkDNSTxtDef;
typedef virNetworkDNSTxtRecordsDef *virNetworkDNSTxtRecordsDefPtr; typedef virNetworkDNSTxtDef *virNetworkDNSTxtDefPtr;
struct _virNetworkDNSTxtRecordsDef { struct _virNetworkDNSTxtDef {
char *name; char *name;
char *value; char *value;
}; };
typedef struct _virNetworkDNSSrvRecordsDef virNetworkDNSSrvRecordsDef; typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef;
typedef virNetworkDNSSrvRecordsDef *virNetworkDNSSrvRecordsDefPtr; typedef virNetworkDNSSrvDef *virNetworkDNSSrvDefPtr;
struct _virNetworkDNSSrvRecordsDef { struct _virNetworkDNSSrvDef {
char *domain; char *domain;
char *service; char *service;
char *protocol; char *protocol;
@ -95,21 +95,23 @@ struct _virNetworkDNSSrvRecordsDef {
int weight; int weight;
}; };
struct _virNetworkDNSHostsDef { typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef;
typedef virNetworkDNSHostDef *virNetworkDNSHostDefPtr;
struct _virNetworkDNSHostDef {
virSocketAddr ip; virSocketAddr ip;
int nnames; int nnames;
char **names; char **names;
}; };
typedef struct _virNetworkDNSHostsDef *virNetworkDNSHostsDefPtr; typedef struct _virNetworkDNSDef virNetworkDNSDef;
typedef virNetworkDNSDef *virNetworkDNSDefPtr;
struct _virNetworkDNSDef { struct _virNetworkDNSDef {
unsigned int ntxtrecords; size_t ntxts;
virNetworkDNSTxtRecordsDefPtr txtrecords; virNetworkDNSTxtDefPtr txts;
unsigned int nhosts; size_t nhosts;
virNetworkDNSHostsDefPtr hosts; virNetworkDNSHostDefPtr hosts;
unsigned int nsrvrecords; size_t nsrvs;
virNetworkDNSSrvRecordsDefPtr srvrecords; virNetworkDNSSrvDefPtr srvs;
}; };
typedef struct _virNetworkDNSDef *virNetworkDNSDefPtr; typedef struct _virNetworkDNSDef *virNetworkDNSDefPtr;

View File

@ -580,7 +580,7 @@ networkBuildDnsmasqHostsfile(dnsmasqContext *dctx,
if (dnsdef) { if (dnsdef) {
for (i = 0; i < dnsdef->nhosts; i++) { for (i = 0; i < dnsdef->nhosts; i++) {
virNetworkDNSHostsDefPtr host = &(dnsdef->hosts[i]); virNetworkDNSHostDefPtr host = &(dnsdef->hosts[i]);
if (VIR_SOCKET_ADDR_VALID(&host->ip)) { if (VIR_SOCKET_ADDR_VALID(&host->ip)) {
for (j = 0; j < host->nnames; j++) for (j = 0; j < host->nnames; j++)
if (dnsmasqAddHost(dctx, &host->ip, host->names[j]) < 0) if (dnsmasqAddHost(dctx, &host->ip, host->names[j]) < 0)
@ -719,38 +719,38 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
virNetworkDNSDefPtr dns = network->def->dns; virNetworkDNSDefPtr dns = network->def->dns;
int i; int i;
for (i = 0; i < dns->ntxtrecords; i++) { for (i = 0; i < dns->ntxts; i++) {
virCommandAddArgFormat(cmd, "--txt-record=%s,%s", virCommandAddArgFormat(cmd, "--txt-record=%s,%s",
dns->txtrecords[i].name, dns->txts[i].name,
dns->txtrecords[i].value); dns->txts[i].value);
} }
for (i = 0; i < dns->nsrvrecords; i++) { for (i = 0; i < dns->nsrvs; i++) {
if (dns->srvrecords[i].service && dns->srvrecords[i].protocol) { if (dns->srvs[i].service && dns->srvs[i].protocol) {
if (dns->srvrecords[i].port) { if (dns->srvs[i].port) {
if (virAsprintf(&recordPort, "%d", dns->srvrecords[i].port) < 0) { if (virAsprintf(&recordPort, "%d", dns->srvs[i].port) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
} }
if (dns->srvrecords[i].priority) { if (dns->srvs[i].priority) {
if (virAsprintf(&recordPriority, "%d", dns->srvrecords[i].priority) < 0) { if (virAsprintf(&recordPriority, "%d", dns->srvs[i].priority) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
} }
if (dns->srvrecords[i].weight) { if (dns->srvs[i].weight) {
if (virAsprintf(&recordWeight, "%d", dns->srvrecords[i].weight) < 0) { if (virAsprintf(&recordWeight, "%d", dns->srvs[i].weight) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
} }
if (virAsprintf(&record, "%s.%s.%s,%s,%s,%s,%s", if (virAsprintf(&record, "%s.%s.%s,%s,%s,%s,%s",
dns->srvrecords[i].service, dns->srvs[i].service,
dns->srvrecords[i].protocol, dns->srvs[i].protocol,
dns->srvrecords[i].domain ? dns->srvrecords[i].domain : "", dns->srvs[i].domain ? dns->srvs[i].domain : "",
dns->srvrecords[i].target ? dns->srvrecords[i].target : "", dns->srvs[i].target ? dns->srvs[i].target : "",
recordPort ? recordPort : "", recordPort ? recordPort : "",
recordPriority ? recordPriority : "", recordPriority ? recordPriority : "",
recordWeight ? recordWeight : "") < 0) { recordWeight ? recordWeight : "") < 0) {
@ -2764,7 +2764,7 @@ networkValidate(struct network_driver *driver,
return -1; return -1;
} }
if (def->dns && if (def->dns &&
(def->dns->ntxtrecords || def->dns->nhosts || def->dns->nsrvrecords)) { (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'"),