Commit Graph

48 Commits

Author SHA1 Message Date
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
2018-03-22 20:21:42 +01:00
Dmitry Rozhkov d686f15c9e resolved: don't check conflicts for DNS-SD enumeration RRs 2017-12-08 14:29:27 +02:00
Dmitry Rozhkov c3036641f0 resolved: implement D-Bus API for DNS-SD 2017-12-08 14:29:27 +02:00
Dmitry Rozhkov 8d67e72cbe resolved: detect and handle mDNS race condition upon probing
As discussed in RFC 6762, Section 8.2 a race condition may
happen when two hosts are probing for the same name simultaniously.

Detect and handle such race conditions.
2017-12-08 14:29:27 +02:00
Dmitry Rozhkov 748a548e1b resolved: set cache-flush bit on mDNS responses
From RFC 6762, Section 10.2
"They (the rules about when to set the cache-flush bit) apply to
startup announcements as described in Section 8.3, "Announcing",
and to responses generated as a result of receiving query messages."

So, set the cache-flush bit for mDNS answers except for DNS-SD
service enumerattion PTRs described in RFC 6763, Section 4.1.
2017-12-08 14:29:27 +02:00
Dmitry Rozhkov 008d4ab7a2 resolved: make rfc4795-specific code run for LLMNR only
RFC6762 specifies different procedure for conflict resolution and
the code is not applicable for the mDNS case.
2017-12-08 14:29:27 +02:00
Dmitry Rozhkov a2bf8a19cc resolved: announce DNS-SD records in mDNS scopes 2017-12-08 14:29:27 +02:00
Dmitry Rozhkov 6db6a4642e resolved: put DNS-SD records to mDNS-enabled zones. 2017-12-08 14:29:27 +02:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Dmitry Rozhkov 53fda2bb93 resolved: implement mDNS probing and announcement
Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
2017-01-19 11:51:21 +02:00
Lennart Poettering 97ebebbc9c resolved: make sure we initialize the ifindex of direct zone answers properly
Previously, after checking the local zone for a reply and finding one we'd not
initialize the answer ifindex from that. Let's fix that.
2016-06-14 23:28:54 +02:00
Lennart Poettering 35aa04e9ed resolved: fix notification iteration logic when transactions are completed
When a transaction is complete, and we notify its owners, make sure we deal
correctly with the requesters removing themselves from the list of owners while
we continue iterating.

This was previously already dealt with with transactions that require other
transactions for DNSSEC purposes, fix this for other possibly transaction
owners too now.

Since iterating through "Set" objects is not safe regarding removal of entries
from it, rework the logic to use two Sets, and move each entry we notified from
one set to the other set before we dispatch the notification. This move operation
requires no additional memory, and enables us to ensure that we don't notify
any object twice.

Fixes: #2676
2016-02-22 23:24:47 +01: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 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 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
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 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 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 5032b16dfe resolved: simplify dns zone logic: take a single key when looking up entries
Instead of taking a DnsQuestion object (i.e. an array of keys) only take
a single key. This simplifies things a bit, and as DNS/LLMNR require a
single question per query message was unnecessary anyway.

This mimics a similar change that was done a while ago for the dns cache
logic.
2015-11-18 17:07:11 +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 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
Lennart Poettering 525d3cc746 tree-wide: take benefit of the fact that hashmap_free() returns NULL
And set_free() too.

Another Coccinelle patch.
2015-09-09 23:12:07 +02:00
Lennart Poettering 4d506d6bb7 resolved: dump cache and zone contents to syslog on SIGUSR1 2015-08-26 09:41:45 +02:00
Lennart Poettering f52e61da04 resolved: only maintain one question RR key per transaction
Let's simplify things and only maintain a single RR key per transaction
object, instead of a full DnsQuestion. Unicast DNS and LLMNR don't
support multiple questions per packet anway, and Multicast DNS suggests
coalescing questions beyond a single dns query, across the whole system.
2015-08-21 22:55:01 +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
Nick Owens 4ad7f2761d resolve: move dns routines into shared 2015-06-10 11:15:45 -07:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +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
Thomas Hindoe Paaboel Andersen bf1594f54e resolved: initialize counter
introduced in: a407657425
2014-08-12 04:42:33 +02:00
Lennart Poettering 4d91eec42d resolved: actually, the peer with the lower IP address wins conflicts 2014-08-11 15:06:22 +02:00
Lennart Poettering 3ef64445cd resolved: make sure we don't mark the wrong zone RRs conflicting 2014-08-11 15:06:22 +02:00
Lennart Poettering 2fb3034cb2 resolved: be a bit more communicative about conflicts 2014-08-11 15:06:22 +02:00
Lennart Poettering 902bb5d8ab resolved: verify all RRs when we come back from suspend 2014-08-11 15:06:22 +02:00
Lennart Poettering a407657425 resolved: implement full LLMNR conflict detection logic 2014-08-11 15:06:22 +02:00
Lennart Poettering 3ef77d0476 resolved: properly check return value of dns_resource_record_equal() 2014-08-11 15:06:22 +02:00
Lennart Poettering d84b686f06 resolved: stop the prober when we detect a conflict in LLMNR 2014-08-05 04:17:45 +02:00
Lennart Poettering 60eb3f7cf1 resolved: don't override zone item state after starting the probe
After all, the probe might be finished immeidately (due to resources,
...), and we shouldn't then set the state back to probing.
2014-08-05 04:17:12 +02:00
Lennart Poettering dc4d47e2c7 resolved: never reuse transactions for probing that are already completed based on cached data 2014-08-05 01:52:25 +02:00
Lennart Poettering cd1b20f90a resolved: if there's already an RR established that has the same name of an RR to be established, skip probing the name
After all, what has been probed once, doesn't need to be probed again.
2014-08-05 01:52:24 +02:00
Lennart Poettering ec2c5e4398 resolved: implement LLMNR uniqueness verification 2014-07-31 17:47:19 +02:00
Lennart Poettering 57f5ad3149 resolved: properly set TTL in SOA records 2014-07-30 19:34:50 +02:00
Lennart Poettering 8bf52d3d17 resolved: include SOA records in LLMNR replies for non-existing RRs to allow negative caching 2014-07-30 16:47:21 +02:00
Lennart Poettering d532366133 resolved: respond to ANY queries from our zone 2014-07-30 02:06:09 +02:00
Lennart Poettering 1d3b690fbd resolved: don't allow adding of ANY class/type RRs to local zones 2014-07-30 02:04:07 +02:00
Lennart Poettering 623a4c97b9 resolve: add llmnr responder side for UDP and TCP
Name defending is still missing.
2014-07-29 20:57:58 +02:00