Generalize the srv.Unsafe and make it pluggeable. Also add a default
accept function that allows to discard malformed DNS messages very early
on. Before we allocate and parse anything furher.
Also re-use the client's message when sending a reply.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Increase the maximum number of allowed compression pointers
* Add a Pack+Unpack test case for many compression pointers
* Clarify maxCompressionPointers comment
* Use range loops in Msg.packBufferWithCompressionMap
* Remove rr set variables in Msg.packBufferWithCompressionMap
* Move Header var down in Msg.packBufferWithCompressionMap
* Move stripTsig comment into Msg.Unpack
* Use map[string]struct{} for compression map in Len
map[string]int requires 8 bytes per entry to store the unused position
information.
* Add MsgLength benchmark with more RRs
* Pass dns.Compress explicitly to packBufferWithCompressionMap
* Avoid creating compression map for question only Msg
This idea was inspired by:
"Skip dname compression for replies with no answers."
https://www.nlnetlabs.nl/bugs-script/show_bug.cgi?id=235
* Continue compressing multiple questions
* 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 <miek@miek.nl>
* Restore tests
Signed-off-by: Miek Gieben <miek@miek.nl>
When packDomainName is called with an escaped domain name and compress
being true, bs wasn't be truncated to the correct length and would
include garbage that would be included in the compression map.
When the dname is found in the compression map and compress is true,
this copy is as it will simply be overwritten later. This could provide
a very slight speedup.
* properly set extended rcode when packing
When calling `SetExtendedRcode`, we expect to get the full extended
rcode, not the rcode after we shift 4 bytes right.
* fix extended rcode
* fix TestOPTTtl test
* set error messages in TestPackExtendedBadCookie
* Set Rcode with extended rcode
* |=
* Set extended RCODE field to 0 when RCODE is not an extended one.
+ unittests
* Force setting extended rcode if we have an OPT available.
* go fmt + @tmthrgd comments
* comments and nits
* reformat comment
* Add test that srv.conns is empty in checkInProgressQueriesAtShutdownServer
* Track ResponseWriter Close without nil-ing tcp
* Remove LocalAddr and RemoteAddr panic after Close
This is no longer needed as the tcp field is no longer set to nil in
Close.
* Add more explicit WriteMsg panic after Close
Previously this would panic with `dns: Write called after Close` which
is obviously less clear.
* Panic if Hijack is called after Close
Previously this worked, but later calls to Write would panic. This is
more explicit.
* Return an error if Close called multiple times
Neither io.Closer, nor ResponseWriter, provide any guarantees about the
behaviour of multiple calls to Close. This was made explicit in
https://golang.org/cl/8575043 and in practice implementations differ
wildly.
This matches ShutdownContext which returns an error if called multiple
times.
* Check map len under lock in checkInProgressQueriesAtShutdownServer
* Correct error message in checkInProgressQueriesAtShutdownServer
* Remove panic-after-Close from Hijack
* Return errors, not panic, on Write after Close