diff options
-rw-r--r-- | clients/cli/devices.c | 124 | ||||
-rw-r--r-- | clients/cli/nmcli-completion | 10 | ||||
-rw-r--r-- | man/nmcli.xml | 52 |
3 files changed, 181 insertions, 5 deletions
diff --git a/clients/cli/devices.c b/clients/cli/devices.c index d4aa76e9b7..774a2254d2 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -30,6 +30,7 @@ #include "utils.h" #include "common.h" #include "devices.h" +#include "connections.h" /* define some prompts */ #define PROMPT_INTERFACE _("Interface: ") @@ -359,6 +360,26 @@ usage_device_reapply (void) } static void +usage_device_modify (void) +{ + g_printerr (_("Usage: nmcli connection modify { ARGUMENTS | --help }\n" + "\n" + "ARGUMENTS := <ifname> ([+|-]<setting>.<property> <value>)+\n" + "\n" + "Modify one or more properties currently active on the device without modifying\n" + "the connection profile. The changes have immediate effect. For multi-valued\n" + "properties you can use optional '+' or '-' prefix to the property name.\n" + "The '+' sign allows appending items instead of overwriting the whole value.\n" + "The '-' sign allows removing selected items instead of the whole value.\n" + "\n" + "Examples:\n" + "nmcli dev mod em1 ipv4.method manual ipv4.addr \"192.168.1.2/24, 10.10.1.5/8\"\n" + "nmcli dev mod em1 +ipv4.dns 8.8.4.4\n" + "nmcli dev mod em1 -ipv4.dns 1\n" + "nmcli dev mod em1 -ipv6.addr \"abbe::cafe/56\"\n")); +} + +static void usage_device_disconnect (void) { g_printerr (_("Usage: nmcli device disconnect { ARGUMENTS | help }\n" @@ -1997,6 +2018,108 @@ do_device_reapply (NmCli *nmc, int argc, char **argv) return nmc->return_value; } +typedef struct { + NmCli *nmc; + int argc; + char **argv; +} ModifyInfo; + +static void +modify_reapply_cb (GObject *object, GAsyncResult *result, gpointer user_data) +{ + NMDevice *device = NM_DEVICE (object); + ModifyInfo *info = user_data; + NmCli *nmc = info->nmc; + GError *error = NULL; + + if (!nm_device_reapply_finish (device, result, &error)) { + g_string_printf (nmc->return_text, _("Error: Reapplying connection to device '%s' (%s) failed: %s"), + nm_device_get_iface (device), + nm_object_get_path (NM_OBJECT (device)), + error->message); + g_error_free (error); + nmc->return_value = NMC_RESULT_ERROR_DEV_DISCONNECT; + } else { + if (nmc->print_output == NMC_PRINT_PRETTY) + nmc_terminal_erase_line (); + g_print (_("Connection successfully reapplied to device '%s'.\n"), + nm_device_get_iface (device)); + } + + g_slice_free (ModifyInfo, info); + quit (); +} + +static void +modify_get_applied_cb (GObject *object, + GAsyncResult *result, + gpointer user_data) +{ + NMDevice *device = NM_DEVICE (object); + ModifyInfo *info = user_data; + NmCli *nmc = info->nmc; + gs_free_error GError *error = NULL; + NMConnection *connection; + guint64 version_id; + + connection = nm_device_get_applied_connection_finish (device, + result, + &version_id, + &error); + if (!connection) { + g_string_printf (nmc->return_text, _("Error: Reading applied connection from device '%s' (%s) failed: %s"), + nm_device_get_iface (device), + nm_object_get_path (NM_OBJECT (device)), + error->message); + nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; + g_slice_free (ModifyInfo, info); + quit (); + return; + } + + if (!nmc_read_connection_properties (info->nmc, connection, &info->argc, &info->argv, &error)) { + g_string_assign (nmc->return_text, error->message); + nmc->return_value = error->code; + g_slice_free (ModifyInfo, info); + quit (); + return; + } + + if (nmc->complete) + quit (); + else + nm_device_reapply_async (device, connection, version_id, 0, NULL, modify_reapply_cb, info); +} + +static NMCResultCode +do_device_modify (NmCli *nmc, int argc, char **argv) +{ + NMDevice *device = NULL; + ModifyInfo *info = NULL; + gs_free_error GError *error = NULL; + + device = get_device (nmc, &argc, &argv, &error); + if (!device) { + g_string_printf (nmc->return_text, _("Error: %s."), error->message); + return error->code; + } + + if (nmc->timeout == -1) + nmc->timeout = 10; + + nmc->nowait_flag = (nmc->timeout == 0); + nmc->should_wait++; + + info = g_slice_new0 (ModifyInfo); + info->nmc = nmc; + info->argc = argc; + info->argv = argv; + + nm_device_get_applied_connection_async (device, 0, NULL, modify_get_applied_cb, info); + + return nmc->return_value; +} + static void disconnect_device_cb (GObject *object, GAsyncResult *result, gpointer user_data) { @@ -3757,6 +3880,7 @@ static const NMCCommand device_cmds[] = { {"monitor", do_devices_monitor, usage_device_monitor }, {"wifi", do_device_wifi, usage_device_wifi }, {"lldp", do_device_lldp, usage_device_lldp }, + {"modify", do_device_modify, usage_device_modify }, {NULL, do_devices_status, usage }, }; diff --git a/clients/cli/nmcli-completion b/clients/cli/nmcli-completion index bb47f2d6ae..e78ab85c82 100644 --- a/clients/cli/nmcli-completion +++ b/clients/cli/nmcli-completion @@ -1184,7 +1184,7 @@ _nmcli() ;; d|de|dev|devi|devic|device) if [[ ${#words[@]} -eq 2 ]]; then - _nmcli_compl_COMMAND "$command" status show connect reapply disconnect delete monitor wifi set lldp + _nmcli_compl_COMMAND "$command" status show connect reapply modify disconnect delete monitor wifi set lldp elif [[ ${#words[@]} -gt 2 ]]; then case "$command" in s|st|sta|stat|statu|status) @@ -1199,6 +1199,14 @@ _nmcli() _nmcli_compl_COMMAND_nl "${words[2]}" "$(_nmcli_dev_status DEVICE)" fi ;; + mod|modi|modif|modify) + if [[ ${#words[@]} -eq 3 ]]; then + _nmcli_compl_COMMAND_nl "${words[2]}" "$(nmcli --complete-args device modify "" 2>/dev/null)" + else + _nmcli_array_delete_at words 0 1 + _nmcli_list_nl "$(nmcli --complete-args device modify "${words[@]}" 2>/dev/null)" + fi + ;; d|di|dis|disc|disco|discon|disconn|disconne|disconnec|disconnect| \ de|del|dele|delet|delete| \ m|mo|mon|moni|monit|monito|monitor) diff --git a/man/nmcli.xml b/man/nmcli.xml index a1f0062cd7..ff8e63e699 100644 --- a/man/nmcli.xml +++ b/man/nmcli.xml @@ -1163,6 +1163,7 @@ <arg choice='plain'><command>set</command></arg> <arg choice='plain'><command>connect</command></arg> <arg choice='plain'><command>reapply</command></arg> + <arg choice='plain'><command>modify</command></arg> <arg choice='plain'><command>disconnect</command></arg> <arg choice='plain'><command>delete</command></arg> <arg choice='plain'><command>monitor</command></arg> @@ -1256,6 +1257,33 @@ <varlistentry> <term> + <command>modify</command> + <arg rep='repeat' choice='plain'> + <group> + <arg choice='plain'><replaceable>option</replaceable> <replaceable>value</replaceable></arg> + <arg choice='plain'>[+|-]<replaceable>setting</replaceable>.<replaceable>property</replaceable> <replaceable>value</replaceable></arg> + </group> + </arg> + </term> + + <listitem> + <para>Modify the settings currently active on the device.</para> + + <para>This command lets you do temporary changes to a configuration active on + a particular device. The changes are not preserved in the connection profile.</para> + + <para>See <citerefentry><refentrytitle>nm-settings</refentrytitle><manvolnum>5</manvolnum> + </citerefentry> for the list of available properties. Please note that some + properties can't be changed on an already connected device.</para> + + <para>You can also use the aliases described in + <link linkend='property_aliases' endterm='property_aliases.title' /> section. The syntax is + the same as of the <command>nmcli connection modify</command> command.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> <command>disconnect</command> <arg rep='repeat'><replaceable>ifname</replaceable></arg> </term> @@ -1599,10 +1627,10 @@ <refsect1 id='property_aliases'><title id='property_aliases.title'>Property Aliases</title> - <para>Apart from the property-value pairs, <command>connection - add</command> and <command>connection modify</command> also accept short forms - of some properties. They exist for convenience and compatiblity with older - versions of <command>nmcli</command> that could not accept the raw + <para>Apart from the property-value pairs, <command>connection add</command>, + <command>connection modify</command> and <command>device modify</command> also + accept short forms of some properties. They exist for convenience and compatiblity + with older versions of <command>nmcli</command> that could not accept the raw properties.</para> <para>The overview of the aliases is below. An actual connection type is used to @@ -2229,6 +2257,22 @@ It's equivalent of using <literal>+ipv6.addresses</literal> syntax.</entry> </varlistentry> <varlistentry> + <term><userinput>nmcli dev modify em1 ipv4.method shared</userinput></term> + <listitem> + <para>starts IPv4 connection sharing using em1 device. The sharing will be active + until the device is disconnected.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term><userinput>nmcli dev modify em1 ipv6.address 2001:db8::a:bad:c0de</userinput></term> + <listitem> + <para>temporarily adds an IP address to a device. The address will be removed + when the same connection is activated again.</para> + </listitem> + </varlistentry> + + <varlistentry> <term><userinput>nmcli connection add type ethernet autoconnect no ifname eth0</userinput></term> <listitem> <para>non-interactively adds an Ethernet connection tied to eth0 interface with |