From d0349f17b792d475d388e4e9836d7417427cf13a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 2 Jul 2021 20:31:05 +0200 Subject: [PATCH] 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.. --- src/nmcli/connections.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index a6b5e58ea2..87cd2a8b94 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -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; }