Commit Graph

80 Commits

Author SHA1 Message Date
Torstein Husebø 61233823aa treewide: fix typos and remove accidental repetition of words 2016-07-11 16:18:43 +02:00
Martin Pitt 54522e941d Merge pull request #3594 from poettering/resolved-servfail
resolved fixes for handling SERVFAIL errors from servers
2016-06-24 08:01:49 +02:00
Lennart Poettering 6ff01a0d64 resolved: when caching replies, check rcode earlier
This way we don't log complaints about packets without SOA in case we are not
caching it anyway because the rcode is not SUCCESS or NXDOMAIN...
2016-06-23 23:36:10 +02:00
Lennart Poettering 17c8de633f resolved: when using the ResolveRecord() bus call, adjust TTL for caching time
When we return the full RR wire data, let's make sure the TTL included in it is
adjusted by the time the RR sat in the cache.

As an optimization we do this only for ResolveRecord() and not for
ResolveHostname() and friends, since adjusting the TTL means copying the RR
object, and we don#t want to do that if there's no reason to.
(ResolveHostname() and friends don't return the TTL hence there's no reason to
in that case)
2016-06-21 13:20:48 +02:00
Vito Caputo 313cefa1d9 tree-wide: make ++/-- usage consistent WRT spacing
Throughout the tree there's spurious use of spaces separating ++ and --
operators from their respective operands.  Make ++ and -- operator
consistent with the majority of existing uses; discard the spaces.
2016-02-22 20:32:04 -08:00
Zbigniew Jędrzejewski-Szmek 18665d1f67 resolved: fix NULL dereference in debug stmt
CID #1351544, #1351545.
2016-02-19 07:27:43 -05:00
Zbigniew Jędrzejewski-Szmek 202b76ae1a Use provided buffer in dns_resource_key_to_string
When the buffer is allocated on the stack we do not have to check for
failure everywhere. This is especially useful in debug statements, because
we can put dns_resource_key_to_string() call in the debug statement, and
we do not need a seperate if (log_level >= LOG_DEBUG) for the conversion.

dns_resource_key_to_string() is changed not to provide any whitespace
padding. Most callers were stripping the whitespace with strstrip(),
and it did not look to well anyway. systemd-resolve output is not column
aligned anymore.

The result of the conversion is not stored in DnsTransaction object
anymore. It is used only for debugging, so it seems fine to generate it
when needed.

Various debug statements are extended to provide more information.
2016-02-16 19:55:51 -05:00
Zbigniew Jędrzejewski-Szmek 1c02e7ba55 Replace DNS_RESOURCE_KEY_NAME with a version which always returns "." for root
This fixes formatting of root domain in debug messages:
Old:
systemd-resolved[10049]: Requesting DS to validate transaction 19313 (., DNSKEY with key tag: 19036).
New:
systemd-resolved[10049]: Requesting DS to validate transaction 19313 (, DNSKEY with key tag: 19036).
2016-02-16 19:55:51 -05:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Lennart Poettering 06d1275435 resolved: correctly store interface index of RRs in cache
Fixes: #2361
2016-02-04 01:10:36 +01:00
Lennart Poettering f6618dcd96 resolved: never store NSEC/NSEC3 RRs from the upper zone of a zone cut in cache
When using NSEC/NSEC3 RRs from the cache to derive existance of arbitrary RRs, we should not get confused by the fact
that NSEC/NSEC3 RRs exist twice at zone cuts: once in the parent zone, and once in the child zone. For most RR types we
should only consult the latter since that's where the beef is. However, for DS lookups we have to check the former.

This change makes sure we never cache NSEC/NSEC3 RRs from any parent zone of a zone-cut. It also makes sure that when
we look for a DS RR in the cache we never consider any cached NSEC RR, as those are now always from the child zone.
2016-01-25 17:19:19 +01:00
Lennart Poettering f57e3cd5fa resolved: try to reduce number or DnsResourceKeys we keep around by merging them
Quite often we read the same RR key multiple times from the same message. Try to replace them by a single object when
we notice this. Do so again when we add things to the cache.

This should reduce memory consumption a tiny bit.
2016-01-17 20:47:46 +01:00
Lennart Poettering d3760be01b resolved: when caching negative responses, honour NSEC/NSEC3 TTLs
When storing negative responses, clamp the SOA minimum TTL (as suggested
by RFC2308) to the TTL of the NSEC/NSEC3 RRs we used to prove
non-existance, if it there is any.

