Commit Graph

68 Commits

Author SHA1 Message Date
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 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
Daniel Mack 5f402ae84b resolved: move LLMNR related functions into separate file 2015-07-13 11:28:29 -04:00
Tom Gundersen 1c4baffc18 sd-netlink: rename from sd-rtnl 2015-06-13 19:52:54 +02:00
Tom Gundersen 31710be527 sd-rtnl: make joining broadcast groups implicit 2015-06-11 17:47:40 +02:00
Nick Owens 4ad7f2761d resolve: move dns routines into shared 2015-06-10 11:15:45 -07:00
Lennart Poettering 2a1288ff89 util: introduce CMSG_FOREACH() macro and make use of it everywhere
It's only marginally shorter then the usual for() loop, but certainly
more readable.
2015-06-10 19:29:47 +02:00
Lennart Poettering cab5b05903 resolved: fix crash when shutting down
Reported by Cristian Rodríguez

http://lists.freedesktop.org/archives/systemd-devel/2015-May/031626.html
2015-05-18 23:23:17 +02:00
Lennart Poettering 958b66ea16 util: split all hostname related calls into hostname-util.c 2015-05-18 17:10:07 +02:00
Ronny Chevalier 3df3e884ae shared: add random-util.[ch] 2015-04-11 00:11:13 +02:00
Lennart Poettering 822db23cfa resolved: maintain order when writing resolv.conf entries
http://lists.freedesktop.org/archives/systemd-devel/2015-March/029850.html
2015-04-08 17:23:27 +02:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Thomas Hindoe Paaboel Andersen 0a6f50c0af include <poll.h> instead of <sys/poll.h>
include-what-you-use automatically does this and it makes finding
unnecessary harder to spot. The only content of poll.h is a include
of sys/poll.h so should be harmless.
2015-02-12 20:47:38 +01:00
Lennart Poettering a38d99451f Revert "tree-wide: Always use recvmsg with MSG_CMSG_CLOEXEC"
This reverts commit d6d810fbf8.

It's apparently not OK to pass MSG_CMSG_CLOEXEC to recvmsg() of raw
sockets.
2015-02-12 11:45:39 +01:00
Cristian Rodríguez d6d810fbf8 tree-wide: Always use recvmsg with MSG_CMSG_CLOEXEC 2015-02-10 21:20:16 +01:00
Torstein Husebø cc98b3025e treewide: fix multiple typos 2015-01-26 10:39:47 -05:00
Lennart Poettering 36a03ca2a8 resolved: when rereading /etc/resolv.conf, always start using first DNS server again
Previously we tried to stick to a DNS server as long as it is available.
When /etc/resolv.conf changed, and the old DNS server we used was still
in there we'd continue to use it, even if it was at the end of the list.

With this change we'll now always start with the first DNS server in the
list again.

Rationale: certain network managing implementations (notably
NetworkManager) when connected to a VPN place both the VPN DNS server as
well as the local DNS server in /etc/resolv.conf. If we used the local
one before we would thus continue to use the local one, making VPN names
unresolvable. NetworkManager really should be fixed to only place the
VPN DNS servers in the file, but with this commit things are at least
similarly bad as they used to be...
2015-01-23 19:03:07 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt 8d3d7072e6 treewide: a few more log_*_errno + return simplifications
The one in tmpfiles.c:create_item() even looks like it fixes a bug.
2014-11-28 19:17:24 +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 a5f0359600 resolved: simplify detection of packets from the loopback device
We can simplify our code quite a bit if we explicitly check for the
ifindex being 1 on Linux as a loopback check. Apparently, this is
hardcoded on Linux on the kernel, and effectively exported to userspace
via rtnl and such, hence we should be able to rely on it.
2014-10-22 16:52:38 +02:00
Zbigniew Jędrzejewski-Szmek a5a807e63a resolved: apply label to /run/systemd/resolve/resolv.conf
Under an SELinux system, we want the file that is created to
have a proper context, different from the default for files in /run.
This is so that the policy can give access to almost everyone to
this file.
2014-10-13 22:37:13 -04:00
Zbigniew Jędrzejewski-Szmek 4713135eae resolved: split out writing of resolv.conf
manager_write_resolv_conf() is quite long anyway.
2014-10-13 22:37:12 -04: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
Tom Gundersen d1c457badf resolved: fall back to hardcoded ifindex when checking if a link is the loopback
Reported by Philippe De Swert <philippedeswert@gmail.com>.

Coverity CID#1237656
2014-09-13 21:10:59 +02:00
Lennart Poettering c4147df156 resolved: fix typo in log message 2014-08-22 18:10:31 +02:00
David Herrmann 40a1eebde6 shared: add MAXSIZE() and use it in resolved
The MAXSIZE() macro takes two types and returns the size of the larger
one. It is much simpler to use than MAX(sizeof(A), sizeof(B)) and also
avoids any compiler-extensions, unlike CONST_MAX() and MAX() (which are
needed to avoid evaluating arguments more than once). This was suggested
by Daniele Nicolodi <daniele@grinta.net>.

