diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2015-12-11 15:40:34 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2015-12-11 17:03:54 +0100 |
commit | 71a684159ff224edcf06f14a95140e6818d5b9f3 (patch) | |
tree | 7692fd5a577b6f2b02aaa453f971131e0fd6393e | |
parent | 95d67c683df6b5a1e1682cd11458154660395ae3 (diff) | |
download | NetworkManager-71a684159ff224edcf06f14a95140e6818d5b9f3.tar.gz |
manager: if there's an unrealized device that matches new connection, realize it
Fixes this:
nmcli c add type bridge # Creates and realizes the device, autoconnects connection
nmcli c del bridge # Device unrealizes
nmcli c add type bridge # The new connection does not autoconnect, since the
# device stays unrealized
-rw-r--r-- | src/nm-manager.c | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/src/nm-manager.c b/src/nm-manager.c index 3001085fc9..69351612c8 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1025,47 +1025,55 @@ system_create_virtual_device (NMManager *self, NMConnection *connection, GError if (!iface) return NULL; - /* If some other device is already compatible with this connection, - * don't create a new device for it. - */ + /* See if there's a device that is already compatible with this connection */ for (iter = priv->devices; iter; iter = g_slist_next (iter)) { NMDevice *candidate = iter->data; if ( g_strcmp0 (nm_device_get_iface (candidate), iface) == 0 && nm_device_check_connection_compatible (candidate, connection)) { - nm_log_dbg (LOGD_DEVICE, "(%s) already created virtual interface name %s", - nm_connection_get_id (connection), iface); - return NULL; + + if (nm_device_is_real (candidate)) { + nm_log_dbg (LOGD_DEVICE, "(%s) already created virtual interface name %s", + nm_connection_get_id (connection), iface); + return NULL; + } + + device = candidate; + break; } } - factory = nm_device_factory_manager_find_factory_for_connection (connection); - if (!factory) { - nm_log_err (LOGD_DEVICE, "(%s:%s) NetworkManager plugin for '%s' unavailable", - nm_connection_get_id (connection), iface, - nm_connection_get_connection_type (connection)); - g_set_error (error, - NM_MANAGER_ERROR, - NM_MANAGER_ERROR_FAILED, - "NetworkManager plugin for '%s' unavailable", - nm_connection_get_connection_type (connection)); - return NULL; - } + if (!device) { + /* No matching device found. Proceed creating a new one. */ - device = nm_device_factory_create_device (factory, iface, NULL, connection, NULL, error); - if (!device) - return NULL; + factory = nm_device_factory_manager_find_factory_for_connection (connection); + if (!factory) { + nm_log_err (LOGD_DEVICE, "(%s:%s) NetworkManager plugin for '%s' unavailable", + nm_connection_get_id (connection), iface, + nm_connection_get_connection_type (connection)); + g_set_error (error, + NM_MANAGER_ERROR, + NM_MANAGER_ERROR_FAILED, + "NetworkManager plugin for '%s' unavailable", + nm_connection_get_connection_type (connection)); + return NULL; + } + + device = nm_device_factory_create_device (factory, iface, NULL, connection, NULL, error); + if (!device) + return NULL; - if (!add_device (self, device, error)) { + if (!add_device (self, device, error)) { + g_object_unref (device); + return NULL; + } + + /* Add device takes a reference that NMManager still owns, so it's + * safe to unref here and still return @device. + */ g_object_unref (device); - return NULL; } - /* Add device takes a reference that NMManager still owns, so it's - * safe to unref here and still return @device. - */ - g_object_unref (device); - /* Create backing resources if the device has any autoconnect connections */ connections = nm_settings_get_connections (priv->settings); for (iter = connections; iter; iter = g_slist_next (iter)) { |