Commit Graph

258 Commits

Author SHA1 Message Date
Thomas Haller
27e2d51abc cli: repeatedly trigger Wi-Fi scans while waiting for scan result
NetworkManager will reject scan requests, if it is currently scanning.
That is very wrong. Even if NetworkManager wants to ratelimit scan
requests or not scan at critical moments, it should never reject a
request, but remember and start scanning as soon as it can.
That should be fixed.

But regardless, also nmcli can do better.

If you issue

  $ nmcli device wifi list --rescan yes

once, it works as expected.

If you issue it again right after, the scan request of nmcli will be
rejected. But nmcli cannot just merely complete and print the result.
Instead, it will wait in the hope that a scan result will be present
soon. But if the request was simply rejected, then the result will
never come, and nmcli hangs for the 15 seconds timeout.

Instead, repeatedly re-trigger scan requests, in the hope that as soon
as possible we will be ready.
2020-04-24 13:58:46 +02:00
Thomas Haller
aede8fa554 cli: remove redundant return value from NMCCommand funcs
Many func implementations are asynchronous, that means, they
cannot return right away. Instead, they record the return value
in nmc->result_value.

The return value from the command functions was thus redundant.
In the best case, the return value agrees with the cached result
in nmc->result_value, in which it was unnecessary. In the worst case,
they disagree, and overwrite each other.

nmc->result_value is state. Tracking state is hard, and there should
be fewer places where the state gets mutated. Also, the rules how that
happened should be clearer. Drop the redundant, conflicting mechanism.
2020-04-10 10:44:37 +02:00
Thomas Haller
c5d45848dd cli: mark argv argument for command line parsing as const
It's bad style to pass the argv argument around and mutate it.
We shouldn't mutate it, and not assume that it stays around after
the function returns to the caller (meaning, we should clone the
array if we intend to use it later).

Add const specifier.
2020-04-10 10:27:27 +02:00
Thomas Haller
d39f5c264b cli: pass cmd to NMCCommand.func()
It is useful from inside a function to know the command that it belongs to.
Currently we have do_networking_on() and do_networking_off() as separate
functions. However, these are basically the same with a minor difference.
If the func callback could know the "cmd" that it was called for, these
function can be combined.

Of course, without passing the NMCCommand instance, you still can
achieve the same results, especially as the NMCCommand instances are
static and known at compile time: just have separate func
implementations. But by passing the command to the function, they
*can* be combined, which is a useful thing to do.
2020-04-10 10:27:27 +02:00
Thomas Haller
e05f35f9f1 cli: cleanup NMCCommand and declarations of func implementations
- move the main func declarations to nmcli.h and give them a common
prefix "nmc_command_func_" prefix.

- remove some of the header files that are now empty. In fact, these
headers did not really declare some well separated module. While we
probably should structure the code in nmcli better with better layering,
it was not and still is not. Having these dummy headers don't mean that
the code is well structured and they serve little purpose.

- move the static NMCommand lists variables into the function scope
where they are used.
2020-04-10 10:27:27 +02:00
Thomas Haller
30b8bb476a cli: avoid using nm_cli global variable in print_data() 2020-04-04 19:28:41 +02:00
Thomas Haller
93a6bcc8a2 cli: fix nmcli device wifi list --rescan=yes to wait
Fixes: db396cea9d ('cli: rework do_device_wifi_list() to scan and print Wi-Fi list')
2020-04-03 11:26:49 +02:00
Beniamino Galvani
2334a27692 cli: support setting removal 2020-03-23 11:42:57 +01:00
Thomas Haller
c03f88575d cli: fix nmcli device wifi with no Wi-Fi devices available
Fixes: db396cea9d ('cli: rework do_device_wifi_list() to scan and print Wi-Fi list')
2020-03-20 10:38:09 +01:00
Thomas Haller
3e869c107d cli: fix use after free in wifi_list_finish()
Fixes: db396cea9d ('cli: rework do_device_wifi_list() to scan and print Wi-Fi list')
2020-03-19 14:45:38 +01:00
Thomas Haller
db396cea9d cli: rework do_device_wifi_list() to scan and print Wi-Fi list
Drop the special casing of not scanning. Now do_device_wifi_list()
always handles the scan list in a callback.

