diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-03-13 12:54:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-13 12:54:22 -0400 |
commit | c281ee3b61e8ab53ff118866d72618ae8cce582b (patch) | |
tree | 776e7bdf6c8bfbb9a1dee5976496ab065959991f /vendor/github.com/miekg | |
parent | 3ada7a41a7fb13abef19dd63dc56b720900dbaa9 (diff) | |
download | chat-c281ee3b61e8ab53ff118866d72618ae8cce582b.tar.gz chat-c281ee3b61e8ab53ff118866d72618ae8cce582b.tar.bz2 chat-c281ee3b61e8ab53ff118866d72618ae8cce582b.zip |
Updating server dependancies. Also adding github.com/jaytaylor/html2text and gopkg.in/gomail.v2 (#5748)
Diffstat (limited to 'vendor/github.com/miekg')
33 files changed, 723 insertions, 367 deletions
diff --git a/vendor/github.com/miekg/dns/README.md b/vendor/github.com/miekg/dns/README.md index 0c1f1b6a9..2acc7f1ff 100644 --- a/vendor/github.com/miekg/dns/README.md +++ b/vendor/github.com/miekg/dns/README.md @@ -25,6 +25,7 @@ two versions of Go, currently: 1.6 and 1.7. A not-so-up-to-date-list-that-may-be-actually-current: +* https://github.com/coredns/coredns * https://cloudflare.com * https://github.com/abh/geodns * http://www.statdns.com/ @@ -54,6 +55,8 @@ A not-so-up-to-date-list-that-may-be-actually-current: * https://github.com/mehrdadrad/mylg * https://github.com/bamarni/dockness * https://github.com/fffaraz/microdns +* http://quilt.io +* https://github.com/ipdcode/hades (JD.COM) Send pull request if you want to be listed here. @@ -142,6 +145,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository. * 6975 - Algorithm Understanding in DNSSEC * 7043 - EUI48/EUI64 records * 7314 - DNS (EDNS) EXPIRE Option +* 7828 - edns-tcp-keepalive EDNS0 Option * 7553 - URI record * 7858 - DNS over TLS: Initiation and Performance Considerations (draft) * 7873 - Domain Name System (DNS) Cookies (draft-ietf-dnsop-cookies) diff --git a/vendor/github.com/miekg/dns/client.go b/vendor/github.com/miekg/dns/client.go index 0db7f7bf6..d54d6422e 100644 --- a/vendor/github.com/miekg/dns/client.go +++ b/vendor/github.com/miekg/dns/client.go @@ -121,12 +121,12 @@ func (c *Client) Exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err erro r, rtt, err, shared := c.group.Do(m.Question[0].Name+t+cl, func() (*Msg, time.Duration, error) { return c.exchange(m, a) }) + if r != nil && shared { + r = r.Copy() + } if err != nil { return r, rtt, err } - if shared { - return r.Copy(), rtt, nil - } return r, rtt, nil } @@ -300,6 +300,18 @@ func tcpMsgLen(t io.Reader) (int, error) { if err != nil { return 0, err } + + // As seen with my local router/switch, retursn 1 byte on the above read, + // resulting a a ShortRead. Just write it out (instead of loop) and read the + // other byte. + if n == 1 { + n1, err := t.Read(p[1:]) + if err != nil { + return 0, err + } + n += n1 + } + if n != 2 { return 0, ErrShortRead } @@ -400,7 +412,7 @@ func (co *Conn) Write(p []byte) (n int, err error) { n, err := io.Copy(w, bytes.NewReader(p)) return int(n), err } - n, err = co.Conn.(*net.UDPConn).Write(p) + n, err = co.Conn.Write(p) return n, err } diff --git a/vendor/github.com/miekg/dns/client_test.go b/vendor/github.com/miekg/dns/client_test.go index 850bcfcda..dee585f36 100644 --- a/vendor/github.com/miekg/dns/client_test.go +++ b/vendor/github.com/miekg/dns/client_test.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "strconv" + "sync" "testing" "time" ) @@ -77,8 +78,8 @@ func TestClientTLSSync(t *testing.T) { } } -func TestClientSyncBadId(t *testing.T) { - HandleFunc("miek.nl.", HelloServerBadId) +func TestClientSyncBadID(t *testing.T) { + HandleFunc("miek.nl.", HelloServerBadID) defer HandleRemove("miek.nl.") s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") @@ -450,3 +451,61 @@ func TestTimeout(t *testing.T) { t.Errorf("exchange took longer (%v) than specified Timeout (%v)", length, timeout) } } + +// Check that responses from deduplicated requests aren't shared between callers +func TestConcurrentExchanges(t *testing.T) { + cases := make([]*Msg, 2) + cases[0] = new(Msg) + cases[1] = new(Msg) + cases[1].Truncated = true + for _, m := range cases { + block := make(chan struct{}) + waiting := make(chan struct{}) + + handler := func(w ResponseWriter, req *Msg) { + r := m.Copy() + r.SetReply(req) + + waiting <- struct{}{} + <-block + w.WriteMsg(r) + } + + HandleFunc("miek.nl.", handler) + defer HandleRemove("miek.nl.") + + s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + if err != nil { + t.Fatalf("unable to run test server: %s", err) + } + defer s.Shutdown() + + m := new(Msg) + m.SetQuestion("miek.nl.", TypeSRV) + c := &Client{ + SingleInflight: true, + } + r := make([]*Msg, 2) + + var wg sync.WaitGroup + wg.Add(len(r)) + for i := 0; i < len(r); i++ { + go func(i int) { + r[i], _, _ = c.Exchange(m.Copy(), addrstr) + wg.Done() + }(i) + } + select { + case <-waiting: + case <-time.After(time.Second): + t.FailNow() + } + close(block) + wg.Wait() + + if r[0] == r[1] { + t.Log("Got same response object, expected non-shared responses") + t.Fail() + } + } +} diff --git a/vendor/github.com/miekg/dns/clientconfig.go b/vendor/github.com/miekg/dns/clientconfig.go index cfa9ad0b2..0a1f5a92c 100644 --- a/vendor/github.com/miekg/dns/clientconfig.go +++ b/vendor/github.com/miekg/dns/clientconfig.go @@ -97,3 +97,35 @@ func ClientConfigFromFile(resolvconf string) (*ClientConfig, error) { } return c, nil } + +// NameList returns all of the names that should be queried based on the +// config. It is based off of go's net/dns name building, but it does not +// check the length of the resulting names. +func (c *ClientConfig) NameList(name string) []string { + // if this domain is already fully qualified, no append needed. + if IsFqdn(name) { + return []string{name} + } + + // Check to see if the name has more labels than Ndots. Do this before making + // the domain fully qualified. + hasNdots := CountLabel(name) > c.Ndots + // Make the domain fully qualified. + name = Fqdn(name) + + // Make a list of names based off search. + names := []string{} + + // If name has enough dots, try that first. + if hasNdots { + names = append(names, name) + } + for _, s := range c.Search { + names = append(names, Fqdn(name+s)) + } + // If we didn't have enough dots, try after suffixes. + if !hasNdots { + names = append(names, name) + } + return names +} diff --git a/vendor/github.com/miekg/dns/clientconfig_test.go b/vendor/github.com/miekg/dns/clientconfig_test.go index 63bc5c814..7755a8a6f 100644 --- a/vendor/github.com/miekg/dns/clientconfig_test.go +++ b/vendor/github.com/miekg/dns/clientconfig_test.go @@ -48,3 +48,40 @@ func testConfig(t *testing.T, data string) { func TestNameserver(t *testing.T) { testConfig(t, normal) } func TestMissingFinalNewLine(t *testing.T) { testConfig(t, missingNewline) } + +func TestNameList(t *testing.T) { + cfg := ClientConfig{ + Ndots: 1, + } + // fqdn should be only result returned + names := cfg.NameList("miek.nl.") + if len(names) != 1 { + t.Errorf("NameList returned != 1 names: %v", names) + } else if names[0] != "miek.nl." { + t.Errorf("NameList didn't return sent fqdn domain: %v", names[0]) + } + + cfg.Search = []string{ + "test", + } + // Sent domain has NDots and search + names = cfg.NameList("miek.nl") + if len(names) != 2 { + t.Errorf("NameList returned != 2 names: %v", names) + } else if names[0] != "miek.nl." { + t.Errorf("NameList didn't return sent domain first: %v", names[0]) + } else if names[1] != "miek.nl.test." { + t.Errorf("NameList didn't return search last: %v", names[1]) + } + + cfg.Ndots = 2 + // Sent domain has less than NDots and search + names = cfg.NameList("miek.nl") + if len(names) != 2 { + t.Errorf("NameList returned != 2 names: %v", names) + } else if names[0] != "miek.nl.test." { + t.Errorf("NameList didn't return search first: %v", names[0]) + } else if names[1] != "miek.nl." { + t.Errorf("NameList didn't return sent domain last: %v", names[1]) + } +} diff --git a/vendor/github.com/miekg/dns/compress_generate.go b/vendor/github.com/miekg/dns/compress_generate.go new file mode 100644 index 000000000..1a301e9f3 --- /dev/null +++ b/vendor/github.com/miekg/dns/compress_generate.go @@ -0,0 +1,184 @@ +//+build ignore + +// compression_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 look to see if there are (compressible) names, if so it will add that +// type to compressionLenHelperType and comressionLenSearchType which "fake" the +// compression so that Len() is fast. +package main + +import ( + "bytes" + "fmt" + "go/format" + "go/importer" + "go/types" + "log" + "os" +) + +var packageHdr = ` +// *** DO NOT MODIFY *** +// AUTOGENERATED BY go generate from compress_generate.go + +package dns + +` + +// 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() + + domainTypes := map[string]bool{} // Types that have a domain name in them (either comressible or not). + cdomainTypes := map[string]bool{} // Types that have a compressible domain name in them (subset of domainType) + for _, name := range scope.Names() { + o := scope.Lookup(name) + if o == nil || !o.Exported() { + continue + } + st, _ := getTypeStruct(o.Type(), scope) + if st == nil { + continue + } + if name == "PrivateRR" { + continue + } + + if scope.Lookup("Type"+o.Name()) == nil && o.Name() != "RFC3597" { + log.Fatalf("Constant Type%s does not exist.", o.Name()) + } + + for i := 1; i < st.NumFields(); i++ { + if _, ok := st.Field(i).Type().(*types.Slice); ok { + if st.Tag(i) == `dns:"domain-name"` { + domainTypes[o.Name()] = true + } + if st.Tag(i) == `dns:"cdomain-name"` { + cdomainTypes[o.Name()] = true + domainTypes[o.Name()] = true + } + continue + } + + switch { + case st.Tag(i) == `dns:"domain-name"`: + domainTypes[o.Name()] = true + case st.Tag(i) == `dns:"cdomain-name"`: + cdomainTypes[o.Name()] = true + domainTypes[o.Name()] = true + } + } + } + + b := &bytes.Buffer{} + b.WriteString(packageHdr) + + // compressionLenHelperType - all types that have domain-name/cdomain-name can be used for compressing names + + fmt.Fprint(b, "func compressionLenHelperType(c map[string]int, r RR) {\n") + fmt.Fprint(b, "switch x := r.(type) {\n") + for name, _ := range domainTypes { + o := scope.Lookup(name) + st, _ := getTypeStruct(o.Type(), scope) + + fmt.Fprintf(b, "case *%s:\n", name) + for i := 1; i < st.NumFields(); i++ { + out := func(s string) { fmt.Fprintf(b, "compressionLenHelper(c, x.%s)\n", st.Field(i).Name()) } + + if _, ok := st.Field(i).Type().(*types.Slice); ok { + switch st.Tag(i) { + case `dns:"domain-name"`: + fallthrough + case `dns:"cdomain-name"`: + // For HIP we need to slice over the elements in this slice. + fmt.Fprintf(b, `for i := range x.%s { + compressionLenHelper(c, x.%s[i]) + } +`, st.Field(i).Name(), st.Field(i).Name()) + } + continue + } + + switch { + case st.Tag(i) == `dns:"cdomain-name"`: + fallthrough + case st.Tag(i) == `dns:"domain-name"`: + out(st.Field(i).Name()) + } + } + } + fmt.Fprintln(b, "}\n}\n\n") + + // compressionLenSearchType - search cdomain-tags types for compressible names. + + fmt.Fprint(b, "func compressionLenSearchType(c map[string]int, r RR) (int, bool) {\n") + fmt.Fprint(b, "switch x := r.(type) {\n") + for name, _ := range cdomainTypes { + o := scope.Lookup(name) + st, _ := getTypeStruct(o.Type(), scope) + + fmt.Fprintf(b, "case *%s:\n", name) + j := 1 + for i := 1; i < st.NumFields(); i++ { + out := func(s string, j int) { + fmt.Fprintf(b, "k%d, ok%d := compressionLenSearch(c, x.%s)\n", j, j, st.Field(i).Name()) + } + + // There are no slice types with names that can be compressed. + + switch { + case st.Tag(i) == `dns:"cdomain-name"`: + out(st.Field(i).Name(), j) + j++ + } + } + k := "k1" + ok := "ok1" + for i := 2; i < j; i++ { + k += fmt.Sprintf(" + k%d", i) + ok += fmt.Sprintf(" && ok%d", i) + } + fmt.Fprintf(b, "return %s, %s\n", k, ok) + } + fmt.Fprintln(b, "}\nreturn 0, false\n}\n\n") + + // gofmt + res, err := format.Source(b.Bytes()) + if err != nil { + b.WriteTo(os.Stderr) + log.Fatal(err) + } + + f, err := os.Create("zcompress.go") + fatalIfErr(err) + defer f.Close() + f.Write(res) +} + +func fatalIfErr(err error) { + if err != nil { + log.Fatal(err) + } +} diff --git a/vendor/github.com/miekg/dns/dane.go b/vendor/github.com/miekg/dns/dane.go index cdaa833ff..8c4a14ef1 100644 --- a/vendor/github.com/miekg/dns/dane.go +++ b/vendor/github.com/miekg/dns/dane.go @@ -6,7 +6,6 @@ import ( "crypto/x509" "encoding/hex" "errors" - "io" ) // CertificateToDANE converts a certificate to a hex string as used in the TLSA or SMIMEA records. @@ -23,20 +22,20 @@ func CertificateToDANE(selector, matchingType uint8, cert *x509.Certificate) (st h := sha256.New() switch selector { case 0: - io.WriteString(h, string(cert.Raw)) + h.Write(cert.Raw) return hex.EncodeToString(h.Sum(nil)), nil case 1: - io.WriteString(h, string(cert.RawSubjectPublicKeyInfo)) + h.Write(cert.RawSubjectPublicKeyInfo) return hex.EncodeToString(h.Sum(nil)), nil } case 2: h := sha512.New() switch selector { case 0: - io.WriteString(h, string(cert.Raw)) + h.Write(cert.Raw) return hex.EncodeToString(h.Sum(nil)), nil case 1: - io.WriteString(h, string(cert.RawSubjectPublicKeyInfo)) + h.Write(cert.RawSubjectPublicKeyInfo) return hex.EncodeToString(h.Sum(nil)), nil } } diff --git a/vendor/github.com/miekg/dns/dns_test.go b/vendor/github.com/miekg/dns/dns_test.go index ad68533fd..dbfe25328 100644 --- a/vendor/github.com/miekg/dns/dns_test.go +++ b/vendor/github.com/miekg/dns/dns_test.go @@ -310,6 +310,23 @@ func TestMsgLengthCompressionMalformed(t *testing.T) { m.Len() // Should not crash. } +func TestMsgCompressLength2(t *testing.T) { + msg := new(Msg) + msg.Compress = true + msg.SetQuestion(Fqdn("bliep."), TypeANY) + msg.Answer = append(msg.Answer, &SRV{Hdr: RR_Header{Name: "blaat.", Rrtype: 0x21, Class: 0x1, Ttl: 0x3c}, Port: 0x4c57, Target: "foo.bar."}) + msg.Extra = append(msg.Extra, &A{Hdr: RR_Header{Name: "foo.bar.", Rrtype: 0x1, Class: 0x1, Ttl: 0x3c}, A: net.IP{0xac, 0x11, 0x0, 0x3}}) + predicted := msg.Len() + buf, err := msg.Pack() + if err != nil { + t.Error(err) + } + if predicted != len(buf) { + t.Errorf("predicted compressed length is wrong: predicted %s (len=%d) %d, actual %d", + msg.Question[0].Name, len(msg.Answer), predicted, len(buf)) + } +} + func TestToRFC3597(t *testing.T) { a, _ := NewRR("miek.nl. IN A 10.0.1.1") x := new(RFC3597) diff --git a/vendor/github.com/miekg/dns/dnssec.go b/vendor/github.com/miekg/dns/dnssec.go index f5f3fbdd8..07262011e 100644 --- a/vendor/github.com/miekg/dns/dnssec.go +++ b/vendor/github.com/miekg/dns/dnssec.go @@ -43,7 +43,7 @@ const ( PRIVATEOID uint8 = 254 ) -// Map for algorithm names. +// AlgorithmToString is a map of algorithm IDs to algorithm names. var AlgorithmToString = map[uint8]string{ RSAMD5: "RSAMD5", DH: "DH", @@ -61,10 +61,10 @@ var AlgorithmToString = map[uint8]string{ PRIVATEOID: "PRIVATEOID", } -// Map of algorithm strings. +// StringToAlgorithm is the reverse of AlgorithmToString. var StringToAlgorithm = reverseInt8(AlgorithmToString) -// Map of algorithm crypto hashes. +// AlgorithmToHash is a map of algorithm crypto hash IDs to crypto.Hash's. var AlgorithmToHash = map[uint8]crypto.Hash{ RSAMD5: crypto.MD5, // Deprecated in RFC 6725 RSASHA1: crypto.SHA1, @@ -85,7 +85,7 @@ const ( SHA512 // Experimental ) -// Map for hash names. +// HashToString is a map of hash IDs to names. var HashToString = map[uint8]string{ SHA1: "SHA1", SHA256: "SHA256", @@ -94,7 +94,7 @@ var HashToString = map[uint8]string{ SHA512: "SHA512", } -// Map of hash strings. +// StringToHash is a map of names to hash IDs. var StringToHash = reverseInt8(HashToString) // DNSKEY flag values. @@ -208,9 +208,6 @@ func (k *DNSKEY) ToDS(h uint8) *DS { // "|" denotes concatenation // DNSKEY RDATA = Flags | Protocol | Algorithm | Public Key. - // digest buffer - digest := append(owner, wire...) // another copy - var hash crypto.Hash switch h { case SHA1: @@ -226,7 +223,8 @@ func (k *DNSKEY) ToDS(h uint8) *DS { } s := hash.New() - s.Write(digest) + s.Write(owner) + s.Write(wire) ds.Digest = hex.EncodeToString(s.Sum(nil)) return ds } @@ -297,7 +295,6 @@ func (rr *RRSIG) Sign(k crypto.Signer, rrset []RR) error { if err != nil { return err } - signdata = append(signdata, wire...) hash, ok := AlgorithmToHash[rr.Algorithm] if !ok { @@ -306,6 +303,7 @@ func (rr *RRSIG) Sign(k crypto.Signer, rrset []RR) error { h := hash.New() h.Write(signdata) + h.Write(wire) signature, err := sign(k, h.Sum(nil), hash, rr.Algorithm) if err != nil { @@ -415,7 +413,6 @@ func (rr *RRSIG) Verify(k *DNSKEY, rrset []RR) error { if err != nil { return err } - signeddata = append(signeddata, wire...) sigbuf := rr.sigBuf() // Get the binary signature data if rr.Algorithm == PRIVATEDNS { // PRIVATEOID @@ -438,6 +435,7 @@ func (rr *RRSIG) Verify(k *DNSKEY, rrset []RR) error { h := hash.New() h.Write(signeddata) + h.Write(wire) return rsa.VerifyPKCS1v15(pubkey, hash, h.Sum(nil), sigbuf) case ECDSAP256SHA256, ECDSAP384SHA384: @@ -452,6 +450,7 @@ func (rr *RRSIG) Verify(k *DNSKEY, rrset []RR) error { h := hash.New() h.Write(signeddata) + h.Write(wire) if ecdsa.Verify(pubkey, h.Sum(nil), r, s) { return nil } diff --git a/vendor/github.com/miekg/dns/dnssec_keygen.go b/vendor/github.com/miekg/dns/dnssec_keygen.go index 229a07937..5e4b7741a 100644 --- a/vendor/github.com/miekg/dns/dnssec_keygen.go +++ b/vendor/github.com/miekg/dns/dnssec_keygen.go @@ -121,17 +121,17 @@ func (k *DNSKEY) setPublicKeyDSA(_Q, _P, _G, _Y *big.Int) bool { // RFC 3110: Section 2. RSA Public KEY Resource Records func exponentToBuf(_E int) []byte { var buf []byte - i := big.NewInt(int64(_E)) - if len(i.Bytes()) < 256 { - buf = make([]byte, 1) - buf[0] = uint8(len(i.Bytes())) + i := big.NewInt(int64(_E)).Bytes() + if len(i) < 256 { + buf = make([]byte, 1, 1+len(i)) + buf[0] = uint8(len(i)) } else { - buf = make([]byte, 3) + buf = make([]byte, 3, 3+len(i)) buf[0] = 0 - buf[1] = uint8(len(i.Bytes()) >> 8) - buf[2] = uint8(len(i.Bytes())) + buf[1] = uint8(len(i) >> 8) + buf[2] = uint8(len(i)) } - buf = append(buf, i.Bytes()...) + buf = append(buf, i...) return buf } diff --git a/vendor/github.com/miekg/dns/dnssec_keyscan.go b/vendor/github.com/miekg/dns/dnssec_keyscan.go index 9ff3a617e..4f8d830b8 100644 --- a/vendor/github.com/miekg/dns/dnssec_keyscan.go +++ b/vendor/github.com/miekg/dns/dnssec_keyscan.go @@ -36,7 +36,7 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (crypto.PrivateKey, er return nil, ErrPrivKey } // TODO(mg): check if the pubkey matches the private key - algo, err := strconv.Atoi(strings.SplitN(m["algorithm"], " ", 2)[0]) + algo, err := strconv.ParseUint(strings.SplitN(m["algorithm"], " ", 2)[0], 10, 8) if err != nil { return nil, ErrPrivKey } diff --git a/vendor/github.com/miekg/dns/edns.go b/vendor/github.com/miekg/dns/edns.go index 465b85f37..dbff3714c 100644 --- a/vendor/github.com/miekg/dns/edns.go +++ b/vendor/github.com/miekg/dns/edns.go @@ -157,7 +157,7 @@ type EDNS0 interface { String() string } -// The nsid EDNS0 option is used to retrieve a nameserver +// EDNS0_NSID option is used to retrieve a nameserver // identifier. When sending a request Nsid must be set to the empty string // The identifier is an opaque string encoded as hex. // Basic use pattern for creating an nsid option: @@ -197,7 +197,7 @@ func (e *EDNS0_NSID) String() string { return string(e.Nsid) } // e := new(dns.EDNS0_SUBNET) // e.Code = dns.EDNS0SUBNET // e.Family = 1 // 1 for IPv4 source address, 2 for IPv6 -// e.SourceNetMask = 32 // 32 for IPV4, 128 for IPv6 +// e.SourceNetmask = 32 // 32 for IPV4, 128 for IPv6 // e.SourceScope = 0 // e.Address = net.ParseIP("127.0.0.1").To4() // for IPv4 // // e.Address = net.ParseIP("2001:7b8:32a::2") // for IPV6 @@ -301,7 +301,7 @@ func (e *EDNS0_SUBNET) String() (s string) { return } -// The Cookie EDNS0 option +// The EDNS0_COOKIE option is used to add a DNS Cookie to a message. // // o := new(dns.OPT) // o.Hdr.Name = "." @@ -543,15 +543,15 @@ func (e *EDNS0_LOCAL) unpack(b []byte) error { return nil } +// EDNS0_TCP_KEEPALIVE is an EDNS0 option that instructs the server to keep +// the TCP connection alive. See RFC 7828. type EDNS0_TCP_KEEPALIVE struct { Code uint16 // Always EDNSTCPKEEPALIVE Length uint16 // the value 0 if the TIMEOUT is omitted, the value 2 if it is present; Timeout uint16 // an idle timeout value for the TCP connection, specified in units of 100 milliseconds, encoded in network byte order. } -func (e *EDNS0_TCP_KEEPALIVE) Option() uint16 { - return EDNS0TCPKEEPALIVE -} +func (e *EDNS0_TCP_KEEPALIVE) Option() uint16 { return EDNS0TCPKEEPALIVE } func (e *EDNS0_TCP_KEEPALIVE) pack() ([]byte, error) { if e.Timeout != 0 && e.Length != 2 { diff --git a/vendor/github.com/miekg/dns/idn/punycode.go b/vendor/github.com/miekg/dns/idn/punycode.go index 7e5c263fc..1d03bf6ae 100644 --- a/vendor/github.com/miekg/dns/idn/punycode.go +++ b/vendor/github.com/miekg/dns/idn/punycode.go @@ -242,11 +242,8 @@ func encode(input []byte) []byte { t, k, cp rune // weight and codepoint calculation ) - s := &bytes.Buffer{} for h := basiclen; h < fulllen; n, delta = n+1, delta+1 { nextltr = next(b, n) - s.Truncate(0) - s.WriteRune(nextltr) delta, n = delta+(nextltr-n)*rune(h+1), nextltr for _, ltr = range b { diff --git a/vendor/github.com/miekg/dns/msg.go b/vendor/github.com/miekg/dns/msg.go index 0d8cc6fb3..b5c074f05 100644 --- a/vendor/github.com/miekg/dns/msg.go +++ b/vendor/github.com/miekg/dns/msg.go @@ -9,6 +9,7 @@ package dns //go:generate go run msg_generate.go +//go:generate go run compress_generate.go import ( crand "crypto/rand" @@ -16,22 +17,9 @@ import ( "math/big" "math/rand" "strconv" + "sync" ) -func init() { - // Initialize default math/rand source using crypto/rand to provide better - // security without the performance trade-off. - buf := make([]byte, 8) - _, err := crand.Read(buf) - if err != nil { - // Failed to read from cryptographic source, fallback to default initial - // seed (1) by returning early - return - } - seed := binary.BigEndian.Uint64(buf) - rand.Seed(int64(seed)) -} - const maxCompressionOffset = 2 << 13 // We have 14 bits for the compression pointer var ( @@ -66,11 +54,45 @@ var ( // dns.Id = func() uint16 { return 3 } var Id func() uint16 = id +var ( + idLock sync.Mutex + idRand *rand.Rand +) + // id returns a 16 bits random number to be used as a // message id. The random provided should be good enough. func id() uint16 { - id32 := rand.Uint32() - return uint16(id32) + idLock.Lock() + + if idRand == nil { + // This (partially) works around + // https://github.com/golang/go/issues/11833 by only + // seeding idRand upon the first call to id. + + var seed int64 + var buf [8]byte + + if _, err := crand.Read(buf[:]); err == nil { + seed = int64(binary.LittleEndian.Uint64(buf[:])) + } else { + seed = rand.Int63() + } + + idRand = rand.New(rand.NewSource(seed)) + } + + // The call to idRand.Uint32 must be within the + // mutex lock because *rand.Rand is not safe for + // concurrent use. + // + // There is no added performance overhead to calling + // idRand.Uint32 inside a mutex lock over just + // calling rand.Uint32 as the global math/rand rng + // is internally protected by a sync.Mutex. + id := uint16(idRand.Uint32()) + + idLock.Unlock() + return id } // MsgHdr is a a manually-unpacked version of (id, bits). @@ -241,7 +263,9 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c bsFresh = true } // Don't try to compress '.' - if compress && roBs[begin:] != "." { + // We should only compress when compress it true, but we should also still pick + // up names that can be used for *future* compression(s). + if compression != nil && roBs[begin:] != "." { if p, ok := compression[roBs[begin:]]; !ok { // Only offsets smaller than this can be used. if offset < maxCompressionOffset { @@ -303,6 +327,7 @@ End: // UnpackDomainName unpacks a domain name into a string. func UnpackDomainName(msg []byte, off int) (string, int, error) { s := make([]byte, 0, 64) + labels := 0 off1 := 0 lenmsg := len(msg) ptr := 0 // number of pointers followed @@ -345,6 +370,15 @@ Loop: } } } + // never exceed the allowed label count lenght (63) + if labels >= 63 { + return "", lenmsg, &Error{err: "name exceeds 63 labels"} + } + labels += 1 + // never exceed the allowed doman name length (255 octets) + if len(s) >= 255 { + return "", lenmsg, &Error{err: "name exceeded allowed 255 octets"} + } s = append(s, '.') off += c case 0xC0: @@ -364,6 +398,9 @@ Loop: if ptr++; ptr > 10 { return "", lenmsg, &Error{err: "too many compression pointers"} } + // pointer should guarantee that it advances and points forwards at least + // but the condition on previous three lines guarantees that it's + // at least loop-free off = (c^0xC0)<<8 | int(c1) default: // 0x80 and 0x40 are reserved @@ -710,12 +747,10 @@ func (dns *Msg) PackBuffer(buf []byte) (msg []byte, err error) { // We need the uncompressed length here, because we first pack it and then compress it. msg = buf - compress := dns.Compress - dns.Compress = false - if packLen := dns.Len() + 1; len(msg) < packLen { + uncompressedLen := compressedLen(dns, false) + if packLen := uncompressedLen + 1; len(msg) < packLen { msg = make([]byte, packLen) } - dns.Compress = compress // Pack it in: header and then the pieces. off := 0 @@ -868,16 +903,18 @@ func (dns *Msg) String() string { // If dns.Compress is true compression it is taken into account. Len() // is provided to be a faster way to get the size of the resulting packet, // than packing it, measuring the size and discarding the buffer. -func (dns *Msg) Len() int { +func (dns *Msg) Len() int { return compressedLen(dns, dns.Compress) } + +// compressedLen returns the message length when in compressed wire format +// when compress is true, otherwise the uncompressed length is returned. +func compressedLen(dns *Msg, compress bool) int { // We always return one more than needed. l := 12 // Message header is always 12 bytes - var compression map[string]int - if dns.Compress { - compression = make(map[string]int) - } + compression := map[string]int{} + for i := 0; i < len(dns.Question); i++ { l += dns.Question[i].len() - if dns.Compress { + if compress { compressionLenHelper(compression, dns.Question[i].Name) } } @@ -886,7 +923,7 @@ func (dns *Msg) Len() int { continue } l += dns.Answer[i].len() - if dns.Compress { + if compress { k, ok := compressionLenSearch(compression, dns.Answer[i].Header().Name) if ok { l += 1 - k @@ -904,7 +941,7 @@ func (dns *Msg) Len() int { continue } l += dns.Ns[i].len() - if dns.Compress { + if compress { k, ok := compressionLenSearch(compression, dns.Ns[i].Header().Name) if ok { l += 1 - k @@ -922,7 +959,7 @@ func (dns *Msg) Len() int { continue } l += dns.Extra[i].len() - if dns.Compress { + if compress { k, ok := compressionLenSearch(compression, dns.Extra[i].Header().Name) if ok { l += 1 - k @@ -970,97 +1007,6 @@ func compressionLenSearch(c map[string]int, s string) (int, bool) { return 0, false } -// TODO(miek): should add all types, because the all can be *used* for compression. Autogenerate from msg_generate and put in zmsg.go -func compressionLenHelperType(c map[string]int, r RR) { - switch x := r.(type) { - case *NS: - compressionLenHelper(c, x.Ns) - case *MX: - compressionLenHelper(c, x.Mx) - case *CNAME: - compressionLenHelper(c, x.Target) - case *PTR: - compressionLenHelper(c, x.Ptr) - case *SOA: - compressionLenHelper(c, x.Ns) - compressionLenHelper(c, x.Mbox) - case *MB: - compressionLenHelper(c, x.Mb) - case *MG: - compressionLenHelper(c, x.Mg) - case *MR: - compressionLenHelper(c, x.Mr) - case *MF: - compressionLenHelper(c, x.Mf) - case *MD: - compressionLenHelper(c, x.Md) - case *RT: - compressionLenHelper(c, x.Host) - case *RP: - compressionLenHelper(c, x.Mbox) - compressionLenHelper(c, x.Txt) - case *MINFO: - compressionLenHelper(c, x.Rmail) - compressionLenHelper(c, x.Email) - case *AFSDB: - compressionLenHelper(c, x.Hostname) - case *SRV: - compressionLenHelper(c, x.Target) - case *NAPTR: - compressionLenHelper(c, x.Replacement) - case *RRSIG: - compressionLenHelper(c, x.SignerName) - case *NSEC: - compressionLenHelper(c, x.NextDomain) - // HIP? - } -} - -// Only search on compressing these types. -func compressionLenSearchType(c map[string]int, r RR) (int, bool) { - switch x := r.(type) { - case *NS: - return compressionLenSearch(c, x.Ns) - case *MX: - return compressionLenSearch(c, x.Mx) - case *CNAME: - return compressionLenSearch(c, x.Target) - case *DNAME: - return compressionLenSearch(c, x.Target) - case *PTR: - return compressionLenSearch(c, x.Ptr) - case *SOA: - k, ok := compressionLenSearch(c, x.Ns) - k1, ok1 := compressionLenSearch(c, x.Mbox) - if !ok && !ok1 { - return 0, false - } - return k + k1, true - case *MB: - return compressionLenSearch(c, x.Mb) - case *MG: - return compressionLenSearch(c, x.Mg) - case *MR: - return compressionLenSearch(c, x.Mr) - case *MF: - return compressionLenSearch(c, x.Mf) - case *MD: - return compressionLenSearch(c, x.Md) - case *RT: - return compressionLenSearch(c, x.Host) - case *MINFO: - k, ok := compressionLenSearch(c, x.Rmail) - k1, ok1 := compressionLenSearch(c, x.Email) - if !ok && !ok1 { - return 0, false - } - return k + k1, true - case *AFSDB: - return compressionLenSearch(c, x.Hostname) - } - return 0, false -} - // Copy returns a new RR which is a deep-copy of r. func Copy(r RR) RR { r1 := r.copy(); return r1 } diff --git a/vendor/github.com/miekg/dns/nsecx.go b/vendor/github.com/miekg/dns/nsecx.go index 6f10f3e65..51ce7f8b1 100644 --- a/vendor/github.com/miekg/dns/nsecx.go +++ b/vendor/github.com/miekg/dns/nsecx.go @@ -3,7 +3,6 @@ package dns import ( "crypto/sha1" "hash" - "io" "strings" ) @@ -36,15 +35,15 @@ func HashName(label string, ha uint8, iter uint16, salt string) string { } // k = 0 - name = append(name, wire...) - io.WriteString(s, string(name)) + s.Write(name) + s.Write(wire) nsec3 := s.Sum(nil) // k > 0 for k := uint16(0); k < iter; k++ { s.Reset() - nsec3 = append(nsec3, wire...) - io.WriteString(s, string(nsec3)) - nsec3 = s.Sum(nil) + s.Write(nsec3) + s.Write(wire) + nsec3 = s.Sum(nsec3[:0]) } return toBase32(nsec3) } diff --git a/vendor/github.com/miekg/dns/parse_test.go b/vendor/github.com/miekg/dns/parse_test.go index dc18b59ce..c727c1301 100644 --- a/vendor/github.com/miekg/dns/parse_test.go +++ b/vendor/github.com/miekg/dns/parse_test.go @@ -836,11 +836,7 @@ func TestSRVPacking(t *testing.T) { if err != nil { continue } - port := 8484 - tmp, err := strconv.Atoi(p) - if err == nil { - port = tmp - } + port, _ := strconv.ParseUint(p, 10, 16) rr := &SRV{ Hdr: RR_Header{Name: "somename.", diff --git a/vendor/github.com/miekg/dns/reverse.go b/vendor/github.com/miekg/dns/reverse.go index 099dac948..f6e7a47a6 100644 --- a/vendor/github.com/miekg/dns/reverse.go +++ b/vendor/github.com/miekg/dns/reverse.go @@ -6,10 +6,10 @@ var StringToType = reverseInt16(TypeToString) // StringToClass is the reverse of ClassToString, needed for string parsing. var StringToClass = reverseInt16(ClassToString) -// Map of opcodes strings. +// StringToOpcode is a map of opcodes to strings. var StringToOpcode = reverseInt(OpcodeToString) -// Map of rcodes strings. +// StringToRcode is a map of rcodes to strings. var StringToRcode = reverseInt(RcodeToString) // Reverse a map diff --git a/vendor/github.com/miekg/dns/scan.go b/vendor/github.com/miekg/dns/scan.go index d34597ba3..de0db32f8 100644 --- a/vendor/github.com/miekg/dns/scan.go +++ b/vendor/github.com/miekg/dns/scan.go @@ -819,8 +819,8 @@ func classToInt(token string) (uint16, bool) { if len(token) < offset+1 { return 0, false } - class, ok := strconv.Atoi(token[offset:]) - if ok != nil || class > maxUint16 { + class, err := strconv.ParseUint(token[offset:], 10, 16) + if err != nil { return 0, false } return uint16(class), true @@ -832,8 +832,8 @@ func typeToInt(token string) (uint16, bool) { if len(token) < offset+1 { return 0, false } - typ, ok := strconv.Atoi(token[offset:]) - if ok != nil || typ > maxUint16 { + typ, err := strconv.ParseUint(token[offset:], 10, 16) + if err != nil { return 0, false } return uint16(typ), true diff --git a/vendor/github.com/miekg/dns/scan_rr.go b/vendor/github.com/miekg/dns/scan_rr.go index 8d6a1bf24..f4c0d3767 100644 --- a/vendor/github.com/miekg/dns/scan_rr.go +++ b/vendor/github.com/miekg/dns/scan_rr.go @@ -447,7 +447,7 @@ func setMX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad MX Pref", l}, "" } @@ -476,7 +476,7 @@ func setRT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil { return nil, &ParseError{f, "bad RT Preference", l}, "" } @@ -506,7 +506,7 @@ func setAFSDB(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad AFSDB Subtype", l}, "" } @@ -551,7 +551,7 @@ func setKX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad KX Pref", l}, "" } @@ -665,7 +665,7 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.err { return nil, &ParseError{f, "bad SOA zone parameter", l}, "" } - if j, e := strconv.Atoi(l.token); e != nil { + if j, e := strconv.ParseUint(l.token, 10, 32); e != nil { if i == 0 { // Serial should be a number return nil, &ParseError{f, "bad SOA zone parameter", l}, "" @@ -705,21 +705,21 @@ func setSRV(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad SRV Priority", l}, "" } rr.Priority = uint16(i) <-c // zBlank l = <-c // zString - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad SRV Weight", l}, "" } rr.Weight = uint16(i) <-c // zBlank l = <-c // zString - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad SRV Port", l}, "" } @@ -749,14 +749,14 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad NAPTR Order", l}, "" } rr.Order = uint16(i) <-c // zBlank l = <-c // zString - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad NAPTR Preference", l}, "" } @@ -885,7 +885,7 @@ func setLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 32) if e != nil || l.err { return nil, &ParseError{f, "bad LOC Latitude", l}, "" } @@ -897,7 +897,7 @@ func setLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok { goto East } - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 32) if e != nil || l.err { return nil, &ParseError{f, "bad LOC Latitude minutes", l}, "" } @@ -923,7 +923,7 @@ East: // East <-c // zBlank l = <-c - if i, e := strconv.Atoi(l.token); e != nil || l.err { + if i, e := strconv.ParseUint(l.token, 10, 32); e != nil || l.err { return nil, &ParseError{f, "bad LOC Longitude", l}, "" } else { rr.Longitude = 1000 * 60 * 60 * uint32(i) @@ -934,7 +934,7 @@ East: if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok { goto Altitude } - if i, e := strconv.Atoi(l.token); e != nil || l.err { + if i, e := strconv.ParseUint(l.token, 10, 32); e != nil || l.err { return nil, &ParseError{f, "bad LOC Longitude minutes", l}, "" } else { rr.Longitude += 1000 * 60 * uint32(i) @@ -1016,7 +1016,7 @@ func setHIP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, l.comment } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad HIP PublicKeyAlgorithm", l}, "" } @@ -1077,14 +1077,14 @@ func setCERT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } if v, ok := StringToCertType[l.token]; ok { rr.Type = v - } else if i, e := strconv.Atoi(l.token); e != nil { + } else if i, e := strconv.ParseUint(l.token, 10, 16); e != nil { return nil, &ParseError{f, "bad CERT Type", l}, "" } else { rr.Type = uint16(i) } <-c // zBlank l = <-c // zString - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad CERT KeyTag", l}, "" } @@ -1093,7 +1093,7 @@ func setCERT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { l = <-c // zString if v, ok := StringToAlgorithm[l.token]; ok { rr.Algorithm = v - } else if i, e := strconv.Atoi(l.token); e != nil { + } else if i, e := strconv.ParseUint(l.token, 10, 8); e != nil { return nil, &ParseError{f, "bad CERT Algorithm", l}, "" } else { rr.Algorithm = uint8(i) @@ -1148,21 +1148,21 @@ func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } <-c // zBlank l = <-c - i, err := strconv.Atoi(l.token) + i, err := strconv.ParseUint(l.token, 10, 8) if err != nil || l.err { return nil, &ParseError{f, "bad RRSIG Algorithm", l}, "" } rr.Algorithm = uint8(i) <-c // zBlank l = <-c - i, err = strconv.Atoi(l.token) + i, err = strconv.ParseUint(l.token, 10, 8) if err != nil || l.err { return nil, &ParseError{f, "bad RRSIG Labels", l}, "" } rr.Labels = uint8(i) <-c // zBlank l = <-c - i, err = strconv.Atoi(l.token) + i, err = strconv.ParseUint(l.token, 10, 32) if err != nil || l.err { return nil, &ParseError{f, "bad RRSIG OrigTtl", l}, "" } @@ -1193,7 +1193,7 @@ func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } <-c // zBlank l = <-c - i, err = strconv.Atoi(l.token) + i, err = strconv.ParseUint(l.token, 10, 16) if err != nil || l.err { return nil, &ParseError{f, "bad RRSIG KeyTag", l}, "" } @@ -1274,21 +1274,21 @@ func setNSEC3(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, l.comment } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad NSEC3 Hash", l}, "" } rr.Hash = uint8(i) <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad NSEC3 Flags", l}, "" } rr.Flags = uint8(i) <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad NSEC3 Iterations", l}, "" } @@ -1342,21 +1342,21 @@ func setNSEC3PARAM(h RR_Header, c chan lex, o, f string) (RR, *ParseError, strin if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad NSEC3PARAM Hash", l}, "" } rr.Hash = uint8(i) <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad NSEC3PARAM Flags", l}, "" } rr.Flags = uint8(i) <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad NSEC3PARAM Iterations", l}, "" } @@ -1440,14 +1440,14 @@ func setSSHFP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad SSHFP Algorithm", l}, "" } rr.Algorithm = uint8(i) <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad SSHFP Type", l}, "" } @@ -1469,21 +1469,21 @@ func setDNSKEYs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, str if l.length == 0 { return rr, nil, l.comment } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad " + typ + " Flags", l}, "" } rr.Flags = uint16(i) <-c // zBlank l = <-c // zString - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad " + typ + " Protocol", l}, "" } rr.Protocol = uint8(i) <-c // zBlank l = <-c // zString - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad " + typ + " Algorithm", l}, "" } @@ -1525,21 +1525,21 @@ func setRKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, l.comment } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad RKEY Flags", l}, "" } rr.Flags = uint16(i) <-c // zBlank l = <-c // zString - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad RKEY Protocol", l}, "" } rr.Protocol = uint8(i) <-c // zBlank l = <-c // zString - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad RKEY Algorithm", l}, "" } @@ -1610,14 +1610,14 @@ func setDSs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, string) if l.length == 0 { return rr, nil, l.comment } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad " + typ + " KeyTag", l}, "" } rr.KeyTag = uint16(i) <-c // zBlank l = <-c - if i, e := strconv.Atoi(l.token); e != nil { + if i, e = strconv.ParseUint(l.token, 10, 8); e != nil { i, ok := StringToAlgorithm[l.tokenUpper] if !ok || l.err { return nil, &ParseError{f, "bad " + typ + " Algorithm", l}, "" @@ -1628,7 +1628,7 @@ func setDSs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, string) } <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad " + typ + " DigestType", l}, "" } @@ -1669,14 +1669,14 @@ func setTA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, l.comment } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad TA KeyTag", l}, "" } rr.KeyTag = uint16(i) <-c // zBlank l = <-c - if i, e := strconv.Atoi(l.token); e != nil { + if i, e := strconv.ParseUint(l.token, 10, 8); e != nil { i, ok := StringToAlgorithm[l.tokenUpper] if !ok || l.err { return nil, &ParseError{f, "bad TA Algorithm", l}, "" @@ -1687,7 +1687,7 @@ func setTA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad TA DigestType", l}, "" } @@ -1707,21 +1707,21 @@ func setTLSA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, l.comment } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad TLSA Usage", l}, "" } rr.Usage = uint8(i) <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad TLSA Selector", l}, "" } rr.Selector = uint8(i) <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad TLSA MatchingType", l}, "" } @@ -1742,21 +1742,21 @@ func setSMIMEA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, l.comment } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad SMIMEA Usage", l}, "" } rr.Usage = uint8(i) <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad SMIMEA Selector", l}, "" } rr.Selector = uint8(i) <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad SMIMEA MatchingType", l}, "" } @@ -1842,14 +1842,14 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad URI Priority", l}, "" } rr.Priority = uint16(i) <-c // zBlank l = <-c - i, e = strconv.Atoi(l.token) + i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad URI Weight", l}, "" } @@ -1888,7 +1888,7 @@ func setNID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad NID Preference", l}, "" } @@ -1911,7 +1911,7 @@ func setL32(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad L32 Preference", l}, "" } @@ -1933,7 +1933,7 @@ func setLP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad LP Preference", l}, "" } @@ -1966,7 +1966,7 @@ func setL64(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad L64 Preference", l}, "" } @@ -1988,7 +1988,7 @@ func setUID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 32) if e != nil || l.err { return nil, &ParseError{f, "bad UID Uid", l}, "" } @@ -2003,7 +2003,7 @@ func setGID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 32) if e != nil || l.err { return nil, &ParseError{f, "bad GID Gid", l}, "" } @@ -2033,7 +2033,7 @@ func setPX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, "" } - i, e := strconv.Atoi(l.token) + i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad PX Preference", l}, "" } @@ -2079,7 +2079,7 @@ func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if l.length == 0 { return rr, nil, l.comment } - i, err := strconv.Atoi(l.token) + i, err := strconv.ParseUint(l.token, 10, 8) if err != nil || l.err { return nil, &ParseError{f, "bad CAA Flag", l}, "" } diff --git a/vendor/github.com/miekg/dns/server_test.go b/vendor/github.com/miekg/dns/server_test.go index 098be2ebe..f17a2f90f 100644 --- a/vendor/github.com/miekg/dns/server_test.go +++ b/vendor/github.com/miekg/dns/server_test.go @@ -20,7 +20,7 @@ func HelloServer(w ResponseWriter, req *Msg) { w.WriteMsg(m) } -func HelloServerBadId(w ResponseWriter, req *Msg) { +func HelloServerBadID(w ResponseWriter, req *Msg) { m := new(Msg) m.SetReply(req) m.Id++ @@ -548,7 +548,7 @@ func TestHandlerCloseTCP(t *testing.T) { return } time.Sleep(time.Second / 10) - tries += 1 + tries++ goto exchange } }() diff --git a/vendor/github.com/miekg/dns/sig0.go b/vendor/github.com/miekg/dns/sig0.go index 2dce06af8..f31e9e684 100644 --- a/vendor/github.com/miekg/dns/sig0.go +++ b/vendor/github.com/miekg/dns/sig0.go @@ -60,16 +60,15 @@ func (rr *SIG) Sign(k crypto.Signer, m *Msg) ([]byte, error) { } rr.Signature = toBase64(signature) - sig := string(signature) - buf = append(buf, sig...) + buf = append(buf, signature...) if len(buf) > int(^uint16(0)) { return nil, ErrBuf } // Adjust sig data length rdoff := len(mbuf) + 1 + 2 + 2 + 4 rdlen := binary.BigEndian.Uint16(buf[rdoff:]) - rdlen += uint16(len(sig)) + rdlen += uint16(len(signature)) binary.BigEndian.PutUint16(buf[rdoff:], rdlen) // Adjust additional count adc := binary.BigEndian.Uint16(buf[10:]) diff --git a/vendor/github.com/miekg/dns/smimea.go b/vendor/github.com/miekg/dns/smimea.go index 3a4bb5700..4e7ded4b3 100644 --- a/vendor/github.com/miekg/dns/smimea.go +++ b/vendor/github.com/miekg/dns/smimea.go @@ -33,15 +33,15 @@ func (r *SMIMEA) Verify(cert *x509.Certificate) error { return ErrSig // ErrSig, really? } -// SIMEAName returns the ownername of a SMIMEA resource record as per the +// SMIMEAName returns the ownername of a SMIMEA resource record as per the // format specified in RFC 'draft-ietf-dane-smime-12' Section 2 and 3 -func SMIMEAName(email_address string, domain_name string) (string, error) { +func SMIMEAName(email, domain string) (string, error) { hasher := sha256.New() - hasher.Write([]byte(email_address)) + hasher.Write([]byte(email)) // RFC Section 3: "The local-part is hashed using the SHA2-256 // algorithm with the hash truncated to 28 octets and // represented in its hexadecimal representation to become the // left-most label in the prepared domain name" - return hex.EncodeToString(hasher.Sum(nil)[:28]) + "." + "_smimecert." + domain_name, nil + return hex.EncodeToString(hasher.Sum(nil)[:28]) + "." + "_smimecert." + domain, nil } diff --git a/vendor/github.com/miekg/dns/tsig.go b/vendor/github.com/miekg/dns/tsig.go index 78365e1c5..24013096b 100644 --- a/vendor/github.com/miekg/dns/tsig.go +++ b/vendor/github.com/miekg/dns/tsig.go @@ -9,7 +9,6 @@ import ( "encoding/binary" "encoding/hex" "hash" - "io" "strconv" "strings" "time" @@ -124,7 +123,7 @@ func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) ([]byte, s default: return nil, "", ErrKeyAlg } - io.WriteString(h, string(buf)) + h.Write(buf) t.MAC = hex.EncodeToString(h.Sum(nil)) t.MACSize = uint16(len(t.MAC) / 2) // Size is half! diff --git a/vendor/github.com/miekg/dns/types.go b/vendor/github.com/miekg/dns/types.go index c8b3191e5..c17251cb6 100644 --- a/vendor/github.com/miekg/dns/types.go +++ b/vendor/github.com/miekg/dns/types.go @@ -144,7 +144,7 @@ const ( OpcodeUpdate = 5 ) -// Headers is the wire format for the DNS packet header. +// Header is the wire format for the DNS packet header. type Header struct { Id uint16 Bits uint16 diff --git a/vendor/github.com/miekg/dns/types_generate.go b/vendor/github.com/miekg/dns/types_generate.go index bf80da329..dd1310942 100644 --- a/vendor/github.com/miekg/dns/types_generate.go +++ b/vendor/github.com/miekg/dns/types_generate.go @@ -197,7 +197,7 @@ func main() { case st.Tag(i) == "": switch st.Field(i).Type().(*types.Basic).Kind() { case types.Uint8: - o("l += 1 // %s\n") + o("l++ // %s\n") case types.Uint16: o("l += 2 // %s\n") case types.Uint32: diff --git a/vendor/github.com/miekg/dns/udp.go b/vendor/github.com/miekg/dns/udp.go index c79c6c883..af111b9a8 100644 --- a/vendor/github.com/miekg/dns/udp.go +++ b/vendor/github.com/miekg/dns/udp.go @@ -1,10 +1,9 @@ -// +build !windows,!plan9 +// +build !windows package dns import ( "net" - "syscall" ) // SessionUDP holds the remote address and the associated @@ -17,29 +16,6 @@ type SessionUDP struct { // RemoteAddr returns the remote network address. func (s *SessionUDP) RemoteAddr() net.Addr { return s.raddr } -// setUDPSocketOptions sets the UDP socket options. -// This function is implemented on a per platform basis. See udp_*.go for more details -func setUDPSocketOptions(conn *net.UDPConn) error { - sa, err := getUDPSocketName(conn) - if err != nil { - return err - } - switch sa.(type) { - case *syscall.SockaddrInet6: - v6only, err := getUDPSocketOptions6Only(conn) - if err != nil { - return err - } - setUDPSocketOptions6(conn) - if !v6only { - setUDPSocketOptions4(conn) - } - case *syscall.SockaddrInet4: - setUDPSocketOptions4(conn) - } - return nil -} - // ReadFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a // net.UDPAddr. func ReadFromSessionUDP(conn *net.UDPConn, b []byte) (int, *SessionUDP, error) { diff --git a/vendor/github.com/miekg/dns/udp_linux.go b/vendor/github.com/miekg/dns/udp_linux.go index 142a80073..033df4239 100644 --- a/vendor/github.com/miekg/dns/udp_linux.go +++ b/vendor/github.com/miekg/dns/udp_linux.go @@ -1,4 +1,4 @@ -// +build linux +// +build linux,!appengine package dns @@ -15,6 +15,29 @@ import ( "syscall" ) +// setUDPSocketOptions sets the UDP socket options. +// This function is implemented on a per platform basis. See udp_*.go for more details +func setUDPSocketOptions(conn *net.UDPConn) error { + sa, err := getUDPSocketName(conn) + if err != nil { + return err + } + switch sa.(type) { + case *syscall.SockaddrInet6: + v6only, err := getUDPSocketOptions6Only(conn) + if err != nil { + return err + } + setUDPSocketOptions6(conn) + if !v6only { + setUDPSocketOptions4(conn) + } + case *syscall.SockaddrInet4: + setUDPSocketOptions4(conn) + } + return nil +} + // setUDPSocketOptions4 prepares the v4 socket for sessions. func setUDPSocketOptions4(conn *net.UDPConn) error { file, err := conn.File() diff --git a/vendor/github.com/miekg/dns/udp_other.go b/vendor/github.com/miekg/dns/udp_other.go index d40732441..488a282b2 100644 --- a/vendor/github.com/miekg/dns/udp_other.go +++ b/vendor/github.com/miekg/dns/udp_other.go @@ -1,17 +1,15 @@ -// +build !linux,!plan9 +// +build !linux appengine package dns import ( "net" - "syscall" ) // These do nothing. See udp_linux.go for an example of how to implement this. // We tried to adhire to some kind of naming scheme. - +func setUDPSocketOptions(conn *net.UDPConn) error { return nil } func setUDPSocketOptions4(conn *net.UDPConn) error { return nil } func setUDPSocketOptions6(conn *net.UDPConn) error { return nil } func getUDPSocketOptions6Only(conn *net.UDPConn) (bool, error) { return false, nil } -func getUDPSocketName(conn *net.UDPConn) (syscall.Sockaddr, error) { return nil, nil } diff --git a/vendor/github.com/miekg/dns/udp_plan9.go b/vendor/github.com/miekg/dns/udp_plan9.go deleted file mode 100644 index b794deeba..000000000 --- a/vendor/github.com/miekg/dns/udp_plan9.go +++ /dev/null @@ -1,34 +0,0 @@ -package dns - -import ( - "net" -) - -func setUDPSocketOptions(conn *net.UDPConn) error { return nil } - -// SessionUDP holds the remote address and the associated -// out-of-band data. -type SessionUDP struct { - raddr *net.UDPAddr - context []byte -} - -// RemoteAddr returns the remote network address. -func (s *SessionUDP) RemoteAddr() net.Addr { return s.raddr } - -// ReadFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a -// net.UDPAddr. -func ReadFromSessionUDP(conn *net.UDPConn, b []byte) (int, *SessionUDP, error) { - oob := make([]byte, 40) - n, oobn, _, raddr, err := conn.ReadMsgUDP(b, oob) - if err != nil { - return n, nil, err - } - return n, &SessionUDP{raddr, oob[:oobn]}, err -} - -// WriteToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *SessionUDP instead of a net.Addr. -func WriteToSessionUDP(conn *net.UDPConn, b []byte, session *SessionUDP) (int, error) { - n, _, err := conn.WriteMsgUDP(b, session.context, session.raddr) - return n, err -} diff --git a/vendor/github.com/miekg/dns/udp_windows.go b/vendor/github.com/miekg/dns/udp_windows.go index 2ce4b3300..51e532ac2 100644 --- a/vendor/github.com/miekg/dns/udp_windows.go +++ b/vendor/github.com/miekg/dns/udp_windows.go @@ -8,6 +8,8 @@ type SessionUDP struct { raddr *net.UDPAddr } +func (s *SessionUDP) RemoteAddr() net.Addr { return s.raddr } + // ReadFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a // net.UDPAddr. func ReadFromSessionUDP(conn *net.UDPConn, b []byte) (int, *SessionUDP, error) { @@ -25,10 +27,3 @@ func WriteToSessionUDP(conn *net.UDPConn, b []byte, session *SessionUDP) (int, e return n, err } -func (s *SessionUDP) RemoteAddr() net.Addr { return s.raddr } - -// setUDPSocketOptions sets the UDP socket options. -// This function is implemented on a per platform basis. See udp_*.go for more details -func setUDPSocketOptions(conn *net.UDPConn) error { - return nil -} diff --git a/vendor/github.com/miekg/dns/update_test.go b/vendor/github.com/miekg/dns/update_test.go index 56602dfe9..12760a1ee 100644 --- a/vendor/github.com/miekg/dns/update_test.go +++ b/vendor/github.com/miekg/dns/update_test.go @@ -92,28 +92,28 @@ func TestPreReqAndRemovals(t *testing.T) { m.Id = 1234 // Use a full set of RRs each time, so we are sure the rdata is stripped. - rr_name1, _ := NewRR("name_used. 3600 IN A 127.0.0.1") - rr_name2, _ := NewRR("name_not_used. 3600 IN A 127.0.0.1") - rr_remove1, _ := NewRR("remove1. 3600 IN A 127.0.0.1") - rr_remove2, _ := NewRR("remove2. 3600 IN A 127.0.0.1") - rr_remove3, _ := NewRR("remove3. 3600 IN A 127.0.0.1") - rr_insert, _ := NewRR("insert. 3600 IN A 127.0.0.1") - rr_rrset1, _ := NewRR("rrset_used1. 3600 IN A 127.0.0.1") - rr_rrset2, _ := NewRR("rrset_used2. 3600 IN A 127.0.0.1") - rr_rrset3, _ := NewRR("rrset_not_used. 3600 IN A 127.0.0.1") + rrName1, _ := NewRR("name_used. 3600 IN A 127.0.0.1") + rrName2, _ := NewRR("name_not_used. 3600 IN A 127.0.0.1") + rrRemove1, _ := NewRR("remove1. 3600 IN A 127.0.0.1") + rrRemove2, _ := NewRR("remove2. 3600 IN A 127.0.0.1") + rrRemove3, _ := NewRR("remove3. 3600 IN A 127.0.0.1") + rrInsert, _ := NewRR("insert. 3600 IN A 127.0.0.1") + rrRrset1, _ := NewRR("rrset_used1. 3600 IN A 127.0.0.1") + rrRrset2, _ := NewRR("rrset_used2. 3600 IN A 127.0.0.1") + rrRrset3, _ := NewRR("rrset_not_used. 3600 IN A 127.0.0.1") // Handle the prereqs. - m.NameUsed([]RR{rr_name1}) - m.NameNotUsed([]RR{rr_name2}) - m.RRsetUsed([]RR{rr_rrset1}) - m.Used([]RR{rr_rrset2}) - m.RRsetNotUsed([]RR{rr_rrset3}) + m.NameUsed([]RR{rrName1}) + m.NameNotUsed([]RR{rrName2}) + m.RRsetUsed([]RR{rrRrset1}) + m.Used([]RR{rrRrset2}) + m.RRsetNotUsed([]RR{rrRrset3}) // and now the updates. - m.RemoveName([]RR{rr_remove1}) - m.RemoveRRset([]RR{rr_remove2}) - m.Remove([]RR{rr_remove3}) - m.Insert([]RR{rr_insert}) + m.RemoveName([]RR{rrRemove1}) + m.RemoveRRset([]RR{rrRemove2}) + m.Remove([]RR{rrRemove3}) + m.Insert([]RR{rrInsert}) // This test function isn't a Example function because we print these RR with tabs at the // end and the Example function trim these, thus they never match. diff --git a/vendor/github.com/miekg/dns/zcompress.go b/vendor/github.com/miekg/dns/zcompress.go new file mode 100644 index 000000000..86a31a916 --- /dev/null +++ b/vendor/github.com/miekg/dns/zcompress.go @@ -0,0 +1,119 @@ +// *** DO NOT MODIFY *** +// AUTOGENERATED BY go generate from compress_generate.go + +package dns + +func compressionLenHelperType(c map[string]int, r RR) { + switch x := r.(type) { + case *KX: + compressionLenHelper(c, x.Exchanger) + case *MX: + compressionLenHelper(c, x.Mx) + case *NSEC: + compressionLenHelper(c, x.NextDomain) + case *DNAME: + compressionLenHelper(c, x.Target) + case *HIP: + for i := range x.RendezvousServers { + compressionLenHelper(c, x.RendezvousServers[i]) + } + case *CNAME: + compressionLenHelper(c, x.Target) + case *MR: + compressionLenHelper(c, x.Mr) + case *PX: + compressionLenHelper(c, x.Map822) + compressionLenHelper(c, x.Mapx400) + case *SIG: + compressionLenHelper(c, x.SignerName) + case *SRV: + compressionLenHelper(c, x.Target) + case *TALINK: + compressionLenHelper(c, x.PreviousName) + compressionLenHelper(c, x.NextName) + case *LP: + compressionLenHelper(c, x.Fqdn) + case *NAPTR: + compressionLenHelper(c, x.Replacement) + case *NS: + compressionLenHelper(c, x.Ns) + case *RP: + compressionLenHelper(c, x.Mbox) + compressionLenHelper(c, x.Txt) + case *RRSIG: + compressionLenHelper(c, x.SignerName) + case *TKEY: + compressionLenHelper(c, x.Algorithm) + case *TSIG: + compressionLenHelper(c, x.Algorithm) + case *AFSDB: + compressionLenHelper(c, x.Hostname) + case *MF: + compressionLenHelper(c, x.Mf) + case *RT: + compressionLenHelper(c, x.Host) + case *MINFO: + compressionLenHelper(c, x.Rmail) + compressionLenHelper(c, x.Email) + case *PTR: + compressionLenHelper(c, x.Ptr) + case *SOA: + compressionLenHelper(c, x.Ns) + compressionLenHelper(c, x.Mbox) + case *MD: + compressionLenHelper(c, x.Md) + case *NSAPPTR: + compressionLenHelper(c, x.Ptr) + case *MG: + compressionLenHelper(c, x.Mg) + case *MB: + compressionLenHelper(c, x.Mb) + } +} + +func compressionLenSearchType(c map[string]int, r RR) (int, bool) { + switch x := r.(type) { + case *MF: + k1, ok1 := compressionLenSearch(c, x.Mf) + return k1, ok1 + case *MG: + k1, ok1 := compressionLenSearch(c, x.Mg) + return k1, ok1 + case *MINFO: + k1, ok1 := compressionLenSearch(c, x.Rmail) + k2, ok2 := compressionLenSearch(c, x.Email) + return k1 + k2, ok1 && ok2 + case *MR: + k1, ok1 := compressionLenSearch(c, x.Mr) + return k1, ok1 + case *PTR: + k1, ok1 := compressionLenSearch(c, x.Ptr) + return k1, ok1 + case *AFSDB: + k1, ok1 := compressionLenSearch(c, x.Hostname) + return k1, ok1 + case *CNAME: + k1, ok1 := compressionLenSearch(c, x.Target) + return k1, ok1 + case *MD: + k1, ok1 := compressionLenSearch(c, x.Md) + return k1, ok1 + case *RT: + k1, ok1 := compressionLenSearch(c, x.Host) + return k1, ok1 + case *SOA: + k1, ok1 := compressionLenSearch(c, x.Ns) + k2, ok2 := compressionLenSearch(c, x.Mbox) + return k1 + k2, ok1 && ok2 + case *MB: + k1, ok1 := compressionLenSearch(c, x.Mb) + return k1, ok1 + case *MX: + k1, ok1 := compressionLenSearch(c, x.Mx) + return k1, ok1 + case *NS: + k1, ok1 := compressionLenSearch(c, x.Ns) + return k1, ok1 + } + return 0, false +} diff --git a/vendor/github.com/miekg/dns/ztypes.go b/vendor/github.com/miekg/dns/ztypes.go index 3c052773e..311b8243b 100644 --- a/vendor/github.com/miekg/dns/ztypes.go +++ b/vendor/github.com/miekg/dns/ztypes.go @@ -254,7 +254,7 @@ func (rr *ANY) len() int { } func (rr *CAA) len() int { l := rr.Hdr.len() - l += 1 // Flag + l++ // Flag l += len(rr.Tag) + 1 l += len(rr.Value) return l @@ -263,7 +263,7 @@ func (rr *CERT) len() int { l := rr.Hdr.len() l += 2 // Type l += 2 // KeyTag - l += 1 // Algorithm + l++ // Algorithm l += base64.StdEncoding.DecodedLen(len(rr.Certificate)) return l } @@ -285,16 +285,16 @@ func (rr *DNAME) len() int { func (rr *DNSKEY) len() int { l := rr.Hdr.len() l += 2 // Flags - l += 1 // Protocol - l += 1 // Algorithm + l++ // Protocol + l++ // Algorithm l += base64.StdEncoding.DecodedLen(len(rr.PublicKey)) return l } func (rr *DS) len() int { l := rr.Hdr.len() l += 2 // KeyTag - l += 1 // Algorithm - l += 1 // DigestType + l++ // Algorithm + l++ // DigestType l += len(rr.Digest)/2 + 1 return l } @@ -333,8 +333,8 @@ func (rr *HINFO) len() int { } func (rr *HIP) len() int { l := rr.Hdr.len() - l += 1 // HitLength - l += 1 // PublicKeyAlgorithm + l++ // HitLength + l++ // PublicKeyAlgorithm l += 2 // PublicKeyLength l += len(rr.Hit)/2 + 1 l += base64.StdEncoding.DecodedLen(len(rr.PublicKey)) @@ -363,10 +363,10 @@ func (rr *L64) len() int { } func (rr *LOC) len() int { l := rr.Hdr.len() - l += 1 // Version - l += 1 // Size - l += 1 // HorizPre - l += 1 // VertPre + l++ // Version + l++ // Size + l++ // HorizPre + l++ // VertPre l += 4 // Latitude l += 4 // Longitude l += 4 // Altitude @@ -455,10 +455,10 @@ func (rr *NSAPPTR) len() int { } func (rr *NSEC3PARAM) len() int { l := rr.Hdr.len() - l += 1 // Hash - l += 1 // Flags + l++ // Hash + l++ // Flags l += 2 // Iterations - l += 1 // SaltLength + l++ // SaltLength l += len(rr.Salt)/2 + 1 return l } @@ -487,8 +487,8 @@ func (rr *RFC3597) len() int { func (rr *RKEY) len() int { l := rr.Hdr.len() l += 2 // Flags - l += 1 // Protocol - l += 1 // Algorithm + l++ // Protocol + l++ // Algorithm l += base64.StdEncoding.DecodedLen(len(rr.PublicKey)) return l } @@ -501,8 +501,8 @@ func (rr *RP) len() int { func (rr *RRSIG) len() int { l := rr.Hdr.len() l += 2 // TypeCovered - l += 1 // Algorithm - l += 1 // Labels + l++ // Algorithm + l++ // Labels l += 4 // OrigTtl l += 4 // Expiration l += 4 // Inception @@ -519,9 +519,9 @@ func (rr *RT) len() int { } func (rr *SMIMEA) len() int { l := rr.Hdr.len() - l += 1 // Usage - l += 1 // Selector - l += 1 // MatchingType + l++ // Usage + l++ // Selector + l++ // MatchingType l += len(rr.Certificate)/2 + 1 return l } @@ -553,16 +553,16 @@ func (rr *SRV) len() int { } func (rr *SSHFP) len() int { l := rr.Hdr.len() - l += 1 // Algorithm - l += 1 // Type + l++ // Algorithm + l++ // Type l += len(rr.FingerPrint)/2 + 1 return l } func (rr *TA) len() int { l := rr.Hdr.len() l += 2 // KeyTag - l += 1 // Algorithm - l += 1 // DigestType + l++ // Algorithm + l++ // DigestType l += len(rr.Digest)/2 + 1 return l } @@ -587,9 +587,9 @@ func (rr *TKEY) len() int { } func (rr *TLSA) len() int { l := rr.Hdr.len() - l += 1 // Usage - l += 1 // Selector - l += 1 // MatchingType + l++ // Usage + l++ // Selector + l++ // MatchingType l += len(rr.Certificate)/2 + 1 return l } |