summary refs log tree commit diff
path: root/src/dns-manager
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2011-03-18 20:17:47 +0100
committerMichael Biebl <biebl@debian.org>2011-03-18 20:17:47 +0100
commite22c6e05e9ebc6cce941762020c5710b8014677b (patch)
tree7e9fd7f8ae24a94b03f683e0cef9a346968e1e8b /src/dns-manager
parenta6b89d35fabd9f5934b84d7cde22e9268f92c3d3 (diff)
Imported Upstream version 0.8.3.998 upstream/0.8.3.998
Diffstat (limited to 'src/dns-manager')
-rw-r--r--src/dns-manager/Makefile.am4
-rw-r--r--src/dns-manager/Makefile.in21
-rw-r--r--src/dns-manager/nm-dns-dnsmasq.c22
-rw-r--r--src/dns-manager/nm-dns-manager.c9
-rw-r--r--src/dns-manager/nm-dns-utils.c99
-rw-r--r--src/dns-manager/nm-dns-utils.h28
6 files changed, 172 insertions, 11 deletions
diff --git a/src/dns-manager/Makefile.am b/src/dns-manager/Makefile.am
index 1ffe62dc..7b5fc4f8 100644
--- a/src/dns-manager/Makefile.am
+++ b/src/dns-manager/Makefile.am
@@ -14,7 +14,9 @@ libdns_manager_la_SOURCES = \
 	nm-dns-dnsmasq.h \
 	nm-dns-dnsmasq.c \
 	nm-dns-bind.h \
-	nm-dns-bind.c
+	nm-dns-bind.c \
+	nm-dns-utils.h \
+	nm-dns-utils.c
 
 libdns_manager_la_CPPFLAGS = \
 	$(DBUS_CFLAGS) \
diff --git a/src/dns-manager/Makefile.in b/src/dns-manager/Makefile.in
index 496d3756..69b76815 100644
--- a/src/dns-manager/Makefile.in
+++ b/src/dns-manager/Makefile.in
@@ -57,7 +57,8 @@ libdns_manager_la_DEPENDENCIES =  \
 am_libdns_manager_la_OBJECTS = libdns_manager_la-nm-dns-manager.lo \
 	libdns_manager_la-nm-dns-plugin.lo \
 	libdns_manager_la-nm-dns-dnsmasq.lo \
-	libdns_manager_la-nm-dns-bind.lo
+	libdns_manager_la-nm-dns-bind.lo \
+	libdns_manager_la-nm-dns-utils.lo
 libdns_manager_la_OBJECTS = $(am_libdns_manager_la_OBJECTS)
 AM_V_lt = $(am__v_lt_$(V))
 am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
@@ -185,6 +186,10 @@ MSGFMT_OPTS = @MSGFMT_OPTS@
 MSGMERGE = @MSGMERGE@
 NM = @NM@
 NMEDIT = @NMEDIT@
+NM_MAJOR_VERSION = @NM_MAJOR_VERSION@
+NM_MICRO_VERSION = @NM_MICRO_VERSION@
+NM_MINOR_VERSION = @NM_MINOR_VERSION@
+NM_VERSION = @NM_VERSION@
 NSS_CFLAGS = @NSS_CFLAGS@
 NSS_LIBS = @NSS_LIBS@
 OBJDUMP = @OBJDUMP@
@@ -199,6 +204,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
 PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
+PKGCONFIG_PATH = @PKGCONFIG_PATH@
 PKG_CONFIG = @PKG_CONFIG@
 PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
 PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
@@ -289,7 +295,9 @@ libdns_manager_la_SOURCES = \
 	nm-dns-dnsmasq.h \
 	nm-dns-dnsmasq.c \
 	nm-dns-bind.h \
-	nm-dns-bind.c
+	nm-dns-bind.c \
+	nm-dns-utils.h \
+	nm-dns-utils.c
 
 libdns_manager_la_CPPFLAGS = \
 	$(DBUS_CFLAGS) \
@@ -357,6 +365,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdns_manager_la-nm-dns-dnsmasq.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdns_manager_la-nm-dns-manager.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdns_manager_la-nm-dns-plugin.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdns_manager_la-nm-dns-utils.Plo@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@@ -417,6 +426,14 @@ libdns_manager_la-nm-dns-bind.lo: nm-dns-bind.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdns_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libdns_manager_la-nm-dns-bind.lo `test -f 'nm-dns-bind.c' || echo '$(srcdir)/'`nm-dns-bind.c
 
