Commit Graph

266 Commits

Author SHA1 Message Date
Yu Watanabe d51c4fca29 tree-wide: fix "a the" or "the a" 2020-11-13 16:28:47 +09:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Lennart Poettering 8facd1ce4f resolved: remove redundant conditionalization
If all protocols are listed there's no point in having the if check.

Follow-up for 8b4198373b
2020-10-28 10:01:03 +01:00
Lennart Poettering 1ed314087f resolved: use structured initialization everywhere 2020-10-28 10:00:28 +01:00
Zbigniew Jędrzejewski-Szmek 90e74a66e6 tree-wide: define iterator inside of the macro 2020-09-08 12:14:05 +02:00
Lennart Poettering a75cb4e20a resolved: remove superfluous ;; 2020-08-28 22:59:26 +02:00
Lennart Poettering 95d2155aeb tree-wide: no need to negate argument to ERROR_IS_XYZ()
These macros call abs() internally, hence let's simplify invocations.
2020-08-28 22:58:58 +02:00
Lennart Poettering fd8a301703 resolved: make sure we initialize t->answer_errno before completing the transaction
We must have the error number around when completing the transaction.
Let's hence make sure we always initialize it *first* (we accidentally
did it once after).

Fixes: #11626
2020-08-28 22:44:57 +02:00
Yu Watanabe 8aa5afd20f resolve: read/save port number and SNI from/into link state file 2020-07-21 04:08:16 +09:00
Yu Watanabe da9de7385a resolve: support port specifier in DNS= setting 2020-07-21 04:04:42 +09:00
Zbigniew Jędrzejewski-Szmek de7fef4b6e tree-wide: use set_ensure_put()
Patch contains a coccinelle script, but it only works in some cases. Many
parts were converted by hand.

