Commit graph

12835 commits

Author SHA1 Message Date
Andreas Henriksson
69aeed4bdc 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.
2020-04-29 11:03:11 +02:00
Andreas Henriksson
cd095f49dc 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.
2020-04-29 10:44:40 +02:00
Thomas Haller
f6e438860b 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.
2020-04-28 18:35:59 +02:00
Thomas Haller
a7476ff082 supplicant: log changes to max-scan-ssids of NMSupplicantInterface 2020-04-28 18:35:59 +02:00
Thomas Haller
b50702775f 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.
2020-04-28 18:35:59 +02:00
Thomas Haller
d935692bc7 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.
2020-04-28 18:35:59 +02:00
Thomas Haller
ef7fd9e4e3 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.
2020-04-28 18:35:59 +02:00
Thomas Haller
800ac28cca 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.
2020-04-28 18:35:59 +02:00
Thomas Haller
9b295f0df5 dhcp: make connection.mud-url configurable as global connection default
Conceptionally, the MUD URL really depends on the device, and not so
much the connection profile. That is, when you have a specific IoT
device, then this device probably should use the same MUD URL for all
profiles (at least by default).

We already have a mechanism for that: global connection defaults. Use
that. This allows a vendor drop pre-install a file
"/usr/lib/NetworkManager/conf.d/10-mud-url.conf" with

  [connection-10-mud-url]
  connection.mud-url=https://example.com

Note that we introduce the special "connection.mud-url" value "none", to
indicate not to use a MUD URL (but also not to consult the global connection
default).
2020-04-28 13:01:18 +02:00
Beniamino Galvani
e302f5ff77 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
2020-04-28 09:57:22 +02:00
Thomas Haller
f89b841b37 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.
2020-04-28 09:41:37 +02:00
Thomas Haller
b437bb4a6e vpn: clear host part of IPv6 routes received from VPN plugin
Kernel would reject adding a route with a destination host part not
all zero. NetworkManager generally coerces such routes and there
are assertions in place to ensure that.

We forgot to ensure that for certain IPv6 routes from VPN plugins.
This can cause an assertion failure and wrong behavior.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/425

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/482
2020-04-28 09:41:18 +02:00
Thomas Haller
552aa962d7 libnm,dhcp: use nm_clear_g_free() instead of nm_clear_pointer(, g_free) 2020-04-27 12:54:14 +02:00
Thomas Haller
16c1869476 wifi: add callback to nm_supplicant_interface_request_scan()
While we request a scan, we are not yet actually scanning. That means, the supplicant's
"scanning" property will only change to TRUE a while after we initiate the scan. It may
even never happen.

We thus need to handle that the request is currently pending and react when the
request completes.
2020-04-24 16:57:28 +02:00
Thomas Haller
8ecc325f29 wifi: add more trace logging to supplicant interface 2020-04-24 13:58:46 +02:00
Thomas Haller
cd5157a0c3 shared: add nm_utils_invoke_on_timeout()
Add nm_utils_invoke_on_timeout() beside nm_utils_invoke_on_idle().
They are fundamentally similar, except one schedules an idle handler
and the other a timeout.

Also, use the current g_main_context_get_thread_default() as context
instead of the singleton instance. That is a change in behavior, but
the only caller of nm_utils_invoke_on_idle() is the daemon, which
doesn't use different main contexts. Anyway, to avoid anybody being
tripped up by this also change the order of arguments. It anyway
seems nicer to first pass the cancellable, and the callback and user
data as last arguments. It's more in line with glib's asynchronous
methods.

Also, in the unlikely case that the cancellable is already cancelled
from the start, always schedule an idle action to complete fast.
2020-04-24 13:58:46 +02:00
Thomas Haller
93b634f1a2 platform: simplify static assert in _nl_static_assert_tb() 2020-04-24 13:58:46 +02:00
Thomas Haller
03b606d1ff dhcp: set MUD URL in DHCPv6 request for systemd DHCP client 2020-04-24 10:09:50 +02:00
Thomas Haller
3a2858a2fd ifcfg-rh/trivial: drop comment for nms_ifcfg_well_known_keys
The comment isn't right. The fixed array size is in the header file,
because other parts of the code need to know how many elements are in
the array. The alternative would be a define for the size, but that
is only redundant information. Also, even with a define the user who
adds an entry needs to adjust the code in the header. Explicitly stating
the array size in the header makes it almost impossible to accidentally
choosing the wrong size, because the compiler (and unit tests) ensure
the consistency.
2020-04-24 10:09:50 +02:00
Thomas Haller
3e6b6d34db dhcp: fix leaking mud_url in NMDhcpClient 2020-04-24 10:09:50 +02:00
Thomas Haller
4bcaff4cb5 dhcp: don't make mud-url property of NMDhcpClient readable
We have this as a GObject property, so that it can be set at construct
time (to be never modified afterwards). We don't need a readable
GObject property, because there is a getter function that should be
used instead.
2020-04-24 10:09:50 +02:00
Thomas Haller
a058535b9d device: rename local variable s_connection and adjust assertions
- avoid g_assert(). Either we want to gracefully assert (g_return_*()) or we
  want to use assertions that are disabled in production builds (nm_assert());

