Blame SOURCES/0008-match-cloned-mac-with-empty-one-rh1256430.patch

ab7d06
From d40ace0df0a6796cdc444a1fc89ba2835734845d Mon Sep 17 00:00:00 2001
ab7d06
From: Lubomir Rintel <lkundrak@v3.sk>
ab7d06
Date: Thu, 19 Feb 2015 17:53:43 +0100
ab7d06
Subject: [PATCH] utils: match a cloned mac address with a connection that does
ab7d06
 not specify it
ab7d06
ab7d06
We do the same for the original MAC address.
ab7d06
ab7d06
A device enslaved to a bond it inherits the bond's MAC address. When
ab7d06
NetworkManager tries to assume a connection the generated cloned-mac property
ab7d06
causes a mismatch with the connection that originally brought up the device,
ab7d06
causing the generated connection to be used instead:
ab7d06
ab7d06
  NetworkManager[14190]: <debug> [1424355817.112154] [NetworkManagerUtils.c:1641]
ab7d06
         nm_utils_match_connection(): Connection 'eth2' differs from candidate
ab7d06
         'bond-slave-eth2' in 802-3-ethernet.cloned-mac-address
ab7d06
ab7d06
https://bugzilla.gnome.org/show_bug.cgi?id=744812
ab7d06
https://bugzilla.redhat.com/show_bug.cgi?id=1256430
ab7d06
(cherry picked from commit cd2cef9cab62db042f646bf0fcdc318106fc627f)
ab7d06
---
ab7d06
 src/NetworkManagerUtils.c | 36 ++++++++++++++++++++++++++++++++++++
ab7d06
 src/tests/test-general.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
ab7d06
 2 files changed, 81 insertions(+)
ab7d06
ab7d06
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
ab7d06
index 63741dc..584b10c 100644
ab7d06
--- a/src/NetworkManagerUtils.c
ab7d06
+++ b/src/NetworkManagerUtils.c
ab7d06
@@ -2033,6 +2033,39 @@ check_connection_mac_address (NMConnection *orig,
ab7d06
 	return FALSE;
ab7d06
 }
ab7d06
 
ab7d06
+static gboolean
ab7d06
+check_connection_cloned_mac_address (NMConnection *orig,
ab7d06
+                              NMConnection *candidate,
ab7d06
+                              GHashTable *settings)
ab7d06
+{
ab7d06
+	GHashTable *props;
ab7d06
+	const char *orig_mac = NULL, *cand_mac = NULL;
ab7d06
+	NMSettingWired *s_wired_orig, *s_wired_cand;
ab7d06
+
ab7d06
+	props = check_property_in_hash (settings,
ab7d06
+	                                NM_SETTING_WIRED_SETTING_NAME,
ab7d06
+	                                NM_SETTING_WIRED_CLONED_MAC_ADDRESS);
ab7d06
+	if (!props)
ab7d06
+		return TRUE;
ab7d06
+
ab7d06
+	/* If one of the MAC addresses is NULL, we accept that connection */
ab7d06
+	s_wired_orig = nm_connection_get_setting_wired (orig);
ab7d06
+	if (s_wired_orig)
ab7d06
+		orig_mac = nm_setting_wired_get_cloned_mac_address (s_wired_orig);
ab7d06
+
ab7d06
+	s_wired_cand = nm_connection_get_setting_wired (candidate);
ab7d06
+	if (s_wired_cand)
ab7d06
+		cand_mac = nm_setting_wired_get_cloned_mac_address (s_wired_cand);
ab7d06
+
ab7d06
+	if (!orig_mac || !cand_mac) {
ab7d06
+		remove_from_hash (settings, props,
ab7d06
+		                  NM_SETTING_WIRED_SETTING_NAME,
ab7d06
+		                  NM_SETTING_WIRED_CLONED_MAC_ADDRESS);
ab7d06
+		return TRUE;
ab7d06
+	}
ab7d06
+	return FALSE;
ab7d06
+}
ab7d06
+
ab7d06
 static NMConnection *
