updated vendored mdns libs
Juan Batiz-Benet committed
Apr 22, 2015 at 00:49 UTC
58d6d1e7b616f3bf370f7db4f5513dee17ed5de8
45 files changed
+1673
-1471
Godeps/Godeps.json
+2
-2
@@ -125,7 +125,7 @@
125
},
126
{
127
"ImportPath": "github.com/hashicorp/mdns",
128
- "Rev": "e4aba3430cd7360a45a596da8eacff13abb8ae2d"
128
+ "Rev": "2b439d37011456df8ff83a70ffd1cd6046410113"
129
},
130
{
131
"ImportPath": "github.com/hashicorp/yamux",
@@ -228,7 +228,7 @@
228
},
229
{
230
"ImportPath": "github.com/miekg/dns",
231
- "Rev": "a76c0a363dd4798064787c742fdf54a593787e91"
231
+ "Rev": "5a357a6fc5e85268b929350aa6423e2d56dcc4ff"
232
},
233
{
234
"ImportPath": "github.com/mitchellh/go-homedir",
Godeps/_workspace/src/github.com/hashicorp/mdns/client.go
+1
-1
@@ -236,7 +236,7 @@ func (c *client) query(params *QueryParam) error {
236
select {
237
case resp := <-msgCh:
238
var inp *ServiceEntry
239
- for _, answer := range resp.Answer {
239
+ for _, answer := range append(resp.Answer, resp.Extra...) {
240
// TODO(reddaly): Check that response corresponds to serviceAddr?
241
switch rr := answer.(type) {
242
case *dns.PTR:
Godeps/_workspace/src/github.com/hashicorp/mdns/server.go
+6
-20
@@ -267,6 +267,8 @@ func (s *Server) handleQuestion(q dns.Question) (multicastRecs, unicastRecs []dn
267
268
// sendResponse is used to send a response packet
269
func (s *Server) sendResponse(resp *dns.Msg, from net.Addr, unicast bool) error {
270
+ // TODO(reddaly): Respect the unicast argument, and allow sending responses
271
+ // over multicast.
272
buf, err := resp.Pack()
273
if err != nil {
274
return err
@@ -274,27 +276,11 @@ func (s *Server) sendResponse(resp *dns.Msg, from net.Addr, unicast bool) error
276
277
// Determine the socket to send from
278
addr := from.(*net.UDPAddr)
277
- var conn *net.UDPConn
279
if addr.IP.To4() != nil {
279
- conn = s.ipv4List
280
+ _, err = s.ipv4List.WriteToUDP(buf, addr)
281
+ return err
282
} else {
281
- conn = s.ipv6List
282
- }
283
-
284
- // Determine the address to send to if not unicast
285
- if !unicast {
286
- if addr.IP.To4() != nil {
287
- addr = ipv4Addr
288
- } else {
289
- addr = ipv6Addr
290
- }
291
- }
292
-
293
- // Guard against a missing connection or address
294
- if conn == nil || addr == nil {
295
- return fmt.Errorf("Unable to respond, missing connection (%v) or address (%v)",
296
- conn, addr)
283
+ _, err = s.ipv6List.WriteToUDP(buf, addr)
284
+ return err
285
}
298
- _, err = conn.WriteToUDP(buf, addr)
299
- return err
286
}
Godeps/_workspace/src/github.com/hashicorp/mdns/zone.go
+1
-1
@@ -99,7 +99,7 @@ func NewMDNSService(instance, service, domain, hostName string, port int, ips []
99
if err != nil {
100
// Try appending the host domain suffix and lookup again
101
// (required for Linux-based hosts)
102
- tmpHostName := fmt.Sprintf("%s%s.", hostName, domain)
102
+ tmpHostName := fmt.Sprintf("%s%s", hostName, domain)
103
104
ips, err = net.LookupIP(tmpHostName)
105
Godeps/_workspace/src/github.com/miekg/dns/.travis.yml
+2
-17
@@ -1,21 +1,6 @@
1
language: go
2
go:
3
- - 1.2
3
- 1.3
5
-env:
6
- # "gvm update" resets GOOS and GOARCH environment variable, workaround it by setting
7
- # BUILD_GOOS and BUILD_GOARCH and overriding GOARCH and GOOS in the build script
8
- global:
9
- - BUILD_GOARCH=amd64
10
- matrix:
11
- - BUILD_GOOS=linux
12
- - BUILD_GOOS=darwin
13
- - BUILD_GOOS=windows
4
+ - 1.4
5
script:
15
- - gvm cross $BUILD_GOOS $BUILD_GOARCH
16
- - GOARCH=$BUILD_GOARCH GOOS=$BUILD_GOOS go build
17
-
18
- # only test on linux
19
- # also specify -short; the crypto tests fail in weird ways *sometimes*
20
- # See issue #151
21
- - if [ $BUILD_GOOS == "linux" ]; then GOARCH=$BUILD_GOARCH GOOS=$BUILD_GOOS go test -short -bench=.; fi
6
+ - go test -short -bench=.
Godeps/_workspace/src/github.com/miekg/dns/README.md
+2
-1
@@ -35,6 +35,7 @@ A not-so-up-to-date-list-that-may-be-actually-current:
35
* https://github.com/DevelopersPL/godnsagent
36
* https://github.com/duedil-ltd/discodns
37
* https://github.com/StalkR/dns-reverse-proxy
38
+* https://github.com/tianon/rawdns
39
40
Send pull request if you want to be listed here.
41
@@ -68,7 +69,7 @@ correctly, the following should work:
69
70
## Examples
71
71
-A short "how to use the API" is at the beginning of dns.go (this also will show
72
+A short "how to use the API" is at the beginning of doc.go (this also will show
73
when you call `godoc github.com/miekg/dns`).
74
75
Example programs can be found in the `github.com/miekg/exdns` repository.
Godeps/_workspace/src/github.com/miekg/dns/client.go
+8
-1
@@ -55,6 +55,13 @@ func Exchange(m *Msg, a string) (r *Msg, err error) {
55
defer co.Close()
56
co.SetReadDeadline(time.Now().Add(dnsTimeout))
57
co.SetWriteDeadline(time.Now().Add(dnsTimeout))
58
+
59
+ opt := m.IsEdns0()
60
+ // If EDNS0 is used use that for size.
61
+ if opt != nil && opt.UDPSize() >= MinMsgSize {
62
+ co.UDPSize = opt.UDPSize()
63
+ }
64
+
65
if err = co.WriteMsg(m); err != nil {
66
return nil, err
67
}
@@ -290,7 +297,7 @@ func Dial(network, address string) (conn *Conn, err error) {
297
return conn, nil
298
}
299
293
-// Dialtimeout acts like Dial but takes a timeout.
300
+// DialTimeout acts like Dial but takes a timeout.
301
func DialTimeout(network, address string, timeout time.Duration) (conn *Conn, err error) {
302
conn = new(Conn)
303
conn.Conn, err = net.DialTimeout(network, address, timeout)
Godeps/_workspace/src/github.com/miekg/dns/client_test.go
+93
-27
@@ -1,6 +1,7 @@
1
package dns
2
3
import (
4
+ "strconv"
5
"testing"
6
"time"
7
)
@@ -11,7 +12,7 @@ func TestClientSync(t *testing.T) {
12
13
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
14
if err != nil {
14
- t.Fatalf("Unable to run test server: %s", err)
15
+ t.Fatalf("Unable to run test server: %v", err)
16
}
17
defer s.Shutdown()
18
@@ -19,26 +20,20 @@ func TestClientSync(t *testing.T) {
20
m.SetQuestion("miek.nl.", TypeSOA)
21
22
c := new(Client)
22
- r, _, e := c.Exchange(m, addrstr)
23
- if e != nil {
24
- t.Logf("failed to exchange: %s", e.Error())
25
- t.Fail()
23
+ r, _, err := c.Exchange(m, addrstr)
24
+ if err != nil {
25
+ t.Errorf("failed to exchange: %v", err)
26
}
27
if r != nil && r.Rcode != RcodeSuccess {
28
- t.Log("failed to get an valid answer")
29
- t.Fail()
30
- t.Logf("%v\n", r)
28
+ t.Errorf("failed to get an valid answer\n%v", r)
29
}
30
// And now with plain Exchange().
33
- r, e = Exchange(m, addrstr)
34
- if e != nil {
35
- t.Logf("failed to exchange: %s", e.Error())
36
- t.Fail()
31
+ r, err = Exchange(m, addrstr)
32
+ if err != nil {
33
+ t.Errorf("failed to exchange: %v", err)
34
}
35
if r != nil && r.Rcode != RcodeSuccess {
39
- t.Log("failed to get an valid answer")
40
- t.Fail()
41
- t.Logf("%v\n", r)
36
+ t.Errorf("failed to get an valid answer\n%v", r)
37
}
38
}
39
@@ -48,7 +43,7 @@ func TestClientEDNS0(t *testing.T) {
43
44
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
45
if err != nil {
51
- t.Fatalf("Unable to run test server: %s", err)
46
+ t.Fatalf("Unable to run test server: %v", err)
47
}
48
defer s.Shutdown()
49
@@ -57,6 +52,58 @@ func TestClientEDNS0(t *testing.T) {
52
53
m.SetEdns0(2048, true)
54
55
+ c := new(Client)
56
+ r, _, err := c.Exchange(m, addrstr)
57
+ if err != nil {
58
+ t.Errorf("failed to exchange: %v", err)
59
+ }
60
+
61
+ if r != nil && r.Rcode != RcodeSuccess {
62
+ t.Errorf("failed to get an valid answer\n%v", r)
63
+ }
64
+}
65
+
66
+// Validates the transmission and parsing of local EDNS0 options.
67
+func TestClientEDNS0Local(t *testing.T) {
68
+
69
+ optStr1 := "1979:0x0707"
70
+ optStr2 := strconv.Itoa(EDNS0LOCALSTART) + ":0x0601"
71
+
72
+ handler := func(w ResponseWriter, req *Msg) {
73
+ m := new(Msg)
74
+ m.SetReply(req)
75
+
76
+ m.Extra = make([]RR, 1, 2)
77
+ m.Extra[0] = &TXT{Hdr: RR_Header{Name: m.Question[0].Name, Rrtype: TypeTXT, Class: ClassINET, Ttl: 0}, Txt: []string{"Hello local edns"}}
78
+
79
+ // If the local options are what we expect, then reflect them back.
80
+ ec1 := req.Extra[0].(*OPT).Option[0].(*EDNS0_LOCAL).String()
81
+ ec2 := req.Extra[0].(*OPT).Option[1].(*EDNS0_LOCAL).String()
82
+ if ec1 == optStr1 && ec2 == optStr2 {
83
+ m.Extra = append(m.Extra, req.Extra[0])
84
+ }
85
+
86
+ w.WriteMsg(m)
87
+ }
88
+
89
+ HandleFunc("miek.nl.", handler)
90
+ defer HandleRemove("miek.nl.")
91
+
92
+ s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
93
+ if err != nil {
94
+ t.Fatalf("Unable to run test server: %s", err)
95
+ }
96
+ defer s.Shutdown()
97
+
98
+ m := new(Msg)
99
+ m.SetQuestion("miek.nl.", TypeTXT)
100
+
101
+ // Add two local edns options to the query.
102
+ ec1 := &EDNS0_LOCAL{Code: 1979, Data: []byte{7, 7}}
103
+ ec2 := &EDNS0_LOCAL{Code: EDNS0LOCALSTART, Data: []byte{6, 1}}
104
+ o := &OPT{Hdr: RR_Header{Name: ".", Rrtype: TypeOPT}, Option: []EDNS0{ec1, ec2}}
105
+ m.Extra = append(m.Extra, o)
106
+
107
c := new(Client)
108
r, _, e := c.Exchange(m, addrstr)
109
if e != nil {
@@ -65,7 +112,28 @@ func TestClientEDNS0(t *testing.T) {
112
}
113
114
if r != nil && r.Rcode != RcodeSuccess {
68
- t.Log("failed to get an valid answer")
115
+ t.Log("failed to get a valid answer")
116
+ t.Fail()
117
+ t.Logf("%v\n", r)
118
+ }
119
+
120
+ txt := r.Extra[0].(*TXT).Txt[0]
121
+ if txt != "Hello local edns" {
122
+ t.Log("Unexpected result for miek.nl", txt, "!= Hello local edns")
123
+ t.Fail()
124
+ }
125
+
126
+ // Validate the local options in the reply.
127
+ got := r.Extra[1].(*OPT).Option[0].(*EDNS0_LOCAL).String()
128
+ if got != optStr1 {
129
+ t.Log("failed to get local edns0 answer; got %s, expected %s", got, optStr1)
130
+ t.Fail()
131
+ t.Logf("%v\n", r)
132
+ }
133
+
134
+ got = r.Extra[1].(*OPT).Option[1].(*EDNS0_LOCAL).String()
135
+ if got != optStr2 {
136
+ t.Log("failed to get local edns0 answer; got %s, expected %s", got, optStr2)
137
t.Fail()
138
t.Logf("%v\n", r)
139
}
@@ -77,7 +145,7 @@ func TestSingleSingleInflight(t *testing.T) {
145
146
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
147
if err != nil {
80
- t.Fatalf("Unable to run test server: %s", err)
148
+ t.Fatalf("Unable to run test server: %v", err)
149
}
150
defer s.Shutdown()
151
@@ -106,8 +174,7 @@ Loop:
174
first = rtt
175
} else {
176
if first != rtt {
109
- t.Log("all rtts should be equal")
110
- t.Fail()
177
+ t.Errorf("all rtts should be equal. got %d want %d", rtt, first)
178
}
179
}
180
i++
@@ -127,14 +194,14 @@ func ExampleUpdateLeaseTSIG(t *testing.T) {
194
rrs[0] = rr
195
m.Insert(rrs)
196
130
- lease_rr := new(OPT)
131
- lease_rr.Hdr.Name = "."
132
- lease_rr.Hdr.Rrtype = TypeOPT
197
+ leaseRr := new(OPT)
198
+ leaseRr.Hdr.Name = "."
199
+ leaseRr.Hdr.Rrtype = TypeOPT
200
e := new(EDNS0_UL)
201
e.Code = EDNS0UL
202
e.Lease = 120
136
- lease_rr.Option = append(lease_rr.Option, e)
137
- m.Extra = append(m.Extra, lease_rr)
203
+ leaseRr.Option = append(leaseRr.Option, e)
204
+ m.Extra = append(m.Extra, leaseRr)
205
206
c := new(Client)
207
m.SetTsig("polvi.", HmacMD5, 300, time.Now().Unix())
@@ -142,7 +209,6 @@ func ExampleUpdateLeaseTSIG(t *testing.T) {
209
210
_, _, err := c.Exchange(m, "127.0.0.1:53")
211
if err != nil {
145
- t.Log(err.Error())
146
- t.Fail()
212
+ t.Error(err)
213
}
214
}
Godeps/_workspace/src/github.com/miekg/dns/clientconfig.go
+8
-3
@@ -7,7 +7,7 @@ import (
7
"strings"
8
)
9
10
-// Wraps the contents of the /etc/resolv.conf.
10
+// ClientConfig wraps the contents of the /etc/resolv.conf file.
11
type ClientConfig struct {
12
Servers []string // servers to use
13
Search []string // suffixes to append to local name
@@ -26,14 +26,19 @@ func ClientConfigFromFile(resolvconf string) (*ClientConfig, error) {
26
}
27
defer file.Close()
28
c := new(ClientConfig)
29
- b := bufio.NewReader(file)
29
+ scanner := bufio.NewScanner(file)
30
c.Servers = make([]string, 0)
31
c.Search = make([]string, 0)
32
c.Port = "53"
33
c.Ndots = 1
34
c.Timeout = 5
35
c.Attempts = 2
36
- for line, ok := b.ReadString('\n'); ok == nil; line, ok = b.ReadString('\n') {
36
+
37
+ for scanner.Scan() {
38
+ if err := scanner.Err(); err != nil {
39
+ return nil, err
40
+ }
41
+ line := scanner.Text()
42
f := strings.Fields(line)
43
if len(f) < 1 {
44
continue
Godeps/_workspace/src/github.com/miekg/dns/clientconfig_test.go
new
+55
@@ -0,0 +1,55 @@
1
+package dns
2
+
3
+import (
4
+ "io/ioutil"
5
+ "os"
6
+ "path/filepath"
7
+ "testing"
8
+)
9
+
10
+const normal string = `
11
+# Comment
12
+domain somedomain.com
13
+nameserver 10.28.10.2
14
+nameserver 11.28.10.1
15
+`
16
+
17
+const missingNewline string = `
18
+domain somedomain.com
19
+nameserver 10.28.10.2
20
+nameserver 11.28.10.1` // <- NOTE: NO newline.
21
+
22
+func testConfig(t *testing.T, data string) {
23
+ tempDir, err := ioutil.TempDir("", "")
24
+ if err != nil {
25
+ t.Fatalf("TempDir: %v", err)
26
+ }
27
+ defer os.RemoveAll(tempDir)
28
+
29
+ path := filepath.Join(tempDir, "resolv.conf")
30
+ if err := ioutil.WriteFile(path, []byte(data), 0644); err != nil {
31
+ t.Fatalf("WriteFile: %v", err)
32
+ }
33
+ cc, err := ClientConfigFromFile(path)
34
+ if err != nil {
35
+ t.Errorf("error parsing resolv.conf: %v", err)
36
+ }
37
+ if l := len(cc.Servers); l != 2 {
38
+ t.Errorf("incorrect number of nameservers detected: %d", l)
39
+ }
40
+ if l := len(cc.Search); l != 1 {
41
+ t.Errorf("domain directive not parsed correctly: %v", cc.Search)
42
+ } else {
43
+ if cc.Search[0] != "somedomain.com" {
44
+ t.Errorf("domain is unexpected: %v", cc.Search[0])
45
+ }
46
+ }
47
+}
48
+
49
+func TestNameserver(t *testing.T) {
50
+ testConfig(t, normal)
51
+}
52
+
53
+func TestMissingFinalNewLine(t *testing.T) {
54
+ testConfig(t, missingNewline)
55
+}
Godeps/_workspace/src/github.com/miekg/dns/defaults.go
+7
-3
@@ -24,7 +24,9 @@ func (dns *Msg) SetReply(request *Msg) *Msg {
24
return dns
25
}
26
27
-// SetQuestion creates a question message.
27
+// SetQuestion creates a question message, it sets the Question
28
+// section, generates an Id and sets the RecursionDesired (RD)
29
+// bit to true.
30
func (dns *Msg) SetQuestion(z string, t uint16) *Msg {
31
dns.Id = Id()
32
dns.RecursionDesired = true
@@ -33,7 +35,9 @@ func (dns *Msg) SetQuestion(z string, t uint16) *Msg {
35
return dns
36
}
37
36
-// SetNotify creates a notify message.
38
+// SetNotify creates a notify message, it sets the Question
39
+// section, generates an Id and sets the Authoritative (AA)
40
+// bit to true.
41
func (dns *Msg) SetNotify(z string) *Msg {
42
dns.Opcode = OpcodeNotify
43
dns.Authoritative = true
@@ -184,7 +188,7 @@ func IsFqdn(s string) bool {
188
return s[l-1] == '.'
189
}
190
187
-// Fqdns return the fully qualified domain name from s.
191
+// Fqdn return the fully qualified domain name from s.
192
// If s is already fully qualified, it behaves as the identity function.
193
func Fqdn(s string) string {
194
if IsFqdn(s) {
Godeps/_workspace/src/github.com/miekg/dns/dns.go
+10
-99
@@ -1,106 +1,16 @@
1
-// Package dns implements a full featured interface to the Domain Name System.
2
-// Server- and client-side programming is supported.
3
-// The package allows complete control over what is send out to the DNS. The package
4
-// API follows the less-is-more principle, by presenting a small, clean interface.
5
-//
6
-// The package dns supports (asynchronous) querying/replying, incoming/outgoing zone transfers,
7
-// TSIG, EDNS0, dynamic updates, notifies and DNSSEC validation/signing.
8
-// Note that domain names MUST be fully qualified, before sending them, unqualified
9
-// names in a message will result in a packing failure.
10
-//
11
-// Resource records are native types. They are not stored in wire format.
12
-// Basic usage pattern for creating a new resource record:
13
-//
14
-// r := new(dns.MX)
15
-// r.Hdr = dns.RR_Header{Name: "miek.nl.", Rrtype: dns.TypeMX, Class: dns.ClassINET, Ttl: 3600}
16
-// r.Preference = 10
17
-// r.Mx = "mx.miek.nl."
18
-//
19
-// Or directly from a string:
20
-//
21
-// mx, err := dns.NewRR("miek.nl. 3600 IN MX 10 mx.miek.nl.")
22
-//
23
-// Or when the default TTL (3600) and class (IN) suit you:
24
-//
25
-// mx, err := dns.NewRR("miek.nl. MX 10 mx.miek.nl.")
26
-//
27
-// Or even:
28
-//
29
-// mx, err := dns.NewRR("$ORIGIN nl.\nmiek 1H IN MX 10 mx.miek")
30
-//
31
-// In the DNS messages are exchanged, these messages contain resource
32
-// records (sets). Use pattern for creating a message:
33
-//
34
-// m := new(dns.Msg)
35
-// m.SetQuestion("miek.nl.", dns.TypeMX)
36
-//
37
-// Or when not certain if the domain name is fully qualified:
38
-//
39
-// m.SetQuestion(dns.Fqdn("miek.nl"), dns.TypeMX)
40
-//
41
-// The message m is now a message with the question section set to ask
42
-// the MX records for the miek.nl. zone.
43
-//
44
-// The following is slightly more verbose, but more flexible:
45
-//
46
-// m1 := new(dns.Msg)
47
-// m1.Id = dns.Id()
48
-// m1.RecursionDesired = true
49
-// m1.Question = make([]dns.Question, 1)
50
-// m1.Question[0] = dns.Question{"miek.nl.", dns.TypeMX, dns.ClassINET}
51
-//
52
-// After creating a message it can be send.
53
-// Basic use pattern for synchronous querying the DNS at a
54
-// server configured on 127.0.0.1 and port 53:
55
-//
56
-// c := new(dns.Client)
57
-// in, rtt, err := c.Exchange(m1, "127.0.0.1:53")
58
-//
59
-// Suppressing
60
-// multiple outstanding queries (with the same question, type and class) is as easy as setting:
61
-//
62
-// c.SingleInflight = true
63
-//
64
-// If these "advanced" features are not needed, a simple UDP query can be send,
65
-// with:
66
-//
67
-// in, err := dns.Exchange(m1, "127.0.0.1:53")
68
-//
69
-// When this functions returns you will get dns message. A dns message consists
70
-// out of four sections.
71
-// The question section: in.Question, the answer section: in.Answer,
72
-// the authority section: in.Ns and the additional section: in.Extra.
73
-//
74
-// Each of these sections (except the Question section) contain a []RR. Basic
75
-// use pattern for accessing the rdata of a TXT RR as the first RR in
76
-// the Answer section:
77
-//
78
-// if t, ok := in.Answer[0].(*dns.TXT); ok {
79
-// // do something with t.Txt
80
-// }
81
-//
82
-// Domain Name and TXT Character String Representations
83
-//
84
-// Both domain names and TXT character strings are converted to presentation
85
-// form both when unpacked and when converted to strings.
86
-//
87
-// For TXT character strings, tabs, carriage returns and line feeds will be
88
-// converted to \t, \r and \n respectively. Back slashes and quotations marks
89
-// will be escaped. Bytes below 32 and above 127 will be converted to \DDD
90
-// form.
91
-//
92
-// For domain names, in addition to the above rules brackets, periods,
93
-// spaces, semicolons and the at symbol are escaped.
1
package dns
2
3
import "strconv"
4
5
const (
99
- year68 = 1 << 31 // For RFC1982 (Serial Arithmetic) calculations in 32 bits.
100
- DefaultMsgSize = 4096 // Standard default for larger than 512 bytes.
101
- MinMsgSize = 512 // Minimal size of a DNS packet.
102
- MaxMsgSize = 65536 // Largest possible DNS packet.
103
- defaultTtl = 3600 // Default TTL.
6
+ year68 = 1 << 31 // For RFC1982 (Serial Arithmetic) calculations in 32 bits.
7
+ // DefaultMsgSize is the standard default for messages larger than 512 bytes.
8
+ DefaultMsgSize = 4096
9
+ // MinMsgSize is the minimal size of a DNS packet.
10
+ MinMsgSize = 512
11
+ // MaxMsgSize is the largest possible DNS packet.
12
+ MaxMsgSize = 65535
13
+ defaultTtl = 3600 // Default internal TTL.
14
)
15
16
// Error represents a DNS error
@@ -137,9 +47,10 @@ type RR_Header struct {
47
Rdlength uint16 // length of data after header
48
}
49
50
+// Header returns itself. This is here to make RR_Header implement the RR interface.
51
func (h *RR_Header) Header() *RR_Header { return h }
52
142
-// Just to imlement the RR interface
53
+// Just to imlement the RR interface.
54
func (h *RR_Header) copy() RR { return nil }
55
56
func (h *RR_Header) copyHeader() *RR_Header {
Godeps/_workspace/src/github.com/miekg/dns/dns_test.go
+109
-66
@@ -17,13 +17,11 @@ func TestPackUnpack(t *testing.T) {
17
out.Answer[0] = key
18
msg, err := out.Pack()
19
if err != nil {
20
- t.Log("failed to pack msg with DNSKEY")
21
- t.Fail()
20
+ t.Error("failed to pack msg with DNSKEY")
21
}
22
in := new(Msg)
23
if in.Unpack(msg) != nil {
25
- t.Log("failed to unpack msg with DNSKEY")
26
- t.Fail()
24
+ t.Error("failed to unpack msg with DNSKEY")
25
}
26
27
sig := new(RRSIG)
@@ -35,13 +33,11 @@ func TestPackUnpack(t *testing.T) {
33
out.Answer[0] = sig
34
msg, err = out.Pack()
35
if err != nil {
38
- t.Log("failed to pack msg with RRSIG")
39
- t.Fail()
36
+ t.Error("failed to pack msg with RRSIG")
37
}
38
39
if in.Unpack(msg) != nil {
43
- t.Log("failed to unpack msg with RRSIG")
44
- t.Fail()
40
+ t.Error("failed to unpack msg with RRSIG")
41
}
42
}
43
@@ -62,8 +58,7 @@ func TestPackUnpack2(t *testing.T) {
58
m.Answer[0] = rr
59
_, err := m.Pack()
60
if err != nil {
65
- t.Log("Packing failed: " + err.Error())
66
- t.Fail()
61
+ t.Error("Packing failed: ", err)
62
return
63
}
64
}
@@ -90,16 +85,14 @@ func TestPackUnpack3(t *testing.T) {
85
m.Answer[0] = rr
86
b, err := m.Pack()
87
if err != nil {
93
- t.Log("packing failed: " + err.Error())
94
- t.Fail()
88
+ t.Error("packing failed: ", err)
89
return
90
}
91
92
var unpackMsg Msg
93
err = unpackMsg.Unpack(b)
94
if err != nil {
101
- t.Log("unpacking failed")
102
- t.Fail()
95
+ t.Error("unpacking failed")
96
return
97
}
98
}
@@ -111,10 +104,9 @@ func TestBailiwick(t *testing.T) {
104
}
105
for parent, child := range yes {
106
if !IsSubDomain(parent, child) {
114
- t.Logf("%s should be child of %s\n", child, parent)
115
- t.Logf("comparelabels %d", CompareDomainName(parent, child))
116
- t.Logf("lenlabels %d %d", CountLabel(parent), CountLabel(child))
117
- t.Fail()
107
+ t.Errorf("%s should be child of %s", child, parent)
108
+ t.Errorf("comparelabels %d", CompareDomainName(parent, child))
109
+ t.Errorf("lenlabels %d %d", CountLabel(parent), CountLabel(child))
110
}
111
}
112
no := map[string]string{
@@ -126,10 +118,9 @@ func TestBailiwick(t *testing.T) {
118
}
119
for parent, child := range no {
120
if IsSubDomain(parent, child) {
129
- t.Logf("%s should not be child of %s\n", child, parent)
130
- t.Logf("comparelabels %d", CompareDomainName(parent, child))
131
- t.Logf("lenlabels %d %d", CountLabel(parent), CountLabel(child))
132
- t.Fail()
121
+ t.Errorf("%s should not be child of %s", child, parent)
122
+ t.Errorf("comparelabels %d", CompareDomainName(parent, child))
123
+ t.Errorf("lenlabels %d %d", CountLabel(parent), CountLabel(child))
124
}
125
}
126
}
@@ -142,13 +133,11 @@ func TestPack(t *testing.T) {
133
for _, r := range rr {
134
m.Answer[0], err = NewRR(r)
135
if err != nil {
145
- t.Logf("failed to create RR: %s\n", err.Error())
146
- t.Fail()
136
+ t.Errorf("failed to create RR: %v", err)
137
continue
138
}
139
if _, err := m.Pack(); err != nil {
150
- t.Logf("packing failed: %s\n", err.Error())
151
- t.Fail()
140
+ t.Errorf("packing failed: %v", err)
141
}
142
}
143
x := new(Msg)
@@ -160,20 +149,17 @@ func TestPack(t *testing.T) {
149
// This crashes due to the fact the a.ntpns.org isn't a FQDN
150
// How to recover() from a remove panic()?
151
if _, err := x.Pack(); err == nil {
163
- t.Log("packing should fail")
164
- t.Fail()
152
+ t.Error("packing should fail")
153
}
154
x.Answer = make([]RR, 1)
155
x.Answer[0], err = NewRR(rr[0])
156
if _, err := x.Pack(); err == nil {
169
- t.Log("packing should fail")
170
- t.Fail()
157
+ t.Error("packing should fail")
158
}
159
x.Question = make([]Question, 1)
160
x.Question[0] = Question{";sd#eddddséâèµââ
â¥âxzztsestxssweewwsssstx@s@Zåµe@cn.pool.ntp.org.", TypeA, ClassINET}
161
if _, err := x.Pack(); err == nil {
175
- t.Log("packing should fail")
176
- t.Fail()
162
+ t.Error("packing should fail")
163
}
164
}
165
@@ -186,11 +172,10 @@ func TestPackNAPTR(t *testing.T) {
172
rr, _ := NewRR(n)
173
msg := make([]byte, rr.len())
174
if off, err := PackRR(rr, msg, 0, nil, false); err != nil {
189
- t.Logf("packing failed: %s", err.Error())
190
- t.Logf("length %d, need more than %d\n", rr.len(), off)
191
- t.Fail()
175
+ t.Errorf("packing failed: %v", err)
176
+ t.Errorf("length %d, need more than %d", rr.len(), off)
177
} else {
193
- t.Logf("buf size needed: %d\n", off)
178
+ t.Logf("buf size needed: %d", off)
179
}
180
}
181
}
@@ -229,12 +214,10 @@ func TestMsgCompressLength(t *testing.T) {
214
buf, err := msg.Pack()
215
if err != nil {
216
t.Error(err)
232
- t.Fail()
217
}
218
if predicted < len(buf) {
235
- t.Errorf("predicted compressed length is wrong: predicted %s (len=%d) %d, actual %d\n",
219
+ t.Errorf("predicted compressed length is wrong: predicted %s (len=%d) %d, actual %d",
220
msg.Question[0].Name, len(msg.Answer), predicted, len(buf))
237
- t.Fail()
221
}
222
}
223
}
@@ -261,12 +244,10 @@ func TestMsgLength(t *testing.T) {
244
buf, err := msg.Pack()
245
if err != nil {
246
t.Error(err)
264
- t.Fail()
247
}
248
if predicted < len(buf) {
267
- t.Errorf("predicted length is wrong: predicted %s (len=%d), actual %d\n",
249
+ t.Errorf("predicted length is wrong: predicted %s (len=%d), actual %d",
250
msg.Question[0].Name, predicted, len(buf))
269
- t.Fail()
251
}
252
}
253
}
@@ -400,10 +381,10 @@ func BenchmarkMsgUnpack(b *testing.B) {
381
name1 := "12345678901234567890123456789012345.12345678.123."
382
rrMx, _ := NewRR(name1 + " 3600 IN MX 10 " + name1)
383
msg := makeMsg(name1, []RR{rrMx, rrMx}, nil, nil)
403
- msg_buf, _ := msg.Pack()
384
+ msgBuf, _ := msg.Pack()
385
b.ResetTimer()
386
for i := 0; i < b.N; i++ {
406
- _ = msg.Unpack(msg_buf)
387
+ _ = msg.Unpack(msgBuf)
388
}
389
}
390
@@ -441,7 +422,7 @@ func TestToRFC3597(t *testing.T) {
422
x := new(RFC3597)
423
x.ToRFC3597(a)
424
if x.String() != `miek.nl. 3600 CLASS1 TYPE1 \# 4 0a000101` {
444
- t.Fail()
425
+ t.Error("string mismatch")
426
}
427
}
428
@@ -453,10 +434,9 @@ func TestNoRdataPack(t *testing.T) {
434
}
435
r := fn()
436
*r.Header() = RR_Header{Name: "miek.nl.", Rrtype: typ, Class: ClassINET, Ttl: 3600}
456
- _, e := PackRR(r, data, 0, nil, false)
457
- if e != nil {
458
- t.Logf("failed to pack RR with zero rdata: %s: %s\n", TypeToString[typ], e.Error())
459
- t.Fail()
437
+ _, err := PackRR(r, data, 0, nil, false)
438
+ if err != nil {
439
+ t.Errorf("failed to pack RR with zero rdata: %s: %v", TypeToString[typ], err)
440
}
441
}
442
}
@@ -472,17 +452,17 @@ func TestNoRdataUnpack(t *testing.T) {
452
}
453
r := fn()
454
*r.Header() = RR_Header{Name: "miek.nl.", Rrtype: typ, Class: ClassINET, Ttl: 3600}
475
- off, e := PackRR(r, data, 0, nil, false)
476
- if e != nil {
477
- // Should always works, TestNoDataPack should have catched this
455
+ off, err := PackRR(r, data, 0, nil, false)
456
+ if err != nil {
457
+ // Should always works, TestNoDataPack should have caught this
458
+ t.Errorf("failed to pack RR: %v", err)
459
continue
460
}
480
- rr, _, e := UnpackRR(data[:off], 0)
481
- if e != nil {
482
- t.Logf("failed to unpack RR with zero rdata: %s: %s\n", TypeToString[typ], e.Error())
483
- t.Fail()
461
+ rr, _, err := UnpackRR(data[:off], 0)
462
+ if err != nil {
463
+ t.Errorf("failed to unpack RR with zero rdata: %s: %v", TypeToString[typ], err)
464
}
485
- t.Logf("%s\n", rr)
465
+ t.Log(rr)
466
}
467
}
468
@@ -510,6 +490,48 @@ func TestCopy(t *testing.T) {
490
}
491
}
492
493
+func TestMsgCopy(t *testing.T) {
494
+ m := new(Msg)
495
+ m.SetQuestion("miek.nl.", TypeA)
496
+ rr, _ := NewRR("miek.nl. 2311 IN A 127.0.0.1")
497
+ m.Answer = []RR{rr}
498
+ rr, _ = NewRR("miek.nl. 2311 IN NS 127.0.0.1")
499
+ m.Ns = []RR{rr}
500
+
501
+ m1 := m.Copy()
502
+ if m.String() != m1.String() {
503
+ t.Fatalf("Msg.Copy() failed %s != %s", m.String(), m1.String())
504
+ }
505
+
506
+ m1.Answer[0], _ = NewRR("somethingelse.nl. 2311 IN A 127.0.0.1")
507
+ if m.String() == m1.String() {
508
+ t.Fatalf("Msg.Copy() failed; change to copy changed template %s", m.String())
509
+ }
510
+
511
+ rr, _ = NewRR("miek.nl. 2311 IN A 127.0.0.2")
512
+ m1.Answer = append(m1.Answer, rr)
513
+ if m1.Ns[0].String() == m1.Answer[1].String() {
514
+ t.Fatalf("Msg.Copy() failed; append changed underlying array %s", m1.Ns[0].String())
515
+ }
516
+}
517
+
518
+func BenchmarkCopy(b *testing.B) {
519
+ b.ReportAllocs()
520
+ m := new(Msg)
521
+ m.SetQuestion("miek.nl.", TypeA)
522
+ rr, _ := NewRR("miek.nl. 2311 IN A 127.0.0.1")
523
+ m.Answer = []RR{rr}
524
+ rr, _ = NewRR("miek.nl. 2311 IN NS 127.0.0.1")
525
+ m.Ns = []RR{rr}
526
+ rr, _ = NewRR("miek.nl. 2311 IN A 127.0.0.1")
527
+ m.Extra = []RR{rr}
528
+
529
+ b.ResetTimer()
530
+ for i := 0; i < b.N; i++ {
531
+ m.Copy()
532
+ }
533
+}
534
+
535
func TestPackIPSECKEY(t *testing.T) {
536
tests := []string{
537
"38.2.0.192.in-addr.arpa. 7200 IN IPSECKEY ( 10 1 2 192.0.2.38 AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ== )",
@@ -521,18 +543,39 @@ func TestPackIPSECKEY(t *testing.T) {
543
buf := make([]byte, 1024)
544
for _, t1 := range tests {
545
rr, _ := NewRR(t1)
524
- off, e := PackRR(rr, buf, 0, nil, false)
525
- if e != nil {
526
- t.Logf("failed to pack IPSECKEY %s: %s\n", e, t1)
527
- t.Fail()
546
+ off, err := PackRR(rr, buf, 0, nil, false)
547
+ if err != nil {
548
+ t.Errorf("failed to pack IPSECKEY %v: %s", err, t1)
549
continue
550
}
551
531
- rr, _, e = UnpackRR(buf[:off], 0)
532
- if e != nil {
533
- t.Logf("failed to unpack IPSECKEY %s: %s\n", e, t1)
534
- t.Fail()
552
+ rr, _, err = UnpackRR(buf[:off], 0)
553
+ if err != nil {
554
+ t.Errorf("failed to unpack IPSECKEY %v: %s", err, t1)
555
+ }
556
+ t.Log(rr)
557
+ }
558
+}
559
+
560
+func TestMsgPackBuffer(t *testing.T) {
561
+ var testMessages = []string{
562
+ // news.ycombinator.com.in.escapemg.com. IN A, response
563
+ "586285830001000000010000046e6577730b79636f6d62696e61746f7203636f6d02696e086573636170656d6703636f6d0000010001c0210006000100000e10002c036e7332c02103646e730b67726f6f7665736861726bc02d77ed50e600002a3000000e1000093a8000000e10",
564
+
565
+ // news.ycombinator.com.in.escapemg.com. IN A, question
566
+ "586201000001000000000000046e6577730b79636f6d62696e61746f7203636f6d02696e086573636170656d6703636f6d0000010001",
567
+
568
+ "398781020001000000000000046e6577730b79636f6d62696e61746f7203636f6d0000010001",
569
+ }
570
+
571
+ for i, hexData := range testMessages {
572
+ // we won't fail the decoding of the hex
573
+ input, _ := hex.DecodeString(hexData)
574
+ m := new(Msg)
575
+ if err := m.Unpack(input); err != nil {
576
+ t.Errorf("packet %d failed to unpack", i)
577
+ continue
578
}
536
- t.Logf("%s\n", rr)
579
+ t.Logf("packet %d %s", i, m.String())
580
}
581
}
Godeps/_workspace/src/github.com/miekg/dns/dnssec.go
+22
-16
@@ -1,16 +1,3 @@
1
-// DNSSEC
2
-//
3
-// DNSSEC (DNS Security Extension) adds a layer of security to the DNS. It
4
-// uses public key cryptography to sign resource records. The
5
-// public keys are stored in DNSKEY records and the signatures in RRSIG records.
6
-//
7
-// Requesting DNSSEC information for a zone is done by adding the DO (DNSSEC OK) bit
8
-// to an request.
9
-//
10
-// m := new(dns.Msg)
11
-// m.SetEdns0(4096, true)
12
-//
13
-// Signature generation, signature verification and key generation are all supported.
1
package dns
2
3
import (
@@ -202,6 +189,22 @@ func (k *DNSKEY) ToDS(h uint8) *DS {
189
return ds
190
}
191
192
+// ToCDNSKEY converts a DNSKEY record to a CDNSKEY record.
193
+func (k *DNSKEY) ToCDNSKEY() *CDNSKEY {
194
+ c := &CDNSKEY{DNSKEY: *k}
195
+ c.Hdr = *k.Hdr.copyHeader()
196
+ c.Hdr.Rrtype = TypeCDNSKEY
197
+ return c
198
+}
199
+
200
+// ToCDS converts a DS record to a CDS record.
201
+func (d *DS) ToCDS() *CDS {
202
+ c := &CDS{DS: *d}
203
+ c.Hdr = *d.Hdr.copyHeader()
204
+ c.Hdr.Rrtype = TypeCDS
205
+ return c
206
+}
207
+
208
// Sign signs an RRSet. The signature needs to be filled in with
209
// the values: Inception, Expiration, KeyTag, SignerName and Algorithm.
210
// The rest is copied from the RRset. Sign returns true when the signing went OK,
@@ -422,8 +425,8 @@ func (rr *RRSIG) ValidityPeriod(t time.Time) bool {
425
}
426
427
// Return the signatures base64 encodedig sigdata as a byte slice.
425
-func (s *RRSIG) sigBuf() []byte {
426
- sigbuf, err := fromBase64([]byte(s.Signature))
428
+func (rr *RRSIG) sigBuf() []byte {
429
+ sigbuf, err := fromBase64([]byte(rr.Signature))
430
if err != nil {
431
return nil
432
}
@@ -588,7 +591,10 @@ func rawSignatureData(rrset []RR, s *RRSIG) (buf []byte, err error) {
591
wires[i] = wire
592
}
593
sort.Sort(wires)
591
- for _, wire := range wires {
594
+ for i, wire := range wires {
595
+ if i > 0 && bytes.Equal(wire, wires[i-1]) {
596
+ continue
597
+ }
598
buf = append(buf, wire...)
599
}
600
return buf, nil
Godeps/_workspace/src/github.com/miekg/dns/dnssec_keygen.go
+7
-7
@@ -15,8 +15,8 @@ import (
15
// what kind of DNSKEY will be generated.
16
// The ECDSA algorithms imply a fixed keysize, in that case
17
// bits should be set to the size of the algorithm.
18
-func (r *DNSKEY) Generate(bits int) (PrivateKey, error) {
19
- switch r.Algorithm {
18
+func (k *DNSKEY) Generate(bits int) (PrivateKey, error) {
19
+ switch k.Algorithm {
20
case DSA, DSANSEC3SHA1:
21
if bits != 1024 {
22
return nil, ErrKeySize
@@ -39,7 +39,7 @@ func (r *DNSKEY) Generate(bits int) (PrivateKey, error) {
39
}
40
}
41
42
- switch r.Algorithm {
42
+ switch k.Algorithm {
43
case DSA, DSANSEC3SHA1:
44
params := new(dsa.Parameters)
45
if err := dsa.GenerateParameters(params, rand.Reader, dsa.L1024N160); err != nil {
@@ -51,18 +51,18 @@ func (r *DNSKEY) Generate(bits int) (PrivateKey, error) {
51
if err != nil {
52
return nil, err
53
}
54
- r.setPublicKeyDSA(params.Q, params.P, params.G, priv.PublicKey.Y)
54
+ k.setPublicKeyDSA(params.Q, params.P, params.G, priv.PublicKey.Y)
55
return (*DSAPrivateKey)(priv), nil
56
case RSAMD5, RSASHA1, RSASHA256, RSASHA512, RSASHA1NSEC3SHA1:
57
priv, err := rsa.GenerateKey(rand.Reader, bits)
58
if err != nil {
59
return nil, err
60
}
61
- r.setPublicKeyRSA(priv.PublicKey.E, priv.PublicKey.N)
61
+ k.setPublicKeyRSA(priv.PublicKey.E, priv.PublicKey.N)
62
return (*RSAPrivateKey)(priv), nil
63
case ECDSAP256SHA256, ECDSAP384SHA384:
64
var c elliptic.Curve
65
- switch r.Algorithm {
65
+ switch k.Algorithm {
66
case ECDSAP256SHA256:
67
c = elliptic.P256()
68
case ECDSAP384SHA384:
@@ -72,7 +72,7 @@ func (r *DNSKEY) Generate(bits int) (PrivateKey, error) {
72
if err != nil {
73
return nil, err
74
}
75
- r.setPublicKeyECDSA(priv.PublicKey.X, priv.PublicKey.Y)
75
+ k.setPublicKeyECDSA(priv.PublicKey.X, priv.PublicKey.Y)
76
return (*ECDSAPrivateKey)(priv), nil
77
default:
78
return nil, ErrAlg
Godeps/_workspace/src/github.com/miekg/dns/dnssec_keyscan.go
+8
-6
@@ -9,6 +9,8 @@ import (
9
"strings"
10
)
11
12
+// NewPrivateKey returns a PrivateKey by parsing the string s.
13
+// s should be in the same form of the BIND private key files.
14
func (k *DNSKEY) NewPrivateKey(s string) (PrivateKey, error) {
15
if s[len(s)-1] != '\n' { // We need a closing newline
16
return k.ReadPrivateKey(strings.NewReader(s+"\n"), "")
@@ -170,9 +172,9 @@ func parseKey(r io.Reader, file string) (map[string]string, error) {
172
for l := range c {
173
// It should alternate
174
switch l.value {
173
- case _KEY:
175
+ case zKey:
176
k = l.token
175
- case _VALUE:
177
+ case zValue:
178
if k == "" {
179
return nil, &ParseError{file, "no private key seen", l}
180
}
@@ -202,14 +204,14 @@ func klexer(s *scan, c chan lex) {
204
}
205
l.token = str
206
if key {
205
- l.value = _KEY
207
+ l.value = zKey
208
c <- l
209
// Next token is a space, eat it
210
s.tokenText()
211
key = false
212
str = ""
213
} else {
212
- l.value = _VALUE
214
+ l.value = zValue
215
}
216
case ';':
217
commt = true
@@ -218,7 +220,7 @@ func klexer(s *scan, c chan lex) {
220
// Reset a comment
221
commt = false
222
}
221
- l.value = _VALUE
223
+ l.value = zValue
224
l.token = str
225
c <- l
226
str = ""
@@ -235,7 +237,7 @@ func klexer(s *scan, c chan lex) {
237
if len(str) > 0 {
238
// Send remainder
239
l.token = str
238
- l.value = _VALUE
240
+ l.value = zValue
241
c <- l
242
}
243
}
Godeps/_workspace/src/github.com/miekg/dns/dnssec_privkey.go
+9
-8
@@ -10,8 +10,9 @@ import (
10
"strconv"
11
)
12
13
-const _FORMAT = "Private-key-format: v1.3\n"
13
+const format = "Private-key-format: v1.3\n"
14
15
+// PrivateKey ... TODO(miek)
16
type PrivateKey interface {
17
Sign([]byte, uint8) ([]byte, error)
18
String(uint8) string
@@ -53,17 +54,17 @@ func (p *RSAPrivateKey) String(alg uint8) string {
54
// Calculate Exponent1/2 and Coefficient as per: http://en.wikipedia.org/wiki/RSA#Using_the_Chinese_remainder_algorithm
55
// and from: http://code.google.com/p/go/issues/detail?id=987
56
one := big.NewInt(1)
56
- p_1 := big.NewInt(0).Sub(p.Primes[0], one)
57
- q_1 := big.NewInt(0).Sub(p.Primes[1], one)
58
- exp1 := big.NewInt(0).Mod(p.D, p_1)
59
- exp2 := big.NewInt(0).Mod(p.D, q_1)
57
+ p1 := big.NewInt(0).Sub(p.Primes[0], one)
58
+ q1 := big.NewInt(0).Sub(p.Primes[1], one)
59
+ exp1 := big.NewInt(0).Mod(p.D, p1)
60
+ exp2 := big.NewInt(0).Mod(p.D, q1)
61
coeff := big.NewInt(0).ModInverse(p.Primes[1], p.Primes[0])
62
63
exponent1 := toBase64(exp1.Bytes())
64
exponent2 := toBase64(exp2.Bytes())
65
coefficient := toBase64(coeff.Bytes())
66
66
- return _FORMAT +
67
+ return format +
68
"Algorithm: " + algorithm + "\n" +
69
"Modulus: " + modulus + "\n" +
70
"PublicExponent: " + publicExponent + "\n" +
@@ -106,7 +107,7 @@ func (p *ECDSAPrivateKey) String(alg uint8) string {
107
intlen = 48
108
}
109
private := toBase64(intToBytes(p.D, intlen))
109
- return _FORMAT +
110
+ return format +
111
"Algorithm: " + algorithm + "\n" +
112
"PrivateKey: " + private + "\n"
113
}
@@ -133,7 +134,7 @@ func (p *DSAPrivateKey) String(alg uint8) string {
134
base := toBase64(intToBytes(p.PublicKey.Parameters.G, 64+T*8))
135
priv := toBase64(intToBytes(p.X, 20))
136
pub := toBase64(intToBytes(p.PublicKey.Y, 64+T*8))
136
- return _FORMAT +
137
+ return format +
138
"Algorithm: " + algorithm + "\n" +
139
"Prime(p): " + prime + "\n" +
140
"Subprime(q): " + subprime + "\n" +
Godeps/_workspace/src/github.com/miekg/dns/dnssec_test.go
+55
-77
@@ -45,8 +45,8 @@ func TestGenerateEC(t *testing.T) {
45
key.Protocol = 3
46
key.Algorithm = ECDSAP256SHA256
47
privkey, _ := key.Generate(256)
48
- t.Logf("%s\n", key.String())
49
- t.Logf("%s\n", key.PrivateKeyString(privkey))
48
+ t.Log(key.String())
49
+ t.Log(key.PrivateKeyString(privkey))
50
}
51
52
func TestGenerateDSA(t *testing.T) {
@@ -62,8 +62,8 @@ func TestGenerateDSA(t *testing.T) {
62
key.Protocol = 3
63
key.Algorithm = DSA
64
privkey, _ := key.Generate(1024)
65
- t.Logf("%s\n", key.String())
66
- t.Logf("%s\n", key.PrivateKeyString(privkey))
65
+ t.Log(key.String())
66
+ t.Log(key.PrivateKeyString(privkey))
67
}
68
69
func TestGenerateRSA(t *testing.T) {
@@ -79,8 +79,8 @@ func TestGenerateRSA(t *testing.T) {
79
key.Protocol = 3
80
key.Algorithm = RSASHA256
81
privkey, _ := key.Generate(1024)
82
- t.Logf("%s\n", key.String())
83
- t.Logf("%s\n", key.PrivateKeyString(privkey))
82
+ t.Log(key.String())
83
+ t.Log(key.PrivateKeyString(privkey))
84
}
85
86
func TestSecure(t *testing.T) {
@@ -107,10 +107,9 @@ func TestSecure(t *testing.T) {
107
key.Algorithm = RSASHA256
108
key.PublicKey = "AwEAAcNEU67LJI5GEgF9QLNqLO1SMq1EdoQ6E9f85ha0k0ewQGCblyW2836GiVsm6k8Kr5ECIoMJ6fZWf3CQSQ9ycWfTyOHfmI3eQ/1Covhb2y4bAmL/07PhrL7ozWBW3wBfM335Ft9xjtXHPy7ztCbV9qZ4TVDTW/Iyg0PiwgoXVesz"
109
110
- // It should validate. Period is checked seperately, so this will keep on working
110
+ // It should validate. Period is checked separately, so this will keep on working
111
if sig.Verify(key, []RR{soa}) != nil {
112
- t.Log("failure to validate")
113
- t.Fail()
112
+ t.Error("failure to validate")
113
}
114
}
115
@@ -131,15 +130,13 @@ func TestSignature(t *testing.T) {
130
131
// Should not be valid
132
if sig.ValidityPeriod(time.Now()) {
134
- t.Log("should not be valid")
135
- t.Fail()
133
+ t.Error("should not be valid")
134
}
135
136
sig.Inception = 315565800 //Tue Jan 1 10:10:00 CET 1980
137
sig.Expiration = 4102477800 //Fri Jan 1 10:10:00 CET 2100
138
if !sig.ValidityPeriod(time.Now()) {
141
- t.Log("should be valid")
142
- t.Fail()
139
+ t.Error("should be valid")
140
}
141
}
142
@@ -196,16 +193,14 @@ func TestSignVerify(t *testing.T) {
193
194
for _, r := range []RR{soa, soa1, srv} {
195
if sig.Sign(privkey, []RR{r}) != nil {
199
- t.Log("failure to sign the record")
200
- t.Fail()
196
+ t.Error("failure to sign the record")
197
continue
198
}
199
if sig.Verify(key, []RR{r}) != nil {
204
- t.Log("failure to validate")
205
- t.Fail()
200
+ t.Error("failure to validate")
201
continue
202
}
208
- t.Logf("validated: %s\n", r.Header().Name)
203
+ t.Logf("validated: %s", r.Header().Name)
204
}
205
}
206
@@ -234,16 +229,14 @@ func Test65534(t *testing.T) {
229
sig.SignerName = key.Hdr.Name
230
sig.Algorithm = RSASHA256
231
if err := sig.Sign(privkey, []RR{t6}); err != nil {
237
- t.Log(err)
238
- t.Log("failure to sign the TYPE65534 record")
239
- t.Fail()
232
+ t.Error(err)
233
+ t.Error("failure to sign the TYPE65534 record")
234
}
235
if err := sig.Verify(key, []RR{t6}); err != nil {
242
- t.Log(err)
243
- t.Log("failure to validate")
244
- t.Fail()
236
+ t.Error(err)
237
+ t.Error("failure to validate")
238
} else {
246
- t.Logf("validated: %s\n", t6.Header().Name)
239
+ t.Logf("validated: %s", t6.Header().Name)
240
}
241
}
242
@@ -271,13 +264,11 @@ Coefficient: UuRoNqe7YHnKmQzE6iDWKTMIWTuoqqrFAmXPmKQnC+Y+BQzOVEHUo9bXdDnoI9hzXP1
264
t.Fatal(err)
265
}
266
if pubkey.(*DNSKEY).PublicKey != "AwEAAZuMCu2FdugHkTrXYgl5qixvcDw1aDDlvL46/xJKbHBAHY16fNUb2b65cwko2Js/aJxUYJbZk5dwCDZxYfrfbZVtDPQuc3o8QaChVxC7/JYz2AHc9qHvqQ1j4VrH71RWINlQo6VYjzN/BGpMhOZoZOEwzp1HfsOE3lNYcoWU1smL" {
274
- t.Log("pubkey is not what we've read")
275
- t.Fail()
267
+ t.Error("pubkey is not what we've read")
268
}
269
if pubkey.(*DNSKEY).PrivateKeyString(privkey) != privStr {
278
- t.Log("privkey is not what we've read")
279
- t.Logf("%v", pubkey.(*DNSKEY).PrivateKeyString(privkey))
280
- t.Fail()
270
+ t.Error("privkey is not what we've read")
271
+ t.Errorf("%v", pubkey.(*DNSKEY).PrivateKeyString(privkey))
272
}
273
}
274
@@ -294,8 +285,7 @@ func TestTag(t *testing.T) {
285
286
tag := key.KeyTag()
287
if tag != 12051 {
297
- t.Logf("wrong key tag: %d for key %v\n", tag, key)
298
- t.Fail()
288
+ t.Errorf("wrong key tag: %d for key %v", tag, key)
289
}
290
}
291
@@ -335,13 +325,11 @@ func TestKeyRSA(t *testing.T) {
325
sig.SignerName = key.Hdr.Name
326
327
if err := sig.Sign(priv, []RR{soa}); err != nil {
338
- t.Logf("failed to sign")
339
- t.Fail()
328
+ t.Error("failed to sign")
329
return
330
}
331
if err := sig.Verify(key, []RR{soa}); err != nil {
343
- t.Logf("failed to verify")
344
- t.Fail()
332
+ t.Error("failed to verify")
333
}
334
}
335
@@ -358,8 +346,7 @@ func TestKeyToDS(t *testing.T) {
346
347
ds := key.ToDS(SHA1)
348
if strings.ToUpper(ds.Digest) != "B5121BDB5B8D86D0CC5FFAFBAAABE26C3E20BAC1" {
361
- t.Logf("wrong DS digest for SHA1\n%v\n", ds)
362
- t.Fail()
349
+ t.Errorf("wrong DS digest for SHA1\n%v", ds)
350
}
351
}
352
@@ -384,23 +371,18 @@ Activate: 20110302104537`
371
k := xk.(*DNSKEY)
372
p, err := k.NewPrivateKey(priv)
373
if err != nil {
387
- t.Logf("%v\n", err)
388
- t.Fail()
374
+ t.Error(err)
375
}
376
switch priv := p.(type) {
377
case *RSAPrivateKey:
378
if 65537 != priv.PublicKey.E {
393
- t.Log("exponenent should be 65537")
394
- t.Fail()
379
+ t.Error("exponenent should be 65537")
380
}
381
default:
397
- t.Logf("we should have read an RSA key: %v", priv)
398
- t.Fail()
382
+ t.Errorf("we should have read an RSA key: %v", priv)
383
}
384
if k.KeyTag() != 37350 {
401
- t.Logf("%d %v\n", k.KeyTag(), k)
402
- t.Log("keytag should be 37350")
403
- t.Fail()
385
+ t.Errorf("keytag should be 37350, got %d %v", k.KeyTag(), k)
386
}
387
388
soa := new(SOA)
@@ -423,9 +405,7 @@ Activate: 20110302104537`
405
406
sig.Sign(p, []RR{soa})
407
if sig.Signature != "D5zsobpQcmMmYsUMLxCVEtgAdCvTu8V/IEeP4EyLBjqPJmjt96bwM9kqihsccofA5LIJ7DN91qkCORjWSTwNhzCv7bMyr2o5vBZElrlpnRzlvsFIoAZCD9xg6ZY7ZyzUJmU6IcTwG4v3xEYajcpbJJiyaw/RqR90MuRdKPiBzSo=" {
426
- t.Log("signature is not correct")
427
- t.Logf("%v\n", sig)
428
- t.Fail()
408
+ t.Errorf("signature is not correct: %v", sig)
409
}
410
}
411
@@ -440,13 +420,13 @@ PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR`
420
421
eckey, err := NewRR(pub)
422
if err != nil {
443
- t.Fatal(err.Error())
423
+ t.Fatal(err)
424
}
425
privkey, err := eckey.(*DNSKEY).NewPrivateKey(priv)
426
if err != nil {
447
- t.Fatal(err.Error())
427
+ t.Fatal(err)
428
}
449
- // TODO: Create seperate test for this
429
+ // TODO: Create separate test for this
430
ds := eckey.(*DNSKEY).ToDS(SHA384)
431
if ds.KeyTag != 10771 {
432
t.Fatal("wrong keytag on DS")
@@ -467,22 +447,21 @@ PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR`
447
t.Fatal("failure to sign the record")
448
}
449
470
- if e := sig.Verify(eckey.(*DNSKEY), []RR{a}); e != nil {
471
- t.Logf("\n%s\n%s\n%s\n\n%s\n\n",
450
+ if err := sig.Verify(eckey.(*DNSKEY), []RR{a}); err != nil {
451
+ t.Fatalf("Failure to validate:\n%s\n%s\n%s\n\n%s\n\n%v",
452
eckey.(*DNSKEY).String(),
453
a.String(),
454
sig.String(),
455
eckey.(*DNSKEY).PrivateKeyString(privkey),
456
+ err,
457
)
477
-
478
- t.Fatalf("failure to validate: %s", e.Error())
458
}
459
}
460
461
func TestSignVerifyECDSA2(t *testing.T) {
462
srv1, err := NewRR("srv.miek.nl. IN SRV 1000 800 0 web1.miek.nl.")
463
if err != nil {
485
- t.Fatalf(err.Error())
464
+ t.Fatal(err)
465
}
466
srv := srv1.(*SRV)
467
@@ -518,14 +497,13 @@ func TestSignVerifyECDSA2(t *testing.T) {
497
498
err = sig.Verify(key, []RR{srv})
499
if err != nil {
521
- t.Logf("\n%s\n%s\n%s\n\n%s\n\n",
500
+ t.Logf("Failure to validate:\n%s\n%s\n%s\n\n%s\n\n%v",
501
key.String(),
502
srv.String(),
503
sig.String(),
504
key.PrivateKeyString(privkey),
505
+ err,
506
)
527
-
528
- t.Fatal("Failure to validate:", err)
507
}
508
}
509
@@ -540,11 +518,11 @@ Algorithm: 13 (ECDSAP256SHA256)
518
PrivateKey: GU6SnQ/Ou+xC5RumuIUIuJZteXT2z0O/ok1s38Et6mQ=`
519
rrDNSKEY, err := NewRR(exDNSKEY)
520
if err != nil {
543
- t.Fatal(err.Error())
521
+ t.Fatal(err)
522
}
523
priv, err := rrDNSKEY.(*DNSKEY).NewPrivateKey(exPriv)
524
if err != nil {
547
- t.Fatal(err.Error())
525
+ t.Fatal(err)
526
}
527
528
exDS := `example.net. 3600 IN DS 55648 13 2 (
@@ -552,11 +530,11 @@ PrivateKey: GU6SnQ/Ou+xC5RumuIUIuJZteXT2z0O/ok1s38Et6mQ=`
530
e2770ce6d6e37df61d17 )`
531
rrDS, err := NewRR(exDS)
532
if err != nil {
555
- t.Fatal(err.Error())
533
+ t.Fatal(err)
534
}
535
ourDS := rrDNSKEY.(*DNSKEY).ToDS(SHA256)
536
if !reflect.DeepEqual(ourDS, rrDS.(*DS)) {
559
- t.Errorf("DS record differs:\n%v\n%v\n", ourDS, rrDS.(*DS))
537
+ t.Errorf("DS record differs:\n%v\n%v", ourDS, rrDS.(*DS))
538
}
539
540
exA := `www.example.net. 3600 IN A 192.0.2.1`
@@ -566,11 +544,11 @@ PrivateKey: GU6SnQ/Ou+xC5RumuIUIuJZteXT2z0O/ok1s38Et6mQ=`
544
yGmt+3SNruPFKG7tZoLBLlUzGGus7ZwmwWep666VCw== )`
545
rrA, err := NewRR(exA)
546
if err != nil {
569
- t.Fatal(err.Error())
547
+ t.Fatal(err)
548
}
549
rrRRSIG, err := NewRR(exRRSIG)
550
if err != nil {
573
- t.Fatal(err.Error())
551
+ t.Fatal(err)
552
}
553
if err = rrRRSIG.(*RRSIG).Verify(rrDNSKEY.(*DNSKEY), []RR{rrA}); err != nil {
554
t.Errorf("Failure to validate the spec RRSIG: %v", err)
@@ -588,7 +566,7 @@ PrivateKey: GU6SnQ/Ou+xC5RumuIUIuJZteXT2z0O/ok1s38Et6mQ=`
566
ourRRSIG.Inception, _ = StringToTime("20100812100439")
567
err = ourRRSIG.Sign(priv, []RR{rrA})
568
if err != nil {
591
- t.Fatal(err.Error())
569
+ t.Fatal(err)
570
}
571
572
if err = ourRRSIG.Verify(rrDNSKEY.(*DNSKEY), []RR{rrA}); err != nil {
@@ -599,7 +577,7 @@ PrivateKey: GU6SnQ/Ou+xC5RumuIUIuJZteXT2z0O/ok1s38Et6mQ=`
577
rrRRSIG.(*RRSIG).Signature = ""
578
ourRRSIG.Signature = ""
579
if !reflect.DeepEqual(ourRRSIG, rrRRSIG.(*RRSIG)) {
602
- t.Fatalf("RRSIG record differs:\n%v\n%v\n", ourRRSIG, rrRRSIG.(*RRSIG))
580
+ t.Fatalf("RRSIG record differs:\n%v\n%v", ourRRSIG, rrRRSIG.(*RRSIG))
581
}
582
}
583
@@ -614,11 +592,11 @@ Algorithm: 14 (ECDSAP384SHA384)
592
PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR`
593
rrDNSKEY, err := NewRR(exDNSKEY)
594
if err != nil {
617
- t.Fatal(err.Error())
595
+ t.Fatal(err)
596
}
597
priv, err := rrDNSKEY.(*DNSKEY).NewPrivateKey(exPriv)
598
if err != nil {
621
- t.Fatal(err.Error())
599
+ t.Fatal(err)
600
}
601
602
exDS := `example.net. 3600 IN DS 10771 14 4 (
@@ -627,11 +605,11 @@ PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR`
605
6df983d6 )`
606
rrDS, err := NewRR(exDS)
607
if err != nil {
630
- t.Fatal(err.Error())
608
+ t.Fatal(err)
609
}
610
ourDS := rrDNSKEY.(*DNSKEY).ToDS(SHA384)
611
if !reflect.DeepEqual(ourDS, rrDS.(*DS)) {
634
- t.Fatalf("DS record differs:\n%v\n%v\n", ourDS, rrDS.(*DS))
612
+ t.Fatalf("DS record differs:\n%v\n%v", ourDS, rrDS.(*DS))
613
}
614
615
exA := `www.example.net. 3600 IN A 192.0.2.1`
@@ -642,11 +620,11 @@ PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR`
620
WTSSPdz7wnqXL5bdcJzusdnI0RSMROxxwGipWcJm )`
621
rrA, err := NewRR(exA)
622
if err != nil {
645
- t.Fatal(err.Error())
623
+ t.Fatal(err)
624
}
625
rrRRSIG, err := NewRR(exRRSIG)
626
if err != nil {
649
- t.Fatal(err.Error())
627
+ t.Fatal(err)
628
}
629
if err = rrRRSIG.(*RRSIG).Verify(rrDNSKEY.(*DNSKEY), []RR{rrA}); err != nil {
630
t.Errorf("Failure to validate the spec RRSIG: %v", err)
@@ -664,7 +642,7 @@ PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR`
642
ourRRSIG.Inception, _ = StringToTime("20100812102025")
643
err = ourRRSIG.Sign(priv, []RR{rrA})
644
if err != nil {
667
- t.Fatal(err.Error())
645
+ t.Fatal(err)
646
}
647
648
if err = ourRRSIG.Verify(rrDNSKEY.(*DNSKEY), []RR{rrA}); err != nil {
@@ -675,6 +653,6 @@ PrivateKey: WURgWHCcYIYUPWgeLmiPY2DJJk02vgrmTfitxgqcL4vwW7BOrbawVmVe0d9V94SR`
653
rrRRSIG.(*RRSIG).Signature = ""
654
ourRRSIG.Signature = ""
655
if !reflect.DeepEqual(ourRRSIG, rrRRSIG.(*RRSIG)) {
678
- t.Fatalf("RRSIG record differs:\n%v\n%v\n", ourRRSIG, rrRRSIG.(*RRSIG))
656
+ t.Fatalf("RRSIG record differs:\n%v\n%v", ourRRSIG, rrRRSIG.(*RRSIG))
657
}
658
}
Godeps/_workspace/src/github.com/miekg/dns/doc.go
new
+247
@@ -0,0 +1,247 @@
1
+/*
2
+Package dns implements a full featured interface to the Domain Name System.
3
+Server- and client-side programming is supported.
4
+The package allows complete control over what is send out to the DNS. The package
5
+API follows the less-is-more principle, by presenting a small, clean interface.
6
+
7
+The package dns supports (asynchronous) querying/replying, incoming/outgoing zone transfers,
8
+TSIG, EDNS0, dynamic updates, notifies and DNSSEC validation/signing.
9
+Note that domain names MUST be fully qualified, before sending them, unqualified
10
+names in a message will result in a packing failure.
11
+
12
+Resource records are native types. They are not stored in wire format.
13
+Basic usage pattern for creating a new resource record:
14
+
15
+ r := new(dns.MX)
16
+ r.Hdr = dns.RR_Header{Name: "miek.nl.", Rrtype: dns.TypeMX, Class: dns.ClassINET, Ttl: 3600}
17
+ r.Preference = 10
18
+ r.Mx = "mx.miek.nl."
19
+
20
+Or directly from a string:
21
+
22
+ mx, err := dns.NewRR("miek.nl. 3600 IN MX 10 mx.miek.nl.")
23
+
24
+Or when the default TTL (3600) and class (IN) suit you:
25
+
26
+ mx, err := dns.NewRR("miek.nl. MX 10 mx.miek.nl.")
27
+
28
+Or even:
29
+
30
+ mx, err := dns.NewRR("$ORIGIN nl.\nmiek 1H IN MX 10 mx.miek")
31
+
32
+In the DNS messages are exchanged, these messages contain resource
33
+records (sets). Use pattern for creating a message:
34
+
35
+ m := new(dns.Msg)
36
+ m.SetQuestion("miek.nl.", dns.TypeMX)
37
+
38
+Or when not certain if the domain name is fully qualified:
39
+
40
+ m.SetQuestion(dns.Fqdn("miek.nl"), dns.TypeMX)
41
+
42
+The message m is now a message with the question section set to ask
43
+the MX records for the miek.nl. zone.
44
+
45
+The following is slightly more verbose, but more flexible:
46
+
47
+ m1 := new(dns.Msg)
48
+ m1.Id = dns.Id()
49
+ m1.RecursionDesired = true
50
+ m1.Question = make([]dns.Question, 1)
51
+ m1.Question[0] = dns.Question{"miek.nl.", dns.TypeMX, dns.ClassINET}
52
+
53
+After creating a message it can be send.
54
+Basic use pattern for synchronous querying the DNS at a
55
+server configured on 127.0.0.1 and port 53:
56
+
57
+ c := new(dns.Client)
58
+ in, rtt, err := c.Exchange(m1, "127.0.0.1:53")
59
+
60
+Suppressing
61
+multiple outstanding queries (with the same question, type and class) is as easy as setting:
62
+
63
+ c.SingleInflight = true
64
+
65
+If these "advanced" features are not needed, a simple UDP query can be send,
66
+with:
67
+
68
+ in, err := dns.Exchange(m1, "127.0.0.1:53")
69
+
70
+When this functions returns you will get dns message. A dns message consists
71
+out of four sections.
72
+The question section: in.Question, the answer section: in.Answer,
73
+the authority section: in.Ns and the additional section: in.Extra.
74
+
75
+Each of these sections (except the Question section) contain a []RR. Basic
76
+use pattern for accessing the rdata of a TXT RR as the first RR in
77
+the Answer section:
78
+
79
+ if t, ok := in.Answer[0].(*dns.TXT); ok {
80
+ // do something with t.Txt
81
+ }
82
+
83
+Domain Name and TXT Character String Representations
84
+
85
+Both domain names and TXT character strings are converted to presentation
86
+form both when unpacked and when converted to strings.
87
+
88
+For TXT character strings, tabs, carriage returns and line feeds will be
89
+converted to \t, \r and \n respectively. Back slashes and quotations marks
90
+will be escaped. Bytes below 32 and above 127 will be converted to \DDD
91
+form.
92
+
93
+For domain names, in addition to the above rules brackets, periods,
94
+spaces, semicolons and the at symbol are escaped.
95
+
96
+DNSSEC
97
+
98
+DNSSEC (DNS Security Extension) adds a layer of security to the DNS. It
99
+uses public key cryptography to sign resource records. The
100
+public keys are stored in DNSKEY records and the signatures in RRSIG records.
101
+
102
+Requesting DNSSEC information for a zone is done by adding the DO (DNSSEC OK) bit
103
+to an request.
104
+
105
+ m := new(dns.Msg)
106
+ m.SetEdns0(4096, true)
107
+
108
+Signature generation, signature verification and key generation are all supported.
109
+
110
+DYNAMIC UPDATES
111
+
112
+Dynamic updates reuses the DNS message format, but renames three of
113
+the sections. Question is Zone, Answer is Prerequisite, Authority is
114
+Update, only the Additional is not renamed. See RFC 2136 for the gory details.
115
+
116
+You can set a rather complex set of rules for the existence of absence of
117
+certain resource records or names in a zone to specify if resource records
118
+should be added or removed. The table from RFC 2136 supplemented with the Go
119
+DNS function shows which functions exist to specify the prerequisites.
120
+
121
+3.2.4 - Table Of Metavalues Used In Prerequisite Section
122
+
123
+ CLASS TYPE RDATA Meaning Function
124
+ --------------------------------------------------------------
125
+ ANY ANY empty Name is in use dns.NameUsed
126
+ ANY rrset empty RRset exists (value indep) dns.RRsetUsed
127
+ NONE ANY empty Name is not in use dns.NameNotUsed
128
+ NONE rrset empty RRset does not exist dns.RRsetNotUsed
129
+ zone rrset rr RRset exists (value dep) dns.Used
130
+
131
+The prerequisite section can also be left empty.
132
+If you have decided on the prerequisites you can tell what RRs should
133
+be added or deleted. The next table shows the options you have and
134
+what functions to call.
135
+
136
+3.4.2.6 - Table Of Metavalues Used In Update Section
137
+
138
+ CLASS TYPE RDATA Meaning Function
139
+ ---------------------------------------------------------------
140
+ ANY ANY empty Delete all RRsets from name dns.RemoveName
141
+ ANY rrset empty Delete an RRset dns.RemoveRRset
142
+ NONE rrset rr Delete an RR from RRset dns.Remove
143
+ zone rrset rr Add to an RRset dns.Insert
144
+
145
+TRANSACTION SIGNATURE
146
+
147
+An TSIG or transaction signature adds a HMAC TSIG record to each message sent.
148
+The supported algorithms include: HmacMD5, HmacSHA1, HmacSHA256 and HmacSHA512.
149
+
150
+Basic use pattern when querying with a TSIG name "axfr." (note that these key names
151
+must be fully qualified - as they are domain names) and the base64 secret
152
+"so6ZGir4GPAqINNh9U5c3A==":
153
+
154
+ c := new(dns.Client)
155
+ c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
156
+ m := new(dns.Msg)
157
+ m.SetQuestion("miek.nl.", dns.TypeMX)
158
+ m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
159
+ ...
160
+ // When sending the TSIG RR is calculated and filled in before sending
161
+
162
+When requesting an zone transfer (almost all TSIG usage is when requesting zone transfers), with
163
+TSIG, this is the basic use pattern. In this example we request an AXFR for
164
+miek.nl. with TSIG key named "axfr." and secret "so6ZGir4GPAqINNh9U5c3A=="
165
+and using the server 176.58.119.54:
166
+
167
+ t := new(dns.Transfer)
168
+ m := new(dns.Msg)
169
+ t.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
170
+ m.SetAxfr("miek.nl.")
171
+ m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
172
+ c, err := t.In(m, "176.58.119.54:53")
173
+ for r := range c { ... }
174
+
175
+You can now read the records from the transfer as they come in. Each envelope is checked with TSIG.
176
+If something is not correct an error is returned.
177
+
178
+Basic use pattern validating and replying to a message that has TSIG set.
179
+
180
+ server := &dns.Server{Addr: ":53", Net: "udp"}
181
+ server.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
182
+ go server.ListenAndServe()
183
+ dns.HandleFunc(".", handleRequest)
184
+
185
+ func handleRequest(w dns.ResponseWriter, r *dns.Msg) {
186
+ m := new(Msg)
187
+ m.SetReply(r)
188
+ if r.IsTsig() {
189
+ if w.TsigStatus() == nil {
190
+ // *Msg r has an TSIG record and it was validated
191
+ m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
192
+ } else {
193
+ // *Msg r has an TSIG records and it was not valided
194
+ }
195
+ }
196
+ w.WriteMsg(m)
197
+ }
198
+
199
+PRIVATE RRS
200
+
201
+RFC 6895 sets aside a range of type codes for private use. This range
202
+is 65,280 - 65,534 (0xFF00 - 0xFFFE). When experimenting with new Resource Records these
203
+can be used, before requesting an official type code from IANA.
204
+
205
+EDNS0
206
+
207
+EDNS0 is an extension mechanism for the DNS defined in RFC 2671 and updated
208
+by RFC 6891. It defines an new RR type, the OPT RR, which is then completely
209
+abused.
210
+Basic use pattern for creating an (empty) OPT RR:
211
+
212
+ o := new(dns.OPT)
213
+ o.Hdr.Name = "." // MUST be the root zone, per definition.
214
+ o.Hdr.Rrtype = dns.TypeOPT
215
+
216
+The rdata of an OPT RR consists out of a slice of EDNS0 (RFC 6891)
217
+interfaces. Currently only a few have been standardized: EDNS0_NSID
218
+(RFC 5001) and EDNS0_SUBNET (draft-vandergaast-edns-client-subnet-02). Note
219
+that these options may be combined in an OPT RR.
220
+Basic use pattern for a server to check if (and which) options are set:
221
+
222
+ // o is a dns.OPT
223
+ for _, s := range o.Option {
224
+ switch e := s.(type) {
225
+ case *dns.EDNS0_NSID:
226
+ // do stuff with e.Nsid
227
+ case *dns.EDNS0_SUBNET:
228
+ // access e.Family, e.Address, etc.
229
+ }
230
+ }
231
+
232
+SIG(0)
233
+
234
+From RFC 2931:
235
+
236
+ SIG(0) provides protection for DNS transactions and requests ....
237
+ ... protection for glue records, DNS requests, protection for message headers
238
+ on requests and responses, and protection of the overall integrity of a response.
239
+
240
+It works like TSIG, except that SIG(0) uses public key cryptography, instead of the shared
241
+secret approach in TSIG.
242
+Supported algorithms: DSA, ECDSAP256SHA256, ECDSAP384SHA384, RSASHA1, RSASHA256 and
243
+RSASHA512.
244
+
245
+Signing subsequent messages in multi-message sessions is not implemented.
246
+*/
247
+package dns
Godeps/_workspace/src/github.com/miekg/dns/edns.go
+49
-27
@@ -1,29 +1,3 @@
1
-// EDNS0
2
-//
3
-// EDNS0 is an extension mechanism for the DNS defined in RFC 2671 and updated
4
-// by RFC 6891. It defines an new RR type, the OPT RR, which is then completely
5
-// abused.
6
-// Basic use pattern for creating an (empty) OPT RR:
7
-//
8
-// o := new(dns.OPT)
9
-// o.Hdr.Name = "." // MUST be the root zone, per definition.
10
-// o.Hdr.Rrtype = dns.TypeOPT
11
-//
12
-// The rdata of an OPT RR consists out of a slice of EDNS0 (RFC 6891)
13
-// interfaces. Currently only a few have been standardized: EDNS0_NSID
14
-// (RFC 5001) and EDNS0_SUBNET (draft-vandergaast-edns-client-subnet-02). Note
15
-// that these options may be combined in an OPT RR.
16
-// Basic use pattern for a server to check if (and which) options are set:
17
-//
18
-// // o is a dns.OPT
19
-// for _, s := range o.Option {
20
-// switch e := s.(type) {
21
-// case *dns.EDNS0_NSID:
22
-// // do stuff with e.Nsid
23
-// case *dns.EDNS0_SUBNET:
24
-// // access e.Family, e.Address, etc.
25
-// }
26
-// }
1
package dns
2
3
import (
@@ -44,9 +18,13 @@ const (
18
EDNS0SUBNET = 0x8 // client-subnet (RFC6891)
19
EDNS0EXPIRE = 0x9 // EDNS0 expire
20
EDNS0SUBNETDRAFT = 0x50fa // Don't use! Use EDNS0SUBNET
21
+ EDNS0LOCALSTART = 0xFDE9 // Beginning of range reserved for local/experimental use (RFC6891)
22
+ EDNS0LOCALEND = 0xFFFE // End of range reserved for local/experimental use (RFC6891)
23
_DO = 1 << 15 // dnssec ok
24
)
25
26
+// OPT is the EDNS0 RR appended to messages to convey extra (meta) information.
27
+// See RFC 6891.
28
type OPT struct {
29
Hdr RR_Header
30
Option []EDNS0 `dns:"opt"`
@@ -92,6 +70,8 @@ func (rr *OPT) String() string {
70
s += "\n; DS HASH UNDERSTOOD: " + o.String()
71
case *EDNS0_N3U:
72
s += "\n; NSEC3 HASH UNDERSTOOD: " + o.String()
73
+ case *EDNS0_LOCAL:
74
+ s += "\n; LOCAL OPT: " + o.String()
75
}
76
}
77
return s
@@ -100,8 +80,9 @@ func (rr *OPT) String() string {
80
func (rr *OPT) len() int {
81
l := rr.Hdr.len()
82
for i := 0; i < len(rr.Option); i++ {
83
+ l += 4 // Account for 2-byte option code and 2-byte option length.
84
lo, _ := rr.Option[i].pack()
104
- l += 2 + len(lo)
85
+ l += len(lo)
86
}
87
return l
88
}
@@ -499,3 +480,44 @@ func (e *EDNS0_EXPIRE) unpack(b []byte) error {
480
e.Expire = uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
481
return nil
482
}
483
+
484
+// The local EDNS0 option is used for local/experimental purposes. The option
485
+// code is recommended to be within the range [EDNS0LOCALSTART, EDNS0LOCALEND]
486
+// (RFC6891), although any unassigned code can actually be used. The content of
487
+// the option is made available in Data, unaltered.
488
+// Basic use pattern for creating a local option:
489
+//
490
+// o := new(dns.OPT)
491
+// o.Hdr.Name = "."
492
+// o.Hdr.Rrtype = dns.TypeOPT
493
+// e := new(dns.EDNS0_LOCAL)
494
+// e.Code = dns.EDNS0LOCALSTART
495
+// e.Data = []byte{72, 82, 74}
496
+// o.Option = append(o.Option, e)
497
+type EDNS0_LOCAL struct {
498
+ Code uint16
499
+ Data []byte
500
+}
501
+
502
+func (e *EDNS0_LOCAL) Option() uint16 { return e.Code }
503
+func (e *EDNS0_LOCAL) String() string {
504
+ return strconv.FormatInt(int64(e.Code), 10) + ":0x" + hex.EncodeToString(e.Data)
505
+}
506
+
507
+func (e *EDNS0_LOCAL) pack() ([]byte, error) {
508
+ b := make([]byte, len(e.Data))
509
+ copied := copy(b, e.Data)
510
+ if copied != len(e.Data) {
511
+ return nil, ErrBuf
512
+ }
513
+ return b, nil
514
+}
515
+
516
+func (e *EDNS0_LOCAL) unpack(b []byte) error {
517
+ e.Data = make([]byte, len(b))
518
+ copied := copy(e.Data, b)
519
+ if copied != len(b) {
520
+ return ErrBuf
521
+ }
522
+ return nil
523
+}
Godeps/_workspace/src/github.com/miekg/dns/idn/punycode.go
+3
-2
@@ -216,8 +216,9 @@ func decode(b []byte) []byte {
216
}
217
out := make([]rune, 0, len(b))
218
b = b[len(_PREFIX):]
219
- for pos, x := range b {
220
- if x == _DELIMITER {
219
+ for pos := len(b) - 1; pos >= 0; pos-- {
220
+ // only last delimiter is our interest
221
+ if b[pos] == _DELIMITER {
222
out = append(out, bytes.Runes(b[:pos])...)
223
b = b[pos+1:] // trim source string
224
break
Godeps/_workspace/src/github.com/miekg/dns/idn/punycode_test.go
+3
@@ -9,10 +9,12 @@ var testcases = [][2]string{
9
{"", ""},
10
{"a", "a"},
11
{"A-B", "a-b"},
12
+ {"A-B-C", "a-b-c"},
13
{"AbC", "abc"},
14
{"я", "xn--41a"},
15
{"zя", "xn--z-0ub"},
16
{"ЯZ", "xn--z-zub"},
17
+ {"а-я", "xn----7sb8g"},
18
{"إختبار", "xn--kgbechtv"},
19
{"آزمایشی", "xn--hgbk6aj7f53bba"},
20
{"测试", "xn--0zwm56d"},
@@ -24,6 +26,7 @@ var testcases = [][2]string{
26
{"טעסט", "xn--deba0ad"},
27
{"テスト", "xn--zckzah"},
28
{"பரிட்சை", "xn--hlcj6aya9esc7a"},
29
+ {"mamão-com-açúcar", "xn--mamo-com-acar-yeb1e6q"},
30
}
31
32
func TestEncodeDecodePunycode(t *testing.T) {
Godeps/_workspace/src/github.com/miekg/dns/labels_test.go
+17
-32
@@ -13,34 +13,27 @@ func TestCompareDomainName(t *testing.T) {
13
s6 := "miek.nl"
14
15
if CompareDomainName(s1, s2) != 2 {
16
- t.Logf("%s with %s should be %d", s1, s2, 2)
17
- t.Fail()
16
+ t.Errorf("%s with %s should be %d", s1, s2, 2)
17
}
18
if CompareDomainName(s1, s3) != 1 {
20
- t.Logf("%s with %s should be %d", s1, s3, 1)
21
- t.Fail()
19
+ t.Errorf("%s with %s should be %d", s1, s3, 1)
20
}
21
if CompareDomainName(s3, s4) != 0 {
24
- t.Logf("%s with %s should be %d", s3, s4, 0)
25
- t.Fail()
22
+ t.Errorf("%s with %s should be %d", s3, s4, 0)
23
}
24
// Non qualified tests
25
if CompareDomainName(s1, s5) != 1 {
29
- t.Logf("%s with %s should be %d", s1, s5, 1)
30
- t.Fail()
26
+ t.Errorf("%s with %s should be %d", s1, s5, 1)
27
}
28
if CompareDomainName(s1, s6) != 2 {
33
- t.Logf("%s with %s should be %d", s1, s5, 2)
34
- t.Fail()
29
+ t.Errorf("%s with %s should be %d", s1, s5, 2)
30
}
31
32
if CompareDomainName(s1, ".") != 0 {
38
- t.Logf("%s with %s should be %d", s1, s5, 0)
39
- t.Fail()
33
+ t.Errorf("%s with %s should be %d", s1, s5, 0)
34
}
35
if CompareDomainName(".", ".") != 0 {
42
- t.Logf("%s with %s should be %d", ".", ".", 0)
43
- t.Fail()
36
+ t.Errorf("%s with %s should be %d", ".", ".", 0)
37
}
38
}
39
@@ -59,10 +52,9 @@ func TestSplit(t *testing.T) {
52
}
53
for s, i := range splitter {
54
if x := len(Split(s)); x != i {
62
- t.Logf("labels should be %d, got %d: %s %v\n", i, x, s, Split(s))
63
- t.Fail()
55
+ t.Errorf("labels should be %d, got %d: %s %v", i, x, s, Split(s))
56
} else {
65
- t.Logf("%s %v\n", s, Split(s))
57
+ t.Logf("%s %v", s, Split(s))
58
}
59
}
60
}
@@ -78,13 +70,11 @@ func TestSplit2(t *testing.T) {
70
switch len(i) {
71
case 1:
72
if x[0] != i[0] {
81
- t.Logf("labels should be %v, got %v: %s\n", i, x, s)
82
- t.Fail()
73
+ t.Errorf("labels should be %v, got %v: %s", i, x, s)
74
}
75
default:
76
if x[0] != i[0] || x[1] != i[1] || x[2] != i[2] {
86
- t.Logf("labels should be %v, got %v: %s\n", i, x, s)
87
- t.Fail()
77
+ t.Errorf("labels should be %v, got %v: %s", i, x, s)
78
}
79
}
80
}
@@ -113,8 +103,7 @@ func TestPrevLabel(t *testing.T) {
103
for s, i := range prever {
104
x, ok := PrevLabel(s.string, s.int)
105
if i != x {
116
- t.Logf("label should be %d, got %d, %t: preving %d, %s\n", i, x, ok, s.int, s.string)
117
- t.Fail()
106
+ t.Errorf("label should be %d, got %d, %t: preving %d, %s", i, x, ok, s.int, s.string)
107
}
108
}
109
}
@@ -129,8 +118,7 @@ func TestCountLabel(t *testing.T) {
118
for s, i := range splitter {
119
x := CountLabel(s)
120
if x != i {
132
- t.Logf("CountLabel should have %d, got %d\n", i, x)
133
- t.Fail()
121
+ t.Errorf("CountLabel should have %d, got %d", i, x)
122
}
123
}
124
}
@@ -149,14 +137,12 @@ domainLoop:
137
for domain, splits := range labels {
138
parts := SplitDomainName(domain)
139
if len(parts) != len(splits) {
152
- t.Logf("SplitDomainName returned %v for %s, expected %v", parts, domain, splits)
153
- t.Fail()
140
+ t.Errorf("SplitDomainName returned %v for %s, expected %v", parts, domain, splits)
141
continue domainLoop
142
}
143
for i := range parts {
144
if parts[i] != splits[i] {
158
- t.Logf("SplitDomainName returned %v for %s, expected %v", parts, domain, splits)
159
- t.Fail()
145
+ t.Errorf("SplitDomainName returned %v for %s, expected %v", parts, domain, splits)
146
continue domainLoop
147
}
148
}
@@ -180,9 +166,8 @@ func TestIsDomainName(t *testing.T) {
166
for d, ok := range names {
167
l, k := IsDomainName(d)
168
if ok.ok != k || ok.lab != l {
183
- t.Logf(" got %v %d for %s ", k, l, d)
184
- t.Logf("have %v %d for %s ", ok.ok, ok.lab, d)
185
- t.Fail()
169
+ t.Errorf(" got %v %d for %s ", k, l, d)
170
+ t.Errorf("have %v %d for %s ", ok.ok, ok.lab, d)
171
}
172
}
173
}
Godeps/_workspace/src/github.com/miekg/dns/msg.go
+83
-53
@@ -23,29 +23,40 @@ import (
23
const maxCompressionOffset = 2 << 13 // We have 14 bits for the compression pointer
24
25
var (
26
- ErrAlg error = &Error{err: "bad algorithm"}
27
- ErrAuth error = &Error{err: "bad authentication"}
28
- ErrBuf error = &Error{err: "buffer size too small"}
29
- ErrConnEmpty error = &Error{err: "conn has no connection"}
30
- ErrConn error = &Error{err: "conn holds both UDP and TCP connection"}
26
+ // ErrAlg indicates an error with the (DNSSEC) algorithm.
27
+ ErrAlg error = &Error{err: "bad algorithm"}
28
+ // ErrAuth indicates an error in the TSIG authentication.
29
+ ErrAuth error = &Error{err: "bad authentication"}
30
+ // ErrBuf indicates that the buffer used it too small for the message.
31
+ ErrBuf error = &Error{err: "buffer size too small"}
32
+ // ErrConn indicates that a connection has both a TCP and UDP socket.
33
+ ErrConn error = &Error{err: "conn holds both UDP and TCP connection"}
34
+ // ErrConnEmpty indicates a connection is being uses before it is initialized.
35
+ ErrConnEmpty error = &Error{err: "conn has no connection"}
36
+ // ErrExtendedRcode ...
37
ErrExtendedRcode error = &Error{err: "bad extended rcode"}
32
- ErrFqdn error = &Error{err: "domain must be fully qualified"}
33
- ErrId error = &Error{err: "id mismatch"}
34
- ErrKeyAlg error = &Error{err: "bad key algorithm"}
35
- ErrKey error = &Error{err: "bad key"}
36
- ErrKeySize error = &Error{err: "bad key size"}
37
- ErrNoSig error = &Error{err: "no signature found"}
38
- ErrPrivKey error = &Error{err: "bad private key"}
39
- ErrRcode error = &Error{err: "bad rcode"}
40
- ErrRdata error = &Error{err: "bad rdata"}
41
- ErrRRset error = &Error{err: "bad rrset"}
42
- ErrSecret error = &Error{err: "no secrets defined"}
43
- ErrServ error = &Error{err: "no servers could be reached"}
44
- ErrShortRead error = &Error{err: "short read"}
45
- ErrSig error = &Error{err: "bad signature"}
46
- ErrSigGen error = &Error{err: "bad signature generation"}
47
- ErrSoa error = &Error{err: "no SOA"}
48
- ErrTime error = &Error{err: "bad time"}
38
+ // ErrFqdn indicates that a domain name does not have a closing dot.
39
+ ErrFqdn error = &Error{err: "domain must be fully qualified"}
40
+ // ErrId indicates there is a mismatch with the message's ID.
41
+ ErrId error = &Error{err: "id mismatch"}
42
+ ErrKeyAlg error = &Error{err: "bad key algorithm"}
43
+ ErrKey error = &Error{err: "bad key"}
44
+ ErrKeySize error = &Error{err: "bad key size"}
45
+ ErrNoSig error = &Error{err: "no signature found"}
46
+ ErrPrivKey error = &Error{err: "bad private key"}
47
+ ErrRcode error = &Error{err: "bad rcode"}
48
+ ErrRdata error = &Error{err: "bad rdata"}
49
+ ErrRRset error = &Error{err: "bad rrset"}
50
+ ErrSecret error = &Error{err: "no secrets defined"}
51
+ ErrShortRead error = &Error{err: "short read"}
52
+ // ErrSig indicates that a signature can not be cryptographically validated.
53
+ ErrSig error = &Error{err: "bad signature"}
54
+ // ErrSigGen indicates a faulure to generate a signature.
55
+ ErrSigGen error = &Error{err: "bad signature generation"}
56
+ // ErrSOA indicates that no SOA RR was seen when doing zone transfers.
57
+ ErrSoa error = &Error{err: "no SOA"}
58
+ // ErrTime indicates a timing error in TSIG authentication.
59
+ ErrTime error = &Error{err: "bad time"}
60
)
61
62
// Id, by default, returns a 16 bits random number to be used as a
@@ -56,8 +67,7 @@ var (
67
// dns.Id = func() uint16 { return 3 }
68
var Id func() uint16 = id
69
59
-// A manually-unpacked version of (id, bits).
60
-// This is in its own struct for easy printing.
70
+// MsgHdr is a a manually-unpacked version of (id, bits).
71
type MsgHdr struct {
72
Id uint16
73
Response bool
@@ -72,7 +82,7 @@ type MsgHdr struct {
82
Rcode int
83
}
84
75
-// The layout of a DNS message.
85
+// Msg contains the layout of a DNS message.
86
type Msg struct {
87
MsgHdr
88
Compress bool `json:"-"` // If true, the message will be compressed when converted to wire format. This not part of the official DNS packet format.
@@ -82,7 +92,7 @@ type Msg struct {
92
Extra []RR // Holds the RR(s) of the additional section.
93
}
94
85
-// Map of strings for each RR wire type.
95
+// TypeToString is a map of strings for each RR wire type.
96
var TypeToString = map[uint16]string{
97
TypeA: "A",
98
TypeAAAA: "AAAA",
@@ -161,8 +171,10 @@ var TypeToString = map[uint16]string{
171
TypeX25: "X25",
172
}
173
164
-// Reverse, needed for string parsing.
174
+// StringToType is the reverse of TypeToString, needed for string parsing.
175
var StringToType = reverseInt16(TypeToString)
176
+
177
+// StringToClass is the reverse of ClassToString, needed for string parsing.
178
var StringToClass = reverseInt16(ClassToString)
179
180
// Map of opcodes strings.
@@ -171,7 +183,7 @@ var StringToOpcode = reverseInt(OpcodeToString)
183
// Map of rcodes strings.
184
var StringToRcode = reverseInt(RcodeToString)
185
174
-// Map of strings for each CLASS wire type.
186
+// ClassToString is a maps Classes to strings for each CLASS wire type.
187
var ClassToString = map[uint16]string{
188
ClassINET: "IN",
189
ClassCSNET: "CS",
@@ -181,7 +193,7 @@ var ClassToString = map[uint16]string{
193
ClassANY: "ANY",
194
}
195
184
-// Map of strings for opcodes.
196
+// OpcodeToString maps Opcodes to strings.
197
var OpcodeToString = map[int]string{
198
OpcodeQuery: "QUERY",
199
OpcodeIQuery: "IQUERY",
@@ -190,7 +202,7 @@ var OpcodeToString = map[int]string{
202
OpcodeUpdate: "UPDATE",
203
}
204
193
-// Map of strings for rcodes.
205
+// RcodeToString maps Rcodes to strings.
206
var RcodeToString = map[int]string{
207
RcodeSuccess: "NOERROR",
208
RcodeFormatError: "FORMERR",
@@ -264,7 +276,7 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
276
// Emit sequence of counted strings, chopping at dots.
277
begin := 0
278
bs := []byte(s)
267
- ro_bs, bs_fresh, escaped_dot := s, true, false
279
+ roBs, bsFresh, escapedDot := s, true, false
280
for i := 0; i < ls; i++ {
281
if bs[i] == '\\' {
282
for j := i; j < ls-1; j++ {
@@ -288,13 +300,13 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
300
} else if bs[i] == 'n' {
301
bs[i] = '\n'
302
}
291
- escaped_dot = bs[i] == '.'
292
- bs_fresh = false
303
+ escapedDot = bs[i] == '.'
304
+ bsFresh = false
305
continue
306
}
307
308
if bs[i] == '.' {
297
- if i > 0 && bs[i-1] == '.' && !escaped_dot {
309
+ if i > 0 && bs[i-1] == '.' && !escapedDot {
310
// two dots back to back is not legal
311
return lenmsg, labels, ErrRdata
312
}
@@ -320,16 +332,16 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
332
}
333
off++
334
}
323
- if compress && !bs_fresh {
324
- ro_bs = string(bs)
325
- bs_fresh = true
335
+ if compress && !bsFresh {
336
+ roBs = string(bs)
337
+ bsFresh = true
338
}
339
// Dont try to compress '.'
328
- if compress && ro_bs[begin:] != "." {
329
- if p, ok := compression[ro_bs[begin:]]; !ok {
340
+ if compress && roBs[begin:] != "." {
341
+ if p, ok := compression[roBs[begin:]]; !ok {
342
// Only offsets smaller than this can be used.
343
if offset < maxCompressionOffset {
332
- compression[ro_bs[begin:]] = offset
344
+ compression[roBs[begin:]] = offset
345
}
346
} else {
347
// The first hit is the longest matching dname
@@ -348,7 +360,7 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
360
labels++
361
begin = i + 1
362
}
351
- escaped_dot = false
363
+ escapedDot = false
364
}
365
// Root label is special
366
if len(bs) == 1 && bs[0] == '.' {
@@ -945,7 +957,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
957
return lenmsg, &Error{"bad tag unpacking slice: " + val.Type().Field(i).Tag.Get("dns")}
958
case `dns:"domain-name"`:
959
// HIP record slice of name (or none)
948
- servers := make([]string, 0)
960
+ var servers []string
961
var s string
962
for off < lenrd {
963
s, off, err = UnpackDomainName(msg, off)
@@ -971,7 +983,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
983
// We can safely return here.
984
break
985
}
974
- edns := make([]EDNS0, 0)
986
+ var edns []EDNS0
987
Option:
988
code := uint16(0)
989
if off+2 > lenmsg {
@@ -1036,7 +1048,12 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
1048
edns = append(edns, e)
1049
off = off1 + int(optlen)
1050
default:
1039
- // do nothing?
1051
+ e := new(EDNS0_LOCAL)
1052
+ e.Code = code
1053
+ if err := e.unpack(msg[off1 : off1+int(optlen)]); err != nil {
1054
+ return lenmsg, err
1055
+ }
1056
+ edns = append(edns, e)
1057
off = off1 + int(optlen)
1058
}
1059
if off < lenrd {
@@ -1077,7 +1094,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
1094
off += net.IPv6len
1095
case `dns:"wks"`:
1096
// Rest of the record is the bitmap
1080
- serv := make([]uint16, 0)
1097
+ var serv []uint16
1098
j := 0
1099
for off < lenrd {
1100
if off+1 > lenmsg {
@@ -1121,7 +1138,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
1138
if off+2 > lenrd || off+2 > lenmsg {
1139
return lenmsg, &Error{err: "overflow unpacking nsecx"}
1140
}
1124
- nsec := make([]uint16, 0)
1141
+ var nsec []uint16
1142
length := 0
1143
window := 0
1144
for off+2 < lenrd {
@@ -1903,7 +1920,11 @@ func Copy(r RR) RR {
1920
1921
// Copy returns a new *Msg which is a deep-copy of dns.
1922
func (dns *Msg) Copy() *Msg {
1906
- r1 := new(Msg)
1923
+ return dns.CopyTo(new(Msg))
1924
+}
1925
+
1926
+// CopyTo copies the contents to the provided message using a deep-copy and returns the copy.
1927
+func (dns *Msg) CopyTo(r1 *Msg) *Msg {
1928
r1.MsgHdr = dns.MsgHdr
1929
r1.Compress = dns.Compress
1930
@@ -1912,25 +1933,34 @@ func (dns *Msg) Copy() *Msg {
1933
copy(r1.Question, dns.Question) // TODO(miek): Question is an immutable value, ok to do a shallow-copy
1934
}
1935
1936
+ rrArr := make([]RR, len(dns.Answer)+len(dns.Ns)+len(dns.Extra))
1937
+ var rri int
1938
+
1939
if len(dns.Answer) > 0 {
1916
- r1.Answer = make([]RR, len(dns.Answer))
1940
+ rrbegin := rri
1941
for i := 0; i < len(dns.Answer); i++ {
1918
- r1.Answer[i] = dns.Answer[i].copy()
1942
+ rrArr[rri] = dns.Answer[i].copy()
1943
+ rri++
1944
}
1945
+ r1.Answer = rrArr[rrbegin:rri:rri]
1946
}
1947
1948
if len(dns.Ns) > 0 {
1923
- r1.Ns = make([]RR, len(dns.Ns))
1949
+ rrbegin := rri
1950
for i := 0; i < len(dns.Ns); i++ {
1925
- r1.Ns[i] = dns.Ns[i].copy()
1951
+ rrArr[rri] = dns.Ns[i].copy()
1952
+ rri++
1953
}
1954
+ r1.Ns = rrArr[rrbegin:rri:rri]
1955
}
1956
1957
if len(dns.Extra) > 0 {
1930
- r1.Extra = make([]RR, len(dns.Extra))
1958
+ rrbegin := rri
1959
for i := 0; i < len(dns.Extra); i++ {
1932
- r1.Extra[i] = dns.Extra[i].copy()
1960
+ rrArr[rri] = dns.Extra[i].copy()
1961
+ rri++
1962
}
1963
+ r1.Extra = rrArr[rrbegin:rri:rri]
1964
}
1965
1966
return r1
Godeps/_workspace/src/github.com/miekg/dns/nsecx.go
+2
@@ -50,6 +50,8 @@ func HashName(label string, ha uint8, iter uint16, salt string) string {
50
return toBase32(nsec3)
51
}
52
53
+// Denialer is an interface that should be implemented by types that are used to denial
54
+// answers in DNSSEC.
55
type Denialer interface {
56
// Cover will check if the (unhashed) name is being covered by this NSEC or NSEC3.
57
Cover(name string) bool
Godeps/_workspace/src/github.com/miekg/dns/nsecx_test.go
+4
-8
@@ -7,14 +7,12 @@ import (
7
func TestPackNsec3(t *testing.T) {
8
nsec3 := HashName("dnsex.nl.", SHA1, 0, "DEAD")
9
if nsec3 != "ROCCJAE8BJJU7HN6T7NG3TNM8ACRS87J" {
10
- t.Logf("%v\n", nsec3)
11
- t.Fail()
10
+ t.Error(nsec3)
11
}
12
13
nsec3 = HashName("a.b.c.example.org.", SHA1, 2, "DEAD")
14
if nsec3 != "6LQ07OAHBTOOEU2R9ANI2AT70K5O0RCG" {
16
- t.Logf("%v\n", nsec3)
17
- t.Fail()
15
+ t.Error(nsec3)
16
}
17
}
18
@@ -22,12 +20,10 @@ func TestNsec3(t *testing.T) {
20
// examples taken from .nl
21
nsec3, _ := NewRR("39p91242oslggest5e6a7cci4iaeqvnk.nl. IN NSEC3 1 1 5 F10E9F7EA83FC8F3 39P99DCGG0MDLARTCRMCF6OFLLUL7PR6 NS DS RRSIG")
22
if !nsec3.(*NSEC3).Cover("snasajsksasasa.nl.") { // 39p94jrinub66hnpem8qdpstrec86pg3
25
- t.Logf("39p94jrinub66hnpem8qdpstrec86pg3. should be covered by 39p91242oslggest5e6a7cci4iaeqvnk.nl. - 39P99DCGG0MDLARTCRMCF6OFLLUL7PR6")
26
- t.Fail()
23
+ t.Error("39p94jrinub66hnpem8qdpstrec86pg3. should be covered by 39p91242oslggest5e6a7cci4iaeqvnk.nl. - 39P99DCGG0MDLARTCRMCF6OFLLUL7PR6")
24
}
25
nsec3, _ = NewRR("sk4e8fj94u78smusb40o1n0oltbblu2r.nl. IN NSEC3 1 1 5 F10E9F7EA83FC8F3 SK4F38CQ0ATIEI8MH3RGD0P5I4II6QAN NS SOA TXT RRSIG DNSKEY NSEC3PARAM")
26
if !nsec3.(*NSEC3).Match("nl.") { // sk4e8fj94u78smusb40o1n0oltbblu2r.nl.
30
- t.Logf("sk4e8fj94u78smusb40o1n0oltbblu2r.nl. should match sk4e8fj94u78smusb40o1n0oltbblu2r.nl.")
31
- t.Fail()
27
+ t.Error("sk4e8fj94u78smusb40o1n0oltbblu2r.nl. should match sk4e8fj94u78smusb40o1n0oltbblu2r.nl.")
28
}
29
}
Godeps/_workspace/src/github.com/miekg/dns/parse_test.go
+192
-223
@@ -20,19 +20,16 @@ func TestDotInName(t *testing.T) {
20
PackDomainName("aa\\.bb.nl.", buf, 0, nil, false)
21
// index 3 must be a real dot
22
if buf[3] != '.' {
23
- t.Log("dot should be a real dot")
24
- t.Fail()
23
+ t.Error("dot should be a real dot")
24
}
25
26
if buf[6] != 2 {
28
- t.Log("this must have the value 2")
29
- t.Fail()
27
+ t.Error("this must have the value 2")
28
}
29
dom, _, _ := UnpackDomainName(buf, 0)
30
// printing it should yield the backspace again
31
if dom != "aa\\.bb.nl." {
34
- t.Log("dot should have been escaped: " + dom)
35
- t.Fail()
32
+ t.Error("dot should have been escaped: ", dom)
33
}
34
}
35
@@ -41,7 +38,7 @@ func TestDotLastInLabel(t *testing.T) {
38
buf := make([]byte, 20)
39
_, err := PackDomainName(sample, buf, 0, nil, false)
40
if err != nil {
44
- t.Fatalf("unexpected error packing domain: %s", err)
41
+ t.Fatalf("unexpected error packing domain: %v", err)
42
}
43
dom, _, _ := UnpackDomainName(buf, 0)
44
if dom != sample {
@@ -52,19 +49,17 @@ func TestDotLastInLabel(t *testing.T) {
49
func TestTooLongDomainName(t *testing.T) {
50
l := "aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrsssttt."
51
dom := l + l + l + l + l + l + l
55
- _, e := NewRR(dom + " IN A 127.0.0.1")
56
- if e == nil {
57
- t.Log("should be too long")
58
- t.Fail()
52
+ _, err := NewRR(dom + " IN A 127.0.0.1")
53
+ if err == nil {
54
+ t.Error("should be too long")
55
} else {
60
- t.Logf("error is %s", e.Error())
56
+ t.Logf("error is %v", err)
57
}
62
- _, e = NewRR("..com. IN A 127.0.0.1")
63
- if e == nil {
64
- t.Log("should fail")
65
- t.Fail()
58
+ _, err = NewRR("..com. IN A 127.0.0.1")
59
+ if err == nil {
60
+ t.Error("should fail")
61
} else {
67
- t.Logf("error is %s", e.Error())
62
+ t.Logf("error is %v", err)
63
}
64
}
65
@@ -76,19 +71,16 @@ func TestDomainName(t *testing.T) {
71
72
for _, ts := range tests {
73
if _, err := PackDomainName(ts, dbuff, 0, nil, false); err != nil {
79
- t.Log("not a valid domain name")
80
- t.Fail()
74
+ t.Error("not a valid domain name")
75
continue
76
}
77
n, _, err := UnpackDomainName(dbuff, 0)
78
if err != nil {
85
- t.Log("failed to unpack packed domain name")
86
- t.Fail()
79
+ t.Error("failed to unpack packed domain name")
80
continue
81
}
82
if ts != n {
90
- t.Logf("must be equal: in: %s, out: %s\n", ts, n)
91
- t.Fail()
83
+ t.Errorf("must be equal: in: %s, out: %s", ts, n)
84
}
85
}
86
}
@@ -110,26 +102,23 @@ func TestDomainNameAndTXTEscapes(t *testing.T) {
102
s := rr1.String()
103
rr2, err := NewRR(s)
104
if err != nil {
113
- t.Logf("Error parsing unpacked RR's string: %v", err)
114
- t.Logf(" Bytes: %v\n", rrbytes)
115
- t.Logf("String: %v\n", s)
116
- t.Fail()
105
+ t.Errorf("Error parsing unpacked RR's string: %v", err)
106
+ t.Errorf(" Bytes: %v", rrbytes)
107
+ t.Errorf("String: %v", s)
108
}
109
repacked := make([]byte, len(rrbytes))
110
if _, err := PackRR(rr2, repacked, 0, nil, false); err != nil {
120
- t.Logf("error packing parsed RR: %v", err)
121
- t.Logf(" original Bytes: %v\n", rrbytes)
122
- t.Logf("unpacked Struct: %V\n", rr1)
123
- t.Logf(" parsed Struct: %V\n", rr2)
124
- t.Fail()
111
+ t.Errorf("error packing parsed RR: %v", err)
112
+ t.Errorf(" original Bytes: %v", rrbytes)
113
+ t.Errorf("unpacked Struct: %v", rr1)
114
+ t.Errorf(" parsed Struct: %v", rr2)
115
}
116
if !bytes.Equal(repacked, rrbytes) {
127
- t.Log("packed bytes don't match original bytes")
128
- t.Logf(" original bytes: %v", rrbytes)
129
- t.Logf(" packed bytes: %v", repacked)
130
- t.Logf("unpacked struct: %V", rr1)
131
- t.Logf(" parsed struct: %V", rr2)
132
- t.Fail()
117
+ t.Error("packed bytes don't match original bytes")
118
+ t.Errorf(" original bytes: %v", rrbytes)
119
+ t.Errorf(" packed bytes: %v", repacked)
120
+ t.Errorf("unpacked struct: %v", rr1)
121
+ t.Errorf(" parsed struct: %v", rr2)
122
}
123
}
124
}
@@ -206,16 +195,16 @@ func TestDomainQuick(t *testing.T) {
195
buf := make([]byte, 255)
196
off, err := PackDomainName(ds, buf, 0, nil, false)
197
if err != nil {
209
- t.Logf("error packing domain: %s", err.Error())
210
- t.Logf(" bytes: %v\n", db)
211
- t.Logf("string: %v\n", ds)
198
+ t.Errorf("error packing domain: %v", err)
199
+ t.Errorf(" bytes: %v", db)
200
+ t.Errorf("string: %v", ds)
201
return false
202
}
203
if !bytes.Equal(db, buf[:off]) {
215
- t.Logf("repacked domain doesn't match original:")
216
- t.Logf("src bytes: %v", db)
217
- t.Logf(" string: %v", ds)
218
- t.Logf("out bytes: %v", buf[:off])
204
+ t.Errorf("repacked domain doesn't match original:")
205
+ t.Errorf("src bytes: %v", db)
206
+ t.Errorf(" string: %v", ds)
207
+ t.Errorf("out bytes: %v", buf[:off])
208
return false
209
}
210
return true
@@ -248,7 +237,13 @@ func GenerateTXT(r *rand.Rand, size int) []byte {
237
return rd
238
}
239
251
-func TestTXTRRQuick(t *testing.T) {
240
+// Ok, 2 things. 1) this test breaks with the new functionality of splitting up larger txt
241
+// chunks into 255 byte pieces. 2) I don't like the random nature of this thing, because I can't
242
+// place the quotes where they need to be.
243
+// So either add some code the places the quotes in just the right spots, make this non random
244
+// or do something else.
245
+// Disabled for now. (miek)
246
+func testTXTRRQuick(t *testing.T) {
247
s := rand.NewSource(0)
248
r := rand.New(s)
249
typeAndClass := []byte{
@@ -272,15 +267,15 @@ func TestTXTRRQuick(t *testing.T) {
267
buf := make([]byte, len(rrbytes)*3)
268
off, err := PackRR(rr, buf, 0, nil, false)
269
if err != nil {
275
- t.Logf("pack Error: %s\nRR: %V", err.Error(), rr)
270
+ t.Errorf("pack Error: %v\nRR: %v", err, rr)
271
return false
272
}
273
buf = buf[:off]
274
if !bytes.Equal(buf, rrbytes) {
280
- t.Logf("packed bytes don't match original bytes")
281
- t.Logf("src bytes: %v", rrbytes)
282
- t.Logf(" struct: %V", rr)
283
- t.Logf("oUt bytes: %v", buf)
275
+ t.Errorf("packed bytes don't match original bytes")
276
+ t.Errorf("src bytes: %v", rrbytes)
277
+ t.Errorf(" struct: %v", rr)
278
+ t.Errorf("out bytes: %v", buf)
279
return false
280
}
281
if len(rdata) == 0 {
@@ -290,35 +285,35 @@ func TestTXTRRQuick(t *testing.T) {
285
rrString := rr.String()
286
rr2, err := NewRR(rrString)
287
if err != nil {
293
- t.Logf("error parsing own output: %s", err.Error())
294
- t.Logf("struct: %V", rr)
295
- t.Logf("string: %v", rrString)
288
+ t.Errorf("error parsing own output: %v", err)
289
+ t.Errorf("struct: %v", rr)
290
+ t.Errorf("string: %v", rrString)
291
return false
292
}
293
if rr2.String() != rrString {
299
- t.Logf("parsed rr.String() doesn't match original string")
300
- t.Logf("original: %v", rrString)
301
- t.Logf(" parsed: %v", rr2.String())
294
+ t.Errorf("parsed rr.String() doesn't match original string")
295
+ t.Errorf("original: %v", rrString)
296
+ t.Errorf(" parsed: %v", rr2.String())
297
return false
298
}
299
300
buf = make([]byte, len(rrbytes)*3)
301
off, err = PackRR(rr2, buf, 0, nil, false)
302
if err != nil {
308
- t.Logf("error packing parsed rr: %s", err.Error())
309
- t.Logf("unpacked Struct: %V", rr)
310
- t.Logf(" string: %v", rrString)
311
- t.Logf(" parsed Struct: %V", rr2)
303
+ t.Errorf("error packing parsed rr: %v", err)
304
+ t.Errorf("unpacked Struct: %v", rr)
305
+ t.Errorf(" string: %v", rrString)
306
+ t.Errorf(" parsed Struct: %v", rr2)
307
return false
308
}
309
buf = buf[:off]
310
if !bytes.Equal(buf, rrbytes) {
316
- t.Logf("parsed packed bytes don't match original bytes")
317
- t.Logf(" source bytes: %v", rrbytes)
318
- t.Logf("unpacked struct: %V", rr)
319
- t.Logf(" string: %v", rrString)
320
- t.Logf(" parsed struct: %V", rr2)
321
- t.Logf(" repacked bytes: %v", buf)
311
+ t.Errorf("parsed packed bytes don't match original bytes")
312
+ t.Errorf(" source bytes: %v", rrbytes)
313
+ t.Errorf("unpacked struct: %v", rr)
314
+ t.Errorf(" string: %v", rrString)
315
+ t.Errorf(" parsed struct: %v", rr2)
316
+ t.Errorf(" repacked bytes: %v", buf)
317
return false
318
}
319
return true
@@ -345,15 +340,13 @@ func TestParseDirectiveMisc(t *testing.T) {
340
"ONE.MY-ROOTS.NET. 3600000 IN A 192.168.1.1": "ONE.MY-ROOTS.NET.\t3600000\tIN\tA\t192.168.1.1",
341
}
342
for i, o := range tests {
348
- rr, e := NewRR(i)
349
- if e != nil {
350
- t.Log("failed to parse RR: " + e.Error())
351
- t.Fail()
343
+ rr, err := NewRR(i)
344
+ if err != nil {
345
+ t.Error("failed to parse RR: ", err)
346
continue
347
}
348
if rr.String() != o {
355
- t.Logf("`%s' should be equal to\n`%s', but is `%s'\n", i, o, rr.String())
356
- t.Fail()
349
+ t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
350
} else {
351
t.Logf("RR is OK: `%s'", rr.String())
352
}
@@ -369,15 +362,13 @@ func TestNSEC(t *testing.T) {
362
"localhost.dnssex.nl. IN NSEC www.dnssex.nl. A RRSIG NSec Type65534": "localhost.dnssex.nl.\t3600\tIN\tNSEC\twww.dnssex.nl. A RRSIG NSEC TYPE65534",
363
}
364
for i, o := range nsectests {
372
- rr, e := NewRR(i)
373
- if e != nil {
374
- t.Log("failed to parse RR: " + e.Error())
375
- t.Fail()
365
+ rr, err := NewRR(i)
366
+ if err != nil {
367
+ t.Error("failed to parse RR: ", err)
368
continue
369
}
370
if rr.String() != o {
379
- t.Logf("`%s' should be equal to\n`%s', but is `%s'\n", i, o, rr.String())
380
- t.Fail()
371
+ t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
372
} else {
373
t.Logf("RR is OK: `%s'", rr.String())
374
}
@@ -390,15 +381,13 @@ func TestParseLOC(t *testing.T) {
381
"SW1A2AA.find.me.uk. LOC 51 0 0.0 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m": "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t51 00 0.000 N 00 07 39.611 W 0m 0.00m 0.00m 0.00m",
382
}
383
for i, o := range lt {
393
- rr, e := NewRR(i)
394
- if e != nil {
395
- t.Log("failed to parse RR: " + e.Error())
396
- t.Fail()
384
+ rr, err := NewRR(i)
385
+ if err != nil {
386
+ t.Error("failed to parse RR: ", err)
387
continue
388
}
389
if rr.String() != o {
400
- t.Logf("`%s' should be equal to\n`%s', but is `%s'\n", i, o, rr.String())
401
- t.Fail()
390
+ t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
391
} else {
392
t.Logf("RR is OK: `%s'", rr.String())
393
}
@@ -410,15 +399,13 @@ func TestParseDS(t *testing.T) {
399
"example.net. 3600 IN DS 40692 12 3 22261A8B0E0D799183E35E24E2AD6BB58533CBA7E3B14D659E9CA09B 2071398F": "example.net.\t3600\tIN\tDS\t40692 12 3 22261A8B0E0D799183E35E24E2AD6BB58533CBA7E3B14D659E9CA09B2071398F",
400
}
401
for i, o := range dt {
413
- rr, e := NewRR(i)
414
- if e != nil {
415
- t.Log("failed to parse RR: " + e.Error())
416
- t.Fail()
402
+ rr, err := NewRR(i)
403
+ if err != nil {
404
+ t.Error("failed to parse RR: ", err)
405
continue
406
}
407
if rr.String() != o {
420
- t.Logf("`%s' should be equal to\n`%s', but is `%s'\n", i, o, rr.String())
421
- t.Fail()
408
+ t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
409
} else {
410
t.Logf("RR is OK: `%s'", rr.String())
411
}
@@ -446,15 +433,13 @@ func TestQuotes(t *testing.T) {
433
"cid.urn.arpa. NAPTR 100 10 \"\" \"\" \"/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i\" .": "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 10 \"\" \"\" \"/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i\" .",
434
}
435
for i, o := range tests {
449
- rr, e := NewRR(i)
450
- if e != nil {
451
- t.Log("failed to parse RR: " + e.Error())
452
- t.Fail()
436
+ rr, err := NewRR(i)
437
+ if err != nil {
438
+ t.Error("failed to parse RR: ", err)
439
continue
440
}
441
if rr.String() != o {
456
- t.Logf("`%s' should be equal to\n`%s', but is\n`%s'\n", i, o, rr.String())
457
- t.Fail()
442
+ t.Errorf("`%s' should be equal to\n`%s', but is\n`%s'", i, o, rr.String())
443
} else {
444
t.Logf("RR is OK: `%s'", rr.String())
445
}
@@ -471,15 +456,13 @@ func TestParseClass(t *testing.T) {
456
"t.example.com. NONE A 127.0.0.1": "t.example.com. 3600 NONE A 127.0.0.1",
457
}
458
for i, o := range tests {
474
- rr, e := NewRR(i)
475
- if e != nil {
476
- t.Log("failed to parse RR: " + e.Error())
477
- t.Fail()
459
+ rr, err := NewRR(i)
460
+ if err != nil {
461
+ t.Error("failed to parse RR: ", err)
462
continue
463
}
464
if rr.String() != o {
481
- t.Logf("`%s' should be equal to\n`%s', but is\n`%s'\n", i, o, rr.String())
482
- t.Fail()
465
+ t.Errorf("`%s' should be equal to\n`%s', but is\n`%s'", i, o, rr.String())
466
} else {
467
t.Logf("RR is OK: `%s'", rr.String())
468
}
@@ -524,15 +507,13 @@ func TestBrace(t *testing.T) {
507
)`: "miek.nl.\t86400\tIN\tSOA\telektron.atoom.net. miekg.atoom.net. 2009032802 21600 7200 604800 3600",
508
}
509
for i, o := range tests {
527
- rr, e := NewRR(i)
528
- if e != nil {
529
- t.Log("failed to parse RR: " + e.Error() + "\n\t" + i)
530
- t.Fail()
510
+ rr, err := NewRR(i)
511
+ if err != nil {
512
+ t.Errorf("failed to parse RR: %v\n\t%s", err, i)
513
continue
514
}
515
if rr.String() != o {
534
- t.Logf("`%s' should be equal to\n`%s', but is `%s'\n", i, o, rr.String())
535
- t.Fail()
516
+ t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
517
} else {
518
t.Logf("RR is OK: `%s'", rr.String())
519
}
@@ -555,8 +536,7 @@ func TestParseFailure(t *testing.T) {
536
for _, s := range tests {
537
_, err := NewRR(s)
538
if err == nil {
558
- t.Logf("should have triggered an error: \"%s\"", s)
559
- t.Fail()
539
+ t.Errorf("should have triggered an error: \"%s\"", s)
540
}
541
}
542
}
@@ -577,11 +557,10 @@ test IN CNAME test.a.example.com.
557
for x := range to {
558
i++
559
if x.Error != nil {
580
- t.Logf("%s\n", x.Error)
581
- t.Fail()
560
+ t.Error(x.Error)
561
continue
562
}
584
- t.Logf("%s\n", x.RR)
563
+ t.Log(x.RR)
564
}
565
delta := time.Now().UnixNano() - start
566
t.Logf("%d RRs parsed in %.2f s (%.2f RR/s)", i, float32(delta)/1e9, float32(i)/(float32(delta)/1e9))
@@ -625,7 +604,7 @@ moutamassey NS ns01.yahoodomains.jp.
604
`
605
to := ParseZone(strings.NewReader(zone), "", "testzone")
606
for x := range to {
628
- fmt.Printf("%s\n", x.RR)
607
+ fmt.Println(x.RR)
608
}
609
// Output:
610
// name. 3600 IN SOA a6.nstld.com. hostmaster.nic.name. 203362132 300 300 1209600 300
@@ -658,7 +637,7 @@ func ExampleHIP() {
637
b1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D
638
rvs.example.com. )`
639
if hip, err := NewRR(h); err == nil {
661
- fmt.Printf("%s\n", hip.String())
640
+ fmt.Println(hip.String())
641
}
642
// Output:
643
// www.example.com. 3600 IN HIP 2 200100107B1A74DF365639CC39F1D578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs.example.com.
@@ -673,30 +652,30 @@ b1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D
652
rvs2.example.com. )`
653
rr, err := NewRR(h)
654
if err != nil {
676
- t.Fatalf("failed to parse RR: %s", err)
655
+ t.Fatalf("failed to parse RR: %v", err)
656
}
657
t.Logf("RR: %s", rr)
658
msg := new(Msg)
659
msg.Answer = []RR{rr, rr}
660
bytes, err := msg.Pack()
661
if err != nil {
683
- t.Fatalf("failed to pack msg: %s", err)
662
+ t.Fatalf("failed to pack msg: %v", err)
663
}
664
if err := msg.Unpack(bytes); err != nil {
686
- t.Fatalf("failed to unpack msg: %s", err)
665
+ t.Fatalf("failed to unpack msg: %v", err)
666
}
667
if len(msg.Answer) != 2 {
689
- t.Fatalf("2 answers expected: %V", msg)
668
+ t.Fatalf("2 answers expected: %v", msg)
669
}
670
for i, rr := range msg.Answer {
671
rr := rr.(*HIP)
672
t.Logf("RR: %s", rr)
673
if l := len(rr.RendezvousServers); l != 2 {
695
- t.Fatalf("2 servers expected, only %d in record %d:\n%V", l, i, msg)
674
+ t.Fatalf("2 servers expected, only %d in record %d:\n%v", l, i, msg)
675
}
676
for j, s := range []string{"rvs1.example.com.", "rvs2.example.com."} {
677
if rr.RendezvousServers[j] != s {
699
- t.Fatalf("expected server %d of record %d to be %s:\n%V", j, i, s, msg)
678
+ t.Fatalf("expected server %d of record %d to be %s:\n%v", j, i, s, msg)
679
}
680
}
681
}
@@ -705,7 +684,7 @@ b1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D
684
func ExampleSOA() {
685
s := "example.com. 1000 SOA master.example.com. admin.example.com. 1 4294967294 4294967293 4294967295 100"
686
if soa, err := NewRR(s); err == nil {
708
- fmt.Printf("%s\n", soa.String())
687
+ fmt.Println(soa.String())
688
}
689
// Output:
690
// example.com. 1000 IN SOA master.example.com. admin.example.com. 1 4294967294 4294967293 4294967295 100
@@ -715,8 +694,7 @@ func TestLineNumberError(t *testing.T) {
694
s := "example.com. 1000 SOA master.example.com. admin.example.com. monkey 4294967294 4294967293 4294967295 100"
695
if _, err := NewRR(s); err != nil {
696
if err.Error() != "dns: bad SOA zone parameter: \"monkey\" at line: 1:68" {
718
- t.Logf("not expecting this error: " + err.Error())
719
- t.Fail()
697
+ t.Error("not expecting this error: ", err)
698
}
699
}
700
}
@@ -733,15 +711,13 @@ func TestLineNumberError2(t *testing.T) {
711
`example.com 1000 IN TALINK ( a.example.com. b...example.com.
712
)`: "dns: bad TALINK NextName: \"b...example.com.\" at line: 2:1"}
713
736
- for in, err := range tests {
737
- _, e := NewRR(in)
738
- if e == nil {
739
- t.Fail()
714
+ for in, errStr := range tests {
715
+ _, err := NewRR(in)
716
+ if err == nil {
717
+ t.Error("err is nil")
718
} else {
741
- if e.Error() != err {
742
- t.Logf("%s\n", in)
743
- t.Logf("error should be %s is %s\n", err, e.Error())
744
- t.Fail()
719
+ if err.Error() != errStr {
720
+ t.Errorf("%s: error should be %s is %v", in, errStr, err)
721
}
722
}
723
}
@@ -756,8 +732,7 @@ func TestRfc1982(t *testing.T) {
732
strtests := []string{"20120525134203", "19700101000000", "20380119031408"}
733
for _, v := range strtests {
734
if x, _ := StringToTime(v); v != TimeToString(x) {
759
- t.Logf("1982 arithmetic string failure %s (%s:%d)", v, TimeToString(x), x)
760
- t.Fail()
735
+ t.Errorf("1982 arithmetic string failure %s (%s:%d)", v, TimeToString(x), x)
736
}
737
}
738
@@ -767,8 +742,7 @@ func TestRfc1982(t *testing.T) {
742
}
743
for i, v := range inttests {
744
if TimeToString(i) != v {
770
- t.Logf("1982 arithmetic int failure %d:%s (%s)", i, v, TimeToString(i))
771
- t.Fail()
745
+ t.Errorf("1982 arithmetic int failure %d:%s (%s)", i, v, TimeToString(i))
746
}
747
}
748
@@ -785,16 +759,14 @@ func TestRfc1982(t *testing.T) {
759
x, _ := StringToTime(from)
760
y := TimeToString(x)
761
if y != to {
788
- t.Logf("1982 arithmetic future failure %s:%s (%s)", from, to, y)
789
- t.Fail()
762
+ t.Errorf("1982 arithmetic future failure %s:%s (%s)", from, to, y)
763
}
764
}
765
}
766
767
func TestEmpty(t *testing.T) {
768
for _ = range ParseZone(strings.NewReader(""), "", "") {
796
- t.Logf("should be empty")
797
- t.Fail()
769
+ t.Errorf("should be empty")
770
}
771
}
772
@@ -819,7 +791,7 @@ func TestLowercaseTokens(t *testing.T) {
791
for _, testrr := range testrecords {
792
_, err := NewRR(testrr)
793
if err != nil {
822
- t.Errorf("failed to parse %#v, got %s", testrr, err.Error())
794
+ t.Errorf("failed to parse %#v, got %v", testrr, err)
795
}
796
}
797
}
@@ -830,7 +802,7 @@ func ExampleGenerate() {
802
to := ParseZone(strings.NewReader(zone), "0.0.192.IN-ADDR.ARPA.", "")
803
for x := range to {
804
if x.Error == nil {
833
- fmt.Printf("%s\n", x.RR.String())
805
+ fmt.Println(x.RR.String())
806
}
807
}
808
// Output:
@@ -881,25 +853,25 @@ func TestSRVPacking(t *testing.T) {
853
854
_, err := msg.Pack()
855
if err != nil {
884
- t.Fatalf("couldn't pack %v\n", msg)
856
+ t.Fatalf("couldn't pack %v: %v", msg, err)
857
}
858
}
859
860
func TestParseBackslash(t *testing.T) {
889
- if r, e := NewRR("nul\\000gap.test.globnix.net. 600 IN A 192.0.2.10"); e != nil {
890
- t.Fatalf("could not create RR with \\000 in it")
861
+ if r, err := NewRR("nul\\000gap.test.globnix.net. 600 IN A 192.0.2.10"); err != nil {
862
+ t.Errorf("could not create RR with \\000 in it")
863
} else {
892
- t.Logf("parsed %s\n", r.String())
864
+ t.Logf("parsed %s", r.String())
865
}
894
- if r, e := NewRR(`nul\000gap.test.globnix.net. 600 IN TXT "Hello\123"`); e != nil {
895
- t.Fatalf("could not create RR with \\000 in it")
866
+ if r, err := NewRR(`nul\000gap.test.globnix.net. 600 IN TXT "Hello\123"`); err != nil {
867
+ t.Errorf("could not create RR with \\000 in it")
868
} else {
897
- t.Logf("parsed %s\n", r.String())
869
+ t.Logf("parsed %s", r.String())
870
}
899
- if r, e := NewRR(`m\ @\ iek.nl. IN 3600 A 127.0.0.1`); e != nil {
900
- t.Fatalf("could not create RR with \\ and \\@ in it")
871
+ if r, err := NewRR(`m\ @\ iek.nl. IN 3600 A 127.0.0.1`); err != nil {
872
+ t.Errorf("could not create RR with \\ and \\@ in it")
873
} else {
902
- t.Logf("parsed %s\n", r.String())
874
+ t.Logf("parsed %s", r.String())
875
}
876
}
877
@@ -919,9 +891,9 @@ func TestILNP(t *testing.T) {
891
"host1.example.com.\t3600\tIN\tLP\t20 l32-subnet1.example.com.",
892
}
893
for _, t1 := range tests {
922
- r, e := NewRR(t1)
923
- if e != nil {
924
- t.Fatalf("an error occured: %s\n", e.Error())
894
+ r, err := NewRR(t1)
895
+ if err != nil {
896
+ t.Fatalf("an error occurred: %v", err)
897
} else {
898
if t1 != r.String() {
899
t.Fatalf("strings should be equal %s %s", t1, r.String())
@@ -941,15 +913,13 @@ func TestNsapGposEidNimloc(t *testing.T) {
913
"VAXA. IN EID 3141592653589793": "VAXA.\t3600\tIN\tEID\t3141592653589793",
914
}
915
for i, o := range dt {
944
- rr, e := NewRR(i)
945
- if e != nil {
946
- t.Log("failed to parse RR: " + e.Error())
947
- t.Fail()
916
+ rr, err := NewRR(i)
917
+ if err != nil {
918
+ t.Error("failed to parse RR: ", err)
919
continue
920
}
921
if rr.String() != o {
951
- t.Logf("`%s' should be equal to\n`%s', but is `%s'\n", i, o, rr.String())
952
- t.Fail()
922
+ t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
923
} else {
924
t.Logf("RR is OK: `%s'", rr.String())
925
}
@@ -962,15 +932,13 @@ func TestPX(t *testing.T) {
932
"ab.net2.it. IN PX 10 ab.net2.it. O-ab.PRMD-net2.ADMDb.C-it.": "ab.net2.it.\t3600\tIN\tPX\t10 ab.net2.it. O-ab.PRMD-net2.ADMDb.C-it.",
933
}
934
for i, o := range dt {
965
- rr, e := NewRR(i)
966
- if e != nil {
967
- t.Log("failed to parse RR: " + e.Error())
968
- t.Fail()
935
+ rr, err := NewRR(i)
936
+ if err != nil {
937
+ t.Error("failed to parse RR: ", err)
938
continue
939
}
940
if rr.String() != o {
972
- t.Logf("`%s' should be equal to\n`%s', but is `%s'\n", i, o, rr.String())
973
- t.Fail()
941
+ t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
942
} else {
943
t.Logf("RR is OK: `%s'", rr.String())
944
}
@@ -1004,8 +972,7 @@ foo. IN TXT "THIS IS TEXT MAN"; this is comment 8
972
if x.Error == nil {
973
if x.Comment != "" {
974
if _, ok := comments[x.Comment]; !ok {
1007
- t.Logf("wrong comment %s", x.Comment)
1008
- t.Fail()
975
+ t.Errorf("wrong comment %s", x.Comment)
976
}
977
}
978
}
@@ -1018,14 +985,12 @@ func TestEUIxx(t *testing.T) {
985
"host.example. IN EUI64 00-00-5e-ef-00-00-00-2a": "host.example.\t3600\tIN\tEUI64\t00-00-5e-ef-00-00-00-2a",
986
}
987
for i, o := range tests {
1021
- r, e := NewRR(i)
1022
- if e != nil {
1023
- t.Logf("failed to parse %s: %s\n", i, e.Error())
1024
- t.Fail()
988
+ r, err := NewRR(i)
989
+ if err != nil {
990
+ t.Errorf("failed to parse %s: %v", i, err)
991
}
992
if r.String() != o {
1027
- t.Logf("want %s, got %s\n", o, r.String())
1028
- t.Fail()
993
+ t.Errorf("want %s, got %s", o, r.String())
994
}
995
}
996
}
@@ -1037,14 +1002,12 @@ func TestUserRR(t *testing.T) {
1002
"host.example. IN UINFO \"Miek Gieben\"": "host.example.\t3600\tIN\tUINFO\t\"Miek Gieben\"",
1003
}
1004
for i, o := range tests {
1040
- r, e := NewRR(i)
1041
- if e != nil {
1042
- t.Logf("failed to parse %s: %s\n", i, e.Error())
1043
- t.Fail()
1005
+ r, err := NewRR(i)
1006
+ if err != nil {
1007
+ t.Errorf("failed to parse %s: %v", i, err)
1008
}
1009
if r.String() != o {
1046
- t.Logf("want %s, got %s\n", o, r.String())
1047
- t.Fail()
1010
+ t.Errorf("want %s, got %s", o, r.String())
1011
}
1012
}
1013
}
@@ -1109,30 +1072,42 @@ func TestTXT(t *testing.T) {
1072
t.Error("bad size of serialized record:", rr.len())
1073
}
1074
}
1075
+
1076
+ // Test TXT record with chunk larger than 255 bytes, they should be split up, by the parser
1077
+ s := ""
1078
+ for i := 0; i < 255; i++ {
1079
+ s += "a"
1080
+ }
1081
+ s += "b"
1082
+ rr, err = NewRR(`test.local. 60 IN TXT "` + s + `"`)
1083
+ if err != nil {
1084
+ t.Error("failed to parse empty-string TXT record", err)
1085
+ }
1086
+ if rr.(*TXT).Txt[1] != "b" {
1087
+ t.Errorf("Txt should have two chunk, last one my be 'b', but is %s", rr.(*TXT).Txt[1])
1088
+ }
1089
+ t.Log(rr.String())
1090
}
1091
1092
func TestTypeXXXX(t *testing.T) {
1093
_, err := NewRR("example.com IN TYPE1234 \\# 4 aabbccdd")
1094
if err != nil {
1117
- t.Logf("failed to parse TYPE1234 RR: %s", err.Error())
1118
- t.Fail()
1095
+ t.Errorf("failed to parse TYPE1234 RR: %v", err)
1096
}
1097
_, err = NewRR("example.com IN TYPE655341 \\# 8 aabbccddaabbccdd")
1098
if err == nil {
1122
- t.Logf("this should not work, for TYPE655341")
1123
- t.Fail()
1099
+ t.Errorf("this should not work, for TYPE655341")
1100
}
1101
_, err = NewRR("example.com IN TYPE1 \\# 4 0a000001")
1102
if err == nil {
1127
- t.Logf("this should not work")
1128
- t.Fail()
1103
+ t.Errorf("this should not work")
1104
}
1105
}
1106
1107
func TestPTR(t *testing.T) {
1108
_, err := NewRR("144.2.0.192.in-addr.arpa. 900 IN PTR ilouse03146p0\\(.example.com.")
1109
if err != nil {
1135
- t.Error("failed to parse ", err.Error())
1110
+ t.Error("failed to parse ", err)
1111
}
1112
}
1113
@@ -1147,13 +1122,13 @@ func TestDigit(t *testing.T) {
1122
"miek\\004.nl. 100 IN TXT \"A\"": 4,
1123
}
1124
for s, i := range tests {
1150
- r, e := NewRR(s)
1125
+ r, err := NewRR(s)
1126
buf := make([]byte, 40)
1152
- if e != nil {
1153
- t.Fatalf("failed to parse %s\n", e.Error())
1127
+ if err != nil {
1128
+ t.Fatalf("failed to parse %v", err)
1129
}
1130
PackRR(r, buf, 0, nil, false)
1156
- t.Logf("%v\n", buf)
1131
+ t.Log(buf)
1132
if buf[5] != i {
1133
t.Fatalf("5 pos must be %d, is %d", i, buf[5])
1134
}
@@ -1169,11 +1144,10 @@ func TestParseRRSIGTimestamp(t *testing.T) {
1144
`miek.nl. IN RRSIG SOA 8 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2BvuNiUJjSYlJAgzyAE6CF875BMvvZa+Sb0 RlSCL7WODQSQHhCx/fegHhVVF+Iz8N8kOLrmXD1+jO3Bm6Prl5UhcsPx WTBsg/kmxbp8sR1kvH4oZJtVfakG3iDerrxNaf0sQwhZzyfJQAqpC7pcBoc=`: true,
1145
`miek.nl. IN RRSIG SOA 8 2 43200 315565800 4102477800 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2BvuNiUJjSYlJAgzyAE6CF875BMvvZa+Sb0 RlSCL7WODQSQHhCx/fegHhVVF+Iz8N8kOLrmXD1+jO3Bm6Prl5UhcsPx WTBsg/kmxbp8sR1kvH4oZJtVfakG3iDerrxNaf0sQwhZzyfJQAqpC7pcBoc=`: true,
1146
}
1172
- for r, _ := range tests {
1173
- _, e := NewRR(r)
1174
- if e != nil {
1175
- t.Fail()
1176
- t.Logf("%s\n", e.Error())
1147
+ for r := range tests {
1148
+ _, err := NewRR(r)
1149
+ if err != nil {
1150
+ t.Error(err)
1151
}
1152
}
1153
}
@@ -1184,11 +1158,10 @@ func TestTxtEqual(t *testing.T) {
1158
rr1.Txt = []string{"a\"a", "\"", "b"}
1159
rr2, _ := NewRR(rr1.String())
1160
if rr1.String() != rr2.String() {
1187
- t.Logf("these two TXT records should match")
1188
- t.Logf("\n%s\n%s\n", rr1.String(), rr2.String())
1189
- t.Fail() // This is not an error, but keep this test.
1161
+ // This is not an error, but keep this test.
1162
+ t.Errorf("these two TXT records should match:\n%s\n%s", rr1.String(), rr2.String())
1163
}
1191
- t.Logf("\n%s\n%s\n", rr1.String(), rr2.String())
1164
+ t.Logf("%s\n%s", rr1.String(), rr2.String())
1165
}
1166
1167
func TestTxtLong(t *testing.T) {
@@ -1202,8 +1175,7 @@ func TestTxtLong(t *testing.T) {
1175
}
1176
str := rr1.String()
1177
if len(str) < len(rr1.Txt[0]) {
1205
- t.Logf("string conversion should work")
1206
- t.Fail()
1178
+ t.Error("string conversion should work")
1179
}
1180
}
1181
@@ -1217,7 +1189,7 @@ func TestMalformedPackets(t *testing.T) {
1189
for _, packet := range packets {
1190
data, _ := hex.DecodeString(packet)
1191
// for _, v := range data {
1220
- // t.Logf("%s ", string(v))
1192
+ // t.Log(v)
1193
// }
1194
var msg Msg
1195
msg.Unpack(data)
@@ -1253,15 +1225,14 @@ func TestNewPrivateKey(t *testing.T) {
1225
key.Algorithm = algo.name
1226
privkey, err := key.Generate(algo.bits)
1227
if err != nil {
1256
- t.Fatal(err.Error())
1228
+ t.Fatal(err)
1229
}
1230
1231
newPrivKey, err := key.NewPrivateKey(key.PrivateKeyString(privkey))
1232
if err != nil {
1261
- t.Log(key.String())
1262
- t.Log(key.PrivateKeyString(privkey))
1263
-
1264
- t.Fatal(err.Error())
1233
+ t.Error(key.String())
1234
+ t.Error(key.PrivateKeyString(privkey))
1235
+ t.Fatal(err)
1236
}
1237
1238
switch newPrivKey := newPrivKey.(type) {
@@ -1270,7 +1241,7 @@ func TestNewPrivateKey(t *testing.T) {
1241
}
1242
1243
if !reflect.DeepEqual(privkey, newPrivKey) {
1273
- t.Errorf("[%v] Private keys differ:\n%#v\n%#v\n", AlgorithmToString[algo.name], privkey, newPrivKey)
1244
+ t.Errorf("[%v] Private keys differ:\n%#v\n%#v", AlgorithmToString[algo.name], privkey, newPrivKey)
1245
}
1246
}
1247
}
@@ -1286,7 +1257,7 @@ func TestNewRRSpecial(t *testing.T) {
1257
rr, err = NewRR("; comment")
1258
expect = ""
1259
if err != nil {
1289
- t.Errorf("unexpected err: %s", err)
1260
+ t.Errorf("unexpected err: %v", err)
1261
}
1262
if rr != nil {
1263
t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
@@ -1295,7 +1266,7 @@ func TestNewRRSpecial(t *testing.T) {
1266
rr, err = NewRR("")
1267
expect = ""
1268
if err != nil {
1298
- t.Errorf("unexpected err: %s", err)
1269
+ t.Errorf("unexpected err: %v", err)
1270
}
1271
if rr != nil {
1272
t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
@@ -1304,7 +1275,7 @@ func TestNewRRSpecial(t *testing.T) {
1275
rr, err = NewRR("$ORIGIN foo.")
1276
expect = ""
1277
if err != nil {
1307
- t.Errorf("unexpected err: %s", err)
1278
+ t.Errorf("unexpected err: %v", err)
1279
}
1280
if rr != nil {
1281
t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
@@ -1313,7 +1284,7 @@ func TestNewRRSpecial(t *testing.T) {
1284
rr, err = NewRR(" ")
1285
expect = ""
1286
if err != nil {
1316
- t.Errorf("unexpected err: %s", err)
1287
+ t.Errorf("unexpected err: %v", err)
1288
}
1289
if rr != nil {
1290
t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
@@ -1322,7 +1293,7 @@ func TestNewRRSpecial(t *testing.T) {
1293
rr, err = NewRR("\n")
1294
expect = ""
1295
if err != nil {
1325
- t.Errorf("unexpected err: %s", err)
1296
+ t.Errorf("unexpected err: %v", err)
1297
}
1298
if rr != nil {
1299
t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
@@ -1331,7 +1302,7 @@ func TestNewRRSpecial(t *testing.T) {
1302
rr, err = NewRR("foo. A 1.1.1.1\nbar. A 2.2.2.2")
1303
expect = "foo.\t3600\tIN\tA\t1.1.1.1"
1304
if err != nil {
1334
- t.Errorf("unexpected err: %s", err)
1305
+ t.Errorf("unexpected err: %v", err)
1306
}
1307
if rr == nil || rr.String() != expect {
1308
t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
@@ -1394,15 +1365,13 @@ func TestParseIPSECKEY(t *testing.T) {
1365
for i := 0; i < len(tests)-1; i++ {
1366
t1 := tests[i]
1367
e1 := tests[i+1]
1397
- r, e := NewRR(t1)
1398
- if e != nil {
1399
- t.Logf("failed to parse IPSECKEY %s", e)
1368
+ r, err := NewRR(t1)
1369
+ if err != nil {
1370
+ t.Errorf("failed to parse IPSECKEY %v", err)
1371
continue
1372
}
1373
if r.String() != e1 {
1403
- t.Logf("these two IPSECKEY records should match")
1404
- t.Logf("\n%s\n%s\n", r.String(), e1)
1405
- t.Fail()
1374
+ t.Errorf("these two IPSECKEY records should match:\n%s\n%s", r.String(), e1)
1375
}
1376
i++
1377
}
Godeps/_workspace/src/github.com/miekg/dns/privaterr.go
+2
-9
@@ -1,10 +1,3 @@
1
-/*
2
-PRIVATE RR
3
-
4
-RFC 6895 sets aside a range of type codes for private use. This range
5
-is 65,280 - 65,534 (0xFF00 - 0xFFFE). When experimenting with new Resource Records these
6
-can be used, before requesting an official type code from IANA.
7
-*/
1
package dns
2
3
import (
@@ -91,9 +84,9 @@ func PrivateHandle(rtypestr string, rtype uint16, generator func() PrivateRdata)
84
// TODO(miek): we could also be returning _QUOTE, this might or might not
85
// be an issue (basically parsing TXT becomes hard)
86
switch l = <-c; l.value {
94
- case _NEWLINE, _EOF:
87
+ case zNewline, zEOF:
88
break FETCH
96
- case _STRING:
89
+ case zString:
90
text = append(text, l.token)
91
}
92
}
Godeps/_workspace/src/github.com/miekg/dns/privaterr_test.go
+4
-3
@@ -1,9 +1,10 @@
1
package dns_test
2
3
import (
4
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/miekg/dns"
4
"strings"
5
"testing"
6
+
7
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/miekg/dns"
8
)
9
10
const TypeISBN uint16 = 0x0F01
@@ -75,7 +76,7 @@ func TestPrivateByteSlice(t *testing.T) {
76
buf := make([]byte, 100)
77
off, err := dns.PackRR(rr, buf, 0, nil, false)
78
if err != nil {
78
- t.Errorf("got error packing ISBN: %s", err)
79
+ t.Errorf("got error packing ISBN: %v", err)
80
}
81
82
custrr := rr.(*dns.PrivateRR)
@@ -85,7 +86,7 @@ func TestPrivateByteSlice(t *testing.T) {
86
87
rr1, off1, err := dns.UnpackRR(buf[:off], 0)
88
if err != nil {
88
- t.Errorf("got error unpacking ISBN: %s", err)
89
+ t.Errorf("got error unpacking ISBN: %v", err)
90
}
91
92
if off1 != off {
Godeps/_workspace/src/github.com/miekg/dns/server.go
+15
-13
@@ -10,6 +10,7 @@ import (
10
"time"
11
)
12
13
+// Handler is implemented by any value that implements ServeDNS.
14
type Handler interface {
15
ServeDNS(w ResponseWriter, r *Msg)
16
}
@@ -44,7 +45,7 @@ type response struct {
45
tsigSecret map[string]string // the tsig secrets
46
udp *net.UDPConn // i/o connection if UDP was used
47
tcp *net.TCPConn // i/o connection if TCP was used
47
- udpSession *sessionUDP // oob data to get egress interface right
48
+ udpSession *SessionUDP // oob data to get egress interface right
49
remoteAddr net.Addr // address of the client
50
}
51
@@ -72,12 +73,12 @@ var DefaultServeMux = NewServeMux()
73
// Handler object that calls f.
74
type HandlerFunc func(ResponseWriter, *Msg)
75
75
-// ServerDNS calls f(w, r)
76
+// ServeDNS calls f(w, r).
77
func (f HandlerFunc) ServeDNS(w ResponseWriter, r *Msg) {
78
f(w, r)
79
}
80
80
-// FailedHandler returns a HandlerFunc that returns SERVFAIL for every request it gets.
81
+// HandleFailed returns a HandlerFunc that returns SERVFAIL for every request it gets.
82
func HandleFailed(w ResponseWriter, r *Msg) {
83
m := new(Msg)
84
m.SetRcode(r, RcodeServerFailure)
@@ -121,10 +122,9 @@ func (mux *ServeMux) match(q string, t uint16) Handler {
122
if h, ok := mux.z[string(b[:l])]; ok { // 'causes garbage, might want to change the map key
123
if t != TypeDS {
124
return h
124
- } else {
125
- // Continue for DS to see if we have a parent too, if so delegeate to the parent
126
- handler = h
125
}
126
+ // Continue for DS to see if we have a parent too, if so delegeate to the parent
127
+ handler = h
128
}
129
off, end = NextLabel(q, off)
130
if end {
@@ -148,7 +148,7 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
148
mux.m.Unlock()
149
}
150
151
-// Handle adds a handler to the ServeMux for pattern.
151
+// HandleFunc adds a handler function to the ServeMux for pattern.
152
func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Msg)) {
153
mux.Handle(pattern, HandlerFunc(handler))
154
}
@@ -264,6 +264,7 @@ func (srv *Server) ListenAndServe() error {
264
if e != nil {
265
return e
266
}
267
+ srv.Listener = l
268
return srv.serveTCP(l)
269
case "udp", "udp4", "udp6":
270
a, e := net.ResolveUDPAddr(srv.Net, addr)
@@ -277,6 +278,7 @@ func (srv *Server) ListenAndServe() error {
278
if e := setUDPSocketOptions(l); e != nil {
279
return e
280
}
281
+ srv.PacketConn = l
282
return srv.serveUDP(l)
283
}
284
return &Error{err: "bad network"}
@@ -372,7 +374,7 @@ func (srv *Server) getReadTimeout() time.Duration {
374
}
375
376
// serveTCP starts a TCP listener for the server.
375
-// Each request is handled in a seperate goroutine.
377
+// Each request is handled in a separate goroutine.
378
func (srv *Server) serveTCP(l *net.TCPListener) error {
379
defer l.Close()
380
@@ -407,7 +409,7 @@ func (srv *Server) serveTCP(l *net.TCPListener) error {
409
}
410
411
// serveUDP starts a UDP listener for the server.
410
-// Each request is handled in a seperate goroutine.
412
+// Each request is handled in a separate goroutine.
413
func (srv *Server) serveUDP(l *net.UDPConn) error {
414
defer l.Close()
415
@@ -438,7 +440,7 @@ func (srv *Server) serveUDP(l *net.UDPConn) error {
440
}
441
442
// Serve a new connection.
441
-func (srv *Server) serve(a net.Addr, h Handler, m []byte, u *net.UDPConn, s *sessionUDP, t *net.TCPConn) {
443
+func (srv *Server) serve(a net.Addr, h Handler, m []byte, u *net.UDPConn, s *SessionUDP, t *net.TCPConn) {
444
w := &response{tsigSecret: srv.TsigSecret, udp: u, tcp: t, remoteAddr: a, udpSession: s}
445
q := 0
446
defer func() {
@@ -537,10 +539,10 @@ func (srv *Server) readTCP(conn *net.TCPConn, timeout time.Duration) ([]byte, er
539
return m, nil
540
}
541
540
-func (srv *Server) readUDP(conn *net.UDPConn, timeout time.Duration) ([]byte, *sessionUDP, error) {
542
+func (srv *Server) readUDP(conn *net.UDPConn, timeout time.Duration) ([]byte, *SessionUDP, error) {
543
conn.SetReadDeadline(time.Now().Add(timeout))
544
m := make([]byte, srv.UDPSize)
543
- n, s, e := readFromSessionUDP(conn, m)
545
+ n, s, e := ReadFromSessionUDP(conn, m)
546
if e != nil || n == 0 {
547
if e != nil {
548
return nil, nil, e
@@ -576,7 +578,7 @@ func (w *response) WriteMsg(m *Msg) (err error) {
578
func (w *response) Write(m []byte) (int, error) {
579
switch {
580
case w.udp != nil:
579
- n, err := writeToSessionUDP(w.udp, m, w.udpSession)
581
+ n, err := WriteToSessionUDP(w.udp, m, w.udpSession)
582
return n, err
583
case w.tcp != nil:
584
lm := len(m)
Godeps/_workspace/src/github.com/miekg/dns/server_test.go
+23
-35
@@ -95,7 +95,7 @@ func TestServing(t *testing.T) {
95
96
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
97
if err != nil {
98
- t.Fatalf("Unable to run test server: %s", err)
98
+ t.Fatalf("Unable to run test server: %v", err)
99
}
100
defer s.Shutdown()
101
@@ -104,38 +104,32 @@ func TestServing(t *testing.T) {
104
m.SetQuestion("miek.nl.", TypeTXT)
105
r, _, err := c.Exchange(m, addrstr)
106
if err != nil || len(r.Extra) == 0 {
107
- t.Log("failed to exchange miek.nl", err)
108
- t.Fatal()
107
+ t.Fatal("failed to exchange miek.nl", err)
108
}
109
txt := r.Extra[0].(*TXT).Txt[0]
110
if txt != "Hello world" {
112
- t.Log("Unexpected result for miek.nl", txt, "!= Hello world")
113
- t.Fail()
111
+ t.Error("Unexpected result for miek.nl", txt, "!= Hello world")
112
}
113
114
m.SetQuestion("example.com.", TypeTXT)
115
r, _, err = c.Exchange(m, addrstr)
116
if err != nil {
119
- t.Log("failed to exchange example.com", err)
120
- t.Fatal()
117
+ t.Fatal("failed to exchange example.com", err)
118
}
119
txt = r.Extra[0].(*TXT).Txt[0]
120
if txt != "Hello example" {
124
- t.Log("Unexpected result for example.com", txt, "!= Hello example")
125
- t.Fail()
121
+ t.Error("Unexpected result for example.com", txt, "!= Hello example")
122
}
123
124
// Test Mixes cased as noticed by Ask.
125
m.SetQuestion("eXaMplE.cOm.", TypeTXT)
126
r, _, err = c.Exchange(m, addrstr)
127
if err != nil {
132
- t.Log("failed to exchange eXaMplE.cOm", err)
133
- t.Fail()
128
+ t.Error("failed to exchange eXaMplE.cOm", err)
129
}
130
txt = r.Extra[0].(*TXT).Txt[0]
131
if txt != "Hello example" {
137
- t.Log("Unexpected result for example.com", txt, "!= Hello example")
138
- t.Fail()
132
+ t.Error("Unexpected result for example.com", txt, "!= Hello example")
133
}
134
}
135
@@ -147,7 +141,7 @@ func BenchmarkServe(b *testing.B) {
141
142
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
143
if err != nil {
150
- b.Fatalf("Unable to run test server: %s", err)
144
+ b.Fatalf("Unable to run test server: %v", err)
145
}
146
defer s.Shutdown()
147
@@ -169,7 +163,7 @@ func benchmarkServe6(b *testing.B) {
163
a := runtime.GOMAXPROCS(4)
164
s, addrstr, err := RunLocalUDPServer("[::1]:0")
165
if err != nil {
172
- b.Fatalf("Unable to run test server: %s", err)
166
+ b.Fatalf("Unable to run test server: %v", err)
167
}
168
defer s.Shutdown()
169
@@ -200,7 +194,7 @@ func BenchmarkServeCompress(b *testing.B) {
194
a := runtime.GOMAXPROCS(4)
195
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
196
if err != nil {
203
- b.Fatalf("Unable to run test server: %s", err)
197
+ b.Fatalf("Unable to run test server: %v", err)
198
}
199
defer s.Shutdown()
200
@@ -301,7 +295,7 @@ func TestServingLargeResponses(t *testing.T) {
295
296
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
297
if err != nil {
304
- t.Fatalf("Unable to run test server: %s", err)
298
+ t.Fatalf("Unable to run test server: %v", err)
299
}
300
defer s.Shutdown()
301
@@ -316,8 +310,7 @@ func TestServingLargeResponses(t *testing.T) {
310
M.Unlock()
311
_, _, err = c.Exchange(m, addrstr)
312
if err != nil {
319
- t.Logf("failed to exchange: %s", err.Error())
320
- t.Fail()
313
+ t.Errorf("failed to exchange: %v", err)
314
}
315
// This must fail
316
M.Lock()
@@ -325,15 +318,13 @@ func TestServingLargeResponses(t *testing.T) {
318
M.Unlock()
319
_, _, err = c.Exchange(m, addrstr)
320
if err == nil {
328
- t.Logf("failed to fail exchange, this should generate packet error")
329
- t.Fail()
321
+ t.Error("failed to fail exchange, this should generate packet error")
322
}
323
// But this must work again
324
c.UDPSize = 7000
325
_, _, err = c.Exchange(m, addrstr)
326
if err != nil {
335
- t.Logf("failed to exchange: %s", err.Error())
336
- t.Fail()
327
+ t.Errorf("failed to exchange: %v", err)
328
}
329
}
330
@@ -344,7 +335,7 @@ func TestServingResponse(t *testing.T) {
335
HandleFunc("miek.nl.", HelloServer)
336
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
337
if err != nil {
347
- t.Fatalf("Unable to run test server: %s", err)
338
+ t.Fatalf("Unable to run test server: %v", err)
339
}
340
341
c := new(Client)
@@ -353,49 +344,46 @@ func TestServingResponse(t *testing.T) {
344
m.Response = false
345
_, _, err = c.Exchange(m, addrstr)
346
if err != nil {
356
- t.Log("failed to exchange", err)
357
- t.Fatal()
347
+ t.Fatal("failed to exchange", err)
348
}
349
m.Response = true
350
_, _, err = c.Exchange(m, addrstr)
351
if err == nil {
362
- t.Log("exchanged response message")
363
- t.Fatal()
352
+ t.Fatal("exchanged response message")
353
}
354
355
s.Shutdown()
356
s, addrstr, err = RunLocalUDPServerUnsafe("127.0.0.1:0")
357
if err != nil {
369
- t.Fatalf("Unable to run test server: %s", err)
358
+ t.Fatalf("Unable to run test server: %v", err)
359
}
360
defer s.Shutdown()
361
362
m.Response = true
363
_, _, err = c.Exchange(m, addrstr)
364
if err != nil {
376
- t.Log("could exchanged response message in Unsafe mode")
377
- t.Fatal()
365
+ t.Fatal("could exchanged response message in Unsafe mode")
366
}
367
}
368
369
func TestShutdownTCP(t *testing.T) {
370
s, _, err := RunLocalTCPServer("127.0.0.1:0")
371
if err != nil {
384
- t.Fatalf("Unable to run test server: %s", err)
372
+ t.Fatalf("Unable to run test server: %v", err)
373
}
374
err = s.Shutdown()
375
if err != nil {
388
- t.Errorf("Could not shutdown test TCP server, %s", err)
376
+ t.Errorf("Could not shutdown test TCP server, %v", err)
377
}
378
}
379
380
func TestShutdownUDP(t *testing.T) {
381
s, _, err := RunLocalUDPServer("127.0.0.1:0")
382
if err != nil {
395
- t.Fatalf("Unable to run test server: %s", err)
383
+ t.Fatalf("Unable to run test server: %v", err)
384
}
385
err = s.Shutdown()
386
if err != nil {
399
- t.Errorf("Could not shutdown test UDP server, %s", err)
387
+ t.Errorf("Could not shutdown test UDP server, %v", err)
388
}
389
}
Godeps/_workspace/src/github.com/miekg/dns/sig0.go
+1
-16
@@ -1,18 +1,3 @@
1
-// SIG(0)
2
-//
3
-// From RFC 2931:
4
-//
5
-// SIG(0) provides protection for DNS transactions and requests ....
6
-// ... protection for glue records, DNS requests, protection for message headers
7
-// on requests and responses, and protection of the overall integrity of a response.
8
-//
9
-// It works like TSIG, except that SIG(0) uses public key cryptography, instead of the shared
10
-// secret approach in TSIG.
11
-// Supported algorithms: DSA, ECDSAP256SHA256, ECDSAP384SHA384, RSASHA1, RSASHA256 and
12
-// RSASHA512.
13
-//
14
-// Signing subsequent messages in multi-message sessions is not implemented.
15
-//
1
package dns
2
3
import (
@@ -92,7 +77,7 @@ func (rr *SIG) Sign(k PrivateKey, m *Msg) ([]byte, error) {
77
buf[rdoff], buf[rdoff+1] = packUint16(rdlen)
78
// Adjust additional count
79
adc, _ := unpackUint16(buf, 10)
95
- adc += 1
80
+ adc++
81
buf[10], buf[11] = packUint16(adc)
82
return buf, nil
83
}
Godeps/_workspace/src/github.com/miekg/dns/sig0_test.go
+8
-16
@@ -27,8 +27,7 @@ func TestSIG0(t *testing.T) {
27
}
28
pk, err := keyrr.Generate(keysize)
29
if err != nil {
30
- t.Logf("Failed to generate key for “%s”: %v", algstr, err)
31
- t.Fail()
30
+ t.Errorf("Failed to generate key for “%s”: %v", algstr, err)
31
continue
32
}
33
now := uint32(time.Now().Unix())
@@ -43,19 +42,16 @@ func TestSIG0(t *testing.T) {
42
sigrr.SignerName = keyrr.Hdr.Name
43
mb, err := sigrr.Sign(pk, m)
44
if err != nil {
46
- t.Logf("Failed to sign message using “%s”: %v", algstr, err)
47
- t.Fail()
45
+ t.Errorf("Failed to sign message using “%s”: %v", algstr, err)
46
continue
47
}
48
m := new(Msg)
49
if err := m.Unpack(mb); err != nil {
52
- t.Logf("Failed to unpack message signed using “%s”: %v", algstr, err)
53
- t.Fail()
50
+ t.Errorf("Failed to unpack message signed using “%s”: %v", algstr, err)
51
continue
52
}
53
if len(m.Extra) != 1 {
57
- t.Logf("Missing SIG for message signed using “%s”", algstr)
58
- t.Fail()
54
+ t.Errorf("Missing SIG for message signed using “%s”", algstr)
55
continue
56
}
57
var sigrrwire *SIG
@@ -63,8 +59,7 @@ func TestSIG0(t *testing.T) {
59
case *SIG:
60
sigrrwire = rr
61
default:
66
- t.Logf("Expected SIG RR, instead: %v", rr)
67
- t.Fail()
62
+ t.Errorf("Expected SIG RR, instead: %v", rr)
63
continue
64
}
65
for _, rr := range []*SIG{sigrr, sigrrwire} {
@@ -73,23 +68,20 @@ func TestSIG0(t *testing.T) {
68
id = "sigrrwire"
69
}
70
if err := rr.Verify(keyrr, mb); err != nil {
76
- t.Logf("Failed to verify “%s” signed SIG(%s): %v", algstr, id, err)
77
- t.Fail()
71
+ t.Errorf("Failed to verify “%s” signed SIG(%s): %v", algstr, id, err)
72
continue
73
}
74
}
75
mb[13]++
76
if err := sigrr.Verify(keyrr, mb); err == nil {
83
- t.Logf("Verify succeeded on an altered message using “%s”", algstr)
84
- t.Fail()
77
+ t.Errorf("Verify succeeded on an altered message using “%s”", algstr)
78
continue
79
}
80
sigrr.Expiration = 2
81
sigrr.Inception = 1
82
mb, _ = sigrr.Sign(pk, m)
83
if err := sigrr.Verify(keyrr, mb); err == nil {
91
- t.Logf("Verify succeeded on an expired message using “%s”", algstr)
92
- t.Fail()
84
+ t.Errorf("Verify succeeded on an expired message using “%s”", algstr)
85
continue
86
}
87
}
Godeps/_workspace/src/github.com/miekg/dns/tlsa.go
+4
-2
@@ -25,7 +25,8 @@ func CertificateToDANE(selector, matchingType uint8, cert *x509.Certificate) (st
25
h := sha256.New()
26
switch selector {
27
case 0:
28
- return hex.EncodeToString(cert.Raw), nil
28
+ io.WriteString(h, string(cert.Raw))
29
+ return hex.EncodeToString(h.Sum(nil)), nil
30
case 1:
31
io.WriteString(h, string(cert.RawSubjectPublicKeyInfo))
32
return hex.EncodeToString(h.Sum(nil)), nil
@@ -34,7 +35,8 @@ func CertificateToDANE(selector, matchingType uint8, cert *x509.Certificate) (st
35
h := sha512.New()
36
switch selector {
37
case 0:
37
- return hex.EncodeToString(cert.Raw), nil
38
+ io.WriteString(h, string(cert.Raw))
39
+ return hex.EncodeToString(h.Sum(nil)), nil
40
case 1:
41
io.WriteString(h, string(cert.RawSubjectPublicKeyInfo))
42
return hex.EncodeToString(h.Sum(nil)), nil
Godeps/_workspace/src/github.com/miekg/dns/tsig.go
+2
-53
@@ -1,56 +1,3 @@
1
-// TRANSACTION SIGNATURE
2
-//
3
-// An TSIG or transaction signature adds a HMAC TSIG record to each message sent.
4
-// The supported algorithms include: HmacMD5, HmacSHA1, HmacSHA256 and HmacSHA512.
5
-//
6
-// Basic use pattern when querying with a TSIG name "axfr." (note that these key names
7
-// must be fully qualified - as they are domain names) and the base64 secret
8
-// "so6ZGir4GPAqINNh9U5c3A==":
9
-//
10
-// c := new(dns.Client)
11
-// c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
12
-// m := new(dns.Msg)
13
-// m.SetQuestion("miek.nl.", dns.TypeMX)
14
-// m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
15
-// ...
16
-// // When sending the TSIG RR is calculated and filled in before sending
17
-//
18
-// When requesting an zone transfer (almost all TSIG usage is when requesting zone transfers), with
19
-// TSIG, this is the basic use pattern. In this example we request an AXFR for
20
-// miek.nl. with TSIG key named "axfr." and secret "so6ZGir4GPAqINNh9U5c3A=="
21
-// and using the server 176.58.119.54:
22
-//
23
-// t := new(dns.Transfer)
24
-// m := new(dns.Msg)
25
-// t.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
26
-// m.SetAxfr("miek.nl.")
27
-// m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
28
-// c, err := t.In(m, "176.58.119.54:53")
29
-// for r := range c { /* r.RR */ }
30
-//
31
-// You can now read the records from the transfer as they come in. Each envelope is checked with TSIG.
32
-// If something is not correct an error is returned.
33
-//
34
-// Basic use pattern validating and replying to a message that has TSIG set.
35
-//
36
-// server := &dns.Server{Addr: ":53", Net: "udp"}
37
-// server.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
38
-// go server.ListenAndServe()
39
-// dns.HandleFunc(".", handleRequest)
40
-//
41
-// func handleRequest(w dns.ResponseWriter, r *dns.Msg) {
42
-// m := new(Msg)
43
-// m.SetReply(r)
44
-// if r.IsTsig() {
45
-// if w.TsigStatus() == nil {
46
-// // *Msg r has an TSIG record and it was validated
47
-// m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
48
-// } else {
49
-// // *Msg r has an TSIG records and it was not valided
50
-// }
51
-// }
52
-// w.WriteMsg(m)
53
-// }
1
package dns
2
3
import (
@@ -75,6 +22,8 @@ const (
22
HmacSHA512 = "hmac-sha512."
23
)
24
25
+// TSIG is the RR the holds the transaction signature of a message.
26
+// See RFC 2845 and RFC 4635.
27
type TSIG struct {
28
Hdr RR_Header
29
Algorithm string `dns:"domain-name"`
Godeps/_workspace/src/github.com/miekg/dns/types.go
+17
-8
@@ -10,9 +10,12 @@ import (
10
)
11
12
type (
13
- Type uint16 // Type is a DNS type.
14
- Class uint16 // Class is a DNS class.
15
- Name string // Name is a DNS domain name.
13
+ // Type is a DNS type.
14
+ Type uint16
15
+ // Class is a DNS class.
16
+ Class uint16
17
+ // Name is a DNS domain name.
18
+ Name string
19
)
20
21
// Packet formats
@@ -20,6 +23,7 @@ type (
23
// Wire constants and supported types.
24
const (
25
// valid RR_Header.Rrtype and Question.qtype
26
+
27
TypeNone uint16 = 0
28
TypeA uint16 = 1
29
TypeNS uint16 = 2
@@ -91,7 +95,9 @@ const (
95
96
TypeTKEY uint16 = 249
97
TypeTSIG uint16 = 250
98
+
99
// valid Question.Qtype only
100
+
101
TypeIXFR uint16 = 251
102
TypeAXFR uint16 = 252
103
TypeMAILB uint16 = 253
@@ -105,6 +111,7 @@ const (
111
TypeReserved uint16 = 65535
112
113
// valid Question.Qclass
114
+
115
ClassINET = 1
116
ClassCSNET = 2
117
ClassCHAOS = 3
@@ -113,6 +120,7 @@ const (
120
ClassANY = 255
121
122
// Msg.rcode
123
+
124
RcodeSuccess = 0
125
RcodeFormatError = 1
126
RcodeServerFailure = 2
@@ -133,11 +141,11 @@ const (
141
RcodeBadAlg = 21
142
RcodeBadTrunc = 22 // TSIG
143
136
- // Opcode
144
+ // Opcode, there is no 3
145
+
146
OpcodeQuery = 0
147
OpcodeIQuery = 1
148
OpcodeStatus = 2
140
- // There is no 3
149
OpcodeNotify = 4
150
OpcodeUpdate = 5
151
)
@@ -198,7 +206,8 @@ var CertTypeToString = map[uint16]string{
206
207
var StringToCertType = reverseInt16(CertTypeToString)
208
201
-// DNS queries.
209
+// Question holds a DNS question. There can be multiple questions in the
210
+// question section of a message. Usually there is just one.
211
type Question struct {
212
Name string `dns:"cdomain-name"` // "cdomain-name" specifies encoding (and may be compressed)
213
Qtype uint16
@@ -801,7 +810,7 @@ func cmToM(m, e uint8) string {
810
s := fmt.Sprintf("%d", m)
811
for e > 2 {
812
s += "0"
804
- e -= 1
813
+ e--
814
}
815
return s
816
}
@@ -838,7 +847,7 @@ func (rr *LOC) String() string {
847
lon = lon % LOC_HOURS
848
s += fmt.Sprintf("%02d %02d %0.3f %s ", h, m, (float64(lon) / 1000), ew)
849
841
- var alt float64 = float64(rr.Altitude) / 100
850
+ var alt = float64(rr.Altitude) / 100
851
alt -= LOC_ALTITUDEBASE
852
if rr.Altitude%100 != 0 {
853
s += fmt.Sprintf("%.2fm ", alt)
Godeps/_workspace/src/github.com/miekg/dns/udp.go
+7
-7
@@ -7,12 +7,12 @@ import (
7
"syscall"
8
)
9
10
-type sessionUDP struct {
10
+type SessionUDP struct {
11
raddr *net.UDPAddr
12
context []byte
13
}
14
15
-func (s *sessionUDP) RemoteAddr() net.Addr { return s.raddr }
15
+func (s *SessionUDP) RemoteAddr() net.Addr { return s.raddr }
16
17
// setUDPSocketOptions sets the UDP socket options.
18
// This function is implemented on a per platform basis. See udp_*.go for more details
@@ -37,19 +37,19 @@ func setUDPSocketOptions(conn *net.UDPConn) error {
37
return nil
38
}
39
40
-// readFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a
40
+// ReadFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a
41
// net.UDPAddr.
42
-func readFromSessionUDP(conn *net.UDPConn, b []byte) (int, *sessionUDP, error) {
42
+func ReadFromSessionUDP(conn *net.UDPConn, b []byte) (int, *SessionUDP, error) {
43
oob := make([]byte, 40)
44
n, oobn, _, raddr, err := conn.ReadMsgUDP(b, oob)
45
if err != nil {
46
return n, nil, err
47
}
48
- return n, &sessionUDP{raddr, oob[:oobn]}, err
48
+ return n, &SessionUDP{raddr, oob[:oobn]}, err
49
}
50
51
-// writeToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *sessionUDP instead of a net.Addr.
52
-func writeToSessionUDP(conn *net.UDPConn, b []byte, session *sessionUDP) (int, error) {
51
+// WriteToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *SessionUDP instead of a net.Addr.
52
+func WriteToSessionUDP(conn *net.UDPConn, b []byte, session *SessionUDP) (int, error) {
53
n, _, err := conn.WriteMsgUDP(b, session.context, session.raddr)
54
return n, err
55
}
Godeps/_workspace/src/github.com/miekg/dns/udp_windows.go
+7
-7
@@ -4,28 +4,28 @@ package dns
4
5
import "net"
6
7
-type sessionUDP struct {
7
+type SessionUDP struct {
8
raddr *net.UDPAddr
9
}
10
11
-// readFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a
11
+// ReadFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a
12
// net.UDPAddr.
13
-func readFromSessionUDP(conn *net.UDPConn, b []byte) (int, *sessionUDP, error) {
13
+func ReadFromSessionUDP(conn *net.UDPConn, b []byte) (int, *SessionUDP, error) {
14
n, raddr, err := conn.ReadFrom(b)
15
if err != nil {
16
return n, nil, err
17
}
18
- session := &sessionUDP{raddr.(*net.UDPAddr)}
18
+ session := &SessionUDP{raddr.(*net.UDPAddr)}
19
return n, session, err
20
}
21
22
-// writeToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *sessionUDP instead of a net.Addr.
23
-func writeToSessionUDP(conn *net.UDPConn, b []byte, session *sessionUDP) (int, error) {
22
+// WriteToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *SessionUDP instead of a net.Addr.
23
+func WriteToSessionUDP(conn *net.UDPConn, b []byte, session *SessionUDP) (int, error) {
24
n, err := conn.WriteTo(b, session.raddr)
25
return n, err
26
}
27
28
-func (s *sessionUDP) RemoteAddr() net.Addr { return s.raddr }
28
+func (s *SessionUDP) RemoteAddr() net.Addr { return s.raddr }
29
30
// setUDPSocketOptions sets the UDP socket options.
31
// This function is implemented on a per platform basis. See udp_*.go for more details
Godeps/_workspace/src/github.com/miekg/dns/update.go
-35
@@ -1,38 +1,3 @@
1
-// DYNAMIC UPDATES
2
-//
3
-// Dynamic updates reuses the DNS message format, but renames three of
4
-// the sections. Question is Zone, Answer is Prerequisite, Authority is
5
-// Update, only the Additional is not renamed. See RFC 2136 for the gory details.
6
-//
7
-// You can set a rather complex set of rules for the existence of absence of
8
-// certain resource records or names in a zone to specify if resource records
9
-// should be added or removed. The table from RFC 2136 supplemented with the Go
10
-// DNS function shows which functions exist to specify the prerequisites.
11
-//
12
-// 3.2.4 - Table Of Metavalues Used In Prerequisite Section
13
-//
14
-// CLASS TYPE RDATA Meaning Function
15
-// --------------------------------------------------------------
16
-// ANY ANY empty Name is in use dns.NameUsed
17
-// ANY rrset empty RRset exists (value indep) dns.RRsetUsed
18
-// NONE ANY empty Name is not in use dns.NameNotUsed
19
-// NONE rrset empty RRset does not exist dns.RRsetNotUsed
20
-// zone rrset rr RRset exists (value dep) dns.Used
21
-//
22
-// The prerequisite section can also be left empty.
23
-// If you have decided on the prerequisites you can tell what RRs should
24
-// be added or deleted. The next table shows the options you have and
25
-// what functions to call.
26
-//
27
-// 3.4.2.6 - Table Of Metavalues Used In Update Section
28
-//
29
-// CLASS TYPE RDATA Meaning Function
30
-// ---------------------------------------------------------------
31
-// ANY ANY empty Delete all RRsets from name dns.RemoveName
32
-// ANY rrset empty Delete an RRset dns.RemoveRRset
33
-// NONE rrset rr Delete an RR from RRset dns.Remove
34
-// zone rrset rr Add to an RRset dns.Insert
35
-//
1
package dns
2
3
// NameUsed sets the RRs in the prereq section to
Godeps/_workspace/src/github.com/miekg/dns/update_test.go
+8
-13
@@ -12,10 +12,9 @@ func TestDynamicUpdateParsing(t *testing.T) {
12
typ == "TSIG" || typ == "ISDN" || typ == "UNSPEC" || typ == "NULL" || typ == "ATMA" {
13
continue
14
}
15
- r, e := NewRR(prefix + typ)
16
- if e != nil {
17
- t.Log("failure to parse: " + prefix + typ)
18
- t.Fail()
15
+ r, err := NewRR(prefix + typ)
16
+ if err != nil {
17
+ t.Errorf("failure to parse: %s %s: %v", prefix, typ, err)
18
} else {
19
t.Logf("parsed: %s", r.String())
20
}
@@ -31,8 +30,7 @@ func TestDynamicUpdateUnpack(t *testing.T) {
30
msg := new(Msg)
31
err := msg.Unpack(buf)
32
if err != nil {
34
- t.Log("failed to unpack: " + err.Error() + "\n" + msg.String())
35
- t.Fail()
33
+ t.Errorf("failed to unpack: %v\n%s", err, msg.String())
34
}
35
}
36
@@ -45,13 +43,11 @@ func TestDynamicUpdateZeroRdataUnpack(t *testing.T) {
43
rr.Rrtype = n
44
bytes, err := m.Pack()
45
if err != nil {
48
- t.Logf("failed to pack %s: %v", s, err)
49
- t.Fail()
46
+ t.Errorf("failed to pack %s: %v", s, err)
47
continue
48
}
49
if err := new(Msg).Unpack(bytes); err != nil {
53
- t.Logf("failed to unpack %s: %v", s, err)
54
- t.Fail()
50
+ t.Errorf("failed to unpack %s: %v", s, err)
51
}
52
}
53
}
@@ -82,8 +78,7 @@ func TestRemoveRRset(t *testing.T) {
78
if err := tmp.Unpack(actual); err != nil {
79
t.Fatalf("Error unpacking actual msg: %v", err)
80
}
85
- t.Logf("Expected msg:\n%s", expectstr)
86
- t.Logf("Actual msg:\n%v", tmp)
87
- t.Fail()
81
+ t.Errorf("Expected msg:\n%s", expectstr)
82
+ t.Errorf("Actual msg:\n%v", tmp)
83
}
84
}
Godeps/_workspace/src/github.com/miekg/dns/xfr.go
+1
@@ -193,6 +193,7 @@ func (t *Transfer) ReadMsg() (*Msg, error) {
193
}
194
// Need to work on the original message p, as that was used to calculate the tsig.
195
err = TsigVerify(p, t.TsigSecret[ts.Hdr.Name], t.tsigRequestMAC, t.tsigTimersOnly)
196
+ t.tsigRequestMAC = ts.MAC
197
}
198
return m, err
199
}
Godeps/_workspace/src/github.com/miekg/dns/xfr_test.go
+10
-17
@@ -7,8 +7,8 @@ import (
7
)
8
9
func getIP(s string) string {
10
- a, e := net.LookupAddr(s)
11
- if e != nil {
10
+ a, err := net.LookupAddr(s)
11
+ if err != nil {
12
return ""
13
}
14
return a[0]
@@ -28,17 +28,15 @@ func testClientAXFR(t *testing.T) {
28
tr := new(Transfer)
29
30
if a, err := tr.In(m, net.JoinHostPort(server, "53")); err != nil {
31
- t.Log("failed to setup axfr: " + err.Error())
32
- t.Fatal()
31
+ t.Fatal("failed to setup axfr: ", err)
32
} else {
33
for ex := range a {
34
if ex.Error != nil {
36
- t.Logf("error %s\n", ex.Error.Error())
37
- t.Fail()
35
+ t.Errorf("error %v", ex.Error)
36
break
37
}
38
for _, rr := range ex.RR {
41
- t.Logf("%s\n", rr.String())
39
+ t.Log(rr.String())
40
}
41
}
42
}
@@ -56,14 +54,11 @@ func testClientAXFRMultipleEnvelopes(t *testing.T) {
54
55
tr := new(Transfer)
56
if a, err := tr.In(m, net.JoinHostPort(server, "53")); err != nil {
59
- t.Log("Failed to setup axfr" + err.Error() + "for server: " + server)
60
- t.Fail()
61
- return
57
+ t.Fatalf("Failed to setup axfr %v for server: %v", err, server)
58
} else {
59
for ex := range a {
60
if ex.Error != nil {
65
- t.Logf("Error %s\n", ex.Error.Error())
66
- t.Fail()
61
+ t.Errorf("Error %v", ex.Error)
62
break
63
}
64
}
@@ -82,17 +77,15 @@ func testClientTsigAXFR(t *testing.T) {
77
tr.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
78
79
if a, err := tr.In(m, "176.58.119.54:53"); err != nil {
85
- t.Log("failed to setup axfr: " + err.Error())
86
- t.Fatal()
80
+ t.Fatal("failed to setup axfr: ", err)
81
} else {
82
for ex := range a {
83
if ex.Error != nil {
90
- t.Logf("error %s\n", ex.Error.Error())
91
- t.Fail()
84
+ t.Errorf("error %v", ex.Error)
85
break
86
}
87
for _, rr := range ex.RR {
95
- t.Logf("%s\n", rr.String())
88
+ t.Log(rr.String())
89
}
90
}
91
}
Godeps/_workspace/src/github.com/miekg/dns/zgenerate.go
+14
-13
@@ -1,6 +1,7 @@
1
package dns
2
3
import (
4
+ "bytes"
5
"fmt"
6
"strconv"
7
"strings"
@@ -24,13 +25,13 @@ func generate(l lex, c chan lex, t chan *Token, o string) string {
25
if i+1 == len(l.token) {
26
return "bad step in $GENERATE range"
27
}
27
- if s, e := strconv.Atoi(l.token[i+1:]); e != nil {
28
- return "bad step in $GENERATE range"
29
- } else {
28
+ if s, e := strconv.Atoi(l.token[i+1:]); e == nil {
29
if s < 0 {
30
return "bad step in $GENERATE range"
31
}
32
step = s
33
+ } else {
34
+ return "bad step in $GENERATE range"
35
}
36
l.token = l.token[:i]
37
}
@@ -46,7 +47,7 @@ func generate(l lex, c chan lex, t chan *Token, o string) string {
47
if err != nil {
48
return "bad stop in $GENERATE range"
49
}
49
- if end < 0 || start < 0 || end <= start {
50
+ if end < 0 || start < 0 || end < start {
51
return "bad range in $GENERATE range"
52
}
53
@@ -55,14 +56,14 @@ func generate(l lex, c chan lex, t chan *Token, o string) string {
56
s := ""
57
BuildRR:
58
l = <-c
58
- if l.value != _NEWLINE && l.value != _EOF {
59
+ if l.value != zNewline && l.value != zEOF {
60
s += l.token
61
goto BuildRR
62
}
63
for i := start; i <= end; i += step {
64
var (
65
escape bool
65
- dom string
66
+ dom bytes.Buffer
67
mod string
68
err string
69
offset int
@@ -72,7 +73,7 @@ BuildRR:
73
switch s[j] {
74
case '\\':
75
if escape {
75
- dom += "\\"
76
+ dom.WriteByte('\\')
77
escape = false
78
continue
79
}
@@ -81,17 +82,17 @@ BuildRR:
82
mod = "%d"
83
offset = 0
84
if escape {
84
- dom += "$"
85
+ dom.WriteByte('$')
86
escape = false
87
continue
88
}
89
escape = false
90
if j+1 >= len(s) { // End of the string
90
- dom += fmt.Sprintf(mod, i+offset)
91
+ dom.WriteString(fmt.Sprintf(mod, i+offset))
92
continue
93
} else {
94
if s[j+1] == '$' {
94
- dom += "$"
95
+ dom.WriteByte('$')
96
j++
97
continue
98
}
@@ -108,17 +109,17 @@ BuildRR:
109
}
110
j += 2 + sep // Jump to it
111
}
111
- dom += fmt.Sprintf(mod, i+offset)
112
+ dom.WriteString(fmt.Sprintf(mod, i+offset))
113
default:
114
if escape { // Pretty useless here
115
escape = false
116
continue
117
}
117
- dom += string(s[j])
118
+ dom.WriteByte(s[j])
119
}
120
}
121
// Re-parse the RR and send it on the current channel t
121
- rx, e := NewRR("$ORIGIN " + o + "\n" + dom)
122
+ rx, e := NewRR("$ORIGIN " + o + "\n" + dom.String())
123
if e != nil {
124
return e.(*ParseError).err
125
}
Godeps/_workspace/src/github.com/miekg/dns/zscan.go
+177
-174
@@ -29,41 +29,41 @@ const maxUint16 = 1<<16 - 1
29
// * Handle braces - anywhere.
30
const (
31
// Zonefile
32
- _EOF = iota
33
- _STRING
34
- _BLANK
35
- _QUOTE
36
- _NEWLINE
37
- _RRTYPE
38
- _OWNER
39
- _CLASS
40
- _DIRORIGIN // $ORIGIN
41
- _DIRTTL // $TTL
42
- _DIRINCLUDE // $INCLUDE
43
- _DIRGENERATE // $GENERATE
32
+ zEOF = iota
33
+ zString
34
+ zBlank
35
+ zQuote
36
+ zNewline
37
+ zRrtpe
38
+ zOwner
39
+ zClass
40
+ zDirOrigin // $ORIGIN
41
+ zDirTtl // $TTL
42
+ zDirInclude // $INCLUDE
43
+ zDirGenerate // $GENERATE
44
45
// Privatekey file
46
- _VALUE
47
- _KEY
48
-
49
- _EXPECT_OWNER_DIR // Ownername
50
- _EXPECT_OWNER_BL // Whitespace after the ownername
51
- _EXPECT_ANY // Expect rrtype, ttl or class
52
- _EXPECT_ANY_NOCLASS // Expect rrtype or ttl
53
- _EXPECT_ANY_NOCLASS_BL // The whitespace after _EXPECT_ANY_NOCLASS
54
- _EXPECT_ANY_NOTTL // Expect rrtype or class
55
- _EXPECT_ANY_NOTTL_BL // Whitespace after _EXPECT_ANY_NOTTL
56
- _EXPECT_RRTYPE // Expect rrtype
57
- _EXPECT_RRTYPE_BL // Whitespace BEFORE rrtype
58
- _EXPECT_RDATA // The first element of the rdata
59
- _EXPECT_DIRTTL_BL // Space after directive $TTL
60
- _EXPECT_DIRTTL // Directive $TTL
61
- _EXPECT_DIRORIGIN_BL // Space after directive $ORIGIN
62
- _EXPECT_DIRORIGIN // Directive $ORIGIN
63
- _EXPECT_DIRINCLUDE_BL // Space after directive $INCLUDE
64
- _EXPECT_DIRINCLUDE // Directive $INCLUDE
65
- _EXPECT_DIRGENERATE // Directive $GENERATE
66
- _EXPECT_DIRGENERATE_BL // Space after directive $GENERATE
46
+ zValue
47
+ zKey
48
+
49
+ zExpectOwnerDir // Ownername
50
+ zExpectOwnerBl // Whitespace after the ownername
51
+ zExpectAny // Expect rrtype, ttl or class
52
+ zExpectAnyNoClass // Expect rrtype or ttl
53
+ zExpectAnyNoClassBl // The whitespace after _EXPECT_ANY_NOCLASS
54
+ zExpectAnyNoTtl // Expect rrtype or class
55
+ zExpectAnyNoTtlBl // Whitespace after _EXPECT_ANY_NOTTL
56
+ zExpectRrtype // Expect rrtype
57
+ zExpectRrtypeBl // Whitespace BEFORE rrtype
58
+ zExpectRdata // The first element of the rdata
59
+ zExpectDirTtlBl // Space after directive $TTL
60
+ zExpectDirTtl // Directive $TTL
61
+ zExpectDirOriginBl // Space after directive $ORIGIN
62
+ zExpectDirOrigin // Directive $ORIGIN
63
+ zExpectDirIncludeBl // Space after directive $INCLUDE
64
+ zExpectDirInclude // Directive $INCLUDE
65
+ zExpectDirGenerate // Directive $GENERATE
66
+ zExpectDirGenerateBl // Space after directive $GENERATE
67
)
68
69
// ParseError is a parsing error. It contains the parse error and the location in the io.Reader
@@ -88,18 +88,21 @@ type lex struct {
88
tokenUpper string // uppercase text of the token
89
length int // lenght of the token
90
err bool // when true, token text has lexer error
91
- value uint8 // value: _STRING, _BLANK, etc.
91
+ value uint8 // value: zString, _BLANK, etc.
92
line int // line in the file
93
column int // column in the file
94
torc uint16 // type or class as parsed in the lexer, we only need to look this up in the grammar
95
comment string // any comment text seen
96
}
97
98
-// *Tokens are returned when a zone file is parsed.
98
+// Token holds the token that are returned when a zone file is parsed.
99
type Token struct {
100
- RR // the scanned resource record when error is not nil
101
- Error *ParseError // when an error occured, this has the error specifics
102
- Comment string // a potential comment positioned after the RR and on the same line
100
+ // The scanned resource record when error is not nil.
101
+ RR
102
+ // When an error occured, this has the error specifics.
103
+ Error *ParseError
104
+ // A potential comment positioned after the RR and on the same line.
105
+ Comment string
106
}
107
108
// NewRR reads the RR contained in the string s. Only the first RR is
@@ -168,17 +171,17 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
171
}
172
}()
173
s := scanInit(r)
171
- c := make(chan lex, 1000)
174
+ c := make(chan lex)
175
// Start the lexer
176
go zlexer(s, c)
177
// 6 possible beginnings of a line, _ is a space
175
- // 0. _RRTYPE -> all omitted until the rrtype
176
- // 1. _OWNER _ _RRTYPE -> class/ttl omitted
177
- // 2. _OWNER _ _STRING _ _RRTYPE -> class omitted
178
- // 3. _OWNER _ _STRING _ _CLASS _ _RRTYPE -> ttl/class
179
- // 4. _OWNER _ _CLASS _ _RRTYPE -> ttl omitted
180
- // 5. _OWNER _ _CLASS _ _STRING _ _RRTYPE -> class/ttl (reversed)
181
- // After detecting these, we know the _RRTYPE so we can jump to functions
178
+ // 0. zRRTYPE -> all omitted until the rrtype
179
+ // 1. zOwner _ zRrtype -> class/ttl omitted
180
+ // 2. zOwner _ zString _ zRrtype -> class omitted
181
+ // 3. zOwner _ zString _ zClass _ zRrtype -> ttl/class
182
+ // 4. zOwner _ zClass _ zRrtype -> ttl omitted
183
+ // 5. zOwner _ zClass _ zString _ zRrtype -> class/ttl (reversed)
184
+ // After detecting these, we know the zRrtype so we can jump to functions
185
// handling the rdata for each of these types.
186
187
if origin == "" {
@@ -190,7 +193,7 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
193
return
194
}
195
193
- st := _EXPECT_OWNER_DIR // initial state
196
+ st := zExpectOwnerDir // initial state
197
var h RR_Header
198
var defttl uint32 = defaultTtl
199
var prevName string
@@ -202,19 +205,19 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
205
206
}
207
switch st {
205
- case _EXPECT_OWNER_DIR:
208
+ case zExpectOwnerDir:
209
// We can also expect a directive, like $TTL or $ORIGIN
210
h.Ttl = defttl
211
h.Class = ClassINET
212
switch l.value {
210
- case _NEWLINE: // Empty line
211
- st = _EXPECT_OWNER_DIR
212
- case _OWNER:
213
+ case zNewline:
214
+ st = zExpectOwnerDir
215
+ case zOwner:
216
h.Name = l.token
217
if l.token[0] == '@' {
218
h.Name = origin
219
prevName = h.Name
217
- st = _EXPECT_OWNER_BL
220
+ st = zExpectOwnerBl
221
break
222
}
223
if h.Name[l.length-1] != '.' {
@@ -226,58 +229,58 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
229
return
230
}
231
prevName = h.Name
229
- st = _EXPECT_OWNER_BL
230
- case _DIRTTL:
231
- st = _EXPECT_DIRTTL_BL
232
- case _DIRORIGIN:
233
- st = _EXPECT_DIRORIGIN_BL
234
- case _DIRINCLUDE:
235
- st = _EXPECT_DIRINCLUDE_BL
236
- case _DIRGENERATE:
237
- st = _EXPECT_DIRGENERATE_BL
238
- case _RRTYPE: // Everthing has been omitted, this is the first thing on the line
232
+ st = zExpectOwnerBl
233
+ case zDirTtl:
234
+ st = zExpectDirTtlBl
235
+ case zDirOrigin:
236
+ st = zExpectDirOriginBl
237
+ case zDirInclude:
238
+ st = zExpectDirIncludeBl
239
+ case zDirGenerate:
240
+ st = zExpectDirGenerateBl
241
+ case zRrtpe:
242
h.Name = prevName
243
h.Rrtype = l.torc
241
- st = _EXPECT_RDATA
242
- case _CLASS: // First thing on the line is the class
244
+ st = zExpectRdata
245
+ case zClass:
246
h.Name = prevName
247
h.Class = l.torc
245
- st = _EXPECT_ANY_NOCLASS_BL
246
- case _BLANK:
248
+ st = zExpectAnyNoClassBl
249
+ case zBlank:
250
// Discard, can happen when there is nothing on the
251
// line except the RR type
249
- case _STRING: // First thing on the is the ttl
250
- if ttl, ok := stringToTtl(l.token); !ok {
252
+ case zString:
253
+ ttl, ok := stringToTtl(l.token)
254
+ if !ok {
255
t <- &Token{Error: &ParseError{f, "not a TTL", l}}
256
return
253
- } else {
254
- h.Ttl = ttl
255
- // Don't about the defttl, we should take the $TTL value
256
- // defttl = ttl
257
}
258
- st = _EXPECT_ANY_NOTTL_BL
258
+ h.Ttl = ttl
259
+ // Don't about the defttl, we should take the $TTL value
260
+ // defttl = ttl
261
+ st = zExpectAnyNoTtlBl
262
263
default:
264
t <- &Token{Error: &ParseError{f, "syntax error at beginning", l}}
265
return
266
}
264
- case _EXPECT_DIRINCLUDE_BL:
265
- if l.value != _BLANK {
267
+ case zExpectDirIncludeBl:
268
+ if l.value != zBlank {
269
t <- &Token{Error: &ParseError{f, "no blank after $INCLUDE-directive", l}}
270
return
271
}
269
- st = _EXPECT_DIRINCLUDE
270
- case _EXPECT_DIRINCLUDE:
271
- if l.value != _STRING {
272
+ st = zExpectDirInclude
273
+ case zExpectDirInclude:
274
+ if l.value != zString {
275
t <- &Token{Error: &ParseError{f, "expecting $INCLUDE value, not this...", l}}
276
return
277
}
278
neworigin := origin // There may be optionally a new origin set after the filename, if not use current one
279
l := <-c
280
switch l.value {
278
- case _BLANK:
281
+ case zBlank:
282
l := <-c
280
- if l.value == _STRING {
283
+ if l.value == zString {
284
if _, ok := IsDomainName(l.token); !ok {
285
t <- &Token{Error: &ParseError{f, "bad origin name", l}}
286
return
@@ -293,7 +296,7 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
296
neworigin = l.token
297
}
298
}
296
- case _NEWLINE, _EOF:
299
+ case zNewline, zEOF:
300
// Ok
301
default:
302
t <- &Token{Error: &ParseError{f, "garbage after $INCLUDE", l}}
@@ -310,15 +313,15 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
313
return
314
}
315
parseZone(r1, l.token, neworigin, t, include+1)
313
- st = _EXPECT_OWNER_DIR
314
- case _EXPECT_DIRTTL_BL:
315
- if l.value != _BLANK {
316
+ st = zExpectOwnerDir
317
+ case zExpectDirTtlBl:
318
+ if l.value != zBlank {
319
t <- &Token{Error: &ParseError{f, "no blank after $TTL-directive", l}}
320
return
321
}
319
- st = _EXPECT_DIRTTL
320
- case _EXPECT_DIRTTL:
321
- if l.value != _STRING {
322
+ st = zExpectDirTtl
323
+ case zExpectDirTtl:
324
+ if l.value != zString {
325
t <- &Token{Error: &ParseError{f, "expecting $TTL value, not this...", l}}
326
return
327
}
@@ -326,21 +329,21 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
329
t <- &Token{Error: e}
330
return
331
}
329
- if ttl, ok := stringToTtl(l.token); !ok {
332
+ ttl, ok := stringToTtl(l.token)
333
+ if !ok {
334
t <- &Token{Error: &ParseError{f, "expecting $TTL value, not this...", l}}
335
return
332
- } else {
333
- defttl = ttl
336
}
335
- st = _EXPECT_OWNER_DIR
336
- case _EXPECT_DIRORIGIN_BL:
337
- if l.value != _BLANK {
337
+ defttl = ttl
338
+ st = zExpectOwnerDir
339
+ case zExpectDirOriginBl:
340
+ if l.value != zBlank {
341
t <- &Token{Error: &ParseError{f, "no blank after $ORIGIN-directive", l}}
342
return
343
}
341
- st = _EXPECT_DIRORIGIN
342
- case _EXPECT_DIRORIGIN:
343
- if l.value != _STRING {
344
+ st = zExpectDirOrigin
345
+ case zExpectDirOrigin:
346
+ if l.value != zString {
347
t <- &Token{Error: &ParseError{f, "expecting $ORIGIN value, not this...", l}}
348
return
349
}
@@ -360,15 +363,15 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
363
} else {
364
origin = l.token
365
}
363
- st = _EXPECT_OWNER_DIR
364
- case _EXPECT_DIRGENERATE_BL:
365
- if l.value != _BLANK {
366
+ st = zExpectOwnerDir
367
+ case zExpectDirGenerateBl:
368
+ if l.value != zBlank {
369
t <- &Token{Error: &ParseError{f, "no blank after $GENERATE-directive", l}}
370
return
371
}
369
- st = _EXPECT_DIRGENERATE
370
- case _EXPECT_DIRGENERATE:
371
- if l.value != _STRING {
372
+ st = zExpectDirGenerate
373
+ case zExpectDirGenerate:
374
+ if l.value != zString {
375
t <- &Token{Error: &ParseError{f, "expecting $GENERATE value, not this...", l}}
376
return
377
}
@@ -376,90 +379,90 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
379
t <- &Token{Error: &ParseError{f, e, l}}
380
return
381
}
379
- st = _EXPECT_OWNER_DIR
380
- case _EXPECT_OWNER_BL:
381
- if l.value != _BLANK {
382
+ st = zExpectOwnerDir
383
+ case zExpectOwnerBl:
384
+ if l.value != zBlank {
385
t <- &Token{Error: &ParseError{f, "no blank after owner", l}}
386
return
387
}
385
- st = _EXPECT_ANY
386
- case _EXPECT_ANY:
388
+ st = zExpectAny
389
+ case zExpectAny:
390
switch l.value {
388
- case _RRTYPE:
391
+ case zRrtpe:
392
h.Rrtype = l.torc
390
- st = _EXPECT_RDATA
391
- case _CLASS:
393
+ st = zExpectRdata
394
+ case zClass:
395
h.Class = l.torc
393
- st = _EXPECT_ANY_NOCLASS_BL
394
- case _STRING: // TTL is this case
395
- if ttl, ok := stringToTtl(l.token); !ok {
396
+ st = zExpectAnyNoClassBl
397
+ case zString:
398
+ ttl, ok := stringToTtl(l.token)
399
+ if !ok {
400
t <- &Token{Error: &ParseError{f, "not a TTL", l}}
401
return
398
- } else {
399
- h.Ttl = ttl
400
- // defttl = ttl // don't set the defttl here
402
}
402
- st = _EXPECT_ANY_NOTTL_BL
403
+ h.Ttl = ttl
404
+ // defttl = ttl // don't set the defttl here
405
+ st = zExpectAnyNoTtlBl
406
default:
407
t <- &Token{Error: &ParseError{f, "expecting RR type, TTL or class, not this...", l}}
408
return
409
}
407
- case _EXPECT_ANY_NOCLASS_BL:
408
- if l.value != _BLANK {
410
+ case zExpectAnyNoClassBl:
411
+ if l.value != zBlank {
412
t <- &Token{Error: &ParseError{f, "no blank before class", l}}
413
return
414
}
412
- st = _EXPECT_ANY_NOCLASS
413
- case _EXPECT_ANY_NOTTL_BL:
414
- if l.value != _BLANK {
415
+ st = zExpectAnyNoClass
416
+ case zExpectAnyNoTtlBl:
417
+ if l.value != zBlank {
418
t <- &Token{Error: &ParseError{f, "no blank before TTL", l}}
419
return
420
}
418
- st = _EXPECT_ANY_NOTTL
419
- case _EXPECT_ANY_NOTTL:
421
+ st = zExpectAnyNoTtl
422
+ case zExpectAnyNoTtl:
423
switch l.value {
421
- case _CLASS:
424
+ case zClass:
425
h.Class = l.torc
423
- st = _EXPECT_RRTYPE_BL
424
- case _RRTYPE:
426
+ st = zExpectRrtypeBl
427
+ case zRrtpe:
428
h.Rrtype = l.torc
426
- st = _EXPECT_RDATA
429
+ st = zExpectRdata
430
default:
431
t <- &Token{Error: &ParseError{f, "expecting RR type or class, not this...", l}}
432
return
433
}
431
- case _EXPECT_ANY_NOCLASS:
434
+ case zExpectAnyNoClass:
435
switch l.value {
433
- case _STRING: // TTL
434
- if ttl, ok := stringToTtl(l.token); !ok {
436
+ case zString:
437
+ ttl, ok := stringToTtl(l.token)
438
+ if !ok {
439
t <- &Token{Error: &ParseError{f, "not a TTL", l}}
440
return
437
- } else {
438
- h.Ttl = ttl
439
- // defttl = ttl // don't set the def ttl anymore
441
}
441
- st = _EXPECT_RRTYPE_BL
442
- case _RRTYPE:
442
+ h.Ttl = ttl
443
+ // defttl = ttl // don't set the def ttl anymore
444
+ st = zExpectRrtypeBl
445
+ case zRrtpe:
446
h.Rrtype = l.torc
444
- st = _EXPECT_RDATA
447
+ st = zExpectRdata
448
default:
449
t <- &Token{Error: &ParseError{f, "expecting RR type or TTL, not this...", l}}
450
return
451
}
449
- case _EXPECT_RRTYPE_BL:
450
- if l.value != _BLANK {
452
+ case zExpectRrtypeBl:
453
+ if l.value != zBlank {
454
t <- &Token{Error: &ParseError{f, "no blank before RR type", l}}
455
return
456
}
454
- st = _EXPECT_RRTYPE
455
- case _EXPECT_RRTYPE:
456
- if l.value != _RRTYPE {
457
+ st = zExpectRrtype
458
+ case zExpectRrtype:
459
+ if l.value != zRrtpe {
460
t <- &Token{Error: &ParseError{f, "unknown RR type", l}}
461
return
462
}
463
h.Rrtype = l.torc
461
- st = _EXPECT_RDATA
462
- case _EXPECT_RDATA:
464
+ st = zExpectRdata
465
+ case zExpectRdata:
466
r, e, c1 := setRR(h, c, origin, f)
467
if e != nil {
468
// If e.lex is nil than we have encounter a unknown RR type
@@ -471,7 +474,7 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
474
return
475
}
476
t <- &Token{RR: r, Comment: c1}
474
- st = _EXPECT_OWNER_DIR
477
+ st = zExpectOwnerDir
478
}
479
}
480
// If we get here, we and the h.Rrtype is still zero, we haven't parsed anything, this
@@ -535,60 +538,60 @@ func zlexer(s *scan, c chan lex) {
538
// Space directly in the beginning, handled in the grammar
539
} else if owner {
540
// If we have a string and its the first, make it an owner
538
- l.value = _OWNER
541
+ l.value = zOwner
542
l.token = string(str[:stri])
543
l.tokenUpper = strings.ToUpper(l.token)
544
l.length = stri
545
// escape $... start with a \ not a $, so this will work
546
switch l.tokenUpper {
547
case "$TTL":
545
- l.value = _DIRTTL
548
+ l.value = zDirTtl
549
case "$ORIGIN":
547
- l.value = _DIRORIGIN
550
+ l.value = zDirOrigin
551
case "$INCLUDE":
549
- l.value = _DIRINCLUDE
552
+ l.value = zDirInclude
553
case "$GENERATE":
551
- l.value = _DIRGENERATE
554
+ l.value = zDirGenerate
555
}
556
debug.Printf("[7 %+v]", l.token)
557
c <- l
558
} else {
556
- l.value = _STRING
559
+ l.value = zString
560
l.token = string(str[:stri])
561
l.tokenUpper = strings.ToUpper(l.token)
562
l.length = stri
563
if !rrtype {
564
if t, ok := StringToType[l.tokenUpper]; ok {
562
- l.value = _RRTYPE
565
+ l.value = zRrtpe
566
l.torc = t
567
rrtype = true
568
} else {
569
if strings.HasPrefix(l.tokenUpper, "TYPE") {
567
- if t, ok := typeToInt(l.token); !ok {
570
+ t, ok := typeToInt(l.token)
571
+ if !ok {
572
l.token = "unknown RR type"
573
l.err = true
574
c <- l
575
return
572
- } else {
573
- l.value = _RRTYPE
574
- l.torc = t
576
}
577
+ l.value = zRrtpe
578
+ l.torc = t
579
}
580
}
581
if t, ok := StringToClass[l.tokenUpper]; ok {
579
- l.value = _CLASS
582
+ l.value = zClass
583
l.torc = t
584
} else {
585
if strings.HasPrefix(l.tokenUpper, "CLASS") {
583
- if t, ok := classToInt(l.token); !ok {
586
+ t, ok := classToInt(l.token)
587
+ if !ok {
588
l.token = "unknown class"
589
l.err = true
590
c <- l
591
return
588
- } else {
589
- l.value = _CLASS
590
- l.torc = t
592
}
593
+ l.value = zClass
594
+ l.torc = t
595
}
596
}
597
}
@@ -598,7 +601,7 @@ func zlexer(s *scan, c chan lex) {
601
stri = 0
602
// I reverse space stuff here
603
if !space && !commt {
601
- l.value = _BLANK
604
+ l.value = zBlank
605
l.token = " "
606
l.length = 1
607
debug.Printf("[5 %+v]", l.token)
@@ -620,7 +623,7 @@ func zlexer(s *scan, c chan lex) {
623
break
624
}
625
if stri > 0 {
623
- l.value = _STRING
626
+ l.value = zString
627
l.token = string(str[:stri])
628
l.length = stri
629
debug.Printf("[4 %+v]", l.token)
@@ -656,7 +659,7 @@ func zlexer(s *scan, c chan lex) {
659
if brace == 0 {
660
owner = true
661
owner = true
659
- l.value = _NEWLINE
662
+ l.value = zNewline
663
l.token = "\n"
664
l.length = 1
665
l.comment = string(com[:comi])
@@ -674,14 +677,14 @@ func zlexer(s *scan, c chan lex) {
677
if brace == 0 {
678
// If there is previous text, we should output it here
679
if stri != 0 {
677
- l.value = _STRING
680
+ l.value = zString
681
l.token = string(str[:stri])
682
l.tokenUpper = strings.ToUpper(l.token)
683
684
l.length = stri
685
if !rrtype {
686
if t, ok := StringToType[l.tokenUpper]; ok {
684
- l.value = _RRTYPE
687
+ l.value = zRrtpe
688
l.torc = t
689
rrtype = true
690
}
@@ -689,7 +692,7 @@ func zlexer(s *scan, c chan lex) {
692
debug.Printf("[2 %+v]", l.token)
693
c <- l
694
}
692
- l.value = _NEWLINE
695
+ l.value = zNewline
696
l.token = "\n"
697
l.length = 1
698
debug.Printf("[1 %+v]", l.token)
@@ -733,7 +736,7 @@ func zlexer(s *scan, c chan lex) {
736
space = false
737
// send previous gathered text and the quote
738
if stri != 0 {
736
- l.value = _STRING
739
+ l.value = zString
740
l.token = string(str[:stri])
741
l.length = stri
742
@@ -743,7 +746,7 @@ func zlexer(s *scan, c chan lex) {
746
}
747
748
// send quote itself as separate token
746
- l.value = _QUOTE
749
+ l.value = zQuote
750
l.token = "\""
751
l.length = 1
752
c <- l
@@ -795,7 +798,7 @@ func zlexer(s *scan, c chan lex) {
798
// Send remainder
799
l.token = string(str[:stri])
800
l.length = stri
798
- l.value = _STRING
801
+ l.value = zString
802
debug.Printf("[%+v]", l.token)
803
c <- l
804
}
@@ -927,15 +930,15 @@ func slurpRemainder(c chan lex, f string) (*ParseError, string) {
930
l := <-c
931
com := ""
932
switch l.value {
930
- case _BLANK:
933
+ case zBlank:
934
l = <-c
935
com = l.comment
933
- if l.value != _NEWLINE && l.value != _EOF {
936
+ if l.value != zNewline && l.value != zEOF {
937
return &ParseError{f, "garbage after rdata", l}, ""
938
}
936
- case _NEWLINE:
939
+ case zNewline:
940
com = l.comment
938
- case _EOF:
941
+ case zEOF:
942
default:
943
return &ParseError{f, "garbage after rdata", l}, ""
944
}
Godeps/_workspace/src/github.com/miekg/dns/zscan_rr.go
+368
-350
@@ -19,9 +19,9 @@ type parserFunc struct {
19
}
20
21
// Parse the rdata of each rrtype.
22
-// All data from the channel c is either _STRING or _BLANK.
23
-// After the rdata there may come a _BLANK and then a _NEWLINE
24
-// or immediately a _NEWLINE. If this is not the case we flag
22
+// All data from the channel c is either zString or zBlank.
23
+// After the rdata there may come a zBlank and then a zNewline
24
+// or immediately a zNewline. If this is not the case we flag
25
// an *ParseError: garbage after rdata.
26
func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
27
parserfunc, ok := typeToparserFunc[h.Rrtype]
@@ -47,12 +47,12 @@ func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
47
// or an error
48
func endingToString(c chan lex, errstr, f string) (string, *ParseError, string) {
49
s := ""
50
- l := <-c // _STRING
51
- for l.value != _NEWLINE && l.value != _EOF {
50
+ l := <-c // zString
51
+ for l.value != zNewline && l.value != zEOF {
52
switch l.value {
53
- case _STRING:
53
+ case zString:
54
s += l.token
55
- case _BLANK: // Ok
55
+ case zBlank: // Ok
56
default:
57
return "", &ParseError{f, errstr, l}, ""
58
}
@@ -64,25 +64,43 @@ func endingToString(c chan lex, errstr, f string) (string, *ParseError, string)
64
// A remainder of the rdata with embedded spaces, return the parsed string slice (sans the spaces)
65
// or an error
66
func endingToTxtSlice(c chan lex, errstr, f string) ([]string, *ParseError, string) {
67
- // Get the remaining data until we see a NEWLINE
67
+ // Get the remaining data until we see a zNewline
68
quote := false
69
l := <-c
70
var s []string
71
- switch l.value == _QUOTE {
71
+ switch l.value == zQuote {
72
case true: // A number of quoted string
73
s = make([]string, 0)
74
empty := true
75
- for l.value != _NEWLINE && l.value != _EOF {
75
+ for l.value != zNewline && l.value != zEOF {
76
switch l.value {
77
- case _STRING:
77
+ case zString:
78
empty = false
79
+ if len(l.token) > 255 {
80
+ // split up tokens that are larger than 255 into 255-chunks
81
+ sx := []string{}
82
+ p, i := 0, 255
83
+ for {
84
+ if i <= len(l.token) {
85
+ sx = append(sx, l.token[p:i])
86
+ } else {
87
+ sx = append(sx, l.token[p:])
88
+ break
89
+
90
+ }
91
+ p, i = p+255, i+255
92
+ }
93
+ s = append(s, sx...)
94
+ break;
95
+ }
96
+
97
s = append(s, l.token)
80
- case _BLANK:
98
+ case zBlank:
99
if quote {
82
- // _BLANK can only be seen in between txt parts.
100
+ // zBlank can only be seen in between txt parts.
101
return nil, &ParseError{f, errstr, l}, ""
102
}
85
- case _QUOTE:
103
+ case zQuote:
104
if empty && quote {
105
s = append(s, "")
106
}
@@ -98,7 +116,7 @@ func endingToTxtSlice(c chan lex, errstr, f string) ([]string, *ParseError, stri
116
}
117
case false: // Unquoted text record
118
s = make([]string, 1)
101
- for l.value != _NEWLINE && l.value != _EOF {
119
+ for l.value != zNewline && l.value != zEOF {
120
s[0] += l.token
121
l = <-c
122
}
@@ -225,7 +243,7 @@ func setRP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
243
rr.Mbox = appendOrigin(rr.Mbox, o)
244
}
245
}
228
- <-c // _BLANK
246
+ <-c // zBlank
247
l = <-c
248
rr.Txt = l.token
249
if l.token == "@" {
@@ -317,8 +335,8 @@ func setHINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
335
336
l := <-c
337
rr.Cpu = l.token
320
- <-c // _BLANK
321
- l = <-c // _STRING
338
+ <-c // zBlank
339
+ l = <-c // zString
340
rr.Os = l.token
341
342
return rr, nil, ""
@@ -344,7 +362,7 @@ func setMINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
362
rr.Rmail = appendOrigin(rr.Rmail, o)
363
}
364
}
347
- <-c // _BLANK
365
+ <-c // zBlank
366
l = <-c
367
rr.Email = l.token
368
if l.token == "@" {
@@ -415,13 +433,13 @@ func setMX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
433
if l.length == 0 {
434
return rr, nil, ""
435
}
418
- if i, e := strconv.Atoi(l.token); e != nil {
436
+ i, e := strconv.Atoi(l.token)
437
+ if e != nil {
438
return nil, &ParseError{f, "bad MX Pref", l}, ""
420
- } else {
421
- rr.Preference = uint16(i)
439
}
423
- <-c // _BLANK
424
- l = <-c // _STRING
440
+ rr.Preference = uint16(i)
441
+ <-c // zBlank
442
+ l = <-c // zString
443
rr.Mx = l.token
444
if l.token == "@" {
445
rr.Mx = o
@@ -444,13 +462,13 @@ func setRT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
462
if l.length == 0 {
463
return rr, nil, ""
464
}
447
- if i, e := strconv.Atoi(l.token); e != nil {
465
+ i, e := strconv.Atoi(l.token)
466
+ if e != nil {
467
return nil, &ParseError{f, "bad RT Preference", l}, ""
449
- } else {
450
- rr.Preference = uint16(i)
468
}
452
- <-c // _BLANK
453
- l = <-c // _STRING
469
+ rr.Preference = uint16(i)
470
+ <-c // zBlank
471
+ l = <-c // zString
472
rr.Host = l.token
473
if l.token == "@" {
474
rr.Host = o
@@ -474,13 +492,13 @@ func setAFSDB(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
492
if l.length == 0 {
493
return rr, nil, ""
494
}
477
- if i, e := strconv.Atoi(l.token); e != nil {
495
+ i, e := strconv.Atoi(l.token)
496
+ if e != nil {
497
return nil, &ParseError{f, "bad AFSDB Subtype", l}, ""
479
- } else {
480
- rr.Subtype = uint16(i)
498
}
482
- <-c // _BLANK
483
- l = <-c // _STRING
499
+ rr.Subtype = uint16(i)
500
+ <-c // zBlank
501
+ l = <-c // zString
502
rr.Hostname = l.token
503
if l.token == "@" {
504
rr.Hostname = o
@@ -513,13 +531,13 @@ func setKX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
531
if l.length == 0 {
532
return rr, nil, ""
533
}
516
- if i, e := strconv.Atoi(l.token); e != nil {
534
+ i, e := strconv.Atoi(l.token)
535
+ if e != nil {
536
return nil, &ParseError{f, "bad KX Pref", l}, ""
518
- } else {
519
- rr.Preference = uint16(i)
537
}
521
- <-c // _BLANK
522
- l = <-c // _STRING
538
+ rr.Preference = uint16(i)
539
+ <-c // zBlank
540
+ l = <-c // zString
541
rr.Exchanger = l.token
542
if l.token == "@" {
543
rr.Exchanger = o
@@ -590,7 +608,7 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
608
if l.length == 0 {
609
return rr, nil, ""
610
}
593
- <-c // _BLANK
611
+ <-c // zBlank
612
if l.token == "@" {
613
rr.Ns = o
614
} else {
@@ -616,7 +634,7 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
634
rr.Mbox = appendOrigin(rr.Mbox, o)
635
}
636
}
619
- <-c // _BLANK
637
+ <-c // zBlank
638
639
var (
640
v uint32
@@ -639,16 +657,16 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
657
switch i {
658
case 0:
659
rr.Serial = v
642
- <-c // _BLANK
660
+ <-c // zBlank
661
case 1:
662
rr.Refresh = v
645
- <-c // _BLANK
663
+ <-c // zBlank
664
case 2:
665
rr.Retry = v
648
- <-c // _BLANK
666
+ <-c // zBlank
667
case 3:
668
rr.Expire = v
651
- <-c // _BLANK
669
+ <-c // zBlank
670
case 4:
671
rr.Minttl = v
672
}
@@ -664,27 +682,27 @@ func setSRV(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
682
if l.length == 0 {
683
return rr, nil, ""
684
}
667
- if i, e := strconv.Atoi(l.token); e != nil {
685
+ i, e := strconv.Atoi(l.token)
686
+ if e != nil {
687
return nil, &ParseError{f, "bad SRV Priority", l}, ""
669
- } else {
670
- rr.Priority = uint16(i)
688
}
672
- <-c // _BLANK
673
- l = <-c // _STRING
674
- if i, e := strconv.Atoi(l.token); e != nil {
689
+ rr.Priority = uint16(i)
690
+ <-c // zBlank
691
+ l = <-c // zString
692
+ i, e = strconv.Atoi(l.token)
693
+ if e != nil {
694
return nil, &ParseError{f, "bad SRV Weight", l}, ""
676
- } else {
677
- rr.Weight = uint16(i)
695
}
679
- <-c // _BLANK
680
- l = <-c // _STRING
681
- if i, e := strconv.Atoi(l.token); e != nil {
696
+ rr.Weight = uint16(i)
697
+ <-c // zBlank
698
+ l = <-c // zString
699
+ i, e = strconv.Atoi(l.token)
700
+ if e != nil {
701
return nil, &ParseError{f, "bad SRV Port", l}, ""
683
- } else {
684
- rr.Port = uint16(i)
702
}
686
- <-c // _BLANK
687
- l = <-c // _STRING
703
+ rr.Port = uint16(i)
704
+ <-c // zBlank
705
+ l = <-c // zString
706
rr.Target = l.token
707
if l.token == "@" {
708
rr.Target = o
@@ -708,77 +726,77 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
726
if l.length == 0 {
727
return rr, nil, ""
728
}
711
- if i, e := strconv.Atoi(l.token); e != nil {
729
+ i, e := strconv.Atoi(l.token)
730
+ if e != nil {
731
return nil, &ParseError{f, "bad NAPTR Order", l}, ""
713
- } else {
714
- rr.Order = uint16(i)
732
}
716
- <-c // _BLANK
717
- l = <-c // _STRING
718
- if i, e := strconv.Atoi(l.token); e != nil {
733
+ rr.Order = uint16(i)
734
+ <-c // zBlank
735
+ l = <-c // zString
736
+ i, e = strconv.Atoi(l.token)
737
+ if e != nil {
738
return nil, &ParseError{f, "bad NAPTR Preference", l}, ""
720
- } else {
721
- rr.Preference = uint16(i)
739
}
740
+ rr.Preference = uint16(i)
741
// Flags
724
- <-c // _BLANK
742
+ <-c // zBlank
743
l = <-c // _QUOTE
726
- if l.value != _QUOTE {
744
+ if l.value != zQuote {
745
return nil, &ParseError{f, "bad NAPTR Flags", l}, ""
746
}
747
l = <-c // Either String or Quote
730
- if l.value == _STRING {
748
+ if l.value == zString {
749
rr.Flags = l.token
750
l = <-c // _QUOTE
733
- if l.value != _QUOTE {
751
+ if l.value != zQuote {
752
return nil, &ParseError{f, "bad NAPTR Flags", l}, ""
753
}
736
- } else if l.value == _QUOTE {
754
+ } else if l.value == zQuote {
755
rr.Flags = ""
756
} else {
757
return nil, &ParseError{f, "bad NAPTR Flags", l}, ""
758
}
759
760
// Service
743
- <-c // _BLANK
761
+ <-c // zBlank
762
l = <-c // _QUOTE
745
- if l.value != _QUOTE {
763
+ if l.value != zQuote {
764
return nil, &ParseError{f, "bad NAPTR Service", l}, ""
765
}
766
l = <-c // Either String or Quote
749
- if l.value == _STRING {
767
+ if l.value == zString {
768
rr.Service = l.token
769
l = <-c // _QUOTE
752
- if l.value != _QUOTE {
770
+ if l.value != zQuote {
771
return nil, &ParseError{f, "bad NAPTR Service", l}, ""
772
}
755
- } else if l.value == _QUOTE {
773
+ } else if l.value == zQuote {
774
rr.Service = ""
775
} else {
776
return nil, &ParseError{f, "bad NAPTR Service", l}, ""
777
}
778
779
// Regexp
762
- <-c // _BLANK
780
+ <-c // zBlank
781
l = <-c // _QUOTE
764
- if l.value != _QUOTE {
782
+ if l.value != zQuote {
783
return nil, &ParseError{f, "bad NAPTR Regexp", l}, ""
784
}
785
l = <-c // Either String or Quote
768
- if l.value == _STRING {
786
+ if l.value == zString {
787
rr.Regexp = l.token
788
l = <-c // _QUOTE
771
- if l.value != _QUOTE {
789
+ if l.value != zQuote {
790
return nil, &ParseError{f, "bad NAPTR Regexp", l}, ""
791
}
774
- } else if l.value == _QUOTE {
792
+ } else if l.value == zQuote {
793
rr.Regexp = ""
794
} else {
795
return nil, &ParseError{f, "bad NAPTR Regexp", l}, ""
796
}
797
// After quote no space??
780
- <-c // _BLANK
781
- l = <-c // _STRING
798
+ <-c // zBlank
799
+ l = <-c // zString
800
rr.Replacement = l.token
801
if l.token == "@" {
802
rr.Replacement = o
@@ -814,7 +832,7 @@ func setTALINK(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
832
rr.PreviousName = appendOrigin(rr.PreviousName, o)
833
}
834
}
817
- <-c // _BLANK
835
+ <-c // zBlank
836
l = <-c
837
rr.NextName = l.token
838
if l.token == "@" {
@@ -849,7 +867,7 @@ func setLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
867
} else {
868
rr.Latitude = 1000 * 60 * 60 * uint32(i)
869
}
852
- <-c // _BLANK
870
+ <-c // zBlank
871
// Either number, 'N' or 'S'
872
l = <-c
873
if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok {
@@ -860,14 +878,14 @@ func setLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
878
} else {
879
rr.Latitude += 1000 * 60 * uint32(i)
880
}
863
- <-c // _BLANK
881
+ <-c // zBlank
882
l = <-c
883
if i, e := strconv.ParseFloat(l.token, 32); e != nil {
884
return nil, &ParseError{f, "bad LOC Latitude seconds", l}, ""
885
} else {
886
rr.Latitude += uint32(1000 * i)
887
}
870
- <-c // _BLANK
888
+ <-c // zBlank
889
// Either number, 'N' or 'S'
890
l = <-c
891
if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok {
@@ -878,14 +896,14 @@ func setLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
896
897
East:
898
// East
881
- <-c // _BLANK
899
+ <-c // zBlank
900
l = <-c
901
if i, e := strconv.Atoi(l.token); e != nil {
902
return nil, &ParseError{f, "bad LOC Longitude", l}, ""
903
} else {
904
rr.Longitude = 1000 * 60 * 60 * uint32(i)
905
}
888
- <-c // _BLANK
906
+ <-c // zBlank
907
// Either number, 'E' or 'W'
908
l = <-c
909
if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok {
@@ -896,14 +914,14 @@ East:
914
} else {
915
rr.Longitude += 1000 * 60 * uint32(i)
916
}
899
- <-c // _BLANK
917
+ <-c // zBlank
918
l = <-c
919
if i, e := strconv.ParseFloat(l.token, 32); e != nil {
920
return nil, &ParseError{f, "bad LOC Longitude seconds", l}, ""
921
} else {
922
rr.Longitude += uint32(1000 * i)
923
}
906
- <-c // _BLANK
924
+ <-c // zBlank
925
// Either number, 'E' or 'W'
926
l = <-c
927
if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok {
@@ -913,7 +931,7 @@ East:
931
return nil, &ParseError{f, "bad LOC Longitude East/West", l}, ""
932
933
Altitude:
916
- <-c // _BLANK
934
+ <-c // zBlank
935
l = <-c
936
if l.token[len(l.token)-1] == 'M' || l.token[len(l.token)-1] == 'm' {
937
l.token = l.token[0 : len(l.token)-1]
@@ -927,31 +945,31 @@ Altitude:
945
// And now optionally the other values
946
l = <-c
947
count := 0
930
- for l.value != _NEWLINE && l.value != _EOF {
948
+ for l.value != zNewline && l.value != zEOF {
949
switch l.value {
932
- case _STRING:
950
+ case zString:
951
switch count {
952
case 0: // Size
935
- if e, m, ok := stringToCm(l.token); !ok {
953
+ e, m, ok := stringToCm(l.token)
954
+ if !ok {
955
return nil, &ParseError{f, "bad LOC Size", l}, ""
937
- } else {
938
- rr.Size = (e & 0x0f) | (m << 4 & 0xf0)
956
}
957
+ rr.Size = (e & 0x0f) | (m << 4 & 0xf0)
958
case 1: // HorizPre
941
- if e, m, ok := stringToCm(l.token); !ok {
959
+ e, m, ok := stringToCm(l.token)
960
+ if !ok {
961
return nil, &ParseError{f, "bad LOC HorizPre", l}, ""
943
- } else {
944
- rr.HorizPre = (e & 0x0f) | (m << 4 & 0xf0)
962
}
963
+ rr.HorizPre = (e & 0x0f) | (m << 4 & 0xf0)
964
case 2: // VertPre
947
- if e, m, ok := stringToCm(l.token); !ok {
965
+ e, m, ok := stringToCm(l.token)
966
+ if !ok {
967
return nil, &ParseError{f, "bad LOC VertPre", l}, ""
949
- } else {
950
- rr.VertPre = (e & 0x0f) | (m << 4 & 0xf0)
968
}
969
+ rr.VertPre = (e & 0x0f) | (m << 4 & 0xf0)
970
}
971
count++
954
- case _BLANK:
972
+ case zBlank:
973
// Ok
974
default:
975
return nil, &ParseError{f, "bad LOC Size, HorizPre or VertPre", l}, ""
@@ -970,27 +988,27 @@ func setHIP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
988
if l.length == 0 {
989
return rr, nil, l.comment
990
}
973
- if i, e := strconv.Atoi(l.token); e != nil {
991
+ i, e := strconv.Atoi(l.token)
992
+ if e != nil {
993
return nil, &ParseError{f, "bad HIP PublicKeyAlgorithm", l}, ""
975
- } else {
976
- rr.PublicKeyAlgorithm = uint8(i)
994
}
978
- <-c // _BLANK
979
- l = <-c // _STRING
995
+ rr.PublicKeyAlgorithm = uint8(i)
996
+ <-c // zBlank
997
+ l = <-c // zString
998
rr.Hit = l.token // This can not contain spaces, see RFC 5205 Section 6.
999
rr.HitLength = uint8(len(rr.Hit)) / 2
1000
983
- <-c // _BLANK
984
- l = <-c // _STRING
1001
+ <-c // zBlank
1002
+ l = <-c // zString
1003
rr.PublicKey = l.token // This cannot contain spaces
1004
rr.PublicKeyLength = uint16(base64.StdEncoding.DecodedLen(len(rr.PublicKey)))
1005
1006
// RendezvousServers (if any)
1007
l = <-c
990
- xs := make([]string, 0)
991
- for l.value != _NEWLINE && l.value != _EOF {
1008
+ var xs []string
1009
+ for l.value != zNewline && l.value != zEOF {
1010
switch l.value {
993
- case _STRING:
1011
+ case zString:
1012
if l.token == "@" {
1013
xs = append(xs, o)
1014
continue
@@ -1003,7 +1021,7 @@ func setHIP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1021
l.token = appendOrigin(l.token, o)
1022
}
1023
xs = append(xs, l.token)
1006
- case _BLANK:
1024
+ case zBlank:
1025
// Ok
1026
default:
1027
return nil, &ParseError{f, "bad HIP RendezvousServers", l}, ""
@@ -1029,15 +1047,15 @@ func setCERT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1047
} else {
1048
rr.Type = uint16(i)
1049
}
1032
- <-c // _BLANK
1033
- l = <-c // _STRING
1034
- if i, e := strconv.Atoi(l.token); e != nil {
1050
+ <-c // zBlank
1051
+ l = <-c // zString
1052
+ i, e := strconv.Atoi(l.token)
1053
+ if e != nil {
1054
return nil, &ParseError{f, "bad CERT KeyTag", l}, ""
1036
- } else {
1037
- rr.KeyTag = uint16(i)
1055
}
1039
- <-c // _BLANK
1040
- l = <-c // _STRING
1056
+ rr.KeyTag = uint16(i)
1057
+ <-c // zBlank
1058
+ l = <-c // zString
1059
if v, ok := StringToAlgorithm[l.token]; ok {
1060
rr.Algorithm = v
1061
} else if i, e := strconv.Atoi(l.token); e != nil {
@@ -1045,9 +1063,9 @@ func setCERT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1063
} else {
1064
rr.Algorithm = uint8(i)
1065
}
1048
- s, e, c1 := endingToString(c, "bad CERT Certificate", f)
1049
- if e != nil {
1050
- return nil, e, c1
1066
+ s, e1, c1 := endingToString(c, "bad CERT Certificate", f)
1067
+ if e1 != nil {
1068
+ return nil, e1, c1
1069
}
1070
rr.Certificate = s
1071
return rr, nil, c1
@@ -1082,39 +1100,39 @@ func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1100
}
1101
if t, ok := StringToType[l.tokenUpper]; !ok {
1102
if strings.HasPrefix(l.tokenUpper, "TYPE") {
1085
- if t, ok = typeToInt(l.tokenUpper); !ok {
1103
+ t, ok = typeToInt(l.tokenUpper)
1104
+ if !ok {
1105
return nil, &ParseError{f, "bad RRSIG Typecovered", l}, ""
1087
- } else {
1088
- rr.TypeCovered = t
1106
}
1107
+ rr.TypeCovered = t
1108
} else {
1109
return nil, &ParseError{f, "bad RRSIG Typecovered", l}, ""
1110
}
1111
} else {
1112
rr.TypeCovered = t
1113
}
1096
- <-c // _BLANK
1114
+ <-c // zBlank
1115
l = <-c
1098
- if i, err := strconv.Atoi(l.token); err != nil {
1116
+ i, err := strconv.Atoi(l.token)
1117
+ if err != nil {
1118
return nil, &ParseError{f, "bad RRSIG Algorithm", l}, ""
1100
- } else {
1101
- rr.Algorithm = uint8(i)
1119
}
1103
- <-c // _BLANK
1120
+ rr.Algorithm = uint8(i)
1121
+ <-c // zBlank
1122
l = <-c
1105
- if i, err := strconv.Atoi(l.token); err != nil {
1123
+ i, err = strconv.Atoi(l.token)
1124
+ if err != nil {
1125
return nil, &ParseError{f, "bad RRSIG Labels", l}, ""
1107
- } else {
1108
- rr.Labels = uint8(i)
1126
}
1110
- <-c // _BLANK
1127
+ rr.Labels = uint8(i)
1128
+ <-c // zBlank
1129
l = <-c
1112
- if i, err := strconv.Atoi(l.token); err != nil {
1130
+ i, err = strconv.Atoi(l.token)
1131
+ if err != nil {
1132
return nil, &ParseError{f, "bad RRSIG OrigTtl", l}, ""
1114
- } else {
1115
- rr.OrigTtl = uint32(i)
1133
}
1117
- <-c // _BLANK
1134
+ rr.OrigTtl = uint32(i)
1135
+ <-c // zBlank
1136
l = <-c
1137
if i, err := StringToTime(l.token); err != nil {
1138
// Try to see if all numeric and use it as epoch
@@ -1127,7 +1145,7 @@ func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1145
} else {
1146
rr.Expiration = i
1147
}
1130
- <-c // _BLANK
1148
+ <-c // zBlank
1149
l = <-c
1150
if i, err := StringToTime(l.token); err != nil {
1151
if i, err := strconv.ParseInt(l.token, 10, 64); err == nil {
@@ -1138,14 +1156,14 @@ func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1156
} else {
1157
rr.Inception = i
1158
}
1141
- <-c // _BLANK
1159
+ <-c // zBlank
1160
l = <-c
1143
- if i, err := strconv.Atoi(l.token); err != nil {
1161
+ i, err = strconv.Atoi(l.token)
1162
+ if err != nil {
1163
return nil, &ParseError{f, "bad RRSIG KeyTag", l}, ""
1145
- } else {
1146
- rr.KeyTag = uint16(i)
1164
}
1148
- <-c // _BLANK
1165
+ rr.KeyTag = uint16(i)
1166
+ <-c // zBlank
1167
l = <-c
1168
rr.SignerName = l.token
1169
if l.token == "@" {
@@ -1194,11 +1212,11 @@ func setNSEC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1212
ok bool
1213
)
1214
l = <-c
1197
- for l.value != _NEWLINE && l.value != _EOF {
1215
+ for l.value != zNewline && l.value != zEOF {
1216
switch l.value {
1199
- case _BLANK:
1217
+ case zBlank:
1218
// Ok
1201
- case _STRING:
1219
+ case zString:
1220
if k, ok = StringToType[l.tokenUpper]; !ok {
1221
if k, ok = typeToInt(l.tokenUpper); !ok {
1222
return nil, &ParseError{f, "bad NSEC TypeBitMap", l}, ""
@@ -1221,25 +1239,25 @@ func setNSEC3(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1239
if l.length == 0 {
1240
return rr, nil, l.comment
1241
}
1224
- if i, e := strconv.Atoi(l.token); e != nil {
1242
+ i, e := strconv.Atoi(l.token)
1243
+ if e != nil {
1244
return nil, &ParseError{f, "bad NSEC3 Hash", l}, ""
1226
- } else {
1227
- rr.Hash = uint8(i)
1245
}
1229
- <-c // _BLANK
1246
+ rr.Hash = uint8(i)
1247
+ <-c // zBlank
1248
l = <-c
1231
- if i, e := strconv.Atoi(l.token); e != nil {
1249
+ i, e = strconv.Atoi(l.token)
1250
+ if e != nil {
1251
return nil, &ParseError{f, "bad NSEC3 Flags", l}, ""
1233
- } else {
1234
- rr.Flags = uint8(i)
1252
}
1236
- <-c // _BLANK
1253
+ rr.Flags = uint8(i)
1254
+ <-c // zBlank
1255
l = <-c
1238
- if i, e := strconv.Atoi(l.token); e != nil {
1256
+ i, e = strconv.Atoi(l.token)
1257
+ if e != nil {
1258
return nil, &ParseError{f, "bad NSEC3 Iterations", l}, ""
1240
- } else {
1241
- rr.Iterations = uint16(i)
1259
}
1260
+ rr.Iterations = uint16(i)
1261
<-c
1262
l = <-c
1263
if len(l.token) == 0 {
@@ -1259,11 +1277,11 @@ func setNSEC3(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1277
ok bool
1278
)
1279
l = <-c
1262
- for l.value != _NEWLINE && l.value != _EOF {
1280
+ for l.value != zNewline && l.value != zEOF {
1281
switch l.value {
1264
- case _BLANK:
1282
+ case zBlank:
1283
// Ok
1266
- case _STRING:
1284
+ case zString:
1285
if k, ok = StringToType[l.tokenUpper]; !ok {
1286
if k, ok = typeToInt(l.tokenUpper); !ok {
1287
return nil, &ParseError{f, "bad NSEC3 TypeBitMap", l}, ""
@@ -1286,25 +1304,25 @@ func setNSEC3PARAM(h RR_Header, c chan lex, o, f string) (RR, *ParseError, strin
1304
if l.length == 0 {
1305
return rr, nil, ""
1306
}
1289
- if i, e := strconv.Atoi(l.token); e != nil {
1307
+ i, e := strconv.Atoi(l.token)
1308
+ if e != nil {
1309
return nil, &ParseError{f, "bad NSEC3PARAM Hash", l}, ""
1291
- } else {
1292
- rr.Hash = uint8(i)
1310
}
1294
- <-c // _BLANK
1311
+ rr.Hash = uint8(i)
1312
+ <-c // zBlank
1313
l = <-c
1296
- if i, e := strconv.Atoi(l.token); e != nil {
1314
+ i, e = strconv.Atoi(l.token)
1315
+ if e != nil {
1316
return nil, &ParseError{f, "bad NSEC3PARAM Flags", l}, ""
1298
- } else {
1299
- rr.Flags = uint8(i)
1317
}
1301
- <-c // _BLANK
1318
+ rr.Flags = uint8(i)
1319
+ <-c // zBlank
1320
l = <-c
1303
- if i, e := strconv.Atoi(l.token); e != nil {
1321
+ i, e = strconv.Atoi(l.token)
1322
+ if e != nil {
1323
return nil, &ParseError{f, "bad NSEC3PARAM Iterations", l}, ""
1305
- } else {
1306
- rr.Iterations = uint16(i)
1324
}
1325
+ rr.Iterations = uint16(i)
1326
<-c
1327
l = <-c
1328
rr.SaltLength = uint8(len(l.token))
@@ -1336,11 +1354,11 @@ func setEUI48(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1354
addr[10] = l.token[15]
1355
addr[11] = l.token[16]
1356
1339
- if i, e := strconv.ParseUint(string(addr), 16, 48); e != nil {
1357
+ i, e := strconv.ParseUint(string(addr), 16, 48)
1358
+ if e != nil {
1359
return nil, &ParseError{f, "bad EUI48 Address", l}, ""
1341
- } else {
1342
- rr.Address = i
1360
}
1361
+ rr.Address = i
1362
return rr, nil, ""
1363
}
1364
@@ -1368,11 +1386,11 @@ func setEUI64(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1386
addr[14] = l.token[21]
1387
addr[15] = l.token[22]
1388
1371
- if i, e := strconv.ParseUint(string(addr), 16, 64); e != nil {
1389
+ i, e := strconv.ParseUint(string(addr), 16, 64)
1390
+ if e != nil {
1391
return nil, &ParseError{f, "bad EUI68 Address", l}, ""
1373
- } else {
1374
- rr.Address = uint64(i)
1392
}
1393
+ rr.Address = uint64(i)
1394
return rr, nil, ""
1395
}
1396
@@ -1389,21 +1407,21 @@ func setWKS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1407
return nil, &ParseError{f, "bad WKS Address", l}, ""
1408
}
1409
1392
- <-c // _BLANK
1410
+ <-c // zBlank
1411
l = <-c
1412
proto := "tcp"
1395
- if i, e := strconv.Atoi(l.token); e != nil {
1413
+ i, e := strconv.Atoi(l.token)
1414
+ if e != nil {
1415
+ return nil, &ParseError{f, "bad WKS Protocol", l}, ""
1416
+ }
1417
+ rr.Protocol = uint8(i)
1418
+ switch rr.Protocol {
1419
+ case 17:
1420
+ proto = "udp"
1421
+ case 6:
1422
+ proto = "tcp"
1423
+ default:
1424
return nil, &ParseError{f, "bad WKS Protocol", l}, ""
1397
- } else {
1398
- rr.Protocol = uint8(i)
1399
- switch rr.Protocol {
1400
- case 17:
1401
- proto = "udp"
1402
- case 6:
1403
- proto = "tcp"
1404
- default:
1405
- return nil, &ParseError{f, "bad WKS Protocol", l}, ""
1406
- }
1425
}
1426
1427
<-c
@@ -1413,11 +1431,11 @@ func setWKS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1431
k int
1432
err error
1433
)
1416
- for l.value != _NEWLINE && l.value != _EOF {
1434
+ for l.value != zNewline && l.value != zEOF {
1435
switch l.value {
1418
- case _BLANK:
1436
+ case zBlank:
1437
// Ok
1420
- case _STRING:
1438
+ case zString:
1439
if k, err = net.LookupPort(proto, l.token); err != nil {
1440
if i, e := strconv.Atoi(l.token); e != nil { // If a number use that
1441
rr.BitMap = append(rr.BitMap, uint16(i))
@@ -1442,19 +1460,19 @@ func setSSHFP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1460
if l.length == 0 {
1461
return rr, nil, ""
1462
}
1445
- if i, e := strconv.Atoi(l.token); e != nil {
1463
+ i, e := strconv.Atoi(l.token)
1464
+ if e != nil {
1465
return nil, &ParseError{f, "bad SSHFP Algorithm", l}, ""
1447
- } else {
1448
- rr.Algorithm = uint8(i)
1466
}
1450
- <-c // _BLANK
1467
+ rr.Algorithm = uint8(i)
1468
+ <-c // zBlank
1469
l = <-c
1452
- if i, e := strconv.Atoi(l.token); e != nil {
1470
+ i, e = strconv.Atoi(l.token)
1471
+ if e != nil {
1472
return nil, &ParseError{f, "bad SSHFP Type", l}, ""
1454
- } else {
1455
- rr.Type = uint8(i)
1473
}
1457
- <-c // _BLANK
1474
+ rr.Type = uint8(i)
1475
+ <-c // zBlank
1476
l = <-c
1477
rr.FingerPrint = l.token
1478
return rr, nil, ""
@@ -1468,28 +1486,28 @@ func setDNSKEYs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, str
1486
if l.length == 0 {
1487
return rr, nil, l.comment
1488
}
1471
- if i, e := strconv.Atoi(l.token); e != nil {
1489
+ i, e := strconv.Atoi(l.token)
1490
+ if e != nil {
1491
return nil, &ParseError{f, "bad " + typ + " Flags", l}, ""
1473
- } else {
1474
- rr.Flags = uint16(i)
1492
}
1476
- <-c // _BLANK
1477
- l = <-c // _STRING
1478
- if i, e := strconv.Atoi(l.token); e != nil {
1493
+ rr.Flags = uint16(i)
1494
+ <-c // zBlank
1495
+ l = <-c // zString
1496
+ i, e = strconv.Atoi(l.token)
1497
+ if e != nil {
1498
return nil, &ParseError{f, "bad " + typ + " Protocol", l}, ""
1480
- } else {
1481
- rr.Protocol = uint8(i)
1499
}
1483
- <-c // _BLANK
1484
- l = <-c // _STRING
1485
- if i, e := strconv.Atoi(l.token); e != nil {
1500
+ rr.Protocol = uint8(i)
1501
+ <-c // zBlank
1502
+ l = <-c // zString
1503
+ i, e = strconv.Atoi(l.token)
1504
+ if e != nil {
1505
return nil, &ParseError{f, "bad " + typ + " Algorithm", l}, ""
1487
- } else {
1488
- rr.Algorithm = uint8(i)
1506
}
1490
- s, e, c1 := endingToString(c, "bad "+typ+" PublicKey", f)
1491
- if e != nil {
1492
- return nil, e, c1
1507
+ rr.Algorithm = uint8(i)
1508
+ s, e1, c1 := endingToString(c, "bad "+typ+" PublicKey", f)
1509
+ if e1 != nil {
1510
+ return nil, e1, c1
1511
}
1512
rr.PublicKey = s
1513
return rr, nil, c1
@@ -1524,28 +1542,28 @@ func setRKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1542
if l.length == 0 {
1543
return rr, nil, l.comment
1544
}
1527
- if i, e := strconv.Atoi(l.token); e != nil {
1545
+ i, e := strconv.Atoi(l.token)
1546
+ if e != nil {
1547
return nil, &ParseError{f, "bad RKEY Flags", l}, ""
1529
- } else {
1530
- rr.Flags = uint16(i)
1548
}
1532
- <-c // _BLANK
1533
- l = <-c // _STRING
1534
- if i, e := strconv.Atoi(l.token); e != nil {
1549
+ rr.Flags = uint16(i)
1550
+ <-c // zBlank
1551
+ l = <-c // zString
1552
+ i, e = strconv.Atoi(l.token)
1553
+ if e != nil {
1554
return nil, &ParseError{f, "bad RKEY Protocol", l}, ""
1536
- } else {
1537
- rr.Protocol = uint8(i)
1555
}
1539
- <-c // _BLANK
1540
- l = <-c // _STRING
1541
- if i, e := strconv.Atoi(l.token); e != nil {
1556
+ rr.Protocol = uint8(i)
1557
+ <-c // zBlank
1558
+ l = <-c // zString
1559
+ i, e = strconv.Atoi(l.token)
1560
+ if e != nil {
1561
return nil, &ParseError{f, "bad RKEY Algorithm", l}, ""
1543
- } else {
1544
- rr.Algorithm = uint8(i)
1562
}
1546
- s, e, c1 := endingToString(c, "bad RKEY PublicKey", f)
1547
- if e != nil {
1548
- return nil, e, c1
1563
+ rr.Algorithm = uint8(i)
1564
+ s, e1, c1 := endingToString(c, "bad RKEY PublicKey", f)
1565
+ if e1 != nil {
1566
+ return nil, e1, c1
1567
}
1568
rr.PublicKey = s
1569
return rr, nil, c1
@@ -1580,15 +1598,15 @@ func setNSAP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1598
if l.length == 0 {
1599
return rr, nil, l.comment
1600
}
1583
- if i, e := strconv.Atoi(l.token); e != nil {
1601
+ i, e := strconv.Atoi(l.token)
1602
+ if e != nil {
1603
return nil, &ParseError{f, "bad NSAP Length", l}, ""
1585
- } else {
1586
- rr.Length = uint8(i)
1604
}
1588
- <-c // _BLANK
1589
- s, e, c1 := endingToString(c, "bad NSAP Nsap", f)
1605
+ rr.Length = uint8(i)
1606
+ <-c // zBlank
1607
+ s, e1, c1 := endingToString(c, "bad NSAP Nsap", f)
1608
if e != nil {
1591
- return nil, e, c1
1609
+ return nil, e1, c1
1610
}
1611
rr.Nsap = s
1612
return rr, nil, c1
@@ -1601,25 +1619,25 @@ func setGPOS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1619
if l.length == 0 {
1620
return rr, nil, ""
1621
}
1604
- if _, e := strconv.ParseFloat(l.token, 64); e != nil {
1622
+ _, e := strconv.ParseFloat(l.token, 64)
1623
+ if e != nil {
1624
return nil, &ParseError{f, "bad GPOS Longitude", l}, ""
1606
- } else {
1607
- rr.Longitude = l.token
1625
}
1609
- <-c // _BLANK
1626
+ rr.Longitude = l.token
1627
+ <-c // zBlank
1628
l = <-c
1611
- if _, e := strconv.ParseFloat(l.token, 64); e != nil {
1629
+ _, e = strconv.ParseFloat(l.token, 64)
1630
+ if e != nil {
1631
return nil, &ParseError{f, "bad GPOS Latitude", l}, ""
1613
- } else {
1614
- rr.Latitude = l.token
1632
}
1616
- <-c // _BLANK
1633
+ rr.Latitude = l.token
1634
+ <-c // zBlank
1635
l = <-c
1618
- if _, e := strconv.ParseFloat(l.token, 64); e != nil {
1636
+ _, e = strconv.ParseFloat(l.token, 64)
1637
+ if e != nil {
1638
return nil, &ParseError{f, "bad GPOS Altitude", l}, ""
1620
- } else {
1621
- rr.Altitude = l.token
1639
}
1640
+ rr.Altitude = l.token
1641
return rr, nil, ""
1642
}
1643
@@ -1630,32 +1648,32 @@ func setDSs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, string)
1648
if l.length == 0 {
1649
return rr, nil, l.comment
1650
}
1633
- if i, e := strconv.Atoi(l.token); e != nil {
1651
+ i, e := strconv.Atoi(l.token)
1652
+ if e != nil {
1653
return nil, &ParseError{f, "bad " + typ + " KeyTag", l}, ""
1635
- } else {
1636
- rr.KeyTag = uint16(i)
1654
}
1638
- <-c // _BLANK
1655
+ rr.KeyTag = uint16(i)
1656
+ <-c // zBlank
1657
l = <-c
1658
if i, e := strconv.Atoi(l.token); e != nil {
1641
- if i, ok := StringToAlgorithm[l.tokenUpper]; !ok {
1659
+ i, ok := StringToAlgorithm[l.tokenUpper]
1660
+ if !ok {
1661
return nil, &ParseError{f, "bad " + typ + " Algorithm", l}, ""
1643
- } else {
1644
- rr.Algorithm = i
1662
}
1663
+ rr.Algorithm = i
1664
} else {
1665
rr.Algorithm = uint8(i)
1666
}
1649
- <-c // _BLANK
1667
+ <-c // zBlank
1668
l = <-c
1651
- if i, e := strconv.Atoi(l.token); e != nil {
1669
+ i, e = strconv.Atoi(l.token)
1670
+ if e != nil {
1671
return nil, &ParseError{f, "bad " + typ + " DigestType", l}, ""
1653
- } else {
1654
- rr.DigestType = uint8(i)
1672
}
1656
- s, e, c1 := endingToString(c, "bad "+typ+" Digest", f)
1657
- if e != nil {
1658
- return nil, e, c1
1673
+ rr.DigestType = uint8(i)
1674
+ s, e1, c1 := endingToString(c, "bad "+typ+" Digest", f)
1675
+ if e1 != nil {
1676
+ return nil, e1, c1
1677
}
1678
rr.Digest = s
1679
return rr, nil, c1
@@ -1675,7 +1693,7 @@ func setDLV(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1693
}
1694
1695
func setCDS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1678
- r, e, s := setDSs(h, c, o, f, "DLV")
1696
+ r, e, s := setDSs(h, c, o, f, "CDS")
1697
if r != nil {
1698
return &CDS{*r.(*DS)}, e, s
1699
}
@@ -1689,32 +1707,32 @@ func setTA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1707
if l.length == 0 {
1708
return rr, nil, l.comment
1709
}
1692
- if i, e := strconv.Atoi(l.token); e != nil {
1710
+ i, e := strconv.Atoi(l.token)
1711
+ if e != nil {
1712
return nil, &ParseError{f, "bad TA KeyTag", l}, ""
1694
- } else {
1695
- rr.KeyTag = uint16(i)
1713
}
1697
- <-c // _BLANK
1714
+ rr.KeyTag = uint16(i)
1715
+ <-c // zBlank
1716
l = <-c
1717
if i, e := strconv.Atoi(l.token); e != nil {
1700
- if i, ok := StringToAlgorithm[l.tokenUpper]; !ok {
1718
+ i, ok := StringToAlgorithm[l.tokenUpper]
1719
+ if !ok {
1720
return nil, &ParseError{f, "bad TA Algorithm", l}, ""
1702
- } else {
1703
- rr.Algorithm = i
1721
}
1722
+ rr.Algorithm = i
1723
} else {
1724
rr.Algorithm = uint8(i)
1725
}
1708
- <-c // _BLANK
1726
+ <-c // zBlank
1727
l = <-c
1710
- if i, e := strconv.Atoi(l.token); e != nil {
1728
+ i, e = strconv.Atoi(l.token)
1729
+ if e != nil {
1730
return nil, &ParseError{f, "bad TA DigestType", l}, ""
1712
- } else {
1713
- rr.DigestType = uint8(i)
1731
}
1732
+ rr.DigestType = uint8(i)
1733
s, e, c1 := endingToString(c, "bad TA Digest", f)
1734
if e != nil {
1717
- return nil, e, c1
1735
+ return nil, e.(*ParseError), c1
1736
}
1737
rr.Digest = s
1738
return rr, nil, c1
@@ -1727,28 +1745,28 @@ func setTLSA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1745
if l.length == 0 {
1746
return rr, nil, l.comment
1747
}
1730
- if i, e := strconv.Atoi(l.token); e != nil {
1748
+ i, e := strconv.Atoi(l.token)
1749
+ if e != nil {
1750
return nil, &ParseError{f, "bad TLSA Usage", l}, ""
1732
- } else {
1733
- rr.Usage = uint8(i)
1751
}
1735
- <-c // _BLANK
1752
+ rr.Usage = uint8(i)
1753
+ <-c // zBlank
1754
l = <-c
1737
- if i, e := strconv.Atoi(l.token); e != nil {
1755
+ i, e = strconv.Atoi(l.token)
1756
+ if e != nil {
1757
return nil, &ParseError{f, "bad TLSA Selector", l}, ""
1739
- } else {
1740
- rr.Selector = uint8(i)
1758
}
1742
- <-c // _BLANK
1759
+ rr.Selector = uint8(i)
1760
+ <-c // zBlank
1761
l = <-c
1744
- if i, e := strconv.Atoi(l.token); e != nil {
1762
+ i, e = strconv.Atoi(l.token)
1763
+ if e != nil {
1764
return nil, &ParseError{f, "bad TLSA MatchingType", l}, ""
1746
- } else {
1747
- rr.MatchingType = uint8(i)
1765
}
1766
+ rr.MatchingType = uint8(i)
1767
s, e, c1 := endingToString(c, "bad TLSA Certificate", f)
1768
if e != nil {
1751
- return nil, e, c1
1769
+ return nil, e.(*ParseError), c1
1770
}
1771
rr.Certificate = s
1772
return rr, nil, c1
@@ -1761,7 +1779,7 @@ func setRFC3597(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string)
1779
if l.token != "\\#" {
1780
return nil, &ParseError{f, "bad RFC3597 Rdata", l}, ""
1781
}
1764
- <-c // _BLANK
1782
+ <-c // zBlank
1783
l = <-c
1784
rdlength, e := strconv.Atoi(l.token)
1785
if e != nil {
@@ -1795,7 +1813,7 @@ func setTXT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1813
rr := new(TXT)
1814
rr.Hdr = h
1815
1798
- // No _BLANK reading here, because this is all rdata is TXT
1816
+ // no zBlank reading here, because all this rdata is TXT
1817
s, e, c1 := endingToTxtSlice(c, "bad TXT Txt", f)
1818
if e != nil {
1819
return nil, e, ""
@@ -1825,23 +1843,23 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1843
if l.length == 0 {
1844
return rr, nil, l.comment
1845
}
1828
- if i, e := strconv.Atoi(l.token); e != nil {
1846
+ i, e := strconv.Atoi(l.token)
1847
+ if e != nil {
1848
return nil, &ParseError{f, "bad URI Priority", l}, ""
1830
- } else {
1831
- rr.Priority = uint16(i)
1849
}
1833
- <-c // _BLANK
1850
+ rr.Priority = uint16(i)
1851
+ <-c // zBlank
1852
l = <-c
1835
- if i, e := strconv.Atoi(l.token); e != nil {
1853
+ i, e = strconv.Atoi(l.token)
1854
+ if e != nil {
1855
return nil, &ParseError{f, "bad URI Weight", l}, ""
1837
- } else {
1838
- rr.Weight = uint16(i)
1856
}
1857
+ rr.Weight = uint16(i)
1858
1841
- <-c // _BLANK
1859
+ <-c // zBlank
1860
s, e, c1 := endingToTxtSlice(c, "bad URI Target", f)
1861
if e != nil {
1844
- return nil, e, ""
1862
+ return nil, e.(*ParseError), ""
1863
}
1864
rr.Target = s
1865
return rr, nil, c1
@@ -1868,13 +1886,13 @@ func setNID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1886
if l.length == 0 {
1887
return rr, nil, ""
1888
}
1871
- if i, e := strconv.Atoi(l.token); e != nil {
1889
+ i, e := strconv.Atoi(l.token)
1890
+ if e != nil {
1891
return nil, &ParseError{f, "bad NID Preference", l}, ""
1873
- } else {
1874
- rr.Preference = uint16(i)
1892
}
1876
- <-c // _BLANK
1877
- l = <-c // _STRING
1893
+ rr.Preference = uint16(i)
1894
+ <-c // zBlank
1895
+ l = <-c // zString
1896
u, err := stringToNodeID(l)
1897
if err != nil {
1898
return nil, err, ""
@@ -1891,13 +1909,13 @@ func setL32(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1909
if l.length == 0 {
1910
return rr, nil, ""
1911
}
1894
- if i, e := strconv.Atoi(l.token); e != nil {
1912
+ i, e := strconv.Atoi(l.token)
1913
+ if e != nil {
1914
return nil, &ParseError{f, "bad L32 Preference", l}, ""
1896
- } else {
1897
- rr.Preference = uint16(i)
1915
}
1899
- <-c // _BLANK
1900
- l = <-c // _STRING
1916
+ rr.Preference = uint16(i)
1917
+ <-c // zBlank
1918
+ l = <-c // zString
1919
rr.Locator32 = net.ParseIP(l.token)
1920
if rr.Locator32 == nil {
1921
return nil, &ParseError{f, "bad L32 Locator", l}, ""
@@ -1913,13 +1931,13 @@ func setLP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1931
if l.length == 0 {
1932
return rr, nil, ""
1933
}
1916
- if i, e := strconv.Atoi(l.token); e != nil {
1934
+ i, e := strconv.Atoi(l.token)
1935
+ if e != nil {
1936
return nil, &ParseError{f, "bad LP Preference", l}, ""
1918
- } else {
1919
- rr.Preference = uint16(i)
1937
}
1921
- <-c // _BLANK
1922
- l = <-c // _STRING
1938
+ rr.Preference = uint16(i)
1939
+ <-c // zBlank
1940
+ l = <-c // zString
1941
rr.Fqdn = l.token
1942
if l.length == 0 {
1943
return rr, nil, ""
@@ -1946,13 +1964,13 @@ func setL64(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1964
if l.length == 0 {
1965
return rr, nil, ""
1966
}
1949
- if i, e := strconv.Atoi(l.token); e != nil {
1967
+ i, e := strconv.Atoi(l.token)
1968
+ if e != nil {
1969
return nil, &ParseError{f, "bad L64 Preference", l}, ""
1951
- } else {
1952
- rr.Preference = uint16(i)
1970
}
1954
- <-c // _BLANK
1955
- l = <-c // _STRING
1971
+ rr.Preference = uint16(i)
1972
+ <-c // zBlank
1973
+ l = <-c // zString
1974
u, err := stringToNodeID(l)
1975
if err != nil {
1976
return nil, err, ""
@@ -1968,11 +1986,11 @@ func setUID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
1986
if l.length == 0 {
1987
return rr, nil, ""
1988
}
1971
- if i, e := strconv.Atoi(l.token); e != nil {
1989
+ i, e := strconv.Atoi(l.token)
1990
+ if e != nil {
1991
return nil, &ParseError{f, "bad UID Uid", l}, ""
1973
- } else {
1974
- rr.Uid = uint32(i)
1992
}
1993
+ rr.Uid = uint32(i)
1994
return rr, nil, ""
1995
}
1996
@@ -1983,11 +2001,11 @@ func setGID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
2001
if l.length == 0 {
2002
return rr, nil, ""
2003
}
1986
- if i, e := strconv.Atoi(l.token); e != nil {
2004
+ i, e := strconv.Atoi(l.token)
2005
+ if e != nil {
2006
return nil, &ParseError{f, "bad GID Gid", l}, ""
1988
- } else {
1989
- rr.Gid = uint32(i)
2007
}
2008
+ rr.Gid = uint32(i)
2009
return rr, nil, ""
2010
}
2011
@@ -2010,13 +2028,13 @@ func setPX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
2028
if l.length == 0 {
2029
return rr, nil, ""
2030
}
2013
- if i, e := strconv.Atoi(l.token); e != nil {
2031
+ i, e := strconv.Atoi(l.token)
2032
+ if e != nil {
2033
return nil, &ParseError{f, "bad PX Preference", l}, ""
2015
- } else {
2016
- rr.Preference = uint16(i)
2034
}
2018
- <-c // _BLANK
2019
- l = <-c // _STRING
2035
+ rr.Preference = uint16(i)
2036
+ <-c // zBlank
2037
+ l = <-c // zString
2038
rr.Map822 = l.token
2039
if l.length == 0 {
2040
return rr, nil, ""
@@ -2032,8 +2050,8 @@ func setPX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
2050
if rr.Map822[l.length-1] != '.' {
2051
rr.Map822 = appendOrigin(rr.Map822, o)
2052
}
2035
- <-c // _BLANK
2036
- l = <-c // _STRING
2053
+ <-c // zBlank
2054
+ l = <-c // zString
2055
rr.Mapx400 = l.token
2056
if l.token == "@" {
2057
rr.Mapx400 = o
@@ -2056,28 +2074,28 @@ func setIPSECKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string)
2074
if l.length == 0 {
2075
return rr, nil, l.comment
2076
}
2059
- if i, err := strconv.Atoi(l.token); err != nil {
2077
+ i, err := strconv.Atoi(l.token)
2078
+ if err != nil {
2079
return nil, &ParseError{f, "bad IPSECKEY Precedence", l}, ""
2061
- } else {
2062
- rr.Precedence = uint8(i)
2080
}
2064
- <-c // _BLANK
2081
+ rr.Precedence = uint8(i)
2082
+ <-c // zBlank
2083
l = <-c
2066
- if i, err := strconv.Atoi(l.token); err != nil {
2084
+ i, err = strconv.Atoi(l.token)
2085
+ if err != nil {
2086
return nil, &ParseError{f, "bad IPSECKEY GatewayType", l}, ""
2068
- } else {
2069
- rr.GatewayType = uint8(i)
2087
}
2071
- <-c // _BLANK
2088
+ rr.GatewayType = uint8(i)
2089
+ <-c // zBlank
2090
l = <-c
2073
- if i, err := strconv.Atoi(l.token); err != nil {
2091
+ i, err = strconv.Atoi(l.token)
2092
+ if err != nil {
2093
return nil, &ParseError{f, "bad IPSECKEY Algorithm", l}, ""
2075
- } else {
2076
- rr.Algorithm = uint8(i)
2094
}
2095
+ rr.Algorithm = uint8(i)
2096
2097
// Now according to GatewayType we can have different elements here
2080
- <-c // _BLANK
2098
+ <-c // zBlank
2099
l = <-c
2100
switch rr.GatewayType {
2101
case 0: