diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index d7fcb53033..f02849b661 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -33,6 +33,21 @@ gboolean nm_ethernet_address_is_valid (gconstpointer addr, gssize len); in_addr_t nm_utils_ip4_address_clear_host_address (in_addr_t addr, guint8 plen); void nm_utils_ip6_address_clear_host_address (struct in6_addr *dst, const struct in6_addr *src, guint8 plen); +/** + * nm_utils_ip6_route_metric_normalize: + * @metric: the route metric + * + * For IPv6 route, kernel treats the value 0 as IP6_RT_PRIO_USER (1024). + * Thus, when comparing metric (values), we want to treat zero as NM_PLATFORM_ROUTE_METRIC_DEFAULT. + * + * Returns: @metric, if @metric is not zero, otherwise 1024. + */ +static inline guint32 +nm_utils_ip6_route_metric_normalize (guint32 metric) +{ + return metric ? metric : 1024 /*NM_PLATFORM_ROUTE_METRIC_DEFAULT*/; +} + int nm_spawn_process (const char *args); /* macro to return strlen() of a compile time string. */ diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index cd2729cddf..13e25affbd 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -216,6 +216,8 @@ G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPAddress, address_ptr) == G_STRUCT_ #undef __NMPlatformIPAddress_COMMON +/* Adding an IPv6 route with metric 0, kernel translates to IP6_RT_PRIO_USER (1024). + * Thus, the value is not choosen arbitraily, but matches kernel IPv6 default. */ #define NM_PLATFORM_ROUTE_METRIC_DEFAULT 1024 #define __NMPlatformIPRoute_COMMON \