cli: add support for 'nmcli con up ifname XXX'
Passes a NULL connection to nm_client_activate_connection() allowing NetworkManager to pick the best available connection for the interface.
This commit is contained in:
@@ -502,6 +502,13 @@ _nmcli_complete_COMMAND_CONNECTION()
|
||||
fi
|
||||
words=("${words[@]:2}")
|
||||
;;
|
||||
ifname)
|
||||
if [[ ${#words[@]} -eq 2 ]]; then
|
||||
_nmcli_list_nl "$(_nmcli_NM_devices)"
|
||||
return 0
|
||||
fi
|
||||
words=("${words[@]:2}")
|
||||
;;
|
||||
*)
|
||||
COMMAND_CONNECTION_TYPE=
|
||||
COMMAND_CONNECTION_ID="${words[0]}"
|
||||
@@ -601,12 +608,18 @@ _nmcli()
|
||||
;;
|
||||
u|up)
|
||||
if [[ ${#words[@]} -eq 3 ]]; then
|
||||
_nmcli_list_nl "$(printf "id\nuuid\npath\n%s" "$(_nmcli_con_id)")"
|
||||
_nmcli_list_nl "$(printf "ifname\nid\nuuid\npath\n%s" "$(_nmcli_con_id)")"
|
||||
elif [[ ${#words[@]} -gt 3 ]]; then
|
||||
local COMMAND_CONNECTION_TYPE=''
|
||||
words=("${words[@]:2}")
|
||||
OPTIONS=(id uuid path)
|
||||
OPTIONS=(ifname id uuid path)
|
||||
_nmcli_complete_COMMAND_CONNECTION && return 0
|
||||
|
||||
if [[ "$COMMAND_CONNECTION_TYPE" = "ifname" ]]; then
|
||||
OPTIONS=(ap nsp)
|
||||
else
|
||||
OPTIONS=(ifname ap nsp)
|
||||
fi
|
||||
_nmcli_complete_COMMAND_ARGS
|
||||
fi
|
||||
;;
|
||||
|
@@ -218,9 +218,9 @@ usage (void)
|
||||
" show configured [[ id | uuid | path ] <ID>]\n\n"
|
||||
" show active [[ id | uuid | path | apath ] <ID>]\n\n"
|
||||
#if WITH_WIMAX
|
||||
" up [ id | uuid | path ] <ID> [ifname <ifname>] [ap <BSSID>] [nsp <name>]\n\n"
|
||||
" up [[ id | uuid | path ] <ID>] [ifname <ifname>] [ap <BSSID>] [nsp <name>]\n\n"
|
||||
#else
|
||||
" up [ id | uuid | path ] <ID> [ifname <ifname>] [ap <BSSID>]\n\n"
|
||||
" up [[ id | uuid | path ] <ID>] [ifname <ifname>] [ap <BSSID>]\n\n"
|
||||
#endif
|
||||
" down [ id | uuid | path | apath ] <ID>\n\n"
|
||||
" add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n"
|
||||
@@ -1517,9 +1517,10 @@ nmc_activate_connection (NmCli *nmc,
|
||||
GError *local = NULL;
|
||||
|
||||
g_return_val_if_fail (nmc != NULL, FALSE);
|
||||
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
|
||||
g_return_val_if_fail (NM_IS_CONNECTION (connection) || ifname, FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
if (connection) {
|
||||
if (nm_connection_get_virtual_iface_name (connection))
|
||||
is_virtual = TRUE;
|
||||
|
||||
@@ -1531,6 +1532,18 @@ nmc_activate_connection (NmCli *nmc,
|
||||
g_clear_error (&local);
|
||||
return FALSE;
|
||||
}
|
||||
} else if (ifname) {
|
||||
device = nm_client_get_device_by_iface (nmc->client, ifname);
|
||||
if (!device) {
|
||||
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_CON_ACTIVATION,
|
||||
_("unknown device '%s'."), ifname);
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_CON_ACTIVATION,
|
||||
_("no connection and no device given."));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
info = g_malloc0 (sizeof (ActivateConnectionInfo));
|
||||
info->nmc = nmc;
|
||||
@@ -1554,7 +1567,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
||||
const char *nsp = NULL;
|
||||
GError *error = NULL;
|
||||
const char *selector = NULL;
|
||||
const char *name;
|
||||
const char *name = NULL;
|
||||
char *line = NULL;
|
||||
|
||||
/*
|
||||
@@ -1570,12 +1583,8 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
||||
name = line ? line : "";
|
||||
// TODO: enhancement: when just Enter is pressed (line is NULL), list
|
||||
// available connections so that the user can select one
|
||||
} else {
|
||||
g_string_printf (nmc->return_text, _("Error: No connection specified."));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
} else if (strcmp (*argv, "ifname") != 0) {
|
||||
if ( strcmp (*argv, "id") == 0
|
||||
|| strcmp (*argv, "uuid") == 0
|
||||
|| strcmp (*argv, "path") == 0) {
|
||||
@@ -1589,16 +1598,11 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
||||
name = *argv;
|
||||
}
|
||||
name = *argv;
|
||||
}
|
||||
|
||||
connection = find_connection (nmc->system_connections, selector, name);
|
||||
|
||||
if (!connection) {
|
||||
g_string_printf (nmc->return_text, _("Error: Unknown connection: %s."), name);
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
goto error;
|
||||
}
|
||||
next_arg (&argc, &argv);
|
||||
}
|
||||
|
||||
if (name)
|
||||
connection = find_connection (nmc->system_connections, selector, name);
|
||||
|
||||
while (argc > 0) {
|
||||
if (strcmp (*argv, "ifname") == 0) {
|
||||
|
@@ -304,14 +304,20 @@ When no command is given to the \fIconnection\fP object, the default action
|
||||
is 'nmcli connection show configured'.
|
||||
.TP
|
||||
.B up [ id | uuid | path ] <ID> [ifname <ifname>] [ap <BSSID>] [nsp <name>]
|
||||
.RE
|
||||
.RS
|
||||
.B up ifname <ifname> [ap <BSSID>] [nsp <name>]
|
||||
.RS
|
||||
.br
|
||||
Activate a connection. The connection is identified by its name, UUID or D-Bus
|
||||
path. If <ID> is ambiguous, a keyword \fIid\fP, \fIuuid\fP or \fIpath\fP can be
|
||||
used. When requiring a particular device to activate the connection on, the
|
||||
\fIifname\fP option with interface name should be given. In case of a VPN
|
||||
connection, the \fIifname\fP option specify the device of the base connection.
|
||||
The \fIap\fP option specify what particular AP should be used in case of
|
||||
a Wi\(hyFi connection.
|
||||
\fIifname\fP option with interface name should be given. If the <ID> is not
|
||||
given an \fIifname\fP is required, and NetworkManager will activate the best
|
||||
available connection for the given \fIifname\fP. In case of a VPN connection,
|
||||
the \fIifname\fP option specifies the device of the base connection. The
|
||||
\fIap\fP option specify what particular AP should be used in case of a Wi\(hyFi
|
||||
connection.
|
||||
.br
|
||||
If '--wait' option is not specified, the default timeout will be 90 seconds.
|
||||
.br
|
||||
@@ -326,6 +332,7 @@ Available options are:
|
||||
.IP \fInsp\fP 13
|
||||
\(en NSP (Network Service Provider) which the command should connect to (for WiMAX connections)
|
||||
.RE
|
||||
.RE
|
||||
.TP
|
||||
.B down [ id | uuid | path | apath ] <ID>
|
||||
.br
|
||||
|
Reference in New Issue
Block a user