From f05a286df4b60cdc0ef57af86046b0a08d8bbc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= Date: Tue, 23 Jul 2024 16:40:09 +0200 Subject: [PATCH] nmcli: ignore non-base setting names for connection type Not all setting names are valid values for the value of the connection's "type". However, if a shortened value is introduced, all setting names are considered, like in: Error: bad connection type: 'eth' is ambiguous: ethernet, ethtool Note that ethtool is not a valid value for "type". Fix it by considering only "base" settings names. --- src/nmcli/connections.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index 72a1fc1897..89d2378f88 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -3798,6 +3798,7 @@ check_valid_name_toplevel(const char *val, const char **port_type, GError **erro gs_unref_ptrarray GPtrArray *tmp_arr = NULL; const NMMetaSettingInfoEditor *setting_info; gs_free_error GError *tmp_err = NULL; + GType gtype = G_TYPE_INVALID; const char *str; int i; @@ -3807,6 +3808,13 @@ check_valid_name_toplevel(const char *val, const char **port_type, GError **erro tmp_arr = g_ptr_array_sized_new(32); for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { setting_info = &nm_meta_setting_infos_editor[i]; + + /* skip "non-base" settings (that means, not valid for a connection's "type") */ + gtype = setting_info->general->get_setting_gtype(); + if (nm_meta_setting_info_get_base_type_priority(setting_info->general, gtype) + == NM_SETTING_PRIORITY_INVALID) + continue; + g_ptr_array_add(tmp_arr, (gpointer) setting_info->general->setting_name); if (setting_info->alias) g_ptr_array_add(tmp_arr, (gpointer) setting_info->alias);