device: move the interface name check from manager
authorLubomir Rintel <lkundrak@v3.sk>
Tue, 16 Feb 2016 14:07:57 +0000 (15:07 +0100)
committerThomas Haller <thaller@redhat.com>
Wed, 17 Feb 2016 17:43:44 +0000 (18:43 +0100)
We not only want to check the device name when creating a virtual device, but
also when determining if the connection can actually be activated there.

Otherwise the device names will mix up if there's more connections that use
virtual devices of the same type.

src/devices/nm-device.c
src/nm-manager.c

index 711ac2a..21e653d 100644 (file)
@@ -2958,15 +2958,18 @@ nm_device_complete_connection (NMDevice *self,
 static gboolean
 check_connection_compatible (NMDevice *self, NMConnection *connection)
 {
-       NMSettingConnection *s_con;
-       const char *config_iface, *device_iface;
-
-       s_con = nm_connection_get_setting_connection (connection);
-       g_assert (s_con);
-
-       config_iface = nm_setting_connection_get_interface_name (s_con);
-       device_iface = nm_device_get_iface (self);
-       if (config_iface && strcmp (config_iface, device_iface) != 0)
+       const char *device_iface = nm_device_get_iface (self);
+       gs_free char *conn_iface = nm_manager_get_connection_iface (nm_manager_get (),
+                                                                   connection,
+                                                                   NULL, NULL);
+
+       /* We always need a interface name for virtual devices, but for
+        * physical ones a connection without interface name is fine for
+        * any device. */
+       if (!conn_iface)
+               return !nm_connection_is_virtual (connection);
+
+       if (strcmp (conn_iface, device_iface) != 0)
                return FALSE;
 
        return TRUE;
index eb9576e..dce5d3c 100644 (file)
@@ -1033,9 +1033,7 @@ system_create_virtual_device (NMManager *self, NMConnection *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)) {
-
+               if (nm_device_check_connection_compatible (candidate, connection)) {
                        if (nm_device_is_real (candidate)) {
                                nm_log_dbg (LOGD_DEVICE, "(%s) already created virtual interface name %s",
                                            nm_connection_get_id (connection), iface);