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 = \
src/settings/nm-secret-agent.h \
src/settings/nm-settings-connection.c \
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.h \
src/settings/nm-settings.c \
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-connection.h \
src/settings/plugins/keyfile/nms-keyfile-storage.c \
src/settings/plugins/keyfile/nms-keyfile-storage.h \
src/settings/plugins/keyfile/nms-keyfile-plugin.c \
src/settings/plugins/keyfile/nms-keyfile-plugin.h \
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
###############################################################################
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-connection.h \
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c \
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.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)
......@@ -3135,8 +3140,6 @@ src_settings_plugins_ifupdown_libnms_ifupdown_core_la_LIBADD = \
$(NULL)
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.h \
$(NULL)
......@@ -4834,6 +4837,7 @@ install-data-hook: $(install_data_hook)
$(mkinstalldirs) -m 0755 $(DESTDIR)$(nmconfdir)/dnsmasq-shared.d
$(mkinstalldirs) -m 0755 $(DESTDIR)$(nmlibdir)/conf.d
$(mkinstalldirs) -m 0755 $(DESTDIR)$(nmlibdir)/VPN
$(mkinstalldirs) -m 0755 $(DESTDIR)$(nmlibdir)/system-connections
$(mkinstalldirs) -m 0700 $(DESTDIR)$(nmstatedir)
$(mkinstalldirs) -m 0755 $(DESTDIR)$(plugindir)
......
......@@ -847,6 +847,7 @@ fi
%dir %{nmlibdir}
%dir %{nmlibdir}/conf.d
%dir %{nmlibdir}/VPN
%dir %{nmlibdir}/system-connections
%{_mandir}/man1/*
%{_mandir}/man5/*
%{_mandir}/man7/nmcli-examples.7*
......
......@@ -56,9 +56,7 @@
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
connection is allowed to be started automatically. Use the 'Save' method
on the connection to save these changes to disk. Note that unsaved changes
will be lost if the connection is reloaded from disk (either automatically
on file change or due to an explicit ReloadConnections call).
on the connection to save these changes to disk.
-->
<method name="AddConnectionUnsaved">
<arg name="connection" type="a{sa{sv}}" direction="in"/>
......
......@@ -1014,6 +1014,9 @@ typedef enum { /*< flags >*/
* 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 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,
* 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.
......
......@@ -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_RUN NMRUNDIR "/system-connections"
#define NM_KEYFILE_PATH_NAME_RUN NMRUNDIR "/system-connections"
#define NM_KEYFILE_PATH_SUFFIX_NMCONNECTION ".nmconnection"
......
......@@ -3537,7 +3537,9 @@ nm_keyfile_read (GKeyFile *keyfile,
vpn_secrets = TRUE;
} else if (NM_STR_HAS_PREFIX (groups[i], NM_KEYFILE_GROUPPREFIX_WIREGUARD_PEER))
_read_setting_wireguard_peer (&info);
else
else if (nm_streq (groups[i], NM_KEYFILE_GROUP_NMMETA)) {
/* pass */
} else
_read_setting (&info);
info.group = NULL;
......
......@@ -235,15 +235,17 @@ pan_connection_check_create (NMBluezDevice *self)
* 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. */
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);
if (added) {
nm_assert (!g_slist_find (priv->connections, 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->pan_connection = added;
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,
static void
cp_connection_updated (NMSettings *settings,
NMSettingsConnection *sett_conn,
gboolean by_user,
guint update_reason_u,
NMBluezDevice *self)
{
if (_internal_track_connection (self, sett_conn,
......@@ -1225,7 +1227,7 @@ dispose (GObject *object)
if (to_delete) {
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_delete (to_delete, NULL);
nm_settings_connection_delete (to_delete, FALSE);
g_object_unref (to_delete);
}
......
......@@ -12404,16 +12404,28 @@ nm_device_set_ip_config (NMDevice *self,
if ( nm_device_sys_iface_state_is_external (self)
&& (settings_connection = nm_device_get_settings_connection (self))
&& NM_FLAGS_HAS (nm_settings_connection_get_flags (settings_connection),
NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED)
&& NM_FLAGS_ALL (nm_settings_connection_get_flags (settings_connection),
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) {
g_object_freeze_notify (G_OBJECT (settings_connection));
/* 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),
gs_unref_object NMConnection *new_connection = NULL;
new_connection = nm_simple_connection_new_clone (nm_settings_connection_get_connection (settings_connection));
nm_connection_add_setting (new_connection,
IS_IPv4
? nm_ip4_config_create_setting (priv->ip_config_4)
: 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);
......@@ -14365,7 +14377,7 @@ cp_connection_added (NMSettings *settings, NMSettingsConnection *sett_conn, gpoi
}
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);
}
......
......@@ -1760,9 +1760,10 @@ supplicant_iface_wps_credentials_cb (NMSupplicantInterface *iface,
}
if (secrets) {
if (nm_settings_connection_new_secrets (nm_act_request_get_settings_connection (req),
nm_act_request_get_applied_connection (req),
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
secrets, &error)) {
nm_act_request_get_applied_connection (req),
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
secrets,
&error)) {
wifi_secrets_cancel (self);
nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self));
} else {
......
......@@ -469,19 +469,18 @@ mirror_8021x_connection (NMIwdManager *self,
if (!nm_connection_normalize (connection, NULL, NULL, NULL))
return NULL;
settings_connection = nm_settings_add_connection (priv->settings, connection,
FALSE, &error);
if (!settings_connection) {
if (!nm_settings_add_connection (priv->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",
name, error->message);
g_error_free (error);
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;
}
......@@ -498,7 +497,7 @@ mirror_8021x_connection_take_and_delete (NMSettingsConnection *sett_conn)
/* If connection has not been saved since we created it
* in interface_added it too can be removed now. */
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);
}
......
......@@ -103,7 +103,7 @@ sources = files(
'dnsmasq/nm-dnsmasq-manager.c',
'dnsmasq/nm-dnsmasq-utils.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-reader.c',
'settings/plugins/keyfile/nms-keyfile-utils.c',
......@@ -113,6 +113,8 @@ sources = files(
'settings/nm-settings.c',
'settings/nm-settings-connection.c',
'settings/nm-settings-plugin.c',
'settings/nm-settings-storage.c',
'settings/nm-settings-utils.c',
'supplicant/nm-supplicant-config.c',
'supplicant/nm-supplicant-interface.c',
'supplicant/nm-supplicant-manager.c',
......
......@@ -181,7 +181,7 @@ NM_UTILS_FLAGS2STR_DEFINE_STATIC (_state_flags_to_string, NMActivationStateFlags
static void
_settings_connection_updated (NMSettingsConnection *sett_conn,
gboolean by_user,
guint update_reason_u,
gpointer user_data)
{
NMActiveConnection *self = user_data;
......@@ -522,8 +522,9 @@ nm_active_connection_clear_secrets (NMActiveConnection *self)
if (nm_settings_connection_has_unmodified_applied_connection (priv->settings_connection.obj,
priv->applied_connection,
NM_SETTING_COMPARE_FLAG_NONE)) {
/* 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 (priv->settings_connection.obj));
nm_settings_connection_clear_secrets (priv->settings_connection.obj,
FALSE,
FALSE);
}
nm_connection_clear_secrets (priv->applied_connection);
}
......
......@@ -217,19 +217,35 @@ restore_and_activate_connection (NMCheckpoint *self,
gs_unref_object NMAuthSubject *subject = NULL;
GError *local_error = NULL;
gboolean need_update, need_activation;
NMSettingsConnectionPersistMode persist_mode;
NMSettingsConnectionIntFlags sett_flags;
NMSettingsConnectionIntFlags sett_mask;
connection = find_settings_connection (self,
dev_checkpoint,
&need_update,
&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 (need_update) {
_LOGD ("rollback: updating connection %s",
nm_settings_connection_get_uuid (connection));
persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP;
nm_settings_connection_update (connection,
dev_checkpoint->settings_connection,
NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK,
NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE,
persist_mode,
sett_flags,
sett_mask,
NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE,
"checkpoint-rollback",
NULL);
}
......@@ -238,11 +254,13 @@ restore_and_activate_connection (NMCheckpoint *self,
_LOGD ("rollback: adding connection %s again",
nm_connection_get_uuid (dev_checkpoint->settings_connection));
connection = nm_settings_add_connection (NM_SETTINGS_GET,
dev_checkpoint->settings_connection,
TRUE,
&local_error);
if (!connection) {
persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK;
if (!nm_settings_add_connection (NM_SETTINGS_GET,
dev_checkpoint->settings_connection,
persist_mode,
sett_flags,
&connection,
&local_error)) {
_LOGD ("rollback: connection add failure: %s", local_error->message);
g_clear_error (&local_error);
return FALSE;
......@@ -428,7 +446,7 @@ next_dev:
nm_settings_connection_get_uuid (con))) {
_LOGD ("rollback: deleting new connection %s",
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,
}
}
/* 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));
nm_settings_connection_clear_secrets (sett_conn, FALSE, FALSE);
}
break;
case NM_DEVICE_STATE_ACTIVATED:
......@@ -1858,9 +1857,7 @@ device_state_changed (NMDevice *device,
/* And clear secrets so they will always be requested from the
* settings service when the next connection is made.
*/
/* 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));
nm_settings_connection_clear_secrets (sett_conn, FALSE, FALSE);
}
/* Add device's new IPv4 and IPv6 configs to DNS */
......@@ -2399,13 +2396,14 @@ dns_config_changed (NMDnsManager *dns_manager, gpointer user_data)
static void
connection_updated (NMSettings *settings,
NMSettingsConnection *connection,
gboolean by_user,
guint update_reason_u,
gpointer user_data)
{
NMPolicyPrivate *priv = user_data;
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;
NMDevice *device;
......@@ -2414,9 +2412,6 @@ connection_updated (NMSettings *settings,
if (nm_device_get_settings_connection (device) == connection)
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);
......
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
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingsStorage *self = NM_SETTINGS_STORAGE (object);
switch (prop_id) {
case PROP_PLUGIN:
/* construct-only */
self->_plugin = g_object_ref (g_value_get_object (value));
nm_assert (NM_IS_SETTINGS_PLUGIN (self->_plugin));
break;
case PROP_UUID:
/* construct-only */
self->_uuid = g_value_dup_string (value);
nm_assert (!self->_uuid || nm_utils_is_uuid (self->_uuid));
break;
case PROP_FILENAME:
/* construct-only */
self->_filename = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/*****************************************************************************/
static void
nm_settings_storage_init (NMSettingsStorage *self)
{
c_list_init (&self->_storage_lst);
c_list_init (&self->_storage_by_uuid_lst);
}
NMSettingsStorage *
nm_settings_storage_new (NMSettingsPlugin *plugin,
const char *uuid,
const char *filename)
{
nm_assert (NM_IS_SETTINGS_PLUGIN (plugin));
nm_assert (nm_utils_is_uuid (uuid));
return g_object_new (NM_TYPE_SETTINGS_STORAGE,
NM_SETTINGS_STORAGE_PLUGIN, plugin,
NM_SETTINGS_STORAGE_UUID, uuid,
NM_SETTINGS_STORAGE_FILENAME, filename,
NULL);
}
static void
finalize (GObject *object)
{
NMSettingsStorage *self = NM_SETTINGS_STORAGE (object);
c_list_unlink_stale (&self->_storage_lst);
c_list_unlink_stale (&self->_storage_by_uuid_lst);
g_object_unref (self->_plugin);
g_free (self->_uuid);
g_free (self->_filename);
G_OBJECT_CLASS (nm_settings_storage_parent_class)->finalize (object);
}
static void
nm_settings_storage_class_init (NMSettingsStorageClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = set_property;
object_class->finalize = finalize;
obj_properties[PROP_PLUGIN] =
g_param_spec_object (NM_SETTINGS_STORAGE_PLUGIN, "", "",
NM_TYPE_SETTINGS_PLUGIN,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_UUID] =
g_param_spec_string (NM_SETTINGS_STORAGE_UUID, "", "",
NULL,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_FILENAME] =
g_param_spec_string (NM_SETTINGS_STORAGE_FILENAME, "", "",
NULL,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
}
/*
* 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.
*/
#ifndef __NM_SETTINGS_STORAGE_H__
#define __NM_SETTINGS_STORAGE_H__
/*****************************************************************************/
#include "c-list/src/c-list.h"
#define NM_TYPE_SETTINGS_STORAGE (nm_settings_storage_get_type ())
#define NM_SETTINGS_STORAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTINGS_STORAGE, NMSettingsStorage))
#define NM_SETTINGS_STORAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTINGS_STORAGE, NMSettingsStorageClass))
#define NM_IS_SETTINGS_STORAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTINGS_STORAGE))
#define NM_IS_SETTINGS_STORAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTINGS_STORAGE))
#define NM_SETTINGS_STORAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTINGS_STORAGE, NMSettingsStorageClass))
#define NM_SETTINGS_STORAGE_PLUGIN "plugin"
#define NM_SETTINGS_STORAGE_UUID "uuid"
#define NM_SETTINGS_STORAGE_FILENAME "filename"
struct _NMSettingsPlugin;
typedef struct NMSettingsStorage {
GObject parent;
struct _NMSettingsPlugin *_plugin;
char *_uuid;
char *_filename;
CList _storage_lst;
CList _storage_by_uuid_lst;
} NMSettingsStorage;
typedef struct {
GObjectClass parent;
int (*cmp_fcn) (NMSettingsStorage *a,
NMSettingsStorage *b);
} NMSettingsStorageClass;
GType nm_settings_storage_get_type (void);
NMSettingsStorage *nm_settings_storage_new (struct _NMSettingsPlugin *plugin,
const char *uuid,
const char *filename);
static inline struct _NMSettingsPlugin *
nm_settings_storage_get_plugin (const NMSettingsStorage *self)
{
GType nm_settings_plugin_get_type (void);
g_return_val_if_fail (NM_IS_SETTINGS_STORAGE (self), NULL);
nm_assert (G_TYPE_CHECK_INSTANCE_TYPE (self->_plugin, nm_settings_plugin_get_type ()));
return self->_plugin;
}
static inline const char *
nm_settings_storage_get_uuid (const NMSettingsStorage *self)
{
gboolean nm_utils_is_uuid (const char *str);
g_return_val_if_fail (NM_IS_SETTINGS_STORAGE (self), NULL);
nm_assert (nm_utils_is_uuid (self->_uuid));
return self->_uuid;
}
static inline const char *
nm_settings_storage_get_uuid_opt (const NMSettingsStorage *self)
{
gboolean nm_utils_is_uuid (const char *str);
g_return_val_if_fail (NM_IS_SETTINGS_STORAGE (self), NULL);
nm_assert (!self->_uuid || nm_utils_is_uuid (self->_uuid));
return self->_uuid;
}