Commit Graph

692 Commits

Author SHA1 Message Date
Lubomir Rintel
ac58146298 cli/agent: use nmc_do_cmd() 2016-08-01 13:52:36 +02:00
Lubomir Rintel
b37c109ee4 cli/radio: add subcommand completion 2016-08-01 13:52:36 +02:00
Lubomir Rintel
5305dfdf19 cli/radio: use nmc_do_cmd() 2016-08-01 13:52:36 +02:00
Lubomir Rintel
2b860e4e95 cli/general: add subcommand completion 2016-08-01 13:52:36 +02:00
Lubomir Rintel
7b6ded8cc4 cli/general: use nmc_do_cmd() 2016-08-01 13:52:36 +02:00
Lubomir Rintel
d73c0e57d5 cli: add ability to indicate command completion expects a file name 2016-08-01 13:52:36 +02:00
Lubomir Rintel
9827725210 cli: get rid of the global command completion whitelist
We're going to implement most of the missing pieces; the rest is going
to handle inability to complete itself.
2016-08-01 13:52:36 +02:00
Lubomir Rintel
60f992c5d3 cli: handle global usage with nmc_do_cmd() 2016-08-01 13:52:36 +02:00
Lubomir Rintel
33cd5149f8 cli: do not skip over a nonexistent argument in nmc_do_cmd()
If we're called without an argument, don't shift arguments of the
callback -- it would be called with argc==-1.
2016-08-01 13:52:36 +02:00
Lubomir Rintel
ba45b5ac6f cli: take a reference to the device when activating
It can go away before the activation finishes:

  (process:378): GLib-GObject-WARNING **: instance with invalid (NULL) class pointer

  Thread 1 "lt-nmcli" received signal SIGTRAP, Trace/breakpoint trap.
  0x00007ffff4fa919b in g_logv () from /lib64/libglib-2.0.so.0
  (gdb) bt
  #0  0x00007ffff4fa919b in g_logv () at /lib64/libglib-2.0.so.0
  #1  0x00007ffff4fa930f in g_log () at /lib64/libglib-2.0.so.0
  #2  0x00007ffff529b3ea in g_type_check_instance () at /lib64/libgobject-2.0.so.0
  #3  0x00007ffff528fa94 in g_signal_handlers_disconnect_matched () at /lib64/libgobject-2.0.so.0
  #4  0x000000000041ae4e in activate_connection_info_finish (info=0x7b5490) at connections.c:2197
  #5  0x00007ffff5279470 in g_cclosure_marshal_VOID__OBJECTv () at /lib64/libgobject-2.0.so.0
  #6  0x00007ffff5276617 in _g_closure_invoke_va () at /lib64/libgobject-2.0.so.0
  #7  0x00007ffff5290ea9 in g_signal_emit_valist () at /lib64/libgobject-2.0.so.0
  #8  0x00007ffff52914ff in g_signal_emit () at /lib64/libgobject-2.0.so.0
  #9  0x00007ffff52763e8 in g_closure_invoke () at /lib64/libgobject-2.0.so.0
  #10 0x00007ffff52884a2 in signal_emit_unlocked_R () at /lib64/libgobject-2.0.so.0
  #11 0x00007ffff529112d in g_signal_emit_valist () at /lib64/libgobject-2.0.so.0
  #12 0x00007ffff52919ab in g_signal_emit_by_name () at /lib64/libgobject-2.0.so.0
  #13 0x00007ffff78fc9b1 in deferred_notify_cb (data=<optimized out>) at nm-object.c:243
  #14 0x00007ffff4fa2703 in g_main_context_dispatch () at /lib64/libglib-2.0.so.0
  #15 0x00007ffff4fa2ab0 in g_main_context_iterate.isra () at /lib64/libglib-2.0.so.0
  #16 0x00007ffff4fa2dd2 in g_main_loop_run () at /lib64/libglib-2.0.so.0
  #17 0x00000000004146e3 in main (argc=<optimized out>, argv=<optimized out>) at nmcli.c:618
  (gdb) print info->device
2016-07-28 11:22:31 +02:00
Beniamino Galvani
1fbdd4d008 cli: fix crash on connection delete/down timeout
connection_op_timeout_cb() passed a wrong object type to timeout_cb();
fix this.

Fixes: ac888de151

