Commit graph

25520 commits

Author SHA1 Message Date
Thomas Haller
747f7d3818
all: use "int/char" instead of "gint/gchar" typedefs
This is also recommended by our checkpatch.pl script.

(cherry picked from commit 2929392855)
2020-05-08 12:57:11 +02:00
Benjamin Porter
1b551ad1c3
man: extents -> extends in man page
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/497
(cherry picked from commit f6e41c19ff)
2020-05-08 08:07:10 +02:00
Thomas Haller
1e1ae9ba07
acd: fix char buffer argument to _acd_event_to_string_buf()
(cherry picked from commit 6e9967939b)
2020-05-08 07:58:12 +02:00
Thomas Haller
ecb9e0e3df
acd: avoid alloca() inside an unbounded loop
(cherry picked from commit b447c80ad8)
2020-05-07 14:02:23 +02:00
Beniamino Galvani
5b88cb6d98 merge: branch 'bg/coverity'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/495
(cherry picked from commit be3549abbd)
2020-05-07 10:54:20 +02:00
Beniamino Galvani
63e0ed1a08 libnm: remove early return statement in test_nm_auth_permissions()
Reported by coverity:

>>> CID 210230: Control flow issues (UNREACHABLE)
>>> This code cannot be reached: "i = 0;".

Fixes: 09e17888f7 ('libnm: add mapping functions between string and NMClientPermission enum')
(cherry picked from commit a29b13c7f1)
2020-05-07 10:53:59 +02:00
Beniamino Galvani
bb40de0ca0 ifcfg-rh: check return value of fdopen()
Reported by coverity:

>>> CID 210222: Null pointer dereferences (NULL_RETURNS)
>>> Dereferencing a pointer that might be "NULL" "f" when calling
    "fseek".

Fixes: ac5206aa9c ('2007-11-21')
(cherry picked from commit 581aa981c2)
2020-05-07 10:53:54 +02:00
Beniamino Galvani
144e7e40f0 libnm: fix assertion in NML_IS_DBUS_OBJECT()
Reported by coverity:

>>> CID 210228: Null pointer dereferences (REVERSE_INULL)
>>> Null-checking "dbobj" suggests that it may be null, but it has
    already been dereferenced on all paths leading to the check.

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
(cherry picked from commit 272f19108b)
2020-05-07 10:53:52 +02:00
Beniamino Galvani
f8a74684f4 libnm-core: replace malloc() with g_malloc()
For consistency with the rest of the code, prefer g_malloc() over
malloc().

(cherry picked from commit 966e3341a6)
2020-05-07 10:53:50 +02:00
Beniamino Galvani
9f23a18124 cli/polkit: add missing variable initialization in retrieve_session_id_cb()
Reported by coverity:

>>> CID 210213 Uninitialized pointer read (UNINIT)
>>> Using uninitialized value iter when calling
    _nm_auto_free_variant_iter

Fixes: df1d214b2e ('clients: polkit-agent: implement polkit agent without using libpolkit')
(cherry picked from commit 8cb58ef1eb)
2020-05-07 10:53:49 +02:00
Beniamino Galvani
0c9814c075 cli/polkit: add missing variable initialization in dbus_method_call_cb()
Reported by coverity:

>>> CID 210217: (UNINIT)
>>> Using uninitialized value "identities_gvariant" when calling
    "gs_local_variant_unref".

Fixes: df1d214b2e ('clients: polkit-agent: implement polkit agent without using libpolkit')
(cherry picked from commit fbccd24db6)
2020-05-07 10:53:48 +02:00
Thomas Haller
195b788d51 device: fix scope of variable in commit_option()
(cherry picked from commit 05fd2a9272)
2020-05-07 09:59:33 +02:00
Thomas Haller
805adec9ca
libnm: fix gtk-doc annotations for nm_setting_match_get_interface_names()
Otherwise the function is not usable via generated bindings.

Fixes: 9b9dce9486 ('all: add 'match' setting')
(cherry picked from commit 180cda7632)
2020-05-06 15:11:03 +02:00
Antonio Cardace
70180b37a3
nm-setting-bridge: add missing 'Since: X.Y' comments to options
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-05-04 17:52:18 +02:00
Beniamino Galvani
1ffb194d1e platform: fix test failure when /proc is mounted read-only
Expect a failure when writing to /proc if the file system is mounted
read-only.

