core: don't configure IP routes unless there are also IP addresses

Since l3cfg rework, NetworkManager tracks IP routes early, not not only
when IP configuration is ready. That means, with `ipv4.method=auto` and
static `ipv4.routes`, then routes are most likely already configured
before the IP address is obtained via DHCP.

That may be desirable in some cases, but for many cases it's probably
wrong.

Instead, only configure the routes (with an ifindex) when we also have
an IP address.

https://bugzilla.redhat.com/show_bug.cgi?id=2102212

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1574
This commit is contained in:
Thomas Haller 2023-03-20 13:52:56 +01:00
parent 07c6f933d1
commit dabfa26a41
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -1188,6 +1188,7 @@ static void
_commit_collect_routes(NML3Cfg *self,
int addr_family,
NML3CfgCommitType commit_type,
gboolean any_addrs,
GPtrArray **routes,
GPtrArray **routes_nodev)
{
@ -1213,6 +1214,24 @@ _commit_collect_routes(NML3Cfg *self,
else {
nm_assert(NMP_OBJECT_CAST_IP_ROUTE(obj)->ifindex == self->priv.ifindex);
if (!any_addrs) {
/* This is a unicast route (or a similar route, which has an
* ifindex).
*
* However, during this commit we don't plan to configure any
* IP addresses. With `ipvx.method=manual` that should not be
* possible. More likely, this is because the profile has
* `ipvx.method=auto` and static routes.
*
* Don't configure any such routes before we also have at least
* one IP address.
*
* This code applies to IPv4 and IPv6, however for IPv6 we
* early on configure a link local address, so in practice the
* branch is not taken for IPv6. */
continue;
}
if (IS_IPv4 && NMP_OBJECT_CAST_IP4_ROUTE(obj)->weight > 0) {
/* This route needs to be registered as ECMP route. */
nm_netns_ip_route_ecmp_register(self->priv.netns, self, obj);
@ -4825,7 +4844,12 @@ _l3_commit_one(NML3Cfg *self,
addresses = _commit_collect_addresses(self, addr_family, commit_type);
_commit_collect_routes(self, addr_family, commit_type, &routes, &routes_nodev);
_commit_collect_routes(self,
addr_family,
commit_type,
nm_g_ptr_array_len(addresses) > 0,
&routes,
&routes_nodev);
route_table_sync =
self->priv.p->combined_l3cd_commited