From ed640f857a1a1eae45d92cce35ea8dcfd8aba08d Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 27 Sep 2017 09:25:16 +0200 Subject: manager: ignore unmanaged devices when looking for parent by UUID If the device is unmanaged, it is not compatible with any connection. https://mail.gnome.org/archives/networkmanager-list/2017-September/msg00032.html --- src/nm-manager.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/nm-manager.c b/src/nm-manager.c index d0429fe9e5..2e47a97591 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1155,6 +1155,10 @@ find_parent_device_for_connection (NMManager *self, NMConnection *connection, NM for (iter = priv->devices; iter; iter = iter->next) { NMDevice *candidate = iter->data; + /* Unmanaged devices are not compatible with any connection */ + if (!nm_device_get_managed (candidate, FALSE)) + continue; + if (nm_device_get_settings_connection (candidate) == parent_connection) return candidate; -- cgit v1.2.1 From 27c281ac5a5c786f996230926ba40e2026ce4d4f Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 27 Sep 2017 09:40:45 +0200 Subject: device: deduplicate match_parent() --- src/devices/nm-device-ip-tunnel.c | 40 ++------------------------------------ src/devices/nm-device-macvlan.c | 41 +-------------------------------------- src/devices/nm-device-private.h | 2 ++ src/devices/nm-device-vlan.c | 40 +------------------------------------- src/devices/nm-device-vxlan.c | 40 +------------------------------------- src/devices/nm-device.c | 32 ++++++++++++++++++++++++++++++ 6 files changed, 39 insertions(+), 156 deletions(-) diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index 317a5d4e74..af3cfe4c98 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -441,40 +441,6 @@ update_connection (NMDevice *device, NMConnection *connection) } } -static gboolean -match_parent (NMDevice *dev_parent, const char *setting_parent) -{ - g_return_val_if_fail (setting_parent, FALSE); - - if (!dev_parent) - return FALSE; - - if (nm_utils_is_uuid (setting_parent)) { - NMActRequest *parent_req; - NMConnection *parent_connection; - - /* If the parent is a UUID, the connection matches if our parent - * device has that connection activated. - */ - parent_req = nm_device_get_act_request (dev_parent); - if (!parent_req) - return FALSE; - - parent_connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (parent_req)); - if (!parent_connection) - return FALSE; - - if (g_strcmp0 (setting_parent, nm_connection_get_uuid (parent_connection)) != 0) - return FALSE; - } else { - /* interface name */ - if (g_strcmp0 (setting_parent, nm_device_get_ip_iface (dev_parent)) != 0) - return FALSE; - } - - return TRUE; -} - static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection) { @@ -496,10 +462,8 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) if (nm_device_is_real (device)) { /* Check parent interface; could be an interface name or a UUID */ parent = nm_setting_ip_tunnel_get_parent (s_ip_tunnel); - if (parent) { - if (!match_parent (nm_device_parent_get_device (device), parent)) - return FALSE; - } + if (parent && !nm_device_match_parent (device, parent)) + return FALSE; if (!address_equal_pp (priv->addr_family, nm_setting_ip_tunnel_get_local (s_ip_tunnel), diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index 8803beb524..ffaa094cb9 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -286,45 +286,6 @@ is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags) /*****************************************************************************/ - -static gboolean -match_parent (NMDeviceMacvlan *self, const char *parent) -{ - NMDevice *parent_device; - - g_return_val_if_fail (parent != NULL, FALSE); - - parent_device = nm_device_parent_get_device (NM_DEVICE (self)); - if (!parent_device) - return FALSE; - - if (nm_utils_is_uuid (parent)) { - NMActRequest *parent_req; - NMConnection *parent_connection; - - /* If the parent is a UUID, the connection matches if our parent - * device has that connection activated. - */ - - parent_req = nm_device_get_act_request (parent_device); - if (!parent_req) - return FALSE; - - parent_connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (parent_req)); - if (!parent_connection) - return FALSE; - - if (g_strcmp0 (parent, nm_connection_get_uuid (parent_connection)) != 0) - return FALSE; - } else { - /* interface name */ - if (g_strcmp0 (parent, nm_device_get_ip_iface (parent_device)) != 0) - return FALSE; - } - - return TRUE; -} - static gboolean match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr) { @@ -378,7 +339,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) /* Check parent interface; could be an interface name or a UUID */ parent = nm_setting_macvlan_get_parent (s_macvlan); if (parent) { - if (!match_parent (NM_DEVICE_MACVLAN (device), parent)) + if (!nm_device_match_parent (device, parent)) return FALSE; } else { /* Parent could be a MAC address in an NMSettingWired */ diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 28702f8af3..f3c301d48e 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -132,4 +132,6 @@ gboolean _nm_device_hash_check_invalid_keys (GHashTable *hash, const char *setti #define nm_device_hash_check_invalid_keys(hash, setting_name, error, ...) \ _nm_device_hash_check_invalid_keys (hash, setting_name, error, ((const char *[]) { __VA_ARGS__, NULL })) +gboolean nm_device_match_parent (NMDevice *device, const char *parent); + #endif /* NM_DEVICE_PRIVATE_H */ diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 171af14e02..0badfd2852 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -314,44 +314,6 @@ is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags) /*****************************************************************************/ -static gboolean -match_parent (NMDeviceVlan *self, const char *parent) -{ - NMDevice *parent_device; - - g_return_val_if_fail (parent != NULL, FALSE); - - parent_device = nm_device_parent_get_device (NM_DEVICE (self)); - if (!parent_device) - return FALSE; - - if (nm_utils_is_uuid (parent)) { - NMActRequest *parent_req; - NMConnection *parent_connection; - - /* If the parent is a UUID, the connection matches if our parent - * device has that connection activated. - */ - - parent_req = nm_device_get_act_request (parent_device); - if (!parent_req) - return FALSE; - - parent_connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (parent_req)); - if (!parent_connection) - return FALSE; - - if (g_strcmp0 (parent, nm_connection_get_uuid (parent_connection)) != 0) - return FALSE; - } else { - /* interface name */ - if (g_strcmp0 (parent, nm_device_get_ip_iface (parent_device)) != 0) - return FALSE; - } - - return TRUE; -} - static gboolean match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr) { @@ -398,7 +360,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) /* Check parent interface; could be an interface name or a UUID */ parent = nm_setting_vlan_get_parent (s_vlan); if (parent) { - if (!match_parent (NM_DEVICE_VLAN (device), parent)) + if (!nm_device_match_parent (device, parent)) return FALSE; } else { /* Parent could be a MAC address in an NMSettingWired */ diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index 204b85c001..d9efe8404b 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -230,43 +230,6 @@ create_and_realize (NMDevice *device, return TRUE; } -static gboolean -match_parent (NMDeviceVxlan *self, const char *parent) -{ - NMDevice *parent_device; - - g_return_val_if_fail (parent != NULL, FALSE); - - parent_device = nm_device_parent_get_device (NM_DEVICE (self)); - if (!parent_device) - return FALSE; - - if (nm_utils_is_uuid (parent)) { - NMActRequest *parent_req; - NMConnection *parent_connection; - - /* If the parent is a UUID, the connection matches if our parent - * device has that connection activated. - */ - parent_req = nm_device_get_act_request (parent_device); - if (!parent_req) - return FALSE; - - parent_connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (parent_req)); - if (!parent_connection) - return FALSE; - - if (g_strcmp0 (parent, nm_connection_get_uuid (parent_connection)) != 0) - return FALSE; - } else { - /* interface name */ - if (g_strcmp0 (parent, nm_device_get_ip_iface (parent_device)) != 0) - return FALSE; - } - - return TRUE; -} - static gboolean address_matches (const char *str, in_addr_t addr4, struct in6_addr *addr6) { @@ -302,8 +265,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) if (nm_device_is_real (device)) { parent = nm_setting_vxlan_get_parent (s_vxlan); - if ( parent - && !match_parent (NM_DEVICE_VXLAN (device), parent)) + if (parent && !nm_device_match_parent (device, parent)) return FALSE; if (priv->props.id != nm_setting_vxlan_get_id (s_vxlan)) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 86e2f9d36d..76b7e28b40 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -4390,6 +4390,38 @@ nm_device_complete_connection (NMDevice *self, return success; } +gboolean +nm_device_match_parent (NMDevice *self, const char *parent) +{ + NMDevice *parent_device; + + g_return_val_if_fail (parent, FALSE); + + parent_device = nm_device_parent_get_device (self); + if (!parent_device) + return FALSE; + + if (nm_utils_is_uuid (parent)) { + NMConnection *connection; + + /* If the parent is a UUID, the connection matches if our parent + * device has that connection activated. + */ + connection = nm_device_get_applied_connection (self); + if (!connection) + return FALSE; + + if (!nm_streq0 (parent, nm_connection_get_uuid (connection))) + return FALSE; + } else { + /* Interface name */ + if (!nm_streq0 (parent, nm_device_get_ip_iface (parent_device))) + return FALSE; + } + + return TRUE; +} + static gboolean check_connection_compatible (NMDevice *self, NMConnection *connection) { -- cgit v1.2.1 From d2e4a2f63992da2b7ca88506b1ca44b502c02e67 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 27 Sep 2017 09:47:22 +0200 Subject: device: deduplicate match_hwaddr() --- src/devices/nm-device-macvlan.c | 28 ++-------------------------- src/devices/nm-device-private.h | 3 +++ src/devices/nm-device-vlan.c | 28 ++-------------------------- src/devices/nm-device.c | 26 ++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 52 deletions(-) diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index ffaa094cb9..2a461543b0 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -286,30 +286,6 @@ is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags) /*****************************************************************************/ -static gboolean -match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr) -{ - NMSettingWired *s_wired; - NMDevice *parent_device; - const char *setting_mac; - const char *parent_mac; - - s_wired = nm_connection_get_setting_wired (connection); - if (!s_wired) - return !fail_if_no_hwaddr; - - setting_mac = nm_setting_wired_get_mac_address (s_wired); - if (!setting_mac) - return !fail_if_no_hwaddr; - - parent_device = nm_device_parent_get_device (device); - if (!parent_device) - return !fail_if_no_hwaddr; - - parent_mac = nm_device_get_permanent_hw_address (parent_device); - return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1); -} - static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection) { @@ -343,7 +319,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) return FALSE; } else { /* Parent could be a MAC address in an NMSettingWired */ - if (!match_hwaddr (device, connection, TRUE)) + if (!nm_device_match_hwaddr (device, connection, TRUE)) return FALSE; } } @@ -380,7 +356,7 @@ complete_connection (NMDevice *device, * settings, then there's not enough information to complete the setting. */ if ( !nm_setting_macvlan_get_parent (s_macvlan) - && !match_hwaddr (device, connection, TRUE)) { + && !nm_device_match_hwaddr (device, connection, TRUE)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, "The 'macvlan' setting had no interface name, parent, or hardware address."); return FALSE; diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index f3c301d48e..416ae845c8 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -133,5 +133,8 @@ gboolean _nm_device_hash_check_invalid_keys (GHashTable *hash, const char *setti _nm_device_hash_check_invalid_keys (hash, setting_name, error, ((const char *[]) { __VA_ARGS__, NULL })) gboolean nm_device_match_parent (NMDevice *device, const char *parent); +gboolean nm_device_match_hwaddr (NMDevice *device, + NMConnection *connection, + gboolean fail_if_no_hwaddr); #endif /* NM_DEVICE_PRIVATE_H */ diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 0badfd2852..06f19c408c 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -314,30 +314,6 @@ is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags) /*****************************************************************************/ -static gboolean -match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr) -{ - NMSettingWired *s_wired; - NMDevice *parent_device; - const char *setting_mac; - const char *parent_mac; - - s_wired = nm_connection_get_setting_wired (connection); - if (!s_wired) - return !fail_if_no_hwaddr; - - setting_mac = nm_setting_wired_get_mac_address (s_wired); - if (!setting_mac) - return !fail_if_no_hwaddr; - - parent_device = nm_device_parent_get_device (device); - if (!parent_device) - return !fail_if_no_hwaddr; - - parent_mac = nm_device_get_permanent_hw_address (parent_device); - return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1); -} - static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection) { @@ -364,7 +340,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) return FALSE; } else { /* Parent could be a MAC address in an NMSettingWired */ - if (!match_hwaddr (device, connection, TRUE)) + if (!nm_device_match_hwaddr (device, connection, TRUE)) return FALSE; } } @@ -413,7 +389,7 @@ complete_connection (NMDevice *device, * settings, then there's not enough information to complete the setting. */ if ( !nm_setting_vlan_get_parent (s_vlan) - && !match_hwaddr (device, connection, TRUE)) { + && !nm_device_match_hwaddr (device, connection, TRUE)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, "The 'vlan' setting had no interface name, parent, or hardware address."); return FALSE; diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 76b7e28b40..71cdead330 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -4422,6 +4422,32 @@ nm_device_match_parent (NMDevice *self, const char *parent) return TRUE; } +gboolean +nm_device_match_hwaddr (NMDevice *device, + NMConnection *connection, + gboolean fail_if_no_hwaddr) +{ + NMSettingWired *s_wired; + NMDevice *parent_device; + const char *setting_mac; + const char *parent_mac; + + s_wired = nm_connection_get_setting_wired (connection); + if (!s_wired) + return !fail_if_no_hwaddr; + + setting_mac = nm_setting_wired_get_mac_address (s_wired); + if (!setting_mac) + return !fail_if_no_hwaddr; + + parent_device = nm_device_parent_get_device (device); + if (!parent_device) + return !fail_if_no_hwaddr; + + parent_mac = nm_device_get_permanent_hw_address (parent_device); + return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1); +} + static gboolean check_connection_compatible (NMDevice *self, NMConnection *connection) { -- cgit v1.2.1 From 6a5363bc8b54d8ee71b7a25acec3a0baa2298879 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 27 Sep 2017 10:23:31 +0200 Subject: device: match all UUIDs when no connection is active nm_device_match_parent() is called to check whether a device is compatible with a given parent (UUID or interface). Accept any UUID If there is no connection active on the device. Without this, when there is a VLAN/MACVLAN connection with a parent UUID the manager would create the device in system_create_virtual_device(), realize it and then at the next call of system_create_virtual_device() it would notice that the connection is not compatible with the device because of the parent UUID; therefore the manager would try to create again the same device, failing. https://mail.gnome.org/archives/networkmanager-list/2017-September/msg00034.html --- src/devices/nm-device.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 71cdead330..96e39bf768 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -4404,12 +4404,13 @@ nm_device_match_parent (NMDevice *self, const char *parent) if (nm_utils_is_uuid (parent)) { NMConnection *connection; - /* If the parent is a UUID, the connection matches if our parent - * device has that connection activated. + /* If the parent is a UUID, the connection matches when there is + * no connection active on the device or when a connection with + * that UUID is active. */ connection = nm_device_get_applied_connection (self); if (!connection) - return FALSE; + return TRUE; if (!nm_streq0 (parent, nm_connection_get_uuid (connection))) return FALSE; -- cgit v1.2.1