Commit Graph

257 Commits

Author SHA1 Message Date
Miek Gieben 6ae357d393
Revert doh (#800)
* Revert "Require URLs for DOH addresses (#684)"

This reverts commit 8ccae88257.

* Revert "WIP: DNS-over-HTTPS support for Client.Exchange API (#671)"

This reverts commit 64746df23b.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Finish revert of DoH

Signed-off-by: Miek Gieben <miek@miek.nl>

* Add back in the race condition comment

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-11-01 20:16:39 +00:00
Tom Thorogood 7f61c6631b
Fix dominikh/go-tools nits (#758)
* Remove unused functions and consts

* Address gosimple nits

* Address staticcheck nits

This excludes several that were intentional or weren't actual errors.

* Reduce size of lex struct

This reduces the size of the lex struct by 8 bytes from:
  lex.token string: 0-16 (size 16, align 8)
  lex.tokenUpper string: 16-32 (size 16, align 8)
  lex.length int: 32-40 (size 8, align 8)
  lex.err bool: 40-41 (size 1, align 1)
  lex.value uint8: 41-42 (size 1, align 1)
  padding: 42-48 (size 6, align 0)
  lex.line int: 48-56 (size 8, align 8)
  lex.column int: 56-64 (size 8, align 8)
  lex.torc uint16: 64-66 (size 2, align 2)
  padding: 66-72 (size 6, align 0)
  lex.comment string: 72-88 (size 16, align 8)
to:
  lex.token string: 0-16 (size 16, align 8)
  lex.tokenUpper string: 16-32 (size 16, align 8)
  lex.length int: 32-40 (size 8, align 8)
  lex.err bool: 40-41 (size 1, align 1)
  lex.value uint8: 41-42 (size 1, align 1)
  lex.torc uint16: 42-44 (size 2, align 2)
  padding: 44-48 (size 4, align 0)
  lex.line int: 48-56 (size 8, align 8)
  lex.column int: 56-64 (size 8, align 8)
  lex.comment string: 64-80 (size 16, align 8)

* Reduce size of response struct

This reduces the size of the response struct by 8 bytes from:
  response.msg []byte: 0-24 (size 24, align 8)
  response.hijacked bool: 24-25 (size 1, align 1)
  padding: 25-32 (size 7, align 0)
  response.tsigStatus error: 32-48 (size 16, align 8)
  response.tsigTimersOnly bool: 48-49 (size 1, align 1)
  padding: 49-56 (size 7, align 0)
  response.tsigRequestMAC string: 56-72 (size 16, align 8)
  response.tsigSecret map[string]string: 72-80 (size 8, align 8)
  response.udp *net.UDPConn: 80-88 (size 8, align 8)
  response.tcp net.Conn: 88-104 (size 16, align 8)
  response.udpSession *github.com/tmthrgd/dns.SessionUDP: 104-112 (size 8, align 8)
  response.writer github.com/tmthrgd/dns.Writer: 112-128 (size 16, align 8)
  response.wg *sync.WaitGroup: 128-136 (size 8, align 8)
to:
  response.msg []byte: 0-24 (size 24, align 8)
  response.hijacked bool: 24-25 (size 1, align 1)
  response.tsigTimersOnly bool: 25-26 (size 1, align 1)
  padding: 26-32 (size 6, align 0)
  response.tsigStatus error: 32-48 (size 16, align 8)
  response.tsigRequestMAC string: 48-64 (size 16, align 8)
  response.tsigSecret map[string]string: 64-72 (size 8, align 8)
  response.udp *net.UDPConn: 72-80 (size 8, align 8)
  response.tcp net.Conn: 80-96 (size 16, align 8)
  response.udpSession *github.com/tmthrgd/dns.SessionUDP: 96-104 (size 8, align 8)
  response.writer github.com/tmthrgd/dns.Writer: 104-120 (size 16, align 8)
  response.wg *sync.WaitGroup: 120-128 (size 8, align 8)
2018-09-27 04:02:05 +09:30
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 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
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
Miek Gieben 0f8c7717de
doh: Fix mime type (#681)
Latest draft uses "application/dns-message".
2018-05-20 16:56:13 +01: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
clmul 22cb769f47 use a local variable to calculate rtt (#656) 2018-03-27 08:01:29 +01:00
Matthijs Mekking cef5150e02 Fix issue #605 (#606)
This makes `client.Readmsg` always return the message,
regardless if and how unpacking the message failed.
2017-12-18 20:15:56 +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 b38dc3dcb7
Cleanup: gofmt -w -s *.go (#548)
Some renames of internal names to make go lint happier.
2017-11-03 16:15:35 +00:00
James Hartig 946bd9fbed Fix DialTimeout always using udp (#526) 2017-09-30 19:54:08 +01:00
insomniac aade52d68e Redesigned Client API around net.Dialer (#511)
* Redesigned Client API around net.Dialer

* Moved Dialer under Client; reverted msgHash; removed unneeded deprecation

* Reverted client_compat.go into client.go and renamed dialer variable

* Shortened comment lines

* Erroneously removed pointer declaration
2017-09-29 10:52:01 +01:00
Jacob Hoffman-Andrews e46719b2fe Add ExchangeContext methods. (#497)
These obey the timeouts provided in a Context.
2017-06-30 04:44:44 -07:00
Julius Rickert 2d7eb4f050 Fixed typo (#472) 2017-03-19 15:10:46 +00:00
devnev e95d107053 Fix data race in error handling. (#459)
The response message must copied regardless of whether there was an
error or not, otherwise two concurrent queries may modify the response
as they write it out.
2017-02-17 11:38:00 +00:00
Andrew Brampton ea75cede31 A co.Conn is not always a (*net.UDPConn) so don't convert to it. (#450) 2017-02-11 08:53:59 +00:00
Miek Gieben 4e953232d8 dns/tcp: more robust read. (#448)
My home router only return 1 byte on the initial tcp read of 2 bytes
for the size of the reply. We should read the other byte as well if this
happen.

With this fix, this:
~~~
% ./q -tcp @192.168.1.1 higgs
;; dns: short read
~~~

becomes:
~~~
% ./q -tcp @192.168.1.1 higgs
;; opcode: QUERY, status: NOERROR, id: 12968
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;higgs.	IN	 A

;; ANSWER SECTION:
higgs.	0	IN	A	192.168.1.108

;; query time: 10737 µs, server: 192.168.1.1:53(tcp), size: 44 bytes
~~~
2017-02-07 22:33:10 +00:00
Kevin Burke b4e7237e90 Fix typos (#405) 2016-10-03 15:10:00 +01:00
Miek Gieben b51e305bc6 Remove reflection (#376)
Everything is generated. Remove all uses of packStruct/unpackStruct and
make the library reflectionless.
2016-06-12 21:06:46 +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
Will Bond c9d1302d54 Add Client.Timeout to allow limiting total exchange duration (#345) 2016-04-19 11:29:51 +01:00
Miek Gieben 4a3ac71278 Better docs on client buffer size
Extend the documentation for Exchange to make it clear that it is
the callers responsibility to enable larger buffers.
2016-03-02 09:40:40 +00:00
Miek Gieben 0985f1e8ff Fix TCP rtt
TCP wasn't returning rrt info anymore, fix this. Also add
an issue_test.go where fixes for specific issues can be put.

Pull the rtt for udp message up into the function where we now
also set the rrt for tcp (for symmetry).
2016-02-28 16:36:19 +00:00
Nick Galbreath a7f8fcc762 spelling 2016-01-19 14:24:18 -08:00
Nick Galbreath 5cbabd2322 spelling 2016-01-19 14:23:11 -08:00
Rafael Dantas Justo 91335a81cf Change how we enable DNS over TLS option
We are removing the TLS atributte from Client type. Now if you want to enable
DNS over TLS you should use the value "tcp-tls", "tcp4-tls" or "tcp6-tls" in
Net attribute.

See #297
2016-01-08 11:21:03 -02:00
Rafael Dantas Justo ab77ae6734 Remove the TLS fallback strategy
After some thoughts, I realized that the fallback should be made by who is
using the client, as it will need to change the port (from 853 to 53). This
would also remove from the library the complexity of storing the recursive
nameservers that aren't working well with TLS (draft-ietf-dprive-dns-over-tls,
section 3.1).

See #297
2016-01-08 07:28:05 -02:00
Rafael Dantas Justo 020f925824 Change low level read/write for TLS connection
As tlc.Conn is just a TCP connection after the handshake, we will modify the
TCP functions to work with an io.Reader/io.Writer parameter instead of a
net.TCPConn so we can reuse them.

See #297
2016-01-07 13:27:07 -02:00
Rafael Dantas Justo 124839738d Fallback to normal connection if TLS fails
As described in document draft-ietf-dprive-dns-over-tls [1] we should fallback
to normal connection (without TLS) if there's any error with the TLS
connection.

See #297

[1] http://tools.ietf.org/html/draft-ietf-dprive-dns-over-tls-02
2016-01-04 10:49:20 -02:00
Rafael Dantas Justo ce3e1286f2 TLS connection must be via TCP
See #297
2016-01-04 10:46:14 -02:00
Rafael Dantas Justo 72d475a8fe Allow changing the default TLS configuration
When starting a TLS connection in some environments, we usually disabled some
certificates checks to allow tests with self-signed certificates. To disable
this checks we need to change some TLS parameters when starting a connection,
and for that we need to inject this parameters in the API.

Now the Client will also have an attribute for the TLS configuration
parameters. For future refactories, we could change the TLS attribute from bool
to a struct that would store the "Enable" flag and the configuration.

See #297
2016-01-04 10:30:39 -02:00
Rafael Dantas Justo 0d866c924c Add option in client to allow DNS over TLS
We should allow the client to send requests to a recursive DNS server using a
encrypted connection. This is proposed on the document
draft-ietf-dprive-dns-over-tls [1].

For now we didn't allow the API user to change the TLS configuration (using
defaults). We also need to add the intelligence to fallback to normal DNS when
the TLS connection fails (as described in the draft).

See #297

[1] http://tools.ietf.org/html/draft-ietf-dprive-dns-over-tls-02
2016-01-04 10:05:29 -02:00
James Hartig 2d2c2ebcfc Instead of removing all RRs on Truncated, attempt to unpack 2015-11-01 15:51:09 -05:00
Tomás Senart 56b3ff5401 client: SetReadDeadline after write, before read
The current code sets the read deadline at the same time as the write
deadline. If the write nearly times out but doesn't, the read timeout
can fire before the read happens within the specified deadline.
2015-10-06 13:34:20 +02: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 2f503031b0 Rename to ReadMsgHeader
Slightly more descriptive and remove the underscore of _DNSHeaderSize
and call is headerSize.
2015-07-03 09:31:53 +01:00
Alex Sergeyev b0d6ff308e Fixed things found in code review (comments, semantics). 2015-07-02 22:42:02 -04:00
Alex Sergeyev b625f190ce Not allocating 64K buffers for reading 2015-06-29 08:06:49 -04:00
Alex Sergeyev 53dfadf090 Shortened ReadMsg using ReadMsgBytes, added a constant. 2015-06-28 20:21:37 -04:00
Alex Sergeyev 2f3bcbd506 Added function for lazy message reading per #222 2015-06-28 20:21:37 -04:00
Alex Sergeyev 387c041985 Changed logic around reserving wire read buffer 2015-06-16 21:21:22 -04:00
Alex Sergeyev 416c39c6e9 Removed redundant code #220 2015-06-16 19:24:38 -04:00
Miek Gieben 031d041ced Merge pull request #209 from michaelharo/client
Cleanup Client.exchange
2015-05-07 07:28:34 +01:00
Michael Haro 32448f39cd Cleanup Client.exchange
Make Client's exchange function easier to read by moving timeout logic
into separate functions.

Start the timers closer to where they're used so that time from other
logic doesn't impact the deadlines.
2015-05-05 23:23:53 -07:00
Michael Haro b9c528f99c Keep Exchange as it was, but still check ID. 2015-05-05 23:20:46 -07:00
Michael Haro dddcd696ba Check that the query ID matches the answer ID.
Reduce some code duplication by making Exchange() use Client.Exchange().

When performing an Exchange if the query ID does not match the answer ID
return an error.  Also add a test for this condition.
2015-05-05 23:00:16 -07:00
Miek Gieben 6427527bba Check EDNS0 bufsize in Exchange()
In client.Exchange we *did* check for this size, to the same in the
function Exchange(). This bug surfaced in issue #184, this sort of
fixes it.

Closes #184.
2015-02-24 18:16:58 +00:00