Commit Graph

252 Commits

Author SHA1 Message Date
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
Miek Gieben 8da60e45f5 Remove refs to IsMsg - we are not going to do this 2015-01-08 09:42:46 +00:00
Miek Gieben 2c1a31d550 Small cleanup of the docs 2014-12-12 12:57:47 +00:00
Hugo Landau f039fd8203 Add NotifyStartedFunc field to Server
Adds a field, NotifyStartedFunc func() to Server.

If non-nil, it is called after a server starts listening. This is useful
for synchronization purposes, for example when a daemon needs to drop
privileges after binding. Otherwise, there is no way to determine when
the server has begun listening and hardcoded delays (!) must be used or
race conditions may occur.
2014-12-12 12:51:17 +00:00
Miek Gieben cd2048a15a Add Unsafe member to dns.Server
This stops it from checking if the incoming requests have the QR bit
unset, so be careful when enabling this. This can be useful in
combination with mDNS.

Also the check for only 1 question in the question section is relaxed
to be "at least one", even without setting Unsafe!

Also update TestServingResponse to test for Unsafe vs not using Unsafe.
2014-11-19 16:34:18 +00:00
Bryan Boreham 61478ac390 Removed duplicated test for UDPSize 2014-11-18 15:59:40 +00:00
Miek Gieben d8da4d2fa7 Fix: drop requests with *cough* qr set.
Err, yeah.
2014-10-19 09:36:26 +00:00
Miek Gieben 0aa3021a83 Remove all copyright notices
Use the central COPYRIGHT file.
2014-09-11 20:57:37 +01:00
Miek Gieben fbc3e49b78 Some documentation updates 2014-09-02 10:31:15 +00:00
Miek Gieben ebc5489482 Fix datarace in Start/Shutdown
Add mutex and guard a 'started' boolean as well as the stopUDP
and tcpTCP channels so that 'go test -race' does not trigger.

Closes #111, closes #114
2014-08-30 10:34:44 +01:00
Alex Sergeyev fce659ba46 Restored code when shutdown needs an exchange...
Clients sents NULL-packet to server which helps to avoid
timeout. Timeout is still possible to encounter.
Shutdown will likely report error for those cases.
2014-08-29 14:27:53 -04:00
Alex Sergeyev c618657d9b Dealt with race condition detector warnings:
* stopped obvious race condition with replacing handler in
  ServingLargeResponses test
* lowered probability of other race conditions with test code
  while test server is yet activating
* fixed errmessage in Shutdown
2014-08-29 14:10:05 -04:00
Alex Sergeyev ef07b9a69a Following up in introducing getReadTimeout() 2014-08-29 12:26:23 -04:00
Alex Sergeyev f735bb9dcb Changed how shutdown works...
Now stopXXX event will stop any reading on currently open
socket and terminate reading loop. No special client/server
message is required anymore.
2014-08-29 12:24:11 -04:00
Alex Sergeyev 32d6e5396e Continued removing Sleeping tests:
* incorporated @miekg suggestions on switch vs if
* for now moved reaction to stopXXX channel messages until
  after the packet is responded to avoid client timeout in
  Shutdown (causing 2 sec. hanged thread)

Still not great how the abort logic is implemented....
2014-08-29 08:31:27 -04:00
Alex Sergeyev 4b21f37064 Proposed way of creating no-timeout tests and...
... fix for Server.Shutdown() function.
2014-08-28 23:11:49 -04:00
Miek Gieben 2127b822dd Add comment about Systemd 2014-08-28 07:54:23 +00:00
Miek Gieben f0bd4137e2 Make Shutdown return error
This will be handy in feature, so that we can add a 1 second
timeout and then return failure.
2014-08-20 15:12:59 +00:00
Miek Gieben 01bbcbef60 Update documentation for Shutdown.
This completes issue #101.
Fixes #101
2014-08-19 22:08:13 +01:00
Miek Gieben eed2b9aeec Fix Shutdown 2014-08-19 21:56:37 +01:00