Commit Graph

3834 Commits

Author SHA1 Message Date
Miek Gieben db37038897 fix docs
Signed-off-by: Miek Gieben <miek@miek.nl>
2018-11-28 18:45:19 +00:00
Miek Gieben 74dbfccc11 Code Review
Signed-off-by: Miek Gieben <miek@miek.nl>
2018-11-28 18:42:48 +00:00
Miek Gieben 2c18e7259a Add MsgAcceptFunc in server
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>
2018-11-28 18:42:48 +00:00
Miek Gieben 6bf402f3c4
Fix "too many compression points" for valid message (#835)
* Increase the maximum number of allowed compression pointers

* Add a Pack+Unpack test case for many compression pointers

* Clarify maxCompressionPointers comment
2018-11-28 11:45:22 +00:00
Tom Thorogood 64a73613cd Use range loop in packBufferWithCompressionMap (#837)
* 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
2018-11-28 11:44:23 +00:00
Tom Thorogood d193d08243
Clarify maxCompressionPointers comment 2018-11-28 21:38:37 +10:30
Tom Thorogood 32d8e33ba2
Add a Pack+Unpack test case for many compression pointers 2018-11-28 19:53:00 +10:30
Tom Thorogood c567cfc2bb
Increase the maximum number of allowed compression pointers 2018-11-28 19:52:41 +10:30
Tom Thorogood 7ae05cdcf8
Use map[string]struct{} for compression map in Len (#820)
* 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
2018-11-28 08:02:08 +10:30
Tom Thorogood 34d23c00e1
Add bounds check comment to dddToByte 2018-11-28 07:42:44 +10:30
Miek Gieben a7e7488e1d
doc: Clean up README and doc.go (#817)
Cleans this up a bit.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-11-27 14:39:19 +00:00
Tom Thorogood 03d7306558 Fix NotImp RCode string (#819)
* Fix NOTIMP typo in RcodeToString

RFC 6895 lists RCODE 4 as NotImp.

* Accept legacy NOTIMPL spelling in StringToRcode
2018-11-27 14:38:33 +00:00
Tom Thorogood c03bc41f33 Remove pointless cast from unpackUint48 (#827) 2018-11-27 14:34:23 +00:00
Tom Thorogood e2f69345fd Avoid creating compression map for question only Msg (#823)
* 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
2018-11-27 14:34:07 +00:00
Tom Thorogood 11fb61cb84 Use copy instead of loop in EDNS0_SUBNET.unpack (#825) 2018-11-27 14:32:41 +00:00
Tom Thorogood 8eab0120c4 Use FQDN for question in TestCompressLength (#831)
This was a bug.
2018-11-27 14:28:13 +00:00
Tom Thorogood e969cef252 Use t.Errorf not panic in TestCompressionLenSearch (#832) 2018-11-27 14:26:34 +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 <miek@miek.nl>

* Restore tests

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-11-27 14:26:11 +00:00
Tom Thorogood 8f269a6b16
Use strings.EqualFold rather than strings.ToLower (#828)
strings.ToLower may allocate and will do more work than
strings.EqualFold.
2018-11-27 21:36:27 +10:30
Tom Thorogood 30d0133e57
Revert commits unrelated to PackDomainName
This reverts commit 2eeda8aabc,
                    8e6e188a87
                and 7bef528091.
2018-11-27 17:55:48 +10:30
Tom Thorogood f522504216
Eliminate roBs allocation from packDomainName
This allocation only occurred when s was escaped, but will no longer
occur.
2018-11-26 16:43:21 +10:30
Tom Thorogood 07ed56b1d6
Add isRootLabel helper for packDomainName
This handles the bs == nil case internally.
2018-11-26 16:38:15 +10:30
Tom Thorogood 149f3c884f
Move bs allocation above length check in packDomainName 2018-11-26 16:16:08 +10:30
Tom Thorogood 7f4b3bb806
Only copy once per \DDD in packDomainName
Previously the remainder of bs would be copied twice.
2018-11-26 16:13:32 +10:30
Tom Thorogood 6aa05940d5
Reset roBs even if compress is false in packDomainName
By only resetting roBs when compress is true, the compression map can
end up with inconsistent entries between compress being true and false.
2018-11-26 16:04:34 +10:30
Tom Thorogood 896cef4ce4
Replace bsFresh variable with bsDirty in packDomainName
This avoids needing to initialise it to true.
2018-11-26 16:00:37 +10:30
Tom Thorogood 5547fd63a0
Fix garbage after name in compression map
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.
2018-11-26 15:53:29 +10:30
Tom Thorogood 260b5b401d
Only compute i-begin once in packDomainName 2018-11-26 15:09:47 +10:30
Tom Thorogood e5bc3b14fb
Use lenmsg rather than len(msg) in packDomainName
This is purely for consistency, they are always equal at this point.
2018-11-26 15:08:05 +10:30
Tom Thorogood 9358e95aef
Simplify final returns from packDomainName 2018-11-26 15:07:17 +10:30
Tom Thorogood 926752f160
Remove nameoffset variable from packDomainName
This is now always equal to off, so use that instead.
2018-11-26 15:05:51 +10:30
Tom Thorogood 03053758d4
Add whitespace to packDomainName 2018-11-26 15:04:35 +10:30
Tom Thorogood 4c43711692
Remove End goto in packDomainName 2018-11-26 15:03:49 +10:30
Tom Thorogood 36a30d2e58
Remove tainted zeroing from packDomainName
With the label copying now moved after the compression, the msg buffer
will no longer be tainted and need clearing.
2018-11-26 15:02:17 +10:30
Tom Thorogood 8995ae83e3
Move label copying below compression in packDomainName
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.
2018-11-26 14:59:17 +10:30
Tom Thorogood ecef32b31b
Merge lenmsg checks in packDomainName 2018-11-26 14:53:33 +10:30
Tom Thorogood 3534784466
Reorder if-statements in packDomainName 2018-11-26 14:50:37 +10:30
Tom Thorogood 7bef528091
Remove pointless cast from unpackUint48 2018-11-26 14:40:27 +10:30
Tom Thorogood bf8065a091
Simplify double dot check in packDomainName 2018-11-26 12:32:35 +10:30
Tom Thorogood 0125cf9d0c
Simplify initial fqdn check in packDomainName 2018-11-26 12:25:11 +10:30
Tom Thorogood 77d26d8088
Avoid allocating copy of s in packDomainName
In the more common case, where the domain name has no escaping, this
avoids an allocation.
2018-11-26 12:21:09 +10:30
Tom Thorogood c12f225763
Use a switch statement in packDomainName 2018-11-26 12:07:46 +10:30
Tom Thorogood 8e6e188a87
Use NextLabel in compressionLenHelper
This avoids the allocation of Split and should have slightly better
performance.
2018-11-26 12:02:04 +10:30
Tom Thorogood 3b3a5b7c6a
Replace another for loop with copy in packDomainName
This change is included as a separate commit because this loop is not as
trivial as the others.
2018-11-26 12:00:33 +10:30
Tom Thorogood 8d08c56229
Replace simple loops with copy in packDomainName 2018-11-26 11:59:38 +10:30
Tom Thorogood ab9dd29c1d
Hoist bounds check in dddToByte
This eliminates two of the bounds checks in dddToByte and
dddStringToByte.
2018-11-26 11:52:43 +10:30
Tom Thorogood 2eeda8aabc
Use copy instead of loop in EDNS0_SUBNET.unpack 2018-11-26 11:51:55 +10:30
chantra 1c9c9bf4c9 properly set extended rcode when packing (#791)
* 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
2018-11-17 10:30:14 +10:30
Yasar Alev 043a442757 nsec3 cover problems (#804)
* nsec3 cover fix

* nsec3 cover fix test

* nsec3 covered empty intervals

* nsec3 another condition

* nsec3 empty interval wildcard test

* nsec3 empty interval comment
2018-11-13 23:30:58 +00:00
Miek Gieben 7064f7248f Release 1.0.15 2018-11-03 09:44:52 +00:00