Commit Graph

966 Commits

Author SHA1 Message Date
Lubomir Rintel
25fadf8f92 cli: add kill switch indication to "nmcli" output
There is some guess work done on the client side. Perhaps the
o.fd.NM.Device could be extended to indicate which kill switch is the
device disabled by. This could be good enough for now though.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/271/commits
2019-09-20 12:49:21 +02:00
Beniamino Galvani
5afcf9c045 cli: add 'general reload' command
Add 'nmcli general reload [flags]' command to reload NM configuration
and perform other updates.
2019-09-17 09:31:34 +02:00
Beniamino Galvani
fd8d5a0c7a cli: don't create a NMClient for the 'connection reload' command
It is a waste of resources instantiating a NMClient, filling the
object cache and then throwing everything away without using it. This
can take seconds on slow systems with many objects. Since the
ReloadConnections doesn't need anything from the cache, just execute
the D-Bus method call directly.
2019-09-17 09:31:34 +02:00
Lubomir Rintel
24028a2246 all: SPDX header conversion
$ find * -type f |xargs perl contrib/scripts/spdx.pl
  $ git rm contrib/scripts/spdx.pl
2019-09-10 11:19:56 +02:00
Lubomir Rintel
b76da15dbf clients: avoid clearing a structure pointer when we're still using it
We're dereferencing the info pointer in the argument list in the call to
nm_client_activate_connection_async(). Stealing it at that point causes
a crash.

