a99f0b8
From 2171b984e3c9a17c032ac80054db79523d97d9dd Mon Sep 17 00:00:00 2001
a99f0b8
From: Dan Williams <dcbw@redhat.com>
a99f0b8
Date: Wed, 14 Jan 2015 17:03:22 -0600
a99f0b8
Subject: [PATCH 2/4] dns: refactor building IP config lists for plugins (bgo
a99f0b8
 #728342)
a99f0b8
a99f0b8
Don't bother building the lists if no DNS plugins are enabled.
a99f0b8
a99f0b8
https://bugzilla.gnome.org/show_bug.cgi?id=728342
a99f0b8
(cherry picked from commit cc8d9f778c2237b3e9e6815a2e0cc5635328edab)
a99f0b8
---
a99f0b8
 src/dns-manager/nm-dns-manager.c | 70 ++++++++++++++++++++++++----------------
a99f0b8
 1 file changed, 43 insertions(+), 27 deletions(-)
a99f0b8
a99f0b8
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c
a99f0b8
index ddf31af..e6984e3 100644
a99f0b8
--- a/src/dns-manager/nm-dns-manager.c
a99f0b8
+++ b/src/dns-manager/nm-dns-manager.c
a99f0b8
@@ -561,6 +561,42 @@ compute_hash (NMDnsManager *self, guint8 buffer[HASH_LEN])
a99f0b8
 	g_checksum_free (sum);
a99f0b8
 }
a99f0b8
 
a99f0b8
+static void
a99f0b8
+build_plugin_config_lists (NMDnsManager *self,
a99f0b8
+                           GSList **out_vpn_configs,
a99f0b8
+                           GSList **out_dev_configs,
a99f0b8
+                           GSList **out_other_configs)
a99f0b8
+{
a99f0b8
+	NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self);
a99f0b8
+	GSList *iter;
a99f0b8
+
a99f0b8
+	g_return_if_fail (out_vpn_configs && !*out_vpn_configs);
a99f0b8
+	g_return_if_fail (out_dev_configs && !*out_dev_configs);
a99f0b8
+	g_return_if_fail (out_other_configs && !*out_other_configs);
a99f0b8
+
a99f0b8
+	/* Build up config lists for plugins; we use the raw configs here, not the
a99f0b8
+	 * merged information that we write to resolv.conf so that the plugins can
a99f0b8
+	 * still use the domain information in each config to provide split DNS if
a99f0b8
+	 * they want to.
a99f0b8
+	 */
a99f0b8
+	if (priv->ip4_vpn_config)
a99f0b8
+		*out_vpn_configs = g_slist_append (*out_vpn_configs, priv->ip4_vpn_config);
a99f0b8
+	if (priv->ip6_vpn_config)
a99f0b8
+		*out_vpn_configs = g_slist_append (*out_vpn_configs, priv->ip6_vpn_config);
a99f0b8
+	if (priv->ip4_device_config)
a99f0b8
+		*out_dev_configs = g_slist_append (*out_dev_configs, priv->ip4_device_config);
a99f0b8
+	if (priv->ip6_device_config)
a99f0b8
+		*out_dev_configs = g_slist_append (*out_dev_configs, priv->ip6_device_config);
a99f0b8
+
a99f0b8
+	for (iter = priv->configs; iter; iter = g_slist_next (iter)) {
a99f0b8
+		if (   (iter->data != priv->ip4_vpn_config)
a99f0b8
+		    && (iter->data != priv->ip4_device_config)
a99f0b8
+		    && (iter->data != priv->ip6_vpn_config)
a99f0b8
+		    && (iter->data != priv->ip6_device_config))
a99f0b8
+			*out_other_configs = g_slist_append (*out_other_configs, iter->data);
a99f0b8
+	}
a99f0b8
+}
a99f0b8
+
a99f0b8
 static gboolean
