diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-11-13 09:09:58 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-13 09:09:58 -0800 |
commit | 1329aa51b605cb54ba9aae3a82a0a87b881fb7b3 (patch) | |
tree | 93cbf354ab894a560fc2cef8ef685d681b4ff889 /vendor/github.com/miekg/dns | |
parent | 7304a61ef597970be3031b14e652fb3a4df44304 (diff) | |
download | chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.gz chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.bz2 chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.zip |
Updating server dependancies. (#7816)
Diffstat (limited to 'vendor/github.com/miekg/dns')
37 files changed, 634 insertions, 783 deletions
diff --git a/vendor/github.com/miekg/dns/.travis.yml b/vendor/github.com/miekg/dns/.travis.yml index bb8b8d40b..542dd68c0 100644 --- a/vendor/github.com/miekg/dns/.travis.yml +++ b/vendor/github.com/miekg/dns/.travis.yml @@ -1,14 +1,20 @@ language: go sudo: false go: - - 1.7.x - - 1.8.x + - 1.9.x - tip +env: + - TESTS="-race -v -bench=. -coverprofile=coverage.txt -covermode=atomic" + - TESTS="-race -v ./..." + before_install: # don't use the miekg/dns when testing forks - mkdir -p $GOPATH/src/github.com/miekg - ln -s $TRAVIS_BUILD_DIR $GOPATH/src/github.com/miekg/ || true script: - - go test -race -v -bench=. + - go test $TESTS + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/vendor/github.com/miekg/dns/README.md b/vendor/github.com/miekg/dns/README.md index 32a49cbf5..94b54fe25 100644 --- a/vendor/github.com/miekg/dns/README.md +++ b/vendor/github.com/miekg/dns/README.md @@ -1,19 +1,19 @@ [![Build Status](https://travis-ci.org/miekg/dns.svg?branch=master)](https://travis-ci.org/miekg/dns) +[![Code Coverage](https://img.shields.io/codecov/c/github/miekg/dns/master.svg)](https://codecov.io/github/miekg/dns?branch=master) +[![Go Report Card](https://goreportcard.com/badge/github.com/miekg/dns)](https://goreportcard.com/report/miekg/dns) [![](https://godoc.org/github.com/miekg/dns?status.svg)](https://godoc.org/github.com/miekg/dns) # Alternative (more granular) approach to a DNS library > Less is more. -Complete and usable DNS library. All widely used Resource Records are -supported, including the DNSSEC types. It follows a lean and mean philosophy. -If there is stuff you should know as a DNS programmer there isn't a convenience -function for it. Server side and client side programming is supported, i.e. you -can build servers and resolvers with it. +Complete and usable DNS library. All widely used Resource Records are supported, including the +DNSSEC types. It follows a lean and mean philosophy. If there is stuff you should know as a DNS +programmer there isn't a convenience function for it. Server side and client side programming is +supported, i.e. you can build servers and resolvers with it. -We try to keep the "master" branch as sane as possible and at the bleeding edge -of standards, avoiding breaking changes wherever reasonable. We support the last -two versions of Go, currently: 1.7 and 1.8. +We try to keep the "master" branch as sane as possible and at the bleeding edge of standards, +avoiding breaking changes wherever reasonable. We support the last two versions of Go. # Goals @@ -55,11 +55,13 @@ 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 +* http://kelda.io * https://github.com/ipdcode/hades (JD.COM) * https://github.com/StackExchange/dnscontrol/ * https://www.dnsperf.com/ * https://dnssectest.net/ +* https://dns.apebits.com +* https://github.com/oif/apex Send pull request if you want to be listed here. @@ -86,8 +88,8 @@ Miek Gieben - 2010-2012 - <miek@miek.nl> # Building -Building is done with the `go` tool. If you have setup your GOPATH -correctly, the following should work: +Building is done with the `go` tool. If you have setup your GOPATH correctly, the following should +work: go get github.com/miekg/dns go build github.com/miekg/dns @@ -150,9 +152,8 @@ Example programs can be found in the `github.com/miekg/exdns` repository. * 7314 - DNS (EDNS) EXPIRE Option * 7828 - edns-tcp-keepalive EDNS0 Option * 7553 - URI record -* 7858 - DNS over TLS: Initiation and Performance Considerations (draft) +* 7858 - DNS over TLS: Initiation and Performance Considerations * 7873 - Domain Name System (DNS) Cookies (draft-ietf-dnsop-cookies) -* xxxx - EDNS0 DNS Update Lease (draft) ## Loosely based upon diff --git a/vendor/github.com/miekg/dns/client.go b/vendor/github.com/miekg/dns/client.go index 359a0ab8f..0914482ab 100644 --- a/vendor/github.com/miekg/dns/client.go +++ b/vendor/github.com/miekg/dns/client.go @@ -78,6 +78,7 @@ func (c *Client) writeTimeout() time.Duration { return dnsTimeout } +// Dial connects to the address on the named network. func (c *Client) Dial(address string) (conn *Conn, err error) { // create a new dialer with the appropriate timeout var d net.Dialer @@ -454,8 +455,7 @@ func ExchangeConn(c net.Conn, m *Msg) (r *Msg, err error) { // DialTimeout acts like Dial but takes a timeout. func DialTimeout(network, address string, timeout time.Duration) (conn *Conn, err error) { - - client := Client{Net: "udp", Dialer: &net.Dialer{Timeout: timeout}} + client := Client{Net: network, Dialer: &net.Dialer{Timeout: timeout}} conn, err = client.Dial(address) if err != nil { return nil, err diff --git a/vendor/github.com/miekg/dns/client_test.go b/vendor/github.com/miekg/dns/client_test.go index 3ff619cfa..ef977aefc 100644 --- a/vendor/github.com/miekg/dns/client_test.go +++ b/vendor/github.com/miekg/dns/client_test.go @@ -6,6 +6,7 @@ import ( "fmt" "net" "strconv" + "strings" "sync" "testing" "time" @@ -15,7 +16,7 @@ func TestDialUDP(t *testing.T) { HandleFunc("miek.nl.", HelloServer) defer HandleRemove("miek.nl.") - s, addrstr, err := RunLocalUDPServer("[::1]:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -38,7 +39,7 @@ func TestClientSync(t *testing.T) { HandleFunc("miek.nl.", HelloServer) defer HandleRemove("miek.nl.") - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -72,7 +73,7 @@ func TestClientLocalAddress(t *testing.T) { HandleFunc("miek.nl.", HelloServerEchoAddrPort) defer HandleRemove("miek.nl.") - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -82,11 +83,11 @@ func TestClientLocalAddress(t *testing.T) { m.SetQuestion("miek.nl.", TypeSOA) c := new(Client) - laddr := net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 12345, Zone: ""} + laddr := net.UDPAddr{IP: net.ParseIP("0.0.0.0"), Port: 12345, Zone: ""} c.Dialer = &net.Dialer{LocalAddr: &laddr} r, _, err := c.Exchange(m, addrstr) if err != nil { - t.Errorf("failed to exchange: %v", err) + t.Fatalf("failed to exchange: %v", err) } if r != nil && r.Rcode != RcodeSuccess { t.Errorf("failed to get an valid answer\n%v", r) @@ -98,7 +99,7 @@ func TestClientLocalAddress(t *testing.T) { if txt == nil { t.Errorf("invalid TXT response\n%v", txt) } - if len(txt.Txt) != 1 || txt.Txt[0] != "127.0.0.1:12345" { + if len(txt.Txt) != 1 || !strings.Contains(txt.Txt[0], ":12345") { t.Errorf("invalid TXT response\n%v", txt.Txt) } } @@ -116,7 +117,7 @@ func TestClientTLSSyncV4(t *testing.T) { Certificates: []tls.Certificate{cert}, } - s, addrstr, err := RunLocalTLSServer("127.0.0.1:0", &config) + s, addrstr, err := RunLocalTLSServer(":0", &config) if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -162,70 +163,11 @@ func TestClientTLSSyncV4(t *testing.T) { } } -func TestClientTLSSyncV6(t *testing.T) { - HandleFunc("miek.nl.", HelloServer) - defer HandleRemove("miek.nl.") - - cert, err := tls.X509KeyPair(CertPEMBlock, KeyPEMBlock) - if err != nil { - t.Fatalf("unable to build certificate: %v", err) - } - - config := tls.Config{ - Certificates: []tls.Certificate{cert}, - } - - s, addrstr, err := RunLocalTLSServer("[::1]:0", &config) - if err != nil { - t.Fatalf("unable to run test server: %v", err) - } - defer s.Shutdown() - - m := new(Msg) - m.SetQuestion("miek.nl.", TypeSOA) - - c := new(Client) - - // test tcp-tls - c.Net = "tcp-tls" - c.TLSConfig = &tls.Config{ - InsecureSkipVerify: true, - } - - r, _, err := c.Exchange(m, addrstr) - if err != nil { - t.Fatalf("failed to exchange: %v", err) - } - if r == nil { - t.Fatal("response is nil") - } - if r.Rcode != RcodeSuccess { - t.Errorf("failed to get an valid answer\n%v", r) - } - - // test tcp6-tls - c.Net = "tcp6-tls" - c.TLSConfig = &tls.Config{ - InsecureSkipVerify: true, - } - - r, _, err = c.Exchange(m, addrstr) - if err != nil { - t.Fatalf("failed to exchange: %v", err) - } - if r == nil { - t.Fatal("response is nil") - } - if r.Rcode != RcodeSuccess { - t.Errorf("failed to get an valid answer\n%v", r) - } -} - func TestClientSyncBadID(t *testing.T) { HandleFunc("miek.nl.", HelloServerBadID) defer HandleRemove("miek.nl.") - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -248,7 +190,7 @@ func TestClientEDNS0(t *testing.T) { HandleFunc("miek.nl.", HelloServer) defer HandleRemove("miek.nl.") - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -295,7 +237,7 @@ func TestClientEDNS0Local(t *testing.T) { HandleFunc("miek.nl.", handler) defer HandleRemove("miek.nl.") - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { t.Fatalf("unable to run test server: %s", err) } @@ -321,7 +263,6 @@ func TestClientEDNS0Local(t *testing.T) { } if r.Rcode != RcodeSuccess { t.Fatal("failed to get a valid answer") - t.Logf("%v\n", r) } txt := r.Extra[0].(*TXT).Txt[0] @@ -333,41 +274,11 @@ func TestClientEDNS0Local(t *testing.T) { got := r.Extra[1].(*OPT).Option[0].(*EDNS0_LOCAL).String() if got != optStr1 { t.Errorf("failed to get local edns0 answer; got %s, expected %s", got, optStr1) - t.Logf("%v\n", r) } got = r.Extra[1].(*OPT).Option[1].(*EDNS0_LOCAL).String() if got != optStr2 { t.Errorf("failed to get local edns0 answer; got %s, expected %s", got, optStr2) - t.Logf("%v\n", r) - } -} - -// ExampleTsigSecret_updateLeaseTSIG shows how to update a lease signed with TSIG -func ExampleTsigSecret_updateLeaseTSIG() { - m := new(Msg) - m.SetUpdate("t.local.ip6.io.") - rr, _ := NewRR("t.local.ip6.io. 30 A 127.0.0.1") - rrs := make([]RR, 1) - rrs[0] = rr - m.Insert(rrs) - - leaseRr := new(OPT) - leaseRr.Hdr.Name = "." - leaseRr.Hdr.Rrtype = TypeOPT - e := new(EDNS0_UL) - e.Code = EDNS0UL - e.Lease = 120 - leaseRr.Option = append(leaseRr.Option, e) - m.Extra = append(m.Extra, leaseRr) - - c := new(Client) - m.SetTsig("polvi.", HmacMD5, 300, time.Now().Unix()) - c.TsigSecret = map[string]string{"polvi.": "pRZgBrBvI4NAHZYhxmhs/Q=="} - - _, _, err := c.Exchange(m, "127.0.0.1:53") - if err != nil { - panic(err) } } @@ -376,7 +287,7 @@ func TestClientConn(t *testing.T) { defer HandleRemove("miek.nl.") // This uses TCP just to make it slightly different than TestClientSync - s, addrstr, err := RunLocalTCPServer("127.0.0.1:0") + s, addrstr, err := RunLocalTCPServer(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -558,7 +469,7 @@ func TestTruncatedMsg(t *testing.T) { func TestTimeout(t *testing.T) { // Set up a dummy UDP server that won't respond - addr, err := net.ResolveUDPAddr("udp", "127.0.0.1:0") + addr, err := net.ResolveUDPAddr("udp", ":0") if err != nil { t.Fatalf("unable to resolve local udp address: %v", err) } @@ -614,7 +525,7 @@ func TestTimeout(t *testing.T) { length := time.Since(start) if length > allowable { - t.Errorf("exchange took longer (%v) than specified Timeout (%v)", length, timeout) + t.Errorf("exchange took longer %v than specified Timeout %v", length, allowable) } } @@ -640,7 +551,7 @@ func TestConcurrentExchanges(t *testing.T) { HandleFunc("miek.nl.", handler) defer HandleRemove("miek.nl.") - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { t.Fatalf("unable to run test server: %s", err) } @@ -673,8 +584,7 @@ func TestConcurrentExchanges(t *testing.T) { wg.Wait() if r[0] == r[1] { - t.Log("Got same response object, expected non-shared responses") - t.Fail() + t.Errorf("got same response, expected non-shared responses") } } } diff --git a/vendor/github.com/miekg/dns/clientconfig.go b/vendor/github.com/miekg/dns/clientconfig.go index 0a1f5a92c..6479fef93 100644 --- a/vendor/github.com/miekg/dns/clientconfig.go +++ b/vendor/github.com/miekg/dns/clientconfig.go @@ -2,6 +2,7 @@ package dns import ( "bufio" + "io" "os" "strconv" "strings" @@ -25,8 +26,13 @@ func ClientConfigFromFile(resolvconf string) (*ClientConfig, error) { return nil, err } defer file.Close() + return ClientConfigFromReader(file) +} + +// ClientConfigFromReader works like ClientConfigFromFile but takes an io.Reader as argument +func ClientConfigFromReader(resolvconf io.Reader) (*ClientConfig, error) { c := new(ClientConfig) - scanner := bufio.NewScanner(file) + scanner := bufio.NewScanner(resolvconf) c.Servers = make([]string, 0) c.Search = make([]string, 0) c.Port = "53" diff --git a/vendor/github.com/miekg/dns/clientconfig_test.go b/vendor/github.com/miekg/dns/clientconfig_test.go index 7755a8a6f..4c5d1fb60 100644 --- a/vendor/github.com/miekg/dns/clientconfig_test.go +++ b/vendor/github.com/miekg/dns/clientconfig_test.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "testing" ) @@ -20,6 +21,26 @@ nameserver 10.28.10.2 nameserver 11.28.10.1` // <- NOTE: NO newline. func testConfig(t *testing.T, data string) { + cc, err := ClientConfigFromReader(strings.NewReader(data)) + if err != nil { + t.Errorf("error parsing resolv.conf: %v", err) + } + if l := len(cc.Servers); l != 2 { + t.Errorf("incorrect number of nameservers detected: %d", l) + } + if l := len(cc.Search); l != 1 { + t.Errorf("domain directive not parsed correctly: %v", cc.Search) + } else { + if cc.Search[0] != "somedomain.com" { + t.Errorf("domain is unexpected: %v", cc.Search[0]) + } + } +} + +func TestNameserver(t *testing.T) { testConfig(t, normal) } +func TestMissingFinalNewLine(t *testing.T) { testConfig(t, missingNewline) } + +func TestReadFromFile(t *testing.T) { tempDir, err := ioutil.TempDir("", "") if err != nil { t.Fatalf("tempDir: %v", err) @@ -27,7 +48,7 @@ func testConfig(t *testing.T, data string) { defer os.RemoveAll(tempDir) path := filepath.Join(tempDir, "resolv.conf") - if err := ioutil.WriteFile(path, []byte(data), 0644); err != nil { + if err := ioutil.WriteFile(path, []byte(normal), 0644); err != nil { t.Fatalf("writeFile: %v", err) } cc, err := ClientConfigFromFile(path) @@ -46,9 +67,6 @@ 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, diff --git a/vendor/github.com/miekg/dns/compress_generate.go b/vendor/github.com/miekg/dns/compress_generate.go index 1a301e9f3..d2e5db26e 100644 --- a/vendor/github.com/miekg/dns/compress_generate.go +++ b/vendor/github.com/miekg/dns/compress_generate.go @@ -51,8 +51,9 @@ func main() { 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) + var domainTypes []string // Types that have a domain name in them (either compressible or not). + var cdomainTypes []string // Types that have a compressible domain name in them (subset of domainType) +Names: for _, name := range scope.Names() { o := scope.Lookup(name) if o == nil || !o.Exported() { @@ -73,21 +74,25 @@ func main() { 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 + domainTypes = append(domainTypes, o.Name()) + continue Names } if st.Tag(i) == `dns:"cdomain-name"` { - cdomainTypes[o.Name()] = true - domainTypes[o.Name()] = true + cdomainTypes = append(cdomainTypes, o.Name()) + domainTypes = append(domainTypes, o.Name()) + continue Names } continue } switch { case st.Tag(i) == `dns:"domain-name"`: - domainTypes[o.Name()] = true + domainTypes = append(domainTypes, o.Name()) + continue Names case st.Tag(i) == `dns:"cdomain-name"`: - cdomainTypes[o.Name()] = true - domainTypes[o.Name()] = true + cdomainTypes = append(cdomainTypes, o.Name()) + domainTypes = append(domainTypes, o.Name()) + continue Names } } } @@ -99,7 +104,7 @@ func main() { fmt.Fprint(b, "func compressionLenHelperType(c map[string]int, r RR) {\n") fmt.Fprint(b, "switch x := r.(type) {\n") - for name, _ := range domainTypes { + for _, name := range domainTypes { o := scope.Lookup(name) st, _ := getTypeStruct(o.Type(), scope) @@ -135,7 +140,7 @@ func main() { 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 { + for _, name := range cdomainTypes { o := scope.Lookup(name) st, _ := getTypeStruct(o.Type(), scope) diff --git a/vendor/github.com/miekg/dns/dns.go b/vendor/github.com/miekg/dns/dns.go index b3292287c..5133eac72 100644 --- a/vendor/github.com/miekg/dns/dns.go +++ b/vendor/github.com/miekg/dns/dns.go @@ -6,9 +6,12 @@ const ( year68 = 1 << 31 // For RFC1982 (Serial Arithmetic) calculations in 32 bits. defaultTtl = 3600 // Default internal TTL. - DefaultMsgSize = 4096 // DefaultMsgSize is the standard default for messages larger than 512 bytes. - MinMsgSize = 512 // MinMsgSize is the minimal size of a DNS packet. - MaxMsgSize = 65535 // MaxMsgSize is the largest possible DNS packet. + // DefaultMsgSize is the standard default for messages larger than 512 bytes. + DefaultMsgSize = 4096 + // MinMsgSize is the minimal size of a DNS packet. + MinMsgSize = 512 + // MaxMsgSize is the largest possible DNS packet. + MaxMsgSize = 65535 ) // Error represents a DNS error. diff --git a/vendor/github.com/miekg/dns/dns_bench_test.go b/vendor/github.com/miekg/dns/dns_bench_test.go index bccc3d540..7bf8bd211 100644 --- a/vendor/github.com/miekg/dns/dns_bench_test.go +++ b/vendor/github.com/miekg/dns/dns_bench_test.go @@ -17,7 +17,26 @@ func BenchmarkMsgLength(b *testing.B) { return msg } name1 := "12345678901234567890123456789012345.12345678.123." - rrMx, _ := NewRR(name1 + " 3600 IN MX 10 " + name1) + rrMx := testRR(name1 + " 3600 IN MX 10 " + name1) + msg := makeMsg(name1, []RR{rrMx, rrMx}, nil, nil) + b.StartTimer() + for i := 0; i < b.N; i++ { + msg.Len() + } +} + +func BenchmarkMsgLengthNoCompression(b *testing.B) { + b.StopTimer() + makeMsg := func(question string, ans, ns, e []RR) *Msg { + msg := new(Msg) + msg.SetQuestion(Fqdn(question), TypeANY) + msg.Answer = append(msg.Answer, ans...) + msg.Ns = append(msg.Ns, ns...) + msg.Extra = append(msg.Extra, e...) + return msg + } + name1 := "12345678901234567890123456789012345.12345678.123." + rrMx := testRR(name1 + " 3600 IN MX 10 " + name1) msg := makeMsg(name1, []RR{rrMx, rrMx}, nil, nil) b.StartTimer() for i := 0; i < b.N; i++ { @@ -36,7 +55,7 @@ func BenchmarkMsgLengthPack(b *testing.B) { return msg } name1 := "12345678901234567890123456789012345.12345678.123." - rrMx, _ := NewRR(name1 + " 3600 IN MX 10 " + name1) + rrMx := testRR(name1 + " 3600 IN MX 10 " + name1) msg := makeMsg(name1, []RR{rrMx, rrMx}, nil, nil) b.ResetTimer() for i := 0; i < b.N; i++ { @@ -77,11 +96,11 @@ func BenchmarkCopy(b *testing.B) { b.ReportAllocs() m := new(Msg) m.SetQuestion("miek.nl.", TypeA) - rr, _ := NewRR("miek.nl. 2311 IN A 127.0.0.1") + rr := testRR("miek.nl. 2311 IN A 127.0.0.1") m.Answer = []RR{rr} - rr, _ = NewRR("miek.nl. 2311 IN NS 127.0.0.1") + rr = testRR("miek.nl. 2311 IN NS 127.0.0.1") m.Ns = []RR{rr} - rr, _ = NewRR("miek.nl. 2311 IN A 127.0.0.1") + rr = testRR("miek.nl. 2311 IN A 127.0.0.1") m.Extra = []RR{rr} b.ResetTimer() @@ -139,7 +158,7 @@ func BenchmarkUnpackMX(b *testing.B) { } func BenchmarkPackAAAAA(b *testing.B) { - aaaa, _ := NewRR(". IN A ::1") + aaaa := testRR(". IN A ::1") buf := make([]byte, aaaa.len()) b.ReportAllocs() @@ -150,7 +169,7 @@ func BenchmarkPackAAAAA(b *testing.B) { } func BenchmarkUnpackAAAA(b *testing.B) { - aaaa, _ := NewRR(". IN A ::1") + aaaa := testRR(". IN A ::1") buf := make([]byte, aaaa.len()) PackRR(aaaa, buf, 0, nil, false) @@ -173,7 +192,7 @@ func BenchmarkPackMsg(b *testing.B) { return msg } name1 := "12345678901234567890123456789012345.12345678.123." - rrMx, _ := NewRR(name1 + " 3600 IN MX 10 " + name1) + rrMx := testRR(name1 + " 3600 IN MX 10 " + name1) msg := makeMsg(name1, []RR{rrMx, rrMx}, nil, nil) buf := make([]byte, 512) b.ReportAllocs() @@ -194,7 +213,7 @@ func BenchmarkUnpackMsg(b *testing.B) { return msg } name1 := "12345678901234567890123456789012345.12345678.123." - rrMx, _ := NewRR(name1 + " 3600 IN MX 10 " + name1) + rrMx := testRR(name1 + " 3600 IN MX 10 " + name1) msg := makeMsg(name1, []RR{rrMx, rrMx}, nil, nil) msgBuf, _ := msg.Pack() b.ReportAllocs() diff --git a/vendor/github.com/miekg/dns/dns_test.go b/vendor/github.com/miekg/dns/dns_test.go index 5568c316c..5835c13d5 100644 --- a/vendor/github.com/miekg/dns/dns_test.go +++ b/vendor/github.com/miekg/dns/dns_test.go @@ -126,60 +126,17 @@ func TestBailiwick(t *testing.T) { } } -func TestPack(t *testing.T) { - rr := []string{"US. 86400 IN NSEC 0-.us. NS SOA RRSIG NSEC DNSKEY TYPE65534"} - m := new(Msg) - var err error - m.Answer = make([]RR, 1) - for _, r := range rr { - m.Answer[0], err = NewRR(r) - if err != nil { - t.Errorf("failed to create RR: %v", err) - continue - } - if _, err := m.Pack(); err != nil { - t.Errorf("packing failed: %v", err) - } - } - x := new(Msg) - ns, _ := NewRR("pool.ntp.org. 390 IN NS a.ntpns.org") - ns.(*NS).Ns = "a.ntpns.org" - x.Ns = append(m.Ns, ns) - x.Ns = append(m.Ns, ns) - x.Ns = append(m.Ns, ns) - // This crashes due to the fact the a.ntpns.org isn't a FQDN - // How to recover() from a remove panic()? - if _, err := x.Pack(); err == nil { - t.Error("packing should fail") - } - x.Answer = make([]RR, 1) - x.Answer[0], err = NewRR(rr[0]) - if err != nil { - t.Fatal(err) - } - if _, err := x.Pack(); err == nil { - t.Error("packing should fail") - } - x.Question = make([]Question, 1) - x.Question[0] = Question{";sd#eddddséâèµââ
â¥âxzztsestxssweewwsssstx@s@Zåµe@cn.pool.ntp.org.", TypeA, ClassINET} - if _, err := x.Pack(); err == nil { - t.Error("packing should fail") - } -} - func TestPackNAPTR(t *testing.T) { for _, n := range []string{ `apple.com. IN NAPTR 100 50 "se" "SIP+D2U" "" _sip._udp.apple.com.`, `apple.com. IN NAPTR 90 50 "se" "SIP+D2T" "" _sip._tcp.apple.com.`, `apple.com. IN NAPTR 50 50 "se" "SIPS+D2T" "" _sips._tcp.apple.com.`, } { - rr, _ := NewRR(n) + rr := testRR(n) msg := make([]byte, rr.len()) if off, err := PackRR(rr, msg, 0, nil, false); err != nil { t.Errorf("packing failed: %v", err) t.Errorf("length %d, need more than %d", rr.len(), off) - } else { - t.Logf("buf size needed: %d", off) } } } @@ -207,8 +164,8 @@ func TestMsgCompressLength(t *testing.T) { } name1 := "12345678901234567890123456789012345.12345678.123." - rrA, _ := NewRR(name1 + " 3600 IN A 192.0.2.1") - rrMx, _ := NewRR(name1 + " 3600 IN MX 10 " + name1) + rrA := testRR(name1 + " 3600 IN A 192.0.2.1") + rrMx := testRR(name1 + " 3600 IN MX 10 " + name1) tests := []*Msg{ makeMsg(name1, []RR{rrA}, nil, nil), makeMsg(name1, []RR{rrMx, rrMx}, nil, nil)} @@ -237,8 +194,8 @@ func TestMsgLength(t *testing.T) { } name1 := "12345678901234567890123456789012345.12345678.123." - rrA, _ := NewRR(name1 + " 3600 IN A 192.0.2.1") - rrMx, _ := NewRR(name1 + " 3600 IN MX 10 " + name1) + rrA := testRR(name1 + " 3600 IN A 192.0.2.1") + rrMx := testRR(name1 + " 3600 IN MX 10 " + name1) tests := []*Msg{ makeMsg(name1, []RR{rrA}, nil, nil), makeMsg(name1, []RR{rrMx, rrMx}, nil, nil)} @@ -331,14 +288,14 @@ func TestMsgCompressLength2(t *testing.T) { } func TestToRFC3597(t *testing.T) { - a, _ := NewRR("miek.nl. IN A 10.0.1.1") + a := testRR("miek.nl. IN A 10.0.1.1") x := new(RFC3597) x.ToRFC3597(a) if x.String() != `miek.nl. 3600 CLASS1 TYPE1 \# 4 0a000101` { t.Errorf("string mismatch, got: %s", x) } - b, _ := NewRR("miek.nl. IN MX 10 mx.miek.nl.") + b := testRR("miek.nl. IN MX 10 mx.miek.nl.") x.ToRFC3597(b) if x.String() != `miek.nl. 3600 CLASS1 TYPE15 \# 14 000a026d78046d69656b026e6c00` { t.Errorf("string mismatch, got: %s", x) @@ -372,11 +329,9 @@ func TestNoRdataUnpack(t *testing.T) { t.Errorf("failed to pack RR: %v", err) continue } - rr, _, err := UnpackRR(data[:off], 0) - if err != nil { + if _, _, err := UnpackRR(data[:off], 0); err != nil { t.Errorf("failed to unpack RR with zero rdata: %s: %v", TypeToString[typ], err) } - t.Log(rr) } } @@ -397,7 +352,7 @@ func TestRdataOverflow(t *testing.T) { } func TestCopy(t *testing.T) { - rr, _ := NewRR("miek.nl. 2311 IN A 127.0.0.1") // Weird TTL to avoid catching TTL + rr := testRR("miek.nl. 2311 IN A 127.0.0.1") // Weird TTL to avoid catching TTL rr1 := Copy(rr) if rr.String() != rr1.String() { t.Fatalf("Copy() failed %s != %s", rr.String(), rr1.String()) @@ -407,9 +362,9 @@ func TestCopy(t *testing.T) { func TestMsgCopy(t *testing.T) { m := new(Msg) m.SetQuestion("miek.nl.", TypeA) - rr, _ := NewRR("miek.nl. 2311 IN A 127.0.0.1") + rr := testRR("miek.nl. 2311 IN A 127.0.0.1") m.Answer = []RR{rr} - rr, _ = NewRR("miek.nl. 2311 IN NS 127.0.0.1") + rr = testRR("miek.nl. 2311 IN NS 127.0.0.1") m.Ns = []RR{rr} m1 := m.Copy() @@ -417,12 +372,12 @@ func TestMsgCopy(t *testing.T) { t.Fatalf("Msg.Copy() failed %s != %s", m.String(), m1.String()) } - m1.Answer[0], _ = NewRR("somethingelse.nl. 2311 IN A 127.0.0.1") + m1.Answer[0] = testRR("somethingelse.nl. 2311 IN A 127.0.0.1") if m.String() == m1.String() { t.Fatalf("Msg.Copy() failed; change to copy changed template %s", m.String()) } - rr, _ = NewRR("miek.nl. 2311 IN A 127.0.0.2") + rr = testRR("miek.nl. 2311 IN A 127.0.0.2") m1.Answer = append(m1.Answer, rr) if m1.Ns[0].String() == m1.Answer[1].String() { t.Fatalf("Msg.Copy() failed; append changed underlying array %s", m1.Ns[0].String()) @@ -448,6 +403,5 @@ func TestMsgPackBuffer(t *testing.T) { t.Errorf("packet %d failed to unpack", i) continue } - t.Logf("packet %d %s", i, m.String()) } } diff --git a/vendor/github.com/miekg/dns/dnssec_test.go b/vendor/github.com/miekg/dns/dnssec_test.go index ca085ed3b..d5de439ba 100644 --- a/vendor/github.com/miekg/dns/dnssec_test.go +++ b/vendor/github.com/miekg/dns/dnssec_test.go @@ -35,57 +35,6 @@ func getSoa() *SOA { return soa } -func TestGenerateEC(t *testing.T) { - if testing.Short() { - t.Skip("skipping test in short mode.") - } - key := new(DNSKEY) - key.Hdr.Rrtype = TypeDNSKEY - key.Hdr.Name = "miek.nl." - key.Hdr.Class = ClassINET - key.Hdr.Ttl = 14400 - key.Flags = 256 - key.Protocol = 3 - key.Algorithm = ECDSAP256SHA256 - privkey, _ := key.Generate(256) - t.Log(key.String()) - t.Log(key.PrivateKeyString(privkey)) -} - -func TestGenerateDSA(t *testing.T) { - if testing.Short() { - t.Skip("skipping test in short mode.") - } - key := new(DNSKEY) - key.Hdr.Rrtype = TypeDNSKEY - key.Hdr.Name = "miek.nl." - key.Hdr.Class = ClassINET - key.Hdr.Ttl = 14400 - key.Flags = 256 - key.Protocol = 3 - key.Algorithm = DSA - privkey, _ := key.Generate(1024) - t.Log(key.String()) - t.Log(key.PrivateKeyString(privkey)) -} - -func TestGenerateRSA(t *testing.T) { - if testing.Short() { - t.Skip("skipping test in short mode.") - } - key := new(DNSKEY) - key.Hdr.Rrtype = TypeDNSKEY - key.Hdr.Name = "miek.nl." - key.Hdr.Class = ClassINET - key.Hdr.Ttl = 14400 - key.Flags = 256 - key.Protocol = 3 - key.Algorithm = RSASHA256 - privkey, _ := key.Generate(1024) - t.Log(key.String()) - t.Log(key.PrivateKeyString(privkey)) -} - func TestSecure(t *testing.T) { soa := getSoa() @@ -211,10 +160,9 @@ func TestSignVerify(t *testing.T) { continue } if err := sig.Verify(key, []RR{r}); err != nil { - t.Error("failure to validate") + t.Errorf("failure to validate: %s", r.Header().Name) continue } - t.Logf("validated: %s", r.Header().Name) } } @@ -248,9 +196,7 @@ func Test65534(t *testing.T) { } if err := sig.Verify(key, []RR{t6}); err != nil { t.Error(err) - t.Error("failure to validate") - } else { - t.Logf("validated: %s", t6.Header().Name) + t.Errorf("failure to validate %s", t6.Header().Name) } } @@ -381,7 +327,7 @@ Created: 20110302104537 Publish: 20110302104537 Activate: 20110302104537` - xk, _ := NewRR(pub) + xk := testRR(pub) k := xk.(*DNSKEY) p, err := k.NewPrivateKey(priv) if err != nil { @@ -432,10 +378,7 @@ func TestSignVerifyECDSA(t *testing.T) { Algorithm: 14 (ECDSAP384SHA384) PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR` - eckey, err := NewRR(pub) - if err != nil { - t.Fatal(err) - } + eckey := testRR(pub) privkey, err := eckey.(*DNSKEY).NewPrivateKey(priv) if err != nil { t.Fatal(err) @@ -448,7 +391,7 @@ PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR` if ds.Digest != "72d7b62976ce06438e9c0bf319013cf801f09ecc84b8d7e9495f27e305c6a9b0563a9b5f4d288405c3008a946df983d6" { t.Fatal("wrong DS Digest") } - a, _ := NewRR("www.example.net. 3600 IN A 192.0.2.1") + a := testRR("www.example.net. 3600 IN A 192.0.2.1") sig := new(RRSIG) sig.Hdr = RR_Header{"example.net.", TypeRRSIG, ClassINET, 14400, 0} sig.Expiration, _ = StringToTime("20100909102025") @@ -473,10 +416,7 @@ PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR` } func TestSignVerifyECDSA2(t *testing.T) { - srv1, err := NewRR("srv.miek.nl. IN SRV 1000 800 0 web1.miek.nl.") - if err != nil { - t.Fatal(err) - } + srv1 := testRR("srv.miek.nl. IN SRV 1000 800 0 web1.miek.nl.") srv := srv1.(*SRV) // With this key @@ -511,7 +451,7 @@ func TestSignVerifyECDSA2(t *testing.T) { err = sig.Verify(key, []RR{srv}) if err != nil { - t.Logf("failure to validate:\n%s\n%s\n%s\n\n%s\n\n%v", + t.Errorf("failure to validate:\n%s\n%s\n%s\n\n%s\n\n%v", key.String(), srv.String(), sig.String(), @@ -530,10 +470,7 @@ func TestRFC6605P256(t *testing.T) { exPriv := `Private-key-format: v1.2 Algorithm: 13 (ECDSAP256SHA256) PrivateKey: GU6SnQ/Ou+xC5RumuIUIuJZteXT2z0O/ok1s38Et6mQ=` - rrDNSKEY, err := NewRR(exDNSKEY) - if err != nil { - t.Fatal(err) - } + rrDNSKEY := testRR(exDNSKEY) priv, err := rrDNSKEY.(*DNSKEY).NewPrivateKey(exPriv) if err != nil { t.Fatal(err) @@ -542,10 +479,7 @@ PrivateKey: GU6SnQ/Ou+xC5RumuIUIuJZteXT2z0O/ok1s38Et6mQ=` exDS := `example.net. 3600 IN DS 55648 13 2 ( b4c8c1fe2e7477127b27115656ad6256f424625bf5c1 e2770ce6d6e37df61d17 )` - rrDS, err := NewRR(exDS) - if err != nil { - t.Fatal(err) - } + rrDS := testRR(exDS) ourDS := rrDNSKEY.(*DNSKEY).ToDS(SHA256) if !reflect.DeepEqual(ourDS, rrDS.(*DS)) { t.Errorf("DS record differs:\n%v\n%v", ourDS, rrDS.(*DS)) @@ -556,15 +490,9 @@ PrivateKey: GU6SnQ/Ou+xC5RumuIUIuJZteXT2z0O/ok1s38Et6mQ=` 20100909100439 20100812100439 55648 example.net. qx6wLYqmh+l9oCKTN6qIc+bw6ya+KJ8oMz0YP107epXA yGmt+3SNruPFKG7tZoLBLlUzGGus7ZwmwWep666VCw== )` - rrA, err := NewRR(exA) - if err != nil { - t.Fatal(err) - } - rrRRSIG, err := NewRR(exRRSIG) - if err != nil { - t.Fatal(err) - } - if err = rrRRSIG.(*RRSIG).Verify(rrDNSKEY.(*DNSKEY), []RR{rrA}); err != nil { + rrA := testRR(exA) + rrRRSIG := testRR(exRRSIG) + if err := rrRRSIG.(*RRSIG).Verify(rrDNSKEY.(*DNSKEY), []RR{rrA}); err != nil { t.Errorf("failure to validate the spec RRSIG: %v", err) } @@ -604,10 +532,7 @@ func TestRFC6605P384(t *testing.T) { exPriv := `Private-key-format: v1.2 Algorithm: 14 (ECDSAP384SHA384) PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR` - rrDNSKEY, err := NewRR(exDNSKEY) - if err != nil { - t.Fatal(err) - } + rrDNSKEY := testRR(exDNSKEY) priv, err := rrDNSKEY.(*DNSKEY).NewPrivateKey(exPriv) if err != nil { t.Fatal(err) @@ -617,10 +542,7 @@ PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR` 72d7b62976ce06438e9c0bf319013cf801f09ecc84b8 d7e9495f27e305c6a9b0563a9b5f4d288405c3008a94 6df983d6 )` - rrDS, err := NewRR(exDS) - if err != nil { - t.Fatal(err) - } + rrDS := testRR(exDS) ourDS := rrDNSKEY.(*DNSKEY).ToDS(SHA384) if !reflect.DeepEqual(ourDS, rrDS.(*DS)) { t.Fatalf("DS record differs:\n%v\n%v", ourDS, rrDS.(*DS)) @@ -632,11 +554,8 @@ PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR` /L5hDKIvGDyI1fcARX3z65qrmPsVz73QD1Mr5CEqOiLP 95hxQouuroGCeZOvzFaxsT8Glr74hbavRKayJNuydCuz WTSSPdz7wnqXL5bdcJzusdnI0RSMROxxwGipWcJm )` - rrA, err := NewRR(exA) - if err != nil { - t.Fatal(err) - } - rrRRSIG, err := NewRR(exRRSIG) + rrA := testRR(exA) + rrRRSIG := testRR(exRRSIG) if err != nil { t.Fatal(err) } diff --git a/vendor/github.com/miekg/dns/dnsutil/util.go b/vendor/github.com/miekg/dns/dnsutil/util.go index c8c6af7b3..76ac4de66 100644 --- a/vendor/github.com/miekg/dns/dnsutil/util.go +++ b/vendor/github.com/miekg/dns/dnsutil/util.go @@ -20,7 +20,9 @@ import ( func AddOrigin(s, origin string) string { // ("foo.", "origin.") -> "foo." (already a FQDN) // ("foo", "origin.") -> "foo.origin." - // ("foo"), "origin" -> "foo.origin" + // ("foo", "origin") -> "foo.origin" + // ("foo", ".") -> "foo." (Same as dns.Fqdn()) + // ("foo.", ".") -> "foo." (Same as dns.Fqdn()) // ("@", "origin.") -> "origin." (@ represents the apex (bare) domain) // ("", "origin.") -> "origin." (not obvious) // ("foo", "") -> "foo" (not obvious) @@ -34,32 +36,34 @@ func AddOrigin(s, origin string) string { if s == "@" || len(s) == 0 { return origin // Expand apex. } - if origin == "." { - return s + origin // AddOrigin(s, ".") is an expensive way to add a ".". + return dns.Fqdn(s) } return s + "." + origin // The simple case. } // TrimDomainName trims origin from s if s is a subdomain. -// This function will never return "", but returns "@" instead (@ represents the apex (bare) domain). +// This function will never return "", but returns "@" instead (@ represents the apex domain). func TrimDomainName(s, origin string) string { // An apex (bare) domain is always returned as "@". // If the return value ends in a ".", the domain was not the suffix. // origin can end in "." or not. Either way the results should be the same. if len(s) == 0 { - return "@" // Return the apex (@) rather than "". + return "@" } // Someone is using TrimDomainName(s, ".") to remove a dot if it exists. if origin == "." { return strings.TrimSuffix(s, origin) } - // Dude, you aren't even if the right subdomain! + original := s + s = dns.Fqdn(s) + origin = dns.Fqdn(origin) + if !dns.IsSubDomain(origin, s) { - return s + return original } slabels := dns.Split(s) diff --git a/vendor/github.com/miekg/dns/dnsutil/util_test.go b/vendor/github.com/miekg/dns/dnsutil/util_test.go index 0f1ecec8e..6754789bc 100644 --- a/vendor/github.com/miekg/dns/dnsutil/util_test.go +++ b/vendor/github.com/miekg/dns/dnsutil/util_test.go @@ -10,6 +10,8 @@ func TestAddOrigin(t *testing.T) { {"@", "example.com.", "example.com."}, {"foo", "example.com.", "foo.example.com."}, {"foo.", "example.com.", "foo."}, + {"example.com", ".", "example.com."}, + {"example.com.", ".", "example.com."}, // Oddball tests: // In general origin should not be "" or "." but at least // these tests verify we don't crash and will keep results @@ -26,16 +28,15 @@ func TestAddOrigin(t *testing.T) { for _, test := range tests { actual := AddOrigin(test.e1, test.e2) if test.expected != actual { - t.Errorf("AddOrigin(%#v, %#v) expected %#v, go %#v\n", test.e1, test.e2, test.expected, actual) + t.Errorf("AddOrigin(%#v, %#v) expected %#v, got %#v\n", test.e1, test.e2, test.expected, actual) } } } func TestTrimDomainName(t *testing.T) { - // Basic tests. // Try trimming "example.com" and "example.com." from typical use cases. - var tests_examplecom = []struct{ experiment, expected string }{ + testsEx := []struct{ experiment, expected string }{ {"foo.example.com", "foo"}, {"foo.example.com.", "foo"}, {".foo.example.com", ".foo"}, @@ -51,10 +52,10 @@ func TestTrimDomainName(t *testing.T) { {".foo.ronco.com.", ".foo.ronco.com."}, } for _, dom := range []string{"example.com", "example.com."} { - for i, test := range tests_examplecom { + for i, test := range testsEx { actual := TrimDomainName(test.experiment, dom) if test.expected != actual { - t.Errorf("%d TrimDomainName(%#v, %#v): expected (%v) got (%v)\n", i, test.experiment, dom, test.expected, actual) + t.Errorf("%d TrimDomainName(%#v, %#v): expected %v, got %v\n", i, test.experiment, dom, test.expected, actual) } } } @@ -63,7 +64,7 @@ func TestTrimDomainName(t *testing.T) { // These test shouldn't be needed but I was weary of off-by-one errors. // In theory, these can't happen because there are no single-letter TLDs, // but it is good to exercize the code this way. - var tests = []struct{ experiment, expected string }{ + tests := []struct{ experiment, expected string }{ {"", "@"}, {".", "."}, {"a.b.c.d.e.f.", "a.b.c.d.e"}, @@ -105,7 +106,7 @@ func TestTrimDomainName(t *testing.T) { for i, test := range tests { actual := TrimDomainName(test.experiment, dom) if test.expected != actual { - t.Errorf("%d TrimDomainName(%#v, %#v): expected (%v) got (%v)\n", i, test.experiment, dom, test.expected, actual) + t.Errorf("%d TrimDomainName(%#v, %#v): expected %v, got %v\n", i, test.experiment, dom, test.expected, actual) } } } @@ -114,17 +115,16 @@ func TestTrimDomainName(t *testing.T) { // These test cases provide both origin, s, and the expected result. // If you find a bug in the while, this is probably the easiest place // to add it as a test case. - var tests_wild = []struct{ e1, e2, expected string }{ + var testsWild = []struct{ e1, e2, expected string }{ {"mathoverflow.net.", ".", "mathoverflow.net"}, {"mathoverflow.net", ".", "mathoverflow.net"}, {"", ".", "@"}, {"@", ".", "@"}, } - for i, test := range tests_wild { + for i, test := range testsWild { actual := TrimDomainName(test.e1, test.e2) if test.expected != actual { - t.Errorf("%d TrimDomainName(%#v, %#v): expected (%v) got (%v)\n", i, test.e1, test.e2, test.expected, actual) + t.Errorf("%d TrimDomainName(%#v, %#v): expected %v, got %v\n", i, test.e1, test.e2, test.expected, actual) } } - } diff --git a/vendor/github.com/miekg/dns/doc.go b/vendor/github.com/miekg/dns/doc.go index ceabd24c1..26e288dfe 100644 --- a/vendor/github.com/miekg/dns/doc.go +++ b/vendor/github.com/miekg/dns/doc.go @@ -168,6 +168,11 @@ Basic use pattern when querying with a TSIG name "axfr." (note that these key na must be fully qualified - as they are domain names) and the base64 secret "so6ZGir4GPAqINNh9U5c3A==": +If an incoming message contains a TSIG record it MUST be the last record in +the additional section (RFC2845 3.2). This means that you should make the +call to SetTsig last, right before executing the query. If you make any +changes to the RRset after calling SetTsig() the signature will be incorrect. + c := new(dns.Client) c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="} m := new(dns.Msg) diff --git a/vendor/github.com/miekg/dns/edns.go b/vendor/github.com/miekg/dns/edns.go index 718842f28..a6a36bdf2 100644 --- a/vendor/github.com/miekg/dns/edns.go +++ b/vendor/github.com/miekg/dns/edns.go @@ -106,15 +106,12 @@ func (rr *OPT) SetVersion(v uint8) { // ExtendedRcode returns the EDNS extended RCODE field (the upper 8 bits of the TTL). func (rr *OPT) ExtendedRcode() int { - return int((rr.Hdr.Ttl&0xFF000000)>>24) + 15 + return int((rr.Hdr.Ttl & 0xFF000000) >> 24) } // SetExtendedRcode sets the EDNS extended RCODE field. func (rr *OPT) SetExtendedRcode(v uint8) { - if v < RcodeBadVers { // Smaller than 16.. Use the 4 bits you have! - return - } - rr.Hdr.Ttl = rr.Hdr.Ttl&0x00FFFFFF | (uint32(v-15) << 24) + rr.Hdr.Ttl = rr.Hdr.Ttl&0x00FFFFFF | (uint32(v) << 24) } // UDPSize returns the UDP buffer size. @@ -185,7 +182,8 @@ func (e *EDNS0_NSID) pack() ([]byte, error) { return h, nil } -func (e *EDNS0_NSID) Option() uint16 { return EDNS0NSID } +// Option implements the EDNS0 interface. +func (e *EDNS0_NSID) Option() uint16 { return EDNS0NSID } // Option returns the option code. func (e *EDNS0_NSID) unpack(b []byte) error { e.Nsid = hex.EncodeToString(b); return nil } func (e *EDNS0_NSID) String() string { return string(e.Nsid) } @@ -219,6 +217,7 @@ type EDNS0_SUBNET struct { DraftOption bool // Set to true if using the old (0x50fa) option code } +// Option implements the EDNS0 interface. func (e *EDNS0_SUBNET) Option() uint16 { if e.DraftOption { return EDNS0SUBNETDRAFT @@ -232,6 +231,12 @@ func (e *EDNS0_SUBNET) pack() ([]byte, error) { b[2] = e.SourceNetmask b[3] = e.SourceScope switch e.Family { + case 0: + // "dig" sets AddressFamily to 0 if SourceNetmask is also 0 + // We might don't need to complain either + if e.SourceNetmask != 0 { + return nil, errors.New("dns: bad address family") + } case 1: if e.SourceNetmask > net.IPv4len*8 { return nil, errors.New("dns: bad netmask") @@ -266,6 +271,13 @@ func (e *EDNS0_SUBNET) unpack(b []byte) error { e.SourceNetmask = b[2] e.SourceScope = b[3] switch e.Family { + case 0: + // "dig" sets AddressFamily to 0 if SourceNetmask is also 0 + // It's okay to accept such a packet + if e.SourceNetmask != 0 { + return errors.New("dns: bad address family") + } + e.Address = net.IPv4(0, 0, 0, 0) case 1: if e.SourceNetmask > net.IPv4len*8 || e.SourceScope > net.IPv4len*8 { return errors.New("dns: bad netmask") @@ -335,6 +347,7 @@ func (e *EDNS0_COOKIE) pack() ([]byte, error) { return h, nil } +// Option implements the EDNS0 interface. func (e *EDNS0_COOKIE) Option() uint16 { return EDNS0COOKIE } func (e *EDNS0_COOKIE) unpack(b []byte) error { e.Cookie = hex.EncodeToString(b); return nil } func (e *EDNS0_COOKIE) String() string { return e.Cookie } @@ -356,6 +369,7 @@ type EDNS0_UL struct { Lease uint32 } +// Option implements the EDNS0 interface. func (e *EDNS0_UL) Option() uint16 { return EDNS0UL } func (e *EDNS0_UL) String() string { return strconv.FormatUint(uint64(e.Lease), 10) } @@ -385,6 +399,7 @@ type EDNS0_LLQ struct { LeaseLife uint32 } +// Option implements the EDNS0 interface. func (e *EDNS0_LLQ) Option() uint16 { return EDNS0LLQ } func (e *EDNS0_LLQ) pack() ([]byte, error) { @@ -421,6 +436,7 @@ type EDNS0_DAU struct { AlgCode []uint8 } +// Option implements the EDNS0 interface. func (e *EDNS0_DAU) Option() uint16 { return EDNS0DAU } func (e *EDNS0_DAU) pack() ([]byte, error) { return e.AlgCode, nil } func (e *EDNS0_DAU) unpack(b []byte) error { e.AlgCode = b; return nil } @@ -442,6 +458,7 @@ type EDNS0_DHU struct { AlgCode []uint8 } +// Option implements the EDNS0 interface. func (e *EDNS0_DHU) Option() uint16 { return EDNS0DHU } func (e *EDNS0_DHU) pack() ([]byte, error) { return e.AlgCode, nil } func (e *EDNS0_DHU) unpack(b []byte) error { e.AlgCode = b; return nil } @@ -463,6 +480,7 @@ type EDNS0_N3U struct { AlgCode []uint8 } +// Option implements the EDNS0 interface. func (e *EDNS0_N3U) Option() uint16 { return EDNS0N3U } func (e *EDNS0_N3U) pack() ([]byte, error) { return e.AlgCode, nil } func (e *EDNS0_N3U) unpack(b []byte) error { e.AlgCode = b; return nil } @@ -485,6 +503,7 @@ type EDNS0_EXPIRE struct { Expire uint32 } +// Option implements the EDNS0 interface. func (e *EDNS0_EXPIRE) Option() uint16 { return EDNS0EXPIRE } func (e *EDNS0_EXPIRE) String() string { return strconv.FormatUint(uint64(e.Expire), 10) } @@ -523,6 +542,7 @@ type EDNS0_LOCAL struct { Data []byte } +// Option implements the EDNS0 interface. func (e *EDNS0_LOCAL) Option() uint16 { return e.Code } func (e *EDNS0_LOCAL) String() string { return strconv.FormatInt(int64(e.Code), 10) + ":0x" + hex.EncodeToString(e.Data) @@ -554,6 +574,7 @@ type EDNS0_TCP_KEEPALIVE struct { Timeout uint16 // an idle timeout value for the TCP connection, specified in units of 100 milliseconds, encoded in network byte order. } +// Option implements the EDNS0 interface. func (e *EDNS0_TCP_KEEPALIVE) Option() uint16 { return EDNS0TCPKEEPALIVE } func (e *EDNS0_TCP_KEEPALIVE) pack() ([]byte, error) { @@ -606,7 +627,8 @@ type EDNS0_PADDING struct { Padding []byte } -func (e *EDNS0_PADDING) pack() ([]byte, error) { return e.Padding, nil } +// Option implements the EDNS0 interface. func (e *EDNS0_PADDING) Option() uint16 { return EDNS0PADDING } +func (e *EDNS0_PADDING) pack() ([]byte, error) { return e.Padding, nil } func (e *EDNS0_PADDING) unpack(b []byte) error { e.Padding = b; return nil } func (e *EDNS0_PADDING) String() string { return fmt.Sprintf("%0X", e.Padding) } diff --git a/vendor/github.com/miekg/dns/edns_test.go b/vendor/github.com/miekg/dns/edns_test.go index c290b0c8a..f7cf15754 100644 --- a/vendor/github.com/miekg/dns/edns_test.go +++ b/vendor/github.com/miekg/dns/edns_test.go @@ -63,6 +63,6 @@ func TestOPTTtl(t *testing.T) { e.SetExtendedRcode(42) if e.ExtendedRcode() != 42 { - t.Errorf("set 42, expected %d, got %d", 42-15, e.ExtendedRcode()) + t.Errorf("set 42, expected %d, got %d", 42, e.ExtendedRcode()) } } diff --git a/vendor/github.com/miekg/dns/issue_test.go b/vendor/github.com/miekg/dns/issue_test.go index 265ad56c0..7299d3143 100644 --- a/vendor/github.com/miekg/dns/issue_test.go +++ b/vendor/github.com/miekg/dns/issue_test.go @@ -26,10 +26,7 @@ func TestTCPRtt(t *testing.T) { } func TestNSEC3MissingSalt(t *testing.T) { - rr, err := NewRR("ji6neoaepv8b5o6k4ev33abha8ht9fgc.example. NSEC3 1 1 12 aabbccdd K8UDEMVP1J2F7EG6JEBPS17VP3N8I58H") - if err != nil { - t.Fatalf("failed to parse example rr: %s", err) - } + rr := testRR("ji6neoaepv8b5o6k4ev33abha8ht9fgc.example. NSEC3 1 1 12 aabbccdd K8UDEMVP1J2F7EG6JEBPS17VP3N8I58H") m := new(Msg) m.Answer = []RR{rr} mb, err := m.Pack() @@ -47,10 +44,7 @@ func TestNSEC3MissingSalt(t *testing.T) { } func TestNSEC3MixedNextDomain(t *testing.T) { - rr, err := NewRR("ji6neoaepv8b5o6k4ev33abha8ht9fgc.example. NSEC3 1 1 12 - k8udemvp1j2f7eg6jebps17vp3n8i58h") - if err != nil { - t.Fatalf("failed to parse example rr: %s", err) - } + rr := testRR("ji6neoaepv8b5o6k4ev33abha8ht9fgc.example. NSEC3 1 1 12 - k8udemvp1j2f7eg6jebps17vp3n8i58h") m := new(Msg) m.Answer = []RR{rr} mb, err := m.Pack() diff --git a/vendor/github.com/miekg/dns/labels.go b/vendor/github.com/miekg/dns/labels.go index 9538d9c3a..760b89e71 100644 --- a/vendor/github.com/miekg/dns/labels.go +++ b/vendor/github.com/miekg/dns/labels.go @@ -1,7 +1,5 @@ package dns -import "strings" - // Holds a bunch of helper functions for dealing with labels. // SplitDomainName splits a name string into it's labels. @@ -44,7 +42,7 @@ func SplitDomainName(s string) (labels []string) { // CompareDomainName compares the names s1 and s2 and // returns how many labels they have in common starting from the *right*. -// The comparison stops at the first inequality. The names are not downcased +// The comparison stops at the first inequality. The names are downcased // before the comparison. // // www.miek.nl. and miek.nl. have two labels in common: miek and nl @@ -52,24 +50,21 @@ func SplitDomainName(s string) (labels []string) { // // s1 and s2 must be syntactically valid domain names. func CompareDomainName(s1, s2 string) (n int) { - s1, s2 = strings.ToLower(s1), strings.ToLower(s2) - s1 = Fqdn(s1) - s2 = Fqdn(s2) - l1 := Split(s1) - l2 := Split(s2) - // the first check: root label - if l1 == nil || l2 == nil { - return + if s1 == "." || s2 == "." { + return 0 } + l1 := Split(s1) + l2 := Split(s2) + j1 := len(l1) - 1 // end i1 := len(l1) - 2 // start j2 := len(l2) - 1 i2 := len(l2) - 2 // the second check can be done here: last/only label // before we fall through into the for-loop below - if s1[l1[j1]:] == s2[l2[j2]:] { + if equal(s1[l1[j1]:], s2[l2[j2]:]) { n++ } else { return @@ -78,7 +73,7 @@ func CompareDomainName(s1, s2 string) (n int) { if i1 < 0 || i2 < 0 { break } - if s1[l1[i1]:l1[j1]] == s2[l2[i2]:l2[j2]] { + if equal(s1[l1[i1]:l1[j1]], s2[l2[i2]:l2[j2]]) { n++ } else { break @@ -169,3 +164,28 @@ func PrevLabel(s string, n int) (i int, start bool) { } return lab[len(lab)-n], false } + +// equal compares a and b while ignoring case. It returns true when equal otherwise false. +func equal(a, b string) bool { + // might be lifted into API function. + la := len(a) + lb := len(b) + if la != lb { + return false + } + + for i := la - 1; i >= 0; i-- { + ai := a[i] + bi := b[i] + if ai >= 'A' && ai <= 'Z' { + ai |= ('a' - 'A') + } + if bi >= 'A' && bi <= 'Z' { + bi |= ('a' - 'A') + } + if ai != bi { + return false + } + } + return true +} diff --git a/vendor/github.com/miekg/dns/labels_test.go b/vendor/github.com/miekg/dns/labels_test.go index 9875d6cd9..d9bb556df 100644 --- a/vendor/github.com/miekg/dns/labels_test.go +++ b/vendor/github.com/miekg/dns/labels_test.go @@ -7,8 +7,8 @@ func TestCompareDomainName(t *testing.T) { s2 := "miek.nl." s3 := "www.bla.nl." s4 := "nl.www.bla." - s5 := "nl" - s6 := "miek.nl" + s5 := "nl." + s6 := "miek.nl." if CompareDomainName(s1, s2) != 2 { t.Errorf("%s with %s should be %d", s1, s2, 2) @@ -54,8 +54,6 @@ func TestSplit(t *testing.T) { for s, i := range splitter { if x := len(Split(s)); x != i { t.Errorf("labels should be %d, got %d: %s %v", i, x, s, Split(s)) - } else { - t.Logf("%s %v", s, Split(s)) } } } @@ -87,19 +85,19 @@ func TestPrevLabel(t *testing.T) { int } prever := map[prev]int{ - prev{"www.miek.nl.", 0}: 12, - prev{"www.miek.nl.", 1}: 9, - prev{"www.miek.nl.", 2}: 4, + {"www.miek.nl.", 0}: 12, + {"www.miek.nl.", 1}: 9, + {"www.miek.nl.", 2}: 4, - prev{"www.miek.nl", 0}: 11, - prev{"www.miek.nl", 1}: 9, - prev{"www.miek.nl", 2}: 4, + {"www.miek.nl", 0}: 11, + {"www.miek.nl", 1}: 9, + {"www.miek.nl", 2}: 4, - prev{"www.miek.nl.", 5}: 0, - prev{"www.miek.nl", 5}: 0, + {"www.miek.nl.", 5}: 0, + {"www.miek.nl", 5}: 0, - prev{"www.miek.nl.", 3}: 0, - prev{"www.miek.nl", 3}: 0, + {"www.miek.nl.", 3}: 0, + {"www.miek.nl", 3}: 0, } for s, i := range prever { x, ok := PrevLabel(s.string, s.int) @@ -176,28 +174,28 @@ func TestIsDomainName(t *testing.T) { func BenchmarkSplitLabels(b *testing.B) { for i := 0; i < b.N; i++ { - Split("www.example.com") + Split("www.example.com.") } } func BenchmarkLenLabels(b *testing.B) { for i := 0; i < b.N; i++ { - CountLabel("www.example.com") + CountLabel("www.example.com.") } } -func BenchmarkCompareLabels(b *testing.B) { +func BenchmarkCompareDomainName(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - CompareDomainName("www.example.com", "aa.example.com") + CompareDomainName("www.example.com.", "aa.example.com.") } } func BenchmarkIsSubDomain(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - IsSubDomain("www.example.com", "aa.example.com") - IsSubDomain("example.com", "aa.example.com") - IsSubDomain("miek.nl", "aa.example.com") + IsSubDomain("www.example.com.", "aa.example.com.") + IsSubDomain("example.com.", "aa.example.com.") + IsSubDomain("miek.nl.", "aa.example.com.") } } diff --git a/vendor/github.com/miekg/dns/msg.go b/vendor/github.com/miekg/dns/msg.go index 605fe6c5c..afce17635 100644 --- a/vendor/github.com/miekg/dns/msg.go +++ b/vendor/github.com/miekg/dns/msg.go @@ -26,6 +26,7 @@ const ( maxDomainNameWireOctets = 255 // See RFC 1035 section 2.3.4 ) +// Errors defined in this package. var ( ErrAlg error = &Error{err: "bad algorithm"} // ErrAlg indicates an error with the (DNSSEC) algorithm. ErrAuth error = &Error{err: "bad authentication"} // ErrAuth indicates an error in the TSIG authentication. @@ -57,7 +58,7 @@ var ( // For instance, to make it return a static value: // // dns.Id = func() uint16 { return 3 } -var Id func() uint16 = id +var Id = id var ( idLock sync.Mutex @@ -360,7 +361,7 @@ Loop: case '"', '\\': s = append(s, '\\', b) // presentation-format \X escapes add an extra byte - maxLen += 1 + maxLen++ default: if b < 32 || b >= 127 { // unprintable, use \DDD var buf [3]byte @@ -913,67 +914,55 @@ func (dns *Msg) Len() int { return compressedLen(dns, dns.Compress) } func compressedLen(dns *Msg, compress bool) int { // We always return one more than needed. l := 12 // Message header is always 12 bytes - compression := map[string]int{} - - for i := 0; i < len(dns.Question); i++ { - l += dns.Question[i].len() - if compress { - compressionLenHelper(compression, dns.Question[i].Name) + if compress { + compression := map[string]int{} + for _, r := range dns.Question { + l += r.len() + compressionLenHelper(compression, r.Name) } - } - for i := 0; i < len(dns.Answer); i++ { - if dns.Answer[i] == nil { - continue + l += compressionLenSlice(compression, dns.Answer) + l += compressionLenSlice(compression, dns.Ns) + l += compressionLenSlice(compression, dns.Extra) + } else { + for _, r := range dns.Question { + l += r.len() } - l += dns.Answer[i].len() - if compress { - k, ok := compressionLenSearch(compression, dns.Answer[i].Header().Name) - if ok { - l += 1 - k + for _, r := range dns.Answer { + if r != nil { + l += r.len() } - compressionLenHelper(compression, dns.Answer[i].Header().Name) - k, ok = compressionLenSearchType(compression, dns.Answer[i]) - if ok { - l += 1 - k - } - compressionLenHelperType(compression, dns.Answer[i]) - } - } - for i := 0; i < len(dns.Ns); i++ { - if dns.Ns[i] == nil { - continue } - l += dns.Ns[i].len() - if compress { - k, ok := compressionLenSearch(compression, dns.Ns[i].Header().Name) - if ok { - l += 1 - k + for _, r := range dns.Ns { + if r != nil { + l += r.len() } - compressionLenHelper(compression, dns.Ns[i].Header().Name) - k, ok = compressionLenSearchType(compression, dns.Ns[i]) - if ok { - l += 1 - k + } + for _, r := range dns.Extra { + if r != nil { + l += r.len() } - compressionLenHelperType(compression, dns.Ns[i]) } } - for i := 0; i < len(dns.Extra); i++ { - if dns.Extra[i] == nil { + return l +} + +func compressionLenSlice(c map[string]int, rs []RR) int { + var l int + for _, r := range rs { + if r == nil { continue } - l += dns.Extra[i].len() - if compress { - k, ok := compressionLenSearch(compression, dns.Extra[i].Header().Name) - if ok { - l += 1 - k - } - compressionLenHelper(compression, dns.Extra[i].Header().Name) - k, ok = compressionLenSearchType(compression, dns.Extra[i]) - if ok { - l += 1 - k - } - compressionLenHelperType(compression, dns.Extra[i]) + l += r.len() + k, ok := compressionLenSearch(c, r.Header().Name) + if ok { + l += 1 - k + } + compressionLenHelper(c, r.Header().Name) + k, ok = compressionLenSearchType(c, r) + if ok { + l += 1 - k } + compressionLenHelperType(c, r) } return l } diff --git a/vendor/github.com/miekg/dns/nsecx_test.go b/vendor/github.com/miekg/dns/nsecx_test.go index 8d5f71797..f8edd6db1 100644 --- a/vendor/github.com/miekg/dns/nsecx_test.go +++ b/vendor/github.com/miekg/dns/nsecx_test.go @@ -15,7 +15,7 @@ func TestPackNsec3(t *testing.T) { } func TestNsec3(t *testing.T) { - nsec3, _ := NewRR("sk4e8fj94u78smusb40o1n0oltbblu2r.nl. IN NSEC3 1 1 5 F10E9F7EA83FC8F3 SK4F38CQ0ATIEI8MH3RGD0P5I4II6QAN NS SOA TXT RRSIG DNSKEY NSEC3PARAM") + nsec3 := testRR("sk4e8fj94u78smusb40o1n0oltbblu2r.nl. IN NSEC3 1 1 5 F10E9F7EA83FC8F3 SK4F38CQ0ATIEI8MH3RGD0P5I4II6QAN NS SOA TXT RRSIG DNSKEY NSEC3PARAM") if !nsec3.(*NSEC3).Match("nl.") { // name hash = sk4e8fj94u78smusb40o1n0oltbblu2r t.Fatal("sk4e8fj94u78smusb40o1n0oltbblu2r.nl. should match sk4e8fj94u78smusb40o1n0oltbblu2r.nl.") } @@ -28,7 +28,7 @@ func TestNsec3(t *testing.T) { if nsec3.(*NSEC3).Match("test.nl.") { // name hash = gd0ptr5bnfpimpu2d3v6gd4n0bai7s0q t.Fatal("gd0ptr5bnfpimpu2d3v6gd4n0bai7s0q.nl. should not match sk4e8fj94u78smusb40o1n0oltbblu2r.nl.") } - nsec3, _ = NewRR("nl. IN NSEC3 1 1 5 F10E9F7EA83FC8F3 SK4F38CQ0ATIEI8MH3RGD0P5I4II6QAN NS SOA TXT RRSIG DNSKEY NSEC3PARAM") + nsec3 = testRR("nl. IN NSEC3 1 1 5 F10E9F7EA83FC8F3 SK4F38CQ0ATIEI8MH3RGD0P5I4II6QAN NS SOA TXT RRSIG DNSKEY NSEC3PARAM") if nsec3.(*NSEC3).Match("nl.") { t.Fatal("sk4e8fj94u78smusb40o1n0oltbblu2r.nl. should not match a record without a owner hash") } @@ -127,7 +127,7 @@ func TestNsec3(t *testing.T) { } { covers := tc.rr.Cover(tc.name) if tc.covers != covers { - t.Fatalf("Cover failed for %s: expected %t, got %t [record: %s]", tc.name, tc.covers, covers, tc.rr) + t.Fatalf("cover failed for %s: expected %t, got %t [record: %s]", tc.name, tc.covers, covers, tc.rr) } } } diff --git a/vendor/github.com/miekg/dns/parse_test.go b/vendor/github.com/miekg/dns/parse_test.go index c7ecb499d..e7ffd4084 100644 --- a/vendor/github.com/miekg/dns/parse_test.go +++ b/vendor/github.com/miekg/dns/parse_test.go @@ -13,7 +13,6 @@ import ( "strings" "testing" "testing/quick" - "time" ) func TestDotInName(t *testing.T) { @@ -53,14 +52,10 @@ func TestTooLongDomainName(t *testing.T) { _, err := NewRR(dom + " IN A 127.0.0.1") if err == nil { t.Error("should be too long") - } else { - t.Logf("error is %v", err) } _, err = NewRR("..com. IN A 127.0.0.1") if err == nil { t.Error("should fail") - } else { - t.Logf("error is %v", err) } } @@ -103,23 +98,14 @@ func TestDomainNameAndTXTEscapes(t *testing.T) { s := rr1.String() rr2, err := NewRR(s) if err != nil { - t.Errorf("Error parsing unpacked RR's string: %v", err) - t.Errorf(" Bytes: %v", rrbytes) - t.Errorf("String: %v", s) + t.Errorf("error parsing unpacked RR's string: %v", err) } repacked := make([]byte, len(rrbytes)) if _, err := PackRR(rr2, repacked, 0, nil, false); err != nil { t.Errorf("error packing parsed RR: %v", err) - t.Errorf(" original Bytes: %v", rrbytes) - t.Errorf("unpacked Struct: %v", rr1) - t.Errorf(" parsed Struct: %v", rr2) } if !bytes.Equal(repacked, rrbytes) { t.Error("packed bytes don't match original bytes") - t.Errorf(" original bytes: %v", rrbytes) - t.Errorf(" packed bytes: %v", repacked) - t.Errorf("unpacked struct: %v", rr1) - t.Errorf(" parsed struct: %v", rr2) } } } @@ -349,8 +335,6 @@ func TestParseDirectiveMisc(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -372,8 +356,6 @@ func TestNSEC(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -391,8 +373,6 @@ func TestParseLOC(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -409,8 +389,6 @@ func TestParseDS(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -443,8 +421,6 @@ func TestQuotes(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is\n`%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -466,8 +442,6 @@ func TestParseClass(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is\n`%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -517,8 +491,6 @@ func TestBrace(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -544,34 +516,6 @@ func TestParseFailure(t *testing.T) { } } -func TestZoneParsing(t *testing.T) { - // parse_test.db - db := ` -a.example.com. IN A 127.0.0.1 -8db7._openpgpkey.example.com. IN OPENPGPKEY mQCNAzIG -$ORIGIN a.example.com. -test IN A 127.0.0.1 - IN SSHFP 1 2 ( - BC6533CDC95A79078A39A56EA7635984ED655318ADA9 - B6159E30723665DA95BB ) -$ORIGIN b.example.com. -test IN CNAME test.a.example.com. -` - start := time.Now().UnixNano() - to := ParseZone(strings.NewReader(db), "", "parse_test.db") - var i int - for x := range to { - i++ - if x.Error != nil { - t.Error(x.Error) - continue - } - t.Log(x.RR) - } - delta := time.Now().UnixNano() - start - t.Logf("%d RRs parsed in %.2f s (%.2f RR/s)", i, float32(delta)/1e9, float32(i)/(float32(delta)/1e9)) -} - func TestOmittedTTL(t *testing.T) { zone := ` $ORIGIN example.com. @@ -667,7 +611,6 @@ b1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D if err != nil { t.Fatalf("failed to parse RR: %v", err) } - t.Logf("RR: %s", rr) msg := new(Msg) msg.Answer = []RR{rr, rr} bytes, err := msg.Pack() @@ -682,7 +625,6 @@ b1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D } for i, rr := range msg.Answer { rr := rr.(*HIP) - t.Logf("RR: %s", rr) if l := len(rr.RendezvousServers); l != 2 { t.Fatalf("2 servers expected, only %d in record %d:\n%v", l, i, msg) } @@ -827,20 +769,14 @@ func TestSRVPacking(t *testing.T) { } func TestParseBackslash(t *testing.T) { - if r, err := NewRR("nul\\000gap.test.globnix.net. 600 IN A 192.0.2.10"); err != nil { + if _, err := NewRR("nul\\000gap.test.globnix.net. 600 IN A 192.0.2.10"); err != nil { t.Errorf("could not create RR with \\000 in it") - } else { - t.Logf("parsed %s", r.String()) } - if r, err := NewRR(`nul\000gap.test.globnix.net. 600 IN TXT "Hello\123"`); err != nil { + if _, err := NewRR(`nul\000gap.test.globnix.net. 600 IN TXT "Hello\123"`); err != nil { t.Errorf("could not create RR with \\000 in it") - } else { - t.Logf("parsed %s", r.String()) } - if r, err := NewRR(`m\ @\ iek.nl. IN 3600 A 127.0.0.1`); err != nil { + if _, err := NewRR(`m\ @\ iek.nl. IN 3600 A 127.0.0.1`); err != nil { t.Errorf("could not create RR with \\ and \\@ in it") - } else { - t.Logf("parsed %s", r.String()) } } @@ -887,8 +823,6 @@ func TestGposEidNimloc(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -906,8 +840,6 @@ func TestPX(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -1053,7 +985,6 @@ func TestTXT(t *testing.T) { if rr.(*TXT).Txt[1] != "b" { t.Errorf("Txt should have two chunk, last one my be 'b', but is %s", rr.(*TXT).Txt[1]) } - t.Log(rr.String()) } func TestTypeXXXX(t *testing.T) { @@ -1095,7 +1026,6 @@ func TestDigit(t *testing.T) { t.Fatalf("failed to parse %v", err) } PackRR(r, buf, 0, nil, false) - t.Log(buf) if buf[5] != i { t.Fatalf("5 pos must be %d, is %d", i, buf[5]) } @@ -1128,7 +1058,6 @@ func TestTxtEqual(t *testing.T) { // This is not an error, but keep this test. t.Errorf("these two TXT records should match:\n%s\n%s", rr1.String(), rr2.String()) } - t.Logf("%s\n%s", rr1.String(), rr2.String()) } func TestTxtLong(t *testing.T) { @@ -1155,12 +1084,8 @@ func TestMalformedPackets(t *testing.T) { // com = 63 6f 6d for _, packet := range packets { data, _ := hex.DecodeString(packet) - // for _, v := range data { - // t.Log(v) - // } var msg Msg msg.Unpack(data) - // println(msg.String()) } } @@ -1317,7 +1242,6 @@ func TestParseTokenOverflow(t *testing.T) { if err == nil { t.Fatalf("token overflow should return an error") } - t.Logf("err: %s\n", err) } func TestParseTLSA(t *testing.T) { @@ -1334,8 +1258,6 @@ func TestParseTLSA(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", o, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -1355,8 +1277,6 @@ func TestParseSMIMEA(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", o, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -1377,8 +1297,6 @@ func TestParseSSHFP(t *testing.T) { } if rr.String() != result { t.Errorf("`%s' should be equal to\n\n`%s', but is \n`%s'", o, result, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -1402,8 +1320,6 @@ func TestParseHINFO(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -1424,8 +1340,6 @@ func TestParseCAA(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -1472,8 +1386,6 @@ func TestParseURI(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } @@ -1490,8 +1402,6 @@ func TestParseAVC(t *testing.T) { } if rr.String() != o { t.Errorf("`%s' should be equal to\n`%s', but is `%s'", avc, o, rr.String()) - } else { - t.Logf("RR is OK: `%s'", rr.String()) } } } diff --git a/vendor/github.com/miekg/dns/privaterr_test.go b/vendor/github.com/miekg/dns/privaterr_test.go index f50d0f48c..fa5ff48fa 100644 --- a/vendor/github.com/miekg/dns/privaterr_test.go +++ b/vendor/github.com/miekg/dns/privaterr_test.go @@ -59,8 +59,6 @@ func TestPrivateText(t *testing.T) { } if rr.String() != testrecord { t.Errorf("record string representation did not match original %#v != %#v", rr.String(), testrecord) - } else { - t.Log(rr.String()) } } @@ -96,8 +94,6 @@ func TestPrivateByteSlice(t *testing.T) { if rr1.String() != testrecord { t.Errorf("record string representation did not match original %#v != %#v", rr1.String(), testrecord) - } else { - t.Log(rr1.String()) } } @@ -166,6 +162,5 @@ func TestPrivateZoneParser(t *testing.T) { if err := x.Error; err != nil { t.Fatal(err) } - t.Log(x.RR) } } diff --git a/vendor/github.com/miekg/dns/rr_test.go b/vendor/github.com/miekg/dns/rr_test.go new file mode 100644 index 000000000..77a153b1e --- /dev/null +++ b/vendor/github.com/miekg/dns/rr_test.go @@ -0,0 +1,7 @@ +package dns + +// testRR returns the RR from string s. The error is thrown away. +func testRR(s string) RR { + r, _ := NewRR(s) + return r +} diff --git a/vendor/github.com/miekg/dns/sanitize_test.go b/vendor/github.com/miekg/dns/sanitize_test.go index 2ba3fe9a3..b2c0e2081 100644 --- a/vendor/github.com/miekg/dns/sanitize_test.go +++ b/vendor/github.com/miekg/dns/sanitize_test.go @@ -3,37 +3,36 @@ package dns import "testing" func TestDedup(t *testing.T) { - // make it []string testcases := map[[3]RR][]string{ [...]RR{ - newRR(t, "mIek.nl. IN A 127.0.0.1"), - newRR(t, "mieK.nl. IN A 127.0.0.1"), - newRR(t, "miek.Nl. IN A 127.0.0.1"), + testRR("mIek.nl. IN A 127.0.0.1"), + testRR("mieK.nl. IN A 127.0.0.1"), + testRR("miek.Nl. IN A 127.0.0.1"), }: {"mIek.nl.\t3600\tIN\tA\t127.0.0.1"}, [...]RR{ - newRR(t, "miEk.nl. 2000 IN A 127.0.0.1"), - newRR(t, "mieK.Nl. 1000 IN A 127.0.0.1"), - newRR(t, "Miek.nL. 500 IN A 127.0.0.1"), + testRR("miEk.nl. 2000 IN A 127.0.0.1"), + testRR("mieK.Nl. 1000 IN A 127.0.0.1"), + testRR("Miek.nL. 500 IN A 127.0.0.1"), }: {"miEk.nl.\t500\tIN\tA\t127.0.0.1"}, [...]RR{ - newRR(t, "miek.nl. IN A 127.0.0.1"), - newRR(t, "miek.nl. CH A 127.0.0.1"), - newRR(t, "miek.nl. IN A 127.0.0.1"), + testRR("miek.nl. IN A 127.0.0.1"), + testRR("miek.nl. CH A 127.0.0.1"), + testRR("miek.nl. IN A 127.0.0.1"), }: {"miek.nl.\t3600\tIN\tA\t127.0.0.1", "miek.nl.\t3600\tCH\tA\t127.0.0.1", }, [...]RR{ - newRR(t, "miek.nl. CH A 127.0.0.1"), - newRR(t, "miek.nl. IN A 127.0.0.1"), - newRR(t, "miek.de. IN A 127.0.0.1"), + testRR("miek.nl. CH A 127.0.0.1"), + testRR("miek.nl. IN A 127.0.0.1"), + testRR("miek.de. IN A 127.0.0.1"), }: {"miek.nl.\t3600\tCH\tA\t127.0.0.1", "miek.nl.\t3600\tIN\tA\t127.0.0.1", "miek.de.\t3600\tIN\tA\t127.0.0.1", }, [...]RR{ - newRR(t, "miek.de. IN A 127.0.0.1"), - newRR(t, "miek.nl. 200 IN A 127.0.0.1"), - newRR(t, "miek.nl. 300 IN A 127.0.0.1"), + testRR("miek.de. IN A 127.0.0.1"), + testRR("miek.nl. 200 IN A 127.0.0.1"), + testRR("miek.nl. 300 IN A 127.0.0.1"), }: {"miek.de.\t3600\tIN\tA\t127.0.0.1", "miek.nl.\t200\tIN\tA\t127.0.0.1", }, @@ -51,9 +50,9 @@ func TestDedup(t *testing.T) { func BenchmarkDedup(b *testing.B) { rrs := []RR{ - newRR(nil, "miEk.nl. 2000 IN A 127.0.0.1"), - newRR(nil, "mieK.Nl. 1000 IN A 127.0.0.1"), - newRR(nil, "Miek.nL. 500 IN A 127.0.0.1"), + testRR("miEk.nl. 2000 IN A 127.0.0.1"), + testRR("mieK.Nl. 1000 IN A 127.0.0.1"), + testRR("Miek.nL. 500 IN A 127.0.0.1"), } m := make(map[string]RR) for i := 0; i < b.N; i++ { @@ -63,9 +62,9 @@ func BenchmarkDedup(b *testing.B) { func TestNormalizedString(t *testing.T) { tests := map[RR]string{ - newRR(t, "mIEk.Nl. 3600 IN A 127.0.0.1"): "miek.nl.\tIN\tA\t127.0.0.1", - newRR(t, "m\\ iek.nL. 3600 IN A 127.0.0.1"): "m\\ iek.nl.\tIN\tA\t127.0.0.1", - newRR(t, "m\\\tIeK.nl. 3600 in A 127.0.0.1"): "m\\009iek.nl.\tIN\tA\t127.0.0.1", + testRR("mIEk.Nl. 3600 IN A 127.0.0.1"): "miek.nl.\tIN\tA\t127.0.0.1", + testRR("m\\ iek.nL. 3600 IN A 127.0.0.1"): "m\\ iek.nl.\tIN\tA\t127.0.0.1", + testRR("m\\\tIeK.nl. 3600 in A 127.0.0.1"): "m\\009iek.nl.\tIN\tA\t127.0.0.1", } for tc, expected := range tests { n := normalizedString(tc) @@ -74,11 +73,3 @@ func TestNormalizedString(t *testing.T) { } } } - -func newRR(t *testing.T, s string) RR { - r, err := NewRR(s) - if err != nil { - t.Logf("newRR: %v", err) - } - return r -} diff --git a/vendor/github.com/miekg/dns/scan.go b/vendor/github.com/miekg/dns/scan.go index c7b1eb19a..243b9cf18 100644 --- a/vendor/github.com/miekg/dns/scan.go +++ b/vendor/github.com/miekg/dns/scan.go @@ -38,7 +38,7 @@ const ( zOwner zClass zDirOrigin // $ORIGIN - zDirTtl // $TTL + zDirTTL // $TTL zDirInclude // $INCLUDE zDirGenerate // $GENERATE @@ -51,13 +51,13 @@ const ( zExpectAny // Expect rrtype, ttl or class zExpectAnyNoClass // Expect rrtype or ttl zExpectAnyNoClassBl // The whitespace after _EXPECT_ANY_NOCLASS - zExpectAnyNoTtl // Expect rrtype or class - zExpectAnyNoTtlBl // Whitespace after _EXPECT_ANY_NOTTL + zExpectAnyNoTTL // Expect rrtype or class + zExpectAnyNoTTLBl // Whitespace after _EXPECT_ANY_NOTTL zExpectRrtype // Expect rrtype zExpectRrtypeBl // Whitespace BEFORE rrtype zExpectRdata // The first element of the rdata - zExpectDirTtlBl // Space after directive $TTL - zExpectDirTtl // Directive $TTL + zExpectDirTTLBl // Space after directive $TTL + zExpectDirTTL // Directive $TTL zExpectDirOriginBl // Space after directive $ORIGIN zExpectDirOrigin // Directive $ORIGIN zExpectDirIncludeBl // Space after directive $INCLUDE @@ -231,8 +231,8 @@ func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *T h.Name = name prevName = h.Name st = zExpectOwnerBl - case zDirTtl: - st = zExpectDirTtlBl + case zDirTTL: + st = zExpectDirTTLBl case zDirOrigin: st = zExpectDirOriginBl case zDirInclude: @@ -251,7 +251,7 @@ func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *T // Discard, can happen when there is nothing on the // line except the RR type case zString: - ttl, ok := stringToTtl(l.token) + ttl, ok := stringToTTL(l.token) if !ok { t <- &Token{Error: &ParseError{f, "not a TTL", l}} return @@ -260,7 +260,7 @@ func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *T if defttl == nil || !defttl.isByDirective { defttl = &ttlState{ttl, false} } - st = zExpectAnyNoTtlBl + st = zExpectAnyNoTTLBl default: t <- &Token{Error: &ParseError{f, "syntax error at beginning", l}} @@ -307,13 +307,13 @@ func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *T } parseZone(r1, neworigin, defttl, l.token, t, include+1) st = zExpectOwnerDir - case zExpectDirTtlBl: + case zExpectDirTTLBl: if l.value != zBlank { t <- &Token{Error: &ParseError{f, "no blank after $TTL-directive", l}} return } - st = zExpectDirTtl - case zExpectDirTtl: + st = zExpectDirTTL + case zExpectDirTTL: if l.value != zString { t <- &Token{Error: &ParseError{f, "expecting $TTL value, not this...", l}} return @@ -322,7 +322,7 @@ func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *T t <- &Token{Error: e} return } - ttl, ok := stringToTtl(l.token) + ttl, ok := stringToTTL(l.token) if !ok { t <- &Token{Error: &ParseError{f, "expecting $TTL value, not this...", l}} return @@ -385,7 +385,7 @@ func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *T h.Class = l.torc st = zExpectAnyNoClassBl case zString: - ttl, ok := stringToTtl(l.token) + ttl, ok := stringToTTL(l.token) if !ok { t <- &Token{Error: &ParseError{f, "not a TTL", l}} return @@ -394,7 +394,7 @@ func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *T if defttl == nil || !defttl.isByDirective { defttl = &ttlState{ttl, false} } - st = zExpectAnyNoTtlBl + st = zExpectAnyNoTTLBl default: t <- &Token{Error: &ParseError{f, "expecting RR type, TTL or class, not this...", l}} return @@ -405,13 +405,13 @@ func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *T return } st = zExpectAnyNoClass - case zExpectAnyNoTtlBl: + case zExpectAnyNoTTLBl: if l.value != zBlank { t <- &Token{Error: &ParseError{f, "no blank before TTL", l}} return } - st = zExpectAnyNoTtl - case zExpectAnyNoTtl: + st = zExpectAnyNoTTL + case zExpectAnyNoTTL: switch l.value { case zClass: h.Class = l.torc @@ -426,7 +426,7 @@ func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *T case zExpectAnyNoClass: switch l.value { case zString: - ttl, ok := stringToTtl(l.token) + ttl, ok := stringToTTL(l.token) if !ok { t <- &Token{Error: &ParseError{f, "not a TTL", l}} return @@ -539,7 +539,7 @@ func zlexer(s *scan, c chan lex) { // escape $... start with a \ not a $, so this will work switch l.tokenUpper { case "$TTL": - l.value = zDirTtl + l.value = zDirTTL case "$ORIGIN": l.value = zDirOrigin case "$INCLUDE": @@ -837,8 +837,8 @@ func typeToInt(token string) (uint16, bool) { return uint16(typ), true } -// Parse things like 2w, 2m, etc, Return the time in seconds. -func stringToTtl(token string) (uint32, bool) { +// stringToTTL parses things like 2w, 2m, etc, and returns the time in seconds. +func stringToTTL(token string) (uint32, bool) { s := uint32(0) i := uint32(0) for _, c := range token { diff --git a/vendor/github.com/miekg/dns/scan_rr.go b/vendor/github.com/miekg/dns/scan_rr.go index 824b9c949..c53ba1d5b 100644 --- a/vendor/github.com/miekg/dns/scan_rr.go +++ b/vendor/github.com/miekg/dns/scan_rr.go @@ -590,7 +590,7 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad SOA zone parameter", l}, "" } // We allow other fields to be unitful duration strings - if v, ok = stringToTtl(l.token); !ok { + if v, ok = stringToTTL(l.token); !ok { return nil, &ParseError{f, "bad SOA zone parameter", l}, "" } diff --git a/vendor/github.com/miekg/dns/server.go b/vendor/github.com/miekg/dns/server.go index 0ca6e008c..ee7e256fb 100644 --- a/vendor/github.com/miekg/dns/server.go +++ b/vendor/github.com/miekg/dns/server.go @@ -297,10 +297,7 @@ type Server struct { // DecorateWriter is optional, allows customization of the process that writes raw DNS messages. DecorateWriter DecorateWriter - // Graceful shutdown handling - - inFlight sync.WaitGroup - + // Shutdown handling lock sync.RWMutex started bool } @@ -412,10 +409,8 @@ func (srv *Server) ActivateAndServe() error { return &Error{err: "bad listeners"} } -// Shutdown gracefully shuts down a server. After a call to Shutdown, ListenAndServe and -// ActivateAndServe will return. All in progress queries are completed before the server -// is taken down. If the Shutdown is taking longer than the reading timeout an error -// is returned. +// Shutdown shuts down a server. After a call to Shutdown, ListenAndServe and +// ActivateAndServe will return. func (srv *Server) Shutdown() error { srv.lock.Lock() if !srv.started { @@ -431,19 +426,7 @@ func (srv *Server) Shutdown() error { if srv.Listener != nil { srv.Listener.Close() } - - fin := make(chan bool) - go func() { - srv.inFlight.Wait() - fin <- true - }() - - select { - case <-time.After(srv.getReadTimeout()): - return &Error{err: "server shutdown is pending"} - case <-fin: - return nil - } + return nil } // getReadTimeout is a helper func to use system timeout if server did not intend to change it. @@ -493,7 +476,6 @@ func (srv *Server) serveTCP(l net.Listener) error { if err != nil { continue } - srv.inFlight.Add(1) go srv.serve(rw.RemoteAddr(), handler, m, nil, nil, rw) } } @@ -529,15 +511,12 @@ func (srv *Server) serveUDP(l *net.UDPConn) error { if err != nil { continue } - srv.inFlight.Add(1) go srv.serve(s.RemoteAddr(), handler, m, l, s, nil) } } // Serve a new connection. func (srv *Server) serve(a net.Addr, h Handler, m []byte, u *net.UDPConn, s *SessionUDP, t net.Conn) { - defer srv.inFlight.Done() - w := &response{tsigSecret: srv.TsigSecret, udp: u, tcp: t, remoteAddr: a, udpSession: s} if srv.DecorateWriter != nil { w.writer = srv.DecorateWriter(w) diff --git a/vendor/github.com/miekg/dns/server_test.go b/vendor/github.com/miekg/dns/server_test.go index b74f2f1a8..1a4b7ca0c 100644 --- a/vendor/github.com/miekg/dns/server_test.go +++ b/vendor/github.com/miekg/dns/server_test.go @@ -147,7 +147,7 @@ func TestServing(t *testing.T) { defer HandleRemove("miek.nl.") defer HandleRemove("example.com.") - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -202,7 +202,7 @@ func TestServingTLS(t *testing.T) { Certificates: []tls.Certificate{cert}, } - s, addrstr, err := RunLocalTLSServer("127.0.0.1:0", &config) + s, addrstr, err := RunLocalTLSServer(":0", &config) if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -247,13 +247,77 @@ func TestServingTLS(t *testing.T) { } } +func TestServingListenAndServe(t *testing.T) { + HandleFunc("example.com.", AnotherHelloServer) + defer HandleRemove("example.com.") + + waitLock := sync.Mutex{} + server := &Server{Addr: ":0", Net: "udp", ReadTimeout: time.Hour, WriteTimeout: time.Hour, NotifyStartedFunc: waitLock.Unlock} + waitLock.Lock() + + go func() { + server.ListenAndServe() + }() + waitLock.Lock() + + c, m := new(Client), new(Msg) + m.SetQuestion("example.com.", TypeTXT) + addr := server.PacketConn.LocalAddr().String() // Get address via the PacketConn that gets set. + r, _, err := c.Exchange(m, addr) + if err != nil { + t.Fatal("failed to exchange example.com", err) + } + txt := r.Extra[0].(*TXT).Txt[0] + if txt != "Hello example" { + t.Error("unexpected result for example.com", txt, "!= Hello example") + } + server.Shutdown() +} + +func TestServingListenAndServeTLS(t *testing.T) { + HandleFunc("example.com.", AnotherHelloServer) + defer HandleRemove("example.com.") + + cert, err := tls.X509KeyPair(CertPEMBlock, KeyPEMBlock) + if err != nil { + t.Fatalf("unable to build certificate: %v", err) + } + + config := &tls.Config{ + Certificates: []tls.Certificate{cert}, + } + + waitLock := sync.Mutex{} + server := &Server{Addr: ":0", Net: "tcp", TLSConfig: config, ReadTimeout: time.Hour, WriteTimeout: time.Hour, NotifyStartedFunc: waitLock.Unlock} + waitLock.Lock() + + go func() { + server.ListenAndServe() + }() + waitLock.Lock() + + c, m := new(Client), new(Msg) + c.Net = "tcp" + m.SetQuestion("example.com.", TypeTXT) + addr := server.Listener.Addr().String() // Get address via the Listener that gets set. + r, _, err := c.Exchange(m, addr) + if err != nil { + t.Fatal(err) + } + txt := r.Extra[0].(*TXT).Txt[0] + if txt != "Hello example" { + t.Error("unexpected result for example.com", txt, "!= Hello example") + } + server.Shutdown() +} + func BenchmarkServe(b *testing.B) { b.StopTimer() HandleFunc("miek.nl.", HelloServer) defer HandleRemove("miek.nl.") a := runtime.GOMAXPROCS(4) - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { b.Fatalf("unable to run test server: %v", err) } @@ -306,7 +370,7 @@ func BenchmarkServeCompress(b *testing.B) { HandleFunc("miek.nl.", HelloServerCompress) defer HandleRemove("miek.nl.") a := runtime.GOMAXPROCS(4) - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { b.Fatalf("unable to run test server: %v", err) } @@ -407,7 +471,7 @@ func TestServingLargeResponses(t *testing.T) { HandleFunc("example.", HelloServerLargeResponse) defer HandleRemove("example.") - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -447,7 +511,7 @@ func TestServingResponse(t *testing.T) { t.Skip("skipping test in short mode.") } HandleFunc("miek.nl.", HelloServer) - s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") + s, addrstr, err := RunLocalUDPServer(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -467,7 +531,7 @@ func TestServingResponse(t *testing.T) { } s.Shutdown() - s, addrstr, err = RunLocalUDPServerUnsafe("127.0.0.1:0") + s, addrstr, err = RunLocalUDPServerUnsafe(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -481,7 +545,7 @@ func TestServingResponse(t *testing.T) { } func TestShutdownTCP(t *testing.T) { - s, _, err := RunLocalTCPServer("127.0.0.1:0") + s, _, err := RunLocalTCPServer(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -501,7 +565,7 @@ func TestShutdownTLS(t *testing.T) { Certificates: []tls.Certificate{cert}, } - s, _, err := RunLocalTLSServer("127.0.0.1:0", &config) + s, _, err := RunLocalTLSServer(":0", &config) if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -529,7 +593,7 @@ func (t *trigger) Get() bool { func TestHandlerCloseTCP(t *testing.T) { - ln, err := net.Listen("tcp", "127.0.0.1:0") + ln, err := net.Listen("tcp", ":0") if err != nil { panic(err) } @@ -553,7 +617,7 @@ func TestHandlerCloseTCP(t *testing.T) { exchange: _, _, err := c.Exchange(m, addr) if err != nil && err != io.EOF { - t.Logf("exchange failed: %s\n", err) + t.Errorf("exchange failed: %s\n", err) if tries == 3 { return } @@ -569,7 +633,7 @@ func TestHandlerCloseTCP(t *testing.T) { } func TestShutdownUDP(t *testing.T) { - s, _, fin, err := RunLocalUDPServerWithFinChan("127.0.0.1:0") + s, _, fin, err := RunLocalUDPServerWithFinChan(":0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -580,7 +644,23 @@ func TestShutdownUDP(t *testing.T) { select { case <-fin: case <-time.After(2 * time.Second): - t.Error("Could not shutdown test UDP server. Gave up waiting") + t.Error("could not shutdown test UDP server. Gave up waiting") + } +} + +func TestServerStartStopRace(t *testing.T) { + for i := 0; i < 10; i++ { + var err error + s := &Server{} + s, _, _, err = RunLocalUDPServerWithFinChan(":0") + if err != nil { + t.Fatalf("Could not start server: %s", err) + } + go func() { + if err := s.Shutdown(); err != nil { + t.Fatalf("Could not stop server: %s", err) + } + }() } } @@ -600,7 +680,7 @@ func ExampleDecorateWriter() { }) // simple UDP server - pc, err := net.ListenPacket("udp", "127.0.0.1:0") + pc, err := net.ListenPacket("udp", ":0") if err != nil { fmt.Println(err.Error()) return @@ -687,43 +767,3 @@ zDCJkckCgYEAndqM5KXGk5xYo+MAA1paZcbTUXwaWwjLU+XSRSSoyBEi5xMtfvUb kFsxKCqxAnBVGEWAvVZAiiTOxleQFjz5RnL0BQp9Lg2cQe+dvuUmIAA= -----END RSA PRIVATE KEY-----`) ) - -func testShutdownBindPort(t *testing.T, protocol string, port string) { - handler := NewServeMux() - handler.HandleFunc(".", func(w ResponseWriter, r *Msg) {}) - startedCh := make(chan struct{}) - s := &Server{ - Addr: net.JoinHostPort("127.0.0.1", port), - Net: protocol, - Handler: handler, - NotifyStartedFunc: func() { - startedCh <- struct{}{} - }, - } - go func() { - if err := s.ListenAndServe(); err != nil { - t.Log(err) - } - }() - <-startedCh - t.Logf("DNS server is started on: %s", s.Addr) - if err := s.Shutdown(); err != nil { - t.Fatal(err) - } - time.Sleep(100 * time.Millisecond) - go func() { - if err := s.ListenAndServe(); err != nil { - t.Fatal(err) - } - }() - <-startedCh - t.Logf("DNS server is started on: %s", s.Addr) -} - -func TestShutdownBindPortUDP(t *testing.T) { - testShutdownBindPort(t, "udp", "1153") -} - -func TestShutdownBindPortTCP(t *testing.T) { - testShutdownBindPort(t, "tcp", "1154") -} diff --git a/vendor/github.com/miekg/dns/types.go b/vendor/github.com/miekg/dns/types.go index 57f065bc8..deddb301b 100644 --- a/vendor/github.com/miekg/dns/types.go +++ b/vendor/github.com/miekg/dns/types.go @@ -164,14 +164,15 @@ const ( _Z = 1 << 6 // Z _AD = 1 << 5 // authticated data _CD = 1 << 4 // checking disabled +) +// Various constants used in the LOC RR, See RFC 1887. +const ( LOC_EQUATOR = 1 << 31 // RFC 1876, Section 2. LOC_PRIMEMERIDIAN = 1 << 31 // RFC 1876, Section 2. - - LOC_HOURS = 60 * 1000 - LOC_DEGREES = 60 * LOC_HOURS - - LOC_ALTITUDEBASE = 100000 + LOC_HOURS = 60 * 1000 + LOC_DEGREES = 60 * LOC_HOURS + LOC_ALTITUDEBASE = 100000 ) // Different Certificate Types, see RFC 4398, Section 2.1 @@ -237,6 +238,7 @@ type ANY struct { func (rr *ANY) String() string { return rr.Hdr.String() } +// CNAME RR. See RFC 1034. type CNAME struct { Hdr RR_Header Target string `dns:"cdomain-name"` @@ -244,6 +246,7 @@ type CNAME struct { func (rr *CNAME) String() string { return rr.Hdr.String() + sprintName(rr.Target) } +// HINFO RR. See RFC 1034. type HINFO struct { Hdr RR_Header Cpu string @@ -254,6 +257,7 @@ func (rr *HINFO) String() string { return rr.Hdr.String() + sprintTxt([]string{rr.Cpu, rr.Os}) } +// MB RR. See RFC 1035. type MB struct { Hdr RR_Header Mb string `dns:"cdomain-name"` @@ -261,6 +265,7 @@ type MB struct { func (rr *MB) String() string { return rr.Hdr.String() + sprintName(rr.Mb) } +// MG RR. See RFC 1035. type MG struct { Hdr RR_Header Mg string `dns:"cdomain-name"` @@ -268,6 +273,7 @@ type MG struct { func (rr *MG) String() string { return rr.Hdr.String() + sprintName(rr.Mg) } +// MINFO RR. See RFC 1035. type MINFO struct { Hdr RR_Header Rmail string `dns:"cdomain-name"` @@ -278,6 +284,7 @@ func (rr *MINFO) String() string { return rr.Hdr.String() + sprintName(rr.Rmail) + " " + sprintName(rr.Email) } +// MR RR. See RFC 1035. type MR struct { Hdr RR_Header Mr string `dns:"cdomain-name"` @@ -287,6 +294,7 @@ func (rr *MR) String() string { return rr.Hdr.String() + sprintName(rr.Mr) } +// MF RR. See RFC 1035. type MF struct { Hdr RR_Header Mf string `dns:"cdomain-name"` @@ -296,6 +304,7 @@ func (rr *MF) String() string { return rr.Hdr.String() + sprintName(rr.Mf) } +// MD RR. See RFC 1035. type MD struct { Hdr RR_Header Md string `dns:"cdomain-name"` @@ -305,6 +314,7 @@ func (rr *MD) String() string { return rr.Hdr.String() + sprintName(rr.Md) } +// MX RR. See RFC 1035. type MX struct { Hdr RR_Header Preference uint16 @@ -315,6 +325,7 @@ func (rr *MX) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Preference)) + " " + sprintName(rr.Mx) } +// AFSDB RR. See RFC 1183. type AFSDB struct { Hdr RR_Header Subtype uint16 @@ -325,6 +336,7 @@ func (rr *AFSDB) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Subtype)) + " " + sprintName(rr.Hostname) } +// X25 RR. See RFC 1183, Section 3.1. type X25 struct { Hdr RR_Header PSDNAddress string @@ -334,6 +346,7 @@ func (rr *X25) String() string { return rr.Hdr.String() + rr.PSDNAddress } +// RT RR. See RFC 1183, Section 3.3. type RT struct { Hdr RR_Header Preference uint16 @@ -344,6 +357,7 @@ func (rr *RT) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Preference)) + " " + sprintName(rr.Host) } +// NS RR. See RFC 1035. type NS struct { Hdr RR_Header Ns string `dns:"cdomain-name"` @@ -353,6 +367,7 @@ func (rr *NS) String() string { return rr.Hdr.String() + sprintName(rr.Ns) } +// PTR RR. See RFC 1035. type PTR struct { Hdr RR_Header Ptr string `dns:"cdomain-name"` @@ -362,6 +377,7 @@ func (rr *PTR) String() string { return rr.Hdr.String() + sprintName(rr.Ptr) } +// RP RR. See RFC 1138, Section 2.2. type RP struct { Hdr RR_Header Mbox string `dns:"domain-name"` @@ -372,6 +388,7 @@ func (rr *RP) String() string { return rr.Hdr.String() + rr.Mbox + " " + sprintTxt([]string{rr.Txt}) } +// SOA RR. See RFC 1035. type SOA struct { Hdr RR_Header Ns string `dns:"cdomain-name"` @@ -392,6 +409,7 @@ func (rr *SOA) String() string { " " + strconv.FormatInt(int64(rr.Minttl), 10) } +// TXT RR. See RFC 1035. type TXT struct { Hdr RR_Header Txt []string `dns:"txt"` @@ -524,6 +542,7 @@ func nextByte(b []byte, offset int) (byte, int) { return b[offset+1], 2 } +// SPF RR. See RFC 4408, Section 3.1.1. type SPF struct { Hdr RR_Header Txt []string `dns:"txt"` @@ -531,6 +550,7 @@ type SPF struct { func (rr *SPF) String() string { return rr.Hdr.String() + sprintTxt(rr.Txt) } +// AVC RR. See https://www.iana.org/assignments/dns-parameters/AVC/avc-completed-template. type AVC struct { Hdr RR_Header Txt []string `dns:"txt"` @@ -538,6 +558,7 @@ type AVC struct { func (rr *AVC) String() string { return rr.Hdr.String() + sprintTxt(rr.Txt) } +// SRV RR. See RFC 2782. type SRV struct { Hdr RR_Header Priority uint16 @@ -553,6 +574,7 @@ func (rr *SRV) String() string { strconv.Itoa(int(rr.Port)) + " " + sprintName(rr.Target) } +// NAPTR RR. See RFC 2915. type NAPTR struct { Hdr RR_Header Order uint16 @@ -573,7 +595,7 @@ func (rr *NAPTR) String() string { rr.Replacement } -// The CERT resource record, see RFC 4398. +// CERT RR. See RFC 4398. type CERT struct { Hdr RR_Header Type uint16 @@ -599,7 +621,7 @@ func (rr *CERT) String() string { " " + rr.Certificate } -// The DNAME resource record, see RFC 2672. +// DNAME RR. See RFC 2672. type DNAME struct { Hdr RR_Header Target string `dns:"domain-name"` @@ -609,6 +631,7 @@ func (rr *DNAME) String() string { return rr.Hdr.String() + sprintName(rr.Target) } +// A RR. See RFC 1035. type A struct { Hdr RR_Header A net.IP `dns:"a"` @@ -621,6 +644,7 @@ func (rr *A) String() string { return rr.Hdr.String() + rr.A.String() } +// AAAA RR. See RFC 3596. type AAAA struct { Hdr RR_Header AAAA net.IP `dns:"aaaa"` @@ -633,6 +657,7 @@ func (rr *AAAA) String() string { return rr.Hdr.String() + rr.AAAA.String() } +// PX RR. See RFC 2163. type PX struct { Hdr RR_Header Preference uint16 @@ -644,6 +669,7 @@ func (rr *PX) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Preference)) + " " + sprintName(rr.Map822) + " " + sprintName(rr.Mapx400) } +// GPOS RR. See RFC 1712. type GPOS struct { Hdr RR_Header Longitude string @@ -655,6 +681,7 @@ func (rr *GPOS) String() string { return rr.Hdr.String() + rr.Longitude + " " + rr.Latitude + " " + rr.Altitude } +// LOC RR. See RFC RFC 1876. type LOC struct { Hdr RR_Header Version uint8 @@ -731,11 +758,12 @@ func (rr *LOC) String() string { return s } -// SIG is identical to RRSIG and nowadays only used for SIG(0), RFC2931. +// SIG RR. See RFC 2535. The SIG RR is identical to RRSIG and nowadays only used for SIG(0), See RFC 2931. type SIG struct { RRSIG } +// RRSIG RR. See RFC 4034 and RFC 3755. type RRSIG struct { Hdr RR_Header TypeCovered uint16 @@ -763,6 +791,7 @@ func (rr *RRSIG) String() string { return s } +// NSEC RR. See RFC 4034 and RFC 3755. type NSEC struct { Hdr RR_Header NextDomain string `dns:"domain-name"` @@ -790,14 +819,13 @@ func (rr *NSEC) len() int { return l } -type DLV struct { - DS -} +// DLV RR. See RFC 4431. +type DLV struct{ DS } -type CDS struct { - DS -} +// CDS RR. See RFC 7344. +type CDS struct{ DS } +// DS RR. See RFC 4034 and RFC 3658. type DS struct { Hdr RR_Header KeyTag uint16 @@ -813,6 +841,7 @@ func (rr *DS) String() string { " " + strings.ToUpper(rr.Digest) } +// KX RR. See RFC 2230. type KX struct { Hdr RR_Header Preference uint16 @@ -824,6 +853,7 @@ func (rr *KX) String() string { " " + sprintName(rr.Exchanger) } +// TA RR. See http://www.watson.org/~weiler/INI1999-19.pdf. type TA struct { Hdr RR_Header KeyTag uint16 @@ -839,6 +869,7 @@ func (rr *TA) String() string { " " + strings.ToUpper(rr.Digest) } +// TALINK RR. See https://www.iana.org/assignments/dns-parameters/TALINK/talink-completed-template. type TALINK struct { Hdr RR_Header PreviousName string `dns:"domain-name"` @@ -850,6 +881,7 @@ func (rr *TALINK) String() string { sprintName(rr.PreviousName) + " " + sprintName(rr.NextName) } +// SSHFP RR. See RFC RFC 4255. type SSHFP struct { Hdr RR_Header Algorithm uint8 @@ -863,14 +895,17 @@ func (rr *SSHFP) String() string { " " + strings.ToUpper(rr.FingerPrint) } +// KEY RR. See RFC RFC 2535. type KEY struct { DNSKEY } +// CDNSKEY RR. See RFC 7344. type CDNSKEY struct { DNSKEY } +// DNSKEY RR. See RFC 4034 and RFC 3755. type DNSKEY struct { Hdr RR_Header Flags uint16 @@ -886,6 +921,7 @@ func (rr *DNSKEY) String() string { " " + rr.PublicKey } +// RKEY RR. See https://www.iana.org/assignments/dns-parameters/RKEY/rkey-completed-template. type RKEY struct { Hdr RR_Header Flags uint16 @@ -901,6 +937,7 @@ func (rr *RKEY) String() string { " " + rr.PublicKey } +// NSAPPTR RR. See RFC 1348. type NSAPPTR struct { Hdr RR_Header Ptr string `dns:"domain-name"` @@ -908,6 +945,7 @@ type NSAPPTR struct { func (rr *NSAPPTR) String() string { return rr.Hdr.String() + sprintName(rr.Ptr) } +// NSEC3 RR. See RFC 5155. type NSEC3 struct { Hdr RR_Header Hash uint8 @@ -946,6 +984,7 @@ func (rr *NSEC3) len() int { return l } +// NSEC3PARAM RR. See RFC 5155. type NSEC3PARAM struct { Hdr RR_Header Hash uint8 @@ -964,6 +1003,7 @@ func (rr *NSEC3PARAM) String() string { return s } +// TKEY RR. See RFC 2930. type TKEY struct { Hdr RR_Header Algorithm string `dns:"domain-name"` @@ -982,7 +1022,7 @@ func (rr *TKEY) String() string { return "" } -// RFC3597 represents an unknown/generic RR. +// RFC3597 represents an unknown/generic RR. See RFC 3597. type RFC3597 struct { Hdr RR_Header Rdata string `dns:"hex"` @@ -1006,6 +1046,7 @@ func rfc3597Header(h RR_Header) string { return s } +// URI RR. See RFC 7553. type URI struct { Hdr RR_Header Priority uint16 @@ -1018,6 +1059,7 @@ func (rr *URI) String() string { " " + strconv.Itoa(int(rr.Weight)) + " " + sprintTxtOctet(rr.Target) } +// DHCID RR. See RFC 4701. type DHCID struct { Hdr RR_Header Digest string `dns:"base64"` @@ -1025,6 +1067,7 @@ type DHCID struct { func (rr *DHCID) String() string { return rr.Hdr.String() + rr.Digest } +// TLSA RR. See RFC 6698. type TLSA struct { Hdr RR_Header Usage uint8 @@ -1041,6 +1084,7 @@ func (rr *TLSA) String() string { " " + rr.Certificate } +// SMIMEA RR. See RFC 8162. type SMIMEA struct { Hdr RR_Header Usage uint8 @@ -1063,6 +1107,7 @@ func (rr *SMIMEA) String() string { return s } +// HIP RR. See RFC 8005. type HIP struct { Hdr RR_Header HitLength uint8 @@ -1084,6 +1129,7 @@ func (rr *HIP) String() string { return s } +// NINFO RR. See https://www.iana.org/assignments/dns-parameters/NINFO/ninfo-completed-template. type NINFO struct { Hdr RR_Header ZSData []string `dns:"txt"` @@ -1091,6 +1137,7 @@ type NINFO struct { func (rr *NINFO) String() string { return rr.Hdr.String() + sprintTxt(rr.ZSData) } +// NID RR. See RFC RFC 6742. type NID struct { Hdr RR_Header Preference uint16 @@ -1104,6 +1151,7 @@ func (rr *NID) String() string { return s } +// L32 RR, See RFC 6742. type L32 struct { Hdr RR_Header Preference uint16 @@ -1118,6 +1166,7 @@ func (rr *L32) String() string { " " + rr.Locator32.String() } +// L64 RR, See RFC 6742. type L64 struct { Hdr RR_Header Preference uint16 @@ -1131,6 +1180,7 @@ func (rr *L64) String() string { return s } +// LP RR. See RFC 6742. type LP struct { Hdr RR_Header Preference uint16 @@ -1141,6 +1191,7 @@ func (rr *LP) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Preference)) + " " + sprintName(rr.Fqdn) } +// EUI48 RR. See RFC 7043. type EUI48 struct { Hdr RR_Header Address uint64 `dns:"uint48"` @@ -1148,6 +1199,7 @@ type EUI48 struct { func (rr *EUI48) String() string { return rr.Hdr.String() + euiToString(rr.Address, 48) } +// EUI64 RR. See RFC 7043. type EUI64 struct { Hdr RR_Header Address uint64 @@ -1155,6 +1207,7 @@ type EUI64 struct { func (rr *EUI64) String() string { return rr.Hdr.String() + euiToString(rr.Address, 64) } +// CAA RR. See RFC 6844. type CAA struct { Hdr RR_Header Flag uint8 @@ -1166,6 +1219,7 @@ func (rr *CAA) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Flag)) + " " + rr.Tag + " " + sprintTxtOctet(rr.Value) } +// UID RR. Deprecated, IANA-Reserved. type UID struct { Hdr RR_Header Uid uint32 @@ -1173,6 +1227,7 @@ type UID struct { func (rr *UID) String() string { return rr.Hdr.String() + strconv.FormatInt(int64(rr.Uid), 10) } +// GID RR. Deprecated, IANA-Reserved. type GID struct { Hdr RR_Header Gid uint32 @@ -1180,6 +1235,7 @@ type GID struct { func (rr *GID) String() string { return rr.Hdr.String() + strconv.FormatInt(int64(rr.Gid), 10) } +// UINFO RR. Deprecated, IANA-Reserved. type UINFO struct { Hdr RR_Header Uinfo string @@ -1187,6 +1243,7 @@ type UINFO struct { func (rr *UINFO) String() string { return rr.Hdr.String() + sprintTxt([]string{rr.Uinfo}) } +// EID RR. See http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt. type EID struct { Hdr RR_Header Endpoint string `dns:"hex"` @@ -1194,6 +1251,7 @@ type EID struct { func (rr *EID) String() string { return rr.Hdr.String() + strings.ToUpper(rr.Endpoint) } +// NIMLOC RR. See http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt. type NIMLOC struct { Hdr RR_Header Locator string `dns:"hex"` @@ -1201,6 +1259,7 @@ type NIMLOC struct { func (rr *NIMLOC) String() string { return rr.Hdr.String() + strings.ToUpper(rr.Locator) } +// OPENPGPKEY RR. See RFC 7929. type OPENPGPKEY struct { Hdr RR_Header PublicKey string `dns:"base64"` diff --git a/vendor/github.com/miekg/dns/types_generate.go b/vendor/github.com/miekg/dns/types_generate.go index dd1310942..3de021ca7 100644 --- a/vendor/github.com/miekg/dns/types_generate.go +++ b/vendor/github.com/miekg/dns/types_generate.go @@ -27,7 +27,7 @@ var skipLen = map[string]struct{}{ var packageHdr = ` // *** DO NOT MODIFY *** -// AUTOGENERATED BY go generate from type_generate.go +// AUTOGENERATED BY go generate from types_generate.go package dns @@ -56,7 +56,6 @@ var TypeToString = map[uint16]string{ `)) var headerFunc = template.Must(template.New("headerFunc").Parse(` -// Header() functions {{range .}} func (rr *{{.}}) Header() *RR_Header { return &rr.Hdr } {{end}} diff --git a/vendor/github.com/miekg/dns/types_test.go b/vendor/github.com/miekg/dns/types_test.go index c117cfbc7..3dbddee1e 100644 --- a/vendor/github.com/miekg/dns/types_test.go +++ b/vendor/github.com/miekg/dns/types_test.go @@ -44,7 +44,7 @@ func TestCmToM(t *testing.T) { func TestSplitN(t *testing.T) { xs := splitN("abc", 5) if len(xs) != 1 && xs[0] != "abc" { - t.Errorf("Failure to split abc") + t.Errorf("failure to split abc") } s := "" diff --git a/vendor/github.com/miekg/dns/update_test.go b/vendor/github.com/miekg/dns/update_test.go index 12760a1ee..6813baa10 100644 --- a/vendor/github.com/miekg/dns/update_test.go +++ b/vendor/github.com/miekg/dns/update_test.go @@ -13,11 +13,8 @@ func TestDynamicUpdateParsing(t *testing.T) { typ == "Reserved" || typ == "None" || typ == "NXT" || typ == "MAILB" || typ == "MAILA" { continue } - r, err := NewRR(prefix + typ) - if err != nil { + if _, err := NewRR(prefix + typ); err != nil { t.Errorf("failure to parse: %s %s: %v", prefix, typ, err) - } else { - t.Logf("parsed: %s", r.String()) } } } @@ -56,10 +53,7 @@ func TestDynamicUpdateZeroRdataUnpack(t *testing.T) { func TestRemoveRRset(t *testing.T) { // Should add a zero data RR in Class ANY with a TTL of 0 // for each set mentioned in the RRs provided to it. - rr, err := NewRR(". 100 IN A 127.0.0.1") - if err != nil { - t.Fatalf("error constructing RR: %v", err) - } + rr := testRR(". 100 IN A 127.0.0.1") m := new(Msg) m.Ns = []RR{&RR_Header{Name: ".", Rrtype: TypeA, Class: ClassANY, Ttl: 0, Rdlength: 0}} expectstr := m.String() @@ -92,15 +86,15 @@ func TestPreReqAndRemovals(t *testing.T) { m.Id = 1234 // Use a full set of RRs each time, so we are sure the rdata is stripped. - 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") + rrName1 := testRR("name_used. 3600 IN A 127.0.0.1") + rrName2 := testRR("name_not_used. 3600 IN A 127.0.0.1") + rrRemove1 := testRR("remove1. 3600 IN A 127.0.0.1") + rrRemove2 := testRR("remove2. 3600 IN A 127.0.0.1") + rrRemove3 := testRR("remove3. 3600 IN A 127.0.0.1") + rrInsert := testRR("insert. 3600 IN A 127.0.0.1") + rrRrset1 := testRR("rrset_used1. 3600 IN A 127.0.0.1") + rrRrset2 := testRR("rrset_used2. 3600 IN A 127.0.0.1") + rrRrset3 := testRR("rrset_not_used. 3600 IN A 127.0.0.1") // Handle the prereqs. m.NameUsed([]RR{rrName1}) diff --git a/vendor/github.com/miekg/dns/xfr.go b/vendor/github.com/miekg/dns/xfr.go index 576c5590a..2e892ea38 100644 --- a/vendor/github.com/miekg/dns/xfr.go +++ b/vendor/github.com/miekg/dns/xfr.go @@ -51,18 +51,18 @@ func (t *Transfer) In(q *Msg, a string) (env chan *Envelope, err error) { env = make(chan *Envelope) go func() { if q.Question[0].Qtype == TypeAXFR { - go t.inAxfr(q.Id, env) + go t.inAxfr(q, env) return } if q.Question[0].Qtype == TypeIXFR { - go t.inIxfr(q.Id, env) + go t.inIxfr(q, env) return } }() return env, nil } -func (t *Transfer) inAxfr(id uint16, c chan *Envelope) { +func (t *Transfer) inAxfr(q *Msg, c chan *Envelope) { first := true defer t.Close() defer close(c) @@ -77,7 +77,7 @@ func (t *Transfer) inAxfr(id uint16, c chan *Envelope) { c <- &Envelope{nil, err} return } - if id != in.Id { + if q.Id != in.Id { c <- &Envelope{in.Answer, ErrId} return } @@ -110,9 +110,11 @@ func (t *Transfer) inAxfr(id uint16, c chan *Envelope) { } } -func (t *Transfer) inIxfr(id uint16, c chan *Envelope) { +func (t *Transfer) inIxfr(q *Msg, c chan *Envelope) { serial := uint32(0) // The first serial seen is the current server serial - first := true + axfr := true + n := 0 + qser := q.Ns[0].(*SOA).Serial defer t.Close() defer close(c) timeout := dnsTimeout @@ -126,21 +128,15 @@ func (t *Transfer) inIxfr(id uint16, c chan *Envelope) { c <- &Envelope{nil, err} return } - if id != in.Id { + if q.Id != in.Id { c <- &Envelope{in.Answer, ErrId} return } - if first { - if in.Rcode != RcodeSuccess { - c <- &Envelope{in.Answer, &Error{err: fmt.Sprintf(errXFR, in.Rcode)}} - return - } - // A single SOA RR signals "no changes" - if len(in.Answer) == 1 && isSOAFirst(in) { - c <- &Envelope{in.Answer, nil} - return - } - + if in.Rcode != RcodeSuccess { + c <- &Envelope{in.Answer, &Error{err: fmt.Sprintf(errXFR, in.Rcode)}} + return + } + if n == 0 { // Check if the returned answer is ok if !isSOAFirst(in) { c <- &Envelope{in.Answer, ErrSoa} @@ -148,21 +144,30 @@ func (t *Transfer) inIxfr(id uint16, c chan *Envelope) { } // This serial is important serial = in.Answer[0].(*SOA).Serial - first = !first + // Check if there are no changes in zone + if qser >= serial { + c <- &Envelope{in.Answer, nil} + return + } } - // Now we need to check each message for SOA records, to see what we need to do - if !first { - t.tsigTimersOnly = true - // If the last record in the IXFR contains the servers' SOA, we should quit - if v, ok := in.Answer[len(in.Answer)-1].(*SOA); ok { + t.tsigTimersOnly = true + for _, rr := range in.Answer { + if v, ok := rr.(*SOA); ok { if v.Serial == serial { - c <- &Envelope{in.Answer, nil} - return + n++ + // quit if it's a full axfr or the the servers' SOA is repeated the third time + if axfr && n == 2 || n == 3 { + c <- &Envelope{in.Answer, nil} + return + } + } else if axfr { + // it's an ixfr + axfr = false } } - c <- &Envelope{in.Answer, nil} } + c <- &Envelope{in.Answer, nil} } } diff --git a/vendor/github.com/miekg/dns/xfr_test.go b/vendor/github.com/miekg/dns/xfr_test.go index a478963a3..e7cc6b2fa 100644 --- a/vendor/github.com/miekg/dns/xfr_test.go +++ b/vendor/github.com/miekg/dns/xfr_test.go @@ -39,7 +39,7 @@ func TestAXFR_Miek(t *testing.T) { break } for _, rr := range ex.RR { - t.Log(rr.String()) + // Nothing } } } @@ -90,7 +90,7 @@ func TestAXFR_Miek_Tsig(t *testing.T) { break } for _, rr := range ex.RR { - t.Log(rr.String()) + // Nothing } } } diff --git a/vendor/github.com/miekg/dns/zcompress.go b/vendor/github.com/miekg/dns/zcompress.go index b277978b9..ee9841ed5 100644 --- a/vendor/github.com/miekg/dns/zcompress.go +++ b/vendor/github.com/miekg/dns/zcompress.go @@ -5,83 +5,80 @@ package dns func compressionLenHelperType(c map[string]int, r RR) { switch x := r.(type) { - case *PTR: - compressionLenHelper(c, x.Ptr) - case *SOA: - compressionLenHelper(c, x.Ns) - compressionLenHelper(c, x.Mbox) case *AFSDB: compressionLenHelper(c, x.Hostname) + case *CNAME: + compressionLenHelper(c, x.Target) + case *DNAME: + compressionLenHelper(c, x.Target) case *HIP: for i := range x.RendezvousServers { compressionLenHelper(c, x.RendezvousServers[i]) } + case *KX: + compressionLenHelper(c, x.Exchanger) case *LP: compressionLenHelper(c, x.Fqdn) - case *CNAME: - compressionLenHelper(c, x.Target) case *MB: compressionLenHelper(c, x.Mb) - case *RP: - compressionLenHelper(c, x.Mbox) - compressionLenHelper(c, x.Txt) - case *RRSIG: - compressionLenHelper(c, x.SignerName) + case *MD: + compressionLenHelper(c, x.Md) case *MF: compressionLenHelper(c, x.Mf) + case *MG: + compressionLenHelper(c, x.Mg) case *MINFO: compressionLenHelper(c, x.Rmail) compressionLenHelper(c, x.Email) - case *SIG: - compressionLenHelper(c, x.SignerName) - case *SRV: - compressionLenHelper(c, x.Target) - case *TSIG: - compressionLenHelper(c, x.Algorithm) - case *KX: - compressionLenHelper(c, x.Exchanger) - case *MG: - compressionLenHelper(c, x.Mg) - case *NSAPPTR: - compressionLenHelper(c, x.Ptr) - case *PX: - compressionLenHelper(c, x.Map822) - compressionLenHelper(c, x.Mapx400) - case *DNAME: - compressionLenHelper(c, x.Target) case *MR: compressionLenHelper(c, x.Mr) case *MX: compressionLenHelper(c, x.Mx) - case *TKEY: - compressionLenHelper(c, x.Algorithm) - case *NSEC: - compressionLenHelper(c, x.NextDomain) - case *TALINK: - compressionLenHelper(c, x.PreviousName) - compressionLenHelper(c, x.NextName) - case *MD: - compressionLenHelper(c, x.Md) case *NAPTR: compressionLenHelper(c, x.Replacement) case *NS: compressionLenHelper(c, x.Ns) + case *NSAPPTR: + compressionLenHelper(c, x.Ptr) + case *NSEC: + compressionLenHelper(c, x.NextDomain) + case *PTR: + compressionLenHelper(c, x.Ptr) + case *PX: + compressionLenHelper(c, x.Map822) + compressionLenHelper(c, x.Mapx400) + case *RP: + compressionLenHelper(c, x.Mbox) + compressionLenHelper(c, x.Txt) + case *RRSIG: + compressionLenHelper(c, x.SignerName) case *RT: compressionLenHelper(c, x.Host) + case *SIG: + compressionLenHelper(c, x.SignerName) + case *SOA: + compressionLenHelper(c, x.Ns) + compressionLenHelper(c, x.Mbox) + case *SRV: + compressionLenHelper(c, x.Target) + case *TALINK: + compressionLenHelper(c, x.PreviousName) + compressionLenHelper(c, x.NextName) + case *TKEY: + compressionLenHelper(c, x.Algorithm) + case *TSIG: + compressionLenHelper(c, x.Algorithm) } } func compressionLenSearchType(c map[string]int, r RR) (int, bool) { switch x := r.(type) { - case *MG: - k1, ok1 := compressionLenSearch(c, x.Mg) - 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 *MB: k1, ok1 := compressionLenSearch(c, x.Mb) return k1, ok1 @@ -91,18 +88,8 @@ func compressionLenSearchType(c map[string]int, r RR) (int, bool) { case *MF: k1, ok1 := compressionLenSearch(c, x.Mf) return k1, ok1 - case *NS: - k1, ok1 := compressionLenSearch(c, x.Ns) - 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 *CNAME: - k1, ok1 := compressionLenSearch(c, x.Target) + case *MG: + k1, ok1 := compressionLenSearch(c, x.Mg) return k1, ok1 case *MINFO: k1, ok1 := compressionLenSearch(c, x.Rmail) @@ -114,6 +101,19 @@ func compressionLenSearchType(c map[string]int, r RR) (int, bool) { case *MX: k1, ok1 := compressionLenSearch(c, x.Mx) return k1, ok1 + case *NS: + k1, ok1 := compressionLenSearch(c, x.Ns) + return k1, ok1 + case *PTR: + k1, ok1 := compressionLenSearch(c, x.Ptr) + 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 } return 0, false } diff --git a/vendor/github.com/miekg/dns/ztypes.go b/vendor/github.com/miekg/dns/ztypes.go index 3e534f12e..0613ba09d 100644 --- a/vendor/github.com/miekg/dns/ztypes.go +++ b/vendor/github.com/miekg/dns/ztypes.go @@ -1,5 +1,5 @@ // *** DO NOT MODIFY *** -// AUTOGENERATED BY go generate from type_generate.go +// AUTOGENERATED BY go generate from types_generate.go package dns @@ -163,7 +163,6 @@ var TypeToString = map[uint16]string{ TypeNSAPPTR: "NSAP-PTR", } -// Header() functions func (rr *A) Header() *RR_Header { return &rr.Hdr } func (rr *AAAA) Header() *RR_Header { return &rr.Hdr } func (rr *AFSDB) Header() *RR_Header { return &rr.Hdr } |