|
|
|
@@ -309,6 +309,30 @@ _match_connection_new (void)
|
|
|
|
|
return connection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMConnection *
|
|
|
|
|
_match_connection (GSList *connections,
|
|
|
|
|
NMConnection *original,
|
|
|
|
|
gboolean device_has_carrier,
|
|
|
|
|
gint64 default_v4_metric,
|
|
|
|
|
gint64 default_v6_metric)
|
|
|
|
|
{
|
|
|
|
|
NMConnection **list;
|
|
|
|
|
guint i, len;
|
|
|
|
|
|
|
|
|
|
len = g_slist_length (connections);
|
|
|
|
|
g_assert (len < 10);
|
|
|
|
|
|
|
|
|
|
list = g_alloca ((len + 1) * sizeof (NMConnection *));
|
|
|
|
|
for (i = 0; i < len; i++, connections = connections->next) {
|
|
|
|
|
g_assert (connections);
|
|
|
|
|
g_assert (connections->data);
|
|
|
|
|
list[i] = connections->data;
|
|
|
|
|
}
|
|
|
|
|
list[i] = NULL;
|
|
|
|
|
|
|
|
|
|
return nm_utils_match_connection (list, original, device_has_carrier, default_v4_metric, default_v6_metric, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_connection_match_basic (void)
|
|
|
|
|
{
|
|
|
|
@@ -320,7 +344,7 @@ test_connection_match_basic (void)
|
|
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
|
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
/* Now change a material property like IPv4 method and ensure matching fails */
|
|
|
|
@@ -329,7 +353,7 @@ test_connection_match_basic (void)
|
|
|
|
|
g_object_set (G_OBJECT (s_ip4),
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
|
|
|
|
|
NULL);
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == NULL);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -365,7 +389,7 @@ test_connection_match_ip6_method (void)
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -399,7 +423,7 @@ test_connection_match_ip6_method_ignore (void)
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -433,7 +457,7 @@ test_connection_match_ip6_method_ignore_auto (void)
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -469,11 +493,11 @@ test_connection_match_ip4_method (void)
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, FALSE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, FALSE, 0, 0);
|
|
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
/* Ensure when carrier=true matching fails */
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == NULL);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -507,7 +531,7 @@ test_connection_match_interface_name (void)
|
|
|
|
|
NM_SETTING_CONNECTION_INTERFACE_NAME, NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -544,7 +568,7 @@ test_connection_match_wired (void)
|
|
|
|
|
NM_SETTING_WIRED_S390_NETTYPE, "qeth",
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -576,7 +600,7 @@ test_connection_match_wired2 (void)
|
|
|
|
|
* the connections match. It can happen if assuming VLAN devices. */
|
|
|
|
|
nm_connection_remove_setting (orig, NM_TYPE_SETTING_WIRED);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -601,7 +625,7 @@ test_connection_match_cloned_mac (void)
|
|
|
|
|
NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23",
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == fuzzy);
|
|
|
|
|
|
|
|
|
|
exact = nm_simple_connection_new_clone (orig);
|
|
|
|
@@ -612,14 +636,14 @@ test_connection_match_cloned_mac (void)
|
|
|
|
|
NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23",
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
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, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched == fuzzy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -679,7 +703,7 @@ test_connection_no_match_ip4_addr (void)
|
|
|
|
|
nm_setting_ip_config_add_address (s_ip4, nm_addr);
|
|
|
|
|
nm_ip_address_unref (nm_addr);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched != copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -725,7 +749,7 @@ test_connection_no_match_vlan (void)
|
|
|
|
|
NM_SETTING_VLAN_FLAGS, 0,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched != copy);
|
|
|
|
|
|
|
|
|
|
/* Check that the connections do not match if VLAN priorities differ */
|
|
|
|
@@ -735,7 +759,7 @@ test_connection_no_match_vlan (void)
|
|
|
|
|
g_object_set (G_OBJECT (s_vlan_copy), NM_SETTING_VLAN_FLAGS, 0, NULL);
|
|
|
|
|
nm_setting_vlan_add_priority_str (s_vlan_copy, NM_VLAN_INGRESS_MAP, "4:2");
|
|
|
|
|
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
|
|
|
|
g_assert (matched != copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
@@ -775,7 +799,7 @@ test_connection_match_ip4_routes1 (void)
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip4, "172.25.17.0", 24, "10.0.0.3", 20);
|
|
|
|
|
|
|
|
|
|
/* Try to match the connections */
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, FALSE, 100, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, FALSE, 100, 0);
|
|
|
|
|
g_assert (matched == NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -812,9 +836,9 @@ test_connection_match_ip4_routes2 (void)
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip4, "172.25.16.0", 24, "10.0.0.2", 100);
|
|
|
|
|
|
|
|
|
|
/* Try to match the connections using different default metrics */
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, FALSE, 100, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, FALSE, 100, 0);
|
|
|
|
|
g_assert (matched == copy);
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, FALSE, 500, 0, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, FALSE, 500, 0);
|
|
|
|
|
g_assert (matched == NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -849,9 +873,9 @@ test_connection_match_ip6_routes (void)
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip6, "2001:db8:a:b:0:0:0:0", 64, "fd01::16", 50);
|
|
|
|
|
|
|
|
|
|
/* Try to match the connections */
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, FALSE, 0, 100, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, FALSE, 0, 100);
|
|
|
|
|
g_assert (matched == NULL);
|
|
|
|
|
matched = nm_utils_match_connection (connections, orig, FALSE, 0, 50, NULL, NULL);
|
|
|
|
|
matched = _match_connection (connections, orig, FALSE, 0, 50);
|
|
|
|
|
g_assert (matched == copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|