[libvirt] [PATCH 0/2] Network: Add TXT record and hosts support for DNS on virtual network

Hi, this is the patch to introduce the TXT record support for the DNS service on the virtual network. This can be defined using the txt-record subelement in the dns element of the network XML description. First patch is adding TXT record support to the DNS service on the virtual network and the second patch is adding support for defining hosts for the DNS service. The new definition syntax is: <dns> <txt-record name="example name" value="example value" /> <host ip='192.168.122.1'> <hostname>gateway</hostname> <hostname>host</hostname> </host> </dns> Where multiple host elements can be defined to put the aliases for specified IP addresses. The patch series has been tested for the configuration and it was working fine and also RelaxNG schema with the tests have been both altered to add test cases to test those patches. Both of the patches passed make, syntax checking and all the tests. Michal Signed-off-by: Michal Novotny <minovotn@redhat.com> Michal Novotny (2): Network: Add TXT record support for virtual DNS service Network: Add support for DNS hosts definition docs/formatnetwork.html.in | 37 +++++- docs/schemas/network.rng | 20 +++ src/conf/network_conf.c | 148 ++++++++++++++++++++ src/conf/network_conf.h | 26 ++++ src/network/bridge_driver.c | 93 ++++++++++++ tests/networkxml2xmlin/nat-network-dns-hosts.xml | 27 ++++ .../nat-network-dns-txt-record.xml | 24 +++ tests/networkxml2xmlout/nat-network-dns-hosts.xml | 27 ++++ .../nat-network-dns-txt-record.xml | 24 +++ tests/networkxml2xmltest.c | 2 + 10 files changed, 427 insertions(+), 1 deletions(-) create mode 100644 tests/networkxml2xmlin/nat-network-dns-hosts.xml create mode 100644 tests/networkxml2xmlin/nat-network-dns-txt-record.xml create mode 100644 tests/networkxml2xmlout/nat-network-dns-hosts.xml create mode 100644 tests/networkxml2xmlout/nat-network-dns-txt-record.xml -- 1.7.3.2

