From a34cf6798a303b4292760d9dbb90f5e8eba6be27 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 21 Jul 2015 07:47:38 +0100 Subject: [PATCH] Fix URI record When the URI record became an RFC they slightly changed the format. Make the needed changes. --- README.md | 10 +++++----- parse_test.go | 18 ++++++++++++++++++ types.go | 24 ++++++------------------ zscan_rr.go | 8 ++------ 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 73d62709..ec33d61c 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository. * 6975 - Algorithm Understanding in DNSSEC * 7043 - EUI48/EUI64 records * 7314 - DNS (EDNS) EXPIRE Option -* xxxx - URI record (draft) +* 7553 - URI record * xxxx - EDNS0 DNS Update Lease (draft) ## Loosely based upon @@ -138,7 +138,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository. ## TODO * privatekey.Precompute() when signing? -* Last remaining RRs: APL, ATMA, A6 and NXT and IPSECKEY; -* Missing in parsing: ISDN, UNSPEC, ATMA; -* NSEC(3) cover/match/closest enclose; -* Replies with TC bit are not parsed to the end; +* Last remaining RRs: APL, ATMA, A6 and NXT. +* Missing in parsing: ISDN, UNSPEC, ATMA. +* NSEC(3) cover/match/closest enclose. +* Replies with TC bit are not parsed to the end. diff --git a/parse_test.go b/parse_test.go index 1c2ef865..659a38ce 100644 --- a/parse_test.go +++ b/parse_test.go @@ -1477,3 +1477,21 @@ func TestParseCAA(t *testing.T) { } } } + +func TestParseURI(t *testing.T) { + lt := map[string]string{ + "_http._tcp IN URI 10 1 \"http://www.example.com/path\"": "_http._tcp\t3600\tIN\tURI\t10 1 \"http://www.example.com/path\"", + } + for i, o := range lt { + rr, err := NewRR(i) + if err != nil { + t.Error("failed to parse RR: ", err) + continue + } + if rr.String() != o { + t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) + } else { + t.Logf("RR is OK: `%s'", rr.String()) + } + } +} diff --git a/types.go b/types.go index 716cabf8..34d3089b 100644 --- a/types.go +++ b/types.go @@ -503,7 +503,7 @@ func sprintName(s string) string { return string(dst) } -func sprintCAAValue(s string) string { +func sprintTxtOctet(s string) string { src := []byte(s) dst := make([]byte, 0, len(src)) dst = append(dst, '"') @@ -1329,27 +1329,15 @@ type URI struct { Hdr RR_Header Priority uint16 Weight uint16 - Target []string `dns:"txt"` + Target string `dns:"octet"` } func (rr *URI) Header() *RR_Header { return &rr.Hdr } -func (rr *URI) copy() RR { - cp := make([]string, len(rr.Target), cap(rr.Target)) - copy(cp, rr.Target) - return &URI{*rr.Hdr.copyHeader(), rr.Weight, rr.Priority, cp} -} - +func (rr *URI) copy() RR { return &URI{*rr.Hdr.copyHeader(), rr.Weight, rr.Priority, rr.Target} } +func (rr *URI) len() int { return rr.Hdr.len() + 4 + len(rr.Target) } func (rr *URI) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Priority)) + - " " + strconv.Itoa(int(rr.Weight)) + sprintTxt(rr.Target) -} - -func (rr *URI) len() int { - l := rr.Hdr.len() + 4 - for _, t := range rr.Target { - l += len(t) + 1 - } - return l + " " + strconv.Itoa(int(rr.Weight)) + sprintTxtOctet(rr.Target) } type DHCID struct { @@ -1571,7 +1559,7 @@ func (rr *CAA) Header() *RR_Header { return &rr.Hdr } func (rr *CAA) copy() RR { return &CAA{*rr.Hdr.copyHeader(), rr.Flag, rr.Tag, rr.Value} } func (rr *CAA) len() int { return rr.Hdr.len() + 1 + len(rr.Tag) + len(rr.Value)/2 } func (rr *CAA) String() string { - return rr.Hdr.String() + strconv.Itoa(int(rr.Flag)) + " " + rr.Tag + " " + sprintCAAValue(rr.Value) + return rr.Hdr.String() + strconv.Itoa(int(rr.Flag)) + " " + rr.Tag + " " + sprintTxtOctet(rr.Value) } type UID struct { diff --git a/zscan_rr.go b/zscan_rr.go index 3763d3f4..c8d73afc 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -1876,9 +1876,6 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { rr.Hdr = h l := <-c - if l.length == 0 { - return rr, nil, l.comment - } i, e := strconv.Atoi(l.token) if e != nil { return nil, &ParseError{f, "bad URI Priority", l}, "" @@ -1897,7 +1894,7 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if e != nil { return nil, e.(*ParseError), "" } - rr.Target = s + rr.Target = s[0] return rr, nil, c1 } @@ -2197,9 +2194,8 @@ func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } if len(s) > 1 { return nil, &ParseError{f, "bad CAA Value", l}, "" - } else { - rr.Value = s[0] } + rr.Value = s[0] return rr, nil, c1 }