summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2012-09-13 15:57:36 -0500
committerDan Williams <dcbw@redhat.com>2013-10-31 14:15:07 -0500
commitf94ac164a6e33ed03fe707fd5eeb2e2ce6c0fbcb (patch)
tree505f9f15881db5a29aea6e4d1ef6831f17022a3a
parenta878cd814564e9d349eb8fd4f7d7d5d81d4aecaf (diff)
downloadNetworkManager-f94ac164a6e33ed03fe707fd5eeb2e2ce6c0fbcb.tar.gz
core: make nm_manager_activate_connection() take a Device, not a path
Simpler; everywhere that called it has an NMDevice already anyway.
-rw-r--r--src/nm-manager.c48
-rw-r--r--src/nm-manager.h2
-rw-r--r--src/nm-policy.c4
3 files changed, 23 insertions, 31 deletions
diff --git a/src/nm-manager.c b/src/nm-manager.c
index cdbd540646..c6123bbf2f 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -195,8 +195,8 @@ struct PendingActivation {
gboolean add_and_activate;
NMConnection *connection;
+ NMDevice *device;
char *specific_object_path;
- char *device_path;
};
typedef struct {
@@ -849,7 +849,7 @@ nm_manager_get_state (NMManager *manager)
static PendingActivation *
pending_activation_new (NMManager *manager,
DBusGMethodInvocation *context,
- const char *device_path,
+ NMDevice *device,
NMConnection *connection,
const char *specific_object_path,
gboolean add_and_activate,
@@ -860,26 +860,21 @@ pending_activation_new (NMManager *manager,
g_return_val_if_fail (manager != NULL, NULL);
g_return_val_if_fail (context != NULL, NULL);
- g_return_val_if_fail (device_path != NULL, NULL);
+ g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
/* A object path of "/" means NULL */
if (g_strcmp0 (specific_object_path, "/") == 0)
specific_object_path = NULL;
- if (g_strcmp0 (device_path, "/") == 0)
- device_path = NULL;
pending = g_slice_new0 (PendingActivation);
pending->manager = manager;
pending->context = context;
pending->callback = callback;
pending->add_and_activate = add_and_activate;
-
pending->connection = g_object_ref (connection);
-
- /* "/" is special-cased to NULL to get through D-Bus */
+ pending->device = g_object_ref (device);
pending->specific_object_path = g_strdup (specific_object_path);
- pending->device_path = g_strdup (device_path);
return pending;
}
@@ -972,7 +967,7 @@ pending_activation_destroy (PendingActivation *pending,
}
g_free (pending->specific_object_path);
- g_free (pending->device_path);
+ g_clear_object (&pending->device);
g_clear_object (&pending->connection);
if (pending->chain)
@@ -2768,7 +2763,7 @@ ensure_master_active_connection (NMManager *self,
master_ac = nm_manager_activate_connection (self,
candidate,
NULL,
- nm_device_get_path (master_device),
+ master_device,
dbus_sender,
error);
if (!master_ac)
@@ -2816,7 +2811,7 @@ ensure_master_active_connection (NMManager *self,
master_ac = nm_manager_activate_connection (self,
master_connection,
NULL,
- nm_device_get_path (candidate),
+ candidate,
dbus_sender,
error);
if (!master_ac)
@@ -2907,12 +2902,11 @@ NMActiveConnection *
nm_manager_activate_connection (NMManager *manager,
NMConnection *connection,
const char *specific_object,
- const char *device_path,
+ NMDevice *device,
const char *dbus_sender,
GError **error)
{
NMManagerPrivate *priv;
- NMDevice *device = NULL;
gulong sender_uid = G_MAXULONG;
char *iface;
NMDevice *master_device = NULL;
@@ -2947,14 +2941,7 @@ nm_manager_activate_connection (NMManager *manager,
}
/* Device-based connection */
- if (device_path) {
- device = nm_manager_get_device_by_path (manager, device_path);
- if (!device) {
- g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
- "Device not found");
- return NULL;
- }
-
+ if (device) {
/* If it's a virtual interface make sure the device given by the
* path matches the connection's interface details.
*/
@@ -3154,7 +3141,7 @@ pending_activate (PendingActivation *pending, NMSettingsConnection *new_connecti
ac = nm_manager_activate_connection (pending->manager,
NM_CONNECTION (pending->connection),
pending->specific_object_path,
- pending->device_path,
+ pending->device,
sender,
&error);
g_free (sender);
@@ -3189,8 +3176,12 @@ validate_activation_request (NMManager *self,
|| nm_connection_is_type (connection, NM_SETTING_VPN_SETTING_NAME))
vpn = TRUE;
- /* Validate the device path, if given; "/" means NULL */
- if (device_path && (g_strcmp0 (device_path, "/") != 0))
+ /* Normalize device path */
+ if (device_path && g_strcmp0 (device_path, "/") == 0)
+ device_path = NULL;
+
+ /* And validate it */
+ if (device_path)
device = nm_manager_get_device_by_path (self, device_path);
/* VPN doesn't require a device, but if one is given validate it.
@@ -3232,6 +3223,7 @@ impl_manager_activate_connection (NMManager *self,
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
PendingActivation *pending;
NMConnection *connection;
+ NMDevice *device = NULL;
GError *error = NULL;
connection = (NMConnection *) nm_settings_get_connection_by_path (priv->settings, connection_path);
@@ -3242,7 +3234,7 @@ impl_manager_activate_connection (NMManager *self,
goto error;
}
- if (!validate_activation_request (self, connection, device_path, NULL, NULL, &error))
+ if (!validate_activation_request (self, connection, device_path, &device, NULL, &error))
goto error;
/* Need to check the caller's permissions and stuff before we can
@@ -3250,7 +3242,7 @@ impl_manager_activate_connection (NMManager *self,
*/
pending = pending_activation_new (self,
context,
- device_path,
+ device,
connection,
specific_object_path,
FALSE,
@@ -3363,7 +3355,7 @@ impl_manager_add_and_activate_connection (NMManager *self,
*/
pending = pending_activation_new (self,
context,
- device_path,
+ device,
connection,
specific_object_path,
TRUE,
diff --git a/src/nm-manager.h b/src/nm-manager.h
index fd6fa0aeee..6baf6f4d90 100644
--- a/src/nm-manager.h
+++ b/src/nm-manager.h
@@ -116,7 +116,7 @@ NMDevice *nm_manager_get_device_by_ifindex (NMManager *manager,
NMActiveConnection *nm_manager_activate_connection (NMManager *manager,
NMConnection *connection,
const char *specific_object,
- const char *device_path,
+ NMDevice *device,
const char *dbus_sender, /* NULL if automatic */
GError **error);
diff --git a/src/nm-policy.c b/src/nm-policy.c
index 49c005c47e..9f1db55cfb 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -1040,7 +1040,7 @@ auto_activate_device (gpointer user_data)
if (!nm_manager_activate_connection (priv->manager,
best_connection,
specific_object,
- nm_device_get_path (data->device),
+ data->device,
NULL,
&error)) {
nm_log_info (LOGD_DEVICE, "Connection '%s' auto-activation failed: (%d) %s",
@@ -1357,7 +1357,7 @@ activate_secondary_connections (NMPolicy *policy,
ac = nm_manager_activate_connection (priv->manager,
NM_CONNECTION (settings_con),
nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)),
- nm_device_get_path (device),
+ device,
nm_act_request_get_dbus_sender (req),
&error);
if (ac) {