(cherry picked from commit 211eb3ff8a)
2020-05-04 14:21:41 +02:00
Thomas Haller
53476d821d
nm-online: fix build of nm-online for missing libcsiphash.la
Fixes: e468b48ab7 ('nm-online: allow configuring timeout via NM_ONLINE_TIMEOUT environment')
(cherry picked from commit 69798fa6cd)
2020-05-02 23:00:08 +02:00
Thomas Haller
496fea7db8
release: bump version to 1.23.91 (1.24-rc2) 2020-05-02 21:47:58 +02:00
Thomas Haller
bd0a713495
NEWS: update
(cherry picked from commit 938aca3fab)
2020-05-02 21:40:04 +02:00
Thomas Haller
60c67b713b
dispatcher: merge branch 'th/dispatcher-doc-connectivity-change-arg'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/485

(cherry picked from commit 2a319c5dbb)
2020-04-30 21:53:21 +02:00
Thomas Haller
775ebba658
dispatcher: minor cleanup error paths in script_dispatch()
Handle the error case first and return early.

(cherry picked from commit 259a07ae46)
2020-04-30 21:53:21 +02:00
Thomas Haller
62b135d337
dispatcher: clarify documentation about first argument to dispatcher scripts for "connectivity-change"
The manual page claimed that for "connectivitiy-change" actions, the dispatcher
scripts would get as first argument (the device name) "none". That was not done,
only for "hostname" actions.

For consistency, maybe that should be adjusted to also pass "none" for connectivity
change events. However, "none" is really an odd value, if there is no device. Passing
an empty word is IMO nicer. So stick to that behavior, despite being inconsistent.
Also fix the documentation about that.

(cherry picked from commit 0b168f7b99)
2020-04-30 21:53:21 +02:00
Thomas Haller
02513e4b5d
nm-online: allow configuring timeout via NM_ONLINE_TIMEOUT environment
https://bugzilla.redhat.com/show_bug.cgi?id=1828458

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/484
(cherry picked from commit e468b48ab7)
2020-04-30 21:47:30 +02:00
Beniamino Galvani
bee01292f8 n-dhcp4: don't fail dispatch in case of receive errors
Currently any error encountered in n_dhcp4_c_connection_dispatch_io()
causes a dispatch failure and interrupts the library state
machine. The recvmsg() on the socket can fail for different reasons;
one of these is for example that the UDP request previously sent got a
ICMP port-unreachable response. This can be reproduced in the
following way:

 ip netns add ns1
 ip link add veth0 type veth peer name veth1
 ip link set veth1 netns ns1
 ip link set veth0 up

 cat > dhcpd.conf <<EOF
 server-identifier 172.25.0.1;
 max-lease-time 120;
 default-lease-time 120;
 subnet 172.25.0.0 netmask 255.255.255.0 {
        range 172.25.0.100 172.25.0.200;
 }
 EOF

 ip -n ns1 link set veth1 up
 ip -n ns1 address add dev veth1 172.25.0.1/24
 ip netns exec ns1 iptables -A INPUT -p udp --dport 67 -j REJECT
 ip netns exec ns1 dhcpd -4 -cf dhcpd.conf -pf /tmp/dhcp-server.pid

If a client is started on veth0, it is able to obtain a lease despite
the firewall rule blocking DHCP, because dhcpd uses a packet
socket. Then it fails during the renewal because the recvmsg() fails:

 dhcp4 (veth0): send REQUEST of 172.25.0.178 to 172.25.0.1
 dhcp4 (veth0): error -111 dispatching events
 dhcp4 (veth0): state changed bound -> fail

The client should consider such errors non fatal and keep running.

https://bugzilla.redhat.com/show_bug.cgi?id=1829178
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/486
(cherry picked from commit c5d1d4c498)
2020-04-30 18:15:42 +02:00
Thomas Haller
39a8dd0dc8 wifi: clear scan_request_ssids_hash if not needed
It is very uncommon that a user provides explicit SSIDs to scan.
So, most of the time there is nothing to do here.

(cherry picked from commit d9740d108d)
2020-04-30 11:21:22 +02:00
Thomas Haller
9f09b17340 wifi: don't unnecessarily trim tracked ssid list
Only _scan_request_ssids_track() adds elements to the list, and that already
trims the list to a maxium length. In all other cases, we never expect a need
to trim the list.

