Commit Graph

3799 Commits

Author SHA1 Message Date
chantra 833bf76c28 [tls] Carry TLS state within (possibly) response writer (#728)
* [tls] Carry TLS state within (possibly) response writer

This allows a server to make decision wether or not the link used to
connect to the DNS server is using TLS.
This can be used by the handler for instance to (but not limited to):
- log that the request was TLS vs TCP
- craft specific responsed knowing that the link is secured
- return custom answers based on client cert (if provided)
...

Fixes #711

* Address @tmthrgd comments:
- do not check whether w.tcp is nil
- create RR after setting txt value

* Address @miekg comments.

Attempt to make a TLS connection state specific test, it goes over
testing each individual server types (TLS, TCP, UDP) and validate that
tls.Connectionstate is only accessible when expected.

* ConnectionState() returns value instead of pointer

* * make ConnectionStater.ConnectionState() return a pointer again
* rename interface ConnectionState to ConnectionStater
* fix nits pointed by @tmthrgd

* @tmthrgd comment: Do not use concret type in `ConnectionState`
2018-09-22 18:34:55 +01:00
Miek Gieben 426ea785a9 Release 1.0.9 2018-09-15 22:43:45 +01:00
Tom Thorogood b0dc93d276
Make Shutdown wait for connections to terminate gracefully (#717)
* Make Shutdown wait for connections to terminate gracefully

* Add graceful shutdown test files from #713

* Tidy up graceful shutdown tests

* Call t.Error directly in checkInProgressQueriesAtShutdownServer

* Remove timeout arguments from RunLocal*ServerWithFinChan

* Merge defers together in (*Server).serve

This removes the defer from the UDP path, in favour of directly
calling (*sync.WaitGroup).Done after (*Serve).serveDNS has
returned.

* Replace checkInProgressQueriesAtShutdownServer implementation

This performs dialing, writing and reading as three seperate steps.

* Add sleep after writing shutdown test messages

* Avoid race condition when setting server timeouts

Server timeouts cannot be set after the server has started without
triggering the race detector. The timeout's are not strictly needed, so
remove them.

* Use a sync.Cond for testShutdownNotify

Using a chan erroneously triggered the race detector, using a sync.Cond
avoids that problem.

* Remove TestShutdownUDPWithContext

This doesn't really add anything.

* Move shutdown and conn into (*Server).init

* Only log ResponseWriter.WriteMsg error once

* Test that ShutdownContext waits for the reply

* Remove stray newline from diff

* Rename err to ctxErr in ShutdownContext

* Reword testShutdownNotify comment
2018-09-13 23:06:28 +09:30
Tom Thorogood e875a31a5c
Add SO_REUSEPORT support (#736)
* Use strings.TrimSuffix in ListenAndServe for TLS

This replaces the if/else statements with something simpler.

Interestingly, the first pull request I submitted to this library was
to fix the tcp6-tls case way back in 4744e915eb.

* Add SO_REUSEPORT implementation

Fixes #654

* Rename Reuseport field to ReusePort

* Rename supportsReuseport to match ReusePort

* Rename listenUDP and listenTCP file to listen_*.go
2018-09-10 20:12:54 +09:30
Tom Thorogood 8f0a42efa0 Fix TestServerStartStopRace calling t.Fatal on wrong goroutine (#739) 2018-09-09 20:47:16 +01:00
Tom Thorogood bfbb1715af Use ReadMsgUDP and WriteMsgUDP on windows (#738) 2018-09-08 17:33:21 +01:00
Tom Thorogood 7da8f0db5c Simplify (*Client).Dial handling of network type (#737)
* Simplify (*Client).Dial handling of network type

* Remove net.Dialer cast from (*Client).Dial
2018-09-08 17:27:21 +01:00
Tom Thorogood bf6da3a5bd Reduce UDP server memory usage (#735)
* Clear the response.msg field after unpacking

The allocated buffer cannot be freed by the garbage collector while the
response is alive, by clearing msg here, the GC can collect the buffer
sooner.

* Use a sync.Pool for UDP message buffers

* Return UDP message buffer to pool in all paths

* Move udpPool.New closure out of (*Server).init

The closure used to capture the *Server which would cause a reference
loop and prevent it from ever being released by the garbage collector.

This also gives the closure a more obvious name in memory profiles:
  github.com/miekg/dns.makeUDPBuffer.func1 rather than
  github.com/miekg/dns.(*Server).init.func1.
2018-09-08 17:15:17 +01:00
Tom Thorogood 3ce7efeace Fix Serve benchmark failures (#734)
* Fix Serve benchmark failures

At present, these benchmarks don't actually work or measure anything.
SetQuestion must have a fully qualified domain name (trailing dot) to
be valid. Because the question wasn't valid, the request never reached
the server and was rejected by the client.

With the error check added, the benchmarks started failing with:
--- FAIL: BenchmarkServe
    server_test.go:346: Exchange failed: dns: domain must be fully qualified

* Enable Serve6 benchmark

Currently this benchmark isn't run as it's not exported.

* Only enable BenchmarkServe6 when IPv6 is supported

The Serve6 benchmark has been disabled since 2014 (in 28d936c032)
because it doesn't play nice with Travis. We can just skip the benchmark
if it fails to bind to an IPv6 address.
2018-09-08 17:10:56 +01:00
Michael 9a34f54f7a Bump travis to 1.10/1.11 (#731) 2018-08-30 07:41:33 +01:00
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
Alberto Bertogli 28216bf382 Add dnss to the users list (#723) 2018-08-16 17:06:07 +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
Olivier Poitrey 21d95e19e6 readme: add dnstrace to Users section (#721) 2018-08-10 20:17:47 +01:00
Tom Thorogood 4a8fde8d2a Add go1.10.x to Travis (#718)
tip now points to what will be go1.11 leaving go1.10 untested.
2018-08-04 08:48:20 +01:00
Tom Thorogood b559d43c31 Abstract shutdown checking into seperate function (#716) 2018-07-28 13:47:30 +01:00
Tom Thorogood 1e845a5b06 Use RFC 8032 functions added to x/crypto/ed25519 (#715)
This was added in golang/crypto@5ba7f63082 and can replace the
workaround from #458.
2018-07-25 13:01:44 +01:00
Lorenzo Fontana 8004f28488 Add testcases to validate consistency of packDataNsec (#714)
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2018-07-23 22:44:09 +01:00
Jerry Jacobs 3e6e47bc11 README.md: Add github.com/xor-gate/sshfp (#706) 2018-07-01 19:37:35 +01:00
Miek Gieben e7c3f513a1
Remove compression from AFSDB (#704)
This type should not compress its rdata.

Fixes #521
2018-06-23 09:43:19 +01:00
Joel Sing ed07089f3b Correctly handle $GENERATE modifiers (#703)
* Add a ParseZone test for $GENERATE.

* Add a test for modToPrintf used by $GENERATE.

* Correctly handle $GENERATE modifiers.

As per http://www.zytrax.com/books/dns/ch8/generate.html, the width and type (aka base)
components of a modifier are optional. This means that ${2,0,d}, ${2,0} and ${2} are
valid modifiers, however only the first format was previously permitted. Use default
values for the width and/or type if they are unspecified in the modifier.
2018-06-23 09:12:44 +01:00
Miek Gieben df46691620
Add IsDuplicate function (#699)
The makes checking for duplicates more efficient, as you don't have to
use String() and re-parse elements from it anymore.

Fixes #679
2018-06-23 09:12:31 +01:00
Miek Gieben f90eb8fb45
tests: remove t.Log(f) when nothing is failing (#698)
* tests: remove t.Log(f) when nothing is failing

This clears up the travis output some more and adheres to the Unix
saying: no output is good news
2018-06-07 19:15:11 +01:00
Miek Gieben 4c681ac41f
dep ensure -update (#697)
* Some deletes

* some adds
2018-06-07 19:14:42 +01:00
Anton Korshikov c9cd01bc14 Update vendor libs (#690 and #655) (#694) 2018-06-06 18:35:07 +01:00
Andrew Tunnell-Jones 0a83f30697 Harden RSA public key unpacking (#693)
RFC 2537 (RSA/MD5) and RFC 3110 (RSA/SHA1) disallow leading zero octets.
RFC 5702 (RSA/SHA256 and RSA/SHA512) isn't specific but defers to these
earlier RFCs in other places.

There is an upper limit of 4096 bits for both the modulus and exponent.
The modulus must be at least 512 bits. No minimum is specified for the
exponent but a quick search suggests single byte exponents are viable.

Exponents larger than 32 bits are already disallowed. This commit adds
checks for the other requirements, general bounds checks, and defers
initialisation of the big num till the other checks have passed.
2018-06-05 07:18:10 +01:00
Miek Gieben 5a2b9fab83 Release 1.0.8 2018-06-04 22:06:13 +01:00
andrewtj da0e668c16 Fix unpacking RSA exponent and tighten exponent validation (#692)
* Add test from #688 demonstrating bug decoding RSA exponent

* Unpack RSA exponent in correct order

Fixes #688

* Don't unpack RSA keys with an exponent too large for the crypto package

* Update dnssec_test.go

Fix the one nit
2018-06-04 21:58:29 +01:00
Francois Tur d8bd04e7e1 Fix DialTimeout for direct call of Dial (#691)
* ensure dialTimeout is used at Dial time. Ensure dial functions setup the right timeout

* - on Dialing, ensure a dialTimeout for the Dialer only if it is just created, else keep going with parameters of the Dialer.
2018-06-04 21:36:08 +01:00
Tom Thorogood 8ccae88257 Require URLs for DOH addresses (#684)
* Require URLs for DOH addresses

* Move time.Now directly above http.Client.Do in DoH

* Remove https scheme check from DOH

Although the draft RFC explicitly requires that the scheme be https,
this was deemed undesirable, so remove it.
2018-05-29 15:39:02 +01:00
andrewtj 350cd086d1 Don't use padding in base32 helpers (#683)
The base32 variant NSEC3 uses doesn't have padding. This hasn't been a
problem in practice because SHA1 is the only current NSEC3 hash algorithm
and its output doesn't require padding.

No-pad support was introduced in Go 1.9 which is the oldest release this
package supports.
2018-05-21 20:47:51 +01:00
Miek Gieben 0947afec0a
Revert 6f3c0a126c (#682)
Previous behavior was correct. Checking with coredns:

current:

~~~
; <<>> DiG 9.10.3-P4-Debian <<>> +norec +noad +edns=1 +noednsneg soa miek.nl @localhost -p 1043
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: ?256, id: 35480
;; flags: qr; QUERY: 0, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 0
;; Query time: 0 msec
;; SERVER: ::1#1043(::1)
;; WHEN: Sat May 19 16:42:54 BST 2018
;; MSG SIZE  rcvd: 23
~~~

this pr:

~~~
; <<>> DiG 9.10.3-P4-Debian <<>> +norec +noad +edns=1 +noednsneg soa miek.nl @localhost -p 1043
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: BADVERS, id: 25912
;; flags: qr; QUERY: 0, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 0
;; Query time: 0 msec
;; SERVER: ::1#1043(::1)
;; WHEN: Sat May 19 16:51:28 BST 2018
;; MSG SIZE  rcvd: 23
~~~
2018-05-21 20:47:30 +01:00
Miek Gieben 0f8c7717de
doh: Fix mime type (#681)
Latest draft uses "application/dns-message".
2018-05-20 16:56:13 +01:00
Miek Gieben e57bf427e6 Release 1.0.7 2018-05-16 07:59:02 +00:00
Tom Thorogood 64746df23b WIP: DNS-over-HTTPS support for Client.Exchange API (#671)
* Add DNS-over-HTTPS support to (*Client).Exchange

* Ignore net/http goroutine leak from DoH

* Use existing Dialer and TLSConfig fields on Client for DOH

* Make DOH http.Client fully configurable

* Pipe context into exchangeDOH
2018-05-16 08:54:01 +01:00
Miek Gieben 3745b9737d
Small comment tweaks (#678)
Some post #668 comments nits.
2018-05-16 08:53:51 +01:00
Pierre Souchay 09649115c1 Fixed len computation when size just goes beyond 14 bits (#668)
* Fixed len computation when size just goes beyond 14 bits

* Added bouds checks around 14bits

* Len() always right including when around 14bits boudaries

* Avoid splitting into labels when not applicable

* Fixed comments

* Added comments in code

* Added new test cases

* Fixed computation of Len() for SRV and all kind of records

* Fixed Sign that was relying on non-copy for Unit tests

* Removed unused padding

* Fixed typo in PackBuffer() function

* Added comment about packBufferWithCompressionMap() for testing purposes
2018-05-16 07:20:13 +01:00
Uladzimir Trehubenka 621df0907e Make MaxTCPQueries configurable (#673) 2018-05-14 20:12:20 +01:00
Tom Thorogood 77d95a53d0 Handle empty NSEC3 salt in scanner (#677)
Fixes #676
2018-05-14 20:07:52 +01:00
chantra 1f2aa4c780 do not modify dns.Rcode when packing to wire format (#675)
* do not modify dns.Rcode when packing to wire format

When the message has an EDNS0 option in the additional section and
dns.Msg.Rcode is set to an extended rcode, dns.Msg.PackBuffer() modifies
dns.Msg.Rcode.
If you were to `Pack` the message and log it after, the Rcode would show
NOERROR.

Running the test before the change would error with:

```
=== RUN   TestPackNoSideEffect
--- FAIL: TestPackNoSideEffect (0.00s)
	msg_test.go:51: after pack: Rcode is expected to be BADVERS
```

after fixing dns.Msg.PackBuffer(), all tests are still passing.

Fixes #674

* address comments from PR#675
2018-05-13 08:36:02 +01:00
Miek Gieben a93f3e4f6b
copyHeader is redundant (#672)
copyHeader() is redundant, we allocate a header and then copy the
non-pointer elements into it; we don't need to do this, because if we
just asssign rr.Hdr to something else we get the same result.

Remove copyHeader() and the generation and use of it in ztypes.go.
2018-05-10 14:50:26 +01:00
Miek Gieben eac804ceef Release 1.0.6 2018-05-09 20:05:41 +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
Stefan Aurori 9c76f9827e Add DSA to SHA1 mapping in dnssec AlgorithmToHash (#670) 2018-05-05 19:03:36 +02: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
Tom Thorogood 3f2548fb60 Skip UDP OOB tests on unsupported architectures (#661) 2018-04-06 14:51:59 +01:00
Tom Thorogood 800934f8d4 Cleanup udp.go somewhat (#662)
* Avoid hard-coding required UDP OOB buffer size

* Simplify parseDstFromOOB if statements

* Use self-invoking function for udpOOBSize variable
2018-04-06 14:51:04 +01:00
Eric Greer 46f728d51b ExchangeWithDialer does not exist anymore (#666) 2018-04-06 12:05:09 +01:00
Miek Gieben 83c435cc65 Release 1.0.5 2018-04-01 13:59:20 +01:00