+libdns_manager_la-nm-dns-utils.lo: nm-dns-utils.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdns_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libdns_manager_la-nm-dns-utils.lo -MD -MP -MF $(DEPDIR)/libdns_manager_la-nm-dns-utils.Tpo -c -o libdns_manager_la-nm-dns-utils.lo `test -f 'nm-dns-utils.c' || echo '$(srcdir)/'`nm-dns-utils.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libdns_manager_la-nm-dns-utils.Tpo $(DEPDIR)/libdns_manager_la-nm-dns-utils.Plo
+@am__fastdepCC_FALSE@	$(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='nm-dns-utils.c' object='libdns_manager_la-nm-dns-utils.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdns_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libdns_manager_la-nm-dns-utils.lo `test -f 'nm-dns-utils.c' || echo '$(srcdir)/'`nm-dns-utils.c
+
 mostlyclean-libtool:
 	-rm -f *.lo
 
diff --git a/src/dns-manager/nm-dns-dnsmasq.c b/src/dns-manager/nm-dns-dnsmasq.c
index 41c8e2a6..9cc01978 100644
--- a/src/dns-manager/nm-dns-dnsmasq.c
+++ b/src/dns-manager/nm-dns-dnsmasq.c
@@ -33,6 +33,7 @@
 #include "nm-logging.h"
 #include "nm-ip4-config.h"
 #include "nm-ip6-config.h"
+#include "nm-dns-utils.h"
 
 G_DEFINE_TYPE (NMDnsDnsmasq, nm_dns_dnsmasq, NM_TYPE_DNS_PLUGIN)
 
@@ -75,9 +76,11 @@ add_ip4_config (GString *str, NMIP4Config *ip4, gboolean split)
 	gboolean added = FALSE;
 
 	if (split) {
+		char **domains, **iter;
+
 		/* FIXME: it appears that dnsmasq can only handle one nameserver
-		 * per domain (at the manpage seems to indicate that) so only use
-		 * the first nameserver here.
+		 * per domain (and the manpage says this too) so only use the first
+		 * nameserver here.
 		 */
 		addr.s_addr = nm_ip4_config_get_nameserver (ip4, 0);
 		memset (&buf[0], 0, sizeof (buf));
@@ -103,6 +106,17 @@ add_ip4_config (GString *str, NMIP4Config *ip4, gboolean split)
 				added = TRUE;
 			}
 		}
+
+		/* Ensure reverse-DNS works by directing queries for in-addr.arpa
+		 * domains to the split domain's nameserver.
+		 */
+		domains = nm_dns_utils_get_ip4_rdns_domains (ip4);
+		if (domains) {
+			for (iter = domains; iter && *iter; iter++)
+				g_string_append_printf (str, "server=/%s/%s\n", *iter, buf);
+			g_strfreev (domains);
+			added = TRUE;
+		}
 	}
 
 	/* If no searches or domains, just add the namservers */
@@ -216,7 +230,7 @@ update (NMDnsPlugin *plugin,
 	}
 
 	/* Now add interface configs without split DNS */
