Commit graph

31277 commits

Author SHA1 Message Date
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
37ab511ed4
glib-aux: add nm_dbus_connection_call_get() helper 2022-10-27 13:46:17 +02:00
Thomas Haller
1b60c1ecba
dns: merge branch 'th/dot-sni'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/528

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1434
2022-10-27 09:17:03 +02:00
Thomas Haller
3970489219
NEWS: update 2022-10-27 09:15:26 +02:00
Thomas Haller
bdb124852f
libnm: unify IPv4/IPv6 forms of DNS to GVariant helper 2022-10-27 09:11:40 +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
a20aae326f
nmcli: drop validation of DNS name in nmcli
Now, nm_setting_ip_config_add_dns() no longer asserts that
the name is a valid DNS nameserver. Instead, that is handled
by nm_connection_verify().

Also, the DNS property is going to be extended to support
specifying the SNI server name for DNS over TLS. The validation
would need to be extended.

Instead, drop the validation from nmcli. nmcli often needs to understand
what is happening. But in this case, it doesn't need to know (or
validate) the exact text. Don't duplicate the validation and let
libnm (or the daemon) reject invalid settings.
2022-10-27 09:11:29 +02:00
Thomas Haller
053d0a0768
libnm: fix inconsistencies and assertions of "ipv[46].dns" handing
- nm_setting_ip_config_add_dns() and nm_setting_ip_config_remove_dns_by_value()
  used to assert that the provided input is valid. That is not
  documented and highly problematic.
  Our parsing code for keyfile, ifcfg-rh and GVariant rightly just call
  add. Likewise, nmcli. We cannot reasonably expect them to pre-validate
  the input. Why would we anyway?
  This is wrong in particular because we usually want the user to be
  able to construct invalid settings. That is often necessary, because
  whether a value is valid depends on other values. So in general, we
  can only validate when all properties are set. We have
  nm_connection_verify() for that, and asserting/validating during add
  is very wrong. Note that "add" still filters out duplicates, which
  may be an inconsistency, but well.
  Also, the user could set any bogus value via the NM_SETTING_IP_CONFIG_DNS
  property. Those should be allowed to be removed, and the same values
  should be allowed to be added via the add method.

- add() does a normalization, presumably so that the values look nice.
  Do the same normalization also when using the NM_SETTING_IP_CONFIG_DNS
  property setter.

- previously, the setter could also set unnormalized values. As
  nm_setting_ip_config_remove_dns_by_value() looked for the normalized
  value, you couldn't remove such values anymore. That is fixed now,
  by letting the property setter do the same normalization.

- don't allocate a GPtrArray unless we need it. No need for the extra
  allocation.

- in the property setter, first set the new value before destroying the
  previous GPtrArray. It might not be possible, but it's not clear to me
  whether the strv argument from the GValue is always deep-copied or
  whether it could contain strings to the DNS property itself.
2022-10-27 09:11:28 +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
63eaf168d1
libnm: add "dns-data" replacement for "ipv[46].dns" properties on D-Bus
On D-Bus, the properties "ipv[46].dns" are of type "au" and "aay",
respectively.

Btw, in particular "au" is bad, because we put there a big-endian
number. There is no D-Bus type to represent big endian numbers, so "u"
is bad because it can cause endianess problem when trying to remote
the D-Bus communication to another host (without explicitly
understanding which "u" properties need to swap for endinness).

Anyway. The plain addresses are not enough. We soon will also support
the DNS-over-TLS server name, or maybe a DoT port number. The previous
property was not extensible, so deprecate it and replace it by
"dns-data".

This one is just a list of strings. That is unlike "address-data" or
"route-data", which do a similar thing but are "a{sv}" dictionaries.
Here a string is supposed to be sufficient also for the future. Also,
because in nmcli and keyfile will will simply have a string format for
representing the extra data, not a structure (unlike for routes or
addresses).
2022-10-27 09:11:26 +02:00
Thomas Haller
3297b079b2
libnm: rework _nm_setting_use_legacy_property() to minimize dictionary lookups
The previous could would first check whether the new property is not
set. In almost all cases, the new property is actually set.

