core: fix checks for default routes by comparing the prefix length

At some places, we considered a default route to be a route with
destination network 0.0.0.0 (::). This is wrong because a default route
is a route with plen==0.

This is for example relevant for OpenVPN which adds two routes
0.0.0.0/1 and 128.0.0.0/1 to hijack the default route. We should
not treat 0.0.0.0/1 as default route, instead  NM should treat
it as any other subnet route (even if it effectively routes large
parts).

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2014-07-29 19:10:08 +02:00
parent a7f05b84f8
commit 06703c1670
4 changed files with 11 additions and 6 deletions

View File

@@ -3553,7 +3553,7 @@ ip4_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
for (object = nl_cache_get_first (priv->route_cache); object; object = nl_cache_get_next (object)) {
if (_route_match ((struct rtnl_route *) object, AF_INET, ifindex)) {
if (init_ip4_route (&route, (struct rtnl_route *) object)) {
if (route.plen != 0 || include_default)
if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT (&route) || include_default)
g_array_append_val (routes, route);
}
}
@@ -3575,7 +3575,7 @@ ip6_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
for (object = nl_cache_get_first (priv->route_cache); object; object = nl_cache_get_next (object)) {
if (_route_match ((struct rtnl_route *) object, AF_INET6, ifindex)) {
if (init_ip6_route (&route, (struct rtnl_route *) object)) {
if (route.plen != 0 || include_default)
if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT (&route) || include_default)
g_array_append_val (routes, route);
}
}