Commit graph

1351 commits

Author SHA1 Message Date
Lennart Poettering bb5e88a226
Merge pull request #11841 from keszybz/dns-packet-speedup
DNS packet speedup
2019-03-04 19:30:23 +01:00
Zbigniew Jędrzejewski-Szmek dffb827772 resolved: when adding RR to an answer, avoid comparing keys twice
We'd call dns_resource_record_equal(), which calls dns_resource_key_equal()
internally, and then dns_resource_key_equal() a second time. Let's be
a bit smarter, and call dns_resource_key_equal() only once.

(before)
dns_resource_key_hash_func_count=514
dns_resource_key_compare_func_count=275
dns_resource_key_equal_count=62371
4.13s user 0.01s system 99% cpu 4.153 total

(after)
dns_resource_key_hash_func_count=514
dns_resource_key_compare_func_count=276
dns_resource_key_equal_count=31337
2.13s user 0.01s system 99% cpu 2.139 total
2019-03-04 15:53:37 +01:00
Zbigniew Jędrzejewski-Szmek 51969a5893 resolve: split the RR comparison function in two
No functional change.
2019-03-04 15:53:37 +01:00
Zbigniew Jędrzejewski-Szmek 2d34cf0c16 resolved: use a temporary Set to speed up dns question parsing
This doesn't necessarily make things faster, because we still spend more time
in dns_answer_add(), but it improves the compuational complexity of this part.
If we even make dns_resource_key_equal_faster, this will become worthwhile.
2019-03-04 15:53:37 +01:00
Zbigniew Jędrzejewski-Szmek f68a26221c tests: use the test helpers in more places
This is mostly cosmetic. It makes those test binaries support SYSTEMD_LOG_*
environment variables.
2019-03-04 14:15:38 +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
Zbigniew Jędrzejewski-Szmek 0b0bfdb53f
Merge pull request #11512 from poettering/resolved-stub-pipeline
support incoming pipelined TCP stream queries in DNS stub server
2019-02-20 19:03:13 +01:00
Alexander Tsoy 13e6f3831d resolved: correctly prove the non-existense of wildcard
* Current logic:
For each NSEC RR find the common suffix between the owner name and
the next name, append asterisk to that suffix and check that
generated wildcard is covered by the NSEC RR in question.

* New logic:
Find NSEC RR covering queried name, generate wildcard as
<asterisk>.<closest encloser> using this RR, then check if any
of the NSEC RRs covers generated wildcard.
2019-02-18 18:34:53 +01:00
Zbigniew Jędrzejewski-Szmek eb5f4dde96 resolved: use standard paths for .dnssd files
/usr/local/lib/systemd/dnssd is now also included in the search path. This
path is of limited usefulness, but it makes sense to be consistent.

Documentation is updated to match. Outdated advice against drop-ins in /usr
is removed.
2019-02-18 10:25:25 +01:00
Zbigniew Jędrzejewski-Szmek 514fbdd78b resolved: add missing spdx header 2019-02-18 10:25:25 +01:00
Yu Watanabe 4bb91a950a resolve: drop unnecessary %n fields from dns_resource_record_to_string()
And use returned value by asprintf() instead.

This hopefully fixes #11733.
2019-02-16 23:29:08 +01:00
Lennart Poettering b412af57a3 resolved: keep stub stream connections up for as long as client wants
This enables pipelining of queries from clients to our stub server.

