[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 3/3] v7.2: put dnsmasq parameters into conf-file



This patch changes how parameters are passed to dnsmasq.  Instead of
being on the command line, the parameters are put into a file (one
parameter per line) and the command line parameter --conf-file=
to specify the location of the file.  This file is located in
the same directory as the leases file.

This also adds the dnsmasq parameter interface=<net-name>

The change of putting the parameters into a configuration file
allows them to be examined and more easily understood than
examining the command lines displayed by "ps ax".  This is
especially true when a number of networks have been started.

I suspect that when the use of dnsmasq was originally done,
the command line was simple but has gotten more complicated
over time and will likely become even more complicated in the
future.

I believe that if use of dnsmasq was done today with
the current requirements for dnsmasq, a configuration file
would have been used.  Many (most?) daemons use configuration
files as oppose to command line parameters.

One potential addition to dnsmasq parameters is to specify
the reverse-lookup queries which are not to be passed on up
the chain.  For IPv4, such queries are rather simple and
take the form:
    <ipv4_address>.in-addr.arpa
but ipv6 queries involve a lot longer specification.  The
IPv6 query will be of the form:
    <ipv6_address>.ip6.arpa
where the above query expands to a 44 character string which is
specified by --local=/<ipv6_address>.ip6.arpa/ which is
certainly a lot of clutter to add to the command line.
---
 src/network/bridge_driver.c                        | 158 +++++++++++++--------
 src/network/bridge_driver.h                        |   7 +-
 tests/networkxml2argvdata/dhcp6-network.argv       |  34 ++---
 tests/networkxml2argvdata/isolated-network.argv    |  32 ++---
 tests/networkxml2argvdata/nat-network-dhcp6.argv   |  40 +++---
 .../networkxml2argvdata/nat-network-dns-hosts.argv |  22 +--
 .../nat-network-dns-srv-record-minimal.argv        |  40 +++---
 .../nat-network-dns-srv-record.argv                |  40 +++---
 .../nat-network-dns-txt-record.argv                |  40 +++---
 tests/networkxml2argvdata/nat-network.argv         |  38 ++---
 tests/networkxml2argvdata/netboot-network.argv     |  38 ++---
 .../networkxml2argvdata/netboot-proxy-network.argv |  34 ++---
 .../routed-network-dhcphost.argv                   |  30 ++--
 tests/networkxml2argvdata/routed-network.argv      |  18 +--
 tests/networkxml2argvtest.c                        |  42 +-----
 15 files changed, 309 insertions(+), 304 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 19a9170..6cb4c16 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -141,6 +141,16 @@ networkDnsmasqLeaseFileNameFunc networkDnsmasqLeaseFileName =
     networkDnsmasqLeaseFileNameDefault;
 
 static char *
