dns-manager: add nm_dns_manager_get_resolv_conf_mode()

Add a property indicating whether NMDnsManager is ignoring
resolv.conf, managing it by explicitly putting nameservers into it, or
managing it by proxying to another service (eg, dnsmasq) with
"nameserver 127.0.0.1".
This commit is contained in:
Dan Winship 2013-12-19 09:37:21 -05:00
parent 69f92cfa2c
commit 3205661096
2 changed files with 34 additions and 7 deletions

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 */
gboolean manage_dns;
NMDnsManagerResolvConfMode resolv_conf_mode;
NMDnsPlugin *plugin;
gboolean dns_touched;
@ -576,7 +576,7 @@ update_dns (NMDnsManager *self,
priv = NM_DNS_MANAGER_GET_PRIVATE (self);
if (!priv->manage_dns)
if (priv->resolv_conf_mode == NM_DNS_MANAGER_RESOLV_CONF_UNMANAGED)
return TRUE;
priv->dns_touched = TRUE;
@ -971,6 +971,12 @@ nm_dns_manager_set_hostname (NMDnsManager *mgr,
}
}
NMDnsManagerResolvConfMode
nm_dns_manager_get_resolv_conf_mode (NMDnsManager *mgr)
{
return NM_DNS_MANAGER_GET_PRIVATE (mgr)->resolv_conf_mode;
}
void
nm_dns_manager_begin_updates (NMDnsManager *mgr, const char *func)
{
@ -1060,13 +1066,14 @@ nm_dns_manager_init (NMDnsManager *self)
mode = nm_config_get_dns_mode (nm_config_get ());
if (!g_strcmp0 (mode, "none")) {
priv->manage_dns = FALSE;
priv->resolv_conf_mode = NM_DNS_MANAGER_RESOLV_CONF_UNMANAGED;
nm_log_info (LOGD_DNS, "DNS: not managing " _PATH_RESCONF);
} else if (!g_strcmp0 (mode, "dnsmasq")) {
priv->resolv_conf_mode = NM_DNS_MANAGER_RESOLV_CONF_PROXY;
priv->plugin = nm_dns_dnsmasq_new ();
} else {
priv->manage_dns = TRUE;
if (!g_strcmp0 (mode, "dnsmasq"))
priv->plugin = nm_dns_dnsmasq_new ();
else if (mode && g_strcmp0 (mode, "default") != 0)
priv->resolv_conf_mode = NM_DNS_MANAGER_RESOLV_CONF_EXPLICIT;
if (mode && g_strcmp0 (mode, "default") != 0)
nm_log_warn (LOGD_DNS, "Unknown DNS mode '%s'", mode);
}

View file

@ -90,6 +90,26 @@ gboolean nm_dns_manager_remove_ip6_config (NMDnsManager *mgr, NMIP6Config *confi
void nm_dns_manager_set_hostname (NMDnsManager *mgr,
const char *hostname);
/**
* NMDnsManagerResolvConfMode:
* @NM_DNS_MANAGER_RESOLV_CONF_UNMANAGED: NM is not managing resolv.conf
* @NM_DNS_MANAGER_RESOLV_CONF_EXPLICIT: NM is managing resolv.conf by
* adding and removing "nameserver" lines corresponding to the currently
* active connections
* @NM_DNS_MANAGER_RESOLV_CONF_PROXY: NM is managing resolv.conf by
* pointing it to some other service (eg, dnsmasq) that knows the
* nameservers corresponding to the currently active connections.
*
* NMDnsManager's behavior toward /etc/resolv.conf.
*/
typedef enum {
NM_DNS_MANAGER_RESOLV_CONF_UNMANAGED,
NM_DNS_MANAGER_RESOLV_CONF_EXPLICIT,
NM_DNS_MANAGER_RESOLV_CONF_PROXY
} NMDnsManagerResolvConfMode;
NMDnsManagerResolvConfMode nm_dns_manager_get_resolv_conf_mode (NMDnsManager *mgr);
G_END_DECLS
#endif /* NM_DNS_MANAGER_H */