From ae28d2251a32e2e819b866ad9bc861e560ea8a3f Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 15 Dec 2021 17:23:23 +0100 Subject: [PATCH] core: set force-commit flag for generated routes The force-commit flag is used to force the commit of an address or a route from DHCP/RA even when it was removed from platform externally (for example because it expired). Routes generated from the l3cd should also have the flag set. Without this, NM properly re-adds the DHCP address after the lease is lost and obtained again, but fails to add the prefix-route. Fixes: 2838b1c5e893 ('core: track force-commit flag for l3cd and platform objects') https://bugzilla.redhat.com/show_bug.cgi?id=2033991 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1049 --- src/core/nm-l3-config-data.c | 15 +++++++++------ src/core/nm-l3-config-data.h | 1 + src/core/nm-l3cfg.c | 1 + src/libnm-platform/nm-platform.c | 18 ++++++++++-------- src/libnm-platform/nm-platform.h | 1 + 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/core/nm-l3-config-data.c b/src/core/nm-l3-config-data.c index 2ea358399e..8d6ac09e92 100644 --- a/src/core/nm-l3-config-data.c +++ b/src/core/nm-l3-config-data.c @@ -2428,6 +2428,7 @@ nm_l3_config_data_add_dependent_device_routes(NML3ConfigData *self, int addr_family, guint32 route_table, guint32 route_metric, + gboolean force_commit, const NML3ConfigData *source) { const int IS_IPv4 = NM_IS_IPv4(addr_family); @@ -2472,6 +2473,7 @@ nm_l3_config_data_add_dependent_device_routes(NML3ConfigData *self, self->ifindex, route_table, route_metric, + force_commit, &r_stack.r4); if (r) nm_l3_config_data_add_route(self, addr_family, NULL, r); @@ -2510,12 +2512,13 @@ nm_l3_config_data_add_dependent_device_routes(NML3ConfigData *self, } rx.r6 = (NMPlatformIP6Route){ - .ifindex = self->ifindex, - .rt_source = NM_IP_CONFIG_SOURCE_KERNEL, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, - .network = *a6, - .plen = plen, + .ifindex = self->ifindex, + .rt_source = NM_IP_CONFIG_SOURCE_KERNEL, + .table_coerced = nm_platform_route_table_coerce(route_table), + .metric = route_metric, + .network = *a6, + .plen = plen, + .r_force_commit = force_commit, }; nm_platform_ip_route_normalize(addr_family, &rx.rx); diff --git a/src/core/nm-l3-config-data.h b/src/core/nm-l3-config-data.h index 8df46ea758..1c776d4edb 100644 --- a/src/core/nm-l3-config-data.h +++ b/src/core/nm-l3-config-data.h @@ -165,6 +165,7 @@ void nm_l3_config_data_add_dependent_device_routes(NML3ConfigData *self, int addr_family, guint32 route_table, guint32 route_metric, + gboolean force_commit, const NML3ConfigData *source); /*****************************************************************************/ diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c index 8337895714..78f03bb62e 100644 --- a/src/core/nm-l3cfg.c +++ b/src/core/nm-l3cfg.c @@ -3533,6 +3533,7 @@ _l3cfg_update_combined_config(NML3Cfg *self, IS_IPv4 ? AF_INET : AF_INET6, l3cd_data->default_route_table_x[IS_IPv4], l3cd_data->default_route_metric_x[IS_IPv4], + l3cd_data->force_commit_once, l3cd_data->l3cd); } } diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index cfb05b68b8..a4863c0d2d 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -8560,6 +8560,7 @@ nm_platform_ip4_address_generate_device_route(const NMPlatformIP4Address *addr, int ifindex, guint32 route_table, guint32 route_metric, + gboolean force_commit, NMPlatformIP4Route *dst) { in_addr_t network_4; @@ -8591,14 +8592,15 @@ nm_platform_ip4_address_generate_device_route(const NMPlatformIP4Address *addr, } *dst = (NMPlatformIP4Route){ - .ifindex = ifindex, - .rt_source = NM_IP_CONFIG_SOURCE_KERNEL, - .network = network_4, - .plen = addr->plen, - .pref_src = addr->address, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, - .scope_inv = nm_platform_route_scope_inv(NM_RT_SCOPE_LINK), + .ifindex = ifindex, + .rt_source = NM_IP_CONFIG_SOURCE_KERNEL, + .network = network_4, + .plen = addr->plen, + .pref_src = addr->address, + .table_coerced = nm_platform_route_table_coerce(route_table), + .metric = route_metric, + .scope_inv = nm_platform_route_scope_inv(NM_RT_SCOPE_LINK), + .r_force_commit = force_commit, }; nm_platform_ip_route_normalize(AF_INET, (NMPlatformIPRoute *) dst); diff --git a/src/libnm-platform/nm-platform.h b/src/libnm-platform/nm-platform.h index a3acc13cb8..c305a1db28 100644 --- a/src/libnm-platform/nm-platform.h +++ b/src/libnm-platform/nm-platform.h @@ -2421,6 +2421,7 @@ NMPlatformIP4Route *nm_platform_ip4_address_generate_device_route(const NMPlatfo int ifindex, guint32 route_table, guint32 route_metric, + gboolean force_commit, NMPlatformIP4Route *dst); /*****************************************************************************/