https://bugzilla.redhat.com/show_bug.cgi?id=1355740
2016-07-23 08:54:32 +02:00
Francesco Giudici
65771b80a6 cli: improve devices vs connection compatibility check
report error message on device compatibility failures
2016-07-22 19:36:23 +02:00
Beniamino Galvani
e7bd55afdd cli: fix typo in overview output
Fixes: f14845cc20
2016-07-20 09:31:11 +02:00
Lubomir Rintel
f14845cc20 cli: output a short summary of devices when called without arguments
This aims to be somewhat similar to what "ifconfig" does.

https://bugzilla.gnome.org/show_bug.cgi?id=766426
2016-07-19 14:29:05 +02:00
Lubomir Rintel
402828d2ed cli/devices: export device_state_to_color()
Also, get rid of the ColorInfo structure. It was not too nice anyway.
2016-07-19 14:29:05 +02:00
Lubomir Rintel
65c6eb5ce5 cli/connections: split out ac_state_to_color()
Going to be useful outside nmcli c.
2016-07-19 14:29:05 +02:00
Jiří Klimeš
2544f78858 nmcli: add missing commands to 'nmcli connection help' usage description 2016-07-15 12:26:24 +02:00
Jiří Klimeš
c875471430 nmcli: fix 'nmcli device modify' description
Fixes: 8b4494598d
2016-07-15 12:26:24 +02:00
Jiří Klimeš
887cdcc217 nmcli: remove the extra full stop from error messages
$ nmcli dev modify
Error: No interface specified..
$ nmcli dev modify bla
Error: Device 'bla' not found..
2016-07-15 11:43:32 +02:00
Lubomir Rintel
ac888de151 cli/connections: fail the activation when the active connection disappears
Relying solemnly on device or active connection state is unreliable.
2016-07-07 11:56:05 +02:00
Beniamino Galvani
938a4b35c6 cli: fix parsing of route metric on 32-bit archs
On 32-bit architectures long and int have the same size and thus it's
wrong to use nmc_string_to_int() since it uses strtol() and the @max
argument can't represent G_MAXUINT32. Use nmc_string_to_uint()
instead.

https://bugzilla.redhat.com/show_bug.cgi?id=1350201
2016-06-30 13:19:46 +02:00
Thomas Haller
96cabbcbb8 all: make MAC address randomization algorithm configurable
For the per-connection settings "ethernet.cloned-mac-address"
and "wifi.cloned-mac-address", and for the per-device setting
"wifi.scan-rand-mac-address", we may generate MAC addresses using
either the "random" or "stable" algorithm.

Add new properties "generate-mac-address-mask" that allow to configure
which bits of the MAC address will be scrambled.

By default, the "random" and "stable" algorithms scamble all bits
of the MAC address, including the OUI part and generate a locally-
administered, unicast address.

By specifying a MAC address mask, we can now configure to perserve
parts of the current MAC address of the device. For example, setting
"FF:FF:FF:00:00:00" will preserve the first 3 octects of the current
MAC address.

One can also explicitly specify a MAC address to use instead of the
current MAC address. For example, "FF:FF:FF:00:00:00 68:F7:28:00:00:00"
sets the OUI part of the MAC address to "68:F7:28" while scrambling
the last 3 octects.
Similarly, "02:00:00:00:00:00 00:00:00:00:00:00" will scamble
all bits of the MAC address, except clearing the second-least
significant bit. Thus, creating a burned-in address, globally
administered.

One can also supply a list of MAC addresses like
"FF:FF:FF:00:00:00 68:F7:28:00:00:00 00:0C:29:00:00:00 ..." in which
case a MAC address is choosen randomly.

To fully scamble the MAC address one can configure
"02:00:00:00:00:00 00:00:00:00:00:00 02:00:00:00:00:00".
which also randomly creates either a locally or globally administered
address.

