diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2015-02-01 08:27:50 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2015-02-02 23:21:45 +0100 |
commit | 669fe553c19b9e2a591b73523d4670530ce1c41a (patch) | |
tree | 9e60c5cc65f76bfb6db03013a80d5941b152027a | |
parent | 5439fbd77cd245b0a69cede67280767f6ffdc996 (diff) | |
download | NetworkManager-669fe553c19b9e2a591b73523d4670530ce1c41a.tar.gz |
manager: allow activating connections without a device given
Just try to pick a suitable device. Keep the connection on the same device
when it's already active. This makes it possible to reactivate a connection
without client knowing which device is it active on.
-rw-r--r-- | src/nm-manager.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/nm-manager.c b/src/nm-manager.c index 30782a1bb4..c727b68fde 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -3017,6 +3017,36 @@ nm_manager_activate_connection (NMManager *self, return active; } +static NMDevice * +nm_manager_get_connection_best_device (NMManager *self, + NMConnection *connection) +{ + const GSList *list, *iter; + + /* If the connection is already active on some device, we just + * want to reuse it. */ + list = nm_manager_get_active_connections (self); + for (iter = list; iter; iter = g_slist_next (iter)) { + NMActiveConnection *ac = NM_ACTIVE_CONNECTION (iter->data); + NMConnection *c = nm_active_connection_get_connection (ac); + + if (c == connection) + return nm_active_connection_get_device (ac); + } + + /* Pick the first device that's compatible with the connection. */ + list = nm_manager_get_devices (self); + for (iter = list; iter; iter = g_slist_next (iter)) { + NMDevice *device = NM_DEVICE (iter->data); + + if (nm_device_connection_is_available (device, connection, TRUE)) + return device; + } + + /* No luck. :( */ + return NULL; +} + static NMAuthSubject * validate_activation_request (NMManager *self, DBusGMethodInvocation *context, @@ -3089,6 +3119,10 @@ validate_activation_request (NMManager *self, goto error; } } else { + device = nm_manager_get_connection_best_device (self, connection); + } + + if (!device) { gboolean is_software = nm_connection_is_virtual (connection); /* VPN and software-device connections don't need a device yet */ |