diff options
author | Thomas Haller <thaller@redhat.com> | 2014-08-29 10:06:22 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-10-31 18:31:19 +0100 |
commit | 22911696f49a282062733981d2f2f70ed279d64f (patch) | |
tree | 19ad36e8993773145eb97de32da3e5a120e27706 | |
parent | 0923769285ba6e5f665a3c9b5f01b17d1be34d5b (diff) | |
download | NetworkManager-22911696f49a282062733981d2f2f70ed279d64f.tar.gz |
core: add nm_utils_ip6_route_metric_normalize() function
Kernel treats IPv6 route metrics with value zero (0) special.
Add a utility function that helps accounting for that.
Signed-off-by: Thomas Haller <thaller@redhat.com>
https://bugzilla.gnome.org/show_bug.cgi?id=738590
-rw-r--r-- | src/NetworkManagerUtils.h | 15 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 2 |
2 files changed, 17 insertions, 0 deletions
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 \ |