core: ignore host-routes routes when matching generated connection

When we generate the connection in nm_device_generate_connection(), we
add all routes that have rt_source (roundtrip(NM_IP_CONFIG_SOURCE_USER)).
Especially since commit e470e13922, this
includes automatically added host-routes to the gateway, added by
ip4_config_merge_and_apply().

Later, during nm_utils_match_connection() this route most not prevent
matching. Either nm_device_generate_connection() should not add it, or
nm_utils_match_connection() should ignore it.

I think adjusting the matching is better, because ip-configs are used
for several things, including exposing routes on D-Bus. We don't want
to hide this route on D-Bus.

Fixes: e470e13922

https://bugzilla.redhat.com/show_bug.cgi?id=1487384
This commit is contained in:
Thomas Haller
2017-09-01 09:14:13 +02:00
parent 4fe884ad7e
commit 1b421645e4

View File

@@ -392,12 +392,14 @@ check_ip_routes (NMConnection *orig,
gint64 default_metric,
gboolean v4)
{
gs_free NMIPRoute **routes1 = NULL, **routes2 = NULL;
gs_free NMIPRoute **routes1 = NULL;
NMIPRoute **routes2;
NMSettingIPConfig *s_ip1, *s_ip2;
gint64 m;
const char *s_name;
GHashTable *props;
guint i, num;
guint i, i1, i2, num1, num2;
const guint8 PLEN = v4 ? 32 : 128;
s_name = v4 ? NM_SETTING_IP4_CONFIG_SETTING_NAME :
NM_SETTING_IP6_CONFIG_SETTING_NAME;
@@ -414,27 +416,49 @@ check_ip_routes (NMConnection *orig,
if (!s_ip1 || !s_ip2)
return FALSE;
num = nm_setting_ip_config_get_num_routes (s_ip1);
if (num != nm_setting_ip_config_get_num_routes (s_ip2))
return FALSE;
num1 = nm_setting_ip_config_get_num_routes (s_ip1);
num2 = nm_setting_ip_config_get_num_routes (s_ip2);
routes1 = g_new (NMIPRoute *, num);
routes2 = g_new (NMIPRoute *, num);
routes1 = g_new (NMIPRoute *, (gsize) num1 + num2);
routes2 = &routes1[num1];
for (i = 0; i < num; i++) {
for (i = 0; i < num1; i++)
routes1[i] = nm_setting_ip_config_get_route (s_ip1, i);
for (i = 0; i < num2; i++)
routes2[i] = nm_setting_ip_config_get_route (s_ip2, i);
}
m = nm_setting_ip_config_get_route_metric (s_ip2);
if (m != -1)
default_metric = m;
g_qsort_with_data (routes1, num, sizeof (NMIPRoute *), route_ptr_compare, &default_metric);
g_qsort_with_data (routes2, num, sizeof (NMIPRoute *), route_ptr_compare, &default_metric);
g_qsort_with_data (routes1, num1, sizeof (NMIPRoute *), route_ptr_compare, &default_metric);
g_qsort_with_data (routes2, num2, sizeof (NMIPRoute *), route_ptr_compare, &default_metric);
for (i = 0; i < num; i++) {
if (route_compare (routes1[i], routes2[i], default_metric))
for (i1 = 0, i2 = 0; i2 < num2; i1++) {
if (i1 >= num1)
return FALSE;
if (route_compare (routes1[i1], routes2[i2], default_metric) == 0) {
i2++;
continue;
}
/* if @orig (@routes1) contains /32 routes that are missing in @candidate,
* we accept that.
*
* A /32 may have been added automatically, as a direct-route to the gateway.
* The generated connection (@orig) would contain that route, so we shall ignore
* it.
*
* Likeweise for /128 for IPv6. */
if (nm_ip_route_get_prefix (routes1[i1]) == PLEN)
continue;
return FALSE;
}
/* check that @orig has no left-over (except host routes that we ignore). */
for (; i1 < num1; i1++) {
if (nm_ip_route_get_prefix (routes1[i1]) != PLEN)
return FALSE;
}