cli: make the *-slave type option parsing out of the common path

We actually don't want to understand these options unless the legacy
*-slave types are used. The properties should be used directly instead.

https://bugzilla.gnome.org/show_bug.cgi?id=748302

This basically undoes most of what has been done in  commit 00e0fffea2.
This commit is contained in:
Lubomir Rintel 2016-03-29 14:08:55 +02:00
parent b645a3b39d
commit e691f01e01
2 changed files with 152 additions and 161 deletions

View file

@ -5542,6 +5542,21 @@ cleanup_bond:
return FALSE;
} else if (!strcmp (con_type, "bond-slave")) {
/* Slave types without any specific settings ('bond-slave') */
const char *master = NULL;
const char *type = NULL;
nmc_arg_t exp_args[] = { {"master", TRUE, &master, FALSE},
{"type", TRUE, &type, FALSE},
{NULL} };
/* Set global variables for use in TAB completion */
nmc_tab_completion.con_type = NM_SETTING_BOND_SETTING_NAME;
if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, error))
return FALSE;
if (!complete_slave (s_con, all_connections, slave_type, master, type, ask, error))
return FALSE;
/* Change properties in 'connection' setting */
g_object_set (s_con,
@ -5602,6 +5617,52 @@ cleanup_team:
return FALSE;
} else if (!strcmp (con_type, "team-slave")) {
/* Build up the settings required for 'team-slave' */
gboolean success = FALSE;
const char *master = NULL;
char *master_ask = NULL;
const char *type = NULL;
const char *config_c = NULL;
char *config = NULL;
char *json = NULL;
nmc_arg_t exp_args[] = { {"master", TRUE, &master, FALSE},
{"type", TRUE, &type, FALSE},
{"config", TRUE, &config_c, FALSE},
{NULL} };
/* Set global variables for use in TAB completion */
nmc_tab_completion.con_type = NM_SETTING_TEAM_SETTING_NAME;
if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, error))
return FALSE;
if (!complete_slave (s_con, all_connections, slave_type, master, type, ask, error))
return FALSE;
/* Also ask for all optional arguments if '--ask' is specified. */
config = g_strdup (config_c);
if (ask)
do_questionnaire_team_slave (&config);
/* Add 'team-port' setting */
s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new ();
nm_connection_add_setting (connection, NM_SETTING (s_team_port));
if (!nmc_team_check_config (config, &json, error)) {
g_prefix_error (error, _("Error: "));
goto cleanup_team_slave;
}
/* Set team-port options */
g_object_set (s_team_port, NM_SETTING_TEAM_PORT_CONFIG, json, NULL);
success = TRUE;
cleanup_team_slave:
g_free (master_ask);
g_free (config);
g_free (json);
if (!success)
return FALSE;
/* Change properties in 'connection' setting */
g_object_set (s_con,
@ -5752,6 +5813,80 @@ cleanup_bridge:
return FALSE;
} else if (!strcmp (con_type, "bridge-slave")) {
/* Build up the settings required for 'bridge-slave' */
gboolean success = FALSE;
const char *master = NULL;
char *master_ask = NULL;
const char *type = NULL;
const char *priority_c = NULL;
char *priority = NULL;
const char *path_cost_c = NULL;
char *path_cost = NULL;
const char *hairpin_c = NULL;
char *hairpin = NULL;
unsigned long prio_int, path_cost_int;
gboolean hairpin_bool;
nmc_arg_t exp_args[] = { {"master", TRUE, &master, FALSE},
{"type", TRUE, &type, FALSE},
{"priority", TRUE, &priority_c, FALSE},
{"path-cost", TRUE, &path_cost_c, FALSE},
{"hairpin", TRUE, &hairpin_c, FALSE},
{NULL} };
/* Set global variables for use in TAB completion */
nmc_tab_completion.con_type = NM_SETTING_BRIDGE_SETTING_NAME;
if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, error))
return FALSE;
if (!complete_slave (s_con, all_connections, slave_type, master, type, ask, error))
return FALSE;
/* Add 'bridge-port' setting */
/* Must be done *before* bridge_prop_string_to_uint() so that the type is known */
s_bridge_port = (NMSettingBridgePort *) nm_setting_bridge_port_new ();
nm_connection_add_setting (connection, NM_SETTING (s_bridge_port));
/* Also ask for all optional arguments if '--ask' is specified. */
priority = g_strdup (priority_c);
path_cost = g_strdup (path_cost_c);
hairpin = g_strdup (hairpin_c);
if (ask)
do_questionnaire_bridge_slave (&priority, &path_cost, &hairpin);
if (priority)
if (!bridge_prop_string_to_uint (priority, "priority", NM_TYPE_SETTING_BRIDGE_PORT,
NM_SETTING_BRIDGE_PORT_PRIORITY, &prio_int, error))
goto cleanup_bridge_slave;
if (path_cost)
if (!bridge_prop_string_to_uint (path_cost, "path-cost", NM_TYPE_SETTING_BRIDGE_PORT,
NM_SETTING_BRIDGE_PORT_PATH_COST, &path_cost_int, error))
goto cleanup_bridge_slave;
if (hairpin) {
GError *tmp_err = NULL;
if (!nmc_string_to_bool (hairpin, &hairpin_bool, &tmp_err)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: 'hairpin': %s."), tmp_err->message);
g_clear_error (&tmp_err);
goto cleanup_bridge_slave;
}
}
if (priority)
g_object_set (s_bridge_port, NM_SETTING_BRIDGE_PORT_PRIORITY, prio_int, NULL);
if (path_cost)
g_object_set (s_bridge_port, NM_SETTING_BRIDGE_PORT_PATH_COST, path_cost_int, NULL);
if (hairpin)
g_object_set (s_bridge_port, NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, hairpin_bool, NULL);
success = TRUE;
cleanup_bridge_slave:
g_free (master_ask);
g_free (priority);
g_free (path_cost);
g_free (hairpin);
if (!success)
return FALSE;
/* Change properties in 'connection' setting */
g_object_set (s_con,
@ -6414,144 +6549,7 @@ cleanup_vxlan:
}
slave_type = nm_setting_connection_get_slave_type (s_con);
if (slave_type) {
/* Set global variables for use in TAB completion */
nmc_tab_completion.con_type = (char *)slave_type;
if (!strcmp (slave_type, NM_SETTING_TEAM_SETTING_NAME)) {
/* Build up the settings required for 'team-slave' */
gboolean success = FALSE;
const char *master = NULL;
char *master_ask = NULL;
const char *type = NULL;
const char *config_c = NULL;
char *config = NULL;
char *json = NULL;
nmc_arg_t exp_args[] = { {"master", TRUE, &master, FALSE},
{"type", TRUE, &type, FALSE},
{"config", TRUE, &config_c, FALSE},
{NULL} };
if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, error))
return FALSE;
if (!complete_slave (s_con, all_connections, slave_type, master, type, ask, error))
return FALSE;
/* Also ask for all optional arguments if '--ask' is specified. */
config = g_strdup (config_c);
if (ask)
do_questionnaire_team_slave (&config);
/* Add 'team-port' setting */
s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new ();
nm_connection_add_setting (connection, NM_SETTING (s_team_port));
if (!nmc_team_check_config (config, &json, error)) {
g_prefix_error (error, _("Error: "));
goto cleanup_team_slave;
}
/* Set team-port options */
g_object_set (s_team_port, NM_SETTING_TEAM_PORT_CONFIG, json, NULL);
success = TRUE;
cleanup_team_slave:
g_free (master_ask);
g_free (config);
g_free (json);
if (!success)
return FALSE;
} else if (!strcmp (slave_type, NM_SETTING_BRIDGE_SETTING_NAME)) {
/* Build up the settings required for 'bridge-slave' */
gboolean success = FALSE;
const char *master = NULL;
char *master_ask = NULL;
const char *type = NULL;
const char *priority_c = NULL;
char *priority = NULL;
const char *path_cost_c = NULL;
char *path_cost = NULL;
const char *hairpin_c = NULL;
char *hairpin = NULL;
unsigned long prio_int, path_cost_int;
gboolean hairpin_bool;
nmc_arg_t exp_args[] = { {"master", TRUE, &master, FALSE},
{"type", TRUE, &type, FALSE},
{"priority", TRUE, &priority_c, FALSE},
{"path-cost", TRUE, &path_cost_c, FALSE},
{"hairpin", TRUE, &hairpin_c, FALSE},
{NULL} };
if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, error))
return FALSE;
if (!complete_slave (s_con, all_connections, slave_type, master, type, ask, error))
return FALSE;
/* Add 'bridge-port' setting */
/* Must be done *before* bridge_prop_string_to_uint() so that the type is known */
s_bridge_port = (NMSettingBridgePort *) nm_setting_bridge_port_new ();
nm_connection_add_setting (connection, NM_SETTING (s_bridge_port));
/* Also ask for all optional arguments if '--ask' is specified. */
priority = g_strdup (priority_c);
path_cost = g_strdup (path_cost_c);
hairpin = g_strdup (hairpin_c);
if (ask)
do_questionnaire_bridge_slave (&priority, &path_cost, &hairpin);
if (priority)
if (!bridge_prop_string_to_uint (priority, "priority", NM_TYPE_SETTING_BRIDGE_PORT,
NM_SETTING_BRIDGE_PORT_PRIORITY, &prio_int, error))
goto cleanup_bridge_slave;
if (path_cost)
if (!bridge_prop_string_to_uint (path_cost, "path-cost", NM_TYPE_SETTING_BRIDGE_PORT,
NM_SETTING_BRIDGE_PORT_PATH_COST, &path_cost_int, error))
goto cleanup_bridge_slave;
if (hairpin) {
GError *tmp_err = NULL;
if (!nmc_string_to_bool (hairpin, &hairpin_bool, &tmp_err)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: 'hairpin': %s."), tmp_err->message);
g_clear_error (&tmp_err);
goto cleanup_bridge_slave;
}
}
if (priority)
g_object_set (s_bridge_port, NM_SETTING_BRIDGE_PORT_PRIORITY, prio_int, NULL);
if (path_cost)
g_object_set (s_bridge_port, NM_SETTING_BRIDGE_PORT_PATH_COST, path_cost_int, NULL);
if (hairpin)
g_object_set (s_bridge_port, NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, hairpin_bool, NULL);
success = TRUE;
cleanup_bridge_slave:
g_free (master_ask);
g_free (priority);
g_free (path_cost);
g_free (hairpin);
if (!success)
return FALSE;
} else {
/* Slave types without any specific settings ('bond-slave') */
const char *master = NULL;
const char *type = NULL;
nmc_arg_t exp_args[] = { {"master", TRUE, &master, FALSE},
{"type", TRUE, &type, FALSE},
{NULL} };
if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, error))
return FALSE;
if (!complete_slave (s_con, all_connections, slave_type, master, type, ask, error))
return FALSE;
}
} else {
if (!slave_type) {
/* Read and add IP configuration */
NMIPAddress *ip4addr = NULL, *ip6addr = NULL;
const char *ip4 = NULL, *gw4 = NULL, *ip6 = NULL, *gw6 = NULL;

View file

@ -435,7 +435,7 @@ See \fBconnection show\fP above for the description of the <ID>-specifying keywo
.br
If '--wait' option is not specified, the default timeout will be 10 seconds.
.TP
.B add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- [+|-]<setting>.<property> <value> ...]
.B add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS [-- [+|-]<setting>.<property> <value> ...]
.br
Add a connection for NetworkManager. Arguments differ according to connection types, see below.
.RS
@ -460,7 +460,6 @@ Note: use quotes around \fB*\fP to suppress shell expansion.
.IP "\fI[master <master (ifname, or connection UUID or name)>]\fP" 42
\(en master interface name, or connection UUID or ID of master connection profile.
The value can be prefixed with \fBifname/\fP, \fBuuid/\fP or \fBid/\fP to disambiguate it.
See below \fBSLAVE_OPTIONS\fP for additional options for slave connection to masters of various types.
.IP "\fI[slave-type <master connection type>]\fP" 42
\(en type of master connection. Only required when it can not be inferred (i.e. the master connection does
not exist yet).
@ -610,6 +609,11 @@ The value can be prefixed with \fBifname/\fP, \fBuuid/\fP or \fBid/\fP to disamb
.RE
.RS
.TP
.IP "\fI[config <file>|<raw JSON data>]\fP" 42
\(en JSON configuration for team
.RE
.RS
.TP
.B bridge:
.IP "\fI[stp yes|no]\fP" 42
\(en controls whether Spanning Tree Protocol (STP) is enabled for this bridge (default: yes)
@ -638,6 +642,16 @@ The value can be prefixed with \fBifname/\fP, \fBuuid/\fP or \fBid/\fP to disamb
.RE
.RS
.TP
.IP "\fI[priority <0-63>]\fP" 42
\(en STP priority of this slave (default: 32)
.IP "\fI[path-cost <1-65535>]\fP" 42
\(en STP port cost for destinations via this slave (default: 100)
.IP "\fI[hairpin yes|no]\fP" 42
\(en 'hairpin mode' for the slave, which allows frames
to be sent back out through the slave the frame was received on (default: yes)
.RE
.RS
.TP
.B vpn:
.IP "\fIvpn-type vpnc|openvpn|pptp|openconnect|openswan|libreswan|strongswan|ssh|l2tp|iodine|fortisslvpn|...\fP" 42
\(en VPN type
@ -724,27 +738,6 @@ The value can be prefixed with \fBifname/\fP, \fBuuid/\fP or \fBid/\fP to disamb
.RE
.RS
.TP
.B SLAVE_OPTIONS:
.RE
.RS
.TP
.B bridge:
.IP "\fI[priority <0-63>]\fP" 42
\(en STP priority of this slave (default: 32)
.IP "\fI[path-cost <1-65535>]\fP" 42
\(en STP port cost for destinations via this slave (default: 100)
.IP "\fI[hairpin yes|no]\fP" 42
\(en 'hairpin mode' for the slave, which allows frames
to be sent back out through the slave the frame was received on (default: yes)
.RE
.RS
.TP
.B team:
.IP "\fI[config <file>|<raw JSON data>]\fP" 42
\(en JSON configuration for team
.RE
.RS
.TP
.B IP_OPTIONS:
.IP "\fI[ip4 <IPv4 address>] [gw4 <IPv4 gateway>]\fP" 42
\(en IPv4 addresses