Hi -
It's currently impossible to tell which upstream DNS servers are in use by
dnsmasq; this is particularly irksome when they're controlled by
NetworkManager or similar (grepping for syslog messages doesn't count as
instrumentation...)
Here's a trivial implementation of a GetServes DBus call that returns the
servers/domains (formatted for re-use in --servers flags). Ideally, there'd
be a call like GetConfig or similar that dumps the entire active
configuration in config-file format...
Gabe
--
Do not think by infection, catching an opinion like a cold.
diff --git a/dbus/DBus-interface b/dbus/DBus-interface
index 2db5c30..482c37e 100644
--- a/dbus/DBus-interface
+++ b/dbus/DBus-interface
@@ -35,6 +35,11 @@ GetVersion
--
Returns a string containing the version of dnsmasq running.
+GetServers
+--
+Returns a string containing the current set of upstream servers (and the
+domains they're used for, if set).
+
ClearCache
--
Returns nothing. Clears the domain name cache and re-reads
diff --git a/po/de.po b/po/de.po
index a8a83e0..874d3f8 100644
--- a/po/de.po
+++ b/po/de.po
@@ -1412,7 +1412,11 @@ msgstr "DNS-Dienst auf lokale Subnetze eingeschränkt"
msgid "compile time options: %s"
msgstr "Übersetzungsoptionen: %s"
-#: dnsmasq.c:751
+#: dnsmasq.c:766
+msgid "DBus support enabled: connected to session bus"
+msgstr "DBus-Unterstützung eingeschaltet: mit Sessionbus verbunden"
+
+#: dnsmasq.c:768
msgid "DBus support enabled: connected to system bus"
msgstr "DBus-Unterstützung eingeschaltet: mit Systembus verbunden"
diff --git a/src/dbus.c b/src/dbus.c
index 6a78b20..a8998d3 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -35,6 +35,9 @@ const char* introspection_xml_template =
"\n"
" \n"
"\n"
+"\n"
+" \n"
+"\n"
#ifdef HAVE_LOOP
"\n"
" \n"
@@ -641,6 +644,38 @@ DBusHandlerResult message_handler(DBusConnection *connection,
dbus_message_append_args(reply, DBUS_TYPE_STRING, &v, DBUS_TYPE_INVALID);
}
+ else if (strcmp(method, "GetServers") == 0)
+{
+ reply = dbus_message_new_method_return(message);
+ char *servers = NULL;
+ size_t servers_len = 0;
+ for (struct server *serv = daemon->servers; serv; serv = serv->next) {
+int domain_len = serv->domain ? strlen(serv->domain) : 0;
+/* "/" + domain + "/" + address + NUL */
+int buf_len = domain_len + 2 + ADDRSTRLEN + 1;
+char *server_flag = calloc(buf_len, 1);
+char *tmp = server_flag;
+if (serv->domain) {
+ *tmp++ = '/';
+ strcpy(tmp, serv->domain);
+ tmp += domain_len;
+ *tmp++ = '/';
+}
+prettyprint_addr(&serv->addr, tmp);
+
+servers = realloc(servers, servers_len + 1 + buf_len);
+tmp = servers + servers_len;
+if (servers_len > 0)
+ {
+*tmp++ = '\n';
+servers_len++;
+ }
+strcpy(tmp, server_flag);
+servers_len += strlen(server_flag);
+free(server_flag);
+ }
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &servers, DBUS_TYPE_INVALID);
+}
#ifdef HAVE_LOOP
else if (strcmp(method, "GetLoopServers") == 0)
{
@@ -721,8 +756,16 @@ char *dbus_init(void)
DBusMessage *message;
dbus_error_init (&dbus_error);
- if (!(connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error)))
-return NULL;
+ if (option_bool(OPT_DEBUG))
+{
+ if (!(connection = dbus_bus_get (DBUS_BUS_SESSION, &dbus_error)))
+return NULL;
+}
+ else
+{
+ if (!(connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error)))
+return NULL;
+}
dbus_connection_set_exit_on_disconnect(connection, FALSE);
dbus_connection_set_watch_functions(connection, add_watch, remove_watch,
diff --git a/src/dnsmasq.c b/src/dnsmasq.c
index ff2c7f2..6d02bda 100644
--- a/src/dnsmasq.c
+++ b/src/dnsmasq.c
@@ -761,7 +761,12 @@ int main (int argc, char **argv)
if (option_bool(OPT_DBUS))
{
if (daemon->dbus)
- my_syslog(LOG_INFO, _("DBus support enabled: connected to system bus"));
+{
+ if (option_bool(OPT_DEBUG))
+my_syslog(LOG_INFO, _("DBus support enabled: connected to session bus"));
+ else
+my_syslog(LOG_INFO, _("DBus support enabled: connected to system bus"));
+}
else
my_syslog(LOG_INFO, _("DBus support enabled: bus connection pending"));
}
___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss