Commit Graph
1964 Commits
Author SHA1 Message Date
Jan Janssen e1eeebbb11 meson: Use files() for tests
Not having to provide the full path in the source tree is much
nicer and the produced lists can also be used anywhere in the source
tree.
2022-01-11 14:15:54 +01:00
Yu Watanabe e28df39269 resolve: add missing initialization of libgcrypt
Fixes #21951.
2022-01-05 12:12:54 +01:00
Yu Watanabe 9bcf483b11 meson: fix build with -Dcryptolib=openssl -Ddns-over-tls=false
Previously, when -Ddns-over-tls=false, libopenssl was missing in the
dependency of resolved.
Also, this drops libgpg_error when it is not necessary.

Replaces #21878.
2021-12-24 15:23:39 +00:00
Zbigniew Jędrzejewski-Szmek c6f20515ab man: describe flags for record resolving 2021-12-20 10:56:14 +01:00
Yu Watanabe d9338387d9 Merge pull request #21786 from keszybz/dirent-work
Make FOREACH_DIRENT and FOREACH_DIRENT_ALL declare the iterator variables
2021-12-17 04:07:35 +09:00
Zbigniew Jędrzejewski-Szmek 03f7ddf0bf meson: stop building out convenience libraries by default
The meson default for static_library() are:
build_by_default=true, install=false. We never interact with the
static libraries, and we only care about them as a stepping-stone towards
the installable executables or libraries. Thus let's only build them if
they are a dependency of something else we are building.

While at it, let's drop install:false, since this appears to be the default.

This change would have fixed the issue with lib_import_common failing
to build too: we wouldn't attempt to build it.

In practice this changes very little, because we generally only declare static
libraries where there's something in the default target that will make use of
them. But it seems to be a better pattern to set build_by_default to false.
2021-12-16 11:01:08 +01:00
Zbigniew Jędrzejewski-Szmek c7f0d9e5ac tree-wide: make FOREACH_DIRENT_ALL define the iterator variable
The variable is not useful outside of the loop (it'll always be null
after the loop is finished), so we can declare it inline in the loop.
This saves one variable declaration and reduces the chances that somebody
tries to use the variable outside of the loop.

For consistency, 'de' is used everywhere for the var name.
2021-12-15 16:19:13 +01:00
Zbigniew Jędrzejewski-Szmek 0ad4efb14b resolved: filter out our own stub resolvers when parsing servers
We get "upstream" dns server config from ~three places: /etc/resolv.conf,
config files, and runtime config via dbus. With this commit, we'll filter out
our own stub listeners if they are configured in either of the first two
sources. For /etc/resolv.conf this is done quitely, and for our own config
files, a LOG_INFO message is emitted, since this is a small inconsistency in
the config.

Setting loops like this over dbus is still allowed. The reason is that in the
past we didn't treat this as an error, and if we were to start responding with
an error, we could break a scenario that worked previously. E.g. NM sends us a
list of servers, and one happens to be the our own. We would just not use that
stub server before, but it'd still be shown in the dbus properties and such.
We would have to return error for the whole message, also rejecting the other
valid servers. I think it's easier to just keep that part unchanged.

Test case:
$ ls -l /etc/resolv.conf
-rw-r--r-- 1 root root 57 Dec 15 10:26 /etc/resolv.conf
$ cat /etc/resolv.conf
nameserver 192.168.150.1
options edns0 trust-ad
search .
$ cat /etc/systemd/resolved.conf.d/stub.conf
[Resolve]
DNSStubListenerExtra=192.168.150.1

$ resolvectl
...
Global
    resolv.conf mode: foreign
         DNS Servers: 192.168.150.1
Fallback DNS Servers: ...
(with the patch):
Global
    resolv.conf mode: foreign
Fallback DNS Servers: ...
2021-12-15 11:47:06 +01:00
Zbigniew Jędrzejewski-Szmek 9d84fdec28 resolved: return immediately if we already know what to return 2021-12-15 11:47:05 +01:00
Tom Yan af45251e4c resolved: filter stub listeners in manager_get_dns_server()
Commit 49ef064c8d attempts to handle
"stub loop" by switching to the next server *after the query has
been made*.

The approach may be good enough for link scopes. However, for the
manager / global scope, it is not. First of all, there are more than
one types (SYSTEM and FALLBACK) of servers it can use. Also, whether
those of type FALLBACK should be used depends.

