Commit graph

52 commits

Author SHA1 Message Date
Lennart Poettering c463eb783e resolved: generalize DNS RR type validity checks
Check the validity of RR types as we parse or receive data from IPC
clients, and use the same code for all of them.
2015-12-11 14:14:27 +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 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 4e2d538f33 resolved: port ResolveRecord() bus call implementation to dns_resource_record_to_wire_format()
Now that we have dns_resource_record_to_wire_format() we can generate
the RR serialization we return to bus clients in ResolveRecord() with
it. We pass the RR data along in the original form, not the DNSSEC
canonical form, since that would mean we'd lose RR name casing, which is
however important to keep for DNS-SD services and similar.
2015-12-02 22:50:11 +01:00
Lennart Poettering 4afd3348c7 tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.

With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.

The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).

This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.

Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:

       #define _cleanup_(function) __attribute__((cleanup(function)))

Or similar, to make the gcc feature easier to use.

Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.

See #2008.
2015-11-27 19:19:36 +01:00
Lennart Poettering 039a8725fd resolved: fix build 2015-11-27 00:10:29 +01:00
Tom Gundersen c283267467 Merge pull request #2031 from poettering/resolved-search-domains
resolved. Fully implement search domains for single-label names
2015-11-26 23:58:45 +01:00
Tom Gundersen 95d46fcaa4 resolved: bus - follow CNAME chains when resolving addresses
It may be unexpected to find a CNAME record when doing a reverse lookup, as we
expect to find a PTR record directly. However, it is explicitly supported
according to <https://tools.ietf.org/html/rfc2181#section-10.2>, and there
seems to be no benefit to not supporting it.
2015-11-26 04:03:08 +01:00
Lennart Poettering 7e8131e9c6 dns-domain: change dns_srv_type_is_valid() return value to bool
For similar reasons as dns_name_is_root() got changed in the previous
commit.
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 7f220d94a9 resolved: expose some properties on the bus
For now, let's just expose the LLMNR hostname currently in use;  a
combined list of all dns servers with their interface indexes; a
combined list of all search domains with their interface indexes.
2015-11-25 21:58:38 +01:00
Lennart Poettering 703e4f5e39 resolved: don't claim DnsQuestion have to have the same names
Wen DnsQuestion objects are used for DnsQuery objects all contained keys
have to share the same name, but otherwise they generally don't have to,
and this can actually happen in real-life because DnsPacket objects for
mDNS use DnsQuestion for the question section.

Hence, rename:

dns_question_is_valid() to dns_question_is_valid_for_query(), since the
name uniqueness check it does is only relevant when used for a query.

Similar, rename dns_question_name() to dns_question_first_name(),
to be more accurate, as this difference matters if we keys don#t have to
share the same name.
2015-11-25 21:58:32 +01:00
Thomas Hindoe Paaboel Andersen 6617082bc8 resolved: remove unused variable 2015-11-24 17:10:32 +01:00
Lennart Poettering 45ec7efb6c resolved: add ResolveService() bus call for resolving SRV and DNS-SD services
This also adds client-side support for this to systemd-resolve-host.

Note that the ResolveService() API can deal both with DNS-SD service
(consisting of service name, type and domain), as well as classic SRV
services (consisting just of a type and a domain), all exposed in the
same call.

This patch also reworks CNAME handling in order to reuse it between
hostname, RR and service lookups.

In contrast to Avahi and Bonjour, this new API will actually reolve the
A/AAAA RRs the SRV RRs point to in one go (unless this is explicitly
disabled). This normally comes for free, as these RRs are sent along
the SRV responses anyway, hence let's make use of that. This makes the
API considerably easier to use, as a single ResolveService() invocation
will return all necessary data to pick a server and connect() to it.

Note that this only implements the DNS-SD resolving step, it does not
implement DNS-SD browsing, as that makes sense primarily on mDNS, due to
its continuous nature.
2015-11-23 21:31:29 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Tom Gundersen 5643c00afe resolved: cache - handle CNAME redirection
CNAME records are special in the way they are treated by DNS servers,
and our cache should mimic that behavior: In case a domain name has an
alias, its CNAME record is returned in place of any other.

Our cache was not doing this despite caching the CNAME records, this
entailed needless lookups to re-resolve the CNAME.
2015-09-16 17:03:17 +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
Lennart Poettering d634711b26 resolved: remove duplicate handling of "no servers" query result
So far we handled immediate "no server" query results differently from
"no server" results we ran into during operation: the former would cause
the dns_query_go() call to fail with ESRCH, the later would result in
the query completion callback to be called.

Remove the duplicate codepaths, by always going through the completion
callback. This allows us to remove quite a number of lines for handling
the ESRCH.

