summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-08-11 11:08:17 +0200
committerThomas Haller <thaller@redhat.com>2018-08-28 15:18:21 +0200
commit8f9234f884fae9acec34419e67ef71b1ccea573d (patch)
tree946bfbe31061374f83463c637c0d0e456e69b802
parent7d676c865f2094dd8b0f5feecbefe24cabfd597b (diff)
downloadNetworkManager-th/settings-delegate-connection.tar.gz
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnectionth/settings-delegate-connection
NMConnection is an interface, which is implemented by the types NMSimpleConnection (libnm-core), NMSettingsConnection (src) and NMRemoteConnection (libnm). NMSettingsConnection does a lot of things already: 1) it "is-a" NMDBusObject and exports the API of a connection profile on D-Bus 2) it interacts with NMSettings and contains functionality for tracking the profiles. 3) it is the base-class of types like NMSKeyfileConnection and NMIfcfgConnection. These handle how the profile is persisted on disk. 4) it implements NMConnection interface, to itself track the settings of the profile. 3) and 4) would be better implemented via delegation than inheritance. Address 4) and don't let NMSettingsConnection implemente the NMConnection interface. Instead, a settings-connection references now a NMSimpleConnection instance, to which it delegates for keeping the actual profiles. Advantages: - by delegating, there is a clearer separation of what NMSettingsConnection does. For example, in C we often required casts from NMSettingsConnection to NMConnection. NMConnection is a very trivial object with very little logic. When we have a NMConnection instance at hand, it's good to know that it is *only* that simple instead of also being an entire NMSettingsConnection instance. The main purpose of this patch is to simplify the code by separating the NMConnection from the NMSettingsConnection. We should generally be aware whether we handle a NMSettingsConnection or a trivial NMConnection instance. Now, because NMSettingsConnection no longer "is-a" NMConnection, this distinction is apparent. - NMConnection is implemented as an interface and we create NMSimpleConnection instances whenever we need a real instance. In GLib, interfaces have a performance overhead, that we needlessly pay all the time. With this change, we no longer require NMConnection to be an interface. Thus, in the future we could compile a version of libnm-core for the daemon, where NMConnection is not an interface but a GObject implementation akin to NMSimpleConnection. - In the previous implementation, we cannot treat NMConnection immutable and copy-on-write. For example, when NMDevice needs a snapshot of the activated profile as applied-connection, all it can do is clone the entire NMSettingsConnection as a NMSimpleConnection. Likewise, when we get a NMConnection instance and want to keep a reference to it, we cannot do that, because we never know who also references and modifies the instance. By separating NMSettingsConnection we could in the future have NMConnection immutable and copy-on-write, to avoid all unnecessary clones.
-rw-r--r--src/NetworkManagerUtils.c4
-rw-r--r--src/devices/bluetooth/nm-bluez-device.c73
-rw-r--r--src/devices/bluetooth/nm-device-bt.c7
-rw-r--r--src/devices/nm-device-ethernet-utils.c22
-rw-r--r--src/devices/nm-device-ethernet-utils.h2
-rw-r--r--src/devices/nm-device-ethernet.c11
-rw-r--r--src/devices/nm-device.c115
-rw-r--r--src/devices/nm-device.h5
-rw-r--r--src/devices/wifi/nm-device-iwd.c9
-rw-r--r--src/devices/wifi/nm-device-wifi.c30
-rw-r--r--src/devices/wifi/nm-wifi-ap.c4
-rw-r--r--src/nm-active-connection.c78
-rw-r--r--src/nm-checkpoint-manager.c4
-rw-r--r--src/nm-checkpoint.c25
-rw-r--r--src/nm-dbus-manager.c2
-rw-r--r--src/nm-dbus-manager.h2
-rw-r--r--src/nm-manager.c469
-rw-r--r--src/nm-policy.c140
-rw-r--r--src/settings/nm-settings-connection.c233
-rw-r--r--src/settings/nm-settings-connection.h12
-rw-r--r--src/settings/nm-settings.c124
-rw-r--r--src/settings/nm-settings.h2
-rw-r--r--src/settings/plugins/ibft/nms-ibft-plugin.c4
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c6
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c26
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h4
-rw-r--r--src/settings/plugins/ifupdown/nms-ifupdown-connection.c15
-rw-r--r--src/settings/plugins/ifupdown/nms-ifupdown-plugin.c7
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-connection.c8
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-plugin.c10
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-utils.h4
-rw-r--r--src/tests/test-wired-defname.c17
-rw-r--r--src/vpn/nm-vpn-connection.c18
33 files changed, 839 insertions, 653 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index a3bd601359..1404854d71 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -805,9 +805,11 @@ nm_utils_match_connection (NMConnection *const*connections,
return NULL;
for (; *connections; connections++) {
- NMConnection *candidate = NM_CONNECTION (*connections);
+ NMConnection *candidate = *connections;
GHashTable *diffs = NULL;
+ nm_assert (NM_IS_CONNECTION (candidate));
+
if (match_filter_func) {
if (!match_filter_func (candidate, match_filter_data))
continue;
diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c
index d8e40d6f38..b69b432039 100644
--- a/src/devices/bluetooth/nm-bluez-device.c
+++ b/src/devices/bluetooth/nm-bluez-device.c
@@ -94,7 +94,7 @@ typedef struct {
NMSettings *settings;
GSList *connections;
- NMConnection *pan_connection;
+ NMSettingsConnection *pan_connection;
gboolean pan_connection_no_autocreate;
} NMBluezDevicePrivate;
@@ -114,8 +114,9 @@ G_DEFINE_TYPE (NMBluezDevice, nm_bluez_device, G_TYPE_OBJECT)
/*****************************************************************************/
static void cp_connection_added (NMSettings *settings,
- NMConnection *connection, NMBluezDevice *self);
-static gboolean connection_compatible (NMBluezDevice *self, NMConnection *connection);
+ NMSettingsConnection *sett_conn,
+ NMBluezDevice *self);
+static gboolean connection_compatible (NMBluezDevice *self, NMSettingsConnection *sett_conn);
/*****************************************************************************/
@@ -181,10 +182,10 @@ nm_bluez_device_get_connected (NMBluezDevice *self)
static void
pan_connection_check_create (NMBluezDevice *self)
{
- NMConnection *connection;
- NMConnection *added;
+ gs_unref_object NMConnection *connection = NULL;
+ NMSettingsConnection *added;
NMSetting *setting;
- char *id;
+ gs_free char *id = NULL;
char uuid[37];
GError *error = NULL;
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
@@ -246,15 +247,14 @@ 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_CONNECTION (nm_settings_add_connection (priv->settings, connection, FALSE, &error));
+ added = nm_settings_add_connection (priv->settings, connection, FALSE, &error);
g_signal_handlers_unblock_by_func (priv->settings, cp_connection_added, self);
if (added) {
- g_assert (!g_slist_find (priv->connections, added));
- g_assert (connection_compatible (self, added));
- g_assert (nm_connection_compare (added, connection, NM_SETTING_COMPARE_FLAG_EXACT));
+ nm_assert (!g_slist_find (priv->connections, added));
+ nm_assert (connection_compatible (self, added));
- nm_settings_connection_set_flags (NM_SETTINGS_CONNECTION (added), NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED, TRUE);
+ 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;
@@ -263,11 +263,7 @@ pan_connection_check_create (NMBluezDevice *self)
nm_log_warn (LOGD_BT, "bluez[%s] couldn't add new Bluetooth connection for NAP device: '%s' (%s): %s",
priv->path, id, uuid, error->message);
g_clear_error (&error);
-
}
- g_object_unref (connection);
-
- g_free (id);
}
static gboolean
@@ -321,9 +317,10 @@ check_emit_usable_schedule (NMBluezDevice *self)
/*****************************************************************************/
static gboolean
-connection_compatible (NMBluezDevice *self, NMConnection *connection)
+connection_compatible (NMBluezDevice *self, NMSettingsConnection *sett_conn)
{
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
+ NMConnection *connection = nm_settings_connection_get_connection (sett_conn);
NMSettingBluetooth *s_bt;
const char *bt_type;
const char *bdaddr;
@@ -361,22 +358,24 @@ connection_compatible (NMBluezDevice *self, NMConnection *connection)
}
static gboolean
-_internal_track_connection (NMBluezDevice *self, NMConnection *connection, gboolean tracked)
+_internal_track_connection (NMBluezDevice *self,
+ NMSettingsConnection *sett_conn,
+ gboolean tracked)
{
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
gboolean was_tracked;
- was_tracked = !!g_slist_find (priv->connections, connection);
+ was_tracked = !!g_slist_find (priv->connections, sett_conn);
if (was_tracked == !!tracked)
return FALSE;
if (tracked)
- priv->connections = g_slist_prepend (priv->connections, g_object_ref (connection));
+ priv->connections = g_slist_prepend (priv->connections, g_object_ref (sett_conn));
else {
- priv->connections = g_slist_remove (priv->connections, connection);
- if (priv->pan_connection == connection)
+ priv->connections = g_slist_remove (priv->connections, sett_conn);
+ if (priv->pan_connection == sett_conn)
priv->pan_connection = NULL;
- g_object_unref (connection);
+ g_object_unref (sett_conn);
}
return TRUE;
@@ -384,32 +383,32 @@ _internal_track_connection (NMBluezDevice *self, NMConnection *connection, gbool
static void
cp_connection_added (NMSettings *settings,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
NMBluezDevice *self)
{
- if (connection_compatible (self, connection)) {
- if (_internal_track_connection (self, connection, TRUE))
+ if (connection_compatible (self, sett_conn)) {
+ if (_internal_track_connection (self, sett_conn, TRUE))
check_emit_usable (self);
}
}
static void
cp_connection_removed (NMSettings *settings,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
NMBluezDevice *self)
{
- if (_internal_track_connection (self, connection, FALSE))
+ if (_internal_track_connection (self, sett_conn, FALSE))
check_emit_usable (self);
}
static void
cp_connection_updated (NMSettings *settings,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
gboolean by_user,
NMBluezDevice *self)
{
- if (_internal_track_connection (self, connection,
- connection_compatible (self, connection)))
+ if (_internal_track_connection (self, sett_conn,
+ connection_compatible (self, sett_conn)))
check_emit_usable_schedule (self);
}
@@ -423,10 +422,8 @@ load_connections (NMBluezDevice *self)
connections = nm_settings_get_connections (priv->settings, NULL);
for (i = 0; connections[i]; i++) {
- NMConnection *connection = (NMConnection *) connections[i];
-
- if (connection_compatible (self, connection))
- changed |= _internal_track_connection (self, connection, TRUE);
+ if (connection_compatible (self, connections[i]))
+ changed |= _internal_track_connection (self, connections[i], TRUE);
}
if (changed)
check_emit_usable (self);
@@ -1178,14 +1175,14 @@ dispose (GObject *object)
{
NMBluezDevice *self = NM_BLUEZ_DEVICE (object);
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
- NMConnection *to_delete = NULL;
+ NMSettingsConnection *to_delete = NULL;
nm_clear_g_source (&priv->check_emit_usable_id);
if (priv->pan_connection) {
/* Check whether we want to remove the created connection. If so, we take a reference
* and delete it at the end of dispose(). */
- if (NM_FLAGS_HAS (nm_settings_connection_get_flags (NM_SETTINGS_CONNECTION (priv->pan_connection)),
+ if (NM_FLAGS_HAS (nm_settings_connection_get_flags (priv->pan_connection),
NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED))
to_delete = g_object_ref (priv->pan_connection);
@@ -1219,8 +1216,8 @@ dispose (GObject *object)
if (to_delete) {
nm_log_dbg (LOGD_BT, "bluez[%s] removing Bluetooth connection for NAP device: '%s' (%s)", priv->path,
- nm_connection_get_id (to_delete), nm_connection_get_uuid (to_delete));
- nm_settings_connection_delete (NM_SETTINGS_CONNECTION (to_delete), NULL);
+ nm_settings_connection_get_id (to_delete), nm_settings_connection_get_uuid (to_delete));
+ nm_settings_connection_delete (to_delete, NULL);
g_object_unref (to_delete);
}
diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c
index a11c798698..1f650d339f 100644
--- a/src/devices/bluetooth/nm-device-bt.c
+++ b/src/devices/bluetooth/nm-device-bt.c
@@ -36,6 +36,7 @@
#include "nm-setting-serial.h"
#include "nm-setting-ppp.h"
#include "NetworkManagerUtils.h"
+#include "settings/nm-settings-connection.h"
#include "nm-utils.h"
#include "nm-bt-error.h"
#include "platform/nm-platform.h"
@@ -137,7 +138,7 @@ get_generic_capabilities (NMDevice *device)
static gboolean
can_auto_connect (NMDevice *device,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
char **specific_object)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) device);
@@ -145,11 +146,11 @@ can_auto_connect (NMDevice *device,
nm_assert (!specific_object || !*specific_object);
- if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->can_auto_connect (device, connection, NULL))
+ if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->can_auto_connect (device, sett_conn, NULL))
return FALSE;
/* Can't auto-activate a DUN connection without ModemManager */
- bt_type = get_connection_bt_type (connection);
+ bt_type = get_connection_bt_type (nm_settings_connection_get_connection (sett_conn));
if (bt_type == NM_BT_CAPABILITY_DUN && priv->mm_running == FALSE)
return FALSE;
diff --git a/src/devices/nm-device-ethernet-utils.c b/src/devices/nm-device-ethernet-utils.c
index 0963803573..8bdb19917a 100644
--- a/src/devices/nm-device-ethernet-utils.c
+++ b/src/devices/nm-device-ethernet-utils.c
@@ -18,31 +18,23 @@
#include "nm-default.h"
-#include <string.h>
-
-#include "nm-connection.h"
-
#include "nm-device-ethernet-utils.h"
+#include "settings/nm-settings-connection.h"
+
char *
-nm_device_ethernet_utils_get_default_wired_name (NMConnection *const *connections)
+nm_device_ethernet_utils_get_default_wired_name (GHashTable *existing_ids)
{
char *temp;
- guint j;
int i;
/* Find the next available unique connection name */
for (i = 1; i <= G_MAXINT; i++) {
temp = g_strdup_printf (_("Wired connection %d"), i);
- for (j = 0; connections[j]; j++) {
- if (nm_streq0 (nm_connection_get_id (connections[j]), temp)) {
- g_free (temp);
- goto next;
- }
- }
- return temp;
-next:
- ;
+ if ( !existing_ids
+ || !g_hash_table_contains (existing_ids, temp))
+ return temp;
+ g_free (temp);
}
return NULL;
}
diff --git a/src/devices/nm-device-ethernet-utils.h b/src/devices/nm-device-ethernet-utils.h
index 197d0a9ea4..7e5c8b313c 100644
--- a/src/devices/nm-device-ethernet-utils.h
+++ b/src/devices/nm-device-ethernet-utils.h
@@ -19,6 +19,6 @@
#ifndef __NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H__
#define __NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H__
-char *nm_device_ethernet_utils_get_default_wired_name (NMConnection *const *connections);
+char *nm_device_ethernet_utils_get_default_wired_name (GHashTable *existing_ids);
#endif /* NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H */
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index 0d9038983c..4d4624b7f8 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -1443,12 +1443,14 @@ new_default_connection (NMDevice *self)
NMConnection *connection;
NMSettingsConnection *const*connections;
NMSetting *setting;
+ gs_unref_hashtable GHashTable *existing_ids = NULL;
struct udev_device *dev;
const char *perm_hw_addr;
const char *uprop = "0";
gs_free char *defname = NULL;
gs_free char *uuid = NULL;
gs_free char *machine_id = NULL;
+ guint i, n_connections;
if (nm_config_get_no_auto_default_for_device (nm_config_get (), self))
return NULL;
@@ -1461,8 +1463,13 @@ new_default_connection (NMDevice *self)
setting = nm_setting_connection_new ();
nm_connection_add_setting (connection, setting);
- connections = nm_settings_get_connections (nm_device_get_settings (self), NULL);
- defname = nm_device_ethernet_utils_get_default_wired_name ((NMConnection *const*) connections);
+ connections = nm_settings_get_connections (nm_device_get_settings (self), &n_connections);
+ if (n_connections > 0) {
+ existing_ids = g_hash_table_new (nm_str_hash, g_str_equal);
+ for (i = 0; i < n_connections; i++)
+ g_hash_table_add (existing_ids, (char *) nm_settings_connection_get_id (connections[i]));
+ }
+ defname = nm_device_ethernet_utils_get_default_wired_name (existing_ids);
if (!defname)
return NULL;
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index b1faf13e15..55a81e4f34 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -1736,7 +1736,7 @@ nm_device_parent_find_for_connection (NMDevice *self,
current_setting_parent);
if ( parent_connection
&& nm_device_check_connection_compatible (parent_device,
- NM_CONNECTION (parent_connection),
+ nm_settings_connection_get_connection (parent_connection),
NULL))
return current_setting_parent;
}
@@ -2346,6 +2346,22 @@ nm_device_get_settings_connection (NMDevice *self)
}
NMConnection *
+nm_device_get_settings_connection_get_connection (NMDevice *self)
+{
+ NMSettingsConnection *sett_con;
+ NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
+
+ if (!priv->act_request.obj)
+ return NULL;
+
+ sett_con = nm_act_request_get_settings_connection (priv->act_request.obj);
+ if (!sett_con)
+ return NULL;
+
+ return nm_settings_connection_get_connection (sett_con);
+}
+
+NMConnection *
nm_device_get_applied_connection (NMDevice *self)
{
NMDevicePrivate *priv;
@@ -5193,7 +5209,7 @@ nm_device_autoconnect_allowed (NMDevice *self)
static gboolean
can_auto_connect (NMDevice *self,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
char **specific_object)
{
nm_assert (!specific_object || !*specific_object);
@@ -5203,27 +5219,27 @@ can_auto_connect (NMDevice *self,
/**
* nm_device_can_auto_connect:
* @self: an #NMDevice
- * @connection: a #NMConnection
+ * @sett_conn: a #NMSettingsConnection
* @specific_object: (out) (transfer full): on output, the path of an
* object associated with the returned connection, to be passed to
* nm_manager_activate_connection(), or %NULL.
*
- * Checks if @connection can be auto-activated on @self right now.
+ * Checks if @sett_conn can be auto-activated on @self right now.
* This requires, at a minimum, that the connection be compatible with
* @self, and that it have the #NMSettingConnection:autoconnect property
* set, and that the device allow auto connections. Some devices impose
* additional requirements. (Eg, a Wi-Fi connection can only be activated
* if its SSID was seen in the last scan.)
*
- * Returns: %TRUE, if the @connection can be auto-activated.
+ * Returns: %TRUE, if the @sett_conn can be auto-activated.
**/
gboolean
nm_device_can_auto_connect (NMDevice *self,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
char **specific_object)
{
g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
- g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (sett_conn), FALSE);
g_return_val_if_fail (!specific_object || !*specific_object, FALSE);
/* the caller must ensure that nm_device_autoconnect_allowed() returns
@@ -5235,10 +5251,14 @@ nm_device_can_auto_connect (NMDevice *self,
* over and over again. The caller is supposed to do that. */
nm_assert (nm_device_autoconnect_allowed (self));
- if (!nm_device_check_connection_available (self, connection, NM_DEVICE_CHECK_CON_AVAILABLE_NONE, NULL, NULL))
+ if (!nm_device_check_connection_available (self,
+ nm_settings_connection_get_connection (sett_conn),
+ NM_DEVICE_CHECK_CON_AVAILABLE_NONE,
+ NULL,
+ NULL))
return FALSE;
- if (!NM_DEVICE_GET_CLASS (self)->can_auto_connect (self, connection, specific_object))
+ if (!NM_DEVICE_GET_CLASS (self)->can_auto_connect (self, sett_conn, specific_object))
return FALSE;
return TRUE;
@@ -11095,7 +11115,7 @@ reapply_cb (NMDevice *self,
nm_device_sys_iface_state_set (self, NM_DEVICE_SYS_IFACE_STATE_MANAGED);
if (!check_and_reapply_connection (self,
- connection ?: (NMConnection *) nm_device_get_settings_connection (self),
+ connection ?: nm_device_get_settings_connection_get_connection (self),
version_id,
&audit_args,
&local)) {
@@ -11883,7 +11903,8 @@ nm_device_set_ip_config (NMDevice *self,
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));
- nm_connection_add_setting (NM_CONNECTION (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),
IS_IPv4
? nm_ip4_config_create_setting (priv->ip_config_4)
: nm_ip6_config_create_setting (priv->ip_config_6));
@@ -13342,7 +13363,7 @@ nm_device_reapply_settings_immediately (NMDevice *self)
NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY))
return;
- s_con_settings = nm_connection_get_setting_connection ((NMConnection *) settings_connection);
+ s_con_settings = nm_connection_get_setting_connection (nm_settings_connection_get_connection (settings_connection));
s_con_applied = nm_connection_get_setting_connection (applied_connection);
if (g_strcmp0 ((zone = nm_setting_connection_get_zone (s_con_settings)),
@@ -13603,15 +13624,15 @@ available_connections_del_all (NMDevice *self)
}
static gboolean
-available_connections_add (NMDevice *self, NMConnection *connection)
+available_connections_add (NMDevice *self, NMSettingsConnection *sett_conn)
{
- return g_hash_table_add (self->_priv->available_connections, g_object_ref (connection));
+ return g_hash_table_add (self->_priv->available_connections, g_object_ref (sett_conn));
}
static gboolean
-available_connections_del (NMDevice *self, NMConnection *connection)
+available_connections_del (NMDevice *self, NMSettingsConnection *sett_conn)
{
- return g_hash_table_remove (self->_priv->available_connections, connection);
+ return g_hash_table_remove (self->_priv->available_connections, sett_conn);
}
static gboolean
@@ -13657,7 +13678,7 @@ nm_device_recheck_available_connections (NMDevice *self)
NMSettingsConnection *const*connections;
gboolean changed = FALSE;
GHashTableIter h_iter;
- NMConnection *connection;
+ NMSettingsConnection *sett_conn;
guint i;
gs_unref_hashtable GHashTable *prune_list = NULL;
@@ -13668,30 +13689,30 @@ nm_device_recheck_available_connections (NMDevice *self)
if (g_hash_table_size (priv->available_connections) > 0) {
prune_list = g_hash_table_new (nm_direct_hash, NULL);
g_hash_table_iter_init (&h_iter, priv->available_connections);
- while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL))
- g_hash_table_add (prune_list, connection);
+ while (g_hash_table_iter_next (&h_iter, (gpointer *) &sett_conn, NULL))
+ g_hash_table_add (prune_list, sett_conn);
}
connections = nm_settings_get_connections (priv->settings, NULL);
for (i = 0; connections[i]; i++) {
- connection = (NMConnection *) connections[i];
+ sett_conn = connections[i];
if (nm_device_check_connection_available (self,
- connection,
+ nm_settings_connection_get_connection (sett_conn),
NM_DEVICE_CHECK_CON_AVAILABLE_NONE,
NULL,
NULL)) {
- if (available_connections_add (self, connection))
+ if (available_connections_add (self, sett_conn))
changed = TRUE;
if (prune_list)
- g_hash_table_remove (prune_list, connection);
+ g_hash_table_remove (prune_list, sett_conn);
}
}
if (prune_list) {
g_hash_table_iter_init (&h_iter, prune_list);
- while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL)) {
- if (available_connections_del (self, connection))
+ while (g_hash_table_iter_next (&h_iter, (gpointer *) &sett_conn, NULL)) {
+ if (available_connections_del (self, sett_conn))
changed = TRUE;
}
}
@@ -13718,7 +13739,7 @@ nm_device_get_best_connection (NMDevice *self,
GError **error)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
- NMSettingsConnection *connection = NULL;
+ NMSettingsConnection *sett_conn = NULL;
NMSettingsConnection *candidate;
guint64 best_timestamp = 0;
GHashTableIter iter;
@@ -13732,44 +13753,44 @@ nm_device_get_best_connection (NMDevice *self,
*/
if ( specific_object /* << Optimization: we know that the connection is available without @specific_object. */
&& !nm_device_check_connection_available (self,
- NM_CONNECTION (candidate),
+ nm_settings_connection_get_connection (candidate),
_NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST,
specific_object,
NULL))
continue;
nm_settings_connection_get_timestamp (candidate, &candidate_timestamp);
- if (!connection || (candidate_timestamp > best_timestamp)) {
- connection = candidate;
+ if (!sett_conn || (candidate_timestamp > best_timestamp)) {
+ sett_conn = candidate;
best_timestamp = candidate_timestamp;
}
}
- if (!connection) {
+ if (!sett_conn) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_CONNECTION,
"The device '%s' has no connections available for activation.",
nm_device_get_iface (self));
}
- return connection;
+ return sett_conn;
}
static void
-cp_connection_added_or_updated (NMDevice *self, NMConnection *connection)
+cp_connection_added_or_updated (NMDevice *self, NMSettingsConnection *sett_conn)
{
gboolean changed;
g_return_if_fail (NM_IS_DEVICE (self));
- g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection));
+ g_return_if_fail (NM_IS_SETTINGS_CONNECTION (sett_conn));
if (nm_device_check_connection_available (self,
- connection,
+ nm_settings_connection_get_connection (sett_conn),
_NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST,
NULL,
NULL))
- changed = available_connections_add (self, connection);
+ changed = available_connections_add (self, sett_conn);
else
- changed = available_connections_del (self, connection);
+ changed = available_connections_del (self, sett_conn);
if (changed) {
_notify (self, PROP_AVAILABLE_CONNECTIONS);
@@ -13778,25 +13799,25 @@ cp_connection_added_or_updated (NMDevice *self, NMConnection *connection)
}
static void
-cp_connection_added (NMSettings *settings, NMConnection *connection, gpointer user_data)
+cp_connection_added (NMSettings *settings, NMSettingsConnection *sett_conn, gpointer user_data)
{
- cp_connection_added_or_updated (user_data, connection);
+ cp_connection_added_or_updated (user_data, sett_conn);
}
static void
-cp_connection_updated (NMSettings *settings, NMConnection *connection, gboolean by_user, gpointer user_data)
+cp_connection_updated (NMSettings *settings, NMSettingsConnection *sett_conn, gboolean by_user, gpointer user_data)
{
- cp_connection_added_or_updated (user_data, connection);
+ cp_connection_added_or_updated (user_data, sett_conn);
}
static void
-cp_connection_removed (NMSettings *settings, NMConnection *connection, gpointer user_data)
+cp_connection_removed (NMSettings *settings, NMSettingsConnection *sett_conn, gpointer user_data)
{
NMDevice *self = user_data;
g_return_if_fail (NM_IS_DEVICE (self));
- if (available_connections_del (self, connection)) {
+ if (available_connections_del (self, sett_conn)) {
_notify (self, PROP_AVAILABLE_CONNECTIONS);
available_connections_check_delete_unrealized (self);
}
@@ -14436,7 +14457,7 @@ _set_state_full (NMDevice *self,
NMDeviceState old_state;
NMActRequest *req;
gboolean no_firmware = FALSE;
- NMSettingsConnection *connection;
+ NMSettingsConnection *sett_conn;
g_return_if_fail (NM_IS_DEVICE (self));
@@ -14695,10 +14716,10 @@ _set_state_full (NMDevice *self,
break;
}
- connection = nm_device_get_settings_connection (self);
+ sett_conn = nm_device_get_settings_connection (self);
_LOGW (LOGD_DEVICE | LOGD_WIFI,
"Activation: failed for connection '%s'",
- connection ? nm_settings_connection_get_id (connection) : "<unknown>");
+ sett_conn ? nm_settings_connection_get_id (sett_conn) : "<unknown>");
/* Notify any slaves of the unexpected failure */
nm_device_master_release_slaves (self);
@@ -14708,8 +14729,8 @@ _set_state_full (NMDevice *self,
* failed (zero timestamp), connections that succeeded (non-zero timestamp),
* and those we haven't tried yet (no timestamp).
*/
- if (connection && !nm_settings_connection_get_timestamp (connection, NULL))
- nm_settings_connection_update_timestamp (connection, (guint64) 0, TRUE);
+ if (sett_conn && !nm_settings_connection_get_timestamp (sett_conn, NULL))
+ nm_settings_connection_update_timestamp (sett_conn, (guint64) 0, TRUE);
/* Schedule the transition to DISCONNECTED. The device can't transition
* immediately because we can't change states again from the state
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index 9660ee3eb2..7d74e5b91d 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -297,7 +297,7 @@ typedef struct _NMDeviceClass {
gboolean (* get_autoconnect_allowed) (NMDevice *self);
gboolean (* can_auto_connect) (NMDevice *self,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
char **specific_object);
guint32 (*get_configured_mtu) (NMDevice *self, NMDeviceMtuSource *out_source);
@@ -512,6 +512,7 @@ NMDevice * nm_device_get_master (NMDevice *dev);
NMActRequest * nm_device_get_act_request (NMDevice *dev);
NMSettingsConnection *nm_device_get_settings_connection (NMDevice *dev);
+NMConnection * nm_device_get_settings_connection_get_connection (NMDevice *self);
NMConnection * nm_device_get_applied_connection (NMDevice *dev);
gboolean nm_device_has_unmodified_applied_connection (NMDevice *self,
NMSettingCompareFlags compare_flags);
@@ -535,7 +536,7 @@ gboolean nm_device_master_update_slave_connection (NMDevice *master,
GError **error);
gboolean nm_device_can_auto_connect (NMDevice *self,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
char **specific_object);
gboolean nm_device_complete_connection (NMDevice *device,
diff --git a/src/devices/wifi/nm-device-iwd.c b/src/devices/wifi/nm-device-iwd.c
index 3a6855cbad..3be6159f24 100644
--- a/src/devices/wifi/nm-device-iwd.c
+++ b/src/devices/wifi/nm-device-iwd.c
@@ -797,11 +797,12 @@ get_autoconnect_allowed (NMDevice *device)
static gboolean
can_auto_connect (NMDevice *device,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
char **specific_object)
{
NMDeviceIwd *self = NM_DEVICE_IWD (device);
NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE (self);
+ NMConnection *connection;
NMSettingWireless *s_wifi;
NMWifiAP *ap;
const char *mode;
@@ -809,9 +810,11 @@ can_auto_connect (NMDevice *device,
nm_assert (!specific_object || !*specific_object);
- if (!NM_DEVICE_CLASS (nm_device_iwd_parent_class)->can_auto_connect (device, connection, NULL))
+ if (!NM_DEVICE_CLASS (nm_device_iwd_parent_class)->can_auto_connect (device, sett_conn, NULL))
return FALSE;
+ connection = nm_settings_connection_get_connection (sett_conn);
+
s_wifi = nm_connection_get_setting_wireless (connection);
g_return_val_if_fail (s_wifi, FALSE);
@@ -824,7 +827,7 @@ can_auto_connect (NMDevice *device,
* but haven't been successful, since these are often accidental choices
* from the menu and the user may not know the password.
*/
- if (nm_settings_connection_get_timestamp (NM_SETTINGS_CONNECTION (connection), &timestamp)) {
+ if (nm_settings_connection_get_timestamp (sett_conn, &timestamp)) {
if (timestamp == 0)
return FALSE;
}
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index 5190faf742..e4b105eb32 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -958,11 +958,12 @@ get_autoconnect_allowed (NMDevice *device)
static gboolean
can_auto_connect (NMDevice *device,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
char **specific_object)
{
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
+ NMConnection *connection;
NMSettingWireless *s_wifi;
NMWifiAP *ap;
const char *method, *mode;
@@ -970,26 +971,28 @@ can_auto_connect (NMDevice *device,
nm_assert (!specific_object || !*specific_object);
- if (!NM_DEVICE_CLASS (nm_device_wifi_parent_class)->can_auto_connect (device, connection, NULL))
+ if (!NM_DEVICE_CLASS (nm_device_wifi_parent_class)->can_auto_connect (device, sett_conn, NULL))
return FALSE;
+ connection = nm_settings_connection_get_connection (sett_conn);
+
s_wifi = nm_connection_get_setting_wireless (connection);
g_return_val_if_fail (s_wifi, FALSE);
/* Always allow autoconnect for AP and non-autoconf Ad-Hoc */
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
mode = nm_setting_wireless_get_mode (s_wifi);
- if (g_strcmp0 (mode, NM_SETTING_WIRELESS_MODE_AP) == 0)
+ if (nm_streq0 (mode, NM_SETTING_WIRELESS_MODE_AP))
return TRUE;
- else if ( g_strcmp0 (mode, NM_SETTING_WIRELESS_MODE_ADHOC) == 0
- && g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) != 0)
+ else if ( nm_streq0 (mode, NM_SETTING_WIRELESS_MODE_ADHOC)
+ && !nm_streq0 (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO))
return TRUE;
/* Don't autoconnect to networks that have been tried at least once
* but haven't been successful, since these are often accidental choices
* from the menu and the user may not know the password.
*/
- if (nm_settings_connection_get_timestamp (NM_SETTINGS_CONNECTION (connection), &timestamp)) {
+ if (nm_settings_connection_get_timestamp (sett_conn, &timestamp)) {
if (timestamp == 0)
return FALSE;
}
@@ -1264,14 +1267,15 @@ check_scanning_prohibited (NMDeviceWifi *self, gboolean periodic)
static gboolean
hidden_filter_func (NMSettings *settings,
- NMSettingsConnection *connection,
+ NMSettingsConnection *set_con,
gpointer user_data)
{
+ NMConnection *connection = nm_settings_connection_get_connection (set_con);
NMSettingWireless *s_wifi;
- if (!nm_connection_is_type (NM_CONNECTION (connection), NM_SETTING_WIRELESS_SETTING_NAME))
+ if (!nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME))
return FALSE;
- s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (connection));
+ s_wifi = nm_connection_get_setting_wireless (connection);
if (!s_wifi)
return FALSE;
if (nm_streq0 (nm_setting_wireless_get_mode (s_wifi), NM_SETTING_WIRELESS_MODE_AP))
@@ -1316,7 +1320,7 @@ build_hidden_probe_list (NMDeviceWifi *self)
if (i >= max_scan_ssids - 1)
break;
- s_wifi = (NMSettingWireless *) nm_connection_get_setting_wireless (NM_CONNECTION (connections[i]));
+ s_wifi = (NMSettingWireless *) nm_connection_get_setting_wireless (nm_settings_connection_get_connection (connections[i]));
ssid = nm_setting_wireless_get_ssid (s_wifi);
g_ptr_array_add (ssids, g_bytes_ref (ssid));
}
@@ -1509,12 +1513,12 @@ try_fill_ssid_for_hidden_ap (NMDeviceWifi *self,
* and if a match is found, copy over the SSID */
connections = nm_settings_get_connections (nm_device_get_settings ((NMDevice *) self), NULL);
for (i = 0; connections[i]; i++) {
- NMConnection *connection = (NMConnection *) connections[i];
+ NMSettingsConnection *sett_conn = connections[i];
NMSettingWireless *s_wifi;
- s_wifi = nm_connection_get_setting_wireless (connection);
+ s_wifi = nm_connection_get_setting_wireless (nm_settings_connection_get_connection (sett_conn));
if (s_wifi) {
- if (nm_settings_connection_has_seen_bssid (NM_SETTINGS_CONNECTION (connection), bssid)) {
+ if (nm_settings_connection_has_seen_bssid (sett_conn, bssid)) {
nm_wifi_ap_set_ssid (ap, nm_setting_wireless_get_ssid (s_wifi));
break;
}
diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c
index 7cfc659875..1dbc054af4 100644
--- a/src/devices/wifi/nm-wifi-ap.c
+++ b/src/devices/wifi/nm-wifi-ap.c
@@ -1544,8 +1544,8 @@ nm_wifi_ap_lookup_for_device (NMDevice *device, const char *exported_path)
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
- ap = (NMWifiAP *) nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (device)),
- exported_path);
+ ap = nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (device)),
+ exported_path);
if ( !ap
|| !NM_IS_WIFI_AP (ap)
|| ap->wifi_device != device)
diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c
index aa83d6d5b9..a2f9ae4a2b 100644
--- a/src/nm-active-connection.c
+++ b/src/nm-active-connection.c
@@ -174,7 +174,7 @@ NM_UTILS_FLAGS2STR_DEFINE_STATIC (_state_flags_to_string, NMActivationStateFlags
/*****************************************************************************/
static void
-_settings_connection_updated (NMSettingsConnection *connection,
+_settings_connection_updated (NMSettingsConnection *sett_conn,
gboolean by_user,
gpointer user_data)
{
@@ -196,24 +196,24 @@ _settings_connection_updated (NMSettingsConnection *connection,
}
static void
-_set_settings_connection (NMActiveConnection *self, NMSettingsConnection *connection)
+_set_settings_connection (NMActiveConnection *self, NMSettingsConnection *sett_conn)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
- if (priv->settings_connection.obj == connection)
+ if (priv->settings_connection.obj == sett_conn)
return;
if (priv->settings_connection.obj) {
g_signal_handlers_disconnect_by_func (priv->settings_connection.obj, _settings_connection_updated, self);
g_signal_handlers_disconnect_by_func (priv->settings_connection.obj, _settings_connection_flags_changed, self);
}
- if (connection) {
- g_signal_connect (connection, NM_SETTINGS_CONNECTION_UPDATED_INTERNAL, (GCallback) _settings_connection_updated, self);
+ if (sett_conn) {
+ g_signal_connect (sett_conn, NM_SETTINGS_CONNECTION_UPDATED_INTERNAL, (GCallback) _settings_connection_updated, self);
if (nm_active_connection_get_activation_type (self) == NM_ACTIVATION_TYPE_EXTERNAL)
- g_signal_connect (connection, NM_SETTINGS_CONNECTION_FLAGS_CHANGED, (GCallback) _settings_connection_flags_changed, self);
+ g_signal_connect (sett_conn, NM_SETTINGS_CONNECTION_FLAGS_CHANGED, (GCallback) _settings_connection_flags_changed, self);
}
- nm_dbus_track_obj_path_set (&priv->settings_connection, connection, TRUE);
+ nm_dbus_track_obj_path_set (&priv->settings_connection, sett_conn, TRUE);
}
NMActiveConnectionState
@@ -367,13 +367,13 @@ nm_active_connection_set_state_flags_full (NMActiveConnection *self,
const char *
nm_active_connection_get_settings_connection_id (NMActiveConnection *self)
{
- NMSettingsConnection *con;
+ NMSettingsConnection *sett_conn;
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), NULL);
- con = NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->settings_connection.obj;
- return con
- ? nm_connection_get_id (NM_CONNECTION (con))
+ sett_conn = NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->settings_connection.obj;
+ return sett_conn
+ ? nm_settings_connection_get_id (sett_conn)
: NULL;
}
@@ -388,31 +388,31 @@ _nm_active_connection_get_settings_connection (NMActiveConnection *self)
NMSettingsConnection *
nm_active_connection_get_settings_connection (NMActiveConnection *self)
{
- NMSettingsConnection *con;
+ NMSettingsConnection *sett_conn;
- con = _nm_active_connection_get_settings_connection (self);
+ sett_conn = _nm_active_connection_get_settings_connection (self);
/* Only call this function on an active-connection that is already
* fully set-up (i.e. that has a settings-connection). Other uses
* indicate a bug. */
- g_return_val_if_fail (con, NULL);
- return con;
+ g_return_val_if_fail (sett_conn, NULL);
+ return sett_conn;
}
NMConnection *
nm_active_connection_get_applied_connection (NMActiveConnection *self)
{
- NMConnection *con;
+ NMConnection *connection;
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), NULL);
- con = NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->applied_connection;
+ connection = NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->applied_connection;
/* Only call this function on an active-connection that is already
* fully set-up (i.e. that has a settings-connection). Other uses
* indicate a bug. */
- g_return_val_if_fail (con, NULL);
- return con;
+ g_return_val_if_fail (connection, NULL);
+ return connection;
}
static void
@@ -447,7 +447,7 @@ _set_applied_connection_take (NMActiveConnection *self,
void
nm_active_connection_set_settings_connection (NMActiveConnection *self,
- NMSettingsConnection *connection)
+ NMSettingsConnection *sett_conn)
{
NMActiveConnectionPrivate *priv;
@@ -455,7 +455,7 @@ nm_active_connection_set_settings_connection (NMActiveConnection *self,
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
- g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection));
+ g_return_if_fail (NM_IS_SETTINGS_CONNECTION (sett_conn));
g_return_if_fail (!priv->settings_connection.obj);
g_return_if_fail (!priv->applied_connection);
@@ -468,10 +468,10 @@ nm_active_connection_set_settings_connection (NMActiveConnection *self,
* For example, we'd have to cancel all pending seret requests. */
g_return_if_fail (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (self)));
- _set_settings_connection (self, connection);
+ _set_settings_connection (self, sett_conn);
_set_applied_connection_take (self,
- nm_simple_connection_new_clone (NM_CONNECTION (priv->settings_connection.obj)));
+ nm_simple_connection_new_clone (nm_settings_connection_get_connection (priv->settings_connection.obj)));
}
gboolean
@@ -503,8 +503,10 @@ 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))
- nm_connection_clear_secrets ((NMConnection *) priv->settings_connection.obj);
+ 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_connection_clear_secrets (priv->applied_connection);
}
@@ -921,7 +923,7 @@ _settings_connection_flags_changed (NMSettingsConnection *settings_connection,
_set_activation_type_managed (self);
if (!nm_device_reapply (nm_active_connection_get_device (self),
- NM_CONNECTION (nm_active_connection_get_settings_connection (self)),
+ nm_settings_connection_get_connection ((nm_active_connection_get_settings_connection (self))),
&error)) {
_LOGW ("failed to reapply new device settings on previously externally managed device: %s",
error->message);
@@ -1112,7 +1114,7 @@ nm_active_connection_authorize (NMActiveConnection *self,
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
const char *wifi_permission = NULL;
- NMConnection *con;
+ NMConnection *connection;
g_return_if_fail (result_func);
g_return_if_fail (!priv->auth.call_id_network_control);
@@ -1122,11 +1124,11 @@ nm_active_connection_authorize (NMActiveConnection *self,
g_return_if_fail (NM_IS_CONNECTION (initial_connection));
g_return_if_fail (!priv->settings_connection.obj);
g_return_if_fail (!priv->applied_connection);
- con = initial_connection;
+ connection = initial_connection;
} else {
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (priv->settings_connection.obj));
g_return_if_fail (NM_IS_CONNECTION (priv->applied_connection));
- con = priv->applied_connection;
+ connection = priv->applied_connection;
}
priv->auth.call_id_network_control = nm_auth_manager_check_authorization (nm_auth_manager_get (),
@@ -1137,7 +1139,7 @@ nm_active_connection_authorize (NMActiveConnection *self,
self);
/* Shared wifi connections require special permissions too */
- wifi_permission = nm_utils_get_shared_wifi_permission (con);
+ wifi_permission = nm_utils_get_shared_wifi_permission (connection);
if (wifi_permission) {
priv->auth.call_id_wifi_shared_permission = nm_auth_manager_check_authorization (nm_auth_manager_get (),
priv->subject,
@@ -1227,13 +1229,13 @@ get_property (GObject *object, guint prop_id,
g_value_set_string (value, nm_dbus_track_obj_path_get (&priv->settings_connection));
break;
case PROP_ID:
- g_value_set_string (value, nm_connection_get_id (NM_CONNECTION (priv->settings_connection.obj)));
+ g_value_set_string (value, nm_settings_connection_get_id (priv->settings_connection.obj));
break;
case PROP_UUID:
- g_value_set_string (value, nm_connection_get_uuid (NM_CONNECTION (priv->settings_connection.obj)));
+ g_value_set_string (value, nm_settings_connection_get_uuid (priv->settings_connection.obj));
break;
case PROP_TYPE:
- g_value_set_string (value, nm_connection_get_connection_type (NM_CONNECTION (priv->settings_connection.obj)));
+ g_value_set_string (value, nm_settings_connection_get_connection_type (priv->settings_connection.obj));
break;
case PROP_SPECIFIC_OBJECT:
@@ -1304,16 +1306,16 @@ set_property (GObject *object, guint prop_id,
NMActiveConnection *self = (NMActiveConnection *) object;
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
const char *tmp;
- NMSettingsConnection *con;
+ NMSettingsConnection *sett_conn;
NMConnection *acon;
int i;
switch (prop_id) {
case PROP_INT_SETTINGS_CONNECTION:
/* construct-only */
- con = g_value_get_object (value);
- if (con)
- _set_settings_connection (self, con);
+ sett_conn = g_value_get_object (value);
+ if (sett_conn)
+ _set_settings_connection (self, sett_conn);
break;
case PROP_INT_APPLIED_CONNECTION:
/* construct-only */
@@ -1410,7 +1412,7 @@ constructed (GObject *object)
if ( !priv->applied_connection
&& priv->settings_connection.obj)
- priv->applied_connection = nm_simple_connection_new_clone (NM_CONNECTION (priv->settings_connection.obj));
+ priv->applied_connection = nm_simple_connection_new_clone (nm_settings_connection_get_connection (priv->settings_connection.obj));
_LOGD ("constructed (%s, version-id %llu, type %s)",
G_OBJECT_TYPE_NAME (self),
diff --git a/src/nm-checkpoint-manager.c b/src/nm-checkpoint-manager.c
index 7e8c8aea9f..0c2af831c3 100644
--- a/src/nm-checkpoint-manager.c
+++ b/src/nm-checkpoint-manager.c
@@ -265,8 +265,8 @@ nm_checkpoint_manager_lookup_by_path (NMCheckpointManager *self, const char *pat
g_return_val_if_fail (self, NULL);
- checkpoint = (NMCheckpoint *) nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (GET_MANAGER (self))),
- path);
+ checkpoint = nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (GET_MANAGER (self))),
+ path);
if ( !checkpoint
|| !NM_IS_CHECKPOINT (checkpoint)) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_INVALID_ARGUMENTS,
diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c
index a17f7eda6f..b0cf1f5117 100644
--- a/src/nm-checkpoint.c
+++ b/src/nm-checkpoint.c
@@ -159,7 +159,7 @@ find_settings_connection (NMCheckpoint *self,
{
NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (self);
NMActiveConnection *active;
- NMSettingsConnection *connection;
+ NMSettingsConnection *sett_conn;
const char *uuid, *ac_uuid;
const CList *tmp_clist;
@@ -167,14 +167,14 @@ find_settings_connection (NMCheckpoint *self,
*need_update = FALSE;
uuid = nm_connection_get_uuid (dev_checkpoint->settings_connection);
- connection = nm_settings_get_connection_by_uuid (nm_settings_get (), uuid);
+ sett_conn = nm_settings_get_connection_by_uuid (nm_settings_get (), uuid);
- if (!connection)
+ if (!sett_conn)
return NULL;
/* Now check if the connection changed, ... */
if (!nm_connection_compare (dev_checkpoint->settings_connection,
- NM_CONNECTION (connection),
+ nm_settings_connection_get_connection (sett_conn),
NM_SETTING_COMPARE_FLAG_EXACT)) {
_LOGT ("rollback: settings connection %s changed", uuid);
*need_update = TRUE;
@@ -193,7 +193,7 @@ find_settings_connection (NMCheckpoint *self,
if (!active) {
_LOGT ("rollback: connection %s is not active", uuid);
*need_activation = TRUE;
- return connection;
+ return sett_conn;
}
/* ... or if the connection was reactivated/reapplied */
@@ -202,7 +202,7 @@ find_settings_connection (NMCheckpoint *self,
*need_activation = TRUE;
}
- return connection;
+ return sett_conn;
}
GVariant *
@@ -337,8 +337,8 @@ activate:
dev_checkpoint->activation_reason,
&local_error)) {
_LOGW ("rollback: reactivation of connection %s/%s failed: %s",
- nm_connection_get_id ((NMConnection *) connection),
- nm_connection_get_uuid ((NMConnection *) connection),
+ nm_settings_connection_get_id (connection),
+ nm_settings_connection_get_uuid (connection),
local_error->message);
g_clear_error (&local_error);
result = NM_ROLLBACK_RESULT_ERR_FAILED;
@@ -436,12 +436,9 @@ device_checkpoint_create (NMDevice *device)
applied_connection = nm_act_request_get_applied_connection (act_request);
dev_checkpoint->applied_connection = nm_simple_connection_new_clone (applied_connection);
- dev_checkpoint->settings_connection =
- nm_simple_connection_new_clone (NM_CONNECTION (settings_connection));
- dev_checkpoint->ac_version_id =
- nm_active_connection_version_id_get (NM_ACTIVE_CONNECTION (act_request));
- dev_checkpoint->activation_reason =
- nm_active_connection_get_activation_reason (NM_ACTIVE_CONNECTION (act_request));
+ dev_checkpoint->settings_connection = nm_simple_connection_new_clone (nm_settings_connection_get_connection (settings_connection));
+ dev_checkpoint->ac_version_id = nm_active_connection_version_id_get (NM_ACTIVE_CONNECTION (act_request));
+ dev_checkpoint->activation_reason = nm_active_connection_get_activation_reason (NM_ACTIVE_CONNECTION (act_request));
}
return dev_checkpoint;
diff --git a/src/nm-dbus-manager.c b/src/nm-dbus-manager.c
index 7f1121f650..0a421aa9b6 100644
--- a/src/nm-dbus-manager.c
+++ b/src/nm-dbus-manager.c
@@ -1084,7 +1084,7 @@ _obj_unregister (NMDBusManager *self,
NULL);
}
-NMDBusObject *
+gpointer
nm_dbus_manager_lookup_object (NMDBusManager *self, const char *path)
{
NMDBusManagerPrivate *priv;
diff --git a/src/nm-dbus-manager.h b/src/nm-dbus-manager.h
index a07413168d..04c42bb0f6 100644
--- a/src/nm-dbus-manager.h
+++ b/src/nm-dbus-manager.h
@@ -61,7 +61,7 @@ gboolean nm_dbus_manager_is_stopping (NMDBusManager *self);
GDBusConnection *nm_dbus_manager_get_connection (NMDBusManager *self);
-NMDBusObject *nm_dbus_manager_lookup_object (NMDBusManager *self, const char *path);
+gpointer nm_dbus_manager_lookup_object (NMDBusManager *self, const char *path);
void _nm_dbus_manager_obj_export (NMDBusObject *obj);
void _nm_dbus_manager_obj_unexport (NMDBusObject *obj);
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 769afc700d..8ca87551c9 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -310,7 +310,8 @@ static void _emit_device_added_removed (NMManager *self,
static NMActiveConnection *_new_active_connection (NMManager *self,
gboolean is_vpn,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
+ NMConnection *incompl_conn,
NMConnection *applied,
const char *specific_object,
NMDevice *device,
@@ -331,7 +332,8 @@ static gboolean find_master (NMManager *self,
static void nm_manager_update_state (NMManager *manager);
-static void connection_changed (NMManager *self, NMConnection *connection);
+static void connection_changed (NMManager *self,
+ NMSettingsConnection *sett_conn);
static void device_sleep_cb (NMDevice *device,
GParamSpec *pspec,
NMManager *self);
@@ -353,7 +355,7 @@ static void active_connection_parent_active (NMActiveConnection *active,
NMManager *self);
static NMActiveConnection *active_connection_find (NMManager *self,
- NMSettingsConnection *settings_connection,
+ NMSettingsConnection *sett_conn,
const char *uuid,
NMActiveConnectionState max_state,
GPtrArray **out_all_matching);
@@ -947,7 +949,7 @@ nm_manager_get_active_connections (NMManager *manager)
static NMActiveConnection *
active_connection_find (NMManager *self,
- NMSettingsConnection *settings_connection,
+ NMSettingsConnection *sett_conn,
const char *uuid,
NMActiveConnectionState max_state /* candidates in state @max_state will be found */,
GPtrArray **out_all_matching)
@@ -957,16 +959,18 @@ active_connection_find (NMManager *self,
NMActiveConnection *best_ac = NULL;
GPtrArray *all = NULL;
- nm_assert (!settings_connection || NM_IS_SETTINGS_CONNECTION (settings_connection));
+ nm_assert (!sett_conn || NM_IS_SETTINGS_CONNECTION (sett_conn));
nm_assert (!out_all_matching || !*out_all_matching);
c_list_for_each_entry (ac, &priv->active_connections_lst_head, active_connections_lst) {
- NMSettingsConnection *con;
+ NMSettingsConnection *ac_conn;
- con = nm_active_connection_get_settings_connection (ac);
- if (settings_connection && con != settings_connection)
+ ac_conn = nm_active_connection_get_settings_connection (ac);
+ if ( sett_conn
+ && sett_conn != ac_conn)
continue;
- if (uuid && !nm_streq0 (uuid, nm_connection_get_uuid (NM_CONNECTION (con))))
+ if ( uuid
+ && !nm_streq0 (uuid, nm_settings_connection_get_uuid (ac_conn)))
continue;
if (nm_active_connection_get_state (ac) > max_state)
continue;
@@ -1005,21 +1009,22 @@ active_connection_find (NMManager *self,
static NMActiveConnection *
active_connection_find_by_connection (NMManager *self,
+ NMSettingsConnection *sett_conn,
NMConnection *connection,
NMActiveConnectionState max_state,
GPtrArray **out_all_matching)
{
- gboolean is_settings_connection;
-
nm_assert (NM_IS_MANAGER (self));
- nm_assert (NM_IS_CONNECTION (connection));
+ nm_assert (!sett_conn || NM_IS_SETTINGS_CONNECTION (sett_conn));
+ nm_assert (!connection || NM_IS_CONNECTION (connection));
+ nm_assert (sett_conn || connection);
+ nm_assert (!connection || !sett_conn || connection == nm_settings_connection_get_connection (sett_conn));
- is_settings_connection = NM_IS_SETTINGS_CONNECTION (connection);
/* Depending on whether connection is a settings connection,
* either lookup by object-identity of @connection, or compare the UUID */
return active_connection_find (self,
- is_settings_connection ? NM_SETTINGS_CONNECTION (connection) : NULL,
- is_settings_connection ? NULL : nm_connection_get_uuid (connection),
+ sett_conn,
+ sett_conn ? NULL : nm_connection_get_uuid (connection),
max_state,
out_all_matching);
}
@@ -1031,17 +1036,17 @@ typedef struct {
static gboolean
_get_activatable_connections_filter (NMSettings *settings,
- NMSettingsConnection *connection,
+ NMSettingsConnection *sett_conn,
gpointer user_data)
{
const GetActivatableConnectionsFilterData *d = user_data;
NMConnectionMultiConnect multi_connect;
- if (NM_FLAGS_HAS (nm_settings_connection_get_flags (connection),
+ if (NM_FLAGS_HAS (nm_settings_connection_get_flags (sett_conn),
NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE))
return FALSE;
- multi_connect = _nm_connection_get_multi_connect (NM_CONNECTION (connection));
+ multi_connect = _nm_connection_get_multi_connect (nm_settings_connection_get_connection (sett_conn));
if ( multi_connect == NM_CONNECTION_MULTI_CONNECT_MULTIPLE
|| ( multi_connect == NM_CONNECTION_MULTI_CONNECT_MANUAL_MULTIPLE
&& !d->for_auto_activation))
@@ -1050,7 +1055,7 @@ _get_activatable_connections_filter (NMSettings *settings,
/* the connection is activatable, if it has no active-connections that are in state
* activated, activating, or waiting to be activated. */
return !active_connection_find (d->self,
- connection,
+ sett_conn,
NULL,
NM_ACTIVE_CONNECTION_STATE_ACTIVATED,
NULL);
@@ -1081,8 +1086,8 @@ active_connection_get_by_path (NMManager *self, const char *path)
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
NMActiveConnection *ac;
- ac = (NMActiveConnection *) nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (self)),
- path);
+ ac = nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (self)),
+ path);
if ( !ac
|| !NM_IS_ACTIVE_CONNECTION (ac)
|| c_list_is_empty (&ac->active_connections_lst))
@@ -1218,8 +1223,8 @@ nm_manager_get_device_by_path (NMManager *self, const char *path)
g_return_val_if_fail (path, NULL);
- device = (NMDevice *) nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (self)),
- path);
+ device = nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (self)),
+ path);
if ( !device
|| !NM_IS_DEVICE (device)
|| c_list_is_empty (&device->devices_lst))
@@ -1735,7 +1740,9 @@ find_parent_device_for_connection (NMManager *self, NMConnection *connection, NM
return candidate;
if ( !first_compatible
- && nm_device_check_connection_compatible (candidate, NM_CONNECTION (parent_connection), NULL))
+ && nm_device_check_connection_compatible (candidate,
+ nm_settings_connection_get_connection (parent_connection),
+ NULL))
first_compatible = candidate;
}
@@ -1829,13 +1836,13 @@ const char *
nm_manager_iface_for_uuid (NMManager *self, const char *uuid)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
- NMSettingsConnection *connection;
+ NMSettingsConnection *sett_conn;
- connection = nm_settings_get_connection_by_uuid (priv->settings, uuid);
- if (!connection)
+ sett_conn = nm_settings_get_connection_by_uuid (priv->settings, uuid);
+ if (!sett_conn)
return NULL;
- return nm_connection_get_interface_name (NM_CONNECTION (connection));
+ return nm_connection_get_interface_name (nm_settings_connection_get_connection (sett_conn));
}
NMDevice *
@@ -1958,7 +1965,7 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
NULL, NULL,
nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
for (i = 0; connections[i]; i++) {
- NMConnection *candidate = NM_CONNECTION (connections[i]);
+ NMConnection *candidate = nm_settings_connection_get_connection (connections[i]);
NMSettingConnection *s_con;
if (!nm_device_check_connection_compatible (device, candidate, NULL))
@@ -2004,18 +2011,19 @@ retry_connections_for_parent_device (NMManager *self, NMDevice *device)
NULL, NULL,
nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
for (i = 0; connections[i]; i++) {
- NMConnection *candidate = NM_CONNECTION (connections[i]);
+ NMSettingsConnection *sett_conn = connections[i];
+ NMConnection *connection = nm_settings_connection_get_connection (sett_conn);
gs_free_error GError *error = NULL;
gs_free char *ifname = NULL;
NMDevice *parent;
- parent = find_parent_device_for_connection (self, candidate, NULL);
+ parent = find_parent_device_for_connection (self, connection, NULL);
if (parent == device) {
/* Only try to activate devices that don't already exist */
- ifname = nm_manager_get_connection_iface (self, candidate, &parent, &error);
+ ifname = nm_manager_get_connection_iface (self, connection, &parent, &error);
if (ifname) {
if (!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, ifname))
- connection_changed (self, candidate);
+ connection_changed (self, sett_conn);
}
}
}
@@ -2023,9 +2031,10 @@ retry_connections_for_parent_device (NMManager *self, NMDevice *device)
static void
connection_changed (NMManager *self,
- NMConnection *connection)
+ NMSettingsConnection *sett_conn)
{
NMDevice *device;
+ NMConnection *connection = nm_settings_connection_get_connection (sett_conn);
if (!nm_connection_is_virtual (connection))
return;
@@ -2042,20 +2051,20 @@ connection_changed (NMManager *self,
static void
connection_added_cb (NMSettings *settings,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
NMManager *self)
{
- connection_changed (self, connection);
+ connection_changed (self, sett_conn);
}
static void
connection_updated_cb (NMSettings *settings,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
gboolean by_user,
NMManager *self)
{
if (by_user)
- connection_changed (self, connection);
+ connection_changed (self, sett_conn);
}
/*****************************************************************************/
@@ -2402,7 +2411,7 @@ static gboolean
new_activation_allowed_for_connection (NMManager *self,
NMSettingsConnection *connection)
{
- if (NM_IN_SET (_nm_connection_get_multi_connect (NM_CONNECTION (connection)),
+ if (NM_IN_SET (_nm_connection_get_multi_connect (nm_settings_connection_get_connection (connection)),
NM_CONNECTION_MULTI_CONNECT_MANUAL_MULTIPLE,
NM_CONNECTION_MULTI_CONNECT_MULTIPLE))
return TRUE;
@@ -2428,12 +2437,12 @@ get_existing_connection (NMManager *self,
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
gs_unref_object NMConnection *connection = NULL;
- NMSettingsConnection *added = NULL;
+ NMSettingsConnection *added;
GError *error = NULL;
gs_free_error GError *gen_error = NULL;
NMDevice *master = NULL;
int ifindex = nm_device_get_ifindex (device);
- NMSettingsConnection *matched;
+ NMSettingsConnection *matched = NULL;
NMSettingsConnection *connection_checked = NULL;
gboolean assume_state_guess_assume = FALSE;
const char *assume_state_connection_uuid = NULL;
@@ -2500,25 +2509,24 @@ get_existing_connection (NMManager *self,
if ( assume_state_connection_uuid
&& (connection_checked = nm_settings_get_connection_by_uuid (priv->settings, assume_state_connection_uuid))
&& new_activation_allowed_for_connection (self, connection_checked)
- && nm_device_check_connection_compatible (device, NM_CONNECTION (connection_checked), NULL)) {
+ && nm_device_check_connection_compatible (device,
+ nm_settings_connection_get_connection (connection_checked),
+ NULL)) {
if (connection) {
- NMConnection *const connections[] = {
- NM_CONNECTION (connection_checked),
- NULL,
- };
-
- matched = NM_SETTINGS_CONNECTION (nm_utils_match_connection (connections,
- connection,
- TRUE,
- nm_device_has_carrier (device),
- nm_device_get_route_metric (device, AF_INET),
- nm_device_get_route_metric (device, AF_INET6),
- NULL, NULL));
+ NMConnection *con = nm_settings_connection_get_connection (connection_checked);
+
+ if (nm_utils_match_connection ((NMConnection *[]) { con, NULL },
+ connection,
+ TRUE,
+ nm_device_has_carrier (device),
+ nm_device_get_route_metric (device, AF_INET),
+ nm_device_get_route_metric (device, AF_INET6),
+ NULL, NULL))
+ matched = connection_checked;
} else
matched = connection_checked;
- } else
- matched = NULL;
+ }
if (!matched && only_by_uuid) {
_LOG2D (LOGD_DEVICE, device, "assume: cannot generate connection: %s",
@@ -2527,32 +2535,51 @@ get_existing_connection (NMManager *self,
}
if (!matched && assume_state_guess_assume) {
- gs_free NMSettingsConnection **connections = NULL;
+ gs_free NMSettingsConnection **sett_conns = NULL;
guint len, i, j;
/* the state file doesn't indicate a connection UUID to assume. Search the
* persistent connections for a matching candidate. */
- connections = nm_manager_get_activatable_connections (self, FALSE, FALSE, &len);
+ sett_conns = nm_manager_get_activatable_connections (self, FALSE, FALSE, &len);
if (len > 0) {
for (i = 0, j = 0; i < len; i++) {
- NMConnection *con = NM_CONNECTION (connections[i]);
+ NMSettingsConnection *sett_conn = sett_conns[i];
- if ( con != NM_CONNECTION (connection_checked)
- && nm_device_check_connection_compatible (device, con, NULL))
- connections[j++] = connections[i];
+ if ( sett_conn != connection_checked
+ && nm_device_check_connection_compatible (device,
+ nm_settings_connection_get_connection (sett_conn),
+ NULL))
+ sett_conns[j++] = sett_conn;
}
- connections[j] = NULL;
+ sett_conns[j] = NULL;
len = j;
- g_qsort_with_data (connections, len, sizeof (connections[0]),
- nm_settings_connection_cmp_timestamp_p_with_data, NULL);
-
- matched = NM_SETTINGS_CONNECTION (nm_utils_match_connection ((NMConnection *const*) connections,
- connection,
- FALSE,
- nm_device_has_carrier (device),
- nm_device_get_route_metric (device, AF_INET),
- nm_device_get_route_metric (device, AF_INET6),
- NULL, NULL));
+ if (len > 0) {
+ gs_free NMConnection **conns = NULL;
+ NMConnection *con;
+
+ g_qsort_with_data (sett_conns, len, sizeof (sett_conns[0]),
+ nm_settings_connection_cmp_timestamp_p_with_data, NULL);
+
+ conns = nm_settings_connections_array_to_connections (sett_conns, len);
+
+ con = nm_utils_match_connection (conns,
+ connection,
+ FALSE,
+ nm_device_has_carrier (device),
+ nm_device_get_route_metric (device, AF_INET),
+ nm_device_get_route_metric (device, AF_INET6),
+ NULL,
+ NULL);
+ if (con) {
+ for (i = 0; i < len; i++) {
+ if (conns[i] == con) {
+ matched = sett_conns[i];
+ break;
+ }
+ }
+ nm_assert (matched);
+ }
+ }
}
}
@@ -2581,7 +2608,7 @@ get_existing_connection (NMManager *self,
return NULL;
}
- nm_settings_connection_set_flags (NM_SETTINGS_CONNECTION (added),
+ nm_settings_connection_set_flags (added,
NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED |
NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE,
TRUE);
@@ -2593,7 +2620,7 @@ static gboolean
recheck_assume_connection (NMManager *self,
NMDevice *device)
{
- NMSettingsConnection *connection;
+ NMSettingsConnection *sett_conn;
gboolean was_unmanaged = FALSE;
gboolean generated = FALSE;
NMDeviceState state;
@@ -2615,9 +2642,9 @@ recheck_assume_connection (NMManager *self,
return FALSE;
}
- connection = get_existing_connection (self, device, &generated);
+ sett_conn = get_existing_connection (self, device, &generated);
/* log no reason. get_existing_connection() already does it. */
- if (!connection)
+ if (!sett_conn)
return FALSE;
nm_device_sys_iface_state_set (device,
@@ -2649,7 +2676,8 @@ recheck_assume_connection (NMManager *self,
subject = nm_auth_subject_new_internal ();
active = _new_active_connection (self,
FALSE,
- NM_CONNECTION (connection),
+ sett_conn,
+ NULL,
NULL,
NULL,
device,
@@ -2660,7 +2688,7 @@ recheck_assume_connection (NMManager *self,
if (!active) {
_LOGW (LOGD_DEVICE, "assume: assumed connection %s failed to activate: %s",
- nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)),
+ nm_dbus_object_get_path (NM_DBUS_OBJECT (sett_conn)),
error->message);
g_error_free (error);
@@ -2672,7 +2700,7 @@ recheck_assume_connection (NMManager *self,
if (generated) {
_LOG2D (LOGD_DEVICE, device, "assume: deleting generated connection after assuming failed");
- nm_settings_connection_delete (connection, NULL);
+ nm_settings_connection_delete (sett_conn, NULL);
} else {
if (nm_device_sys_iface_state_get (device) == NM_DEVICE_SYS_IFACE_STATE_ASSUME)
nm_device_sys_iface_state_set (device, NM_DEVICE_SYS_IFACE_STATE_EXTERNAL);
@@ -2682,7 +2710,14 @@ recheck_assume_connection (NMManager *self,
/* If the device is a slave or VLAN, find the master ActiveConnection */
master_ac = NULL;
- if (find_master (self, NM_CONNECTION (connection), device, NULL, NULL, &master_ac, NULL) && master_ac)
+ if ( find_master (self,
+ nm_settings_connection_get_connection (sett_conn),
+ device,
+ NULL,
+ NULL,
+ &master_ac,
+ NULL)
+ && master_ac)
nm_active_connection_set_master (active, master_ac);
active_connection_add (self, active);
@@ -3274,6 +3309,7 @@ nm_manager_get_devices (NMManager *manager)
static NMDevice *
nm_manager_get_best_device_for_connection (NMManager *self,
+ NMSettingsConnection *sett_conn,
NMConnection *connection,
gboolean for_user_request,
GHashTable *unavailable_devices,
@@ -3288,9 +3324,17 @@ nm_manager_get_best_device_for_connection (NMManager *self,
gs_unref_ptrarray GPtrArray *all_ac_arr = NULL;
gs_free_error GError *local_best = NULL;
+ nm_assert (!sett_conn || NM_IS_SETTINGS_CONNECTION (sett_conn));
+ nm_assert (!connection || NM_IS_CONNECTION (connection));
+ nm_assert (sett_conn || connection);
+ nm_assert (!connection || !sett_conn || connection == nm_settings_connection_get_connection (sett_conn));
+
+ if (!connection)
+ connection = nm_settings_connection_get_connection (sett_conn);
+
flags = for_user_request ? NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST : NM_DEVICE_CHECK_CON_AVAILABLE_NONE;
- ac = active_connection_find_by_connection (self, connection, NM_ACTIVE_CONNECTION_STATE_DEACTIVATING, &all_ac_arr);
+ ac = active_connection_find_by_connection (self, sett_conn, connection, NM_ACTIVE_CONNECTION_STATE_DEACTIVATING, &all_ac_arr);
if (ac) {
ac_device = nm_active_connection_get_device (ac);
@@ -3576,7 +3620,7 @@ find_master (NMManager *self,
NMSettingConnection *s_con;
const char *master;
NMDevice *master_device = NULL;
- NMSettingsConnection *master_connection = NULL;
+ NMSettingsConnection *master_connection;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@@ -3595,7 +3639,9 @@ find_master (NMManager *self,
}
master_connection = nm_device_get_settings_connection (master_device);
- if (master_connection && !is_compatible_with_slave (NM_CONNECTION (master_connection), connection)) {
+ if ( master_connection
+ && !is_compatible_with_slave (nm_settings_connection_get_connection (master_connection),
+ connection)) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_DEPENDENCY_FAILED,
"The active connection on %s is not compatible",
nm_device_get_iface (master_device));
@@ -3695,7 +3741,9 @@ ensure_master_active_connection (NMManager *self,
* be already activated on the device, eg returned from find_master().
*/
g_assert (!master_connection || master_connection == device_connection);
- if (device_connection && !is_compatible_with_slave (NM_CONNECTION (device_connection), connection)) {
+ if ( device_connection
+ && !is_compatible_with_slave (nm_settings_connection_get_connection (device_connection),
+ connection)) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_DEPENDENCY_FAILED,
"The active connection %s is not compatible",
nm_connection_get_id (connection));
@@ -3723,15 +3771,16 @@ ensure_master_active_connection (NMManager *self,
connections = nm_manager_get_activatable_connections (self, FALSE, TRUE, NULL);
for (i = 0; connections[i]; i++) {
NMSettingsConnection *candidate = connections[i];
+ NMConnection *cand_conn = nm_settings_connection_get_connection (candidate);
/* Ensure eg bond/team slave and the candidate master is a
* bond/team master
*/
- if (!is_compatible_with_slave (NM_CONNECTION (candidate), connection))
+ if (!is_compatible_with_slave (cand_conn, connection))
continue;
if (nm_device_check_connection_available (master_device,
- NM_CONNECTION (candidate),
+ cand_conn,
NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST,
NULL,
NULL)) {
@@ -3771,7 +3820,7 @@ ensure_master_active_connection (NMManager *self,
}
if (!nm_device_check_connection_available (candidate,
- NM_CONNECTION (master_connection),
+ nm_settings_connection_get_connection (master_connection),
NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST,
NULL,
NULL))
@@ -3813,18 +3862,18 @@ typedef struct {
/**
* find_slaves:
* @manager: #NMManager object
- * @connection: the master #NMSettingsConnection to find slave connections for
- * @device: the master #NMDevice for the @connection
+ * @sett_conn: the master #NMSettingsConnection to find slave connections for
+ * @device: the master #NMDevice for the @sett_conn
* @out_n_slaves: on return, the number of slaves found
*
- * Given an #NMSettingsConnection, attempts to find its slaves. If @connection is not
+ * Given an #NMSettingsConnection, attempts to find its slaves. If @sett_conn is not
* master, or has not any slaves, this will return %NULL.
*
- * Returns: an array of #SlaveConnectionInfo for given master @connection, or %NULL
+ * Returns: an array of #SlaveConnectionInfo for given master @sett_conn, or %NULL
**/
static SlaveConnectionInfo *
find_slaves (NMManager *manager,
- NMSettingsConnection *connection,
+ NMSettingsConnection *sett_conn,
NMDevice *device,
guint *out_n_slaves)
{
@@ -3839,7 +3888,7 @@ find_slaves (NMManager *manager,
nm_assert (out_n_slaves);
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (sett_conn));
g_return_val_if_fail (s_con, NULL);
devices = g_hash_table_new (nm_direct_hash, NULL);
@@ -3854,13 +3903,20 @@ find_slaves (NMManager *manager,
for (i = 0; i < n_all_connections; i++) {
NMSettingsConnection *master_connection = NULL;
NMDevice *master_device = NULL, *slave_device;
- NMConnection *candidate = NM_CONNECTION (all_connections[i]);
-
- find_master (manager, candidate, NULL, &master_connection, &master_device, NULL, NULL);
- if ( (master_connection && master_connection == connection)
+ NMSettingsConnection *candidate = all_connections[i];
+
+ find_master (manager,
+ nm_settings_connection_get_connection (candidate),
+ NULL,
+ &master_connection,
+ &master_device,
+ NULL,
+ NULL);
+ if ( (master_connection && master_connection == sett_conn)
|| (master_device && master_device == device)) {
slave_device = nm_manager_get_best_device_for_connection (manager,
candidate,
+ NULL,
FALSE,
devices,
NULL);
@@ -3872,7 +3928,7 @@ find_slaves (NMManager *manager,
}
nm_assert (n_slaves < n_all_connections);
- slaves[n_slaves].connection = NM_SETTINGS_CONNECTION (candidate),
+ slaves[n_slaves].connection = candidate,
slaves[n_slaves].device = slave_device,
n_slaves++;
@@ -3944,7 +4000,8 @@ autoconnect_slaves (NMManager *self,
{
GError *local_err = NULL;
- if (should_connect_slaves (NM_CONNECTION (master_connection), master_device)) {
+ if (should_connect_slaves (nm_settings_connection_get_connection (master_connection),
+ master_device)) {
gs_free SlaveConnectionInfo *slaves = NULL;
guint i, n_slaves = 0;
@@ -4085,7 +4142,7 @@ active_connection_parent_active (NMActiveConnection *active,
{
NMDevice *device = nm_active_connection_get_device (active);
GError *error = NULL;
- NMSettingsConnection *connection;
+ NMSettingsConnection *sett_conn;
NMDevice *parent;
g_signal_handlers_disconnect_by_func (active,
@@ -4101,10 +4158,13 @@ active_connection_parent_active (NMActiveConnection *active,
return;
}
- connection = nm_active_connection_get_settings_connection (active);
+ sett_conn = nm_active_connection_get_settings_connection (active);
parent = nm_active_connection_get_device (parent_ac);
- if (!nm_device_create_and_realize (device, (NMConnection *) connection, parent, &error)) {
+ if (!nm_device_create_and_realize (device,
+ nm_settings_connection_get_connection (sett_conn),
+ parent,
+ &error)) {
_LOGW (LOGD_CORE, "Could not realize device '%s': %s",
nm_device_get_iface (device), error->message);
nm_active_connection_set_state_fail (active,
@@ -4122,7 +4182,7 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
{
NMDevice *device, *master_device = NULL;
NMConnection *applied;
- NMSettingsConnection *connection;
+ NMSettingsConnection *sett_conn;
NMSettingsConnection *master_connection = NULL;
NMConnection *existing_connection = NULL;
NMActiveConnection *master_ac = NULL;
@@ -4139,8 +4199,8 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
device = nm_active_connection_get_device (active);
g_return_val_if_fail (device != NULL, FALSE);
- connection = nm_active_connection_get_settings_connection (active);
- nm_assert (connection);
+ sett_conn = nm_active_connection_get_settings_connection (active);
+ nm_assert (sett_conn);
applied = nm_active_connection_get_applied_connection (active);
@@ -4165,7 +4225,7 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
if (!nm_device_check_connection_available (device, applied, NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST, NULL, &local)) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_CONNECTION,
"Connection '%s' is not available on device %s because %s",
- nm_settings_connection_get_id (connection),
+ nm_settings_connection_get_id (sett_conn),
nm_device_get_iface (device),
local->message);
g_error_free (local);
@@ -4179,7 +4239,9 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
if (!nm_device_is_real (device)) {
NMDevice *parent;
- parent = find_parent_device_for_connection (self, (NMConnection *) connection, NULL);
+ parent = find_parent_device_for_connection (self,
+ nm_settings_connection_get_connection (sett_conn),
+ NULL);
if (parent && !nm_device_is_real (parent)) {
NMSettingsConnection *parent_con;
@@ -4191,7 +4253,11 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
return FALSE;
}
- parent_ac = nm_manager_activate_connection (self, parent_con, NULL, NULL, parent,
+ parent_ac = nm_manager_activate_connection (self,
+ parent_con,
+ NULL,
+ NULL,
+ parent,
subject,
NM_ACTIVATION_TYPE_MANAGED,
nm_active_connection_get_activation_reason (active),
@@ -4209,7 +4275,10 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
nm_active_connection_set_parent (active, parent_ac);
} else {
/* We can realize now; no need to wait for a parent device. */
- if (!nm_device_create_and_realize (device, (NMConnection *) connection, parent, error)) {
+ if (!nm_device_create_and_realize (device,
+ nm_settings_connection_get_connection (sett_conn),
+ parent,
+ error)) {
g_prefix_error (error, "%s failed to create resources: ", nm_device_get_iface (device));
return FALSE;
}
@@ -4217,11 +4286,15 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
}
/* Try to find the master connection/device if the connection has a dependency */
- if (!find_master (self, applied, device,
- &master_connection, &master_device, &master_ac,
+ if (!find_master (self,
+ applied,
+ device,
+ &master_connection,
+ &master_device,
+ &master_ac,
error)) {
g_prefix_error (error, "Can not find a master for %s: ",
- nm_settings_connection_get_id (connection));
+ nm_settings_connection_get_id (sett_conn));
return FALSE;
}
@@ -4231,21 +4304,23 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
if (master_connection || master_device) {
if (master_connection) {
_LOGD (LOGD_CORE, "Activation of '%s' requires master connection '%s'",
- nm_settings_connection_get_id (connection),
+ nm_settings_connection_get_id (sett_conn),
nm_settings_connection_get_id (master_connection));
}
if (master_device) {
_LOGD (LOGD_CORE, "Activation of '%s' requires master device '%s'",
- nm_settings_connection_get_id (connection),
+ nm_settings_connection_get_id (sett_conn),
nm_device_get_ip_iface (master_device));
}
/* Ensure eg bond slave and the candidate master is a bond master */
- if (master_connection && !is_compatible_with_slave (NM_CONNECTION (master_connection), applied)) {
+ if ( master_connection
+ && !is_compatible_with_slave (nm_settings_connection_get_connection (master_connection),
+ applied)) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_DEPENDENCY_FAILED,
"The master connection '%s' is not compatible with '%s'",
nm_settings_connection_get_id (master_connection),
- nm_settings_connection_get_id (connection));
+ nm_settings_connection_get_id (sett_conn));
return FALSE;
}
@@ -4264,7 +4339,7 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
nm_device_get_ip_iface (device));
} else {
g_prefix_error (error, "Master connection '%s' can't be activated: ",
- nm_settings_connection_get_id (connection));
+ nm_settings_connection_get_id (sett_conn));
}
return FALSE;
}
@@ -4281,15 +4356,15 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
nm_active_connection_set_master (active, master_ac);
_LOGD (LOGD_CORE, "Activation of '%s' depends on active connection %p %s",
- nm_settings_connection_get_id (connection),
+ nm_settings_connection_get_id (sett_conn),
master_ac,
nm_dbus_object_get_path (NM_DBUS_OBJECT (master_ac)) ?: "");
}
/* Check slaves for master connection and possibly activate them */
- autoconnect_slaves (self, connection, device, nm_active_connection_get_subject (active));
+ autoconnect_slaves (self, sett_conn, device, nm_active_connection_get_subject (active));
- multi_connect = _nm_connection_get_multi_connect (NM_CONNECTION (connection));
+ multi_connect = _nm_connection_get_multi_connect (nm_settings_connection_get_connection (sett_conn));
if ( multi_connect == NM_CONNECTION_MULTI_CONNECT_MULTIPLE
|| ( multi_connect == NM_CONNECTION_MULTI_CONNECT_MANUAL_MULTIPLE
&& NM_IN_SET (nm_active_connection_get_activation_reason (active),
@@ -4304,7 +4379,7 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
/* Disconnect the connection if already connected or queued for activation.
* The connection cannot be active multiple times (at the same time). */
- ac = active_connection_find (self, connection, NULL, NM_ACTIVE_CONNECTION_STATE_ACTIVATED,
+ ac = active_connection_find (self, sett_conn, NULL, NM_ACTIVE_CONNECTION_STATE_ACTIVATED,
&all_ac_arr);
if (ac) {
n_all = all_ac_arr ? all_ac_arr->len : ((guint) 1);
@@ -4376,7 +4451,8 @@ _internal_activate_generic (NMManager *self, NMActiveConnection *active, GError
static NMActiveConnection *
_new_active_connection (NMManager *self,
gboolean is_vpn,
- NMConnection *connection,
+ NMSettingsConnection *sett_conn,
+ NMConnection *incompl_conn,
NMConnection *applied,
const char *specific_object,
NMDevice *device,
@@ -4386,18 +4462,19 @@ _new_active_connection (NMManager *self,
GError **error)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
- NMSettingsConnection *settings_connection = NULL;
NMDevice *parent_device;
- g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
- g_return_val_if_fail (NM_IS_AUTH_SUBJECT (subject), NULL);
-
- nm_assert (is_vpn == _connection_is_vpn (connection));
+ nm_assert (!sett_conn || NM_IS_SETTINGS_CONNECTION (sett_conn));
+ nm_assert (!incompl_conn || NM_IS_CONNECTION (incompl_conn));
+ nm_assert ((!incompl_conn) ^ (!sett_conn));
+ nm_assert (NM_IS_AUTH_SUBJECT (subject));
+ nm_assert (is_vpn == _connection_is_vpn (sett_conn
+ ? nm_settings_connection_get_connection (sett_conn)
+ : incompl_conn));
nm_assert (is_vpn || NM_IS_DEVICE (device));
nm_assert (!nm_streq0 (specific_object, "/"));
-
- if (NM_IS_SETTINGS_CONNECTION (connection))
- settings_connection = (NMSettingsConnection *) connection;
+ nm_assert (!applied || NM_IS_CONNECTION (applied));
+ nm_assert (!is_vpn || !applied);
if (is_vpn) {
NMActiveConnection *parent;
@@ -4405,21 +4482,20 @@ _new_active_connection (NMManager *self,
/* FIXME: for VPN connections, we don't allow re-activating an
* already active connection. It's a bug, and should be fixed together
* when reworking VPN handling. */
- if (active_connection_find_by_connection (self, connection, NM_ACTIVE_CONNECTION_STATE_ACTIVATED, NULL)) {
+ if (active_connection_find_by_connection (self,
+ sett_conn,
+ incompl_conn,
+ NM_ACTIVE_CONNECTION_STATE_ACTIVATED,
+ NULL)) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_ALREADY_ACTIVE,
"Connection '%s' is already active",
- nm_connection_get_id (connection));
+ sett_conn ? nm_settings_connection_get_id (sett_conn) : nm_connection_get_id (incompl_conn));
return NULL;
}
- /* FIXME: apparently, activation here only works if @connection is
- * a settings-connection. Which is not the case during AddAndActivate.
- * Probably, AddAndActivate is broken for VPN. */
if (activation_type != NM_ACTIVATION_TYPE_MANAGED)
g_return_val_if_reached (NULL);
- g_return_val_if_fail (!settings_connection || NM_IS_SETTINGS_CONNECTION (settings_connection), NULL);
-
if (specific_object) {
/* Find the specific connection the client requested we use */
parent = active_connection_get_by_path (self, specific_object);
@@ -4450,14 +4526,14 @@ _new_active_connection (NMManager *self,
return NULL;
}
- return (NMActiveConnection *) nm_vpn_connection_new (settings_connection,
+ return (NMActiveConnection *) nm_vpn_connection_new (sett_conn,
parent_device,
nm_dbus_object_get_path (NM_DBUS_OBJECT (parent)),
activation_reason,
subject);
}
- return (NMActiveConnection *) nm_act_request_new (settings_connection,
+ return (NMActiveConnection *) nm_act_request_new (sett_conn,
applied,
specific_object,
subject,
@@ -4518,17 +4594,17 @@ fail:
/**
* nm_manager_activate_connection():
* @self: the #NMManager
- * @connection: the #NMSettingsConnection to activate on @device
+ * @sett_conn: the #NMSettingsConnection to activate on @device
* @applied: (allow-none): the applied connection to activate on @device
* @specific_object: the specific object path, if any, for the activation
- * @device: the #NMDevice to activate @connection on. Can be %NULL for VPNs.
+ * @device: the #NMDevice to activate @sett_conn on. Can be %NULL for VPNs.
* @subject: the subject which requested activation
* @activation_type: whether to assume the connection. That is, take over gracefully,
* non-destructible.
* @activation_reason: the reason for activation
* @error: return location for an error
*
- * Begins a new internally-initiated activation of @connection on @device.
+ * Begins a new internally-initiated activation of @sett_conn on @device.
* @subject should be the subject of the activation that triggered this
* one, or if this is an autoconnect request, a new internal subject.
* The returned #NMActiveConnection is owned by the Manager and should be
@@ -4536,11 +4612,11 @@ fail:
* is supplied, it shall not be modified by the caller afterwards.
*
* Returns: (transfer none): the new #NMActiveConnection that tracks
- * activation of @connection on @device
+ * activation of @sett_conn on @device
*/
NMActiveConnection *
nm_manager_activate_connection (NMManager *self,
- NMSettingsConnection *connection,
+ NMSettingsConnection *sett_conn,
NMConnection *applied,
const char *specific_object,
NMDevice *device,
@@ -4555,15 +4631,15 @@ nm_manager_activate_connection (NMManager *self,
gboolean is_vpn;
g_return_val_if_fail (NM_IS_MANAGER (self), NULL);
- g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), NULL);
- is_vpn = _connection_is_vpn (NM_CONNECTION (connection));
+ g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (sett_conn), NULL);
+ is_vpn = _connection_is_vpn (nm_settings_connection_get_connection (sett_conn));
g_return_val_if_fail (is_vpn || NM_IS_DEVICE (device), NULL);
g_return_val_if_fail (!error || !*error, NULL);
nm_assert (!nm_streq0 (specific_object, "/"));
priv = NM_MANAGER_GET_PRIVATE (self);
- if (!nm_auth_is_subject_in_acl_set_error (NM_CONNECTION (connection),
+ if (!nm_auth_is_subject_in_acl_set_error (nm_settings_connection_get_connection (sett_conn),
subject,
NM_MANAGER_ERROR,
NM_MANAGER_ERROR_PERMISSION_DENIED,
@@ -4581,7 +4657,7 @@ nm_manager_activate_connection (NMManager *self,
continue;
active = async_op_data->ac_auth.active;
- if ( connection == nm_active_connection_get_settings_connection (active)
+ if ( sett_conn == nm_active_connection_get_settings_connection (active)
&& nm_streq0 (nm_active_connection_get_specific_object (active), specific_object)
&& (!device || nm_active_connection_get_device (active) == device)
&& nm_auth_subject_is_internal (nm_active_connection_get_subject (active))
@@ -4592,7 +4668,8 @@ nm_manager_activate_connection (NMManager *self,
active = _new_active_connection (self,
is_vpn,
- NM_CONNECTION (connection),
+ sett_conn,
+ NULL,
applied,
specific_object,
device,
@@ -4615,7 +4692,9 @@ nm_manager_activate_connection (NMManager *self,
* validate_activation_request:
* @self: the #NMManager
* @context: the D-Bus context of the requestor
- * @connection: the partial or complete #NMConnection to be activated
+ * @sett_conn: the #NMSettingsConnection to be activated, or %NULL if there
+ * is only a partial activation.
+ * @connection: the partial #NMConnection to be activated (if @sett_conn is unspecified)
* @device_path: the object path of the device to be activated, or NULL
* @out_device: on successful reutrn, the #NMDevice to be activated with @connection
* The caller may pass in a device which shortcuts the lookup by path.
@@ -4634,6 +4713,7 @@ nm_manager_activate_connection (NMManager *self,
static NMAuthSubject *
validate_activation_request (NMManager *self,
GDBusMethodInvocation *context,
+ NMSettingsConnection *sett_conn,
NMConnection *connection,
const char *device_path,
NMDevice **out_device,
@@ -4644,10 +4724,16 @@ validate_activation_request (NMManager *self,
gboolean is_vpn = FALSE;
gs_unref_object NMAuthSubject *subject = NULL;
- nm_assert (NM_IS_CONNECTION (connection));
+ nm_assert (!sett_conn || NM_IS_SETTINGS_CONNECTION (sett_conn));
+ nm_assert (!connection || NM_IS_CONNECTION (connection));
+ nm_assert (sett_conn || connection);
+ nm_assert (!connection || !sett_conn || connection == nm_settings_connection_get_connection (sett_conn));
nm_assert (out_device);
nm_assert (out_is_vpn);
+ if (!connection)
+ connection = nm_settings_connection_get_connection (sett_conn);
+
/* Validate the caller */
subject = nm_auth_subject_new_unix_process_from_context (context);
if (!subject) {
@@ -4685,7 +4771,7 @@ validate_activation_request (NMManager *self,
} else if (!is_vpn) {
gs_free_error GError *local = NULL;
- device = nm_manager_get_best_device_for_connection (self, connection, TRUE, NULL, &local);
+ device = nm_manager_get_best_device_for_connection (self, sett_conn, connection, TRUE, NULL, &local);
if (!device) {
gs_free char *iface = NULL;
@@ -4782,7 +4868,7 @@ impl_manager_activate_connection (NMDBusObject *obj,
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
gs_unref_object NMActiveConnection *active = NULL;
gs_unref_object NMAuthSubject *subject = NULL;
- NMSettingsConnection *connection = NULL;
+ NMSettingsConnection *sett_conn = NULL;
NMDevice *device = NULL;
gboolean is_vpn = FALSE;
GError *error = NULL;
@@ -4802,8 +4888,8 @@ impl_manager_activate_connection (NMDBusObject *obj,
* (since this is an explicit request, not an auto-activation request).
*/
if (connection_path) {
- connection = nm_settings_get_connection_by_path (priv->settings, connection_path);
- if (!connection) {
+ sett_conn = nm_settings_get_connection_by_path (priv->settings, connection_path);
+ if (!sett_conn) {
error = g_error_new_literal (NM_MANAGER_ERROR,
NM_MANAGER_ERROR_UNKNOWN_CONNECTION,
"Connection could not be found.");
@@ -4823,14 +4909,15 @@ impl_manager_activate_connection (NMDBusObject *obj,
goto error;
}
- connection = nm_device_get_best_connection (device, specific_object_path, &error);
- if (!connection)
+ sett_conn = nm_device_get_best_connection (device, specific_object_path, &error);
+ if (!sett_conn)
goto error;
}
subject = validate_activation_request (self,
invocation,
- NM_CONNECTION (connection),
+ sett_conn,
+ NULL,
device_path,
&device,
&is_vpn,
@@ -4840,7 +4927,8 @@ impl_manager_activate_connection (NMDBusObject *obj,
active = _new_active_connection (self,
is_vpn,
- NM_CONNECTION (connection),
+ sett_conn,
+ NULL,
NULL,
specific_object_path,
device,
@@ -4864,8 +4952,8 @@ impl_manager_activate_connection (NMDBusObject *obj,
return;
error:
- if (connection) {
- nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ACTIVATE, connection, FALSE, NULL,
+ if (sett_conn) {
+ nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ACTIVATE, sett_conn, FALSE, NULL,
subject, error->message);
}
g_dbus_method_invocation_take_error (invocation, error);
@@ -4980,7 +5068,7 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj,
{
NMManager *self = NM_MANAGER (obj);
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
- gs_unref_object NMConnection *connection = NULL;
+ gs_unref_object NMConnection *incompl_conn = NULL;
NMActiveConnection *active = NULL;
gs_unref_object NMAuthSubject *subject = NULL;
GError *error = NULL;
@@ -4989,6 +5077,7 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj,
gs_unref_variant GVariant *settings = NULL;
const char *device_path;
const char *specific_object_path;
+ gs_free NMConnection **conns = NULL;
g_variant_get (parameters, "(@a{sa{sv}}&o&o)", &settings, &device_path, &specific_object_path);
@@ -5002,13 +5091,14 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj,
* specific data being in the connection till then (especially in
* validate_activation_request()).
*/
- connection = nm_simple_connection_new ();
+ incompl_conn = nm_simple_connection_new ();
if (settings && g_variant_n_children (settings))
- _nm_connection_replace_settings (connection, settings, NM_SETTING_PARSE_FLAGS_STRICT, NULL);
+ _nm_connection_replace_settings (incompl_conn, settings, NM_SETTING_PARSE_FLAGS_STRICT, NULL);
subject = validate_activation_request (self,
invocation,
- connection,
+ NULL,
+ incompl_conn,
device_path,
&device,
&is_vpn,
@@ -5018,7 +5108,7 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj,
if (is_vpn) {
/* Try to fill the VPN's connection setting and name at least */
- if (!nm_connection_get_setting_vpn (connection)) {
+ if (!nm_connection_get_setting_vpn (incompl_conn)) {
error = g_error_new_literal (NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_SETTING,
"VPN connections require a 'vpn' setting");
@@ -5026,27 +5116,31 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj,
goto error;
}
+ conns = nm_settings_connections_array_to_connections (nm_settings_get_connections (priv->settings, NULL), -1);
+
nm_utils_complete_generic (priv->platform,
- connection,
+ incompl_conn,
NM_SETTING_VPN_SETTING_NAME,
- (NMConnection *const*) nm_settings_get_connections (priv->settings, NULL),
+ conns,
NULL,
_("VPN connection"),
NULL,
FALSE); /* No IPv6 by default for now */
} else {
+ conns = nm_settings_connections_array_to_connections (nm_settings_get_connections (priv->settings, NULL), -1);
/* Let each device subclass complete the connection */
if (!nm_device_complete_connection (device,
- connection,
+ incompl_conn,
specific_object_path,
- (NMConnection *const*) nm_settings_get_connections (priv->settings, NULL),
+ conns,
&error))
goto error;
}
active = _new_active_connection (self,
is_vpn,
- connection,
+ NULL,
+ incompl_conn,
NULL,
specific_object_path,
device,
@@ -5057,15 +5151,16 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj,
if (!active)
goto error;
- nm_active_connection_authorize (active, connection,
+ nm_active_connection_authorize (active,
+ incompl_conn,
_async_op_complete_ac_auth_cb,
_async_op_data_new_ac_auth_add_and_activate (self,
active,
invocation,
- connection));
+ incompl_conn));
/* we passed the pointers on to _async_op_data_new_ac_auth_add_and_activate() */
- g_steal_pointer (&connection);
+ g_steal_pointer (&incompl_conn);
g_steal_pointer (&active);
return;
@@ -5182,7 +5277,7 @@ impl_manager_deactivate_connection (NMDBusObject *obj,
NMManager *self = NM_MANAGER (obj);
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
NMActiveConnection *ac;
- NMSettingsConnection *connection = NULL;
+ NMSettingsConnection *sett_conn = NULL;
GError *error = NULL;
NMAuthSubject *subject = NULL;
NMAuthChain *chain;
@@ -5193,9 +5288,9 @@ impl_manager_deactivate_connection (NMDBusObject *obj,
/* Find the connection by its object path */
ac = active_connection_get_by_path (self, active_path);
if (ac)
- connection = nm_active_connection_get_settings_connection (ac);
+ sett_conn = nm_active_connection_get_settings_connection (ac);
- if (!connection) {
+ if (!sett_conn) {
error = g_error_new_literal (NM_MANAGER_ERROR,
NM_MANAGER_ERROR_CONNECTION_NOT_ACTIVE,
"The connection was not active.");
@@ -5211,7 +5306,7 @@ impl_manager_deactivate_connection (NMDBusObject *obj,
goto done;
}
- if (!nm_auth_is_subject_in_acl_set_error (NM_CONNECTION (connection),
+ if (!nm_auth_is_subject_in_acl_set_error (nm_settings_connection_get_connection (sett_conn),
subject,
NM_MANAGER_ERROR,
NM_MANAGER_ERROR_PERMISSION_DENIED,
@@ -5233,8 +5328,9 @@ impl_manager_deactivate_connection (NMDBusObject *obj,
done:
if (error) {
- if (connection) {
- nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DEACTIVATE, connection, FALSE, NULL,
+ if (sett_conn) {
+ nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DEACTIVATE,
+ sett_conn, FALSE, NULL,
subject, error->message);
}
g_dbus_method_invocation_take_error (invocation, error);
@@ -5990,7 +6086,6 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device)
int ifindex;
gboolean managed;
NMConfigDeviceStateManagedType managed_type;
- NMConnection *settings_connection;
const char *uuid = NULL;
const char *perm_hw_addr_fake = NULL;
gboolean perm_hw_addr_is_fake;
@@ -6011,9 +6106,11 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device)
managed = nm_device_get_managed (device, FALSE);
if (managed) {
- settings_connection = NM_CONNECTION (nm_device_get_settings_connection (device));
- if (settings_connection)
- uuid = nm_connection_get_uuid (settings_connection);
+ NMSettingsConnection *sett_conn;
+
+ sett_conn = nm_device_get_settings_connection (device);
+ if (sett_conn)
+ uuid = nm_settings_connection_get_uuid (sett_conn);
managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_MANAGED;
} else if (nm_device_get_unmanaged_flags (device, NM_UNMANAGED_USER_EXPLICIT))
managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNMANAGED;
@@ -6131,7 +6228,7 @@ nm_manager_start (NMManager *self, GError **error)
NULL, NULL,
nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
for (i = 0; connections[i]; i++)
- connection_changed (self, NM_CONNECTION (connections[i]));
+ connection_changed (self, connections[i]);
nm_clear_g_source (&priv->devices_inited_id);
priv->devices_inited_id = g_idle_add_full (G_PRIORITY_LOW + 10, devices_inited_cb, self, NULL);
diff --git a/src/nm-policy.c b/src/nm-policy.c
index 0dc4d80e22..7f8c665c30 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -1242,23 +1242,26 @@ auto_activate_device (NMPolicy *self,
/* Find the first connection that should be auto-activated */
best_connection = NULL;
for (i = 0; i < len; i++) {
- NMSettingsConnection *candidate = NM_SETTINGS_CONNECTION (connections[i]);
+ NMSettingsConnection *candidate = connections[i];
+ NMConnection *cand_conn;
NMSettingConnection *s_con;
const char *permission;
if (nm_settings_connection_autoconnect_is_blocked (candidate))
continue;
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (candidate));
+ cand_conn = nm_settings_connection_get_connection (candidate);
+
+ s_con = nm_connection_get_setting_connection (cand_conn);
if (!nm_setting_connection_get_autoconnect (s_con))
continue;
- permission = nm_utils_get_shared_wifi_permission (NM_CONNECTION (candidate));
+ permission = nm_utils_get_shared_wifi_permission (cand_conn);
if ( permission
&& !nm_settings_connection_check_permission (candidate, permission))
continue;
- if (nm_device_can_auto_connect (device, (NMConnection *) candidate, &specific_object)) {
+ if (nm_device_can_auto_connect (device, candidate, &specific_object)) {
best_connection = candidate;
break;
}
@@ -1441,34 +1444,36 @@ reset_autoconnect_all (NMPolicy *self,
connections = nm_settings_get_connections (priv->settings, NULL);
for (i = 0; connections[i]; i++) {
- NMSettingsConnection *connection = connections[i];
+ NMSettingsConnection *sett_conn = connections[i];
if ( device
- && !nm_device_check_connection_compatible (device, NM_CONNECTION (connection), NULL))
+ && !nm_device_check_connection_compatible (device,
+ nm_settings_connection_get_connection (sett_conn),
+ NULL))
continue;
if (only_no_secrets) {
/* we only reset the no-secrets blocked flag. */
- if (nm_settings_connection_autoconnect_blocked_reason_set (connection,
+ if (nm_settings_connection_autoconnect_blocked_reason_set (sett_conn,
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS,
FALSE)) {
/* maybe the connection is still blocked afterwards for other reasons
* and in the larger picture nothing changed. But it's too complicated
* to find out exactly. Just assume, something changed to be sure. */
- if (!nm_settings_connection_autoconnect_is_blocked (connection))
+ if (!nm_settings_connection_autoconnect_is_blocked (sett_conn))
changed = TRUE;
}
} else {
/* we reset the tries-count and any blocked-reason */
- if (nm_settings_connection_autoconnect_retries_get (connection) == 0)
+ if (nm_settings_connection_autoconnect_retries_get (sett_conn) == 0)
changed = TRUE;
- nm_settings_connection_autoconnect_retries_reset (connection);
+ nm_settings_connection_autoconnect_retries_reset (sett_conn);
- if (nm_settings_connection_autoconnect_blocked_reason_set (connection,
+ if (nm_settings_connection_autoconnect_blocked_reason_set (sett_conn,
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL
& ~NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST,
FALSE)) {
- if (!nm_settings_connection_autoconnect_is_blocked (connection))
+ if (!nm_settings_connection_autoconnect_is_blocked (sett_conn))
changed = TRUE;
}
}
@@ -1589,7 +1594,9 @@ static void
activate_slave_connections (NMPolicy *self, NMDevice *device)
{
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
- const char *master_device, *master_uuid_settings = NULL, *master_uuid_applied = NULL;
+ const char *master_device;
+ const char *master_uuid_settings = NULL;
+ const char *master_uuid_applied = NULL;
guint i;
NMActRequest *req;
gboolean internal_activation = FALSE;
@@ -1601,16 +1608,18 @@ activate_slave_connections (NMPolicy *self, NMDevice *device)
req = nm_device_get_act_request (device);
if (req) {
- NMConnection *con;
+ NMConnection *connection;
+ NMSettingsConnection *sett_conn;
NMAuthSubject *subject;
- con = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (req));
- if (con)
- master_uuid_applied = nm_connection_get_uuid (con);
- con = NM_CONNECTION (nm_active_connection_get_settings_connection (NM_ACTIVE_CONNECTION (req)));
- if (con) {
- master_uuid_settings = nm_connection_get_uuid (con);
- if (!g_strcmp0 (master_uuid_settings, master_uuid_applied))
+ connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (req));
+ if (connection)
+ master_uuid_applied = nm_connection_get_uuid (connection);
+
+ sett_conn = nm_active_connection_get_settings_connection (NM_ACTIVE_CONNECTION (req));
+ if (sett_conn) {
+ master_uuid_settings = nm_settings_connection_get_uuid (sett_conn);
+ if (nm_streq0 (master_uuid_settings, master_uuid_applied))
master_uuid_settings = NULL;
}
@@ -1621,11 +1630,11 @@ activate_slave_connections (NMPolicy *self, NMDevice *device)
changed = FALSE;
connections = nm_settings_get_connections (priv->settings, NULL);
for (i = 0; connections[i]; i++) {
- NMSettingsConnection *connection = connections[i];
+ NMSettingsConnection *sett_conn = connections[i];
NMSettingConnection *s_slave_con;
const char *slave_master;
- s_slave_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
+ s_slave_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (sett_conn));
slave_master = nm_setting_connection_get_master (s_slave_con);
if (!slave_master)
continue;
@@ -1635,14 +1644,14 @@ activate_slave_connections (NMPolicy *self, NMDevice *device)
continue;
if (!internal_activation) {
- if (nm_settings_connection_autoconnect_retries_get (connection) == 0)
+ if (nm_settings_connection_autoconnect_retries_get (sett_conn) == 0)
changed = TRUE;
- nm_settings_connection_autoconnect_retries_reset (connection);
+ nm_settings_connection_autoconnect_retries_reset (sett_conn);
}
- if (nm_settings_connection_autoconnect_blocked_reason_set (connection,
+ if (nm_settings_connection_autoconnect_blocked_reason_set (sett_conn,
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED,
FALSE)) {
- if (!nm_settings_connection_autoconnect_is_blocked (connection))
+ if (!nm_settings_connection_autoconnect_is_blocked (sett_conn))
changed = TRUE;
}
}
@@ -1658,7 +1667,6 @@ activate_secondary_connections (NMPolicy *self,
{
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
NMSettingConnection *s_con;
- NMSettingsConnection *settings_con;
NMActiveConnection *ac;
PendingSecondaryData *secondary_data;
GSList *secondary_ac_list = NULL;
@@ -1667,22 +1675,25 @@ activate_secondary_connections (NMPolicy *self,
gboolean success = TRUE;
s_con = nm_connection_get_setting_connection (connection);
- g_assert (s_con);
+ nm_assert (s_con);
for (i = 0; i < nm_setting_connection_get_num_secondaries (s_con); i++) {
+ NMSettingsConnection *sett_conn;
const char *sec_uuid = nm_setting_connection_get_secondary (s_con, i);
NMActRequest *req;
- settings_con = nm_settings_get_connection_by_uuid (priv->settings, sec_uuid);
- if (!settings_con) {
+ sett_conn = nm_settings_get_connection_by_uuid (priv->settings, sec_uuid);
+ if (!sett_conn) {
_LOGW (LOGD_DEVICE, "secondary connection '%s' auto-activation failed: The connection doesn't exist.",
sec_uuid);
success = FALSE;
break;
}
- if (!nm_connection_is_type (NM_CONNECTION (settings_con), NM_SETTING_VPN_SETTING_NAME)) {
+
+ if (!nm_connection_is_type (nm_settings_connection_get_connection (sett_conn),
+ NM_SETTING_VPN_SETTING_NAME)) {
_LOGW (LOGD_DEVICE, "secondary connection '%s (%s)' auto-activation failed: The connection is not a VPN.",
- nm_settings_connection_get_id (settings_con), sec_uuid);
+ nm_settings_connection_get_id (sett_conn), sec_uuid);
success = FALSE;
break;
}
@@ -1691,10 +1702,10 @@ activate_secondary_connections (NMPolicy *self,
g_assert (req);
_LOGD (LOGD_DEVICE, "activating secondary connection '%s (%s)' for base connection '%s (%s)'",
- nm_settings_connection_get_id (settings_con), sec_uuid,
+ nm_settings_connection_get_id (sett_conn), sec_uuid,
nm_connection_get_id (connection), nm_connection_get_uuid (connection));
ac = nm_manager_activate_connection (priv->manager,
- settings_con,
+ sett_conn,
NULL,
nm_dbus_object_get_path (NM_DBUS_OBJECT (req)),
device,
@@ -1706,7 +1717,7 @@ activate_secondary_connections (NMPolicy *self,
secondary_ac_list = g_slist_append (secondary_ac_list, g_object_ref (ac));
else {
_LOGW (LOGD_DEVICE, "secondary connection '%s (%s)' auto-activation failed: (%d) %s",
- nm_settings_connection_get_id (settings_con), sec_uuid,
+ nm_settings_connection_get_id (sett_conn), sec_uuid,
error->code,
error->message);
g_clear_error (&error);
@@ -1734,7 +1745,7 @@ device_state_changed (NMDevice *device,
NMPolicyPrivate *priv = user_data;
NMPolicy *self = _PRIV_TO_SELF (priv);
NMActiveConnection *ac;
- NMSettingsConnection *connection = nm_device_get_settings_connection (device);
+ NMSettingsConnection *sett_conn = nm_device_get_settings_connection (device);
NMIP4Config *ip4_config;
NMIP6Config *ip6_config;
NMSettingConnection *s_con = NULL;
@@ -1752,8 +1763,8 @@ device_state_changed (NMDevice *device,
/* Block autoconnect of the just-failed connection for situations
* where a retry attempt would just fail again.
*/
- if (connection) {
- nm_settings_connection_autoconnect_blocked_reason_set (connection,
+ if (sett_conn) {
+ nm_settings_connection_autoconnect_blocked_reason_set (sett_conn,
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED,
TRUE);
}
@@ -1767,7 +1778,7 @@ device_state_changed (NMDevice *device,
/* Mark the connection invalid if it failed during activation so that
* it doesn't get automatically chosen over and over and over again.
*/
- if ( connection
+ if ( sett_conn
&& old_state >= NM_DEVICE_STATE_PREPARE
&& old_state <= NM_DEVICE_STATE_ACTIVATED) {
gboolean block_no_secrets = FALSE;
@@ -1788,7 +1799,7 @@ device_state_changed (NMDevice *device,
* That can happen when nm_settings_connection_get_secrets() fails early without actually
* consulting any agents.
*/
- con_v = nm_settings_connection_get_last_secret_agent_version_id (connection);
+ con_v = nm_settings_connection_get_last_secret_agent_version_id (sett_conn);
if ( con_v == 0
|| con_v == nm_agent_manager_get_agent_version_id (priv->agent_mgr))
block_no_secrets = TRUE;
@@ -1796,33 +1807,35 @@ device_state_changed (NMDevice *device,
if (block_no_secrets) {
_LOGD (LOGD_DEVICE, "connection '%s' now blocked from autoconnect due to no secrets",
- nm_settings_connection_get_id (connection));
- nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS, TRUE);
+ nm_settings_connection_get_id (sett_conn));
+ nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS, TRUE);
} else {
- tries = nm_settings_connection_autoconnect_retries_get (connection);
+ tries = nm_settings_connection_autoconnect_retries_get (sett_conn);
if (tries > 0) {
_LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left",
- nm_settings_connection_get_id (connection), tries - 1);
- _connection_autoconnect_retries_set (self, connection, tries - 1);
+ nm_settings_connection_get_id (sett_conn), tries - 1);
+ _connection_autoconnect_retries_set (self, sett_conn, tries - 1);
} else if (tries != 0) {
_LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; infinite tries left",
- nm_settings_connection_get_id (connection));
+ nm_settings_connection_get_id (sett_conn));
}
}
- nm_connection_clear_secrets (NM_CONNECTION (connection));
+ /* 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));
}
break;
case NM_DEVICE_STATE_ACTIVATED:
- if (connection) {
+ if (sett_conn) {
/* Reset auto retries back to default since connection was successful */
- nm_settings_connection_autoconnect_retries_reset (connection);
+ nm_settings_connection_autoconnect_retries_reset (sett_conn);
/* And clear secrets so they will always be requested from the
* settings service when the next connection is made.
*/
- nm_connection_clear_secrets (NM_CONNECTION (connection));
+ /* 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 */
@@ -1846,7 +1859,7 @@ device_state_changed (NMDevice *device,
update_routing_and_dns (self, FALSE);
break;
case NM_DEVICE_STATE_DEACTIVATING:
- if (connection) {
+ if (sett_conn) {
NMSettingsAutoconnectBlockedReason blocked_reason = NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE;
switch (nm_device_state_reason_check (reason)) {
@@ -1861,10 +1874,10 @@ device_state_changed (NMDevice *device,
}
if (blocked_reason != NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE) {
_LOGD (LOGD_DEVICE, "blocking autoconnect of connection '%s': %s",
- nm_settings_connection_get_id (connection),
+ nm_settings_connection_get_id (sett_conn),
NM_UTILS_LOOKUP_STR (nm_device_state_reason_to_str,
nm_device_state_reason_check (reason)));
- nm_settings_connection_autoconnect_blocked_reason_set (connection, blocked_reason, TRUE);
+ nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, blocked_reason, TRUE);
}
}
ip6_remove_device_prefix_delegations (self, device);
@@ -1900,20 +1913,25 @@ device_state_changed (NMDevice *device,
break;
case NM_DEVICE_STATE_IP_CONFIG:
/* We must have secrets if we got here. */
- if (connection)
- nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL, FALSE);
+ if (sett_conn)
+ nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL, FALSE);
break;
case NM_DEVICE_STATE_SECONDARIES:
- if (connection)
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
- if (s_con && nm_setting_connection_get_num_secondaries (s_con) > 0) {
+ if (sett_conn)
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (sett_conn));
+ if ( s_con
+ && nm_setting_connection_get_num_secondaries (s_con) > 0) {
/* Make routes and DNS up-to-date before activating dependent connections */
update_routing_and_dns (self, FALSE);
/* Activate secondary (VPN) connections */
- if (!activate_secondary_connections (self, NM_CONNECTION (connection), device))
- nm_device_queue_state (device, NM_DEVICE_STATE_FAILED,
+ if (!activate_secondary_connections (self,
+ nm_settings_connection_get_connection (sett_conn),
+ device)) {
+ nm_device_queue_state (device,
+ NM_DEVICE_STATE_FAILED,
NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED);
+ }
} else
nm_device_queue_state (device, NM_DEVICE_STATE_ACTIVATED,
NM_DEVICE_STATE_REASON_NONE);
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index c09f680400..1b2edc8316 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -49,7 +49,26 @@
/*****************************************************************************/
-static void nm_settings_connection_connection_interface_init (NMConnectionInterface *iface);
+NMConnection **
+nm_settings_connections_array_to_connections (NMSettingsConnection *const*connections,
+ gssize n_connections)
+{
+ NMConnection **arr;
+ gssize i;
+
+ if (n_connections < 0)
+ n_connections = NM_PTRARRAY_LEN (connections);
+ if (n_connections == 0)
+ return NULL;
+
+ arr = g_new (NMConnection *, n_connections + 1);
+ for (i = 0; i < n_connections; i++)
+ arr[i] = nm_settings_connection_get_connection (connections[i]);
+ arr[i] = NULL;
+ return arr;
+}
+
+/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE (NMSettingsConnection,
PROP_UNSAVED,
@@ -87,6 +106,8 @@ typedef struct _NMSettingsConnectionPrivate {
CList call_ids_lst_head; /* in-progress secrets requests */
+ NMConnection *connection;
+
/* Caches secrets from on-disk connections; were they not cached any
* call to nm_connection_clear_secrets() wipes them out and we'd have
* to re-read them from disk which defeats the purpose of having the
@@ -115,9 +136,7 @@ typedef struct _NMSettingsConnectionPrivate {
} NMSettingsConnectionPrivate;
-G_DEFINE_TYPE_WITH_CODE (NMSettingsConnection, nm_settings_connection, NM_TYPE_DBUS_OBJECT,
- G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION, nm_settings_connection_connection_interface_init)
- )
+G_DEFINE_TYPE (NMSettingsConnection, nm_settings_connection, NM_TYPE_DBUS_OBJECT)
#define NM_SETTINGS_CONNECTION_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR (self, NMSettingsConnection, NM_IS_SETTINGS_CONNECTION)
@@ -152,6 +171,16 @@ static const NMDBusInterfaceInfoExtended interface_info_settings_connection;
/*****************************************************************************/
+NMConnection *
+nm_settings_connection_get_connection (NMSettingsConnection *self)
+{
+ g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), NULL);
+
+ return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->connection;
+}
+
+/*****************************************************************************/
+
gboolean
nm_settings_connection_has_unmodified_applied_connection (NMSettingsConnection *self,
NMConnection *applied_connection,
@@ -163,7 +192,8 @@ nm_settings_connection_has_unmodified_applied_connection (NMSettingsConnection *
/* for convenience, we *always* ignore certain settings. */
compare_flags |= NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS | NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP;
- return nm_connection_compare (NM_CONNECTION (self), applied_connection, compare_flags);
+ return nm_connection_compare (nm_settings_connection_get_connection (self),
+ applied_connection, compare_flags);
}
/*****************************************************************************/
@@ -332,8 +362,7 @@ nm_settings_connection_recheck_visibility (NMSettingsConnection *self)
priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (self));
- g_assert (s_con);
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (self));
/* Check every user in the ACL for a session */
num = nm_setting_connection_get_num_permissions (s_con);
@@ -362,9 +391,9 @@ nm_settings_connection_recheck_visibility (NMSettingsConnection *self)
}
static void
-session_changed_cb (NMSessionMonitor *self, gpointer user_data)
+session_changed_cb (NMSessionMonitor *self, NMSettingsConnection *sett_conn)
{
- nm_settings_connection_recheck_visibility (NM_SETTINGS_CONNECTION (user_data));
+ nm_settings_connection_recheck_visibility (sett_conn);
}
/*****************************************************************************/
@@ -390,8 +419,7 @@ nm_settings_connection_check_permission (NMSettingsConnection *self,
NM_SETTINGS_CONNECTION_INT_FLAGS_VISIBLE))
return FALSE;
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (self));
- g_assert (s_con);
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (self));
/* Check every user in the ACL for a session */
num = nm_setting_connection_get_num_permissions (s_con);
@@ -447,7 +475,7 @@ update_system_secrets_cache (NMSettingsConnection *self)
if (priv->system_secrets)
g_object_unref (priv->system_secrets);
- priv->system_secrets = nm_simple_connection_new_clone (NM_CONNECTION (self));
+ priv->system_secrets = nm_simple_connection_new_clone (nm_settings_connection_get_connection (self));
/* Clear out non-system-owned and not-saved secrets */
nm_connection_clear_secrets_with_flags (priv->system_secrets,
@@ -463,7 +491,8 @@ update_agent_secrets_cache (NMSettingsConnection *self, NMConnection *new)
if (priv->agent_secrets)
g_object_unref (priv->agent_secrets);
- priv->agent_secrets = nm_simple_connection_new_clone (new ?: NM_CONNECTION(self));
+ priv->agent_secrets = nm_simple_connection_new_clone ( new
+ ?: nm_settings_connection_get_connection (self));
/* Clear out non-system-owned secrets */
nm_connection_clear_secrets_with_flags (priv->agent_secrets,
@@ -472,7 +501,7 @@ update_agent_secrets_cache (NMSettingsConnection *self, NMConnection *new)
}
static void
-secrets_cleared_cb (NMSettingsConnection *self)
+secrets_cleared_cb (NMConnection *connection, NMSettingsConnection *self)
{
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
@@ -533,7 +562,7 @@ _emit_updated (NMSettingsConnection *self, gboolean by_user)
}
static void
-connection_changed_cb (NMSettingsConnection *self, gpointer unused)
+connection_changed_cb (NMConnection *connection, NMSettingsConnection *self)
{
set_persist_mode (self, NM_SETTINGS_CONNECTION_PERSIST_MODE_UNSAVED);
_emit_updated (self, FALSE);
@@ -636,7 +665,7 @@ nm_settings_connection_update (NMSettingsConnection *self,
if (persist_mode == NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK) {
if (!klass->commit_changes (self,
- new_connection ?: NM_CONNECTION (self),
+ new_connection ?: nm_settings_connection_get_connection (self),
commit_reason,
&reread_connection,
&logmsg_change,
@@ -655,30 +684,30 @@ nm_settings_connection_update (NMSettingsConnection *self,
/* Disconnect the changed signal to ensure we don't set Unsaved when
* it's not required.
*/
- g_signal_handlers_block_by_func (self, G_CALLBACK (connection_changed_cb), NULL);
+ g_signal_handlers_block_by_func (priv->connection, G_CALLBACK (connection_changed_cb), self);
/* Do nothing if there's nothing to update */
if ( replace_connection
- && !nm_connection_compare (NM_CONNECTION (self),
+ && !nm_connection_compare (nm_settings_connection_get_connection (self),
replace_connection,
NM_SETTING_COMPARE_FLAG_EXACT)) {
gs_unref_object NMConnection *simple = NULL;
if (log_diff_name) {
- nm_utils_log_connection_diff (replace_connection, NM_CONNECTION (self), LOGL_DEBUG, LOGD_CORE, log_diff_name, "++ ",
+ nm_utils_log_connection_diff (replace_connection, nm_settings_connection_get_connection (self), LOGL_DEBUG, LOGD_CORE, log_diff_name, "++ ",
nm_dbus_object_get_path (NM_DBUS_OBJECT (self)));
}
/* Make a copy of agent-owned secrets because they won't be present in
* the connection returned by plugins, as plugins return only what was
* reread from the file. */
- simple = nm_simple_connection_new_clone (NM_CONNECTION (self));
+ simple = nm_simple_connection_new_clone (nm_settings_connection_get_connection (self));
nm_connection_clear_secrets_with_flags (simple,
secrets_filter_cb,
GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED));
con_agent_secrets = nm_connection_to_dbus (simple, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
- nm_connection_replace_settings_from_connection (NM_CONNECTION (self), replace_connection);
+ nm_connection_replace_settings_from_connection (nm_settings_connection_get_connection (self), replace_connection);
replaced = TRUE;
}
@@ -701,12 +730,12 @@ nm_settings_connection_update (NMSettingsConnection *self,
dict = nm_connection_to_dbus (priv->agent_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
if (dict) {
- (void) nm_connection_update_secrets (NM_CONNECTION (self), NULL, dict, NULL);
+ (void) nm_connection_update_secrets (nm_settings_connection_get_connection (self), NULL, dict, NULL);
g_variant_unref (dict);
}
}
if (con_agent_secrets)
- (void) nm_connection_update_secrets (NM_CONNECTION (self), NULL, con_agent_secrets, NULL);
+ (void) nm_connection_update_secrets (nm_settings_connection_get_connection (self), NULL, con_agent_secrets, NULL);
}
nm_settings_connection_recheck_visibility (self);
@@ -724,7 +753,7 @@ nm_settings_connection_update (NMSettingsConnection *self,
NM_SETTINGS_CONNECTION_PERSIST_MODE_VOLATILE_DETACHED))
nm_settings_connection_set_filename (self, NULL);
- g_signal_handlers_unblock_by_func (self, G_CALLBACK (connection_changed_cb), NULL);
+ g_signal_handlers_unblock_by_func (priv->connection, G_CALLBACK (connection_changed_cb), self);
_emit_updated (self, TRUE);
@@ -800,7 +829,7 @@ nm_settings_connection_delete (NMSettingsConnection *self,
set_visible (self, FALSE);
/* Tell agents to remove secrets for this connection */
- for_agents = nm_simple_connection_new_clone (NM_CONNECTION (self));
+ for_agents = nm_simple_connection_new_clone (nm_settings_connection_get_connection (self));
nm_connection_clear_secrets (for_agents);
nm_agent_manager_delete_secrets (priv->agent_mgr,
nm_dbus_object_get_path (NM_DBUS_OBJECT (self)),
@@ -920,7 +949,7 @@ get_cmp_flags (NMSettingsConnection *self, /* only needed for logging */
gboolean *agent_had_system,
ForEachSecretFlags *cmp_flags)
{
- gboolean is_self = (((NMConnection *) self) == connection);
+ gboolean is_self = (nm_settings_connection_get_connection (self) == connection);
g_return_if_fail (secrets);
@@ -1001,7 +1030,7 @@ nm_settings_connection_new_secrets (NMSettingsConnection *self,
return FALSE;
}
- if (!nm_connection_update_secrets (NM_CONNECTION (self), setting_name, secrets, error))
+ if (!nm_connection_update_secrets (nm_settings_connection_get_connection (self), setting_name, secrets, error))
return FALSE;
update_system_secrets_cache (self);
@@ -1073,7 +1102,7 @@ get_secrets_done_cb (NMAgentManager *manager,
goto out;
}
- if (!nm_connection_get_setting_by_name (NM_CONNECTION (self), setting_name)) {
+ if (!nm_connection_get_setting_by_name (nm_settings_connection_get_connection (self), setting_name)) {
g_set_error (&local, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND,
"Connection didn't have requested setting '%s'.",
setting_name);
@@ -1083,7 +1112,7 @@ get_secrets_done_cb (NMAgentManager *manager,
get_cmp_flags (self,
call_id,
- NM_CONNECTION (self),
+ nm_settings_connection_get_connection (self),
agent_dbus_owner,
agent_has_modify,
setting_name,
@@ -1100,8 +1129,8 @@ get_secrets_done_cb (NMAgentManager *manager,
dict = nm_connection_to_dbus (priv->system_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
/* Update the connection with our existing secrets from backing storage */
- nm_connection_clear_secrets (NM_CONNECTION (self));
- if (!dict || nm_connection_update_secrets (NM_CONNECTION (self), setting_name, dict, &local)) {
+ nm_connection_clear_secrets (nm_settings_connection_get_connection (self));
+ if (!dict || nm_connection_update_secrets (nm_settings_connection_get_connection (self), setting_name, dict, &local)) {
GVariant *filtered_secrets;
/* Update the connection with the agent's secrets; by this point if any
@@ -1109,8 +1138,8 @@ get_secrets_done_cb (NMAgentManager *manager,
* will have been authenticated, so those secrets can replace the existing
* system secrets.
*/
- filtered_secrets = for_each_secret (NM_CONNECTION (self), secrets, TRUE, validate_secret_flags, &cmp_flags);
- if (nm_connection_update_secrets (NM_CONNECTION (self), setting_name, filtered_secrets, &local)) {
+ filtered_secrets = for_each_secret (nm_settings_connection_get_connection (self), secrets, TRUE, validate_secret_flags, &cmp_flags);
+ if (nm_connection_update_secrets (nm_settings_connection_get_connection (self), setting_name, filtered_secrets, &local)) {
/* Now that all secrets are updated, copy and cache new secrets,
* then save them to backing storage.
*/
@@ -1250,7 +1279,7 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), NULL);
g_return_val_if_fail ( !applied_connection
|| ( NM_IS_CONNECTION (applied_connection)
- && (((NMConnection *) self) != applied_connection)), NULL);
+ && (nm_settings_connection_get_connection (self) != applied_connection)), NULL);
call_id = g_slice_new0 (NMSettingsConnectionCallId);
call_id->self = self;
@@ -1264,7 +1293,7 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
c_list_link_tail (&priv->call_ids_lst_head, &call_id->call_ids_lst);
/* Make sure the request actually requests something we can return */
- if (!nm_connection_get_setting_by_name (NM_CONNECTION (self), setting_name)) {
+ if (!nm_connection_get_setting_by_name (nm_settings_connection_get_connection (self), setting_name)) {
g_set_error (&local, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND,
"Connection didn't have requested setting '%s'.",
setting_name);
@@ -1295,7 +1324,7 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
call_id_a = nm_agent_manager_get_secrets (priv->agent_mgr,
nm_dbus_object_get_path (NM_DBUS_OBJECT (self)),
- NM_CONNECTION (self),
+ nm_settings_connection_get_connection (self),
subject,
existing_secrets,
setting_name,
@@ -1465,7 +1494,7 @@ auth_start (NMSettingsConnection *self,
nm_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
nm_assert (NM_IS_AUTH_SUBJECT (subject));
- if (!nm_auth_is_subject_in_acl_set_error (NM_CONNECTION (self),
+ if (!nm_auth_is_subject_in_acl_set_error (nm_settings_connection_get_connection (self),
subject,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_PERMISSION_DENIED,
@@ -1539,15 +1568,14 @@ get_settings_auth_cb (NMSettingsConnection *self,
if (error)
g_dbus_method_invocation_return_gerror (context, error);
else {
+ gs_unref_object NMConnection *dupl_con = NULL;
GVariant *settings;
- NMConnection *dupl_con;
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
guint64 timestamp = 0;
- char **bssids;
+ gs_free char **bssids = NULL;
- dupl_con = nm_simple_connection_new_clone (NM_CONNECTION (self));
- g_assert (dupl_con);
+ dupl_con = nm_simple_connection_new_clone (nm_settings_connection_get_connection (self));
/* Timestamp is not updated in connection's 'timestamp' property,
* because it would force updating the connection and in turn
@@ -1557,8 +1585,7 @@ get_settings_auth_cb (NMSettingsConnection *self,
*/
nm_settings_connection_get_timestamp (self, &timestamp);
if (timestamp) {
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (dupl_con));
- g_assert (s_con);
+ s_con = nm_connection_get_setting_connection (dupl_con);
g_object_set (s_con, NM_SETTING_CONNECTION_TIMESTAMP, timestamp, NULL);
}
/* Seen BSSIDs are not updated in 802-11-wireless 'seen-bssids' property
@@ -1566,20 +1593,17 @@ get_settings_auth_cb (NMSettingsConnection *self,
* return settings too.
*/
bssids = nm_settings_connection_get_seen_bssids (self);
- s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (dupl_con));
+ s_wifi = nm_connection_get_setting_wireless (dupl_con);
if (bssids && bssids[0] && s_wifi)
g_object_set (s_wifi, NM_SETTING_WIRELESS_SEEN_BSSIDS, bssids, NULL);
- g_free (bssids);
/* Secrets should *never* be returned by the GetSettings method, they
* get returned by the GetSecrets method which can be better
* protected against leakage of secrets to unprivileged callers.
*/
- settings = nm_connection_to_dbus (NM_CONNECTION (dupl_con), NM_CONNECTION_SERIALIZE_NO_SECRETS);
- g_assert (settings);
+ settings = nm_connection_to_dbus (dupl_con, NM_CONNECTION_SERIALIZE_NO_SECRETS);
g_dbus_method_invocation_return_value (context,
g_variant_new ("(@a{sa{sv}})", settings));
- g_object_unref (dupl_con);
}
}
@@ -1734,7 +1758,7 @@ update_auth_cb (NMSettingsConnection *self,
gs_unref_hashtable GHashTable *diff = NULL;
gboolean same;
- same = nm_connection_diff (NM_CONNECTION (self), info->new_settings,
+ same = nm_connection_diff (nm_settings_connection_get_connection (self), info->new_settings,
NM_SETTING_COMPARE_FLAG_EXACT |
NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT,
&diff);
@@ -1745,7 +1769,7 @@ update_auth_cb (NMSettingsConnection *self,
commit_reason = NM_SETTINGS_CONNECTION_COMMIT_REASON_USER_ACTION;
if ( info->new_settings
- && !nm_streq0 (nm_connection_get_id (NM_CONNECTION (self)),
+ && !nm_streq0 (nm_connection_get_id (nm_settings_connection_get_connection (self)),
nm_connection_get_id (info->new_settings)))
commit_reason |= NM_SETTINGS_CONNECTION_COMMIT_REASON_ID_CHANGED;
@@ -1791,7 +1815,7 @@ update_auth_cb (NMSettingsConnection *self,
* as agent-owned secrets are the only ones we send back be saved.
* Only send secrets to agents of the same UID that called update too.
*/
- for_agent = nm_simple_connection_new_clone (NM_CONNECTION (self));
+ for_agent = nm_simple_connection_new_clone (nm_settings_connection_get_connection (self));
nm_connection_clear_secrets_with_flags (for_agent,
secrets_filter_cb,
GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED));
@@ -1811,11 +1835,9 @@ get_update_modify_permission (NMConnection *old, NMConnection *new)
guint32 orig_num = 0, new_num = 0;
s_con = nm_connection_get_setting_connection (old);
- g_assert (s_con);
orig_num = nm_setting_connection_get_num_permissions (s_con);
s_con = nm_connection_get_setting_connection (new);
- g_assert (s_con);
new_num = nm_setting_connection_get_num_permissions (s_con);
/* If the caller is the only user in either connection's permissions, then
@@ -1848,7 +1870,7 @@ settings_connection_update (NMSettingsConnection *self,
* the problem (ex a system settings plugin that can't write connections out)
* instead of over D-Bus.
*/
- if (!check_writable (NM_CONNECTION (self), &error))
+ if (!check_writable (nm_settings_connection_get_connection (self), &error))
goto error;
/* Check if the settings are valid first */
@@ -1879,7 +1901,7 @@ settings_connection_update (NMSettingsConnection *self,
* that's sending the update request. You can't make a connection
* invisible to yourself.
*/
- if (!nm_auth_is_subject_in_acl_set_error (tmp ?: NM_CONNECTION(self),
+ if (!nm_auth_is_subject_in_acl_set_error (tmp ?: nm_settings_connection_get_connection (self),
subject,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_PERMISSION_DENIED,
@@ -1894,8 +1916,8 @@ settings_connection_update (NMSettingsConnection *self,
info->flags = flags;
info->new_settings = tmp;
- permission = get_update_modify_permission (NM_CONNECTION (self),
- tmp ?: NM_CONNECTION(self));
+ permission = get_update_modify_permission (nm_settings_connection_get_connection (self),
+ tmp ?: nm_settings_connection_get_connection (self));
auth_start (self, context, subject, permission, update_auth_cb, info);
return;
@@ -2066,8 +2088,7 @@ get_modify_permission_basic (NMSettingsConnection *self)
* we use the 'modify.own' permission instead of 'modify.system'. If the
* request affects more than just the caller, require 'modify.system'.
*/
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (self));
- nm_assert (s_con);
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (self));
if (nm_setting_connection_get_num_permissions (s_con) == 1)
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN;
@@ -2087,7 +2108,7 @@ impl_settings_connection_delete (NMDBusObject *obj,
gs_unref_object NMAuthSubject *subject = NULL;
GError *error = NULL;
- if (!check_writable (NM_CONNECTION (self), &error))
+ if (!check_writable (nm_settings_connection_get_connection (self), &error))
goto err;
subject = _new_auth_subject (invocation, &error);
@@ -2122,7 +2143,7 @@ dbus_get_agent_secrets_cb (NMSettingsConnection *self,
* secrets from backing storage and those returned from the agent
* by the time we get here.
*/
- dict = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
+ dict = nm_connection_to_dbus (nm_settings_connection_get_connection (self), NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
if (!dict)
dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
g_dbus_method_invocation_return_value (context, g_variant_new ("(@a{sa{sv}})", dict));
@@ -2204,7 +2225,7 @@ dbus_clear_secrets_auth_cb (NMSettingsConnection *self,
}
/* Clear secrets in connection and caches */
- nm_connection_clear_secrets (NM_CONNECTION (self));
+ nm_connection_clear_secrets (nm_settings_connection_get_connection (self));
if (priv->system_secrets)
nm_connection_clear_secrets (priv->system_secrets);
if (priv->agent_secrets)
@@ -2213,7 +2234,7 @@ dbus_clear_secrets_auth_cb (NMSettingsConnection *self,
/* Tell agents to remove secrets for this connection */
nm_agent_manager_delete_secrets (priv->agent_mgr,
nm_dbus_object_get_path (NM_DBUS_OBJECT (self)),
- NM_CONNECTION (self));
+ nm_settings_connection_get_connection (self));
nm_settings_connection_update (self,
NULL,
@@ -2388,15 +2409,8 @@ _cmp_timestamp (NMSettingsConnection *a, NMSettingsConnection *b)
static int
_cmp_last_resort (NMSettingsConnection *a, NMSettingsConnection *b)
{
- int c;
-
- nm_assert (NM_IS_SETTINGS_CONNECTION (a));
- nm_assert (NM_IS_SETTINGS_CONNECTION (b));
-
- c = g_strcmp0 (nm_connection_get_uuid (NM_CONNECTION (a)),
- nm_connection_get_uuid (NM_CONNECTION (b)));
- if (c)
- return c;
+ NM_CMP_DIRECT_STRCMP0 (nm_settings_connection_get_uuid (a),
+ nm_settings_connection_get_uuid (b));
/* hm, same UUID. Use their pointer value to give them a stable
* order. */
@@ -2411,19 +2425,11 @@ _cmp_last_resort (NMSettingsConnection *a, NMSettingsConnection *b)
int
nm_settings_connection_cmp_timestamp (NMSettingsConnection *a, NMSettingsConnection *b)
{
- int c;
+ NM_CMP_SELF (a, b);
- if (a == b)
- return 0;
- if (!a)
- return 1;
- if (!b)
- return -1;
-
- if ((c = _cmp_timestamp (a, b)))
- return c;
- if ((c = nm_utils_cmp_connection_by_autoconnect_priority (NM_CONNECTION (a), NM_CONNECTION (b))))
- return c;
+ NM_CMP_RETURN (_cmp_timestamp (a, b));
+ NM_CMP_RETURN (nm_utils_cmp_connection_by_autoconnect_priority (nm_settings_connection_get_connection (a),
+ nm_settings_connection_get_connection (b)));
return _cmp_last_resort (a, b);
}
@@ -2437,14 +2443,11 @@ nm_settings_connection_cmp_timestamp_p_with_data (gconstpointer pa, gconstpointe
int
nm_settings_connection_cmp_autoconnect_priority (NMSettingsConnection *a, NMSettingsConnection *b)
{
- int c;
-
if (a == b)
return 0;
- if ((c = nm_utils_cmp_connection_by_autoconnect_priority (NM_CONNECTION (a), NM_CONNECTION (b))))
- return c;
- if ((c = _cmp_timestamp (a, b)))
- return c;
+ NM_CMP_RETURN (nm_utils_cmp_connection_by_autoconnect_priority (nm_settings_connection_get_connection (a),
+ nm_settings_connection_get_connection (b)));
+ NM_CMP_RETURN (_cmp_timestamp (a, b));
return _cmp_last_resort (a, b);
}
@@ -2727,7 +2730,7 @@ nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *self)
* seen-bssids list from the deprecated seen-bssids property of the
* wifi setting.
*/
- s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (self));
+ s_wifi = nm_connection_get_setting_wireless (nm_settings_connection_get_connection (self));
if (s_wifi) {
len = nm_setting_wireless_get_num_seen_bssids (s_wifi);
for (i = 0; i < len; i++) {
@@ -2747,7 +2750,7 @@ _autoconnect_retries_initial (NMSettingsConnection *self)
NMSettingConnection *s_con;
int retries = -1;
- s_con = nm_connection_get_setting_connection ((NMConnection *) self);
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (self));
if (s_con)
retries = nm_setting_connection_get_autoconnect_retries (s_con);
@@ -2959,13 +2962,19 @@ nm_settings_connection_get_filename (NMSettingsConnection *self)
const char *
nm_settings_connection_get_id (NMSettingsConnection *self)
{
- return nm_connection_get_id (NM_CONNECTION (self));
+ return nm_connection_get_id (nm_settings_connection_get_connection (self));
}
const char *
nm_settings_connection_get_uuid (NMSettingsConnection *self)
{
- return nm_connection_get_uuid (NM_CONNECTION (self));
+ return nm_connection_get_uuid (nm_settings_connection_get_connection (self));
+}
+
+const char *
+nm_settings_connection_get_connection_type (NMSettingsConnection *self)
+{
+ return nm_connection_get_connection_type (nm_settings_connection_get_connection (self));
}
/*****************************************************************************/
@@ -2995,8 +3004,10 @@ nm_settings_connection_init (NMSettingsConnection *self)
priv->autoconnect_retries = AUTOCONNECT_RETRIES_UNSET;
- g_signal_connect (self, NM_CONNECTION_SECRETS_CLEARED, G_CALLBACK (secrets_cleared_cb), NULL);
- g_signal_connect (self, NM_CONNECTION_CHANGED, G_CALLBACK (connection_changed_cb), NULL);
+ priv->connection = nm_simple_connection_new ();
+
+ g_signal_connect (priv->connection, NM_CONNECTION_SECRETS_CLEARED, G_CALLBACK (secrets_cleared_cb), self);
+ g_signal_connect (priv->connection, NM_CONNECTION_CHANGED, G_CALLBACK (connection_changed_cb), self);
}
static void
@@ -3027,26 +3038,32 @@ dispose (GObject *object)
_get_secrets_cancel (self, call_id, TRUE);
}
- /* Disconnect handlers.
- * connection_changed_cb() has to be disconnected *before* nm_connection_clear_secrets(),
- * because nm_connection_clear_secrets() emits NM_CONNECTION_CHANGED signal.
- */
- g_signal_handlers_disconnect_by_func (self, G_CALLBACK (secrets_cleared_cb), NULL);
- g_signal_handlers_disconnect_by_func (self, G_CALLBACK (connection_changed_cb), NULL);
+ set_visible (self, FALSE);
+
+ if (priv->connection) {
+ /* Disconnect handlers.
+ * connection_changed_cb() has to be disconnected *before* nm_connection_clear_secrets(),
+ * because nm_connection_clear_secrets() emits NM_CONNECTION_CHANGED signal.
+ */
+ g_signal_handlers_disconnect_by_func (priv->connection, G_CALLBACK (secrets_cleared_cb), self);
+ g_signal_handlers_disconnect_by_func (priv->connection, G_CALLBACK (connection_changed_cb), self);
+
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ nm_connection_clear_secrets (priv->connection);
+ }
- nm_connection_clear_secrets (NM_CONNECTION (self));
g_clear_object (&priv->system_secrets);
g_clear_object (&priv->agent_secrets);
g_clear_pointer (&priv->seen_bssids, g_hash_table_destroy);
- set_visible (self, FALSE);
-
nm_clear_g_signal_handler (priv->session_monitor, &priv->session_changed_id);
g_clear_object (&priv->session_monitor);
g_clear_object (&priv->agent_mgr);
+ g_clear_object (&priv->connection);
+
g_clear_pointer (&priv->filename, g_free);
G_OBJECT_CLASS (nm_settings_connection_parent_class)->dispose (object);
@@ -3264,9 +3281,3 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
-
-static void
-nm_settings_connection_connection_interface_init (NMConnectionInterface *iface)
-{
-}
-
diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h
index cd64f9762d..e796b71645 100644
--- a/src/settings/nm-settings-connection.h
+++ b/src/settings/nm-settings-connection.h
@@ -139,6 +139,8 @@ struct _NMSettingsConnectionClass {
GType nm_settings_connection_get_type (void);
+NMConnection *nm_settings_connection_get_connection (NMSettingsConnection *self);
+
guint64 nm_settings_connection_get_last_secret_agent_version_id (NMSettingsConnection *self);
gboolean nm_settings_connection_has_unmodified_applied_connection (NMSettingsConnection *self,
@@ -268,7 +270,13 @@ void nm_settings_connection_set_filename (NMSettingsConnection *self,
const char *filename);
const char *nm_settings_connection_get_filename (NMSettingsConnection *self);
-const char *nm_settings_connection_get_id (NMSettingsConnection *connection);
-const char *nm_settings_connection_get_uuid (NMSettingsConnection *connection);
+const char *nm_settings_connection_get_id (NMSettingsConnection *connection);
+const char *nm_settings_connection_get_uuid (NMSettingsConnection *connection);
+const char *nm_settings_connection_get_connection_type (NMSettingsConnection *connection);
+
+/*****************************************************************************/
+
+NMConnection **nm_settings_connections_array_to_connections (NMSettingsConnection *const*connections,
+ gssize n_connections);
#endif /* __NETWORKMANAGER_SETTINGS_CONNECTION_H__ */
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index a4d47f5346..6ddc9a94ab 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -214,9 +214,9 @@ connection_ready_changed (NMSettingsConnection *conn,
static void
plugin_connection_added (NMSettingsPlugin *config,
NMSettingsConnection *connection,
- gpointer user_data)
+ NMSettings *self)
{
- claim_connection (NM_SETTINGS (user_data), connection);
+ claim_connection (self, connection);
}
static void
@@ -237,7 +237,7 @@ load_connections (NMSettings *self)
// priority plugin.
for (elt = plugin_connections; elt; elt = g_slist_next (elt))
- claim_connection (self, NM_SETTINGS_CONNECTION (elt->data));
+ claim_connection (self, elt->data);
g_slist_free (plugin_connections);
@@ -306,15 +306,15 @@ impl_settings_get_connection_by_uuid (NMDBusObject *obj,
GVariant *parameters)
{
NMSettings *self = NM_SETTINGS (obj);
- NMSettingsConnection *connection = NULL;
+ NMSettingsConnection *sett_conn;
gs_unref_object NMAuthSubject *subject = NULL;
GError *error = NULL;
const char *uuid;
g_variant_get (parameters, "(&s)", &uuid);
- connection = nm_settings_get_connection_by_uuid (self, uuid);
- if (!connection) {
+ sett_conn = nm_settings_get_connection_by_uuid (self, uuid);
+ if (!sett_conn) {
error = g_error_new_literal (NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_INVALID_CONNECTION,
"No connection with the UUID was found.");
@@ -329,7 +329,7 @@ impl_settings_get_connection_by_uuid (NMDBusObject *obj,
goto error;
}
- if (!nm_auth_is_subject_in_acl_set_error (NM_CONNECTION (connection),
+ if (!nm_auth_is_subject_in_acl_set_error (nm_settings_connection_get_connection (sett_conn),
subject,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_PERMISSION_DENIED,
@@ -338,7 +338,7 @@ impl_settings_get_connection_by_uuid (NMDBusObject *obj,
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)",
- nm_dbus_object_get_path (NM_DBUS_OBJECT (connection))));
+ nm_dbus_object_get_path (NM_DBUS_OBJECT (sett_conn))));
return;
error:
@@ -362,6 +362,7 @@ _clear_connections_cached_list (NMSettingsPrivate *priv)
0xdeaddead,
sizeof (NMSettingsConnection *) * (priv->connections_len + 1));
#endif
+
nm_clear_g_free (&priv->connections_cached_list);
}
@@ -480,8 +481,8 @@ nm_settings_get_connection_by_path (NMSettings *self, const char *path)
priv = NM_SETTINGS_GET_PRIVATE (self);
- connection = (NMSettingsConnection *) nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (self)),
- path);
+ connection = nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (self)),
+ path);
if ( !connection
|| !NM_IS_SETTINGS_CONNECTION (connection))
return NULL;
@@ -931,29 +932,33 @@ openconnect_migrate_hack (NMConnection *connection)
}
static void
-claim_connection (NMSettings *self, NMSettingsConnection *connection)
+claim_connection (NMSettings *self, NMSettingsConnection *sett_conn)
{
- NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
+ NMSettingsPrivate *priv;
GError *error = NULL;
const char *path;
NMSettingsConnection *existing;
- g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection));
- g_return_if_fail (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (connection)));
+ g_return_if_fail (NM_IS_SETTINGS (self));
+ g_return_if_fail (NM_IS_SETTINGS_CONNECTION (sett_conn));
+ g_return_if_fail (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (sett_conn)));
+
+ priv = NM_SETTINGS_GET_PRIVATE (self);
/* prevent duplicates */
- if (!c_list_is_empty (&connection->_connections_lst)) {
- nm_assert (c_list_contains (&priv->connections_lst_head, &connection->_connections_lst));
+ if (!c_list_is_empty (&sett_conn->_connections_lst)) {
+ nm_assert (c_list_contains (&priv->connections_lst_head, &sett_conn->_connections_lst));
return;
}
- if (!nm_connection_normalize (NM_CONNECTION (connection), NULL, NULL, &error)) {
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ if (!nm_connection_normalize (nm_settings_connection_get_connection (sett_conn), NULL, NULL, &error)) {
_LOGW ("plugin provided invalid connection: %s", error->message);
g_error_free (error);
return;
}
- existing = nm_settings_get_connection_by_uuid (self, nm_settings_connection_get_uuid (connection));
+ existing = nm_settings_get_connection_by_uuid (self, nm_settings_connection_get_uuid (sett_conn));
if (existing) {
/* Cannot add duplicate connections per UUID. Just return without action and
* log a warning.
@@ -966,51 +971,56 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection)
* error out. That should not happen unless the admin misconfigured the system
* to create conflicting connections. */
_LOGW ("plugin provided duplicate connection with UUID %s",
- nm_settings_connection_get_uuid (connection));
+ nm_settings_connection_get_uuid (sett_conn));
return;
}
/* Read timestamp from look-aside file and put it into the connection's data */
- nm_settings_connection_read_and_fill_timestamp (connection);
+ nm_settings_connection_read_and_fill_timestamp (sett_conn);
/* Read seen-bssids from look-aside file and put it into the connection's data */
- nm_settings_connection_read_and_fill_seen_bssids (connection);
+ nm_settings_connection_read_and_fill_seen_bssids (sett_conn);
/* Ensure its initial visibility is up-to-date */
- nm_settings_connection_recheck_visibility (connection);
+ nm_settings_connection_recheck_visibility (sett_conn);
/* Evil openconnect migration hack */
- openconnect_migrate_hack (NM_CONNECTION (connection));
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ openconnect_migrate_hack (nm_settings_connection_get_connection (sett_conn));
/* This one unexports the connection, it needs to run late to give the active
* connection a chance to deal with its reference to this settings connection. */
- g_signal_connect_after (connection, NM_SETTINGS_CONNECTION_REMOVED,
+ g_signal_connect_after (sett_conn, NM_SETTINGS_CONNECTION_REMOVED,
G_CALLBACK (connection_removed), self);
- g_signal_connect (connection, NM_SETTINGS_CONNECTION_UPDATED_INTERNAL,
+ g_signal_connect (sett_conn, NM_SETTINGS_CONNECTION_UPDATED_INTERNAL,
G_CALLBACK (connection_updated), self);
- g_signal_connect (connection, NM_SETTINGS_CONNECTION_FLAGS_CHANGED,
+ g_signal_connect (sett_conn, NM_SETTINGS_CONNECTION_FLAGS_CHANGED,
G_CALLBACK (connection_flags_changed),
self);
if (!priv->startup_complete) {
- g_signal_connect (connection, "notify::" NM_SETTINGS_CONNECTION_READY,
+ g_signal_connect (sett_conn, "notify::" NM_SETTINGS_CONNECTION_READY,
G_CALLBACK (connection_ready_changed),
self);
}
_clear_connections_cached_list (priv);
- g_object_ref (connection);
+ g_object_ref (sett_conn);
/* FIXME(shutdown): The NMSettings instance can't be disposed
* while there is any exported connection. Ideally we should
* unexport all connections on NMSettings' disposal, but for now
* leak @self on termination when there are connections alive. */
g_object_ref (self);
priv->connections_len++;
- c_list_link_tail (&priv->connections_lst_head, &connection->_connections_lst);
+ c_list_link_tail (&priv->connections_lst_head, &sett_conn->_connections_lst);
- path = nm_dbus_object_export (NM_DBUS_OBJECT (connection));
+ path = nm_dbus_object_export (NM_DBUS_OBJECT (sett_conn));
- nm_utils_log_connection_diff (NM_CONNECTION (connection), NULL, LOGL_DEBUG, LOGD_CORE, "new connection", "++ ",
+ nm_utils_log_connection_diff (nm_settings_connection_get_connection (sett_conn),
+ NULL,
+ LOGL_DEBUG,
+ LOGD_CORE,
+ "new connection", "++ ",
path);
/* Only emit the individual connection-added signal after connections
@@ -1021,13 +1031,13 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection)
&interface_info_settings,
&signal_info_new_connection,
"(o)",
- nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)));
+ nm_dbus_object_get_path (NM_DBUS_OBJECT (sett_conn)));
- g_signal_emit (self, signals[CONNECTION_ADDED], 0, connection);
+ g_signal_emit (self, signals[CONNECTION_ADDED], 0, sett_conn);
_notify (self, PROP_CONNECTIONS);
}
- nm_settings_connection_added (connection);
+ nm_settings_connection_added (sett_conn);
}
static gboolean
@@ -1079,7 +1089,7 @@ nm_settings_add_connection (NMSettings *self,
/* Make sure a connection with this UUID doesn't already exist */
c_list_for_each_entry (candidate, &priv->connections_lst_head, _connections_lst) {
- if (nm_streq0 (uuid, nm_connection_get_uuid (NM_CONNECTION (candidate)))) {
+ if (nm_streq0 (uuid, nm_settings_connection_get_uuid (candidate))) {
g_set_error_literal (error,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_UUID_EXISTS,
@@ -1113,8 +1123,13 @@ nm_settings_add_connection (NMSettings *self,
added = nm_settings_plugin_add_connection (plugin, connection, save_to_disk, &add_error);
if (added) {
- if (secrets)
- nm_connection_update_secrets (NM_CONNECTION (added), NULL, secrets, NULL);
+ if (secrets) {
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ nm_connection_update_secrets (nm_settings_connection_get_connection (added),
+ NULL,
+ secrets,
+ NULL);
+ }
claim_connection (self, added);
return added;
}
@@ -1132,7 +1147,7 @@ nm_settings_add_connection (NMSettings *self,
static void
send_agent_owned_secrets (NMSettings *self,
- NMSettingsConnection *connection,
+ NMSettingsConnection *sett_conn,
NMAuthSubject *subject)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
@@ -1142,12 +1157,12 @@ send_agent_owned_secrets (NMSettings *self,
* as agent-owned secrets are the only ones we send back to be saved.
* Only send secrets to agents of the same UID that called update too.
*/
- for_agent = nm_simple_connection_new_clone (NM_CONNECTION (connection));
+ for_agent = nm_simple_connection_new_clone (nm_settings_connection_get_connection (sett_conn));
nm_connection_clear_secrets_with_flags (for_agent,
secrets_filter_cb,
GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED));
nm_agent_manager_save_secrets (priv->agent_mgr,
- nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)),
+ nm_dbus_object_get_path (NM_DBUS_OBJECT (sett_conn)),
for_agent,
subject);
}
@@ -1190,7 +1205,8 @@ pk_add_cb (NMAuthChain *chain,
} else {
/* Authorized */
connection = nm_auth_chain_get_data (chain, "connection");
- g_assert (connection);
+ nm_assert (connection);
+
save_to_disk = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "save-to-disk"));
added = nm_settings_add_connection (self, connection, save_to_disk, &error);
}
@@ -1612,20 +1628,21 @@ have_connection_for_device (NMSettings *self, NMDevice *device)
NMSettingWired *s_wired;
const char *setting_hwaddr;
const char *perm_hw_addr;
- NMSettingsConnection *connection;
+ NMSettingsConnection *sett_conn;
g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE);
perm_hw_addr = nm_device_get_permanent_hw_address (device);
/* Find a wired connection locked to the given MAC address, if any */
- c_list_for_each_entry (connection, &priv->connections_lst_head, _connections_lst) {
+ c_list_for_each_entry (sett_conn, &priv->connections_lst_head, _connections_lst) {
+ NMConnection *connection = nm_settings_connection_get_connection (sett_conn);
const char *ctype, *iface;
- if (!nm_device_check_connection_compatible (device, NM_CONNECTION (connection), NULL))
+ if (!nm_device_check_connection_compatible (device, connection, NULL))
continue;
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
+ s_con = nm_connection_get_setting_connection (connection);
iface = nm_setting_connection_get_interface_name (s_con);
if (iface && strcmp (iface, nm_device_get_iface (device)) != 0)
@@ -1636,14 +1653,15 @@ have_connection_for_device (NMSettings *self, NMDevice *device)
&& strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME))
continue;
- s_wired = nm_connection_get_setting_wired (NM_CONNECTION (connection));
+ s_wired = nm_connection_get_setting_wired (connection);
- if (!s_wired && !strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME)) {
+ if ( !s_wired
+ && nm_streq (ctype, NM_SETTING_PPPOE_SETTING_NAME)) {
/* No wired setting; therefore the PPPoE connection applies to any device */
return TRUE;
}
- g_assert (s_wired != NULL);
+ nm_assert (s_wired);
setting_hwaddr = nm_setting_wired_get_mac_address (s_wired);
if (setting_hwaddr) {
@@ -1687,11 +1705,11 @@ default_wired_clear_tag (NMSettings *self,
NMSettingsConnection *connection,
gboolean add_to_no_auto_default)
{
- g_return_if_fail (NM_IS_SETTINGS (self));
- g_return_if_fail (NM_IS_DEVICE (device));
- g_return_if_fail (NM_IS_CONNECTION (connection));
- g_return_if_fail (device == g_object_get_qdata (G_OBJECT (connection), _default_wired_device_quark ()));
- g_return_if_fail (connection == g_object_get_qdata (G_OBJECT (device), _default_wired_connection_quark ()));
+ nm_assert (NM_IS_SETTINGS (self));
+ nm_assert (NM_IS_DEVICE (device));
+ nm_assert (NM_IS_SETTINGS_CONNECTION (connection));
+ nm_assert (device == g_object_get_qdata (G_OBJECT (connection), _default_wired_device_quark ()));
+ nm_assert (connection == g_object_get_qdata (G_OBJECT (device), _default_wired_connection_quark ()));
g_object_set_qdata (G_OBJECT (connection), _default_wired_device_quark (), NULL);
g_object_set_qdata (G_OBJECT (device), _default_wired_connection_quark (), NULL);
diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h
index 021512fdaf..38d8ad4ed8 100644
--- a/src/settings/nm-settings.h
+++ b/src/settings/nm-settings.h
@@ -85,7 +85,7 @@ void nm_settings_add_connection_dbus (NMSettings *self,
NMSettingsAddCallback callback,
gpointer user_data);
-NMSettingsConnection *const* nm_settings_get_connections (NMSettings *settings, guint *out_len);
+NMSettingsConnection *const*nm_settings_get_connections (NMSettings *settings, guint *out_len);
NMSettingsConnection **nm_settings_get_connections_clone (NMSettings *self,
guint *out_len,
diff --git a/src/settings/plugins/ibft/nms-ibft-plugin.c b/src/settings/plugins/ibft/nms-ibft-plugin.c
index 77ce208f41..9785ba49c0 100644
--- a/src/settings/plugins/ibft/nms-ibft-plugin.c
+++ b/src/settings/plugins/ibft/nms-ibft-plugin.c
@@ -84,9 +84,9 @@ read_connections (NMSIbftPlugin *self)
connection = nms_ibft_connection_new (iter->data, &error);
if (connection) {
nm_log_info (LOGD_SETTINGS, "ibft: read connection '%s'",
- nm_connection_get_id (NM_CONNECTION (connection)));
+ nm_settings_connection_get_id (NM_SETTINGS_CONNECTION (connection)));
g_hash_table_insert (priv->connections,
- g_strdup (nm_connection_get_uuid (NM_CONNECTION (connection))),
+ g_strdup (nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection))),
connection);
} else {
nm_log_warn (LOGD_SETTINGS, "ibft: failed to read iscsiadm record: %s", error->message);
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c
index 6979fdaaaf..ca319ddc61 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c
@@ -143,7 +143,7 @@ devtimeout_expired (gpointer user_data)
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self);
nm_log_info (LOGD_SETTINGS, "Device for connection '%s' did not appear before timeout",
- nm_connection_get_id (NM_CONNECTION (self)));
+ nm_settings_connection_get_id (NM_SETTINGS_CONNECTION (self)));
g_signal_handler_disconnect (NM_PLATFORM_GET, priv->devtimeout_link_changed_handler);
priv->devtimeout_link_changed_handler = 0;
@@ -163,7 +163,7 @@ nm_ifcfg_connection_check_devtimeout (NMIfcfgConnection *self)
guint devtimeout;
const NMPlatformLink *pllink;
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (self));
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (self)));
if (!nm_setting_connection_get_autoconnect (s_con))
return;
@@ -186,7 +186,7 @@ nm_ifcfg_connection_check_devtimeout (NMIfcfgConnection *self)
nm_settings_connection_set_ready (NM_SETTINGS_CONNECTION (self), FALSE);
nm_log_info (LOGD_SETTINGS, "Waiting %u seconds for %s to appear for connection '%s'",
- devtimeout, ifname, nm_connection_get_id (NM_CONNECTION (self)));
+ devtimeout, ifname, nm_settings_connection_get_id (NM_SETTINGS_CONNECTION (self)));
priv->devtimeout_link_changed_handler =
g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_LINK_CHANGED,
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c
index 0fb77b9d20..23856b1cd6 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c
@@ -139,7 +139,7 @@ static void
connection_removed_cb (NMSettingsConnection *obj, gpointer user_data)
{
g_hash_table_remove (SETTINGS_PLUGIN_IFCFG_GET_PRIVATE ((SettingsPluginIfcfg *) user_data)->connections,
- nm_connection_get_uuid (NM_CONNECTION (obj)));
+ nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (obj)));
}
static void
@@ -157,7 +157,7 @@ remove_connection (SettingsPluginIfcfg *self, NMIfcfgConnection *connection)
unrecognized = !!nm_ifcfg_connection_get_unrecognized_spec (connection);
g_object_ref (connection);
- g_hash_table_remove (priv->connections, nm_connection_get_uuid (NM_CONNECTION (connection)));
+ g_hash_table_remove (priv->connections, nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection)));
if (!unmanaged && !unrecognized)
nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection));
g_object_unref (connection);
@@ -228,7 +228,7 @@ update_connection (SettingsPluginIfcfg *self,
return NULL;
}
- uuid = nm_connection_get_uuid (NM_CONNECTION (connection_new));
+ uuid = nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection_new));
connection_by_uuid = g_hash_table_lookup (priv->connections, uuid);
if ( connection
@@ -285,12 +285,16 @@ update_connection (SettingsPluginIfcfg *self,
if ( !unmanaged_changed
&& !unrecognized_changed
- && nm_connection_compare (NM_CONNECTION (connection_by_uuid),
- NM_CONNECTION (connection_new),
+ && nm_connection_compare (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection_by_uuid)),
+ nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection_new)),
NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS |
NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) {
- if (old_path && g_strcmp0 (old_path, full_path) != 0)
- _LOGI ("rename \"%s\" to "NM_IFCFG_CONNECTION_LOG_FMT" without other changes", nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_by_uuid)), NM_IFCFG_CONNECTION_LOG_ARG (connection_new));
+ if ( old_path
+ && !nm_streq0 (old_path, full_path)) {
+ _LOGI ("rename \"%s\" to "NM_IFCFG_CONNECTION_LOG_FMT" without other changes",
+ nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_by_uuid)),
+ NM_IFCFG_CONNECTION_LOG_ARG (connection_new));
+ }
} else {
/*******************************************************
@@ -299,7 +303,7 @@ update_connection (SettingsPluginIfcfg *self,
if (source)
_LOGI ("update "NM_IFCFG_CONNECTION_LOG_FMT" from %s", NM_IFCFG_CONNECTION_LOG_ARG (connection_new), NM_IFCFG_CONNECTION_LOG_PATH (old_path));
- else if (!g_strcmp0 (old_path, nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_new))))
+ else if (nm_streq0 (old_path, nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_new))))
_LOGI ("update "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_new));
else if (old_path)
_LOGI ("rename \"%s\" to "NM_IFCFG_CONNECTION_LOG_FMT, old_path, NM_IFCFG_CONNECTION_LOG_ARG (connection_new));
@@ -312,7 +316,7 @@ update_connection (SettingsPluginIfcfg *self,
NULL);
if (!nm_settings_connection_update (NM_SETTINGS_CONNECTION (connection_by_uuid),
- NM_CONNECTION (connection_new),
+ nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection_new)),
NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED,
NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE,
"ifcfg-update",
@@ -338,7 +342,7 @@ update_connection (SettingsPluginIfcfg *self,
* so add it back now.
*/
g_hash_table_insert (priv->connections,
- g_strdup (nm_connection_get_uuid (NM_CONNECTION (connection_by_uuid))),
+ g_strdup (nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection_by_uuid))),
connection_by_uuid /* we took reference above and pass it on */);
}
} else {
@@ -731,7 +735,7 @@ impl_ifcfgrh_get_ifcfg_details (SettingsPluginIfcfg *plugin,
return;
}
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection)));
if (!s_con) {
g_dbus_method_invocation_return_error (context,
NM_SETTINGS_ERROR,
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h
index d95b1f61cf..84c22094f3 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h
@@ -28,9 +28,9 @@
#define NM_IFCFG_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory")
#define NM_IFCFG_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
-#define NM_IFCFG_CONNECTION_LOG_ARG(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con))
+#define NM_IFCFG_CONNECTION_LOG_ARG(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con))
#define NM_IFCFG_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"
-#define NM_IFCFG_CONNECTION_LOG_ARGD(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con)
+#define NM_IFCFG_CONNECTION_LOG_ARGD(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con)), (con)
char *utils_cert_path (const char *parent, const char *suffix, const char *extension);
diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-connection.c b/src/settings/plugins/ifupdown/nms-ifupdown-connection.c
index c3d231fe16..bdca91d66c 100644
--- a/src/settings/plugins/ifupdown/nms-ifupdown-connection.c
+++ b/src/settings/plugins/ifupdown/nms-ifupdown-connection.c
@@ -64,26 +64,29 @@ nm_ifupdown_connection_init (NMIfupdownConnection *connection)
{
}
-NMIfupdownConnection*
+NMIfupdownConnection *
nm_ifupdown_connection_new (if_block *block)
{
- GObject *object;
+ NMIfupdownConnection *connection;
GError *error = NULL;
g_return_val_if_fail (block != NULL, NULL);
- object = g_object_new (NM_TYPE_IFUPDOWN_CONNECTION, NULL);
+ connection = g_object_new (NM_TYPE_IFUPDOWN_CONNECTION, NULL);
- if (!ifupdown_update_connection_from_if_block (NM_CONNECTION (object), block, &error)) {
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ if (!ifupdown_update_connection_from_if_block (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection)),
+ block,
+ &error)) {
nm_log_warn (LOGD_SETTINGS, "%s.%d - invalid connection read from /etc/network/interfaces: %s",
__FILE__,
__LINE__,
error->message);
- g_object_unref (object);
+ g_object_unref (connection);
return NULL;
}
- return (NMIfupdownConnection *) object;
+ return connection;
}
static void
diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c
index 8bd72d0268..a6b22de24d 100644
--- a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c
+++ b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c
@@ -126,8 +126,8 @@ bind_device_to_connection (SettingsPluginIfupdown *self,
return;
}
- s_wired = nm_connection_get_setting_wired (NM_CONNECTION (exported));
- s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (exported));
+ s_wired = nm_connection_get_setting_wired (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (exported)));
+ s_wifi = nm_connection_get_setting_wireless (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (exported)));
if (s_wired) {
nm_log_info (LOGD_SETTINGS, "locking wired connection setting");
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, address, NULL);
@@ -415,7 +415,8 @@ init (NMSettingsPlugin *config)
NMSettingConnection *setting;
if (g_hash_table_lookup (auto_ifaces, block_name)) {
- setting = nm_connection_get_setting_connection (NM_CONNECTION (connection));
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ setting = nm_connection_get_setting_connection (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection)));
g_object_set (setting, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL);
nm_log_info (LOGD_SETTINGS, "autoconnect");
}
diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c
index 5f72a9fabe..2dbce4e0c9 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-connection.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c
@@ -142,7 +142,7 @@ nms_keyfile_connection_new (NMConnection *source,
if (!tmp)
return NULL;
- uuid = nm_connection_get_uuid (NM_CONNECTION (tmp));
+ uuid = nm_connection_get_uuid (tmp);
if (!uuid) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Connection in file %s had no UUID", full_path);
@@ -154,9 +154,9 @@ nms_keyfile_connection_new (NMConnection *source,
update_unsaved = FALSE;
}
- object = (GObject *) g_object_new (NMS_TYPE_KEYFILE_CONNECTION,
- NM_SETTINGS_CONNECTION_FILENAME, full_path,
- NULL);
+ object = g_object_new (NMS_TYPE_KEYFILE_CONNECTION,
+ NM_SETTINGS_CONNECTION_FILENAME, full_path,
+ NULL);
/* Update our settings with what was read from the file */
if (!nm_settings_connection_update (NM_SETTINGS_CONNECTION (object),
diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
index 3723db945c..7b2249460b 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
@@ -85,10 +85,10 @@ G_DEFINE_TYPE_EXTENDED (NMSKeyfilePlugin, nms_keyfile_plugin, G_TYPE_OBJECT, 0,
/*****************************************************************************/
static void
-connection_removed_cb (NMSettingsConnection *obj, gpointer user_data)
+connection_removed_cb (NMSettingsConnection *sett_conn, NMSKeyfilePlugin *self)
{
- g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) user_data)->connections,
- nm_connection_get_uuid (NM_CONNECTION (obj)));
+ g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE (self)->connections,
+ nm_settings_connection_get_uuid (sett_conn));
}
/* Monitoring */
@@ -106,7 +106,7 @@ remove_connection (NMSKeyfilePlugin *self, NMSKeyfileConnection *connection)
g_object_ref (connection);
g_signal_handlers_disconnect_by_func (connection, connection_removed_cb, self);
removed = g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE (self)->connections,
- nm_connection_get_uuid (NM_CONNECTION (connection)));
+ nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection)));
nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection));
g_object_unref (connection);
@@ -197,7 +197,7 @@ update_connection (NMSKeyfilePlugin *self,
return NULL;
}
- uuid = nm_connection_get_uuid (NM_CONNECTION (connection_new));
+ uuid = nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection_new));
connection_by_uuid = g_hash_table_lookup (priv->connections, uuid);
if ( connection
diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.h b/src/settings/plugins/keyfile/nms-keyfile-utils.h
index cd3f42b9f9..d5ddb8d536 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-utils.h
+++ b/src/settings/plugins/keyfile/nms-keyfile-utils.h
@@ -25,9 +25,9 @@
#define NMS_KEYFILE_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory")
#define NMS_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
-#define NMS_KEYFILE_CONNECTION_LOG_ARG(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con))
+#define NMS_KEYFILE_CONNECTION_LOG_ARG(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con))
#define NMS_KEYFILE_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"
-#define NMS_KEYFILE_CONNECTION_LOG_ARGD(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con)
+#define NMS_KEYFILE_CONNECTION_LOG_ARGD(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con)), (con)
gboolean nms_keyfile_utils_should_ignore_file (const char *filename);
diff --git a/src/tests/test-wired-defname.c b/src/tests/test-wired-defname.c
index a966ed2181..97a6c319c9 100644
--- a/src/tests/test-wired-defname.c
+++ b/src/tests/test-wired-defname.c
@@ -44,15 +44,14 @@ _new_connection (const char *id)
static char *
_get_default_wired_name (GSList *list)
{
- gs_free NMConnection **v = NULL;
- guint l, i;
-
- l = g_slist_length (list);
- v = g_new0 (NMConnection *, l + 1);
- for (i = 0; list; list = list->next, i++)
- v[i] = NM_CONNECTION (list->data);
- g_assert (i == l);
- return nm_device_ethernet_utils_get_default_wired_name (v);
+ gs_unref_hashtable GHashTable *existing_ids = NULL;
+
+ if (list) {
+ existing_ids = g_hash_table_new (nm_str_hash, g_str_equal);
+ for (; list; list = list->next)
+ g_hash_table_add (existing_ids, (char *) nm_connection_get_id (list->data));
+ }
+ return nm_device_ethernet_utils_get_default_wired_name (existing_ids);
}
/*****************************************************************************/
diff --git a/src/vpn/nm-vpn-connection.c b/src/vpn/nm-vpn-connection.c
index ad752c4c1f..f06d94a3a8 100644
--- a/src/vpn/nm-vpn-connection.c
+++ b/src/vpn/nm-vpn-connection.c
@@ -193,7 +193,7 @@ static void _set_vpn_state (NMVpnConnection *self,
#define __NMLOG_prefix_buf_len 128
static const char *
-__LOG_create_prefix (char *buf, NMVpnConnection *self, NMConnection *con)
+__LOG_create_prefix (char *buf, NMVpnConnection *self, NMSettingsConnection *con)
{
NMVpnConnectionPrivate *priv;
const char *id;
@@ -202,7 +202,7 @@ __LOG_create_prefix (char *buf, NMVpnConnection *self, NMConnection *con)
return _NMLOG_PREFIX_NAME;
priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
- id = con ? nm_connection_get_id (con) : NULL;
+ id = con ? nm_settings_connection_get_id (con) : NULL;
g_snprintf (buf, __NMLOG_prefix_buf_len,
"%s["
@@ -214,7 +214,7 @@ __LOG_create_prefix (char *buf, NMVpnConnection *self, NMConnection *con)
"]",
_NMLOG_PREFIX_NAME,
self,
- con ? "," : "--", con ? (nm_connection_get_uuid (con) ?: "??") : "",
+ con ? "," : "--", con ? (nm_settings_connection_get_uuid (con) ?: "??") : "",
con ? "," : "", NM_PRINT_FMT_QUOTED (id, "\"", id, "\"", con ? "??" : ""),
priv->ip_ifindex,
NM_PRINT_FMT_QUOTED (priv->ip_iface, ":(", priv->ip_iface, ")", "")
@@ -225,17 +225,17 @@ __LOG_create_prefix (char *buf, NMVpnConnection *self, NMConnection *con)
#define _NMLOG(level, ...) \
G_STMT_START { \
- const NMLogLevel __level = (level); \
- NMConnection *__con = (self) ? (NMConnection *) _get_settings_connection (self, TRUE) : NULL; \
+ const NMLogLevel _level = (level); \
+ NMSettingsConnection *_con = (self) ? _get_settings_connection (self, TRUE) : NULL; \
\
- if (nm_logging_enabled (__level, _NMLOG_DOMAIN)) { \
+ if (nm_logging_enabled (_level, _NMLOG_DOMAIN)) { \
char __prefix[__NMLOG_prefix_buf_len]; \
\
- _nm_log (__level, _NMLOG_DOMAIN, 0, \
+ _nm_log (_level, _NMLOG_DOMAIN, 0, \
(self) ? NM_VPN_CONNECTION_GET_PRIVATE (self)->ip_iface : NULL, \
- (__con) ? nm_connection_get_uuid (__con) : NULL, \
+ (_con) ? nm_settings_connection_get_uuid (_con) : NULL, \
"%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
- __LOG_create_prefix (__prefix, (self), __con) \
+ __LOG_create_prefix (__prefix, (self), _con) \
_NM_UTILS_MACRO_REST (__VA_ARGS__)); \
} \
} G_STMT_END