Besides, dns_scope_good_domain() determines whether things should
be routed to a scope by checking whether the scope has a server.
The decision made would be incorrect if stubs were not filtered
beforehand.

Therefore, to avoid failing query unnecessarily, and to make sure
that extra stub listeners will not trigger unexpected and/or
inconsistent behavior, make manager_get_dns_server() do what it
should have done.
2021-12-13 23:08:40 +08:00
Zbigniew Jędrzejewski-Szmek acfdfb8620 openssl: supress warnings about functions deprecated by openssl 3.0
We get warnings for RSA_free(), EC_KEY_free(), EC_KEY_new(), etc. Those
functions are now deprecated and we're supposed to use the new "EVP API" that
is all the rage in openssl 3.0.

With some effort I converted dnssec_rsa_verify_raw() to use the new API.  The
code is significantly longer and, if anything, less readable. The EC code is
more complicated and I assume that the EVP API version will be even more
complex. It is possiblet that I'm missing some way to call the new functions in
a better way, but the documentation is abysmal, so it's really hard to figure
out the best way. Of course there are almost no examples, and the ones that are
there are not terribly useful and are also stubs that don't do interesting
things, don't implement error handling, or memory cleanup. I'll submit my
conversion draft as a separate PR. Maybe somebody who knows openssl better
will pick it up and write a proper solution.

For now, let's just use the existing code, but suppress the warnings. The
new version just came out, so it's unlikely that the deprecated functions will
be removed any time soon.

Fixes #21666.
2021-12-09 10:27:18 +01:00
Luca Boccassi c65a0cf62f Merge pull request #21667 from yuwata/resolve-do-not-re-read-settings-from-networkd-when-unmodified
resolve: do not re-read settings from networkd when link state file is unmodified
2021-12-08 13:28:15 +00:00
Yu Watanabe 214db8eb5d resolve: do not re-read settings from networkd if link state file is unmodified
If many interface creation/deletion occurs continuously, then resolved
becomes easily busy. Let's slightly optimize the event triggered by
sd-network.
2021-12-08 18:34:08 +09:00
Zbigniew Jędrzejewski-Szmek e7bd34cd64 meson: drop libgcrypt dep from resolved tests
Follow-up for pull request #21170.

I hoped that we would drop libgcrypt fully and drop all references to the
library in meson, but this doesn't seem feasible (because of the use in
sd-journal). But let's remove it here, all the resolved code has been switched
to work either of the two libraries.
2021-12-08 01:00:56 +00:00
Dan Streetman 526fce97af resolve: remove server 'large' level
This removes the DNS_SERVER_FEATURE_LEVEL_LARGE, and sets the EDNS0
advertised max packet size as if always in 'large' mode.

Without this, we always send out EDNS0 opts that limit response sizes
to 512 bytes, thus the remote server will never send anything larger
and will always truncate responses larger than 512 bytes, forcing us
to drop from EDNS0 down to TCP, even though one of the primary benefits
of EDNS0 is larger packet sizes.

Fixes: #20993
2021-12-07 14:20:47 +01:00
Frantisek Sumsal 33b7988d2e analyze,resolve: suppress a couple of false-positive alerts 2021-12-06 17:45:37 +01:00
Frantisek Sumsal c73f413d8d tree-wide: check for NULLs in more places
Fixes issues pointed out by the `cpp/inconsistent-null-check` LGTM
query.
2021-12-06 08:50:53 +09:00
Zbigniew Jędrzejewski-Szmek 939387bdc6 Merge pull request #21170 from keszybz/delibgcryptify
Allow systemd-resolved and systemd-importd to use libgcrypt or libopenssl
2021-12-03 13:44:53 +01:00
Zbigniew Jędrzejewski-Szmek 6e7323137a resolved: do not use BN_dup() unnecessarilly
Suggested in https://github.com/systemd/systemd/pull/21170#discussion_r738696794
2021-12-01 12:36:57 +01:00
Zbigniew Jędrzejewski-Szmek 7e8facb36b port string_hashsum from libgcrypt to openssl^gcrypt
This allows resolved and importd to be built without libgcrypt.

