Commit Graph

271 Commits

Author SHA1 Message Date
Tom Thorogood 4bda1db839 Improve documentation of maxWorkersCount const (#726)
While I'm here, rename it to maxIdleWorkersCount so it's purpose is
clearer.

Updates #722
Updates #725
2018-08-16 17:10:20 +01:00
Tom Thorogood c9b812d1d9 Remove redundant parenthesis (#727)
* Remove redundant parenthesis

These were caught with:
    gofmt -r '(a) -> a' -w *.go

This commit only includes the changes where the formatting makes the
ordering of operations clear.

* Remove more redundant parenthesis

These were caught with:
    gofmt -r '(a) -> a' -w *.go

This commit includes the remaining changes where the formatting does not
make the ordering of operations as clear as the previous commit.
2018-08-16 17:05:27 +01:00
Tom Thorogood 208cd1e89e Simplify unlocking dance in *Serve functions (#719) 2018-08-10 22:50:48 +01:00
Tom Thorogood b559d43c31 Abstract shutdown checking into seperate function (#716) 2018-07-28 13:47:30 +01:00
Uladzimir Trehubenka 621df0907e Make MaxTCPQueries configurable (#673) 2018-05-14 20:12:20 +01:00
Uladzimir Trehubenka 98a1ef4565 Use workers instead spawning goroutines for each incoming DNS request (#664)
* Use workers instead spawning goroutines for each incoming DNS request

* Replace count (int) with inUse (bool)
2018-05-09 16:44:32 +01:00
Tom Thorogood 01d59357d4 Cleanup serve function (reland) (#667)
* Split central ServeDNS code out of (*Server).serve

* Add UDP and TCP specific (*Server).serve wrappers

* Move UDP serve functionality into serveUDPPacket

* Merge serve into serveTCPConn

* Cleanup serveTCPConn replacing goto with for

* defer Close in serveTCPConn

* Remove remoteAddr field from response struct

* Fix broken tsigSecret check in serveDNS

* Reorder serveDNS arguments

This makes it consistent with the ordering of arguments to
serveUDPPacket and serveTCPConn.
2018-04-06 16:09:55 +01:00
Miek Gieben 7fdfb0141b Revert "Cleanup serve function (#653)"
This reverts commit d174bbf0a5.
2018-04-01 12:27:36 +01:00
Tom Thorogood d174bbf0a5 Cleanup serve function (#653)
* Split central ServeDNS code out of (*Server).serve

* Add UDP and TCP specific (*Server).serve wrappers

* Move UDP serve functionality into serveUDPPacket

* Merge serve into serveTCPConn

* Cleanup serveTCPConn replacing goto with for

* defer Close in serveTCPConn

* Remove remoteAddr field from response struct

* Fix broken tsigSecret check in serveDNS

* Reorder serveDNS arguments

This makes it consistent with the ordering of arguments to
serveUDPPacket and serveTCPConn.
2018-03-30 14:50:27 +01:00
Miek Gieben 43913f2f4f
Fix for CVE-2017-15133 TCP DOS (#631)
serveTCP calls reader.ReadTCP in the accept loop rather than in
the per-connection goroutine. If an attacker opens a connection
and leaves it idle, this will block the accept loop until the
connection times out (2s by default). During this time no other
incoming connections will succeed, preventing legitimate queries
from being answered.

This commit moves the call to reader.ReadTCP into the per-connection
goroutine. It also adds a missing call to Close whose absence allowed
file-descirptors to leak in select cases.

This attack and fix have no impact on serving UDP queries.
2018-01-25 10:36:19 +00:00
Tom Thorogood f5ac34d755 Fix TCP Shutdown 'use of closed network connection' (#623)
The check for srv.started being false is in the wrong place, it should
be after Accept not after ReadTCP. If Shutdown is called, serveTCP will
currently return a 'use of closed network connection' error, which is
undesired.

This commit mirrors the behaviour of serveUDP with respect to Shutdown.
2018-01-10 13:37:59 +00:00
Tom Thorogood ddd8477be2 Ignore malformed UDP datagrams without headers (#622)
Ignore malformed UDP datagrams with incomplete DNS headers
2018-01-10 07:51:00 +00:00
Tom Thorogood 69d25e845f Fixes #613 & #619 (#621)
* Do not reutrn ErrShortRead in readUDP

A read of zero bytes indicates a peer shutdown for TCP sockets -- and
thus returning ErrShortRead is fine in readTCP -- but not for UDP
sockets. For UDP sockets a read of zero bytes literally indicates a
zero-byte datagram, and is a valid return value not indicating an error.

Removing this case will cause readUDP to correctly return a zero-byte
message.

* Return non-temporary error from serveUDP loop

Fixes #613
2018-01-09 13:57:26 +00:00
Miek Gieben e2db8456df
Revert "Fixes #613 (#617)" (#620)
This reverts commit ac8cd7878c.
2018-01-09 08:03:27 +00:00
Twitch ac8cd7878c Fixes #613 (#617)
* Fixes #613

* use net.Error interface for detecting temporary errors
2018-01-06 16:01:19 +00:00
Matthijs Mekking 99c447f9f6 TSIG name must be presented in canonical form (#574)
* TSIG name must be presented in canonical form

Update the documentation to make clear that the zonename in the
TsigSecret map must be in canonical form.

* Reference RFC 4034 for canonical form
2017-11-17 13:17:47 +00:00
Miek Gieben 9fc4eb252e
Server: drop inflight waitgroup (#561)
* Server: drop inflight waitgroup

This drops the waitgroup in Server, the suspicion is this can make the server
fail to stop; doing this make graceful shutdown not work.

Add test that tries to find a race between starting on stopping race;
there was a data race on srv.Inflight.

The coredns' TestReadme doesn't race anymore with this as it did with
the more evasive PR #546.
2017-11-10 10:33:17 +00:00
Miek Gieben 4bb60ce4d8
Revert "server: drop graceful handling (#546)" (#560)
This reverts commit 8223ae840e.
2017-11-09 21:01:09 +00:00
Miek Gieben 8223ae840e
server: drop graceful handling (#546)
Drop all graceful handling. There is just too much locking in
waitgrouping going on for very little gain; deal with it.

Make the error handling between serve{TCP,UDP} identical.
2017-11-09 09:38:14 +00:00
Tom Thorogood 4744e915eb Fix tcp6-tls support in (*Server).ListenAndServe(). (#427)
In the switch statement srv.Net is matched for tcp6-tls but
then compared against tcp6 within the case statement. This
causes tcp6-tls to be equivalent to tcp-tls and not specific
to tcp6. The `network = "tcp6"` line was previously unreachable.

This change corrects this and ensures tcp6-tls listens on IPv6
only.
2016-12-09 07:38:01 +00:00
Santhosh Manohar 271c58e0c1 Add nil check for interface value in ActivateAndServe (#419)
Signed-off-by: Santhosh Manohar <santhosh@docker.com>
2016-11-22 06:12:14 +00:00
Preet Bhinder 3f1f7c8ec9 Fix a couple of comments (#386) 2016-10-03 19:18:08 +01:00
Michael Haro 1be7320498 Use t.Errorf in tests and make the error variable naming more consistent. (#367)
* Make the error variable always named err.

Sometimes the error variable was named 'err' sometimes 'e'.  Sometimes
'e' refered to an EDNS or string and not an error type.

* Use t.Errorf instead of t.Logf & t.Fail.
2016-06-09 07:00:08 +01:00
Michael Haro a465e84f54 Use encoding/binary's conversion functions when possible. (#364)
* Remove {un,}packUint{16,32}Msg functions.

unpackUint16Msg unpackUint32Msg packUint16Msg packUint32Msg implemented
functionality that is part of the encoding/binary package.

* Use encoding/binary's encoding in more places.
2016-06-08 16:38:42 +01:00
Miek Gieben 475ab80867 Remove (most) reflection
Remove the use of reflection when packing and unpacking, instead
generate all the pack and unpack functions using msg_generate.
This will generate zmsg.go which in turn calls the helper functions from
msg_helper.go.

This increases the speed by about ~30% while cutting back on memory
usage. Not all RRs are using it, but that will be rectified in upcoming
PR.

Most of the speed increase is in the header/question section parsing.
These functions *are* not generated, but straight forward enough. The
implementation can be found in msg.go.

The new code has been fuzzed by go-fuzz, which turned up some issues.

All files that started with 'z', and not autogenerated were renamed,
i.e. zscan.go is now scan.go.

Reflection is still used, in subsequent PRs it will be removed entirely.
2016-06-03 12:45:22 +01:00
Nick Galbreath 5cbabd2322 spelling 2016-01-19 14:23:11 -08:00
Rafael Dantas Justo ad79b3f5fb Change documentation based on @miekg comments
See #297
2016-01-11 08:40:14 -02:00
Rafael Dantas Justo 72c041d2f5 Create new function ListenAndServeTLS to easy run a DNS server with TLS support
Using the ListenAndServe with network as "tcp-tls" will cause an error, as the
certificates weren't informed. To solve that we created the function
ListenAndServeTLS that will configure a DNS server listening TCP and handling
requests on incoming TLS connections.

See #297
2016-01-08 13:20:22 -02:00
Rafael Dantas Justo 6fe70412bc Add option in server to allow DNS over TLS
We should allow the server to receive requests of an encrypted connection. This
is proposed on the document draft-ietf-dprive-dns-over-tls [1].

Now it is possible to initialize the DNS server to listen with TLS using
"tcp-tls" value in network parameter of ListenAndServe function, or passing a
listener initialized with tls.Listen to ActivateAndServe.

There's also an option in Server type to change the TLS confirguration, to
inform the certificates that are going to be used, or to change any other
desired option of tls.Config.

See #297

[1] http://tools.ietf.org/html/draft-ietf-dprive-dns-over-tls-02
2016-01-08 11:26:13 -02:00
Andrew Tunnell-Jones 3062dcb751 Check server TCP conn exists before reading
w.tcp could be nil if the conn has been closed by a handler.
2015-11-26 08:10:55 +00:00
Bryan Boreham e54a6cf1bc Only re-try AcceptTCP() if the error is temporary 2015-10-30 17:08:27 +00:00
Filippo Valsorda a58e9c7a9e Refactor server shutdown to call Close() on conn and sync on srv.started
Remove the necessity for the hackish (and unreliable) fake packet.
Fix a couple races and unclutter the start/stop internal state.
2015-10-07 00:13:40 +01:00
Miek Gieben 3c158e6e74 Correct set srv.started to false on error
Unlock the lock and set started to false when we return an error
during the startup.

Fixes #263
2015-09-23 22:00:38 +01:00
Miek Gieben 540899743c Handle the last TCP connection
We currently close the connection after 128 TCP queries. But the
when the last query comes in, we close the connection immediately.
Fix this by moving the check to before we read data from the TCP
socket.

Fixes: #218.
2015-08-31 17:40:56 +01:00
Miek Gieben 114b68f41b go vet fixes 2015-08-23 07:24:08 +01:00
Miek Gieben a6742d536c Lock zone pattern deletion too
Go 1.5 -race flags this as data race, it's not performance critical,
add locking on the mutex.
2015-08-22 18:31:23 +01:00
Miek Gieben eac4ea318f Revert "Use defer Unlock() in ListAndServe"
This reverts commit d2cb5e8fef.
2015-08-17 11:11:14 +01:00
Miek Gieben d2cb5e8fef Use defer Unlock() in ListAndServe 2015-08-12 07:49:41 +01:00
Jeff Hodges 1cb2437ad1 fix some data races in Server
This avoids some issues with Server.PacketConn and Server.Listener being
accessed outside of their locks.

Fixes #244.
2015-08-11 17:00:14 -07:00
Miek Gieben bbe3422804 small doc fixes 2015-08-09 15:34:29 +01:00
James DeFelice 8255b4a03f update docs; replace "data frame" refs with "raw message" 2015-08-06 17:55:37 -04:00
James DeFelice e148c23156 add docs and example for DNS frame read/write decorators 2015-08-04 09:04:40 -04:00
James DeFelice e0f83dee9a add interfaces to allow packet-level inspection for pre/post processing 2015-08-04 01:17:14 -04:00
Robert Gordon 5a357a6fc5 Expose the udp/tcp listening socket w/ ListenAndServe()
Expose the udp and tcp listening socket when ListenAndServe() is used, it seems like
plopping them on Server.Listener and Server.PacketConn would be ideal. The use case is so
that a port of zero can be used and having them exposed will allow for examination of the port
that is bound.
2015-04-18 06:52:30 +01:00
Peter M. Goldstein 9ef29b5646 Export UDP interfaces 2015-03-09 15:00:21 -07:00
Miek Gieben 67945c119e A bunch of golint fixes
The proposed vars names are a nono, because they break the API.
Things left: document each RR and zscan_rr.go has some funcky if-then-elses.
2015-02-19 09:58:33 +00:00
Matthew Farrellee 24ccdb3008 fix spelling of separate 2015-02-18 17:04:12 -05:00
Miek Gieben 2b6f0d61e5 When locking *do* unlock
Add unlocking to some more places as pointed out by bronze1man.

Really closes #161.
2015-01-13 08:12:02 +00:00
Miek Gieben a07be6b2c1 Server: unlock when already started.
Closes #161
2015-01-11 09:26:00 +00:00
Miek Gieben 79f88fc5d7 fmt 2015-01-11 09:23:26 +00:00