Commit graph

260 commits

Author SHA1 Message Date
Tom Gundersen 3b31df8301 resolved: transaction - increase number of retry attempts
With the exponential backoff, we can perform more requests in the same amount of time,
so bump this a bit.

In case of large RTT this may be necessary in order not to regress, and in case
of large packet-loss it will make us more robust. The latter is particularly
relevant once we start probing for features (and hence may see packet-loss
until we settle on the right feature level).
2015-08-03 14:25:49 +02:00
Tom Gundersen 9df3ba6c6c resolved: transaction - exponentially increase retry timeouts
Rather than fixing this to 5s for unicast DNS and 1s for LLMNR, start
at a tenth of those values and increase exponentially until the old
values are reached. For LLMNR the recommended timeout for IEEE802
networks (which basically means all of the ones we care about) is 100ms,
so that should be uncontroversial. For unicast DNS I have found no
recommended value. However, it seems vastly more likely that hitting a
500ms timeout is casued by a packet loss, rather than the RTT genuinely
being greater than 500ms, so taking this as a startnig value seems
reasonable to me.

In the common case this greatly reduces the latency due to normal packet
loss. Moreover, once we get support for probing for features, this means
that we can send more packets before degrading the feature level whilst
still allowing us to settle on the correct feature level in a reasonable
timeframe.

The timeouts are tracked per server (or per scope for the multicast
protocols), and once a server (or scope) receives a successfull package
the timeout is reset. We also track the largest RTT for the given
server/scope, and always start our timouts at twice the largest
observed RTT.
2015-08-03 14:06:58 +02:00
Tom Gundersen 240b589b14 resolved: cache - use clock_boottime_or_monotonic()
We cannot rely on CLOCK_BOOTTIME being supported by the kernel, so fallack
to CLOCK_MONOTONIC if the former is not supported.
2015-08-03 13:42:44 +02:00
Daniel Mack 3512af1706 Merge pull request #768 from poettering/resolved-localhost
resolved: never attempt to resolve loopback addresses via DNS/LLMNR/mDNS
2015-07-29 12:44:22 +02:00
Lennart Poettering 9436e8cae4 resolved: never attempt to resolve loopback addresses via DNS/LLMNR/mDNS
We already refuse to resolve "localhost", hence we should also refuse
resolving "127.0.0.1" and friends.
2015-07-29 12:30:49 +02:00
Torstein Husebø 94e5ba370a treewide: fix typos 2015-07-29 12:29:46 +02:00
Tom Gundersen bfcc67093d resolved: packet - refuse empty type bitmaps
The NSEC type itself must at least be in the bitmap, so NSEC records with empty
bitmaps must be bogus.
2015-07-28 23:25:52 +02:00
Tom Gundersen 2ad613addb resolved: packet - fix read_type_window()
We were tracking the bit offset inside each byte, rather than inside the whole bitmap.
2015-07-28 23:25:52 +02:00
Tom Gundersen 1792f2231f resolve: packet - fix append_types()
We were counting the number of bits set rather than the number of bytes they occupied.
2015-07-28 23:25:52 +02:00
Lennart Poettering 1086182d83 resolved: compare dns question arrays properly
Let's optimize things a bit and properly compare DNS question arrays,
instead of checking if they are mutual supersets. This also makes ANY
query handling more accurate.
2015-07-28 18:38:54 +02:00
Tom Gundersen c73ee39d10 resolved: transaction - don't explicitly verify packet source
This is handled by the kernel now that the socket is connect()ed.
2015-07-27 20:34:28 +02:00
Tom Gundersen 088480faf1 resolved: transaction - don't unref server when creating TCP socket
This was a bug.
2015-07-27 20:34:15 +02:00
Tom Gundersen 72290734be resolved: scope - write() unicast DNS packets
As we have connect()ed to the desired DNS server, we no longer need to pass
control messages manually when sending packets. Simplify the logic accordingly.
2015-07-27 20:32:24 +02:00
Tom Gundersen 471d40d92f resolved: transaction - introduce dns_transaction_emit()
This function emits the UDP packet via the scope, but first it will
determine the current server (and connect to it) and store the
server in the transaction.

This should not change the behavior, but simplifies the code.
2015-07-27 20:30:54 +02:00
Tom Gundersen c19ffd9fbf resolved: transaction - move a couple of functions
No functional change, but makes follow-up patch clearer.
2015-07-27 20:18:43 +02:00
Tom Gundersen 0db643664c resolved: transaction - move DNS UDP socket creation to the scope
With access to the server when creating the socket, we can connect()
to the server and hence simplify message sending and receiving in
follow-up patches.
2015-07-27 20:13:11 +02:00
Tom Gundersen 647f6aa8fc resolved: transaction - close socket when changing server
Close the socket when changing the server in a transaction, in
order for it to be reopened with the right server when we send
the next packet.