- rename variable s_connection to s_con. This is how variables for this
  purpose are commonly called.
2020-04-24 10:09:50 +02:00
Thomas Haller
54e2c60d34 dhcp/nettools: cleanup setting error message from n-dhcp4 error code
n-dhcp4 error codes can also be some positive numbers. Those shall not
be converted to errno. Instead, print the error code directly.
2020-04-24 10:09:50 +02:00
Thomas Haller
a2956db2ee dhcp: abort on error setting DHCP MUD URL option for nettools 2020-04-24 10:09:50 +02:00
Thomas Haller
db645623ee dhcp: rename mudurl to mud_url 2020-04-24 10:09:50 +02:00
Thomas Haller
ce282fa3f7 systemd: make string argument of sd_dhcp6_client_set_request_mud_url() const
See-also: https://github.com/systemd/systemd/pull/15586
2020-04-24 10:09:42 +02:00
Eliot Lear
295e6678dd dhcp: add support for MUD URL (RFC 8520)
[thaller@redhat.com: rewritten commit message]

https://tools.ietf.org/html/rfc8520
https://blog.apnic.net/2019/05/14/protecting-the-internet-of-things-with-mud/

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/402

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/463
2020-04-24 10:07:38 +02:00
Thomas Haller
115291a46f wireguard: don't let explicit gateway override WireGuard's peer route
The profile's "ipv4.gateway" and "ipv6.gateway" has only one real
purpose: to define the next hop of a static default route.

Usually, when specifying a gateway in this way, the default route from
other addressing methods (like DHCPv4 or IPv6 autoconf) gets ignored.

If you have a WireGuard peer with "AllowedIPs=0.0.0.0/0" and
"wireguard.peer-routes" enabled, NetworkManager would automatically add
a route to the peer. Previously, if the user also set a gateway, that
route was suppressed.

That doesn't feel right. Note that configuring a gateway on a WireGuard
profile is likely to be wrong to begin with. At least, unless you take
otherwise care to avoid routing loops. If you take care, setting a
gateway may work, but it would feel clearer to instead just add an
explicit /0 manual route instead.

Also, note that usually you don't need a gateway anyway. WireGuard is a
Layer 3 (IP) tunnel, where the next hop is alway just the other side of
the tunnel. The next hop has little effect on the routes that you
configure on a WireGuard interface. What however matters is whether a
default route is present or not.

Also, an explicit gateway probably works badly with "ipv[46].ip4-auto-default-route",
because in that case the automatism should add a /0 peer-route route in a
separate routing table. The explicit gateway interferes with that too.

Nonetheless, without this patch it's not obvious why the /0 peer
route gets suppressed when a gateway is set. Don't allow for that, and
always add the peer-route.

Probably the profile's gateway setting is still wrong and causes the
profile not to work. But at least, you see all routes configured, and
it's clearer where the (wrong) default route to the gateway comes from.
2020-04-22 11:36:51 +02:00
Thomas Haller
5da82ee3ea wireguard: suppress automatic "wireguard.peer-routes" for default routes if "ipv[46].never-default" is enabled
Enabling both peer-routes and never-default conflicts with having
AllowedIPs set to a default route. Let never-default win.
2020-04-22 11:05:39 +02:00
Thomas Haller
e8b86f8445 core: add NMIPConfigFlags for NMIPConfig flags
This will be useful to set future options on the NMIPConfig.

Yes, the code duplication of NMIP[46]Config is horrible. Needs
to be unified in the future.
2020-04-22 10:52:59 +02:00
Thomas Haller
b2a5b179fd platform: avoid undefined behavior comparing unrelated pointers in nmp_object_id_cmp()
Pointers cannot in general be compared directly. Cast to an int first
to avoid the undefined behavior.
2020-04-22 09:49:45 +02:00
Beniamino Galvani
5c547fdab3 bluetooth: disconnect signal on dispose
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/417

Fixes: 4154d9618c ('bluetooth: refactor BlueZ handling and let NMBluezManager cache ObjectManager data')
2020-04-22 09:15:43 +02:00
Beniamino Galvani
fb023cc6e8 supplicant: set error when interface creation fails and was cancelled
https://bugzilla.redhat.com/show_bug.cgi?id=1823164

Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')
2020-04-21 17:26:51 +02:00
Thomas Haller
f4cf907a42 auth-manager: watch PolicyKit name owner to emit changed signal when name owner appears
We shall emit a changed signal when PolicyKit changes. That implies also
emitting the signal when PolicyKit starts. Watch the name owner for
that.

