Commit d35d3c46 authored by Thomas Haller's avatar Thomas Haller

settings: rework tracking settings connections and settings plugins

Completely rework how settings plugin handle connections and how
NMSettings tracks the list of connections.

Previously, settings plugins would return objects of (a subtype of) type
NMSettingsConnection. The NMSettingsConnection was tightly coupled with
the settings plugin. That has a lot of downsides.

Change that. When changing this basic relation how settings connections
are tracked, everything falls appart. That's why this is a huge change.
Also, since I have to largely rewrite the settings plugins, I also
added support for multiple keyfile directories, handle in-memory
connections only by keyfile plugin and (partly) use copy-on-write NMConnection
instances. I don't want to spend effort rewriting large parts while
preserving the old way, that anyway should change. E.g. while rewriting ifcfg-rh,
I don't want to let it handle in-memory connections because that's not right
long-term.

--

If the settings plugins themself create subtypes of NMSettingsConnection
instances, then a lot of knowledge about tracking connections moves
to the plugins.
Just try to follow the code what happend during nm_settings_add_connection().
Note how the logic is spread out:
 - nm_settings_add_connection() calls plugin's add_connection()
 - add_connection() creates a NMSettingsConnection subtype
 - the plugin has to know that it's called during add-connection and
   not emit NM_SETTINGS_PLUGIN_CONNECTION_ADDED signal
 - NMSettings calls claim_connection() which hocks up the new
   NMSettingsConnection instance and configures the instance
   (like calling nm_settings_connection_added()).
This summary does not sound like a lot, but try to follow that code. The logic
is all over the place.

Instead, settings plugins should have a very simple API for adding, modifying,
deleting, loading and reloading connections. All the plugin does is to return a
NMSettingsStorage handle. The storage instance is a handle to identify a profile
in storage (e.g. a particular file). The settings plugin is free to subtype
NMSettingsStorage, but it's not necessary.
There are no more events raised, and the settings plugin implements the small
API in a straightforward manner.
NMSettings now drives all of this. Even NMSettingsConnection has now
very little concern about how it's tracked and delegates only to NMSettings.

This should make settings plugins simpler. Currently settings plugins
are so cumbersome to implement, that we avoid having them. It should not be
like that and it should be easy, beneficial and lightweight to create a new
settings plugin.

Note also how the settings plugins no longer care about duplicate UUIDs.
Duplicated UUIDs are a fact of life and NMSettings must handle them. No
need to overly concern settings plugins with that.

--

NMSettingsConnection is exposed directly on D-Bus (being a subtype of
NMDBusObject) but it was also a GObject type provided by the settings
plugin. Hence, it was not possible to migrate a profile from one plugin to
another.
However that would be useful when one profile does not support a
connection type (like ifcfg-rh not supporting VPN). Currently such
migration is not implemented except for migrating them to/from keyfile's
run directory. The problem is that migrating profiles in general is
complicated but in some cases it is important to do.

For example checkpoint rollback should recreate the profile in the right
settings plugin, not just add it to persistent storage. This is not yet
properly implemented.

--