This fixes a regression where we could get stuck with a failing
server.
2015-07-27 20:01:07 +02:00
Tom Gundersen 86ad4cd709 resolved: transaction - don't request PKTINFO for unicast DNS
This was only ever used by LLMNR, so don't request this for unicast DNS packets.
2015-07-27 19:56:45 +02:00
Tom Gundersen 0eb99d0a6a resloved: transaction - unify IPv4 and IPv6 sockets
A transaction can only have one socket at a time, so no need to distinguish these.
2015-07-27 19:52:48 +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 6709eb94f9 resolve: transaction - stop processing packet when found to be invalid
We were stopping the transaction, but we need to stop processing the packet alltogether.
2015-07-23 18:06:50 +02:00
Tom Gundersen 0e03ade57e resolved: packet - fix segfault in truncate()
A size_t was being accessed as a char* due to the order of arguments being inverted.
2015-07-23 18:06:50 +02:00
Tom Gundersen 8e6edc490c resolved: rr - ignore pseudo types in NSEC(3) bitmaps 2015-07-23 18:06:50 +02:00
Tom Gundersen 0bbd72b2f3 resolved: rr - fix parsing of NSEC3
We were appending rather than reading the bitmap.
2015-07-23 18:06:50 +02:00
Tom Gundersen 89492aaf99 resolved: rr - don't read past end of RR when parsing NSEC(3)
We can never read past the end of the packet, so this seems impossible
to exploit, but let's error out early as reading past the end of the
current RR is clearly an error.

Found by Lennart, based on patch by Daniel.
2015-07-23 18:06:50 +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 f1d178cce1 resolved: packet - fail on invalid zero-length data
Most blobs (keys, signatures, ...) should have a specific size given by
the relevant algorithm. However, as we don't use/verify the algorithms
yet, let's just ensure that we don't read out zero-length data in cases
where this does not make sense.

The only exceptions, where zero-length data is allowed are in the NSEC3
salt field, and the generic data (which we don't know anything about,
so  better not make any assumptions).
2015-07-23 18:01:17 +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
Daniel Mack 33b63dd732 Merge pull request #673 from poettering/dns-packet-append-type-window
resolved: make sure we alway initialize *start in dns_packet_append_t…
2015-07-23 08:53:36 +02:00
Lennart Poettering 6fa919016a resolved: make sure we alway initialize *start in dns_packet_append_type_window() 2015-07-23 04:54:35 +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
Tom Gundersen f7d51e1c19 Merge pull request #667 from poettering/dns-rr-memleak
resolve: fix two minor memory leaks
2015-07-23 03:58:47 +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
Lennart Poettering 3ea1453c42 resolve: drop dns_scope_good_dns_server()
It's not used anymore since 29815b6c60,
hence let's remove it from the sources.
2015-07-23 03:10:42 +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
Daniel Mack 9ecec7d766 Merge pull request #586 from teg/resolved-rrs-3
resolved: minor improvements to RR handling
2015-07-14 13:43:18 -04: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 d20b1667db resolved: use one UDP socket per transaction
We used to have one global socket, use one per transaction instead. This
has the side-effect of giving us a random UDP port per transaction, and
hence increasing the entropy and making cache poisoining significantly
harder to achieve.

We still reuse the same port number for packets belonging to the same
transaction (resent packets).
2015-07-14 18:50:57 +02:00
Tom Gundersen 29815b6c60 resolved: implement RFC5452
This improves the resilience against cache poisoning by being stricter
about only accepting responses that match precisely the requst they
are in reply to.

It should be noted that we still only use one port (which is picked
at random), rather than one port for each transaction. Port
randomization would improve things further, but is not required by
the RFC.
2015-07-14 18:50:57 +02:00
Tom Gundersen 8300ba218e resolved: pin the server used in a transaction
We want to discover information about the server and use that in when crafting
packets to be resent.
2015-07-14 18:50:53 +02:00
Tom Gundersen 91b14d6ff3 resolved: reference count the dns servers
We want to reference the servers from their active transactions, so make sure
they stay around as long as the transaction does.
2015-07-14 12:03:04 +02:00
Tom Gundersen a0166609f7 resolved: packet - ensure there is space for IP+UDP headers
Currently we only make sure our links can handle the size of the payload witohut
taking the headers into account.
2015-07-14 12:03:04 +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
Daniel Mack 818ef443f0 resolved: make LLMNR checks conditional
Make all LLMNR related packet inspections conditional to p->protocol.
Use switch-case statements while at it, which will make future additions
more readable.
2015-07-13 11:28:30 -04:00
Daniel Mack 8b757a3861 resolved: separate LLMNR specific header bits
The C and T bits in the DNS packet header definitions are specific to LLMNR.
In regular DNS, they are called AA and RD instead. Reflect that by calling
the macros accordingly, and alias LLMNR specific macros.

While at it, define RA, AD and CD getters as well.
2015-07-13 11:28:29 -04:00
Daniel Mack 22a37591ed resolved: use a #define for LLMNR port
De-duplicate some magic numbers.
2015-07-13 11:28:29 -04:00