From fdcdc6dbf6cde0e8a7e20227f45296cb9fbd310a Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 26 Aug 2013 21:11:24 -0700 Subject: [PATCH] Add test to zero rdata (for dyn updates) This triggerd a bunch of failures, the most important one is the packing and zero length domain name now works. --- TODO.markdown | 2 ++ dns_test.go | 6 +++--- msg.go | 9 +++++++-- types.go | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/TODO.markdown b/TODO.markdown index 804f2310..b479118a 100644 --- a/TODO.markdown +++ b/TODO.markdown @@ -3,6 +3,8 @@ * Support for on-the-fly-signing or check how to do it * Test all rdata packing with zero rdata -- allowed for dynamic updates * Actually mimic net/ ? Dial. Read/Write ? + - if I want this i need to work on something else than \*Client, because a single client + can have multiple oustanding qeuries * Ratelimiting? server side (rrl) * Ratelimiting? client side diff --git a/dns_test.go b/dns_test.go index 9f7fba84..126e7852 100644 --- a/dns_test.go +++ b/dns_test.go @@ -243,12 +243,12 @@ func TestToRFC3597(t *testing.T) { func TestNoRdata(t *testing.T) { data := make([]byte, 1024) - for typ, _ := range TypeToString { - r := rr_mk[typ]() + for typ, fn := range rr_mk { + r := fn() *r.Header() = RR_Header{Name: "miek.nl.", Rrtype: typ, Class: ClassINET, Ttl: 3600} _, e := PackRR(r, data, 0, nil, false) if e != nil { - t.Logf("Failed to pack rdata zero RR %d: %s\n", typ, e.Error()) + t.Logf("Failed to pack rdata zero RR %s: %s\n", TypeToString[typ], e.Error()) t.Fail() } } diff --git a/msg.go b/msg.go index 1bdf4a74..b84d30b9 100644 --- a/msg.go +++ b/msg.go @@ -214,8 +214,11 @@ var RcodeToString = map[int]string{ func PackDomainName(s string, msg []byte, off int, compression map[string]int, compress bool) (off1 int, err error) { lenmsg := len(msg) ls := len(s) + if ls == 0 { // Ok, for instance when dealing with update RR without any rdata. + return off, nil + } // If not fully qualified, error out - if ls == 0 || s[ls-1] != '.' { + if s[ls-1] != '.' { return lenmsg, ErrFqdn } // Each dot ends a segment of the name. @@ -468,7 +471,9 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str return lenmsg, &Error{err: "overflow packing a"} } case `dns:"aaaa"`: - // fv.Len TODO(mg) dynamic updates? + if fv.Len() == 0 { + break + } if fv.Len() > net.IPv6len || off+fv.Len() > lenmsg { return lenmsg, &Error{err: "overflow packing aaaa"} } diff --git a/types.go b/types.go index 9e578bb8..b77e1564 100644 --- a/types.go +++ b/types.go @@ -884,8 +884,8 @@ func (rr *TA) len() int { type TALINK struct { Hdr RR_Header - PreviousName string `dns:"domain"` - NextName string `dns:"domain"` + PreviousName string `dns:"domain-name"` + NextName string `dns:"domain-name"` } func (rr *TALINK) Header() *RR_Header { return &rr.Hdr }