From dcdbe984065ed06753a0ce542c1aaaa9336d8424 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Jul 2019 23:25:03 +0200 Subject: [PATCH 1/5] shared: add nm_g_slice_free() helper How odd that such a macro does not exist yet. It seems like the majorities of calls to g_slice_free() could be replaced by this. --- shared/nm-glib-aux/nm-macros-internal.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 9062fe8d98..9502c442ec 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -1569,6 +1569,11 @@ nm_strcmp_p (gconstpointer a, gconstpointer b) /*****************************************************************************/ +#define nm_g_slice_free(ptr) \ + g_slice_free (typeof (*(ptr)), ptr) + +/*****************************************************************************/ + /* like g_memdup(). The difference is that the @size argument is of type * gsize, while g_memdup() has type guint. Since, the size of container types * like GArray is guint as well, this means trying to g_memdup() an From 0aa323fb2887fc4b5decfb5360d7384bf774e6db Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 9 Jul 2019 12:46:53 +0200 Subject: [PATCH 2/5] settings: add NM_SETTINGS_UPDATE2_FLAG_NO_REAPPLY to prevent runtime changes when updating connection profile When modifying a connection profile that happens to be active on a device, then most of the changes don't take effect immediately. Only after a full re-activation or reapply (nmcli device reapply) does the configuration of the active device change (the "applied-connection"). With two execptions: "connection.zone" and "connection.metered" take effect immediately. I think this is historic, but also to facilitate firewall-cmd to modify a profile and change the zone right away. Anyway, I think it should be possible to modify a profile without changes to the runtime. Add a flag to prevent reapplying these properties right away. https://bugzilla.redhat.com/show_bug.cgi?id=1677070 --- libnm-core/nm-dbus-interface.h | 8 ++++++++ src/settings/nm-settings-connection.c | 11 +++++++---- src/settings/nm-settings-connection.h | 5 ++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/libnm-core/nm-dbus-interface.h b/libnm-core/nm-dbus-interface.h index c68c7757b2..42c3319025 100644 --- a/libnm-core/nm-dbus-interface.h +++ b/libnm-core/nm-dbus-interface.h @@ -1039,6 +1039,13 @@ typedef enum { /*< flags >*/ * has autoconnect enabled and is modified, it becomes eligible to autoconnect * right away. Setting this flag, disables autoconnect until the connection * is manually activated. + * @NM_SETTINGS_UPDATE2_FLAG_NO_REAPPLY: when a profile gets modified that is + * currently active, then these changes don't take effect for the active + * device unless the profile gets reactivated or the configuration reapplied. + * There are two exceptions: by default "connection.zone" and "connection.metered" + * properties take effect immediately. Specify this flag to prevent these + * properties to take effect, so that the change is restricted to modify + * the profile. Since: 1.20. * * Since: 1.12 */ @@ -1050,6 +1057,7 @@ typedef enum { /*< flags >*/ NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY_ONLY = 0x8, NM_SETTINGS_UPDATE2_FLAG_VOLATILE = 0x10, NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT = 0x20, + NM_SETTINGS_UPDATE2_FLAG_NO_REAPPLY = 0x40, } NMSettingsUpdate2Flags; /** diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 06b1561b6b..c789ec0826 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -1529,7 +1529,9 @@ update_auth_cb (NMSettingsConnection *self, NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED | NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE, NM_SETTINGS_CONNECTION_UPDATE_REASON_FORCE_RENAME - | NM_SETTINGS_CONNECTION_UPDATE_REASON_REAPPLY_PARTIAL + | ( NM_FLAGS_HAS (info->flags, NM_SETTINGS_UPDATE2_FLAG_NO_REAPPLY) + ? NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE + : NM_SETTINGS_CONNECTION_UPDATE_REASON_REAPPLY_PARTIAL) | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS, "update-from-dbus", @@ -1733,9 +1735,10 @@ impl_settings_connection_update2 (NMDBusObject *obj, g_variant_get (parameters, "(@a{sa{sv}}u@a{sv})", &settings, &flags_u, &args); - if (NM_FLAGS_ANY (flags_u, ~((guint32) (ALL_PERSIST_MODES | - NM_SETTINGS_UPDATE2_FLAG_VOLATILE | - NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT)))) { + if (NM_FLAGS_ANY (flags_u, ~((guint32) ( ALL_PERSIST_MODES + | NM_SETTINGS_UPDATE2_FLAG_VOLATILE + | NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT + | NM_SETTINGS_UPDATE2_FLAG_NO_REAPPLY)))) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_ARGUMENTS, "Unknown flags"); diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index 9dfc473da7..f3d6e35e51 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -50,7 +50,10 @@ typedef enum { /* Usually, changing a profile that is currently active does not immediately * reapply the changes. The exception are connection.zone and connection.metered * properties. When this flag is set, then these two properties are reapplied - * right away. */ + * right away. + * + * See also %NM_SETTINGS_UPDATE2_FLAG_NO_REAPPLY flag, to prevent partial reapply + * during Update2(). */ NM_SETTINGS_CONNECTION_UPDATE_REASON_REAPPLY_PARTIAL = (1u << 2), NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_SYSTEM_SECRETS = (1u << 3), From 22c8721f35ec111335be0acc36bb0cc7b89bf97d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 9 Jul 2019 15:22:01 +0200 Subject: [PATCH 3/5] core,libnm: add AddConnection2() D-Bus API to block autoconnect from the start It should be possible to add a profile with autoconnect blocked form the start. Update2() has a %NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT flag to block autoconnect, and so we need something similar when adding a connection. As the existing AddConnection() and AddConnectionUnsaved() API is not extensible, add AddConnection2() that has flags and room for additional arguments. Then add and implement the new flag %NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT for AddConnection2(). Note that libnm's nm_client_add_connection2() API can completely replace the existing nm_client_add_connection_async() call. In particular, it will automatically prefer to call the D-Bus methods AddConnection() and AddConnectionUnsaved(), in order to work with server versions older than 1.20. The purpose of this is that when upgrading the package, the running NetworkManager might still be older than the installed libnm. Anyway, so since nm_client_add_connection2_finish() also has a result output, the caller needs to decide whether he cares about that result. Hence it has an argument ignore_out_result, which allows to fallback to the old API. One might argue that a caller who doesn't care about the output results while still wanting to be backward compatible, should itself choose to call nm_client_add_connection_async() or nm_client_add_connection2(). But instead, it's more convenient if the new function can fully replace the old one, so that the caller does not need to switch which start/finish method to call. https://bugzilla.redhat.com/show_bug.cgi?id=1677068 --- ...rg.freedesktop.NetworkManager.Settings.xml | 35 +++ libnm-core/nm-dbus-interface.h | 21 ++ libnm/libnm.ver | 3 + libnm/nm-client.c | 178 +++++++++++-- libnm/nm-client.h | 16 ++ libnm/nm-remote-settings.c | 249 +++++++++++------- libnm/nm-remote-settings.h | 23 +- src/devices/bluetooth/nm-bluez-device.c | 1 + src/devices/wifi/nm-iwd-manager.c | 1 + src/nm-checkpoint.c | 1 + src/nm-manager.c | 2 + src/settings/nm-settings-connection.c | 21 +- src/settings/nm-settings-connection.h | 10 + src/settings/nm-settings.c | 133 +++++++++- src/settings/nm-settings.h | 2 + 15 files changed, 551 insertions(+), 145 deletions(-) diff --git a/introspection/org.freedesktop.NetworkManager.Settings.xml b/introspection/org.freedesktop.NetworkManager.Settings.xml index 73da345ceb..f7be2717b8 100644 --- a/introspection/org.freedesktop.NetworkManager.Settings.xml +++ b/introspection/org.freedesktop.NetworkManager.Settings.xml @@ -63,6 +63,41 @@ + + + + + + + + +