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
This commit is contained in:
Thomas Haller 2021-06-30 14:04:45 +02:00
parent f9b43ed7d4
commit a32d04f0bb
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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;