From f71572a4bc18df5c92e826613a747d36a50ed8b3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 1 Feb 2023 22:40:38 +0100 Subject: [PATCH] core: suppress onlink flag for IPv4 routes without gateway (cherry picked from commit e59d09b05308353c56211c4a6ea66a8c6bf1bb6a) --- src/core/nm-l3-config-data.c | 16 ++++++++++++++++ src/libnm-core-impl/nm-setting-ip4-config.c | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/core/nm-l3-config-data.c b/src/core/nm-l3-config-data.c index 30a9b5444..17bb9db87 100644 --- a/src/core/nm-l3-config-data.c +++ b/src/core/nm-l3-config-data.c @@ -2851,6 +2851,22 @@ _init_from_connection_ip(NML3ConfigData *self, int addr_family, NMConnection *co nm_utils_ip_route_attribute_to_platform(addr_family, s_route, &r.rx, -1); + if (IS_IPv4 && r.r4.gateway == 0) { + /* As far as kernel is concerned, an IPv4 without gateway cannot have + * the onlink flag set, we need to clear it. If we wouldn't clear it, + * then the address we would add in kernel would be entirely different than + * the one we create here (because the "onlink" flag is part of the + * identifier of a route, see nm_platform_ip4_route_cmp()). + * + * Note however that for ECMP routes we currently can only merge routes + * that agree in their onlink flag. So a route without gateway cannot + * merge with an onlink route that has a gateway. That needs fixing, + * by not treating the onlink flag as for the entire route, but allowing + * to merge ECMP routes with different onlink flag. And first, we need + * to track the onlink flag for the nexthop (NMPlatformIP4RtNextHop). */ + r.r4.r_rtm_flags &= ~((unsigned) RTNH_F_ONLINK); + } + nm_l3_config_data_add_route(self, addr_family, NULL, &r.rx); } diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index d2ca88241..f847918ed 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -1116,7 +1116,11 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * "mtu" - an unsigned 32 bit integer. * * - * "onlink" - a boolean value. + * "onlink" - a boolean value. The onlink flag + * is ignored for IPv4 routes without a gateway. That also means, + * with a positive "weight" the route cannot merge with ECMP routes + * which are onlink and have a gateway. + * * * * "quickack" - a boolean value.