Commit Graph

61 Commits

Author SHA1 Message Date
Lennart Poettering 565147b7bb stub: don't ever respond to datagrams coming in on non-localhost addreses, on the stub 2020-12-03 09:35:40 +09:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Lennart Poettering b370adb593 resolved: advertise smaller UDP datagram size on extra stubs 2020-10-28 10:01:07 +01:00
Lennart Poettering c36d5b5be9 resolved: don't append RFC6975 data to stub replies
We previously checked the QR bit to decide whether the RFC6975 algorithm
data in our packets. But that doesn't work in many cases, since we
initialize the QR flags along with the other flags usually only after
appending OPT (since success to do so propagates into flags). Hence,
let's add an explicit parameter that controls whether to include RFC6975
data in DNS packets, and set it to false for stub reply, and on true for
upstream queries.

Fixes: #17217
2020-10-10 16:22:22 +02:00
Frantisek Sumsal 69e3234db7 tree-wide: fix typos found by codespell
Reported by Fossies.org
2020-09-14 15:32:37 +02:00
Lennart Poettering 5d0fe4233b tree-wide: add helper for IPv4/IPv6 sockopts
A variety of sockopts exist both for IPv4 and IPv6 but require a
different pair of sockopt level/option number. Let's add helpers for
these that internally determine the right sockopt to call.

This should shorten code that generically wants to support both ipv4 +
ipv6 and for the first time adds correct support for some cases where we
only called the ipv4 versions, and not the ipv6 options.
2020-09-11 10:33:13 +02:00
Zbigniew Jędrzejewski-Szmek d491917c9f resolved: unify the two functions to create main stubs
There is a small functional difference: IP_TTL==1 is now also set for the UDP
socket. I assume that it wasn't set by mistake.
2020-09-10 00:46:44 +02:00
Zbigniew Jędrzejewski-Szmek b5febb3f56 resolved: unify the two functions to create extra stubs
There is a minor functional change:
IPV6_FREEBIND is set of IPv6 sockets, not IP_FREEBIND. This was missed in
af8b1384, but I noticed only after the merging the two functions.

And a not-so-minor functional chagnge:
7216a3b5dc changed manager_dns_stub_tcp_fd_extra() to return the fd even
if the source was already initialized, but it didn't do the same change for
manager_dns_stub_udp_fd_extra(), so it would return 0 in that case. But
0354029bf5 uses manager_dns_stub_udp_fd_extra() when preparing to call
manager_send(), and will pass 0 as the fd in that case. For both socket types
fd is now always returned.
2020-09-10 00:44:53 +02:00
Zbigniew Jędrzejewski-Szmek e4bed40f40 resolve: move handler functions higher
No functional change, preparation for subsequent refactoring.
2020-09-10 00:06:35 +02:00
Lennart Poettering 0354029bf5 resolved: don't store udp/tcp fd in DnsPacket object
DnsPacket should better be a "dead" object, i.e. list facts, not track
resources. By including an fd in its fields it started tracking
resources however, without actually taking a ref to the fd (i.e. no
dup() or so was called on it).

Let's hence rework things so that we don#t have to keep track of the fd
a packet came in from. Instead, pass around the DnsStubListenerExtra
object wherever we need to.

This should be useful as soon as we start caching whole DnsPacket
objects to allow replying to DNSSEC/CO packets, i.e. where we have to
keep a copy of the original DnsPacket around for a long time in cache,
potentially much longer than the fds the packet was received on.
2020-09-08 19:47:30 +02:00
Lennart Poettering ae8f0ec323 resolved: move dns stub definitions to resolved-dns-stub.[ch]
Just some moving around, no logic changes.
2020-09-08 19:47:25 +02:00
Lennart Poettering 36aaabc35e resolve: DNSStubListenerExtra → DnsStubListenerExtra
All our other struct types use the "Dns" spelling, rather than "DNS". Do
the same for this struct.
2020-09-08 19:47:19 +02:00
Zbigniew Jędrzejewski-Szmek 90e74a66e6 tree-wide: define iterator inside of the macro 2020-09-08 12:14:05 +02:00
Yu Watanabe 89f7435d0c resolve: use correct fd for UDP stub listner 2020-09-04 23:54:35 +09:00
Yu Watanabe d1fb8cdae2 resolve: do not check sender and destination for packet received by extra DNS stub listner 2020-09-04 23:54:35 +09:00
Yu Watanabe 7216a3b5dc resolve: use sd_event_source_set_io_fd_own() for stub listners 2020-09-04 23:54:35 +09:00
Yu Watanabe bf22f231cf resolve: introduce dns_stub_listener_extra_free() and set it as a key destructor 2020-09-04 23:54:35 +09:00
Yu Watanabe 1c17bcb3ad resolve: adjust error messages 2020-09-04 23:54:35 +09:00
Yu Watanabe af8b138422 resolve: do not set IPv4 specific options on IPv6 socket 2020-09-04 23:54:30 +09:00
Yu Watanabe d40f00d798 resolve: do not set IP_TTL for extra DNS stub listeners 2020-09-04 23:53:22 +09:00
Yu Watanabe ca8b62b522 resolve: use in_addr_union to store addresses for extra dns stub listeners 2020-09-04 20:05:58 +09:00
Yu Watanabe b4b7ea1b32 resolve: fix indentation 2020-09-04 20:05:58 +09:00
Yu Watanabe 7314b39746 resolve: set DNS_STUB_LISTENER_YES if no protocol is specified in DNSStubListenExtra= 2020-09-04 20:05:58 +09:00
Yu Watanabe dce65cd40f resolve: Manager::dns_stub_listener_mode is not relevant to extra stub listeners 2020-09-04 20:05:58 +09:00
Yu Watanabe 88d2cb7c0e resolve: make DnsStubListenerMode bitfield 2020-09-04 20:05:58 +09:00
Yu Watanabe 8ae07803a0 resolve: rename dns_stub_extra_event_source -> event_source
As the name is too redundant.
2020-09-04 20:05:58 +09:00
Lennart Poettering 5b49641015 resolved: ttl/hopcount sockopt is not a boolean
These are integer values, hence specify them as integers, not as
booleans.
2020-09-04 15:23:12 +09:00
Susant Sahani 1f05101fb6 resolve: allow configurable bind address 2020-09-03 08:27:41 +00:00
Zbigniew Jędrzejewski-Szmek ceb17827fa resolved: simplify allocation failure handling in dns_stub_process_query()
Old code was correct, but let's make things more explicit.
2020-06-24 10:38:15 +02:00
Zbigniew Jędrzejewski-Szmek de7fef4b6e tree-wide: use set_ensure_put()
Patch contains a coccinelle script, but it only works in some cases. Many
parts were converted by hand.

