Commit Graph

123 Commits

Author SHA1 Message Date
João Oliveirinha ff611cdc4b
Add back support for *net.UnixCon with seqpacket type (#1378)
This was broken by PR:
2022-06-08 14:03:24 +02:00
Miek Gieben af1ebf55eb
Id check tests: stop using Exchange (#1343)
Using Exchange doesn't add anything, as it just wraps client.Exchange
with a default client.

Remove them and speed up the tests, goes from 3s to 1s (for the entire
test suite).

Signed-off-by: Miek Gieben <>
2022-03-02 13:52:49 +01:00
Tom Thorogood 0544c8bb11
Only treat a *net.UnixConn of unixgram as a packet conn (#1322)
* Refactor net.PacketConn checks into helper function

* Only treat a *net.UnixConn of unixgram as a packet conn

* Handle wrapped net.Conn types in isPacketConn

* Use Error instead of Fatal where appropriate in TestIsPacketConn
2021-12-28 13:52:38 +00:00
Andrey Meshkov 67bd57debd
Send DNS query in one packet when using TCP/TLS (#1219)
* Send DNS query in one packet when using TCP/TLS

* fix review comments

* Removed net.Buffers

* Added unit-tests for writing messages over TCP in one go
2021-02-13 19:49:02 +01:00
Tom Thorogood 0e1c4e69dd
Support generic net.PacketConn's for the Server (#1174)
* Support generic net.PacketConn's for the Server

This commit adds support for listening on generic net.PacketConn's for
UDP DNS requests, previously *net.UDPConn was the only supported type.

In the event of a future v2 of this module, this should be streamlined.

* Eliminate wrapper functions around RunLocalXServerWithFinChan

* Eliminate RunLocalTCPServerWithTsig function

* Replace RunLocalTLSServer with a wrapper around RunLocalTCPServer

This reduces code duplication.

* Add net.PacketConn server tests

This provides coverage over nearly all of the newly added code (with
the unfortunate exception of (*response).RemoteAddr).

* Fix broken client_test.go tests

a433fbede4 was merged into master between this PR being opened and
being merged. This broke the CI tests in rather strange ways as the
code was being merged into master in a way that wasn't at all clear.
This commit fixes the two broken lines.
2020-10-25 02:23:01 +10:30
Andrew Ayer a433fbede4
Ignore responses with unexpected IDs (#1155)
* Ignore replies with unexpected IDs

This fixes the following problem:

At time 0, we send a query with ID X from port P.

At time T, we time out the query due to lack of response, and then send
a different query with ID Y.  By coincidence, the new query is sent from
the same port number P (since port numbers are only 16 bits, this can happen
with non-negligible probability when making queries at a high rate).

At time T+epsilon, we receive a response to the original query.
Since the ID in this response is X, not Y, we would previously return
ErrId, preventing the second query from succeeding.

With this commit, we simply ignore the response with the mismatched ID
and return once we receive the response with the correct ID.

* Update test for bad ID

The new test sends two replies: the first one has a bad ID, which should
be ignored, and the second one has the correct ID.

* Add test to ensure query times out when server returns bad ID

* Avoid use of error string matching in test case

* Check for mismatched query IDs when using TCP

* Reduce timeout in TestClientSyncBadID
2020-10-18 07:55:24 +02:00
yaakov kuperman 1fc9fa1db0
Adds function ExchangeWithConn (#1110)
* Implements ExchangeWithConn, a function that allows callers to pass in a connection instead of having the library create a new one for them.  Exchange now wraps around this, implementing the existing behavior by creating a new connection and passing it to ExchangeWithConn. has been updated to support this behavior as well.

* adding tab

* formatting problem

* adds test case for ExchangeWithConn
2020-05-04 10:22:21 +02:00
Tom Thorogood 870a59089c Prevent timeout in TestConcurrentExchanges (#862)
This eliminates the possibility of deadlocking the handler and also
simplifies the test considerably.
2018-12-04 07:29:08 +00:00
Tom Thorogood 65b2aa0a63 Make TestTimeout less flaky (#863)
This test currently fails on occasion due to what appears to be
goroutine scheduling differences. This should eliminate those failures.
2018-12-03 07:40:52 +00:00
Tom Thorogood ff7d445081 Avoid setting the Rdlength field when packing records (#859)
* Avoid setting the Rdlength field when packing

The offset of the end of the header is now returned from the RR.pack
method, with the RDLENGTH record field being written in packRR.

To maintain compatability with callers of PackRR who might be relying
on this old behaviour, PackRR will now set rr.Header().Rdlength for
external callers. Care must be taken by callers to ensure this won't
cause a data-race.

* Prevent panic if TestClientLocalAddress fails

This came up during testing of the previous change.

* Change style of overflow check in packRR
2018-12-02 08:23:35 +00:00
Miek Gieben 1ff265a784
Remove ErrTruncated from the library (#815)
* Remove ErrTruncated from the library

ErrTruncated is removed. This (correctly) assume that a truncated
message will be fully formed. Any message that isn't fully formed will
return (most likely) an unpack error.

Any program using ErrTruncated will fail to compile when they update to
this version: this is by design: you're doing it wrong. For checking if
a message was truncated you should checked the msg.Truncated boolean;
assuming the unpack didn't fail.

Fixes #814

Signed-off-by: Miek Gieben <>

* Restore tests

Signed-off-by: Miek Gieben <>
2018-11-27 14:26:11 +00:00
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 <>

* Finish revert of DoH

Signed-off-by: Miek Gieben <>

* Add back in the race condition comment

Signed-off-by: Miek Gieben <>
2018-11-01 20:16:39 +00:00
Tom Thorogood c10ce5142a Fix race on loop variable in TestConcurrentExchanges (#773) 2018-10-04 07:24:09 +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
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
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
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 5f2d7c7013
Unpack: return header (#608)
When we unpack a message and only have the header consider it a valid
message and don't return an error.
2017-12-20 10:51:13 +00:00
Miek Gieben 7994cb36ea
Test: rework concurrentExchange (#576)
See issue #575. Try to fix (and maybe trigger it)
2017-11-17 15:31:51 +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 9cfd42f1df
Tests: add ListenAndServe tests (#562)
This increases the test coverage as these methods where not tested.
Add some cosmetic changes to the mix.
2017-11-10 10:11:23 +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
Miek Gieben 388f6eea29
Tests updates (#556)
Use :0 for loopback testing. This is more portable between testing environments.
Add testRR that calls NewRR and throws error away - apply it everywhere where needed.

It seems only Go 1.9 can deal with :0 being used. Disable 1.8 in travis.
2017-11-08 10:01:19 +00:00
Miek Gieben 348c84f37e
Test: remove all Logf/Log (#547)
Move some of them to Errorf and friends, but most of them are just
gone: This make go test -v actually readable.

Remove a bunch of test that used ipv6 on localhost as this does not work
on Travis.
2017-11-03 15:50:01 +00: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
Lars Lehtonen 0559e6d230 Fix ignored err variables. (#498)
* Fix ignored err variables.

* Removed unneeded err return.
2017-07-08 23:56:13 -07: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
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
Miek Gieben 5a15a35f5f Golint fixes (#456)
Fixes #370
2017-02-15 20:40:16 +00: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
Will Bond c9d1302d54 Add Client.Timeout to allow limiting total exchange duration (#345) 2016-04-19 11:29:51 +01:00
Rafael Dantas Justo 97f81a2cb5 Test client with TLS support
See #297
2016-01-08 11:34:08 -02:00
Miek Gieben f520760857 Lowercase all error msg from the tests 2015-11-26 14:12:38 +00:00
James Hartig 2d2c2ebcfc Instead of removing all RRs on Truncated, attempt to unpack 2015-11-01 15:51:09 -05:00
Masayoshi Sekimura ae0cb9ccb6 deleting a dot to retrigger travis CI 2015-10-05 20:14:57 -07:00
Masa Sekimura a9a71b9628 gofmt and revert unnecessary changes 2015-09-30 09:08:17 -07:00
Masayoshi Sekimura a14e77725f tidyup a little with the latest 2015-09-29 23:04:25 -07:00
Alex Sergeyev 7eb4621b6c Remove TestSingleInflight as per #250 2015-09-15 11:24:38 -04:00
Michael Haro 4c495b2aea Correct formatting directive in Log call 2015-08-22 10:10:57 -07:00
Miek Gieben 996ff55983 minimize the race in TestSingleInflight 2015-08-22 13:42:02 +01:00
Miek Gieben 076c8ffa9a Rename TestSingleSingleInflight to TestSingleInflight and some cosmetic changes 2015-08-22 08:55:23 +01:00
Miek Gieben 3e549e2f6f And of course the test too 2015-07-03 09:34:46 +01:00
Alex Sergeyev 2f3bcbd506 Added function for lazy message reading per #222 2015-06-28 20:21:37 -04: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
Harvo Jones 57d8407ad7 Changes applied:
* Added EDNS0LOCAL constants
* Added documentation
2015-03-18 12:12:53 -07:00
Harvo Jones 8bd3ac773f Add support for custom EDNS options in GoDNS.
A handful of EDNS options have been standardized, and they each have a type defined in GoDNS.  However there is currently no way a development team can use GoDNS with internally defined options, or with new options that may be proposed in the future.

This change solves the problem by giving users an EDNS0_CUSTOM type to allow clients to send, and servers to receive, custom EDNS options.
2015-03-17 10:41:55 -07:00
Michael Haro 2fb2a25e84 More test clean up
Remove trailing \n from t.Log and t.Error messages as it's unnecessary.

In some instances, combine multiple t.Error()s into one

To provide more consistency across the tests, rename e to err and use %v
as the format arg for errors.

Replace Logf and Errorf with Log and Error when it made sense.  For
example t.Errorf("%v", err) to t.Error(err)
2015-02-25 22:14:21 -08:00
Michael Haro f995f1aff3 Convert tests from being t.Log(..) then t.Fail() to just t.Error(...) as
t.Error(...) does both and makes it more clear which messages are errors
vs information log messages.
2015-02-23 17:43:07 -08: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