Commit Graph

472 Commits

Author SHA1 Message Date
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