Commit bed2fa1b authored by Thomas Haller's avatar Thomas Haller

core: track external activations types in the active-connection

We need a distinction between external activations and assuming
connections. The former shall have the meaning of devices that are
*not* managed by NetworkManager, the latter are configurations that
are gracefully taken over after restart (but fully managed).

Express that in the activation-type of the active connection.

Also, no longer use the settings NM_SETTINGS_CONNECTION_FLAGS_VOLATILE
flag to determine whether an assumed connection is "external". These
concepts are entirely orthogonal (although in pratice, external
activations are in-memory and flagged as volatile, but the inverse
is not necessarily true).

Also change match_connection_filter() to consider all connections.
Later, we only call nm_utils_match_connection() for the connection
we want to assume -- which will be a regular settings connection,
not a generated one.
parent fa015f2a
...@@ -1602,16 +1602,10 @@ static gboolean ...@@ -1602,16 +1602,10 @@ static gboolean
nm_device_has_activation_type_external (NMDevice *self) nm_device_has_activation_type_external (NMDevice *self)
{ {
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMSettingsConnection *connection;
if ( priv->act_request return priv->act_request
&& nm_active_connection_has_activation_type_assume_or_external (NM_ACTIVE_CONNECTION (priv->act_request))) { && NM_IN_SET (nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)),
connection = nm_act_request_get_settings_connection (priv->act_request); NM_ACTIVATION_TYPE_EXTERNAL);
if ( connection
&& nm_settings_connection_get_volatile (connection))
return TRUE;
}
return FALSE;
} }
gboolean gboolean
...@@ -1619,10 +1613,10 @@ nm_device_has_activation_type_assume_or_external (NMDevice *self) ...@@ -1619,10 +1613,10 @@ nm_device_has_activation_type_assume_or_external (NMDevice *self)
{ {
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
if ( priv->act_request return priv->act_request
&& nm_active_connection_has_activation_type_assume_or_external (NM_ACTIVE_CONNECTION (priv->act_request))) && NM_IN_SET (nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)),
return TRUE; NM_ACTIVATION_TYPE_ASSUME,
return FALSE; NM_ACTIVATION_TYPE_EXTERNAL);
} }
static SlaveInfo * static SlaveInfo *
......
...@@ -51,6 +51,8 @@ typedef struct _NMActiveConnectionPrivate { ...@@ -51,6 +51,8 @@ typedef struct _NMActiveConnectionPrivate {
bool vpn:1; bool vpn:1;
bool master_ready:1; bool master_ready:1;
/* TODO: when the user updates a connection with an extern activation
* type, the activation type must be updated to FULL. */
NMActivationType activation_type:3; NMActivationType activation_type:3;
NMAuthSubject *subject; NMAuthSubject *subject;
...@@ -567,7 +569,7 @@ nm_active_connection_set_device (NMActiveConnection *self, NMDevice *device) ...@@ -567,7 +569,7 @@ nm_active_connection_set_device (NMActiveConnection *self, NMDevice *device)
g_signal_connect (device, "notify::" NM_DEVICE_METERED, g_signal_connect (device, "notify::" NM_DEVICE_METERED,
G_CALLBACK (device_metered_changed), self); G_CALLBACK (device_metered_changed), self);
if (priv->activation_type == NM_ACTIVATION_TYPE_MANAGED) { if (priv->activation_type != NM_ACTIVATION_TYPE_EXTERNAL) {
priv->pending_activation_id = g_strdup_printf (NM_PENDING_ACTIONPREFIX_ACTIVATION"%p", (void *)self); priv->pending_activation_id = g_strdup_printf (NM_PENDING_ACTIONPREFIX_ACTIVATION"%p", (void *)self);
nm_device_add_pending_action (device, priv->pending_activation_id, TRUE); nm_device_add_pending_action (device, priv->pending_activation_id, TRUE);
} }
...@@ -724,7 +726,9 @@ nm_active_connection_get_activation_type (NMActiveConnection *self) ...@@ -724,7 +726,9 @@ nm_active_connection_get_activation_type (NMActiveConnection *self)
gboolean gboolean
nm_active_connection_has_activation_type_assume_or_external (NMActiveConnection *self) nm_active_connection_has_activation_type_assume_or_external (NMActiveConnection *self)
{ {
return nm_active_connection_get_activation_type (self) == NM_ACTIVATION_TYPE_ASSUME; return NM_IN_SET (nm_active_connection_get_activation_type (self),
NM_ACTIVATION_TYPE_ASSUME,
NM_ACTIVATION_TYPE_EXTERNAL);
} }
/*****************************************************************************/ /*****************************************************************************/
...@@ -1081,7 +1085,9 @@ set_property (GObject *object, guint prop_id, ...@@ -1081,7 +1085,9 @@ set_property (GObject *object, guint prop_id,
case PROP_INT_ACTIVATION_TYPE: case PROP_INT_ACTIVATION_TYPE:
/* construct-only */ /* construct-only */
i = g_value_get_int (value); i = g_value_get_int (value);
if (!NM_IN_SET (i, NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_ASSUME)) if (!NM_IN_SET (i, NM_ACTIVATION_TYPE_MANAGED,
NM_ACTIVATION_TYPE_ASSUME,
NM_ACTIVATION_TYPE_EXTERNAL))
g_return_if_reached (); g_return_if_reached ();
priv->activation_type = (NMActivationType) i; priv->activation_type = (NMActivationType) i;
break; break;
...@@ -1331,7 +1337,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) ...@@ -1331,7 +1337,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
obj_properties[PROP_INT_ACTIVATION_TYPE] = obj_properties[PROP_INT_ACTIVATION_TYPE] =
g_param_spec_int (NM_ACTIVE_CONNECTION_INT_ACTIVATION_TYPE, "", "", g_param_spec_int (NM_ACTIVE_CONNECTION_INT_ACTIVATION_TYPE, "", "",
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
NM_ACTIVATION_TYPE_ASSUME, NM_ACTIVATION_TYPE_EXTERNAL,
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
G_PARAM_WRITABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
......
...@@ -4344,6 +4344,7 @@ nm_utils_format_con_diff_for_audit (GHashTable *diff) ...@@ -4344,6 +4344,7 @@ nm_utils_format_con_diff_for_audit (GHashTable *diff)
NM_UTILS_LOOKUP_STR_DEFINE (nm_activation_type_to_string, NMActivationType, NM_UTILS_LOOKUP_STR_DEFINE (nm_activation_type_to_string, NMActivationType,
NM_UTILS_LOOKUP_DEFAULT_WARN ("(unknown)"), NM_UTILS_LOOKUP_DEFAULT_WARN ("(unknown)"),
NM_UTILS_LOOKUP_STR_ITEM (NM_ACTIVATION_TYPE_MANAGED, "managed"), NM_UTILS_LOOKUP_STR_ITEM (NM_ACTIVATION_TYPE_MANAGED, "managed"),
NM_UTILS_LOOKUP_STR_ITEM (NM_ACTIVATION_TYPE_ASSUME, "assume"), NM_UTILS_LOOKUP_STR_ITEM (NM_ACTIVATION_TYPE_ASSUME, "assume"),
NM_UTILS_LOOKUP_STR_ITEM (NM_ACTIVATION_TYPE_EXTERNAL, "external"),
) )
...@@ -478,9 +478,10 @@ dispatcher_idle_cb (gpointer user_data) ...@@ -478,9 +478,10 @@ dispatcher_idle_cb (gpointer user_data)
static gboolean static gboolean
_dispatcher_call (NMDispatcherAction action, _dispatcher_call (NMDispatcherAction action,
gboolean blocking, gboolean blocking,
NMDevice *device,
NMSettingsConnection *settings_connection, NMSettingsConnection *settings_connection,
NMConnection *applied_connection, NMConnection *applied_connection,
NMDevice *device, gboolean activation_type_external,
NMConnectivityState connectivity_state, NMConnectivityState connectivity_state,
const char *vpn_iface, const char *vpn_iface,
NMProxyConfig *vpn_proxy_config, NMProxyConfig *vpn_proxy_config,
...@@ -575,7 +576,7 @@ _dispatcher_call (NMDispatcherAction action, ...@@ -575,7 +576,7 @@ _dispatcher_call (NMDispatcherAction action,
NMD_CONNECTION_PROPS_FILENAME, NMD_CONNECTION_PROPS_FILENAME,
g_variant_new_string (filename)); g_variant_new_string (filename));
} }
if (nm_settings_connection_get_volatile (settings_connection)) { if (activation_type_external) {
g_variant_builder_add (&connection_props, "{sv}", g_variant_builder_add (&connection_props, "{sv}",
NMD_CONNECTION_PROPS_EXTERNAL, NMD_CONNECTION_PROPS_EXTERNAL,
g_variant_new_boolean (TRUE)); g_variant_new_boolean (TRUE));
...@@ -711,8 +712,10 @@ nm_dispatcher_call_hostname (NMDispatcherFunc callback, ...@@ -711,8 +712,10 @@ nm_dispatcher_call_hostname (NMDispatcherFunc callback,
gpointer user_data, gpointer user_data,
guint *out_call_id) guint *out_call_id)
{ {
return _dispatcher_call (NM_DISPATCHER_ACTION_HOSTNAME, FALSE, NULL, NULL, NULL, return _dispatcher_call (NM_DISPATCHER_ACTION_HOSTNAME, FALSE,
NM_CONNECTIVITY_UNKNOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, FALSE,
NM_CONNECTIVITY_UNKNOWN,
NULL, NULL, NULL, NULL,
callback, user_data, out_call_id); callback, user_data, out_call_id);
} }
...@@ -748,10 +751,12 @@ nm_dispatcher_call_device (NMDispatcherAction action, ...@@ -748,10 +751,12 @@ nm_dispatcher_call_device (NMDispatcherAction action,
} }
nm_assert (NM_IN_SET (nm_active_connection_get_device (NM_ACTIVE_CONNECTION (act_request)), NULL, device)); nm_assert (NM_IN_SET (nm_active_connection_get_device (NM_ACTIVE_CONNECTION (act_request)), NULL, device));
return _dispatcher_call (action, FALSE, return _dispatcher_call (action, FALSE,
device,
nm_act_request_get_settings_connection (act_request), nm_act_request_get_settings_connection (act_request),
nm_act_request_get_applied_connection (act_request), nm_act_request_get_applied_connection (act_request),
device, nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (act_request)) == NM_ACTIVATION_TYPE_EXTERNAL,
NM_CONNECTIVITY_UNKNOWN, NULL, NULL, NULL, NULL, NM_CONNECTIVITY_UNKNOWN,
NULL, NULL, NULL, NULL,
callback, user_data, out_call_id); callback, user_data, out_call_id);
} }
...@@ -780,10 +785,12 @@ nm_dispatcher_call_device_sync (NMDispatcherAction action, ...@@ -780,10 +785,12 @@ nm_dispatcher_call_device_sync (NMDispatcherAction action,
} }
nm_assert (NM_IN_SET (nm_active_connection_get_device (NM_ACTIVE_CONNECTION (act_request)), NULL, device)); nm_assert (NM_IN_SET (nm_active_connection_get_device (NM_ACTIVE_CONNECTION (act_request)), NULL, device));
return _dispatcher_call (action, TRUE, return _dispatcher_call (action, TRUE,
device,
nm_act_request_get_settings_connection (act_request), nm_act_request_get_settings_connection (act_request),
nm_act_request_get_applied_connection (act_request), nm_act_request_get_applied_connection (act_request),
device, nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (act_request)) == NM_ACTIVATION_TYPE_EXTERNAL,
NM_CONNECTIVITY_UNKNOWN, NULL, NULL, NULL, NULL, NM_CONNECTIVITY_UNKNOWN,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
} }
...@@ -820,9 +827,14 @@ nm_dispatcher_call_vpn (NMDispatcherAction action, ...@@ -820,9 +827,14 @@ nm_dispatcher_call_vpn (NMDispatcherAction action,
gpointer user_data, gpointer user_data,
guint *out_call_id) guint *out_call_id)
{ {
return _dispatcher_call (action, FALSE, settings_connection, applied_connection, return _dispatcher_call (action, FALSE,
parent_device, NM_CONNECTIVITY_UNKNOWN, vpn_iface, vpn_proxy_config, parent_device,
vpn_ip4_config, vpn_ip6_config, callback, user_data, out_call_id); settings_connection,
applied_connection,
FALSE,
NM_CONNECTIVITY_UNKNOWN,
vpn_iface, vpn_proxy_config, vpn_ip4_config, vpn_ip6_config,
callback, user_data, out_call_id);
} }
/** /**
...@@ -851,9 +863,14 @@ nm_dispatcher_call_vpn_sync (NMDispatcherAction action, ...@@ -851,9 +863,14 @@ nm_dispatcher_call_vpn_sync (NMDispatcherAction action,
NMIP4Config *vpn_ip4_config, NMIP4Config *vpn_ip4_config,
NMIP6Config *vpn_ip6_config) NMIP6Config *vpn_ip6_config)
{ {
return _dispatcher_call (action, TRUE, settings_connection, applied_connection, return _dispatcher_call (action, TRUE,
parent_device, NM_CONNECTIVITY_UNKNOWN, vpn_iface, vpn_proxy_config, parent_device,
vpn_ip4_config, vpn_ip6_config, NULL, NULL, NULL); settings_connection,
applied_connection,
FALSE,
NM_CONNECTIVITY_UNKNOWN,
vpn_iface, vpn_proxy_config, vpn_ip4_config, vpn_ip6_config,
NULL, NULL, NULL);
} }
/** /**
...@@ -874,7 +891,9 @@ nm_dispatcher_call_connectivity (NMConnectivityState connectivity_state, ...@@ -874,7 +891,9 @@ nm_dispatcher_call_connectivity (NMConnectivityState connectivity_state,
gpointer user_data, gpointer user_data,
guint *out_call_id) guint *out_call_id)
{ {
return _dispatcher_call (NM_DISPATCHER_ACTION_CONNECTIVITY_CHANGE, FALSE, NULL, NULL, NULL, connectivity_state, return _dispatcher_call (NM_DISPATCHER_ACTION_CONNECTIVITY_CHANGE, FALSE,
NULL, NULL, NULL, FALSE,
connectivity_state,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
callback, user_data, out_call_id); callback, user_data, out_call_id);
} }
......
...@@ -1698,9 +1698,6 @@ done: ...@@ -1698,9 +1698,6 @@ done:
static gboolean static gboolean
match_connection_filter (NMConnection *connection, gpointer user_data) match_connection_filter (NMConnection *connection, gpointer user_data)
{ {
if (nm_settings_connection_get_volatile (NM_SETTINGS_CONNECTION (connection)))
return FALSE;
return nm_device_check_connection_compatible (NM_DEVICE (user_data), connection); return nm_device_check_connection_compatible (NM_DEVICE (user_data), connection);
} }
...@@ -1818,7 +1815,10 @@ get_existing_connection (NMManager *self, NMDevice *device, gboolean *out_genera ...@@ -1818,7 +1815,10 @@ get_existing_connection (NMManager *self, NMDevice *device, gboolean *out_genera
} }
static gboolean static gboolean
assume_connection (NMManager *self, NMDevice *device, NMSettingsConnection *connection) assume_connection (NMManager *self,
NMDevice *device,
NMSettingsConnection *connection,
gboolean generated)
{ {
NMActiveConnection *active, *master_ac; NMActiveConnection *active, *master_ac;
NMAuthSubject *subject; NMAuthSubject *subject;
...@@ -1837,7 +1837,9 @@ assume_connection (NMManager *self, NMDevice *device, NMSettingsConnection *conn ...@@ -1837,7 +1837,9 @@ assume_connection (NMManager *self, NMDevice *device, NMSettingsConnection *conn
subject = nm_auth_subject_new_internal (); subject = nm_auth_subject_new_internal ();
active = _new_active_connection (self, NM_CONNECTION (connection), NULL, NULL, active = _new_active_connection (self, NM_CONNECTION (connection), NULL, NULL,
device, subject, NM_ACTIVATION_TYPE_ASSUME, &error); device, subject,
generated ? NM_ACTIVATION_TYPE_EXTERNAL : NM_ACTIVATION_TYPE_ASSUME,
&error);
g_object_unref (subject); g_object_unref (subject);
if (!active) { if (!active) {
...@@ -1895,7 +1897,7 @@ recheck_assume_connection (NMManager *self, NMDevice *device) ...@@ -1895,7 +1897,7 @@ recheck_assume_connection (NMManager *self, NMDevice *device)
NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED); NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED);
} }
success = assume_connection (self, device, connection); success = assume_connection (self, device, connection, generated);
if (!success) { if (!success) {
if (was_unmanaged) { if (was_unmanaged) {
nm_device_state_changed (device, nm_device_state_changed (device,
......
...@@ -64,6 +64,11 @@ typedef enum { ...@@ -64,6 +64,11 @@ typedef enum {
/* gracefully/seamlessly take over the device. This leaves additional /* gracefully/seamlessly take over the device. This leaves additional
* IP addresses and does not restore missing manual addresses. */ * IP addresses and does not restore missing manual addresses. */
NM_ACTIVATION_TYPE_ASSUME = 1, NM_ACTIVATION_TYPE_ASSUME = 1,
/* external activation. This device is not managed by NM, instead
* a in-memory connection is generated and NM pretends the device
* to be active, but it doesn't do anything really. */
NM_ACTIVATION_TYPE_EXTERNAL = 2,
} NMActivationType; } NMActivationType;
typedef enum { typedef enum {
......
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