From 6a133d10a1e54c21fbacf7893f69c71fc6a41f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= Date: Fri, 14 Mar 2025 08:18:46 +0100 Subject: [PATCH] nmcli: connection: don't overwrite port-type if explicitly set When processing the "type" property we deduce the port-type in some cases and set it. If the user has chosen a port-type we must not overwrite it. In any case, we should raise an error when validating the connection. Fixes: c5324ed285af ('nmcli: streamline connection addition') --- src/nmcli/connections.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index ed7a7b62d9..d4c583f86f 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -4616,8 +4616,11 @@ set_connection_type(NmCli *nmc, gboolean allow_reset, GError **error) { - GError *local = NULL; - const char *port_type = NULL; + NMSettingConnection *s_con = nm_connection_get_setting_connection(con); + GError *local = NULL; + const char *port_type = NULL; + + nm_assert(s_con); value = check_valid_name_toplevel(value, &port_type, &local); if (!value) { @@ -4632,7 +4635,7 @@ set_connection_type(NmCli *nmc, return FALSE; } - if (port_type) { + if (!nm_setting_connection_get_port_type(s_con) && port_type) { if (!set_property(nmc->client, con, NM_SETTING_CONNECTION_SETTING_NAME,