This reverts a chunk of commit b298f2e605 ('cli: use cleanup macro for
freeing AddAndActivateInfo').
2019-09-02 14:58:43 +02:00
Beniamino Galvani
73b3806228 wifi: expose IBSS_RSN capability
The new capability indicates whether the device supports WPA2/RSN in
an IBSS (ad-hoc) network.

https://bugzilla.gnome.org/show_bug.cgi?id=757823
2019-08-26 10:25:00 +02:00
Maciek Borzecki
378099c60e cli: include BSSID to NMC_FIELDS_DEV_WIFI_LIST_COMMON
When using WiFi in an environment with multiple APs of the same SSID (eg.
conference venue, hotels), it is often useful to be able to identify particular
APs by their BSSID.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/235
2019-08-22 11:36:06 +02:00
Francesco Giudici
40647bd887 cli: prefer nm_assert() to g_assert*() 2019-08-22 11:35:53 +02:00
Francesco Giudici
1a91ef2dc6 cli: fix bad indentation 2019-08-22 11:35:38 +02:00
Thomas Haller
0e1748afe1 cli: cleanup unique_master_iface_ifname()
- use appropriate types for integer variables

- rework the confusing loop which would reset the loop-counter
  to start again.
2019-08-20 15:31:08 +02:00
Thomas Haller
e1ec22f74b cli: cleanup setting default interface-name 2019-08-20 15:24:15 +02:00
Thomas Haller
b789ce01e9 cli: fix handling modifier in nmc_read_connection_properties() for aliases
Various cleanups:

  - after detecting the modifier, remove it from the string right away.
    It's redundant and confusing to do it later.

  - rename variables and move to inner scope.

  - don't use g_str_split() to split the property name at the
    first dot. strchr() is sufficient.

Also, now that we strip the modifier from option early, they start also
working for aliases. There is no need to not support (or behave
differently) w.r.t. whether aliases support modifiers or not.

This fixes:

  $ nmcli connection modify r +ip4 192.168.5.2/24
  Error: invalid <setting>.<property> 'ip4'.
2019-08-16 08:16:02 +02:00
Thomas Haller
0825ec34fd cli: add NMMetaAccessorModifier enum instead of using "char" type
The enum values are unique throughout the source code so they
can easier be searched (e.g. with grep), compared to '\0'. It
is often interesting where a certain modifier is used, so searching
the source code is important to give relevant results.

Also, the modifier is really an enum and we shouldn't misuse char type.
If that would be a good idea in general, we wouldn't need any enums
at all. But we use them for good reasons.
2019-08-16 08:16:02 +02:00
Thomas Haller
de40eb0403 cli: reorder checks in nmc_setting_set_property() for modifier type
No notable change in behavior, but makes more sense this way.
2019-08-16 08:16:02 +02:00
Thomas Haller
b298f2e605 cli: use cleanup macro for freeing AddAndActivateInfo
We should prefer the cleanup macors nm_auto*() because they express
ownership in code.

Also, they allow to return early without additional cleanup code.
That way we can refactor if-else blocks.

Also, in cases where we intentionally pass on the reference, we use
g_steal_pointer(), which literally spells out what happens in code.
2019-08-05 10:11:01 +02:00
Thomas Haller
cf6cd06422 cli: add helper function to create and initialize AddAndActivateInfo struct
Also use gslice allocator instead of malloc as the size of
AddAndActivateInfo is fixed and known beforehand.
2019-08-05 10:11:01 +02:00
Lubomir Rintel
a4740fb82a cli: update the existing connection on "dev wifi connect"
If we find a matching connection, ensure it's exactly as we want it
before actually proceeding to activate it. Fixes this problem:

  # nmcli dev wifi connect "Network of Doom" password santa <-- bad
  Error: Connection activation failed: (7) Invalid secrets
  # nmcli dev wifi connect "Network of Doom" password satan <-- correct
  Error: Connection activation failed: (7) Invalid secrets

The password is now correct, but nmcli chose to re-activate the wrong
connection it created previously.
2019-08-02 23:00:26 +02:00
Lubomir Rintel
bc614783f0 cli: take a reference to device in AddAndActivateInfo
The device could vanish in between.
2019-08-02 23:00:26 +02:00
Lubomir Rintel
69ed759ddf cli: remove an unnecessary condition
Do not check for password when creating a simple connection object for
"nmcli dev wifi connect".

This makes no difference in practice. The password is checked for
existence later on and the connection instance is created anyway. This
just makes things look a bit more consistent.
2019-08-02 23:00:26 +02:00
Lubomir Rintel
cc3681c96c cli: (trivial) rename do_device_wifi_connect_network() to do_device_wifi_connect()
This is consistent with the surrounding code and avoids lines
unnecessarily too wide.
2019-08-02 23:00:26 +02:00
Thomas Haller
ec982ceb8e cli: fix dereferncing NULL pointer in parse_passwords() with empty file
Warned by coverity.
2019-08-02 08:33:36 +02:00
Thomas Haller
bee0b20e3f cli: use gs_free_error in nmcli's "connections.c" 2019-08-02 08:30:56 +02:00
Lubomir Rintel
577769b983 cli: abort on extra arguments
Instead of straight-out rejecting extra parameters for various nmcli
sub-commands (such as "nmcli dev status", "nmcli dev wifi rescan" or
"nmcli dev wifi connect", etc.), we just print a warning and go ahead.

This is unhelpful. In case the user makes a typo, we'll do the wrong
thing and possibly even drown the warning in the output.

While at that, let's make the error message consistent. One less string
to translate.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/217
2019-07-30 18:40:31 +02:00
Lubomir Rintel
ce08b44471 cli: drop NMC_RETURN
It's criminally ugly. Also -- totally useless.

These functions return NMCResultCode, call_cmd() expects them to do
so, and assigns the return_value itself.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/218
2019-07-30 18:38:59 +02:00
Lubomir Rintel
dd80d3c6be clients: Wi-Fi Mesh support
Allow setting mesh mode in wireless connections and recognize the Mesh
support as indicated by the device flags.
2019-07-29 11:00:24 +02:00
Thomas Haller
64c178712a cli: use nm_client_add_connection2() API from nmcli
Make use of the new API. Note that AddConnection2() covers all
functionality of AddConnection() and AddConnectionUnsaved(). Let's
only use one API for all.

There is a minor downside to this patch: now nmcli requires
libnm 1.20 API. Note that libnm's nm_client_add_connection2()
makes an effort to avoid AddConnection2() under the hood to
still work against older server versions. So, you can use nmcli
with libnm 1.20 to talk to older versions of NetworkManager.

But with this change nmcli strictly requires libnm 1.20. I think that is
sensible because commonly nmcli requires a libnm version that is as new
as itself.
Also, the value of allowing nmcli to talk to older NetworkManager
versions is during package upgrade (where the daemon might not be
restarted). This is much less concern w.r.t. to updating the nmcli/libnm
combo, which is commonly packaged together.
2019-07-25 15:26:49 +02:00
Lubomir Rintel
bd119981a1 clients: add ovs-dpdk interface support 2019-06-14 12:10:20 +02:00
Beniamino Galvani
6a3bb90ad4 cli: fix crash on autocompletion
@connections is NULL when doing autocompletion. Fixes the following:

 $ nmcli --complete-args con monitor ""
  help
  id
  uuid
  path
  filename
  ...
  Segmentation fault (core dumped)

Fixes: 4b3297271e ('cli: rework connection handling for multiple results')

https://bugzilla.redhat.com/show_bug.cgi?id=1716948
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/177
2019-06-11 16:44:06 +02:00
Francesco Giudici
58eee5896d cli: enforce int type in for loops 2019-05-29 11:37:42 +02:00
Lubomir Rintel
9c24c81ad0 cli: don't force interface name on add_and_activate
The daemon is already responsible for pinning the connection to a
particular device. In fact, it may choose to use a different means than
an interface name, such as a MAC address or a gsm.device-id. Remove it
from the client.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/140
2019-05-28 14:40:18 +02:00
Beniamino Galvani
eb724293c2 cli: allow completing filenames
Allow the completion function to indicate that the word should be
completed as a filename by the shell.
2019-05-06 10:10:00 +02:00
Beniamino Galvani
78b9448b69 cli: remove bluetooth completion code
The 'bt-type' property alias accepts values provided by
gen_func_bt_type(); instead the 'bluetooth.type' property can only be
set to [dun, panu, nap] and therefore it doesn't need special
handling.
2019-05-06 10:10:00 +02:00
Thomas Haller
020c4c81d8 cli: drop GValue transform functions for strdict and implement it in _get_fcn_gobject_impl()
The only remaining GValue transform function was from GHashTable (of (str,str) type)
to string. Drop that too, and implement the conversion in _get_fcn_gobject_impl().

Note that there are few GObject properties of type GHashTable and most
of them implement their own logic. This only applies to
"802-3-ethernet.s390-options".

Also, always sort the keys. Otherwise, the output is not stable.
2019-04-25 08:20:03 +02:00
Thomas Haller
e55a45faa2 cli: drop GValue transformation of GBytes to string and implement bytes getter via _get_fcn_gobject_impl()
The g_value_register_transform_func() for handling GBytes was not actually used.
All properties of type G_TYPE_BYTES have their explit handler how to convert bytes
to string. That is good, because the implementation there was very bad (it did not
honor pretty/parsable get-type).

Also, merge _get_fcn_gobject_bytes() into _get_fcn_gobject_impl(). We
already have a generic handler that handles properties solely based on
the GObject type: _get_fcn_gobject_impl(). Just let it also handle
bytes. It's better to have fewer handlers, if they don't need special
context.
2019-04-25 08:20:03 +02:00
Thomas Haller
d4d1e5f00d cli: drop GValue transform function for G_TYPE_STRV to G_TYPE_STRING
It's ugly to modify the global behavior of glib to convert between
types. Instead, _get_fcn_gobject_impl() is perfectly capable to implement
converting a strv array to string.
2019-04-25 08:20:03 +02:00
Beniamino Galvani
2d347e7e17 cli: don't wait for connection change on update failure
When saving a connection, we wait the connection-changed signal before
proceeding to ensure that the remote connection is up to date.
However, no signal is emitted if the update fails and so we shouldn't
wait for it.

Fixes: a370faeb59 ('cli: wait for changed signal after updating a connection'):

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/124
https://bugzilla.redhat.com/show_bug.cgi?id=1702203
2019-04-24 16:18:25 +02:00
Thomas Haller
c27ad37c27 build/meson: rename "nm_core_dep" to "libnm_core_dep"
The library is called "libnm_core". So the dependency should be called
"libnm_core_dep", like in all other cases.
2019-04-18 18:59:09 +02:00
Thomas Haller
af07ed01c0 shared: build helper "libnm-libnm-core-{intern|aux}.la" library for libnm-core
"libnm-core" implements common functionality for "NetworkManager" and
"libnm".

Note that clients like "nmcli" cannot access the internal API provided
by "libnm-core". So, if nmcli wants to do something that is also done by
"libnm-core", , "libnm", or "NetworkManager", the code would have to be
duplicated.

Instead, such code can be in "libnm-libnm-core-{intern|aux}.la".
Note that:

  0) "libnm-libnm-core-intern.la" is used by libnm-core itsself.
     On the other hand, "libnm-libnm-core-aux.la" is not used by
     libnm-core, but provides utilities on top of it.

  1) they both extend "libnm-core" with utlities that are not public
     API of libnm itself. Maybe part of the code should one day become
     public API of libnm. On the other hand, this is code for which
     we may not want to commit to a stable interface or which we
     don't want to provide as part of the API.

  2) "libnm-libnm-core-intern.la" is statically linked by "libnm-core"
     and thus directly available to "libnm" and "NetworkManager".
     On the other hand, "libnm-libnm-core-aux.la" may be used by "libnm"
     and "NetworkManager".
     Both libraries may be statically linked by libnm clients (like
     nmcli).

  3) it must only use glib, libnm-glib-aux.la, and the public API
     of libnm-core.
     This is important: it must not use "libnm-core/nm-core-internal.h"
     nor "libnm-core/nm-utils-private.h" so the static library is usable
     by nmcli which couldn't access these.

