Commit Graph

283 Commits

Author SHA1 Message Date
Lubomir Rintel
9f5711bec4 cli: split off the update or add-and-activate logic 2019-10-30 14:08:57 +01:00
Lubomir Rintel
7061341a41 cli: add "nmcli d wifi show"
A quick overview of the currently connected Wi-Fi network, including
credentials. Comes handy if someone wants to connect more devices to
their Hotspot or the same network as they are connected to.
2019-10-18 17:38:57 +02:00
Lubomir Rintel
976eebae73 cli/devices: keep the AddAndActivateInfo alive until the activation ends
In a future commit it will be useful to know whether the activation
details when the activation succeeds.

This also makes the state tracking of the ongoing activation more
elegant, since we got our device and AC neatly packed together and we
can treat their respective state changes consistently.
2019-10-18 17:38:57 +02:00
Lubomir Rintel
8766d05ea9 cli/devices: on connecting a device, don't uselessly look it up from the ac
For quite some time we already pass the AddAndActivateInfo for device
connect too, and that one remembers the device.
2019-10-18 17:38:57 +02:00
Thomas Haller
3b69f02164 all: unify format of our Copyright source code comments
```bash

readarray -d '' FILES < <(
  git ls-files -z \
    ':(exclude)po' \
    ':(exclude)shared/c-rbtree' \
    ':(exclude)shared/c-list' \
    ':(exclude)shared/c-siphash' \
    ':(exclude)shared/c-stdaux' \
    ':(exclude)shared/n-acd' \
    ':(exclude)shared/n-dhcp4' \
    ':(exclude)src/systemd/src' \
    ':(exclude)shared/systemd/src' \
    ':(exclude)m4' \
    ':(exclude)COPYING*'
  )

sed \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \
  -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \
  -i \
  "${FILES[@]}"

echo ">>> untouched Copyright lines"
git grep Copyright "${FILES[@]}"

echo ">>> Copyright lines with unusual extra"
git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved

sed \
  -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \
  -i \
  "${FILES[@]}"

```

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
2019-10-02 17:03:52 +02:00
Thomas Haller
abff46cacf all: manually drop code comments with file description 2019-10-01 07:50:52 +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
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
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
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
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
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
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
a3370af3a8 all: drop unnecessary includes of <errno.h> and <string.h>
"nm-macros-interal.h" already includes <errno.h> and <string.h>.
No need to include it everywhere else too.
2019-02-12 08:50:28 +01:00
Lubomir Rintel
fab1116494 clients/cli: if the AP supports SAE, claim WPA3 support
RSN with SAE is what's called WPA3-Personal.
Also, if there's neither PSK nor 802.1x, it's not WPA2.
2019-02-05 10:20:30 +01:00
Lubomir Rintel
245c9c93d1 clients/cli: don't translate abbreviations 2019-02-05 10:20:27 +01:00
Lubomir Rintel
2344e958cf client/cli: send a PSK when using SAE 2019-02-05 10:20:27 +01:00
Lubomir Rintel
998ebe731e client/cli: add support for SAE key management flag 2019-02-05 10:20:27 +01:00
Lubomir Rintel
ab0d348792 client/devices: get rid of useless g_strdup()s
And, while at that, add a hint to the developer adding new items. It's
helps avoid a mistake that I believe is common (because I just made it
twice...).
2019-02-05 10:20:27 +01:00
Thomas Haller
93c848ca03 clients: don't tread secret agent as NMSecretAgentOld
Most of the times we actually need a NMSecretAgentSimple typed pointer.
This way, need need to cast less.

