summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2015-02-19 17:53:43 +0100
committerLubomir Rintel <lkundrak@v3.sk>2015-04-27 11:33:58 +0200
commitcd2cef9cab62db042f646bf0fcdc318106fc627f (patch)
tree1a6c3d42523c3c656a4333d7c152010c244203f9
parentcb6bafb9af721fcd2295b4da73f4a7812eb4f3e8 (diff)
downloadNetworkManager-cd2cef9cab62db042f646bf0fcdc318106fc627f.tar.gz
utils: match a cloned mac address with a connection that does not specify it
We do the same for the original MAC address. A device enslaved to a bond it inherits the bond's MAC address. When NetworkManager tries to assume a connection the generated cloned-mac property causes a mismatch with the connection that originally brought up the device, causing the generated connection to be used instead: NetworkManager[14190]: <debug> [1424355817.112154] [NetworkManagerUtils.c:1641] nm_utils_match_connection(): Connection 'eth2' differs from candidate 'bond-slave-eth2' in 802-3-ethernet.cloned-mac-address https://bugzilla.gnome.org/show_bug.cgi?id=744812
-rw-r--r--src/NetworkManagerUtils.c36
-rw-r--r--src/tests/test-general.c45
2 files changed, 81 insertions, 0 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index a5de386652..0f957814d3 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -1646,6 +1646,39 @@ check_connection_mac_address (NMConnection *orig,
return FALSE;
}
+static gboolean
+check_connection_cloned_mac_address (NMConnection *orig,
+ NMConnection *candidate,
+ GHashTable *settings)
+{
+ GHashTable *props;
+ const char *orig_mac = NULL, *cand_mac = NULL;
+ NMSettingWired *s_wired_orig, *s_wired_cand;
+
+ props = check_property_in_hash (settings,
+ NM_SETTING_WIRED_SETTING_NAME,
+ NM_SETTING_WIRED_CLONED_MAC_ADDRESS);
+ if (!props)
+ return TRUE;
+
+ /* If one of the MAC addresses is NULL, we accept that connection */
+ s_wired_orig = nm_connection_get_setting_wired (orig);
+ if (s_wired_orig)
+ orig_mac = nm_setting_wired_get_cloned_mac_address (s_wired_orig);
+
+ s_wired_cand = nm_connection_get_setting_wired (candidate);
+ if (s_wired_cand)
+ cand_mac = nm_setting_wired_get_cloned_mac_address (s_wired_cand);
+
+ if (!orig_mac || !cand_mac) {
+ remove_from_hash (settings, props,
+ NM_SETTING_WIRED_SETTING_NAME,
+ NM_SETTING_WIRED_CLONED_MAC_ADDRESS);
+ return TRUE;
+ }
+ return FALSE;
+}
+
static NMConnection *
check_possible_match (NMConnection *orig,
NMConnection *candidate,
@@ -1666,6 +1699,9 @@ check_possible_match (NMConnection *orig,
if (!check_connection_mac_address (orig, candidate, settings))
return NULL;
+ if (!check_connection_cloned_mac_address (orig, candidate, settings))
+ return NULL;
+
if (g_hash_table_size (settings) == 0)
return candidate;
else
diff --git a/src/tests/test-general.c b/src/tests/test-general.c
index dae872c86d..baea1d54e2 100644
--- a/src/tests/test-general.c
+++ b/src/tests/test-general.c
@@ -440,6 +440,50 @@ test_connection_match_wired (void)
}
static void
+test_connection_match_cloned_mac (void)
+{
+ NMConnection *orig, *exact, *fuzzy, *matched;
+ GSList *connections = NULL;
+ NMSettingWired *s_wired;
+
+ orig = _match_connection_new ();
+
+ fuzzy = nm_simple_connection_new_clone (orig);
+ connections = g_slist_append (connections, fuzzy);
+ s_wired = nm_connection_get_setting_wired (orig);
+ g_assert (s_wired);
+ g_object_set (G_OBJECT (s_wired),
+ NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23",
+ NULL);
+
+ matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
+ g_assert (matched == fuzzy);
+
+ exact = nm_simple_connection_new_clone (orig);
+ connections = g_slist_append (connections, exact);
+ s_wired = nm_connection_get_setting_wired (exact);
+ g_assert (s_wired);
+ g_object_set (G_OBJECT (s_wired),
+ NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23",
+ NULL);
+
+ matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
+ g_assert (matched == exact);
+
+ g_object_set (G_OBJECT (s_wired),
+ NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:24",
+ NULL);
+
+ matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
+ g_assert (matched == fuzzy);
+
+ g_slist_free (connections);
+ g_object_unref (orig);
+ g_object_unref (fuzzy);
+ g_object_unref (exact);
+}
+
+static void
test_connection_no_match_ip4_addr (void)
{
NMConnection *orig, *copy, *matched;
@@ -727,6 +771,7 @@ main (int argc, char **argv)
g_test_add_func ("/general/connection-match/ip4-method", test_connection_match_ip4_method);
g_test_add_func ("/general/connection-match/con-interface-name", test_connection_match_interface_name);
g_test_add_func ("/general/connection-match/wired", test_connection_match_wired);
+ g_test_add_func ("/general/connection-match/cloned_mac", test_connection_match_cloned_mac);
g_test_add_func ("/general/connection-match/no-match-ip4-addr", test_connection_no_match_ip4_addr);
g_test_add_func ("/general/connection-sort/autoconnect-priority", test_connection_sort_autoconnect_priority);