Note that "shared/nm-meta-setting.c" is an entirely different case,
because it behaves differently depending on whether linking against
"libnm-core" or the client programs. As such, this file must be compiled
twice.
2019-04-18 18:59:09 +02:00
Thomas Haller
f4afb38bd9 cli: fix crash in split_required_fields_for_con_show()
Depending on the architecture (calling convention), function
arguments are evaluated in one order or the other.

https://bugzilla.redhat.com/show_bug.cgi?id=1700409

Fixes: 34e60bf228 ('cli: cleanup split_required_fields_for_con_show()')
2019-04-16 16:00:32 +02:00
Thomas Haller
43d93e7c1f cli: tab complete only full D-Bus paths if there is no prefix
When tab completing connections by path name without any already
typed parts, only suggest full D-Bus paths. The numbers are duplicate
and not preferred.

Before:

    $ nmcli connection show path <TAB>
    Display all 118 possibilities? (y or n)
    1                                            46                                           /org/freedesktop/NetworkManager/Settings/29
    10                                           47                                           /org/freedesktop/NetworkManager/Settings/3
    11                                           48                                           /org/freedesktop/NetworkManager/Settings/30
    12                                           49                                           /org/freedesktop/NetworkManager/Settings/31
    13                                           5                                            /org/freedesktop/NetworkManager/Settings/32