With this, the following macchanger options can be implemented:

  `macchanger --random`
   This is the default if no mask is configured.
   -> ""
   while is the same as:
   -> "00:00:00:00:00:00"
   -> "02:00:00:00:00:00 02:00:00:00:00:00"

  `macchanger --random --bia`
   -> "02:00:00:00:00:00 00:00:00:00:00:00"

  `macchanger --ending`
   This option cannot be fully implemented, because macchanger
   uses the current MAC address but also implies --bia.
   -> "FF:FF:FF:00:00:00"
      This would yields the same result only if the current MAC address
      is already a burned-in address too. Otherwise, it has not the same
      effect as --ending.
   -> "FF:FF:FF:00:00:00 <MAC_ADDR>"
      Alternatively, instead of using the current MAC address,
      spell the OUI part out. But again, that is not really the
      same as macchanger does because you explictly have to name
      the OUI part to use.

  `machanger --another`
  `machanger --another_any`
  -> "FF:FF:FF:00:00:00 <MAC_ADDR> <MAC_ADDR> ..."
     "$(printf "FF:FF:FF:00:00:00 %s\n" "$(sed -n 's/^\([0-9a-fA-F][0-9a-fA-F]\) \([0-9a-fA-F][0-9a-fA-F]\) \([0-9a-fA-F][0-9a-fA-F]\) .*/\1:\2:\3:00:00:00/p' /usr/share/macchanger/wireless.list | xargs)")"
2016-06-30 08:32:50 +02:00
Thomas Haller
8eed67122c device: extend MAC address handling including randomization for ethernet and wifi
Extend the "ethernet.cloned-mac-address" and "wifi.cloned-mac-address"
settings. Instead of specifying an explicit MAC address, the additional
special values "permanent", "preserve", "random", "random-bia", "stable" and
"stable-bia" are supported.

"permanent" means to use the permanent hardware address. Previously that
was the default if no explict cloned-mac-address was set. The default is
thus still "permanent", but it can be overwritten by global
configuration.

"preserve" means not to configure the MAC address when activating the
device. That was actually the default behavior before introducing MAC
address handling with commit 1b49f941a6.

"random" and "random-bia" use a randomized MAC address for each
connection. "stable" and "stable-bia" use a generated, stable
address based on some token. The "bia" suffix says to generate a
burned-in address. The stable method by default uses as token the
connection UUID, but the token can be explicitly choosen via
"stable:<TOKEN>" and "stable-bia:<TOKEN>".

On a D-Bus level, the "cloned-mac-address" is a bytestring and thus
cannot express the new forms. It is replaced by the new
"assigned-mac-address" field. For the GObject property, libnm's API,
nmcli, keyfile, etc. the old name "cloned-mac-address" is still used.
Deprecating the old field seems more complicated then just extending
the use of the existing "cloned-mac-address" field, although the name
doesn't match well with the extended meaning.

There is some overlap with the "wifi.mac-address-randomization" setting.

https://bugzilla.gnome.org/show_bug.cgi?id=705545
https://bugzilla.gnome.org/show_bug.cgi?id=708820
https://bugzilla.gnome.org/show_bug.cgi?id=758301
2016-06-30 08:29:56 +02:00
Thomas Haller
3f3ea1df21 libnm: add NMSettingConnection:stable-id property
This new property be used as token to generate stable-ids instead
of the connection's UUID.

Later, this will be used by ipv6.addr-gen-mode=stable-privacy,
ethernet.cloned-mac-address=stable, and wifi.cloned-mac-address=stable
setting. Those generate stable addresses based on the connection's
UUID, but allow to use the stable-id instead.

