Commit graph

64 commits

Author SHA1 Message Date
Beniamino Galvani
e5868f21ec dns: detect more quickly when systemd-resolved can't be D-Bus activated
Pass a callback and a 4-second timeout to the "StartServiceByName()"
D-Bus call, so that we can detect any failure immediately.

In this way when systemd-resolved fails to start at boot (for example
because it's masked), nm-online doesn't need to wait those additional
4 seconds due to the fixed timeout source.

Fixes-test: @nm_online_wait_for_delayed_device

https://bugzilla.redhat.com/show_bug.cgi?id=2083332
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1233
2022-05-25 16:03:12 +02:00
Thomas Haller
c4f5111920
all: use nm_hostname_is_valid() instead of systemd code 2022-04-20 12:07:04 +02:00
Thomas Haller
cef5b8dd46
dns: prevent update-pending to hang indefinitely
For example, if you have a dnsmasq service running and bound to port 53, then
NetworkManager's [main].dns=dnsmasq will fail to start. And we keep retrying
to start it. But then update pending would hang indefinitely, and devices could
not become active. That must not happen.

Give the DNS update only 5 seconds. If it's not done by then, assume we
have a problem and unblock.
2022-04-15 09:04:30 +02:00
Thomas Haller
f2abcf2082
dns/dnsmasq: implement update-pending flag in NMDnsDnsmasq plugin
We want to know when we are busy (have an update pending or on-going).
Implement that.
2022-04-15 09:04:30 +02:00
Thomas Haller
ccf0e8d327
dns/dnsmasq: use GSource for timeout in NMDnsDnsmasq 2022-04-15 09:04:30 +02:00
Thomas Haller
5da17c689b
dns/unbound: drop deprecated "unbound" DNS plugin
The "unbound" DNS plugin was very rudimentary and is deprecated since
commit 4a2fe09853 ('man: mark [main].dns=unbound as deprecated') (Jun
2021).

It is part of dnssec-trigger tool, but the dnssec-trigger tool doesn't
actually use it. Instead it installs a dispatcher script
"/usr/lib/NetworkManager/dispatcher.d/01-dnssec-trigger".

Especially, since the plugin requires "/usr/libexec/dnssec-trigger-script",
which is provided by "dnssec-trigger" package on Fedora. At the same
time, the package provides the dispatcher script. So I don't this works
or anybody is using this.

https://mail.gnome.org/archives/networkmanager-list/2022-April/msg00002.html
2022-04-15 09:04:30 +02:00
Thomas Haller
bbbb1b7339
dns/resolved: implement update-pending flag in NMDnsSystemdResolved plugin 2022-04-15 09:04:30 +02:00
Thomas Haller
a74a517f49
dns/resolved: track pending counter for D-Bus calls in NMDnsSystemdResolved
This is used to signal that an update is pending or in progress.
For this to work, we also need to implement the stop() handle.
Otherwise, we couldn't abort pending requests, which is necessary
during shutdown (not today, but in the future).
2022-04-15 09:04:30 +02:00
Thomas Haller
2f1feb9651
dns/resolved: use GPtrArray to collect ip datas in NMDnsSystemdResolved's update()
CList is a great, simple data structure. Especially, if we can embed it
into the data we track.

Here we just create a (temporary) list of pointers. A GPtrArray is the
better data structure for that.
2022-04-15 09:04:30 +02:00
Thomas Haller
eb25c9ecd2
dns/resolved: use nm_utils_hash_to_array_with_buffer() in NMDnsSystemdResolved's update()
We copy the content of the hash table to an array, so that we can sort
the entries and they have a defined order.

We are not only interested in the keys, but the keys and the values.
Hence, use nm_utils_hash_to_array_with_buffer() which gives both at
the same time.
2022-04-15 09:04:29 +02:00
Thomas Haller
51cec67253
dns/resolved: sort dirty interfaces to prune in "nm-dns-systemd-resolved.c"
When we do something where the order makes a visible difference,
we should do it in a consistent way, that does not depend on arbitray
things. Sort the ifindexes from dirty_interfaces hash table.
2022-04-15 09:04:29 +02:00
Thomas Haller
39b68d72d3
dns/resolved: add const to parameters in "nm-dns-systemd-resolved.c" 2022-04-15 09:04:29 +02:00
Thomas Haller
4564adfb53
dns/resolved: minor cleanups in "nm-dns-systemd-resolved.c" 2022-04-15 09:04:29 +02:00
Thomas Haller
a60b971003
dns: add update-pending property to NMDnsManager 2022-04-15 09:04:29 +02:00
Thomas Haller
b7ca08e971
dns: add "update-pending" state to NMDnsPlugin
Theoretically, this should be a GObject property, and not a signal.
But then I'd  also have to implement the get_property() function,
which is more hazzle than necessary. A signal will do nicely.
2022-04-15 09:04:29 +02:00
Thomas Haller
f68230fbe9
dns: call nm_dns_plugin_stop() also for NMDnsSystemdResolved instance
Currently NMDnsSystemdResolved does not implement "stop()". That is
about to change. Make sure to call stop before unreferencing the
instance.
2022-04-15 09:04:29 +02:00
Thomas Haller
0001a2fd0c
dns: fix NMDnsPluginPrivate and drop unused fields
NM_DNS_PLUGIN_GET_PRIVATE() macro was broken. Also NMDnsPluginPrivate
contained unused fields. Fix that.

The private data is unused at the moment, but will be used next.
Hence it is fixed and not removed.
2022-04-15 09:04:28 +02:00
Thomas Haller
068ca09d16
dns: obfuscate pointer value for NMDnsPlugin logging 2022-04-15 09:04:28 +02:00
Thomas Haller
f7b41fc18c
dns: avoid printing pointer value for NMDnsManager logging statements
We avoid printing raw pointer values. Also, in this case this is a
singleton, and we only create one instance of this type.

Note that we would still have printed the pointer instance while
constructing the instances, before setting it as singleton.

Just drop this.
2022-04-15 09:04:28 +02:00
Thomas Haller
bd95a5c0ec
dns: register NMDnsPlugin instance as wait-obj for shutdown
nm_shutdown_wait_obj_register_object() today has no practical effect.
In the future it will block shutdown until the object gets destroyed.
We will want that NMDnsPlugin gets wrapped up during shut down, before
quitting.
2022-04-15 09:04:28 +02: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
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
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
Beniamino Galvani
ce0a36d20f dns: better track l3cd changes
Update DNS only when something relevant changes:

 - an old l3cd gets removed, without adding a new one

 - a new one is added without removing an old one

 - an old is removed and it differs (in routes and DNS) from the new
   added one
2022-01-26 14:54:52 +01:00
Thomas Haller
20eb6df215
core: simplify code in nm_dns_manager_set_hostname() 2022-01-10 20:43:18 +01:00
Thomas Haller
615221a99c format: reformat source tree with clang-format 13.0
We use clang-format for automatic formatting of our source files.
Since clang-format is actively maintained software, the actual
formatting depends on the used version of clang-format. That is
unfortunate and painful, but really unavoidable unless clang-format
would be strictly bug-compatible.

So the version that we must use is from the current Fedora release, which
is also tested by our gitlab-ci. Previously, we were using Fedora 34 with
clang-tools-extra-12.0.1-1.fc34.x86_64.

As Fedora 35 comes along, we need to update our formatting as Fedora 35
comes with version "13.0.0~rc1-1.fc35".
An alternative would be to freeze on version 12, but that has different
problems (like, it's cumbersome to rebuild clang 12 on Fedora 35 and it
would be cumbersome for our developers which are on Fedora 35 to use a
clang that they cannot easily install).

The (differently painful) solution is to reformat from time to time, as we
switch to a new Fedora (and thus clang) version.
Usually we would expect that such a reformatting brings minor changes.
But this time, the changes are huge. That is mentioned in the release
notes [1] as

  Makes PointerAligment: Right working with AlignConsecutiveDeclarations. (Fixes https://llvm.org/PR27353)

[1] https://releases.llvm.org/13.0.0/tools/clang/docs/ReleaseNotes.html#clang-format
2021-11-29 09:31:09 +00:00
Wen Liang
8995d44a0b core: compare the DNS configurations before updating DNS
DNS manager always sets `priv->config_changed = TRUE` and overwrites
the "resolv.conf" file. To fix it, compare the new configuration with
the old configuration, if there is no change, skipping the update.

Fixes-test: @ipv4_ignore_resolveconf_with_ignore_auto_dns
Fixes-test: @ipv4_ignore_resolveconf_with_ignore_auto_dns_var1

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1023
2021-11-18 16:21:34 +01:00
Beniamino Galvani
32443ef3b5 dns: fix assertion failure
nm_l3_config_data_get_searches() and nm_l3_config_data_get_domains()
require an 'out_len' argument.
2021-11-18 16:21:30 +01:00
Thomas Haller
58287cbcc0 core: rework IP configuration in NetworkManager using layer 3 configuration
Completely rework IP configuration in the daemon. Use NML3Cfg as layer 3
manager for the IP configuration of an interface. Use NML3ConfigData as
pieces of configuration that the various components collect and
configure. NMDevice is managing most of the IP configuration at a higher
level, that is, it starts DHCP and other IP methods. Rework the state
handling there.

This is a huge rework of how NetworkManager daemon handles IP
configuration. Some fallout is to be expected.

It appears the patch deletes many lines of code. That is not accurate, because
you also have to count the files `src/core/nm-l3*`, which were unused previously.

Co-authored-by: Beniamino Galvani <bgalvani@redhat.com>
2021-11-18 16:21:29 +01:00
Robin Ebert
a2f6cde3eb
core: Save whether SetLinkDNSOverTLS is supported 2021-10-15 10:01:13 +02:00
Robin Ebert
1a98cf1669
core: add support for connection.dns-over-tls 2021-10-15 10:00:31 +02:00
Thomas Haller
e0e58fd5bc
dns: fix format string for printing size_t in send_updates()
This in particular breaks i386 builds.

Fixes: 6f663b8f8e ('dns: log about what NMDnsSystemdResolved is doing')
2021-10-11 20:44:52 +02:00
Thomas Haller
45bcedb77e
core: move NM_DNS_PRIORITY_DEFAULT_{NORMAL,VPN} to libnm-base
We will use these values from NML3Cfg, and it seems wrong that NML3Cfg
would include "dns/nm-dns-manager.h" for this.

Enums are very "static". They have no logic, and there is less need to
separate the code well. Meaning, it doesn't hurt to define this enum
in "libnm-base/nm-base.h" which can be included by (almost) anybody.
2021-09-15 22:08:42 +02:00
Thomas Haller
3f6365f5d0
all: use G_CALLBACK() macro instead of plain cast 2021-08-05 14:59:11 +02:00
Thomas Haller
4ac66a4215
all: rename nm_utils_strdup_reset*() to nm_strdup_reset*() 2021-08-02 09:26:47 +02:00
Thomas Haller
4c3aac899e
all: unify and rename strv helper API
Naming is important, because the name of a thing should give you a good
idea what it does. Also, to find a thing, it needs a good name in the
first place. But naming is also hard.

Historically, some strv helper API was named as nm_utils_strv_*(),
and some API had a leading underscore (as it is internal API).

This was all inconsistent. Do some renaming and try to unify things.

We get rid of the leading underscore if this is just a regular
(internal) helper. But not for example from _nm_strv_find_first(),
because that is the implementation of nm_strv_find_first().

  - _nm_utils_strv_cleanup()                 -> nm_strv_cleanup()
  - _nm_utils_strv_cleanup_const()           -> nm_strv_cleanup_const()
  - _nm_utils_strv_cmp_n()                   -> _nm_strv_cmp_n()
  - _nm_utils_strv_dup()                     -> _nm_strv_dup()
  - _nm_utils_strv_dup_packed()              -> _nm_strv_dup_packed()
  - _nm_utils_strv_find_first()              -> _nm_strv_find_first()
  - _nm_utils_strv_sort()                    -> _nm_strv_sort()
  - _nm_utils_strv_to_ptrarray()             -> nm_strv_to_ptrarray()
  - _nm_utils_strv_to_slist()                -> nm_strv_to_gslist()
  - nm_utils_strv_cmp_n()                    -> nm_strv_cmp_n()
  - nm_utils_strv_dup()                      -> nm_strv_dup()
  - nm_utils_strv_dup_packed()               -> nm_strv_dup_packed()
  - nm_utils_strv_dup_shallow_maybe_a()      -> nm_strv_dup_shallow_maybe_a()
  - nm_utils_strv_equal()                    -> nm_strv_equal()
  - nm_utils_strv_find_binary_search()       -> nm_strv_find_binary_search()
  - nm_utils_strv_find_first()               -> nm_strv_find_first()
  - nm_utils_strv_make_deep_copied()         -> nm_strv_make_deep_copied()
  - nm_utils_strv_make_deep_copied_n()       -> nm_strv_make_deep_copied_n()
  - nm_utils_strv_make_deep_copied_nonnull() -> nm_strv_make_deep_copied_nonnull()
  - nm_utils_strv_sort()                     -> nm_strv_sort()

Note that no names are swapped and none of the new names existed
previously. That means, all the new names are really new, which
simplifies to find errors due to this larger refactoring. E.g. if
you backport a patch from after this change to an old branch, you'll
get a compiler error and notice that something is missing.
2021-07-29 10:26:50 +02:00
Thomas Haller
3775f4395a
all: drop unnecessary casts from nm_utils_strv_find_first()
And, where the argument is a GPtrArray, use
nm_strv_ptrarray_find_first() instead.
2021-07-29 09:33:50 +02:00
Thomas Haller
4e109bacab
clang-format: use "IndentPPDirectives:None" instead of "BeforeHash"
Subjectively, I think this looks better.
2021-07-09 08:49:06 +02:00
Thomas Haller
61d2af3518
all: use nm_{idle,timeout}_add_source() instead of g_source_attach() 2021-06-28 13:31:35 +02:00
Beniamino Galvani
4f9ff47e2d dns: add function to retrieve the systemd-resolved plugin instance
Now that we have nm_dns_systemd_resolved_resolve_address(), we also
need a way to obtain a reference to the plugin.

(cherry picked from commit 7285bc56a9)
2021-06-11 21:59:11 +02:00
Beniamino Galvani
3c96d4bb59 dns/resolved: fix memory leak
'v_name' must be freed. Pass ownership to the result element.

Fixes: e7b76f6757 ('dns/resolved: add API for ResolveAddress call')
(cherry picked from commit 9e69d921c1)
2021-06-11 21:59:11 +02:00
Thomas Haller
96d9baacdb
glib-aux/trivial: rename nm_{pint,puint32}_equals() to nm_\1_equal()
Our "_equal()" methods are commonly spelled without 's'.
2021-05-27 09:56:40 +02:00
Thomas Haller
0abc14b3a0
core: remove unused best_ip_config_[46] field in NMDnsManager 2021-05-18 09:41:54 +02:00
Thomas Haller
48dce1b66c
core: drop deprecated PropertiesChanged D-Bus signal (API BREAK)
D-Bus 1.3.1 (2010) introduced the standard "PropertiesChanged" signal
on "org.freedesktop.DBus.Properties". NetworkManager is old, and predates
this API. From that time, it still had it's own PropertiesChanged signal
that are emitted together with the standard ones. NetworkManager
supports the standard PropertiesChanged signal since it switched to
gdbus library in version 1.2.0 (2016).

These own signals are deprecated for a long time already ([1], 2016), and
are hopefully not used by anybody anymore. libnm-glib was using them and
relied on them, but that library is gone. libnm does not use them and neither
does plasma-nm.

Hopefully no users are left that are affected by this API break.

[1] 6fb917178a
2021-05-14 10:57:34 +02:00
Beniamino Galvani
fa1f628bce core: force emission of DNS_CONFIG_CHANGED signal on SIGUSR1
If the configuration contains dns=none and resolv.conf is updated
through a dispatcher script, currently there is no way to tell NM that
the content of resolv.conf changed, so that it can restart a hostname
resolution.

Use SIGUSR1 (and SIGHUP) for that.
2021-05-03 22:13:36 +02:00
Thomas Haller
e7b76f6757
dns/resolved: add API for ResolveAddress call
ResolveAddress is a simple D-Bus API. One might think that it does not
require much logic, and we would just make the D-Bus call directly.

However, we want to ensure that we always sent our latest DNS
configuration to systemd-resolved first, before making any D-Bus request
to resolve a name.

Also, as we D-Bus activate the service and watch the name owner, we
want to handle that. If a user resolves a name while we are still D-Bus
activating, then we need to queue the request.

This adds some complexity in the implementation. But the benefit is that
the API becomes simple from the user's point of view. The queuing and
avoiding race conditions is handled internally.

The implementation does not use standard glib patterns with GAsyncResult
GTask and GCancellable. I find implementing them correctly is more
effort and leads to a less nice API. That might be fine for public API,
which should follow glib style. But this is entirely internal, and
returning a NMDnsSystemdResolvedResolveHandle that allows cancellation
seems more convenient to me.
2021-04-28 13:20:03 +02:00
Thomas Haller
5cc6932d5a
dns/resolved: use unique D-Bus name for systemd-resolved request
As we already track the current name owner, it seems wrong to make
requests to the well-known name. It theoretically opens a race
where we would talk to the wrong systemd-resolved instance.

So far, we didn't care and it didn't make much of a difference.
Still, let's talk to the process that we expect.
2021-04-28 13:20:03 +02:00
Thomas Haller
e7d78e90a3
dns/resolved: track D-Bus owner of resolved D-Bus service 2021-04-28 13:20:03 +02:00
Thomas Haller
4285eed8eb
dns/resolved: add watchdog D-Bus activating systemd-resolved
Currently, it doesn't actually do anything (beside logging).
Will be used next.
2021-04-28 13:20:02 +02:00
Thomas Haller
8ee5ec00f9
dns/trivial: rename NMDnsSystemdResolvedPrivate.request_queue_to_send to "send_updates_waiting"
The previous name seems confusing to me.
2021-04-28 13:20:02 +02:00