Afterwards:

    $ nmcli connection show path <TAB>
    /org/freedesktop/NetworkManager/Settings/1   /org/freedesktop/NetworkManager/Settings/28  /org/freedesktop/NetworkManager/Settings/46
    ...

and

    $ nmcli connection modify path 4<TAB>
    4   40  41  42  43  44  45  46  47  48  49
2019-04-15 20:50:50 +02:00
Thomas Haller
68bd018a88 cli: prefer matching connections by "uuid" instead of "id"
Scripts should refer to connections by UUID. That means, whenever a
UUID matches, that is really what the user wants. The specifier "uuid"
must have precedence over "id" (and all others). That means, we must
search all connections.

For example:

    $ UUIDS=($(nmcli -g TYPE,UUID connection show | sed -n 's/802-11-wireless://p'))
    $ nmcli -f connection.id,connection.uuid connection show "${UUIDS[@]}"

in this case we must preferrably match by UUID, regardless of whether
a "connection.id" exists.

Note that if you have:

    $ nmcli connection show | grep fdf7b2d2-2858-3938-9b14-7f1b514a9a00
    b                                     fdf7b2d2-2858-3938-9b14-7f1b514a9a00  ethernet   --
    fdf7b2d2-2858-3938-9b14-7f1b514a9a00  ab9f3891-3420-335e-89da-f14c1b94c540  ethernet   --