Hi, this is the patch to add support for adding TXT records to the DNS service running on the virtual network. This has been tested on Fedora-14 i386 box and tests are also added to RelaxNG schema and test XML files. It's been tested and checked/syntax-checked and everything was working fine. Also, the formatnetwork HTML document has been altered to include those information about new DNS tag. Michal Signed-off-by: Michal Novotny <minovotn@redhat.com> --- docs/formatnetwork.html.in | 26 ++++++++- docs/schemas/network.rng | 12 ++++ src/conf/network_conf.c | 65 ++++++++++++++++++++ src/conf/network_conf.h | 16 +++++ src/network/bridge_driver.c | 27 ++++++++ .../nat-network-dns-txt-record.xml | 24 +++++++ .../nat-network-dns-txt-record.xml | 24 +++++++ tests/networkxml2xmltest.c | 1 + 8 files changed, 194 insertions(+), 1 deletions(-) create mode 100644 tests/networkxml2xmlin/nat-network-dns-txt-record.xml create mode 100644 tests/networkxml2xmlout/nat-network-dns-txt-record.xml diff --git a/docs/formatnetwork.html.in b/docs/formatnetwork.html.in index c6969eb..2d76d3d 100644 --- a/docs/formatnetwork.html.in +++ b/docs/formatnetwork.html.in @@ -108,7 +108,10 @@ The final set of elements define the addresses (IPv4 and/or IPv6, as well as MAC) to be assigned to the bridge device associated with the virtual network, and optionally enable DHCP - services. + services. The network creation also supports the TXT record in + the DNS to expose some information to the guest using this + record. This feature could be used in the similar way like DKIM + uses TXT records of DNS to expose public key. </p> <pre> @@ -120,6 +123,9 @@ <host mac="00:16:3e:77:e2:ed" name="foo.example.com" ip="192.168.122.10" /> <host mac="00:16:3e:3e:a9:1a" name="bar.example.com" ip="192.168.122.11" /> </dhcp> + <dns> + <txt-record name="example name" value="example value" /> + </dns> </ip> </network></pre> @@ -199,6 +205,24 @@ element is used. The BOOTP options currently have to be the same for all address ranges and statically assigned addresses.<span class="since">Since 0.7.1 (<code>server</code> since 0.7.3).</span> + </dd><dt><code>dns</code></dt><dd>Also within the <code>ip</code> element + there is an optional <code>dns</code> element. The presence of this element + enables configuration and exposal of records in the DNS service on the + virtual network. It will further contain one or more <code>txt-record</code> + elements. The <code>dns</code> element is supported for both IPv4 and IPv6 + networks. <span class="since">Since 0.9.0</span> + </dd> + <dt><code>txt-record</code></dt> + <dd>The <code>txt-record</code> element is the definition of TXT record for the + DNS service. There are two attributes that both have to be used for the TXT + record definition: <code>name</code> and <code>value</code>. The <code>name + </code>attribute doesn't support commas in it's value and therefore you should + avoid using them since they are automatically replaced by spaces, e.g. <code> + name, clarification</code> value of the <code>name</code> tag will be replaced + to be <code>name clarification</code> instead. This rule doesn't apply to the + record <code>value</code> contents since it supports multiple values separated + by commas. + <span class="since">Since 0.9.0</span> </dd> </dl> diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng index 6d01b06..e27dace 100644 --- a/docs/schemas/network.rng +++ b/docs/schemas/network.rng @@ -136,6 +136,18 @@ </optional> </element> </optional> + <optional> + <!-- Define the DNS related elements like TXT records + and other features --> + <element name="dns"> + <zeroOrMore> + <element name="txt-record"> + <attribute name="name"><text/></attribute> + <attribute name="value"><text/></attribute> + </element> + </zeroOrMore> + </element> + </optional> </element> </zeroOrMore> </interleave> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index dcab9de..145ae20 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -435,6 +435,54 @@ virNetworkDHCPRangeDefParseXML(const char *networkName, } static int +virNetworkDNSDefParseXML(virNetworkIpDefPtr def, + xmlNodePtr node) +{ + + xmlNodePtr cur; + int result = -1; + + if (VIR_ALLOC(def->dns)) + goto oom_error; + + cur = node->children; + while (cur != NULL) { + if (cur->type == XML_ELEMENT_NODE && + xmlStrEqual(cur->name, BAD_CAST "txt-record")) { + char *name, *value; + + if (!(name = virXMLPropString(cur, "name"))) { + cur = cur->next; + continue; + } + if (!(value = virXMLPropString(cur, "value"))) { + VIR_FREE(name); + cur = cur->next; + continue; + } + + if (VIR_REALLOC_N(def->dns->txtrecords, def->dns->ntxtrecords + 1) < 0) + goto oom_error; + + def->dns->txtrecords[def->dns->ntxtrecords].name = strdup(name); + def->dns->txtrecords[def->dns->ntxtrecords].value = strdup(value); + def->dns->ntxtrecords++; + + VIR_FREE(name); + VIR_FREE(value); + } + + cur = cur->next; + } + + return 0; + +oom_error: + virReportOOMError(); + return result; +} + +static int virNetworkIPParseXML(const char *networkName, virNetworkIpDefPtr def, xmlNodePtr node, @@ -550,6 +598,12 @@ virNetworkIPParseXML(const char *networkName, goto error; } else if (cur->type == XML_ELEMENT_NODE && + xmlStrEqual(cur->name, BAD_CAST "dns")) { + result = virNetworkDNSDefParseXML(def, cur); + if (result) + goto error; + + } else if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "tftp")) { char *root; @@ -828,6 +882,17 @@ virNetworkIpDefFormat(virBufferPtr buf, virBufferAddLit(buf, " </dhcp>\n"); } + if ((def->dns != NULL) && (def->dns->ntxtrecords)) { + int ii; + + virBufferAddLit(buf, " <dns>\n"); + for (ii = 0 ; ii < def->dns->ntxtrecords ; ii++) { + virBufferVSprintf(buf, " <txt-record name='%s' value='%s' />\n", + def->dns->txtrecords[ii].name, + def->dns->txtrecords[ii].value); + } + virBufferAddLit(buf, " </dns>\n"); + } virBufferAddLit(buf, " </ip>\n"); diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 281124b..5f47595 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -57,6 +57,20 @@ struct _virNetworkDHCPHostDef { virSocketAddr ip; }; +typedef struct _virNetworkDNSTxtRecordsDef virNetworkDNSTxtRecordsDef; +typedef virNetworkDNSTxtRecordsDef *virNetworkDNSTxtRecordsDefPtr; +struct _virNetworkDNSTxtRecordsDef { + char *name; + char *value; +}; + +struct virNetworkDNSDef { + unsigned int ntxtrecords; + virNetworkDNSTxtRecordsDefPtr txtrecords; +} virNetworkDNSDef; + +typedef struct virNetworkDNSDef *virNetworkDNSDefPtr; + typedef struct _virNetworkIpDef virNetworkIpDef; typedef virNetworkIpDef *virNetworkIpDefPtr; struct _virNetworkIpDef { @@ -75,6 +89,8 @@ struct _virNetworkIpDef { unsigned int nranges; /* Zero or more dhcp ranges */ virNetworkDHCPRangeDefPtr ranges; + virNetworkDNSDefPtr dns; /* DNS related settings for DNSMasq */ + unsigned int nhosts; /* Zero or more dhcp hosts */ virNetworkDHCPHostDefPtr hosts; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index ea2bfd4..5d901ff 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -442,6 +442,18 @@ networkSaveDnsmasqHostsfile(virNetworkIpDefPtr ipdef, return 0; } +static char * +replace_all(char *input, int chr1, int chr2) +{ + char *tmp; + char *out; + + out = strdup(input); + while ((tmp = strchr(out, chr1)) != NULL) + out[ strlen(input) - strlen(tmp) ] = chr2; + + return out; +} static int networkBuildDnsmasqArgv(virNetworkObjPtr network, @@ -497,6 +509,21 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network, if (network->def->forwardType == VIR_NETWORK_FORWARD_NONE) virCommandAddArg(cmd, "--dhcp-option=3"); + if (ipdef->dns != NULL) { + int i; + + for (i = 0; i < ipdef->dns->ntxtrecords; i++) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferVSprintf(&buf, "%s,%s", + replace_all(ipdef->dns->txtrecords[i].name, ',', ' '), + ipdef->dns->txtrecords[i].value); + + virCommandAddArgPair(cmd, "--txt-record", virBufferContentAndReset(&buf)); + VIR_FREE(buf); + } + } + /* * --interface does not actually work with dnsmasq < 2.47, * due to DAD for ipv6 addresses on the interface. diff --git a/tests/networkxml2xmlin/nat-network-dns-txt-record.xml b/tests/networkxml2xmlin/nat-network-dns-txt-record.xml new file mode 100644 index 0000000..d3cdbd5 --- /dev/null +++ b/tests/networkxml2xmlin/nat-network-dns-txt-record.xml @@ -0,0 +1,24 @@ +<network> + <name>default</name> + <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid> + <forward dev='eth1' mode='nat'/> + <bridge name='virbr0' stp='on' delay='0' /> + <ip address='192.168.122.1' netmask='255.255.255.0'> + <dhcp> + <range start='192.168.122.2' end='192.168.122.254' /> + <host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10' /> + <host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11' /> + </dhcp> + <dns> + <txt-record name='example name' value='example value' /> + </dns> + </ip> + <ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'> + </ip> + <ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'> + </ip> + <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'> + </ip> + <ip family='ipv4' address='10.24.10.1'> + </ip> +</network> diff --git a/tests/networkxml2xmlout/nat-network-dns-txt-record.xml b/tests/networkxml2xmlout/nat-network-dns-txt-record.xml new file mode 100644 index 0000000..d3cdbd5 --- /dev/null +++ b/tests/networkxml2xmlout/nat-network-dns-txt-record.xml @@ -0,0 +1,24 @@ +<network> + <name>default</name> + <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid> + <forward dev='eth1' mode='nat'/> + <bridge name='virbr0' stp='on' delay='0' /> + <ip address='192.168.122.1' netmask='255.255.255.0'> + <dhcp> + <range start='192.168.122.2' end='192.168.122.254' /> + <host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10' /> + <host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11' /> + </dhcp> + <dns> + <txt-record name='example name' value='example value' /> + </dns> + </ip> + <ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'> + </ip> + <ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'> + </ip> + <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'> + </ip> + <ip family='ipv4' address='10.24.10.1'> + </ip> +</network> diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index 7805548..beb00ef 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -90,6 +90,7 @@ mymain(int argc, char **argv) DO_TEST("nat-network"); DO_TEST("netboot-network"); DO_TEST("netboot-proxy-network"); + DO_TEST("nat-network-dns-txt-record"); return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); } -- 1.7.3.2

On 03/30/2011 02:57 PM, Michal Novotny wrote:
The<code>name +</code>attribute doesn't support commas in it's value and therefore you should + avoid using them since they are automatically replaced by spaces
No, names with commas should be rejected. Paolo

Hi, this is the patch to add support for defining the hosts into the DNS service on the virtual network. You can define the host IP address and the aliases for the IP address. The DNS hosts record can be defined in the XML file as the host element in this form: <host ip='192.168.122.1'> <hostname>example1</hostname> <hostname>example2</hostname> </host> This definition defines aliases example1 and example2 to the IP address of 192.168.122.1. Michal Signed-off-by: Michal Novotny <minovotn@redhat.com> --- docs/formatnetwork.html.in | 11 +++ docs/schemas/network.rng | 8 ++ src/conf/network_conf.c | 97 +++++++++++++++++++-- src/conf/network_conf.h | 10 ++ src/network/bridge_driver.c | 66 ++++++++++++++ tests/networkxml2xmlin/nat-network-dns-hosts.xml | 27 ++++++ tests/networkxml2xmlout/nat-network-dns-hosts.xml | 27 ++++++ tests/networkxml2xmltest.c | 1 + 8 files changed, 240 insertions(+), 7 deletions(-) create mode 100644 tests/networkxml2xmlin/nat-network-dns-hosts.xml create mode 100644 tests/networkxml2xmlout/nat-network-dns-hosts.xml diff --git a/docs/formatnetwork.html.in b/docs/formatnetwork.html.in index 2d76d3d..9baf2ee 100644 --- a/docs/formatnetwork.html.in +++ b/docs/formatnetwork.html.in @@ -125,6 +125,10 @@ </dhcp> <dns> <txt-record name="example name" value="example value" /> + <host ip='192.168.122.1'> + <hostname>gateway</hostname> + <hostname>host</hostname> + </host> </dns;> </ip> </network></pre> @@ -224,6 +228,13 @@ by commas. <span class="since">Since 0.9.0</span> </dd> + <dt><code>host</code></dt> + <dd>The <code>host</code> element is the definition of DNS hosts to be passed + to the DNS service. The IP address is identified by the <code>ip</code> attribute + and the names for the IP addresses are identified in the <code>hostname</code> + subelements of the <code>host</code> element. + <span class="since">Since 0.9.0</span> + </dd> </dl> <h2><a name="examples">Example configuration</a></h2> diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng index e27dace..d09801f 100644 --- a/docs/schemas/network.rng +++ b/docs/schemas/network.rng @@ -146,6 +146,14 @@ <attribute name="value"><text/></attribute> </element> </zeroOrMore> + <zeroOrMore> + <element name="host"> + <attribute name="ip"><ref name="ipv4-addr"/></attribute> + <zeroOrMore> + <element name="hostname"><text/></element> + </zeroOrMore> + </element> + </zeroOrMore> </element> </optional> </element> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 145ae20..a0d223e 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -435,6 +435,61 @@ virNetworkDHCPRangeDefParseXML(const char *networkName, } static int +virNetworkDNSHostsDefParseXML(virNetworkIpDefPtr def, + xmlNodePtr node, + char *ip) +{ + xmlNodePtr cur; + int result = -1; + int i = 0; + + if (def->dns->hosts == NULL) { + if (VIR_ALLOC(def->dns->hosts) < 0) + goto oom_error; + def->dns->nhosts = 0; + } + + if (VIR_REALLOC_N(def->dns->hosts, def->dns->nhosts + 1) < 0) + goto oom_error; + + i = def->dns->nhosts; + if (VIR_ALLOC(def->dns->hosts[i]) < 0) + goto oom_error; + + def->dns->hosts[i]->ip = strdup(ip); + def->dns->nhosts++; + + def->dns->hosts[i]->nhostnames = 0; + cur = node->children; + while (cur != NULL) { + if (cur->type == XML_ELEMENT_NODE && + xmlStrEqual(cur->name, BAD_CAST "hostname")) { + if (cur->children != NULL) { + char *hostname; + + hostname = strdup((char *)cur->children->content); + + if (VIR_REALLOC_N(def->dns->hosts[i]->hostnames, def->dns->hosts[i]->nhostnames + 1) < 0) + goto oom_error; + + def->dns->hosts[i]->hostnames[def->dns->hosts[i]->nhostnames] = strdup(hostname); + def->dns->hosts[i]->nhostnames++; + + VIR_FREE(hostname); + } + } + + cur = cur->next; + } + + return 0; + +oom_error: + virReportOOMError(); + return result; +} + +static int virNetworkDNSDefParseXML(virNetworkIpDefPtr def, xmlNodePtr node) { @@ -470,6 +525,17 @@ virNetworkDNSDefParseXML(virNetworkIpDefPtr def, VIR_FREE(name); VIR_FREE(value); + } else if (cur->type == XML_ELEMENT_NODE && + xmlStrEqual(cur->name, BAD_CAST "host")) { + char *ip; + + if (!(ip = virXMLPropString(cur, "ip"))) { + cur = cur->next; + continue; + } + result = virNetworkDNSHostsDefParseXML(def, cur, ip); + if (result) + goto error; } cur = cur->next; @@ -479,6 +545,7 @@ virNetworkDNSDefParseXML(virNetworkIpDefPtr def, oom_error: virReportOOMError(); +error: return result; } @@ -882,15 +949,31 @@ virNetworkIpDefFormat(virBufferPtr buf, virBufferAddLit(buf, " </dhcp>\n"); } - if ((def->dns != NULL) && (def->dns->ntxtrecords)) { - int ii; - + if (def->dns != NULL) { virBufferAddLit(buf, " <dns>\n"); - for (ii = 0 ; ii < def->dns->ntxtrecords ; ii++) { - virBufferVSprintf(buf, " <txt-record name='%s' value='%s' />\n", - def->dns->txtrecords[ii].name, - def->dns->txtrecords[ii].value); + + if (def->dns->ntxtrecords) { + int ii; + + for (ii = 0 ; ii < def->dns->ntxtrecords; ii++) { + virBufferVSprintf(buf, " <txt-record name='%s' value='%s' />\n", + def->dns->txtrecords[ii].name, + def->dns->txtrecords[ii].value); + } + } + if (def->dns->nhosts) { + int ii, j; + + for (ii = 0 ; ii < def->dns->nhosts; ii++) { + virBufferVSprintf(buf, " <host ip='%s'>\n", def->dns->hosts[ii]->ip); + for (j = 0 ; j < def->dns->hosts[ii]->nhostnames; j++) { + virBufferVSprintf(buf, " <hostname>%s</hostname>\n", + def->dns->hosts[ii]->hostnames[j]); + } + virBufferVSprintf(buf, " </host>\n"); + } } + virBufferAddLit(buf, " </dns>\n"); } diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 5f47595..f3f1381 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -64,9 +64,19 @@ struct _virNetworkDNSTxtRecordsDef { char *value; }; +struct virNetworkDNSHostsDef { + char *ip; + unsigned int nhostnames; + char **hostnames; +} virNetworkDNSHostsDef; + +typedef struct virNetworkDNSHostsDef *virNetworkDNSHostsDefPtr; + struct virNetworkDNSDef { unsigned int ntxtrecords; + unsigned int nhosts; virNetworkDNSTxtRecordsDefPtr txtrecords; + virNetworkDNSHostsDefPtr *hosts; } virNetworkDNSDef; typedef struct virNetworkDNSDef *virNetworkDNSDefPtr; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 5d901ff..392ef23 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -60,6 +60,7 @@ #include "dnsmasq.h" #include "util/network.h" #include "configmake.h" +#include "files.h" #define NETWORK_PID_DIR LOCALSTATEDIR "/run/libvirt/network" #define NETWORK_STATE_DIR LOCALSTATEDIR "/lib/libvirt/network" @@ -456,6 +457,60 @@ replace_all(char *input, int chr1, int chr2) } static int +networkDnsmasqGenHosts(const char *hostsFile, + virNetworkDNSDefPtr def) +{ + char *contents = NULL; + int fd = -1, ret = -1; + size_t towrite; + virBuffer buf = VIR_BUFFER_INITIALIZER; + int i, ii; + + if ((fd = open(hostsFile, + O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR )) < 0) { + virReportSystemError(errno, + _("cannot create hosts config file '%s'"), + hostsFile); + goto cleanup; + } + + for (i = 0; i < def->nhosts; i++) { + virBufferVSprintf(&buf, "%s", def->hosts[i]->ip); + for (ii = 0; ii < def->hosts[i]->nhostnames; ii++) + virBufferVSprintf(&buf, "\t%s", def->hosts[i]->hostnames[ii]); + virBufferVSprintf(&buf, "\n"); + } + + contents = virBufferContentAndReset(&buf); + VIR_FREE(buf); + + towrite = strlen(contents); + if (safewrite(fd, contents, towrite) < 0) { + virReportSystemError(errno, + _("cannot write hosts config file '%s'"), + hostsFile); + goto cleanup; + } + + fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + if (VIR_CLOSE(fd) < 0) { + virReportSystemError(errno, + _("cannot save hosts config file '%s'"), + hostsFile); + goto cleanup; + } + + ret = 0; + + cleanup: + VIR_FORCE_CLOSE(fd); + + return ret; +} + +static int networkBuildDnsmasqArgv(virNetworkObjPtr network, virNetworkIpDefPtr ipdef, const char *pidfile, @@ -522,6 +577,17 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network, virCommandAddArgPair(cmd, "--txt-record", virBufferContentAndReset(&buf)); VIR_FREE(buf); } + + if (ipdef->dns->nhosts > 0) { + char hostsFile[1024] = { 0 }; + + snprintf(hostsFile, sizeof(hostsFile), "%s/%s.hosts", + NETWORK_PID_DIR, network->def->name); + + networkDnsmasqGenHosts(hostsFile, ipdef->dns); + + virCommandAddArgPair(cmd, "--addn-hosts", hostsFile); + } } /* diff --git a/tests/networkxml2xmlin/nat-network-dns-hosts.xml b/tests/networkxml2xmlin/nat-network-dns-hosts.xml new file mode 100644 index 0000000..fe545cf --- /dev/null +++ b/tests/networkxml2xmlin/nat-network-dns-hosts.xml @@ -0,0 +1,27 @@ +<network> + <name>default</name> + <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid> + <forward dev='eth1' mode='nat'/> + <bridge name='virbr0' stp='on' delay='0' /> + <ip address='192.168.122.1' netmask='255.255.255.0'> + <dhcp> + <range start='192.168.122.2' end='192.168.122.254' /> + <host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10' /> + <host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11' /> + </dhcp> + <dns> + <host ip='192.168.122.1'> + <hostname>host</hostname> + <hostname>gateway</hostname> + </host> + </dns> + </ip> + <ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'> + </ip> + <ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'> + </ip> + <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'> + </ip> + <ip family='ipv4' address='10.24.10.1'> + </ip> +</network> diff --git a/tests/networkxml2xmlout/nat-network-dns-hosts.xml b/tests/networkxml2xmlout/nat-network-dns-hosts.xml new file mode 100644 index 0000000..fe545cf --- /dev/null +++ b/tests/networkxml2xmlout/nat-network-dns-hosts.xml @@ -0,0 +1,27 @@ +<network> + <name>default</name> + <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid> + <forward dev='eth1' mode='nat'/> + <bridge name='virbr0' stp='on' delay='0' /> + <ip address='192.168.122.1' netmask='255.255.255.0'> + <dhcp> + <range start='192.168.122.2' end='192.168.122.254' /> + <host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10' /> + <host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11' /> + </dhcp> + <dns> + <host ip='192.168.122.1'> + <hostname>host</hostname> + <hostname>gateway</hostname> + </host> + </dns> + </ip> + <ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'> + </ip> + <ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'> + </ip> + <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'> + </ip> + <ip family='ipv4' address='10.24.10.1'> + </ip> +</network> diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index beb00ef..f5c5715 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -91,6 +91,7 @@ mymain(int argc, char **argv) DO_TEST("netboot-network"); DO_TEST("netboot-proxy-network"); DO_TEST("nat-network-dns-txt-record"); + DO_TEST("nat-network-dns-hosts"); return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); } -- 1.7.3.2

+<zeroOrMore> +<element name="host"> +<attribute name="ip"><ref name="ipv4-addr"/></attribute> +<zeroOrMore> +<element name="hostname"><text/></element> +</zeroOrMore>
oneOrMore hostname elements seems preferrable.
+ if ((fd = open(hostsFile,
You can use fopen and fprintf. This function also should be in src/util/dnsmasq.c (e.g. with addnhost* APIs in that file and dnsmasqAddHost as a public API). See the hostsfile* APIs there. Then you could further split the patch this way: - one patch that moves the creation of the dnsmasqContext into networkSaveDnsmasqHostsfile; - one patch that makes src/util/dnsmasq.c create the hostsfile only after the first call to dnsmasqAddDhcpHost - this would be the third patch in the series, and it would add dnsmasqAddHost calls in networkSaveDnsmasqHostsfile
diff --git a/tests/networkxml2xmlin/nat-network-dns-hosts.xml b/tests/networkxml2xmlin/nat-network-dns-hosts.xml new file mode 100644 index 0000000..fe545cf
Uhm, libvirt has no tests that actually check whether the dnsmasq command line works? That's a bit bad, perhaps you can add them... Paolo

On 03/31/2011 10:16 AM, Paolo Bonzini wrote:
+<zeroOrMore> +<element name="host"> +<attribute name="ip"><ref name="ipv4-addr"/></attribute> +<zeroOrMore> +<element name="hostname"><text/></element> +</zeroOrMore> oneOrMore hostname elements seems preferrable.
Well, this could be better. That's right.
+ if ((fd = open(hostsFile, You can use fopen and fprintf.
Well, I don't know since it's rarely used in to fopen and fprintf form and I'm not sure whether syntax checking enables it or not. I know there are some native functions disabled so this one can be as well but open() is not disabled since it's used somewhere - that's what I'm sure about.
This function also should be in src/util/dnsmasq.c (e.g. with addnhost* APIs in that file and dnsmasqAddHost as a public API). See the hostsfile* APIs there.
Oh, I'll have a look to this one.
Then you could further split the patch this way:
- one patch that moves the creation of the dnsmasqContext into networkSaveDnsmasqHostsfile;
What do you mean by dnsmasqContents? The code to generate the hostsfile, i.e. the one I added?
- one patch that makes src/util/dnsmasq.c create the hostsfile only after the first call to dnsmasqAddDhcpHost
You mean that the first call to dnsmasqAddDhcpHost should call the function you mentioned about? Also, this is named dnsmasqAddDhcpHost() .. what if somebody will use <dns> tag but without <dhcp> tag?
- this would be the third patch in the series, and it would add dnsmasqAddHost calls in networkSaveDnsmasqHostsfile
So this patch will be just adding the networkSaveDnsmasqHostsfile() call to the dnsmasqAddHost() and nothing else ?
diff --git a/tests/networkxml2xmlin/nat-network-dns-hosts.xml b/tests/networkxml2xmlin/nat-network-dns-hosts.xml new file mode 100644 index 0000000..fe545cf Uhm, libvirt has no tests that actually check whether the dnsmasq command line works? That's a bit bad, perhaps you can add them...
Well, unfortunately there are no tests to check whether the dnsmasq command line works. What would you prefer? To run it with some bogus PID file and port and check the command execution error code and if it's 0 (and PID is working) then to kill $PID and make the test pass, otherwise fail the test or something similar? Michal -- Michal Novotny <minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat

On 03/31/2011 01:06 PM, Michal Novotny wrote:
- this would be the third patch in the series, and it would add dnsmasqAddHost calls in networkSaveDnsmasqHostsfile So this patch will be just adding the networkSaveDnsmasqHostsfile() call to the dnsmasqAddHost() and nothing else ?
And all the XML processing.
diff --git a/tests/networkxml2xmlin/nat-network-dns-hosts.xml b/tests/networkxml2xmlin/nat-network-dns-hosts.xml new file mode 100644 index 0000000..fe545cf Uhm, libvirt has no tests that actually check whether the dnsmasq command line works? That's a bit bad, perhaps you can add them... Well, unfortunately there are no tests to check whether the dnsmasq command line works. What would you prefer? To run it with some bogus PID file and port and check the command execution error code and if it's 0 (and PID is working) then to kill $PID and make the test pass, otherwise fail the test or something similar?
Even a regression test that compares the command-line with what is in a file, would be great. Regarding all other questions, I suggest you start by studying src/util/dnsmasq.c and how it is used. Paolo

On 03/31/2011 01:14 PM, Paolo Bonzini wrote:
On 03/31/2011 01:06 PM, Michal Novotny wrote:
- this would be the third patch in the series, and it would add dnsmasqAddHost calls in networkSaveDnsmasqHostsfile So this patch will be just adding the networkSaveDnsmasqHostsfile() call to the dnsmasqAddHost() and nothing else ? And all the XML processing.
Oh, ok. That's fine :) I'll create put it there as well.
diff --git a/tests/networkxml2xmlin/nat-network-dns-hosts.xml b/tests/networkxml2xmlin/nat-network-dns-hosts.xml new file mode 100644 index 0000000..fe545cf Uhm, libvirt has no tests that actually check whether the dnsmasq command line works? That's a bit bad, perhaps you can add them... Well, unfortunately there are no tests to check whether the dnsmasq command line works. What would you prefer? To run it with some bogus PID file and port and check the command execution error code and if it's 0 (and PID is working) then to kill $PID and make the test pass, otherwise fail the test or something similar? Even a regression test that compares the command-line with what is in a file, would be great.
You mean to compare command-line from the XML, i.e. to generate the command-line from XML and put the tests whether the generated command-line is the same as mentioned in the *.argv file containing whole command-line? Like for QEMU? Michal -- Michal Novotny <minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat

On 03/31/2011 01:18 PM, Michal Novotny wrote:
You mean to compare command-line from the XML, i.e. to generate the command-line from XML and put the tests whether the generated command-line is the same as mentioned in the *.argv file containing whole command-line? Like for QEMU?
Yes. Paolo

On Wed, Mar 30, 2011 at 02:57:10PM +0200, Michal Novotny wrote:
Hi, this is the patch to introduce the TXT record support for the DNS service on the virtual network. This can be defined using the txt-record subelement in the dns element of the network XML description.
First patch is adding TXT record support to the DNS service on the virtual network and the second patch is adding support for defining hosts for the DNS service.
The new definition syntax is:
<dns> <txt-record name="example name" value="example value" /> <host ip='192.168.122.1'> <hostname>gateway</hostname> <hostname>host</hostname> </host> </dns>
Where multiple host elements can be defined to put the aliases for specified IP addresses.
The patch series has been tested for the configuration and it was working fine and also RelaxNG schema with the tests have been both altered to add test cases to test those patches.
Both of the patches passed make, syntax checking and all the tests.
Principle sounds fine but let's defer this to after 0.9.0, :) Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Wed, Mar 30, 2011 at 02:57:10PM +0200, Michal Novotny wrote:
Hi, this is the patch to introduce the TXT record support for the DNS service on the virtual network. This can be defined using the txt-record subelement in the dns element of the network XML description.
First patch is adding TXT record support to the DNS service on the virtual network and the second patch is adding support for defining hosts for the DNS service.
The new definition syntax is:
<dns> <txt-record name="example name" value="example value" /> <host ip='192.168.122.1'> <hostname>gateway</hostname> <hostname>host</hostname> </host> </dns>
Where multiple host elements can be defined to put the aliases for specified IP addresses.
The patch series has been tested for the configuration and it was working fine and also RelaxNG schema with the tests have been both altered to add test cases to test those patches.
Both of the patches passed make, syntax checking and all the tests. Principle sounds fine but let's defer this to after 0.9.0, :)
Daniel
I already mentioned it's since 0.9.0 in the formatnetwork.html.in file :) Michal -- Michal Novotny <minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat

On Wed, Mar 30, 2011 at 15:47:45 +0200, Michal Novotny wrote:
Principle sounds fine but let's defer this to after 0.9.0, :)
Daniel
I already mentioned it's since 0.9.0 in the formatnetwork.html.in file :) Which is wrong since it will be since 0.9.1 :-)
Jirka Oh, I can see the point however this is the simple change to formatnetwork.html.in file :) I don't know whether there's a real point working on this before 0.9.1 though so I'll leave it for now and I guess this would be better if somebody asks me or just merges it to 0.9.1 when it's on :)
Michal -- Michal Novotny <minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat

On Wed, Mar 30, 2011 at 02:57:10PM +0200, Michal Novotny wrote:
Hi, this is the patch to introduce the TXT record support for the DNS service on the virtual network. This can be defined using the txt-record subelement in the dns element of the network XML description.
First patch is adding TXT record support to the DNS service on the virtual network and the second patch is adding support for defining hosts for the DNS service.
The new definition syntax is:
<dns> <txt-record name="example name" value="example value" /> <host ip='192.168.122.1'> <hostname>gateway</hostname> <hostname>host</hostname> </host> </dns>
Where multiple host elements can be defined to put the aliases for specified IP addresses.
The patch series has been tested for the configuration and it was working fine and also RelaxNG schema with the tests have been both altered to add test cases to test those patches.
Both of the patches passed make, syntax checking and all the tests. Principle sounds fine but let's defer this to after 0.9.0, :)
Daniel
Oh, do you mean we not only put this to version after 0.9.0 but also we add some new things to this as well? Is my patch good for this and will we just merge it to "after 0.9.0" version or should we rewrite it entirely once it's OK? Since I don't work in libvirt team maybe I won't be working on this one (unless somebody ask me to do it) so based on this fact I'm not primarily working in the libvirt team I may not know about whether work on this one is on or not so maybe it's good if you ask me to work on this when it's on or lead the assigned engineer to ask me about this. Michal -- Michal Novotny <minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat

On Wed, Mar 30, 2011 at 03:54:07PM +0200, Michal Novotny wrote:
On Wed, Mar 30, 2011 at 02:57:10PM +0200, Michal Novotny wrote:
Hi, this is the patch to introduce the TXT record support for the DNS service on the virtual network. This can be defined using the txt-record subelement in the dns element of the network XML description.
First patch is adding TXT record support to the DNS service on the virtual network and the second patch is adding support for defining hosts for the DNS service.
The new definition syntax is:
<dns> <txt-record name="example name" value="example value" /> <host ip='192.168.122.1'> <hostname>gateway</hostname> <hostname>host</hostname> </host> </dns>
Where multiple host elements can be defined to put the aliases for specified IP addresses.
The patch series has been tested for the configuration and it was working fine and also RelaxNG schema with the tests have been both altered to add test cases to test those patches.
Both of the patches passed make, syntax checking and all the tests. Principle sounds fine but let's defer this to after 0.9.0, :)
Daniel
Oh, do you mean we not only put this to version after 0.9.0 but also we add some new things to this as well?
Is my patch good for this and will we just merge it to "after 0.9.0" version or should we rewrite it entirely once it's OK? Since I don't work in libvirt team maybe I won't be working on this one (unless somebody ask me to do it) so based on this fact I'm not primarily working in the libvirt team I may not know about whether work on this one is on or not so maybe it's good if you ask me to work on this when it's on or lead the assigned engineer to ask me about this.
Just that we are in freeze for 0.9.0, so I suggest to review and apply this there after, say early next week, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Wed, Mar 30, 2011 at 03:54:07PM +0200, Michal Novotny wrote:
On Wed, Mar 30, 2011 at 02:57:10PM +0200, Michal Novotny wrote:
Hi, this is the patch to introduce the TXT record support for the DNS service on the virtual network. This can be defined using the txt-record subelement in the dns element of the network XML description.
First patch is adding TXT record support to the DNS service on the virtual network and the second patch is adding support for defining hosts for the DNS service.
The new definition syntax is:
<dns> <txt-record name="example name" value="example value" /> <host ip='192.168.122.1'> <hostname>gateway</hostname> <hostname>host</hostname> </host> </dns>
Where multiple host elements can be defined to put the aliases for specified IP addresses.
The patch series has been tested for the configuration and it was working fine and also RelaxNG schema with the tests have been both altered to add test cases to test those patches.
Both of the patches passed make, syntax checking and all the tests. Principle sounds fine but let's defer this to after 0.9.0, :)
Daniel
Oh, do you mean we not only put this to version after 0.9.0 but also we add some new things to this as well?
Is my patch good for this and will we just merge it to "after 0.9.0" version or should we rewrite it entirely once it's OK? Since I don't work in libvirt team maybe I won't be working on this one (unless somebody ask me to do it) so based on this fact I'm not primarily working in the libvirt team I may not know about whether work on this one is on or not so maybe it's good if you ask me to work on this when it's on or lead the assigned engineer to ask me about this. Just that we are in freeze for 0.9.0, so I suggest to review and apply this there after, say early next week,
Daniel
Well, that way I think it's OK and committee could simply change 0.9.0 in the formatnetwork.html.in to 0.9.1 if there are no further issues with the patch itself and once it's ACKed :) Michal -- Michal Novotny <minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat

Any followup on v2 of the patch? Just because Daniel (Veillard) wrote something after 0.9.0 and I read already something about 0.9.1 so I would like to remind about v2 of the patch because I don't want it to go to the /dev/null :) Michal On 03/30/2011 03:46 PM, Daniel Veillard wrote:
On Wed, Mar 30, 2011 at 02:57:10PM +0200, Michal Novotny wrote:
Hi, this is the patch to introduce the TXT record support for the DNS service on the virtual network. This can be defined using the txt-record subelement in the dns element of the network XML description.
First patch is adding TXT record support to the DNS service on the virtual network and the second patch is adding support for defining hosts for the DNS service.
The new definition syntax is:
<dns> <txt-record name="example name" value="example value" /> <host ip='192.168.122.1'> <hostname>gateway</hostname> <hostname>host</hostname> </host> </dns>
Where multiple host elements can be defined to put the aliases for specified IP addresses.
The patch series has been tested for the configuration and it was working fine and also RelaxNG schema with the tests have been both altered to add test cases to test those patches.
Both of the patches passed make, syntax checking and all the tests. Principle sounds fine but let's defer this to after 0.9.0, :)
Daniel
-- Michal Novotny <minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat
participants (4)
-
Daniel Veillard
-
Jiri Denemark
-
Michal Novotny
-
Paolo Bonzini