You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
NetworkManager/SOURCES/1007-settings-preserve-exis...

90 lines
3.7 KiB

From 895ed1ef14c49a94fb665e519bad409adf53c80f Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Mon, 27 Feb 2023 09:10:34 +0100
Subject: [PATCH] settings: preserve existing connection flags on update
We are passing to the plugin only 'sett_flags', which is the bitmask
of flags to change and works together with 'sett_mask'; however,
plugins interpret that value as the new flags value. The result is
that if there is no change needed (0/0), the existing flags are lost.
Simple reproducer:
ip link add dummy1 type dummy
ip link set dummy1 up
ip addr add dev dummy1 fd01::12/64
sleep 1
# now, a external connection is created by NM
echo "BEFORE:"
cat /run/NetworkManager/system-connections/dummy1.nmconnection | grep "nm-generated\|volatile\|external"
# just add a new address to the interface to make it lose
# the external flag
ip addr add dev dummy1 172.25.42.1/24
sleep 1
echo "AFTER:"
cat /run/NetworkManager/system-connections/dummy1.nmconnection | grep "nm-generated\|volatile\|external"
Output:
BEFORE:
nm-generated=true
volatile=true
external=true
AFTER:
Fixes: d35d3c468a30 ('settings: rework tracking settings connections and settings plugins')
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1548
(cherry picked from commit 86b922695f18566132980bd23516038b6ca4c0f4)
(cherry picked from commit 4353f842303d0d905c92e8e497e22f8440261381)
---
src/core/settings/nm-settings.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/core/settings/nm-settings.c b/src/core/settings/nm-settings.c
index 63476c3c94..9995b490d2 100644
--- a/src/core/settings/nm-settings.c
+++ b/src/core/settings/nm-settings.c
@@ -2009,6 +2009,7 @@ nm_settings_update_connection(NMSettings *self,
const char *uuid;
gboolean tombstone_in_memory = FALSE;
gboolean tombstone_on_disk = FALSE;
+ NMSettingsConnectionIntFlags new_flags;
g_return_val_if_fail(NM_IS_SETTINGS(self), FALSE);
g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(sett_conn), FALSE);
@@ -2228,13 +2229,16 @@ nm_settings_update_connection(NMSettings *self,
}
}
+ new_flags = nm_settings_connection_get_flags(sett_conn);
+ new_flags = NM_FLAGS_ASSIGN_MASK(new_flags, sett_mask, sett_flags);
+
if (!update_storage) {
success = _add_connection_to_first_plugin(self,
plugin_name,
sett_conn_entry,
connection,
new_in_memory,
- sett_flags,
+ new_flags,
new_shadowed_storage_filename,
new_shadowed_owned,
&new_storage,
@@ -2245,7 +2249,7 @@ nm_settings_update_connection(NMSettings *self,
success = _update_connection_to_plugin(self,
update_storage,
connection,
- sett_flags,
+ new_flags,
update_reason,
new_shadowed_storage_filename,
new_shadowed_owned,
--
2.41.0