Commit 07a42191 authored by Thomas Haller's avatar Thomas Haller Committed by Beniamino Galvani

core: extend nm_manager_get_activatable_connections() for autoconnect and multi-connect

In general, a activatable connection is one that is currently not
active, or supports to be activatable multiple times according to
multi-connect setting. In addition, during autoconnect, a profile
which is marked as multi-connect=manual-multiple will not be avalable.
Hence, add an argument "for_auto_activation".

The code is mostly unused but will be used next (except for connections,
which set connection.multi-connect=multiple).
parent 55ae6923
......@@ -1024,28 +1024,53 @@ active_connection_find_by_connection (NMManager *self,
out_all_matching);
}
typedef struct {
NMManager *self;
gboolean for_auto_activation;
} GetActivatableConnectionsFilterData;
static gboolean
_get_activatable_connections_filter (NMSettings *settings,
NMSettingsConnection *connection,
gpointer user_data)
{
const GetActivatableConnectionsFilterData *d = user_data;
NMConnectionMultiConnect multi_connect;
if (NM_FLAGS_HAS (nm_settings_connection_get_flags (connection),
NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE))
return FALSE;
multi_connect = _nm_connection_get_multi_connect (NM_CONNECTION (connection));
if ( multi_connect == NM_CONNECTION_MULTI_CONNECT_MULTIPLE
|| ( multi_connect == NM_CONNECTION_MULTI_CONNECT_MANUAL_MULTIPLE
&& !d->for_auto_activation))
return TRUE;
/* 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 (user_data, connection, NULL, NM_ACTIVE_CONNECTION_STATE_ACTIVATED, NULL);
return !active_connection_find (d->self,
connection,
NULL,
NM_ACTIVE_CONNECTION_STATE_ACTIVATED,
NULL);
}
NMSettingsConnection **
nm_manager_get_activatable_connections (NMManager *manager, guint *out_len, gboolean sort)
nm_manager_get_activatable_connections (NMManager *manager,
gboolean for_auto_activation,
gboolean sort,
guint *out_len)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
const GetActivatableConnectionsFilterData d = {
.self = manager,
.for_auto_activation = for_auto_activation,
};
return nm_settings_get_connections_clone (priv->settings, out_len,
_get_activatable_connections_filter,
manager,
(gpointer) &d,
sort ? nm_settings_connection_cmp_autoconnect_priority_p_with_data : NULL,
NULL);
}
......@@ -2495,7 +2520,7 @@ get_existing_connection (NMManager *self,
/* 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, &len, FALSE);
connections = 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]);
......@@ -3683,7 +3708,7 @@ ensure_master_active_connection (NMManager *self,
g_assert (master_connection == NULL);
/* Find a compatible connection and activate this device using it */
connections = nm_manager_get_activatable_connections (self, NULL, TRUE);
connections = nm_manager_get_activatable_connections (self, FALSE, TRUE, NULL);
for (i = 0; connections[i]; i++) {
NMSettingsConnection *candidate = connections[i];
......
......@@ -98,8 +98,9 @@ const CList * nm_manager_get_active_connections (NMManager *manager);
iter = c_list_entry (iter->active_connections_lst.next, NMActiveConnection, active_connections_lst))
NMSettingsConnection **nm_manager_get_activatable_connections (NMManager *manager,
guint *out_len,
gboolean sort);
gboolean for_auto_activation,
gboolean sort,
guint *out_len);
void nm_manager_write_device_state_all (NMManager *manager);
gboolean nm_manager_write_device_state (NMManager *manager, NMDevice *device);
......
......@@ -1235,7 +1235,7 @@ auto_activate_device (NMPolicy *self,
if (!nm_device_autoconnect_allowed (device))
return;
connections = nm_manager_get_activatable_connections (priv->manager, &len, TRUE);
connections = nm_manager_get_activatable_connections (priv->manager, FALSE, TRUE, &len);
if (!connections[0])
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment