Commit Graph

337 Commits

Author SHA1 Message Date
DesWurstes 0972db6834
Implement SVCB (#1067)
* Implement SVCB

* Fix serialization and deserialization of double quotes

* More effort (?)

4 months old commit

* DEBUG

* _

* Presentation format serialization/deserialization

* _

Remove generated

* Progress on presentation format parse & write

* _

* Finish parsing presentation format

* Regenerate

* Pack unpack

* Move to svcb.go

Scan_rr.go and types.go should be untouched now

* 🐛

Thanks ghedo

* Definitions

* TypeHTTPSSVC

* Generated

and isDuplicate

* Goodbye lenient functions

Now private key=value pairs have to be defined as structs too. They are no longer automatically named as KeyNNNNN

* Encode/decode

* Experimental svc

* Read method

* Implement some of the methods, use trick...

to  report where the error is while reading it. This should be applied to EDNS too. Todo: Find if case can only contain e := new(SVC_ALPN) and rest moved out

Also fix two compile errors

* Add SVC_LOCAL methods, reorder, remove alpn value, bugs

* Errors

* Alpn, make it build

* Correct testsuite

* Fully implement parser

Change from keeping a state variable to reading in one iteration until the key=value pair is fully consumed

* Simplify and document

EDNS should be simplified too

* Attempt to fix fuzzer

And Alpn bug

* A bug and change type values to match @ghedo's implementation

* IP bug

Also there are two ip duplicating patterns, one with copy, one with append. Maybe change it to be consistent.

* Check for strictly increasing keys as required

* Don't panic on invalid alpn

* Redundant check, don't modify original array

* Size calculation

* Fix the fuzzer, match the style

* 65535 is reserved too, don't delay errors

* Check keyNNN, check for aliasform having values

* IPvNHint is an array

* Fix ipvNHint

* Rename everything

* Unrecognized keys according to the updated specification

* Skip zero-length structs in generators. Fix CI

* Doc cleanup

* Off by one

* Add parse tests

* Check if private key doesn't collide with known key, invalid tests

* Disallow IPv4 as IPv6. More tests.

Related #1107

* Style fixes

* More consistency, more tests

* 🐛 Deep copy as in the documentation

	a := make([]net.IP, 1)
	a[0] = net.ParseIP("1.1.1.1").To4()
	b := append(make([]net.IP, 0, 1), a...)
	b[0] = net.ParseIP("3.1.1.1").To4()
	fmt.Println(a[0][0])

* Make tests readable

* Move valid parse tests to different file

* 🐛 One of previous commits not fully committed

* Test binary single value encoding/decoding and full encode/decode

* Add worst-case grows to builders, 🐛 Wrong visible character range, redundant tests

* Testing improvements

And don't convert to IPv4 twice

* Doc update only

* Document worst case allocations

and ipv6 can be at most of length 39, not 40

* Redundant IP copy, consistent IPv6 behavior, fix deep copy

* isDuplicate for SVCB

* Optimizations

* echoconfig

* Svc => SVCB

* Fix CI

* Regenerate after REBASE (2)

Rebased twice on 15th and 20th May

* Rename svc, use escapeByte.

* Fix parsing whitespaces between quotes, rename ECHOHOConfig

* resolve

Remove svcbFieldLen
Use reverseInt
Uppercase SVCB
Rename key_value
"invalid" => bad
Alpn comments
> 65535 check
Unneeded slices

* a little more

read => parse
IP array meaning
Force pushed because forgot to change read in svcb_test.go

* HTTPSSVC -> HTTPS

* Use new values

* mandatory code

https://github.com/MikeBishop/dns-alt-svc/pull/205

* Resolve comments

Rename svcb-pairs
Remove SVCB_PRIVATE ranges
Comment on SVCB_KEY65535
ParseError return l.token
rename svcbKeyToString and svcbStringToKey
privatize SVCBKeyToString, SVCBStringToKey

* Refactor 1

Rename sorted, originalPairs
Use append instead of copy
Use svcb_RESERVED instead of 65535, with it now being private
"type SVCBKey uint16"

* Refactor 2

svcbKeyToString as method
svcbStringToKey updated after key 0
🐛 mandatory has missing key
Rename str
idx < 0

* Refactor 3

Use l.token as z
var key, value string
Comment wrap
0:
Sentences with '.'
keyValue => kv

* Refactor 4

* Refactor 5

len() int

* Refactor 6

* Refactor 7

* Test remove parsing

* Error messages

* Rewrite two estimate comments

* parse shouldn't modify original array 🐛

* Remove two unneeded comments

* Address review comments

Push 2 because can't build fuzzer python
Push 3 to try again

* Simplify argument duplication as per tmthrgd's suggestion

And add the relevant test
Force push edit: Make sorting code fit into one line

* Rewrite ECHConfig and address the review

* Remove the optional tab

* Add To4() Check

* More cleanup and fix mandatory not sorting bug
2020-10-11 09:09:36 +02:00
Richard Gibson 978b9a827a
Be consistent about domain name label character escaping (#1122)
* Improve sprintName tests

* Fix sprintName handling of escaped dots

* Make sprintName consistently drop dangling incomplete escapes

* Be consistent about domain name label character escaping

Fixes #1121

* Replace strings.IndexByte with faster special-purpose function
2020-07-06 10:07:56 +02:00
Alex Fattouche b28dcc1849
Fix URI and CAA parsing on quotes and backslashes. (#1101) (#1104)
Automatically submitted.
2020-05-13 19:24:22 +00:00
Adam Chalkley fd9c7eb788
RFCs allow multiple questions, but not in practice (#1097)
Paraphrase @miekg's response to emphasize that multiple
questions in the question section of a DNS message
is not supported in practice.

refs miekg/dns#1092

Co-authored-by: Adam Chalkley <atc0005@users.noreply.github.com>
2020-03-29 19:46:09 +02:00
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
Jan Včelák c9b62b4215 APL record support (#1058)
* APL record: add structure and code point

* APL record: add wire format support

* APL record: add presentation format support

* APL record: add isDuplicate implementation

* APL record: add copy implementation

* APL record: add len implementation

* APL record: run go generate

* APL record: fix condition checking for equality

* APL record: use switches to map family to address length

* APL record: check bounds of individual fields rather than whole header

* APL record: stylistic changes

* APL record: remove APLPrefix methods from public interface

* APL record: update README

* APL record: additional cleanup for code review

* APL record: change return type from pointer to struct

* APL record: refactor of pack and unpack to eliminate extra variables
2020-01-03 13:41:45 +01:00
Charlie Vieth e393768b85 types: improve the performance of sprintName by ~30% and halve allocs (#1008)
```
benchmark                                          old ns/op     new ns/op     delta
BenchmarkSprintName-12                             174           117           -32.76%

benchmark                                          old allocs     new allocs     delta
BenchmarkSprintName-12                             2              1              -50.00%

benchmark                                          old bytes     new bytes     delta
BenchmarkSprintName-12                             48            32            -33.33%
```
2019-09-23 07:17:00 +01:00
Tom Thorogood 25cacca8ca Prohibit newlines before record data in the ZoneParser (#979)
* Merge setRR into ZoneParser.Next

* Remove file argument from RR.parse

This was only used to fill in the ParseError file field. Instead we now
fill in that field in ZoneParser.Next.

* Move dynamic update check out of RR.parse

This consolidates all the dynamic update checks into one place.

* Check for unexpected newline before parsing RR data

* Move rr.parse call into if-statement

* Allow dynamic updates for TKEY and RFC3597 records

* Document that ParseError file field is unset from parse

* Inline allowDynamicUpdate into ZoneParser.Next

* Improve and simplify TestUnexpectedNewline
2019-06-10 07:38:54 +01:00
chantra ccd41ffaf8 [nsec3] fix crash in nsec3 packing (#973)
Both NSEC and NSEC3 use the same logic to pack the bitmap.
CSYNC.pack also appear to make use of `packDataNsec` so I am giving it
the same treatment by moving the logic in a helper function and making
all those types `len` call use that function.
2019-05-21 07:27:24 +01:00
chantra 37f455fa04 [nsec] compute NSEC.len() the same way that we would do in packDataNsec (#967)
The byte sequence, when Unpack()-ed and subsequential Pack()-ed created a
panic: runtime error: slice bounds out of range
github.com/miekg/dns.(*Msg).packBufferWithCompressionMap(0xc0000d4000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x100, 0x14, 0x14e80b, 0xbf2d4654d501a3c8, ...)
/Users/chantra/go/src/github.com/miekg/dns/msg.go:868 +0x13a8

Confirmed that Unpacking/Repacking payload described in TestCrashNSEC
did not raise a slice bound out of range panic, added unittests which
failed prior to this change.

```
go test -run TestCrashNSEC
--- FAIL: TestCrashNSEC (0.00s)
    types_test.go:135: expected length of 19, got 12
FAIL
exit status 1
FAIL	github.com/miekg/dns	0.067s
```
2019-05-19 08:40:22 +01:00
Tom Thorogood d8ff986484 Use for range loops instead of manual for loops (#937)
* Use for range loops instead of manual loops

* Use for range loop in Msg.CopyTo

This is a separate commit as the change is slightly more than just
switching the loop style.

* Use for range loop in DNSKEY.publicKeyRSA

* Add explen comment to DNSKEY.publicKeyRSA
2019-03-18 07:06:44 +00:00
Tom Thorogood 39e689aa4a Fix String formatting of RP record (#914) 2019-02-28 06:28:44 +00:00
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
Tom Thorogood e8b24e80da Move all reversed map creation into reverse.go (#889) 2019-01-04 08:10:15 +00:00
Tom Thorogood bfd648e102
Rename NULL's Anything field to Data (#880) 2019-01-03 21:03:38 +10:30
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
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 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 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
Tom Thorogood 0d29b283ac
Optimise sprintX functions in types.go (#757)
* Simplify appendByte

* Add test case and benchmark for sprintName

* Add test case and benchmark for sprintTxtOctet

* Add test case and benchmark for sprintTxt

* Use strings.Builder for sprint* functions in types.go

* Use writeByte helper in unpackString

* Rename writeByte to writeEscapedByte

This better captures the purpose of this function.
2018-10-06 02:06:59 +09:30
Tom Thorogood c9b812d1d9 Remove redundant parenthesis (#727)
* Remove redundant parenthesis

These were caught with:
    gofmt -r '(a) -> a' -w *.go

This commit only includes the changes where the formatting makes the
ordering of operations clear.

* Remove more redundant parenthesis

These were caught with:
    gofmt -r '(a) -> a' -w *.go

This commit includes the remaining changes where the formatting does not
make the ordering of operations as clear as the previous commit.
2018-08-16 17:05:27 +01:00
Miek Gieben e7c3f513a1
Remove compression from AFSDB (#704)
This type should not compress its rdata.

Fixes #521
2018-06-23 09:43:19 +01:00
spsholleman 052efef004 Add support for TKEY RRs (#567)
* Add support for TKEY RRs

- make sure Key and Data fields are variable length hex fields
- checkin output from 'go generate'
- add a TKEY specific test to ensure this stays working

* go format changes

* address review comments

* add ability to parse TKEY via string

* handle review comments - change TKEY string output
2017-11-28 07:48:02 +00:00
Miek Gieben 2ae4695cc7
Implement CSYNC (#585)
Implement the CSYNC record.

Fixes #290

Long overdue, lets add this record. Similar in vain as NSEC/NSEC3, we
need to implement len() our selves. Presentation format parsing and
tests are done as well.

This is CoreDNS running with CSYNC support, `dig` doesn't support this
at the moment, so:

~~~
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40323
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;csync.example.org.		IN	TYPE62

;; ANSWER SECTION:
csync.example.org.	10	IN	TYPE62	\# 12 000335240042000460000008

;; AUTHORITY SECTION:
example.org.		10	IN	NS	a.iana-servers.net.
example.org.		10	IN	NS	b.iana-servers.net.
~~~
2017-11-25 08:19:06 +00:00
Miek Gieben 4bcc48899c
golint fixes (#553)
* golint fixes

Comment all RR with references to relevant RFC or other docs.
Some lint fixes in edns0.go.

* Some more fixes
2017-11-07 13:45:27 +00:00
Pat Moroney 0f3adef2e2 document RCodes from the IANA registry (#499)
* document RCodes from the IANA registry

* added URL to IANA registry for DNS parameters
2017-07-21 08:02:54 -07:00
Miek Gieben 767422ac12 Add AVC record (#480)
See
https://www.iana.org/assignments/dns-parameters/AVC/avc-completed-template
for the template, a new record that is (again) a mirror of the TXT
record. For lack of a better name, name the rdata Txt - as we do in SPF
and TXT.
2017-03-29 22:17:13 +02:00
Miek Gieben 5a15a35f5f Golint fixes (#456)
Fixes #370
2017-02-15 20:40:16 +00:00
Richard Gibson 21314e1838 Fix TXT RDATA parsing (#421)
* Test for proper parsing of whitespace-separated (TXT) character-strings

* Properly parse whitespace-separated (TXT) character-strings

* Remove non-RFC treatment of backslash sequences in character-strings

Fixes gh-420

* For tests, remove non-RFC treatment of backslashes in domain names
2016-12-02 09:34:49 +00:00
Miek Gieben 46df8c9462 Fix for miekg/dns issue #289: support the SMIMEA record (#410)
1) Refactoring of tlsa.go
   - moved routine to create the certificate rdata to its own go module
     as this is shared between TLSA and SMIMEA records
2) Added support for creating an SMIMEA domain name
3) Developed in accordance with draft-ietf-dane-smime-12 RFC

Miek,

Submitting for your review. Happy to make any recommended changes or
address omissions.

Lightly tested against our internal DNS service which hosts DANE
SMIMEA records for our email certificates.

Parse tests are added.
2016-10-17 18:09:52 +01:00
Miek Gieben db96a2b759 Handle empty salt value (#392)
When removing the reflection we inadvertely also removed the code for
handling empty salt values in NSEC3 and NSEC3PARAM. These are somewhat
annoying because the text representation is '-', which is not valid hex.
2016-07-25 20:20:27 -07:00
Miek Gieben dbffa4b057 Kill all reflection when packing/unpacking RR (#372)
Update the size-xxx-member tags to point to another field in the struct
that should be used for the length in that field. Fix NSEC3/HIP and TSIG
to use to this and generate the correct pack/unpack functions for them.

Remove IPSECKEY from the lib and handle it as an unknown record - it is
such a horrible RR, needed kludges before - now just handle it as an
unknown RR.

All types now use generated pack and unpack functions. The blacklist is
removed.
2016-06-12 18:31:50 +01:00
Miek Gieben 331ecbbc51 Add RcodeBadCookie (23) 2016-06-12 13:10:24 +01:00
Michael Haro 1be7320498 Use t.Errorf in tests and make the error variable naming more consistent. (#367)
* Make the error variable always named err.

Sometimes the error variable was named 'err' sometimes 'e'.  Sometimes
'e' refered to an EDNS or string and not an error type.

* Use t.Errorf instead of t.Logf & t.Fail.
2016-06-09 07:00:08 +01:00
Miek Gieben 799de7044d Remove WKS support
Support for WKS was incomplete, i.e. len() method was incorrect.
Remove support for the record and handle it as an unknown one.

Fixes #361
2016-06-05 08:23:44 +01:00
Filippo Valsorda 25846488f9 Apply per-type code generation to .copy()
This fixes bugs in MB and CNAME.copy() (using sprintName for copying),
IPSECKEY (missed copyIP) and OPT (partially, Options was not copied as
slice; EDNS0 objects themselves are still pointers).
2015-10-07 05:51:36 +01:00
Filippo Valsorda d4a4e089d0 Generate programmatically per-type code, including .len()
This process probably fixes a bug in NSAPPTR.len(), after a similar one was
found in HINFO.len().

This should also make it easier to make changes to these functions, and
check their correctness.

Generate the code by running "go generate".
2015-10-07 05:48:12 +01:00
Filippo Valsorda e9635cc83b Fix (*HINFO).len() and HINFO canonicalization in rawSignatureData 2015-10-05 14:37:42 +01:00
Miek Gieben 5b9c36bf67 Small doc cleanups 2015-08-23 12:55:01 +01:00
Miek Gieben 8de6ade9ec golint: document ANY a bit 2015-08-23 10:21:18 +01:00
Miek Gieben 9bf52083d1 golint fixes 2015-08-23 08:03:13 +01:00
Miek Gieben 21b35db538 Remove the NSAP record
The NSAP was not implemented correctly, see #239. Just remove it. It will still work as unknown RR.
2015-08-10 07:26:35 +01:00
Miek Gieben bbe3422804 small doc fixes 2015-08-09 15:34:29 +01:00
Miek Gieben 2839b93f6b merge conflict 2015-07-28 21:45:20 +01:00
Miek Gieben 179a68fbec Some small fixes 2015-07-27 22:12:46 +01:00
Miek Gieben a34cf6798a Fix URI record
When the URI record became an RFC they slightly changed the format.
Make the needed changes.
2015-07-21 07:47:38 +01:00
Roland Shoemaker 3d5407e128 Fix CAA packing bug 2015-07-07 20:20:25 +01:00
Miek Gieben 2f503031b0 Rename to ReadMsgHeader
Slightly more descriptive and remove the underscore of _DNSHeaderSize
and call is headerSize.
2015-07-03 09:31:53 +01:00
Alex Sergeyev b0d6ff308e Fixed things found in code review (comments, semantics). 2015-07-02 22:42:02 -04:00