+networkDnsmasqConfigFileName(const char *netname)
+{
+    char *conffile;
+
+    ignore_value(virAsprintf(&conffile, DNSMASQ_STATE_DIR "/%s.conf",
+                             netname));
+    return conffile;
+}
+
+static char *
 networkRadvdPidfileBasename(const char *netname)
 {
     /* this is simple but we want to be sure it's consistently done */
@@ -168,6 +178,7 @@ networkRemoveInactive(struct network_driver *driver,
     char *leasefile = NULL;
     char *radvdconfigfile = NULL;
     char *radvdpidbase = NULL;
+    char *configfile = NULL;
     dnsmasqContext *dctx = NULL;
     virNetworkDefPtr def = virNetworkObjGetPersistentDef(net);
 
@@ -186,9 +197,13 @@ networkRemoveInactive(struct network_driver *driver,
     if (!(radvdpidbase = networkRadvdPidfileBasename(def->name)))
         goto no_memory;
 
+    if (!(configfile = networkDnsmasqConfigFileName(def->name)))
+        goto no_memory;
+
     /* dnsmasq */
     dnsmasqDelete(dctx);
     unlink(leasefile);
+    unlink(configfile);
 
     /* radvd */
     unlink(radvdconfigfile);
@@ -201,6 +216,7 @@ networkRemoveInactive(struct network_driver *driver,
 
 cleanup:
     VIR_FREE(leasefile);
+    VIR_FREE(configfile);
     VIR_FREE(radvdconfigfile);
     VIR_FREE(radvdpidbase);
     dnsmasqContextFree(dctx);
@@ -627,13 +643,14 @@ networkBuildDnsmasqHostsList(dnsmasqContext *dctx,
     return 0;
 }
 
-
+        /* build the dnsmasq conf file contents */
 static int
-networkBuildDnsmasqArgv(virNetworkObjPtr network,
+networkDnsmasqConfContents(virNetworkObjPtr network,
                         const char *pidfile,
-                        virCommandPtr cmd,
+                        char **configstr,
                         dnsmasqContext *dctx)
 {
+    virBuffer configbuf = VIR_BUFFER_INITIALIZER;;
     int r, ret = -1;
     int nbleases = 0;
     int ii;
@@ -644,6 +661,8 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
     virNetworkIpDefPtr tmpipdef, ipdef, ipv4def, ipv6def;
     bool dhcp4flag, dhcp6flag;
 
+    *configstr = NULL;
+
     /*
      * NB, be careful about syntax for dnsmasq options in long format.
      *
@@ -663,29 +682,27 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
      * very explicit on this.
      */
 
-    /*
-     * Needed to ensure dnsmasq uses same algorithm for processing
-     * multiple namedriver entries in /etc/resolv.conf as GLibC.
-     */
-    virCommandAddArgList(cmd, "--strict-order",
-                              "--bind-interfaces",
-                              "--domain-needed",
-                              "--except-interface=lo",
-                              NULL);
+    /* create dnsmasq config file appropriate for this network */
+    virBufferAsprintf(&configbuf,
+                              "# dnsmasq conf file created by libvirt\n"
+                              "strict-order\n"
+                              "bind-interfaces\n"
+                              "domain-needed\n"
+                              "except-interface=lo\n");
 
     if (network->def->domain) {
-        virCommandAddArgPair(cmd, "--domain", network->def->domain);
-        virCommandAddArg(cmd, "--expand-hosts");
+        virBufferAsprintf(&configbuf,
+                 "domain=%s\n"
+                 "expand-hosts\n",
+                 network->def->domain);
     }
     /* need to specify local even if no domain specified */
-    virCommandAddArgFormat(cmd, "--local=/%s/",
-                           network->def->domain ? network->def->domain : "");
+    virBufferAsprintf(&configbuf,
+                "local=/%s/\n",
+                network->def->domain ? network->def->domain : "");
 
     if (pidfile)
-        virCommandAddArgPair(cmd, "--pid-file", pidfile);
-
-    /* *no* conf file */
-    virCommandAddArg(cmd, "--conf-file=");
+        virBufferAsprintf(&configbuf, "pid-file=%s\n", pidfile);
 
     /* If this is an isolated network, set the default route option
      * (3) to be empty to avoid setting a default route that's
@@ -695,8 +712,8 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
      * to build a connection to the outside).
      */
     if (network->def->forwardType == VIR_NETWORK_FORWARD_NONE) {
-        virCommandAddArgList(cmd, "--dhcp-option=3",
-                             "--no-resolv", NULL);
+        virBufferAsprintf(&configbuf, "dhcp-option=3\n"
+                                      "no-resolv\n");
     }
 
     if (network->def->dns != NULL) {
@@ -704,7 +721,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
         int i;
 
         for (i = 0; i < dns->ntxtrecords; i++) {
-            virCommandAddArgFormat(cmd, "--txt-record=%s,%s",
+            virBufferAsprintf(&configbuf, "txt-record=%s,%s\n",
                                    dns->txtrecords[i].name,
                                    dns->txtrecords[i].value);
         }
@@ -742,7 +759,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
                     goto cleanup;
                 }
 
-                virCommandAddArgPair(cmd, "--srv-host", record);
+                virBufferAsprintf(&configbuf, "srv-host=%s\n", record);
                 VIR_FREE(record);
                 VIR_FREE(recordPort);
                 VIR_FREE(recordWeight);
@@ -751,21 +768,15 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
         }
     }
 
-    /*
-     * --interface does not actually work with dnsmasq < 2.47,
-     * due to DAD for ipv6 addresses on the interface.
-     *
-     * virCommandAddArgList(cmd, "--interface", ipdef->bridge, NULL);
-     *
-     * So listen on all defined IPv[46] addresses
-     */
+    virBufferAsprintf(&configbuf, "interface=%s\n", network->def->bridge);
+
     for (ii = 0;
          (tmpipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, ii));
          ii++) {
         char *ipaddr = virSocketAddrFormat(&tmpipdef->address);
         if (!ipaddr)
             goto cleanup;
-        virCommandAddArgList(cmd, "--listen-address", ipaddr, NULL);
+        virBufferAsprintf(&configbuf, "listen-address=%s\n", ipaddr);
         VIR_FREE(ipaddr);
     }
 
@@ -811,8 +822,8 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
                 VIR_FREE(saddr);
                 goto cleanup;
             }
-            virCommandAddArg(cmd, "--dhcp-range");
-            virCommandAddArgFormat(cmd, "%s,%s", saddr, eaddr);
+            virBufferAsprintf(&configbuf, "dhcp-range=%s,%s\n",
+                                        saddr, eaddr);
             VIR_FREE(saddr);
             VIR_FREE(eaddr);
             nbleases += virSocketAddrGetRange(&ipdef->ranges[r].start,
@@ -828,8 +839,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
             char *bridgeaddr = virSocketAddrFormat(&ipdef->address);
             if (!bridgeaddr)
                 goto cleanup;
-            virCommandAddArg(cmd, "--dhcp-range");
-            virCommandAddArgFormat(cmd, "%s,static", bridgeaddr);
+            virBufferAsprintf(&configbuf, "dhcp-range=%s,static\n", bridgeaddr);
             VIR_FREE(bridgeaddr);
         }
 
@@ -839,26 +849,23 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
         /* Note: the following is IPv4 only */
         if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET)) {
             if (ipdef->nranges || ipdef->nhosts)
-                virCommandAddArg(cmd, "--dhcp-no-override");
+                virBufferAsprintf(&configbuf, "dhcp-no-override\n");
 
             if (ipdef->tftproot) {
-                virCommandAddArgList(cmd, "--enable-tftp",
-                                     "--tftp-root", ipdef->tftproot,
-                                     NULL);
+                virBufferAsprintf(&configbuf, "enable-tftp\n");
+                virBufferAsprintf(&configbuf, "tftp-root=%s\n", ipdef->tftproot);
             }
-
             if (ipdef->bootfile) {
-                virCommandAddArg(cmd, "--dhcp-boot");
                 if (VIR_SOCKET_ADDR_VALID(&ipdef->bootserver)) {
                     char *bootserver = virSocketAddrFormat(&ipdef->bootserver);
 
                     if (!bootserver)
                         goto cleanup;
-                    virCommandAddArgFormat(cmd, "%s%s%s",
+                    virBufferAsprintf(&configbuf, "dhcp-boot=%s%s%s\n",
                                        ipdef->bootfile, ",,", bootserver);
                     VIR_FREE(bootserver);
                 } else {
-                    virCommandAddArg(cmd, ipdef->bootfile);
+                    virBufferAsprintf(&configbuf, "dhcp-boot=%s\n", ipdef->bootfile);
                 }
             }
         }
@@ -872,9 +879,9 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
         char *leasefile = networkDnsmasqLeaseFileName(network->def->name);
         if (!leasefile)
             goto cleanup;
-        virCommandAddArgFormat(cmd, "--dhcp-leasefile=%s", leasefile);
+        virBufferAsprintf(&configbuf, "dhcp-leasefile=%s\n", leasefile);
         VIR_FREE(leasefile);
-        virCommandAddArgFormat(cmd, "--dhcp-lease-max=%d", nbleases);
+        virBufferAsprintf(&configbuf, "dhcp-lease-max=%d\n", nbleases);
     }
 
     /* this is done once per interface */
@@ -886,27 +893,27 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
      * file to allow for runtime additions.
      */
     if (dhcp4flag || dhcp6flag)
-        virCommandAddArgPair(cmd, "--dhcp-hostsfile",
-                             dctx->hostsfile->path);
+            virBufferAsprintf(&configbuf, "dhcp-hostsfile=%s\n",
+                                 dctx->hostsfile->path);
 
     /* Likewise, always create this file and put it on the commandline, to allow for
      * for runtime additions.
      */
-    virCommandAddArgPair(cmd, "--addn-hosts",
-                         dctx->addnhostsfile->path);
+        virBufferAsprintf(&configbuf, "addn-hosts=%s\n",
+                             dctx->addnhostsfile->path);
 
     /* we are doing RA instead of radvd */
     if (CHECK_DNSMASQ_VERSION()) {
         if (dhcp6flag)
-            virCommandAddArg(cmd, "--enable-ra");
+            virBufferAsprintf(&configbuf, "enable-ra\n");
         else {
             char *bridgeaddr = NULL;
             ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET6, 0);
             if (ipdef) {
                 bridgeaddr = virSocketAddrFormat(&ipdef->address);
                 if (bridgeaddr) {
-                    virCommandAddArgFormat(cmd,
-                        "--dhcp-range=%s,ra-only", bridgeaddr);
+                    virBufferAsprintf(&configbuf,
+                        "dhcp-range=%s,ra-only\n", bridgeaddr);
                 } else {
                     virReportError(VIR_ERR_XML_ERROR,
                        _("invalid IPv6 configuration for %s ra-only"),
@@ -917,10 +924,15 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
             }
         }
     }
+    if (!(*configstr = virBufferContentAndReset(&configbuf))) {
+        virReportOOMError();
+        goto cleanup;
+    }
 
     ret = 0;
 
 cleanup:
+    virBufferFreeAndReset(&configbuf);
     VIR_FREE(record);
     VIR_FREE(recordPort);
     VIR_FREE(recordWeight);
@@ -928,13 +940,17 @@ cleanup:
     return ret;
 }
 
+        /* build the dnsmasq command line */
 int
 networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, virCommandPtr *cmdout,
-                                  char *pidfile, dnsmasqContext *dctx)
+                                  char *pidfile, dnsmasqContext *dctx,
+                                  int testOnly, char **testConfigStr)
 {
     virCommandPtr cmd = NULL;
     int ret = -1, ii;
     virNetworkIpDefPtr ipdef;
+    char *configfile = NULL;
+    char *configstr = NULL;
 
     network->dnsmasqPid = -1;
 
@@ -958,15 +974,39 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, virCommandPtr *cmdou
     if (!virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, 0))
         return 0;
 