Note that we now say either 'cryptographic library' or 'cryptolib'.

Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2021-12-01 12:36:57 +01:00
Kevin KuehlerandZbigniew Jędrzejewski-Szmek 1736344e9e resolve: Port nsec3 code to openssl^gcrypt
Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2021-12-01 12:36:45 +01:00
Kevin KuehlerandZbigniew Jędrzejewski-Szmek 1cd7a2c172 resolve: Port dnskey verification by ds to openssl^gcrypt
Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2021-11-30 23:00:21 +01:00
Kevin KuehlerandZbigniew Jędrzejewski-Szmek 0351cbb9e4 resolve: Port dnssec verify from gcrypt to openssl^gcrypt
Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2021-11-30 23:00:21 +01:00
Zbigniew Jędrzejewski-Szmek 667dac6ed6 resolved: split out function to hash signature
dnssec_verify_rrset() is just too long.
2021-11-30 23:00:21 +01:00
Zbigniew Jędrzejewski-Szmek cc1ecbaaf3 resolved: split out function to generate signature
dnssec_verify_rrset() is just too long.
2021-11-30 23:00:21 +01:00
Kevin Kuehler bf4b1adf6f resolve: Add coverage for dnssec ecdsa (rfc6605) 2021-11-30 23:00:21 +01:00
Yu Watanabe 8add30a03c tree-wide: use ERRNO_IS_TRANSIENT() 2021-11-30 23:06:43 +09:00
Lennart Poettering 383c6f41e8 Merge pull request #21479 from keszybz/cosmetic-initialization-adjustments
Cosmetic initialization adjustments
2021-11-23 18:42:45 +01:00
Zbigniew Jędrzejewski-Szmek fc44acc0d2 resolved: add _unused_ annotations to appease clang 2021-11-23 16:20:14 +01:00
Zbigniew Jędrzejewski-Szmek 64ea42e975 resolved: inline declarations of iterator variables 2021-11-23 16:20:14 +01:00
Zbigniew Jędrzejewski-Szmek 0c4f37f0fb resolved: move packet rewinder initalization inline
There is no functional change, but this reduces the risk that
in some future refactoring we'll forget the do the initialization in all
execution paths.
2021-11-23 16:20:14 +01:00
Lennart Poettering e1158539e7 resolved: lower connection timeout for DoT connections in opportunistic mode
Fixes: #20801
2021-11-22 22:33:40 +01:00
Lennart Poettering e2ef1e9aea resolved: clean up manager_write_resolv_conf() a bit
Let's downgrade log messages which are not fatal for the service to
LOG_WARNING.

And let's simplify clean-up by using _cleanup_(unlink_and_freep).
2021-11-22 22:33:40 +01:00
Lennart Poettering 8cf9898a96 resolved: make sure we don't hit an assert when dealing with incomplete DNSSD service definitions
Fixes: #21142
2021-11-22 22:33:40 +01:00
Lennart Poettering 5a78106ad9 resolved: fix ResolveService() hostname handling
Let's eat up special returns of dns_query_process_cname_many() when
storing hostname resolution results.

The rest of the code assumes only == 0 means success and != 0 means
error, but so far > 0 also could mean success, let's fix that.

Fixes: #21365 #21140

(This was originally broken in 1db8e6d1db)
2021-11-22 22:33:40 +01:00
Lennart Poettering a8d0906344 resolved: add "proxy-only" stub on 127.0.0.54
This beefs up the DNS stub logic to listen on two IP addresses:
127.0.0.53 (as before) + 127.0.0.54 (new). When the latter is contact
our stub will operate in "bypass" mode only, i.e we'll try to pass DNS
requests as unmodified upstream as we can (and not do mDNS/LLMNR and
such, also no DNSSEC validation – but we'll still do DNS-over-TLS
wrapping).

This is supposed to be useful for container environments or tethering:
this stub could be exposed (via NAT redirect) to clients of this system
and we'll try to stay out of the way with doing too much DNS magic
ourselves, but still expose whatever the current DNS server is from
upstream under a stable address/port.

How to use this:

  # iptables -t nat -I PREROUTING -p udp -i <interface> --dport 53 -j DNAT --to 127.0.0.54:53
  # echo 1 > /proc/sys/net/ipv4/conf/<interface>/route_localnet
