Commit graph

806 commits

Author SHA1 Message Date
Thomas Haller
18d0ab14bc
device: drop unused variable and avoid compiler warning
../src/core/devices/nm-device-ethernet.c:1164:35: error: unused variable error [-Werror,-Wunused-variable]
              gs_free_error GError *error    = NULL;
                                    ^

Fixes: aa9b5e28eb ('ethernet: fix setting ip-ifindex for PPPoE connections')
2022-03-17 19:31:29 +01:00
Lubomir Rintel
feee84aac4 wifi: mark WEP connections incompatible if supplicant lacks capability
This allows us to reject activation of WEP profiles very early,
also providing a reasonable error code to the client:

  $ nmcli d wifi connect test
  Error: Failed to add/activate new connection: wpa_supplicant does not support WEP encryption
2022-03-17 12:44:53 +01:00
Lubomir Rintel
41d03a1b17 supplicant: check whether WEP is available
Since version 2.10, it's possible to build wpa_supplicant without WEP
support. In fact, it's disabled by default. Regrettably, there's no
indication in that version as to whether WEP is enabled or not.

A patch has been sent upstream that exposes the information on D-Bus:
https://patchwork.ozlabs.org/project/hostap/patch/20220307085446.706024-1-lkundrak@v3.sk/

This makes use of the above to indicate presence or absence of WEP
support.
2022-03-17 12:44:53 +01:00
Lubomir Rintel
91f076d235 supplicant: add a comment about extending NMSupplCapType
We've failed to amend logging in relevant places twice. Let's add a
hopefully helpful remark.
2022-03-17 12:44:53 +01:00
Lubomir Rintel
78c937cb23 supplicant: log WPA-EAP-SUITE-B-192 capability
Fixes: e874ccc917 ('wifi: add WPA-EAP-SUITE-B-192 support')
2022-03-17 12:44:53 +01:00
Thomas Haller
ca9c67565a
connectivity: use GSource instead of source id for tracking timeout/idle source
I think we should move away from using the source-ids.

Having a "GSource*" pointer makes it clearer what this is, compared to a
guint source ID. Also, g_source_remove() always needs to first do a hash
lookup (with locking) to resolve the source ID to the GSource. This is
unnecessary.
2022-03-17 10:27:33 +01:00
Thomas Haller
63d68e7f42
connectivity: minor cleanup resolve_cb() to use nm_utils_addr_family_to_size()
And change code so that clang-format produces nicer alignment.
2022-03-17 10:10:41 +01:00
Thomas Haller
593d08db81
connectivity: skip unexpected addr family from resolved response
In practice, systemd-resolved will give us always AF_INET/AF_INET6. Still,
check for that.
2022-03-17 10:10:22 +01:00
Beniamino Galvani
c65ae9b1db core/tests: fix tests for nm_utils_shorten_hostname()
The test currently fails on systems where HOST_NAME_MAX != 64 (for
example, Alpine Linux). Update the test to not assume a predefined
maximum length.

Fixes: 9498702242 ('core: add nm_utils_shorten_hostname()')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1149
2022-03-16 11:24:02 +01:00
Beniamino Galvani
aa9b5e28eb ethernet: fix setting ip-ifindex for PPPoE connections
When a NMDevice is involved in a PPPoE activation, it means that the
connection has connection.interface-name=<ethernet-interface>. In such
case, the ppp ifindex should be set as ip-ifindex of the ethernet
device.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-03-16 10:43:46 +01:00
Beniamino Galvani
7b2bea7ceb ethernet: don't do DHCPv4 on PPPoE
It's not going to work.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-03-16 10:43:46 +01:00
Beniamino Galvani
041df05f3c ppp: allow autoconf6 when ipv6.method is 'auto'
PPP supports IPv6 autoconfiguration.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-03-16 10:43:46 +01:00
Thomas Haller
8aaee8c50c
core/device: avoid logging "%p" format and use obfuscated ptr 2022-03-13 12:08:59 +01:00
Thomas Haller
4629506b80
core/device: rename nm_device_master_release_one_slave()
We have nm_device_master_add_slave(). This should be mirrored by
nm_device_master_release_slave() (not release-one-slave).

