Commit Graph

3799 Commits

Author SHA1 Message Date
Tom Thorogood 2f8cf50b32
Add a HashName benchmark 2018-11-29 10:28:29 +10:30
Tom Thorogood 1afd10068a
Rename wire to wireSalt in HashName
This is slightly clearer.
2018-11-29 10:25:34 +10:30
Tom Thorogood 4058ac87fa
Remove saltWireFmt from nsecx.go
This isn't really needed and doesn't make the code any clearer.
2018-11-29 10:24:25 +10:30
Miek Gieben fa589750ad
Merge pull request #842 from tmthrgd/compression-map-escaped
Put escaped names into compression map
2018-11-28 23:39:22 +00:00
Tom Thorogood 56118562d7
Fix typo in TestMsgCompressLengthEscapingMatch comment 2018-11-29 09:58:18 +10:30
Tom Thorogood d27f0d3482
Add a test case to cover escaping in the compression map 2018-11-29 09:53:00 +10:30
Tom Thorogood 07ae768ab1
Put escaped names into compression map in PackDomainName 2018-11-29 09:49:18 +10:30
Tom Thorogood c1ad186588
Use compressionMapsEqual in TestPackDomainNameCompressionMap 2018-11-29 09:48:02 +10:30
Miek Gieben a220737569 Release 1.1.0 2018-11-28 23:08:28 +00:00
Miek Gieben 1c92765836
Merge pull request #830 from miekg/passfunc
Add MsgAcceptFunc
2018-11-28 23:07:35 +00:00
Miek Gieben f92da6fc6e Code review
Signed-off-by: Miek Gieben <miek@miek.nl>
2018-11-28 22:40:08 +00:00
Miek Gieben fef7963e99 remove newlines
Signed-off-by: Miek Gieben <miek@miek.nl>
2018-11-28 22:32:50 +00:00
Miek Gieben ab67d69d9b review
Signed-off-by: Miek Gieben <miek@miek.nl>
2018-11-28 22:25:28 +00:00
Tom Thorogood 6aa28be819
Bail early from UnpackDomainName when name is too long (#839)
* Simplify maxDomainNameWireOctets checking in UnpackDomainName

* Don't return too long name in UnpackDomainName

* Simplify root domain return in UnpackDomainName

* Bail early from UnpackDomainName when name is too long

This drastically reduces the amount of garbage created
in UnpackDomainName for certain malicious names.

The wire formatted name
 "\x3Faaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuu\xC0\x00"
would previously generate 1936B of garbage (36112B since maxCompressionPointers
was raised) before returning the "too many compression pointers" error, while
it now generates just 384B of garbage.

* Change +1 budget comment to reflect spec

This better reflects what maxDomainNameWireOctets is actually measuring.

* Remove budget check from after loop in UnpackDomainName

This can never be tripped as budget is always checked immediately after
subtracting inside the loop.

* Improve UnpackDomainName documentation
2018-11-29 08:26:30 +10:30
Miek Gieben 091d66a39f
Merge pull request #818 from tmthrgd/comp-opt
Improve PackDomainName performance
2018-11-28 18:53:23 +00:00
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