summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-03-18 14:21:59 +0100
committerJiří Klimeš <jklimes@redhat.com>2014-03-21 09:24:13 +0100
commit7ff7df76404099601dddaf4b64daea2e5024ce61 (patch)
treec262869f600492cdfb873fb246cd6510c32caa1b
parente4bcfc20ca6de7a39506a2eda050fa144e3cc52c (diff)
downloadNetworkManager-7ff7df76404099601dddaf4b64daea2e5024ce61.tar.gz
core: improve ifname matching of existing x generated connections (rh #1077743)
DEVICE="ens3" ONBOOT=yes NETBOOT=yes UUID="23466771-f5fa-4ca9-856f-eaf4a8e20c3f" BOOTPROTO=none IPADDR="10.0.0.2" PREFIX="24" GATEWAY="10.0.0.1" HWADDR="52:54:00:12:34:56" TYPE=Ethernet NAME="ens3" This ifcfg file results in connection.interface-name=ens3. However, device-generated connection didn't set interface-name property. Fix that by setting interface-name property when generating a connection. Also allow matching connections if interface-name is not set in a connection. https://bugzilla.redhat.com/show_bug.cgi?id=1077743
-rw-r--r--src/NetworkManagerUtils.c32
-rw-r--r--src/devices/nm-device.c1
-rw-r--r--src/tests/test-general.c35
3 files changed, 68 insertions, 0 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index c5823e80c3..fbd69129b9 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -753,6 +753,35 @@ check_ip4_method_disabled_auto (NMConnection *orig,
return FALSE;
}
+static gboolean
+check_connection_interface_name (NMConnection *orig,
+ NMConnection *candidate,
+ GHashTable *settings)
+{
+ GHashTable *props;
+ const char *orig_ifname, *cand_ifname;
+ NMSettingConnection *s_con_orig, *s_con_cand;
+
+ props = g_hash_table_lookup (settings, NM_SETTING_CONNECTION_SETTING_NAME);
+ if ( !props
+ || (g_hash_table_size (props) != 1)
+ || !g_hash_table_lookup (props, NM_SETTING_CONNECTION_INTERFACE_NAME)) {
+ /* We only handle 'interface-name' here. */
+ return FALSE;
+ }
+
+ /* If one of the interface name is NULL, we accept that connection */
+ s_con_orig = nm_connection_get_setting_connection (orig);
+ s_con_cand = nm_connection_get_setting_connection (candidate);
+ orig_ifname = nm_setting_connection_get_interface_name (s_con_orig);
+ cand_ifname = nm_setting_connection_get_interface_name (s_con_cand);
+
+ if (!orig_ifname || !cand_ifname)
+ return TRUE;
+
+ return FALSE;
+}
+
static NMConnection *
check_possible_match (NMConnection *orig,
NMConnection *candidate,
@@ -770,6 +799,9 @@ check_possible_match (NMConnection *orig,
if (check_ip4_method_disabled_auto (orig, candidate, settings, device_has_carrier))
return candidate;
+ if (check_connection_interface_name (orig, candidate, settings))
+ return candidate;
+
return NULL;
}
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index ea5f3affec..9361aac50d 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -1790,6 +1790,7 @@ nm_device_generate_connection (NMDevice *device)
NM_SETTING_CONNECTION_UUID, uuid,
NM_SETTING_CONNECTION_ID, name,
NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
+ NM_SETTING_CONNECTION_INTERFACE_NAME, ifname,
NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL),
NULL);
if (klass->connection_type)
diff --git a/src/tests/test-general.c b/src/tests/test-general.c
index a62a1ef621..4711bc5f30 100644
--- a/src/tests/test-general.c
+++ b/src/tests/test-general.c
@@ -312,6 +312,40 @@ test_connection_match_ip4_method (void)
g_object_unref (copy);
}
+static void
+test_connection_match_interface_name (void)
+{
+ NMConnection *orig, *copy, *matched;
+ GSList *connections = NULL;
+ NMSettingConnection *s_con;
+
+ orig = _match_connection_new ();
+ copy = nm_connection_duplicate (orig);
+ connections = g_slist_append (connections, copy);
+
+ /* Check that if the original connection is IPv6 method=link-local, and the
+ * candidate is method=ignore, that the candidate is matched.
+ */
+ s_con = nm_connection_get_setting_connection (orig);
+ g_assert (s_con);
+ g_object_set (G_OBJECT (s_con),
+ NM_SETTING_CONNECTION_INTERFACE_NAME, "em1",
+ NULL);
+
+ s_con = nm_connection_get_setting_connection (copy);
+ g_assert (s_con);
+ g_object_set (G_OBJECT (s_con),
+ NM_SETTING_CONNECTION_INTERFACE_NAME, NULL,
+ NULL);
+
+ matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
+ g_assert (matched == copy);
+
+ g_slist_free (connections);
+ g_object_unref (orig);
+ g_object_unref (copy);
+}
+
/*******************************************/
int
@@ -328,6 +362,7 @@ main (int argc, char **argv)
g_test_add_func ("/general/connection-match/ip6-method", test_connection_match_ip6_method);
g_test_add_func ("/general/connection-match/ip6-method-ignore", test_connection_match_ip6_method_ignore);
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);
return g_test_run ();
}