Note: I did not fix errors in return value handing. This will be done separate
to keep the patch comprehensible. No functional change is intended in this
patch.
2020-06-22 16:32:37 +02:00
Zbigniew Jędrzejewski-Szmek 29bd6012f1 resolved: introduce dns_transaction_gcp() 2020-06-22 16:32:37 +02:00
Zbigniew Jędrzejewski-Szmek e53b8cc521 resolved: return org.freedesktop.resolve1.DnsError.NXDOMAIN on LLMNR resolution failure
Fixes #14922.
2020-04-20 15:33:18 +02:00
Zbigniew Jędrzejewski-Szmek f731fd5be6 resolved: fix abort when recv() returns 0
https://bugzilla.redhat.com/show_bug.cgi?id=1703598
2019-09-13 13:31:43 +09:00
Jorge Niedbalski 37d7a7d984 resolved: switch cache option to a tri-state option (systemd#5552).
Change the resolved.conf Cache option to a tri-state "no, no-negative, yes" values.

If a lookup returns SERVFAIL systemd-resolved will cache the result for 30s (See 201d995),
however, there are several use cases on which this condition is not acceptable (See systemd#5552 comments)
and the only workaround would be to disable cache entirely or flush it , which isn't optimal.

This change adds the 'no-negative' option when set it avoids putting in cache
negative answers but still works the same heuristics for positive answers.

Signed-off-by: Jorge Niedbalski <jnr@metaklass.org>
2019-07-17 10:42:53 -04:00
Iwan Timmer aedf00a2bd resolved: don't require check when importing resolved-dnstls.h 2019-06-19 13:10:44 +02:00
Ben Boeckel 5238e95759 codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
Yu Watanabe 6ff79f7640 resolve: rename Link.name -> Link.ifname
This also changes the type from char[IF_NAMESIZE] to char*.
By changing the type, now resolved-link.h can drop the dependency to
the header net/if.h.
2019-04-13 17:51:59 +09:00
Lennart Poettering c3fecddf0d util: move ERRNO_IS_xyz macros to errno-util.h
It's where they fit much better.
2019-03-19 15:29:44 +01:00
Yu Watanabe 30f9e0bfe5 resolve: fix null pointer dereferences
Follow-up for 8227cfa137.

Fixes CID#1398986.
2019-02-21 11:07:32 +01:00
Lennart Poettering 8227cfa137 transaction: simplify handling if we get an unexpected DNS packet via TCP
There's no point in calling on_stream_complete() as it doesn't do
anything with the zero argument. Let's hence simplify this and just log.
2019-02-15 17:13:58 +01:00
Lennart Poettering 652ba568c6 stream: track type of DnsStream object
We use stream objects in four different cases: let's track them.

This in particular allows us to make sure the limit on outgoing streams
cannot be exhausted by having incoming streams as this means we can
neatly separate the counters for all four types.
2019-02-15 17:13:58 +01:00
Lennart Poettering 6d72da2f3e resolved: mention which RRs we query when requesting them to authenticate some other RR 2018-12-18 11:25:21 +01:00
Lennart Poettering d5acaa51db resolved: only attempt non-answer SOA RRs if they are parents of our query
There's no value in authenticating SOA RRs that are neither answer to
our question nor parent of our question (the latter being relevant so
that we have a TTL from the SOA field for negative caching of the actual
query).

By being to eager here, and trying to authenticate too much we run the
risk of creating cyclic deps between our transactions which then causes
the over-all authentication to fail.

Fixes: #9771
2018-12-18 11:25:21 +01:00
Lennart Poettering 7172e4ee1e resolved: implicitly disconnect a stream from its server when a stream is closed
Previously, the callback function did this, but let's do this in the
caller instead, to make this more robust, and use our new helper
function for it.
2018-12-07 17:22:59 +01:00
Lennart Poettering 904dcaf9d4 resolved: take particular care when detaching DnsServer from its default stream
DnsStream and DnsServer have a symbiotic relationship: one DnsStream is
the current "default" stream of the server (and thus reffed by it), but
each stream also refs the server it is connected to. This cyclic
dependency can result in weird situations: when one is
destroyed/unlinked/stopped it needs to unregister itself from the other,
but doing this will trigger unregistration of the other. Hence, let's
make sure we unregister the stream from the server before destroying it,
to break this cycle.

Most likely fixes: #10725
2018-12-07 17:16:29 +01:00
Lennart Poettering 199dda9c25 resolved: before assuming we have a server, check we are talking DNS and not LLMNR/mDNS 2018-12-07 17:16:29 +01:00
Lennart Poettering ec962fba62 resolved: add small helper to pick DNS port number
This shouldn't be hidden in some function argument expression. Let's
make this more explicit by turning this into its own helper function.
2018-12-07 17:16:29 +01:00
Lennart Poettering 747a8a74c0 resolved: rename dns_stream_on_packet() → on_stream_packet()
Let's name this similar to on_stream_complete(). Moreover we shouldn't
invade dns_stream's namespace if we are a consumer of it.
2018-12-07 17:16:29 +01:00
Lennart Poettering 97d5d9055f resolved: don't read packet from DnsStream on on_stream_complete() of DnsTransaction
We register an on_packet() handler anyway, which is called first.
There's hence no need to check in on_stream_complete() again, as it is
already taken by that time.
2018-12-07 17:16:29 +01:00
Lennart Poettering aa337a5e72 resolved: add new accessor dns_stream_take_read_packet() for taking read packet from stream
This ensures the packet is complete when it is taken out, and resets
n_read so that we can start reading the next one.
2018-12-07 17:16:29 +01:00
Lennart Poettering 56e267dee2 resolved: remove redundant code 2018-12-07 17:16:29 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Iwan Timmer 19feb28fa1 resolved: do not keep dns_server to dns_stream ref if tls connection failed (#9855)
The references to the dns_server are now setup after the tls connection is setup.
This ensures that the stream got fully stopped when the initial tls setup failed
instead of having the unref being blocked by the reference to the stream by the server.
Therefore on_stream_io would no longer be called with a half setup encrypted connection.

Fixes the issue reported in #9838.
2018-08-13 15:20:25 +09:00
Iwan Timmer 6016fcb0ea resolved: refactor GnuTLS specific code in separate source file
This is a first step towards supporting alternative TLS implementations for DNS-over-TLS.

Co-authored-by: Filipe Brandenburger <filbranden@google.com>
2018-07-27 21:23:17 +01:00
Yu Watanabe 18df5fb017 resolve: unref stream after completion processes
Fixes #9511.
2018-07-12 12:57:55 +09:00
Filipe Brandenburger b02a7e1aea resolved: assert t->server is set in dns_transaction_emit_tcp.
Uncovered by Coverity. Fixes CID 1393390.
2018-06-25 13:17:25 +02:00
Yu Watanabe 86b112a315 resolve: dns_scope_network_good() does not returns negative errno 2018-06-25 13:25:34 +09:00
Yu Watanabe 56ddbf1009 meson: make DNS-over-TLS support optional
This adds dns-over-tls option to meson. If set to 'false',
systemd-resolved is not linked with libgnutls.
2018-06-20 22:28:01 +02:00
Zbigniew Jędrzejewski-Szmek 1183320594 resolved: move dot to end of sentence
Noticed in #9285.
2018-06-19 16:14:48 +09:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Yu Watanabe daab72ea44 resolve: do not complete stream transaction when it is under retrying 2018-06-13 13:43:36 +09:00
Yu Watanabe 3da3cdd592 resolve: drop unused argument of dns_server_packet_lost() 2018-06-13 13:20:23 +09:00
Yu Watanabe eab39da1fa resolve: correctly count TCP transaction failures
Fixes #9281.
2018-06-13 13:13:40 +09:00
Matthias-Christian Ott dbc4661a2c resolve: do not derive query timeout from RTT
DNS queries need timeout values to detect whether a DNS server is
unresponsive or, if the query is sent over UDP, whether a DNS message
was lost and has to be resent. The total time that it takes to answer a
query to arrive is t + RTT, where t is the maximum time that the DNS
server that is being queried needs to answer the query.

An authoritative server stores a copy of the zone that it serves in main
memory or secondary storage, so t is very small and therefore the time
that it takes to answer a query is almost entirely determined by the
RTT. Modern authoritative server software keeps its zones in main memory
and, for example, Knot DNS and NSD are able to answer in less than
100 µs [1]. So iterative resolvers continuously measure the RTT to
optimize their query timeouts and to resend queries more quickly if they
are lost.

systemd-resolved is a stub resolver: it forwards DNS queries to an
upstream resolver and waits for an answer. So the time that it takes for
systemd-resolved to answer a query is determined by the RTT and the time
that it takes the upstream resolver to answer the query.

It seems common for iterative resolver software to set a total timeout
for the query. Such total timeout subsumes the timeout of all queries
that the iterative has to make to answer a query. For example, BIND
seems to use a default timeout of 10 s.

At the moment systemd-resolved derives its query timeout entirely from
the RTT and does not consider the query timeout of the upstream
resolver. Therefore it often mistakenly degrades the feature set of its
upstream resolvers if it takes them longer than usual to answer a query.
It has been reported to be a considerable problem in practice, in
particular if DNSSEC=yes. So the query timeout systemd-resolved should
be derived from the timeout of the upstream resolved and the RTT to the
upstream resolver.

At the moment systemd-resolved measures the RTT as the time that it
takes the upstream resolver to answer a query. This clearly leads to
incorrect measurements. In order to correctly measure the RTT
systemd-resolved would have to measure RTT separately and continuously,
for example with a query with an empty question section or a query for
the SOA RR of the root zone so that the upstream resolver would be able
to answer to query without querying another server. However, this
requires significant changes to systemd-resolved. So it seems best to
postpone them until other issues have been addressed and to set the
resend timeout to a fixed value for now.

As mentioned, BIND seems to use a timeout of 10 s, so perhaps 12 s is a
reasonable value that also accounts for common RTT values. If we assume
that the we are going to retry, it could be less. So it should be enough
to set the resend timeout to DNS_TIMEOUT_MAX_USEC as
DNS_SERVER_FEATURE_RETRY_ATTEMPTS * DNS_TIMEOUT_MAX_USEC = 15 s.
However, this will not solve the incorrect feature set degradation and
should be seen as a temporary change until systemd-resolved does
probe the feature set of an upstream resolver independently from the
actual queries.

[1] https://www.knot-dns.cz/benchmark/
2018-06-12 23:21:18 +02:00
Iwan Timmer 5d67a7ae74 resolved: support for DNS-over-TLS
Add support for DNS-over-TLS using GnuTLS. To reduce latency also TLS False Start and TLS session resumption is supported.
2018-06-11 21:35:58 +02:00
Iwan Timmer 91ccab1e40 resolved: TCP fast open connections
Add suport for TCP fast open connection to reduce latency for successive DNS request over TCP
2018-06-11 21:35:58 +02:00
Iwan Timmer 98767d75d7 resolved: longlived TCP connections
Keep DNS over TCP connection open until it's closed by the server or after a timeout.
2018-06-11 20:17:51 +02:00
Zbigniew Jędrzejewski-Szmek a1230ff972 basic/log: add the log_struct terminator to macro
This way all callers do not need to specify it.
Exhaustively tested by running test-log under valgrind ;)
2018-06-04 13:46:03 +02:00