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:
@@ -197,7 +197,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
|
|||||||
for (i = 0; i < priv->routes->len; i++) {
|
for (i = 0; i < priv->routes->len; i++) {
|
||||||
const NMPlatformIP4Route *route = &g_array_index (priv->routes, NMPlatformIP4Route, i);
|
const NMPlatformIP4Route *route = &g_array_index (priv->routes, NMPlatformIP4Route, i);
|
||||||
|
|
||||||
if (route->network == 0) {
|
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) {
|
||||||
if (route->metric < lowest_metric) {
|
if (route->metric < lowest_metric) {
|
||||||
priv->gateway = route->gateway;
|
priv->gateway = route->gateway;
|
||||||
lowest_metric = route->metric;
|
lowest_metric = route->metric;
|
||||||
@@ -275,7 +275,8 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex)
|
|||||||
/* Don't add the default route if the connection
|
/* Don't add the default route if the connection
|
||||||
* is never supposed to be the default connection.
|
* is never supposed to be the default connection.
|
||||||
*/
|
*/
|
||||||
if (nm_ip4_config_get_never_default (config) && route.network == 0)
|
if ( nm_ip4_config_get_never_default (config)
|
||||||
|
&& NM_PLATFORM_IP_ROUTE_IS_DEFAULT (&route))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
g_array_append_val (routes, route);
|
g_array_append_val (routes, route);
|
||||||
|
@@ -307,7 +307,7 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co
|
|||||||
for (i = 0; i < priv->routes->len; i++) {
|
for (i = 0; i < priv->routes->len; i++) {
|
||||||
const NMPlatformIP6Route *route = &g_array_index (priv->routes, NMPlatformIP6Route, i);
|
const NMPlatformIP6Route *route = &g_array_index (priv->routes, NMPlatformIP6Route, i);
|
||||||
|
|
||||||
if (IN6_IS_ADDR_UNSPECIFIED (&route->network)) {
|
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) {
|
||||||
if (route->metric < lowest_metric) {
|
if (route->metric < lowest_metric) {
|
||||||
priv->gateway = route->gateway;
|
priv->gateway = route->gateway;
|
||||||
lowest_metric = route->metric;
|
lowest_metric = route->metric;
|
||||||
@@ -386,7 +386,8 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex)
|
|||||||
/* Don't add the default route if the connection
|
/* Don't add the default route if the connection
|
||||||
* is never supposed to be the default connection.
|
* is never supposed to be the default connection.
|
||||||
*/
|
*/
|
||||||
if (nm_ip6_config_get_never_default (config) && IN6_IS_ADDR_UNSPECIFIED (&route.network))
|
if ( nm_ip6_config_get_never_default (config)
|
||||||
|
&& NM_PLATFORM_IP_ROUTE_IS_DEFAULT (&route))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
g_array_append_val (routes, route);
|
g_array_append_val (routes, route);
|
||||||
|
@@ -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)) {
|
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 (_route_match ((struct rtnl_route *) object, AF_INET, ifindex)) {
|
||||||
if (init_ip4_route (&route, (struct rtnl_route *) object)) {
|
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);
|
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)) {
|
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 (_route_match ((struct rtnl_route *) object, AF_INET6, ifindex)) {
|
||||||
if (init_ip6_route (&route, (struct rtnl_route *) object)) {
|
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);
|
g_array_append_val (routes, route);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -250,6 +250,9 @@ typedef struct {
|
|||||||
};
|
};
|
||||||
} NMPlatformIPRoute;
|
} NMPlatformIPRoute;
|
||||||
|
|
||||||
|
#define NM_PLATFORM_IP_ROUTE_IS_DEFAULT(route) \
|
||||||
|
( ((const NMPlatformIPRoute *) (route))->plen <= 0 )
|
||||||
|
|
||||||
struct _NMPlatformIP4Route {
|
struct _NMPlatformIP4Route {
|
||||||
__NMPlatformIPRoute_COMMON;
|
__NMPlatformIPRoute_COMMON;
|
||||||
in_addr_t network;
|
in_addr_t network;
|
||||||
|
Reference in New Issue
Block a user