aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/miekg/dns/dns.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/miekg/dns/dns.go')
-rw-r--r--vendor/github.com/miekg/dns/dns.go99
1 files changed, 75 insertions, 24 deletions
diff --git a/vendor/github.com/miekg/dns/dns.go b/vendor/github.com/miekg/dns/dns.go
index 5133eac..a88484b 100644
--- a/vendor/github.com/miekg/dns/dns.go
+++ b/vendor/github.com/miekg/dns/dns.go
@@ -1,6 +1,9 @@
package dns
-import "strconv"
+import (
+ "encoding/hex"
+ "strconv"
+)
const (
year68 = 1 << 31 // For RFC1982 (Serial Arithmetic) calculations in 32 bits.
@@ -34,10 +37,30 @@ type RR interface {
// copy returns a copy of the RR
copy() RR
- // len returns the length (in octets) of the uncompressed RR in wire format.
- len() int
- // pack packs an RR into wire format.
- pack([]byte, int, map[string]int, bool) (int, error)
+
+ // len returns the length (in octets) of the compressed or uncompressed RR in wire format.
+ //
+ // If compression is nil, the uncompressed size will be returned, otherwise the compressed
+ // size will be returned and domain names will be added to the map for future compression.
+ len(off int, compression map[string]struct{}) int
+
+ // pack packs the records RDATA into wire format. The header will
+ // already have been packed into msg.
+ pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error)
+
+ // unpack unpacks an RR from wire format.
+ //
+ // This will only be called on a new and empty RR type with only the header populated. It
+ // will only be called if the record's RDATA is non-empty.
+ unpack(msg []byte, off int) (off1 int, err error)
+
+ // parse parses an RR from zone file format.
+ //
+ // This will only be called on a new and empty RR type with only the header populated.
+ parse(c *zlexer, origin string) *ParseError
+
+ // isDuplicate returns whether the two RRs are duplicates.
+ isDuplicate(r2 RR) bool
}
// RR_Header is the header all DNS resource records share.
@@ -55,16 +78,6 @@ func (h *RR_Header) Header() *RR_Header { return h }
// Just to implement the RR interface.
func (h *RR_Header) copy() RR { return nil }
-func (h *RR_Header) copyHeader() *RR_Header {
- r := new(RR_Header)
- r.Name = h.Name
- r.Rrtype = h.Rrtype
- r.Class = h.Class
- r.Ttl = h.Ttl
- r.Rdlength = h.Rdlength
- return r
-}
-
func (h *RR_Header) String() string {
var s string
@@ -80,28 +93,66 @@ func (h *RR_Header) String() string {
return s
}
-func (h *RR_Header) len() int {
- l := len(h.Name) + 1
+func (h *RR_Header) len(off int, compression map[string]struct{}) int {
+ l := domainNameLen(h.Name, off, compression, true)
l += 10 // rrtype(2) + class(2) + ttl(4) + rdlength(2)
return l
}
+func (h *RR_Header) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
+ // RR_Header has no RDATA to pack.
+ return off, nil
+}
+
+func (h *RR_Header) unpack(msg []byte, off int) (int, error) {
+ panic("dns: internal error: unpack should never be called on RR_Header")
+}
+
+func (h *RR_Header) parse(c *zlexer, origin string) *ParseError {
+ panic("dns: internal error: parse should never be called on RR_Header")
+}
+
// ToRFC3597 converts a known RR to the unknown RR representation from RFC 3597.
func (rr *RFC3597) ToRFC3597(r RR) error {
- buf := make([]byte, r.len()*2)
- off, err := PackRR(r, buf, 0, nil, false)
+ buf := make([]byte, Len(r))
+ headerEnd, off, err := packRR(r, buf, 0, compressionMap{}, false)
if err != nil {
return err
}
buf = buf[:off]
- if int(r.Header().Rdlength) > off {
- return ErrBuf
+
+ *rr = RFC3597{Hdr: *r.Header()}
+ rr.Hdr.Rdlength = uint16(off - headerEnd)
+
+ if noRdata(rr.Hdr) {
+ return nil
}
- rfc3597, _, err := unpackRFC3597(*r.Header(), buf, off-int(r.Header().Rdlength))
+ _, err = rr.unpack(buf, headerEnd)
+ return err
+}
+
+// fromRFC3597 converts an unknown RR representation from RFC 3597 to the known RR type.
+func (rr *RFC3597) fromRFC3597(r RR) error {
+ hdr := r.Header()
+ *hdr = rr.Hdr
+
+ // Can't overflow uint16 as the length of Rdata is validated in (*RFC3597).parse.
+ // We can only get here when rr was constructed with that method.
+ hdr.Rdlength = uint16(hex.DecodedLen(len(rr.Rdata)))
+
+ if noRdata(*hdr) {
+ // Dynamic update.
+ return nil
+ }
+
+ // rr.pack requires an extra allocation and a copy so we just decode Rdata
+ // manually, it's simpler anyway.
+ msg, err := hex.DecodeString(rr.Rdata)
if err != nil {
return err
}
- *rr = *rfc3597.(*RFC3597)
- return nil
+
+ _, err = r.unpack(msg, 0)
+ return err
}