Commit Graph

56 Commits

Author SHA1 Message Date
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 c52a97b896 resolved: when outputting RRs in text form, append a trailing dot to owner names
After all, that's how this is done in DNS, and is particularly important
if we look a DS/DNSKEY RRs for the root zone itself, where the owner
name would otherwise be shown as completely empty (i.e. missing).
2015-12-10 11:28:01 +01:00
Lennart Poettering 4d247a6cd3 resolved: shortcut RR comparisons if pointers match
When iterating through RR lists we frequently end up comparing RRs and
RR keys with themselves, hence att a minor optimization to check ptr
values first, before doing a deep comparison.
2015-12-10 11:28:01 +01:00
Lennart Poettering 28b9b76406 resolved: rework how we allow allow queries to be dispatched to scopes
Previously, we'd never do any single-label or root domain lookups via
DNS, thus leaving single-label lookups to LLMNR and the search path
logic in order that single-label names don't leak too easily onto the
internet. With this change we open things up a bit, and only prohibit
A/AAAA lookups of single-label/root domains, but allow all other
lookups. This should provide similar protection, but allow us to resolve
DNSKEY+DS RRs for the top-level and root domains.

(This also simplifies handling of the search domain detection, and gets
rid of dns_scope_has_search_domains() in favour of
dns_scope_get_search_domains()).
2015-12-03 21:17:49 +01:00
Lennart Poettering 1b4f6e79ec resolved: optionally, allocate DnsResourceKey objects on the stack
Sometimes when looking up entries in hashmaps indexed by a
DnsResourceKey it is helpful not having to allocate a full
DnsResourceKey dynamically just to use it as search key. Instead,
optionally allow allocation of a DnsResourceKey on the stack. Resource
keys allocated like that of course are subject to other lifetime cycles
than the usual Resource keys, hence initialize the reference counter to
to (unsigned) -1.

While we are at it, remove the prototype for
dns_resource_key_new_dname() which was never implemented.
2015-12-03 21:17:49 +01:00
Lennart Poettering 8730bccfc5 resolved: move algorithm/digest definitions into resolved-dns-rr.h
After all, they are for flags and parameters of RRs and already relevant
when dealing with RRs outside of the serialization concept.
2015-12-03 00:26:58 +01:00
Lennart Poettering a8812dd7f1 resolved: add code to generate the wire format for a single RR
This adds dns_resource_record_to_wire_format() that generates the raw
wire-format of a single DnsResourceRecord object, and caches it in the
object, optionally in DNSSEC canonical form. This call is used later to
generate the RR serialization of RRs to verify.

This adds four new fields to DnsResourceRecord objects:

- wire_format points to the buffer with the wire-format version of the
  RR
- wire_format_size stores the size of that buffer
- wire_format_rdata_offset specifies the index into the buffer where the
  RDATA of the RR begins (i.e. the size of the key part of the RR).
- wire_format_canonical is a boolean that stores whether the cached wire
  format is in DNSSEC canonical form or not.

Note that this patch adds a mode where a DnsPacket is allocated on the
stack (instead of on the heap), so that it is cheaper to reuse the
DnsPacket object for generating this wire format. After all we reuse the
DnsPacket object for this, since it comes with all the dynamic memory
management, and serialization calls we need anyway.
2015-12-02 22:50:11 +01:00
Lennart Poettering f91dc2400d resolved: store DNSKEY fields flags+protocol as-is
When verifying signatures we need to be able to verify the original
data we got for an RR set, and that means we cannot simply drop flags
bits or consider RRs invalid too eagerly. Hence, instead of parsing the
DNSKEY flags store them as-is. Similar, accept the protocol field as it
is, and don't consider it a parsing error if it is not 3.

Of course, this means that the DNSKEY handling code later on needs to
check explicit for protocol != 3.
2015-12-02 22:50:11 +01:00
Lennart Poettering dc477e7385 dns-domain: simplify dns_name_is_root() and dns_name_is_single_label()
Let's change the return value to bool. If we encounter an error while
parsing, return "false" instead of the actual parsing error, after all
the specified hostname does not qualify for what the function is
supposed to test.

Dealing with the additional error codes was always cumbersome, and
easily misused, like for example in the DHCP code.

Let's also rename the functions from dns_name_root() to
dns_name_is_root(), to indicate that this function checks something and
returns a bool. Similar for dns_name_is_signal_label().
2015-11-25 22:00:07 +01:00
Lennart Poettering 801ad6a6a9 resolved: fully support DNS search domains
This adds support for searching single-label hostnames in a set of
configured search domains.