Note: I did not fix errors in return value handing. This will be done separate
to keep the patch comprehensible. No functional change is intended in this
patch.
2020-06-22 16:32:37 +02:00
Lennart Poettering 4ff9bc2ea6 tree-wide: port users over to use new ERRNO_IS_ACCEPT_AGAIN() call 2019-04-10 22:11:18 +02:00
Lennart Poettering 953a02d11b tree-wide: port various users over to socket_bind_to_ifindex() 2019-03-18 12:02:32 +01:00
Lennart Poettering ff4caaaeba resolved: if we can't append EDNS OPT RR, then indicate truncation to stub client
We do so for any other RR we can't add, do this here too.

Fixes: #11625
2019-03-13 19:38:14 +01:00
Lennart Poettering aa11cab98c resolved: don't follow cnames if we already noticed truncation 2019-03-13 19:34:05 +01:00
Lennart Poettering b412af57a3 resolved: keep stub stream connections up for as long as client wants
This enables pipelining of queries from clients to our stub server.

Fixes: #11332
2019-02-15 17:13:58 +01:00
Lennart Poettering 652ba568c6 stream: track type of DnsStream object
We use stream objects in four different cases: let's track them.

This in particular allows us to make sure the limit on outgoing streams
cannot be exhausted by having incoming streams as this means we can
neatly separate the counters for all four types.
2019-02-15 17:13:58 +01:00
Lennart Poettering aa337a5e72 resolved: add new accessor dns_stream_take_read_packet() for taking read packet from stream
This ensures the packet is complete when it is taken out, and resets
n_read so that we can start reading the next one.
2018-12-07 17:16:29 +01:00
Yu Watanabe ef118d00eb util: drop missing.h from socket-util.h 2018-12-06 13:31:16 +01:00
Lennart Poettering 2ff48e981e tree-wide: introduce setsockopt_int() helper and make use of it everywhere
As suggested by @heftig:

6d5e65f645 (commitcomment-30938667)
2018-10-18 19:50:29 +02:00
Lennart Poettering 6d5e65f645 tree-wide: add a single version of "static const int one = 1"
All over the place we define local variables for the various sockopts
that take a bool-like "int" value. Sometimes they are const, sometimes
static, sometimes both, sometimes neither.

Let's clean this up, introduce a common const variable "const_int_one"
(as well as one matching "const_int_zero") and use it everywhere, all
acorss the codebase.
2018-10-15 19:40:51 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Iwan Timmer 91ccab1e40 resolved: TCP fast open connections
Add suport for TCP fast open connection to reduce latency for successive DNS request over TCP
2018-06-11 21:35:58 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Lennart Poettering c10d6bdb89 macro: introduce new TAKE_FD() macro
This is similar to TAKE_PTR() but operates on file descriptors, and thus
assigns -1 to the fd parameter after returning it.

Removes 60 lines from our codebase. Pretty good too I think.
2018-03-22 20:30:40 +01: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
Lennart Poettering 5102765695 resolved: rework how we handle truncation in the stub resolver
When we a reply message gets longer than the client supports we need to
truncate the response and set the TC bit, and we already do that.
However, we are not supposed to send incomplete RRs in that case, but
instead truncate right at a record boundary. Do that.

This fixes the "Message parser reports malformed message packet."
warning the venerable "host" tool outputs when a very large response is
requested.

See: #6520
2017-10-05 12:22:43 +02:00
Andreas Rammhold 3742095b27
tree-wide: use IN_SET where possible
In addition to the changes from #6933 this handles cases that could be
matched with the included cocci file.
2017-10-02 13:09:54 +02:00
Zbigniew Jędrzejewski-Szmek d5da77077d resolved: add debug message about stub listener 2017-07-31 14:42:10 -04:00
Lennart Poettering 2b2d98c175 resolved: propagate AD bit for NXDOMAIN into stub replies
When we managed to prove non-existance of a name, then we should
properly propagate this to clients by setting the AD bit on NXDOMAIN.

See: #4621
2017-02-17 10:25:15 +01:00