But even if we would need to cast more, it's better to have pointers
point to the actual type, not merely to avoid shortcomings of C.
2019-02-05 08:27:42 +01:00
Lubomir Rintel
96782b94e1 merge: branch 'master' of https://github.com/balrog-kun/NetworkManager
https://github.com/NetworkManager/NetworkManager/pull/137
2019-01-04 18:26:41 +01:00
Lubomir Rintel
f13da72b3c cli/devices: remove redundant Device/AC state evaluation
The state handling in add_and_activate_cb() and connect_device_cb() is
redundant to connected_state_cb() and in fact executed only if the
activation is really really really quick (which it never is).

Also, the return_text those implementations provide is different from
what connected_state_cb(), potentially confusing the users and adding
extra work for translators.

Not to mention extra lines of code, reading whose wastes our precious
time on the planet we could spend doing heroin instead.
2018-12-04 14:46:37 +01:00
Andrew Zaborowski
3593237527 cli: reuse connections in nmcli dev wifi con
Try to locate an existing connection before creating a new one when
handling "nmcli device wifi connect".  This allows WPA-Enterprise
networks to be activated this way, consistent with the comment that this
command is equivalent to clicking on an SSID in a GUI client.
2018-12-04 14:46:37 +01:00
Andrew Zaborowski
0c70a9ef6d cli: match both ssid and bssid when connecting to wifi
Instead of matching candidate APs by either SSID or BSSID (bssid1_arr)
make sure both match if a bssid2_arr was given.
2018-12-04 14:46:23 +01:00
Beniamino Galvani
cf1126f60b cli: avoid crash on device disconnect
When nm_device_disconnect_async() returns, the device could be still
in DEACTIVATING state, and so we also register to device-state signal
notifications to know when the device state goes to DISCONNECTED.

Sometimes it happens that the device state goes to DISCONNECTED before
nm_device_disconnect_async() returns. In this case the signal handler
exits the main loop and then the callback for disconnect_async() is
executed anyway because it was already dispatched, leading to an
invalid memory access.

To avoid this we should cancel nm_device_disconnect_async() when we
are quitting the main loop.

Reproducer:
  nmcli connection add type team ifname t1 con-name t1
  nmcli connection up t1
  nmcli device disconnect t1 & nmcli device delete t1

Crash example:
 ==14955==ERROR: AddressSanitizer: SEGV on unknown address 0xffffffff0000000b (pc 0x7f128c8ba3dd bp 0x0000004be080 sp 0x7ffcda7dc6e0 T0)
 ==14955==The signal is caused by a READ memory access.
    0 0x7f128c8ba3dc in g_string_truncate (/lib64/libglib-2.0.so.0+0x713dc)
    1 0x7f128c8bb4bb in g_string_printf (/lib64/libglib-2.0.so.0+0x724bb)
    2 0x45bdfa in disconnect_device_cb clients/cli/devices.c:2321
    3 0x7f128ca3d1a9 in g_simple_async_result_complete /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gsimpleasyncresult.c:802
    4 0x7f128cf85d0e in device_disconnect_cb libnm/nm-device.c:2354
    5 0x7f128ca4ff73 in g_task_return_now /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1148
    6 0x7f128ca508d5 in g_task_return /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1206
    7 0x7f128ca8ecfc in reply_cb /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gdbusproxy.c:2586
    8 0x7f128ca4ff73 in g_task_return_now /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1148
    9 0x7f128ca508d5 in g_task_return /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1206
    10 0x7f128ca83440 in g_dbus_connection_call_done /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gdbusconnection.c:5713
    11 0x7f128ca4ff73 in g_task_return_now /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1148
    12 0x7f128ca4ffac in complete_in_idle_cb /usr/src/debug/glib2-2.58.1-1.fc29.x86_64/gio/gtask.c:1162
    13 0x7f128c893b7a in g_idle_dispatch gmain.c:5620
    14 0x7f128c89726c in g_main_dispatch gmain.c:3182
    15 0x7f128c897637 in g_main_context_iterate gmain.c:3920
    16 0x7f128c897961 in g_main_loop_run (/lib64/libglib-2.0.so.0+0x4e961)
    17 0x473afb in main clients/cli/nmcli.c:1067
    18 0x7f128c6a1412 in __libc_start_main (/lib64/libc.so.6+0x24412)
    19 0x416c39 in _start (/usr/bin/nmcli+0x416c39)