A new object DnsQueryCandidate is added that links queries to scopes.
It keeps track of the search domain last used for a query on a specific
link. Whenever a host name was unsuccessfuly resolved on a scope all its
transactions are flushed out and replaced by a new set, with the next
search domain appended.

This also adds a new flag SD_RESOLVED_NO_SEARCH to disable search domain
behaviour. The "systemd-resolve-host" tool is updated to make this
configurable via --search=.

Fixes #1697
2015-11-25 21:59:16 +01:00
Lennart Poettering 58db254ade resolved: implement client-side DNAME resolution
Most servers apparently always implicitly convert DNAME to CNAME, but
some servers don't, hence implement this properly, as this is required
by edns0.
2015-11-24 00:20:39 +01:00
Lennart Poettering 2001c80560 resolved: accept TXT records with non-UTF8 strings
RFC 6763 is very clear that TXT RRs should allow arbitrary binary
content, hence let's actually accept that. This also means accepting NUL
bytes in the middle of strings.
2015-11-23 21:31:28 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering e4e73a6325 util-lib: split out hex/dec/oct encoding/decoding into its own file 2015-10-27 13:25:55 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Tom Gundersen b826ab586c hashmap: refactor hash_func
All our hash functions are based on siphash24(), factor out
siphash_init() and siphash24_finalize() and pass the siphash
state to the hash functions rather than the hash key.

This simplifies the hash functions, and in particular makes
composition simpler as calling siphash24_compress() repeatedly
on separate chunks of input has the same effect as first
concatenating the input and then calling siphash23_compress()
on the result.
2015-10-05 18:22:10 +02:00
Tom Gundersen 36d9205d66 resolved: rr - introduce dns_resource_key_new_redirect()
Takes a key and CNAME RR and returns the canonical RR of the right
type. Make use of this in dns_question_redirect().
2015-09-16 17:03:17 +02:00
Tom Gundersen 7c1ff6ac3d resolved: rr - introduce dns_resource_key_new_cname()
Creates a new CNAME RR key with the same class and name as an existing key.
2015-09-16 17:03:17 +02:00
Lennart Poettering 78c6a153c4 resolved: rework synthesizing logic
With this change we'll now also generate synthesized RRs for the local
LLMNR hostname (first label of system hostname), the local mDNS hostname
(first label of system hostname suffixed with .local), the "gateway"
hostname and all the reverse PTRs. This hence takes over part of what
nss-myhostname already implemented.

Local hostnames resolve to the set of local IP addresses. Since the
addresses are possibly on different interfaces it is necessary to change
the internal DnsAnswer object to track per-RR interface indexes, and to
change the bus API to always return the interface per-address rather than
per-reply. This change also patches  the existing clients for resolved
accordingly (nss-resolve + systemd-resolve-host).

This also changes the routing logic for queries slightly: we now ensure
that the local hostname is never resolved via LLMNR, thus making it
trustable on the local system.
2015-08-21 12:41:08 +02:00
Daniel Mack 816b4547da resolved: fix DNS_TYPE_ANY vs DNS_CLASS_ANY confusion
Assigning a TPYE enum value to a class variable is certainly wrong.
However, they both have the same value, so the result was correct
nevertheless.
2015-07-24 19:54:00 +02:00
Tom Gundersen 549c1a2564 resolved: rr - SSHFP contains the fingerprint, not the key
Rename the field to make this clearer.
2015-07-23 18:01:50 +02:00
Tom Gundersen b96c778a00 Merge pull request #669 from poettering/dns-rr-memdup
resolve: unify memdup() code when parsing RRs
2015-07-23 12:34:34 +02:00
Lennart Poettering f5430a3ef3 resolve: unify memdup() code when parsing RRs
Let's make dns_packet_read_public_key() more generic by renaming it to
dns_packet_read_memdup() (which more accurately describes what it
does...). Then, patch all cases where we memdup() RR data to use this
new call.

This specifically checks for zero-length objects, and handles them
gracefully. It will set zero length payload fields as a result.

Special care should be taken to ensure that any code using this call
can handle the returned allocated field to be NULL if the size is
specified as 0!
2015-07-23 04:50:19 +02:00
Lennart Poettering 2c1fb4f712 resolve: fix two minor memory leaks
strv_extend() already strdup()s internally, no need to to this twice.
(Also, was missing OOM check...).

Use strv_consume() when we already have a string allocated whose
ownership we want to pass to the strv.

This fixes 50f1e641a9.
2015-07-23 03:26:01 +02:00
Tom Gundersen cb57dd4159 bitmap: use external iterator
Reuse the Iterator object from hashmap.h and expose a similar API.

