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:
@@ -217,9 +217,9 @@ usage_connection_add (void)
|
|||||||
" OPTIONS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n"
|
" OPTIONS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n"
|
||||||
" COMMON_OPTIONS:\n"
|
" COMMON_OPTIONS:\n"
|
||||||
" type <type>\n"
|
" type <type>\n"
|
||||||
|
" ifname <interface name> | \"*\"\n"
|
||||||
" [con-name <connection name>]\n"
|
" [con-name <connection name>]\n"
|
||||||
" [autoconnect yes|no]\n"
|
" [autoconnect yes|no]\n\n"
|
||||||
" [ifname <interface name>]\n\n"
|
|
||||||
" TYPE_SPECIFIC_OPTIONS:\n"
|
" TYPE_SPECIFIC_OPTIONS:\n"
|
||||||
" ethernet: [mac <MAC address>]\n"
|
" ethernet: [mac <MAC address>]\n"
|
||||||
" [cloned-mac <cloned 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;
|
const char *autoconnect = NULL;
|
||||||
gboolean auto_bool = TRUE;
|
gboolean auto_bool = TRUE;
|
||||||
const char *ifname = NULL;
|
const char *ifname = NULL;
|
||||||
|
char *ifname_ask = NULL;
|
||||||
|
gboolean ifname_mandatory = TRUE;
|
||||||
AddConnectionInfo *info = NULL;
|
AddConnectionInfo *info = NULL;
|
||||||
const char *setting_name;
|
const char *setting_name;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@@ -2972,13 +2974,31 @@ do_connection_add (NmCli *nmc, int argc, char **argv)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ifname) {
|
|
||||||
if (!nm_utils_iface_valid_name (ifname)) {
|
/* ifname is mandatory for all connection types except virtual ones (bond, bridge, vlan) */
|
||||||
g_string_printf (nmc->return_text,
|
if ( strcmp (type, NM_SETTING_BOND_SETTING_NAME) == 0
|
||||||
_("Error: 'ifname': '%s' is not a valid interface."),
|
|| strcmp (type, NM_SETTING_BRIDGE_SETTING_NAME) == 0
|
||||||
ifname);
|
|| 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;
|
goto error;
|
||||||
}
|
}
|
||||||
|
if (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 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 */
|
/* Create a new connection object */
|
||||||
@@ -3041,6 +3061,7 @@ error:
|
|||||||
if (connection)
|
if (connection)
|
||||||
g_object_unref (connection);
|
g_object_unref (connection);
|
||||||
g_free (type_ask);
|
g_free (type_ask);
|
||||||
|
g_free (ifname_ask);
|
||||||
|
|
||||||
nmc->should_wait = FALSE;
|
nmc->should_wait = FALSE;
|
||||||
return nmc->return_value;
|
return nmc->return_value;
|
||||||
|
@@ -325,12 +325,15 @@ Add a connection for NetworkManager. Arguments differ according to connection ty
|
|||||||
.B COMMON_OPTIONS:
|
.B COMMON_OPTIONS:
|
||||||
.IP "\fItype <type>\fP" 42
|
.IP "\fItype <type>\fP" 42
|
||||||
\(en connection type; see bellow \fBTYPE_SPECIFIC_OPTIONS\fP for allowed values; (mandatory)
|
\(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
|
.IP "\fI[con-name <connection name>]\fP" 42
|
||||||
\(en connection name (when not provided a default name is generated: <type>[-<ifname>][-<num>])
|
\(en connection name (when not provided a default name is generated: <type>[-<ifname>][-<num>])
|
||||||
.IP "\fI[autoconnect yes|no]\fP" 42
|
.IP "\fI[autoconnect yes|no]\fP" 42
|
||||||
\(en whether the connection can auto-connect or not
|
\(en whether the connection can auto-connect or not
|
||||||
.IP "\fI[ifname <ifname>]\fP" 42
|
|
||||||
\(en interface to bind the connection to
|
|
||||||
.RE
|
.RE
|
||||||
.RS
|
.RS
|
||||||
.TP
|
.TP
|
||||||
|
Reference in New Issue
Block a user