Commit Graph

136 Commits

Author SHA1 Message Date
Miek Gieben 9dcf47a409
Doc updates (#1075)
* Doc updates

Was reading https://pkg.go.dev/github.com/miekg/dns?tab=doc and spotted
some types and things to could be slightly better.

Make v unexported, as this version stuff should not be part of the
public API.

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

* fix test

Signed-off-by: Miek Gieben <miek@miek.nl>
2020-02-14 22:47:21 +01:00
Tom Thorogood d051b464e9 Add a message truncation implementation (#854)
* Add a message truncation implementation

* Remove OPT if-statement at end of Scrub

* Impose RFC 6891 payload size limit in Scrub

* Remove *Msg receiver from truncateLoop

* Remove OPT record creation from Scrub

* Test that TestRequestScrubAnswerExact has correct record count

* Rename (*Msg).Scrub to Truncate

This better reflects it's purpose.

* Remove comment reference to scrubbing in Truncate

* Properly calculate the length of OPT record in Truncate

* Correct comment in IsEdns0 in regards to RFC 6891

* Handle the OPT record being anywhere in Truncate

* Slight cleanup of Msg.Truncate
2019-03-24 09:20: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 57ca5ae8f4 Use headerSize const instead of hardcoded 12 (#894) 2019-01-04 10:19:01 +00:00
Tom Thorogood 09499bd07f Use IsFqdn and Fqdn helper functions more (#892) 2019-01-04 08:13:00 +00:00
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
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
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
Miek Gieben dcdbddd810
ClassANY: don't convert CLASS255 to ANY (#618)
* ClassANY: don't convert CLASS255 to ANY

Class "ANY" is wireformat only. In zonefile you can use CLASS255, but
when String-ing we convert this into "ANY" which is wrong. I.e. this
means we can't read back our own update.

Bit of a kludge to work around this, as I'm not sure we can just remove
ANY from the ClassToString map.
2018-01-07 17:57:04 +00:00
Ray Bellis 193f91db0b Fix default response generation (#492)
- response Opcode must match request
- RD and CD semantics are only defined for QUERY
2017-05-24 15:34:52 +01:00
Matthijs Mekking 2be0b50f7f use the fudge (#441) 2017-01-26 12:40:32 +00:00
Miek Gieben dd83d5cbcf IsSubDomain docs
Improve the docs a little and add a test for when the child and parent
are equal.
2016-04-12 22:05:53 +01:00
Miek Gieben 51f75cadab Optimize IsEdns0
Start at the end of the additional section instead of the beginning.
Optionally we only scan the last 2 records, and get rid of the loop
in its entirety.
2016-04-08 08:22:36 +00:00
Miek Gieben 68ed04e36e More documentation for IsDomainName 2015-09-22 07:41:03 +01:00
Aaron Lehmann 2cee5e58b0 Rename isValidRRSet to IsRRset, and move it to defaults.go 2015-06-28 17:04:05 -07:00
Miek Gieben 0fda12a2bb Add extra docs for SetQuestion and SetNotify
See issue #196
2015-03-25 09:52:14 +00: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
Miek Gieben f2aff624fc Fix SetIxfr
Making a ixfr message requires a complete SOA. Add to paramaters
to SetIxfr: Ns and Mbox that will be used in the SOA in the msg.
2015-01-22 09:01:49 +00:00
Miek Gieben d8da4d2fa7 Fix: drop requests with *cough* qr set.
Err, yeah.
2014-10-19 09:36:26 +00:00
Miek Gieben 0aa3021a83 Remove all copyright notices
Use the central COPYRIGHT file.
2014-09-11 20:57:37 +01:00
Miek Gieben 9b0cfb5a13 Dont mirror CD bit 2014-08-07 22:29:44 +01:00
Miek Gieben 22f120cfe8 Copy CD bit too 2014-08-05 21:17:24 +01:00
Miek Gieben 17c7921aa2 Documentation updates 2014-07-31 08:48:26 +00:00
Miek Gieben 060e66250e Add IsMsg()
A quick validating function that checks if a buffer is a valid
DNS message.
The code is *far* from complete.
2014-05-18 09:02:00 +01:00
Miek Gieben b7a8c14d7d Add dns.Name as a type
This can be used for printing names.
2014-04-23 21:06:17 +01:00
Miek Gieben 37356f5e68 Documenation fixes 2014-01-12 10:43:59 +00:00
Alex Ciuba 848a6c7268 Refactor SetRcode, rd bit is now set properly for error packets 2014-01-05 15:20:41 -05:00
Miek Gieben b435d836c6 gofmt 2013-10-15 14:21:47 +00:00
Miek Gieben 79cce8e6c8 Small go vet issues 2013-10-15 14:21:32 +00:00
Miek Gieben 9c1ee5d5ca Update IsDomainName
This new functions just compiles the domain to wire format, if that
works, the name is deemed OK. It is also much less strict than the
older code. Almost everything is allowed in the name, except two
dots back to back (there is an explicit test for that).
2013-09-10 18:09:22 +00:00
Miek Gieben 9c72d3aa52 Fix docs 2013-09-10 13:21:55 +00:00
Miek Gieben 47cc5b052d Work on making IsDomainName better 2013-09-10 13:13:10 +00:00
Miek Gieben db41985b91 copy the optimization from go tip into here 2013-08-23 18:41:35 +00:00
Miek Gieben 83a2c0b789 small tweaks 2013-06-23 21:41:49 +01:00
Miek Gieben e15a4b1508 Dont downcase when doing IsSubDomain, let the caller decide 2013-06-22 09:26:20 +01:00
Miek Gieben 38ea608d79 Rename the Label* functions
SplitLabels -> SplitDomainName
CompareLabels -> CompareDomainName
LenLabels -> CountLabel
          -> NextLabel was added as a simple iterator-like function
2013-06-22 07:21:15 +00:00
Miek Gieben 5f6228d4cc Use the non-exported version err 2013-06-20 07:27:28 +01:00
Miek Gieben 70f9c6b964 Make err non-exported 2013-06-20 07:25:29 +01:00
fdeweerdt 6de33f30fe Fix 1.1.1 missing return error 2013-06-18 10:38:14 -07:00
Miek Gieben d171a352d9 Small fix for go < 1.1 versions 2013-06-15 18:27:52 +01:00
Miek Gieben 6ee0baab56 anything escaped in domain name is legal
Allow all character after a \ in a domainname. It's escaped, it's
legal.
2013-06-13 19:41:37 +01:00
Miek Gieben b35306b755 Created two new types: Type and Class
Actually just go with Robert's suggestion as this seems the
cleanest way to do it. Also saves me from thinking about could
names for the new functions.
2013-06-08 14:09:37 +01:00
Miek Gieben c72535f2d6 Add TypeToTypeString and ClassToClassString
After some discussion with Robert Edmonds, these helper functions
seems in order. It is not what he requested (that was an RRType
and RRClass as new types), but is does make sense to add some
convience functions to save some typing. The dns package itself
also used these function (4 times). So clearly there is a need.

I'm not completely sold about the names.
2013-06-08 13:59:49 +01:00
Miek Gieben e8e8e84200 remove println 2013-06-05 22:33:15 +01:00
Miek Gieben f6c697f52b Fix IsDomainName
Make \.. legal (as it should be) and don't allocate a new var byte c
and every loop.
2013-06-05 22:06:02 +01:00
Miek Gieben 81941d4422 Update all copyright notices 2013-05-12 16:15:52 +02:00
Miek Gieben d53d9eab81 gofmt 2013-05-05 20:30:44 +02:00
Miek Gieben 235e892dfc Rename the RR types drop the RR_ prefix
This is also done in the official Go library. It also make the
code shorter.
2012-12-09 19:23:25 +01:00
Miek Gieben d758825590 more documentation 2012-12-02 10:14:53 +01:00