summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-03-20 13:52:56 +0100
committerThomas Haller <thaller@redhat.com>2023-03-22 17:47:49 +0100
commitdabfa26a41edc7911a45a4689d555e8f055b0373 (patch)
tree25975fc4d4e87891e3b6ca1750a4ceacc7a9af6e
parent07c6f933d1b4ba20be43bb5f5d6f977572411750 (diff)
downloadNetworkManager-dabfa26a41edc7911a45a4689d555e8f055b0373.tar.gz
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
-rw-r--r--src/core/nm-l3cfg.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c
index 4a49c4f8d9..3c2d3ec838 100644
--- a/src/core/nm-l3cfg.c
+++ b/src/core/nm-l3cfg.c
@@ -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