This is necessary since otherwise an attacker might put together a faked
negative response for one of our question including a high-ttl SOA RR
for any parent zone, and we'd use trust the TTL.
2016-01-05 01:35:28 +01:00
Lennart Poettering 6af47493de resolved: add comments referencing various RFCs to various places 2015-12-29 21:42:10 +01:00
Lennart Poettering b211dc7e83 resolved: also use RRSIG expiry for negative caching
This makes sure that we also honour the RRSIG expiry for negative
caching.
2015-12-28 14:46:39 +01:00
Lennart Poettering ee3d6aff9b resolved: use RRSIG expiry and original TTL for cache management
When we verified a signature, fix up the RR's TTL to the original TTL
mentioned in the signature, and store the signature expiry information
in the RR, too. Then, use that when adding RRs to the cache.
2015-12-28 14:46:39 +01:00
Lennart Poettering a150ff5e4e resolved: gather statistics about resolved names
This collects statistical data about transactions, dnssec verifications
and the cache, and exposes it over the bus. The systemd-resolve-host
tool learns new options to query these statistics and reset them.
2015-12-26 19:09:10 +01:00
Lennart Poettering 7b50eb2efa resolved: internalize string buffer of dns_resource_record_to_string()
Let's simplify usage and memory management of DnsResourceRecord's
dns_resource_record_to_string() call: cache the formatted string as
part of the object, and return it on subsequent calls, freeing it when
the DnsResourceRecord itself is freed.
2015-12-26 19:09:10 +01:00
Lennart Poettering a5444ca9fd resolved: when caching NXDOMAIN for an RR, make sure we flush out old ANY entries
We use ANY RR keys to store NXDOMAIN information, but we previously
didn't flush out old ANY RR items in the cache when adding new entries.
Fix that.
2015-12-26 19:09:09 +01:00
Lennart Poettering d3c7e9139c resolved: split out a new dns_type_may_redirect() call
Let's abstract which RRs shall honour CNAMEs, and which ones should not.
2015-12-26 19:09:09 +01:00
Lennart Poettering 98b6be7784 resolved: merge two comments 2015-12-18 19:47:24 +01:00
Lennart Poettering 39963f1123 resolved: rename dns_cache_item_remove_and_free() → _unlink_and_free()
In most of the other call, we called similar functions that remove the
data structure link-ups to other objects "unlink", hence we should here,
too.
2015-12-18 19:44:15 +01:00
Lennart Poettering 2dda578f1e resolved: rename dns_cache_remove() → dns_cache_remove_by_key()
Given that we already have dns_cache_remove_by_rr() this makes clearer
what the operation actually does.
2015-12-18 19:43:10 +01:00
Lennart Poettering d2579eec5e resolved: rework mDNS cache-flush bit handling
This adds a new DnsAnswer item flag "DNS_ANSWER_SHARED_OWNER" which is
set for mDNS RRs that lack the cache-flush bit. The cache-flush bit is
removed from the DnsResourceRecord object in favour of this.

This also splits out the code that removes previous entries when adding
new positive ones into a new separate call dns_cache_remove_previous().
2015-12-18 19:40:47 +01:00
Lennart Poettering ea207b639a resolved: properly determine size of DnsAnswer object
After all we want to allow NULL DnsAnswer objects as equivalent to empty
ones, hence we should use the right checks everywhere.
2015-12-18 19:31:21 +01:00
Lennart Poettering eed749cca6 resolved: pass out precise authenticated bit we got passed in
Make sure the cache never altes the authenticated bit of RRs stored in
it, and drops it for RRs when passing it out again.
2015-12-18 19:29:50 +01:00
Lennart Poettering ef9a3e3c28 resolve: optimize dns_cache_flush() a bit
Let's use dns_cache_remove() rather than
dns_cache_item_remove_and_free() to destroy the cache, since the former
requires far fewer hash table lookups.
2015-12-18 19:25:04 +01:00
Lennart Poettering f5bdeb01e4 resolved: when receiving a TTL=0 RR, only flush that specific RR
When we receieve a TTL=0 RR, then let's only flush that specific RR and
not the whole RRset.