(cherry picked from commit 3af9209d47)
2020-04-30 11:21:22 +02:00
Thomas Haller
6dc581f9af wifi: pass now_msec to _scan_request_ssids_fetch()
We make decisions based on the timestamp. We should only fetch the timestamp
once, and make consistent decisions about that. Don't read different timestamps.

(cherry picked from commit a0e115cb44)
2020-04-30 11:21:22 +02:00
Thomas Haller
783be3ab7e wifi: fix trimming list of tracked ssids to scan
Fixes: e07fc217ec ('wifi: rework scanning of Wi-Fi device')
(cherry picked from commit 8fb2241183)
2020-04-30 11:21:22 +02:00
Thomas Haller
c81f599b04 wifi: really fix crash during dispose of NMDeviceWifi
The right fix is to return from _scan_kickoff() right away.

Backtrace:

  #0  0x00007f520eeb2002 g_logv (libglib-2.0.so.0 + 0x5a002)
  #1  0x00007f520eeb2273 g_log (libglib-2.0.so.0 + 0x5a273)
  #2  0x000056026929b25a nm_supplicant_interface_get_max_scan_ssids (NetworkManager + 0x27e25a)
  #3  0x00007f520c238bb1 _scan_request_ssids_build_hidden (libnm-device-plugin-wifi.so + 0x15bb1)
  #4  0x00007f520c23a2d5 _scan_notify_is_scanning (libnm-device-plugin-wifi.so + 0x172d5)
  #5  0x00007f520c2433d3 dispose (libnm-device-plugin-wifi.so + 0x203d3)
  #6  0x00007f520efa3c78 g_object_unref (libgobject-2.0.so.0 + 0x18c78)
  #7  0x00005602690ada1a remove_device (NetworkManager + 0x90a1a)
  #8  0x00005602690be428 nm_manager_stop (NetworkManager + 0xa1428)
  #9  0x0000560269064adb main (NetworkManager + 0x47adb)
  #10 0x00007f520ec70042 __libc_start_main (libc.so.6 + 0x27042)
  #11 0x0000560269064efe _start (NetworkManager + 0x47efe)

Fixes: e07fc217ec ('wifi: rework scanning of Wi-Fi device')
Fixes: a2deb0da5e ('wifi: fix crash during dispose of NMDeviceWifi')
(cherry picked from commit 2794f3cff8)
2020-04-30 11:21:22 +02:00
Thomas Haller
db68ebd41c wifi: fix crash during dispose of NMDeviceWifi
Backtrace:

  #0  0x00007f520eeb2002 g_logv (libglib-2.0.so.0 + 0x5a002)
  #1  0x00007f520eeb2273 g_log (libglib-2.0.so.0 + 0x5a273)
  #2  0x000056026929b25a nm_supplicant_interface_get_max_scan_ssids (NetworkManager + 0x27e25a)
  #3  0x00007f520c238bb1 _scan_request_ssids_build_hidden (libnm-device-plugin-wifi.so + 0x15bb1)
  #4  0x00007f520c23a2d5 _scan_notify_is_scanning (libnm-device-plugin-wifi.so + 0x172d5)
  #5  0x00007f520c2433d3 dispose (libnm-device-plugin-wifi.so + 0x203d3)
  #6  0x00007f520efa3c78 g_object_unref (libgobject-2.0.so.0 + 0x18c78)
  #7  0x00005602690ada1a remove_device (NetworkManager + 0x90a1a)
  #8  0x00005602690be428 nm_manager_stop (NetworkManager + 0xa1428)
  #9  0x0000560269064adb main (NetworkManager + 0x47adb)
  #10 0x00007f520ec70042 __libc_start_main (libc.so.6 + 0x27042)
  #11 0x0000560269064efe _start (NetworkManager + 0x47efe)

Fixes: e07fc217ec ('wifi: rework scanning of Wi-Fi device')
(cherry picked from commit a2deb0da5e)
2020-04-29 21:16:10 +02:00
Thomas Haller
54e15618c4 wifi: reduce scan rate limiting while not being activated
While we are not activated, there is less need to rate limit the scan
requests to 8 seconds. Only rate limit the requests for 1.5 seconds
in that case.

Also, when changing the MAC address, supplicant flushes the AP list.
We should be able to scan right away. Reset the counters for the rate
limiting and periodic scanning.

(cherry picked from commit 12a54a44f8)
2020-04-29 13:46:52 +02:00
Thomas Haller
8a4472654d wifi: merge branch 'th/wifi-scan' (part 2)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/479

