Merge branch 'master' of github.com:miekg/dns

This commit is contained in:
Miek Gieben 2012-12-14 12:35:25 +01:00
commit 4a951fc1f8
4 changed files with 83 additions and 49 deletions

View File

@ -192,10 +192,6 @@ Flags:
m.Question[0] = dns.Question{dns.Fqdn(v), qtype, qclass} m.Question[0] = dns.Question{dns.Fqdn(v), qtype, qclass}
m.Id = dns.Id() m.Id = dns.Id()
if *query {
fmt.Printf("%s", m.String())
fmt.Printf("\n;; size: %d bytes\n\n", m.Len())
}
// Add tsig // Add tsig
if *tsig != "" { if *tsig != "" {
if algo, name, secret, ok := tsigKeyParse(*tsig); ok { if algo, name, secret, ok := tsigKeyParse(*tsig); ok {
@ -206,6 +202,10 @@ Flags:
return return
} }
} }
if *query {
fmt.Printf("%s", m.String())
fmt.Printf("\n;; size: %d bytes\n\n", m.Len())
}
if qtype == dns.TypeAXFR { if qtype == dns.TypeAXFR {
c.Net = "tcp" c.Net = "tcp"
doXfr(c, m, nameserver) doXfr(c, m, nameserver)
@ -269,7 +269,7 @@ func tsigKeyParse(s string) (algo, name, secret string, ok bool) {
case 3: case 3:
switch s1[0] { switch s1[0] {
case "hmac-md5": case "hmac-md5":
return "hmac-md5.sig-alg.reg.int.", s1[0], s1[1], true return "hmac-md5.sig-alg.reg.int.", s1[1], s1[2], true
case "hmac-sha1": case "hmac-sha1":
return "hmac-sha1.", s1[1], s1[2], true return "hmac-sha1.", s1[1], s1[2], true
case "hmac-sha256": case "hmac-sha256":

View File

@ -414,6 +414,47 @@ func TestZoneParsing(t *testing.T) {
t.Logf("%d RRs parsed in %.2f s (%.2f RR/s)", i, float32(delta)/1e9, float32(i)/(float32(delta)/1e9)) t.Logf("%d RRs parsed in %.2f s (%.2f RR/s)", i, float32(delta)/1e9, float32(i)/(float32(delta)/1e9))
} }
func ExampleZone() {
zone := `$ORIGIN .
$TTL 3600 ; 1 hour
name IN SOA a6.nstld.com. hostmaster.nic.name. (
203362132 ; serial
300 ; refresh (5 minutes)
300 ; retry (5 minutes)
1209600 ; expire (2 weeks)
300 ; minimum (5 minutes)
)
$TTL 10800 ; 3 hours
name. 10800 IN NS name.
IN NS g6.nstld.com.
7200 NS h6.nstld.com.
3600 IN NS j6.nstld.com.
IN 3600 NS k6.nstld.com.
NS l6.nstld.com.
NS a6.nstld.com.
NS c6.nstld.com.
NS d6.nstld.com.
NS f6.nstld.com.
NS m6.nstld.com.
(
NS m7.nstld.com.
)
$ORIGIN name.
0-0onlus NS ns7.ehiweb.it.
NS ns8.ehiweb.it.
0-g MX 10 mx01.nic
MX 10 mx02.nic
MX 10 mx03.nic
MX 10 mx04.nic
$ORIGIN 0-g.name
moutamassey NS ns01.yahoodomains.jp.
NS ns02.yahoodomains.jp.
`
to := ParseZone(strings.NewReader(zone), "", "testzone")
for x := range to {
fmt.Printf("%s\n", x.RR)
}
// Output:
// name. 3600 IN SOA a6.nstld.com. hostmaster.nic.name. 203362132 300 300 1209600 300 // name. 3600 IN SOA a6.nstld.com. hostmaster.nic.name. 203362132 300 300 1209600 300
// name. 10800 IN NS name. // name. 10800 IN NS name.
// name. 10800 IN NS g6.nstld.com. // name. 10800 IN NS g6.nstld.com.
@ -426,56 +467,17 @@ func TestZoneParsing(t *testing.T) {
// name. 10800 IN NS d6.nstld.com. // name. 10800 IN NS d6.nstld.com.
// name. 10800 IN NS f6.nstld.com. // name. 10800 IN NS f6.nstld.com.
// name. 10800 IN NS m6.nstld.com. // name. 10800 IN NS m6.nstld.com.
// name. 10800 IN NS m7.nstld.com.
// 0-0onlus.name. 10800 IN NS ns7.ehiweb.it. // 0-0onlus.name. 10800 IN NS ns7.ehiweb.it.
// 0-0onlus.name. 10800 IN NS ns8.ehiweb.it. // 0-0onlus.name. 10800 IN NS ns8.ehiweb.it.
// 0-g.name. 10800 IN MX 10 mx01.nic.name. // 0-g.name. 10800 IN MX 10 mx01.nic.name.
// 0-g.name. 10800 IN MX 10 mx02.nic.name. // 0-g.name. 10800 IN MX 10 mx02.nic.name.
// 0-g.name. 10800 IN MX 10 mx03.nic.name. // 0-g.name. 10800 IN MX 10 mx03.nic.name.
// 0-g.name. 10800 IN MX 10 mx04.nic.name. // 0-g.name. 10800 IN MX 10 mx04.nic.name.
// 0-g.name. 10800 IN TXT "10 mx\"04.nic"
// moutamassey.0-g.name.name. 10800 IN NS ns01.yahoodomains.jp. // moutamassey.0-g.name.name. 10800 IN NS ns01.yahoodomains.jp.
// moutamassey.0-g.name.name. 10800 IN NS ns02.yahoodomains.jp. // moutamassey.0-g.name.name. 10800 IN NS ns02.yahoodomains.jp.
func ExampleZone() {
zone := `$ORIGIN .
$TTL 3600 ; 1 hour
name IN SOA a6.nstld.com. hostmaster.nic.name. (
203362132 ; serial
300 ; refresh (5 minutes)
300 ; retry (5 minutes)
1209600 ; expire (2 weeks)
300 ; minimum (5 minutes)
)
$TTL 10800 ; 3 hours
@ 10800 IN NS @
IN NS g6.nstld.com.
7200 NS h6.nstld.com.
3600 IN NS j6.nstld.com.
IN 3600 NS k6.nstld.com.
NS l6.nstld.com.
NS a6.nstld.com.
NS c6.nstld.com.
NS d6.nstld.com.
NS f6.nstld.com.
NS m6.nstld.com.
$ORIGIN name.
0-0onlus NS ns7.ehiweb.it.
NS ns8.ehiweb.it.
0-g MX 10 mx01.nic
MX 10 mx02.nic
MX 10 mx03.nic
MX 10 mx04.nic
TXT "10 mx\"04.nic"
$ORIGIN 0-g.name
moutamassey NS ns01.yahoodomains.jp.
NS ns02.yahoodomains.jp.
`
to := ParseZone(strings.NewReader(zone), "", "testzone")
for x := range to {
fmt.Printf("%s\n", x.RR)
}
} }
// www.example.com. 3600 IN HIP 2 200100107B1A74DF365639CC39F1D578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs.example.com.
func ExampleHIP() { func ExampleHIP() {
h := `www.example.com IN HIP ( 2 200100107B1A74DF365639CC39F1D578 h := `www.example.com IN HIP ( 2 200100107B1A74DF365639CC39F1D578
AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p
@ -485,14 +487,17 @@ b1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D
if hip, err := NewRR(h); err == nil { if hip, err := NewRR(h); err == nil {
fmt.Printf("%s\n", hip.String()) fmt.Printf("%s\n", hip.String())
} }
// Output:
// www.example.com. 3600 IN HIP 2 200100107B1A74DF365639CC39F1D578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs.example.com.
} }
// example.com. 1000 IN SOA master.example.com. admin.example.com. 1 4294967294 4294967293 4294967295 100
func ExampleSOA() { func ExampleSOA() {
s := "example.com. 1000 SOA master.example.com. admin.example.com. 1 4294967294 4294967293 4294967295 100" s := "example.com. 1000 SOA master.example.com. admin.example.com. 1 4294967294 4294967293 4294967295 100"
if soa, err := NewRR(s); err == nil { if soa, err := NewRR(s); err == nil {
fmt.Printf("%s\n", soa.String()) fmt.Printf("%s\n", soa.String())
} }
// Output:
// example.com. 1000 IN SOA master.example.com. admin.example.com. 1 4294967294 4294967293 4294967295 100
} }
func TestLineNumberError(t *testing.T) { func TestLineNumberError(t *testing.T) {
@ -582,6 +587,16 @@ func TestEmpty(t *testing.T) {
} }
} }
func ExampleGenerate() {
// From the manual: http://www.bind9.net/manual/bind/9.3.2/Bv9ARM.ch06.html#id2566761
zone := "$GENERATE 1-2 0 NS SERVER$.EXAMPLE.\n$GENERATE 1-8 $ CNAME $.0"
to := ParseZone(strings.NewReader(zone), "0.0.192.IN-ADDR.ARPA.", "")
for x := range to {
if x.Error == nil {
fmt.Printf("%s\n", x.RR.String())
}
}
// Output:
// 0.0.0.192.IN-ADDR.ARPA. 3600 IN NS SERVER1.EXAMPLE. // 0.0.0.192.IN-ADDR.ARPA. 3600 IN NS SERVER1.EXAMPLE.
// 0.0.0.192.IN-ADDR.ARPA. 3600 IN NS SERVER2.EXAMPLE. // 0.0.0.192.IN-ADDR.ARPA. 3600 IN NS SERVER2.EXAMPLE.
// 1.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 1.0.0.0.192.IN-ADDR.ARPA. // 1.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 1.0.0.0.192.IN-ADDR.ARPA.
@ -592,15 +607,6 @@ func TestEmpty(t *testing.T) {
// 6.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 6.0.0.0.192.IN-ADDR.ARPA. // 6.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 6.0.0.0.192.IN-ADDR.ARPA.
// 7.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 7.0.0.0.192.IN-ADDR.ARPA. // 7.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 7.0.0.0.192.IN-ADDR.ARPA.
// 8.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 8.0.0.0.192.IN-ADDR.ARPA. // 8.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 8.0.0.0.192.IN-ADDR.ARPA.
func ExampleGenerate() {
// From the manual: http://www.bind9.net/manual/bind/9.3.2/Bv9ARM.ch06.html#id2566761
zone := "$GENERATE 1-2 0 NS SERVER$.EXAMPLE.\n$GENERATE 1-8 $ CNAME $.0"
to := ParseZone(strings.NewReader(zone), "0.0.192.IN-ADDR.ARPA.", "")
for x := range to {
if x.Error == nil {
fmt.Printf("%s\n", x.RR.String())
}
}
} }
func TestSRVPacking(t *testing.T) { func TestSRVPacking(t *testing.T) {

View File

@ -125,7 +125,7 @@ type tsigWireFmt struct {
Ttl uint32 Ttl uint32
// Rdata of the TSIG // Rdata of the TSIG
Algorithm string `dns:"domain-name"` Algorithm string `dns:"domain-name"`
TimeSigned uint64 TimeSigned uint64 `dns:"uint48"`
Fudge uint16 Fudge uint16
// MACSize, MAC and OrigId excluded // MACSize, MAC and OrigId excluded
Error uint16 Error uint16
@ -142,7 +142,7 @@ type macWireFmt struct {
// 3.3. Time values used in TSIG calculations // 3.3. Time values used in TSIG calculations
type timerWireFmt struct { type timerWireFmt struct {
TimeSigned uint64 TimeSigned uint64 `dns:"uint48"`
Fudge uint16 Fudge uint16
} }
@ -220,7 +220,6 @@ func TsigVerify(msg []byte, secret, requestMAC string, timersOnly bool) error {
} }
buf := tsigBuffer(stripped, tsig, requestMAC, timersOnly) buf := tsigBuffer(stripped, tsig, requestMAC, timersOnly)
ti := uint64(time.Now().Unix()) - tsig.TimeSigned ti := uint64(time.Now().Unix()) - tsig.TimeSigned
if uint64(tsig.Fudge) < ti { if uint64(tsig.Fudge) < ti {
return ErrTime return ErrTime

View File

@ -227,7 +227,8 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
return return
} else { } else {
h.Ttl = ttl h.Ttl = ttl
defttl = ttl // Don't about the defttl, we should take the $TTL value
// defttl = ttl
} }
st = _EXPECT_ANY_NOTTL_BL st = _EXPECT_ANY_NOTTL_BL
@ -246,8 +247,32 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
t <- Token{Error: &ParseError{f, "expecting $INCLUDE value, not this...", l}} t <- Token{Error: &ParseError{f, "expecting $INCLUDE value, not this...", l}}
return return
} }
if e := slurpRemainder(c, f); e != nil { neworigin := origin // There may be optionally a new origin set after the filename, if not use current one
t <- Token{Error: e} l := <-c
switch l.value {
case _BLANK:
l := <-c
if l.value == _STRING {
if _, _, ok := IsDomainName(l.token); !ok {
t <- Token{Error: &ParseError{f, "bad origin name", l}}
return
}
// a new origin is specified.
if !IsFqdn(l.token) {
if origin != "." { // Prevent .. endings
neworigin = l.token + "." + origin
} else {
neworigin = l.token + origin
}
} else {
neworigin = l.token
}
}
case _NEWLINE, _EOF:
// Ok
default:
t <- Token{Error: &ParseError{f, "garbage after $INCLUDE", l}}
return
} }
// Start with the new file // Start with the new file
r1, e1 := os.Open(l.token) r1, e1 := os.Open(l.token)
@ -259,7 +284,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
t <- Token{Error: &ParseError{f, "too deeply nested $INCLUDE", l}} t <- Token{Error: &ParseError{f, "too deeply nested $INCLUDE", l}}
return return
} }
parseZone(r1, l.token, origin, t, include+1) parseZone(r1, l.token, neworigin, t, include+1)
st = _EXPECT_OWNER_DIR st = _EXPECT_OWNER_DIR
case _EXPECT_DIRTTL_BL: case _EXPECT_DIRTTL_BL:
if l.value != _BLANK { if l.value != _BLANK {
@ -297,6 +322,10 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
if e := slurpRemainder(c, f); e != nil { if e := slurpRemainder(c, f); e != nil {
t <- Token{Error: e} t <- Token{Error: e}
} }
if _, _, ok := IsDomainName(l.token); !ok {
t <- Token{Error: &ParseError{f, "bad origin name", l}}
return
}
if !IsFqdn(l.token) { if !IsFqdn(l.token) {
if origin != "." { // Prevent .. endings if origin != "." { // Prevent .. endings
origin = l.token + "." + origin origin = l.token + "." + origin
@ -343,7 +372,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
return return
} else { } else {
h.Ttl = ttl h.Ttl = ttl
defttl = ttl // defttl = ttl // don't set the defttl here
} }
st = _EXPECT_ANY_NOTTL_BL st = _EXPECT_ANY_NOTTL_BL
default: default:
@ -382,7 +411,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
return return
} else { } else {
h.Ttl = ttl h.Ttl = ttl
defttl = ttl // defttl = ttl // don't set the def ttl anymore
} }
st = _EXPECT_RRTYPE_BL st = _EXPECT_RRTYPE_BL
case _RRTYPE: case _RRTYPE: