NetworkManager/rh978435-dns-none.patch

585 lines
19 KiB
Diff

Took these three 'master' commits and rebased them to nm-0-9-8:
commit a15558daed7b94fd810303451089f7799d3eb65d
commit df1f4bee0ed048c1b434d65e5d0cd884f2e7040b
commit 282a9720ab4432b919e0fa57a9b71dfe87ee8ac1
---
commit a15558daed7b94fd810303451089f7799d3eb65d
Author: Dan Winship <danw@gnome.org>
Date: Mon Mar 11 16:15:14 2013 -0400
dns-manager: minor cleanups
Remove the unused NMDnsPlugin::init method, some unused #includes, and
an out-of-date comment.
Use the correct macro for the default "/etc/resolv.conf" path.
Simplify NMDnsManager::dispose() a bit.
Make nm_dns_dnsmasq_new() return an NMDnsPlugin* rather than
NMDnsDnsmasq*.
diff --git a/src/dns-manager/nm-dns-dnsmasq.c b/src/dns-manager/nm-dns-dnsmasq.c
index f7e27da..61b08c6 100644
--- a/src/dns-manager/nm-dns-dnsmasq.c
+++ b/src/dns-manager/nm-dns-dnsmasq.c
@@ -387,12 +387,6 @@ child_quit (NMDnsPlugin *plugin, gint status)
/****************************************************************/
static gboolean
-init (NMDnsPlugin *plugin)
-{
- return TRUE;
-}
-
-static gboolean
is_caching (NMDnsPlugin *plugin)
{
return TRUE;
@@ -406,10 +400,10 @@ get_name (NMDnsPlugin *plugin)
/****************************************************************/
-NMDnsDnsmasq *
+NMDnsPlugin *
nm_dns_dnsmasq_new (void)
{
- return (NMDnsDnsmasq *) g_object_new (NM_TYPE_DNS_DNSMASQ, NULL);
+ return g_object_new (NM_TYPE_DNS_DNSMASQ, NULL);
}
static void
@@ -435,7 +429,6 @@ nm_dns_dnsmasq_class_init (NMDnsDnsmasqClass *dns_class)
object_class->dispose = dispose;
- plugin_class->init = init;
plugin_class->child_quit = child_quit;
plugin_class->is_caching = is_caching;
plugin_class->update = update;
diff --git a/src/dns-manager/nm-dns-dnsmasq.h b/src/dns-manager/nm-dns-dnsmasq.h
index 01ec579..70933c0 100644
--- a/src/dns-manager/nm-dns-dnsmasq.h
+++ b/src/dns-manager/nm-dns-dnsmasq.h
@@ -41,7 +41,7 @@ typedef struct {
GType nm_dns_dnsmasq_get_type (void);
-NMDnsDnsmasq *nm_dns_dnsmasq_new (void);
+NMDnsPlugin *nm_dns_dnsmasq_new (void);
#endif /* NM_DNS_DNSMASQ_H */
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c
index 742ab82..ff030f4 100644
--- a/src/dns-manager/nm-dns-manager.c
+++ b/src/dns-manager/nm-dns-manager.c
@@ -23,17 +23,11 @@
#include "config.h"
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
#include <errno.h>
-#include <arpa/inet.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <glib.h>
+#include <resolv.h>
+#include <stdlib.h>
+#include <glib.h>
#include <glib/gi18n.h>
#include "nm-dns-manager.h"
@@ -47,11 +41,7 @@
#include "nm-dns-plugin.h"
#include "nm-dns-dnsmasq.h"
-#ifndef RESOLV_CONF
-#define RESOLV_CONF "/etc/resolv.conf"
-#endif
-
-G_DEFINE_TYPE(NMDnsManager, nm_dns_manager, G_TYPE_OBJECT)
+G_DEFINE_TYPE (NMDnsManager, nm_dns_manager, G_TYPE_OBJECT)
#define NM_DNS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
NM_TYPE_DNS_MANAGER, \
@@ -60,8 +50,6 @@ G_DEFINE_TYPE(NMDnsManager, nm_dns_manager, G_TYPE_OBJECT)
#define HASH_LEN 20
typedef struct {
- gboolean disposed;
-
NMIP4Config *ip4_vpn_config;
NMIP4Config *ip4_device_config;
NMIP6Config *ip6_vpn_config;
@@ -350,7 +338,7 @@ write_resolv_conf (FILE *f, const char *domain,
g_set_error (error,
NM_DNS_MANAGER_ERROR,
NM_DNS_MANAGER_ERROR_SYSTEM,
- "Could not write " RESOLV_CONF ": %s\n",
+ "Could not write " _PATH_RESCONF ": %s\n",
g_strerror (errno));
return FALSE;
}
@@ -458,9 +446,9 @@ update_resolv_conf (const char *domain,
g_return_val_if_fail (error != NULL, FALSE);
/* Find the real path of resolv.conf; it could be a symlink to something */
- resolv_conf_realpath = realpath (RESOLV_CONF, NULL);
+ resolv_conf_realpath = realpath (_PATH_RESCONF, NULL);
if (!resolv_conf_realpath)
- resolv_conf_realpath = strdup (RESOLV_CONF);
+ resolv_conf_realpath = strdup (_PATH_RESCONF);
/* Build up the real path for the temp resolv.conf that we're about to
* write out.
@@ -475,21 +463,21 @@ update_resolv_conf (const char *domain,
if ((f = fopen (tmp_resolv_conf_realpath, "w")) == NULL) {
do_rename = 0;
old_errno = errno;
- if ((f = fopen (RESOLV_CONF, "w")) == NULL) {
+ if ((f = fopen (_PATH_RESCONF, "w")) == NULL) {
g_set_error (error,
NM_DNS_MANAGER_ERROR,
NM_DNS_MANAGER_ERROR_SYSTEM,
"Could not open %s: %s\nCould not open %s: %s\n",
tmp_resolv_conf_realpath,
g_strerror (old_errno),
- RESOLV_CONF,
+ _PATH_RESCONF,
g_strerror (errno));
goto out;
}
/* Update tmp_resolv_conf_realpath so the error message on fclose()
* failure will be correct.
*/
- strcpy (tmp_resolv_conf_realpath, RESOLV_CONF);
+ strcpy (tmp_resolv_conf_realpath, _PATH_RESCONF);
}
write_resolv_conf (f, domain, searches, nameservers, error);
@@ -516,7 +504,7 @@ update_resolv_conf (const char *domain,
g_set_error (error,
NM_DNS_MANAGER_ERROR,
NM_DNS_MANAGER_ERROR_SYSTEM,
- "Could not replace " RESOLV_CONF ": %s\n",
+ "Could not replace " _PATH_RESCONF ": %s\n",
g_strerror (errno));
}
}
@@ -967,10 +955,6 @@ nm_dns_manager_set_hostname (NMDnsManager *mgr,
g_free (priv->hostname);
priv->hostname = g_strdup (filtered);
- /* Passing the last interface here is completely bogus, but SUSE's netconfig
- * wants one. But hostname changes are system-wide and *not* tied to a
- * specific interface, so netconfig can't really handle this. Fake it.
- */
if (!priv->updates_queue && !update_dns (mgr, FALSE, &error)) {
nm_log_warn (LOGD_DNS, "could not commit DNS changes: (%d) %s",
error ? error->code : -1,
@@ -1043,7 +1027,7 @@ load_plugins (NMDnsManager *self, const char **plugins)
/* Create each configured plugin */
for (iter = plugins; iter && *iter; iter++) {
if (!strcasecmp (*iter, "dnsmasq"))
- plugin = NM_DNS_PLUGIN (nm_dns_dnsmasq_new ());
+ plugin = nm_dns_dnsmasq_new ();
else {
nm_log_warn (LOGD_DNS, "Unknown DNS plugin '%s'", *iter);\
continue;
@@ -1118,30 +1102,25 @@ dispose (GObject *object)
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self);
GError *error = NULL;
- if (priv->disposed == FALSE) {
- priv->disposed = TRUE;
-
- g_slist_foreach (priv->plugins, (GFunc) g_object_unref, NULL);
- g_slist_free (priv->plugins);
- priv->plugins = NULL;
+ g_slist_free_full (priv->plugins, g_object_unref);
+ priv->plugins = NULL;
- /* If we're quitting leave a valid resolv.conf in place, not one
- * pointing to 127.0.0.1 if any plugins were active. Thus update
- * DNS after disposing of all plugins. But if we haven't done any
- * DNS updates yet, there's no reason to touch resolv.conf on shutdown.
- */
- if (priv->dns_touched && !update_dns (self, TRUE, &error)) {
- nm_log_warn (LOGD_DNS, "could not commit DNS changes on shutdown: (%d) %s",
- error ? error->code : -1,
- error && error->message ? error->message : "(unknown)");
- g_clear_error (&error);
- }
-
- g_slist_foreach (priv->configs, (GFunc) g_object_unref, NULL);
- g_slist_free (priv->configs);
- priv->configs = NULL;
+ /* If we're quitting, leave a valid resolv.conf in place, not one
+ * pointing to 127.0.0.1 if any plugins were active. Thus update
+ * DNS after disposing of all plugins. But if we haven't done any
+ * DNS updates yet, there's no reason to touch resolv.conf on shutdown.
+ */
+ if (priv->dns_touched && !update_dns (self, TRUE, &error)) {
+ nm_log_warn (LOGD_DNS, "could not commit DNS changes on shutdown: (%d) %s",
+ error ? error->code : -1,
+ error && error->message ? error->message : "(unknown)");
+ g_clear_error (&error);
+ priv->dns_touched = FALSE;
}
+ g_slist_free_full (priv->configs, g_object_unref);
+ priv->configs = NULL;
+
G_OBJECT_CLASS (nm_dns_manager_parent_class)->dispose (object);
}
diff --git a/src/dns-manager/nm-dns-plugin.h b/src/dns-manager/nm-dns-plugin.h
index 2a66557..41a12a5 100644
--- a/src/dns-manager/nm-dns-plugin.h
+++ b/src/dns-manager/nm-dns-plugin.h
@@ -42,7 +42,6 @@ typedef struct {
GObjectClass parent;
/* Methods */
- gboolean (*init) (NMDnsPlugin *self);
/* Called when DNS information is changed. 'vpn_configs' is a list of
* NMIP4Config or NMIP6Config objects from VPN connections, while
commit df1f4bee0ed048c1b434d65e5d0cd884f2e7040b
Author: Dan Winship <danw@gnome.org>
Date: Tue Mar 26 10:03:06 2013 -0400
dns-manager, config: make the dns config key single-valued
Make the main/dns config key be a single value rather than a list of
plugins. Since there is currently only one valid value for it
("dnsmasq"), this is backward-compatible.
In the future, it will be possible to specify custom DNS-configuring
scripts here, which is a more flexible way of handling complicated
behavior than trying to create chainable internal plugins.
diff --git a/man/NetworkManager.conf.5.in b/man/NetworkManager.conf.5.in
index 17f82e6..b69eafa 100644
--- a/man/NetworkManager.conf.5.in
+++ b/man/NetworkManager.conf.5.in
@@ -135,17 +135,22 @@ no-auto-default=*
no-auto-default=*
.fi
.TP
-.B dns=\fIplugin1\fP,\fIplugin2\fP, ...
-List DNS plugin names separated by ','. DNS plugins are used to provide local
-caching nameserver functionality (which speeds up DNS queries) and to push
-DNS data to applications that use it.
+.B dns=\fImode\fP
+Set the DNS/resolv.conf-processing mode.
.P
.RS
-.B "Available plugins:"
+.B "Supported modes:"
.br
.TP
+.I default
+The default if the key is not specified. NetworkManager will update
+resolv.conf to reflect the nameservers provided by currently active
+connections.
+.TP
.I dnsmasq
-this plugin uses dnsmasq to provide local caching nameserver functionality.
+NetworkManager will run dnsmasq as a local caching nameserver, using
+a "split DNS" configuration if you are connected to a VPN, and then
+update resolv.conf to point to the local nameserver.
.RE
.SS [keyfile]
This section contains keyfile-specific options and thus only has effect when using \fIkeyfile\fP plugin.
diff --git a/src/nm-config.c b/src/nm-config.c
index 0266dd5..606a889 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -31,7 +31,7 @@ struct NMConfig {
char *path;
char **plugins;
char *dhcp_client;
- char **dns_plugins;
+ char *dns_mode;
char *log_level;
char *log_domains;
char *connectivity_uri;
@@ -76,12 +76,12 @@ nm_config_get_dhcp_client (NMConfig *config)
return config->dhcp_client;
}
-const char **
-nm_config_get_dns_plugins (NMConfig *config)
+const char *
+nm_config_get_dns_mode (NMConfig *config)
{
g_return_val_if_fail (config != NULL, NULL);
- return (const char **) config->dns_plugins;
+ return (const char *) config->dns_mode;
}
const char *
@@ -164,7 +164,7 @@ nm_config_new (GError **error)
config->plugins = g_key_file_get_string_list (kf, "main", "plugins", NULL, NULL);
config->dhcp_client = g_key_file_get_value (kf, "main", "dhcp", NULL);
- config->dns_plugins = g_key_file_get_string_list (kf, "main", "dns", NULL, NULL);
+ config->dns_mode = g_key_file_get_value (kf, "main", "dns", NULL);
if (cli_log_level && strlen (cli_log_level))
config->log_level = g_strdup (cli_log_level);
@@ -283,7 +283,7 @@ nm_config_free (NMConfig *config)
g_free (config->path);
g_strfreev (config->plugins);
g_free (config->dhcp_client);
- g_strfreev (config->dns_plugins);
+ g_free (config->dns_mode);
g_free (config->log_level);
g_free (config->log_domains);
g_free (config->connectivity_uri);
diff --git a/src/nm-config.h b/src/nm-config.h
index ed84613..82cf8c5 100644
--- a/src/nm-config.h
+++ b/src/nm-config.h
@@ -51,7 +51,7 @@ NMConfig *nm_config_get (void);
const char *nm_config_get_path (NMConfig *config);
const char **nm_config_get_plugins (NMConfig *config);
const char *nm_config_get_dhcp_client (NMConfig *config);
-const char **nm_config_get_dns_plugins (NMConfig *config);
+const char *nm_config_get_dns_mode (NMConfig *config);
const char *nm_config_get_log_level (NMConfig *config);
const char *nm_config_get_log_domains (NMConfig *config);
const char *nm_config_get_connectivity_uri (NMConfig *config);
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c
index ff030f4..d0185c6 100644
--- a/src/dns-manager/nm-dns-manager.c
+++ b/src/dns-manager/nm-dns-manager.c
@@ -61,7 +61,7 @@ typedef struct {
guint8 hash[HASH_LEN]; /* SHA1 hash of current DNS config */
guint8 prev_hash[HASH_LEN]; /* Hash when begin_updates() was called */
- GSList *plugins;
+ NMDnsPlugin *plugin;
gboolean dns_touched;
} NMDnsManagerPrivate;
@@ -686,15 +686,15 @@ update_dns (NMDnsManager *self,
}
/* Let any plugins do their thing first */
- for (iter = priv->plugins; iter; iter = g_slist_next (iter)) {
- NMDnsPlugin *plugin = NM_DNS_PLUGIN (iter->data);
+ if (priv->plugin) {
+ NMDnsPlugin *plugin = priv->plugin;
const char *plugin_name = nm_dns_plugin_get_name (plugin);
if (nm_dns_plugin_is_caching (plugin)) {
if (no_caching) {
nm_log_dbg (LOGD_DNS, "DNS: plugin %s ignored (caching disabled)",
plugin_name);
- continue;
+ goto skip;
}
caching = TRUE;
}
@@ -712,7 +712,11 @@ update_dns (NMDnsManager *self,
*/
caching = FALSE;
}
+
+ skip:
+ ;
}
+
g_slist_free (vpn_configs);
g_slist_free (dev_configs);
g_slist_free (other_configs);
@@ -1015,60 +1019,28 @@ nm_dns_manager_end_updates (NMDnsManager *mgr, const char *func)
memset (priv->prev_hash, 0, sizeof (priv->prev_hash));
}
-static void
-load_plugins (NMDnsManager *self, const char **plugins)
-{
- NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self);
- NMDnsPlugin *plugin;
- const char **iter;
- gboolean have_caching = FALSE;
-
- if (plugins && *plugins) {
- /* Create each configured plugin */
- for (iter = plugins; iter && *iter; iter++) {
- if (!strcasecmp (*iter, "dnsmasq"))
- plugin = nm_dns_dnsmasq_new ();
- else {
- nm_log_warn (LOGD_DNS, "Unknown DNS plugin '%s'", *iter);\
- continue;
- }
- g_assert (plugin);
-
- /* Only one caching DNS plugin is allowed */
- if (nm_dns_plugin_is_caching (plugin)) {
- if (have_caching) {
- nm_log_warn (LOGD_DNS,
- "Ignoring plugin %s; only one caching DNS "
- "plugin is allowed.",
- *iter);
- g_object_unref (plugin);
- continue;
- }
- have_caching = TRUE;
- }
-
- nm_log_info (LOGD_DNS, "DNS: loaded plugin %s", nm_dns_plugin_get_name (plugin));
- priv->plugins = g_slist_append (priv->plugins, plugin);
- g_signal_connect (plugin, NM_DNS_PLUGIN_FAILED,
- G_CALLBACK (plugin_failed),
- self);
- }
- } else {
- /* Create default plugins */
- }
-}
-
/******************************************************************/
NMDnsManager *
-nm_dns_manager_get (const char **plugins)
+nm_dns_manager_get (const char *mode)
{
static NMDnsManager * singleton = NULL;
+ NMDnsManagerPrivate *priv;
if (!singleton) {
singleton = NM_DNS_MANAGER (g_object_new (NM_TYPE_DNS_MANAGER, NULL));
g_assert (singleton);
- load_plugins (singleton, plugins);
+ priv = NM_DNS_MANAGER_GET_PRIVATE (singleton);
+
+ if (!g_strcmp0 (mode, "dnsmasq"))
+ priv->plugin = nm_dns_dnsmasq_new ();
+ else if (mode && g_strcmp0 (mode, "default") != 0)
+ nm_log_warn (LOGD_DNS, "Unknown DNS mode '%s'", mode);
+
+ if (priv->plugin) {
+ nm_log_info (LOGD_DNS, "DNS: loaded plugin %s", nm_dns_plugin_get_name (priv->plugin));
+ g_signal_connect (priv->plugin, NM_DNS_PLUGIN_FAILED, G_CALLBACK (plugin_failed), singleton);
+ }
} else
g_object_ref (singleton);
@@ -1102,8 +1073,7 @@ dispose (GObject *object)
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self);
GError *error = NULL;
- g_slist_free_full (priv->plugins, g_object_unref);
- priv->plugins = NULL;
+ g_clear_object (&priv->plugin);
/* If we're quitting, leave a valid resolv.conf in place, not one
* pointing to 127.0.0.1 if any plugins were active. Thus update
diff --git a/src/dns-manager/nm-dns-manager.h b/src/dns-manager/nm-dns-manager.h
index 0fd4c19..431d66a 100644
--- a/src/dns-manager/nm-dns-manager.h
+++ b/src/dns-manager/nm-dns-manager.h
@@ -67,7 +67,7 @@ typedef struct {
GType nm_dns_manager_get_type (void);
-NMDnsManager * nm_dns_manager_get (const char **plugins);
+NMDnsManager * nm_dns_manager_get (const char *mode);
/* Allow changes to be batched together */
void nm_dns_manager_begin_updates (NMDnsManager *mgr, const char *func);
diff --git a/src/main.c b/src/main.c
index feb8fa3..0f92d19 100644
--- a/src/main.c
+++ b/src/main.c
@@ -534,7 +534,7 @@ main (int argc, char *argv[])
goto done;
}
- dns_mgr = nm_dns_manager_get (nm_config_get_dns_plugins (config));
+ dns_mgr = nm_dns_manager_get (nm_config_get_dns_mode (config));
if (!dns_mgr) {
nm_log_err (LOGD_CORE, "failed to start the DNS manager.");
goto done;
commit 282a9720ab4432b919e0fa57a9b71dfe87ee8ac1
Author: Dan Winship <danw@gnome.org>
Date: Tue Mar 26 10:05:25 2013 -0400
dns-manager: add dns=none
Add a new dns mode "none", meaning that NM should not modify
resolv.conf at all.
https://bugzilla.gnome.org/show_bug.cgi?id=690404
diff --git a/man/NetworkManager.conf.5.in b/man/NetworkManager.conf.5.in
index b69eafa..368d776 100644
--- a/man/NetworkManager.conf.5.in
+++ b/man/NetworkManager.conf.5.in
@@ -151,6 +151,9 @@ connections.
NetworkManager will run dnsmasq as a local caching nameserver, using
a "split DNS" configuration if you are connected to a VPN, and then
update resolv.conf to point to the local nameserver.
+.TP
+.I none
+NetworkManager will not modify resolv.conf.
.RE
.SS [keyfile]
This section contains keyfile-specific options and thus only has effect when using \fIkeyfile\fP plugin.
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c
index d0185c6..84d5ddf 100644
--- a/src/dns-manager/nm-dns-manager.c
+++ b/src/dns-manager/nm-dns-manager.c
@@ -61,6 +61,7 @@ typedef struct {
guint8 hash[HASH_LEN]; /* SHA1 hash of current DNS config */
guint8 prev_hash[HASH_LEN]; /* Hash when begin_updates() was called */
+ gboolean manage_dns;
NMDnsPlugin *plugin;
gboolean dns_touched;
@@ -575,6 +576,9 @@ update_dns (NMDnsManager *self,
priv = NM_DNS_MANAGER_GET_PRIVATE (self);
+ if (!priv->manage_dns)
+ return TRUE;
+
priv->dns_touched = TRUE;
nm_log_dbg (LOGD_DNS, "updating resolv.conf");
@@ -1029,10 +1033,16 @@ nm_dns_manager_get (const char *mode)
g_assert (singleton);
priv = NM_DNS_MANAGER_GET_PRIVATE (singleton);
- if (!g_strcmp0 (mode, "dnsmasq"))
- priv->plugin = nm_dns_dnsmasq_new ();
- else if (mode && g_strcmp0 (mode, "default") != 0)
- nm_log_warn (LOGD_DNS, "Unknown DNS mode '%s'", mode);
+ if (!g_strcmp0 (mode, "none")) {
+ priv->manage_dns = FALSE;
+ nm_log_info (LOGD_DNS, "DNS: not managing " _PATH_RESCONF);
+ } else {
+ priv->manage_dns = TRUE;
+ if (!g_strcmp0 (mode, "dnsmasq"))
+ priv->plugin = nm_dns_dnsmasq_new ();
+ else if (mode && g_strcmp0 (mode, "default") != 0)
+ nm_log_warn (LOGD_DNS, "Unknown DNS mode '%s'", mode);
+ }
if (priv->plugin) {
nm_log_info (LOGD_DNS, "DNS: loaded plugin %s", nm_dns_plugin_get_name (priv->plugin));