network: put dnsmasq parameters in conf-file instead of command line

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 a commandline --conf-file= specifies the
location of the file.  The file is located in the same directory as
the leases file.

Putting the dnsmasq 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.

When the use of dnsmasq was originally done, the required command line
was simple, but it has gotten more complicated over time and will
likely become even more complicated in the future.

Note: The test conf files have all been renamed .conf instead of
.argv, and tests/networkxml2xmlargvdata was moved to
tests/networkxml2xmlconfdata.
This commit is contained in:
Gene Czarcinski 2012-12-06 12:20:39 -05:00 committed by Laine Stump
parent 2d5cd1d724
commit 8b32c80df0
40 changed files with 365 additions and 312 deletions

View File

@ -137,6 +137,16 @@ networkDnsmasqLeaseFileNameDefault(const char *netname)
networkDnsmasqLeaseFileNameFunc networkDnsmasqLeaseFileName = networkDnsmasqLeaseFileNameFunc networkDnsmasqLeaseFileName =
networkDnsmasqLeaseFileNameDefault; networkDnsmasqLeaseFileNameDefault;
static char *
networkDnsmasqConfigFileName(const char *netname)
{
char *conffile;
ignore_value(virAsprintf(&conffile, DNSMASQ_STATE_DIR "/%s.conf",
netname));
return conffile;
}
static char * static char *
networkRadvdPidfileBasename(const char *netname) networkRadvdPidfileBasename(const char *netname)
{ {
@ -164,6 +174,7 @@ networkRemoveInactive(struct network_driver *driver,
{ {
char *leasefile = NULL; char *leasefile = NULL;
char *radvdconfigfile = NULL; char *radvdconfigfile = NULL;
char *configfile = NULL;
char *radvdpidbase = NULL; char *radvdpidbase = NULL;
dnsmasqContext *dctx = NULL; dnsmasqContext *dctx = NULL;
virNetworkDefPtr def = virNetworkObjGetPersistentDef(net); virNetworkDefPtr def = virNetworkObjGetPersistentDef(net);
@ -183,9 +194,13 @@ networkRemoveInactive(struct network_driver *driver,
if (!(radvdpidbase = networkRadvdPidfileBasename(def->name))) if (!(radvdpidbase = networkRadvdPidfileBasename(def->name)))
goto no_memory; goto no_memory;
if (!(configfile = networkDnsmasqConfigFileName(def->name)))
goto no_memory;
/* dnsmasq */ /* dnsmasq */
dnsmasqDelete(dctx); dnsmasqDelete(dctx);
unlink(leasefile); unlink(leasefile);
unlink(configfile);
/* radvd */ /* radvd */
unlink(radvdconfigfile); unlink(radvdconfigfile);
@ -198,6 +213,7 @@ networkRemoveInactive(struct network_driver *driver,
cleanup: cleanup:
VIR_FREE(leasefile); VIR_FREE(leasefile);
VIR_FREE(configfile);
VIR_FREE(radvdconfigfile); VIR_FREE(radvdconfigfile);
VIR_FREE(radvdpidbase); VIR_FREE(radvdpidbase);
dnsmasqContextFree(dctx); dnsmasqContextFree(dctx);
@ -609,13 +625,14 @@ networkBuildDnsmasqHostsList(dnsmasqContext *dctx,
} }
static int int
networkBuildDnsmasqArgv(virNetworkObjPtr network, networkDnsmasqConfContents(virNetworkObjPtr network,
const char *pidfile, const char *pidfile,
virCommandPtr cmd, char **configstr,
dnsmasqContext *dctx, dnsmasqContext *dctx,
dnsmasqCapsPtr caps ATTRIBUTE_UNUSED) dnsmasqCapsPtr caps ATTRIBUTE_UNUSED)
{ {
virBuffer configbuf = VIR_BUFFER_INITIALIZER;
int r, ret = -1; int r, ret = -1;
int nbleases = 0; int nbleases = 0;
int ii; int ii;
@ -627,46 +644,48 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
virNetworkIpDefPtr tmpipdef, ipdef, ipv4def, ipv6def; virNetworkIpDefPtr tmpipdef, ipdef, ipv4def, ipv6def;
bool ipv6SLAAC; bool ipv6SLAAC;
*configstr = NULL;
/* /*
* NB, be careful about syntax for dnsmasq options in long format. * All dnsmasq parameters are put into a configuration file, except the
* command line --conf-file=parameter which specifies the location of
* configuration file.
* *
* If the flag has a mandatory argument, it can be given using * All dnsmasq conf-file parameters must be specified as "foo=bar"
* either syntax: * as oppose to "--foo bar" which was acceptable on the command line.
*
* --foo bar
* --foo=bar
*
* If the flag has a optional argument, it *must* be given using
* the syntax:
*
* --foo=bar
*
* It is hard to determine whether a flag is optional or not,
* without reading the dnsmasq source :-( The manpage is not
* very explicit on this.
*/ */
/* /*
* Needed to ensure dnsmasq uses same algorithm for processing * Needed to ensure dnsmasq uses same algorithm for processing
* multiple namedriver entries in /etc/resolv.conf as GLibC. * multiple namedriver entries in /etc/resolv.conf as GLibC.
*/ */
virCommandAddArgList(cmd, "--strict-order",
"--domain-needed",
NULL);
if (network->def->domain) { /* create dnsmasq config file appropriate for this network */
virCommandAddArgPair(cmd, "--domain", network->def->domain); virBufferAsprintf(&configbuf,
virCommandAddArg(cmd, "--expand-hosts"); "##WARNING: THIS IS AN AUTO-GENERATED FILE. "
} "CHANGES TO IT ARE LIKELY TO BE\n"
/* need to specify local even if no domain specified */ "##OVERWRITTEN AND LOST. Changes to this "
virCommandAddArgFormat(cmd, "--local=/%s/", "configuration should be made using:\n"
network->def->domain ? network->def->domain : ""); "## virsh net-edit %s\n"
"## of other applications using the libvirt API.\n"
"##\n## dnsmasq conf file created by libvirt\n"
"strict-order\n"
"domain-needed\n",
network->def->name);
if (pidfile) if (network->def->domain) {
virCommandAddArgPair(cmd, "--pid-file", pidfile); virBufferAsprintf(&configbuf,
"domain=%s\n"
"expand-hosts\n",
network->def->domain);
}
/* need to specify local even if no domain specified */
virBufferAsprintf(&configbuf,
"local=/%s/\n",
network->def->domain ? network->def->domain : "");
/* *no* conf file */ if (pidfile)
virCommandAddArg(cmd, "--conf-file="); virBufferAsprintf(&configbuf, "pid-file=%s\n", pidfile);
if (dnsmasqCapsGet(caps, DNSMASQ_CAPS_BIND_DYNAMIC)) { if (dnsmasqCapsGet(caps, DNSMASQ_CAPS_BIND_DYNAMIC)) {
/* using --bind-dynamic with only --interface (no /* using --bind-dynamic with only --interface (no
@ -676,15 +695,14 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
* other than one of the virtual guests connected directly to * other than one of the virtual guests connected directly to
* this network). This was added in response to CVE 2012-3411. * this network). This was added in response to CVE 2012-3411.
*/ */
virCommandAddArgList(cmd, virBufferAsprintf(&configbuf,
"--bind-dynamic", "bind-dynamic\n"
"--interface", network->def->bridge, "interface=%s\n",
NULL); network->def->bridge);
} else { } else {
virCommandAddArgList(cmd, virBufferAddLit(&configbuf,
"--bind-interfaces", "bind-interfaces\n"
"--except-interface", "lo", "except-interface=lo\n");
NULL);
/* /*
* --interface does not actually work with dnsmasq < 2.47, * --interface does not actually work with dnsmasq < 2.47,
* due to DAD for ipv6 addresses on the interface. * due to DAD for ipv6 addresses on the interface.
@ -701,7 +719,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
if (!ipaddr) if (!ipaddr)
goto cleanup; goto cleanup;
/* also part of CVE 2012-3411 - if the host's version of /* also part of CVE 2012-3411 - if the host's version of
* dnsmasq doesn't have --bind-dynamic, only allow listening on * dnsmasq doesn't have bind-dynamic, only allow listening on
* private/local IP addresses (see RFC1918/RFC3484/RFC4193) * private/local IP addresses (see RFC1918/RFC3484/RFC4193)
*/ */
if (!virSocketAddrIsPrivate(&tmpipdef->address)) { if (!virSocketAddrIsPrivate(&tmpipdef->address)) {
@ -710,7 +728,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Publicly routable address %s is prohibited. " _("Publicly routable address %s is prohibited. "
"The version of dnsmasq on this host (%d.%d) doesn't " "The version of dnsmasq on this host (%d.%d) doesn't "
"support the --bind-dynamic option, which is required " "support the bind-dynamic option, which is required "
"for safe operation on a publicly routable subnet " "for safe operation on a publicly routable subnet "
"(see CVE-2012-3411). You must either upgrade dnsmasq, " "(see CVE-2012-3411). You must either upgrade dnsmasq, "
"or use a private/local subnet range for this network " "or use a private/local subnet range for this network "
@ -718,27 +736,27 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
(int)version / 1000000, (int)(version % 1000000) / 1000); (int)version / 1000000, (int)(version % 1000000) / 1000);
goto cleanup; goto cleanup;
} }
virCommandAddArgList(cmd, "--listen-address", ipaddr, NULL); virBufferAsprintf(&configbuf, "listen-address=%s\n", ipaddr);
VIR_FREE(ipaddr); VIR_FREE(ipaddr);
} }
} }
/* If this is an isolated network, set the default route option /* If this is an isolated network, set the default route option
* (3) to be empty to avoid setting a default route that's * (3) to be empty to avoid setting a default route that's
* guaranteed to not work, and set --no-resolv so that no dns * guaranteed to not work, and set no-resolv so that no dns
* requests are forwarded on to the dns server listed in the * requests are forwarded on to the dns server listed in the
* host's /etc/resolv.conf (since this could be used as a channel * host's /etc/resolv.conf (since this could be used as a channel
* to build a connection to the outside). * to build a connection to the outside).
*/ */
if (network->def->forward.type == VIR_NETWORK_FORWARD_NONE) { if (network->def->forward.type == VIR_NETWORK_FORWARD_NONE) {
virCommandAddArgList(cmd, "--dhcp-option=3", virBufferAddLit(&configbuf, "dhcp-option=3\n"
"--no-resolv", NULL); "no-resolv\n");
} }
for (ii = 0; ii < dns->ntxts; ii++) { for (ii = 0; ii < dns->ntxts; ii++) {
virCommandAddArgFormat(cmd, "--txt-record=%s,%s", virBufferAsprintf(&configbuf, "txt-record=%s,%s\n",
dns->txts[ii].name, dns->txts[ii].name,
dns->txts[ii].value); dns->txts[ii].value);
} }
for (ii = 0; ii < dns->nsrvs; ii++) { for (ii = 0; ii < dns->nsrvs; ii++) {
@ -774,7 +792,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
goto cleanup; goto cleanup;
} }
virCommandAddArgPair(cmd, "--srv-host", record); virBufferAsprintf(&configbuf, "srv-host=%s\n", record);
VIR_FREE(record); VIR_FREE(record);
VIR_FREE(recordPort); VIR_FREE(recordPort);
VIR_FREE(recordWeight); VIR_FREE(recordWeight);
@ -845,8 +863,8 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
VIR_FREE(saddr); VIR_FREE(saddr);
goto cleanup; goto cleanup;
} }
virCommandAddArg(cmd, "--dhcp-range"); virBufferAsprintf(&configbuf, "dhcp-range=%s,%s\n",
virCommandAddArgFormat(cmd, "%s,%s", saddr, eaddr); saddr, eaddr);
VIR_FREE(saddr); VIR_FREE(saddr);
VIR_FREE(eaddr); VIR_FREE(eaddr);
nbleases += virSocketAddrGetRange(&ipdef->ranges[r].start, nbleases += virSocketAddrGetRange(&ipdef->ranges[r].start,
@ -862,8 +880,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
char *bridgeaddr = virSocketAddrFormat(&ipdef->address); char *bridgeaddr = virSocketAddrFormat(&ipdef->address);
if (!bridgeaddr) if (!bridgeaddr)
goto cleanup; goto cleanup;
virCommandAddArg(cmd, "--dhcp-range"); virBufferAsprintf(&configbuf, "dhcp-range=%s,static\n", bridgeaddr);
virCommandAddArgFormat(cmd, "%s,static", bridgeaddr);
VIR_FREE(bridgeaddr); VIR_FREE(bridgeaddr);
} }
@ -873,16 +890,14 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
/* Note: the following is IPv4 only */ /* Note: the following is IPv4 only */
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET)) { if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET)) {
if (ipdef->nranges || ipdef->nhosts) if (ipdef->nranges || ipdef->nhosts)
virCommandAddArg(cmd, "--dhcp-no-override"); virBufferAddLit(&configbuf, "dhcp-no-override\n");
if (ipdef->tftproot) { if (ipdef->tftproot) {
virCommandAddArgList(cmd, "--enable-tftp", virBufferAddLit(&configbuf, "enable-tftp\n");
"--tftp-root", ipdef->tftproot, virBufferAsprintf(&configbuf, "tftp-root=%s\n", ipdef->tftproot);
NULL);
} }
if (ipdef->bootfile) { if (ipdef->bootfile) {
virCommandAddArg(cmd, "--dhcp-boot");
if (VIR_SOCKET_ADDR_VALID(&ipdef->bootserver)) { if (VIR_SOCKET_ADDR_VALID(&ipdef->bootserver)) {
char *bootserver = virSocketAddrFormat(&ipdef->bootserver); char *bootserver = virSocketAddrFormat(&ipdef->bootserver);
@ -890,11 +905,11 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
virCommandAddArgFormat(cmd, "%s%s%s", virBufferAsprintf(&configbuf, "dhcp-boot=%s%s%s\n",
ipdef->bootfile, ",,", bootserver); ipdef->bootfile, ",,", bootserver);
VIR_FREE(bootserver); VIR_FREE(bootserver);
} else { } else {
virCommandAddArg(cmd, ipdef->bootfile); virBufferAsprintf(&configbuf, "dhcp-boot=%s\n", ipdef->bootfile);
} }
} }
} }
@ -907,9 +922,9 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
virCommandAddArgFormat(cmd, "--dhcp-leasefile=%s", leasefile); virBufferAsprintf(&configbuf, "dhcp-leasefile=%s\n", leasefile);
VIR_FREE(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 */ /* this is done once per interface */
@ -921,19 +936,19 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
* file to allow for runtime additions. * file to allow for runtime additions.
*/ */
if (ipv4def || ipv6def) if (ipv4def || ipv6def)
virCommandAddArgPair(cmd, "--dhcp-hostsfile", virBufferAsprintf(&configbuf, "dhcp-hostsfile=%s\n",
dctx->hostsfile->path); dctx->hostsfile->path);
/* Likewise, always create this file and put it on the commandline, /* Likewise, always create this file and put it on the commandline, to allow for
* to allow for runtime additions. * for runtime additions.
*/ */
virCommandAddArgPair(cmd, "--addn-hosts", virBufferAsprintf(&configbuf, "addn-hosts=%s\n",
dctx->addnhostsfile->path); dctx->addnhostsfile->path);
/* Are we doing RA instead of radvd? */ /* Are we doing RA instead of radvd? */
if (DNSMASQ_RA_SUPPORT(caps)) { if (DNSMASQ_RA_SUPPORT(caps)) {
if (ipv6def) if (ipv6def)
virCommandAddArg(cmd, "--enable-ra"); virBufferAddLit(&configbuf, "enable-ra\n");
else { else {
for (ii = 0; for (ii = 0;
(ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET6, ii)); (ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET6, ii));
@ -942,17 +957,21 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
char *bridgeaddr = virSocketAddrFormat(&ipdef->address); char *bridgeaddr = virSocketAddrFormat(&ipdef->address);
if (!bridgeaddr) if (!bridgeaddr)
goto cleanup; goto cleanup;
virCommandAddArgFormat(cmd, "--dhcp-range=%s,ra-only", virBufferAsprintf(&configbuf,
bridgeaddr); "dhcp-range=%s,ra-only\n", bridgeaddr);
VIR_FREE(bridgeaddr); VIR_FREE(bridgeaddr);
} }
} }
} }
} }
if (!(*configstr = virBufferContentAndReset(&configbuf)))
goto cleanup;
ret = 0; ret = 0;
cleanup: cleanup:
virBufferFreeAndReset(&configbuf);
VIR_FREE(record); VIR_FREE(record);
VIR_FREE(recordPort); VIR_FREE(recordPort);
VIR_FREE(recordWeight); VIR_FREE(recordWeight);
@ -960,21 +979,41 @@ cleanup:
return ret; return ret;
} }
int /* build the dnsmasq command line */
static int
networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, virCommandPtr *cmdout, networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, virCommandPtr *cmdout,
char *pidfile, dnsmasqContext *dctx, char *pidfile, dnsmasqContext *dctx,
dnsmasqCapsPtr caps) dnsmasqCapsPtr caps)
{ {
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
int ret = -1; int ret = -1;
char *configfile = NULL;
char *configstr = NULL;
network->dnsmasqPid = -1; network->dnsmasqPid = -1;
cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps)); if (networkDnsmasqConfContents(network, pidfile, &configstr, dctx, caps) < 0)
if (networkBuildDnsmasqArgv(network, pidfile, cmd, dctx, caps) < 0) { goto cleanup;
if (!configstr)
goto cleanup;
/* construct the filename */
if (!(configfile = networkDnsmasqConfigFileName(network->def->name))) {
virReportOOMError();
goto cleanup; 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(dnsmasqCapsGetBinaryPath(caps));
virCommandAddArgFormat(cmd, "--conf-file=%s", configfile);
if (cmdout) if (cmdout)
*cmdout = cmd; *cmdout = cmd;
ret = 0; ret = 0;
@ -1298,7 +1337,7 @@ networkStartRadvd(struct network_driver *driver ATTRIBUTE_UNUSED,
network->radvdPid = -1; network->radvdPid = -1;
/* Is dnsmasq handling RA? */ /* Is dnsmasq handling RA? */
if (DNSMASQ_RA_SUPPORT(driver->dnsmasqCaps)) { if (DNSMASQ_RA_SUPPORT(driver->dnsmasqCaps)) {
ret = 0; ret = 0;
goto cleanup; goto cleanup;
} }

View File

@ -46,18 +46,19 @@ int networkReleaseActualDevice(virDomainNetDefPtr iface)
int networkGetNetworkAddress(const char *netname, char **netaddr) int networkGetNetworkAddress(const char *netname, char **netaddr)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, int networkDnsmasqConfContents(virNetworkObjPtr network,
virCommandPtr *cmdout, char *pidfile, const char *pidfile,
dnsmasqContext *dctx, char **configstr,
dnsmasqCapsPtr caps) dnsmasqContext *dctx,
; dnsmasqCapsPtr caps);
# else # else
/* Define no-op replacements that don't drag in any link dependencies. */ /* Define no-op replacements that don't drag in any link dependencies. */
# define networkAllocateActualDevice(iface) 0 # define networkAllocateActualDevice(iface) 0
# define networkNotifyActualDevice(iface) (iface=iface, 0) # define networkNotifyActualDevice(iface) (iface=iface, 0)
# define networkReleaseActualDevice(iface) (iface=iface, 0) # define networkReleaseActualDevice(iface) (iface=iface, 0)
# define networkGetNetworkAddress(netname, netaddr) (-2) # define networkGetNetworkAddress(netname, netaddr) (-2)
# define networkBuildDhcpDaemonCommandLine(network, cmdout, pidfile, dctx, caps) 0 # define networkDnsmasqConfContents(network, pidfile, configstr, \
dctx, caps) 0
# endif # endif
typedef char *(*networkDnsmasqLeaseFileNameFunc)(const char *netname); typedef char *(*networkDnsmasqLeaseFileNameFunc)(const char *netname);

View File

@ -56,7 +56,7 @@ EXTRA_DIST = \
networkschematest \ networkschematest \
networkxml2xmlin \ networkxml2xmlin \
networkxml2xmlout \ networkxml2xmlout \
networkxml2argvdata \ networkxml2confdata \
nodedevschemadata \ nodedevschemadata \
nodedevschematest \ nodedevschematest \
nodeinfodata \ nodeinfodata \
@ -147,7 +147,7 @@ endif
test_programs += networkxml2xmltest test_programs += networkxml2xmltest
if WITH_NETWORK if WITH_NETWORK
test_programs += networkxml2argvtest test_programs += networkxml2conftest
endif endif
if WITH_STORAGE_SHEEPDOG if WITH_STORAGE_SHEEPDOG
@ -431,12 +431,12 @@ networkxml2xmltest_SOURCES = \
networkxml2xmltest_LDADD = $(LDADDS) networkxml2xmltest_LDADD = $(LDADDS)
if WITH_NETWORK if WITH_NETWORK
networkxml2argvtest_SOURCES = \ networkxml2conftest_SOURCES = \
networkxml2argvtest.c \ networkxml2conftest.c \
testutils.c testutils.h testutils.c testutils.h
networkxml2argvtest_LDADD = ../src/libvirt_driver_network_impl.la $(LDADDS) networkxml2conftest_LDADD = ../src/libvirt_driver_network_impl.la $(LDADDS)
else else
EXTRA_DIST += networkxml2argvtest.c EXTRA_DIST += networkxml2conftest.c
endif endif
if WITH_STORAGE_SHEEPDOG if WITH_STORAGE_SHEEPDOG

View File

@ -1,15 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--local=// \
--conf-file= \
--bind-dynamic \
--interface virbr0 \
--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\

View File

@ -1,15 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--domain=mynet \
--expand-hosts \
--local=/mynet/ \
--conf-file= \
--bind-dynamic \
--interface virbr0 \
--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\

View File

@ -1,13 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--local=// \
--conf-file= \
--bind-dynamic \
--interface virbr1 \
--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\

View File

@ -1,16 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--local=// \
--conf-file= \
--bind-interfaces \
--except-interface lo \
--listen-address 192.168.152.1 \
--dhcp-option=3 \
--no-resolv \
--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\

View File

@ -1,10 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--domain=example.com \
--expand-hosts \
--local=/example.com/ \
--conf-file= \
--bind-dynamic \
--interface virbr0 \
--addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts\

View File

@ -1,19 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--local=// \
--conf-file= \
--bind-interfaces \
--except-interface lo \
--listen-address 192.168.122.1 \
--listen-address 192.168.123.1 \
--listen-address fc00:db8:ac10:fe01::1 \
--listen-address fc00:db8:ac10:fd01::1 \
--listen-address 10.24.10.1 \
--srv-host=name.tcp.,,,, \
--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\

View File

@ -1,14 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--local=// \
--conf-file= \
--bind-dynamic \
--interface virbr0 \
--srv-host=name.tcp.test-domain-name,.,1024,10,10 \
--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\

View File

@ -1,13 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--local=// \
--conf-file= \
--bind-dynamic --interface virbr0 \
'--txt-record=example,example value' \
--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\

View File

@ -1,15 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--local=// \
--conf-file= \
--bind-dynamic \
--interface virbr0 \
--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 \
--dhcp-range=2001:db8:ac10:fd01::1,ra-only\

View File

@ -1,19 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--domain=example.com \
--expand-hosts \
--local=/example.com/ \
--conf-file= \
--bind-interfaces \
--except-interface lo \
--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\

View File

@ -1,17 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--domain=example.com \
--expand-hosts \
--local=/example.com/ \
--conf-file= \
--bind-interfaces \
--except-interface lo \
--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\

View File

@ -1,8 +0,0 @@
@DNSMASQ@ \
--strict-order \
--domain-needed \
--local=// \
--conf-file= \
--bind-dynamic \
--interface virbr1 \
--addn-hosts=/var/lib/libvirt/dnsmasq/local.addnhosts\

View File

@ -0,0 +1,19 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
local=//
bind-dynamic
interface=virbr0
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

View File

@ -0,0 +1,19 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
domain=mynet
expand-hosts
local=/mynet/
bind-dynamic
interface=virbr0
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

View File

@ -0,0 +1,17 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit local
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
local=//
bind-dynamic
interface=virbr1
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

View File

@ -0,0 +1,20 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit private
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
local=//
bind-interfaces
except-interface=lo
listen-address=192.168.152.1
dhcp-option=3
no-resolv
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

View File

@ -0,0 +1,14 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
domain=example.com
expand-hosts
local=/example.com/
bind-dynamic
interface=virbr0
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts

View File

@ -0,0 +1,23 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
local=//
bind-interfaces
except-interface=lo
listen-address=192.168.122.1
listen-address=192.168.123.1
listen-address=fc00:db8:ac10:fe01::1
listen-address=fc00:db8:ac10:fd01::1
listen-address=10.24.10.1
srv-host=name.tcp.,,,,
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

View File

@ -0,0 +1,18 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
local=//
bind-dynamic
interface=virbr0
srv-host=name.tcp.test-domain-name,.,1024,10,10
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

View File

@ -0,0 +1,18 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
local=//
bind-dynamic
interface=virbr0
txt-record=example,example value
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

View File

@ -0,0 +1,19 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
local=//
bind-dynamic
interface=virbr0
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
dhcp-range=2001:db8:ac10:fd01::1,ra-only

View File

@ -0,0 +1,23 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit netboot
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
domain=example.com
expand-hosts
local=/example.com/
bind-interfaces
except-interface=lo
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

View File

@ -0,0 +1,21 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit netboot
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
domain=example.com
expand-hosts
local=/example.com/
bind-interfaces
except-interface=lo
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

View File

@ -0,0 +1,12 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit local
## of other applications using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
domain-needed
local=//
bind-dynamic
interface=virbr1
addn-hosts=/var/lib/libvirt/dnsmasq/local.addnhosts

View File

@ -15,42 +15,11 @@
#include "memory.h" #include "memory.h"
#include "network/bridge_driver.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 static int
testCompareXMLToArgvFiles(const char *inxml, const char *outargv, dnsmasqCapsPtr caps) testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr caps)
{ {
char *inXmlData = NULL; char *inXmlData = NULL;
char *outArgvData = NULL; char *outConfData = NULL;
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
virNetworkDefPtr dev = NULL; virNetworkDefPtr dev = NULL;
@ -62,10 +31,7 @@ testCompareXMLToArgvFiles(const char *inxml, const char *outargv, dnsmasqCapsPtr
if (virtTestLoadFile(inxml, &inXmlData) < 0) if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(outargv, &outArgvData) < 0) if (virtTestLoadFile(outconf, &outConfData) < 0)
goto fail;
if (replaceTokens(&outArgvData, "@DNSMASQ@", DNSMASQ))
goto fail; goto fail;
if (!(dev = virNetworkDefParseString(inXmlData))) if (!(dev = virNetworkDefParseString(inXmlData)))
@ -80,14 +46,12 @@ testCompareXMLToArgvFiles(const char *inxml, const char *outargv, dnsmasqCapsPtr
if (dctx == NULL) if (dctx == NULL)
goto fail; goto fail;
if (networkBuildDhcpDaemonCommandLine(obj, &cmd, pidfile, dctx, caps) < 0) if (networkDnsmasqConfContents(obj, pidfile, &actual,
dctx, caps) < 0)
goto fail; goto fail;
if (!(actual = virCommandToString(cmd))) if (STRNEQ(outConfData, actual)) {
goto fail; virtTestDifference(stderr, outConfData, actual);
if (STRNEQ(outArgvData, actual)) {
virtTestDifference(stderr, outArgvData, actual);
goto fail; goto fail;
} }
@ -95,7 +59,7 @@ testCompareXMLToArgvFiles(const char *inxml, const char *outargv, dnsmasqCapsPtr
fail: fail:
VIR_FREE(inXmlData); VIR_FREE(inXmlData);
VIR_FREE(outArgvData); VIR_FREE(outConfData);
VIR_FREE(actual); VIR_FREE(actual);
VIR_FREE(pidfile); VIR_FREE(pidfile);
virCommandFree(cmd); virCommandFree(cmd);
@ -110,21 +74,21 @@ typedef struct {
} testInfo; } testInfo;
static int static int
testCompareXMLToArgvHelper(const void *data) testCompareXMLToConfHelper(const void *data)
{ {
int result = -1; int result = -1;
const testInfo *info = data; const testInfo *info = data;
char *inxml = NULL; char *inxml = NULL;
char *outxml = NULL; char *outxml = NULL;
if (virAsprintf(&inxml, "%s/networkxml2argvdata/%s.xml", if (virAsprintf(&inxml, "%s/networkxml2confdata/%s.xml",
abs_srcdir, info->name) < 0 || abs_srcdir, info->name) < 0 ||
virAsprintf(&outxml, "%s/networkxml2argvdata/%s.argv", virAsprintf(&outxml, "%s/networkxml2confdata/%s.conf",
abs_srcdir, info->name) < 0) { abs_srcdir, info->name) < 0) {
goto cleanup; goto cleanup;
} }
result = testCompareXMLToArgvFiles(inxml, outxml, info->caps); result = testCompareXMLToConfFiles(inxml, outxml, info->caps);
cleanup: cleanup:
VIR_FREE(inxml); VIR_FREE(inxml);
@ -163,8 +127,8 @@ mymain(void)
\ \
info.name = xname; \ info.name = xname; \
info.caps = xcaps; \ info.caps = xcaps; \
if (virtTestRun("Network XML-2-Argv " xname, \ if (virtTestRun("Network XML-2-Conf " xname, \
1, testCompareXMLToArgvHelper, &info) < 0) { \ 1, testCompareXMLToConfHelper, &info) < 0) { \
ret = -1; \ ret = -1; \
} \ } \
} while (0) } while (0)