Thereby, also rename nm_device_master_release_slaves() to
nm_device_master_release_slaves_all() to make it clearer.
2022-03-13 12:08:52 +01:00
Thomas Haller
17ac71cd58
core/device: add ReleaseSlaveType argument for nm_device_master_release_one_slave()
I find the two (dependent) booleans "configure" and "force" confusing.
nm_device_master_release_one_slave() has many callers, it's interesting
to be able to grep for the release-type. Add an enum to make this more
readable.
2022-03-13 12:08:08 +01:00
Thomas Haller
a566fd8cf4
core/device: use c_list_for_each_entry() for interating of slaves list
This convenience macro is just shorter, resulting in more(?) readable
code and less clutter.
2022-03-13 12:02:09 +01:00
Thomas Haller
53406e721d
core/trivial: rename parameter to link_changed_cb()
"info" is not a good name. Variables of this kind are usually
called "plink" or "pllink". Rename.
2022-03-13 12:02:08 +01:00
Thomas Haller
6f948fcd2e
core: use nm_dbus_manager_lookup_object_with_type()
I think this makes it clearer that we should always look for a certain
type, because NMDBusManager tracks all D-Bus objects.
2022-03-13 12:02:08 +01:00
Thomas Haller
de61722efe
core: add nm_dbus_manager_lookup_object_with_type() helper
This makes the non-obvious fact clearer, that when you look up an object
by an untrusted, user-provided path, it might not be the object type you
are looking for. In basically all cases, you need to check that the
result is of the expected type. This helper makes that clearer.
2022-03-13 12:02:07 +01:00
Thomas Haller
216c46c881
all: prefer nm wrappers to automatically attach GSource to default context
We often create the source with default priority, no destroy function and
attach it to the default context (g_main_context_default()). For that
case, we have wrapper functions like nm_g_timeout_add_source()
and nm_g_idle_add_source(). Use those.

There should be no change in behavior.
2022-03-13 11:59:42 +01:00
Thomas Haller
9b030a3988
all: change scheduling priority for idle actions to G_PRIORITY_DEFAULT_IDLE
g_idle_add() uses G_PRIORITY_DEFAULT_IDLE priority. Most of the time we don't
care much about the priority.

But at the places that this patch changes, I think that using
G_PRIORITY_DEFAULT_IDLE (and following g_idle_add()) is more correct. The
reason for this is not very strong, except that it's probably the better
choice. And the old choice was made because I didn't realize that
g_idle_add() uses another default priority. Hence, the old choice was not
for good reasons either.
2022-03-13 11:59:42 +01:00
Fernando Fernandez Mancera
482d99f549 bond: do not reapply when setting fail_over_mac
When a bond has ports attached kernel disallows writing
`/sys/devices/virtual/net/bond0/bonding/fail_over_mac`. NetworkManager
should fail when trying to do reapply if `fail_over_mac` needs to be
set.

https://bugzilla.redhat.com/2003214
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1143
2022-03-11 20:49:10 +01:00
Thomas Haller
9c8a937280
core/trivial: add code comment to nm_utils_stable_id_parse() 2022-03-11 10:21:44 +01:00
Thomas Haller
8fc40206ec
core: use NM_STR_HAS_PREFIX() in nm_utils_stable_id_parse()
NM_STR_HAS_PREFIX() expands to one `strncpy()`, with the length being a
compile time constant. It's faster than calling through glib.
2022-03-11 10:09:16 +01:00
Thomas Haller
69376e20a5
core: rename nm_utils_host_id_get_timestamp_ns() to "nsec"
We change more and more to prefer "nsec" (and "usec", "msec", and "sec")
as abbreviations, instead of "ns" (and "us", "ms", "s"). Rename.
2022-03-11 09:43:02 +01:00
Thomas Haller
513c0b3f24
core/trivial: reword code comment about fake host-id timestamp 2022-03-11 09:43:02 +01:00
Thomas Haller
63664719be
core/dhcp: use gs_free_error in NMDhcpDhcpcd's ip4_start()
It just seems less error prone. Use the cleanup attribute.
2022-03-09 23:14:39 +01:00
Thomas Haller
fd50323232
core/dhcp: fix uninitialized GError in NMDhcpDhcpcd's ip4_start()
Found with `git grep 'GError.*[^,)];'| grep ' *= *NULL;' -v`

