core: suppress onlink flag for IPv4 routes without gateway

(cherry picked from commit e59d09b053)
This commit is contained in:
Thomas Haller
2023-02-01 22:40:38 +01:00
parent 4ccca2b5bd
commit f71572a4bc
2 changed files with 21 additions and 1 deletions

View File

@@ -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); 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); nm_l3_config_data_add_route(self, addr_family, NULL, &r.rx);
} }

View File

@@ -1116,7 +1116,11 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass)
* <para><literal>"mtu"</literal> - an unsigned 32 bit integer.</para> * <para><literal>"mtu"</literal> - an unsigned 32 bit integer.</para>
* </listitem> * </listitem>
* <listitem> * <listitem>
* <para><literal>"onlink"</literal> - a boolean value.</para> * <para><literal>"onlink"</literal> - 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.
* </para>
* </listitem> * </listitem>
* <listitem> * <listitem>
* <para><literal>"quickack"</literal> - a boolean value.</para> * <para><literal>"quickack"</literal> - a boolean value.</para>