Previously, both keyfile and ifcfg-rh plugin implemented in-memory (unsaved)
profiles, while ifupdown plugin cannot handle them. That meant duplication of code
and a ifupdown profile could not be modified or made unsaved.
This is now unified and only keyfile plugin handles in-memory profiles (bgo #744711).
Also, NMSettings is aware of such profiles and treats them specially.
In particular, NMSettings drives the migration between persistent and non-persistent
storage.

Note that a settings plugins may create truly generated, in-memory profiles.
The settings plugin is free to generate and persist the profiles in any way it
wishes. But the concept of "unsaved" profiles is now something explicitly handled
by keyfile plugin. Also, these "unsaved" keyfile profiles are persisted to file system
too, to the /run directory. This is great for two reasons: first of all, all
profiles from keyfile storage in fact have a backing file -- even the
unsaved ones. It also means you can create "unsaved" profiles in /run
and load them with `nmcli connection load`, meaning there is a file
based API for creating unsaved profiles.
The other advantage is that these profiles now survive restarting
NetworkManager. It's paramount that restarting the daemon is as
non-disruptive as possible. Persisting unsaved files to /run improves
here significantly.

--

In the past, NMSettingsConnection also implemented NMConnection interface.
That was already changed a while ago and instead users call now
nm_settings_connection_get_connection() to delegate to a
NMSimpleConnection. What however still happened was that the NMConnection
instance gets never swapped but instead the instance was modified with
nm_connection_replace_settings_from_connection(), clear-secrets, etc.
Change that and treat the NMConnection instance immutable. Instead of modifying
it, reference/clone a new instance. This changes that previously when somebody
wanted to keep a reference to an NMConnection, then the profile would be cloned.
Now, it is supposed to be safe to reference the instance directly and everybody
must ensure not to modify the instance. nmtst_connection_assert_unchanging()
should help with that.
The point is that the settings plugins may keep references to the
NMConnection instance, and so does the NMSettingsConnection. We want
to avoid cloning the instances as long as they are the same.
Likewise, the device's applied connection can now also be referenced
instead of cloning it. This is not yet done, and possibly there are
further improvements possible.

--

Also implement multiple keyfile directores /usr/lib, /etc, /run (rh #1674545,
bgo #772414).

It was always the case that multiple files could provide the same UUID
(both in case of keyfile and ifcfg-rh). For keyfile plugin, if a profile in
read-only storage in /usr/lib gets modified, then it gets actually stored in
/etc (or /run, if the profile is unsaved).

--

While at it, make /etc/network/interfaces profiles for ifupdown plugin reloadable.

--

https://bugzilla.gnome.org/show_bug.cgi?id=772414
https://bugzilla.gnome.org/show_bug.cgi?id=744711
https://bugzilla.redhat.com/show_bug.cgi?id=1674545
parent 0631129c
...@@ -2094,13 +2094,17 @@ src_libNetworkManager_la_SOURCES = \ ...@@ -2094,13 +2094,17 @@ src_libNetworkManager_la_SOURCES = \
src/settings/nm-secret-agent.h \ src/settings/nm-secret-agent.h \
src/settings/nm-settings-connection.c \ src/settings/nm-settings-connection.c \
src/settings/nm-settings-connection.h \ src/settings/nm-settings-connection.h \
src/settings/nm-settings-storage.c \
src/settings/nm-settings-storage.h \
src/settings/nm-settings-plugin.c \ src/settings/nm-settings-plugin.c \
src/settings/nm-settings-plugin.h \ src/settings/nm-settings-plugin.h \
src/settings/nm-settings.c \ src/settings/nm-settings.c \
src/settings/nm-settings.h \ src/settings/nm-settings.h \
src/settings/nm-settings-utils.c \
src/settings/nm-settings-utils.h \
\ \
src/settings/plugins/keyfile/nms-keyfile-connection.c \ src/settings/plugins/keyfile/nms-keyfile-storage.c \
src/settings/plugins/keyfile/nms-keyfile-connection.h \ src/settings/plugins/keyfile/nms-keyfile-storage.h \
src/settings/plugins/keyfile/nms-keyfile-plugin.c \ src/settings/plugins/keyfile/nms-keyfile-plugin.c \
src/settings/plugins/keyfile/nms-keyfile-plugin.h \ src/settings/plugins/keyfile/nms-keyfile-plugin.h \
src/settings/plugins/keyfile/nms-keyfile-reader.c \ src/settings/plugins/keyfile/nms-keyfile-reader.c \
...@@ -2819,10 +2823,11 @@ $(src_settings_plugins_ifcfg_rh_libnms_ifcfg_rh_core_la_OBJECTS): $(libnm_core_l ...@@ -2819,10 +2823,11 @@ $(src_settings_plugins_ifcfg_rh_libnms_ifcfg_rh_core_la_OBJECTS): $(libnm_core_l
############################################################################### ###############################################################################
src_settings_plugins_ifcfg_rh_libnm_settings_plugin_ifcfg_rh_la_SOURCES = \ src_settings_plugins_ifcfg_rh_libnm_settings_plugin_ifcfg_rh_la_SOURCES = \
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c \ src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c \
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.h \ src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.h \
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c \ src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c \
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.h src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.h \
$(NULL)
src_settings_plugins_ifcfg_rh_libnm_settings_plugin_ifcfg_rh_la_CPPFLAGS = $(src_cppflags_base) src_settings_plugins_ifcfg_rh_libnm_settings_plugin_ifcfg_rh_la_CPPFLAGS = $(src_cppflags_base)
...@@ -3135,8 +3140,6 @@ src_settings_plugins_ifupdown_libnms_ifupdown_core_la_LIBADD = \ ...@@ -3135,8 +3140,6 @@ src_settings_plugins_ifupdown_libnms_ifupdown_core_la_LIBADD = \
$(NULL) $(NULL)
src_settings_plugins_ifupdown_libnm_settings_plugin_ifupdown_la_SOURCES = \ src_settings_plugins_ifupdown_libnm_settings_plugin_ifupdown_la_SOURCES = \
src/settings/plugins/ifupdown/nms-ifupdown-connection.c \
src/settings/plugins/ifupdown/nms-ifupdown-connection.h \
src/settings/plugins/ifupdown/nms-ifupdown-plugin.c \ src/settings/plugins/ifupdown/nms-ifupdown-plugin.c \
src/settings/plugins/ifupdown/nms-ifupdown-plugin.h \ src/settings/plugins/ifupdown/nms-ifupdown-plugin.h \
$(NULL) $(NULL)
...@@ -4834,6 +4837,7 @@ install-data-hook: $(install_data_hook) ...@@ -4834,6 +4837,7 @@ install-data-hook: $(install_data_hook)
$(mkinstalldirs) -m 0755 $(DESTDIR)$(nmconfdir)/dnsmasq-shared.d $(mkinstalldirs) -m 0755 $(DESTDIR)$(nmconfdir)/dnsmasq-shared.d
$(mkinstalldirs) -m 0755 $(DESTDIR)$(nmlibdir)/conf.d $(mkinstalldirs) -m 0755 $(DESTDIR)$(nmlibdir)/conf.d
$(mkinstalldirs) -m 0755 $(DESTDIR)$(nmlibdir)/VPN $(mkinstalldirs) -m 0755 $(DESTDIR)$(nmlibdir)/VPN
$(mkinstalldirs) -m 0755 $(DESTDIR)$(nmlibdir)/system-connections
$(mkinstalldirs) -m 0700 $(DESTDIR)$(nmstatedir) $(mkinstalldirs) -m 0700 $(DESTDIR)$(nmstatedir)
$(mkinstalldirs) -m 0755 $(DESTDIR)$(plugindir) $(mkinstalldirs) -m 0755 $(DESTDIR)$(plugindir)
......
...@@ -847,6 +847,7 @@ fi ...@@ -847,6 +847,7 @@ fi
%dir %{nmlibdir} %dir %{nmlibdir}
%dir %{nmlibdir}/conf.d %dir %{nmlibdir}/conf.d
%dir %{nmlibdir}/VPN %dir %{nmlibdir}/VPN
%dir %{nmlibdir}/system-connections
%{_mandir}/man1/* %{_mandir}/man1/*
%{_mandir}/man5/* %{_mandir}/man5/*
%{_mandir}/man7/nmcli-examples.7* %{_mandir}/man7/nmcli-examples.7*
......
...@@ -56,9 +56,7 @@ ...@@ -56,9 +56,7 @@
does not start the network connection unless (1) device is idle and able does not start the network connection unless (1) device is idle and able
to connect to the network described by the new connection, and (2) the to connect to the network described by the new connection, and (2) the
connection is allowed to be started automatically. Use the 'Save' method connection is allowed to be started automatically. Use the 'Save' method
on the connection to save these changes to disk. Note that unsaved changes on the connection to save these changes to disk.
will be lost if the connection is reloaded from disk (either automatically
on file change or due to an explicit ReloadConnections call).
--> -->
<method name="AddConnectionUnsaved"> <method name="AddConnectionUnsaved">
<arg name="connection" type="a{sa{sv}}" direction="in"/> <arg name="connection" type="a{sa{sv}}" direction="in"/>
......
...@@ -1014,6 +1014,9 @@ typedef enum { /*< flags >*/ ...@@ -1014,6 +1014,9 @@ typedef enum { /*< flags >*/
* is not deleted but merely the connection is decoupled from the file * is not deleted but merely the connection is decoupled from the file
* on disk. If you later delete an in-memory connection, the connection * on disk. If you later delete an in-memory connection, the connection
* on disk will be deleted as well. * on disk will be deleted as well.
* Note: with 1.20, this flag is no longer implemented because in-memory connections
* are also persisted under /run. For the moment, this behaves the same as
* @NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY_DETACHED.
* @NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY_DETACHED: this is like @NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY, * @NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY_DETACHED: this is like @NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY,
* but if the connection has a corresponding file on disk, the association between * but if the connection has a corresponding file on disk, the association between
* the connection and the file is forgotten but the file is not modified. * the connection and the file is forgotten but the file is not modified.
......
...@@ -171,8 +171,13 @@ gboolean _nm_keyfile_has_values (GKeyFile *keyfile); ...@@ -171,8 +171,13 @@ gboolean _nm_keyfile_has_values (GKeyFile *keyfile);
/*****************************************************************************/ /*****************************************************************************/
#define NM_KEYFILE_GROUP_NMMETA ".nmmeta"
#define NM_KEYFILE_KEY_NMMETA_NM_GENERATED "nm-generated"
#define NM_KEYFILE_KEY_NMMETA_VOLATILE "volatile"
#define NM_KEYFILE_PATH_NAME_LIB NMLIBDIR "/system-connections"
#define NM_KEYFILE_PATH_NAME_ETC_DEFAULT NMCONFDIR "/system-connections" #define NM_KEYFILE_PATH_NAME_ETC_DEFAULT NMCONFDIR "/system-connections"
#define NM_KEYFILE_PATH_NAME_RUN NMRUNDIR "/system-connections" #define NM_KEYFILE_PATH_NAME_RUN NMRUNDIR "/system-connections"
#define NM_KEYFILE_PATH_SUFFIX_NMCONNECTION ".nmconnection" #define NM_KEYFILE_PATH_SUFFIX_NMCONNECTION ".nmconnection"
......
...@@ -3537,7 +3537,9 @@ nm_keyfile_read (GKeyFile *keyfile, ...@@ -3537,7 +3537,9 @@ nm_keyfile_read (GKeyFile *keyfile,
vpn_secrets = TRUE; vpn_secrets = TRUE;
} else if (NM_STR_HAS_PREFIX (groups[i], NM_KEYFILE_GROUPPREFIX_WIREGUARD_PEER)) } else if (NM_STR_HAS_PREFIX (groups[i], NM_KEYFILE_GROUPPREFIX_WIREGUARD_PEER))
_read_setting_wireguard_peer (&info); _read_setting_wireguard_peer (&info);
else else if (nm_streq (groups[i], NM_KEYFILE_GROUP_NMMETA)) {
/* pass */
} else
_read_setting (&info); _read_setting (&info);
info.group = NULL; info.group = NULL;
......
...@@ -235,15 +235,17 @@ pan_connection_check_create (NMBluezDevice *self) ...@@ -235,15 +235,17 @@ pan_connection_check_create (NMBluezDevice *self)
* which then already finds the suitable connection in priv->connections. This is confusing, * which then already finds the suitable connection in priv->connections. This is confusing,
* so block the signal. check_emit_usable will succeed after this function call returns. */ * so block the signal. check_emit_usable will succeed after this function call returns. */
g_signal_handlers_block_by_func (priv->settings, cp_connection_added, self); g_signal_handlers_block_by_func (priv->settings, cp_connection_added, self);
added = nm_settings_add_connection (priv->settings, connection, FALSE, &error); nm_settings_add_connection (priv->settings,
connection,
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY,
NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED,
&added,
&error);
g_signal_handlers_unblock_by_func (priv->settings, cp_connection_added, self); g_signal_handlers_unblock_by_func (priv->settings, cp_connection_added, self);
if (added) { if (added) {
nm_assert (!g_slist_find (priv->connections, added)); nm_assert (!g_slist_find (priv->connections, added));
nm_assert (connection_compatible (self, added)); nm_assert (connection_compatible (self, added));
nm_settings_connection_set_flags (added, NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED, TRUE);
priv->connections = g_slist_prepend (priv->connections, g_object_ref (added)); priv->connections = g_slist_prepend (priv->connections, g_object_ref (added));
priv->pan_connection = added; priv->pan_connection = added;
nm_log_dbg (LOGD_BT, "bluez[%s] added new Bluetooth connection for NAP device: '%s' (%s)", priv->path, id, uuid); nm_log_dbg (LOGD_BT, "bluez[%s] added new Bluetooth connection for NAP device: '%s' (%s)", priv->path, id, uuid);
...@@ -392,7 +394,7 @@ cp_connection_removed (NMSettings *settings, ...@@ -392,7 +394,7 @@ cp_connection_removed (NMSettings *settings,
static void static void
cp_connection_updated (NMSettings *settings, cp_connection_updated (NMSettings *settings,
NMSettingsConnection *sett_conn, NMSettingsConnection *sett_conn,
gboolean by_user, guint update_reason_u,
NMBluezDevice *self) NMBluezDevice *self)
{ {
if (_internal_track_connection (self, sett_conn, if (_internal_track_connection (self, sett_conn,
...@@ -1225,7 +1227,7 @@ dispose (GObject *object) ...@@ -1225,7 +1227,7 @@ dispose (GObject *object)
if (to_delete) { if (to_delete) {
nm_log_dbg (LOGD_BT, "bluez[%s] removing Bluetooth connection for NAP device: '%s' (%s)", priv->path, nm_log_dbg (LOGD_BT, "bluez[%s] removing Bluetooth connection for NAP device: '%s' (%s)", priv->path,
nm_settings_connection_get_id (to_delete), nm_settings_connection_get_uuid (to_delete)); nm_settings_connection_get_id (to_delete), nm_settings_connection_get_uuid (to_delete));
nm_settings_connection_delete (to_delete, NULL); nm_settings_connection_delete (to_delete, FALSE);
g_object_unref (to_delete); g_object_unref (to_delete);
} }
......
...@@ -12404,16 +12404,28 @@ nm_device_set_ip_config (NMDevice *self, ...@@ -12404,16 +12404,28 @@ nm_device_set_ip_config (NMDevice *self,
if ( nm_device_sys_iface_state_is_external (self) if ( nm_device_sys_iface_state_is_external (self)
&& (settings_connection = nm_device_get_settings_connection (self)) && (settings_connection = nm_device_get_settings_connection (self))
&& NM_FLAGS_HAS (nm_settings_connection_get_flags (settings_connection), && NM_FLAGS_ALL (nm_settings_connection_get_flags (settings_connection),
NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED) NM_SETTINGS_CONNECTION_INT_FLAGS_UNSAVED
| NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE
| NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED)
&& nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request.obj)) == NM_ACTIVATION_TYPE_EXTERNAL) { && nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request.obj)) == NM_ACTIVATION_TYPE_EXTERNAL) {
g_object_freeze_notify (G_OBJECT (settings_connection)); gs_unref_object NMConnection *new_connection = NULL;
/* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
nm_connection_add_setting (nm_settings_connection_get_connection (settings_connection), new_connection = nm_simple_connection_new_clone (nm_settings_connection_get_connection (settings_connection));
nm_connection_add_setting (new_connection,
IS_IPv4 IS_IPv4
? nm_ip4_config_create_setting (priv->ip_config_4) ? nm_ip4_config_create_setting (priv->ip_config_4)
: nm_ip6_config_create_setting (priv->ip_config_6)); : nm_ip6_config_create_setting (priv->ip_config_6));
g_object_thaw_notify (G_OBJECT (settings_connection));
nm_settings_connection_update (settings_connection,
new_connection,
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_DETACHED,
NM_SETTINGS_CONNECTION_INT_FLAGS_NONE,
NM_SETTINGS_CONNECTION_INT_FLAGS_NONE,
NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE,
"update-external",
NULL);
} }
nm_device_queue_recheck_assume (self); nm_device_queue_recheck_assume (self);
...@@ -14365,7 +14377,7 @@ cp_connection_added (NMSettings *settings, NMSettingsConnection *sett_conn, gpoi ...@@ -14365,7 +14377,7 @@ cp_connection_added (NMSettings *settings, NMSettingsConnection *sett_conn, gpoi
} }
static void static void
cp_connection_updated (NMSettings *settings, NMSettingsConnection *sett_conn, gboolean by_user, gpointer user_data) cp_connection_updated (NMSettings *settings, NMSettingsConnection *sett_conn, guint update_reason_u, gpointer user_data)
{ {
cp_connection_added_or_updated (user_data, sett_conn); cp_connection_added_or_updated (user_data, sett_conn);
} }
......
...@@ -1760,9 +1760,10 @@ supplicant_iface_wps_credentials_cb (NMSupplicantInterface *iface, ...@@ -1760,9 +1760,10 @@ supplicant_iface_wps_credentials_cb (NMSupplicantInterface *iface,
} }
if (secrets) { if (secrets) {
if (nm_settings_connection_new_secrets (nm_act_request_get_settings_connection (req), if (nm_settings_connection_new_secrets (nm_act_request_get_settings_connection (req),
nm_act_request_get_applied_connection (req), nm_act_request_get_applied_connection (req),
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
secrets, &error)) { secrets,
&error)) {
wifi_secrets_cancel (self); wifi_secrets_cancel (self);
nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self)); nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self));
} else { } else {
......
...@@ -469,19 +469,18 @@ mirror_8021x_connection (NMIwdManager *self, ...@@ -469,19 +469,18 @@ mirror_8021x_connection (NMIwdManager *self,
if (!nm_connection_normalize (connection, NULL, NULL, NULL)) if (!nm_connection_normalize (connection, NULL, NULL, NULL))
return NULL; return NULL;
settings_connection = nm_settings_add_connection (priv->settings, connection, if (!nm_settings_add_connection (priv->settings,
FALSE, &error); connection,
if (!settings_connection) { NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY,
NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED,
&settings_connection,
&error)) {
_LOGW ("failed to add a mirror NMConnection for IWD's Known Network '%s': %s", _LOGW ("failed to add a mirror NMConnection for IWD's Known Network '%s': %s",
name, error->message); name, error->message);
g_error_free (error); g_error_free (error);
return NULL; return NULL;
} }
nm_settings_connection_set_flags (settings_connection,
NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED |
NM_SETTINGS_CONNECTION_INT_FLAGS_UNSAVED,
TRUE);
return settings_connection; return settings_connection;
} }
...@@ -498,7 +497,7 @@ mirror_8021x_connection_take_and_delete (NMSettingsConnection *sett_conn) ...@@ -498,7 +497,7 @@ mirror_8021x_connection_take_and_delete (NMSettingsConnection *sett_conn)
/* If connection has not been saved since we created it /* If connection has not been saved since we created it
* in interface_added it too can be removed now. */ * in interface_added it too can be removed now. */
if (NM_FLAGS_HAS (flags, NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED)) if (NM_FLAGS_HAS (flags, NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED))
nm_settings_connection_delete (sett_conn, NULL); nm_settings_connection_delete (sett_conn, FALSE);
g_object_unref (sett_conn); g_object_unref (sett_conn);
} }
......
...@@ -103,7 +103,7 @@ sources = files( ...@@ -103,7 +103,7 @@ sources = files(
'dnsmasq/nm-dnsmasq-manager.c', 'dnsmasq/nm-dnsmasq-manager.c',
'dnsmasq/nm-dnsmasq-utils.c', 'dnsmasq/nm-dnsmasq-utils.c',
'ppp/nm-ppp-manager-call.c', 'ppp/nm-ppp-manager-call.c',
'settings/plugins/keyfile/nms-keyfile-connection.c', 'settings/plugins/keyfile/nms-keyfile-storage.c',
'settings/plugins/keyfile/nms-keyfile-plugin.c', 'settings/plugins/keyfile/nms-keyfile-plugin.c',
'settings/plugins/keyfile/nms-keyfile-reader.c', 'settings/plugins/keyfile/nms-keyfile-reader.c',
'settings/plugins/keyfile/nms-keyfile-utils.c', 'settings/plugins/keyfile/nms-keyfile-utils.c',
...@@ -113,6 +113,8 @@ sources = files( ...@@ -113,6 +113,8 @@ sources = files(
'settings/nm-settings.c', 'settings/nm-settings.c',
'settings/nm-settings-connection.c', 'settings/nm-settings-connection.c',
'settings/nm-settings-plugin.c', 'settings/nm-settings-plugin.c',
'settings/nm-settings-storage.c',
'settings/nm-settings-utils.c',
'supplicant/nm-supplicant-config.c', 'supplicant/nm-supplicant-config.c',
'supplicant/nm-supplicant-interface.c', 'supplicant/nm-supplicant-interface.c',
'supplicant/nm-supplicant-manager.c', 'supplicant/nm-supplicant-manager.c',
......
...@@ -181,7 +181,7 @@ NM_UTILS_FLAGS2STR_DEFINE_STATIC (_state_flags_to_string, NMActivationStateFlags ...@@ -181,7 +181,7 @@ NM_UTILS_FLAGS2STR_DEFINE_STATIC (_state_flags_to_string, NMActivationStateFlags
static void static void
_settings_connection_updated (NMSettingsConnection *sett_conn, _settings_connection_updated (NMSettingsConnection *sett_conn,
gboolean by_user, guint update_reason_u,
gpointer user_data) gpointer user_data)
{ {
NMActiveConnection *self = user_data; NMActiveConnection *self = user_data;
...@@ -522,8 +522,9 @@ nm_active_connection_clear_secrets (NMActiveConnection *self) ...@@ -522,8 +522,9 @@ nm_active_connection_clear_secrets (NMActiveConnection *self)
if (nm_settings_connection_has_unmodified_applied_connection (priv->settings_connection.obj, if (nm_settings_connection_has_unmodified_applied_connection (priv->settings_connection.obj,
priv->applied_connection, priv->applied_connection,
NM_SETTING_COMPARE_FLAG_NONE)) { NM_SETTING_COMPARE_FLAG_NONE)) {
/* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */ nm_settings_connection_clear_secrets (priv->settings_connection.obj,
nm_connection_clear_secrets (nm_settings_connection_get_connection (priv->settings_connection.obj)); FALSE,
FALSE);
} }
nm_connection_clear_secrets (priv->applied_connection); nm_connection_clear_secrets (priv->applied_connection);
} }
......
...@@ -217,19 +217,35 @@ restore_and_activate_connection (NMCheckpoint *self, ...@@ -217,19 +217,35 @@ restore_and_activate_connection (NMCheckpoint *self,
gs_unref_object NMAuthSubject *subject = NULL; gs_unref_object NMAuthSubject *subject = NULL;
GError *local_error = NULL; GError *local_error = NULL;
gboolean need_update, need_activation; gboolean need_update, need_activation;
NMSettingsConnectionPersistMode persist_mode;
NMSettingsConnectionIntFlags sett_flags;
NMSettingsConnectionIntFlags sett_mask;
connection = find_settings_connection (self, connection = find_settings_connection (self,
dev_checkpoint, dev_checkpoint,
&need_update, &need_update,
&need_activation); &need_activation);
/* FIXME: we need to ensure to re-create/update the profile for the
* same settings plugin. E.g. if it was a keyfile in /run or /etc,
* it must be again. If it was previously handled by a certain settings plugin,
* so it must again.
*
* FIXME: preserve and restore the right settings flags (volatile, nm-generated). */
sett_flags = NM_SETTINGS_CONNECTION_INT_FLAGS_NONE;
sett_mask = NM_SETTINGS_CONNECTION_INT_FLAGS_NONE;
if (connection) { if (connection) {
if (need_update) { if (need_update) {
_LOGD ("rollback: updating connection %s", _LOGD ("rollback: updating connection %s",
nm_settings_connection_get_uuid (connection)); nm_settings_connection_get_uuid (connection));
persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP;
nm_settings_connection_update (connection, nm_settings_connection_update (connection,
dev_checkpoint->settings_connection, dev_checkpoint->settings_connection,
NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK, persist_mode,
NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE, sett_flags,
sett_mask,
NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE,
"checkpoint-rollback", "checkpoint-rollback",
NULL); NULL);
} }
...@@ -238,11 +254,13 @@ restore_and_activate_connection (NMCheckpoint *self, ...@@ -238,11 +254,13 @@ restore_and_activate_connection (NMCheckpoint *self,
_LOGD ("rollback: adding connection %s again", _LOGD ("rollback: adding connection %s again",
nm_connection_get_uuid (dev_checkpoint->settings_connection)); nm_connection_get_uuid (dev_checkpoint->settings_connection));
connection = nm_settings_add_connection (NM_SETTINGS_GET, persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK;
dev_checkpoint->settings_connection, if (!nm_settings_add_connection (NM_SETTINGS_GET,
TRUE, dev_checkpoint->settings_connection,
&local_error); persist_mode,
if (!connection) { sett_flags,
&connection,
&local_error)) {
_LOGD ("rollback: connection add failure: %s", local_error->message); _LOGD ("rollback: connection add failure: %s", local_error->message);
g_clear_error (&local_error); g_clear_error (&local_error);
return FALSE; return FALSE;
...@@ -428,7 +446,7 @@ next_dev: ...@@ -428,7 +446,7 @@ next_dev:
nm_settings_connection_get_uuid (con))) { nm_settings_connection_get_uuid (con))) {
_LOGD ("rollback: deleting new connection %s", _LOGD ("rollback: deleting new connection %s",
nm_settings_connection_get_uuid (con)); nm_settings_connection_get_uuid (con));
nm_settings_connection_delete (con, NULL); nm_settings_connection_delete (con, FALSE);
} }
} }
} }
......
This diff is collapsed.
...@@ -1846,8 +1846,7 @@ device_state_changed (NMDevice *device, ...@@ -1846,8 +1846,7 @@ device_state_changed (NMDevice *device,
} }
} }
/* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */ nm_settings_connection_clear_secrets (sett_conn, FALSE, FALSE);
nm_connection_clear_secrets (nm_settings_connection_get_connection (sett_conn));
} }
break; break;
case NM_DEVICE_STATE_ACTIVATED: case NM_DEVICE_STATE_ACTIVATED:
...@@ -1858,9 +1857,7 @@ device_state_changed (NMDevice *device, ...@@ -1858,9 +1857,7 @@ device_state_changed (NMDevice *device,
/* And clear secrets so they will always be requested from the /* And clear secrets so they will always be requested from the
* settings service when the next connection is made. * settings service when the next connection is made.
*/ */
nm_settings_connection_clear_secrets (sett_conn, FALSE, FALSE);
/* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
nm_connection_clear_secrets (nm_settings_connection_get_connection (sett_conn));
} }
/* Add device's new IPv4 and IPv6 configs to DNS */ /* Add device's new IPv4 and IPv6 configs to DNS */
...@@ -2399,13 +2396,14 @@ dns_config_changed (NMDnsManager *dns_manager, gpointer user_data) ...@@ -2399,13 +2396,14 @@ dns_config_changed (NMDnsManager *dns_manager, gpointer user_data)
static void static void
connection_updated (NMSettings *settings, connection_updated (NMSettings *settings,
NMSettingsConnection *connection, NMSettingsConnection *connection,
gboolean by_user, guint update_reason_u,
gpointer user_data) gpointer user_data)
{ {
NMPolicyPrivate *priv = user_data; NMPolicyPrivate *priv = user_data;
NMPolicy *self = _PRIV_TO_SELF (priv); NMPolicy *self = _PRIV_TO_SELF (priv);
NMSettingsConnectionUpdateReason update_reason = update_reason_u;
if (by_user) { if (NM_FLAGS_HAS (update_reason, NM_SETTINGS_CONNECTION_UPDATE_REASON_REAPPLY_PARTIAL)) {
const CList *tmp_lst; const CList *tmp_lst;
NMDevice *device; NMDevice *device;
...@@ -2414,9 +2412,6 @@ connection_updated (NMSettings *settings, ...@@ -2414,9 +2412,6 @@ connection_updated (NMSettings *settings,
if (nm_device_get_settings_connection (device) == connection) if (nm_device_get_settings_connection (device) == connection)
nm_device_reapply_settings_immediately (device); nm_device_reapply_settings_immediately (device);
} }
/* Reset auto retries back to default since connection was updated */
nm_settings_connection_autoconnect_retries_reset (connection);
} }
schedule_activate_all (self); schedule_activate_all (self);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2018 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-settings-storage.h"
#include "nm-utils.h"
#include "nm-settings-plugin.h"
#include "settings/plugins/keyfile/nms-keyfile-storage.h"
/*****************************************************************************/
int
nm_settings_storage_cmp (NMSettingsStorage *a,
NMSettingsStorage *b,
const GSList *plugin_list)
{
NMSettingsStorageClass *klass;
NMSettingsPlugin *plugin_a;
NMSettingsPlugin *plugin_b;
/* Sort by priority.
*
* If a > b (by priority), we return a positive number (as one
* would expect by a cmp() function). */
nm_assert (NM_IS_SETTINGS_STORAGE (a));
nm_assert (NM_IS_SETTINGS_STORAGE (b));
nm_assert (a != b);
nm_assert (nm_streq (nm_settings_storage_get_uuid (a), nm_settings_storage_get_uuid (b)));
/* in-memory has always higher priority */
NM_CMP_DIRECT (nm_settings_storage_is_keyfile_run (a),
nm_settings_storage_is_keyfile_run (b));
plugin_a = nm_settings_storage_get_plugin (a);
plugin_b = nm_settings_storage_get_plugin (b);
if (plugin_a != plugin_b) {
int idx_a = g_slist_index ((GSList *) plugin_list, plugin_a);
int idx_b = g_slist_index ((GSList *) plugin_list, plugin_b);
/* the plugins must be found in the list. */
nm_assert (idx_a >= 0);
nm_assert (idx_b >= 0);
nm_assert (idx_a != idx_b);
/* plugins that appear first in @plugin_list have higher priority.
* That means: smaller index -> higher priority. Reverse sort. */
NM_CMP_DIRECT (idx_b, idx_a);
/* undecided. We really don't expect unknown plugins here. */
return 0;
}
klass = NM_SETTINGS_STORAGE_GET_CLASS (a);
if (klass != NM_SETTINGS_STORAGE_GET_CLASS (b)) {
/* one plugin must return storages of the same type. Otherwise, it's
* unclear how cmp_fcn() should compare them. */
nm_assert_not_reached ();
return 0;
}
if (klass->cmp_fcn)
NM_CMP_RETURN (klass->cmp_fcn (a, b));
return 0;
}
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_PLUGIN,
PROP_UUID,
PROP_FILENAME,
);
G_DEFINE_TYPE (NMSettingsStorage, nm_settings_storage, G_TYPE_OBJECT)
/*****************************************************************************/
static void