Add some helper function for ENDS

cleanups - starts to work. Still FORMERR on EDNS0 request, but
we are getting there
This commit is contained in:
Miek Gieben 2010-12-23 14:27:04 +01:00
parent 18afd5e536
commit f16ad2a7af
2 changed files with 20 additions and 37 deletions

24
edns.go
View File

@ -16,15 +16,16 @@ type Option struct {
// EDNS extended RR.
// Not used yet
type EDNS0_Header struct {
Name string "extended-name"
/*
This is the EDNS0 Header
Name string "domain-name"
Opt uint16 // was type, but is always TypeOPT
UDPSize uint16 // was class
ExtendedRcode uint8 // was TTL
Version uint8 // was TTL
Z uint16 // was TTL (all flags should be put here)
Rdlength uint16 // length of data after the header
}
*/
type RR_OPT struct {
Hdr RR_Header // this must become a EDNS0_Header
@ -36,7 +37,7 @@ func (rr *RR_OPT) Header() *RR_Header {
}
func (rr *RR_OPT) String() string {
s := rr.Hdr.String()
s := rr.Hdr.String() // Hier misschien andere representatie
for _, o := range rr.Option {
switch o.Code {
case OptionCodeNSID:
@ -45,3 +46,18 @@ func (rr *RR_OPT) String() string {
}
return s
}
// when set is true, set the size otherwise get it
func (rr *RR_OPT) UDPSize(size int, set bool) int {
return 0
}
// when set is true, set the Do bit, otherwise get it
func (rr *RR_OPT) DoBit(do, set bool) bool {
return true
}
// when set is true, set the nsid, otherwise get it
func (rr *RR_OPT) Nsid(nsid string, set bool) string {
return ""
}

View File

@ -1,33 +0,0 @@
// check with what kind of RR header we are dealing with
// I'm sitting on the start byte of the name, with off?
// ifso I can check the. From RFC 1035 4.1.4
// The first two bits are ones. This allows a pointer to be distinguished
// from a label, since the label must begin with two zero bits because
// labels are restricted to 63 octets or less. (The 10 and 01 combinations
// are reserved for future use.)
// EDNS takes 01
c := int(msg[off])
switch c & 0xC0 {
case 0x00,0xC0:
// normal name
// pack twice, once to find end of header
// and again to find end of packet.
// a bit inefficient but this doesn't need to be fast.
// off1 is end of header
// off2 is end of rr
off1, ok = packStruct(rr.Header(), msg, off)
off2, ok = packStruct(rr, msg, off)
if !ok {
return len(msg), false
}
// pack a third time; redo header with correct data length
rr.Header().Rdlength = uint16(off2 - off1)
packStruct(rr.Header(), msg, off)
return off2, true
case 0x40:
// EDNS0 header
return 0,true
}
return 0, true // BUG in Go
}