mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-05 05:20:32 +01:00
core: add DNS plugin config options
This commit is contained in:
parent
9b2b809aae
commit
64b6cd1ebc
7 changed files with 126 additions and 44 deletions
|
|
@ -44,12 +44,13 @@ Description of sections and available keys follows:
|
|||
This section is the only mandatory section of the configuration file.
|
||||
.TP
|
||||
.B plugins=\fIplugin1\fP,\fIplugin2\fP, ...
|
||||
List plugin names separated by ','. Plugins are used to read/write system-wide
|
||||
connection. When more plugins are specified, the connections are read from all
|
||||
listed plugins. When writing connections, the plugins will be asked to save the
|
||||
connection in the order listed here. If the first plugin cannot write out that
|
||||
connection type, or can't write out any connections, the next plugin is tried.
|
||||
If none of the plugins can save the connection, the error is returned to the user.
|
||||
List system settings plugin names separated by ','. These plugins are used to
|
||||
read/write system-wide connection. When more plugins are specified, the
|
||||
connections are read from all listed plugins. When writing connections, the
|
||||
plugins will be asked to save the connection in the order listed here. If the
|
||||
first plugin cannot write out that connection type, or can't write out any
|
||||
connections, the next plugin is tried. If none of the plugins can save the
|
||||
connection, the error is returned to the user.
|
||||
.P
|
||||
.RS
|
||||
.B "Available plugins:"
|
||||
|
|
@ -87,6 +88,27 @@ This key sets up what DHCP client NetworkManager will use. Presently
|
|||
\fIdhclient\fP and \fIdhcpcd\fP are supported. The client configured here should
|
||||
be available on your system too. If this key is missing, available DHCP clients
|
||||
are looked for in this order: dhclient, dhcpcd.
|
||||
.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.
|
||||
.P
|
||||
.RS
|
||||
.B "Available plugins:"
|
||||
.br
|
||||
.TP
|
||||
.I dnsmasq
|
||||
this plugin uses dnsmasq to provide local caching nameserver functionality.
|
||||
.TP
|
||||
.I bind
|
||||
this plugin uses the ISC BIND program to provide local caching nameserver
|
||||
functionality.
|
||||
.TP
|
||||
.I chromium
|
||||
this plugin provides DNS information to the Chromium web browser. It does not
|
||||
provide local caching nameserver functionality.
|
||||
.RE
|
||||
.SS [keyfile]
|
||||
This section contains keyfile-specific options and thus only has effect when using \fIkeyfile\fP plugin.
|
||||
.TP
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ G_DEFINE_TYPE(NMDnsManager, nm_dns_manager, G_TYPE_OBJECT)
|
|||
NM_TYPE_DNS_MANAGER, \
|
||||
NMDnsManagerPrivate))
|
||||
|
||||
|
||||
struct NMDnsManagerPrivate {
|
||||
NMIP4Config *ip4_vpn_config;
|
||||
NMIP4Config *ip4_device_config;
|
||||
|
|
@ -68,6 +67,8 @@ struct NMDnsManagerPrivate {
|
|||
GSList *configs;
|
||||
char *hostname;
|
||||
|
||||
GSList *plugins;
|
||||
|
||||
/* This is a hack because SUSE's netconfig always wants changes
|
||||
* associated with a network interface, but sometimes a change isn't
|
||||
* associated with a network interface (like hostnames).
|
||||
|
|
@ -76,31 +77,6 @@ struct NMDnsManagerPrivate {
|
|||
};
|
||||
|
||||
|
||||
NMDnsManager *
|
||||
nm_dns_manager_get (void)
|
||||
{
|
||||
static NMDnsManager * singleton = NULL;
|
||||
|
||||
if (!singleton)
|
||||
singleton = NM_DNS_MANAGER (g_object_new (NM_TYPE_DNS_MANAGER, NULL));
|
||||
else
|
||||
g_object_ref (singleton);
|
||||
|
||||
g_assert (singleton);
|
||||
return singleton;
|
||||
}
|
||||
|
||||
|
||||
GQuark
|
||||
nm_dns_manager_error_quark (void)
|
||||
{
|
||||
static GQuark quark = 0;
|
||||
if (!quark)
|
||||
quark = g_quark_from_static_string ("nm_dns_manager_error");
|
||||
|
||||
return quark;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GPtrArray *nameservers;
|
||||
const char *domain;
|
||||
|
|
@ -852,6 +828,83 @@ nm_dns_manager_set_hostname (NMDnsManager *mgr,
|
|||
}
|
||||
}
|
||||
|
||||
static GObject *
|
||||
nm_dns_dnsmasq_new (void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GObject *
|
||||
nm_dns_bind_new (void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GObject *
|
||||
nm_dns_chromium_new (void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
load_plugins (NMDnsManager *self, const char **plugins)
|
||||
{
|
||||
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self);
|
||||
GObject *plugin;
|
||||
const char **iter;
|
||||
|
||||
if (plugins && *plugins) {
|
||||
/* Create each configured plugin */
|
||||
for (iter = plugins; iter && *iter; iter++) {
|
||||
if (!strcasecmp (*iter, "dnsmasq"))
|
||||
plugin = nm_dns_dnsmasq_new ();
|
||||
else if (!strcasecmp (*iter, "bind"))
|
||||
plugin = nm_dns_bind_new ();
|
||||
else if (!strcasecmp (*iter, "chromium"))
|
||||
plugin = nm_dns_chromium_new ();
|
||||
else {
|
||||
nm_log_warn (LOGD_DNS, "Unknown DNS plugin '%s'", *iter);
|
||||
}
|
||||
|
||||
if (plugin)
|
||||
priv->plugins = g_slist_append (priv->plugins, plugin);
|
||||
}
|
||||
} else {
|
||||
/* Create default plugins */
|
||||
|
||||
/* Chromium support */
|
||||
plugin = nm_dns_chromium_new ();
|
||||
g_assert (plugin);
|
||||
priv->plugins = g_slist_append (priv->plugins, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
NMDnsManager *
|
||||
nm_dns_manager_get (const char **plugins)
|
||||
{
|
||||
static NMDnsManager * singleton = NULL;
|
||||
|
||||
if (!singleton) {
|
||||
singleton = NM_DNS_MANAGER (g_object_new (NM_TYPE_DNS_MANAGER, NULL));
|
||||
g_assert (singleton);
|
||||
load_plugins (singleton, plugins);
|
||||
} else
|
||||
g_object_ref (singleton);
|
||||
|
||||
return singleton;
|
||||
}
|
||||
|
||||
GQuark
|
||||
nm_dns_manager_error_quark (void)
|
||||
{
|
||||
static GQuark quark = 0;
|
||||
if (!quark)
|
||||
quark = g_quark_from_static_string ("nm_dns_manager_error");
|
||||
|
||||
return quark;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_dns_manager_init (NMDnsManager *mgr)
|
||||
|
|
@ -868,6 +921,9 @@ nm_dns_manager_finalize (GObject *object)
|
|||
g_free (priv->hostname);
|
||||
g_free (priv->last_iface);
|
||||
|
||||
g_slist_foreach (priv->plugins, (GFunc) g_object_unref, NULL);
|
||||
g_slist_free (priv->plugins);
|
||||
|
||||
G_OBJECT_CLASS (nm_dns_manager_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ typedef struct {
|
|||
|
||||
GType nm_dns_manager_get_type (void);
|
||||
|
||||
NMDnsManager * nm_dns_manager_get (void);
|
||||
NMDnsManager * nm_dns_manager_get (const char **plugins);
|
||||
|
||||
gboolean nm_dns_manager_add_ip4_config (NMDnsManager *mgr,
|
||||
const char *iface,
|
||||
|
|
|
|||
12
src/main.c
12
src/main.c
|
|
@ -300,6 +300,7 @@ static gboolean
|
|||
parse_config_file (const char *filename,
|
||||
char **plugins,
|
||||
char **dhcp_client,
|
||||
char ***dns_plugins,
|
||||
char **log_level,
|
||||
char **log_domains,
|
||||
GError **error)
|
||||
|
|
@ -322,6 +323,7 @@ parse_config_file (const char *filename,
|
|||
return FALSE;
|
||||
|
||||
*dhcp_client = g_key_file_get_value (config, "main", "dhcp", NULL);
|
||||
*dns_plugins = g_key_file_get_string_list (config, "main", "dns", NULL, NULL);
|
||||
|
||||
*log_level = g_key_file_get_value (config, "logging", "level", NULL);
|
||||
*log_domains = g_key_file_get_value (config, "logging", "domains", NULL);
|
||||
|
|
@ -442,6 +444,7 @@ main (int argc, char *argv[])
|
|||
char *pidfile = NULL, *state_file = NULL, *dhcp = NULL;
|
||||
char *config = NULL, *plugins = NULL, *conf_plugins = NULL;
|
||||
char *log_level = NULL, *log_domains = NULL;
|
||||
char **dns = NULL;
|
||||
gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE;
|
||||
gboolean success;
|
||||
NMPolicy *policy = NULL;
|
||||
|
|
@ -515,7 +518,7 @@ main (int argc, char *argv[])
|
|||
|
||||
/* Parse the config file */
|
||||
if (config) {
|
||||
if (!parse_config_file (config, &conf_plugins, &dhcp, &cfg_log_level, &cfg_log_domains, &error)) {
|
||||
if (!parse_config_file (config, &conf_plugins, &dhcp, &dns, &cfg_log_level, &cfg_log_domains, &error)) {
|
||||
fprintf (stderr, "Config file %s invalid: (%d) %s\n",
|
||||
config,
|
||||
error ? error->code : -1,
|
||||
|
|
@ -535,7 +538,7 @@ main (int argc, char *argv[])
|
|||
/* Try deprecated nm-system-settings.conf first */
|
||||
if (g_file_test (NM_OLD_SYSTEM_CONF_FILE, G_FILE_TEST_EXISTS)) {
|
||||
config = g_strdup (NM_OLD_SYSTEM_CONF_FILE);
|
||||
parsed = parse_config_file (config, &conf_plugins, &dhcp, &cfg_log_level, &cfg_log_domains, &error);
|
||||
parsed = parse_config_file (config, &conf_plugins, &dhcp, &dns, &cfg_log_level, &cfg_log_domains, &error);
|
||||
if (!parsed) {
|
||||
fprintf (stderr, "Default config file %s invalid: (%d) %s\n",
|
||||
config,
|
||||
|
|
@ -550,7 +553,7 @@ main (int argc, char *argv[])
|
|||
/* Try the preferred NetworkManager.conf last */
|
||||
if (!parsed && g_file_test (NM_DEFAULT_SYSTEM_CONF_FILE, G_FILE_TEST_EXISTS)) {
|
||||
config = g_strdup (NM_DEFAULT_SYSTEM_CONF_FILE);
|
||||
parsed = parse_config_file (config, &conf_plugins, &dhcp, &cfg_log_level, &cfg_log_domains, &error);
|
||||
parsed = parse_config_file (config, &conf_plugins, &dhcp, &dns, &cfg_log_level, &cfg_log_domains, &error);
|
||||
if (!parsed) {
|
||||
fprintf (stderr, "Default config file %s invalid: (%d) %s\n",
|
||||
config,
|
||||
|
|
@ -663,7 +666,7 @@ main (int argc, char *argv[])
|
|||
goto done;
|
||||
}
|
||||
|
||||
dns_mgr = nm_dns_manager_get ();
|
||||
dns_mgr = nm_dns_manager_get ((const char **) dns);
|
||||
if (!dns_mgr) {
|
||||
nm_log_err (LOGD_CORE, "failed to start the DNS manager.");
|
||||
goto done;
|
||||
|
|
@ -756,6 +759,7 @@ done:
|
|||
g_free (config);
|
||||
g_free (plugins);
|
||||
g_free (dhcp);
|
||||
g_strfreev (dns);
|
||||
g_free (log_level);
|
||||
g_free (log_domains);
|
||||
g_free (cfg_log_level);
|
||||
|
|
|
|||
|
|
@ -3038,7 +3038,7 @@ nm_device_set_ip4_config (NMDevice *self,
|
|||
if (diff == NM_IP4_COMPARE_FLAG_NONE)
|
||||
return TRUE;
|
||||
|
||||
dns_mgr = nm_dns_manager_get ();
|
||||
dns_mgr = nm_dns_manager_get (NULL);
|
||||
if (old_config) {
|
||||
/* Remove any previous IP4 Config from the DNS manager */
|
||||
nm_dns_manager_remove_ip4_config (dns_mgr, ip_iface, old_config);
|
||||
|
|
@ -3141,7 +3141,7 @@ nm_device_set_ip6_config (NMDevice *self,
|
|||
if (diff == NM_IP6_COMPARE_FLAG_NONE)
|
||||
return TRUE;
|
||||
|
||||
dns_mgr = nm_dns_manager_get ();
|
||||
dns_mgr = nm_dns_manager_get (NULL);
|
||||
if (old_config) {
|
||||
/* Remove any previous IP6 Config from the DNS manager */
|
||||
nm_dns_manager_remove_ip6_config (dns_mgr, ip_iface, old_config);
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ _set_hostname (NMPolicy *policy,
|
|||
g_free (policy->cur_hostname);
|
||||
policy->cur_hostname = g_strdup (new_hostname);
|
||||
|
||||
dns_mgr = nm_dns_manager_get ();
|
||||
dns_mgr = nm_dns_manager_get (NULL);
|
||||
nm_dns_manager_set_hostname (dns_mgr, policy->cur_hostname);
|
||||
g_object_unref (dns_mgr);
|
||||
}
|
||||
|
|
@ -553,7 +553,7 @@ update_ip4_routing_and_dns (NMPolicy *policy, gboolean force_update)
|
|||
nm_act_request_set_default (req, FALSE);
|
||||
}
|
||||
|
||||
dns_mgr = nm_dns_manager_get ();
|
||||
dns_mgr = nm_dns_manager_get (NULL);
|
||||
nm_dns_manager_add_ip4_config (dns_mgr, ip_iface, ip4_config, dns_type);
|
||||
g_object_unref (dns_mgr);
|
||||
|
||||
|
|
@ -679,7 +679,7 @@ update_ip6_routing_and_dns (NMPolicy *policy, gboolean force_update)
|
|||
nm_act_request_set_default6 (req, FALSE);
|
||||
}
|
||||
|
||||
dns_mgr = nm_dns_manager_get ();
|
||||
dns_mgr = nm_dns_manager_get (NULL);
|
||||
nm_dns_manager_add_ip6_config (dns_mgr, ip_iface, ip6_config, dns_type);
|
||||
g_object_unref (dns_mgr);
|
||||
|
||||
|
|
|
|||
|
|
@ -549,7 +549,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
|
|||
priv->gw_route = nm_system_add_ip4_vpn_gateway_route (priv->parent_dev, config);
|
||||
|
||||
/* Add the VPN to DNS */
|
||||
dns_mgr = nm_dns_manager_get ();
|
||||
dns_mgr = nm_dns_manager_get (NULL);
|
||||
nm_dns_manager_add_ip4_config (dns_mgr, priv->ip_iface, config, NM_DNS_IP_CONFIG_TYPE_VPN);
|
||||
g_object_unref (dns_mgr);
|
||||
|
||||
|
|
@ -902,7 +902,7 @@ vpn_cleanup (NMVPNConnection *connection)
|
|||
NMDnsManager *dns_mgr;
|
||||
|
||||
/* Remove attributes of the VPN's IP4 Config */
|
||||
dns_mgr = nm_dns_manager_get ();
|
||||
dns_mgr = nm_dns_manager_get (NULL);
|
||||
nm_dns_manager_remove_ip4_config (dns_mgr, priv->ip_iface, priv->ip4_config);
|
||||
g_object_unref (dns_mgr);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue