From 428fcc29a5922f0209b0a42b3641a00479eadbe3 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 20 Jun 2024 10:25:30 +0200 Subject: [PATCH] Save connection timestamps when shutting down Resolves: RHEL-35539 --- ...r-save-timestamps-when-shutting-down.patch | 71 +++++++++++++++++++ NetworkManager.spec | 6 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 1002-manager-save-timestamps-when-shutting-down.patch diff --git a/1002-manager-save-timestamps-when-shutting-down.patch b/1002-manager-save-timestamps-when-shutting-down.patch new file mode 100644 index 0000000..640b6ab --- /dev/null +++ b/1002-manager-save-timestamps-when-shutting-down.patch @@ -0,0 +1,71 @@ +From e17de03eec59fc28d69c44300bb2fc58a319f1f5 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= +Date: Wed, 22 May 2024 12:37:41 +0200 +Subject: [PATCH] manager: save timestamps when shutting down + +Connection timestamps are updated (saved to disk) on connection up and +down. This way, the last used connection will take precedence for +autoconnect if they have the same priority. + +But as we don't actually do connection down when NM stops, the last +connection timestamp of all active connections is the timestamp of when +they were brought up. Then, the activation order might be wrong on next +start. + +One case where timestamps are wrong (although it is not clear how +important it is because the connections are activated on different +interfaces): +1. Activate con1 <- timestamp updated +2. Activate con2 <- timestamp updated +3. Deactivate con2 <- timestamp updated +4. Stop NM <- timestamp of con2 is higher than con1, but con1 was still + active when con2 was brought down. + +Other case that is reproducible (from +https://issues.redhat.com/browse/RHEL-35539): +1. Activate con1 +2. Activate con2 on same interface: + - As a consequence con1 is deactivated and its timestamp updated + - The timestamp of con2 is also updated +3. Stop NM <- timestamp of con1 and con2 is the same, next activation + order will be undefined. + +Fix by saving the timestamps on NM shutdown. + +Resolves: https://issues.redhat.com/browse/RHEL-35539 +(cherry picked from commit 4bf11b7d66f392f581d5f5fd2618e138faeefea8) +(cherry picked from commit 7c0d9aed576cfd3b3058a871edf1299a7c6a8bd6) +--- + src/core/nm-manager.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c +index 2c2834e9fc..ddbd20218b 100644 +--- a/src/core/nm-manager.c ++++ b/src/core/nm-manager.c +@@ -7960,6 +7960,7 @@ nm_manager_write_device_state_all(NMManager *self) + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + gs_unref_hashtable GHashTable *preserve_ifindexes = NULL; + NMDevice *device; ++ NMActiveConnection *ac; + + preserve_ifindexes = g_hash_table_new(nm_direct_hash, NULL); + +@@ -7971,6 +7972,14 @@ nm_manager_write_device_state_all(NMManager *self) + } + } + ++ /* Save to disk the timestamps of active connections as if we were bringing them down. ++ * Otherwise they will be wrong on next start and affect the activation order. ++ */ ++ c_list_for_each_entry (ac, &priv->active_connections_lst_head, active_connections_lst) { ++ NMSettingsConnection *sett = nm_active_connection_get_settings_connection(ac); ++ nm_settings_connection_update_timestamp(sett, (guint64) time(NULL)); ++ } ++ + nm_config_device_state_prune_stale(preserve_ifindexes, NULL); + } + +-- +2.41.0 + diff --git a/NetworkManager.spec b/NetworkManager.spec index babe1a7..3de8537 100644 --- a/NetworkManager.spec +++ b/NetworkManager.spec @@ -6,7 +6,7 @@ %global epoch_version 1 %global real_version 1.48.0 %global rpm_version %{real_version} -%global release_version 1 +%global release_version 2 %global snapshot %{nil} %global git_sha %{nil} %global bcond_default_debug 0 @@ -213,6 +213,7 @@ Patch0001: 0001-revert-change-default-value-for-ipv4.dad-timeout-from-0-to-200ms # Bugfixes that are only relevant until next rebase of the package. # Patch1001: 1001-some.patch Patch1001: 1001-checkpoint-fix-port-reactivation-when-controller-is-.patch +Patch1002: 1002-manager-save-timestamps-when-shutting-down.patch Requires(post): systemd %if 0%{?fedora} || 0%{?rhel} >= 8 @@ -1268,6 +1269,9 @@ fi %changelog +* Thu Jun 20 2024 Beniamino Galvani - 1:1.48.0-2 +- Save connection timestamps when shutting down (RHEL-35539) + * Thu May 30 2024 Lubomir Rintel - 1:1.48.0-1 - Upgrade to 1.48.0 release