summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2022-06-24 00:30:04 +0200
committerLubomir Rintel <lkundrak@v3.sk>2022-06-24 00:30:04 +0200
commitcd2945f223e00200684d1d906142a06106ff3fba (patch)
treea8478a2e60582af32e3d97d8d61ea88c850ac7bd
parent647e2553627d38f6a7c254d162cc9ea697c662f1 (diff)
downloadNetworkManager-lr/ask-mode.tar.gz
nmcli/connections: fix setting ifname with "--ask c add"lr/ask-mode
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 <not asking for interface name at all> 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.
-rw-r--r--src/nmcli/connections.c27
1 files 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 {