This allows multiple connections to generate the same addresses
-- on the same machine, because in the above cases a machine
dependant key is also hashed.
2016-06-30 08:29:54 +02:00
Lubomir Rintel
9dafcc8b26 cli/device: allow completion of the "wifi" command name
That's the "wifi" string itself. The subcommands need some work.
2016-06-29 20:49:34 +02:00
Lubomir Rintel
b8bc57c9d3 cli/device: add "lldp list" subcommand completion 2016-06-29 20:49:34 +02:00
Lubomir Rintel
08969b1789 cli: make subcommand dispatch do autocompletion 2016-06-29 20:49:34 +02:00
Lubomir Rintel
1e582f0172 cli: add boolean value completion helper 2016-06-29 20:49:34 +02:00
Lubomir Rintel
e2fe0eeb18 cli: add arbitrary string list completion helper 2016-06-29 20:49:34 +02:00
Lubomir Rintel
39f6d5a5ba cli/device: make "lldp list" subcommand use get_device() 2016-06-29 20:44:05 +02:00
Lubomir Rintel
95a13ef100 cli/device: make "set" subcommand use get_devices() 2016-06-29 20:39:09 +02:00
Lubomir Rintel
78c4038d8c cli/device: convert lldp subcommand to nmc_do_cmd() 2016-06-29 20:32:31 +02:00
Lubomir Rintel
05108ca975 cli/device: convert wifi subcommand to nmc_do_cmd() 2016-06-29 20:32:31 +02:00
Lubomir Rintel
8b4494598d cli/device: add modify command
It modifies the applied connection using the Reapply API.
2016-06-29 20:28:42 +02:00
Lubomir Rintel
a0bb8cd6cb cli/connection: export read_connection_properties()
It makes sense to modify the applied connection from the device object.
2016-06-29 20:28:42 +02:00
Lubomir Rintel
c054b871f7 cli/device: add device name completion
Useful with connect, disconnect, delete, monitor, show and reapply.
2016-06-29 20:28:42 +02:00
Lubomir Rintel
59bc820e66 cli/device: split get_device()
Parsing a single device name from the command line is generally
useful. Remove the open coded versions in reapply, connect & status.
2016-06-29 20:28:42 +02:00
Lubomir Rintel
55d349bc34 cli/trivial: rename device_list() to get_device_list()
It will look nicer when we have get_device().
2016-06-29 20:28:42 +02:00
Lubomir Rintel
5182ab3d5d cli/device: use nmc_do_cmd() 2016-06-29 20:28:42 +02:00
Lubomir Rintel
1a88eac02a cli: split out do_cmd() 2016-06-29 20:28:42 +02:00
Lubomir Rintel
a30224f6af cli: use should_wait consistently
It's a semaphore, not a boolean.
2016-06-29 20:28:42 +02:00
Lubomir Rintel
ef8d696252 cli: move the final completion check after the main loop exit
For "nmcli d modify" we'll need to do the completion from async
handlers. This seems to be the most reasonable place to ignore the
errors.
2016-06-29 20:28:42 +02:00
Lubomir Rintel
56804f4a3f cli/trivial: rename some functions for consistency
Some functions that take device lists use plural form in name.
2016-06-29 20:28:42 +02:00
Lubomir Rintel
86ffc08775 cli/connections: only do completion for the last argument
Completing the property when we stop parsing due to error is not the
right thing to do.
2016-06-29 20:28:42 +02:00
Francesco Giudici
fdecb6b669 cli: option autocompletion should not match words without trailing '-'
This would fix for example:
nmcli e <TAB>
(e interpreted as --escape, would allow autocompletion to work... but
when the command is executed an error is reported)

Moreover, we will now have:
nmcli c <TAB>
autocompletion work correctly, i.e., c is correctly interpreted  as
"connection" instead of "--colors"
2016-06-28 12:12:39 +02:00
Beniamino Galvani
bf7b9c60b6 cli: initialize connection list in do_device_connect()
The connection list may be required in nmc_secrets_requested() if
secrets are needed.

Fixes: 45fc268890

https://bugzilla.gnome.org/show_bug.cgi?id=767987
2016-06-27 13:09:20 +02:00
Francesco Giudici
18cd265b2d nmcli: when adding a vpn store the full service name in vpn-type
When NM looks for vpn plugins, it would expect the full service name
otherwise it will not be able to retrieve the correct plugin.
Fixes VPN configurations generated with "nmcli connection add".
2016-06-27 12:13:46 +02:00
Beniamino Galvani
4c7f609d51 cli: autocompletion: add missing log level and domains
Add KEEP level and DHCP, IP, AUDIT, SYSTEMD, VPN_PLUGIN domains.
2016-06-27 11:40:39 +02:00
Francesco Giudici
aed19ff12a nmcli: fix ambiguous properties check for autocompletion
Re-enable the check on ambiguos properties but this time manage perfect
matches (i.e., the full property name has been typed) that are prefix
of other properties.

Test case:
nmcli --complete-args connection add type wifi wifi.

Here "wifi" is a property alias that is also prefix of the property
alias "wifi-sec".
2016-06-23 17:37:37 +02:00
Francesco Giudici
ea9dcd08fa nmcli: manage autocompletion of "nmcli connection add" when no args are passed
This enables back "help" "--help" "-help" in autocompletion.
2016-06-23 17:35:08 +02:00