Commit graph

1161 commits

Author SHA1 Message Date
Thomas Haller
dc26e65928
tests: add tests for generating stable UUIDs for keyfile/initrd
Fixes: 7ee0da3eaf ('build: don't "update-po" during make dist')
2022-11-03 09:23:57 +01:00
Thomas Haller
4fa20ce710
platform/tests: don't use translations in test tool
Otherwise, this file would need to be included in POTFILES.in.
This is unnecessary.

Fixes: 06cf1f5e2d ('platform/tests: extend monitor tool to dump the state of NMPlatform')
2022-10-27 15:18:54 +02:00
Thomas Haller
3a8decd9cf
hostname: rename nm_hostname_manager_write_hostname() to set_static_hostname() 2022-10-27 15:18:54 +02:00
Thomas Haller
d5be1c706e
dns/resolved: set DoT server name (SNI) in systemd-resolved
Unfortunately, for this we require SetLinkDNSEx() API from v246.
That adds extra complexity.

If the configuration contains no server name, we continue using
SetLinkDNS(). Otherwise, at first we try using SetLinkDNSEx().
We will notice if that method is unsupported, reconfigure with
SetLinkDNS(), and set a flag to not try that again.
2022-10-27 09:11:38 +02:00
Thomas Haller
ba33942734
dns/resolved: cleanup detection of supported API in "nm-dns-systemd-resolved.c"
- rename the "has_" variables to have the same name as the API that they
  check.
- do an if-else-if for checking the operation when detecting support.

This just feels nicer. No strong reasons.
2022-10-27 09:11:35 +02:00
Thomas Haller
c68e148b02
core: extend NML3ConfigData:nameserver to track DNS as string
The DNS name can now also contain the DoT server name. It's not longer a
binary IP address only.

Extend NML3ConfigData to account for that. To track the additional
data, use the string representation. The alternative to have a separate
type that contains the parsed information would be cumbersome too.
2022-10-27 09:11:33 +02:00
Thomas Haller
6f9090538f
dns: accept DoT SNI server name in "ipv[46].dns" settings 2022-10-27 09:11:31 +02:00
Thomas Haller
d8ea008372
wifi/iwd: merge ip[46]_config_to_iwd_config()
It is almost always wrong, to split IPv4 and IPv6 behaviors at a high level.
Most of the code does something very similar. Combine the two functions.
and let them handle the difference closer to where it is.
2022-10-27 09:11:27 +02:00
Thomas Haller
8e3202e499
policy: refactor all_devices_not_active() to any_devices_active()
The double negation is hard to understand.
2022-10-26 13:50:50 +02:00
Beniamino Galvani
8e85c86add dhcp: improve detection of DADFAILED addresses
Instead of assuming any address that disappeared was because of a DAD
failure, check explicitly that either:

 - the address is still present with DADFAILED flag (in case it was a
   permanent address), or

 - the address was removed and platform recorded that it had the
   DADFAILED flag.
2022-10-26 10:08:53 +02:00
Beniamino Galvani
922ef4344e ndisc: log DAD failures at info level
A DAD failure is in most cases a symptom of a network
misconfiguration; as such it must be logged in the default
configuration (info level).

While at it, fix other log messages.
2022-10-26 10:08:53 +02:00
Beniamino Galvani
addb4e3a0c device: generate a new AC6 address when DAD fails
For addresses that fail DAD we need to call nm_ndisc_dad_failed() to
generate a new address if addrgenmode is stable-privacy.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1046
2022-10-26 10:08:53 +02:00
Beniamino Galvani
15d55e5a68 device: use nm_l3cfg_check_ready() in _dev_ipac6_ndisc_config_changed()
Instead of open coding the check for ready addresses, use
nm_l3cfg_check_ready().
2022-10-26 10:05:16 +02:00
Beniamino Galvani
5da8e0666b ndisc: accept multiple addresses in nm_ndisc_dad_failed()
Since we evaluate platform changes in a idle handler, there can be
multiple DAD failure at the same time that must generate a single
ndisc.configuration-change signal.

The function is unused at the moment.
2022-10-26 08:54:29 +02:00
Beniamino Galvani
afa208c862 core: return conflicting addresses from nm_l3cfg_check_ready()
It can be useful to know which addresses are conflicting, return them
from nm_l3cfg_check_ready().
2022-10-26 08:54:29 +02:00
Beniamino Galvani
19c0018f58 l3cfg: don't accept AF_UNSPEC in nm_l3cfg_check_ready()
All the callers pass either AF_INET or AF_INET6, drop support for
AF_UNSPEC; this simplifies the function for the next commit that adds
a @conflicts argument.
2022-10-26 08:54:29 +02:00
Thomas Haller
ff9f413fcc
platform/tests: use nmtst_inet6_from_string() instead of *nmtst_inet6_from_string_p() 2022-10-26 08:24:29 +02:00
Thomas Haller
2786a30a7c
platform/tests: rename nmtst_inet6_from_string() to nmtst_inet6_from_string_p()
This helper returns a pointer (to a thread local variable).
2022-10-26 08:24:28 +02:00
Thomas Haller
06cf1f5e2d
platform/tests: extend monitor tool to dump the state of NMPlatform
This is useful for manual testing ("manual", in the sense that you can
write a script that tests the behavior of the platform cache, without
humanly reading the logfile).

Usage:

To write the content of the platform cache once:

  ./src/core/platform/tests/monitor -P -S './statefile'

To keep monitor running, and update the state file:

  ./src/core/platform/tests/monitor -S './statefile'
2022-10-26 08:24:28 +02:00
Thomas Haller
3654fc8145
platform/tests: make "external_command" int type
The variable is passed to nmtstp_run_command_check_external(), which accepts
-1 to mean choose randomly. Change the function signature to reflect that.
2022-10-26 08:24:28 +02:00
Andrew Zaborowski
2ee0536f2a
iwd: Register the Netconfig agent
Handle IP Configuration requests from IWD so that, when IWD's main.conf
setting [General].NetworkConfigurationEnabled is true, we don't try to
run DHCP or static addressing in parallel with IWD's internal DHCP or
static addressing.

Since part of the IWD secret agent and the new NetConfig agent
registration code is common, the agent object's path is changed.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1337
2022-10-25 16:35:48 +02:00
Thomas Haller
d98553e9e7
main: use helper function to write pid file in nm_main_utils_write_pidfile()
On the surface, writing a file seams simple enough. But there are many
pitfalls:

- we should retry on EINTR.

- we should check for incomplete writes and loop.

- we possibly should check errors from close.

- we possibly should write to a temporary file and do atomic rename.

Use nm_utils_file_set_contents() to get this right.
2022-10-25 13:12:49 +02:00
Thomas Haller
ad7d5887cd
all: cleanup close() handling and clarify nm_close()/nm_close_with_error()
Cleanup the handling of close().

First of all, closing an invalid (non-negative) file descriptor (EBADF) is
always a serious bug. We want to catch that. Hence, we should use nm_close()
(or nm_close_with_error()) which asserts against such bugs. Don't ever use
close() directly, to get that additional assertion.

Also, our nm_close() handles EINTR internally and correctly. Recent
POSIX defines that on EINTR the close should be retried. On Linux,
that is never correct. After close() returns, the file descriptor is
always closed (or invalid). nm_close() gets this right, and pretends
that EINTR is a success (without retrying).

The majority of our file descriptors are sockets, etc. That means,
often an error from close isn't something that we want to handle. Adjust
nm_close() to return no error and preserve the caller's errno. That is
the appropriate reaction to error (ignoring it) in most of our cases.

And error from close may mean that there was an IO error (except EINTR
and EBADF). In a few cases, we may want to handle that. For those
cases we have nm_close_with_error().

TL;DR: use almost always nm_close(). Unless you want to handle the error
code, then use nm_close_with_error(). Never use close() directly.

There is much reading on the internet about handling errors of close and
in particular EINTR. See the following links:

https://lwn.net/Articles/576478/
https://askcodes.net/coding/what-to-do-if-a-posix-close-call-fails-
https://www.austingroupbugs.net/view.php?id=529
https://sourceware.org/bugzilla/show_bug.cgi?id=14627
https://news.ycombinator.com/item?id=3363819
https://peps.python.org/pep-0475/
2022-10-25 13:12:48 +02:00
Thomas Haller
f0fff996e2
vpn: drop redundant check in device_changed()
lgtm.com correclty warns that ifindex is always positive at this point.
Drop unnecessary code.
2022-10-25 12:06:12 +02:00
Thomas Haller
debc66e823
lldp: use nm_lldp_neighbor_id_hash() in "nm-lldp-listener.c" 2022-10-25 10:59:02 +02:00
Thomas Haller
c416c066cf
lldp/systemd: remove systemd LLDP sources
They are no longer used. We use now libnm-llpd instead.
2022-10-25 10:59:01 +02:00
Thomas Haller
04e72b6b4d
lldp: use new libnm-lldp instead of systemd's sd_lldp_rx 2022-10-25 10:59:01 +02:00
Thomas Haller
9f534341e0
core: fix code comment in _host_id_hash_v2()
The previous snippet was wrong, there was an additional newline after
`stat`. Fix that and reformat the comment.
2022-10-25 10:35:07 +02:00
Thomas Haller
16c0be1ada
style: various minor adjustments 2022-10-25 08:41:45 +02:00
Alexander Elbs
61a302ff6b
core: use new rerequest infrastructure
instead of always re-requesting secrets on authentication failure ask NMSetting
if this is really needed. Currently only for the case "802.1x with TLS" this
behaves differently, i.e. no re-request.
2022-10-25 08:40:09 +02:00
Thomas Haller
77ea230817
glib-aux,core: use nm_memdup_nul() and nm_memcpy() 2022-10-24 08:48:11 +02:00
Beniamino Galvani
50b6f3d6d3 core: fix setting IPv6 retrans timer
Fixes: 5c48c5d5d6 ('l3cfg: set IPv6 sysctls during NML3Cfg commit')
2022-10-21 14:56:23 +02:00
Michael Catanzaro
e6dac4f0b6
core: don't restrict DNS interface when performing connectivity check
Currently, when performing DNS resolution with systemd-resolved,
NetworkManager tells systemd-resolved to consider only DNS configuration
for the network interface that the connectivity check request will be
routed through. But this is not correct because DNS and routing are
configured entirely separately. For example, say we have a VPN that
receives all DNS but only a subset of routing. NetworkManager will
configure systemd-resolved with no DNS servers on any interface except
for the VPN interface, but will still route traffic through other
interfaces. This is entirely legitimate and works fine in practice,
except for the connectivity check.

To fix this, we just drop the restriction and allow systemd-resolved to
consider its full configuration, which is what gets used normally
anyway. This allows our connectivity check to match the real
configuration instead of failing spuriously.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1415
2022-10-19 21:00:47 +02:00
Lubomir Rintel
a7ff6b647c style: fix code formatting
Fixes: 7bf46ced2e ('core/device: demote "strictly unamanged" error')
2022-10-17 17:40:40 +02:00
Lubomir Rintel
7bf46ced2e core/device: demote "strictly unamanged" error
The "device ... not available because device is strictly unmanaged" is
almost certainly the least interesting of the reasons why connection
can't be activated on a device.

Invent a new error level for it and demote it.

Before:

  Error: Connection activation failed: No suitable device found
         for this connection (device lo not available because
         device is strictly unmanaged).

After

  Error: Connection activation failed: No suitable device found
         for this connection (device eth0 not available because
         profile is not compatible with device (...)).

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1433
2022-10-17 11:43:58 +02:00
Lubomir Rintel
59b2ef50e4 core/device: make sriov setting require sriov cap
Make connections that have "sriov" setting incompatible with devices
that lack NM_DEVICE_CAP_SRIOV capability.

Otherwise applying the SR-IOV properties either fails too late, or is
ignored silently.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1432
2022-10-17 11:43:20 +02:00
Ana Cabral
0a280c5a93 device: remove the possibility of inheriting the unmanaged condition from the parent of a device
This commit is part of a broader change that eliminates inheriting
the unmanaged condition from the parent of a device, for all device
types:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418

What motivates this change are the unncessary issues brought by this
inheritance. You can see some problems described here:
https://bugzilla.redhat.com/show_bug.cgi?id=2110307#c0.
2022-10-15 18:29:10 +02:00
Ana Cabral
412c7449b3 device: remove the unmanaged inheritance from the parent for macvlan devices
This commit is part of a broader change that eliminates inheriting
the unmanaged condition from the parent of a device, for all device
types:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418

What motivates this change are the unncessary issues brought by this
inheritance. You can see some problems described here:
https://bugzilla.redhat.com/show_bug.cgi?id=2110307#c0.
2022-10-15 18:29:10 +02:00
Ana Cabral
66857bafe8 device: remove the unmanaged inheritance from the parent for macsec devices
This commit is part of a broader change that eliminates inheriting
the unmanaged condition from the parent of a device, for all device
types:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418

What motivates this change are the unncessary issues brought by this
inheritance. You can see some problems described here:
https://bugzilla.redhat.com/show_bug.cgi?id=2110307#c0.
2022-10-15 18:29:10 +02:00
Ana Cabral
f1a79e97ea device: remove the unmanaged inheritance from the parent for 6lowpan devices
This commit is part of a broader change that eliminates inheriting
the unmanaged condition from the parent of a device, for all device
types:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418

What motivates this change are the unncessary issues brought by this
inheritance. You can see some problems described here:
https://bugzilla.redhat.com/show_bug.cgi?id=2110307#c0.
2022-10-15 18:29:10 +02:00
Ana Cabral
e2dd68b610 device: allow configuration of VLAN on an unmanaged interface
It is not possible to configure a VLAN interface on unmanaged NIC.
This forces users who only want to create a VLAN interface to take
ownership over possibly shared underlying NIC.

In OpenShift, the SR-IOV operator is currently not using
NetworkManager to configure VFs. When it starts working with a NIC,
it explicitly makes it unmanaged. Then, users cannot create a VLAN
interface on PFs managed by the operator.

This commit eliminates this issue by allowing configuring VLAN on
an interface without requesting it to be managed by NetworkManager.

This commit is part of a broader change that eliminates inheriting
the unmanaged condition from the parent of a device, for all device
types:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418

https://bugzilla.redhat.com/show_bug.cgi?id=2110307
2022-10-15 18:29:10 +02:00
Lubomir Rintel
020c8ff2e2 team: log port config when it's set
Log the port config at trace level. Helps making debugging less
miserable.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1423
2022-10-14 22:43:08 +02:00
Lubomir Rintel
a721413d20 team: don't log failures to connect to teamd on error level
ensure_teamd_connection() is called from multiple spots. Sometimes
we call opportunistically without having started teamd (e.g. when on
update_connection() when generating a connection for teaming device that
was created) and handle the failure to connect gracefully.

Let's not pollute the logs with things on ERROR level that are not
actually serious. Replace the logging statements with DEBUG or WARN
depending on whether we expect ensure_teamd_connection() to actually
succeed.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1422
2022-10-14 22:40:56 +02:00
Lubomir Rintel
6897f6e6df team: set port configuration even if it's empty
Call teamdctl_port_config_update_raw() when we're attaching a port even
if all of team-slave setting properties are default.

This is done to ensure teamd "knows" about the port (that is,
"teamdctl ...  port present" returns success) when we're done activating
the slave connection. It will pick it up anyway from netlink, but that
can happen after the activation is done, resulting in a possible race.

Fixes-test: @remove_active_team_profile

https://bugzilla.redhat.com/show_bug.cgi?id=2102375
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1421
2022-10-14 22:25:07 +02:00
Beniamino Galvani
3cc7801779 dns: sort the ip-data list when a new element is added
In nm_dns_manager_set_ip_config() we try to avoid calling update_dns()
unless something changes, because updating DNS is expensive and can
trigger other actions such as a new hostname resolution.

When we add a new ip_data, even if the new element is equivalent to
the old one that was removed, we need to sort the list again.

Fixes: ce0a36d20f ('dns: better track l3cd changes')
https://bugzilla.redhat.com/show_bug.cgi?id=2098574
2022-10-13 17:25:21 +02:00
Beniamino Galvani
4d1ecd8d6d dns: add comment explaining the purpose of any_removed 2022-10-13 17:24:58 +02:00
Thomas Haller
977787171e
trivial: fix indentation 2022-10-11 18:27:32 +02:00
Thomas Haller
b28c6ca30e
all: avoid "-Wunreachable-code-generic-assoc" warning with _Generic()
Clang 15 ([1], [2]) added

  Added the -Wunreachable-code-generic-assoc diagnostic flag (grouped
  under the -Wunreachable-code flag) which is enabled by default and warns
  the user about _Generic selection associations which are unreachable
  because the type specified is an array type or a qualified type.

This causes compiler warnings with various uses of _Generic():

  ../src/libnm-glib-aux/nm-shared-utils.h:2489:12: error: due to lvalue conversion of the controlling expression, association of type 'const char *const *const' will never be selected becaus
  e it is qualified [-Werror,-Wunreachable-code-generic-assoc]
      return nm_strv_find_first((const char *const *) strv->pdata, strv->len, str);
             ^
  ../src/libnm-glib-aux/nm-shared-utils.h:475:25: note: expanded from macro 'nm_strv_find_first'
      _nm_strv_find_first(NM_CAST_STRV_CC(list), (len), (needle))
                          ^
  ../src/libnm-glib-aux/nm-macros-internal.h:397:22: note: expanded from macro 'NM_CAST_STRV_CC'
                 const char *const*const: (const char *const*) (value), \
                       ^

Clang is correct.

[1] https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.html#improvements-to-clang-s-diagnostics
[2] https://reviews.llvm.org/D125259
2022-10-11 17:21:11 +02:00
Thomas Haller
8aa8d483f2
all: fix deprecated function declaration without a prototype
Clang 15 now (correctly) warns about this:

  ../src/libnm-core-impl/nm-vpn-plugin-info.c:201:40: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
  _nm_vpn_plugin_info_get_default_dir_etc()
                                         ^
                                          void
  ../src/libnm-core-impl/nm-vpn-plugin-info.c:213:40: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
  _nm_vpn_plugin_info_get_default_dir_lib()
                                         ^
                                          void
  ../src/libnm-core-impl/nm-vpn-plugin-info.c:226:41: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
  _nm_vpn_plugin_info_get_default_dir_user()
                                          ^
                                           void
  ../src/libnm-core-impl/nm-vpn-plugin-info.c:315:29: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
  nm_vpn_plugin_info_list_load()
                              ^
                               void
2022-10-11 17:21:11 +02:00
Thomas Haller
b5e7e48bc1
glib-aux: add and use nm_uuid_generate_from_strings_old()
For a long time we have a function like nm_uuid_generate_from_strings().
This was recently reworked and renamed, but it preserved behavior. Preserving
behavior is important for this function, because for the existing users,
we need to keep generating the same UUIDs.

Originally, this function was a variadic function with NULL sentinel.
That means, when you write

  nm_uuid_generate_from_strings(uuid_type, type_arg, v1, v2, v3, NULL);

and v2 happens to be NULL, then v3 is ignored. That is most likely not
what the user intended. Maybe they had a bug and v2 should not be NULL.
But nm_uuid_generate_from_strings() should not require that all
arguments are non-NULL and it should not ignore arguments after the
first NULL.

For example, one user works around this via

    uuid = nm_uuid_generate_from_strings_old("ibft",
                                             s_hwaddr,
                                             s_vlanid ? "V" : "v",
                                             s_vlanid ? s_vlanid : "",
                                             s_ipaddr ? "A" : "DHCP",
                                             s_ipaddr ? s_ipaddr : "");

which is cumbersome and ugly.

That will be fixed next, by adding a function that doesn't suffer
from this problem. But "this problem" is part of the API of the
function, we cannot just change it. Instead, rename it and all
users, so they can keep doing the same.

New users of course should no longer use the "old" function.
2022-10-11 09:03:17 +02:00