-    cmd = virCommandNew(DNSMASQ);
-    if (networkBuildDnsmasqArgv(network, pidfile, cmd, dctx) < 0) {
+    if (networkDnsmasqConfContents(network, pidfile, &configstr, dctx) < 0)
+        goto cleanup;
+    if (!configstr)
+        goto cleanup;
+
+    if (testOnly) {
+        *testConfigStr = configstr;
+        return 0;
+    }
+
+    /* construct the filename */
+    if (!(configfile = networkDnsmasqConfigFileName(network->def->name))) {
+        virReportOOMError();
         goto cleanup;
     }
 
+    /* Write the file */
+    if (virFileWriteStr(configfile, configstr, 0600) < 0) {
+        virReportSystemError(errno,
+                         _("couldn't write dnsmasq config file '%s'"),
+                         configfile);
+        goto cleanup;
+    }
+
+    cmd = virCommandNew(DNSMASQ);
+    virCommandAddArgFormat(cmd, "--conf-file=%s", configfile);
+
     if (cmdout)
         *cmdout = cmd;
     ret = 0;
 cleanup:
+    VIR_FREE(configstr);
+    VIR_FREE(configfile);
     if (ret < 0)
         virCommandFree(cmd);
     return ret;
@@ -980,6 +1020,7 @@ networkStartDhcpDaemon(virNetworkObjPtr network)
     char *tmp, *version = NULL;
     unsigned int  major = 0, minor = 0;
     char *pidfile = NULL;
+    char *testconfigstr = NULL;
     int ret = -1;
     dnsmasqContext *dctx = NULL;
 
@@ -1044,7 +1085,8 @@ networkStartDhcpDaemon(virNetworkObjPtr network)
     if (dctx == NULL)
         goto cleanup;
 
-    ret = networkBuildDhcpDaemonCommandLine(network, &cmd, pidfile, dctx);
+    ret = networkBuildDhcpDaemonCommandLine(network, &cmd, pidfile, dctx,
+                                            0, &testconfigstr);
     if (ret < 0)
         goto cleanup;
 
diff --git a/src/network/bridge_driver.h b/src/network/bridge_driver.h
index 0fae275..b6dd6c9 100644
--- a/src/network/bridge_driver.h
+++ b/src/network/bridge_driver.h
@@ -48,15 +48,16 @@ int networkGetNetworkAddress(const char *netname, char **netaddr)
 
 int networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
                                       virCommandPtr *cmdout, char *pidfile,
-                                      dnsmasqContext *dctx)
-    ;
+                                      dnsmasqContext *dctx,
+                                      int testOnly, char **testConfigStr);
 # else
 /* Define no-op replacements that don't drag in any link dependencies.  */
 #  define networkAllocateActualDevice(iface) 0
 #  define networkNotifyActualDevice(iface) 0
 #  define networkReleaseActualDevice(iface) 0
 #  define networkGetNetworkAddress(netname, netaddr) (-2)