a99f0b8
 update_dns (NMDnsManager *self,
a99f0b8
             gboolean no_caching,
a99f0b8
@@ -568,7 +604,7 @@ update_dns (NMDnsManager *self,
a99f0b8
 {
a99f0b8
 	NMDnsManagerPrivate *priv;
a99f0b8
 	NMResolvConfData rc;
a99f0b8
-	GSList *iter, *vpn_configs = NULL, *dev_configs = NULL, *other_configs = NULL;
a99f0b8
+	GSList *iter;
a99f0b8
 	const char *nis_domain = NULL;
a99f0b8
 	char **searches = NULL;
a99f0b8
 	char **nameservers = NULL;
a99f0b8
@@ -674,32 +710,11 @@ update_dns (NMDnsManager *self,
a99f0b8
 
a99f0b8
 	nis_domain = rc.nis_domain;
a99f0b8
 
a99f0b8
-	/* Build up config lists for plugins; we use the raw configs here, not the
a99f0b8
-	 * merged information that we write to resolv.conf so that the plugins can
a99f0b8
-	 * still use the domain information in each config to provide split DNS if
a99f0b8
-	 * they want to.
a99f0b8
-	 */
a99f0b8
-	if (priv->ip4_vpn_config)
a99f0b8
-		vpn_configs = g_slist_append (vpn_configs, priv->ip4_vpn_config);
a99f0b8
-	if (priv->ip6_vpn_config)
a99f0b8
-		vpn_configs = g_slist_append (vpn_configs, priv->ip6_vpn_config);
a99f0b8
-	if (priv->ip4_device_config)
a99f0b8
-		dev_configs = g_slist_append (dev_configs, priv->ip4_device_config);
a99f0b8
-	if (priv->ip6_device_config)
a99f0b8
-		dev_configs = g_slist_append (dev_configs, priv->ip6_device_config);
a99f0b8
-
a99f0b8
-	for (iter = priv->configs; iter; iter = g_slist_next (iter)) {
a99f0b8
-		if (   (iter->data != priv->ip4_vpn_config)
a99f0b8
-		    && (iter->data != priv->ip4_device_config)
a99f0b8
-		    && (iter->data != priv->ip6_vpn_config)
a99f0b8
-		    && (iter->data != priv->ip6_device_config))
a99f0b8
-			other_configs = g_slist_append (other_configs, iter->data);
a99f0b8
-	}
a99f0b8
-
a99f0b8
 	/* Let any plugins do their thing first */
a99f0b8
 	if (priv->plugin) {
a99f0b8
 		NMDnsPlugin *plugin = priv->plugin;
a99f0b8
 		const char *plugin_name = nm_dns_plugin_get_name (plugin);
a99f0b8
+		GSList *vpn_configs = NULL, *dev_configs = NULL, *other_configs = NULL;
a99f0b8
 
a99f0b8
 		if (nm_dns_plugin_is_caching (plugin)) {
a99f0b8
 			if (no_caching) {
a99f0b8
@@ -710,6 +725,8 @@ update_dns (NMDnsManager *self,
a99f0b8
 			caching = TRUE;
a99f0b8
 		}
a99f0b8
 
a99f0b8
+		build_plugin_config_lists (self, &vpn_configs, &dev_configs, &other_configs);
a99f0b8
+
a99f0b8
 		nm_log_dbg (LOGD_DNS, "DNS: updating plugin %s", plugin_name);
a99f0b8
 		if (!nm_dns_plugin_update (plugin,
a99f0b8
 		                           vpn_configs,
a99f0b8
@@ -723,15 +740,14 @@ update_dns (NMDnsManager *self,
a99f0b8
 			 */
a99f0b8
 			caching = FALSE;
a99f0b8
 		}
a99f0b8
+		g_slist_free (vpn_configs);
a99f0b8
+		g_slist_free (dev_configs);
a99f0b8
+		g_slist_free (other_configs);
a99f0b8
 
a99f0b8
 	skip:
a99f0b8
 		;
a99f0b8
 	}
a99f0b8
 
a99f0b8
-	g_slist_free (vpn_configs);
a99f0b8
-	g_slist_free (dev_configs);
a99f0b8
-	g_slist_free (other_configs);
a99f0b8
-
a99f0b8
 	/* If caching was successful, we only send 127.0.0.1 to /etc/resolv.conf
a99f0b8
 	 * to ensure that the glibc resolver doesn't try to round-robin nameservers,
a99f0b8
 	 * but only uses the local caching nameserver.
a99f0b8
-- 
a99f0b8
2.4.0
a99f0b8