(cherry picked from commit 20c17978ff)
2020-04-29 12:30:19 +02:00
Thomas Haller
e00475ac8f wifi: don't limit active scans for SSIDs to 5
As far as NMSupplicantInterface is concerned, don't clamp the
max-scan-ssids to 5. We should track the real value that wpa_supplicant
announces, and it's up to the caller to provide fewer SSIDs.

In particular, we want to limit the number of hidden SSIDs that we
accept from connection profiles, but we don't want to limit the number
of active scans via `nmcli device wifi rescan ssid $SSID [...]`.

(cherry picked from commit c9ae23af5e)
2020-04-29 12:30:14 +02:00
Thomas Haller
7500e90b53 wifi: rework scanning of Wi-Fi device
Handling the scanning is complicated.

- we want to have periodic scans. But only at certain times,
and with an increasing back off timeout.

- the user can initiate explicit scans via D-Bus. Thereby a list
of SSIDs scan be provided.

- if there are any hidden Wi-Fi profiles configured, we want
to explicitly scan for their SSIDs.

- explicit scans are not possible at any time. But we should not reject
the scan request, but instead remember to scan later, when possible.

This is a heavy rework. It also aims to fix issues of scanning since
the recent rework of supplicant handling in commit b83f07916a
('supplicant: large rework of wpa_supplicant handling') that can render
Wi-Fi scanning broken.

Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling'):
(cherry picked from commit e07fc217ec)
2020-04-29 12:30:12 +02:00
Thomas Haller
1fea82083e wifi: merge branch 'th/wifi-scan' (part 1)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/479

(cherry picked from commit daee41b82a)
2020-04-29 12:30:04 +02:00
Thomas Haller
17615fbc2b wifi: express SCAN_RAND_MAC_ADDRESS_EXPIRE time in seconds
We commonly use already seconds and milliseconds scales for computing timeouts.
Reduce the number of difference scales and don't also use minutes.

(cherry picked from commit f6e438860b)
2020-04-29 12:30:00 +02:00
Thomas Haller
8c2b282b11 supplicant: log changes to max-scan-ssids of NMSupplicantInterface
(cherry picked from commit a7476ff082)
2020-04-29 12:29:58 +02:00
Thomas Haller
fa5434fa1c device: implement "auth-request" as async operation nm_manager_device_auth_request()
GObject signals only complicate the code and are less efficient.

Also, NM_DEVICE_AUTH_REQUEST signal really invoked an asynchronous
request. Of course, fundamentally emitting a signal *is* the same as
calling a method. However, implementing this as signal is really not
nice nor best practice. For one, there is a (negligible) overhead emitting
a GObject signal. But what is worse, GObject signals are not as strongly
typed and make it harder to understand what happens.

The signal had the appearance of providing some special decoupling of
NMDevice and NMManager. Of course, in practice, they were not more
decoupled (both forms are the same in nature), but it was harder to
understand how they work together.

Add and call a method nm_manager_device_auth_request() instead. This
has the notion of invoking an asynchronous method. Also, never invoke
the callback synchronously and provide a cancellable. Like every asynchronous
operation, it *must* be cancellable, and callers should make sure to
provide a mechanism to abort.

(cherry picked from commit b50702775f)
2020-04-29 12:29:57 +02:00
Thomas Haller
35a6edd963 auth: track NMAuthChain data in array instead of CList
It's about as complicated to track a CList as it is to track
an allocated array. The latter requires fewer allocations and
has better locality. That makes it preferable.

(cherry picked from commit d935692bc7)
2020-04-29 12:29:57 +02:00
Thomas Haller
d81977c0ae auth: natively support GCancellable in NMAuthChain
We want that our asynchronous operations are cancellable.

In fact, NMAuthChain is already (manually) cancellable by the
user calling nm_auth_chain_destroy(). However, sometimes we have a
GCancellable at hand, so the callers would have to register to the
cancellable themselves.

Instead, support setting a cancellable to the NMAuthChain, that aborts
the request and invokes the callback.

It does so always on an idle handler. Also, the user may only set the
cancellable once, and only before starting the first call.