This commit should not alter behaviour at all.
2015-08-24 23:44:33 +02:00
Lennart Poettering f6a5fec6b9 resolved: when passing RRs across the bus, make sure not to use name compression
We explicitly need to turn off name compression when marshalling or
demarshalling RRs for bus transfer, since they otherwise refer to packet
offsets that reference packets that are not transmitted themselves.
2015-08-21 16:04:59 +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
Lennart Poettering 966c66e349 tree-wide: get rid of a few more explicit bus parameters 2015-04-29 19:10:09 +02:00
Lennart Poettering 190700621f sd-bus: drop bus parameter from message callback prototype
This should simplify the prototype a bit. The bus parameter is redundant
in most cases, and in the few where it matters it can be derived from
the message via sd_bus_message_get_bus().
2015-04-29 18:36:25 +02:00
Zbigniew Jędrzejewski-Szmek 657dbed29a resolved: use == for comparing unsigned against zero 2015-02-23 23:38:30 -05:00
Lennart Poettering 63c372cb9d util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the
same time, add support for NULL sentinels, even if they are normally not
necessary.
2015-02-03 02:05:59 +01:00
Lennart Poettering 96aad8d15a sd-bus: move common errors src/shared/bus-errors.h → src/libsystemd/sd-bus/bus-common-errors.h
Stuff in src/shared/ should not use stuff from src/libsystemd/ really.
2014-12-10 19:07:48 +01:00
Michal Schmidt f647962d64 treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
 'local $/;
  local $_=<>;
  s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
  print;'
 $f
done

And a couple of manual whitespace fixups.
2014-11-28 18:56:16 +01: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
Lennart Poettering 51323288fc resolved: allow passing on which protocol, family and interface to look something up
Also, return on which protocol/family/interface we found something.
2014-08-14 01:01:43 +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 82bd6dddc4 resolved: destroy outstanding queries if the clients that initiated them die 2014-08-11 15:06:22 +02:00
Lennart Poettering 818f766b12 resolved: properly pass aborted transaction result back to clients 2014-08-11 15:06:22 +02:00
Thomas Hindoe Paaboel Andersen e850d8e1ac resolved: remove unused variables 2014-08-03 13:19:19 +02:00
Lennart Poettering 39d8db043b resolved: rename resolved.h to resolved-manager.h
After all it pretty much exlcusively containers definitions about the
"Manager" object, hence let's call this the most obvious way.
2014-08-01 16:14:59 +02:00
Lennart Poettering 7b9f7afcc0 resolved: accept UTF-8 hostnames from bus clients 2014-07-31 19:53:59 +02:00
Lennart Poettering ec2c5e4398 resolved: implement LLMNR uniqueness verification 2014-07-31 17:47:19 +02:00
Lennart Poettering 2d4c5cbc0e resolved: add API for resolving specific RRs 2014-07-30 19:24:13 +02:00
Lennart Poettering 3339cb71d4 resolved: properly pass empty answers back to bus clients 2014-07-30 17:53:19 +02:00
Lennart Poettering faa133f3aa resolved: rework logic so that we can share transactions between queries of different clients 2014-07-23 02:00:40 +02:00
Lennart Poettering 878cd63db2 resolved: fix bus signatures to follow family as int change 2014-07-18 21:01:07 +02:00
Lennart Poettering 0dd25fb9f0 change type for address family to "int"
Let's settle on a single type for all address family values, even if
UNIX is very inconsitent on the precise type otherwise. Given that
socket() is the primary entrypoint for the sockets API, and that uses
"int", and "int" is relatively simple and generic, we settle on "int"
for this.
2014-07-18 16:10:51 +02:00
Thomas Hindoe Paaboel Andersen 962225baa8 resolved: silence warnings
No need to write to r here since it will be overwritten as the first
step in parse_fail.
2014-07-17 21:12:39 +02:00
Thomas Hindoe Paaboel Andersen f12ea7dad0 resolved: remove unused variable 2014-07-17 19:59:47 +02:00
Lennart Poettering 322345fdb9 resolved: add DNS cache 2014-07-17 19:39:50 +02:00
Lennart Poettering 309e9d86f0 resolved: properly pass canonical name information to resolving client
Also, hook up nss-resolve to make use of this information
2014-07-16 22:51:50 +02:00
Lennart Poettering 8ba9fd9cee resolved: add CNAME lookup support 2014-07-16 22:51:50 +02:00
Lennart Poettering ad86766293 resolved: support for TCP DNS queries 2014-07-16 20:15:47 +02:00
Lennart Poettering 3cb10d3a0b dns-domain: introduce macros for accessing all DNS header fields 2014-07-16 18:03:46 +02:00
Lennart Poettering 4d1cf1e229 resolved: add small NSS module that uses resolved to resolve DNS names 2014-07-16 03:31:30 +02:00