Commit graph

70 commits

Author SHA1 Message Date
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
ffd8baa49f
all: use nm_g_array_{index,first,last,index_p}() instead of g_array_index()
These variants provide additional nm_assert() checks, and are thus
preferable.

Note that we cannot just blindly replace &g_array_index() with
&nm_g_array_index(), because the latter would not allow getting a
pointer at index [arr->len]. That might be a valid (though uncommon)
usecase. The correct replacement of &g_array_index() is thus
nm_g_array_index_p().

I checked the code manually and replaced uses of nm_g_array_index_p()
with &nm_g_array_index(), if that was a safe thing to do. The latter
seems preferable, because it is familar to &g_array_index().
2022-09-15 12:39:07 +02:00
Thomas Haller
08eff4c46e
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
  `nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.

- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
  of our wrapper is chosen to be familiar with the libc underlying
  function. With this, also name functions that are about string
  representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
  `nm_inet6_*()`. For example, `nm_inet_parse_str()`,
  `nm_inet_is_normalized()`.

<<<<

  R() {
     git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
  }

  R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX          NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
  R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX          NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
  R NM_UTILS_INET_ADDRSTRLEN                   NM_INET_ADDRSTRLEN
  R _nm_utils_inet4_ntop                       nm_inet4_ntop
  R _nm_utils_inet6_ntop                       nm_inet6_ntop
  R _nm_utils_ip4_get_default_prefix           nm_ip4_addr_get_default_prefix
  R _nm_utils_ip4_get_default_prefix0          nm_ip4_addr_get_default_prefix0
  R _nm_utils_ip4_netmask_to_prefix            nm_ip4_addr_netmask_to_prefix
  R _nm_utils_ip4_prefix_to_netmask            nm_ip4_addr_netmask_from_prefix
  R nm_utils_inet4_ntop_dup                    nm_inet4_ntop_dup
  R nm_utils_inet6_ntop_dup                    nm_inet6_ntop_dup
  R nm_utils_inet_ntop                         nm_inet_ntop
  R nm_utils_inet_ntop_dup                     nm_inet_ntop_dup
  R nm_utils_ip4_address_clear_host_address    nm_ip4_addr_clear_host_address
  R nm_utils_ip4_address_is_link_local         nm_ip4_addr_is_link_local
  R nm_utils_ip4_address_is_loopback           nm_ip4_addr_is_loopback
  R nm_utils_ip4_address_is_zeronet            nm_ip4_addr_is_zeronet
  R nm_utils_ip4_address_same_prefix           nm_ip4_addr_same_prefix
  R nm_utils_ip4_address_same_prefix_cmp       nm_ip4_addr_same_prefix_cmp
  R nm_utils_ip6_address_clear_host_address    nm_ip6_addr_clear_host_address
  R nm_utils_ip6_address_same_prefix           nm_ip6_addr_same_prefix
  R nm_utils_ip6_address_same_prefix_cmp       nm_ip6_addr_same_prefix_cmp
  R nm_utils_ip6_is_ula                        nm_ip6_addr_is_ula
  R nm_utils_ip_address_same_prefix            nm_ip_addr_same_prefix
  R nm_utils_ip_address_same_prefix_cmp        nm_ip_addr_same_prefix_cmp
  R nm_utils_ip_is_site_local                  nm_ip_addr_is_site_local
  R nm_utils_ipaddr_is_normalized              nm_inet_is_normalized
  R nm_utils_ipaddr_is_valid                   nm_inet_is_valid
  R nm_utils_ipx_address_clear_host_address    nm_ip_addr_clear_host_address
  R nm_utils_parse_inaddr                      nm_inet_parse_str
  R nm_utils_parse_inaddr_bin                  nm_inet_parse_bin
  R nm_utils_parse_inaddr_bin_full             nm_inet_parse_bin_full
  R nm_utils_parse_inaddr_prefix               nm_inet_parse_with_prefix_str
  R nm_utils_parse_inaddr_prefix_bin           nm_inet_parse_with_prefix_bin
  R test_nm_utils_ip6_address_same_prefix      test_nm_ip_addr_same_prefix

  ./contrib/scripts/nm-code-format.sh -F
2022-08-25 19:05:51 +02:00
Wen Liang
6058445aea dns: kill pending dnsmasq process when mode is not 'dnsmasq'
When NM starts, if `main.dns` is not `dnsmasq`, then the pending dnsmasq
process should be killed by NM.

https://bugzilla.redhat.com/show_bug.cgi?id=2120763

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1344
2022-08-25 12:31:48 -04:00
Wen Liang
9b3a96f821 dnsmasq: silently ignore if pid file is not existed when killing 2022-08-25 10:56:47 -04:00
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