-	for (iter = (GSList *) dev_configs; iter;iter = g_slist_next (iter)) {
+	for (iter = (GSList *) dev_configs; iter; iter = g_slist_next (iter)) {
 		if (NM_IS_IP4_CONFIG (iter->data))
 			add_ip4_config (conf, NM_IP4_CONFIG (iter->data), FALSE);
 		else if (NM_IS_IP6_CONFIG (iter->data))
@@ -224,7 +238,7 @@ update (NMDnsPlugin *plugin,
 	}
 
 	/* And any other random configs */
-	for (iter = (GSList *) other_configs; iter;iter = g_slist_next (iter)) {
+	for (iter = (GSList *) other_configs; iter; iter = g_slist_next (iter)) {
 		if (NM_IS_IP4_CONFIG (iter->data))
 			add_ip4_config (conf, NM_IP4_CONFIG (iter->data), FALSE);
 		else if (NM_IS_IP6_CONFIG (iter->data))
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c
index 7a6fbbc9..32800d0b 100644
--- a/src/dns-manager/nm-dns-manager.c
+++ b/src/dns-manager/nm-dns-manager.c
@@ -16,7 +16,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Copyright (C) 2004 - 2005 Colin Walters <walters@redhat.com>
- * Copyright (C) 2004 - 2010 Red Hat, Inc.
+ * Copyright (C) 2004 - 2011 Red Hat, Inc.
  * Copyright (C) 2005 - 2008 Novell, Inc.
  *   and others
  */
@@ -583,6 +583,7 @@ update_dns (NMDnsManager *self,
 	rc.nameservers = g_ptr_array_new ();
 	rc.domain = NULL;
 	rc.searches = g_ptr_array_new ();
+	rc.nis_domain = NULL;
 	rc.nis_servers = g_ptr_array_new ();
 
 	if (priv->ip4_vpn_config)
@@ -860,7 +861,7 @@ nm_dns_manager_remove_ip4_config (NMDnsManager *mgr,
 
 	g_object_unref (config);
 
-	if (config_changed (mgr))
+	if (!config_changed (mgr))
 		return TRUE;
 
 	if (!update_dns (mgr, iface, FALSE, &error)) {
@@ -905,7 +906,7 @@ nm_dns_manager_add_ip6_config (NMDnsManager *mgr,
 	if (!g_slist_find (priv->configs, config))
 		priv->configs = g_slist_append (priv->configs, g_object_ref (config));
 
-	if (config_changed (mgr))
+	if (!config_changed (mgr))
 		return TRUE;
 
 	if (!update_dns (mgr, iface, FALSE, &error)) {
@@ -945,7 +946,7 @@ nm_dns_manager_remove_ip6_config (NMDnsManager *mgr,
 
 	g_object_unref (config);	
 
-	if (config_changed (mgr))
+	if (!config_changed (mgr))
 		return TRUE;
 
 	if (!update_dns (mgr, iface, FALSE, &error)) {
diff --git a/src/dns-manager/nm-dns-utils.c b/src/dns-manager/nm-dns-utils.c
new file mode 100644
index 00000000..615adfd1
--- /dev/null
+++ b/src/dns-manager/nm-dns-utils.c
@@ -0,0 +1,99 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ */
+
+#include <arpa/inet.h>
+#include <string.h>
+
+#include "nm-dns-utils.h"
+#include "nm-utils.h"
+
+static void
+add_ip4_to_rdns_array (guint32 ip, GPtrArray *domains) /* network byte order */
+{
+	guint32 defprefix;
+	guchar *p;
+	char *str = NULL;
+	int i;
+
+	defprefix = nm_utils_ip4_get_default_prefix (ip);
+
+	/* Convert to host byte order, mask the host bits, and convert back */
+	ip = ntohl (ip);
+	ip &= 0xFFFFFFFF << (32 - defprefix);
+	ip = htonl (ip);
+	p = (guchar *) &ip;
+
+	if (defprefix == 8)
+		str = g_strdup_printf ("%u.in-addr.arpa", p[0] & 0xFF);
+	else if (defprefix == 16)
+		str = g_strdup_printf ("%u.%u.in-addr.arpa", p[1] & 0xFF, p[0] & 0xFF);
+	else if (defprefix == 24)
+		str = g_strdup_printf ("%u.%u.%u.in-addr.arpa", p[2] & 0xFF, p[1] & 0xFF, p[0] & 0xFF);
+
+	g_return_if_fail (str != NULL);
+
+	/* Suppress duplicates */
+	for (i = 0; i < domains->len; i++) {
+		if (strcmp (str, g_ptr_array_index (domains, i)) == 0)
+			break;
+	}
+
+	if (i == domains->len)
+		g_ptr_array_add (domains, str);
+	else
+		g_free (str);
+}
+
+char **
+nm_dns_utils_get_ip4_rdns_domains (NMIP4Config *ip4)
+{
+	GPtrArray *domains = NULL;
+	int i;
+
+	g_return_val_if_fail (ip4 != NULL, NULL);
+
+	domains = g_ptr_array_sized_new (5);
+
+	/* To calculate the reverse DNS domains for this IP4 config, we take
+	 * all the IP addresses and routes in the config, calculate the network
+	 * portion, and convert that to classful, and use the network bits for
+	 * the final domain.  FIXME: better handle classless routing, which might
+	 * require us to add multiple domains for each actual network prefix to
+	 * cover all the separate networks in that block.
+	 */
+
+	for (i = 0; i < nm_ip4_config_get_num_addresses (ip4); i++) {
+		NMIP4Address *addr = nm_ip4_config_get_address (ip4, i);
+
+		add_ip4_to_rdns_array (nm_ip4_address_get_address (addr), domains);
+	}
+
+	for (i = 0; i < nm_ip4_config_get_num_routes (ip4); i++) {
+		NMIP4Route *route = nm_ip4_config_get_route (ip4, i);
+
+		add_ip4_to_rdns_array (nm_ip4_route_get_dest (route), domains);
+	}
+
+	/* Terminating NULL so we can use g_strfreev() to free it */
+	g_ptr_array_add (domains, NULL);
+
+	/* Free the array and return NULL if the only element was the ending NULL */
+	return (char **) g_ptr_array_free (domains, (domains->len == 1));
+}
+
diff --git a/src/dns-manager/nm-dns-utils.h b/src/dns-manager/nm-dns-utils.h
new file mode 100644
index 00000000..daa6711c
--- /dev/null
+++ b/src/dns-manager/nm-dns-utils.h
@@ -0,0 +1,28 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ */
+
+#ifndef NM_DNS_UTILS_H
+#define NM_DNS_UTILS_H
+
+#include "nm-ip4-config.h"
+
+char **nm_dns_utils_get_ip4_rdns_domains (NMIP4Config *ip4);
+
+#endif  /* NM_DNS_UTILS_H */
+