-#  define networkBuildDhcpDaemonCommandLine(network, cmdout, pidfile, dctx) 0
+#  define networkBuildDhcpDaemonCommandLine(network, cmdout, pidfile, \
+                dctx, testOnly, testConfigStr) 0
 # endif
 
 typedef char *(*networkDnsmasqLeaseFileNameFunc)(const char *netname);
diff --git a/tests/networkxml2argvdata/dhcp6-network.argv b/tests/networkxml2argvdata/dhcp6-network.argv
index 87c68ac..3698eae 100644
--- a/tests/networkxml2argvdata/dhcp6-network.argv
+++ b/tests/networkxml2argvdata/dhcp6-network.argv
@@ -1,17 +1,17 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---domain=mynet \
---expand-hosts \
---local=/mynet/ \
---conf-file= \
---listen-address 2001:db8:ac10:fe01::1 \
---listen-address 2001:db8:ac10:fd01::1 \
---dhcp-range 2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff \
---dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases \
---dhcp-lease-max=240 \
---dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile \
---addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts \
---enable-ra\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+domain=mynet
+expand-hosts
+local=/mynet/
+interface=virbr0
+listen-address=2001:db8:ac10:fe01::1
+listen-address=2001:db8:ac10:fd01::1
+dhcp-range=2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff
+dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
+dhcp-lease-max=240
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+enable-ra
diff --git a/tests/networkxml2argvdata/isolated-network.argv b/tests/networkxml2argvdata/isolated-network.argv
index 97f7b11..ef02dcb 100644
--- a/tests/networkxml2argvdata/isolated-network.argv
+++ b/tests/networkxml2argvdata/isolated-network.argv
@@ -1,16 +1,16 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---local=// \
---conf-file= \
---dhcp-option=3 \
---no-resolv \
---listen-address 192.168.152.1 \
---dhcp-range 192.168.152.2,192.168.152.254 \
---dhcp-no-override \
---dhcp-leasefile=/var/lib/libvirt/dnsmasq/private.leases \
---dhcp-lease-max=253 \
---dhcp-hostsfile=/var/lib/libvirt/dnsmasq/private.hostsfile \
---addn-hosts=/var/lib/libvirt/dnsmasq/private.addnhosts\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+local=//
+dhcp-option=3
+no-resolv
+interface=virbr2
+listen-address=192.168.152.1
+dhcp-range=192.168.152.2,192.168.152.254
+dhcp-no-override
+dhcp-leasefile=/var/lib/libvirt/dnsmasq/private.leases
+dhcp-lease-max=253
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/private.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/private.addnhosts
diff --git a/tests/networkxml2argvdata/nat-network-dhcp6.argv b/tests/networkxml2argvdata/nat-network-dhcp6.argv
index a4795e5..e148853 100644
--- a/tests/networkxml2argvdata/nat-network-dhcp6.argv
+++ b/tests/networkxml2argvdata/nat-network-dhcp6.argv
@@ -1,20 +1,20 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---local=// \
---conf-file= \
---listen-address 192.168.122.1 \
---listen-address 192.168.123.1 \
---listen-address 2001:db8:ac10:fe01::1 \
---listen-address 2001:db8:ac10:fd01::1 \
---listen-address 10.24.10.1 \
---dhcp-range 192.168.122.2,192.168.122.254 \
---dhcp-no-override \
---dhcp-range 2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff \
---dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases \
---dhcp-lease-max=493 \
---dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile \
---addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts \
---enable-ra\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+local=//
+interface=virbr0
+listen-address=192.168.122.1
+listen-address=192.168.123.1
+listen-address=2001:db8:ac10:fe01::1
+listen-address=2001:db8:ac10:fd01::1
+listen-address=10.24.10.1
+dhcp-range=192.168.122.2,192.168.122.254
+dhcp-no-override
+dhcp-range=2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff
+dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
+dhcp-lease-max=493
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+enable-ra
diff --git a/tests/networkxml2argvdata/nat-network-dns-hosts.argv b/tests/networkxml2argvdata/nat-network-dns-hosts.argv
index 32ad19f..66bc077 100644
--- a/tests/networkxml2argvdata/nat-network-dns-hosts.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-hosts.argv
@@ -1,11 +1,11 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---domain=example.com \
---expand-hosts \
---local=/example.com/ \
---conf-file= \
---listen-address 192.168.122.1 \
---addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+domain=example.com
+expand-hosts
+local=/example.com/
+interface=virbr0
+listen-address=192.168.122.1
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
diff --git a/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv b/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv
index 4c21ff1..db0a8d2 100644
--- a/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv
@@ -1,20 +1,20 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---local=// \
---conf-file= \
---srv-host=name.tcp.,,,, \
---listen-address 192.168.122.1 \
---listen-address 192.168.123.1 \
---listen-address 2001:db8:ac10:fe01::1 \
---listen-address 2001:db8:ac10:fd01::1 \
---listen-address 10.24.10.1 \
---dhcp-range 192.168.122.2,192.168.122.254 \
---dhcp-no-override \
---dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases \
---dhcp-lease-max=253 \
---dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile \
---addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts \
---dhcp-range=2001:db8:ac10:fe01::1,ra-only\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+local=//
+srv-host=name.tcp.,,,,
+interface=virbr0
+listen-address=192.168.122.1
+listen-address=192.168.123.1
+listen-address=2001:db8:ac10:fe01::1
+listen-address=2001:db8:ac10:fd01::1
+listen-address=10.24.10.1
+dhcp-range=192.168.122.2,192.168.122.254
+dhcp-no-override
+dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
+dhcp-lease-max=253
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+dhcp-range=2001:db8:ac10:fe01::1,ra-only
diff --git a/tests/networkxml2argvdata/nat-network-dns-srv-record.argv b/tests/networkxml2argvdata/nat-network-dns-srv-record.argv
index 246dbeb..de01002 100644
--- a/tests/networkxml2argvdata/nat-network-dns-srv-record.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-srv-record.argv
@@ -1,20 +1,20 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---local=// \
---conf-file= \
---srv-host=name.tcp.test-domain-name,.,1024,10,10 \
---listen-address 192.168.122.1 \
---listen-address 192.168.123.1 \
---listen-address 2001:db8:ac10:fe01::1 \
---listen-address 2001:db8:ac10:fd01::1 \
---listen-address 10.24.10.1 \
---dhcp-range 192.168.122.2,192.168.122.254 \
---dhcp-no-override \
---dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases \
---dhcp-lease-max=253 \
---dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile \
---addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts \
---dhcp-range=2001:db8:ac10:fe01::1,ra-only\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+local=//
+srv-host=name.tcp.test-domain-name,.,1024,10,10
+interface=virbr0
+listen-address=192.168.122.1
+listen-address=192.168.123.1
+listen-address=2001:db8:ac10:fe01::1
+listen-address=2001:db8:ac10:fd01::1
+listen-address=10.24.10.1
+dhcp-range=192.168.122.2,192.168.122.254
+dhcp-no-override
+dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
+dhcp-lease-max=253
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+dhcp-range=2001:db8:ac10:fe01::1,ra-only
diff --git a/tests/networkxml2argvdata/nat-network-dns-txt-record.argv b/tests/networkxml2argvdata/nat-network-dns-txt-record.argv
index 8d18f3f..72455c0 100644
--- a/tests/networkxml2argvdata/nat-network-dns-txt-record.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-txt-record.argv
@@ -1,20 +1,20 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---local=// \
---conf-file= \
-'--txt-record=example,example value' \
---listen-address 192.168.122.1 \
---listen-address 192.168.123.1 \
---listen-address 2001:db8:ac10:fe01::1 \
---listen-address 2001:db8:ac10:fd01::1 \
---listen-address 10.24.10.1 \
---dhcp-range 192.168.122.2,192.168.122.254 \
---dhcp-no-override \
---dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases \
---dhcp-lease-max=253 \
---dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile \
---addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts \
---dhcp-range=2001:db8:ac10:fe01::1,ra-only\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+local=//
+txt-record=example,example value
+interface=virbr0
+listen-address=192.168.122.1
+listen-address=192.168.123.1
+listen-address=2001:db8:ac10:fe01::1
+listen-address=2001:db8:ac10:fd01::1
+listen-address=10.24.10.1
+dhcp-range=192.168.122.2,192.168.122.254
+dhcp-no-override
+dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
+dhcp-lease-max=253
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+dhcp-range=2001:db8:ac10:fe01::1,ra-only
diff --git a/tests/networkxml2argvdata/nat-network.argv b/tests/networkxml2argvdata/nat-network.argv
index 32afeaa..91090ef 100644
--- a/tests/networkxml2argvdata/nat-network.argv
+++ b/tests/networkxml2argvdata/nat-network.argv
@@ -1,19 +1,19 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---local=// \
---conf-file= \
---listen-address 192.168.122.1 \
---listen-address 192.168.123.1 \
---listen-address 2001:db8:ac10:fe01::1 \
---listen-address 2001:db8:ac10:fd01::1 \
---listen-address 10.24.10.1 \
---dhcp-range 192.168.122.2,192.168.122.254 \
---dhcp-no-override \
---dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases \
---dhcp-lease-max=253 \
---dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile \
---addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts \
---dhcp-range=2001:db8:ac10:fe01::1,ra-only\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+local=//
+interface=virbr0
+listen-address=192.168.122.1
+listen-address=192.168.123.1
+listen-address=2001:db8:ac10:fe01::1
+listen-address=2001:db8:ac10:fd01::1
+listen-address=10.24.10.1
+dhcp-range=192.168.122.2,192.168.122.254
+dhcp-no-override
+dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
+dhcp-lease-max=253
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+dhcp-range=2001:db8:ac10:fe01::1,ra-only
diff --git a/tests/networkxml2argvdata/netboot-network.argv b/tests/networkxml2argvdata/netboot-network.argv
index 41e9416..35b8e40 100644
--- a/tests/networkxml2argvdata/netboot-network.argv
+++ b/tests/networkxml2argvdata/netboot-network.argv
@@ -1,19 +1,19 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---domain=example.com \
---expand-hosts \
---local=/example.com/ \
---conf-file= \
---listen-address 192.168.122.1 \
---dhcp-range 192.168.122.2,192.168.122.254 \
---dhcp-no-override \
---enable-tftp \
---tftp-root /var/lib/tftproot \
---dhcp-boot pxeboot.img \
---dhcp-leasefile=/var/lib/libvirt/dnsmasq/netboot.leases \
---dhcp-lease-max=253 \
---dhcp-hostsfile=/var/lib/libvirt/dnsmasq/netboot.hostsfile \
---addn-hosts=/var/lib/libvirt/dnsmasq/netboot.addnhosts\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+domain=example.com
+expand-hosts
+local=/example.com/
+interface=virbr1
+listen-address=192.168.122.1
+dhcp-range=192.168.122.2,192.168.122.254
+dhcp-no-override
+enable-tftp
+tftp-root=/var/lib/tftproot
+dhcp-boot=pxeboot.img
+dhcp-leasefile=/var/lib/libvirt/dnsmasq/netboot.leases
+dhcp-lease-max=253
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/netboot.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/netboot.addnhosts
diff --git a/tests/networkxml2argvdata/netboot-proxy-network.argv b/tests/networkxml2argvdata/netboot-proxy-network.argv
index eebe560..f25feea 100644
--- a/tests/networkxml2argvdata/netboot-proxy-network.argv
+++ b/tests/networkxml2argvdata/netboot-proxy-network.argv
@@ -1,17 +1,17 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---domain=example.com \
---expand-hosts \
---local=/example.com/ \
---conf-file= \
---listen-address 192.168.122.1 \
---dhcp-range 192.168.122.2,192.168.122.254 \
---dhcp-no-override \
---dhcp-boot pxeboot.img,,10.20.30.40 \
---dhcp-leasefile=/var/lib/libvirt/dnsmasq/netboot.leases \
---dhcp-lease-max=253 \
---dhcp-hostsfile=/var/lib/libvirt/dnsmasq/netboot.hostsfile \
---addn-hosts=/var/lib/libvirt/dnsmasq/netboot.addnhosts\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+domain=example.com
+expand-hosts
+local=/example.com/
+interface=virbr1
+listen-address=192.168.122.1
+dhcp-range=192.168.122.2,192.168.122.254
+dhcp-no-override
+dhcp-boot=pxeboot.img,,10.20.30.40
+dhcp-leasefile=/var/lib/libvirt/dnsmasq/netboot.leases
+dhcp-lease-max=253
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/netboot.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/netboot.addnhosts
diff --git a/tests/networkxml2argvdata/routed-network-dhcphost.argv b/tests/networkxml2argvdata/routed-network-dhcphost.argv
index 9f52b98..da6aad4 100644
--- a/tests/networkxml2argvdata/routed-network-dhcphost.argv
+++ b/tests/networkxml2argvdata/routed-network-dhcphost.argv
@@ -1,15 +1,15 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---local=// \
---conf-file= \
---listen-address 192.168.122.1 \
---listen-address 2001:db8:ac10:fd01::1 \
---dhcp-range 192.168.122.1,static \
---dhcp-no-override \
---dhcp-range 2001:db8:ac10:fd01::1,static \
---dhcp-hostsfile=/var/lib/libvirt/dnsmasq/local.hostsfile \
---addn-hosts=/var/lib/libvirt/dnsmasq/local.addnhosts \
---enable-ra\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+local=//
+interface=virbr1
+listen-address=192.168.122.1
+listen-address=2001:db8:ac10:fd01::1
+dhcp-range=192.168.122.1,static
+dhcp-no-override
+dhcp-range=2001:db8:ac10:fd01::1,static
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/local.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/local.addnhosts
+enable-ra
diff --git a/tests/networkxml2argvdata/routed-network.argv b/tests/networkxml2argvdata/routed-network.argv
index 78ad8a2..20240d3 100644
--- a/tests/networkxml2argvdata/routed-network.argv
+++ b/tests/networkxml2argvdata/routed-network.argv
@@ -1,9 +1,9 @@
- DNSMASQ@ \
---strict-order \
---bind-interfaces \
---domain-needed \
---except-interface=lo \
---local=// \
---conf-file= \
---listen-address 192.168.122.1 \
---addn-hosts=/var/lib/libvirt/dnsmasq/local.addnhosts\
+# dnsmasq conf file created by libvirt
+strict-order
+bind-interfaces
+domain-needed
+except-interface=lo
+local=//
+interface=virbr1
+listen-address=192.168.122.1
+addn-hosts=/var/lib/libvirt/dnsmasq/local.addnhosts
diff --git a/tests/networkxml2argvtest.c b/tests/networkxml2argvtest.c
index 206e2d7..521f750 100644
--- a/tests/networkxml2argvtest.c
+++ b/tests/networkxml2argvtest.c
@@ -15,37 +15,6 @@
 #include "memory.h"
 #include "network/bridge_driver.h"
 
