Fix EDNS0 (OPT_RR) printing

This commit is contained in:
Miek Gieben 2010-12-27 14:31:31 +01:00
parent 8dbefdd3f1
commit 7f88c92f0f
5 changed files with 53 additions and 38 deletions

3
TODO
View File

@ -1,5 +1,5 @@
Todo: Todo:
* parse RRs from strings * parse RRs from strings AToRR()
* DNSSEC validation * DNSSEC validation
* Unknown RRs * Unknown RRs
* fix os.Erros usage * fix os.Erros usage
@ -11,3 +11,4 @@ Tesing:
Issues: Issues:
* shortened ipv6 addresses are not parsed correctly * shortened ipv6 addresses are not parsed correctly
* quoted quotes in txt records * quoted quotes in txt records
* divide the code in multiple packages? dns, dnssec

View File

@ -2,7 +2,7 @@ package dns
import ( import (
"testing" "testing"
"fmt" //togo "strings"
) )
func TestKeyToDS(t *testing.T) { func TestKeyToDS(t *testing.T) {
@ -17,6 +17,8 @@ func TestKeyToDS(t *testing.T) {
key.PubKey = "AwEAAcNEU67LJI5GEgF9QLNqLO1SMq1EdoQ6E9f85ha0k0ewQGCblyW2836GiVsm6k8Kr5ECIoMJ6fZWf3CQSQ9ycWfTyOHfmI3eQ/1Covhb2y4bAmL/07PhrL7ozWBW3wBfM335Ft9xjtXHPy7ztCbV9qZ4TVDTW/Iyg0PiwgoXVesz" key.PubKey = "AwEAAcNEU67LJI5GEgF9QLNqLO1SMq1EdoQ6E9f85ha0k0ewQGCblyW2836GiVsm6k8Kr5ECIoMJ6fZWf3CQSQ9ycWfTyOHfmI3eQ/1Covhb2y4bAmL/07PhrL7ozWBW3wBfM335Ft9xjtXHPy7ztCbV9qZ4TVDTW/Iyg0PiwgoXVesz"
ds := key.ToDS(HashSHA1) ds := key.ToDS(HashSHA1)
if strings.ToUpper(ds.Digest) != "B5121BDB5B8D86D0CC5FFAFBAAABE26C3E20BAC1" {
fmt.Printf("%v\n%v\n", key, ds) t.Logf("Wrong DS digest for Sha1\n%v\n", ds)
t.Fail()
}
} }

76
edns.go
View File

@ -2,13 +2,17 @@
// convience functions to operate on it. // convience functions to operate on it.
package dns package dns
import (
"strconv"
)
// EDNS0 option codes // EDNS0 option codes
const ( const (
OptionCodeLLQ = 1 // Not used OptionCodeLLQ = 1 // Not used
OptionCodeUL = 2 // Not used OptionCodeUL = 2 // Not used
OptionCodeNSID = 3 // NSID, RFC5001 OptionCodeNSID = 3 // NSID, RFC5001
// EDNS flag bits (put in Z section) // EDNS flag bits (put in Z section)
_DO = 1 << 7 // dnssec ok _DO = 1 << 7 // dnssec ok
) )
// An ENDS0 option rdata element. // An ENDS0 option rdata element.
@ -30,12 +34,7 @@ This is the EDNS0 Header
type RR_OPT struct { type RR_OPT struct {
Hdr RR_Header Hdr RR_Header
Option []Option "OPT" // Tag is used in pack and unpack Option []Option "OPT" // Tag is used in pack and unpack
}
// A ENDS packet must show differently. TODO
func (h *RR_Header) ednsString() string {
return h.String()
} }
func (rr *RR_OPT) Header() *RR_Header { func (rr *RR_OPT) Header() *RR_Header {
@ -43,44 +42,55 @@ func (rr *RR_OPT) Header() *RR_Header {
} }
func (rr *RR_OPT) String() string { func (rr *RR_OPT) String() string {
s := rr.Hdr.ednsString() // Hier misschien andere representatie s := ";; EDNS: version " + strconv.Itoa(int(rr.Version(0, false))) + "; "
if rr.DoBit(false, false) {
s += "flags: do; "
} else {
s += "flags: ; "
}
s += "udp: " + strconv.Itoa(int(rr.UDPSize(0, false))) + ";"
for _, o := range rr.Option { for _, o := range rr.Option {
switch o.Code { switch o.Code {
case OptionCodeNSID: case OptionCodeNSID:
s += "NSID: " + o.Data s += " nsid: " + o.Data + ";"
} }
} }
return s return s
} }
// Set the version of edns, currently only 0 is there
func (rr *RR_OPT) Version(v uint8, set bool) uint8 {
return 0
}
// when set is true, set the size otherwise get it // when set is true, set the size otherwise get it
func (rr *RR_OPT) UDPSize(size int, set bool) int { func (rr *RR_OPT) UDPSize(size uint16, set bool) uint16 {
// fiddle in rr.Hdr.Class should be set if set {
if set { rr.Hdr.Class = size
rr.Hdr.Class = uint16(size) }
} return rr.Hdr.Class
return int(rr.Hdr.Class)
} }
// when set is true, set the Do bit, otherwise get it // when set is true, set the Do bit, otherwise get it
func (rr *RR_OPT) DoBit(do, set bool) bool { func (rr *RR_OPT) DoBit(do, set bool) bool {
// rr.TTL last 2 bytes, left most bit // rr.TTL last 2 bytes, left most bit
// See line 239 in msg.go for TTL encoding // See line 239 in msg.go for TTL encoding
if set { if set {
leftbyte := byte(rr.Hdr.Ttl >> 24) leftbyte := byte(rr.Hdr.Ttl >> 24)
leftbyte = leftbyte | _DO leftbyte = leftbyte | _DO
rr.Hdr.Ttl = uint32(leftbyte<<24) rr.Hdr.Ttl = uint32(leftbyte << 24)
return true return true
} else { } else {
// jaja TODO(MG) // jaja?? TODO(MG)
leftbyte := byte(rr.Hdr.Ttl >> 24) leftbyte := byte(rr.Hdr.Ttl >> 24)
return leftbyte & _DO == 1 return leftbyte&_DO == 1
} }
return true // dead code, bug in Go return true // dead code, bug in Go
} }
// when set is true, set the nsid, otherwise get it // when set is true, set the nsid, otherwise get it
func (rr *RR_OPT) Nsid(nsid string, set bool) string { func (rr *RR_OPT) Nsid(nsid string, set bool) string {
// RR.Option[0] to be set // RR.Option[0] to be set
return "" return ""
} }

View File

@ -39,6 +39,8 @@ func TestResolverEdns(t *testing.T) {
ch <- DnsMsg{m, nil} ch <- DnsMsg{m, nil}
in := <-ch in := <-ch
t.Fail()
t.Log("%v\n", in.Dns)
if in.Dns.Rcode != RcodeSuccess { if in.Dns.Rcode != RcodeSuccess {
t.Log("Failed to get an valid answer") t.Log("Failed to get an valid answer")

View File

@ -8,7 +8,7 @@ package dns
// miek.nl. A 192.168.1.1 // ok, ttl and class omitted // miek.nl. A 192.168.1.1 // ok, ttl and class omitted
// miek.nl. 3600 A 192.168.1.1 // ok, class omitted // miek.nl. 3600 A 192.168.1.1 // ok, class omitted
// IN A 192.168.1.1 // not ok // IN A 192.168.1.1 // not ok
func AtoRR(s string) *RR { func ParseString(s string) *RR {
// up to first whitespace is domainname // up to first whitespace is domainname
// next word is: // next word is:
// <number> -> TTL // <number> -> TTL