Commit Graph

543 Commits

Author SHA1 Message Date
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
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
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 7ca2be95a9 NSEC type bitmap packing bug (#768)
* Add test case for NSEC after packing and unpacking

This is ported from:
https://gist.github.com/cesarkuroiwa/ebc2b4fb1103a7e88824865184f0c73c

* Clear msg data after pointer in packDomainName
2018-10-04 07:39:45 +01:00
Tom Thorogood 7f61c6631b
Fix dominikh/go-tools nits (#758)
* Remove unused functions and consts

* Address gosimple nits

* Address staticcheck nits

This excludes several that were intentional or weren't actual errors.

* Reduce size of lex struct

This reduces the size of the lex struct by 8 bytes from:
  lex.token string: 0-16 (size 16, align 8)
  lex.tokenUpper string: 16-32 (size 16, align 8)
  lex.length int: 32-40 (size 8, align 8)
  lex.err bool: 40-41 (size 1, align 1)
  lex.value uint8: 41-42 (size 1, align 1)
  padding: 42-48 (size 6, align 0)
  lex.line int: 48-56 (size 8, align 8)
  lex.column int: 56-64 (size 8, align 8)
  lex.torc uint16: 64-66 (size 2, align 2)
  padding: 66-72 (size 6, align 0)
  lex.comment string: 72-88 (size 16, align 8)
to:
  lex.token string: 0-16 (size 16, align 8)
  lex.tokenUpper string: 16-32 (size 16, align 8)
  lex.length int: 32-40 (size 8, align 8)
  lex.err bool: 40-41 (size 1, align 1)
  lex.value uint8: 41-42 (size 1, align 1)
  lex.torc uint16: 42-44 (size 2, align 2)
  padding: 44-48 (size 4, align 0)
  lex.line int: 48-56 (size 8, align 8)
  lex.column int: 56-64 (size 8, align 8)
  lex.comment string: 64-80 (size 16, align 8)

* Reduce size of response struct

This reduces the size of the response struct by 8 bytes from:
  response.msg []byte: 0-24 (size 24, align 8)
  response.hijacked bool: 24-25 (size 1, align 1)
  padding: 25-32 (size 7, align 0)
  response.tsigStatus error: 32-48 (size 16, align 8)
  response.tsigTimersOnly bool: 48-49 (size 1, align 1)
  padding: 49-56 (size 7, align 0)
  response.tsigRequestMAC string: 56-72 (size 16, align 8)
  response.tsigSecret map[string]string: 72-80 (size 8, align 8)
  response.udp *net.UDPConn: 80-88 (size 8, align 8)
  response.tcp net.Conn: 88-104 (size 16, align 8)
  response.udpSession *github.com/tmthrgd/dns.SessionUDP: 104-112 (size 8, align 8)
  response.writer github.com/tmthrgd/dns.Writer: 112-128 (size 16, align 8)
  response.wg *sync.WaitGroup: 128-136 (size 8, align 8)
to:
  response.msg []byte: 0-24 (size 24, align 8)
  response.hijacked bool: 24-25 (size 1, align 1)
  response.tsigTimersOnly bool: 25-26 (size 1, align 1)
  padding: 26-32 (size 6, align 0)
  response.tsigStatus error: 32-48 (size 16, align 8)
  response.tsigRequestMAC string: 48-64 (size 16, align 8)
  response.tsigSecret map[string]string: 64-72 (size 8, align 8)
  response.udp *net.UDPConn: 72-80 (size 8, align 8)
  response.tcp net.Conn: 80-96 (size 16, align 8)
  response.udpSession *github.com/tmthrgd/dns.SessionUDP: 96-104 (size 8, align 8)
  response.writer github.com/tmthrgd/dns.Writer: 104-120 (size 16, align 8)
  response.wg *sync.WaitGroup: 120-128 (size 8, align 8)
2018-09-27 04:02:05 +09:30
Tom Thorogood f195b71879 Replace unpackTxtString with identical unpackString (#751)
These two functions were identical (sans-variable names) before I
optimized unpackString in 5debfeec63.

This will improve the performance of it's only caller unpackTxt and is
covered by the test and benchmark added in 5debfeec63.
2018-09-26 09:14:19 +01:00
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 3745b9737d
Small comment tweaks (#678)
Some post #668 comments nits.
2018-05-16 08:53:51 +01:00
Pierre Souchay 09649115c1 Fixed len computation when size just goes beyond 14 bits (#668)
* Fixed len computation when size just goes beyond 14 bits

* Added bouds checks around 14bits

* Len() always right including when around 14bits boudaries

* Avoid splitting into labels when not applicable

* Fixed comments

* Added comments in code

* Added new test cases

* Fixed computation of Len() for SRV and all kind of records

* Fixed Sign that was relying on non-copy for Unit tests

* Removed unused padding

* Fixed typo in PackBuffer() function

* Added comment about packBufferWithCompressionMap() for testing purposes
2018-05-16 07:20:13 +01:00
chantra 1f2aa4c780 do not modify dns.Rcode when packing to wire format (#675)
* do not modify dns.Rcode when packing to wire format

When the message has an EDNS0 option in the additional section and
dns.Msg.Rcode is set to an extended rcode, dns.Msg.PackBuffer() modifies
dns.Msg.Rcode.
If you were to `Pack` the message and log it after, the Rcode would show
NOERROR.

Running the test before the change would error with:

```
=== RUN   TestPackNoSideEffect
--- FAIL: TestPackNoSideEffect (0.00s)
	msg_test.go:51: after pack: Rcode is expected to be BADVERS
```

after fixing dns.Msg.PackBuffer(), all tests are still passing.

Fixes #674

* address comments from PR#675
2018-05-13 08:36:02 +01:00
Miek Gieben dfb943b13e
Take the max compression offset into account in Len(). (#658)
This offset max was not taking into account leading Len() to emit a
smaller value that could not be matched by Pack(), i.e all names can
be fully compressed or used as a target for compression.

Split length tests off in seperate file length_test.go to clean up
dns_test.og a bit.
2018-04-01 09:45:32 +01:00
chantra 5b169d1842 [msg] Add UnpackRRWithHeader (#643)
This function allow to extra the raw content of a record type based on
an existing header.
Fixes #633
2018-03-15 09:09:45 +00:00
Lorenz Bauer 9088876525 Don't use untrusted lengths from Header to pre-allocate (#610)
We currently use information from a potential attacker to pre-allocate slices for the Question, Answer, etc. sections. This allows an attacker to force allocation of several MiB per parsed Msg.

Instead, don't pre-allocate those slices. append() always allocates in powers of two, which is probably the best we can do.

Fixes #609.
2017-12-21 10:24:07 +00:00
Miek Gieben 5f2d7c7013
Unpack: return header (#608)
When we unpack a message and only have the header consider it a valid
message and don't return an error.
2017-12-20 10:51:13 +00:00
Miek Gieben b38dc3dcb7
Cleanup: gofmt -w -s *.go (#548)
Some renames of internal names to make go lint happier.
2017-11-03 16:15:35 +00:00
Tom Thorogood 5f64fb22f9 Simplify compressed length code (#527)
* Add BenchmarkMsgLengthNoCompression

* Simplify compressedLen loops

* Fix typo in compressionLenSlice
2017-10-13 17:21:12 +02:00
Danny Berger 113c7538ea Fix minor typos in comments (#486) 2017-04-26 18:46:52 +01:00
Richard Gibson c1bdeb82b2 Domain name limits (#478)
* limiting domain names to 255/63 octets/labels (#463)

(cherry picked from commit 0b729df06c)

* account for \ and \xxx in presentation format

(cherry picked from commit a094f774892fb4305051d185c2488cb43200c4d9)

* go fmt

* Add tests for UnpackDomainName

Domain names must not exceed 255 octets in wire format.

Ref gh-463
Ref gh-469

* Fix UnpackDomainName

* Introduce a long-domain sentinel error

A typed error would be better, but inconsistent with this library.
cf.  https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
2017-03-29 20:43:02 +01:00
Miek Gieben 25ac7f1714 Revert "limiting domain names to 255/63 octets/labels (#463)"
This reverts commit 0b729df06c.
2017-03-21 07:03:31 +00:00
Olafur Gudmundsson 0b729df06c limiting domain names to 255/63 octets/labels (#463) 2017-02-21 22:36:40 +00:00
Miek Gieben 75229eecb7 msg.go: don't fiddle with Compress (#460)
Don't set Compress to false on dns to calucate the uncompressed length,
instead a a function where the compression is a flag and use that.
2017-02-17 12:10:30 +00:00
Miek Gieben 74ec3b2433 Generate the compressionHelper functions (#454)
* Generate the compressionHelper functions and fix compression.

This was a long standing TODO: generate the compression helper
functions. This now automatically picks up new names that can be
used for compression.

When packing add names to compression map:

When packing a message we should only compress when compress is true.
But whenever the compression map is not nil we should still add names
to it that can be *used* for future compression. The packing
inadvertently only added those names when compress would be true.

* Removed unused functions
2017-02-17 09:48:37 +00:00
Tom Thorogood f3c59acd3d Work around golang/go#11833 predictable random issue in Id. (#447)
* Work around golang/go#11833 predictable random issue.

In certain circumstances crypto/rand.Reader will return non-random
bytes. The most likely case is near boot, and as init is run when
the go program is started, it's possible that a non-random seed
could be used. While this is very unlikely to ever be an issue,
it is a very easy fix and it is preferable to be resilient.

Instead of seeding the global math/rand rng during init, a separate
math/rand.Rand is seeded upon the first call to Id. This also avoids
polluting the global math/rand rng which might be seeded elsewhere.

If crypto/rand.Reader fails, math/rand.Int63 will be called to
provide a seed. This is better than the current fallback to a seed
of 1.

This change introduces no noticeable performance overhead as the
global math/rand rng already uses a sync.Mutex internally.

* Document lack of performance overhead from mutex in `func id()`
2017-02-05 08:47:07 +00:00
Matthijs Mekking 99f84ae56e return errTruncated after setting header bits (#442) 2017-01-30 10:53:01 +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
Preet Bhinder 3f1f7c8ec9 Fix a couple of comments (#386) 2016-10-03 19:18:08 +01:00
Miek Gieben e6b37d00af Cleanup and removals (#377)
* Cleanup and removals

Gut rawmsg.go as most functions are not used. Reword some documentation.
Add more types to be checked for name compression.

* Yeah, we do use these

* Remove this function as well - only used one
2016-06-13 19:44:38 +01:00
Miek Gieben b51e305bc6 Remove reflection (#376)
Everything is generated. Remove all uses of packStruct/unpackStruct and
make the library reflectionless.
2016-06-12 21:06:46 +01: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 6ae3b9f061 Skip reflection for most types (#369)
Make the reflection types a black list (these types use (or should use)
the tag 'size-xxx' in their struct definition.s

HIP, IPSECKEY, NSEC3, TSIG

All other types don't use reflection anymore.

* Return a pointer to the header when there is no rdata, this restores old
  behavior. The rest of the conversion mostly hangs on getting size-hex
  right, but then packStruct and packStructValue and the unpack variant
  can be killed.
* Generate pack and unpack for all embedded types as well.
* Fix PrivateRRs, register an unpack function as well, when you register
  a new PrivateRR.
* Add the tag octet, nsec, []domains and more  to msg_helper.go
2016-06-12 16:09:37 +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
Michael Haro a465e84f54 Use encoding/binary's conversion functions when possible. (#364)
* Remove {un,}packUint{16,32}Msg functions.

unpackUint16Msg unpackUint32Msg packUint16Msg packUint32Msg implemented
functionality that is part of the encoding/binary package.

* Use encoding/binary's encoding in more places.
2016-06-08 16:38:42 +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
Miek Gieben 907a4aef57 Generate pack/unpack for all RRs (#360)
Add dns:txt parsing helper to prevent compile errors. This allows
us to generate all unpack/pack function.

Add pack to the RR interface definition and add this method to
PrivateRR.

We still use typeToUnpack to select which types don't use reflection.
2016-06-05 07:53:12 +01:00
Roland Bracewell Shoemaker 3f53d75269 Seed math/rand with crypto/rand (#359)
* Use crypto/rand to seed math/rand instead of using the default seed

* Better seeding+generation and fallback on crypto/rand.Read failure

* Remove user warning
2016-06-05 07:51:30 +01:00
Miek Gieben 475ab80867 Remove (most) reflection
Remove the use of reflection when packing and unpacking, instead
generate all the pack and unpack functions using msg_generate.
This will generate zmsg.go which in turn calls the helper functions from
msg_helper.go.

This increases the speed by about ~30% while cutting back on memory
usage. Not all RRs are using it, but that will be rectified in upcoming
PR.

Most of the speed increase is in the header/question section parsing.
These functions *are* not generated, but straight forward enough. The
implementation can be found in msg.go.

The new code has been fuzzed by go-fuzz, which turned up some issues.

All files that started with 'z', and not autogenerated were renamed,
i.e. zscan.go is now scan.go.

Reflection is still used, in subsequent PRs it will be removed entirely.
2016-06-03 12:45:22 +01:00
Miek Gieben f53eb22bfb Check length before packing OPT (#352)
fixes #351
2016-05-05 16:56:17 +01:00
Shumon Huque b534177a1a small patch for EDNS0 cookie support (#350)
* Add EDNS0 Cookie (option 10) support.

* Add EDNS0 Cookie processing.

* Fix nits.

* Add EDNS0 cookie support mention.
2016-05-03 16:19:28 +01:00
Matthijs Mekking 5107215070 Len returns the rr len of the uncompressed format. 2016-03-17 15:07:51 +01:00
Nick Galbreath 5cbabd2322 spelling 2016-01-19 14:23:11 -08:00
James Hartig 2d2c2ebcfc Instead of removing all RRs on Truncated, attempt to unpack 2015-11-01 15:51:09 -05:00
Filippo Valsorda 023972bb19 Expose TypeToRR 2015-10-16 23:36:49 +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
Miek Gieben 79547a0341 Add Dedup function
Add function that dedups a list of RRs. Work on strings, which
adds garbage, but seems to be the least intrusive and takes the
last amount of memory.

Some fmt changes snook in as well.
2015-08-24 22:02:57 +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 8eb292db07 Doc update for future change in TC handling
Update the comment in msg.go#L1700 about the TC bit handling

Small cleanups.
2015-08-09 16:26:25 +01:00
Miek Gieben 58c5f4cf6e Small doc updates 2015-08-07 20:58:26 +01:00
Filippo Valsorda 40484667f4 rewrite NSEC bitmap [un]packing to account for out-of-order 2015-08-05 00:18:02 +01:00
Filippo Valsorda 2b564cd047 UnpackDomainName: fix infinite loop where it would lower 'off'
When a pointer points to a empty name, the "return '.'" special case used to
kick in which is not pointer-aware so it would reset the parsing offset to
the pointer target

This was independently found and fixed in c13d4ee, I'm submitting this patch
anyway as it seems a bit more robust and DRY [citation needed].
2015-08-05 00:18:02 +01:00
Filippo Valsorda 77aa064ef9 packStructValue: rewrite dns:"wks" packing which was writing out of bounds 2015-08-05 00:18:02 +01:00
Filippo Valsorda 0df69faa6e packStructValue: fix a overflow in NSEC packing 2015-08-05 00:18:02 +01:00
Filippo Valsorda b5133fead4 unpackStructValue: drop rdlen, reslice msg instead 2015-08-05 00:18:02 +01:00
Filippo Valsorda 6313235fed unpackStructValue: fix a overflow in opt 2015-08-05 00:18:01 +01:00
Miek Gieben 14e381d23e fuzzzz 2015-07-27 21:48:46 +01:00
Miek Gieben fcf516f280 fuzzzz 2015-07-27 20:57:02 +01:00
Miek Gieben c13d4ee9cd domain names: fix compression of root-label
If the root label is compressed (which is 2 bytes, the root label
itself is only 1 byte, so why do it?), go dns incorrectly set the
offset when encountering such a name.

Fixes #234
2015-07-27 20:48:09 +01:00
Roland Shoemaker 259969e797 Better buffer size 2015-07-21 16:04:21 -07:00
Roland Shoemaker 3d5407e128 Fix CAA packing bug 2015-07-07 20:20:25 +01:00
Roland Shoemaker 52647ae7a7 Address miekg's comments 2015-06-18 19:17:02 -07:00
Roland Shoemaker 020002b9e0 Switch setCAA, CAA.String to presentation format, add various encoding helpers 2015-06-17 16:06:31 -07:00
Roland Shoemaker 522331911d Enable CAA parsing 2015-06-16 02:01:28 -07:00
Harvo Jones 57d8407ad7 Changes applied:
* Renamed EDNS0_CUSTOM to EDNS0_LOCAL
* Added EDNS0LOCAL constants
* Added documentation
2015-03-18 12:12:53 -07:00
Harvo Jones 8bd3ac773f Add support for custom EDNS options in GoDNS.
A handful of EDNS options have been standardized, and they each have a type defined in GoDNS.  However there is currently no way a development team can use GoDNS with internally defined options, or with new options that may be proposed in the future.

This change solves the problem by giving users an EDNS0_CUSTOM type to allow clients to send, and servers to receive, custom EDNS options.
2015-03-17 10:41:55 -07:00
Michael Haro f1f17ffdbc Split Copy into Copy and CopyTo.
CopyTo allows bypassing allocating a new Msg to work towards less
allocation GC churn.
2015-02-23 23:11:31 -08:00
Miek Gieben 574544eb08 Documentation updates 2015-02-20 11:39:15 +00:00
Miek Gieben faa311bf55 golint: more docs 2015-02-19 11:26:46 +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
Daniel Morsing a4af4dd14e Used shared backing array for Msg.Copy
If you have a system with large amounts of copies, these slice
allocations start stacking up. Use a shared slice and then subslice
them with a cap limit so that append works properly.

Also, add a benchmark and test for Msg.Copy

Benchcmp:
benchmark         old ns/op     new ns/op     delta
BenchmarkCopy     1880          1672          -11.06%

benchmark         old allocs     new allocs     delta
BenchmarkCopy     13             11             -15.38%

benchmark         old bytes     new bytes     delta
BenchmarkCopy     528           528           +0.00%
2015-02-05 13:07:07 +00:00
Miek Gieben b6ff23905a Finish implementing IPSECKEY
Remaining tests and unpack for IPSECKEY.
2015-01-25 12:24:39 +00:00
Miek Gieben 477cb4d3fa Implement IPSECKEY
IPSECKEY is kinda strange because it has a type selector which tells
what type a later rdata field has. The type can be a domainname, address
or v6 address. You sort of wish Go would have a union type for this, but
alas.
Currently this is implemented as:

	GatewayA    net.IP `dns:"a"`
	GatewayAAAA net.IP `dns:"aaaa"`
	GatewayName string `dns:"domain-name"`

In the IPSECKEY. Only one of these is active at any one time. When
parsing/packing and unpacking the value of GatewayType is checked
to see what to do.

Parsing from strings is also implemented properly and tested. The Unpack
function still needs work.
2015-01-25 10:58:30 +00:00
Filippo Valsorda ed475ae9fa [DNSSEC] Make int to bytes conversions fixed length in ECDSA
ECDSA public keys consist of a single value, called "Q" in FIPS
  186-3.  In DNSSEC keys, Q is a simple bit string that represents the
  uncompressed form of a curve point, "x | y".

  The ECDSA signature is the combination of two non-negative integers,
  called "r" and "s" in FIPS 186-3.  The two integers, each of which is
  formatted as a simple octet string, are combined into a single longer
  octet string for DNSSEC as the concatenation "r | s".  (Conversion of
  the integers to bit strings is described in Section C.2 of FIPS
  186-3.)  For P-256, each integer MUST be encoded as 32 octets; for
  P-384, each integer MUST be encoded as 48 octets.
2014-12-05 20:17:11 +00:00
Filippo Valsorda 0f1b1184ae Rename and simplify packing helper functions 2014-12-05 19:27:44 +00:00
Andrew Tunnell-Jones 71436daebe Make TestDynamicUpdateZeroRdataUnpack pass
Straight up: took a guess and the tests pass.
2014-11-12 07:56:21 +00:00
Miek Gieben 34f43d398b Stop parsing when hitting rdlen
Stop parsing these records when we hit rdlen.
2014-11-09 16:17:06 +00:00
Miek Gieben 11bbb59419 Rename rdlen to lenrd
More in sync with lenmsg.
2014-11-09 16:16:41 +00:00
Miek Gieben d33af8db79 Update test and gofmt 2014-11-09 16:09:49 +00:00
Miek Gieben eff0e9354f Apply 433ab7b569 here too
The same Sprintf was used here, so this can be optimized as well.

Thanks to @andrewtj for the ping.
2014-11-09 08:03:03 +00:00
Daniel Morsing 433ab7b569 Reduce amount of work done when unpacking unprintable characters.
Instead of going through the fmt package, we can use append int,
which saves an allocation.

benchmark                                old ns/op     new ns/op     delta
BenchmarkUnpackDomainNameUnprintable     2147          506           -76.43%
2014-11-06 13:51:29 +00:00
Andrew Tunnell-Jones 91b8c69a22 Implement SIG(0) signing and verification
This is based on @miekg's sig0 branch. That branch diverged from master
and I didn't want to wander off on a rebase.

As implemented there's no allowance for multi-envelope (TCP) support.

TODO:

* unpackUint32() could be moved out and used elsewhere
* tests
* multi-envelope support (if useful)
2014-11-01 11:32:46 +00:00
Miek Gieben 6bbae6c6ea Add CDNSKEY support 2014-10-23 22:18:23 +01:00
Miek Gieben 467e368cc1 check for overflowing msg len when unpacking A
unclebadtouches catched this.

closes #141
2014-10-22 21:08:34 +01:00
Miek Gieben 3d0face066 Fixup tests 2014-10-08 14:35:23 +00:00
Miek Gieben de954625b6 Add ErrExtendedRcode and fix up the callers 2014-10-08 14:31:28 +00:00
Filippo Valsorda 9088298b2b Add support for extended RCODEs and detect bad RCODEs 2014-09-26 12:18:36 +01:00
Miek Gieben 9c455b0214 PrivateRR: naming naming naming
Try to find better (=more in sync with the rest of the lib) naming. My
guess is that these are better, but YMMV.
2014-09-21 08:28:38 +01:00
Alex Sergeyev fcf9302ae1 Changed logic to typeswitch and added comments.
And also added my name to contrib list as promised before.
2014-09-20 18:15:42 -04:00
Alex Sergeyev 8aab8c6fb2 Lots of renamed funcs and structures. More readability. 2014-09-20 18:07:36 -04:00
Alex Sergeyev 5b8552609c Added docstrings, tests and example for PrivateRRs.
(renamed CustomRR to PrivateRR)
2014-09-19 17:30:10 -04:00
Alex Sergeyev 7c507e7592 New functionality for adding private RRs to dns lib. 2014-09-19 17:28:53 -04:00
Miek Gieben 02dd474056 Dont export typeToRR (old rr_mk) 2014-09-16 07:31:20 +01:00
Miek Gieben bcb640ccaf Make rr_mk public and call it TypeToRR 2014-09-16 07:15:06 +01:00
Miek Gieben 0aa3021a83 Remove all copyright notices
Use the central COPYRIGHT file.
2014-09-11 20:57:37 +01:00
Miek Gieben 8fecf17714 Check that off <= lenmsg
Defense in depth, this should happen, but it happens... So check
for it and return an error.

Maybe (there is no testcase) fixes #106
2014-08-23 07:43:00 +01:00