diff options
author | Thomas Haller <thaller@redhat.com> | 2017-04-13 19:15:02 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-04-15 00:35:25 +0200 |
commit | 034b7fb51c1d16a4002d2902c60aac05e946bb4f (patch) | |
tree | c635c0546deb0efdbb7f6a3c31f5020b6cce87a2 | |
parent | 57b0dce083a1991530e14735588d873e441f26fa (diff) | |
download | NetworkManager-034b7fb51c1d16a4002d2902c60aac05e946bb4f.tar.gz |
src: only compare network parts of routes in nm_utils_match_connection()
Kernel requires that routes have a host part of zero. For NetworkManager
configuration we allow non-zero host parts (but ignore them). Fix
route_compare() to ignore the host part.
This has only effect during assuming connections. That means, on
restart NM would fail to match a connection with static routes
if it has a non-zero host part. So, the impact is rather small.
-rw-r--r-- | src/NetworkManagerUtils.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index fbca3b82f3..779dc8aaeb 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -342,18 +342,19 @@ static int route_compare (NMIPRoute *route1, NMIPRoute *route2, gint64 default_metric) { gint64 r, metric1, metric2; + int family; + guint plen; + NMIPAddr a1 = { 0 }, a2 = { 0 }; - r = g_strcmp0 (nm_ip_route_get_dest (route1), nm_ip_route_get_dest (route2)); - if (r) - return r; - - r = nm_ip_route_get_prefix (route1) - nm_ip_route_get_prefix (route2); + family = nm_ip_route_get_family (route1); + r = family - nm_ip_route_get_family (route2); if (r) return r > 0 ? 1 : -1; - r = g_strcmp0 (nm_ip_route_get_next_hop (route1), nm_ip_route_get_next_hop (route2)); + plen = nm_ip_route_get_prefix (route1); + r = plen - nm_ip_route_get_prefix (route2); if (r) - return r; + return r > 0 ? 1 : -1; metric1 = nm_ip_route_get_metric (route1) == -1 ? default_metric : nm_ip_route_get_metric (route1); metric2 = nm_ip_route_get_metric (route2) == -1 ? default_metric : nm_ip_route_get_metric (route2); @@ -362,9 +363,18 @@ route_compare (NMIPRoute *route1, NMIPRoute *route2, gint64 default_metric) if (r) return r > 0 ? 1 : -1; - r = nm_ip_route_get_family (route1) - nm_ip_route_get_family (route2); + r = g_strcmp0 (nm_ip_route_get_next_hop (route1), nm_ip_route_get_next_hop (route2)); if (r) - return r > 0 ? 1 : -1; + return r; + + /* NMIPRoute validates family and dest. inet_pton() is not expected to fail. */ + inet_pton (family, nm_ip_route_get_dest (route1), &a1); + inet_pton (family, nm_ip_route_get_dest (route2), &a2); + nm_utils_ipx_address_clear_host_address (family, &a1, &a1, plen); + nm_utils_ipx_address_clear_host_address (family, &a2, &a2, plen); + r = memcmp (&a1, &a2, sizeof (a1)); + if (r) + return r; return 0; } |