cli: fail nmcli connection up $PROFILE ifname $DEVICE for non-existing virtual device

$ nmcli connection add type dummy con-name x autoconnect no ipv4.method disabled ipv6.method disabled ifname d0
  $ mcli connection up x ifname bogus
  Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)

This is not right. A non-existing ifname argument was simply ignored
and nmcli would tell NetworkManager to activate the profile (on any
device).

Instead, if the user specifies a device argument, also for a virtual
type, it must exist.

Note that usually for virtual devices (like 'dummy'), the device
in fact does not exist, so passing `ifname` is likely to fail.
If the device already exists, then the command is no going to work
as expected, with

  $ mcli connection up x ifname d0

succeeding, while

  $ mcli connection up x ifname d1

fails (as intended) with

  Error: device 'd1' not compatible with connection 'x': The interface names of the device and the connection didn't match..
This commit is contained in:
Thomas Haller 2021-07-02 20:31:05 +02:00
parent bb3c93bfd4
commit d0349f17b7
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -2844,8 +2844,7 @@ nmc_activate_connection(NmCli * nmc,
&spec_object,
&local);
/* Virtual connection may not have their interfaces created yet */
if (!device_found && !nm_connection_is_virtual(connection)) {
if (!device_found) {
g_set_error(error, NMCLI_ERROR, NMC_RESULT_ERROR_CON_ACTIVATION, "%s", local->message);
return FALSE;
}