Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
  • renovate/git.autistici.org-ai3-go-common-digest
  • renovate/github.com-miekg-dns-1.x
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/golang.org-x-crypto-0.x
  • renovate/golang.org-x-net-0.x
  • v2
  • v3
8 results

Target

Select target project
  • ai3/tools/acmeserver
  • godog/acmeserver
  • svp-bot/acmeserver
3 results
Select Git revision
  • lintian-fixes
  • master
  • renovate/github.com-miekg-dns-1.x
  • renovate/golang.org-x-crypto-digest
4 results
Show changes
Showing
with 2144 additions and 2787 deletions
...@@ -14,11 +14,8 @@ func (r *TLSA) Sign(usage, selector, matchingType int, cert *x509.Certificate) ( ...@@ -14,11 +14,8 @@ func (r *TLSA) Sign(usage, selector, matchingType int, cert *x509.Certificate) (
r.MatchingType = uint8(matchingType) r.MatchingType = uint8(matchingType)
r.Certificate, err = CertificateToDANE(r.Selector, r.MatchingType, cert) r.Certificate, err = CertificateToDANE(r.Selector, r.MatchingType, cert)
if err != nil {
return err return err
} }
return nil
}
// Verify verifies a TLSA record against an SSL certificate. If it is OK // Verify verifies a TLSA record against an SSL certificate. If it is OK
// a nil error is returned. // a nil error is returned.
......
// +build tools
// We include our tool dependencies for `go generate` here to ensure they're
// properly tracked by the go tool. See the Go Wiki for the rationale behind this:
// https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module.
package dns
import _ "golang.org/x/tools/go/packages"
...@@ -2,7 +2,6 @@ package dns ...@@ -2,7 +2,6 @@ package dns
import ( import (
"crypto/hmac" "crypto/hmac"
"crypto/md5"
"crypto/sha1" "crypto/sha1"
"crypto/sha256" "crypto/sha256"
"crypto/sha512" "crypto/sha512"
...@@ -16,12 +15,83 @@ import ( ...@@ -16,12 +15,83 @@ import (
// HMAC hashing codes. These are transmitted as domain names. // HMAC hashing codes. These are transmitted as domain names.
const ( const (
HmacMD5 = "hmac-md5.sig-alg.reg.int."
HmacSHA1 = "hmac-sha1." HmacSHA1 = "hmac-sha1."
HmacSHA224 = "hmac-sha224."
HmacSHA256 = "hmac-sha256." HmacSHA256 = "hmac-sha256."
HmacSHA384 = "hmac-sha384."
HmacSHA512 = "hmac-sha512." HmacSHA512 = "hmac-sha512."
HmacMD5 = "hmac-md5.sig-alg.reg.int." // Deprecated: HmacMD5 is no longer supported.
) )
// TsigProvider provides the API to plug-in a custom TSIG implementation.
type TsigProvider interface {
// Generate is passed the DNS message to be signed and the partial TSIG RR. It returns the signature and nil, otherwise an error.
Generate(msg []byte, t *TSIG) ([]byte, error)
// Verify is passed the DNS message to be verified and the TSIG RR. If the signature is valid it will return nil, otherwise an error.
Verify(msg []byte, t *TSIG) error
}
type tsigHMACProvider string
func (key tsigHMACProvider) Generate(msg []byte, t *TSIG) ([]byte, error) {
// If we barf here, the caller is to blame
rawsecret, err := fromBase64([]byte(key))
if err != nil {
return nil, err
}
var h hash.Hash
switch CanonicalName(t.Algorithm) {
case HmacSHA1:
h = hmac.New(sha1.New, rawsecret)
case HmacSHA224:
h = hmac.New(sha256.New224, rawsecret)
case HmacSHA256:
h = hmac.New(sha256.New, rawsecret)
case HmacSHA384:
h = hmac.New(sha512.New384, rawsecret)
case HmacSHA512:
h = hmac.New(sha512.New, rawsecret)
default:
return nil, ErrKeyAlg
}
h.Write(msg)
return h.Sum(nil), nil
}
func (key tsigHMACProvider) Verify(msg []byte, t *TSIG) error {
b, err := key.Generate(msg, t)
if err != nil {
return err
}
mac, err := hex.DecodeString(t.MAC)
if err != nil {
return err
}
if !hmac.Equal(b, mac) {
return ErrSig
}
return nil
}
type tsigSecretProvider map[string]string
func (ts tsigSecretProvider) Generate(msg []byte, t *TSIG) ([]byte, error) {
key, ok := ts[t.Hdr.Name]
if !ok {
return nil, ErrSecret
}
return tsigHMACProvider(key).Generate(msg, t)
}
func (ts tsigSecretProvider) Verify(msg []byte, t *TSIG) error {
key, ok := ts[t.Hdr.Name]
if !ok {
return ErrSecret
}
return tsigHMACProvider(key).Verify(msg, t)
}
// TSIG is the RR the holds the transaction signature of a message. // TSIG is the RR the holds the transaction signature of a message.
// See RFC 2845 and RFC 4635. // See RFC 2845 and RFC 4635.
type TSIG struct { type TSIG struct {
...@@ -40,7 +110,7 @@ type TSIG struct { ...@@ -40,7 +110,7 @@ type TSIG struct {
// TSIG has no official presentation format, but this will suffice. // TSIG has no official presentation format, but this will suffice.
func (rr *TSIG) String() string { func (rr *TSIG) String() string {
s := "\n;; TSIG PSEUDOSECTION:\n" s := "\n;; TSIG PSEUDOSECTION:\n; " // add another semi-colon to signify TSIG does not have a presentation format
s += rr.Hdr.String() + s += rr.Hdr.String() +
" " + rr.Algorithm + " " + rr.Algorithm +
" " + tsigTimeToString(rr.TimeSigned) + " " + tsigTimeToString(rr.TimeSigned) +
...@@ -54,6 +124,10 @@ func (rr *TSIG) String() string { ...@@ -54,6 +124,10 @@ func (rr *TSIG) String() string {
return s return s
} }
func (*TSIG) parse(c *zlexer, origin string) *ParseError {
return &ParseError{err: "TSIG records do not have a presentation format"}
}
// The following values must be put in wireformat, so that the MAC can be calculated. // The following values must be put in wireformat, so that the MAC can be calculated.
// RFC 2845, section 3.4.2. TSIG Variables. // RFC 2845, section 3.4.2. TSIG Variables.
type tsigWireFmt struct { type tsigWireFmt struct {
...@@ -84,22 +158,20 @@ type timerWireFmt struct { ...@@ -84,22 +158,20 @@ type timerWireFmt struct {
} }
// TsigGenerate fills out the TSIG record attached to the message. // TsigGenerate fills out the TSIG record attached to the message.
// The message should contain // The message should contain a "stub" TSIG RR with the algorithm, key name
// a "stub" TSIG RR with the algorithm, key name (owner name of the RR), // (owner name of the RR), time fudge (defaults to 300 seconds) and the current
// time fudge (defaults to 300 seconds) and the current time // time The TSIG MAC is saved in that Tsig RR. When TsigGenerate is called for
// The TSIG MAC is saved in that Tsig RR. // the first time requestMAC should be set to the empty string and timersOnly to
// When TsigGenerate is called for the first time requestMAC is set to the empty string and // false.
// timersOnly is false.
// If something goes wrong an error is returned, otherwise it is nil.
func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) ([]byte, string, error) { func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) ([]byte, string, error) {
return TsigGenerateWithProvider(m, tsigHMACProvider(secret), requestMAC, timersOnly)
}
// TsigGenerateWithProvider is similar to TsigGenerate, but allows for a custom TsigProvider.
func TsigGenerateWithProvider(m *Msg, provider TsigProvider, requestMAC string, timersOnly bool) ([]byte, string, error) {
if m.IsTsig() == nil { if m.IsTsig() == nil {
panic("dns: TSIG not last RR in additional") panic("dns: TSIG not last RR in additional")
} }
// If we barf here, the caller is to blame
rawsecret, err := fromBase64([]byte(secret))
if err != nil {
return nil, "", err
}
rr := m.Extra[len(m.Extra)-1].(*TSIG) rr := m.Extra[len(m.Extra)-1].(*TSIG)
m.Extra = m.Extra[0 : len(m.Extra)-1] // kill the TSIG from the msg m.Extra = m.Extra[0 : len(m.Extra)-1] // kill the TSIG from the msg
...@@ -107,69 +179,75 @@ func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) ([]byte, s ...@@ -107,69 +179,75 @@ func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) ([]byte, s
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }
buf := tsigBuffer(mbuf, rr, requestMAC, timersOnly)
t := new(TSIG) buf, err := tsigBuffer(mbuf, rr, requestMAC, timersOnly)
var h hash.Hash if err != nil {
switch strings.ToLower(rr.Algorithm) { return nil, "", err
case HmacMD5:
h = hmac.New(md5.New, []byte(rawsecret))
case HmacSHA1:
h = hmac.New(sha1.New, []byte(rawsecret))
case HmacSHA256:
h = hmac.New(sha256.New, []byte(rawsecret))
case HmacSHA512:
h = hmac.New(sha512.New, []byte(rawsecret))
default:
return nil, "", ErrKeyAlg
} }
h.Write(buf)
t.MAC = hex.EncodeToString(h.Sum(nil))
t.MACSize = uint16(len(t.MAC) / 2) // Size is half!
t.Hdr = RR_Header{Name: rr.Hdr.Name, Rrtype: TypeTSIG, Class: ClassANY, Ttl: 0} t := new(TSIG)
t.Fudge = rr.Fudge // Copy all TSIG fields except MAC, its size, and time signed which are filled when signing.
*t = *rr
t.TimeSigned = 0
t.MAC = ""
t.MACSize = 0
// Sign unless there is a key or MAC validation error (RFC 8945 5.3.2)
if rr.Error != RcodeBadKey && rr.Error != RcodeBadSig {
mac, err := provider.Generate(buf, rr)
if err != nil {
return nil, "", err
}
t.TimeSigned = rr.TimeSigned t.TimeSigned = rr.TimeSigned
t.Algorithm = rr.Algorithm t.MAC = hex.EncodeToString(mac)
t.OrigId = m.Id t.MACSize = uint16(len(t.MAC) / 2) // Size is half!
}
tbuf := make([]byte, t.len()) tbuf := make([]byte, Len(t))
if off, err := PackRR(t, tbuf, 0, nil, false); err == nil { off, err := PackRR(t, tbuf, 0, nil, false)
tbuf = tbuf[:off] // reset to actual size used if err != nil {
} else {
return nil, "", err return nil, "", err
} }
mbuf = append(mbuf, tbuf...) mbuf = append(mbuf, tbuf[:off]...)
// Update the ArCount directly in the buffer. // Update the ArCount directly in the buffer.
binary.BigEndian.PutUint16(mbuf[10:], uint16(len(m.Extra)+1)) binary.BigEndian.PutUint16(mbuf[10:], uint16(len(m.Extra)+1))
return mbuf, t.MAC, nil return mbuf, t.MAC, nil
} }
// TsigVerify verifies the TSIG on a message. // TsigVerify verifies the TSIG on a message. If the signature does not
// If the signature does not validate err contains the // validate the returned error contains the cause. If the signature is OK, the
// error, otherwise it is nil. // error is nil.
func TsigVerify(msg []byte, secret, requestMAC string, timersOnly bool) error { func TsigVerify(msg []byte, secret, requestMAC string, timersOnly bool) error {
rawsecret, err := fromBase64([]byte(secret)) return tsigVerify(msg, tsigHMACProvider(secret), requestMAC, timersOnly, uint64(time.Now().Unix()))
if err != nil { }
return err
// TsigVerifyWithProvider is similar to TsigVerify, but allows for a custom TsigProvider.
func TsigVerifyWithProvider(msg []byte, provider TsigProvider, requestMAC string, timersOnly bool) error {
return tsigVerify(msg, provider, requestMAC, timersOnly, uint64(time.Now().Unix()))
} }
// actual implementation of TsigVerify, taking the current time ('now') as a parameter for the convenience of tests.
func tsigVerify(msg []byte, provider TsigProvider, requestMAC string, timersOnly bool, now uint64) error {
// Strip the TSIG from the incoming msg // Strip the TSIG from the incoming msg
stripped, tsig, err := stripTsig(msg) stripped, tsig, err := stripTsig(msg)
if err != nil { if err != nil {
return err return err
} }
msgMAC, err := hex.DecodeString(tsig.MAC) buf, err := tsigBuffer(stripped, tsig, requestMAC, timersOnly)
if err != nil { if err != nil {
return err return err
} }
buf := tsigBuffer(stripped, tsig, requestMAC, timersOnly) if err := provider.Verify(buf, tsig); err != nil {
return err
}
// Fudge factor works both ways. A message can arrive before it was signed because // Fudge factor works both ways. A message can arrive before it was signed because
// of clock skew. // of clock skew.
now := uint64(time.Now().Unix()) // We check this after verifying the signature, following draft-ietf-dnsop-rfc2845bis
// instead of RFC2845, in order to prevent a security vulnerability as reported in CVE-2017-3142/3143.
ti := now - tsig.TimeSigned ti := now - tsig.TimeSigned
if now < tsig.TimeSigned { if now < tsig.TimeSigned {
ti = tsig.TimeSigned - now ti = tsig.TimeSigned - now
...@@ -178,28 +256,11 @@ func TsigVerify(msg []byte, secret, requestMAC string, timersOnly bool) error { ...@@ -178,28 +256,11 @@ func TsigVerify(msg []byte, secret, requestMAC string, timersOnly bool) error {
return ErrTime return ErrTime
} }
var h hash.Hash
switch strings.ToLower(tsig.Algorithm) {
case HmacMD5:
h = hmac.New(md5.New, rawsecret)
case HmacSHA1:
h = hmac.New(sha1.New, rawsecret)
case HmacSHA256:
h = hmac.New(sha256.New, rawsecret)
case HmacSHA512:
h = hmac.New(sha512.New, rawsecret)
default:
return ErrKeyAlg
}
h.Write(buf)
if !hmac.Equal(h.Sum(nil), msgMAC) {
return ErrSig
}
return nil return nil
} }
// Create a wiredata buffer for the MAC calculation. // Create a wiredata buffer for the MAC calculation.
func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []byte { func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) ([]byte, error) {
var buf []byte var buf []byte
if rr.TimeSigned == 0 { if rr.TimeSigned == 0 {
rr.TimeSigned = uint64(time.Now().Unix()) rr.TimeSigned = uint64(time.Now().Unix())
...@@ -216,7 +277,10 @@ func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []b ...@@ -216,7 +277,10 @@ func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []b
m.MACSize = uint16(len(requestMAC) / 2) m.MACSize = uint16(len(requestMAC) / 2)
m.MAC = requestMAC m.MAC = requestMAC
buf = make([]byte, len(requestMAC)) // long enough buf = make([]byte, len(requestMAC)) // long enough
n, _ := packMacWire(m, buf) n, err := packMacWire(m, buf)
if err != nil {
return nil, err
}
buf = buf[:n] buf = buf[:n]
} }
...@@ -225,20 +289,26 @@ func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []b ...@@ -225,20 +289,26 @@ func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []b
tsig := new(timerWireFmt) tsig := new(timerWireFmt)
tsig.TimeSigned = rr.TimeSigned tsig.TimeSigned = rr.TimeSigned
tsig.Fudge = rr.Fudge tsig.Fudge = rr.Fudge
n, _ := packTimerWire(tsig, tsigvar) n, err := packTimerWire(tsig, tsigvar)
if err != nil {
return nil, err
}
tsigvar = tsigvar[:n] tsigvar = tsigvar[:n]
} else { } else {
tsig := new(tsigWireFmt) tsig := new(tsigWireFmt)
tsig.Name = strings.ToLower(rr.Hdr.Name) tsig.Name = CanonicalName(rr.Hdr.Name)
tsig.Class = ClassANY tsig.Class = ClassANY
tsig.Ttl = rr.Hdr.Ttl tsig.Ttl = rr.Hdr.Ttl
tsig.Algorithm = strings.ToLower(rr.Algorithm) tsig.Algorithm = CanonicalName(rr.Algorithm)
tsig.TimeSigned = rr.TimeSigned tsig.TimeSigned = rr.TimeSigned
tsig.Fudge = rr.Fudge tsig.Fudge = rr.Fudge
tsig.Error = rr.Error tsig.Error = rr.Error
tsig.OtherLen = rr.OtherLen tsig.OtherLen = rr.OtherLen
tsig.OtherData = rr.OtherData tsig.OtherData = rr.OtherData
n, _ := packTsigWire(tsig, tsigvar) n, err := packTsigWire(tsig, tsigvar)
if err != nil {
return nil, err
}
tsigvar = tsigvar[:n] tsigvar = tsigvar[:n]
} }
...@@ -248,7 +318,7 @@ func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []b ...@@ -248,7 +318,7 @@ func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []b
} else { } else {
buf = append(msgbuf, tsigvar...) buf = append(msgbuf, tsigvar...)
} }
return buf return buf, nil
} }
// Strip the TSIG from the raw message. // Strip the TSIG from the raw message.
......
package dns package dns
import ( import (
"bytes"
"fmt" "fmt"
"net" "net"
"strconv" "strconv"
...@@ -61,6 +62,7 @@ const ( ...@@ -61,6 +62,7 @@ const (
TypeCERT uint16 = 37 TypeCERT uint16 = 37
TypeDNAME uint16 = 39 TypeDNAME uint16 = 39
TypeOPT uint16 = 41 // EDNS TypeOPT uint16 = 41 // EDNS
TypeAPL uint16 = 42
TypeDS uint16 = 43 TypeDS uint16 = 43
TypeSSHFP uint16 = 44 TypeSSHFP uint16 = 44
TypeRRSIG uint16 = 46 TypeRRSIG uint16 = 46
...@@ -79,6 +81,9 @@ const ( ...@@ -79,6 +81,9 @@ const (
TypeCDNSKEY uint16 = 60 TypeCDNSKEY uint16 = 60
TypeOPENPGPKEY uint16 = 61 TypeOPENPGPKEY uint16 = 61
TypeCSYNC uint16 = 62 TypeCSYNC uint16 = 62
TypeZONEMD uint16 = 63
TypeSVCB uint16 = 64
TypeHTTPS uint16 = 65
TypeSPF uint16 = 99 TypeSPF uint16 = 99
TypeUINFO uint16 = 100 TypeUINFO uint16 = 100
TypeUID uint16 = 101 TypeUID uint16 = 101
...@@ -146,6 +151,14 @@ const ( ...@@ -146,6 +151,14 @@ const (
OpcodeUpdate = 5 OpcodeUpdate = 5
) )
// Used in ZONEMD https://tools.ietf.org/html/rfc8976
const (
ZoneMDSchemeSimple = 1
ZoneMDHashAlgSHA384 = 1
ZoneMDHashAlgSHA512 = 2
)
// Header is the wire format for the DNS packet header. // Header is the wire format for the DNS packet header.
type Header struct { type Header struct {
Id uint16 Id uint16
...@@ -163,11 +176,11 @@ const ( ...@@ -163,11 +176,11 @@ const (
_RD = 1 << 8 // recursion desired _RD = 1 << 8 // recursion desired
_RA = 1 << 7 // recursion available _RA = 1 << 7 // recursion available
_Z = 1 << 6 // Z _Z = 1 << 6 // Z
_AD = 1 << 5 // authticated data _AD = 1 << 5 // authenticated data
_CD = 1 << 4 // checking disabled _CD = 1 << 4 // checking disabled
) )
// Various constants used in the LOC RR, See RFC 1887. // Various constants used in the LOC RR. See RFC 1887.
const ( const (
LOC_EQUATOR = 1 << 31 // RFC 1876, Section 2. LOC_EQUATOR = 1 << 31 // RFC 1876, Section 2.
LOC_PRIMEMERIDIAN = 1 << 31 // RFC 1876, Section 2. LOC_PRIMEMERIDIAN = 1 << 31 // RFC 1876, Section 2.
...@@ -205,21 +218,23 @@ var CertTypeToString = map[uint16]string{ ...@@ -205,21 +218,23 @@ var CertTypeToString = map[uint16]string{
CertOID: "OID", CertOID: "OID",
} }
// StringToCertType is the reverseof CertTypeToString.
var StringToCertType = reverseInt16(CertTypeToString)
//go:generate go run types_generate.go //go:generate go run types_generate.go
// Question holds a DNS question. There can be multiple questions in the // Question holds a DNS question. Usually there is just one. While the
// question section of a message. Usually there is just one. // original DNS RFCs allow multiple questions in the question section of a
// message, in practice it never works. Because most DNS servers see multiple
// questions as an error, it is recommended to only have one question per
// message.
type Question struct { type Question struct {
Name string `dns:"cdomain-name"` // "cdomain-name" specifies encoding (and may be compressed) Name string `dns:"cdomain-name"` // "cdomain-name" specifies encoding (and may be compressed)
Qtype uint16 Qtype uint16
Qclass uint16 Qclass uint16
} }
func (q *Question) len() int { func (q *Question) len(off int, compression map[string]struct{}) int {
return len(q.Name) + 1 + 2 + 2 l := domainNameLen(q.Name, off, compression, true)
l += 2 + 2
return l
} }
func (q *Question) String() (s string) { func (q *Question) String() (s string) {
...@@ -239,6 +254,25 @@ type ANY struct { ...@@ -239,6 +254,25 @@ type ANY struct {
func (rr *ANY) String() string { return rr.Hdr.String() } func (rr *ANY) String() string { return rr.Hdr.String() }
func (*ANY) parse(c *zlexer, origin string) *ParseError {
return &ParseError{err: "ANY records do not have a presentation format"}
}
// NULL RR. See RFC 1035.
type NULL struct {
Hdr RR_Header
Data string `dns:"any"`
}
func (rr *NULL) String() string {
// There is no presentation format; prefix string with a comment.
return ";" + rr.Hdr.String() + rr.Data
}
func (*NULL) parse(c *zlexer, origin string) *ParseError {
return &ParseError{err: "NULL records do not have a presentation format"}
}
// CNAME RR. See RFC 1034. // CNAME RR. See RFC 1034.
type CNAME struct { type CNAME struct {
Hdr RR_Header Hdr RR_Header
...@@ -351,7 +385,7 @@ func (rr *X25) String() string { ...@@ -351,7 +385,7 @@ func (rr *X25) String() string {
type RT struct { type RT struct {
Hdr RR_Header Hdr RR_Header
Preference uint16 Preference uint16
Host string `dns:"cdomain-name"` Host string `dns:"domain-name"` // RFC 3597 prohibits compressing records not defined in RFC 1035.
} }
func (rr *RT) String() string { func (rr *RT) String() string {
...@@ -386,7 +420,7 @@ type RP struct { ...@@ -386,7 +420,7 @@ type RP struct {
} }
func (rr *RP) String() string { func (rr *RP) String() string {
return rr.Hdr.String() + rr.Mbox + " " + sprintTxt([]string{rr.Txt}) return rr.Hdr.String() + sprintName(rr.Mbox) + " " + sprintName(rr.Txt)
} }
// SOA RR. See RFC 1035. // SOA RR. See RFC 1035.
...@@ -419,128 +453,172 @@ type TXT struct { ...@@ -419,128 +453,172 @@ type TXT struct {
func (rr *TXT) String() string { return rr.Hdr.String() + sprintTxt(rr.Txt) } func (rr *TXT) String() string { return rr.Hdr.String() + sprintTxt(rr.Txt) }
func sprintName(s string) string { func sprintName(s string) string {
src := []byte(s) var dst strings.Builder
dst := make([]byte, 0, len(src))
for i := 0; i < len(src); { for i := 0; i < len(s); {
if i+1 < len(src) && src[i] == '\\' && src[i+1] == '.' { if s[i] == '.' {
dst = append(dst, src[i:i+2]...) if dst.Len() != 0 {
i += 2 dst.WriteByte('.')
} else { }
b, n := nextByte(src, i) i++
continue
}
b, n := nextByte(s, i)
if n == 0 { if n == 0 {
i++ // dangling back slash // Drop "dangling" incomplete escapes.
} else if b == '.' { if dst.Len() == 0 {
dst = append(dst, b) return s[:i]
}
break
}
if isDomainNameLabelSpecial(b) {
if dst.Len() == 0 {
dst.Grow(len(s) * 2)
dst.WriteString(s[:i])
}
dst.WriteByte('\\')
dst.WriteByte(b)
} else if b < ' ' || b > '~' { // unprintable, use \DDD
if dst.Len() == 0 {
dst.Grow(len(s) * 2)
dst.WriteString(s[:i])
}
dst.WriteString(escapeByte(b))
} else { } else {
dst = appendDomainNameByte(dst, b) if dst.Len() != 0 {
dst.WriteByte(b)
}
} }
i += n i += n
} }
if dst.Len() == 0 {
return s
} }
return string(dst) return dst.String()
} }
func sprintTxtOctet(s string) string { func sprintTxtOctet(s string) string {
src := []byte(s) var dst strings.Builder
dst := make([]byte, 0, len(src)) dst.Grow(2 + len(s))
dst = append(dst, '"') dst.WriteByte('"')
for i := 0; i < len(src); { for i := 0; i < len(s); {
if i+1 < len(src) && src[i] == '\\' && src[i+1] == '.' { if i+1 < len(s) && s[i] == '\\' && s[i+1] == '.' {
dst = append(dst, src[i:i+2]...) dst.WriteString(s[i : i+2])
i += 2 i += 2
} else { continue
b, n := nextByte(src, i) }
b, n := nextByte(s, i)
if n == 0 { if n == 0 {
i++ // dangling back slash i++ // dangling back slash
} else if b == '.' {
dst = append(dst, b)
} else { } else {
if b < ' ' || b > '~' { writeTXTStringByte(&dst, b)
dst = appendByte(dst, b)
} else {
dst = append(dst, b)
}
} }
i += n i += n
} }
} dst.WriteByte('"')
dst = append(dst, '"') return dst.String()
return string(dst)
} }
func sprintTxt(txt []string) string { func sprintTxt(txt []string) string {
var out []byte var out strings.Builder
for i, s := range txt { for i, s := range txt {
out.Grow(3 + len(s))
if i > 0 { if i > 0 {
out = append(out, ` "`...) out.WriteString(` "`)
} else { } else {
out = append(out, '"') out.WriteByte('"')
} }
bs := []byte(s) for j := 0; j < len(s); {
for j := 0; j < len(bs); { b, n := nextByte(s, j)
b, n := nextByte(bs, j)
if n == 0 { if n == 0 {
break break
} }
out = appendTXTStringByte(out, b) writeTXTStringByte(&out, b)
j += n j += n
} }
out = append(out, '"') out.WriteByte('"')
} }
return string(out) return out.String()
} }
func appendDomainNameByte(s []byte, b byte) []byte { func writeTXTStringByte(s *strings.Builder, b byte) {
switch b { switch {
case '.', ' ', '\'', '@', ';', '(', ')': // additional chars to escape case b == '"' || b == '\\':
return append(s, '\\', b) s.WriteByte('\\')
s.WriteByte(b)
case b < ' ' || b > '~':
s.WriteString(escapeByte(b))
default:
s.WriteByte(b)
} }
return appendTXTStringByte(s, b)
} }
func appendTXTStringByte(s []byte, b byte) []byte { const (
switch b { escapedByteSmall = "" +
case '"', '\\': `\000\001\002\003\004\005\006\007\008\009` +
return append(s, '\\', b) `\010\011\012\013\014\015\016\017\018\019` +
} `\020\021\022\023\024\025\026\027\028\029` +
if b < ' ' || b > '~' { `\030\031`
return appendByte(s, b) escapedByteLarge = `\127\128\129` +
} `\130\131\132\133\134\135\136\137\138\139` +
return append(s, b) `\140\141\142\143\144\145\146\147\148\149` +
`\150\151\152\153\154\155\156\157\158\159` +
`\160\161\162\163\164\165\166\167\168\169` +
`\170\171\172\173\174\175\176\177\178\179` +
`\180\181\182\183\184\185\186\187\188\189` +
`\190\191\192\193\194\195\196\197\198\199` +
`\200\201\202\203\204\205\206\207\208\209` +
`\210\211\212\213\214\215\216\217\218\219` +
`\220\221\222\223\224\225\226\227\228\229` +
`\230\231\232\233\234\235\236\237\238\239` +
`\240\241\242\243\244\245\246\247\248\249` +
`\250\251\252\253\254\255`
)
// escapeByte returns the \DDD escaping of b which must
// satisfy b < ' ' || b > '~'.
func escapeByte(b byte) string {
if b < ' ' {
return escapedByteSmall[b*4 : b*4+4]
} }
func appendByte(s []byte, b byte) []byte { b -= '~' + 1
var buf [3]byte // The cast here is needed as b*4 may overflow byte.
bufs := strconv.AppendInt(buf[:0], int64(b), 10) return escapedByteLarge[int(b)*4 : int(b)*4+4]
s = append(s, '\\')
for i := 0; i < 3-len(bufs); i++ {
s = append(s, '0')
} }
for _, r := range bufs {
s = append(s, r) // isDomainNameLabelSpecial returns true if
// a domain name label byte should be prefixed
// with an escaping backslash.
func isDomainNameLabelSpecial(b byte) bool {
switch b {
case '.', ' ', '\'', '@', ';', '(', ')', '"', '\\':
return true
} }
return s return false
} }
func nextByte(b []byte, offset int) (byte, int) { func nextByte(s string, offset int) (byte, int) {
if offset >= len(b) { if offset >= len(s) {
return 0, 0 return 0, 0
} }
if b[offset] != '\\' { if s[offset] != '\\' {
// not an escape sequence // not an escape sequence
return b[offset], 1 return s[offset], 1
} }
switch len(b) - offset { switch len(s) - offset {
case 1: // dangling escape case 1: // dangling escape
return 0, 0 return 0, 0
case 2, 3: // too short to be \ddd case 2, 3: // too short to be \ddd
default: // maybe \ddd default: // maybe \ddd
if isDigit(b[offset+1]) && isDigit(b[offset+2]) && isDigit(b[offset+3]) { if isDigit(s[offset+1]) && isDigit(s[offset+2]) && isDigit(s[offset+3]) {
return dddToByte(b[offset+1:]), 4 return dddStringToByte(s[offset+1:]), 4
} }
} }
// not \ddd, just an RFC 1035 "quoted" character // not \ddd, just an RFC 1035 "quoted" character
return b[offset+1], 2 return s[offset+1], 2
} }
// SPF RR. See RFC 4408, Section 3.1.1. // SPF RR. See RFC 4408, Section 3.1.1.
...@@ -695,7 +773,7 @@ type LOC struct { ...@@ -695,7 +773,7 @@ type LOC struct {
} }
// cmToM takes a cm value expressed in RFC 1876 SIZE mantissa/exponent // cmToM takes a cm value expressed in RFC 1876 SIZE mantissa/exponent
// format and returns a string in m (two decimals for the cm) // format and returns a string in m (two decimals for the cm).
func cmToM(m, e uint8) string { func cmToM(m, e uint8) string {
if e < 2 { if e < 2 {
if e == 1 { if e == 1 {
...@@ -801,22 +879,16 @@ type NSEC struct { ...@@ -801,22 +879,16 @@ type NSEC struct {
func (rr *NSEC) String() string { func (rr *NSEC) String() string {
s := rr.Hdr.String() + sprintName(rr.NextDomain) s := rr.Hdr.String() + sprintName(rr.NextDomain)
for i := 0; i < len(rr.TypeBitMap); i++ { for _, t := range rr.TypeBitMap {
s += " " + Type(rr.TypeBitMap[i]).String() s += " " + Type(t).String()
} }
return s return s
} }
func (rr *NSEC) len() int { func (rr *NSEC) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() + len(rr.NextDomain) + 1 l := rr.Hdr.len(off, compression)
lastwindow := uint32(2 ^ 32 + 1) l += domainNameLen(rr.NextDomain, off+l, compression, false)
for _, t := range rr.TypeBitMap { l += typeBitMapLen(rr.TypeBitMap)
window := t / 256
if uint32(window) != lastwindow {
l += 1 + 32
}
lastwindow = uint32(window)
}
return l return l
} }
...@@ -966,22 +1038,16 @@ func (rr *NSEC3) String() string { ...@@ -966,22 +1038,16 @@ func (rr *NSEC3) String() string {
" " + strconv.Itoa(int(rr.Iterations)) + " " + strconv.Itoa(int(rr.Iterations)) +
" " + saltToString(rr.Salt) + " " + saltToString(rr.Salt) +
" " + rr.NextDomain " " + rr.NextDomain
for i := 0; i < len(rr.TypeBitMap); i++ { for _, t := range rr.TypeBitMap {
s += " " + Type(rr.TypeBitMap[i]).String() s += " " + Type(t).String()
} }
return s return s
} }
func (rr *NSEC3) len() int { func (rr *NSEC3) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() + 6 + len(rr.Salt)/2 + 1 + len(rr.NextDomain) + 1 l := rr.Hdr.len(off, compression)
lastwindow := uint32(2 ^ 32 + 1) l += 6 + len(rr.Salt)/2 + 1 + len(rr.NextDomain) + 1
for _, t := range rr.TypeBitMap { l += typeBitMapLen(rr.TypeBitMap)
window := t / 256
if uint32(window) != lastwindow {
l += 1 + 32
}
lastwindow = uint32(window)
}
return l return l
} }
...@@ -1020,10 +1086,16 @@ type TKEY struct { ...@@ -1020,10 +1086,16 @@ type TKEY struct {
// TKEY has no official presentation format, but this will suffice. // TKEY has no official presentation format, but this will suffice.
func (rr *TKEY) String() string { func (rr *TKEY) String() string {
s := "\n;; TKEY PSEUDOSECTION:\n" s := ";" + rr.Hdr.String() +
s += rr.Hdr.String() + " " + rr.Algorithm + " " + " " + rr.Algorithm +
strconv.Itoa(int(rr.KeySize)) + " " + rr.Key + " " + " " + TimeToString(rr.Inception) +
strconv.Itoa(int(rr.OtherLen)) + " " + rr.OtherData " " + TimeToString(rr.Expiration) +
" " + strconv.Itoa(int(rr.Mode)) +
" " + strconv.Itoa(int(rr.Error)) +
" " + strconv.Itoa(int(rr.KeySize)) +
" " + rr.Key +
" " + strconv.Itoa(int(rr.OtherLen)) +
" " + rr.OtherData
return s return s
} }
...@@ -1059,6 +1131,7 @@ type URI struct { ...@@ -1059,6 +1131,7 @@ type URI struct {
Target string `dns:"octet"` Target string `dns:"octet"`
} }
// rr.Target to be parsed as a sequence of character encoded octets according to RFC 3986
func (rr *URI) String() string { func (rr *URI) String() string {
return rr.Hdr.String() + strconv.Itoa(int(rr.Priority)) + return rr.Hdr.String() + strconv.Itoa(int(rr.Priority)) +
" " + strconv.Itoa(int(rr.Weight)) + " " + sprintTxtOctet(rr.Target) " " + strconv.Itoa(int(rr.Weight)) + " " + sprintTxtOctet(rr.Target)
...@@ -1220,6 +1293,7 @@ type CAA struct { ...@@ -1220,6 +1293,7 @@ type CAA struct {
Value string `dns:"octet"` Value string `dns:"octet"`
} }
// rr.Value Is the character-string encoding of the value field as specified in RFC 1035, Section 5.1.
func (rr *CAA) String() string { func (rr *CAA) String() string {
return rr.Hdr.String() + strconv.Itoa(int(rr.Flag)) + " " + rr.Tag + " " + sprintTxtOctet(rr.Value) return rr.Hdr.String() + strconv.Itoa(int(rr.Flag)) + " " + rr.Tag + " " + sprintTxtOctet(rr.Value)
} }
...@@ -1283,23 +1357,116 @@ type CSYNC struct { ...@@ -1283,23 +1357,116 @@ type CSYNC struct {
func (rr *CSYNC) String() string { func (rr *CSYNC) String() string {
s := rr.Hdr.String() + strconv.FormatInt(int64(rr.Serial), 10) + " " + strconv.Itoa(int(rr.Flags)) s := rr.Hdr.String() + strconv.FormatInt(int64(rr.Serial), 10) + " " + strconv.Itoa(int(rr.Flags))
for i := 0; i < len(rr.TypeBitMap); i++ { for _, t := range rr.TypeBitMap {
s += " " + Type(rr.TypeBitMap[i]).String() s += " " + Type(t).String()
} }
return s return s
} }
func (rr *CSYNC) len() int { func (rr *CSYNC) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() + 4 + 2 l := rr.Hdr.len(off, compression)
lastwindow := uint32(2 ^ 32 + 1) l += 4 + 2
for _, t := range rr.TypeBitMap { l += typeBitMapLen(rr.TypeBitMap)
window := t / 256 return l
if uint32(window) != lastwindow {
l += 1 + 32
} }
lastwindow = uint32(window)
// ZONEMD RR, from draft-ietf-dnsop-dns-zone-digest
type ZONEMD struct {
Hdr RR_Header
Serial uint32
Scheme uint8
Hash uint8
Digest string `dns:"hex"`
} }
return l
func (rr *ZONEMD) String() string {
return rr.Hdr.String() +
strconv.Itoa(int(rr.Serial)) +
" " + strconv.Itoa(int(rr.Scheme)) +
" " + strconv.Itoa(int(rr.Hash)) +
" " + rr.Digest
}
// APL RR. See RFC 3123.
type APL struct {
Hdr RR_Header
Prefixes []APLPrefix `dns:"apl"`
}
// APLPrefix is an address prefix hold by an APL record.
type APLPrefix struct {
Negation bool
Network net.IPNet
}
// String returns presentation form of the APL record.
func (rr *APL) String() string {
var sb strings.Builder
sb.WriteString(rr.Hdr.String())
for i, p := range rr.Prefixes {
if i > 0 {
sb.WriteByte(' ')
}
sb.WriteString(p.str())
}
return sb.String()
}
// str returns presentation form of the APL prefix.
func (a *APLPrefix) str() string {
var sb strings.Builder
if a.Negation {
sb.WriteByte('!')
}
switch len(a.Network.IP) {
case net.IPv4len:
sb.WriteByte('1')
case net.IPv6len:
sb.WriteByte('2')
}
sb.WriteByte(':')
switch len(a.Network.IP) {
case net.IPv4len:
sb.WriteString(a.Network.IP.String())
case net.IPv6len:
// add prefix for IPv4-mapped IPv6
if v4 := a.Network.IP.To4(); v4 != nil {
sb.WriteString("::ffff:")
}
sb.WriteString(a.Network.IP.String())
}
sb.WriteByte('/')
prefix, _ := a.Network.Mask.Size()
sb.WriteString(strconv.Itoa(prefix))
return sb.String()
}
// equals reports whether two APL prefixes are identical.
func (a *APLPrefix) equals(b *APLPrefix) bool {
return a.Negation == b.Negation &&
bytes.Equal(a.Network.IP, b.Network.IP) &&
bytes.Equal(a.Network.Mask, b.Network.Mask)
}
// copy returns a copy of the APL prefix.
func (a *APLPrefix) copy() APLPrefix {
return APLPrefix{
Negation: a.Negation,
Network: copyNet(a.Network),
}
}
// len returns size of the prefix in wire format.
func (a *APLPrefix) len() int {
// 4-byte header and the network address prefix (see Section 4 of RFC 3123)
prefix, _ := a.Network.Mask.Size()
return 4 + (prefix+7)/8
} }
// TimeToString translates the RRSIG's incep. and expir. times to the // TimeToString translates the RRSIG's incep. and expir. times to the
...@@ -1331,7 +1498,7 @@ func StringToTime(s string) (uint32, error) { ...@@ -1331,7 +1498,7 @@ func StringToTime(s string) (uint32, error) {
// saltToString converts a NSECX salt to uppercase and returns "-" when it is empty. // saltToString converts a NSECX salt to uppercase and returns "-" when it is empty.
func saltToString(s string) string { func saltToString(s string) string {
if len(s) == 0 { if s == "" {
return "-" return "-"
} }
return strings.ToUpper(s) return strings.ToUpper(s)
...@@ -1358,6 +1525,17 @@ func copyIP(ip net.IP) net.IP { ...@@ -1358,6 +1525,17 @@ func copyIP(ip net.IP) net.IP {
return p return p
} }
// copyNet returns a copy of a subnet.
func copyNet(n net.IPNet) net.IPNet {
m := make(net.IPMask, len(n.Mask))
copy(m, n.Mask)
return net.IPNet{
IP: copyIP(n.IP),
Mask: m,
}
}
// SplitN splits a string into N sized string chunks. // SplitN splits a string into N sized string chunks.
// This might become an exported function once. // This might become an exported function once.
func splitN(s string, n int) []string { func splitN(s string, n int) []string {
......
//+build ignore
// types_generate.go is meant to run with go generate. It will use
// go/{importer,types} to track down all the RR struct types. Then for each type
// it will generate conversion tables (TypeToRR and TypeToString) and banal
// methods (len, Header, copy) based on the struct tags. The generated source is
// written to ztypes.go, and is meant to be checked into git.
package main
import (
"bytes"
"fmt"
"go/format"
"go/importer"
"go/types"
"log"
"os"
"strings"
"text/template"
)
var skipLen = map[string]struct{}{
"NSEC": {},
"NSEC3": {},
"OPT": {},
"CSYNC": {},
}
var packageHdr = `
// Code generated by "go run types_generate.go"; DO NOT EDIT.
package dns
import (
"encoding/base64"
"net"
)
`
var TypeToRR = template.Must(template.New("TypeToRR").Parse(`
// TypeToRR is a map of constructors for each RR type.
var TypeToRR = map[uint16]func() RR{
{{range .}}{{if ne . "RFC3597"}} Type{{.}}: func() RR { return new({{.}}) },
{{end}}{{end}} }
`))
var typeToString = template.Must(template.New("typeToString").Parse(`
// TypeToString is a map of strings for each RR type.
var TypeToString = map[uint16]string{
{{range .}}{{if ne . "NSAPPTR"}} Type{{.}}: "{{.}}",
{{end}}{{end}} TypeNSAPPTR: "NSAP-PTR",
}
`))
var headerFunc = template.Must(template.New("headerFunc").Parse(`
{{range .}} func (rr *{{.}}) Header() *RR_Header { return &rr.Hdr }
{{end}}
`))
// getTypeStruct will take a type and the package scope, and return the
// (innermost) struct if the type is considered a RR type (currently defined as
// those structs beginning with a RR_Header, could be redefined as implementing
// the RR interface). The bool return value indicates if embedded structs were
// resolved.
func getTypeStruct(t types.Type, scope *types.Scope) (*types.Struct, bool) {
st, ok := t.Underlying().(*types.Struct)
if !ok {
return nil, false
}
if st.Field(0).Type() == scope.Lookup("RR_Header").Type() {
return st, false
}
if st.Field(0).Anonymous() {
st, _ := getTypeStruct(st.Field(0).Type(), scope)
return st, true
}
return nil, false
}
func main() {
// Import and type-check the package
pkg, err := importer.Default().Import("github.com/miekg/dns")
fatalIfErr(err)
scope := pkg.Scope()
// Collect constants like TypeX
var numberedTypes []string
for _, name := range scope.Names() {
o := scope.Lookup(name)
if o == nil || !o.Exported() {
continue
}
b, ok := o.Type().(*types.Basic)
if !ok || b.Kind() != types.Uint16 {
continue
}
if !strings.HasPrefix(o.Name(), "Type") {
continue
}
name := strings.TrimPrefix(o.Name(), "Type")
if name == "PrivateRR" {
continue
}
numberedTypes = append(numberedTypes, name)
}
// Collect actual types (*X)
var namedTypes []string
for _, name := range scope.Names() {
o := scope.Lookup(name)
if o == nil || !o.Exported() {
continue
}
if st, _ := getTypeStruct(o.Type(), scope); st == nil {
continue
}
if name == "PrivateRR" {
continue
}
// Check if corresponding TypeX exists
if scope.Lookup("Type"+o.Name()) == nil && o.Name() != "RFC3597" {
log.Fatalf("Constant Type%s does not exist.", o.Name())
}
namedTypes = append(namedTypes, o.Name())
}
b := &bytes.Buffer{}
b.WriteString(packageHdr)
// Generate TypeToRR
fatalIfErr(TypeToRR.Execute(b, namedTypes))
// Generate typeToString
fatalIfErr(typeToString.Execute(b, numberedTypes))
// Generate headerFunc
fatalIfErr(headerFunc.Execute(b, namedTypes))
// Generate len()
fmt.Fprint(b, "// len() functions\n")
for _, name := range namedTypes {
if _, ok := skipLen[name]; ok {
continue
}
o := scope.Lookup(name)
st, isEmbedded := getTypeStruct(o.Type(), scope)
if isEmbedded {
continue
}
fmt.Fprintf(b, "func (rr *%s) len() int {\n", name)
fmt.Fprintf(b, "l := rr.Hdr.len()\n")
for i := 1; i < st.NumFields(); i++ {
o := func(s string) { fmt.Fprintf(b, s, st.Field(i).Name()) }
if _, ok := st.Field(i).Type().(*types.Slice); ok {
switch st.Tag(i) {
case `dns:"-"`:
// ignored
case `dns:"cdomain-name"`, `dns:"domain-name"`, `dns:"txt"`:
o("for _, x := range rr.%s { l += len(x) + 1 }\n")
default:
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
}
continue
}
switch {
case st.Tag(i) == `dns:"-"`:
// ignored
case st.Tag(i) == `dns:"cdomain-name"`, st.Tag(i) == `dns:"domain-name"`:
o("l += len(rr.%s) + 1\n")
case st.Tag(i) == `dns:"octet"`:
o("l += len(rr.%s)\n")
case strings.HasPrefix(st.Tag(i), `dns:"size-base64`):
fallthrough
case st.Tag(i) == `dns:"base64"`:
o("l += base64.StdEncoding.DecodedLen(len(rr.%s))\n")
case strings.HasPrefix(st.Tag(i), `dns:"size-hex:`): // this has an extra field where the length is stored
o("l += len(rr.%s)/2\n")
case strings.HasPrefix(st.Tag(i), `dns:"size-hex`):
fallthrough
case st.Tag(i) == `dns:"hex"`:
o("l += len(rr.%s)/2 + 1\n")
case st.Tag(i) == `dns:"a"`:
o("l += net.IPv4len // %s\n")
case st.Tag(i) == `dns:"aaaa"`:
o("l += net.IPv6len // %s\n")
case st.Tag(i) == `dns:"txt"`:
o("for _, t := range rr.%s { l += len(t) + 1 }\n")
case st.Tag(i) == `dns:"uint48"`:
o("l += 6 // %s\n")
case st.Tag(i) == "":
switch st.Field(i).Type().(*types.Basic).Kind() {
case types.Uint8:
o("l++ // %s\n")
case types.Uint16:
o("l += 2 // %s\n")
case types.Uint32:
o("l += 4 // %s\n")
case types.Uint64:
o("l += 8 // %s\n")
case types.String:
o("l += len(rr.%s) + 1\n")
default:
log.Fatalln(name, st.Field(i).Name())
}
default:
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
}
}
fmt.Fprintf(b, "return l }\n")
}
// Generate copy()
fmt.Fprint(b, "// copy() functions\n")
for _, name := range namedTypes {
o := scope.Lookup(name)
st, isEmbedded := getTypeStruct(o.Type(), scope)
if isEmbedded {
continue
}
fmt.Fprintf(b, "func (rr *%s) copy() RR {\n", name)
fields := []string{"rr.Hdr"}
for i := 1; i < st.NumFields(); i++ {
f := st.Field(i).Name()
if sl, ok := st.Field(i).Type().(*types.Slice); ok {
t := sl.Underlying().String()
t = strings.TrimPrefix(t, "[]")
if strings.Contains(t, ".") {
splits := strings.Split(t, ".")
t = splits[len(splits)-1]
}
fmt.Fprintf(b, "%s := make([]%s, len(rr.%s)); copy(%s, rr.%s)\n",
f, t, f, f, f)
fields = append(fields, f)
continue
}
if st.Field(i).Type().String() == "net.IP" {
fields = append(fields, "copyIP(rr."+f+")")
continue
}
fields = append(fields, "rr."+f)
}
fmt.Fprintf(b, "return &%s{%s}\n", name, strings.Join(fields, ","))
fmt.Fprintf(b, "}\n")
}
// gofmt
res, err := format.Source(b.Bytes())
if err != nil {
b.WriteTo(os.Stderr)
log.Fatal(err)
}
// write result
f, err := os.Create("ztypes.go")
fatalIfErr(err)
defer f.Close()
f.Write(res)
}
func fatalIfErr(err error) {
if err != nil {
log.Fatal(err)
}
}
...@@ -20,15 +20,13 @@ func ReadFromSessionUDP(conn *net.UDPConn, b []byte) (int, *SessionUDP, error) { ...@@ -20,15 +20,13 @@ func ReadFromSessionUDP(conn *net.UDPConn, b []byte) (int, *SessionUDP, error) {
if err != nil { if err != nil {
return n, nil, err return n, nil, err
} }
session := &SessionUDP{raddr.(*net.UDPAddr)} return n, &SessionUDP{raddr.(*net.UDPAddr)}, err
return n, session, err
} }
// WriteToSessionUDP acts just like net.UDPConn.WriteTo(), but uses a *SessionUDP instead of a net.Addr. // WriteToSessionUDP acts just like net.UDPConn.WriteTo(), but uses a *SessionUDP instead of a net.Addr.
// TODO(fastest963): Once go1.10 is released, use WriteMsgUDP. // TODO(fastest963): Once go1.10 is released, use WriteMsgUDP.
func WriteToSessionUDP(conn *net.UDPConn, b []byte, session *SessionUDP) (int, error) { func WriteToSessionUDP(conn *net.UDPConn, b []byte, session *SessionUDP) (int, error) {
n, err := conn.WriteTo(b, session.raddr) return conn.WriteTo(b, session.raddr)
return n, err
} }
// TODO(fastest963): Once go1.10 is released and we can use *MsgUDP methods // TODO(fastest963): Once go1.10 is released and we can use *MsgUDP methods
......
...@@ -32,7 +32,9 @@ func (u *Msg) Used(rr []RR) { ...@@ -32,7 +32,9 @@ func (u *Msg) Used(rr []RR) {
u.Answer = make([]RR, 0, len(rr)) u.Answer = make([]RR, 0, len(rr))
} }
for _, r := range rr { for _, r := range rr {
r.Header().Class = u.Question[0].Qclass hdr := r.Header()
hdr.Class = u.Question[0].Qclass
hdr.Ttl = 0
u.Answer = append(u.Answer, r) u.Answer = append(u.Answer, r)
} }
} }
...@@ -44,7 +46,8 @@ func (u *Msg) RRsetUsed(rr []RR) { ...@@ -44,7 +46,8 @@ func (u *Msg) RRsetUsed(rr []RR) {
u.Answer = make([]RR, 0, len(rr)) u.Answer = make([]RR, 0, len(rr))
} }
for _, r := range rr { for _, r := range rr {
u.Answer = append(u.Answer, &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: r.Header().Rrtype, Class: ClassANY}}) h := r.Header()
u.Answer = append(u.Answer, &ANY{Hdr: RR_Header{Name: h.Name, Ttl: 0, Rrtype: h.Rrtype, Class: ClassANY}})
} }
} }
...@@ -55,7 +58,8 @@ func (u *Msg) RRsetNotUsed(rr []RR) { ...@@ -55,7 +58,8 @@ func (u *Msg) RRsetNotUsed(rr []RR) {
u.Answer = make([]RR, 0, len(rr)) u.Answer = make([]RR, 0, len(rr))
} }
for _, r := range rr { for _, r := range rr {
u.Answer = append(u.Answer, &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: r.Header().Rrtype, Class: ClassNONE}}) h := r.Header()
u.Answer = append(u.Answer, &ANY{Hdr: RR_Header{Name: h.Name, Ttl: 0, Rrtype: h.Rrtype, Class: ClassNONE}})
} }
} }
...@@ -79,7 +83,8 @@ func (u *Msg) RemoveRRset(rr []RR) { ...@@ -79,7 +83,8 @@ func (u *Msg) RemoveRRset(rr []RR) {
u.Ns = make([]RR, 0, len(rr)) u.Ns = make([]RR, 0, len(rr))
} }
for _, r := range rr { for _, r := range rr {
u.Ns = append(u.Ns, &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: r.Header().Rrtype, Class: ClassANY}}) h := r.Header()
u.Ns = append(u.Ns, &ANY{Hdr: RR_Header{Name: h.Name, Ttl: 0, Rrtype: h.Rrtype, Class: ClassANY}})
} }
} }
...@@ -99,8 +104,9 @@ func (u *Msg) Remove(rr []RR) { ...@@ -99,8 +104,9 @@ func (u *Msg) Remove(rr []RR) {
u.Ns = make([]RR, 0, len(rr)) u.Ns = make([]RR, 0, len(rr))
} }
for _, r := range rr { for _, r := range rr {
r.Header().Class = ClassNONE h := r.Header()
r.Header().Ttl = 0 h.Class = ClassNONE
h.Ttl = 0
u.Ns = append(u.Ns, r) u.Ns = append(u.Ns, r)
} }
} }
...@@ -3,13 +3,13 @@ package dns ...@@ -3,13 +3,13 @@ package dns
import "fmt" import "fmt"
// Version is current version of this library. // Version is current version of this library.
var Version = V{1, 0, 8} var Version = v{1, 1, 50}
// V holds the version of this library. // v holds the version of this library.
type V struct { type v struct {
Major, Minor, Patch int Major, Minor, Patch int
} }
func (v V) String() string { func (v v) String() string {
return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch) return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch)
} }
...@@ -17,11 +17,22 @@ type Transfer struct { ...@@ -17,11 +17,22 @@ type Transfer struct {
DialTimeout time.Duration // net.DialTimeout, defaults to 2 seconds DialTimeout time.Duration // net.DialTimeout, defaults to 2 seconds
ReadTimeout time.Duration // net.Conn.SetReadTimeout value for connections, defaults to 2 seconds ReadTimeout time.Duration // net.Conn.SetReadTimeout value for connections, defaults to 2 seconds
WriteTimeout time.Duration // net.Conn.SetWriteTimeout value for connections, defaults to 2 seconds WriteTimeout time.Duration // net.Conn.SetWriteTimeout value for connections, defaults to 2 seconds
TsigProvider TsigProvider // An implementation of the TsigProvider interface. If defined it replaces TsigSecret and is used for all TSIG operations.
TsigSecret map[string]string // Secret(s) for Tsig map[<zonename>]<base64 secret>, zonename must be in canonical form (lowercase, fqdn, see RFC 4034 Section 6.2) TsigSecret map[string]string // Secret(s) for Tsig map[<zonename>]<base64 secret>, zonename must be in canonical form (lowercase, fqdn, see RFC 4034 Section 6.2)
tsigTimersOnly bool tsigTimersOnly bool
} }
// Think we need to away to stop the transfer func (t *Transfer) tsigProvider() TsigProvider {
if t.TsigProvider != nil {
return t.TsigProvider
}
if t.TsigSecret != nil {
return tsigSecretProvider(t.TsigSecret)
}
return nil
}
// TODO: Think we need to away to stop the transfer
// In performs an incoming transfer with the server in a. // In performs an incoming transfer with the server in a.
// If you would like to set the source IP, or some other attribute // If you would like to set the source IP, or some other attribute
...@@ -35,30 +46,36 @@ type Transfer struct { ...@@ -35,30 +46,36 @@ type Transfer struct {
// channel, err := transfer.In(message, master) // channel, err := transfer.In(message, master)
// //
func (t *Transfer) In(q *Msg, a string) (env chan *Envelope, err error) { func (t *Transfer) In(q *Msg, a string) (env chan *Envelope, err error) {
switch q.Question[0].Qtype {
case TypeAXFR, TypeIXFR:
default:
return nil, &Error{"unsupported question type"}
}
timeout := dnsTimeout timeout := dnsTimeout
if t.DialTimeout != 0 { if t.DialTimeout != 0 {
timeout = t.DialTimeout timeout = t.DialTimeout
} }
if t.Conn == nil { if t.Conn == nil {
t.Conn, err = DialTimeout("tcp", a, timeout) t.Conn, err = DialTimeout("tcp", a, timeout)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
if err := t.WriteMsg(q); err != nil { if err := t.WriteMsg(q); err != nil {
return nil, err return nil, err
} }
env = make(chan *Envelope) env = make(chan *Envelope)
go func() { switch q.Question[0].Qtype {
if q.Question[0].Qtype == TypeAXFR { case TypeAXFR:
go t.inAxfr(q, env) go t.inAxfr(q, env)
return case TypeIXFR:
}
if q.Question[0].Qtype == TypeIXFR {
go t.inIxfr(q, env) go t.inIxfr(q, env)
return
} }
}()
return env, nil return env, nil
} }
...@@ -111,7 +128,7 @@ func (t *Transfer) inAxfr(q *Msg, c chan *Envelope) { ...@@ -111,7 +128,7 @@ func (t *Transfer) inAxfr(q *Msg, c chan *Envelope) {
} }
func (t *Transfer) inIxfr(q *Msg, c chan *Envelope) { func (t *Transfer) inIxfr(q *Msg, c chan *Envelope) {
serial := uint32(0) // The first serial seen is the current server serial var serial uint32 // The first serial seen is the current server serial
axfr := true axfr := true
n := 0 n := 0
qser := q.Ns[0].(*SOA).Serial qser := q.Ns[0].(*SOA).Serial
...@@ -176,14 +193,17 @@ func (t *Transfer) inIxfr(q *Msg, c chan *Envelope) { ...@@ -176,14 +193,17 @@ func (t *Transfer) inIxfr(q *Msg, c chan *Envelope) {
// //
// ch := make(chan *dns.Envelope) // ch := make(chan *dns.Envelope)
// tr := new(dns.Transfer) // tr := new(dns.Transfer)
// go tr.Out(w, r, ch) // var wg sync.WaitGroup
// go func() {
// tr.Out(w, r, ch)
// wg.Done()
// }()
// ch <- &dns.Envelope{RR: []dns.RR{soa, rr1, rr2, rr3, soa}} // ch <- &dns.Envelope{RR: []dns.RR{soa, rr1, rr2, rr3, soa}}
// close(ch) // close(ch)
// w.Hijack() // wg.Wait() // wait until everything is written out
// // w.Close() // Client closes connection // w.Close() // close connection
// //
// The server is responsible for sending the correct sequence of RRs through the // The server is responsible for sending the correct sequence of RRs through the channel ch.
// channel ch.
func (t *Transfer) Out(w ResponseWriter, q *Msg, ch chan *Envelope) error { func (t *Transfer) Out(w ResponseWriter, q *Msg, ch chan *Envelope) error {
for x := range ch { for x := range ch {
r := new(Msg) r := new(Msg)
...@@ -192,11 +212,14 @@ func (t *Transfer) Out(w ResponseWriter, q *Msg, ch chan *Envelope) error { ...@@ -192,11 +212,14 @@ func (t *Transfer) Out(w ResponseWriter, q *Msg, ch chan *Envelope) error {
r.Authoritative = true r.Authoritative = true
// assume it fits TODO(miek): fix // assume it fits TODO(miek): fix
r.Answer = append(r.Answer, x.RR...) r.Answer = append(r.Answer, x.RR...)
if tsig := q.IsTsig(); tsig != nil && w.TsigStatus() == nil {
r.SetTsig(tsig.Hdr.Name, tsig.Algorithm, tsig.Fudge, time.Now().Unix())
}
if err := w.WriteMsg(r); err != nil { if err := w.WriteMsg(r); err != nil {
return err return err
} }
}
w.TsigTimersOnly(true) w.TsigTimersOnly(true)
}
return nil return nil
} }
...@@ -212,12 +235,9 @@ func (t *Transfer) ReadMsg() (*Msg, error) { ...@@ -212,12 +235,9 @@ func (t *Transfer) ReadMsg() (*Msg, error) {
if err := m.Unpack(p); err != nil { if err := m.Unpack(p); err != nil {
return nil, err return nil, err
} }
if ts := m.IsTsig(); ts != nil && t.TsigSecret != nil { if ts, tp := m.IsTsig(), t.tsigProvider(); ts != nil && tp != nil {
if _, ok := t.TsigSecret[ts.Hdr.Name]; !ok {
return m, ErrSecret
}
// Need to work on the original message p, as that was used to calculate the tsig. // Need to work on the original message p, as that was used to calculate the tsig.
err = TsigVerify(p, t.TsigSecret[ts.Hdr.Name], t.tsigRequestMAC, t.tsigTimersOnly) err = TsigVerifyWithProvider(p, tp, t.tsigRequestMAC, t.tsigTimersOnly)
t.tsigRequestMAC = ts.MAC t.tsigRequestMAC = ts.MAC
} }
return m, err return m, err
...@@ -226,35 +246,26 @@ func (t *Transfer) ReadMsg() (*Msg, error) { ...@@ -226,35 +246,26 @@ func (t *Transfer) ReadMsg() (*Msg, error) {
// WriteMsg writes a message through the transfer connection t. // WriteMsg writes a message through the transfer connection t.
func (t *Transfer) WriteMsg(m *Msg) (err error) { func (t *Transfer) WriteMsg(m *Msg) (err error) {
var out []byte var out []byte
if ts := m.IsTsig(); ts != nil && t.TsigSecret != nil { if ts, tp := m.IsTsig(), t.tsigProvider(); ts != nil && tp != nil {
if _, ok := t.TsigSecret[ts.Hdr.Name]; !ok { out, t.tsigRequestMAC, err = TsigGenerateWithProvider(m, tp, t.tsigRequestMAC, t.tsigTimersOnly)
return ErrSecret
}
out, t.tsigRequestMAC, err = TsigGenerate(m, t.TsigSecret[ts.Hdr.Name], t.tsigRequestMAC, t.tsigTimersOnly)
} else { } else {
out, err = m.Pack() out, err = m.Pack()
} }
if err != nil { if err != nil {
return err return err
} }
if _, err = t.Write(out); err != nil { _, err = t.Write(out)
return err return err
} }
return nil
}
func isSOAFirst(in *Msg) bool { func isSOAFirst(in *Msg) bool {
if len(in.Answer) > 0 { return len(in.Answer) > 0 &&
return in.Answer[0].Header().Rrtype == TypeSOA in.Answer[0].Header().Rrtype == TypeSOA
}
return false
} }
func isSOALast(in *Msg) bool { func isSOALast(in *Msg) bool {
if len(in.Answer) > 0 { return len(in.Answer) > 0 &&
return in.Answer[len(in.Answer)-1].Header().Rrtype == TypeSOA in.Answer[len(in.Answer)-1].Header().Rrtype == TypeSOA
}
return false
} }
const errXFR = "bad xfr rcode: %d" const errXFR = "bad xfr rcode: %d"
// Code generated by "go run compress_generate.go"; DO NOT EDIT.
package dns
func compressionLenHelperType(c map[string]int, r RR, initLen int) int {
currentLen := initLen
switch x := r.(type) {
case *AFSDB:
currentLen -= len(x.Hostname) + 1
currentLen += compressionLenHelper(c, x.Hostname, currentLen)
case *CNAME:
currentLen -= len(x.Target) + 1
currentLen += compressionLenHelper(c, x.Target, currentLen)
case *DNAME:
currentLen -= len(x.Target) + 1
currentLen += compressionLenHelper(c, x.Target, currentLen)
case *HIP:
for i := range x.RendezvousServers {
currentLen -= len(x.RendezvousServers[i]) + 1
}
for i := range x.RendezvousServers {
currentLen += compressionLenHelper(c, x.RendezvousServers[i], currentLen)
}
case *KX:
currentLen -= len(x.Exchanger) + 1
currentLen += compressionLenHelper(c, x.Exchanger, currentLen)
case *LP:
currentLen -= len(x.Fqdn) + 1
currentLen += compressionLenHelper(c, x.Fqdn, currentLen)
case *MB:
currentLen -= len(x.Mb) + 1
currentLen += compressionLenHelper(c, x.Mb, currentLen)
case *MD:
currentLen -= len(x.Md) + 1
currentLen += compressionLenHelper(c, x.Md, currentLen)
case *MF:
currentLen -= len(x.Mf) + 1
currentLen += compressionLenHelper(c, x.Mf, currentLen)
case *MG:
currentLen -= len(x.Mg) + 1
currentLen += compressionLenHelper(c, x.Mg, currentLen)
case *MINFO:
currentLen -= len(x.Rmail) + 1
currentLen += compressionLenHelper(c, x.Rmail, currentLen)
currentLen -= len(x.Email) + 1
currentLen += compressionLenHelper(c, x.Email, currentLen)
case *MR:
currentLen -= len(x.Mr) + 1
currentLen += compressionLenHelper(c, x.Mr, currentLen)
case *MX:
currentLen -= len(x.Mx) + 1
currentLen += compressionLenHelper(c, x.Mx, currentLen)
case *NAPTR:
currentLen -= len(x.Replacement) + 1
currentLen += compressionLenHelper(c, x.Replacement, currentLen)
case *NS:
currentLen -= len(x.Ns) + 1
currentLen += compressionLenHelper(c, x.Ns, currentLen)
case *NSAPPTR:
currentLen -= len(x.Ptr) + 1
currentLen += compressionLenHelper(c, x.Ptr, currentLen)
case *NSEC:
currentLen -= len(x.NextDomain) + 1
currentLen += compressionLenHelper(c, x.NextDomain, currentLen)
case *PTR:
currentLen -= len(x.Ptr) + 1
currentLen += compressionLenHelper(c, x.Ptr, currentLen)
case *PX:
currentLen -= len(x.Map822) + 1
currentLen += compressionLenHelper(c, x.Map822, currentLen)
currentLen -= len(x.Mapx400) + 1
currentLen += compressionLenHelper(c, x.Mapx400, currentLen)
case *RP:
currentLen -= len(x.Mbox) + 1
currentLen += compressionLenHelper(c, x.Mbox, currentLen)
currentLen -= len(x.Txt) + 1
currentLen += compressionLenHelper(c, x.Txt, currentLen)
case *RRSIG:
currentLen -= len(x.SignerName) + 1
currentLen += compressionLenHelper(c, x.SignerName, currentLen)
case *RT:
currentLen -= len(x.Host) + 1
currentLen += compressionLenHelper(c, x.Host, currentLen)
case *SIG:
currentLen -= len(x.SignerName) + 1
currentLen += compressionLenHelper(c, x.SignerName, currentLen)
case *SOA:
currentLen -= len(x.Ns) + 1
currentLen += compressionLenHelper(c, x.Ns, currentLen)
currentLen -= len(x.Mbox) + 1
currentLen += compressionLenHelper(c, x.Mbox, currentLen)
case *SRV:
currentLen -= len(x.Target) + 1
currentLen += compressionLenHelper(c, x.Target, currentLen)
case *TALINK:
currentLen -= len(x.PreviousName) + 1
currentLen += compressionLenHelper(c, x.PreviousName, currentLen)
currentLen -= len(x.NextName) + 1
currentLen += compressionLenHelper(c, x.NextName, currentLen)
case *TKEY:
currentLen -= len(x.Algorithm) + 1
currentLen += compressionLenHelper(c, x.Algorithm, currentLen)
case *TSIG:
currentLen -= len(x.Algorithm) + 1
currentLen += compressionLenHelper(c, x.Algorithm, currentLen)
}
return currentLen - initLen
}
func compressionLenSearchType(c map[string]int, r RR) (int, bool, int) {
switch x := r.(type) {
case *CNAME:
k1, ok1, sz1 := compressionLenSearch(c, x.Target)
return k1, ok1, sz1
case *MB:
k1, ok1, sz1 := compressionLenSearch(c, x.Mb)
return k1, ok1, sz1
case *MD:
k1, ok1, sz1 := compressionLenSearch(c, x.Md)
return k1, ok1, sz1
case *MF:
k1, ok1, sz1 := compressionLenSearch(c, x.Mf)
return k1, ok1, sz1
case *MG:
k1, ok1, sz1 := compressionLenSearch(c, x.Mg)
return k1, ok1, sz1
case *MINFO:
k1, ok1, sz1 := compressionLenSearch(c, x.Rmail)
k2, ok2, sz2 := compressionLenSearch(c, x.Email)
return k1 + k2, ok1 && ok2, sz1 + sz2
case *MR:
k1, ok1, sz1 := compressionLenSearch(c, x.Mr)
return k1, ok1, sz1
case *MX:
k1, ok1, sz1 := compressionLenSearch(c, x.Mx)
return k1, ok1, sz1
case *NS:
k1, ok1, sz1 := compressionLenSearch(c, x.Ns)
return k1, ok1, sz1
case *PTR:
k1, ok1, sz1 := compressionLenSearch(c, x.Ptr)
return k1, ok1, sz1
case *RT:
k1, ok1, sz1 := compressionLenSearch(c, x.Host)
return k1, ok1, sz1
case *SOA:
k1, ok1, sz1 := compressionLenSearch(c, x.Ns)
k2, ok2, sz2 := compressionLenSearch(c, x.Mbox)
return k1 + k2, ok1 && ok2, sz1 + sz2
}
return 0, false, 0
}
...@@ -2,174 +2,79 @@ ...@@ -2,174 +2,79 @@
package dns package dns
// isDuplicateRdata calls the rdata specific functions // isDuplicate() functions
func isDuplicateRdata(r1, r2 RR) bool {
switch r1.Header().Rrtype { func (r1 *A) isDuplicate(_r2 RR) bool {
case TypeA: r2, ok := _r2.(*A)
return isDuplicateA(r1.(*A), r2.(*A)) if !ok {
case TypeAAAA: return false
return isDuplicateAAAA(r1.(*AAAA), r2.(*AAAA))
case TypeAFSDB:
return isDuplicateAFSDB(r1.(*AFSDB), r2.(*AFSDB))
case TypeAVC:
return isDuplicateAVC(r1.(*AVC), r2.(*AVC))
case TypeCAA:
return isDuplicateCAA(r1.(*CAA), r2.(*CAA))
case TypeCERT:
return isDuplicateCERT(r1.(*CERT), r2.(*CERT))
case TypeCNAME:
return isDuplicateCNAME(r1.(*CNAME), r2.(*CNAME))
case TypeCSYNC:
return isDuplicateCSYNC(r1.(*CSYNC), r2.(*CSYNC))
case TypeDHCID:
return isDuplicateDHCID(r1.(*DHCID), r2.(*DHCID))
case TypeDNAME:
return isDuplicateDNAME(r1.(*DNAME), r2.(*DNAME))
case TypeDNSKEY:
return isDuplicateDNSKEY(r1.(*DNSKEY), r2.(*DNSKEY))
case TypeDS:
return isDuplicateDS(r1.(*DS), r2.(*DS))
case TypeEID:
return isDuplicateEID(r1.(*EID), r2.(*EID))
case TypeEUI48:
return isDuplicateEUI48(r1.(*EUI48), r2.(*EUI48))
case TypeEUI64:
return isDuplicateEUI64(r1.(*EUI64), r2.(*EUI64))
case TypeGID:
return isDuplicateGID(r1.(*GID), r2.(*GID))
case TypeGPOS:
return isDuplicateGPOS(r1.(*GPOS), r2.(*GPOS))
case TypeHINFO:
return isDuplicateHINFO(r1.(*HINFO), r2.(*HINFO))
case TypeHIP:
return isDuplicateHIP(r1.(*HIP), r2.(*HIP))
case TypeKX:
return isDuplicateKX(r1.(*KX), r2.(*KX))
case TypeL32:
return isDuplicateL32(r1.(*L32), r2.(*L32))
case TypeL64:
return isDuplicateL64(r1.(*L64), r2.(*L64))
case TypeLOC:
return isDuplicateLOC(r1.(*LOC), r2.(*LOC))
case TypeLP:
return isDuplicateLP(r1.(*LP), r2.(*LP))
case TypeMB:
return isDuplicateMB(r1.(*MB), r2.(*MB))
case TypeMD:
return isDuplicateMD(r1.(*MD), r2.(*MD))
case TypeMF:
return isDuplicateMF(r1.(*MF), r2.(*MF))
case TypeMG:
return isDuplicateMG(r1.(*MG), r2.(*MG))
case TypeMINFO:
return isDuplicateMINFO(r1.(*MINFO), r2.(*MINFO))
case TypeMR:
return isDuplicateMR(r1.(*MR), r2.(*MR))
case TypeMX:
return isDuplicateMX(r1.(*MX), r2.(*MX))
case TypeNAPTR:
return isDuplicateNAPTR(r1.(*NAPTR), r2.(*NAPTR))
case TypeNID:
return isDuplicateNID(r1.(*NID), r2.(*NID))
case TypeNIMLOC:
return isDuplicateNIMLOC(r1.(*NIMLOC), r2.(*NIMLOC))
case TypeNINFO:
return isDuplicateNINFO(r1.(*NINFO), r2.(*NINFO))
case TypeNS:
return isDuplicateNS(r1.(*NS), r2.(*NS))
case TypeNSAPPTR:
return isDuplicateNSAPPTR(r1.(*NSAPPTR), r2.(*NSAPPTR))
case TypeNSEC:
return isDuplicateNSEC(r1.(*NSEC), r2.(*NSEC))
case TypeNSEC3:
return isDuplicateNSEC3(r1.(*NSEC3), r2.(*NSEC3))
case TypeNSEC3PARAM:
return isDuplicateNSEC3PARAM(r1.(*NSEC3PARAM), r2.(*NSEC3PARAM))
case TypeOPENPGPKEY:
return isDuplicateOPENPGPKEY(r1.(*OPENPGPKEY), r2.(*OPENPGPKEY))
case TypePTR:
return isDuplicatePTR(r1.(*PTR), r2.(*PTR))
case TypePX:
return isDuplicatePX(r1.(*PX), r2.(*PX))
case TypeRKEY:
return isDuplicateRKEY(r1.(*RKEY), r2.(*RKEY))
case TypeRP:
return isDuplicateRP(r1.(*RP), r2.(*RP))
case TypeRRSIG:
return isDuplicateRRSIG(r1.(*RRSIG), r2.(*RRSIG))
case TypeRT:
return isDuplicateRT(r1.(*RT), r2.(*RT))
case TypeSMIMEA:
return isDuplicateSMIMEA(r1.(*SMIMEA), r2.(*SMIMEA))
case TypeSOA:
return isDuplicateSOA(r1.(*SOA), r2.(*SOA))
case TypeSPF:
return isDuplicateSPF(r1.(*SPF), r2.(*SPF))
case TypeSRV:
return isDuplicateSRV(r1.(*SRV), r2.(*SRV))
case TypeSSHFP:
return isDuplicateSSHFP(r1.(*SSHFP), r2.(*SSHFP))
case TypeTA:
return isDuplicateTA(r1.(*TA), r2.(*TA))
case TypeTALINK:
return isDuplicateTALINK(r1.(*TALINK), r2.(*TALINK))
case TypeTKEY:
return isDuplicateTKEY(r1.(*TKEY), r2.(*TKEY))
case TypeTLSA:
return isDuplicateTLSA(r1.(*TLSA), r2.(*TLSA))
case TypeTSIG:
return isDuplicateTSIG(r1.(*TSIG), r2.(*TSIG))
case TypeTXT:
return isDuplicateTXT(r1.(*TXT), r2.(*TXT))
case TypeUID:
return isDuplicateUID(r1.(*UID), r2.(*UID))
case TypeUINFO:
return isDuplicateUINFO(r1.(*UINFO), r2.(*UINFO))
case TypeURI:
return isDuplicateURI(r1.(*URI), r2.(*URI))
case TypeX25:
return isDuplicateX25(r1.(*X25), r2.(*X25))
} }
_ = r2
if !r1.A.Equal(r2.A) {
return false return false
} }
return true
}
// isDuplicate() functions func (r1 *AAAA) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*AAAA)
func isDuplicateA(r1, r2 *A) bool { if !ok {
if len(r1.A) != len(r2.A) {
return false return false
} }
for i := 0; i < len(r1.A); i++ { _ = r2
if r1.A[i] != r2.A[i] { if !r1.AAAA.Equal(r2.AAAA) {
return false return false
} }
}
return true return true
} }
func isDuplicateAAAA(r1, r2 *AAAA) bool { func (r1 *AFSDB) isDuplicate(_r2 RR) bool {
if len(r1.AAAA) != len(r2.AAAA) { r2, ok := _r2.(*AFSDB)
if !ok {
return false return false
} }
for i := 0; i < len(r1.AAAA); i++ { _ = r2
if r1.AAAA[i] != r2.AAAA[i] { if r1.Subtype != r2.Subtype {
return false return false
} }
if !isDuplicateName(r1.Hostname, r2.Hostname) {
return false
} }
return true return true
} }
func isDuplicateAFSDB(r1, r2 *AFSDB) bool { func (r1 *ANY) isDuplicate(_r2 RR) bool {
if r1.Subtype != r2.Subtype { r2, ok := _r2.(*ANY)
if !ok {
return false return false
} }
if !isDulicateName(r1.Hostname, r2.Hostname) { _ = r2
return true
}
func (r1 *APL) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*APL)
if !ok {
return false return false
} }
_ = r2
if len(r1.Prefixes) != len(r2.Prefixes) {
return false
}
for i := 0; i < len(r1.Prefixes); i++ {
if !r1.Prefixes[i].equals(&r2.Prefixes[i]) {
return false
}
}
return true return true
} }
func isDuplicateAVC(r1, r2 *AVC) bool { func (r1 *AVC) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*AVC)
if !ok {
return false
}
_ = r2
if len(r1.Txt) != len(r2.Txt) { if len(r1.Txt) != len(r2.Txt) {
return false return false
} }
...@@ -181,7 +86,12 @@ func isDuplicateAVC(r1, r2 *AVC) bool { ...@@ -181,7 +86,12 @@ func isDuplicateAVC(r1, r2 *AVC) bool {
return true return true
} }
func isDuplicateCAA(r1, r2 *CAA) bool { func (r1 *CAA) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*CAA)
if !ok {
return false
}
_ = r2
if r1.Flag != r2.Flag { if r1.Flag != r2.Flag {
return false return false
} }
...@@ -194,7 +104,54 @@ func isDuplicateCAA(r1, r2 *CAA) bool { ...@@ -194,7 +104,54 @@ func isDuplicateCAA(r1, r2 *CAA) bool {
return true return true
} }
func isDuplicateCERT(r1, r2 *CERT) bool { func (r1 *CDNSKEY) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*CDNSKEY)
if !ok {
return false
}
_ = r2
if r1.Flags != r2.Flags {
return false
}
if r1.Protocol != r2.Protocol {
return false
}
if r1.Algorithm != r2.Algorithm {
return false
}
if r1.PublicKey != r2.PublicKey {
return false
}
return true
}
func (r1 *CDS) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*CDS)
if !ok {
return false
}
_ = r2
if r1.KeyTag != r2.KeyTag {
return false
}
if r1.Algorithm != r2.Algorithm {
return false
}
if r1.DigestType != r2.DigestType {
return false
}
if r1.Digest != r2.Digest {
return false
}
return true
}
func (r1 *CERT) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*CERT)
if !ok {
return false
}
_ = r2
if r1.Type != r2.Type { if r1.Type != r2.Type {
return false return false
} }
...@@ -210,14 +167,24 @@ func isDuplicateCERT(r1, r2 *CERT) bool { ...@@ -210,14 +167,24 @@ func isDuplicateCERT(r1, r2 *CERT) bool {
return true return true
} }
func isDuplicateCNAME(r1, r2 *CNAME) bool { func (r1 *CNAME) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Target, r2.Target) { r2, ok := _r2.(*CNAME)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Target, r2.Target) {
return false return false
} }
return true return true
} }
func isDuplicateCSYNC(r1, r2 *CSYNC) bool { func (r1 *CSYNC) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*CSYNC)
if !ok {
return false
}
_ = r2
if r1.Serial != r2.Serial { if r1.Serial != r2.Serial {
return false return false
} }
...@@ -235,21 +202,57 @@ func isDuplicateCSYNC(r1, r2 *CSYNC) bool { ...@@ -235,21 +202,57 @@ func isDuplicateCSYNC(r1, r2 *CSYNC) bool {
return true return true
} }
func isDuplicateDHCID(r1, r2 *DHCID) bool { func (r1 *DHCID) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*DHCID)
if !ok {
return false
}
_ = r2
if r1.Digest != r2.Digest { if r1.Digest != r2.Digest {
return false return false
} }
return true return true
} }
func isDuplicateDNAME(r1, r2 *DNAME) bool { func (r1 *DLV) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Target, r2.Target) { r2, ok := _r2.(*DLV)
if !ok {
return false
}
_ = r2
if r1.KeyTag != r2.KeyTag {
return false
}
if r1.Algorithm != r2.Algorithm {
return false
}
if r1.DigestType != r2.DigestType {
return false
}
if r1.Digest != r2.Digest {
return false
}
return true
}
func (r1 *DNAME) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*DNAME)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Target, r2.Target) {
return false return false
} }
return true return true
} }
func isDuplicateDNSKEY(r1, r2 *DNSKEY) bool { func (r1 *DNSKEY) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*DNSKEY)
if !ok {
return false
}
_ = r2
if r1.Flags != r2.Flags { if r1.Flags != r2.Flags {
return false return false
} }
...@@ -265,7 +268,12 @@ func isDuplicateDNSKEY(r1, r2 *DNSKEY) bool { ...@@ -265,7 +268,12 @@ func isDuplicateDNSKEY(r1, r2 *DNSKEY) bool {
return true return true
} }
func isDuplicateDS(r1, r2 *DS) bool { func (r1 *DS) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*DS)
if !ok {
return false
}
_ = r2
if r1.KeyTag != r2.KeyTag { if r1.KeyTag != r2.KeyTag {
return false return false
} }
...@@ -281,35 +289,60 @@ func isDuplicateDS(r1, r2 *DS) bool { ...@@ -281,35 +289,60 @@ func isDuplicateDS(r1, r2 *DS) bool {
return true return true
} }
func isDuplicateEID(r1, r2 *EID) bool { func (r1 *EID) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*EID)
if !ok {
return false
}
_ = r2
if r1.Endpoint != r2.Endpoint { if r1.Endpoint != r2.Endpoint {
return false return false
} }
return true return true
} }
func isDuplicateEUI48(r1, r2 *EUI48) bool { func (r1 *EUI48) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*EUI48)
if !ok {
return false
}
_ = r2
if r1.Address != r2.Address { if r1.Address != r2.Address {
return false return false
} }
return true return true
} }
func isDuplicateEUI64(r1, r2 *EUI64) bool { func (r1 *EUI64) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*EUI64)
if !ok {
return false
}
_ = r2
if r1.Address != r2.Address { if r1.Address != r2.Address {
return false return false
} }
return true return true
} }
func isDuplicateGID(r1, r2 *GID) bool { func (r1 *GID) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*GID)
if !ok {
return false
}
_ = r2
if r1.Gid != r2.Gid { if r1.Gid != r2.Gid {
return false return false
} }
return true return true
} }
func isDuplicateGPOS(r1, r2 *GPOS) bool { func (r1 *GPOS) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*GPOS)
if !ok {
return false
}
_ = r2
if r1.Longitude != r2.Longitude { if r1.Longitude != r2.Longitude {
return false return false
} }
...@@ -322,7 +355,12 @@ func isDuplicateGPOS(r1, r2 *GPOS) bool { ...@@ -322,7 +355,12 @@ func isDuplicateGPOS(r1, r2 *GPOS) bool {
return true return true
} }
func isDuplicateHINFO(r1, r2 *HINFO) bool { func (r1 *HINFO) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*HINFO)
if !ok {
return false
}
_ = r2
if r1.Cpu != r2.Cpu { if r1.Cpu != r2.Cpu {
return false return false
} }
...@@ -332,7 +370,12 @@ func isDuplicateHINFO(r1, r2 *HINFO) bool { ...@@ -332,7 +370,12 @@ func isDuplicateHINFO(r1, r2 *HINFO) bool {
return true return true
} }
func isDuplicateHIP(r1, r2 *HIP) bool { func (r1 *HIP) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*HIP)
if !ok {
return false
}
_ = r2
if r1.HitLength != r2.HitLength { if r1.HitLength != r2.HitLength {
return false return false
} }
...@@ -352,39 +395,91 @@ func isDuplicateHIP(r1, r2 *HIP) bool { ...@@ -352,39 +395,91 @@ func isDuplicateHIP(r1, r2 *HIP) bool {
return false return false
} }
for i := 0; i < len(r1.RendezvousServers); i++ { for i := 0; i < len(r1.RendezvousServers); i++ {
if !isDulicateName(r1.RendezvousServers[i], r2.RendezvousServers[i]) { if !isDuplicateName(r1.RendezvousServers[i], r2.RendezvousServers[i]) {
return false return false
} }
} }
return true return true
} }
func isDuplicateKX(r1, r2 *KX) bool { func (r1 *HTTPS) isDuplicate(_r2 RR) bool {
if r1.Preference != r2.Preference { r2, ok := _r2.(*HTTPS)
if !ok {
return false return false
} }
if !isDulicateName(r1.Exchanger, r2.Exchanger) { _ = r2
if r1.Priority != r2.Priority {
return false
}
if !isDuplicateName(r1.Target, r2.Target) {
return false
}
if len(r1.Value) != len(r2.Value) {
return false
}
if !areSVCBPairArraysEqual(r1.Value, r2.Value) {
return false return false
} }
return true return true
} }
func isDuplicateL32(r1, r2 *L32) bool { func (r1 *KEY) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*KEY)
if !ok {
return false
}
_ = r2
if r1.Flags != r2.Flags {
return false
}
if r1.Protocol != r2.Protocol {
return false
}
if r1.Algorithm != r2.Algorithm {
return false
}
if r1.PublicKey != r2.PublicKey {
return false
}
return true
}
func (r1 *KX) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*KX)
if !ok {
return false
}
_ = r2
if r1.Preference != r2.Preference { if r1.Preference != r2.Preference {
return false return false
} }
if len(r1.Locator32) != len(r2.Locator32) { if !isDuplicateName(r1.Exchanger, r2.Exchanger) {
return false return false
} }
for i := 0; i < len(r1.Locator32); i++ { return true
if r1.Locator32[i] != r2.Locator32[i] { }
func (r1 *L32) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*L32)
if !ok {
return false return false
} }
_ = r2
if r1.Preference != r2.Preference {
return false
}
if !r1.Locator32.Equal(r2.Locator32) {
return false
} }
return true return true
} }
func isDuplicateL64(r1, r2 *L64) bool { func (r1 *L64) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*L64)
if !ok {
return false
}
_ = r2
if r1.Preference != r2.Preference { if r1.Preference != r2.Preference {
return false return false
} }
...@@ -394,7 +489,12 @@ func isDuplicateL64(r1, r2 *L64) bool { ...@@ -394,7 +489,12 @@ func isDuplicateL64(r1, r2 *L64) bool {
return true return true
} }
func isDuplicateLOC(r1, r2 *LOC) bool { func (r1 *LOC) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*LOC)
if !ok {
return false
}
_ = r2
if r1.Version != r2.Version { if r1.Version != r2.Version {
return false return false
} }
...@@ -419,72 +519,117 @@ func isDuplicateLOC(r1, r2 *LOC) bool { ...@@ -419,72 +519,117 @@ func isDuplicateLOC(r1, r2 *LOC) bool {
return true return true
} }
func isDuplicateLP(r1, r2 *LP) bool { func (r1 *LP) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*LP)
if !ok {
return false
}
_ = r2
if r1.Preference != r2.Preference { if r1.Preference != r2.Preference {
return false return false
} }
if !isDulicateName(r1.Fqdn, r2.Fqdn) { if !isDuplicateName(r1.Fqdn, r2.Fqdn) {
return false return false
} }
return true return true
} }
func isDuplicateMB(r1, r2 *MB) bool { func (r1 *MB) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Mb, r2.Mb) { r2, ok := _r2.(*MB)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Mb, r2.Mb) {
return false return false
} }
return true return true
} }
func isDuplicateMD(r1, r2 *MD) bool { func (r1 *MD) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Md, r2.Md) { r2, ok := _r2.(*MD)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Md, r2.Md) {
return false return false
} }
return true return true
} }
func isDuplicateMF(r1, r2 *MF) bool { func (r1 *MF) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Mf, r2.Mf) { r2, ok := _r2.(*MF)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Mf, r2.Mf) {
return false return false
} }
return true return true
} }
func isDuplicateMG(r1, r2 *MG) bool { func (r1 *MG) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Mg, r2.Mg) { r2, ok := _r2.(*MG)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Mg, r2.Mg) {
return false return false
} }
return true return true
} }
func isDuplicateMINFO(r1, r2 *MINFO) bool { func (r1 *MINFO) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Rmail, r2.Rmail) { r2, ok := _r2.(*MINFO)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Rmail, r2.Rmail) {
return false return false
} }
if !isDulicateName(r1.Email, r2.Email) { if !isDuplicateName(r1.Email, r2.Email) {
return false return false
} }
return true return true
} }
func isDuplicateMR(r1, r2 *MR) bool { func (r1 *MR) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Mr, r2.Mr) { r2, ok := _r2.(*MR)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Mr, r2.Mr) {
return false return false
} }
return true return true
} }
func isDuplicateMX(r1, r2 *MX) bool { func (r1 *MX) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*MX)
if !ok {
return false
}
_ = r2
if r1.Preference != r2.Preference { if r1.Preference != r2.Preference {
return false return false
} }
if !isDulicateName(r1.Mx, r2.Mx) { if !isDuplicateName(r1.Mx, r2.Mx) {
return false return false
} }
return true return true
} }
func isDuplicateNAPTR(r1, r2 *NAPTR) bool { func (r1 *NAPTR) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*NAPTR)
if !ok {
return false
}
_ = r2
if r1.Order != r2.Order { if r1.Order != r2.Order {
return false return false
} }
...@@ -500,13 +645,18 @@ func isDuplicateNAPTR(r1, r2 *NAPTR) bool { ...@@ -500,13 +645,18 @@ func isDuplicateNAPTR(r1, r2 *NAPTR) bool {
if r1.Regexp != r2.Regexp { if r1.Regexp != r2.Regexp {
return false return false
} }
if !isDulicateName(r1.Replacement, r2.Replacement) { if !isDuplicateName(r1.Replacement, r2.Replacement) {
return false return false
} }
return true return true
} }
func isDuplicateNID(r1, r2 *NID) bool { func (r1 *NID) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*NID)
if !ok {
return false
}
_ = r2
if r1.Preference != r2.Preference { if r1.Preference != r2.Preference {
return false return false
} }
...@@ -516,14 +666,24 @@ func isDuplicateNID(r1, r2 *NID) bool { ...@@ -516,14 +666,24 @@ func isDuplicateNID(r1, r2 *NID) bool {
return true return true
} }
func isDuplicateNIMLOC(r1, r2 *NIMLOC) bool { func (r1 *NIMLOC) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*NIMLOC)
if !ok {
return false
}
_ = r2
if r1.Locator != r2.Locator { if r1.Locator != r2.Locator {
return false return false
} }
return true return true
} }
func isDuplicateNINFO(r1, r2 *NINFO) bool { func (r1 *NINFO) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*NINFO)
if !ok {
return false
}
_ = r2
if len(r1.ZSData) != len(r2.ZSData) { if len(r1.ZSData) != len(r2.ZSData) {
return false return false
} }
...@@ -535,22 +695,37 @@ func isDuplicateNINFO(r1, r2 *NINFO) bool { ...@@ -535,22 +695,37 @@ func isDuplicateNINFO(r1, r2 *NINFO) bool {
return true return true
} }
func isDuplicateNS(r1, r2 *NS) bool { func (r1 *NS) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Ns, r2.Ns) { r2, ok := _r2.(*NS)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Ns, r2.Ns) {
return false return false
} }
return true return true
} }
func isDuplicateNSAPPTR(r1, r2 *NSAPPTR) bool { func (r1 *NSAPPTR) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Ptr, r2.Ptr) { r2, ok := _r2.(*NSAPPTR)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Ptr, r2.Ptr) {
return false return false
} }
return true return true
} }
func isDuplicateNSEC(r1, r2 *NSEC) bool { func (r1 *NSEC) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.NextDomain, r2.NextDomain) { r2, ok := _r2.(*NSEC)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.NextDomain, r2.NextDomain) {
return false return false
} }
if len(r1.TypeBitMap) != len(r2.TypeBitMap) { if len(r1.TypeBitMap) != len(r2.TypeBitMap) {
...@@ -564,7 +739,12 @@ func isDuplicateNSEC(r1, r2 *NSEC) bool { ...@@ -564,7 +739,12 @@ func isDuplicateNSEC(r1, r2 *NSEC) bool {
return true return true
} }
func isDuplicateNSEC3(r1, r2 *NSEC3) bool { func (r1 *NSEC3) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*NSEC3)
if !ok {
return false
}
_ = r2
if r1.Hash != r2.Hash { if r1.Hash != r2.Hash {
return false return false
} }
...@@ -597,7 +777,12 @@ func isDuplicateNSEC3(r1, r2 *NSEC3) bool { ...@@ -597,7 +777,12 @@ func isDuplicateNSEC3(r1, r2 *NSEC3) bool {
return true return true
} }
func isDuplicateNSEC3PARAM(r1, r2 *NSEC3PARAM) bool { func (r1 *NSEC3PARAM) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*NSEC3PARAM)
if !ok {
return false
}
_ = r2
if r1.Hash != r2.Hash { if r1.Hash != r2.Hash {
return false return false
} }
...@@ -616,34 +801,78 @@ func isDuplicateNSEC3PARAM(r1, r2 *NSEC3PARAM) bool { ...@@ -616,34 +801,78 @@ func isDuplicateNSEC3PARAM(r1, r2 *NSEC3PARAM) bool {
return true return true
} }
func isDuplicateOPENPGPKEY(r1, r2 *OPENPGPKEY) bool { func (r1 *NULL) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*NULL)
if !ok {
return false
}
_ = r2
if r1.Data != r2.Data {
return false
}
return true
}
func (r1 *OPENPGPKEY) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*OPENPGPKEY)
if !ok {
return false
}
_ = r2
if r1.PublicKey != r2.PublicKey { if r1.PublicKey != r2.PublicKey {
return false return false
} }
return true return true
} }
func isDuplicatePTR(r1, r2 *PTR) bool { func (r1 *PTR) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Ptr, r2.Ptr) { r2, ok := _r2.(*PTR)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Ptr, r2.Ptr) {
return false return false
} }
return true return true
} }
func isDuplicatePX(r1, r2 *PX) bool { func (r1 *PX) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*PX)
if !ok {
return false
}
_ = r2
if r1.Preference != r2.Preference { if r1.Preference != r2.Preference {
return false return false
} }
if !isDulicateName(r1.Map822, r2.Map822) { if !isDuplicateName(r1.Map822, r2.Map822) {
return false
}
if !isDuplicateName(r1.Mapx400, r2.Mapx400) {
return false
}
return true
}
func (r1 *RFC3597) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*RFC3597)
if !ok {
return false return false
} }
if !isDulicateName(r1.Mapx400, r2.Mapx400) { _ = r2
if r1.Rdata != r2.Rdata {
return false return false
} }
return true return true
} }
func isDuplicateRKEY(r1, r2 *RKEY) bool { func (r1 *RKEY) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*RKEY)
if !ok {
return false
}
_ = r2
if r1.Flags != r2.Flags { if r1.Flags != r2.Flags {
return false return false
} }
...@@ -659,17 +888,27 @@ func isDuplicateRKEY(r1, r2 *RKEY) bool { ...@@ -659,17 +888,27 @@ func isDuplicateRKEY(r1, r2 *RKEY) bool {
return true return true
} }
func isDuplicateRP(r1, r2 *RP) bool { func (r1 *RP) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Mbox, r2.Mbox) { r2, ok := _r2.(*RP)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Mbox, r2.Mbox) {
return false return false
} }
if !isDulicateName(r1.Txt, r2.Txt) { if !isDuplicateName(r1.Txt, r2.Txt) {
return false return false
} }
return true return true
} }
func isDuplicateRRSIG(r1, r2 *RRSIG) bool { func (r1 *RRSIG) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*RRSIG)
if !ok {
return false
}
_ = r2
if r1.TypeCovered != r2.TypeCovered { if r1.TypeCovered != r2.TypeCovered {
return false return false
} }
...@@ -691,7 +930,7 @@ func isDuplicateRRSIG(r1, r2 *RRSIG) bool { ...@@ -691,7 +930,7 @@ func isDuplicateRRSIG(r1, r2 *RRSIG) bool {
if r1.KeyTag != r2.KeyTag { if r1.KeyTag != r2.KeyTag {
return false return false
} }
if !isDulicateName(r1.SignerName, r2.SignerName) { if !isDuplicateName(r1.SignerName, r2.SignerName) {
return false return false
} }
if r1.Signature != r2.Signature { if r1.Signature != r2.Signature {
...@@ -700,17 +939,63 @@ func isDuplicateRRSIG(r1, r2 *RRSIG) bool { ...@@ -700,17 +939,63 @@ func isDuplicateRRSIG(r1, r2 *RRSIG) bool {
return true return true
} }
func isDuplicateRT(r1, r2 *RT) bool { func (r1 *RT) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*RT)
if !ok {
return false
}
_ = r2
if r1.Preference != r2.Preference { if r1.Preference != r2.Preference {
return false return false
} }
if !isDulicateName(r1.Host, r2.Host) { if !isDuplicateName(r1.Host, r2.Host) {
return false
}
return true
}
func (r1 *SIG) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*SIG)
if !ok {
return false
}
_ = r2
if r1.TypeCovered != r2.TypeCovered {
return false
}
if r1.Algorithm != r2.Algorithm {
return false
}
if r1.Labels != r2.Labels {
return false
}
if r1.OrigTtl != r2.OrigTtl {
return false
}
if r1.Expiration != r2.Expiration {
return false
}
if r1.Inception != r2.Inception {
return false
}
if r1.KeyTag != r2.KeyTag {
return false
}
if !isDuplicateName(r1.SignerName, r2.SignerName) {
return false
}
if r1.Signature != r2.Signature {
return false return false
} }
return true return true
} }
func isDuplicateSMIMEA(r1, r2 *SMIMEA) bool { func (r1 *SMIMEA) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*SMIMEA)
if !ok {
return false
}
_ = r2
if r1.Usage != r2.Usage { if r1.Usage != r2.Usage {
return false return false
} }
...@@ -726,11 +1011,16 @@ func isDuplicateSMIMEA(r1, r2 *SMIMEA) bool { ...@@ -726,11 +1011,16 @@ func isDuplicateSMIMEA(r1, r2 *SMIMEA) bool {
return true return true
} }
func isDuplicateSOA(r1, r2 *SOA) bool { func (r1 *SOA) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Ns, r2.Ns) { r2, ok := _r2.(*SOA)
if !ok {
return false return false
} }
if !isDulicateName(r1.Mbox, r2.Mbox) { _ = r2
if !isDuplicateName(r1.Ns, r2.Ns) {
return false
}
if !isDuplicateName(r1.Mbox, r2.Mbox) {
return false return false
} }
if r1.Serial != r2.Serial { if r1.Serial != r2.Serial {
...@@ -751,7 +1041,12 @@ func isDuplicateSOA(r1, r2 *SOA) bool { ...@@ -751,7 +1041,12 @@ func isDuplicateSOA(r1, r2 *SOA) bool {
return true return true
} }
func isDuplicateSPF(r1, r2 *SPF) bool { func (r1 *SPF) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*SPF)
if !ok {
return false
}
_ = r2
if len(r1.Txt) != len(r2.Txt) { if len(r1.Txt) != len(r2.Txt) {
return false return false
} }
...@@ -763,7 +1058,12 @@ func isDuplicateSPF(r1, r2 *SPF) bool { ...@@ -763,7 +1058,12 @@ func isDuplicateSPF(r1, r2 *SPF) bool {
return true return true
} }
func isDuplicateSRV(r1, r2 *SRV) bool { func (r1 *SRV) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*SRV)
if !ok {
return false
}
_ = r2
if r1.Priority != r2.Priority { if r1.Priority != r2.Priority {
return false return false
} }
...@@ -773,13 +1073,18 @@ func isDuplicateSRV(r1, r2 *SRV) bool { ...@@ -773,13 +1073,18 @@ func isDuplicateSRV(r1, r2 *SRV) bool {
if r1.Port != r2.Port { if r1.Port != r2.Port {
return false return false
} }
if !isDulicateName(r1.Target, r2.Target) { if !isDuplicateName(r1.Target, r2.Target) {
return false return false
} }
return true return true
} }
func isDuplicateSSHFP(r1, r2 *SSHFP) bool { func (r1 *SSHFP) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*SSHFP)
if !ok {
return false
}
_ = r2
if r1.Algorithm != r2.Algorithm { if r1.Algorithm != r2.Algorithm {
return false return false
} }
...@@ -792,7 +1097,33 @@ func isDuplicateSSHFP(r1, r2 *SSHFP) bool { ...@@ -792,7 +1097,33 @@ func isDuplicateSSHFP(r1, r2 *SSHFP) bool {
return true return true
} }
func isDuplicateTA(r1, r2 *TA) bool { func (r1 *SVCB) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*SVCB)
if !ok {
return false
}
_ = r2
if r1.Priority != r2.Priority {
return false
}
if !isDuplicateName(r1.Target, r2.Target) {
return false
}
if len(r1.Value) != len(r2.Value) {
return false
}
if !areSVCBPairArraysEqual(r1.Value, r2.Value) {
return false
}
return true
}
func (r1 *TA) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*TA)
if !ok {
return false
}
_ = r2
if r1.KeyTag != r2.KeyTag { if r1.KeyTag != r2.KeyTag {
return false return false
} }
...@@ -808,18 +1139,28 @@ func isDuplicateTA(r1, r2 *TA) bool { ...@@ -808,18 +1139,28 @@ func isDuplicateTA(r1, r2 *TA) bool {
return true return true
} }
func isDuplicateTALINK(r1, r2 *TALINK) bool { func (r1 *TALINK) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.PreviousName, r2.PreviousName) { r2, ok := _r2.(*TALINK)
if !ok {
return false return false
} }
if !isDulicateName(r1.NextName, r2.NextName) { _ = r2
if !isDuplicateName(r1.PreviousName, r2.PreviousName) {
return false
}
if !isDuplicateName(r1.NextName, r2.NextName) {
return false return false
} }
return true return true
} }
func isDuplicateTKEY(r1, r2 *TKEY) bool { func (r1 *TKEY) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Algorithm, r2.Algorithm) { r2, ok := _r2.(*TKEY)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Algorithm, r2.Algorithm) {
return false return false
} }
if r1.Inception != r2.Inception { if r1.Inception != r2.Inception {
...@@ -849,7 +1190,12 @@ func isDuplicateTKEY(r1, r2 *TKEY) bool { ...@@ -849,7 +1190,12 @@ func isDuplicateTKEY(r1, r2 *TKEY) bool {
return true return true
} }
func isDuplicateTLSA(r1, r2 *TLSA) bool { func (r1 *TLSA) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*TLSA)
if !ok {
return false
}
_ = r2
if r1.Usage != r2.Usage { if r1.Usage != r2.Usage {
return false return false
} }
...@@ -865,8 +1211,13 @@ func isDuplicateTLSA(r1, r2 *TLSA) bool { ...@@ -865,8 +1211,13 @@ func isDuplicateTLSA(r1, r2 *TLSA) bool {
return true return true
} }
func isDuplicateTSIG(r1, r2 *TSIG) bool { func (r1 *TSIG) isDuplicate(_r2 RR) bool {
if !isDulicateName(r1.Algorithm, r2.Algorithm) { r2, ok := _r2.(*TSIG)
if !ok {
return false
}
_ = r2
if !isDuplicateName(r1.Algorithm, r2.Algorithm) {
return false return false
} }
if r1.TimeSigned != r2.TimeSigned { if r1.TimeSigned != r2.TimeSigned {
...@@ -896,7 +1247,12 @@ func isDuplicateTSIG(r1, r2 *TSIG) bool { ...@@ -896,7 +1247,12 @@ func isDuplicateTSIG(r1, r2 *TSIG) bool {
return true return true
} }
func isDuplicateTXT(r1, r2 *TXT) bool { func (r1 *TXT) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*TXT)
if !ok {
return false
}
_ = r2
if len(r1.Txt) != len(r2.Txt) { if len(r1.Txt) != len(r2.Txt) {
return false return false
} }
...@@ -908,21 +1264,36 @@ func isDuplicateTXT(r1, r2 *TXT) bool { ...@@ -908,21 +1264,36 @@ func isDuplicateTXT(r1, r2 *TXT) bool {
return true return true
} }
func isDuplicateUID(r1, r2 *UID) bool { func (r1 *UID) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*UID)
if !ok {
return false
}
_ = r2
if r1.Uid != r2.Uid { if r1.Uid != r2.Uid {
return false return false
} }
return true return true
} }
func isDuplicateUINFO(r1, r2 *UINFO) bool { func (r1 *UINFO) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*UINFO)
if !ok {
return false
}
_ = r2
if r1.Uinfo != r2.Uinfo { if r1.Uinfo != r2.Uinfo {
return false return false
} }
return true return true
} }
func isDuplicateURI(r1, r2 *URI) bool { func (r1 *URI) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*URI)
if !ok {
return false
}
_ = r2
if r1.Priority != r2.Priority { if r1.Priority != r2.Priority {
return false return false
} }
...@@ -935,9 +1306,35 @@ func isDuplicateURI(r1, r2 *URI) bool { ...@@ -935,9 +1306,35 @@ func isDuplicateURI(r1, r2 *URI) bool {
return true return true
} }
func isDuplicateX25(r1, r2 *X25) bool { func (r1 *X25) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*X25)
if !ok {
return false
}
_ = r2
if r1.PSDNAddress != r2.PSDNAddress { if r1.PSDNAddress != r2.PSDNAddress {
return false return false
} }
return true return true
} }
func (r1 *ZONEMD) isDuplicate(_r2 RR) bool {
r2, ok := _r2.(*ZONEMD)
if !ok {
return false
}
_ = r2
if r1.Serial != r2.Serial {
return false
}
if r1.Scheme != r2.Scheme {
return false
}
if r1.Hash != r2.Hash {
return false
}
if r1.Digest != r2.Digest {
return false
}
return true
}
...@@ -4,82 +4,55 @@ package dns ...@@ -4,82 +4,55 @@ package dns
// pack*() functions // pack*() functions
func (rr *A) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *A) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packDataA(rr.A, msg, off) off, err = packDataA(rr.A, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *AAAA) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *AAAA) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packDataAAAA(rr.AAAA, msg, off) off, err = packDataAAAA(rr.AAAA, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *AFSDB) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *AFSDB) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Subtype, msg, off) off, err = packUint16(rr.Subtype, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Hostname, msg, off, compression, false) off, err = packDomainName(rr.Hostname, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *ANY) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *ANY) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *AVC) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *APL) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDataApl(rr.Prefixes, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
headerEnd := off return off, nil
}
func (rr *AVC) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err = packStringTxt(rr.Txt, msg, off) off, err = packStringTxt(rr.Txt, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *CAA) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *CAA) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint8(rr.Flag, msg, off) off, err = packUint8(rr.Flag, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -92,16 +65,10 @@ func (rr *CAA) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -92,16 +65,10 @@ func (rr *CAA) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *CDNSKEY) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *CDNSKEY) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Flags, msg, off) off, err = packUint16(rr.Flags, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -118,16 +85,10 @@ func (rr *CDNSKEY) pack(msg []byte, off int, compression map[string]int, compres ...@@ -118,16 +85,10 @@ func (rr *CDNSKEY) pack(msg []byte, off int, compression map[string]int, compres
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *CDS) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *CDS) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.KeyTag, msg, off) off, err = packUint16(rr.KeyTag, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -144,16 +105,10 @@ func (rr *CDS) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -144,16 +105,10 @@ func (rr *CDS) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *CERT) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *CERT) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Type, msg, off) off, err = packUint16(rr.Type, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -170,30 +125,18 @@ func (rr *CERT) pack(msg []byte, off int, compression map[string]int, compress b ...@@ -170,30 +125,18 @@ func (rr *CERT) pack(msg []byte, off int, compression map[string]int, compress b
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *CNAME) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *CNAME) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Target, msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Target, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *CSYNC) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *CSYNC) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint32(rr.Serial, msg, off) off, err = packUint32(rr.Serial, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -206,30 +149,18 @@ func (rr *CSYNC) pack(msg []byte, off int, compression map[string]int, compress ...@@ -206,30 +149,18 @@ func (rr *CSYNC) pack(msg []byte, off int, compression map[string]int, compress
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *DHCID) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *DHCID) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packStringBase64(rr.Digest, msg, off) off, err = packStringBase64(rr.Digest, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *DLV) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *DLV) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.KeyTag, msg, off) off, err = packUint16(rr.KeyTag, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -246,30 +177,18 @@ func (rr *DLV) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -246,30 +177,18 @@ func (rr *DLV) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *DNAME) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *DNAME) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Target, msg, off, compression, false)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Target, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *DNSKEY) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *DNSKEY) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Flags, msg, off) off, err = packUint16(rr.Flags, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -286,16 +205,10 @@ func (rr *DNSKEY) pack(msg []byte, off int, compression map[string]int, compress ...@@ -286,16 +205,10 @@ func (rr *DNSKEY) pack(msg []byte, off int, compression map[string]int, compress
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *DS) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *DS) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.KeyTag, msg, off) off, err = packUint16(rr.KeyTag, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -312,72 +225,42 @@ func (rr *DS) pack(msg []byte, off int, compression map[string]int, compress boo ...@@ -312,72 +225,42 @@ func (rr *DS) pack(msg []byte, off int, compression map[string]int, compress boo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *EID) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *EID) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packStringHex(rr.Endpoint, msg, off) off, err = packStringHex(rr.Endpoint, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *EUI48) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *EUI48) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint48(rr.Address, msg, off) off, err = packUint48(rr.Address, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *EUI64) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *EUI64) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint64(rr.Address, msg, off) off, err = packUint64(rr.Address, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *GID) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *GID) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint32(rr.Gid, msg, off) off, err = packUint32(rr.Gid, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *GPOS) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *GPOS) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packString(rr.Longitude, msg, off) off, err = packString(rr.Longitude, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -390,16 +273,10 @@ func (rr *GPOS) pack(msg []byte, off int, compression map[string]int, compress b ...@@ -390,16 +273,10 @@ func (rr *GPOS) pack(msg []byte, off int, compression map[string]int, compress b
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *HINFO) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *HINFO) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packString(rr.Cpu, msg, off) off, err = packString(rr.Cpu, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -408,16 +285,10 @@ func (rr *HINFO) pack(msg []byte, off int, compression map[string]int, compress ...@@ -408,16 +285,10 @@ func (rr *HINFO) pack(msg []byte, off int, compression map[string]int, compress
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *HIP) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *HIP) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint8(rr.HitLength, msg, off) off, err = packUint8(rr.HitLength, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -438,20 +309,30 @@ func (rr *HIP) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -438,20 +309,30 @@ func (rr *HIP) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = packDataDomainNames(rr.RendezvousServers, msg, off, compression, compress) off, err = packDataDomainNames(rr.RendezvousServers, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *KEY) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *HTTPS) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packUint16(rr.Priority, msg, off)
if err != nil {
return off, err
}
off, err = packDomainName(rr.Target, msg, off, compression, false)
if err != nil {
return off, err
}
off, err = packDataSVCB(rr.Value, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
headerEnd := off return off, nil
}
func (rr *KEY) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err = packUint16(rr.Flags, msg, off) off, err = packUint16(rr.Flags, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -468,34 +349,22 @@ func (rr *KEY) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -468,34 +349,22 @@ func (rr *KEY) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *KX) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *KX) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Preference, msg, off) off, err = packUint16(rr.Preference, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Exchanger, msg, off, compression, false) off, err = packDomainName(rr.Exchanger, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *L32) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *L32) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Preference, msg, off) off, err = packUint16(rr.Preference, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -504,16 +373,10 @@ func (rr *L32) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -504,16 +373,10 @@ func (rr *L32) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *L64) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *L64) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Preference, msg, off) off, err = packUint16(rr.Preference, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -522,16 +385,10 @@ func (rr *L64) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -522,16 +385,10 @@ func (rr *L64) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *LOC) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *LOC) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint8(rr.Version, msg, off) off, err = packUint8(rr.Version, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -560,140 +417,86 @@ func (rr *LOC) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -560,140 +417,86 @@ func (rr *LOC) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *LP) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *LP) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Preference, msg, off) off, err = packUint16(rr.Preference, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Fqdn, msg, off, compression, false) off, err = packDomainName(rr.Fqdn, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *MB) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *MB) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Mb, msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Mb, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *MD) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *MD) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Md, msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Md, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *MF) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *MF) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Mf, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
headerEnd := off
off, err = PackDomainName(rr.Mf, msg, off, compression, compress)
if err != nil {
return off, err
}
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *MG) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *MG) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Mg, msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Mg, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *MINFO) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *MINFO) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Rmail, msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Rmail, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Email, msg, off, compression, compress) off, err = packDomainName(rr.Email, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *MR) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *MR) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Mr, msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Mr, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *MX) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *MX) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Preference, msg, off) off, err = packUint16(rr.Preference, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Mx, msg, off, compression, compress) off, err = packDomainName(rr.Mx, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *NAPTR) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *NAPTR) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Order, msg, off) off, err = packUint16(rr.Order, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -714,20 +517,14 @@ func (rr *NAPTR) pack(msg []byte, off int, compression map[string]int, compress ...@@ -714,20 +517,14 @@ func (rr *NAPTR) pack(msg []byte, off int, compression map[string]int, compress
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Replacement, msg, off, compression, false) off, err = packDomainName(rr.Replacement, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *NID) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *NID) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Preference, msg, off) off, err = packUint16(rr.Preference, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -736,73 +533,43 @@ func (rr *NID) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -736,73 +533,43 @@ func (rr *NID) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *NIMLOC) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *NIMLOC) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packStringHex(rr.Locator, msg, off) off, err = packStringHex(rr.Locator, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *NINFO) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *NINFO) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packStringTxt(rr.ZSData, msg, off) off, err = packStringTxt(rr.ZSData, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *NS) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *NS) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Ns, msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Ns, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *NSAPPTR) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *NSAPPTR) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Ptr, msg, off, compression, false)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Ptr, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *NSEC) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *NSEC) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.NextDomain, msg, off, compression, false)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.NextDomain, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
...@@ -810,16 +577,10 @@ func (rr *NSEC) pack(msg []byte, off int, compression map[string]int, compress b ...@@ -810,16 +577,10 @@ func (rr *NSEC) pack(msg []byte, off int, compression map[string]int, compress b
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *NSEC3) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *NSEC3) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint8(rr.Hash, msg, off) off, err = packUint8(rr.Hash, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -855,16 +616,10 @@ func (rr *NSEC3) pack(msg []byte, off int, compression map[string]int, compress ...@@ -855,16 +616,10 @@ func (rr *NSEC3) pack(msg []byte, off int, compression map[string]int, compress
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *NSEC3PARAM) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *NSEC3PARAM) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint8(rr.Hash, msg, off) off, err = packUint8(rr.Hash, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -888,94 +643,66 @@ func (rr *NSEC3PARAM) pack(msg []byte, off int, compression map[string]int, comp ...@@ -888,94 +643,66 @@ func (rr *NSEC3PARAM) pack(msg []byte, off int, compression map[string]int, comp
return off, err return off, err
} }
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *OPENPGPKEY) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *NULL) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packStringAny(rr.Data, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
headerEnd := off return off, nil
}
func (rr *OPENPGPKEY) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err = packStringBase64(rr.PublicKey, msg, off) off, err = packStringBase64(rr.PublicKey, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *OPT) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *OPT) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packDataOpt(rr.Option, msg, off) off, err = packDataOpt(rr.Option, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *PTR) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *PTR) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Ptr, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
headerEnd := off
off, err = PackDomainName(rr.Ptr, msg, off, compression, compress)
if err != nil {
return off, err
}
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *PX) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *PX) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Preference, msg, off) off, err = packUint16(rr.Preference, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Map822, msg, off, compression, false) off, err = packDomainName(rr.Map822, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Mapx400, msg, off, compression, false) off, err = packDomainName(rr.Mapx400, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *RFC3597) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *RFC3597) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packStringHex(rr.Rdata, msg, off) off, err = packStringHex(rr.Rdata, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *RKEY) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *RKEY) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Flags, msg, off) off, err = packUint16(rr.Flags, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -992,34 +719,22 @@ func (rr *RKEY) pack(msg []byte, off int, compression map[string]int, compress b ...@@ -992,34 +719,22 @@ func (rr *RKEY) pack(msg []byte, off int, compression map[string]int, compress b
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *RP) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *RP) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Mbox, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
headerEnd := off off, err = packDomainName(rr.Txt, msg, off, compression, false)
off, err = PackDomainName(rr.Mbox, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Txt, msg, off, compression, false)
if err != nil {
return off, err
}
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *RRSIG) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *RRSIG) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.TypeCovered, msg, off) off, err = packUint16(rr.TypeCovered, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -1048,7 +763,7 @@ func (rr *RRSIG) pack(msg []byte, off int, compression map[string]int, compress ...@@ -1048,7 +763,7 @@ func (rr *RRSIG) pack(msg []byte, off int, compression map[string]int, compress
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.SignerName, msg, off, compression, false) off, err = packDomainName(rr.SignerName, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
...@@ -1056,34 +771,22 @@ func (rr *RRSIG) pack(msg []byte, off int, compression map[string]int, compress ...@@ -1056,34 +771,22 @@ func (rr *RRSIG) pack(msg []byte, off int, compression map[string]int, compress
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *RT) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *RT) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Preference, msg, off) off, err = packUint16(rr.Preference, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Host, msg, off, compression, compress) off, err = packDomainName(rr.Host, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *SIG) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *SIG) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.TypeCovered, msg, off) off, err = packUint16(rr.TypeCovered, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -1112,7 +815,7 @@ func (rr *SIG) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -1112,7 +815,7 @@ func (rr *SIG) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.SignerName, msg, off, compression, false) off, err = packDomainName(rr.SignerName, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
...@@ -1120,16 +823,10 @@ func (rr *SIG) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -1120,16 +823,10 @@ func (rr *SIG) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *SMIMEA) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *SMIMEA) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint8(rr.Usage, msg, off) off, err = packUint8(rr.Usage, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -1146,21 +843,15 @@ func (rr *SMIMEA) pack(msg []byte, off int, compression map[string]int, compress ...@@ -1146,21 +843,15 @@ func (rr *SMIMEA) pack(msg []byte, off int, compression map[string]int, compress
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *SOA) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *SOA) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Ns, msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Ns, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Mbox, msg, off, compression, compress) off, err = packDomainName(rr.Mbox, msg, off, compression, compress)
if err != nil { if err != nil {
return off, err return off, err
} }
...@@ -1184,30 +875,18 @@ func (rr *SOA) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -1184,30 +875,18 @@ func (rr *SOA) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *SPF) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *SPF) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packStringTxt(rr.Txt, msg, off) off, err = packStringTxt(rr.Txt, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *SRV) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *SRV) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Priority, msg, off) off, err = packUint16(rr.Priority, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -1220,20 +899,14 @@ func (rr *SRV) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -1220,20 +899,14 @@ func (rr *SRV) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.Target, msg, off, compression, false) off, err = packDomainName(rr.Target, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *SSHFP) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *SSHFP) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint8(rr.Algorithm, msg, off) off, err = packUint8(rr.Algorithm, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -1246,16 +919,26 @@ func (rr *SSHFP) pack(msg []byte, off int, compression map[string]int, compress ...@@ -1246,16 +919,26 @@ func (rr *SSHFP) pack(msg []byte, off int, compression map[string]int, compress
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *TA) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *SVCB) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packUint16(rr.Priority, msg, off)
if err != nil {
return off, err
}
off, err = packDomainName(rr.Target, msg, off, compression, false)
if err != nil {
return off, err
}
off, err = packDataSVCB(rr.Value, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
headerEnd := off return off, nil
}
func (rr *TA) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err = packUint16(rr.KeyTag, msg, off) off, err = packUint16(rr.KeyTag, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -1272,35 +955,23 @@ func (rr *TA) pack(msg []byte, off int, compression map[string]int, compress boo ...@@ -1272,35 +955,23 @@ func (rr *TA) pack(msg []byte, off int, compression map[string]int, compress boo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *TALINK) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *TALINK) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.PreviousName, msg, off, compression, false)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.PreviousName, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
off, err = PackDomainName(rr.NextName, msg, off, compression, false) off, err = packDomainName(rr.NextName, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *TKEY) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *TKEY) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Algorithm, msg, off, compression, false)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Algorithm, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
...@@ -1336,16 +1007,10 @@ func (rr *TKEY) pack(msg []byte, off int, compression map[string]int, compress b ...@@ -1336,16 +1007,10 @@ func (rr *TKEY) pack(msg []byte, off int, compression map[string]int, compress b
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *TLSA) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *TLSA) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint8(rr.Usage, msg, off) off, err = packUint8(rr.Usage, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -1362,17 +1027,11 @@ func (rr *TLSA) pack(msg []byte, off int, compression map[string]int, compress b ...@@ -1362,17 +1027,11 @@ func (rr *TLSA) pack(msg []byte, off int, compression map[string]int, compress b
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *TSIG) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *TSIG) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packDomainName(rr.Algorithm, msg, off, compression, false)
if err != nil {
return off, err
}
headerEnd := off
off, err = PackDomainName(rr.Algorithm, msg, off, compression, false)
if err != nil { if err != nil {
return off, err return off, err
} }
...@@ -1408,58 +1067,34 @@ func (rr *TSIG) pack(msg []byte, off int, compression map[string]int, compress b ...@@ -1408,58 +1067,34 @@ func (rr *TSIG) pack(msg []byte, off int, compression map[string]int, compress b
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *TXT) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *TXT) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packStringTxt(rr.Txt, msg, off) off, err = packStringTxt(rr.Txt, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *UID) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *UID) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint32(rr.Uid, msg, off) off, err = packUint32(rr.Uid, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *UINFO) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *UINFO) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packString(rr.Uinfo, msg, off) off, err = packString(rr.Uinfo, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *URI) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *URI) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
off, err = packUint16(rr.Priority, msg, off) off, err = packUint16(rr.Priority, msg, off)
if err != nil { if err != nil {
return off, err return off, err
...@@ -1472,2144 +1107,1769 @@ func (rr *URI) pack(msg []byte, off int, compression map[string]int, compress bo ...@@ -1472,2144 +1107,1769 @@ func (rr *URI) pack(msg []byte, off int, compression map[string]int, compress bo
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
func (rr *X25) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) { func (rr *X25) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err := rr.Hdr.pack(msg, off, compression, compress) off, err = packString(rr.PSDNAddress, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
headerEnd := off return off, nil
off, err = packString(rr.PSDNAddress, msg, off) }
func (rr *ZONEMD) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
off, err = packUint32(rr.Serial, msg, off)
if err != nil {
return off, err
}
off, err = packUint8(rr.Scheme, msg, off)
if err != nil {
return off, err
}
off, err = packUint8(rr.Hash, msg, off)
if err != nil {
return off, err
}
off, err = packStringHex(rr.Digest, msg, off)
if err != nil { if err != nil {
return off, err return off, err
} }
rr.Header().Rdlength = uint16(off - headerEnd)
return off, nil return off, nil
} }
// unpack*() functions // unpack*() functions
func unpackA(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *A) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(A)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.A, off, err = unpackDataA(msg, off) rr.A, off, err = unpackDataA(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackAAAA(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *AAAA) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(AAAA)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.AAAA, off, err = unpackDataAAAA(msg, off) rr.AAAA, off, err = unpackDataAAAA(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackAFSDB(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *AFSDB) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(AFSDB)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Subtype, off, err = unpackUint16(msg, off) rr.Subtype, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Hostname, off, err = UnpackDomainName(msg, off) rr.Hostname, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackANY(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *ANY) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(ANY)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
return rr, off, err return off, nil
} }
func unpackAVC(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *APL) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(AVC)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Txt, off, err = unpackStringTxt(msg, off) rr.Prefixes, off, err = unpackDataApl(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackCAA(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *AVC) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(CAA) rdStart := off
rr.Hdr = h _ = rdStart
if noRdata(h) {
return rr, off, nil rr.Txt, off, err = unpackStringTxt(msg, off)
} if err != nil {
var err error return off, err
}
return off, nil
}
func (rr *CAA) unpack(msg []byte, off int) (off1 int, err error) {
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Flag, off, err = unpackUint8(msg, off) rr.Flag, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Tag, off, err = unpackString(msg, off) rr.Tag, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Value, off, err = unpackStringOctet(msg, off) rr.Value, off, err = unpackStringOctet(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackCDNSKEY(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *CDNSKEY) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(CDNSKEY)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Flags, off, err = unpackUint16(msg, off) rr.Flags, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Protocol, off, err = unpackUint8(msg, off) rr.Protocol, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.PublicKey, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.PublicKey, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackCDS(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *CDS) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(CDS)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.KeyTag, off, err = unpackUint16(msg, off) rr.KeyTag, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.DigestType, off, err = unpackUint8(msg, off) rr.DigestType, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Digest, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Digest, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackCERT(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *CERT) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(CERT)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Type, off, err = unpackUint16(msg, off) rr.Type, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.KeyTag, off, err = unpackUint16(msg, off) rr.KeyTag, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Certificate, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Certificate, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackCNAME(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *CNAME) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(CNAME)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Target, off, err = UnpackDomainName(msg, off) rr.Target, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackCSYNC(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *CSYNC) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(CSYNC)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Serial, off, err = unpackUint32(msg, off) rr.Serial, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Flags, off, err = unpackUint16(msg, off) rr.Flags, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.TypeBitMap, off, err = unpackDataNsec(msg, off) rr.TypeBitMap, off, err = unpackDataNsec(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackDHCID(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *DHCID) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(DHCID)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Digest, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Digest, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackDLV(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *DLV) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(DLV)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.KeyTag, off, err = unpackUint16(msg, off) rr.KeyTag, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.DigestType, off, err = unpackUint8(msg, off) rr.DigestType, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Digest, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Digest, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackDNAME(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *DNAME) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(DNAME)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Target, off, err = UnpackDomainName(msg, off) rr.Target, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackDNSKEY(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *DNSKEY) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(DNSKEY)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Flags, off, err = unpackUint16(msg, off) rr.Flags, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Protocol, off, err = unpackUint8(msg, off) rr.Protocol, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.PublicKey, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.PublicKey, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackDS(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *DS) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(DS)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.KeyTag, off, err = unpackUint16(msg, off) rr.KeyTag, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.DigestType, off, err = unpackUint8(msg, off) rr.DigestType, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Digest, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Digest, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackEID(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *EID) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(EID)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Endpoint, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Endpoint, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackEUI48(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *EUI48) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(EUI48)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Address, off, err = unpackUint48(msg, off) rr.Address, off, err = unpackUint48(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackEUI64(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *EUI64) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(EUI64)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Address, off, err = unpackUint64(msg, off) rr.Address, off, err = unpackUint64(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackGID(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *GID) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(GID)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Gid, off, err = unpackUint32(msg, off) rr.Gid, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackGPOS(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *GPOS) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(GPOS)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Longitude, off, err = unpackString(msg, off) rr.Longitude, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Latitude, off, err = unpackString(msg, off) rr.Latitude, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Altitude, off, err = unpackString(msg, off) rr.Altitude, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackHINFO(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *HINFO) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(HINFO)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Cpu, off, err = unpackString(msg, off) rr.Cpu, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Os, off, err = unpackString(msg, off) rr.Os, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackHIP(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *HIP) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(HIP)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.HitLength, off, err = unpackUint8(msg, off) rr.HitLength, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.PublicKeyAlgorithm, off, err = unpackUint8(msg, off) rr.PublicKeyAlgorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.PublicKeyLength, off, err = unpackUint16(msg, off) rr.PublicKeyLength, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Hit, off, err = unpackStringHex(msg, off, off+int(rr.HitLength)) rr.Hit, off, err = unpackStringHex(msg, off, off+int(rr.HitLength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
rr.PublicKey, off, err = unpackStringBase64(msg, off, off+int(rr.PublicKeyLength)) rr.PublicKey, off, err = unpackStringBase64(msg, off, off+int(rr.PublicKeyLength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
rr.RendezvousServers, off, err = unpackDataDomainNames(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.RendezvousServers, off, err = unpackDataDomainNames(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackKEY(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *HTTPS) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(KEY) rdStart := off
rr.Hdr = h _ = rdStart
if noRdata(h) {
return rr, off, nil rr.Priority, off, err = unpackUint16(msg, off)
if err != nil {
return off, err
}
if off == len(msg) {
return off, nil
}
rr.Target, off, err = UnpackDomainName(msg, off)
if err != nil {
return off, err
}
if off == len(msg) {
return off, nil
}
rr.Value, off, err = unpackDataSVCB(msg, off)
if err != nil {
return off, err
} }
var err error return off, nil
}
func (rr *KEY) unpack(msg []byte, off int) (off1 int, err error) {
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Flags, off, err = unpackUint16(msg, off) rr.Flags, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Protocol, off, err = unpackUint8(msg, off) rr.Protocol, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.PublicKey, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.PublicKey, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackKX(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *KX) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(KX)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Preference, off, err = unpackUint16(msg, off) rr.Preference, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Exchanger, off, err = UnpackDomainName(msg, off) rr.Exchanger, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackL32(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *L32) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(L32)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Preference, off, err = unpackUint16(msg, off) rr.Preference, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Locator32, off, err = unpackDataA(msg, off) rr.Locator32, off, err = unpackDataA(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackL64(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *L64) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(L64)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Preference, off, err = unpackUint16(msg, off) rr.Preference, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Locator64, off, err = unpackUint64(msg, off) rr.Locator64, off, err = unpackUint64(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackLOC(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *LOC) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(LOC)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Version, off, err = unpackUint8(msg, off) rr.Version, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Size, off, err = unpackUint8(msg, off) rr.Size, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.HorizPre, off, err = unpackUint8(msg, off) rr.HorizPre, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.VertPre, off, err = unpackUint8(msg, off) rr.VertPre, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Latitude, off, err = unpackUint32(msg, off) rr.Latitude, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Longitude, off, err = unpackUint32(msg, off) rr.Longitude, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Altitude, off, err = unpackUint32(msg, off) rr.Altitude, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackLP(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *LP) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(LP)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Preference, off, err = unpackUint16(msg, off) rr.Preference, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Fqdn, off, err = UnpackDomainName(msg, off) rr.Fqdn, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackMB(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *MB) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(MB)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Mb, off, err = UnpackDomainName(msg, off) rr.Mb, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackMD(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *MD) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(MD)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Md, off, err = UnpackDomainName(msg, off) rr.Md, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackMF(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *MF) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(MF)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Mf, off, err = UnpackDomainName(msg, off) rr.Mf, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackMG(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *MG) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(MG)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Mg, off, err = UnpackDomainName(msg, off) rr.Mg, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackMINFO(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *MINFO) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(MINFO)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Rmail, off, err = UnpackDomainName(msg, off) rr.Rmail, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Email, off, err = UnpackDomainName(msg, off) rr.Email, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackMR(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *MR) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(MR)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Mr, off, err = UnpackDomainName(msg, off) rr.Mr, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackMX(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *MX) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(MX)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Preference, off, err = unpackUint16(msg, off) rr.Preference, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Mx, off, err = UnpackDomainName(msg, off) rr.Mx, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackNAPTR(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *NAPTR) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(NAPTR)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Order, off, err = unpackUint16(msg, off) rr.Order, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Preference, off, err = unpackUint16(msg, off) rr.Preference, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Flags, off, err = unpackString(msg, off) rr.Flags, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Service, off, err = unpackString(msg, off) rr.Service, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Regexp, off, err = unpackString(msg, off) rr.Regexp, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Replacement, off, err = UnpackDomainName(msg, off) rr.Replacement, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackNID(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *NID) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(NID)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Preference, off, err = unpackUint16(msg, off) rr.Preference, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.NodeID, off, err = unpackUint64(msg, off) rr.NodeID, off, err = unpackUint64(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackNIMLOC(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *NIMLOC) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(NIMLOC)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Locator, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Locator, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackNINFO(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *NINFO) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(NINFO)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.ZSData, off, err = unpackStringTxt(msg, off) rr.ZSData, off, err = unpackStringTxt(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackNS(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *NS) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(NS)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Ns, off, err = UnpackDomainName(msg, off) rr.Ns, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackNSAPPTR(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *NSAPPTR) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(NSAPPTR)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Ptr, off, err = UnpackDomainName(msg, off) rr.Ptr, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackNSEC(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *NSEC) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(NSEC)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.NextDomain, off, err = UnpackDomainName(msg, off) rr.NextDomain, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.TypeBitMap, off, err = unpackDataNsec(msg, off) rr.TypeBitMap, off, err = unpackDataNsec(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackNSEC3(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *NSEC3) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(NSEC3)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Hash, off, err = unpackUint8(msg, off) rr.Hash, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Flags, off, err = unpackUint8(msg, off) rr.Flags, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Iterations, off, err = unpackUint16(msg, off) rr.Iterations, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.SaltLength, off, err = unpackUint8(msg, off) rr.SaltLength, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Salt, off, err = unpackStringHex(msg, off, off+int(rr.SaltLength)) rr.Salt, off, err = unpackStringHex(msg, off, off+int(rr.SaltLength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
rr.HashLength, off, err = unpackUint8(msg, off) rr.HashLength, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.NextDomain, off, err = unpackStringBase32(msg, off, off+int(rr.HashLength)) rr.NextDomain, off, err = unpackStringBase32(msg, off, off+int(rr.HashLength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
rr.TypeBitMap, off, err = unpackDataNsec(msg, off) rr.TypeBitMap, off, err = unpackDataNsec(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackNSEC3PARAM(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *NSEC3PARAM) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(NSEC3PARAM)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Hash, off, err = unpackUint8(msg, off) rr.Hash, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Flags, off, err = unpackUint8(msg, off) rr.Flags, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Iterations, off, err = unpackUint16(msg, off) rr.Iterations, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.SaltLength, off, err = unpackUint8(msg, off) rr.SaltLength, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Salt, off, err = unpackStringHex(msg, off, off+int(rr.SaltLength)) rr.Salt, off, err = unpackStringHex(msg, off, off+int(rr.SaltLength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackOPENPGPKEY(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *NULL) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(OPENPGPKEY) rdStart := off
rr.Hdr = h _ = rdStart
if noRdata(h) {
return rr, off, nil rr.Data, off, err = unpackStringAny(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil {
return off, err
} }
var err error return off, nil
}
func (rr *OPENPGPKEY) unpack(msg []byte, off int) (off1 int, err error) {
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.PublicKey, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.PublicKey, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackOPT(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *OPT) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(OPT)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Option, off, err = unpackDataOpt(msg, off) rr.Option, off, err = unpackDataOpt(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackPTR(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *PTR) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(PTR)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Ptr, off, err = UnpackDomainName(msg, off) rr.Ptr, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackPX(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *PX) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(PX)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Preference, off, err = unpackUint16(msg, off) rr.Preference, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Map822, off, err = UnpackDomainName(msg, off) rr.Map822, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Mapx400, off, err = UnpackDomainName(msg, off) rr.Mapx400, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackRFC3597(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *RFC3597) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(RFC3597)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Rdata, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Rdata, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackRKEY(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *RKEY) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(RKEY)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Flags, off, err = unpackUint16(msg, off) rr.Flags, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Protocol, off, err = unpackUint8(msg, off) rr.Protocol, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.PublicKey, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.PublicKey, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackRP(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *RP) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(RP)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Mbox, off, err = UnpackDomainName(msg, off) rr.Mbox, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Txt, off, err = UnpackDomainName(msg, off) rr.Txt, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackRRSIG(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *RRSIG) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(RRSIG)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.TypeCovered, off, err = unpackUint16(msg, off) rr.TypeCovered, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Labels, off, err = unpackUint8(msg, off) rr.Labels, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.OrigTtl, off, err = unpackUint32(msg, off) rr.OrigTtl, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Expiration, off, err = unpackUint32(msg, off) rr.Expiration, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Inception, off, err = unpackUint32(msg, off) rr.Inception, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.KeyTag, off, err = unpackUint16(msg, off) rr.KeyTag, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.SignerName, off, err = UnpackDomainName(msg, off) rr.SignerName, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Signature, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Signature, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackRT(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *RT) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(RT)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Preference, off, err = unpackUint16(msg, off) rr.Preference, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Host, off, err = UnpackDomainName(msg, off) rr.Host, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackSIG(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *SIG) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(SIG)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.TypeCovered, off, err = unpackUint16(msg, off) rr.TypeCovered, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Labels, off, err = unpackUint8(msg, off) rr.Labels, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.OrigTtl, off, err = unpackUint32(msg, off) rr.OrigTtl, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Expiration, off, err = unpackUint32(msg, off) rr.Expiration, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Inception, off, err = unpackUint32(msg, off) rr.Inception, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.KeyTag, off, err = unpackUint16(msg, off) rr.KeyTag, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.SignerName, off, err = UnpackDomainName(msg, off) rr.SignerName, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Signature, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Signature, off, err = unpackStringBase64(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackSMIMEA(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *SMIMEA) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(SMIMEA)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Usage, off, err = unpackUint8(msg, off) rr.Usage, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Selector, off, err = unpackUint8(msg, off) rr.Selector, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.MatchingType, off, err = unpackUint8(msg, off) rr.MatchingType, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Certificate, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Certificate, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackSOA(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *SOA) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(SOA)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Ns, off, err = UnpackDomainName(msg, off) rr.Ns, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Mbox, off, err = UnpackDomainName(msg, off) rr.Mbox, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Serial, off, err = unpackUint32(msg, off) rr.Serial, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Refresh, off, err = unpackUint32(msg, off) rr.Refresh, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Retry, off, err = unpackUint32(msg, off) rr.Retry, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Expire, off, err = unpackUint32(msg, off) rr.Expire, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Minttl, off, err = unpackUint32(msg, off) rr.Minttl, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackSPF(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *SPF) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(SPF)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Txt, off, err = unpackStringTxt(msg, off) rr.Txt, off, err = unpackStringTxt(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackSRV(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *SRV) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(SRV)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Priority, off, err = unpackUint16(msg, off) rr.Priority, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Weight, off, err = unpackUint16(msg, off) rr.Weight, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Port, off, err = unpackUint16(msg, off) rr.Port, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Target, off, err = UnpackDomainName(msg, off) rr.Target, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackSSHFP(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *SSHFP) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(SSHFP)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Type, off, err = unpackUint8(msg, off) rr.Type, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.FingerPrint, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.FingerPrint, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackTA(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *SVCB) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(TA) rdStart := off
rr.Hdr = h _ = rdStart
if noRdata(h) {
return rr, off, nil rr.Priority, off, err = unpackUint16(msg, off)
if err != nil {
return off, err
}
if off == len(msg) {
return off, nil
}
rr.Target, off, err = UnpackDomainName(msg, off)
if err != nil {
return off, err
}
if off == len(msg) {
return off, nil
} }
var err error rr.Value, off, err = unpackDataSVCB(msg, off)
if err != nil {
return off, err
}
return off, nil
}
func (rr *TA) unpack(msg []byte, off int) (off1 int, err error) {
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.KeyTag, off, err = unpackUint16(msg, off) rr.KeyTag, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Algorithm, off, err = unpackUint8(msg, off) rr.Algorithm, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.DigestType, off, err = unpackUint8(msg, off) rr.DigestType, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Digest, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Digest, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackTALINK(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *TALINK) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(TALINK)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.PreviousName, off, err = UnpackDomainName(msg, off) rr.PreviousName, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.NextName, off, err = UnpackDomainName(msg, off) rr.NextName, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackTKEY(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *TKEY) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(TKEY)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Algorithm, off, err = UnpackDomainName(msg, off) rr.Algorithm, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Inception, off, err = unpackUint32(msg, off) rr.Inception, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Expiration, off, err = unpackUint32(msg, off) rr.Expiration, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Mode, off, err = unpackUint16(msg, off) rr.Mode, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Error, off, err = unpackUint16(msg, off) rr.Error, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.KeySize, off, err = unpackUint16(msg, off) rr.KeySize, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Key, off, err = unpackStringHex(msg, off, off+int(rr.KeySize)) rr.Key, off, err = unpackStringHex(msg, off, off+int(rr.KeySize))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
rr.OtherLen, off, err = unpackUint16(msg, off) rr.OtherLen, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.OtherData, off, err = unpackStringHex(msg, off, off+int(rr.OtherLen)) rr.OtherData, off, err = unpackStringHex(msg, off, off+int(rr.OtherLen))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackTLSA(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *TLSA) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(TLSA)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Usage, off, err = unpackUint8(msg, off) rr.Usage, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Selector, off, err = unpackUint8(msg, off) rr.Selector, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.MatchingType, off, err = unpackUint8(msg, off) rr.MatchingType, off, err = unpackUint8(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Certificate, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength)) rr.Certificate, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackTSIG(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *TSIG) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(TSIG)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Algorithm, off, err = UnpackDomainName(msg, off) rr.Algorithm, off, err = UnpackDomainName(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.TimeSigned, off, err = unpackUint48(msg, off) rr.TimeSigned, off, err = unpackUint48(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Fudge, off, err = unpackUint16(msg, off) rr.Fudge, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.MACSize, off, err = unpackUint16(msg, off) rr.MACSize, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.MAC, off, err = unpackStringHex(msg, off, off+int(rr.MACSize)) rr.MAC, off, err = unpackStringHex(msg, off, off+int(rr.MACSize))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
rr.OrigId, off, err = unpackUint16(msg, off) rr.OrigId, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Error, off, err = unpackUint16(msg, off) rr.Error, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.OtherLen, off, err = unpackUint16(msg, off) rr.OtherLen, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.OtherData, off, err = unpackStringHex(msg, off, off+int(rr.OtherLen)) rr.OtherData, off, err = unpackStringHex(msg, off, off+int(rr.OtherLen))
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackTXT(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *TXT) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(TXT)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Txt, off, err = unpackStringTxt(msg, off) rr.Txt, off, err = unpackStringTxt(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackUID(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *UID) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(UID)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Uid, off, err = unpackUint32(msg, off) rr.Uid, off, err = unpackUint32(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackUINFO(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *UINFO) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(UINFO)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Uinfo, off, err = unpackString(msg, off) rr.Uinfo, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackURI(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *URI) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(URI)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.Priority, off, err = unpackUint16(msg, off) rr.Priority, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Weight, off, err = unpackUint16(msg, off) rr.Weight, off, err = unpackUint16(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
if off == len(msg) { if off == len(msg) {
return rr, off, nil return off, nil
} }
rr.Target, off, err = unpackStringOctet(msg, off) rr.Target, off, err = unpackStringOctet(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
func unpackX25(h RR_Header, msg []byte, off int) (RR, int, error) { func (rr *X25) unpack(msg []byte, off int) (off1 int, err error) {
rr := new(X25)
rr.Hdr = h
if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off rdStart := off
_ = rdStart _ = rdStart
rr.PSDNAddress, off, err = unpackString(msg, off) rr.PSDNAddress, off, err = unpackString(msg, off)
if err != nil { if err != nil {
return rr, off, err return off, err
} }
return rr, off, err return off, nil
} }
var typeToUnpack = map[uint16]func(RR_Header, []byte, int) (RR, int, error){ func (rr *ZONEMD) unpack(msg []byte, off int) (off1 int, err error) {
TypeA: unpackA, rdStart := off
TypeAAAA: unpackAAAA, _ = rdStart
TypeAFSDB: unpackAFSDB,
TypeANY: unpackANY, rr.Serial, off, err = unpackUint32(msg, off)
TypeAVC: unpackAVC, if err != nil {
TypeCAA: unpackCAA, return off, err
TypeCDNSKEY: unpackCDNSKEY, }
TypeCDS: unpackCDS, if off == len(msg) {
TypeCERT: unpackCERT, return off, nil
TypeCNAME: unpackCNAME, }
TypeCSYNC: unpackCSYNC, rr.Scheme, off, err = unpackUint8(msg, off)
TypeDHCID: unpackDHCID, if err != nil {
TypeDLV: unpackDLV, return off, err
TypeDNAME: unpackDNAME, }
TypeDNSKEY: unpackDNSKEY, if off == len(msg) {
TypeDS: unpackDS, return off, nil
TypeEID: unpackEID, }
TypeEUI48: unpackEUI48, rr.Hash, off, err = unpackUint8(msg, off)
TypeEUI64: unpackEUI64, if err != nil {
TypeGID: unpackGID, return off, err
TypeGPOS: unpackGPOS, }
TypeHINFO: unpackHINFO, if off == len(msg) {
TypeHIP: unpackHIP, return off, nil
TypeKEY: unpackKEY, }
TypeKX: unpackKX, rr.Digest, off, err = unpackStringHex(msg, off, rdStart+int(rr.Hdr.Rdlength))
TypeL32: unpackL32, if err != nil {
TypeL64: unpackL64, return off, err
TypeLOC: unpackLOC, }
TypeLP: unpackLP, return off, nil
TypeMB: unpackMB,
TypeMD: unpackMD,
TypeMF: unpackMF,
TypeMG: unpackMG,
TypeMINFO: unpackMINFO,
TypeMR: unpackMR,
TypeMX: unpackMX,
TypeNAPTR: unpackNAPTR,
TypeNID: unpackNID,
TypeNIMLOC: unpackNIMLOC,
TypeNINFO: unpackNINFO,
TypeNS: unpackNS,
TypeNSAPPTR: unpackNSAPPTR,
TypeNSEC: unpackNSEC,
TypeNSEC3: unpackNSEC3,
TypeNSEC3PARAM: unpackNSEC3PARAM,
TypeOPENPGPKEY: unpackOPENPGPKEY,
TypeOPT: unpackOPT,
TypePTR: unpackPTR,
TypePX: unpackPX,
TypeRKEY: unpackRKEY,
TypeRP: unpackRP,
TypeRRSIG: unpackRRSIG,
TypeRT: unpackRT,
TypeSIG: unpackSIG,
TypeSMIMEA: unpackSMIMEA,
TypeSOA: unpackSOA,
TypeSPF: unpackSPF,
TypeSRV: unpackSRV,
TypeSSHFP: unpackSSHFP,
TypeTA: unpackTA,
TypeTALINK: unpackTALINK,
TypeTKEY: unpackTKEY,
TypeTLSA: unpackTLSA,
TypeTSIG: unpackTSIG,
TypeTXT: unpackTXT,
TypeUID: unpackUID,
TypeUINFO: unpackUINFO,
TypeURI: unpackURI,
TypeX25: unpackX25,
} }
...@@ -13,6 +13,7 @@ var TypeToRR = map[uint16]func() RR{ ...@@ -13,6 +13,7 @@ var TypeToRR = map[uint16]func() RR{
TypeAAAA: func() RR { return new(AAAA) }, TypeAAAA: func() RR { return new(AAAA) },
TypeAFSDB: func() RR { return new(AFSDB) }, TypeAFSDB: func() RR { return new(AFSDB) },
TypeANY: func() RR { return new(ANY) }, TypeANY: func() RR { return new(ANY) },
TypeAPL: func() RR { return new(APL) },
TypeAVC: func() RR { return new(AVC) }, TypeAVC: func() RR { return new(AVC) },
TypeCAA: func() RR { return new(CAA) }, TypeCAA: func() RR { return new(CAA) },
TypeCDNSKEY: func() RR { return new(CDNSKEY) }, TypeCDNSKEY: func() RR { return new(CDNSKEY) },
...@@ -32,6 +33,7 @@ var TypeToRR = map[uint16]func() RR{ ...@@ -32,6 +33,7 @@ var TypeToRR = map[uint16]func() RR{
TypeGPOS: func() RR { return new(GPOS) }, TypeGPOS: func() RR { return new(GPOS) },
TypeHINFO: func() RR { return new(HINFO) }, TypeHINFO: func() RR { return new(HINFO) },
TypeHIP: func() RR { return new(HIP) }, TypeHIP: func() RR { return new(HIP) },
TypeHTTPS: func() RR { return new(HTTPS) },
TypeKEY: func() RR { return new(KEY) }, TypeKEY: func() RR { return new(KEY) },
TypeKX: func() RR { return new(KX) }, TypeKX: func() RR { return new(KX) },
TypeL32: func() RR { return new(L32) }, TypeL32: func() RR { return new(L32) },
...@@ -54,6 +56,7 @@ var TypeToRR = map[uint16]func() RR{ ...@@ -54,6 +56,7 @@ var TypeToRR = map[uint16]func() RR{
TypeNSEC: func() RR { return new(NSEC) }, TypeNSEC: func() RR { return new(NSEC) },
TypeNSEC3: func() RR { return new(NSEC3) }, TypeNSEC3: func() RR { return new(NSEC3) },
TypeNSEC3PARAM: func() RR { return new(NSEC3PARAM) }, TypeNSEC3PARAM: func() RR { return new(NSEC3PARAM) },
TypeNULL: func() RR { return new(NULL) },
TypeOPENPGPKEY: func() RR { return new(OPENPGPKEY) }, TypeOPENPGPKEY: func() RR { return new(OPENPGPKEY) },
TypeOPT: func() RR { return new(OPT) }, TypeOPT: func() RR { return new(OPT) },
TypePTR: func() RR { return new(PTR) }, TypePTR: func() RR { return new(PTR) },
...@@ -68,6 +71,7 @@ var TypeToRR = map[uint16]func() RR{ ...@@ -68,6 +71,7 @@ var TypeToRR = map[uint16]func() RR{
TypeSPF: func() RR { return new(SPF) }, TypeSPF: func() RR { return new(SPF) },
TypeSRV: func() RR { return new(SRV) }, TypeSRV: func() RR { return new(SRV) },
TypeSSHFP: func() RR { return new(SSHFP) }, TypeSSHFP: func() RR { return new(SSHFP) },
TypeSVCB: func() RR { return new(SVCB) },
TypeTA: func() RR { return new(TA) }, TypeTA: func() RR { return new(TA) },
TypeTALINK: func() RR { return new(TALINK) }, TypeTALINK: func() RR { return new(TALINK) },
TypeTKEY: func() RR { return new(TKEY) }, TypeTKEY: func() RR { return new(TKEY) },
...@@ -78,6 +82,7 @@ var TypeToRR = map[uint16]func() RR{ ...@@ -78,6 +82,7 @@ var TypeToRR = map[uint16]func() RR{
TypeUINFO: func() RR { return new(UINFO) }, TypeUINFO: func() RR { return new(UINFO) },
TypeURI: func() RR { return new(URI) }, TypeURI: func() RR { return new(URI) },
TypeX25: func() RR { return new(X25) }, TypeX25: func() RR { return new(X25) },
TypeZONEMD: func() RR { return new(ZONEMD) },
} }
// TypeToString is a map of strings for each RR type. // TypeToString is a map of strings for each RR type.
...@@ -86,6 +91,7 @@ var TypeToString = map[uint16]string{ ...@@ -86,6 +91,7 @@ var TypeToString = map[uint16]string{
TypeAAAA: "AAAA", TypeAAAA: "AAAA",
TypeAFSDB: "AFSDB", TypeAFSDB: "AFSDB",
TypeANY: "ANY", TypeANY: "ANY",
TypeAPL: "APL",
TypeATMA: "ATMA", TypeATMA: "ATMA",
TypeAVC: "AVC", TypeAVC: "AVC",
TypeAXFR: "AXFR", TypeAXFR: "AXFR",
...@@ -107,6 +113,7 @@ var TypeToString = map[uint16]string{ ...@@ -107,6 +113,7 @@ var TypeToString = map[uint16]string{
TypeGPOS: "GPOS", TypeGPOS: "GPOS",
TypeHINFO: "HINFO", TypeHINFO: "HINFO",
TypeHIP: "HIP", TypeHIP: "HIP",
TypeHTTPS: "HTTPS",
TypeISDN: "ISDN", TypeISDN: "ISDN",
TypeIXFR: "IXFR", TypeIXFR: "IXFR",
TypeKEY: "KEY", TypeKEY: "KEY",
...@@ -150,6 +157,7 @@ var TypeToString = map[uint16]string{ ...@@ -150,6 +157,7 @@ var TypeToString = map[uint16]string{
TypeSPF: "SPF", TypeSPF: "SPF",
TypeSRV: "SRV", TypeSRV: "SRV",
TypeSSHFP: "SSHFP", TypeSSHFP: "SSHFP",
TypeSVCB: "SVCB",
TypeTA: "TA", TypeTA: "TA",
TypeTALINK: "TALINK", TypeTALINK: "TALINK",
TypeTKEY: "TKEY", TypeTKEY: "TKEY",
...@@ -161,6 +169,7 @@ var TypeToString = map[uint16]string{ ...@@ -161,6 +169,7 @@ var TypeToString = map[uint16]string{
TypeUNSPEC: "UNSPEC", TypeUNSPEC: "UNSPEC",
TypeURI: "URI", TypeURI: "URI",
TypeX25: "X25", TypeX25: "X25",
TypeZONEMD: "ZONEMD",
TypeNSAPPTR: "NSAP-PTR", TypeNSAPPTR: "NSAP-PTR",
} }
...@@ -168,6 +177,7 @@ func (rr *A) Header() *RR_Header { return &rr.Hdr } ...@@ -168,6 +177,7 @@ func (rr *A) Header() *RR_Header { return &rr.Hdr }
func (rr *AAAA) Header() *RR_Header { return &rr.Hdr } func (rr *AAAA) Header() *RR_Header { return &rr.Hdr }
func (rr *AFSDB) Header() *RR_Header { return &rr.Hdr } func (rr *AFSDB) Header() *RR_Header { return &rr.Hdr }
func (rr *ANY) Header() *RR_Header { return &rr.Hdr } func (rr *ANY) Header() *RR_Header { return &rr.Hdr }
func (rr *APL) Header() *RR_Header { return &rr.Hdr }
func (rr *AVC) Header() *RR_Header { return &rr.Hdr } func (rr *AVC) Header() *RR_Header { return &rr.Hdr }
func (rr *CAA) Header() *RR_Header { return &rr.Hdr } func (rr *CAA) Header() *RR_Header { return &rr.Hdr }
func (rr *CDNSKEY) Header() *RR_Header { return &rr.Hdr } func (rr *CDNSKEY) Header() *RR_Header { return &rr.Hdr }
...@@ -187,6 +197,7 @@ func (rr *GID) Header() *RR_Header { return &rr.Hdr } ...@@ -187,6 +197,7 @@ func (rr *GID) Header() *RR_Header { return &rr.Hdr }
func (rr *GPOS) Header() *RR_Header { return &rr.Hdr } func (rr *GPOS) Header() *RR_Header { return &rr.Hdr }
func (rr *HINFO) Header() *RR_Header { return &rr.Hdr } func (rr *HINFO) Header() *RR_Header { return &rr.Hdr }
func (rr *HIP) Header() *RR_Header { return &rr.Hdr } func (rr *HIP) Header() *RR_Header { return &rr.Hdr }
func (rr *HTTPS) Header() *RR_Header { return &rr.Hdr }
func (rr *KEY) Header() *RR_Header { return &rr.Hdr } func (rr *KEY) Header() *RR_Header { return &rr.Hdr }
func (rr *KX) Header() *RR_Header { return &rr.Hdr } func (rr *KX) Header() *RR_Header { return &rr.Hdr }
func (rr *L32) Header() *RR_Header { return &rr.Hdr } func (rr *L32) Header() *RR_Header { return &rr.Hdr }
...@@ -209,6 +220,7 @@ func (rr *NSAPPTR) Header() *RR_Header { return &rr.Hdr } ...@@ -209,6 +220,7 @@ func (rr *NSAPPTR) Header() *RR_Header { return &rr.Hdr }
func (rr *NSEC) Header() *RR_Header { return &rr.Hdr } func (rr *NSEC) Header() *RR_Header { return &rr.Hdr }
func (rr *NSEC3) Header() *RR_Header { return &rr.Hdr } func (rr *NSEC3) Header() *RR_Header { return &rr.Hdr }
func (rr *NSEC3PARAM) Header() *RR_Header { return &rr.Hdr } func (rr *NSEC3PARAM) Header() *RR_Header { return &rr.Hdr }
func (rr *NULL) Header() *RR_Header { return &rr.Hdr }
func (rr *OPENPGPKEY) Header() *RR_Header { return &rr.Hdr } func (rr *OPENPGPKEY) Header() *RR_Header { return &rr.Hdr }
func (rr *OPT) Header() *RR_Header { return &rr.Hdr } func (rr *OPT) Header() *RR_Header { return &rr.Hdr }
func (rr *PTR) Header() *RR_Header { return &rr.Hdr } func (rr *PTR) Header() *RR_Header { return &rr.Hdr }
...@@ -224,6 +236,7 @@ func (rr *SOA) Header() *RR_Header { return &rr.Hdr } ...@@ -224,6 +236,7 @@ func (rr *SOA) Header() *RR_Header { return &rr.Hdr }
func (rr *SPF) Header() *RR_Header { return &rr.Hdr } func (rr *SPF) Header() *RR_Header { return &rr.Hdr }
func (rr *SRV) Header() *RR_Header { return &rr.Hdr } func (rr *SRV) Header() *RR_Header { return &rr.Hdr }
func (rr *SSHFP) Header() *RR_Header { return &rr.Hdr } func (rr *SSHFP) Header() *RR_Header { return &rr.Hdr }
func (rr *SVCB) Header() *RR_Header { return &rr.Hdr }
func (rr *TA) Header() *RR_Header { return &rr.Hdr } func (rr *TA) Header() *RR_Header { return &rr.Hdr }
func (rr *TALINK) Header() *RR_Header { return &rr.Hdr } func (rr *TALINK) Header() *RR_Header { return &rr.Hdr }
func (rr *TKEY) Header() *RR_Header { return &rr.Hdr } func (rr *TKEY) Header() *RR_Header { return &rr.Hdr }
...@@ -234,146 +247,160 @@ func (rr *UID) Header() *RR_Header { return &rr.Hdr } ...@@ -234,146 +247,160 @@ func (rr *UID) Header() *RR_Header { return &rr.Hdr }
func (rr *UINFO) Header() *RR_Header { return &rr.Hdr } func (rr *UINFO) Header() *RR_Header { return &rr.Hdr }
func (rr *URI) Header() *RR_Header { return &rr.Hdr } func (rr *URI) Header() *RR_Header { return &rr.Hdr }
func (rr *X25) Header() *RR_Header { return &rr.Hdr } func (rr *X25) Header() *RR_Header { return &rr.Hdr }
func (rr *ZONEMD) Header() *RR_Header { return &rr.Hdr }
// len() functions // len() functions
func (rr *A) len() int { func (rr *A) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += net.IPv4len // A if len(rr.A) != 0 {
l += net.IPv4len
}
return l return l
} }
func (rr *AAAA) len() int { func (rr *AAAA) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += net.IPv6len // AAAA if len(rr.AAAA) != 0 {
l += net.IPv6len
}
return l return l
} }
func (rr *AFSDB) len() int { func (rr *AFSDB) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Subtype l += 2 // Subtype
l += len(rr.Hostname) + 1 l += domainNameLen(rr.Hostname, off+l, compression, false)
return l
}
func (rr *ANY) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len(off, compression)
return l return l
} }
func (rr *ANY) len() int { func (rr *APL) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
for _, x := range rr.Prefixes {
l += x.len()
}
return l return l
} }
func (rr *AVC) len() int { func (rr *AVC) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
for _, x := range rr.Txt { for _, x := range rr.Txt {
l += len(x) + 1 l += len(x) + 1
} }
return l return l
} }
func (rr *CAA) len() int { func (rr *CAA) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l++ // Flag l++ // Flag
l += len(rr.Tag) + 1 l += len(rr.Tag) + 1
l += len(rr.Value) l += len(rr.Value)
return l return l
} }
func (rr *CERT) len() int { func (rr *CERT) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Type l += 2 // Type
l += 2 // KeyTag l += 2 // KeyTag
l++ // Algorithm l++ // Algorithm
l += base64.StdEncoding.DecodedLen(len(rr.Certificate)) l += base64.StdEncoding.DecodedLen(len(rr.Certificate))
return l return l
} }
func (rr *CNAME) len() int { func (rr *CNAME) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Target) + 1 l += domainNameLen(rr.Target, off+l, compression, true)
return l return l
} }
func (rr *DHCID) len() int { func (rr *DHCID) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += base64.StdEncoding.DecodedLen(len(rr.Digest)) l += base64.StdEncoding.DecodedLen(len(rr.Digest))
return l return l
} }
func (rr *DNAME) len() int { func (rr *DNAME) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Target) + 1 l += domainNameLen(rr.Target, off+l, compression, false)
return l return l
} }
func (rr *DNSKEY) len() int { func (rr *DNSKEY) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Flags l += 2 // Flags
l++ // Protocol l++ // Protocol
l++ // Algorithm l++ // Algorithm
l += base64.StdEncoding.DecodedLen(len(rr.PublicKey)) l += base64.StdEncoding.DecodedLen(len(rr.PublicKey))
return l return l
} }
func (rr *DS) len() int { func (rr *DS) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // KeyTag l += 2 // KeyTag
l++ // Algorithm l++ // Algorithm
l++ // DigestType l++ // DigestType
l += len(rr.Digest)/2 + 1 l += len(rr.Digest) / 2
return l return l
} }
func (rr *EID) len() int { func (rr *EID) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Endpoint)/2 + 1 l += len(rr.Endpoint) / 2
return l return l
} }
func (rr *EUI48) len() int { func (rr *EUI48) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 6 // Address l += 6 // Address
return l return l
} }
func (rr *EUI64) len() int { func (rr *EUI64) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 8 // Address l += 8 // Address
return l return l
} }
func (rr *GID) len() int { func (rr *GID) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 4 // Gid l += 4 // Gid
return l return l
} }
func (rr *GPOS) len() int { func (rr *GPOS) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Longitude) + 1 l += len(rr.Longitude) + 1
l += len(rr.Latitude) + 1 l += len(rr.Latitude) + 1
l += len(rr.Altitude) + 1 l += len(rr.Altitude) + 1
return l return l
} }
func (rr *HINFO) len() int { func (rr *HINFO) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Cpu) + 1 l += len(rr.Cpu) + 1
l += len(rr.Os) + 1 l += len(rr.Os) + 1
return l return l
} }
func (rr *HIP) len() int { func (rr *HIP) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l++ // HitLength l++ // HitLength
l++ // PublicKeyAlgorithm l++ // PublicKeyAlgorithm
l += 2 // PublicKeyLength l += 2 // PublicKeyLength
l += len(rr.Hit) / 2 l += len(rr.Hit) / 2
l += base64.StdEncoding.DecodedLen(len(rr.PublicKey)) l += base64.StdEncoding.DecodedLen(len(rr.PublicKey))
for _, x := range rr.RendezvousServers { for _, x := range rr.RendezvousServers {
l += len(x) + 1 l += domainNameLen(x, off+l, compression, false)
} }
return l return l
} }
func (rr *KX) len() int { func (rr *KX) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Preference l += 2 // Preference
l += len(rr.Exchanger) + 1 l += domainNameLen(rr.Exchanger, off+l, compression, false)
return l return l
} }
func (rr *L32) len() int { func (rr *L32) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Preference l += 2 // Preference
l += net.IPv4len // Locator32 if len(rr.Locator32) != 0 {
l += net.IPv4len
}
return l return l
} }
func (rr *L64) len() int { func (rr *L64) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Preference l += 2 // Preference
l += 8 // Locator64 l += 8 // Locator64
return l return l
} }
func (rr *LOC) len() int { func (rr *LOC) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l++ // Version l++ // Version
l++ // Size l++ // Size
l++ // HorizPre l++ // HorizPre
...@@ -383,89 +410,89 @@ func (rr *LOC) len() int { ...@@ -383,89 +410,89 @@ func (rr *LOC) len() int {
l += 4 // Altitude l += 4 // Altitude
return l return l
} }
func (rr *LP) len() int { func (rr *LP) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Preference l += 2 // Preference
l += len(rr.Fqdn) + 1 l += domainNameLen(rr.Fqdn, off+l, compression, false)
return l return l
} }
func (rr *MB) len() int { func (rr *MB) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Mb) + 1 l += domainNameLen(rr.Mb, off+l, compression, true)
return l return l
} }
func (rr *MD) len() int { func (rr *MD) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Md) + 1 l += domainNameLen(rr.Md, off+l, compression, true)
return l return l
} }
func (rr *MF) len() int { func (rr *MF) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Mf) + 1 l += domainNameLen(rr.Mf, off+l, compression, true)
return l return l
} }
func (rr *MG) len() int { func (rr *MG) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Mg) + 1 l += domainNameLen(rr.Mg, off+l, compression, true)
return l return l
} }
func (rr *MINFO) len() int { func (rr *MINFO) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Rmail) + 1 l += domainNameLen(rr.Rmail, off+l, compression, true)
l += len(rr.Email) + 1 l += domainNameLen(rr.Email, off+l, compression, true)
return l return l
} }
func (rr *MR) len() int { func (rr *MR) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Mr) + 1 l += domainNameLen(rr.Mr, off+l, compression, true)
return l return l
} }
func (rr *MX) len() int { func (rr *MX) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Preference l += 2 // Preference
l += len(rr.Mx) + 1 l += domainNameLen(rr.Mx, off+l, compression, true)
return l return l
} }
func (rr *NAPTR) len() int { func (rr *NAPTR) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Order l += 2 // Order
l += 2 // Preference l += 2 // Preference
l += len(rr.Flags) + 1 l += len(rr.Flags) + 1
l += len(rr.Service) + 1 l += len(rr.Service) + 1
l += len(rr.Regexp) + 1 l += len(rr.Regexp) + 1
l += len(rr.Replacement) + 1 l += domainNameLen(rr.Replacement, off+l, compression, false)
return l return l
} }
func (rr *NID) len() int { func (rr *NID) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Preference l += 2 // Preference
l += 8 // NodeID l += 8 // NodeID
return l return l
} }
func (rr *NIMLOC) len() int { func (rr *NIMLOC) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Locator)/2 + 1 l += len(rr.Locator) / 2
return l return l
} }
func (rr *NINFO) len() int { func (rr *NINFO) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
for _, x := range rr.ZSData { for _, x := range rr.ZSData {
l += len(x) + 1 l += len(x) + 1
} }
return l return l
} }
func (rr *NS) len() int { func (rr *NS) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Ns) + 1 l += domainNameLen(rr.Ns, off+l, compression, true)
return l return l
} }
func (rr *NSAPPTR) len() int { func (rr *NSAPPTR) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Ptr) + 1 l += domainNameLen(rr.Ptr, off+l, compression, false)
return l return l
} }
func (rr *NSEC3PARAM) len() int { func (rr *NSEC3PARAM) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l++ // Hash l++ // Hash
l++ // Flags l++ // Flags
l += 2 // Iterations l += 2 // Iterations
...@@ -473,44 +500,49 @@ func (rr *NSEC3PARAM) len() int { ...@@ -473,44 +500,49 @@ func (rr *NSEC3PARAM) len() int {
l += len(rr.Salt) / 2 l += len(rr.Salt) / 2
return l return l
} }
func (rr *OPENPGPKEY) len() int { func (rr *NULL) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Data)
return l
}
func (rr *OPENPGPKEY) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len(off, compression)
l += base64.StdEncoding.DecodedLen(len(rr.PublicKey)) l += base64.StdEncoding.DecodedLen(len(rr.PublicKey))
return l return l
} }
func (rr *PTR) len() int { func (rr *PTR) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Ptr) + 1 l += domainNameLen(rr.Ptr, off+l, compression, true)
return l return l
} }
func (rr *PX) len() int { func (rr *PX) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Preference l += 2 // Preference
l += len(rr.Map822) + 1 l += domainNameLen(rr.Map822, off+l, compression, false)
l += len(rr.Mapx400) + 1 l += domainNameLen(rr.Mapx400, off+l, compression, false)
return l return l
} }
func (rr *RFC3597) len() int { func (rr *RFC3597) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Rdata)/2 + 1 l += len(rr.Rdata) / 2
return l return l
} }
func (rr *RKEY) len() int { func (rr *RKEY) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Flags l += 2 // Flags
l++ // Protocol l++ // Protocol
l++ // Algorithm l++ // Algorithm
l += base64.StdEncoding.DecodedLen(len(rr.PublicKey)) l += base64.StdEncoding.DecodedLen(len(rr.PublicKey))
return l return l
} }
func (rr *RP) len() int { func (rr *RP) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Mbox) + 1 l += domainNameLen(rr.Mbox, off+l, compression, false)
l += len(rr.Txt) + 1 l += domainNameLen(rr.Txt, off+l, compression, false)
return l return l
} }
func (rr *RRSIG) len() int { func (rr *RRSIG) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // TypeCovered l += 2 // TypeCovered
l++ // Algorithm l++ // Algorithm
l++ // Labels l++ // Labels
...@@ -518,28 +550,28 @@ func (rr *RRSIG) len() int { ...@@ -518,28 +550,28 @@ func (rr *RRSIG) len() int {
l += 4 // Expiration l += 4 // Expiration
l += 4 // Inception l += 4 // Inception
l += 2 // KeyTag l += 2 // KeyTag
l += len(rr.SignerName) + 1 l += domainNameLen(rr.SignerName, off+l, compression, false)
l += base64.StdEncoding.DecodedLen(len(rr.Signature)) l += base64.StdEncoding.DecodedLen(len(rr.Signature))
return l return l
} }
func (rr *RT) len() int { func (rr *RT) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Preference l += 2 // Preference
l += len(rr.Host) + 1 l += domainNameLen(rr.Host, off+l, compression, false)
return l return l
} }
func (rr *SMIMEA) len() int { func (rr *SMIMEA) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l++ // Usage l++ // Usage
l++ // Selector l++ // Selector
l++ // MatchingType l++ // MatchingType
l += len(rr.Certificate)/2 + 1 l += len(rr.Certificate) / 2
return l return l
} }
func (rr *SOA) len() int { func (rr *SOA) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Ns) + 1 l += domainNameLen(rr.Ns, off+l, compression, true)
l += len(rr.Mbox) + 1 l += domainNameLen(rr.Mbox, off+l, compression, true)
l += 4 // Serial l += 4 // Serial
l += 4 // Refresh l += 4 // Refresh
l += 4 // Retry l += 4 // Retry
...@@ -547,45 +579,54 @@ func (rr *SOA) len() int { ...@@ -547,45 +579,54 @@ func (rr *SOA) len() int {
l += 4 // Minttl l += 4 // Minttl
return l return l
} }
func (rr *SPF) len() int { func (rr *SPF) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
for _, x := range rr.Txt { for _, x := range rr.Txt {
l += len(x) + 1 l += len(x) + 1
} }
return l return l
} }
func (rr *SRV) len() int { func (rr *SRV) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Priority l += 2 // Priority
l += 2 // Weight l += 2 // Weight
l += 2 // Port l += 2 // Port
l += len(rr.Target) + 1 l += domainNameLen(rr.Target, off+l, compression, false)
return l return l
} }
func (rr *SSHFP) len() int { func (rr *SSHFP) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l++ // Algorithm l++ // Algorithm
l++ // Type l++ // Type
l += len(rr.FingerPrint)/2 + 1 l += len(rr.FingerPrint) / 2
return l return l
} }
func (rr *TA) len() int { func (rr *SVCB) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Priority
l += domainNameLen(rr.Target, off+l, compression, false)
for _, x := range rr.Value {
l += 4 + int(x.len())
}
return l
}
func (rr *TA) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len(off, compression)
l += 2 // KeyTag l += 2 // KeyTag
l++ // Algorithm l++ // Algorithm
l++ // DigestType l++ // DigestType
l += len(rr.Digest)/2 + 1 l += len(rr.Digest) / 2
return l return l
} }
func (rr *TALINK) len() int { func (rr *TALINK) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.PreviousName) + 1 l += domainNameLen(rr.PreviousName, off+l, compression, false)
l += len(rr.NextName) + 1 l += domainNameLen(rr.NextName, off+l, compression, false)
return l return l
} }
func (rr *TKEY) len() int { func (rr *TKEY) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Algorithm) + 1 l += domainNameLen(rr.Algorithm, off+l, compression, false)
l += 4 // Inception l += 4 // Inception
l += 4 // Expiration l += 4 // Expiration
l += 2 // Mode l += 2 // Mode
...@@ -596,17 +637,17 @@ func (rr *TKEY) len() int { ...@@ -596,17 +637,17 @@ func (rr *TKEY) len() int {
l += len(rr.OtherData) / 2 l += len(rr.OtherData) / 2
return l return l
} }
func (rr *TLSA) len() int { func (rr *TLSA) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l++ // Usage l++ // Usage
l++ // Selector l++ // Selector
l++ // MatchingType l++ // MatchingType
l += len(rr.Certificate)/2 + 1 l += len(rr.Certificate) / 2
return l return l
} }
func (rr *TSIG) len() int { func (rr *TSIG) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Algorithm) + 1 l += domainNameLen(rr.Algorithm, off+l, compression, false)
l += 6 // TimeSigned l += 6 // TimeSigned
l += 2 // Fudge l += 2 // Fudge
l += 2 // MACSize l += 2 // MACSize
...@@ -617,35 +658,43 @@ func (rr *TSIG) len() int { ...@@ -617,35 +658,43 @@ func (rr *TSIG) len() int {
l += len(rr.OtherData) / 2 l += len(rr.OtherData) / 2
return l return l
} }
func (rr *TXT) len() int { func (rr *TXT) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
for _, x := range rr.Txt { for _, x := range rr.Txt {
l += len(x) + 1 l += len(x) + 1
} }
return l return l
} }
func (rr *UID) len() int { func (rr *UID) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 4 // Uid l += 4 // Uid
return l return l
} }
func (rr *UINFO) len() int { func (rr *UINFO) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.Uinfo) + 1 l += len(rr.Uinfo) + 1
return l return l
} }
func (rr *URI) len() int { func (rr *URI) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += 2 // Priority l += 2 // Priority
l += 2 // Weight l += 2 // Weight
l += len(rr.Target) l += len(rr.Target)
return l return l
} }
func (rr *X25) len() int { func (rr *X25) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len() l := rr.Hdr.len(off, compression)
l += len(rr.PSDNAddress) + 1 l += len(rr.PSDNAddress) + 1
return l return l
} }
func (rr *ZONEMD) len(off int, compression map[string]struct{}) int {
l := rr.Hdr.len(off, compression)
l += 4 // Serial
l++ // Scheme
l++ // Hash
l += len(rr.Digest) / 2
return l
}
// copy() functions // copy() functions
func (rr *A) copy() RR { func (rr *A) copy() RR {
...@@ -660,6 +709,13 @@ func (rr *AFSDB) copy() RR { ...@@ -660,6 +709,13 @@ func (rr *AFSDB) copy() RR {
func (rr *ANY) copy() RR { func (rr *ANY) copy() RR {
return &ANY{rr.Hdr} return &ANY{rr.Hdr}
} }
func (rr *APL) copy() RR {
Prefixes := make([]APLPrefix, len(rr.Prefixes))
for i, e := range rr.Prefixes {
Prefixes[i] = e.copy()
}
return &APL{rr.Hdr, Prefixes}
}
func (rr *AVC) copy() RR { func (rr *AVC) copy() RR {
Txt := make([]string, len(rr.Txt)) Txt := make([]string, len(rr.Txt))
copy(Txt, rr.Txt) copy(Txt, rr.Txt)
...@@ -668,6 +724,12 @@ func (rr *AVC) copy() RR { ...@@ -668,6 +724,12 @@ func (rr *AVC) copy() RR {
func (rr *CAA) copy() RR { func (rr *CAA) copy() RR {
return &CAA{rr.Hdr, rr.Flag, rr.Tag, rr.Value} return &CAA{rr.Hdr, rr.Flag, rr.Tag, rr.Value}
} }
func (rr *CDNSKEY) copy() RR {
return &CDNSKEY{*rr.DNSKEY.copy().(*DNSKEY)}
}
func (rr *CDS) copy() RR {
return &CDS{*rr.DS.copy().(*DS)}
}
func (rr *CERT) copy() RR { func (rr *CERT) copy() RR {
return &CERT{rr.Hdr, rr.Type, rr.KeyTag, rr.Algorithm, rr.Certificate} return &CERT{rr.Hdr, rr.Type, rr.KeyTag, rr.Algorithm, rr.Certificate}
} }
...@@ -682,6 +744,9 @@ func (rr *CSYNC) copy() RR { ...@@ -682,6 +744,9 @@ func (rr *CSYNC) copy() RR {
func (rr *DHCID) copy() RR { func (rr *DHCID) copy() RR {
return &DHCID{rr.Hdr, rr.Digest} return &DHCID{rr.Hdr, rr.Digest}
} }
func (rr *DLV) copy() RR {
return &DLV{*rr.DS.copy().(*DS)}
}
func (rr *DNAME) copy() RR { func (rr *DNAME) copy() RR {
return &DNAME{rr.Hdr, rr.Target} return &DNAME{rr.Hdr, rr.Target}
} }
...@@ -714,6 +779,12 @@ func (rr *HIP) copy() RR { ...@@ -714,6 +779,12 @@ func (rr *HIP) copy() RR {
copy(RendezvousServers, rr.RendezvousServers) copy(RendezvousServers, rr.RendezvousServers)
return &HIP{rr.Hdr, rr.HitLength, rr.PublicKeyAlgorithm, rr.PublicKeyLength, rr.Hit, rr.PublicKey, RendezvousServers} return &HIP{rr.Hdr, rr.HitLength, rr.PublicKeyAlgorithm, rr.PublicKeyLength, rr.Hit, rr.PublicKey, RendezvousServers}
} }
func (rr *HTTPS) copy() RR {
return &HTTPS{*rr.SVCB.copy().(*SVCB)}
}
func (rr *KEY) copy() RR {
return &KEY{*rr.DNSKEY.copy().(*DNSKEY)}
}
func (rr *KX) copy() RR { func (rr *KX) copy() RR {
return &KX{rr.Hdr, rr.Preference, rr.Exchanger} return &KX{rr.Hdr, rr.Preference, rr.Exchanger}
} }
...@@ -783,12 +854,17 @@ func (rr *NSEC3) copy() RR { ...@@ -783,12 +854,17 @@ func (rr *NSEC3) copy() RR {
func (rr *NSEC3PARAM) copy() RR { func (rr *NSEC3PARAM) copy() RR {
return &NSEC3PARAM{rr.Hdr, rr.Hash, rr.Flags, rr.Iterations, rr.SaltLength, rr.Salt} return &NSEC3PARAM{rr.Hdr, rr.Hash, rr.Flags, rr.Iterations, rr.SaltLength, rr.Salt}
} }
func (rr *NULL) copy() RR {
return &NULL{rr.Hdr, rr.Data}
}
func (rr *OPENPGPKEY) copy() RR { func (rr *OPENPGPKEY) copy() RR {
return &OPENPGPKEY{rr.Hdr, rr.PublicKey} return &OPENPGPKEY{rr.Hdr, rr.PublicKey}
} }
func (rr *OPT) copy() RR { func (rr *OPT) copy() RR {
Option := make([]EDNS0, len(rr.Option)) Option := make([]EDNS0, len(rr.Option))
copy(Option, rr.Option) for i, e := range rr.Option {
Option[i] = e.copy()
}
return &OPT{rr.Hdr, Option} return &OPT{rr.Hdr, Option}
} }
func (rr *PTR) copy() RR { func (rr *PTR) copy() RR {
...@@ -812,6 +888,9 @@ func (rr *RRSIG) copy() RR { ...@@ -812,6 +888,9 @@ func (rr *RRSIG) copy() RR {
func (rr *RT) copy() RR { func (rr *RT) copy() RR {
return &RT{rr.Hdr, rr.Preference, rr.Host} return &RT{rr.Hdr, rr.Preference, rr.Host}
} }
func (rr *SIG) copy() RR {
return &SIG{*rr.RRSIG.copy().(*RRSIG)}
}
func (rr *SMIMEA) copy() RR { func (rr *SMIMEA) copy() RR {
return &SMIMEA{rr.Hdr, rr.Usage, rr.Selector, rr.MatchingType, rr.Certificate} return &SMIMEA{rr.Hdr, rr.Usage, rr.Selector, rr.MatchingType, rr.Certificate}
} }
...@@ -829,6 +908,13 @@ func (rr *SRV) copy() RR { ...@@ -829,6 +908,13 @@ func (rr *SRV) copy() RR {
func (rr *SSHFP) copy() RR { func (rr *SSHFP) copy() RR {
return &SSHFP{rr.Hdr, rr.Algorithm, rr.Type, rr.FingerPrint} return &SSHFP{rr.Hdr, rr.Algorithm, rr.Type, rr.FingerPrint}
} }
func (rr *SVCB) copy() RR {
Value := make([]SVCBKeyValue, len(rr.Value))
for i, e := range rr.Value {
Value[i] = e.copy()
}
return &SVCB{rr.Hdr, rr.Priority, rr.Target, Value}
}
func (rr *TA) copy() RR { func (rr *TA) copy() RR {
return &TA{rr.Hdr, rr.KeyTag, rr.Algorithm, rr.DigestType, rr.Digest} return &TA{rr.Hdr, rr.KeyTag, rr.Algorithm, rr.DigestType, rr.Digest}
} }
...@@ -861,3 +947,6 @@ func (rr *URI) copy() RR { ...@@ -861,3 +947,6 @@ func (rr *URI) copy() RR {
func (rr *X25) copy() RR { func (rr *X25) copy() RR {
return &X25{rr.Hdr, rr.PSDNAddress} return &X25{rr.Hdr, rr.PSDNAddress}
} }
func (rr *ZONEMD) copy() RR {
return &ZONEMD{rr.Hdr, rr.Serial, rr.Scheme, rr.Hash, rr.Digest}
}
.DEFAULT_GOAL := test
.PHONY: test
test:
go test -v -race -cover ./...
.PHONY: bench
bench:
go test -v -run - -bench . -benchmem ./...
.PHONY: protoc
protoc:
protoc --go_out=. proto/v2/zipkin.proto
.PHONY: lint
lint:
# Ignore grep's exit code since no match returns 1.
-if [[ ! $TRAVIS_GO_VERSION = 1.8* ]]; then echo 'linting...' ; golint ./... ; fi
.PHONY: vet
vet:
go vet ./...
.PHONY: all
all: vet lint test bench
.PHONY: example
# Zipkin Library for Go
[![Travis CI](https://travis-ci.org/openzipkin/zipkin-go.svg?branch=master)](https://travis-ci.org/openzipkin/zipkin-go)
[![CircleCI](https://circleci.com/gh/openzipkin/zipkin-go.svg?style=shield)](https://circleci.com/gh/openzipkin/zipkin-go)
[![Appveyor CI](https://ci.appveyor.com/api/projects/status/1d0e5k96g10ajl63/branch/master?svg=true)](https://ci.appveyor.com/project/basvanbeek/zipkin-go)
[![Coverage Status](https://img.shields.io/coveralls/github/openzipkin/zipkin-go.svg)](https://coveralls.io/github/openzipkin/zipkin-go?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/openzipkin/zipkin-go)](https://goreportcard.com/report/github.com/openzipkin/zipkin-go)
[![GoDoc](https://godoc.org/github.com/openzipkin/zipkin-go?status.svg)](https://godoc.org/github.com/openzipkin/zipkin-go)
[![Gitter chat](https://badges.gitter.im/openzipkin/zipkin.svg)](https://gitter.im/openzipkin/zipkin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Sourcegraph](https://sourcegraph.com/github.com/openzipkin/zipkin-go/-/badge.svg)](https://sourcegraph.com/github.com/openzipkin/zipkin-go?badge)
Zipkin Go is the official Go Tracer implementation for Zipkin, supported by the
OpenZipkin community.
## package organization
`zipkin-go` is built with interoperability in mind within the OpenZipkin
community and even 3rd parties, the library consists of several packages.
The main tracing implementation can be found in the root folder of this
repository. Reusable parts not considered core implementation or deemed
beneficiary for usage by others are placed in their own packages within this
repository.
### model
This library implements the Zipkin V2 Span Model which is available in the model
package. It contains a Go data model compatible with the Zipkin V2 API and can
automatically sanitize, parse and (de)serialize to and from the required JSON
representation as used by the official Zipkin V2 Collectors.
### propagation
The propagation package and B3 subpackage hold the logic for propagating
SpanContext (span identifiers and sampling flags) between services participating
in traces. Currently Zipkin B3 Propagation is supported for HTTP and GRPC.
### middleware
The middleware subpackages contain officially supported middleware handlers and
tracing wrappers.
#### http
An easy to use http.Handler middleware for tracing server side requests is
provided. This allows one to use this middleware in applications using
standard library servers as well as most available higher level frameworks. Some
frameworks will have their own instrumentation and middleware that maps better
for their ecosystem.
For HTTP client operations `NewTransport` can return a `http.RoundTripper`
implementation that can either wrap the standard http.Client's Transport or a
custom provided one and add per request tracing. Since HTTP Requests can have
one or multiple redirects it is advisable to always enclose HTTP Client calls
with a `Span` either around the `*http.Client` call level or parent function
level.
For convenience `NewClient` is provided which returns a HTTP Client which embeds
`*http.Client` and provides an `application span` around the HTTP calls when
calling the `DoWithAppSpan()` method.
#### grpc
gRPC middleware / interceptors are planned for the near future.
### reporter
The reporter package holds the interface which the various Reporter
implementations use. It is exported into its own package as it can be used by
3rd parties to use these Reporter packages in their own libraries for exporting
to the Zipkin ecosystem. The `zipkin-go` tracer also uses the interface to
accept 3rd party Reporter implementations.
#### HTTP Reporter
Most common Reporter type used by Zipkin users transporting Spans to the Zipkin
server using JSON over HTTP. The reporter holds a buffer and reports to the
backend asynchronously.
#### Kafka Reporter
High performance Reporter transporting Spans to the Zipkin server using a Kafka
Producer digesting JSON V2 Spans. The reporter uses the
[Sarama async producer](https://godoc.org/github.com/Shopify/sarama#AsyncProducer)
underneath.
## usage and examples
[HTTP Server Example](example_httpserver_test.go)
version: v1.0.0.{build}
platform: x64
clone_folder: c:\gopath\src\github.com\openzipkin\zipkin-go
environment:
GOPATH: c:\gopath
install:
- echo %PATH%
- echo %GOPATH%
- set PATH=%GOPATH%\bin;c:\go\bin;%PATH%
- go version
- go env
build_script:
- go get -t -v ./...
- go vet ./...
- go test -v -race -cover ./...
- go test -v -run - -bench . -benchmem ./...
version: 2
jobs:
build:
working_directory: /go/src/github.com/openzipkin/zipkin-go
parallelism: 1
docker:
- image: circleci/golang
steps:
- checkout
- run: go get -t -v -d ./...
- run: make vet test bench
package zipkin
import (
"context"
)
// SpanFromContext retrieves a Zipkin Span from Go's context propagation
// mechanism if found. If not found, returns nil.
func SpanFromContext(ctx context.Context) Span {
if s, ok := ctx.Value(spanKey).(Span); ok {
return s
}
return nil
}
// NewContext stores a Zipkin Span into Go's context propagation mechanism.
func NewContext(ctx context.Context, s Span) context.Context {
return context.WithValue(ctx, spanKey, s)
}
type ctxKey struct{}
var spanKey = ctxKey{}
/*
Package zipkin implements a native Zipkin instrumentation library for Go.
See https://zipkin.io for more information about Zipkin.
*/
package zipkin
package zipkin
import (
"net"
"strconv"
"strings"
"github.com/openzipkin/zipkin-go/model"
)
// NewEndpoint creates a new endpoint given the provided serviceName and
// hostPort.
func NewEndpoint(serviceName string, hostPort string) (*model.Endpoint, error) {
e := &model.Endpoint{
ServiceName: serviceName,
}
if hostPort == "" || hostPort == ":0" {
if serviceName == "" {
// if all properties are empty we should not have an Endpoint object.
return nil, nil
}
return e, nil
}
if strings.IndexByte(hostPort, ':') < 0 {
hostPort += ":0"
}
host, port, err := net.SplitHostPort(hostPort)
if err != nil {
return nil, err
}
p, err := strconv.ParseUint(port, 10, 16)
if err != nil {
return nil, err
}
e.Port = uint16(p)
addrs, err := net.LookupIP(host)
if err != nil {
return nil, err
}
for i := range addrs {
addr := addrs[i].To4()
if addr == nil {
// IPv6 - 16 bytes
if e.IPv6 == nil {
e.IPv6 = addrs[i].To16()
}
} else {
// IPv4 - 4 bytes
if e.IPv4 == nil {
e.IPv4 = addr
}
}
if e.IPv4 != nil && e.IPv6 != nil {
// Both IPv4 & IPv6 have been set, done...
break
}
}
return e, nil
}