summary refs log tree commit diff
path: root/src/nm-ip4-config.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2015-12-24 00:24:58 +0100
committerMichael Biebl <biebl@debian.org>2015-12-24 00:24:58 +0100
commit54f6333410ffd570e62717d9e77c5c987175e397 (patch)
treed0698cc29d0f53c0b6d2c68d35ee2e9d72153948 /src/nm-ip4-config.c
parenta6ece1a2aa19a6268335c87d4fdef20123dd04a5 (diff)
Imported Upstream version 1.0.10 upstream/1.0.10
Diffstat (limited to 'src/nm-ip4-config.c')
-rw-r--r--src/nm-ip4-config.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index 5918f3dc..f625d350 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -876,8 +876,8 @@ nm_ip4_config_intersect (NMIP4Config *dst, const NMIP4Config *src)
 
 /**
  * nm_ip4_config_replace:
- * @dst: config from which to remove everything in @src
- * @src: config to remove from @dst
+ * @dst: config to replace with @src content
+ * @src: source config to copy
  * @relevant_changes: return whether there are changes to the
  * destination object that are relevant. This is equal to
  * nm_ip4_config_equal() showing any difference.
@@ -922,7 +922,10 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
 	/* default gateway */
 	if (   src_priv->gateway != dst_priv->gateway
 	    || src_priv->has_gateway != dst_priv->has_gateway) {
-		nm_ip4_config_set_gateway (dst, src_priv->gateway);
+		if (src_priv->has_gateway)
+			nm_ip4_config_set_gateway (dst, src_priv->gateway);
+		else
+			nm_ip4_config_unset_gateway (dst);
 		has_relevant_changes = TRUE;
 	}
 
@@ -1629,16 +1632,31 @@ void
 nm_ip4_config_add_search (NMIP4Config *config, const char *new)
 {
 	NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
-	int i;
+	char *search;
+	size_t len;
 
 	g_return_if_fail (new != NULL);
 	g_return_if_fail (new[0] != '\0');
 
-	for (i = 0; i < priv->searches->len; i++)
-		if (!g_strcmp0 (g_ptr_array_index (priv->searches, i), new))
-			return;
+	search = g_strdup (new);
+
+	/* Remove trailing dot as it has no effect */
+	len = strlen (search);
+	if (search[len - 1] == '.')
+		search[len - 1] = 0;
+
+	if (!search[0]) {
+		g_free (search);
+		return;
+	}
+
+	if (_nm_utils_strv_find_first ((char **) priv->searches->pdata,
+	                               priv->searches->len, search) >= 0) {
+		g_free (search);
+		return;
+	}
 
-	g_ptr_array_add (priv->searches, g_strdup (new));
+	g_ptr_array_add (priv->searches, search);
 	_NOTIFY (config, PROP_SEARCHES);
 }