From 84d93315d81182deec59ca0365fc9ad0cd79f28c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 21 Jul 2020 18:18:18 +0200 Subject: [PATCH] platform: add nmp_object_ip_route_is_best_defaut_route() helper --- src/platform/nmp-object.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index cef25ea79b..dd00522064 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -1039,4 +1039,22 @@ nmp_object_link_get_ifname (const NMPObject *obj) return NMP_OBJECT_CAST_LINK (obj)->name; } +static inline gboolean +nmp_object_ip_route_is_best_defaut_route (const NMPObject *obj) +{ + const NMPlatformIPRoute *r = NMP_OBJECT_CAST_IP_ROUTE (obj); + + /* return whether @obj is considered a default-route. + * + * NMIP4Config/NMIP6Config tracks the (best) default-route explicitly, because + * at various places we act differently depending on whether there is a default-route + * configured. + * + * Note that this only considers the main routing table. */ + return r + && NM_PLATFORM_IP_ROUTE_IS_DEFAULT (r) + && nm_platform_route_table_is_main (r->table_coerced) + && r->type_coerced == nm_platform_route_type_coerce (1 /* RTN_UNICAST */); +} + #endif /* __NMP_OBJECT_H__ */