core: specify an activation reason for active connections

Specify a reason when creating active connections. The reason will be
used in the next commit to tell whether slaves must be reconnected or
not if a master has autoconnect-slaves=yes.
This commit is contained in:
Beniamino Galvani
2018-03-28 17:18:04 +02:00
parent d607f28899
commit 43a0f47ea2
11 changed files with 78 additions and 7 deletions

View File

@@ -537,7 +537,8 @@ nm_act_request_init (NMActRequest *req)
* @specific_object: the object path of the specific object (ie, WiFi access point, * @specific_object: the object path of the specific object (ie, WiFi access point,
* etc) that will be used to activate @connection and @device * etc) that will be used to activate @connection and @device
* @subject: the #NMAuthSubject representing the requestor of the activation * @subject: the #NMAuthSubject representing the requestor of the activation
* @activation_type: the #NMActivationType. * @activation_type: the #NMActivationType
* @activation_reason: the reason for activation
* @device: the device/interface to configure according to @connection * @device: the device/interface to configure according to @connection
* *
* Creates a new device-based activation request. If an applied connection is * Creates a new device-based activation request. If an applied connection is
@@ -551,6 +552,7 @@ nm_act_request_new (NMSettingsConnection *settings_connection,
const char *specific_object, const char *specific_object,
NMAuthSubject *subject, NMAuthSubject *subject,
NMActivationType activation_type, NMActivationType activation_type,
NMActivationReason activation_reason,
NMDevice *device) NMDevice *device)
{ {
g_return_val_if_fail (!settings_connection || NM_IS_SETTINGS_CONNECTION (settings_connection), NULL); g_return_val_if_fail (!settings_connection || NM_IS_SETTINGS_CONNECTION (settings_connection), NULL);
@@ -564,6 +566,7 @@ nm_act_request_new (NMSettingsConnection *settings_connection,
NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object, NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object,
NM_ACTIVE_CONNECTION_INT_SUBJECT, subject, NM_ACTIVE_CONNECTION_INT_SUBJECT, subject,
NM_ACTIVE_CONNECTION_INT_ACTIVATION_TYPE, (int) activation_type, NM_ACTIVE_CONNECTION_INT_ACTIVATION_TYPE, (int) activation_type,
NM_ACTIVE_CONNECTION_INT_ACTIVATION_REASON, (int) activation_reason,
NULL); NULL);
} }

View File

@@ -41,6 +41,7 @@ NMActRequest *nm_act_request_new (NMSettingsConnection *settings_connec
const char *specific_object, const char *specific_object,
NMAuthSubject *subject, NMAuthSubject *subject,
NMActivationType activation_type, NMActivationType activation_type,
NMActivationReason activation_reason,
NMDevice *device); NMDevice *device);
NMSettingsConnection *nm_act_request_get_settings_connection (NMActRequest *req); NMSettingsConnection *nm_act_request_get_settings_connection (NMActRequest *req);

View File