Also fix the error code for scanning for a certain "bssid", which
previously was not set if scanning was not performed:

  $ nmcli device wifi list --rescan no bssid bogus
  Success
2020-03-19 10:46:58 +01:00
Thomas Haller
81d12f020a cli: use nm_utils_hwaddr_matches() for matching BSSID in wifi_print_aps()
We have a proper implementation for comparing MAC addresses. Don't
reimplement it differently.
2020-03-19 10:40:13 +01:00
Thomas Haller
a01355ba64 cli: add get_type argument to ap_wpa_rsn_flags_to_string() for optional i18n
Will be used later.
2020-03-16 13:40:51 +01:00
Thomas Haller
49dacaa34e cli: use slice allocator in do_device_wifi_list() and designated initializers for data 2020-03-16 13:40:51 +01:00
Thomas Haller
30cf1885d4 cli: cleanup selecting Wi-Fi device for nmcli device wifi list
Refactor the selection of the Wi-Fi device by name. Avoid
find_wifi_device_by_iface() to lookup by name. We already
have a sorted list of candidate devices. The ifname is just
an additional filter to exclude devices. So, we shouldn't
use find_wifi_device_by_iface(), but instead check our prepared
list of devices, whether it contains matching candidates.
2020-03-16 13:40:51 +01:00
Thomas Haller
e0e39a7452 cli: take reference in sort_access_points() for "clients/cli/devices.c"
It's not really necessary, but it feels slightly more correct. The only
reason not to take a reference is to safe the overhead of increasing and
decreasing the reference counter. But that doesn't matter for nmcli
at this point (and is tiny anyway). Let the API make sure that the instances
are kept alive.
2020-03-16 13:40:51 +01:00
Thomas Haller
ca4b530742 cli: use NM_CMP*() macros for compare_aps() in "clients/cli/devices.c"
The compare pattern seems simple, but seems error prone and subtle.
NM_CMP*() avoids that.

For example, nm_access_point_get_strength() returns an uint8_t.
C will promote those values to "int" before doing the subtraction.
Likewise, nm_access_point_get_frequency() returns a uint32_t. This
gets promoted to unsigned int when doing the subtraction. Afterwards,
that is converted to a signed int.
So both cases were in fact correct. But such things are not obvious.

Also, as fallback sort by D-Bus path. While that is not semantically
useful, we should use a defined sort order.
2020-03-16 13:40:51 +01:00
Thomas Haller
c69d703017 all: use g_ascii_strcasecmp() instead of the locale dependent strcasecmp()
In all the cases, we don't want to perform locale dependent comparison.

  $ sed -i 's/\<strcasecmp\>/g_ascii_\0/g' $(git grep -w -l strcasecmp -- ':(exclude)shared/systemd/' )
2020-02-11 15:23:06 +01:00
Antonio Cardace
730adf2afd clients,libnm-core: zero-out memory used to store plain-text secrets 2019-12-18 16:15:06 +01:00
Thomas Haller
bd9b253540 all: rename time related function to spell out nsec/usec/msec/sec
The abbreviations "ns" and "ms" seem not very clear to me. Spell them
out to nsec/msec. Also, in parts we already used the longer abbreviations,
so it wasn't consistent.
2019-12-13 16:54:40 +01:00
Beniamino Galvani
622eef4882 cli: expose device D-Bus path
https://bugzilla.redhat.com/show_bug.cgi?id=1745574
2019-12-10 17:57:10 +01:00
David Bauer
977c0c2387 client/cli: add support for OWE key management flag 2019-12-05 14:00:10 +01:00
Beniamino Galvani
2b7def052f all: add device carrier flag
Add a new 'carrier' flag to the InterfaceFlags property of devices to
indicate the current carrier state.

The new flag is equivalent to the 'lower-up' flag for all devices
except the ones that use a non-standard carrier detection mechanism
like NMDeviceAdsl.
2019-11-22 10:18:27 +01:00
Beniamino Galvani
62c811b2bd cli: print interface flags 2019-11-22 10:18:26 +01:00
Lubomir Rintel
9c5ea0917d devices: reuse the hotspot connection if we find appropriate one
Otherwise repeated "nmcli d wifi hotspot" commands create multiple
Hostpot connections, which is just sad. We do already reuse existing
connections with "nmcli d wifi connect" -- let's just do a similar thing
here.
2019-10-30 14:29:38 +01:00
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