diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index e27c0436ff..3956132bfe 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -198,7 +198,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) for (i = 0; i < priv->routes->len; 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) { priv->gateway = route->gateway; lowest_metric = route->metric; @@ -276,7 +276,8 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex) /* Don't add the default route if the 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; g_array_append_val (routes, route); diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 7a1f74af70..55c6b20050 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -308,7 +308,7 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co for (i = 0; i < priv->routes->len; 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) { priv->gateway = route->gateway; lowest_metric = route->metric; @@ -387,7 +387,8 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex) /* Don't add the default route if the 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; g_array_append_val (routes, route); diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 7b11a6b5b9..c18132760c 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -3523,7 +3523,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); } } @@ -3545,7 +3545,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); } } diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 96b6cfabbd..348d1fa546 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -248,6 +248,9 @@ typedef struct { }; } NMPlatformIPRoute; +#define NM_PLATFORM_IP_ROUTE_IS_DEFAULT(route) \ + ( ((const NMPlatformIPRoute *) (route))->plen <= 0 ) + typedef struct { __NMPlatformIPRoute_COMMON; in_addr_t network;