Note that I don't manage to actually receive the "Changed" signal from
PolicyKit. That seems to be due to wrong D-Bus configuration which
prevents the "Changed" signal from PolicyKit to reach NetworkManager.
That is independent from this patch.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/469
2020-04-21 12:19:43 +02:00
Beniamino Galvani
cb9a6f3b92 dns: fix handling of trust-ad option
Fixes: 5e47fb630b ('dns: add trust-ad DNS option only if all contributing settings agree')
2020-04-21 10:50:12 +02:00
Beniamino Galvani
eefe5dacaa dhcp-helper: retry in case of failure connecting to D-Bus unix socket
Connecting to the unix socket can fail with EAGAIN if there are too
many pending connections and the server can't accept them in time
before reaching backlog capacity. Ideally the server should increase
the backlog length, but GLib doesn't provide a way to change it for a
GDBus server. Retry for up to 5 seconds in case of failure.

https://bugzilla.redhat.com/show_bug.cgi?id=1821594
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/471
2020-04-21 08:54:44 +02:00
Beniamino Galvani
a5338affb5 wifi: change return type of p2p-connect D-Bus method call
Fix the following error when invoking the Connect() p2p method:

 call-p2p-connect: failed with Method “fi.w1.wpa_supplicant1.Interface.P2PDevice.Connect” returned type “(s)”, but expected “()”

Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')
2020-04-20 17:12:18 +02:00
Thomas Haller
5e47fb630b dns: add trust-ad DNS option only if all contributing settings agree
https://bugzilla.redhat.com/show_bug.cgi?id=1825285
2020-04-20 15:54:43 +02:00
Beniamino Galvani
70916a1183 ifcfg-rh: add PKEY_ID to well-known keys
Fixes: 81e6fe963e ('ifcfg-rh: add functions to detect well-known ifcfg-rh keys')
2020-04-17 09:47:16 +02:00
Thomas Haller
216e97b7fa dbus: pretty format "org.freedesktop.NetworkManager.conf"
- indent by 4 spaces, not 8. We do that for the other 2 D-Bus
  configuration files. Also, since our lines here are rather long,
  save a bit in this regard.

- don't wrap lines for the XML elements. It makes it easier to visually
  parse.

- sort some lines asciibetically.

No changes otherwise.
2020-04-15 19:17:00 +02:00
Thomas Haller
b681aec452 dbus: indent by 4 space in "nm-ifcfg-rh.conf" D-Bus configuration file 2020-04-15 18:48:32 +02:00
Antonio Cardace
2a5d9eb60b
bond: small cleanups
* Use an enum instead of a string, is faster for comparisons.
* Add debug assertions
* Have NMBondMode enum correspond to Kernel numbering
2020-04-10 17:46:22 +02:00
Beniamino Galvani
db37e530e8 ovsdb: retry calls in case of communication error with server
When the server is restarted the write to unix socket fails with
EPIPE. In such case, don't fail all the calls in queue; instead, after
a sync of the ovsdb state (through a monitor call), start processing
the queue again, including the call that previously failed.

Add a retry counter to avoid that calls are stuck in the queue forever
in a hypothetical scenario in which the write always fails.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/459
2020-04-09 17:26:18 +02:00
Beniamino Galvani
d213c3cd1a device: fix assertion failure configuring bridge ports
Fixes: 177ee2d7bf ('device/bridge: code cleanup in commit_option()')
2020-04-09 16:45:18 +02:00
Thomas Haller
177ee2d7bf device/bridge: code cleanup in commit_option() 2020-04-09 09:34:18 +02:00
Thomas Haller
36ab1e841f device/bridge: fix uninitialized variable in commit_option()
Fixes: 93e38cbe56 ('nm-setting-bridge: add 'group-address' bridge option')
2020-04-09 09:32:39 +02:00
Thomas Haller
95888e8861 dns: fix crash in rebuild_domain_lists()
Fixes: 103943776c ('dns: cleanup rebuild_domain_lists() constructing domains list')
2020-04-08 18:02:15 +02:00
Thomas Haller
9a74d2e023 dns: add FIXME comment about adding default "~" routing search domain 2020-04-08 12:41:32 +02:00
Thomas Haller
103943776c dns: cleanup rebuild_domain_lists() constructing domains list 2020-04-08 09:32:45 +02:00
Thomas Haller
c3969425ec systemd: merge branch systemd into master 2020-04-08 09:08:49 +02:00