(cherry picked from commit ef7fd9e4e3)
2020-04-29 12:29:56 +02:00
Thomas Haller
6db85c56dc device: add nm_device_get_manager()
NMDevice already has access to the NMSettings singleton. It is permissible that
NMDevice *knows* about NMManager. The current alternative is emitting GObject signals
like NM_DEVICE_AUTH_REQUEST, pretending that NMDevice and NMManager would be completely
independent, or that there could be anybody else handling the request aside NMManager.

No, NMManager and NMDevice may know each other and refer to each other. Just like
NMDevice also knows and refers to NMSettings.

(cherry picked from commit 800ac28cca)
2020-04-29 12:29:55 +02:00
Thomas Haller
887351fca2 shared/glib: prevent users to use g_cancellable_reset()
When handling a GCancellable, you make decisions based on when the cancelled
property of a GCancellable changes. Correctly handling a cancellable becoming
uncancelled again is really complicated, nor is it clear what it even means:
should the flipping be treated as cancellation or not? Probably if the
cancelled property gets reset, you already start aborting and there is
no way back. So, you would want that a cancellation is always handled.
But it's hard to implement that correctly, and it's odd to claim
something was cancelled, if g_cancellable_is_cancelled() doesn't agree
(anymore).

Avoid such problems by preventing users to call g_cancellable_reset().

(cherry picked from commit ee7fbc954e)
2020-04-29 12:29:55 +02:00
Thomas Haller
24b2fbbfc7 shared: add nm_gbytes_get_empty() singleton getter
(cherry picked from commit 32664c72a5)
2020-04-29 12:29:55 +02:00
Thomas Haller
616c18a612 shared: add nm_gbytes_hash() and nm_gbytes_equal()
(cherry picked from commit 2a26562ec8)
2020-04-29 12:29:55 +02:00
Thomas Haller
e62dcb3c6b wifi/iwd: merge branch 'andhe:iwd-connect-hidden'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/285

(cherry picked from commit d0d91ed6ac)
2020-04-29 11:45:00 +02:00
Andreas Henriksson
4bb0e48b13 iwd: use ConnectHiddenNetwork to provision hidden network
The Station.ConnectHiddenNetwork will provision a network in the iwd
known-networks list. This should allow us to later use the
Network.Connect interface to connect in the future.
(Note: Attempts to use Station.ConnectHiddenNetwork on already provisioned
networks, i.e. networks iwd knows about, will fail.)

This commit squashed several fixups made by thaller.

(cherry picked from commit 69aeed4bdc)
2020-04-29 11:45:00 +02:00
Andreas Henriksson
dc115bf406 iwd: support connecting to hidden networks
Newer versions of iwd has supported connecting to hidden networks for a
while now. There's a separate "connect-hidden" command in iwctl that
needs to be used instead of the regular "connect" command.
The equivalent on dbus is to use ConnectHiddenNetwork instead of
Connect on the Station interface. NetworkManager however uses the
Network interface and given we the explicit SSID usage we can connect
to hidden networks with that.

This change disabled the explicit check that disallows even attempting
hidden networks when using iwd.

This has been tested to work with a previously known hidden network.
Tests connecting to a previously unknown network has failed.

(cherry picked from commit cd095f49dc)
2020-04-29 11:44:59 +02:00
Thomas Haller
da757f80cc libnm/doc: fix spelling in nm_client_add_and_activate_connection2() documentation
(cherry picked from commit c8a9703130)
2020-04-28 18:36:47 +02:00
Beniamino Galvani
0344a97105 device: flush IP configuration of slaves during activation
If a device only has an IPv6 link-local address, we don't generate an
assumed connection. Therefore, when a new slave connection (without IP
configuration) is activated on the device, we don't deactivate any
existing connection and the link-local address remains configured.

The IP configuration of an activated slave should be predictable and
not depend on the previous state; let's flush addresses and routes on
activation.

https://bugzilla.redhat.com/show_bug.cgi?id=1816517
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/480
(cherry picked from commit e302f5ff77)
2020-04-28 10:00:28 +02:00
Thomas Haller
cfc79124ef vpn: merge branch 'th/vpn-ipv6-addr-fix-assert'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/482

(cherry picked from commit d9dbe88427)
2020-04-28 09:42:32 +02:00
Thomas Haller
61e65e42dc vpn: cleanup loop in nm_vpn_connection_ip6_config_get()
I find it simpler to follow the pattern of checking conditions and
"erroring out", by going to the next entry. The entire loop already
behaves like that.

(cherry picked from commit f89b841b37)
2020-04-28 09:42:32 +02:00