We can get away with fewer lookups, by checking for the expected things
first.
2022-10-27 09:11:25 +02:00
Thomas Haller
c8392018ca
libnm: refactor to-dbus on the client skipping to serialize legacy properties
We have 4 legacy properties ("ipv[46].addresses", "ipv[46].routes") that
got replaced by newer variants ("ipv[46].address-data", "ipv[46].route-data").

When the client side of libnm (_nm_utils_is_manager_process) serializes
those properties, it must only serialize the newer version. That is so
that the forward/backward compatibility works as intended.

Previously, there was the NM_SETTING_PARAM_LEGACY GObject property flag.
That was fine, but not very clear.

For one, the legacy part of those properties is only about D-Bus. In
particular, they are not deprecated in libnm, keyfile, or nmcli. Thus
the name wasn't very clear.

Also, in the meantime we have more elaborate property meta data, that
goes beyond the meta data of the GObject property.

Move NM_SETTING_PARAM_LEGACY to NMSettInfoProperty.to_dbus_only_in_manager_process.
I think, this is a better name. It's also right at

```
     _nm_properties_override_gobj(
         properties_override,
         g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ROUTES),
         NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("a(ayuayu)"),
                                        .to_dbus_fcn   = ip6_routes_to_dbus,
                                        .compare_fcn   = _nm_setting_ip_config_compare_fcn_routes,
                                        .from_dbus_fcn = ip6_routes_from_dbus, ),
         .to_dbus_only_in_manager_process = TRUE,
         .dbus_deprecated                 = TRUE, );
```

that is, directly at the place where we describe how the D-Bus property behaves.
2022-10-27 09:11:24 +02:00
Thomas Haller
b1ec664869
libnm: cleanup from/to dbus callbacks in ip[46]-config 2022-10-27 09:11:23 +02:00
Thomas Haller
05d0b81130
libnm: mark deprecated D-Bus properties in meta data
This has no effect (yet), but we will generate documentation
from this information. Also, it's just self-documenting code.
2022-10-27 09:11:23 +02:00
Thomas Haller
0fd7691b09
libnm: add NMSettInfoProperty.{,dbus_}deprecated flag to mark deprecated properties 2022-10-27 09:11:22 +02:00
Thomas Haller
bb9a9b8ee1
libnm: add extra arguments to _nm_properties_override_dbus() 2022-10-27 09:11:22 +02:00
Thomas Haller
e94abbc465
libnm: rename internal to/from dbus functions 2022-10-27 09:11:21 +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
63f4783c59 core: merge branch 'bg/ipv6-dad'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1366
2022-10-26 13:31:03 +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
Beniamino Galvani
9feffe7ad4 platform: detect dadfailed IPv6 addresses during pruning
If an address is removed during pruning and it had the TENTATIVE flag
before, the most likely cause of the removal is that it failed DAD. It
could also be that the user removed it at the same time we needed to
resync the platform cache, but that seems more unlikely.
2022-10-26 08:54:29 +02:00
Beniamino Galvani
3f84ee27a0 platform: add mechanism to report removed IPv6 addresses that failed DAD 2022-10-26 08:54:29 +02:00
Thomas Haller
06bf0707ee
platform/tests: merge branch 'th/platform-1'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1440
2022-10-26 08:25:59 +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
edfb4e578e
platform/tests: add nmtst_inet6_from_string() helper
This returns a struct (not a pointer like nmtst_inet6_from_string_p()).
It is thus consistent with nmtst_inet4_from_string().
2022-10-26 08:24:28 +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
Thomas Haller
358d4c691d
glib-aux: add nm_auto_unref_gdatetime cleanup macro 2022-10-26 08:24:22 +02:00
Thomas Haller
a558b8c88c
systemd: merge branch systemd into main 2022-10-25 18:50:32 +02:00
Thomas Haller
37ccc08abf
examples: fix code formatting in "gmaincontext.py" 2022-10-25 16:47:48 +02:00
Fernando Fernandez Mancera
8111f7f33e docs: document routing-rules dbus properties
Add IP setting routing-rules properties DBus documentation. The type is
specified using the DBus formatting.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1439

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2022-10-25 16:42:02 +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
ced829d8fd
all: merge branch 'th/nm-close'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1430
2022-10-25 15:42:13 +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
70417fda9e
glib-aux: handle errors from close() in nm_utils_file_set_contents()
glib's g_file_set_contents() also does that.
2022-10-25 13:12:48 +02:00
Thomas Haller
3254f33b33
std-aux: assert against any EBADF error in nm_close()
Previously, nm_close() accepted EBADF, as long as fd was negative.