Fixes: a2abd15fe0 ('DHCP: Support dhcpcd-9.x')
2022-03-09 23:14:38 +01:00
Thomas Haller
43748d2980
core/team: fix leak and uninitialized GError in NMDeviceTeam's constructed()
Found with `git grep 'GError.*[^,)];'| grep ' *= *NULL;' -v`

Fixes: d689380cfc ('team: support operation without D-Bus')
2022-03-09 23:14:37 +01:00
Beniamino Galvani
143f7b1df7 core: preserve the domain when system hostname is truncated
Pass the full hostname to the DNS manager, so that the domain gets
added to resolv.conf even when the hostname was truncated.

Note that "hostname" argument for plugins's update() function is
currently unused. Don't remove that because it can be potentially
useful to set a global search domain based on the hostname, but change
it to carry the domain directly.
2022-03-09 08:34:26 +01:00
Beniamino Galvani
59f57e8a0b core: shorten hostname when too long
If the hostname received via DHCP is too long, shorten it.
2022-03-09 08:34:26 +01:00
Beniamino Galvani
9498702242 core: add nm_utils_shorten_hostname()
Add a function to shorten a overlong hostname, truncating it to the
first dot or 64 characters.
2022-03-09 08:34:26 +01:00
Beniamino Galvani
c41ad0ebe3 dns: drop nm_dns_manager_set_initial_hostname()
It can be replaced by nm_dns_manager_set_hostname() with
skip_update=TRUE.
2022-03-09 08:34:26 +01:00
Thomas Haller
5402a72179
dhcp6: fix setting ifindex in nm_dhcp_utils_merge_new_dhcp6_lease()
nm_l3_config_data_new_clone() takes non-positive ifindex to use
the ifindex of the l3cd. But it also asserts that the ifindex
is not negative. Fix that assertion failure, by setting the ifindex
to zero.

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

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-03-07 09:11:07 +01:00
Beniamino Galvani
392daa5dab core: fall back to loading all known settings plugins
Currently it is possible to specify a list of default settings plugins
to be used when configuration doesn't contain the main.plugins key.

We want to add a mechanism that allows to automatically load any
plugin found in the plugins directory without needing
configuration. This mechanism is useful when plugins are shipped in a
different, optional subpackage, to automatically use them.

With such mechanism, the actual list of plugins will be determined
(in order of evaluation):

 1. via explicit user configuration in /etc, if any
 2. via distro configuration in /usr, if any
 3. using the build-time default, if any
 4. looking for known plugins in /usr/lib
2022-03-06 09:12:06 +01:00
Lubomir Rintel
65fdfb2500 ovs-port: fix removal of ovsdb entry if the interface goes away
Hope third time is the charm.

The idea here is to remove the OVSDB entry if the device actually went away
violently (like, the it was actually removed from the platform), but keep it if
we're shutting down.

