This commit is contained in:
Miek Gieben 2012-01-12 22:49:26 +01:00
parent 1d5e916a1e
commit 9b48d4b899
4 changed files with 89 additions and 90 deletions

View File

@ -229,7 +229,7 @@ func (c *Client) Exchange(m *Msg, a string) (r *Msg, err error) {
var n int
out, ok := m.Pack()
if !ok {
return nil, ErrPack
return nil, ErrPack
}
var in []byte
switch c.Net {
@ -238,7 +238,7 @@ func (c *Client) Exchange(m *Msg, a string) (r *Msg, err error) {
case "udp":
in = make([]byte, DefaultMsgSize)
}
//TODO(mg): look at the buffer size here
//TODO(mg): look at the buffer size here
if n, err = c.ExchangeBuffer(out, a, in); err != nil {
return nil, err
}
@ -359,7 +359,7 @@ func (w *reply) Send(m *Msg) error {
if !ok {
return ErrSecret
}
// Compressie maakt dit stuk
// Compressie maakt dit stuk
if err := TsigGenerate(m, w.Client().TsigSecret[secret], w.tsigRequestMAC, w.tsigTimersOnly); err != nil {
return err
}

View File

@ -101,7 +101,7 @@ z2.miek.nl. 86400 IN NSEC miek.nl. TXT RRSIG NSEC
$TTL 100
z3.miek.nl. IN NSEC miek.nl. TXT RRSIG NSEC`
// Need to implementen owner substitution in the lexer.
to := ParseZone(strings.NewReader(zone))
to := ParseZone(strings.NewReader(zone))
i := 0
for x := range to {
if x.Error == nil {
@ -117,10 +117,10 @@ z3.miek.nl. IN NSEC miek.nl. TXT RRSIG NSEC`
t.Fail()
}
case 2:
if x.RR.String() != "z3.miek.nl.\t100\tIN\tNSEC\tmiek.nl. TXT RRSIG NSEC" {
if x.RR.String() != "z3.miek.nl.\t100\tIN\tNSEC\tmiek.nl. TXT RRSIG NSEC" {
t.Logf("Failed to parse z3 %s", x.RR.String())
t.Fail()
}
}
}
} else {
t.Logf("Failed to parse: %v\n", x.Error)
@ -131,27 +131,26 @@ z3.miek.nl. IN NSEC miek.nl. TXT RRSIG NSEC`
}
func TestDomainName(t *testing.T) {
tests := []string{"r\\.gieben.miek.nl.", "www\\.www.miek.nl."}
dbuff := make([]byte, 40)
tests := []string{"r\\.gieben.miek.nl.", "www\\.www.miek.nl."}
dbuff := make([]byte, 40)
for _, ts := range tests {
if _, ok := PackDomainName(ts, dbuff, 0, nil, false); !ok {
t.Log("Not a valid domain name")
t.Fail()
continue
}
n, _, ok := UnpackDomainName(dbuff, 0)
if !ok {
t.Log("Failed to unpack packed domain name")
t.Fail()
continue;
}
if ts != n {
t.Logf("Must be equal: in: %s, out: %s\n", ts, n)
t.Fail()
}
}
for _, ts := range tests {
if _, ok := PackDomainName(ts, dbuff, 0, nil, false); !ok {
t.Log("Not a valid domain name")
t.Fail()
continue
}
n, _, ok := UnpackDomainName(dbuff, 0)
if !ok {
t.Log("Failed to unpack packed domain name")
t.Fail()
continue
}
if ts != n {
t.Logf("Must be equal: in: %s, out: %s\n", ts, n)
t.Fail()
}
}
}
func TestParseBrace(t *testing.T) {
@ -161,8 +160,8 @@ func TestParseBrace(t *testing.T) {
`miek.nl. IN (
3600 A 127.0.0.1)`: "miek.nl.\t3600\tIN\tA\t127.0.0.1",
"(miek.nl.) (A) (127.0.0.1)": "miek.nl.\t3600\tIN\tA\t127.0.0.1",
"miek.nl A 127.0.0.1": "miek.nl.\t3600\tIN\tA\t127.0.0.1",
"miek.nl. NS ns.miek.nl": "miek.nl.\t3600\tIN\tNS\tns.miek.nl.",
"miek.nl A 127.0.0.1": "miek.nl.\t3600\tIN\tA\t127.0.0.1",
"miek.nl. NS ns.miek.nl": "miek.nl.\t3600\tIN\tNS\tns.miek.nl.",
`(miek.nl.) (
(IN)
(AAAA)
@ -171,16 +170,16 @@ func TestParseBrace(t *testing.T) {
(IN)
(AAAA)
(::1))`: "miek.nl.\t3600\tIN\tAAAA\t::1",
`((m)(i)ek.(n)l.) (SOA) (soa.) (soa.) (
`((m)(i)ek.(n)l.) (SOA) (soa.) (soa.) (
2009032802 ; serial
21600 ; refresh (6 hours)
7(2)00 ; retry (2 hours)
604()800 ; expire (1 week)
3600 ; minimum (1 hour)
)`: "miek.nl.\t3600\tIN\tSOA\tsoa. soa. 2009032802 21600 7200 604800 3600",
"miek\\.nl. IN A 127.0.0.1": "miek\\.nl.\t3600\tIN\tA\t127.0.0.1",
"miek.nl. IN A 127.0.0.1": "miek.nl.\t3600\tIN\tA\t127.0.0.1",
"miek.nl. A 127.0.0.1": "miek.nl.\t3600\tIN\tA\t127.0.0.1",
"miek\\.nl. IN A 127.0.0.1": "miek\\.nl.\t3600\tIN\tA\t127.0.0.1",
"miek.nl. IN A 127.0.0.1": "miek.nl.\t3600\tIN\tA\t127.0.0.1",
"miek.nl. A 127.0.0.1": "miek.nl.\t3600\tIN\tA\t127.0.0.1",
`miek.nl. 86400 IN SOA elektron.atoom.net. miekg.atoom.net. (
2009032802 ; serial
21600 ; refresh (6 hours)
@ -231,7 +230,7 @@ func BenchmarkZoneParsing(b *testing.B) {
return
}
defer f.Close()
to := ParseZone(f)
to := ParseZone(f)
for x := range to {
x = x
}
@ -244,7 +243,7 @@ func TestZoneParsing(t *testing.T) {
}
defer f.Close()
start := time.Now().UnixNano()
to := ParseZone(f)
to := ParseZone(f)
var i int
for x := range to {
t.Logf("%s\n", x.RR)

View File

@ -74,7 +74,7 @@ type lex struct {
}
type Token struct {
RR // the scanned resource record
RR // the scanned resource record
Error *ParseError // when an error occured, this is the specifics
}
@ -147,13 +147,13 @@ func parseZone(r io.Reader, t chan Token) {
st = _EXPECT_OWNER_DIR
case _OWNER:
h.Name = l.token
if _, ok := IsDomainName(l.token); !ok {
t <- Token{Error: &ParseError{"bad owner name", l}}
return
}
if !IsFqdn(h.Name) {
h.Name += origin
}
if _, ok := IsDomainName(l.token); !ok {
t <- Token{Error: &ParseError{"bad owner name", l}}
return
}
if !IsFqdn(h.Name) {
h.Name += origin
}
st = _EXPECT_OWNER_BL
case _DIRTTL:
st = _EXPECT_DIRTTL_BL
@ -180,22 +180,22 @@ func parseZone(r io.Reader, t chan Token) {
defttl = ttl
}
st = _EXPECT_OWNER_DIR
case _EXPECT_DIRORIGIN_BL:
if l.value != _BLANK {
t <- Token{Error: &ParseError{"No blank after $-directive", l}}
return
}
st = _EXPECT_DIRORIGIN
case _EXPECT_DIRORIGIN:
if l.value != _STRING {
t <- Token{Error: &ParseError{"Expecting $ORIGIN value, not this...", l}}
return
}
if !IsFqdn(l.token) {
origin = l.token + origin // Append old origin if the new one isn't a fqdn
} else {
origin = l.token
}
case _EXPECT_DIRORIGIN_BL:
if l.value != _BLANK {
t <- Token{Error: &ParseError{"No blank after $-directive", l}}
return
}
st = _EXPECT_DIRORIGIN
case _EXPECT_DIRORIGIN:
if l.value != _STRING {
t <- Token{Error: &ParseError{"Expecting $ORIGIN value, not this...", l}}
return
}
if !IsFqdn(l.token) {
origin = l.token + origin // Append old origin if the new one isn't a fqdn
} else {
origin = l.token
}
case _EXPECT_OWNER_BL:
if l.value != _BLANK {
t <- Token{Error: &ParseError{"No blank after owner", l}}

View File

@ -123,12 +123,12 @@ func setNS(h RR_Header, c chan lex, o string) (RR, *ParseError) {
l := <-c
rr.Ns = l.token
if _, ok := IsDomainName(l.token); !ok {
if _, ok := IsDomainName(l.token); !ok {
return nil, &ParseError{"bad NS Ns", l}
}
if !IsFqdn(rr.Ns) {
rr.Ns += o
}
if !IsFqdn(rr.Ns) {
rr.Ns += o
}
return rr, nil
}
@ -145,12 +145,12 @@ func setMX(h RR_Header, c chan lex, o string) (RR, *ParseError) {
<-c // _BLANK
l = <-c // _STRING
rr.Mx = l.token
if _, ok := IsDomainName(l.token); !ok {
if _, ok := IsDomainName(l.token); !ok {
return nil, &ParseError{"bad MX Mx", l}
}
if !IsFqdn(rr.Mx) {
rr.Mx += o
}
if !IsFqdn(rr.Mx) {
rr.Mx += o
}
return rr, nil
}
@ -160,12 +160,12 @@ func setCNAME(h RR_Header, c chan lex, o string) (RR, *ParseError) {
l := <-c
rr.Cname = l.token
if _, ok := IsDomainName(l.token); !ok {
if _, ok := IsDomainName(l.token); !ok {
return nil, &ParseError{"bad CNAME", l}
}
if !IsFqdn(rr.Cname) {
rr.Cname += o
}
if !IsFqdn(rr.Cname) {
rr.Cname += o
}
return rr, nil
}
@ -176,21 +176,21 @@ func setSOA(h RR_Header, c chan lex, o string) (RR, *ParseError) {
l := <-c
rr.Ns = l.token
<-c // _BLANK
if _, ok := IsDomainName(l.token); !ok {
if _, ok := IsDomainName(l.token); !ok {
return nil, &ParseError{"bad SOA mname", l}
}
if !IsFqdn(rr.Ns) {
rr.Ns += o
}
if !IsFqdn(rr.Ns) {
rr.Ns += o
}
l = <-c
rr.Mbox = l.token
if _, ok := IsDomainName(l.token); !ok {
if _, ok := IsDomainName(l.token); !ok {
return nil, &ParseError{"bad SOA rname", l}
}
if !IsFqdn(rr.Mbox) {
rr.Mbox += o
}
if !IsFqdn(rr.Mbox) {
rr.Mbox += o
}
<-c // _BLANK
var j int
@ -274,12 +274,12 @@ func setRRSIG(h RR_Header, c chan lex, o string) (RR, *ParseError) {
<-c // _BLANK
l = <-c
rr.SignerName = l.token
if _, ok := IsDomainName(l.token); !ok {
if _, ok := IsDomainName(l.token); !ok {
return nil, &ParseError{"bad RRSIG signername", l}
}
if !IsFqdn(rr.SignerName) {
rr.SignerName += o
}
if !IsFqdn(rr.SignerName) {
rr.SignerName += o
}
// Get the remaining data until we see a NEWLINE
l = <-c
s := ""
@ -304,12 +304,12 @@ func setNSEC(h RR_Header, c chan lex, o string) (RR, *ParseError) {
l := <-c
rr.NextDomain = l.token
if _, ok := IsDomainName(l.token); !ok {
if _, ok := IsDomainName(l.token); !ok {
return nil, &ParseError{"bad NSEC nextdomain", l}
}
if !IsFqdn(rr.NextDomain) {
rr.NextDomain += o
}
if !IsFqdn(rr.NextDomain) {
rr.NextDomain += o
}
rr.TypeBitMap = make([]uint16, 0)
l = <-c
@ -364,12 +364,12 @@ func setNSEC3(h RR_Header, c chan lex, o string) (RR, *ParseError) {
l = <-c
rr.HashLength = uint8(len(l.token))
rr.NextDomain = l.token
if _, ok := IsDomainName(l.token); !ok {
if _, ok := IsDomainName(l.token); !ok {
return nil, &ParseError{"bad NSEC nextdomain", l}
}
if !IsFqdn(rr.NextDomain) {
rr.NextDomain += o
}
if !IsFqdn(rr.NextDomain) {
rr.NextDomain += o
}
rr.TypeBitMap = make([]uint16, 0)
l = <-c