This allows us to do

{
    Iterator i;
    unsigned n;

    BITMAP_FOREACH(n, b, i) {
        Iterator j;
        unsigned m;

        BITMAP_FOREACH(m, b, j) {
            ...
        }
    }
}

without getting confused. Requested by David.
2015-07-16 14:11:12 +02:00
Tom Gundersen 5d45a88084 resolved: rr - add NSEC3 support
Needed for DNSSEC.
2015-07-14 22:17:24 +02:00
Tom Gundersen 50f1e641a9 resolved: rr - add NSEC support
Needed for DNSSEC.
2015-07-14 21:53:10 +02:00
Tom Gundersen d23a27a964 resolved: improve printing of unknown RRs
This implements the recommendations from RFC3597.
2015-07-14 19:36:35 +02:00
Tom Gundersen abf126a355 resolved: rr - add DS support
Needed for DNSSEC.
2015-07-14 19:16:16 +02:00
Tom Gundersen 7c6423e191 resolved: rr - print formated timestamps in RRSIG 2015-07-14 19:16:12 +02:00
Tom Gundersen 1bf968f363 resolved: rr - print DNSKEY and RRSIG in base64
As mandated by RFC4034.
2015-07-14 01:18:51 +02:00
Nick Owens 4ad7f2761d resolve: move dns routines into shared 2015-06-10 11:15:45 -07:00
David Herrmann 0f84a72e3c resolve: fix NULL deref on strv comparison
A strv might be NULL if it is empty. The txt.strings comparison doesn't
take that into account. Introduce strv_equal() to provide a proper helper
for this and fix resolve to use it.

Thanks to Stanisław Pitucha <viraptor@gmail.com> for reporting this!
2014-11-27 16:10:44 +01:00
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02:00
Lukas Nykryn 03664a6291 resolved-dns-rr: fix typo
a->rrsig.type_covered != a->rrsig.type_covered" is always false
regardless of the values of its operands because those operands are identical.
2014-08-20 14:34:26 +02:00
Zbigniew Jędrzejewski-Szmek 151226ab4b resolved: RRSIG records 2014-08-03 22:02:32 -04:00
Zbigniew Jędrzejewski-Szmek ff3d6560be resolved: add identifiers for dnssec algorithms 2014-08-03 22:02:32 -04:00
Zbigniew Jędrzejewski-Szmek 8db0d2f5c3 resolved: DNSKEY records 2014-08-03 22:02:32 -04:00
Zbigniew Jędrzejewski-Szmek 7263f72499 resolve: add more record types and convert to gperf table
We are unlikely to evert support most of them, but we can at least
display the types properly.

The list is taken from the IANA list.

The table of number->name mappings is converted to a switch
statement. gcc does a nice job of optimizing lookup (when optimization
is enabled).

systemd-resolve-host -t is now case insensitive.
2014-08-03 22:02:32 -04:00
Zbigniew Jędrzejewski-Szmek 23432a1c24 resolved: align last rr column 2014-08-03 21:46:08 -04:00
Lennart Poettering fd0b4602f6 resolved: properly compare RRs we cannot parse 2014-07-31 18:41:54 +02:00
Lennart Poettering 42cc2eebb0 resolved: properly process SSHFP RRs 2014-07-31 18:41:41 +02:00
Lennart Poettering 9c92ce6d67 resolved: properly process SRV records 2014-07-31 18:23:34 +02:00
Lennart Poettering 8ac4e9e1e5 resolved: properly process DNAME RRs 2014-07-31 18:02:24 +02:00
Zbigniew Jędrzejewski-Szmek 0dae31d468 resolved: LOC records
LOC records have a version field. So far only version 0 has been
published, but if a record with a different version was encountered,
our only recourse is to treat it as an unknown type. This is
implemented with the 'unparseable' flag, which causes the
serialization/deserialization and printing function to cause the
record as a blob. The flag can be used if other packet types cannot be
parsed for whatever reason.
2014-07-31 08:56:03 -04:00
Zbigniew Jędrzejewski-Szmek 9de3e32940 resolved: SPF records 2014-07-31 08:56:03 -04:00
Zbigniew Jędrzejewski-Szmek 2e276efc7b resolved: TXT records 2014-07-31 08:56:03 -04:00
Zbigniew Jędrzejewski-Szmek 946c70944e resolved: MX records 2014-07-31 08:56:03 -04:00
Lennart Poettering 2d4c5cbc0e resolved: add API for resolving specific RRs 2014-07-30 19:24:13 +02:00