Fixes-test: @ovs_nmstate
Fixes: 966413e78f ('ovs-port: avoid removing the OVSDB entry if we're shutting down')
Fixes: ecc73eb239 ('ovs-port: always remove the OVSDB entry on slave release')

https://bugzilla.redhat.com/show_bug.cgi?id=2055665
2022-03-04 10:31:07 +01:00
Thomas Haller
98b3056604
core: preserve external ports during checkpoint rollback
When we have a bridge interface with ports attached externally (that is,
not by NetworkManager itself), then it can make sense that during
checkpoint rollback we want to keep those ports attached.

During rollback, we may need to deactivate the bridge device and
re-activate it. Implement this, by setting a flag before deactivating,
which prevents external ports to be detached. The flag gets cleared,
when the device state changes to activated (the following activation)
or unmanaged.

This is an ugly solution, for several reasons.

For one, NMDevice tracks its ports in the "slaves" list. But what
it does is ugly. There is no clear concept to understand what it
actually tacks. For example, it tracks externally added interfaces
(nm_device_sys_iface_state_is_external()) that are attached while
not being connected. But it also tracks interfaces that we want to attach
during activation (but which are not yet actually enslaved). It also tracks
slaves that have no actual netdev device (OVS). So it's not clear what this
list contains and what it should contain at any point in time. When we skip
the change of the slaves states during nm_device_master_release_slaves_all(),
it's not really clear what the effects are. It's ugly, but probably correct
enough. What would be better, if we had a clear purpose of what the
lists (or several lists) mean. E.g. a list of all ports that are
currently, physically attached vs. a list of ports we want to attach vs.
a list of OVS slaves that have no actual netdev device.

Another problem is that we attach state on the device
("activation_state_preserve_external_ports"), which should linger there
during the deactivation and reactivation. How can we be sure that we don't
leave that flag dangling there, and that the desired following activation
is the one we cared about? If the follow-up activation fails short (e.g. an
unmanaged command comes first), will we properly disconnect the slaves?
Should we even? In practice, it might be correct enough.

Also, we only implement this for bridges. I think this is where it makes
the most sense. And after all, it's an odd thing to preserve unknown,
external things during a rollback -- unknown, because we have no knowledge
about why these ports are attached and what to do with them.

Also, the change doesn't remember the ports that were attached when the
checkpoint was created. Instead, we preserve all ports that are attached
during rollback. That seems more useful and easier to implement. So we
don't actually rollback to the configuration when the checkpoint was
created. Instead, we rollback, but keep external devices.

Also, we do this now by default and introduce a flag to get the previous
behavior.

https://bugzilla.redhat.com/show_bug.cgi?id=2035519
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/ # 909
2022-03-03 11:25:14 +01:00
Thomas Haller
df6ee44fb2
core: reject unsupported flags for CheckpointCreate D-Bus request 2022-03-03 10:47:44 +01:00
Thomas Haller
9e422f01de
core/trivial: add comment about "startup complate" log message 2022-03-02 11:35:59 +01:00
Emmanuel Grumbach
237c028e53
rfkill: fix the rfkill reason property query and parsing
The udev property is RFKILL_HW_BLOCK_REASON and it is returned as a
bitmap in hexadecimal.

Fixes: 9c4fbbe1b8 ('rfkill: query the hardware rfkill reason from udev')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1128
2022-03-02 09:13:57 +01:00
Thomas Haller
b8f689ac53
all: add support for route type "throw"
After adding support for "blackhole", "unreachable" and "prohibit" route
types, let's also add support for "throw" type. It works basically the
same as the other types, so supporting it seems very straight forward.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1124
2022-02-28 17:17:03 +01:00
Beniamino Galvani
b2e559fab2 core: initialize l3cd dns-priority for ppp and wwan
For devices that configure IP by themselves (by returning
"->ready_for_ip_config() = TRUE" and implementing
->act_stage3_ip_config()), we skip manual configuration. Currently,
manual configuration is the only one that sets flag HAS_DNS_PRIORITY
into the resulting l3cd.

So, the merged l3cd for such devices misses a dns-priority and is
ignored by the DNS manager.

Explicitly initialize the priority to 0; in this way, the default
value for the device will be set in the final l3cd during the merge.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/931
2022-02-28 10:08:24 +01:00
Emmanuel Grumbach
72102011e9 core: teach nm-manager about os_owner
Reflect what the rfkill-manager saw in the nm-manager.
This will allow to take decision based on the os_owner state.
2022-02-24 23:12:39 +02:00
Emmanuel Grumbach
9c4fbbe1b8 rfkill: query the hardware rfkill reason from udev
The kernel may add a reason for hardware rfkill. Make the NetworkManager
able eto fetch it and parse it.
For now, no action will be taken upon the new reasons.

The different reasons that the kernel can expose are either the radio
was switched off by a hardware rfkill switch. This reason is adveritsed
by bit 0 in the bitmap returned by RFKILL_STATE_REASON udev property.
This is the rfkill that existed until now.

The new reason is mapped to bit 1 and teaches the user space that the
wifi device is currently used by the CSME firmware on the platform. In
that case, the NetworkManager can ask CSME (through the iwlmei kernel
module) what BSSID the CSME firmware is associated to. Once the
NetworkManager gets to the conclusion is has the credentials to connect
to that very same AP, it can request the wifi device and the CSME
firmware will allow the host to take the ownership on the device. CSME
will give 3 seconds to the host to get an IP or it'll take the device
back. In order to complete all the process until we get the DHCP ACK
within 3 seconds, the NetworkManager will need to optimize the scan and
limit the scan to that specific BSSID on that specific channel.

All this flow is not implemented yet, but the first step is to identify
that the device is not owned by the host.
2022-02-24 23:04:48 +02:00
Thomas Haller
7c874ed456
core: use NM_SHUTDOWN_TIMEOUT_5000_MSEC define in _ppp_manager_stop()
The define makes it clearer that there is an important relationship
between the timeout for the async operation, and the wrapup time when
NetworkManager is quitting. Well, not for the time being. But in the future,
when we rework the quitting of NetworkManager.
2022-02-24 09:38:54 +01:00
Thomas Haller
2ebf9a0e89
core: increase NM_SHUTDOWN_TIMEOUT_MAX_MSEC to 5 sec to cover pppd
NM_SHUTDOWN_TIMEOUT_MAX_MSEC is the maximum timeout for how long any
async operation may take. The idea is that during shutdown of NetworkManager
we give that much time to tear down. Then async operations may either implement
cancellation or not bother with that. But in any case, they must complete within
NM_SHUTDOWN_TIMEOUT_MAX_MSEC.

Actually, for the time being, this has no effect at all. I am talking about the
future here. See "Improve Shutdown of NetworkManager" in TODO. This patch
is preparation for that effort.

Anyway. Stopping pppd can take a longer time (5 seconds). That is
currently the (known) longest time how long any of our async operations
is allowed to take.

As all async operations must complete before NM_SHUTDOWN_TIMEOUT_MAX_MSEC,
and we want to wait at least 5 seconds for pppd, we need to increase the
wait time NM_SHUTDOWN_TIMEOUT_MAX_MSEC.

Also add and use NM_SHUTDOWN_TIMEOUT_5000_MSEC, which serves a similar
purpose as NM_SHUTDOWN_TIMEOUT_1500_MSEC.
2022-02-24 09:38:53 +01:00
Thomas Haller
ed9e3bac03
core: use NM_SHUTDOWN_TIMEOUT_1500_MSEC
At some places we scheduled a timeout in NM_SHUTDOWN_TIMEOUT_MAX_MSEC.
There, we want to make sure that we don't take longer than
NM_SHUTDOWN_TIMEOUT_MAX_MSEC. But this leaves the actual wait time
unspecified.

Those callers don't want to wait an undefined time. They really should
be clear about how long they wait. Hence, use NM_SHUTDOWN_TIMEOUT_1500_MSEC
which makes it clear this is 1500 msec but also chosen to be not longer than
NM_SHUTDOWN_TIMEOUT_MAX_MSEC.
2022-02-24 09:38:53 +01:00
Thomas Haller
8bb85aecda
core: add NM_SHUTDOWN_TIMEOUT_1500_MSEC macro
When you have an async operation, you must make sure that
it is cancellable or completes in at most NM_SHUTDOWN_TIMEOUT_MAX_MSEC.

But NM_SHUTDOWN_TIMEOUT_MAX_MSEC leaves it undefined how long it is.
If you really want to wait for 1500msec, but also need to ensure
to stay within NM_SHUTDOWN_TIMEOUT_MAX_MSEC, then use
NM_SHUTDOWN_TIMEOUT_1500_MSEC. This has the semantic of guaranteeing
both.
2022-02-24 09:38:53 +01:00
Thomas Haller
32a828080c
core/trivial: rename NM_SHUTDOWN_TIMEOUT_MS to NM_SHUTDOWN_TIMEOUT_MAX_MSEC
The abbreviations "ms", "us", "ns" don't look good.
Spell out to "msec", "usec", "nsec" as done at other places.

Also, rename NM_SHUTDOWN_TIMEOUT_MS_WATCHDOG to
NM_SHUTDOWN_TIMEOUT_ADDITIONAL_MSEC.

Also, rename NM_SHUTDOWN_TIMEOUT_MS to NM_SHUTDOWN_TIMEOUT_MAX_MSEC.
There are different timeouts, and this is the maximum gracetime we
will give during shutdown to complete async operations.

Naming is hard, but I think these are better names.
2022-02-24 09:38:52 +01:00
Thomas Haller
7a1734926a
connectivity,cloud-setup: restrict curl protocols to HTTP and HTTPS
See-also: https://fedoraproject.org/wiki/Changes/CurlMinimal_as_Default#Benefit_to_Fedora
See-also: 55b90ee00b

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1121
2022-02-24 09:37:58 +01:00