Commit Graph

4104 Commits

Author SHA1 Message Date
Peter Banik 72df20724e Added github.com/peterzen/goresolver (#917)
goresolver is a DNSSEC validating resolver library based on miekg/dns
2019-03-04 07:36:23 +00:00
Jens Erat 092d7745b4 Ignore empty lines when parsing private keys (#911)
When migrating zones to CoreDNS, it did not accept private key files
the former bind setup gracefully accepted. It turned out they had a
trailing newline for whateveer reason. The dns library should handle
them gracefully, too.
2019-02-28 06:32:07 +00:00
Tom Thorogood 12ac8fb6e8 Add go1.12 to Travis CI (#915) 2019-02-28 06:29:30 +00:00
Tom Thorogood 39e689aa4a Fix String formatting of RP record (#914) 2019-02-28 06:28:44 +00:00
Tariq Ibrahim 164b22ef9a follow convention for deprecation notice in ExchangeConn (#908) 2019-02-07 07:30:09 +00:00
Dmitry Zubarev a288d199dc Fixed a misspelling. (#906) 2019-02-01 16:34:24 +00:00
Miek Gieben 8fc2e5773b Release 1.1.4 2019-01-30 18:12:07 +00:00
Francois Tur 896800ef1d fix OPT Record deep copy (#902)
* - implement deep-copy for OPT records + simple UT

* - adding ztypes.go (generated).

* - properly comment the specific behavior for EDNS0

* - remove too narrow UT + down-scope copy() method to package level only

* - tune comment
2019-01-30 18:11:33 +00:00
Anurag Goel 2df14c5c9f Add render to list (#904) 2019-01-29 07:32:45 +00:00
Miek Gieben 56be65265e Release 1.1.3 2019-01-12 10:18:55 +00:00
Miek Gieben 5c2ec9f7e4
RFC 1996 allows SOA in answer in notify (#900)
* RFC 1996 allows SOA in answer in notify

The answer section of a notify can contain a SOA record that we should
not ignore in the DefaultAcceptFunc.

* End sentence

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-01-12 10:11:11 +00:00
Tom Thorogood 5beb962416
Test for escaped dots in IsFqdn (#896)
This catches situations where the final dot in a name is actually
escaped. This was causing problems when packing these domain names.
2019-01-06 14:55:21 +10:30
Tom Thorogood c5493ad28d
Use an interface method for IsDuplicate (#883)
* Prevent IsDuplicate from panicing on wrong Rrtype

* Replace the isDuplicateRdata switch with an interface method

This is substantially simpler and avoids the need to use reflect.

* Add equal RR case to TestDuplicateWrongRrtype

* Move RR_Header duplicate checking back into IsDuplicate

This restores the previous behaviour that RR_Header's were never
equal to each other.

* Revert "Move RR_Header duplicate checking back into IsDuplicate"

This reverts commit a3d7eba50825d546074d81084e639bbecf9cbb57.

* Run go fmt on package

This was a mistake when I merged the master branch into this PR.

* Move isDuplicate method to end of RR interface
2019-01-06 14:42:38 +10:30
Tom Thorogood db3d0ce13b
Use an interface method for parsing zone file records (#886)
* Eliminate Variable bool from parserFunc

Instead we now check whether the last token read from the zlexer was
a zNewline or zEOF. The error check above should be tripped for any
record that ends prematurely.

* Use an interface method for parsing zone file records

* Prevent panic in TestOmittedTTL if no regexp match

* Move slurpRemainder into fixed length parse functions

This is consistent with the original logic in setRR and avoids potential
edge cases.

* Parse synthetic records according to RFC 3597

These records lack a presentation format and cannot be parsed otherwise.
This behaviour is consistent with how this previously operated.
2019-01-06 14:36:16 +10:30
Miek Gieben 44a8c5f8ba Release 1.1.2 2019-01-04 19:22:34 +00:00
Tom Thorogood 29b9bf368b Remove pointless casts (#895)
* Remove pointless casts

These are all casts where the value was already of the same type.

* Use var style for zero-value not cast style
2019-01-04 10:30:55 +00:00
Tom Thorogood 513c1ff221 Simplify and unify various returns (#893) 2019-01-04 10:19:42 +00:00
Tom Thorogood 57ca5ae8f4 Use headerSize const instead of hardcoded 12 (#894) 2019-01-04 10:19:01 +00:00
Tom Thorogood 34be74deeb Flatten goroutine inside goroutine in Transfer.In (#890)
* Flatten goroutine inside goroutine in Transfer.In

* Return an error for unknown question types

Previously this would just be silently ignored leaving nothing to close
the returned channel or return an error.
2019-01-04 08:14:40 +00:00
Tom Thorogood 09499bd07f Use IsFqdn and Fqdn helper functions more (#892) 2019-01-04 08:13:00 +00:00
Tom Thorogood b9e1e7529b Avoid calling RR.Header more than once per RR (#891)
* Avoid calling RR.Header more than once per RR

Header is an interface method so there's non-zero overhead when calling
it.

* Reset entire RR_Header in SIG.Sign

This is equivilant (while also clearing Rdlength) while being simpler.
2019-01-04 08:12:32 +00:00
Tom Thorogood e8b24e80da Move all reversed map creation into reverse.go (#889) 2019-01-04 08:10:15 +00:00
Tom Thorogood 5b818eed53 Use a value reciever for defaultReader (#888)
As defaultReader contains a single pointer, we can pass it by value and
avoid an allocation when it's put inside an interface{}.
2019-01-04 08:09:23 +00:00
Tom Thorogood ace4e60848 Make defaultMsgAcceptFunc a func not a var (#887) 2019-01-04 08:09:04 +00:00
Tom Thorogood b955100a79
Move RR header packing out of generated code (#885) 2019-01-04 10:09:14 +10:30
Tom Thorogood 813bd39114 Stop using packDomainName in IsDomainName (#873)
* Fork packDomainName for IsDomainName

* Eliminate msg buffer from packDomainName2

* Eliminate compression code from packDomainName2

* Remove off argument and return from packDomainName2

* Remove bs buffer from packDomainName2

* Merge packDomainName2 into IsDomainName

* Eliminate root label special case from IsDomainName

* Remove ls variable from IsDomainName

* Fixup comments in IsDomainName

* Remove msg == nil special cases from packDomainName

* Eliminate lenmsg variable from packDomainName

* Eliminate label counting from packDomainName

* Change off length check in IsDomainName

* Fix IsDomainName for escaped names

* Use strings.HasSuffix for IsFqdn

* Revert "Use strings.HasSuffix for IsFqdn"

I'll submit this as a seperate PR.

This reverts commit 80bf8c83700d121ea45edac0f00db52817498166.

* Cross reference IsDomainName and packDomainName

* Correct IsDomainName max length comment
2019-01-03 17:39:37 +01:00
Miek Gieben 1048d2bf96
Add newly released RFC to readme (#878)
Add RFC 8499 on DNS terminology. This is and will be used to name
various things in this package.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-01-03 17:37:57 +01:00
Tom Thorogood 57b81e0614 Use an interface method for unpacking records (#884)
* Use an interface method for unpacking records

* Eliminate err var declaration from unpack functions

* Remove pointless r.Data assignment in PrivateRR.unpack
2019-01-03 17:35:32 +01:00
Tom Thorogood 17dcb39074 Use (net.IP).Equal in isDuplicate functions (#882) 2019-01-03 17:32:22 +01:00
Tom Thorogood f9fcf1448b Return nil error from final return in unpack*() (#881)
This is consistent with the pack*() functions and is idiomatic Go.
2019-01-03 11:44:50 +01:00
Tom Thorogood bfd648e102
Rename NULL's Anything field to Data (#880) 2019-01-03 21:03:38 +10:30
Tom Thorogood 2533d75276 Move scanner comment handling out of scanRR (#877)
* Add comment getter to zlexer

* Use zlexer.Comment instead of lex.comment

* Move comment handling out of setRR code

* Move comment field from lex to zlexer

* Eliminate ZoneParser.com field

* Return empty string from zlexer.Comment on error

* Only reset zlexer.comment field once per Next

* Remove zlexer merge TODO

I'm pretty sure these have to remain separate which is okay.
2018-12-31 10:20:26 +01:00
Tom Thorogood ac5c421c48 Use binary.BigEndian.PutUint32 in EDNS0_EXPIRE.pack (#875) 2018-12-30 16:44:37 +01:00
Tom Thorogood 67bd05e2f4 Remove unused variable from switch in Field (#876) 2018-12-30 16:41:07 +01:00
Tom Thorogood 5913ad55e9 Use strings.HasSuffix for IsFqdn (#874) 2018-12-30 16:37:49 +01:00
Tom Thorogood b0835fab5e Reduce allocations in ReverseAddr (#872)
* Add ReverseAddr benchmarks

* Eliminate buffer allocation in ReverseAddr for v6

When the size of a slice is constant it can be allocated on the stack
rather than the heap.

name                old time/op    new time/op    delta
ReverseAddr/IP4-12     175ns ± 5%     173ns ± 4%     ~     (p=0.323 n=10+10)
ReverseAddr/IP6-12     364ns ±14%     218ns ±24%  -40.12%  (p=0.000 n=10+10)

name                old alloc/op   new alloc/op   delta
ReverseAddr/IP4-12     51.0B ± 0%     51.0B ± 0%     ~     (all equal)
ReverseAddr/IP6-12      176B ± 0%       96B ± 0%  -45.45%  (p=0.000 n=10+10)

name                old allocs/op  new allocs/op  delta
ReverseAddr/IP4-12      3.00 ± 0%      3.00 ± 0%     ~     (all equal)
ReverseAddr/IP6-12      3.00 ± 0%      2.00 ± 0%  -33.33%  (p=0.000 n=10+10)

* Reduce allocations in ReverseAddr for v4

name                old time/op    new time/op    delta
ReverseAddr/IP4-12     173ns ± 4%     140ns ±13%  -18.97%  (p=0.000 n=10+10)
ReverseAddr/IP6-12     218ns ±24%     218ns ±22%     ~     (p=0.838 n=10+10)

name                old alloc/op   new alloc/op   delta
ReverseAddr/IP4-12     51.0B ± 0%     48.0B ± 0%   -5.88%  (p=0.000 n=10+10)
ReverseAddr/IP6-12     96.0B ± 0%     96.0B ± 0%     ~     (all equal)

name                old allocs/op  new allocs/op  delta
ReverseAddr/IP4-12      3.00 ± 0%      2.00 ± 0%  -33.33%  (p=0.000 n=10+10)
ReverseAddr/IP6-12      2.00 ± 0%      2.00 ± 0%     ~     (all equal)

* Compare returned address in BenchmarkReverseAddr
2018-12-30 10:28:48 +00:00
Miek Gieben 56516cf4de
Add NULL record (#840)
Sorely missing from this library. Add it. As there is no presentation
format the String method for this type puts a comment in front of it.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-12-30 09:45:18 +00:00
cesarkuroiwa 5f5f2380fc Don't reject Nscount > 0 (#868)
* Don't reject Nscount > 0

IXFR request could have a SOA RR in the NS section
RFC 1995, section 3: https://tools.ietf.org/html/rfc1995

* Only one RR in the NS section is acceptable

* Remove URL from comment
2018-12-19 16:28:26 +00:00
Miek Gieben 450ab7d57f
Simplify TKEY presentation format (#856)
* Simplify TKEY presentation format

Just put add ";" in front of it, instead of the whole pseudo option
text.

Fixes #855

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

* Add more fields to presentation format - convert time using the RRSIG routines

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-12-04 07:31:40 +00: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
Miek Gieben 7586a3cbe8 Release 1.1.1 2018-12-02 09:00:23 +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
Tom Thorogood 470f08e191
Reduce compression memory use with map[string]uint16 (#852)
* Reduce compression memory use with map[string]uint16

map[string]uint16 uses 25% less memory per-entry than a map[string]int
(16+2)/(16+8) = 0.75. All entries in the compression map are bound by
maxCompressionOffset which is 14-bits and fits within a uint16.

* Add PackMsg benchmark with more RRs

* Add a comment to the compressionMap struct
2018-12-02 08:50:51 +10:30
Tom Thorogood 5c9c0e7818 Pretty print test compression map differences (#853)
* Pretty print test compression map differences

* Use compressionMapsDifference in TestPackDomainNameCompressionMap

This isn't strictly needed as it only contains a small number of
entries, but is consistent nonetheless.

* Fix map ordering in compressionMapsDifference
2018-12-01 08:30:40 +00:00
Tom Thorogood 6b6e08b48c
Stop compressing names in RT records (#847)
* Stop compressing names in RT records

Although RFC 1183 allows names in the RT record to be compressed with:
 "The concrete encoding is identical to the MX RR."

RFC 3597 specifically prohibits compressing names in any record not
defined in RFC 1035.

* Add comment to RT struct regarding compression
2018-11-30 22:50:24 +10:30
Tom Thorogood 8d24af5fb5 Fix compressed length calculations for escaped names (#850)
* Fix compressed length calculations for escaped names

* Add Len benchmark for escaped name

* Fix length with escaping after compression point

* Avoid calling escapedNameLen multiple times in domainNameLen

* Use regular quotes for question in TestMsgCompressLengthEscaped
2018-11-30 07:50:49 +00:00
Tom Thorogood 6ade5b5fff Move compress=false out of packDataDomainNames into caller (#849)
This makes packDataDomainNames more consistent with PackDomainName where
it will only be called with compress = true for `dns:"cdomain-name"`.
2018-11-30 07:49:06 +00:00
Tom Thorogood 778aa4f83d
Properly calculate compressed message lengths (#833)
* Remove fullSize return from compressionLenSearch

This wasn't used anywhere but TestCompressionLenSearch, and was very
wrong.

* Add generated compressedLen functions and use them

This replaces the confusing and complicated compressionLenSlice
function.

* Use compressedLenWithCompressionMap even for uncompressed

This leaves the len() functions unused and they'll soon be removed.

This also fixes the off-by-one error of compressedLen when a (Q)NAME
is ".".

* Use Len helper instead of RR.len private method

* Merge len and compressedLen functions

* Merge compressedLen helper into Msg.Len

* Remove compress bool from compressedLenWithCompressionMap

* Merge map insertion into compressionLenSearch

This eliminates the need to loop over the domain name twice when we're
compressing the name.

* Use compressedNameLen for NSEC.NextDomain

This was a mistake.

* Remove compress from RR.len

* Add test case for multiple questions length

* Add test case for MINFO and SOA compression

These are the only RRs with multiple compressible names within the same
RR, and they were previously broken.

* Rename compressedNameLen to domainNameLen

It also handles the length of uncompressed domain names.

* Use off directly instead of len(s[:off])

* Move initial maxCompressionOffset check out of compressionLenMapInsert

This should allow us to avoid the call overhead of
compressionLenMapInsert in certain limited cases and may result in a
slight performance increase.

compressionLenMapInsert still has a maxCompressionOffset check inside
the for loop.

* Rename compressedLenWithCompressionMap to msgLenWithCompressionMap

This better reflects that it also calculates the uncompressed length.

* Merge TestMsgCompressMINFO with TestMsgCompressSOA

They're both testing the same thing.

* Remove compressionLenMapInsert

compressionLenSearch does everything compressionLenMapInsert did anyway.

* Only call compressionLenSearch in one place in domainNameLen

* Split if statement in domainNameLen

The last two commits worsened the performance of domainNameLen
noticably, this change restores it's original performance.

name                            old time/op    new time/op    delta
MsgLength-12                       550ns ±13%     510ns ±21%    ~     (p=0.050 n=10+10)
MsgLengthNoCompression-12         26.9ns ± 2%    27.0ns ± 1%    ~     (p=0.198 n=9+10)
MsgLengthPack-12                  2.30µs ±12%    2.26µs ±16%    ~     (p=0.739 n=10+10)
MsgLengthMassive-12               32.9µs ± 7%    32.0µs ±10%    ~     (p=0.243 n=9+10)
MsgLengthOnlyQuestion-12          9.60ns ± 1%    9.20ns ± 1%  -4.16%  (p=0.000 n=9+9)

* Remove stray newline from TestMsgCompressionMultipleQuestions

* Remove stray newline in length_test.go

This was introduced when resolving merge conflicts.
2018-11-30 10:03:41 +10:30
Tom Thorogood 2c039114d2 Use a table lookup for escaping unprintable bytes (#846) 2018-11-29 19:57:48 +00:00