then certain commands will still select all matching connections:

    $ nmcli -f connection.id,connection.uuid --mode multiline connection show fdf7b2d2-2858-3938-9b14-7f1b514a9a00
    connection.id:                          fdf7b2d2-2858-3938-9b14-7f1b514a9a00
    connection.uuid:                        ab9f3891-3420-335e-89da-f14c1b94c540

    connection.id:                          b
    connection.uuid:                        fdf7b2d2-2858-3938-9b14-7f1b514a9a00

This only makes a difference for commands that must pick only one profile:

    $ nmcli connection modify fdf7b2d2-2858-3938-9b14-7f1b514a9a00 con-name new-name
2019-04-15 20:50:50 +02:00
Thomas Haller
87d16e935c cli: drop unnecessary NULL sentinel from nmc_complete_strings()
Since commit 62b939de4e ('cli: add nmc_complete_strv() which takes a
string array for completion that may contain NULL'), the sentinel is
no longer needed.
2019-04-15 20:50:50 +02:00
Thomas Haller
7b6a3aaf29 cli: fix typo in nmcli usage output
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/157
2019-04-12 09:56:51 +02:00
Thomas Haller
34e60bf228 cli: cleanup split_required_fields_for_con_show()
- return early and use cleanup attribute for freeing memory
- use nm_utils_strsplit_set_with_empty() instead of g_strsplit_set().
2019-04-10 15:05:57 +02:00
Thomas Haller
84f2037648 shared: add flags argument to nm_utils_strsplit_set()
It will be useful to extend nm_utils_strsplit_set() with various
flavors and subtly different behaviors. Add a flags argument to
support these.
2019-04-10 15:05:57 +02:00
Thomas Haller
a77c5d18c4 cli: fix missing newline for printing error message about "Connection deletion failed"
$ nmcli connection delete Wired\ connection\ 1
  Error: Connection deletion failed: Insufficient privilegesError: not all connections deleted.
2019-04-05 20:25:28 +02:00
Beniamino Galvani
5b5a768b69 clients: only ask secrets for settings that require them
When nmcli needs secrets for a connection it asks them for every known
setting. nmtui is a bit smarter and asks them only for settings that
actually exist in the connection. Make a step further and let clients
ask secrets only for setting that exist *and* have any secret
property. This decreases the number of D-Bus calls when editing or
showing a connection with secrets.

https://bugzilla.redhat.com/show_bug.cgi?id=1506536
https://github.com/NetworkManager/NetworkManager/pull/327
2019-04-02 11:20:28 +02:00
Lubomir Rintel
9c9c8c68ff cli: fix a crash on "nmcli d wifi hotspot"
Call the correct _finish() function for
nm_client_add_and_activate_connection_async(). add_and_activate_cb()
somewhat confusingly alternates between two different ones depending on
whether info->create is set.

Fixes: 3593237527 ('cli: reuse connections in nmcli dev wifi con')
https://github.com/NetworkManager/NetworkManager/pull/326
2019-04-02 09:09:54 +02:00
Thomas Haller
598ecbc482 cli: fix accepting %NULL value for '+' modifier
I find it questionable, how nmcli likes to coerce the empty input to
NULL to indicate resetting the value. If nmcli would like to set a
default, it should use a different way of signalling that. Anyway, the
assertion was too strict.

    $ nmcli connection modify "$PROFILE" +ipv4.addresses ''
2019-03-27 16:12:15 +01:00
Thomas Haller
7dcf368cf0 cli: freeze/thaw property changed signals in nmc_setting_set_property()
Setting one property might affect multiple properties.
For example, setting a team property might also emit property changed
signal for "team.config".

Or, one property might be modified multiple times. For example list
properties may first clear the property, then append multiple elements.
Or a list property might remove multiple elements.

Combine these signals via g_object_freeze_notify() and
g_object_thaw_notify().
2019-03-25 09:12:33 +01:00