Fixes: #11332
2019-02-15 17:13:58 +01:00
Lennart Poettering f447d9e376 resolved: add comment to dns_stream_complete() about its 'error' argument 2019-02-15 17:13:58 +01:00
Lennart Poettering 9c9e017067 resolved: only call complete() with zero argument in LLMNR client cases
In all other cases (i.e. classic DNS connection towards an upstream
server, or incoming stub connection, or incoming LMMNR connection) we
want long-running connections, hence keep the connection open for good.
Only in the LLMNR client case let's close the stream as soon as we are
done.
2019-02-15 17:13:58 +01:00
Lennart Poettering 5971dffd4a resolved: restart stream timeout whenever we managed to read or write something
Previously we'd start the timeout once when we allocated the stream.
However, we'd now like to emphasize long-running connections hence let's
rework the timeout logic, and restart it whenever we see action ont the
stream. Thus, idle streams are eventually closed down, but those where
we read or write from are not.
2019-02-15 17:13:58 +01:00
Lennart Poettering 31f2a5e2b8 llmnr: add comment why we install no complete() handler on stream 2019-02-15 17:13:58 +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 57bdb749b8 stream: follow coding style, don't use degrade-to-bool for checking numeric value 2019-02-15 17:13:58 +01:00
Lennart Poettering 6e9417f5b4 tree-wide: use newa() instead of alloca() wherever we can
Typesafety is nice. And this way we can take benefit of the new size
assert() the previous commit added.
2019-01-26 16:17:04 +01:00
Chris Lamb 4605de118d Correct more spelling errors. 2019-01-23 23:34:52 +01:00
Lennart Poettering fea46786ce resolved: preferably route single-label lookups to unicast DNS scopes with search domains (#11485)
Fixes: #11391
2019-01-22 09:57:49 +01:00
Lennart Poettering 92e31da100 tree-wide: make sure to flush/close all bus connections when our daemons exit
Let's make sure everything is written out ebfore we exit, so that no
messages keep our bus connections referenced.

Fixes: #11462
2019-01-17 16:12:38 +01:00
Topi Miettinen a1e92eee3e Remove 'inline' attributes from static functions in .c files (#11426)
Let the compiler perform inlining (see #11397).
2019-01-15 08:12:28 +01:00
Zbigniew Jędrzejewski-Szmek 690f02f4b8 timesyncd,resolved,machinectl: drop calls to sd_event_get_exit_code()
In all three cases, sd_event_loop() will return the exit code anyway.
If sd_event_loop() returns negative, failure is logged and results in an
immediate return. Otherwise, we don't care if sd_event_loop() returns 0
or positive, because the return value feeds into DEFINE_MAIN_FUNCTION(), which
doesn't make the distinction.
2019-01-08 23:26:07 +01:00
Lennart Poettering be0b7a1a66 tree-wide: always declare bitflag enums the same way
let's always use the 1 << x syntax. No change of behaviour or even of
the compiled binary.
2019-01-07 17:50:39 +01:00
Lennart Poettering fdb4d3138a resolved: read DNS default route option from networkd 2018-12-21 12:10:07 +01:00
Lennart Poettering f2fd3cdb45 resolvectl: add support for reading/writing per-link 'default-route' boolean 2018-12-21 12:10:07 +01:00
Lennart Poettering efe55c8165 resolvectl: minor whitespace fix 2018-12-21 12:10:07 +01:00
Lennart Poettering 77673795dc resolved: add bus API to set per-link "default route" boolean 2018-12-21 12:10:07 +01:00
Lennart Poettering ca5394d260 resolved: add an explicit way to configure whether a link is useful as default route
Previously, we'd use a link as "default" route depending on whether
there are route-only domains defined on it or not. (If there are, it
would not be used as default route, if there aren't it would.)

Let's make this explicit and add a link variable controlling this. The
variable is not changeable from the outside yet, but subsequent commits
are supposed to add that.

Note that making this configurable adds a certain amount of redundancy,
as there are now two ways to ensure a link does not receive "default"
lookup (i.e. DNS queries matching no configured route):

1. By ensuring that at least one other link configures a route on it
   (for example by add "." to its search list)

2. By setting this new boolean to false.

But this is exactly what is intended with this patch: that there is an
explicit way to configure on the link itself whether it receives
'default' traffic, rather than require this to be configured on other
links.

The variable added is a tri-state: if true, the link is suitable for
recieving "default" traffic. If false, the link is not suitable for it.
If unset (i.e. negative) the original logic of "has this route-only
routes" is used, to ensure compatibility with the status quo ante.
2018-12-21 12:10:07 +01:00
Lennart Poettering f76fa08899 resolved: rework dns_server_limited_domains(), replace by dns_scope_has_route_only_domains()
The function dns_server_limited_domains() was very strange as it
enumerate the domains associated with a DnsScope object to determine
whether any "route-only" domains, but did so as a function associated
with a DnsServer object.

Let's clear this up, and replace it by a function associated with a
DnsScope instead. This makes more sense philosphically and allows us to
reduce the loops through which we need to jump to determine whether a
scope is suitable for default routing a bit.
2018-12-21 12:09:00 +01:00
Lennart Poettering 1750854916 resolved: bind .local domains to mDNS with DNS_SCOPE_YES, similar LLMNR
Previously, we'd return DNS_SCOPE_MAYBE for all domain lookups matching
LLMNR or mDNS. Let's upgrade this to DNS_SCOPE_YES, to make the binding
stronger.

The effect of this is that even if "local" is defined as routing domain
on some iface, we'll still lookup domains in local via mDNS — if mDNS is
turned on. This should not be limiting, as people who don't want such
lookups should turn off mDNS altogether, as it is useless if nothing is
routed to it.

This also has the nice benefit that mDNS/LLMR continue to work if people
use "~." as routing domain on some interface.

Similar for LLMNR and single label names.

Similar also for the link local IPv4 and IPv6 reverse lookups.

Fixes: #10125
2018-12-21 11:41:45 +01:00
Lennart Poettering a97a3b256c resolved: rework how we determine which scope to send a query to
Fixes: #10830 #9825 #9472
2018-12-21 11:04:11 +01:00
Lennart Poettering 89307df394 resolved: add comment, explaining when Scope variables are copied from Link 2018-12-21 11:04:11 +01:00
Lennart Poettering 2bfdd6dc54 resolved: rename_DNS_SCOPE_INVALID → _DNS_SCOPE_MATCH_INVALID
The _INVALID and _MAX enum fields should always use the full name of
thenum.
2018-12-21 11:04:11 +01:00
Lennart Poettering dc2bc986eb resolved: check dns_over_tls_mode in link_needs_save()
This was forgotten when DoT was added.
2018-12-21 11:04:11 +01:00
Lennart Poettering 9a1bbc6642 resolved: use structured initialization for DnsScope 2018-12-21 11:04:11 +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 a9238f6a33
Merge pull request #11184 from poettering/resolved-search-domains-max
resolve: bump max of dns servers/search domains
2018-12-17 15:15:45 +01:00
Tore Anderson 93158c77bc resolve: enable EDNS0 towards the 127.0.0.53 stub resolver
This appears to be necessary for client software to ensure the reponse data
is validated with DNSSEC. For example, `ssh -v -o VerifyHostKeyDNS=yes -o
StrictHostKeyChecking=yes redpilllinpro01.ring.nlnog.net` fails if EDNS0 is
not enabled. The debugging output reveals that the `SSHFP` records were
found in DNS, but were considered insecure.

Note that the patch intentionally does *not* enable EDNS0 in the
`/run/systemd/resolve/resolv.conf` file (the one that contains `nameserver`
entries for the upstream DNS servers), as it is impossible to know for
certain that all the upstream DNS servers handles EDNS0 correctly.
2018-12-17 15:15:18 +01:00
Lennart Poettering b950ee06e6 resolve: bump max of dns servers/search domains
Apparently people want more of these (as #11175 shows). Since this is
merely a safety limit for us, let's just bump all values substantially.

Fixes: #11175
2018-12-17 13:34:50 +01:00
Lennart Poettering 2d41e9b7a0
Merge pull request #11143 from keszybz/enable-symlink
Runtime mask symlink confusion fix
2018-12-16 12:37:07 +01:00
Sam Morris 4b987478b0 resolved: have the stub resolver listen on both TCP and UDP by default
RFC7766 section 4 states that in the absence of EDNS0, a response that
is too large for a 512-byte UDP packet will have the 'truncated' bit
set. The client is expected to retry the query over TCP.

Fixes #10264.
2018-12-12 21:21:04 +01:00
Zbigniew Jędrzejewski-Szmek 303ee60151 Mark *data and *userdata params to specifier_printf() as const
It would be very wrong if any of the specfier printf calls modified
any of the objects or data being printed. Let's mark all arguments as const
(primarily to make it easier for the reader to see where modifications cannot
occur).
2018-12-12 16:45:33 +01:00
Chris Down 912b4547b5 Always explicitly discard popped stream type from __fsetlocking
No biggie, but I noticed this while looking into bus_match_to_string.
2018-12-11 18:49:54 +01:00
Lennart Poettering ec68d13789
Merge pull request #10897 from keszybz/etc-fstab-parsing
Forbid dashes in hostnames and /etc/fstab parsing improvements
2018-12-10 12:31:30 +01:00
Zbigniew Jędrzejewski-Szmek 7470cc4c73 resolve: reject host names with leading or trailing dashes in /etc/hosts
https://tools.ietf.org/html/rfc1035#section-2.3.1 says (approximately)
that only letters, numbers, and non-leading non-trailing dashes are allowed
(for entries with A/AAAA records). We set no restrictions.

hosts(5) says:
> Host names may contain only alphanumeric characters, minus signs ("-"), and
> periods (".").  They must begin with an alphabetic character and end with an
> alphanumeric character.

nss-files follows those rules, and will ignore names in /etc/hosts that do not
follow this rule.

Let's follow the documented rules for /etc/hosts. In particular, this makes us
consitent with nss-files, reducing surprises for the user.

I'm pretty sure we should apply stricter filtering to names received over DNS
and LLMNR and MDNS, but it's a bigger project, because the rules differ
depepending on which level the label appears (rules for top-level names are
stricter), and this patch takes the minimalistic approach and only changes
behaviour for /etc/hosts.

Escape syntax is also disallowed in /etc/hosts, even if the resulting character
would be allowed. Other tools that parse /etc/hosts do not support this, and
there is no need to use it because no allowed characters benefit from escaping.
2018-12-10 09:56:56 +01:00
Zbigniew Jędrzejewski-Szmek bd00527779 resolved: rework parsing of /etc/hosts
Do not treat various errors (missing hostname, invalid address) as fatal,
just warn and continue. /etc/hosts is written by humans and we should not
reject the whole file just because a singly entry is not to our liking.

Handle comments as described in hosts(5):
everything from the comment character until the end of the line should be
ignored.

Fixes #10779.

Add tests.
2018-12-10 09:56:56 +01:00