From a32d04f0bb9b106a602b384defd7dfb09d208fe3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Jun 2021 14:04:45 +0200 Subject: [PATCH] core: fix `nmcli device connect dummy0` to add-and-activate dummy profile $ ip link add dd type dummy $ nmcli device DEVICE TYPE STATE CONNECTION ... dd dummy unmanaged -- $ nmcli device connect dd Error: Failed to add/activate new connection: A 'dummy' setting is required. There are two problems here. The first is that we don't pass the interface name to nm_utils_complete_generic(), but dummy devices require "connection.interface-name" set. As a consequence, nm_utils_complete_generic() fails to normalize the connection and there is no [dummy] setting. Which then results in a failure with complete_connection(). The important part of the fix is to set the interface name. Once we do that, nm_utils_complete_generic() should be able to add the [dummy] setting and the second part is not strictly necessary. Still, the job of complete_connection() is not to verify the profile but to create it with best effort. If a [dummy] setting is still missing, we should just add it. The caller will then again try to normalize/verify the connection, and that might then fail -- but this time not with the wrong error message about missing 'dummy' setting. https://bugzilla.redhat.com/show_bug.cgi?id=1763054 --- src/core/devices/nm-device-dummy.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/devices/nm-device-dummy.c b/src/core/devices/nm-device-dummy.c index 488f0ba003..7668be7b1b 100644 --- a/src/core/devices/nm-device-dummy.c +++ b/src/core/devices/nm-device-dummy.c @@ -57,16 +57,13 @@ complete_connection(NMDevice * device, NULL, _("Dummy connection"), NULL, - NULL, + nm_device_get_ip_iface(device), TRUE); s_dummy = nm_connection_get_setting_dummy(connection); if (!s_dummy) { - g_set_error_literal(error, - NM_DEVICE_ERROR, - NM_DEVICE_ERROR_INVALID_CONNECTION, - "A 'dummy' setting is required."); - return FALSE; + s_dummy = NM_SETTING_DUMMY(nm_setting_dummy_new()); + nm_connection_add_setting(connection, NM_SETTING(s_dummy)); } return TRUE;