Also make resolved use this macro instead of CONST_MAX(). This enhances
readability quite a bit.
2014-08-22 14:01:05 +02:00
Tom Gundersen a9feff3d77 resolved: write resolv.conf search - switch arguments
Found by Lukáš Nykrýn.
2014-08-20 15:56:18 +02:00
David Herrmann bf32f99f65 resolve: fix compilation on LLVM+clang
LLVM+clang does not allow statement-expressions inside of
type-declarations (file-scope). Use CONST_MAX() to avoid this.
2014-08-15 16:59:09 +02:00
Tom Gundersen bda2c408f8 resolved: pull in domain names from sd-network 2014-08-14 23:38:38 +02:00
Lennart Poettering 90ab504273 resolved: skip IPv6 LLMNR if IPv6 is not available 2014-08-13 15:00:12 +02:00
Lennart Poettering 3e684349c2 resolved: unify logic how we flush out DNS servers we learnt 2014-08-12 19:32:55 +02:00
Lennart Poettering 87f5a19343 resolved: filter out duplicate DNS servers when writing resolv.conf 2014-08-12 13:02:27 +02:00
Lennart Poettering 556a22945f resolved: when picking a new hostname make sure two hosts pick different ones
This way we can avoid always picking the same replacement hostnames when
picking one.
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 21d73c87b0 resolved: actually read the initial state data from networkd when we initialize 2014-08-04 23:08:49 +02:00
Lennart Poettering f0e1546763 resolved: fix order in which we destroy manager resources 2014-08-04 19:59:05 +02:00
Lennart Poettering edc501d467 resolved: when there's already somebody listening on the LLMNR ports, simple disable LLMNR and warn, but continue
This allows us to run resolved inside an nspawn container that shares
the network namespace with the host, if there's already an instance
running.
2014-08-04 19:48:03 +02:00
Thomas Hindoe Paaboel Andersen e850d8e1ac resolved: remove unused variables 2014-08-03 13:19:19 +02:00
Lennart Poettering 2c27fbca2d resolved: flush cache each time we change to a different DNS server 2014-08-01 18:10:01 +02:00
Lennart Poettering 5cb36f41f0 resolved: read the system /etc/resolv.conf unless we wrote it ourselves
This way we integrate nicely with foreign network management stacks,
such as NM.
2014-08-01 18:10:01 +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 4e945a6f79 resolved: beef up DNS server configuration logic
We now maintain two lists of DNS servers: system servers and fallback
servers.

system servers are used in combination with any per-link servers.

fallback servers are only used if there are no system servers or
per-link servers configured.

The system server list is supposed to be populated from a foreign tool's
/etc/resolv.conf (not implemented yet).

Also adds a configuration switch for LLMNR, that allows configuring
whether LLMNR shall be used simply for resolving or also for responding.
2014-08-01 16:06:39 +02:00
Lennart Poettering eb60f9cd4e hostnamed: watch system hostname changes and update LLMNR RRs accordingly 2014-07-31 19:54:43 +02:00
Lennart Poettering ec2c5e4398 resolved: implement LLMNR uniqueness verification 2014-07-31 17:47:19 +02:00
Zbigniew Jędrzejewski-Szmek b2fadec604 Properly report invalid quoted strings
$ systemd-analyze verify trailing-g.service
[./trailing-g.service:2] Trailing garbage, ignoring.
trailing-g.service lacks ExecStart setting. Refusing.
Error: org.freedesktop.systemd1.LoadFailed: Unit trailing-g.service failed to load: Invalid argument.
Failed to create trailing-g.service/start: Invalid argument
2014-07-31 08:56:03 -04:00
Zbigniew Jędrzejewski-Szmek a2a5291b3f Reject invalid quoted strings
String which ended in an unfinished quote were accepted, potentially
with bad memory accesses.

Reject anything which ends in a unfished quote, or contains
non-whitespace characters right after the closing quote.

_FOREACH_WORD now returns the invalid character in *state. But this return
value is not checked anywhere yet.

Also, make 'word' and 'state' variables const pointers, and rename 'w'
to 'word' in various places. Things are easier to read if the same name
is used consistently.

mbiebl_> am I correct that something like this doesn't work
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-passwd "Unlock EncFS"'
mbiebl_> systemd seems to strip of the quotes
mbiebl_> systemctl status shows
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-password Unlock EncFS  $RootDir $MountPoint
mbiebl_> which is pretty weird
2014-07-31 04:00:31 -04:00
Lennart Poettering a2a416f768 resolved: add more debug logging 2014-07-29 23:53:08 +02:00