On mDNS with RRsets that a shared-owner this is how specific RRs are
removed from the set, hence support this. And on non-mDNS the whole
RRset will already be removed much earlier in dns_cache_put() hence
there's no reason remove it again.
2015-12-18 19:22:26 +01:00
Lennart Poettering 1f97052fe0 resolved: optimize dns_cache_remove() a bit 2015-12-18 19:19:56 +01:00
Lennart Poettering 950b692bfb resolved: use dns_name_parent() where appropriate 2015-12-18 19:15:34 +01:00
Lennart Poettering fd009cd80e resolved: check SOA authentication state when negative caching
We should never use the TTL of an unauthenticated SOA to cache an
authenticated RR.
2015-12-18 19:12:48 +01:00
Lennart Poettering 1069048089 resolved: don't call dns_cache_remove() from dns_cache_put_negative()
We call it anyway as one of the first calls in dns_cache_put(), hence
there's no reason to do this multiple times.
2015-12-18 19:09:27 +01:00
Lennart Poettering d98e550420 resolved: bump cache size a bit
Let's keep entries for longer and more of them. After all, due to the
DNSSEC hookup the amount of RRs we need to store is much higher now.
2015-12-18 19:07:31 +01:00
Lennart Poettering 222148b66d resolved: make use of dns_{class|type}_is_{pseudo|valid_rr}() everywhere 2015-12-18 19:06:23 +01:00
Lennart Poettering 105e151299 resolved: add support NSEC3 proofs, as well as proofs for domains that are OK to be unsigned
This large patch adds a couple of mechanisms to ensure we get NSEC3 and
proof-of-unsigned support into place. Specifically:

- Each item in an DnsAnswer gets two bit flags now:
  DNS_ANSWER_AUTHENTICATED and DNS_ANSWER_CACHEABLE. The former is
  necessary since DNS responses might contain signed as well as unsigned
  RRsets in one, and we need to remember which ones are signed and which
  ones aren't. The latter is necessary, since not we need to keep track
  which RRsets may be cached and which ones may not be, even while
  manipulating DnsAnswer objects.

- The .n_answer_cachable of DnsTransaction is dropped now (it used to
  store how many of the first DnsAnswer entries are cachable), and
  replaced by the DNS_ANSWER_CACHABLE flag instead.

- NSEC3 proofs are implemented now (lacking support for the wildcard
  part, to be added in a later commit).

- Support for the "AD" bit has been dropped. It's unsafe, and now that
  we have end-to-end authentication we don't need it anymore.

- An auxiliary DnsTransaction of a DnsTransactions is now kept around as
  least as long as the latter stays around. We no longer remove the
  auxiliary DnsTransaction as soon as it completed. THis is necessary,
  as we now are interested not only in the RRsets it acquired but also
  in its authentication status.
2015-12-18 14:48:50 +01:00
Thomas Hindoe Paaboel Andersen b78b0b674f resolve: remove unused variable 2015-12-16 19:59:45 +01:00
Lennart Poettering c33be4a6f2 resolved: refuse to cache ANY kind of pseudo-RR-type 2015-12-11 14:14:27 +01:00
Tom Gundersen a257f9d4a5 resolved: cache - only stringify RR keys when in debug mode
This is in the fast path, so let's not do all this work unneccessarily.
2015-12-10 20:17:49 +01:00
Tom Gundersen 02c2857b8d resolved: cache - don't flush the cache of mDNS records unneccesarily
When the DNS_RESOURCE_KEY_CACHE_FLUSH flag is not set for an mDNS packet, we should not flush
the cache for RRs with matching keys. However, we were unconditionally flushing the cache
also for these packets.

Now mark all packets as cache_flush by default, except for these mDNS packets, and respect
that flag in the cache handling.

This fixes 90325e8c2e.
2015-12-10 20:15:58 +01:00
Tom Gundersen d7ce6c9464 resolved: cache - rework which RR types we apply redirection to
The logic of dns_cache_get() is now:
 - look up the precise key;
 - look up NXDOMAIN item;
 - if an RR type that may be redirected
   (i.e., not CNAME, DNAME, RRSIG, NSEC, NSEC3, SIG, KEY, or
   NXT) look up a correpsonding CNAME or DNAME record;
 - look up a corresponding NSEC record;

Before this change we would give up before potentially finding
negative cache entries for DNAME, CNAME and NSEC records, we
would return NSEC records for aliases where we had DNAME or CNAME
records available and we would incorrectly try to redirect DNSSEC RRs.
2015-12-10 17:06:26 +01:00
Tom Gundersen c3cb6dc20b resolved: cache - improve logging
Some DNS servers will hand out negative answers without SOA records,
these can not be cached, so log about that fact.
2015-12-10 17:06:26 +01:00
Tom Gundersen 71e136699c resolved: cache - don't cache NXDOMAIN by TYPE
An NXDOMAIN entry means there are no RRs of any type for a name,
so only cache by CLASS + NAME, rather than CLASS + NAME + TYPE.
2015-12-10 17:06:26 +01:00
Tom Gundersen 5d27351f85 resolved: cache - do negative caching only on the canonical name
Apart from dropping redundant information, this fixes an issue
where, due to broken DNS servers, we can only be certain of whether
an apparent NODATA response is in fact an NXDOMAIN response after
explicitly resolving the canonical name. This issue is outlined in
RFC2308. Moreover, by caching NXDOMAIN for an existing name, we
would mistakenly return NXDOMAIN for types which should not be
redirected. I.e., a query for AAAA on test-nx-1.jklm.no correctly
returns NXDOMAIN, but a query for CNAME should return the record
and a query for DNAME should return NODATA.

