From ccae5dc0e29be145ce4f7ea193c29f2234097f2e Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Wed, 5 Feb 2025 14:09:39 +0100 Subject: [PATCH] Revert "manager: create virtual devices on AddAndActivate()" This reverts commit eb635c23a7f7486c3d7f67a092d5b39ccfad15ca. --- src/core/nm-manager.c | 85 +++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 48 deletions(-) diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index e6d1ceb59a..7d1e7ba127 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -6538,9 +6538,18 @@ find_device_for_activation(NMManager *self, return FALSE; device = find_device_by_iface(self, iface, connection, NULL, NULL); + if (!device) { + g_set_error_literal(error, + NM_MANAGER_ERROR, + NM_MANAGER_ERROR_UNKNOWN_DEVICE, + "Failed to find a compatible device for this connection"); + return FALSE; + } } } + nm_assert(is_vpn || NM_IS_DEVICE(device)); + *out_device = device; *out_is_vpn = is_vpn; @@ -6665,14 +6674,7 @@ impl_manager_activate_connection(NMDBusObject *obj, if (!subject) goto error; - if (!find_device_for_activation(self, sett_conn, NULL, device_path, &device, &is_vpn, &error)) - goto error; - - if (!device && !is_vpn) { - g_set_error_literal(&error, - NM_MANAGER_ERROR, - NM_MANAGER_ERROR_UNKNOWN_DEVICE, - "Failed to find a compatible device for this connection"); + if (!find_device_for_activation(self, sett_conn, NULL, device_path, &device, &is_vpn, &error)) { goto error; } @@ -6703,10 +6705,6 @@ impl_manager_activate_connection(NMDBusObject *obj, return; error: - if (device && nm_device_is_software(device)) { - if (_check_remove_dev_on_link_deleted(self, device)) - remove_device(self, device, FALSE); - } if (sett_conn) { nm_audit_log_connection_op(NM_AUDIT_OP_CONN_ACTIVATE, sett_conn, @@ -6799,7 +6797,6 @@ _add_and_activate_auth_done(NMManager *self, const char *error_desc) { NMManagerPrivate *priv; - NMDevice *device; GError *error = NULL; if (!success) { @@ -6812,12 +6809,6 @@ _add_and_activate_auth_done(NMManager *self, nm_active_connection_get_subject(active), error->message); g_dbus_method_invocation_take_error(invocation, error); - - device = nm_active_connection_get_device(active); - if (device && nm_device_is_software(device)) { - if (_check_remove_dev_on_link_deleted(self, device)) - remove_device(self, device, FALSE); - } return; } @@ -6973,11 +6964,32 @@ impl_manager_add_and_activate_connection(NMDBusObject *obj, goto error; } - conns = nm_settings_connections_array_to_connections( - nm_settings_get_connections(priv->settings, NULL), - -1); + if (is_vpn) { + /* Try to fill the VPN's connection setting and name at least */ + if (!nm_connection_get_setting_vpn(incompl_conn)) { + error = g_error_new_literal(NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_MISSING_SETTING, + "VPN connections require a 'vpn' setting"); + g_prefix_error(&error, "%s: ", NM_SETTING_VPN_SETTING_NAME); + goto error; + } - if (device) { + conns = nm_settings_connections_array_to_connections( + nm_settings_get_connections(priv->settings, NULL), + -1); + + nm_utils_complete_generic(priv->platform, + incompl_conn, + NM_SETTING_VPN_SETTING_NAME, + conns, + NULL, + _("VPN connection"), + NULL, + NULL); + } else { + conns = nm_settings_connections_array_to_connections( + nm_settings_get_connections(priv->settings, NULL), + -1); /* Let each device subclass complete the connection */ if (!nm_device_complete_connection(device, incompl_conn, @@ -6985,33 +6997,10 @@ impl_manager_add_and_activate_connection(NMDBusObject *obj, conns, &error)) goto error; - } else { - nm_utils_complete_generic(priv->platform, - incompl_conn, - nm_connection_get_connection_type(incompl_conn), - conns, - is_vpn ? _("VPN connection") : NULL, - nm_connection_get_connection_type(incompl_conn), - NULL, - NULL); - - if (!nm_connection_verify(incompl_conn, &error)) - goto error; - - if (!is_vpn && !device) { - nm_assert(nm_connection_is_virtual(incompl_conn)); - - device = system_create_virtual_device(self, incompl_conn); - if (!device) { - g_set_error_literal(&error, - NM_MANAGER_ERROR, - NM_MANAGER_ERROR_UNKNOWN_DEVICE, - "Failed to create a device for this connection"); - goto error; - } - } } + nm_assert(_nm_connection_verify(incompl_conn, NULL) == NM_SETTING_VERIFY_SUCCESS); + active = _new_active_connection(self, is_vpn, NULL,