2021-11-22 22:33:24 +01:00
Lennart Poettering f96b500ece resolved: include IP address info in debug output for incoming datagrams 2021-11-22 22:18:34 +01:00
Lennart Poettering ded152134e resolved: use RET_NERRNO() where it makes sense 2021-11-22 18:36:03 +01:00
Zbigniew Jędrzejewski-Szmek 718ca77232 shared/json: use int64_t instead of intmax_t
We were already asserting that the intmax_t and uintmax_t types
are the same as int64_t and uint64_t. Pretty much everywhere in
the code base we use the latter types. In principle intmax_t could
be something different on some new architecture, and then the code would
fail to compile or behave differently. We actually do not want the code
to behave differently on those architectures, because that'd break
interoperability. So let's just use int64_t/uint64_t since that's what
we indend to use.
2021-11-18 01:34:31 +01:00
Lennart Poettering 35cd0ba516 shared: clean up mkdir.h/label.h situation
Previously the mkdir_label() family of calls was implemented in
src/shared/mkdir-label.c but its functions partly declared ins
src/shared/label.h and partly in src/basic/mkdir.h (!!). That's weird
(and wrong).

Let's clean this up, and add a proper mkdir-label.h matching the .c
file.
2021-11-16 17:03:28 +01:00
Yu Watanabe 26591ffffd resolve: do not clear DNS servers or friends on link which is not managed by networkd
When networkd detects an unmanaged link, then the state is changed in
the following order:
pending -> initialized -> unmanaged

The "initialized" state was added by bd08ce5615.
2021-11-15 08:17:34 +09:00
Christian Brauner a6d1760024 build: preserve correct mode when generating files via jinja2
When using "capture : true" in custom_target()s the mode of the source
file is not preserved when the generated file is not installed and so
needs to be tweaked manually. Switch from output capture to creating the
target file and copy the permissions from the input file.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-08 12:06:48 +00:00
Zbigniew Jędrzejewski-Szmek 384c2c3239 Make pager_open() return void 2021-11-03 15:24:56 +01:00
Lennart Poettering 2f82562bad alloc-util: add strdupa_safe() + strndupa_safe() and use it everywhere
Let's define two helpers strdupa_safe() + strndupa_safe() which do the
same as their non-safe counterparts, except that they abort if called
with allocations larger than ALLOCA_MAX.

This should ensure that all our alloca() based allocations are subject
to this limit.

afaics glibc offers three alloca() based APIs: alloca() itself,
strndupa() + strdupa(). With this we have now replacements for all of
them, that take the limit into account.
2021-10-14 15:57:52 +02:00
Yu Watanabe f21b863eeb test: use assert_se() instead of assert() 2021-10-12 15:20:28 +09:00
Frantisek Sumsal b98416e100 tree-wide: assorted Coccinelle fixes
It's that time of year again.
2021-10-08 15:03:27 +02:00
Luca Boccassi 948def4af6 tree-wide: fix SPDX short identifier for LGPL-2.1-or-later
https://spdx.dev/ids/#:~:text=Allowing%20later%20versions%20of%20a%20license
https://spdx.org/licenses/LGPL-2.1-or-later.html
2021-10-01 17:27:34 +01:00
Lennart Poettering bee07a3995 resolvconf-compat: make "-u" operation a NOP
According to the various man pages of "resolvconf" the -u switch is for:

"-u Just run the update scripts (if updating is enabled)."

"-u Force resolvconf to update all its subscribers. resolvconf does not
    update the subscribers when adding a resolv.conf that matches what
    it already has for that interface."

We have no "subscribers", we ourselves are the only "subscriber" we
support. Hence it's probably better to ignore such a request and make it
a NOP, then to fail.

Fixes: #20748
2021-09-29 14:36:47 +02:00
Yu Watanabe 17373589f3 Merge pull request #20860 from yuwata/libsystemd-network-get-ifname-negative-errno
libsystemd-network: make sd_dhcp_client_get_ifname() or friends return negative errno
2021-09-29 12:27:01 +09:00
Yu Watanabe 01afd0f7f5 tree-wide: make format_ifname() or friends return negative errno on failure
Also,
- drop unnecessary +1 from buffer size, as IF_NAMESIZE or IFNAMSIZ
  includes the nul at the end.
- format_ifname() does not update buffer on failure,
- introduces format_ifname_alloc(), FORMAT_IFNAME(), and their friends.
2021-09-29 03:37:06 +09:00