-/* Replace all occurrences of @token in @buf by @replacement and adjust size of
- * @buf accordingly. Returns 0 on success and -1 on out-of-memory errors. */
-static int replaceTokens(char **buf, const char *token, const char *replacement) {
-    size_t token_start, token_end;
-    size_t buf_len, rest_len;
-    const size_t token_len = strlen(token);
-    const size_t replacement_len = strlen(replacement);
-    const int diff = replacement_len - token_len;
-
-    buf_len = rest_len = strlen(*buf) + 1;
-    token_end = 0;
-    for (;;) {
-        char *match = strstr(*buf + token_end, token);
-        if (match == NULL)
-            break;
-        token_start = match - *buf;
-        rest_len -= token_start + token_len - token_end;
-        token_end = token_start + token_len;
-        buf_len += diff;
-        if (diff > 0)
-            if (VIR_REALLOC_N(*buf, buf_len) < 0)
-                return -1;
-        if (diff != 0)
-            memmove(*buf + token_end + diff, *buf + token_end, rest_len);
-        memcpy(*buf + token_start, replacement, replacement_len);
-        token_end += diff;
-    }
-    /* if diff < 0, we could shrink the buffer here... */
-    return 0;
-}
-
 static int testCompareXMLToArgvFiles(const char *inxml, const char *outargv) {
     char *inXmlData = NULL;
     char *outArgvData = NULL;
@@ -62,10 +31,6 @@ static int testCompareXMLToArgvFiles(const char *inxml, const char *outargv) {
 
     if (virtTestLoadFile(outargv, &outArgvData) < 0)
         goto fail;
-
-    if (replaceTokens(&outArgvData, "@DNSMASQ@", DNSMASQ))
-        goto fail;
-
     if (!(dev = virNetworkDefParseString(inXmlData)))
         goto fail;
 
@@ -79,12 +44,9 @@ static int testCompareXMLToArgvFiles(const char *inxml, const char *outargv) {
     if (dctx == NULL)
         goto fail;
 
-    if (networkBuildDhcpDaemonCommandLine(obj, &cmd, pidfile, dctx) < 0)
-        goto fail;
-
-    if (!(actual = virCommandToString(cmd)))
+    if (networkBuildDhcpDaemonCommandLine(obj, &cmd, pidfile,
+                        dctx, 1, &actual) < 0)
         goto fail;
-
     if (STRNEQ(outArgvData, actual)) {
         virtTestDifference(stderr, outArgvData, actual);
         goto fail;
-- 
1.7.11.7


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]