From 4ec2123aa22ca7bb960b05dbd082f2472b19becb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 3 Jan 2023 20:19:12 +0100 Subject: [PATCH] platform: parse routes of any type to handle replace When you issue ip route replace broadcast 1.2.3.4/32 dev eth0 then this route may well replace a (unicast) route that we have in the cache. Previously, we would right away ignore such messages in _new_from_nl_route(), which means we miss the fact that a route gets replaced. Instead, we need to parse the message at least so far, that we can detect and handle the replace. --- src/libnm-platform/nm-linux-platform.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index aea08e54f7..067eaf5463 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -3787,15 +3787,6 @@ _new_from_nl_route(const struct nlmsghdr *nlh, gboolean id_only, ParseNlmsgIter else return NULL; - if (!NM_IN_SET(rtm->rtm_type, - RTN_UNICAST, - RTN_LOCAL, - RTN_BLACKHOLE, - RTN_UNREACHABLE, - RTN_PROHIBIT, - RTN_THROW)) - return NULL; - if (nlmsg_parse_arr(nlh, sizeof(struct rtmsg), tb, policy) < 0) return NULL; @@ -5331,6 +5322,17 @@ ip_route_is_alive(const NMPlatformIPRoute *route) return FALSE; } + if (!NM_IN_SET(nm_platform_route_type_uncoerce(route->type_coerced), + RTN_UNICAST, + RTN_LOCAL, + RTN_BLACKHOLE, + RTN_UNREACHABLE, + RTN_PROHIBIT, + RTN_THROW)) { + /* Certain route types are ignored and not placed into the cache. */ + return FALSE; + } + return TRUE; }