Commit 5754a056 authored by Beniamino Galvani's avatar Beniamino Galvani

core: allow passing an applied connection to nm_act_request_new()

This is useful for the checkpoint/restore functionality to revert both
the applied and the settings connections.
parent 1a6e3e0a
......@@ -462,17 +462,20 @@ master_failed (NMActiveConnection *self)
* nm_act_request_new:
*
* @settings_connection: (allow-none): the connection to activate @device with
* @applied_connection: (allow-none): the applied connection
* @specific_object: the object path of the specific object (ie, WiFi access point,
* etc) that will be used to activate @connection and @device
* @subject: the #NMAuthSubject representing the requestor of the activation
* @device: the device/interface to configure according to @connection
*
* Creates a new device-based activation request.
* Creates a new device-based activation request. If an applied connection is
* supplied, it shall not be modified by the caller afterwards.
*
* Returns: the new activation request on success, %NULL on error.
*/
NMActRequest *
nm_act_request_new (NMSettingsConnection *settings_connection,
NMConnection *applied_connection,
const char *specific_object,
NMAuthSubject *subject,
NMDevice *device)
......@@ -482,6 +485,7 @@ nm_act_request_new (NMSettingsConnection *settings_connection,
g_return_val_if_fail (NM_IS_AUTH_SUBJECT (subject), NULL);
return (NMActRequest *) g_object_new (NM_TYPE_ACT_REQUEST,
NM_ACTIVE_CONNECTION_INT_APPLIED_CONNECTION, applied_connection,
NM_ACTIVE_CONNECTION_INT_SETTINGS_CONNECTION, settings_connection,
NM_ACTIVE_CONNECTION_INT_DEVICE, device,
NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object,
......
......@@ -46,6 +46,7 @@ typedef struct {
GType nm_act_request_get_type (void);
NMActRequest *nm_act_request_new (NMSettingsConnection *settings_connection,
NMConnection *applied_connection,
const char *specific_object,
NMAuthSubject *subject,
NMDevice *device);
......
......@@ -90,6 +90,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMActiveConnection,
PROP_MASTER,
PROP_INT_SETTINGS_CONNECTION,
PROP_INT_APPLIED_CONNECTION,
PROP_INT_DEVICE,
PROP_INT_SUBJECT,
PROP_INT_MASTER,
......@@ -951,6 +952,14 @@ constructed (GObject *object)
G_OBJECT_CLASS (nm_active_connection_parent_class)->constructed (object);
if (!priv->applied_connection && priv->settings_connection) {
priv->applied_connection =
nm_simple_connection_new_clone ((NMConnection *) priv->settings_connection);
}
if (priv->applied_connection)
nm_connection_clear_secrets (priv->applied_connection);
_LOGD ("constructed (%s, version-id %llu)", G_OBJECT_TYPE_NAME (self), (long long unsigned) priv->version_id);
g_return_if_fail (priv->subject);
......@@ -964,16 +973,20 @@ set_property (GObject *object, guint prop_id,
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
const char *tmp;
NMSettingsConnection *con;
NMConnection *acon;
switch (prop_id) {
case PROP_INT_SETTINGS_CONNECTION:
/* construct-only */
con = g_value_get_object (value);
if (con) {
if (con)
_set_settings_connection (self, con);
priv->applied_connection = nm_simple_connection_new_clone ((NMConnection *) priv->settings_connection);
nm_connection_clear_secrets (priv->applied_connection);
}
break;
case PROP_INT_APPLIED_CONNECTION:
/* construct-only */
acon = g_value_get_object (value);
if (acon)
priv->applied_connection = g_object_ref (acon);
break;
case PROP_INT_DEVICE:
/* construct-only */
......@@ -1259,6 +1272,12 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_INT_APPLIED_CONNECTION] =
g_param_spec_object (NM_ACTIVE_CONNECTION_INT_APPLIED_CONNECTION, "", "",
NM_TYPE_CONNECTION,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_INT_DEVICE] =
g_param_spec_object (NM_ACTIVE_CONNECTION_INT_DEVICE, "", "",
NM_TYPE_DEVICE,
......
......@@ -50,6 +50,7 @@
/* Internal non-exported properties */
#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_DEVICE "int-device"
#define NM_ACTIVE_CONNECTION_INT_SUBJECT "int-subject"
#define NM_ACTIVE_CONNECTION_INT_MASTER "int-master"
......
......@@ -178,6 +178,7 @@ nm_checkpoint_rollback (NMCheckpoint *self)
if (!nm_manager_activate_connection (priv->manager,
connection,
NULL,
NULL,
device,
subject,
&local_error)) {
......
......@@ -64,6 +64,7 @@ static gboolean add_device (NMManager *self, NMDevice *device, GError **error);
static NMActiveConnection *_new_active_connection (NMManager *self,
NMConnection *connection,
NMConnection *applied,
const char *specific_object,
NMDevice *device,
NMAuthSubject *subject,
......@@ -1745,7 +1746,7 @@ assume_connection (NMManager *self, NMDevice *device, NMSettingsConnection *conn
g_return_val_if_fail (nm_device_get_state (device) >= NM_DEVICE_STATE_DISCONNECTED, FALSE);
subject = nm_auth_subject_new_internal ();
active = _new_active_connection (self, NM_CONNECTION (connection), NULL, device, subject, &error);
active = _new_active_connection (self, NM_CONNECTION (connection), NULL, NULL, device, subject, &error);
g_object_unref (subject);
if (!active) {
......@@ -2634,6 +2635,7 @@ ensure_master_active_connection (NMManager *self,
master_ac = nm_manager_activate_connection (self,
candidate,
NULL,
NULL,
master_device,
subject,
error);
......@@ -2680,6 +2682,7 @@ ensure_master_active_connection (NMManager *self,
master_ac = nm_manager_activate_connection (self,
master_connection,
NULL,
NULL,
candidate,
subject,
error);
......@@ -2804,6 +2807,7 @@ autoconnect_slaves (NMManager *self,
nm_manager_activate_connection (self,
slave_connection,
NULL,
NULL,
nm_manager_get_best_device_for_connection (self, NM_CONNECTION (slave_connection), FALSE),
subject,
&local_err);
......@@ -2963,7 +2967,7 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
return FALSE;
}
parent_ac = nm_manager_activate_connection (self, parent_con, NULL, parent, subject, error);
parent_ac = nm_manager_activate_connection (self, parent_con, NULL, NULL, parent, subject, error);
if (!parent_ac) {
g_prefix_error (error, "%s failed to activate parent: ", nm_device_get_iface (device));
return FALSE;
......@@ -3145,6 +3149,7 @@ _new_vpn_active_connection (NMManager *self,
static NMActiveConnection *
_new_active_connection (NMManager *self,
NMConnection *connection,
NMConnection *applied,
const char *specific_object,
NMDevice *device,
NMAuthSubject *subject,
......@@ -3184,6 +3189,7 @@ _new_active_connection (NMManager *self,
}
return (NMActiveConnection *) nm_act_request_new (settings_connection,
applied,
specific_object,
subject,
device);
......@@ -3234,6 +3240,7 @@ _internal_activation_auth_done (NMActiveConnection *active,
* nm_manager_activate_connection():
* @self: the #NMManager
* @connection: 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
* @subject: the subject which requested activation
......@@ -3243,7 +3250,8 @@ _internal_activation_auth_done (NMActiveConnection *active,
* @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
* referenced by the caller if the caller continues to use it.
* referenced by the caller if the caller continues to use it. If @applied
* is supplied, it shall not be modified by the caller afterwards.
*
* Returns: (transfer none): the new #NMActiveConnection that tracks
* activation of @connection on @device
......@@ -3251,6 +3259,7 @@ _internal_activation_auth_done (NMActiveConnection *active,
NMActiveConnection *
nm_manager_activate_connection (NMManager *self,
NMSettingsConnection *connection,
NMConnection *applied,
const char *specific_object,
NMDevice *device,
NMAuthSubject *subject,
......@@ -3296,6 +3305,7 @@ nm_manager_activate_connection (NMManager *self,
active = _new_active_connection (self,
NM_CONNECTION (connection),
applied,
specific_object,
device,
subject,
......@@ -3550,6 +3560,7 @@ impl_manager_activate_connection (NMManager *self,
active = _new_active_connection (self,
NM_CONNECTION (connection),
NULL,
specific_object_path,
device,
subject,
......@@ -3757,6 +3768,7 @@ impl_manager_add_and_activate_connection (NMManager *self,
active = _new_active_connection (self,
connection,
NULL,
specific_object_path,
device,
subject,
......
......@@ -105,6 +105,7 @@ char * nm_manager_get_connection_iface (NMManager *self,
NMActiveConnection *nm_manager_activate_connection (NMManager *manager,
NMSettingsConnection *connection,
NMConnection *applied_connection,
const char *specific_object,
NMDevice *device,
NMAuthSubject *subject,
......
......@@ -724,6 +724,7 @@ auto_activate_device (gpointer user_data)
subject = nm_auth_subject_new_internal ();
if (!nm_manager_activate_connection (priv->manager,
best_connection,
NULL,
specific_object,
data->device,
subject,
......@@ -1117,6 +1118,7 @@ activate_secondary_connections (NMPolicy *self,
nm_connection_get_id (connection), nm_connection_get_uuid (connection));
ac = nm_manager_activate_connection (priv->manager,
settings_con,
NULL,
nm_exported_object_get_path (NM_EXPORTED_OBJECT (req)),
device,
nm_active_connection_get_subject (NM_ACTIVE_CONNECTION (req)),
......@@ -1520,6 +1522,7 @@ vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *self)
connection,
NULL,
NULL,
NULL,
nm_active_connection_get_subject (ac),
&error)) {
_LOGW (LOGD_DEVICE, "VPN '%s' reconnect failed: %s",
......
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