https://github.com/NetworkManager/NetworkManager/pull/254
https://bugzilla.redhat.com/show_bug.cgi?id=1546061
2018-11-30 14:15:27 +01:00
Lubomir Rintel
64e51241e6 cli: fix a couple of typos 2018-11-29 17:53:35 +01:00
Lubomir Rintel
b385ad0159 all: say Wi-Fi instead of "wifi" or "WiFi"
Correct the spelling across the *entire* tree, including translations,
comments, etc. It's easier that way.

Even the places where it's not exposed to the user, such as tests, so
that we learn how is it spelled correctly.
2018-11-29 17:53:35 +01:00
Lubomir Rintel
13d2d332dd cli: deduplicate active connections sort
Both connections and devices need to sort active connections. Make the
more sensible policy default.
2018-11-21 11:46:22 +01:00
Lubomir Rintel
2a7e60d724 cli/devices: sort hotspots above in nmcli output
In general we want to keep the connections that the user is most likely
to want to see topmost. Default connections should be close to the top,
but the connections that are likely to have been brought up manually
shall be above them. It applies to VPN connections and should apply to
Hotspots too.
2018-11-21 11:46:21 +01:00
Beniamino Galvani
c7edb34eb9 cli: add --rescan option to help output 2018-11-05 09:32:20 +01:00
Beniamino Galvani
a985efaf93 cli: fix memory leaks 2018-11-02 14:56:40 +01:00
Beniamino Galvani
c0138cdb35 cli: wait for all wifi scans to finish before displaying the result
Otherwise devices are displayed in a inconsistent order.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/39
2018-11-02 14:56:40 +01:00
Beniamino Galvani
6130a4561e cli: fix crash when removing devices
When a software device is removed by nmcli in parallel with a
disconnection, e.g.:

     nmcli connection add type team ifname t1 con-name t1
     sleep 1
     nmcli connection down t1 & nmcli device delete t1

nmcli sometimes crashes in the following way:

 ...
 Connection 't1' (e4701688-d1a9-4942-85f0-a2081e120023) successfully added.
 Connection 't1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/36)
 Device 't1' successfully removed.
 AddressSanitizer:DEADLYSIGNAL
 =================================================================
 ==15217==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000000b (pc 0x7fa6d92d1c9d bp 0x0000004ba260 sp 0x7ffffe6a6f40 T0)
 ==15217==The signal is caused by a READ memory access.
 ==15217==Hint: address points to the zero page.
     0 0x7fa6d92d1c9c in g_string_truncate (/lib64/libglib-2.0.so.0+0x6ec9c)
     1 0x7fa6d92d2d7b in g_string_printf (/lib64/libglib-2.0.so.0+0x6fd7b)
     2 0x45a6d7 in delete_device_cb clients/cli/devices.c:2465
     3 0x7fa6d9849289 in g_simple_async_result_complete /usr/src/debug/glib2-2.56.1-1.fc28.x86_64/gio/gsimpleasyncresult.c:802
     4 0x7fa6dbaa9836 in device_delete_cb libnm/nm-device.c:2458
     5 0x7fa6d985bcf3 in g_task_return_now /usr/src/debug/glib2-2.56.1-1.fc28.x86_64/gio/gtask.c:1148
     6 0x7fa6d985c7a5 in g_task_return /usr/src/debug/glib2-2.56.1-1.fc28.x86_64/gio/gtask.c:1206
     7 0x7fa6d989ca6c in reply_cb /usr/src/debug/glib2-2.56.1-1.fc28.x86_64/gio/gdbusproxy.c:2586
     8 0x7fa6d985bcf3 in g_task_return_now /usr/src/debug/glib2-2.56.1-1.fc28.x86_64/gio/gtask.c:1148
     9 0x7fa6d985c7a5 in g_task_return /usr/src/debug/glib2-2.56.1-1.fc28.x86_64/gio/gtask.c:1206
     10 0x7fa6d98913c0 in g_dbus_connection_call_done /usr/src/debug/glib2-2.56.1-1.fc28.x86_64/gio/gdbusconnection.c:5722
     11 0x7fa6d985bcf3 in g_task_return_now /usr/src/debug/glib2-2.56.1-1.fc28.x86_64/gio/gtask.c:1148
     12 0x7fa6d985bd2c in complete_in_idle_cb /usr/src/debug/glib2-2.56.1-1.fc28.x86_64/gio/gtask.c:1162
     13 0x7fa6d92ac0ea in g_idle_dispatch gmain.c:5535
     14 0x7fa6d92af7cc in g_main_dispatch gmain.c:3177
     15 0x7fa6d92afb97 in g_main_context_iterate gmain.c:3903
     16 0x7fa6d92afec1 in g_main_loop_run (/lib64/libglib-2.0.so.0+0x4cec1)
     17 0x472892 in main clients/cli/nmcli.c:1067
     18 0x7fa6d8cc31ba in __libc_start_main (/lib64/libc.so.6+0x231ba)
     19 0x4162b9 in _start (/usr/bin/nmcli+0x4162b9)

