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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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 ();
|
||||
}
|
||||
|
Reference in New Issue
Block a user