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.
This commit is contained in:
Dan Winship 2013-03-26 10:03:06 -04:00
parent a15558daed
commit df1f4bee0e
4 changed files with 41 additions and 66 deletions

View file

@ -135,17 +135,22 @@ no-auto-default=*
Set devices for which NetworkManager should ignore device carrier state when
deciding whether to activate or deactivate connections.
.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.

View file

@ -43,7 +43,7 @@ typedef struct {
char **plugins;
char *dhcp_client;
char **dns_plugins;
char *dns_mode;
char *log_level;
char *log_domains;
@ -88,12 +88,12 @@ nm_config_get_dhcp_client (NMConfig *config)
return NM_CONFIG_GET_PRIVATE (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 **) NM_CONFIG_GET_PRIVATE (config)->dns_plugins;
return NM_CONFIG_GET_PRIVATE (config)->dns_mode;
}
const char *
@ -492,7 +492,7 @@ nm_config_new (GError **error)
priv->plugins = g_key_file_get_string_list (priv->keyfile, "main", "plugins", NULL, NULL);
priv->dhcp_client = g_key_file_get_value (priv->keyfile, "main", "dhcp", NULL);
priv->dns_plugins = g_key_file_get_string_list (priv->keyfile, "main", "dns", NULL, NULL);
priv->dns_mode = g_key_file_get_value (priv->keyfile, "main", "dns", NULL);
if (cli_log_level && cli_log_level[0])
g_key_file_set_value (priv->keyfile, "logging", "level", cli_log_level);
@ -541,7 +541,7 @@ finalize (GObject *gobject)
g_clear_pointer (&priv->keyfile, g_key_file_unref);
g_strfreev (priv->plugins);
g_free (priv->dhcp_client);
g_strfreev (priv->dns_plugins);
g_free (priv->dns_mode);
g_free (priv->log_level);
g_free (priv->log_domains);
g_free (priv->connectivity_uri);

View file

@ -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);

View file

@ -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,63 +1019,16 @@ 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 (void)
{
static NMDnsManager * singleton = NULL;
const char **plugins;
if (!singleton) {
singleton = NM_DNS_MANAGER (g_object_new (NM_TYPE_DNS_MANAGER, NULL));
g_assert (singleton);
plugins = nm_config_get_dns_plugins (nm_config_get ());
load_plugins (singleton, plugins);
} else
g_object_ref (singleton);
@ -1091,8 +1048,22 @@ nm_dns_manager_error_quark (void)
static void
nm_dns_manager_init (NMDnsManager *self)
{
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self);
const char *mode;
/* Set the initial hash */
compute_hash (self, NM_DNS_MANAGER_GET_PRIVATE (self)->hash);
mode = nm_config_get_dns_mode (nm_config_get ());
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), self);
}
}
static void
@ -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