@@ -52,6 +52,7 @@ typedef struct _NMActiveConnectionPrivate {
bool master_ready:1; bool master_ready:1;
NMActivationType activation_type:3; NMActivationType activation_type:3;
NMActivationReason activation_reason:3;
NMAuthSubject *subject; NMAuthSubject *subject;
NMActiveConnection *master; NMActiveConnection *master;
@@ -90,6 +91,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMActiveConnection,
PROP_INT_MASTER, PROP_INT_MASTER,
PROP_INT_MASTER_READY, PROP_INT_MASTER_READY,
PROP_INT_ACTIVATION_TYPE, PROP_INT_ACTIVATION_TYPE,
PROP_INT_ACTIVATION_REASON,
); );
enum { enum {
@@ -892,6 +894,14 @@ _set_activation_type_managed (NMActiveConnection *self)
nm_device_sys_iface_state_set (priv->device, NM_DEVICE_SYS_IFACE_STATE_MANAGED); nm_device_sys_iface_state_set (priv->device, NM_DEVICE_SYS_IFACE_STATE_MANAGED);
} }
NMActivationReason
nm_active_connection_get_activation_reason (NMActiveConnection *self)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), NM_ACTIVATION_REASON_UNSET);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->activation_reason;
}
/*****************************************************************************/ /*****************************************************************************/
static void static void
@@ -1291,6 +1301,12 @@ set_property (GObject *object, guint prop_id,
g_return_if_reached (); g_return_if_reached ();
_set_activation_type (self, (NMActivationType) i); _set_activation_type (self, (NMActivationType) i);
break; break;
case PROP_INT_ACTIVATION_REASON:
/* construct-only */
i = g_value_get_int (value);
priv->activation_reason = i;
nm_assert (priv->activation_reason == ((NMActivationReason) i));
break;
case PROP_SPECIFIC_OBJECT: case PROP_SPECIFIC_OBJECT:
/* construct-only */ /* construct-only */
tmp = g_value_get_string (value); tmp = g_value_get_string (value);
@@ -1598,6 +1614,15 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_INT_ACTIVATION_REASON] =
g_param_spec_int (NM_ACTIVE_CONNECTION_INT_ACTIVATION_REASON, "", "",
NM_ACTIVATION_REASON_UNSET,
NM_ACTIVATION_REASON_USER_REQUEST,
NM_ACTIVATION_REASON_UNSET,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
signals[DEVICE_CHANGED] = signals[DEVICE_CHANGED] =

View File

@@ -53,11 +53,12 @@
/* Internal non-exported properties */ /* Internal non-exported properties */
#define NM_ACTIVE_CONNECTION_INT_SETTINGS_CONNECTION "int-settings-connection" #define NM_ACTIVE_CONNECTION_INT_SETTINGS_CONNECTION "int-settings-connection"
#define NM_ACTIVE_CONNECTION_INT_APPLIED_CONNECTION "int-applied-connection" #define NM_ACTIVE_CONNECTION_INT_APPLIED_CONNECTION "int-applied-connection"
#define NM_ACTIVE_CONNECTION_INT_DEVICE "int-device" #define NM_ACTIVE_CONNECTION_INT_DEVICE "int-device"
#define NM_ACTIVE_CONNECTION_INT_SUBJECT "int-subject" #define NM_ACTIVE_CONNECTION_INT_SUBJECT "int-subject"
#define NM_ACTIVE_CONNECTION_INT_MASTER "int-master" #define NM_ACTIVE_CONNECTION_INT_MASTER "int-master"
#define NM_ACTIVE_CONNECTION_INT_MASTER_READY "int-master-ready" #define NM_ACTIVE_CONNECTION_INT_MASTER_READY "int-master-ready"
#define NM_ACTIVE_CONNECTION_INT_ACTIVATION_TYPE "int-activation-type" #define NM_ACTIVE_CONNECTION_INT_ACTIVATION_TYPE "int-activation-type"
#define NM_ACTIVE_CONNECTION_INT_ACTIVATION_REASON "int-activation-reason"
/* Signals */ /* Signals */
#define NM_ACTIVE_CONNECTION_STATE_CHANGED "state-changed" #define NM_ACTIVE_CONNECTION_STATE_CHANGED "state-changed"
@@ -184,6 +185,8 @@ void nm_active_connection_set_parent (NMActiveConnection *self,
NMActivationType nm_active_connection_get_activation_type (NMActiveConnection *self); NMActivationType nm_active_connection_get_activation_type (NMActiveConnection *self);
NMActivationReason nm_active_connection_get_activation_reason (NMActiveConnection *self);
void nm_active_connection_clear_secrets (NMActiveConnection *self); void nm_active_connection_clear_secrets (NMActiveConnection *self);
#endif /* __NETWORKMANAGER_ACTIVE_CONNECTION_H__ */ #endif /* __NETWORKMANAGER_ACTIVE_CONNECTION_H__ */

View File

@@ -47,6 +47,7 @@ typedef struct {
NMDeviceState state; NMDeviceState state;
bool realized:1; bool realized:1;
NMUnmanFlagOp unmanaged_explicit; NMUnmanFlagOp unmanaged_explicit;
NMActivationReason activation_reason;
} DeviceCheckpoint; } DeviceCheckpoint;
NM_GOBJECT_PROPERTIES_DEFINE (NMCheckpoint, NM_GOBJECT_PROPERTIES_DEFINE (NMCheckpoint,
@@ -333,6 +334,7 @@ activate:
device, device,
subject, subject,
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
dev_checkpoint->activation_reason,
&local_error)) { &local_error)) {
_LOGW ("rollback: reactivation of connection %s/%s failed: %s", _LOGW ("rollback: reactivation of connection %s/%s failed: %s",
nm_connection_get_id ((NMConnection *) connection), nm_connection_get_id ((NMConnection *) connection),
@@ -438,6 +440,8 @@ device_checkpoint_create (NMDevice *device)
nm_simple_connection_new_clone (NM_CONNECTION (settings_connection)); nm_simple_connection_new_clone (NM_CONNECTION (settings_connection));
dev_checkpoint->ac_version_id = dev_checkpoint->ac_version_id =
nm_active_connection_version_id_get (NM_ACTIVE_CONNECTION (act_request)); 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; return dev_checkpoint;

View File

@@ -285,6 +285,7 @@ static NMActiveConnection *_new_active_connection (NMManager *self,
NMDevice *device, NMDevice *device,
NMAuthSubject *subject, NMAuthSubject *subject,
NMActivationType activation_type, NMActivationType activation_type,
NMActivationReason activation_reason,
GError **error); GError **error);
static void policy_activating_device_changed (GObject *object, GParamSpec *pspec, gpointer user_data); static void policy_activating_device_changed (GObject *object, GParamSpec *pspec, gpointer user_data);
@@ -2334,6 +2335,7 @@ recheck_assume_connection (NMManager *self,
active = _new_active_connection (self, NM_CONNECTION (connection), NULL, NULL, active = _new_active_connection (self, NM_CONNECTION (connection), NULL, NULL,
device, subject, device, subject,
generated ? NM_ACTIVATION_TYPE_EXTERNAL : NM_ACTIVATION_TYPE_ASSUME, generated ? NM_ACTIVATION_TYPE_EXTERNAL : NM_ACTIVATION_TYPE_ASSUME,
NM_ACTIVATION_REASON_AUTOCONNECT,
&error); &error);
if (!active) { if (!active) {
@@ -3216,6 +3218,7 @@ find_master (NMManager *self,
* @device: the #NMDevice, if any, which will activate @connection * @device: the #NMDevice, if any, which will activate @connection
* @master_connection: the master connection, or %NULL * @master_connection: the master connection, or %NULL
* @master_device: the master device, or %NULL * @master_device: the master device, or %NULL
* @activation_reason: the reason for activation
* @error: the error, if an error occurred * @error: the error, if an error occurred
* *
* Determines whether a given #NMConnection depends on another connection to * Determines whether a given #NMConnection depends on another connection to
@@ -3243,6 +3246,7 @@ ensure_master_active_connection (NMManager *self,
NMDevice *device, NMDevice *device,
NMSettingsConnection *master_connection, NMSettingsConnection *master_connection,
NMDevice *master_device, NMDevice *master_device,
NMActivationReason activation_reason,
GError **error) GError **error)
{ {
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
@@ -3305,6 +3309,7 @@ ensure_master_active_connection (NMManager *self,
master_device, master_device,
subject, subject,
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
activation_reason,
error); error);
return master_ac; return master_ac;
} }
@@ -3348,6 +3353,7 @@ ensure_master_active_connection (NMManager *self,
candidate, candidate,
subject, subject,
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
activation_reason,
error); error);
return master_ac; return master_ac;
} }
@@ -3570,6 +3576,7 @@ autoconnect_slaves (NMManager *self,
slave->device, slave->device,
subject, subject,
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
NM_ACTIVATION_REASON_AUTOCONNECT_SLAVES,
&local_err); &local_err);
if (local_err) { if (local_err) {
_LOGW (LOGD_CORE, "Slave connection activation failed: %s", local_err->message); _LOGW (LOGD_CORE, "Slave connection activation failed: %s", local_err->message);
@@ -3744,7 +3751,10 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
} }
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, error); subject,
NM_ACTIVATION_TYPE_MANAGED,
nm_active_connection_get_activation_reason (active),
error);
if (!parent_ac) { if (!parent_ac) {
g_prefix_error (error, "%s failed to activate parent: ", nm_device_get_iface (device)); g_prefix_error (error, "%s failed to activate parent: ", nm_device_get_iface (device));
return FALSE; return FALSE;
@@ -3805,6 +3815,7 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
device, device,
master_connection, master_connection,
master_device, master_device,
nm_active_connection_get_activation_reason (active),
error); error);
if (!master_ac) { if (!master_ac) {
if (master_device) { if (master_device) {
@@ -3907,6 +3918,7 @@ _new_vpn_active_connection (NMManager *self,
NMSettingsConnection *settings_connection, NMSettingsConnection *settings_connection,
const char *specific_object, const char *specific_object,
NMAuthSubject *subject, NMAuthSubject *subject,
NMActivationReason activation_reason,
GError **error) GError **error)
{ {
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
@@ -3942,6 +3954,7 @@ _new_vpn_active_connection (NMManager *self,
return (NMActiveConnection *) nm_vpn_connection_new (settings_connection, return (NMActiveConnection *) nm_vpn_connection_new (settings_connection,
device, device,
nm_dbus_object_get_path (NM_DBUS_OBJECT (parent)), nm_dbus_object_get_path (NM_DBUS_OBJECT (parent)),
activation_reason,
subject); subject);
} }
@@ -3953,6 +3966,7 @@ _new_active_connection (NMManager *self,
NMDevice *device, NMDevice *device,
NMAuthSubject *subject, NMAuthSubject *subject,
NMActivationType activation_type, NMActivationType activation_type,
NMActivationReason activation_reason,
GError **error) GError **error)
{ {
NMSettingsConnection *settings_connection = NULL; NMSettingsConnection *settings_connection = NULL;
@@ -3987,6 +4001,7 @@ _new_active_connection (NMManager *self,
settings_connection, settings_connection,
specific_object, specific_object,
subject, subject,
activation_reason,
error); error);
} }
@@ -3998,6 +4013,7 @@ _new_active_connection (NMManager *self,
specific_object, specific_object,
subject, subject,
activation_type, activation_type,
activation_reason,
device); device);
} }
@@ -4061,6 +4077,7 @@ _internal_activation_auth_done (NMActiveConnection *active,
* @subject: the subject which requested activation * @subject: the subject which requested activation
* @activation_type: whether to assume the connection. That is, take over gracefully, * @activation_type: whether to assume the connection. That is, take over gracefully,
* non-destructible. * non-destructible.
* @activation_reason: the reason for activation
* @error: return location for an error * @error: return location for an error
* *
* Begins a new internally-initiated activation of @connection on @device. * Begins a new internally-initiated activation of @connection on @device.
@@ -4081,6 +4098,7 @@ nm_manager_activate_connection (NMManager *self,
NMDevice *device, NMDevice *device,
NMAuthSubject *subject, NMAuthSubject *subject,
NMActivationType activation_type, NMActivationType activation_type,
NMActivationReason activation_reason,
GError **error) GError **error)
{ {
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
@@ -4128,6 +4146,7 @@ nm_manager_activate_connection (NMManager *self,
device, device,
subject, subject,
activation_type, activation_type,
activation_reason,
error); error);
if (active) { if (active) {
priv->authorizing_connections = g_slist_prepend (priv->authorizing_connections, active); priv->authorizing_connections = g_slist_prepend (priv->authorizing_connections, active);
@@ -4379,6 +4398,7 @@ impl_manager_activate_connection (NMDBusObject *obj,
device, device,
subject, subject,
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
NM_ACTIVATION_REASON_USER_REQUEST,
&error); &error);
if (!active) if (!active)
goto error; goto error;
@@ -4600,6 +4620,7 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj,
device, device,
subject, subject,
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
NM_ACTIVATION_REASON_USER_REQUEST,
&error); &error);
if (!active) if (!active)
goto error; goto error;

