summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2015-01-14 17:03:22 -0600
committerDan Williams <dcbw@redhat.com>2015-03-27 16:17:10 -0500
commitcc8d9f778c2237b3e9e6815a2e0cc5635328edab (patch)
tree7a53eb40a16f333345351a7032d8f9f160bcd9a1
parent452c224656ca6129d4ae34eee86e6ecea02fa8c2 (diff)
downloadNetworkManager-cc8d9f778c2237b3e9e6815a2e0cc5635328edab.tar.gz
dns: refactor building IP config lists for plugins (bgo #728342)
Don't bother building the lists if no DNS plugins are enabled. https://bugzilla.gnome.org/show_bug.cgi?id=728342
-rw-r--r--src/dns-manager/nm-dns-manager.c70
1 files changed, 43 insertions, 27 deletions
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c
index f9a4fd44ae..05f2457824 100644
--- a/src/dns-manager/nm-dns-manager.c
+++ b/src/dns-manager/nm-dns-manager.c
@@ -585,6 +585,42 @@ compute_hash (NMDnsManager *self, guint8 buffer[HASH_LEN])
g_checksum_free (sum);
}
+static void
+build_plugin_config_lists (NMDnsManager *self,
+ GSList **out_vpn_configs,
+ GSList **out_dev_configs,
+ GSList **out_other_configs)
+{
+ NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self);
+ GSList *iter;
+
+ g_return_if_fail (out_vpn_configs && !*out_vpn_configs);
+ g_return_if_fail (out_dev_configs && !*out_dev_configs);
+ g_return_if_fail (out_other_configs && !*out_other_configs);
+
+ /* Build up config lists for plugins; we use the raw configs here, not the
+ * merged information that we write to resolv.conf so that the plugins can
+ * still use the domain information in each config to provide split DNS if
+ * they want to.
+ */
+ if (priv->ip4_vpn_config)
+ *out_vpn_configs = g_slist_append (*out_vpn_configs, priv->ip4_vpn_config);
+ if (priv->ip6_vpn_config)
+ *out_vpn_configs = g_slist_append (*out_vpn_configs, priv->ip6_vpn_config);
+ if (priv->ip4_device_config)
+ *out_dev_configs = g_slist_append (*out_dev_configs, priv->ip4_device_config);
+ if (priv->ip6_device_config)
+ *out_dev_configs = g_slist_append (*out_dev_configs, priv->ip6_device_config);
+
+ for (iter = priv->configs; iter; iter = g_slist_next (iter)) {
+ if ( (iter->data != priv->ip4_vpn_config)
+ && (iter->data != priv->ip4_device_config)
+ && (iter->data != priv->ip6_vpn_config)
+ && (iter->data != priv->ip6_device_config))
+ *out_other_configs = g_slist_append (*out_other_configs, iter->data);
+ }
+}
+
static gboolean
update_dns (NMDnsManager *self,
gboolean no_caching,
@@ -592,7 +628,7 @@ update_dns (NMDnsManager *self,
{
NMDnsManagerPrivate *priv;
NMResolvConfData rc;
- GSList *iter, *vpn_configs = NULL, *dev_configs = NULL, *other_configs = NULL;
+ GSList *iter;
const char *nis_domain = NULL;
char **searches = NULL;
char **nameservers = NULL;
@@ -698,32 +734,11 @@ update_dns (NMDnsManager *self,
nis_domain = rc.nis_domain;
- /* Build up config lists for plugins; we use the raw configs here, not the
- * merged information that we write to resolv.conf so that the plugins can
- * still use the domain information in each config to provide split DNS if
- * they want to.
- */
- if (priv->ip4_vpn_config)
- vpn_configs = g_slist_append (vpn_configs, priv->ip4_vpn_config);
- if (priv->ip6_vpn_config)
- vpn_configs = g_slist_append (vpn_configs, priv->ip6_vpn_config);
- if (priv->ip4_device_config)
- dev_configs = g_slist_append (dev_configs, priv->ip4_device_config);
- if (priv->ip6_device_config)
- dev_configs = g_slist_append (dev_configs, priv->ip6_device_config);
-
- for (iter = priv->configs; iter; iter = g_slist_next (iter)) {
- if ( (iter->data != priv->ip4_vpn_config)
- && (iter->data != priv->ip4_device_config)
- && (iter->data != priv->ip6_vpn_config)
- && (iter->data != priv->ip6_device_config))
- other_configs = g_slist_append (other_configs, iter->data);
- }
-
/* Let any plugins do their thing first */
if (priv->plugin) {
NMDnsPlugin *plugin = priv->plugin;
const char *plugin_name = nm_dns_plugin_get_name (plugin);
+ GSList *vpn_configs = NULL, *dev_configs = NULL, *other_configs = NULL;
if (nm_dns_plugin_is_caching (plugin)) {
if (no_caching) {
@@ -734,6 +749,8 @@ update_dns (NMDnsManager *self,
caching = TRUE;
}
+ build_plugin_config_lists (self, &vpn_configs, &dev_configs, &other_configs);
+
nm_log_dbg (LOGD_DNS, "DNS: updating plugin %s", plugin_name);
if (!nm_dns_plugin_update (plugin,
vpn_configs,
@@ -747,15 +764,14 @@ update_dns (NMDnsManager *self,
*/
caching = FALSE;
}
+ g_slist_free (vpn_configs);
+ g_slist_free (dev_configs);
+ g_slist_free (other_configs);
skip:
;
}
- g_slist_free (vpn_configs);
- g_slist_free (dev_configs);
- g_slist_free (other_configs);
-
/* If caching was successful, we only send 127.0.0.1 to /etc/resolv.conf
* to ensure that the glibc resolver doesn't try to round-robin nameservers,
* but only uses the local caching nameserver.