The reason is that after calling nm_device_delete_async() we also
listen for the manager device-removed signal. When the signal is
received, device_removed_cb() destroy the @info structure and calls
g_main_loop_quit (loop). However, if the delete_device_cb() callback
has already been dispatched it is executed anyway and it tries to
access a stale @info.

It makes little sense to listen for the device-removed signal since
the return value of nm_device_delete_async() already tells us whether
the device was removed successfully or not.

The only advantage would be that when the device goes away for other
reasons we can still return success, but that is racy and should not
be relied upon.

https://bugzilla.redhat.com/show_bug.cgi?id=1639208
2018-10-22 08:43:44 +02:00
Thomas Haller
86502bef9c cli: don't needlessly cast function pointer for rl_attempted_completion_function 2018-10-10 09:55:45 +02:00
Thomas Haller
411243c654 cli: don't use global nm_cli in nmc_readline_*()
Globals are bad. Don't let nmc_readline_helper() access
nm_cli.

Instead, pass nmc_config along. nmc_config albeit being
a complex struct, is much more begning:

  - the configuration nmc_config is initialized early on
    and afterwards immutable.
  - it only contains simple fields, which affect the behavior.
  - it's not a global. While passing around the complex configuration
    struct, it is clear that all callpaths don't access additional
    global information.
2018-10-10 09:55:45 +02:00
Lubomir Rintel
de7a159e69 cli: print per-device & per-AF connectivity status 2018-09-24 15:38:08 +02:00
Beniamino Galvani
c955d91d4b cli: remove assertion in nmc_device_state_to_color()
nmcli should not fail when the state device state is > ACTIVATED.
Just return an unknown color code like we used to do, and like we do
for connections.

Fixes: 31aa2cfe29

https://bugzilla.gnome.org/show_bug.cgi?id=796834
2018-08-10 10:10:51 +02:00
Thomas Haller
ac07cbb98b cli: minor cleanup explicitly checking print_output
The print-output knows three modes: NORMAL, PRETTY, TERSE.
Never compare whether a mode is != a particular mode.

Instead, always explicitly check for the modes for which we enable a
particular behavior.

The effect is, that we always do something when the mode is set to a
particular value. We don't ever do something, if the mode is not set to
a particular value. Consistently opt-in is easier to understand.
2018-07-25 17:08:37 +02:00
Thomas Haller
e0570ae8d6 cli: don't translate device state in --terse mode 2018-07-25 17:08:37 +02:00
Thomas Haller
e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00