Index: src/named-manager/nm-named-manager.c
===================================================================
--- src/named-manager/nm-named-manager.c	(revision 4055)
+++ src/named-manager/nm-named-manager.c	(working copy)
@@ -36,10 +36,12 @@
 #include <glib/gi18n.h>
 
 #include "nm-named-manager.h"
+#include "nm-dbus-manager.h"
 #include "nm-ip4-config.h"
 #include "nm-utils.h"
 #include "NetworkManagerSystem.h"
 #include "NetworkManagerUtils.h"
+#include <dbus/dbus-glib-lowlevel.h>
 
 #ifdef HAVE_SELINUX
 #include <selinux/selinux.h>
@@ -51,6 +53,11 @@
 
 #define ADDR_BUF_LEN 50
 
+#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq"
+#define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
+#define DNSMASQ_IFACE DNSMASQ_SERVICE
+/* dnsmasq doesn't specify any particular interface name */
+
 G_DEFINE_TYPE(NMNamedManager, nm_named_manager, G_TYPE_OBJECT)
 
 #define NM_NAMED_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
@@ -62,6 +69,7 @@
 	NMIP4Config *   vpn_config;
 	NMIP4Config *   device_config;
 	GSList *        configs;
+	DBusGProxy *dnsmasq_proxy;
 
 	gboolean disposed;
 };
@@ -356,7 +364,64 @@
 	return *error ? FALSE : TRUE;
 }
 
+static gboolean
+dnsmasq_update(NMNamedManager *mgr)
+{
+	NMNamedManagerPrivate *priv;
+	GSList *iter;
+	DBusMessage *msg;
+	const char *domain;
 
+	priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
+
+	msg = dbus_message_new_method_call(
+		DNSMASQ_SERVICE,
+		DNSMASQ_PATH,
+		DNSMASQ_IFACE,
+		"SetServers");
+	for (iter = priv->configs; iter; iter = g_slist_next (iter)) {
+		NMIP4Config *config = NM_IP4_CONFIG (iter->data);
+		int i, num_nameservers, num_domains;
+
+		/* assume VPN nameserver should only be used for
+		 * the VPN's domain
+		 */
+		if (priv->vpn_config == config)
+		{
+			num_domains = nm_ip4_config_get_num_domains (config);
+		} else
+		{
+			num_domains = 0;
+		}
+		num_nameservers = nm_ip4_config_get_num_nameservers (config);
+		for (i = 0; i < num_nameservers; i++) {
+			guint32 addr;
+			int j;
+
+			addr = htonl(nm_ip4_config_get_nameserver (config, i));
+			dbus_message_append_args(msg,
+				DBUS_TYPE_UINT32, &addr,
+				DBUS_TYPE_INVALID);
+			for (j=0; j<num_domains; j++) {
+				domain = nm_ip4_config_get_domain (config, j);
+				dbus_message_append_args(msg,
+					DBUS_TYPE_STRING, &domain,
+					DBUS_TYPE_INVALID);
+			}
+		}
+	}
+	dbus_g_proxy_send(priv->dnsmasq_proxy, msg, NULL);
+	dbus_message_unref(msg);
+	return TRUE;
+}
+
+static void
+dnsmasq_resend(DBusGProxy *proxy, gpointer data)
+{
+	NMNamedManager *mgr = NM_NAMED_MANAGER(data);
+	dnsmasq_update(mgr);
+}
+
 static gboolean
 rewrite_resolv_conf (NMNamedManager *mgr, const char *iface, GError **error)
 {
@@ -378,6 +443,19 @@
 
 	priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
 
+	if (priv->dnsmasq_proxy)
+	{
+		GString *ver;
+		/* see if dnsmasq is listening */
+		if (dbus_g_proxy_call(priv->dnsmasq_proxy, "GetVersion", error,
+			G_TYPE_INVALID, G_TYPE_STRING, &ver, G_TYPE_INVALID ))
+		{
+			success = dnsmasq_update(mgr);
+			if (success)
+				return success;
+		}
+	}
+
 	/* Construct the composite config from all the currently active IP4Configs */
 	composite = nm_ip4_config_new ();
 
@@ -548,6 +626,21 @@
 static void
 nm_named_manager_init (NMNamedManager *mgr)
 {
+	NMNamedManagerPrivate *priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
+	NMDBusManager	*dbus_mgr;
+
+	dbus_mgr = nm_dbus_manager_get ();
+	priv->dnsmasq_proxy = dbus_g_proxy_new_for_name(nm_dbus_manager_get_connection(dbus_mgr),
+		DNSMASQ_SERVICE,
+		DNSMASQ_PATH,
+		DNSMASQ_IFACE);
+	if (priv->dnsmasq_proxy)
+	{
+		dbus_g_proxy_add_signal(priv->dnsmasq_proxy, "Up",
+			G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(priv->dnsmasq_proxy, "Up",
+			G_CALLBACK(dnsmasq_resend), mgr, NULL);
+	}
 }
 
 static void
