From 93fd03277fc7c81bddbe75cbea417a29db78befb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Jul 2017 07:21:01 +0200 Subject: [PATCH] platform: cleanup handling locks for non-exclusive routes --- src/platform/nm-linux-platform.c | 37 +++++++++++++++----------------- src/platform/nm-platform.c | 10 +++++++++ src/platform/nm-platform.h | 22 ++++++++++--------- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 37fe7398d..1e4ee8e58 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2033,11 +2033,11 @@ _new_from_nl_route (struct nlmsghdr *nlh, gboolean id_only) obj->ip_route.initrwnd = initrwnd; obj->ip_route.mtu = mtu; obj->ip_route.tos = rtm->rtm_tos; - obj->ip_route.lock_window = NM_FLAGS_HAS (lock, 1 << RTAX_WINDOW); - obj->ip_route.lock_cwnd = NM_FLAGS_HAS (lock, 1 << RTAX_CWND); + obj->ip_route.lock_window = NM_FLAGS_HAS (lock, 1 << RTAX_WINDOW); + obj->ip_route.lock_cwnd = NM_FLAGS_HAS (lock, 1 << RTAX_CWND); obj->ip_route.lock_initcwnd = NM_FLAGS_HAS (lock, 1 << RTAX_INITCWND); obj->ip_route.lock_initrwnd = NM_FLAGS_HAS (lock, 1 << RTAX_INITRWND); - obj->ip_route.lock_mtu = NM_FLAGS_HAS (lock, 1 << RTAX_MTU); + obj->ip_route.lock_mtu = NM_FLAGS_HAS (lock, 1 << RTAX_MTU); if (NM_FLAGS_HAS (rtm->rtm_flags, RTM_F_CLONED)) { /* we must not straight way reject cloned routes, because we might have cached @@ -2416,6 +2416,16 @@ nla_put_failure: g_return_val_if_reached (NULL); } +static guint32 +ip_route_get_lock_flag (const NMPlatformIPRoute *route) +{ + return (((guint32) route->lock_window) << RTAX_WINDOW) + | (((guint32) route->lock_cwnd) << RTAX_CWND) + | (((guint32) route->lock_initcwnd) << RTAX_INITCWND) + | (((guint32) route->lock_initrwnd) << RTAX_INITRWND) + | (((guint32) route->lock_mtu) << RTAX_MTU); +} + /* Copied and modified from libnl3's build_route_msg() and rtnl_route_build_msg(). */ static struct nl_msg * _nl_msg_new_route (int nlmsg_type, @@ -2424,12 +2434,12 @@ _nl_msg_new_route (int nlmsg_type, guint32 cwnd, guint32 initcwnd, guint32 initrwnd, - guint32 mtu, - guint32 lock) + guint32 mtu) { struct nl_msg *msg; const NMPClass *klass = NMP_OBJECT_GET_CLASS (obj); gboolean is_v4 = klass->addr_family == AF_INET; + const guint32 lock = ip_route_get_lock_flag (NMP_OBJECT_CAST_IP_ROUTE (obj)); struct rtmsg rtmsg = { .rtm_family = klass->addr_family, .rtm_tos = obj->ip_route.tos, @@ -5689,16 +5699,6 @@ ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, gui /*****************************************************************************/ -static guint32 -ip_route_get_lock_flag (NMPlatformIPRoute *route) -{ - return (((guint32) route->lock_window) << RTAX_WINDOW) - | (((guint32) route->lock_cwnd) << RTAX_CWND) - | (((guint32) route->lock_initcwnd) << RTAX_INITCWND) - | (((guint32) route->lock_initrwnd) << RTAX_INITRWND) - | (((guint32) route->lock_mtu) << RTAX_MTU); -} - static gboolean ip4_route_add (NMPlatform *platform, const NMPlatformIP4Route *route) { @@ -5719,8 +5719,7 @@ ip4_route_add (NMPlatform *platform, const NMPlatformIP4Route *route) route->cwnd, route->initcwnd, route->initrwnd, - route->mtu, - ip_route_get_lock_flag ((NMPlatformIPRoute *) route)); + route->mtu); return do_add_addrroute (platform, &obj, nlmsg); } @@ -5743,8 +5742,7 @@ ip6_route_add (NMPlatform *platform, const NMPlatformIP6Route *route) route->cwnd, route->initcwnd, route->initrwnd, - route->mtu, - ip_route_get_lock_flag ((NMPlatformIPRoute *) route)); + route->mtu); return do_add_addrroute (platform, &obj, nlmsg); } @@ -5798,7 +5796,6 @@ ip_route_delete (NMPlatform *platform, 0, 0, 0, - 0, 0); if (!nlmsg) return FALSE; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index cd2ebb6f5..487f3472d 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -4737,6 +4737,11 @@ nm_platform_ip4_route_hash (const NMPlatformIP4Route *obj, NMPlatformIPRouteCmpT h = NM_HASH_COMBINE (h, obj->mss); h = NM_HASH_COMBINE (h, obj->pref_src); h = NM_HASH_COMBINE (h, obj->window); + h = NM_HASH_COMBINE (h, obj->lock_window); + h = NM_HASH_COMBINE (h, obj->lock_cwnd); + h = NM_HASH_COMBINE (h, obj->lock_initcwnd); + h = NM_HASH_COMBINE (h, obj->lock_initrwnd); + h = NM_HASH_COMBINE (h, obj->lock_mtu); } break; case NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY: @@ -4795,6 +4800,11 @@ nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route NM_CMP_FIELD (a, b, mss); NM_CMP_FIELD (a, b, pref_src); NM_CMP_FIELD (a, b, window); + NM_CMP_FIELD_UNSAFE (a, b, lock_window); + NM_CMP_FIELD_UNSAFE (a, b, lock_cwnd); + NM_CMP_FIELD_UNSAFE (a, b, lock_initcwnd); + NM_CMP_FIELD_UNSAFE (a, b, lock_initrwnd); + NM_CMP_FIELD_UNSAFE (a, b, lock_mtu); } break; case NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY: diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 4043029ee..4ea2f91e1 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -347,15 +347,6 @@ typedef union { * of platform users. This flag is internal to track those hidden * routes. Such a route is not alive, according to nmp_object_is_alive(). */ \ bool rt_cloned:1; \ - bool lock_window:1; \ - bool lock_cwnd:1; \ - bool lock_initcwnd:1; \ - bool lock_initrwnd:1; \ - bool lock_mtu:1; \ - \ - guint32 metric; \ - \ - guint32 tos; \ \ \ /* RTA_METRICS: @@ -370,6 +361,13 @@ typedef union { * That is a problem/bug for IPv4 because you cannot explicitly select which * route to delete. Kernel just picks the first. See rh#1475642. */ \ \ + /* RTA_METRICS.RTAX_LOCK (iproute2: "lock" arguments) */ \ + bool lock_window:1; \ + bool lock_cwnd:1; \ + bool lock_initcwnd:1; \ + bool lock_initrwnd:1; \ + bool lock_mtu:1; \ + \ /* RTA_METRICS.RTAX_ADVMSS (iproute2: advmss) */ \ guint32 mss; \ \ @@ -380,7 +378,11 @@ typedef union { guint32 initcwnd; \ guint32 initrwnd; \ guint32 mtu; \ - ; + guint32 metric; \ + guint32 tos; \ + \ + /*end*/ + typedef struct { __NMPlatformIPRoute_COMMON;