[PATCH] dnsmasq: support local custom configuration



In some cases it's useful to add additional configurations to the
dnsmasq instance handled by the dns plugin. One use case is defining
additional dns servers for domains that are not controlled by NM, for
example libvirt networks:

 local=/virbr1.myhost.example.com/192.168.122.2
 local=/122.168.192.in-addr.arpa/192.168.122.2

This patch adds the support for the configuration directory that usually
will be defined as /etc/nm-dnsmasq.d.

There is a potential risk allowing custom configurations but by default
the configuration directory will be empty (or won't exist) and it's the
sysadmin's responsibility to use it wisely.

Signed-off-by: Federico Simoncelli <fsimonce redhat com>
---
 src/dns-manager/Makefile.am      |    1 +
 src/dns-manager/nm-dns-dnsmasq.c |   12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/src/dns-manager/Makefile.am b/src/dns-manager/Makefile.am
index fd31b14..43d954d 100644
--- a/src/dns-manager/Makefile.am
+++ b/src/dns-manager/Makefile.am
@@ -25,6 +25,7 @@ libdns_manager_la_CPPFLAGS = \
 	$(LIBNL_CFLAGS) \
 	$(DBUS_CFLAGS) \
 	$(GLIB_CFLAGS) \
+	-DSYSCONFDIR=\"$(sysconfdir)\" \
 	-DLOCALSTATEDIR=\"$(localstatedir)\"
 
 libdns_manager_la_LIBADD = \
diff --git a/src/dns-manager/nm-dns-dnsmasq.c b/src/dns-manager/nm-dns-dnsmasq.c
index 8e216f4..57989ad 100644
--- a/src/dns-manager/nm-dns-dnsmasq.c
+++ b/src/dns-manager/nm-dns-dnsmasq.c
@@ -41,6 +41,7 @@ G_DEFINE_TYPE (NMDnsDnsmasq, nm_dns_dnsmasq, NM_TYPE_DNS_PLUGIN)
 
 #define PIDFILE LOCALSTATEDIR "/run/nm-dns-dnsmasq.pid"
 #define CONFFILE LOCALSTATEDIR "/run/nm-dns-dnsmasq.conf"
+#define CONFDIR SYSCONFDIR "/nm-dnsmasq.d"
 
 typedef struct {
 	guint32 foo;
@@ -245,8 +246,9 @@ update (NMDnsPlugin *plugin,
 {
 	NMDnsDnsmasq *self = NM_DNS_DNSMASQ (plugin);
 	GString *conf;
+	struct stat confdst;
 	GSList *iter;
-	const char *argv[11];
+	const char *argv[12];
 	GError *error = NULL;
 	int ignored;
 	GPid pid = 0;
@@ -311,6 +313,14 @@ update (NMDnsPlugin *plugin,
 	argv[9] = "--proxy-dnssec"; /* Allow DNSSEC to pass through */
 	argv[10] = NULL;
 
+	/* Add the additional configuration directory when present */
+	if (stat (CONFDIR, &confdst) == 0) {
+		if (S_ISDIR (confdst.st_mode)) {
+			argv[10] = "--conf-dir=" CONFDIR;
+			argv[11] = NULL;
+		}
+	}
+
 	/* And finally spawn dnsmasq */
 	pid = nm_dns_plugin_child_spawn (NM_DNS_PLUGIN (self), argv, PIDFILE, "bin/dnsmasq");
 
-- 
1.7.7.6



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