Note that this means we will not cache an NXDOMAIN response in the
presence of redirection, meaning one redundant roundtrip in case the
name is queried again.
2015-12-10 17:04:42 +01:00
Lennart Poettering 547973dea7 resolved: chase DNSKEY/DS RRs when doing look-ups with DNSSEC enabled
This adds initial support for validating RRSIG/DNSKEY/DS chains when
doing lookups. Proof-of-non-existance, or proof-of-unsigned-zones is not
implemented yet.

With this change DnsTransaction objects will generate additional
DnsTransaction objects when looking for DNSKEY or DS RRs to validate an
RRSIG on a response. DnsTransaction objects are thus created for three
reasons now:

1) Because a user asked for something to be resolved, i.e. requested by
   a DnsQuery/DnsQueryCandidate object.
2) As result of LLMNR RR probing, requested by a DnsZoneItem.
3) Because another DnsTransaction requires the requested RRs for
   validation of its own response.

DnsTransactions are shared between all these users, and are GC
automatically as soon as all of these users don't need a specific
transaction anymore.

To unify the handling of these three reasons for existance for a
DnsTransaction, a new common naming is introduced: each DnsTransaction
now tracks its "owners" via a Set* object named "notify_xyz", containing
all owners to notify on completion.

A new DnsTransaction state is introduced called "VALIDATING" that is
entered after a response has been receieved which needs to be validated,
as long as we are still waiting for the DNSKEY/DS RRs from other
DnsTransactions.

This patch will request the DNSKEY/DS RRs bottom-up, and then validate
them top-down.

Caching of RRs is now only done after verification, so that the cache is
not poisoned with known invalid data.

The "DnsAnswer" object gained a substantial number of new calls, since
we need to add/remove RRs to it dynamically now.
2015-12-10 11:35:52 +01:00
Lennart Poettering 0bb4749d1f resolved: partially revert 5eefe54
Quoting @teg:

"Contrary to what the comment said, we always verify redirect chains in
full, and cache all the CNAME records. There is therefore no need to
do extra negative caching along a CNAME chain."

This simply steals @teg's commit since we'll touch the SOA matching case
in a later patch, and rather want this bit gone, so that we don't have
to "fix" it, only to remove it later on.
2015-12-10 11:28:01 +01:00
Daniel Mack 261f3673c1 resolved: add more linked packets for overlong known answers
For mDNS, if we're unable to stuff all known answers into the given packet,
allocate a new one, push the RR into that one and link it to the current
one.
2015-12-10 10:21:50 +01:00
Daniel Mack 7778dffff3 resolved: add dns_cache_export_to_packet()
This new functions exports cached records of type PTR, SRV and TXT into
an existing DnsPacket. This is used in order to fill in known records
to mDNS queries, for known answer supression.
2015-12-08 16:51:41 +01:00
Daniel Mack 90325e8c2e resolved: flush keys when DNS_RESOURCE_KEY_CACHE_FLUSH is set
In mDNS, DNS_RESOURCE_KEY_CACHE_FLUSH denotes whether other records with the
same key should be flushed from the cache.
2015-12-08 16:51:39 +01:00
Lennart Poettering 931851e8e4 resolved: add a concept of "authenticated" responses
This adds a new SD_RESOLVED_AUTHENTICATED flag for responses we return
on the bus. When set, then the data has been authenticated. For now this
mostly reflects the DNSSEC AD bit, if DNSSEC=trust is set. As soon as
the client-side validation is complete it will be hooked up to this flag
too.

We also set this bit whenver we generated the data ourselves, for
example, because it originates in our local LLMNR zone, or from the
built-in trust anchor database.

The "systemd-resolve-host" tool has been updated to show the flag state
for the data it shows.
2015-12-03 21:17:49 +01:00
Lennart Poettering 3ba27cd339 resolved: when synthesizing NODATA from cached NSEC bitmaps, honour CNAME/DNAME
When an RR type is not set in an NSEC, then the CNAME/DNAME types might
still be, hence check them too.

Otherwise we might end up refusing resolving of CNAME'd RRs if we cached
an NSEC before.
2015-12-03 21:17:49 +01:00