ab7d06
 check_possible_match (NMConnection *orig,
ab7d06
                       NMConnection *candidate,
ab7d06
@@ -2053,6 +2086,9 @@ check_possible_match (NMConnection *orig,
ab7d06
 	if (!check_connection_mac_address (orig, candidate, settings))
ab7d06
 		return NULL;
ab7d06
 
ab7d06
+	if (!check_connection_cloned_mac_address (orig, candidate, settings))
ab7d06
+		return NULL;
ab7d06
+
ab7d06
 	if (g_hash_table_size (settings) == 0)
ab7d06
 		return candidate;
ab7d06
 	else
ab7d06
diff --git a/src/tests/test-general.c b/src/tests/test-general.c
ab7d06
index de65d50..eda7a1f 100644
ab7d06
--- a/src/tests/test-general.c
ab7d06
+++ b/src/tests/test-general.c
ab7d06
@@ -440,6 +440,50 @@ test_connection_match_wired (void)
ab7d06
 }
ab7d06
 
ab7d06
 static void
ab7d06
+test_connection_match_cloned_mac (void)
ab7d06
+{
ab7d06
+	NMConnection *orig, *exact, *fuzzy, *matched;
ab7d06
+	GSList *connections = NULL;
ab7d06
+	NMSettingWired *s_wired;
ab7d06
+
ab7d06
+	orig = _match_connection_new ();
ab7d06
+
ab7d06
+	fuzzy = nm_simple_connection_new_clone (orig);
ab7d06
+	connections = g_slist_append (connections, fuzzy);
ab7d06
+	s_wired = nm_connection_get_setting_wired (orig);
ab7d06
+	g_assert (s_wired);
ab7d06
+	g_object_set (G_OBJECT (s_wired),
ab7d06
+	              NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23",
ab7d06
+	              NULL);
ab7d06
+
ab7d06
+	matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
ab7d06
+	g_assert (matched == fuzzy);
ab7d06
+
ab7d06
+	exact = nm_simple_connection_new_clone (orig);
ab7d06
+	connections = g_slist_append (connections, exact);
ab7d06
+	s_wired = nm_connection_get_setting_wired (exact);
ab7d06
+	g_assert (s_wired);
ab7d06
+	g_object_set (G_OBJECT (s_wired),
ab7d06
+	              NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23",
ab7d06
+	              NULL);
ab7d06
+
ab7d06
+	matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
ab7d06
+	g_assert (matched == exact);
ab7d06
+
ab7d06
+	g_object_set (G_OBJECT (s_wired),
ab7d06
+	              NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:24",
ab7d06
+	              NULL);
ab7d06
+
ab7d06
+	matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
ab7d06
+	g_assert (matched == fuzzy);
ab7d06
+
ab7d06
+	g_slist_free (connections);
ab7d06
+	g_object_unref (orig);
ab7d06
+	g_object_unref (fuzzy);
ab7d06
+	g_object_unref (exact);
ab7d06
+}
ab7d06
+
ab7d06
+static void
ab7d06
 test_connection_no_match_ip4_addr (void)
ab7d06
 {
ab7d06
 	NMConnection *orig, *copy, *matched;
ab7d06
@@ -747,6 +791,7 @@ main (int argc, char **argv)
ab7d06
 	g_test_add_func ("/general/connection-match/ip4-method", test_connection_match_ip4_method);
ab7d06
 	g_test_add_func ("/general/connection-match/con-interface-name", test_connection_match_interface_name);
ab7d06
 	g_test_add_func ("/general/connection-match/wired", test_connection_match_wired);
ab7d06
+	g_test_add_func ("/general/connection-match/cloned_mac", test_connection_match_cloned_mac);
ab7d06
 	g_test_add_func ("/general/connection-match/no-match-ip4-addr", test_connection_no_match_ip4_addr);
ab7d06
 
ab7d06
 	g_test_add_func ("/general/connection-sort/autoconnect-priority", test_connection_sort_autoconnect_priority);
ab7d06
-- 
ab7d06
2.4.3
ab7d06