Make a stab for EDNS

This commit is contained in:
Miek Gieben 2010-12-22 12:26:50 +01:00
parent e650aae18b
commit 0f05a2f434
6 changed files with 44 additions and 73 deletions

View File

@ -23,8 +23,5 @@ restest: restest.go $(GOFILES)
manglertest: manglertest.go $(GOFILES)
6g -I _obj manglertest.go && 6l -L _obj -o manglertest manglertest.6
packtest: packtest.go $(GOFILES)
6g -I _obj packtest.go && 6l -L _obj -o packtest packtest.6
dnssectest: dnssectest.go $(GOFILES)
6g -I _obj dnssectest.go && 6l -L _obj -o dnssectest dnssectest.6

View File

@ -1,8 +1,7 @@
package dns
// This is the base layer for ENDS, in practise
// You'll only need to set updsize, do bit
// You'll only need to set updsize, do bit, and??
const (
OptionCodeLLQ = 1
@ -13,7 +12,7 @@ const (
)
// Need PackOption I guess?? TODO
type Edns0Option struct {
type Option struct {
Code uint16
// Length uint16
Data string "hex" // len(data) is must be encode in packet
@ -32,7 +31,7 @@ type EDNS0_Header struct {
type RR_EDNS0 struct {
Hdr RR_Header // this must become a EDNS0_Header
Option []Edns0Option
Option []Option
}
func (rr *RR_EDNS0) Header() *RR_Header {

19
edns_test.go Normal file
View File

@ -0,0 +1,19 @@
package dns
// Test EDNS RR records
import (
"testing"
)
func TestEDNS_RR(t *testing.T) {
edns := new(RR_EDNS0)
edns.Hdr.Name = "miek.nl." // must . be for edns
edns.Hdr.Rrtype = TypeOPT
edns.Hdr.Class = ClassINET
edns.Hdr.Ttl = 3600
edns.Option = make([]Option, 1)
edns.Option[0].Code = OptionCodeNSID
edns.Option[0].Data = "lalalala"
//fmt.Printf("%s\n", edns)
}

View File

@ -70,16 +70,28 @@ func TestPackUnpack(t *testing.T) {
sig.SignerName = "miek.nl."
sig.Sig = "AwEAAaHIwpx3w4VHKi6i1LHnTaWeHCL154Jug0Rtc9ji5qwPXpBo6A5sRv7cSsPQKPIwxLpyCrbJ4mr2L0EPOdvP6z6YfljK2ZmTbogU9aSU2fiq/4wjxbdkLyoDVgtO+JsxNN4bjr4WcWhsmk1Hg93FV9ZpkWb0Tbad8DFqNDzr//kZ"
edns := new(RR_EDNS0)
edns.Hdr.Name = "miek.nl." // must . be for edns
edns.Hdr.Rrtype = TypeOPT
edns.Hdr.Class = ClassINET
edns.Hdr.Ttl = 3600
edns.Option = make([]Option, 1)
edns.Option[0].Code = OptionCodeNSID
edns.Option[0].Data = "lalalala"
out.Answer[0] = sig
out.Extra = make([]RR, 1)
out.Extra[0] = edns
msg, ok = out.Pack()
// fmt.Printf("%v\n", msg)
if ! ok {
t.Log("Failed to pack msg with RRSIG")
t.Log("Failed to pack msg with RRSIG and EDNS")
t.Fail()
}
if ! in.Unpack(msg) {
t.Log("Failed to unpack msg with RRSIG")
t.Log("Failed to unpack msg with RRSIG and EDNS")
t.Fail()
}
fmt.Printf("%v\n", in)

View File

@ -1,47 +0,0 @@
package main
import (
"dns"
"fmt"
"net"
)
func main() {
out := new(dns.Msg)
r := new(dns.RR_AAAA)
r.AAAA = net.ParseIP("2001:7b8:206:1:200:39ff:fe59:b187").To16()
// r.AAAA = net.ParseIP("2003::53").To16()
r.Hdr.Name = "a.miek.nl"
r.Hdr.Rrtype = dns.TypeAAAA
r.Hdr.Class = dns.ClassINET
r.Hdr.Ttl = 3600
out.Answer = make([]dns.RR, 1)
out.Answer[0] = r
msg, _ := out.Pack()
in := new(dns.Msg)
in.Unpack(msg)
fmt.Printf("%v\n", in)
sig := new(dns.RR_RRSIG)
sig.Hdr.Name = "miek.nl."
sig.Hdr.Rrtype = dns.TypeRRSIG
sig.Hdr.Class = dns.ClassINET
sig.Hdr.Ttl = 3600
sig.TypeCovered = dns.TypeDNSKEY
sig.Algorithm = dns.AlgRSASHA1
sig.OrigTtl = 4000
sig.Expiration = 1000
sig.Inception = 800
sig.KeyTag = 34641
sig.SignerName = "miek.nl."
sig.Sig = "AwEAAaHIwpx3w4VHKi6i1LHnTaWeHCL154Jug0Rtc9ji5qwPXpBo6A5sRv7cSsPQKPIwxLpyCrbJ4mr2L0EPOdvP6z6YfljK2ZmTbogU9aSU2fiq/4wjxbdkLyoDVgtO+JsxNN4bjr4WcWhsmk1Hg93FV9ZpkWb0Tbad8DFq NDzr//kZ"
out.Answer[0] = sig
msg, _ = out.Pack()
in.Unpack(msg)
fmt.Printf("%v\n", in)
}

View File

@ -11,7 +11,6 @@ import (
"net"
"strconv"
"time"
"reflect"
)
// Packet formats
@ -133,23 +132,15 @@ func (h *RR_Header) Header() *RR_Header {
}
func (h *RR_Header) String() string {
//
r := reflect.NewValue(h).(*reflect.PtrValue).Elem().(*reflect.StructValue)
f := r.Type().(*reflect.StructType).Field(0).Tag
var s string
switch f {
default:
if len(h.Name) == 0 {
s = ".\t"
} else {
s = h.Name + "\t"
}
s = s + strconv.Itoa(int(h.Ttl)) + "\t"
s = s + class_str[h.Class] + "\t"
s = s + rr_str[h.Rrtype] + "\t"
case "edns":
// edns here
}
if len(h.Name) == 0 {
s = ".\t"
} else {
s = h.Name + "\t"
}
s = s + strconv.Itoa(int(h.Ttl)) + "\t"
s = s + class_str[h.Class] + "\t"
s = s + rr_str[h.Rrtype] + "\t"
return s
}