Getting EBADF for a non-negative file descriptor is a serious bug,
because in multi threaded applications there is a race to close
an unrelated file descriptor. Also, it indicates that somebody
messed up the tracking of the resource, which indicates a bug.

Getting EBADF on a negative FD is less of a problem.
But it still indicates that the caller does something they likely
don't intend to.

Assert against any EBADF.

Note that nm_clear_fd() and nm_auto_close take already care to not
close negative "file descriptors". So, if you use those, you are
not affected.

If you want a close function that doesn't care about whether fd is set,
then maybe use `nm_clear_fd(&fd)` instead.
2022-10-25 13:12:48 +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
1ce29e120b
std-aux: drop assertion and function name from assert() in release mode
For g_assert() and g_return*() we already do the same, in
"src/libnm-glib-aux/nm-gassert-patch.h"

Also patch __assert_fail() so that it omits the condition text and the
function name in production builds.

Note that this is a bit ugly, for two reasons:

- again, we make assumptions that __assert_fail() exists. In practice,
  this is the case for glibc and musl.

- <assert.h> can be included multiple times, while also forward
  declaring __assert_fail(). That means, we cannot add a macro

  #define __assert_fail(...)

  because that would break the forward declaration. Instead,
  just `#define __assert_fail _nm_assert_fail_internal`

Of course, this only affects direct calls to assert(), which we have
few. nm_assert() is not affected, because that anyway doesn't do
anything, unless NM_MORE_ASSERTS is enabled.
2022-10-25 13:12:48 +02:00
Thomas Haller
8e3299498d
std-aux,glib-aux: rework nm_assert() implementations
1) ensure the compiler always sees the condition (even if
  it's unreachable). That is important, to avoid warnings
  about unused variables and to ensure the condition compiles.
  Previously, if NM_MORE_ASSERTS was enabled and NDEBUG (or
  G_DISABLE_ASSERT) was defined, the condition was not seen by
  the compiler.

2) to achieve point 1, we evaluate the expression now always in
  nm_assert() macro directly. This also has the benefit that we
  control exactly what is done there, and the implementation is
  guaranteed to not use any code that is not async-signal-safe
  (unless the assertion fails, of course).

3) add NM_MORE_ASSERTS_EFFECTIVE.
  When using no glib (libnm-std-aux), the assert is implemented
  by C89 assert(), while libnm-glib-aux redirects that to g_assert().
  Note that these assertions are only in effect, if both NM_MORE_ASSERTS
  and NDEBUG/G_DISABLE_ASSERT say so. NM_MORE_ASSERTS_EFFECTIVE
  is thus the effectively used level for nm_assert().

4) use the proper __assert_fail() and g_assertion_message_expr()
  calls. __assert_fail() is not standard, but it is there for glibc
  and musl. So relying on this is probably fine. Otherwise, we will
  get a compilation error and notice it.
2022-10-25 13:12:48 +02:00