Re: dnsmasq
- From: Howard Chu <hyc symas com>
- To: Alexander Sack <asac jwsdot com>
- Cc: networkmanager-list gnome org
- Subject: Re: dnsmasq
- Date: Sat, 06 Sep 2008 13:41:28 -0700
Howard Chu wrote:
Alexander Sack wrote:
Is there a particular reason to put that include here instead of the
.c file where its used?
Not really. I put it where<dbus/dbus.h> was included because they're related,
but you're right, it should just go in the .c file.
Revised patch, doesn't touch the nm-named-manager.h file.
--
-- Howard Chu
CTO, Symas Corp. http://www.symas.com
Director, Highland Sun http://highlandsun.com/hyc/
Chief Architect, OpenLDAP http://www.openldap.org/project/
Index: nm-device-wifi.c
===================================================================
--- nm-device-wifi.c (revision 4043)
+++ nm-device-wifi.c (working copy)
@@ -969,10 +969,10 @@
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
if (s_con == NULL)
continue;
+ if (!s_con->autoconnect)
+ continue;
if (strcmp (s_con->type, NM_SETTING_WIRELESS_SETTING_NAME))
continue;
- if (!s_con->autoconnect)
- continue;
s_wireless = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS);
if (!s_wireless)
Index: named-manager/nm-named-manager.c
===================================================================
--- named-manager/nm-named-manager.c (revision 4043)
+++ 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]