From bed2fa1bec3af102c60a3871d0f86a546b7c2a0c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 8 Mar 2017 12:22:01 +0100 Subject: [PATCH] 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. --- src/devices/nm-device.c | 20 ++++++---------- src/nm-active-connection.c | 14 +++++++---- src/nm-core-utils.c | 5 ++-- src/nm-dispatcher.c | 49 ++++++++++++++++++++++++++------------ src/nm-manager.c | 14 ++++++----- src/nm-types.h | 5 ++++ 6 files changed, 67 insertions(+), 40 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 83027588b..efa365c77 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1602,16 +1602,10 @@ static gboolean nm_device_has_activation_type_external (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMSettingsConnection *connection; - if ( priv->act_request - && nm_active_connection_has_activation_type_assume_or_external (NM_ACTIVE_CONNECTION (priv->act_request))) { - connection = nm_act_request_get_settings_connection (priv->act_request); - if ( connection - && nm_settings_connection_get_volatile (connection)) - return TRUE; - } - return FALSE; + return priv->act_request + && NM_IN_SET (nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)), + NM_ACTIVATION_TYPE_EXTERNAL); } gboolean @@ -1619,10 +1613,10 @@ nm_device_has_activation_type_assume_or_external (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - if ( priv->act_request - && nm_active_connection_has_activation_type_assume_or_external (NM_ACTIVE_CONNECTION (priv->act_request))) - return TRUE; - return FALSE; + return priv->act_request + && NM_IN_SET (nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (priv->act_request)), + NM_ACTIVATION_TYPE_ASSUME, + NM_ACTIVATION_TYPE_EXTERNAL); } static SlaveInfo * diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index 78dd95a93..c4cd6c85c 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -51,6 +51,8 @@ typedef struct _NMActiveConnectionPrivate { bool vpn: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; NMAuthSubject *subject; @@ -567,7 +569,7 @@ nm_active_connection_set_device (NMActiveConnection *self, NMDevice *device) g_signal_connect (device, "notify::" NM_DEVICE_METERED, 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); nm_device_add_pending_action (device, priv->pending_activation_id, TRUE); } @@ -724,7 +726,9 @@ nm_active_connection_get_activation_type (NMActiveConnection *self) gboolean 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, case PROP_INT_ACTIVATION_TYPE: /* construct-only */ 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 (); priv->activation_type = (NMActivationType) i; break; @@ -1331,7 +1337,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) obj_properties[PROP_INT_ACTIVATION_TYPE] = g_param_spec_int (NM_ACTIVE_CONNECTION_INT_ACTIVATION_TYPE, "", "", NM_ACTIVATION_TYPE_MANAGED, - NM_ACTIVATION_TYPE_ASSUME, + NM_ACTIVATION_TYPE_EXTERNAL, NM_ACTIVATION_TYPE_MANAGED, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 25b126219..adef77e29 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -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_DEFAULT_WARN ("(unknown)"), - 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_MANAGED, "managed"), + NM_UTILS_LOOKUP_STR_ITEM (NM_ACTIVATION_TYPE_ASSUME, "assume"), + NM_UTILS_LOOKUP_STR_ITEM (NM_ACTIVATION_TYPE_EXTERNAL, "external"), ) diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index 4fa4ce6ab..1bb26e1c4 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -478,9 +478,10 @@ dispatcher_idle_cb (gpointer user_data) static gboolean _dispatcher_call (NMDispatcherAction action, gboolean blocking, + NMDevice *device, NMSettingsConnection *settings_connection, NMConnection *applied_connection, - NMDevice *device, + gboolean activation_type_external, NMConnectivityState connectivity_state, const char *vpn_iface, NMProxyConfig *vpn_proxy_config, @@ -575,7 +576,7 @@ _dispatcher_call (NMDispatcherAction action, NMD_CONNECTION_PROPS_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}", NMD_CONNECTION_PROPS_EXTERNAL, g_variant_new_boolean (TRUE)); @@ -711,8 +712,10 @@ nm_dispatcher_call_hostname (NMDispatcherFunc callback, gpointer user_data, guint *out_call_id) { - return _dispatcher_call (NM_DISPATCHER_ACTION_HOSTNAME, FALSE, NULL, NULL, NULL, - NM_CONNECTIVITY_UNKNOWN, NULL, NULL, NULL, NULL, + return _dispatcher_call (NM_DISPATCHER_ACTION_HOSTNAME, FALSE, + NULL, NULL, NULL, FALSE, + NM_CONNECTIVITY_UNKNOWN, + NULL, NULL, NULL, NULL, callback, user_data, out_call_id); } @@ -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)); return _dispatcher_call (action, FALSE, + device, nm_act_request_get_settings_connection (act_request), nm_act_request_get_applied_connection (act_request), - device, - NM_CONNECTIVITY_UNKNOWN, NULL, NULL, NULL, NULL, + nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (act_request)) == NM_ACTIVATION_TYPE_EXTERNAL, + NM_CONNECTIVITY_UNKNOWN, + NULL, NULL, NULL, NULL, callback, user_data, out_call_id); } @@ -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)); return _dispatcher_call (action, TRUE, + device, nm_act_request_get_settings_connection (act_request), nm_act_request_get_applied_connection (act_request), - device, - NM_CONNECTIVITY_UNKNOWN, NULL, NULL, NULL, NULL, + nm_active_connection_get_activation_type (NM_ACTIVE_CONNECTION (act_request)) == NM_ACTIVATION_TYPE_EXTERNAL, + NM_CONNECTIVITY_UNKNOWN, + NULL, NULL, NULL, NULL, NULL, NULL, NULL); } @@ -820,9 +827,14 @@ nm_dispatcher_call_vpn (NMDispatcherAction action, gpointer user_data, guint *out_call_id) { - return _dispatcher_call (action, FALSE, settings_connection, applied_connection, - parent_device, NM_CONNECTIVITY_UNKNOWN, vpn_iface, vpn_proxy_config, - vpn_ip4_config, vpn_ip6_config, callback, user_data, out_call_id); + return _dispatcher_call (action, FALSE, + parent_device, + 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, NMIP4Config *vpn_ip4_config, NMIP6Config *vpn_ip6_config) { - return _dispatcher_call (action, TRUE, settings_connection, applied_connection, - parent_device, NM_CONNECTIVITY_UNKNOWN, vpn_iface, vpn_proxy_config, - vpn_ip4_config, vpn_ip6_config, NULL, NULL, NULL); + return _dispatcher_call (action, TRUE, + parent_device, + 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, gpointer user_data, 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, callback, user_data, out_call_id); } diff --git a/src/nm-manager.c b/src/nm-manager.c index 831b04820..e273bff8c 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1698,9 +1698,6 @@ done: static gboolean 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); } @@ -1818,7 +1815,10 @@ get_existing_connection (NMManager *self, NMDevice *device, gboolean *out_genera } static gboolean -assume_connection (NMManager *self, NMDevice *device, NMSettingsConnection *connection) +assume_connection (NMManager *self, + NMDevice *device, + NMSettingsConnection *connection, + gboolean generated) { NMActiveConnection *active, *master_ac; NMAuthSubject *subject; @@ -1837,7 +1837,9 @@ assume_connection (NMManager *self, NMDevice *device, NMSettingsConnection *conn subject = nm_auth_subject_new_internal (); 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); if (!active) { @@ -1895,7 +1897,7 @@ recheck_assume_connection (NMManager *self, NMDevice *device) NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED); } - success = assume_connection (self, device, connection); + success = assume_connection (self, device, connection, generated); if (!success) { if (was_unmanaged) { nm_device_state_changed (device, diff --git a/src/nm-types.h b/src/nm-types.h index cf5f4cb0a..32f4198ad 100644 --- a/src/nm-types.h +++ b/src/nm-types.h @@ -64,6 +64,11 @@ typedef enum { /* gracefully/seamlessly take over the device. This leaves additional * IP addresses and does not restore missing manual addresses. */ 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; typedef enum {