mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-26 23:55:23 +00:00
9065cfaa88
If you define a libvirt virtual network with one or more IP addresses, it starts up an instance of dnsmasq. It's always been possible to avoid dnsmasq's dhcp server (simply don't include a <dhcp> element), but until now it wasn't possible to avoid having the DNS server listening; even if the network has no <dns> element, it is started using default settings. This patch adds a new attribute to <dns>: enable='yes|no'. For backward compatibility, it defaults to 'yes', but if you don't want a DNS server created for the network, you can simply add: <dns enable='no'/> to the network configuration, and next time the network is started there will be no dns server created (if there is dhcp configuration, dnsmasq will be started with "port=0" which disables the DNS server; if there is no dhcp configuration, dnsmasq won't be started at all).
141 lines
3.9 KiB
C
141 lines
3.9 KiB
C
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
#include <fcntl.h>
|
|
|
|
#include "internal.h"
|
|
#include "testutils.h"
|
|
#include "network_conf.h"
|
|
#include "vircommand.h"
|
|
#include "viralloc.h"
|
|
#include "network/bridge_driver.h"
|
|
#include "virstring.h"
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
static int
|
|
testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr caps)
|
|
{
|
|
char *actual = NULL;
|
|
int ret = -1;
|
|
virNetworkDefPtr dev = NULL;
|
|
virNetworkObjPtr obj = NULL;
|
|
virCommandPtr cmd = NULL;
|
|
char *pidfile = NULL;
|
|
dnsmasqContext *dctx = NULL;
|
|
|
|
if (!(dev = virNetworkDefParseFile(inxml)))
|
|
goto fail;
|
|
|
|
if (!(obj = virNetworkObjNew()))
|
|
goto fail;
|
|
|
|
obj->def = dev;
|
|
dctx = dnsmasqContextNew(dev->name, "/var/lib/libvirt/dnsmasq");
|
|
|
|
if (dctx == NULL)
|
|
goto fail;
|
|
|
|
if (networkDnsmasqConfContents(obj, pidfile, &actual,
|
|
dctx, caps) < 0)
|
|
goto fail;
|
|
|
|
if (virTestCompareToFile(actual, outconf) < 0)
|
|
goto fail;
|
|
|
|
ret = 0;
|
|
|
|
fail:
|
|
VIR_FREE(actual);
|
|
VIR_FREE(pidfile);
|
|
virCommandFree(cmd);
|
|
virObjectUnref(obj);
|
|
dnsmasqContextFree(dctx);
|
|
return ret;
|
|
}
|
|
|
|
typedef struct {
|
|
const char *name;
|
|
dnsmasqCapsPtr caps;
|
|
} testInfo;
|
|
|
|
static int
|
|
testCompareXMLToConfHelper(const void *data)
|
|
{
|
|
int result = -1;
|
|
const testInfo *info = data;
|
|
char *inxml = NULL;
|
|
char *outxml = NULL;
|
|
|
|
if (virAsprintf(&inxml, "%s/networkxml2confdata/%s.xml",
|
|
abs_srcdir, info->name) < 0 ||
|
|
virAsprintf(&outxml, "%s/networkxml2confdata/%s.conf",
|
|
abs_srcdir, info->name) < 0) {
|
|
goto cleanup;
|
|
}
|
|
|
|
result = testCompareXMLToConfFiles(inxml, outxml, info->caps);
|
|
|
|
cleanup:
|
|
VIR_FREE(inxml);
|
|
VIR_FREE(outxml);
|
|
|
|
return result;
|
|
}
|
|
|
|
static int
|
|
mymain(void)
|
|
{
|
|
int ret = 0;
|
|
dnsmasqCapsPtr restricted
|
|
= dnsmasqCapsNewFromBuffer("Dnsmasq version 2.48", DNSMASQ);
|
|
dnsmasqCapsPtr full
|
|
= dnsmasqCapsNewFromBuffer("Dnsmasq version 2.63\n--bind-dynamic", DNSMASQ);
|
|
dnsmasqCapsPtr dhcpv6
|
|
= dnsmasqCapsNewFromBuffer("Dnsmasq version 2.64\n--bind-dynamic", DNSMASQ);
|
|
|
|
#define DO_TEST(xname, xcaps) \
|
|
do { \
|
|
static testInfo info; \
|
|
\
|
|
info.name = xname; \
|
|
info.caps = xcaps; \
|
|
if (virTestRun("Network XML-2-Conf " xname, \
|
|
testCompareXMLToConfHelper, &info) < 0) { \
|
|
ret = -1; \
|
|
} \
|
|
} while (0)
|
|
|
|
DO_TEST("isolated-network", restricted);
|
|
DO_TEST("netboot-network", restricted);
|
|
DO_TEST("netboot-proxy-network", restricted);
|
|
DO_TEST("nat-network-dns-srv-record-minimal", restricted);
|
|
DO_TEST("nat-network-name-with-quotes", restricted);
|
|
DO_TEST("routed-network", full);
|
|
DO_TEST("routed-network-no-dns", full);
|
|
DO_TEST("open-network", full);
|
|
DO_TEST("nat-network", dhcpv6);
|
|
DO_TEST("nat-network-dns-txt-record", full);
|
|
DO_TEST("nat-network-dns-srv-record", full);
|
|
DO_TEST("nat-network-dns-hosts", full);
|
|
DO_TEST("nat-network-dns-forward-plain", full);
|
|
DO_TEST("nat-network-dns-forwarders", full);
|
|
DO_TEST("nat-network-dns-local-domain", full);
|
|
DO_TEST("dhcp6-network", dhcpv6);
|
|
DO_TEST("dhcp6-nat-network", dhcpv6);
|
|
DO_TEST("dhcp6host-routed-network", dhcpv6);
|
|
|
|
virObjectUnref(dhcpv6);
|
|
virObjectUnref(full);
|
|
virObjectUnref(restricted);
|
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
}
|
|
|
|
VIRT_TEST_MAIN(mymain)
|