cli: 'con add': make ifname mandatory (except bond,bridge,vlan) (bgo #698113)

Optional 'ifname' allowed creating connection applicable to all interfaces,
which was confusing for some users. Now we require the user to provide ifname
to lock the connection for an interface. An "unbound" connection can be
created with ifname "*".

$ nmcli connection add type eth ifname eth0

$ nmcli connection add type eth
now becomes
$ nmcli connection add type eth ifname "*"

bond, bridge:
- when ifname is not specified or is "*",
  interface name is generated (nm-bond, nm-bridge)
vlan:
- when ifname is not specified or is "*",
  vlan device is named "dev.id"

Note: the quotes around * are required to suppress shell expansion.
This commit is contained in:
Jiří Klimeš
2013-06-10 15:31:09 +02:00
parent 88d9db0cdb
commit a91eafdf95
2 changed files with 30 additions and 6 deletions

View File

@@ -217,9 +217,9 @@ usage_connection_add (void)
" OPTIONS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n"
" COMMON_OPTIONS:\n"
" type <type>\n"
" ifname <interface name> | \"*\"\n"
" [con-name <connection name>]\n"
" [autoconnect yes|no]\n"
" [ifname <interface name>]\n\n"
" [autoconnect yes|no]\n\n"
" TYPE_SPECIFIC_OPTIONS:\n"
" ethernet: [mac <MAC address>]\n"
" [cloned-mac <cloned MAC address>]\n"
@@ -2925,6 +2925,8 @@ do_connection_add (NmCli *nmc, int argc, char **argv)
const char *autoconnect = NULL;
gboolean auto_bool = TRUE;
const char *ifname = NULL;
char *ifname_ask = NULL;
gboolean ifname_mandatory = TRUE;
AddConnectionInfo *info = NULL;
const char *setting_name;
GError *error = NULL;
@@ -2972,13 +2974,31 @@ do_connection_add (NmCli *nmc, int argc, char **argv)
goto error;
}
}
/* ifname is mandatory for all connection types except virtual ones (bond, bridge, vlan) */
if ( strcmp (type, NM_SETTING_BOND_SETTING_NAME) == 0
|| strcmp (type, NM_SETTING_BRIDGE_SETTING_NAME) == 0
|| strcmp (type, NM_SETTING_VLAN_SETTING_NAME) == 0)
ifname_mandatory = FALSE;
if (!ifname && ifname_mandatory && nmc->ask)
ifname = ifname_ask = nmc_get_user_input (_("Interface name: "));
if (!ifname && ifname_mandatory) {
g_string_printf (nmc->return_text, _("Error: 'ifname' argument is required."));
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
if (ifname) {
if (!nm_utils_iface_valid_name (ifname)) {
if (!nm_utils_iface_valid_name (ifname) && strcmp (ifname, "*") != 0) {
g_string_printf (nmc->return_text,
_("Error: 'ifname': '%s' is not a valid interface."),
_("Error: 'ifname': '%s' is not a valid interface nor '*'."),
ifname);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
/* Special value of '*' means no specific interface name */
if (strcmp (ifname, "*") == 0)
ifname = NULL;
}
/* Create a new connection object */
@@ -3041,6 +3061,7 @@ error:
if (connection)
g_object_unref (connection);
g_free (type_ask);
g_free (ifname_ask);
nmc->should_wait = FALSE;
return nmc->return_value;

View File

@@ -325,12 +325,15 @@ Add a connection for NetworkManager. Arguments differ according to connection ty
.B COMMON_OPTIONS:
.IP "\fItype <type>\fP" 42
\(en connection type; see bellow \fBTYPE_SPECIFIC_OPTIONS\fP for allowed values; (mandatory)
.IP "\fIifname <ifname> | \(dq\&*\(dq\&\fP" 42
\(en interface to bind the connection to. The connection will only be applicable to this
interface name. A special value of "\fB*\fP" can be used for interface-independent connections.
The \fIifname\fP argument is mandatory for all connection types except bond, bridge and vlan.
Note: use quotes around \fB*\fP to suppress shell expansion.
.IP "\fI[con-name <connection name>]\fP" 42
\(en connection name (when not provided a default name is generated: <type>[-<ifname>][-<num>])
.IP "\fI[autoconnect yes|no]\fP" 42
\(en whether the connection can auto-connect or not
.IP "\fI[ifname <ifname>]\fP" 42
\(en interface to bind the connection to
.RE
.RS
.TP