From cd2945f223e00200684d1d906142a06106ff3fba Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Fri, 24 Jun 2022 00:30:04 +0200 Subject: nmcli/connections: fix setting ifname with "--ask c add" We almost always do the wrong thing in interactive add: The software devices generally require an interactive name, but we don't insist of asking for them; treating them as optional: $ nmcli -a c add type dummy There is 1 optional setting for General settings. Do you want to provide it? (yes/no) [yes] For some interface types (bridges, bonds, ...) we make up a name, presumably for historical reasons. But we don't give the user an option to modify them: $ nmcli -a c add type bridge There are 9 optional settings for Bridge device. Do you want to provide them? (yes/no) [yes] This fixes the above use cases -- still set the default, but be sure to ask: $ nmcli -a c add type dummy Interface name: $ nmcli -a c add type bridge Interface name [nm-bridge1]: Beautiful. --- src/nmcli/connections.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index 3370277ae2..34012d8622 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -4509,7 +4509,7 @@ gen_func_bond_lacp_rate(const char *text, int state) /*****************************************************************************/ static gboolean -enable_type_settings_and_options(NMConnection *con, GError **error) +enable_type_settings_and_options(NmCli *nmc, NMConnection *con, GError **error) { const NMMetaSettingValidPartItem *const *type_settings; const NMMetaSettingValidPartItem *const *slv_settings; @@ -4522,11 +4522,20 @@ enable_type_settings_and_options(NMConnection *con, GError **error) enable_options(NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, NULL); if (NM_IN_STRSET(nm_setting_connection_get_connection_type(s_con), + NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BOND_SETTING_NAME, - NM_SETTING_TEAM_SETTING_NAME, NM_SETTING_BRIDGE_SETTING_NAME, - NM_SETTING_VLAN_SETTING_NAME)) { - disable_options(NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME); + NM_SETTING_DUMMY_SETTING_NAME, + NM_SETTING_OVS_BRIDGE_SETTING_NAME, + NM_SETTING_OVS_PATCH_SETTING_NAME, + NM_SETTING_OVS_PORT_SETTING_NAME, + NM_SETTING_TEAM_SETTING_NAME, + NM_SETTING_VETH_SETTING_NAME, + NM_SETTING_VRF_SETTING_NAME, + NM_SETTING_WIREGUARD_SETTING_NAME)) { + enable_options(NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_INTERFACE_NAME, + NULL); } if (!con_settings(con, &type_settings, &slv_settings, error)) @@ -4535,6 +4544,9 @@ enable_type_settings_and_options(NMConnection *con, GError **error) ensure_settings(con, slv_settings); ensure_settings(con, type_settings); + /* For some software connection types we generate the interface name for the user. */ + set_default_interface_name(nmc, s_con); + return TRUE; } @@ -4583,7 +4595,7 @@ set_connection_type(NmCli *nmc, error)) return FALSE; - return enable_type_settings_and_options(con, error); + return enable_type_settings_and_options(nmc, con, error); } static gboolean @@ -5891,7 +5903,7 @@ read_properties: if (nmc->complete) goto finish; - if (!enable_type_settings_and_options(connection, &error)) { + if (!enable_type_settings_and_options(nmc, connection, &error)) { g_string_assign(nmc->return_text, error->message); nmc->return_value = error->code; goto finish; @@ -5932,9 +5944,6 @@ read_properties: } } - /* For some software connection types we generate the interface name for the user. */ - set_default_interface_name(nmc, s_con); - /* Now see if there's something optional that needs to be asked for. * Keep asking until there's no more things to ask for. */ do { -- cgit v1.2.1