Some cleanup
This commit is contained in:
parent
70552b49ca
commit
d6efd37302
2
TODO
2
TODO
|
@ -1,6 +1,8 @@
|
||||||
EDNS -- finish EDNS0 support
|
EDNS -- finish EDNS0 support
|
||||||
DNSSEC - validation and the remaining records, DS (encoding), NSEC and NSEC3
|
DNSSEC - validation and the remaining records, DS (encoding), NSEC and NSEC3
|
||||||
unknown RRs - if I ever get around to make it
|
unknown RRs - if I ever get around to make it
|
||||||
|
|
||||||
|
|
||||||
convience functions
|
convience functions
|
||||||
parsing from strings
|
parsing from strings
|
||||||
"miek.nl IN A 192.168.1.2" -> <correct Go type>
|
"miek.nl IN A 192.168.1.2" -> <correct Go type>
|
||||||
|
|
1
edns.go
1
edns.go
|
@ -9,6 +9,7 @@ const (
|
||||||
_DO = 1 << 15 // dnssec ok
|
_DO = 1 << 15 // dnssec ok
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// An ENDS0 option rdata element.
|
||||||
type Option struct {
|
type Option struct {
|
||||||
Code uint16
|
Code uint16
|
||||||
Data string "hex"
|
Data string "hex"
|
||||||
|
|
30
msg.go
30
msg.go
|
@ -174,9 +174,6 @@ func packStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int, o
|
||||||
BadType:
|
BadType:
|
||||||
fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v\n", f.Type)
|
fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v\n", f.Type)
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
case *reflect.BoolValue:
|
|
||||||
// Used internally for Edns, not present in the DNS
|
|
||||||
continue
|
|
||||||
case *reflect.SliceValue:
|
case *reflect.SliceValue:
|
||||||
switch f.Tag {
|
switch f.Tag {
|
||||||
default:
|
default:
|
||||||
|
@ -306,9 +303,6 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
|
||||||
BadType:
|
BadType:
|
||||||
fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type)
|
fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type)
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
case *reflect.BoolValue:
|
|
||||||
// Used internally for Edns, not present in the DNS
|
|
||||||
continue
|
|
||||||
case *reflect.SliceValue:
|
case *reflect.SliceValue:
|
||||||
switch f.Tag {
|
switch f.Tag {
|
||||||
default:
|
default:
|
||||||
|
@ -331,7 +325,18 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
|
||||||
fv.Set(reflect.NewValue(b).(*reflect.SliceValue))
|
fv.Set(reflect.NewValue(b).(*reflect.SliceValue))
|
||||||
off += net.IPv6len
|
off += net.IPv6len
|
||||||
case "OPT": // edns
|
case "OPT": // edns
|
||||||
// do it here
|
// check rdlength, if more, then more options
|
||||||
|
// TODO(mg) checking
|
||||||
|
// for now: allow only 1. TODO(mg)
|
||||||
|
/*
|
||||||
|
opt := make([]Option, 1)
|
||||||
|
opt[0].Code, off = unpackUint16(msg, off)
|
||||||
|
length := uint16(msg[off])<<8 | uint16(msg[off+1])
|
||||||
|
off += 2
|
||||||
|
opt[0].Data = string(msg[off:off+int(length)])
|
||||||
|
off += int(length)
|
||||||
|
//opt
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
case *reflect.StructValue:
|
case *reflect.StructValue:
|
||||||
off, ok = unpackStructValue(fv, msg, off)
|
off, ok = unpackStructValue(fv, msg, off)
|
||||||
|
@ -347,12 +352,12 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
|
||||||
fv.Set(uint64(i))
|
fv.Set(uint64(i))
|
||||||
off++
|
off++
|
||||||
case reflect.Uint16:
|
case reflect.Uint16:
|
||||||
|
var i uint16
|
||||||
if off+2 > len(msg) {
|
if off+2 > len(msg) {
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
}
|
}
|
||||||
i := uint16(msg[off])<<8 | uint16(msg[off+1])
|
i, off = unpackUint16(msg, off)
|
||||||
fv.Set(uint64(i))
|
fv.Set(uint64(i))
|
||||||
off += 2
|
|
||||||
case reflect.Uint32:
|
case reflect.Uint32:
|
||||||
if off+4 > len(msg) {
|
if off+4 > len(msg) {
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
|
@ -425,6 +430,13 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
|
||||||
return off, true
|
return off, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function for unpacking
|
||||||
|
func unpackUint16(msg []byte, off int) (v uint16, off1 int) {
|
||||||
|
v = uint16(msg[off])<<8 | uint16(msg[off+1])
|
||||||
|
off1 = off+2
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func unpackStruct(any interface{}, msg []byte, off int) (off1 int, ok bool) {
|
func unpackStruct(any interface{}, msg []byte, off int) (off1 int, ok bool) {
|
||||||
off, ok = unpackStructValue(structValue(any), msg, off)
|
off, ok = unpackStructValue(structValue(any), msg, off)
|
||||||
return off, ok
|
return off, ok
|
||||||
|
|
|
@ -15,7 +15,7 @@ func TestResolverEdns(t *testing.T) {
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
m.MsgHdr.Recursion_desired = true //only set this bit
|
m.MsgHdr.Recursion_desired = true //only set this bit
|
||||||
m.Question = make([]Question, 1)
|
m.Question = make([]Question, 1)
|
||||||
m.Ns = make([]RR, 1)
|
m.Extra = make([]RR, 1)
|
||||||
|
|
||||||
// Add EDNS rr
|
// Add EDNS rr
|
||||||
edns := new(RR_OPT)
|
edns := new(RR_OPT)
|
||||||
|
@ -23,11 +23,11 @@ func TestResolverEdns(t *testing.T) {
|
||||||
edns.Hdr.Rrtype = TypeOPT
|
edns.Hdr.Rrtype = TypeOPT
|
||||||
// You can handle an OTP RR as any other, but there
|
// You can handle an OTP RR as any other, but there
|
||||||
// are some convience functions
|
// are some convience functions
|
||||||
ends.UDPSize(4096, true)
|
// edns.UDPSize(4096, true)
|
||||||
edns.DoBit(true, true)
|
// edns.DoBit(true, true)
|
||||||
// edns.Nsid("mieks-server", true)
|
// edns.Nsid("mieks-server", true)
|
||||||
// edns.Hdr.Class = ClassINET
|
edns.Hdr.Class = ClassINET
|
||||||
// edns.Hdr.Ttl = 3600
|
edns.Hdr.Ttl = 3600
|
||||||
// no options for now
|
// no options for now
|
||||||
// edns.Option = make([]Option, 1)
|
// edns.Option = make([]Option, 1)
|
||||||
// edns.Option[0].Code = OptionCodeNSID
|
// edns.Option[0].Code = OptionCodeNSID
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
|
// use scanner or ebnf
|
||||||
|
|
||||||
// Convert a string to an resource record. The string must fir on one line.
|
// Convert a string to an resource record. The string must fir on one line.
|
||||||
// miek.nl. 3600 IN A 192.168.1.1 // ok
|
// miek.nl. 3600 IN A 192.168.1.1 // ok
|
||||||
// miek.nl. IN A 192.168.1.1 // ok, ttl may be omitted
|
// miek.nl. IN A 192.168.1.1 // ok, ttl may be omitted
|
||||||
|
|
Loading…
Reference in New Issue