View File

@@ -147,6 +147,7 @@ NMActiveConnection *nm_manager_activate_connection (NMManager *manager,
NMDevice *device, NMDevice *device,
NMAuthSubject *subject, NMAuthSubject *subject,
NMActivationType activation_type, NMActivationType activation_type,
NMActivationReason activation_reason,
GError **error); GError **error);
gboolean nm_manager_deactivate_connection (NMManager *manager, gboolean nm_manager_deactivate_connection (NMManager *manager,

View File

@@ -1252,6 +1252,7 @@ auto_activate_device (NMPolicy *self,
device, device,
subject, subject,
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
NM_ACTIVATION_REASON_AUTOCONNECT,
&error); &error);
if (!ac) { if (!ac) {
_LOGI (LOGD_DEVICE, "connection '%s' auto-activation failed: %s", _LOGI (LOGD_DEVICE, "connection '%s' auto-activation failed: %s",
@@ -1674,6 +1675,7 @@ activate_secondary_connections (NMPolicy *self,
device, device,
nm_active_connection_get_subject (NM_ACTIVE_CONNECTION (req)), nm_active_connection_get_subject (NM_ACTIVE_CONNECTION (req)),
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
nm_active_connection_get_activation_reason (NM_ACTIVE_CONNECTION (req)),
&error); &error);
if (ac) if (ac)
secondary_ac_list = g_slist_append (secondary_ac_list, g_object_ref (ac)); secondary_ac_list = g_slist_append (secondary_ac_list, g_object_ref (ac));
@@ -2115,6 +2117,7 @@ vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *self)
NULL, NULL,
nm_active_connection_get_subject (ac), nm_active_connection_get_subject (ac),
NM_ACTIVATION_TYPE_MANAGED, NM_ACTIVATION_TYPE_MANAGED,
nm_active_connection_get_activation_reason (ac),
&error)) { &error)) {
_LOGW (LOGD_DEVICE, "VPN '%s' reconnect failed: %s", _LOGW (LOGD_DEVICE, "VPN '%s' reconnect failed: %s",
nm_settings_connection_get_id (connection), nm_settings_connection_get_id (connection),

View File

@@ -75,6 +75,13 @@ typedef enum {
NM_ACTIVATION_TYPE_EXTERNAL = 2, NM_ACTIVATION_TYPE_EXTERNAL = 2,
} NMActivationType; } NMActivationType;
typedef enum {
NM_ACTIVATION_REASON_UNSET = 0,
NM_ACTIVATION_REASON_AUTOCONNECT = 1,
NM_ACTIVATION_REASON_AUTOCONNECT_SLAVES = 2,
NM_ACTIVATION_REASON_USER_REQUEST = 3,
} NMActivationReason;
typedef enum { typedef enum {
/* In priority order; higher number == higher priority */ /* In priority order; higher number == higher priority */

View File

@@ -850,6 +850,7 @@ NMVpnConnection *
nm_vpn_connection_new (NMSettingsConnection *settings_connection, nm_vpn_connection_new (NMSettingsConnection *settings_connection,
NMDevice *parent_device, NMDevice *parent_device,
const char *specific_object, const char *specific_object,
NMActivationReason activation_reason,
NMAuthSubject *subject) NMAuthSubject *subject)
{ {
g_return_val_if_fail (!settings_connection || NM_IS_SETTINGS_CONNECTION (settings_connection), NULL); g_return_val_if_fail (!settings_connection || NM_IS_SETTINGS_CONNECTION (settings_connection), NULL);
@@ -860,6 +861,7 @@ nm_vpn_connection_new (NMSettingsConnection *settings_connection,
NM_ACTIVE_CONNECTION_INT_DEVICE, parent_device, NM_ACTIVE_CONNECTION_INT_DEVICE, parent_device,
NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object, NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object,
NM_ACTIVE_CONNECTION_INT_SUBJECT, subject, NM_ACTIVE_CONNECTION_INT_SUBJECT, subject,
NM_ACTIVE_CONNECTION_INT_ACTIVATION_REASON, activation_reason,
NM_ACTIVE_CONNECTION_VPN, TRUE, NM_ACTIVE_CONNECTION_VPN, TRUE,
NULL); NULL);
} }

View File

@@ -52,6 +52,7 @@ GType nm_vpn_connection_get_type (void);
NMVpnConnection * nm_vpn_connection_new (NMSettingsConnection *settings_connection, NMVpnConnection * nm_vpn_connection_new (NMSettingsConnection *settings_connection,
NMDevice *parent_device, NMDevice *parent_device,
const char *specific_object, const char *specific_object,
NMActivationReason activation_reason,
NMAuthSubject *subject); NMAuthSubject *subject);
void nm_vpn_connection_activate (NMVpnConnection *self, void nm_vpn_connection_activate (NMVpnConnection *self,