NSID is broken
This commit is contained in:
parent
acfb57879c
commit
1a81ac9c85
|
@ -11,12 +11,13 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Detected software types
|
// Detected software types
|
||||||
NSD = "nsd"
|
NSD = "NSD"
|
||||||
BIND = "bind"
|
BIND = "BIND"
|
||||||
|
|
||||||
// Vendors
|
// Vendors
|
||||||
ISC = "ISC"
|
ISC = "ISC"
|
||||||
NLNETLABS = "NLnet Labs"
|
NLNETLABS = "NLnet Labs"
|
||||||
|
MICROSOFT = "Microsoft"
|
||||||
)
|
)
|
||||||
|
|
||||||
func startParse(addr string) {
|
func startParse(addr string) {
|
||||||
|
|
|
@ -108,8 +108,20 @@ Flags:
|
||||||
m.MsgHdr.RecursionDesired = *rd
|
m.MsgHdr.RecursionDesired = *rd
|
||||||
m.Question = make([]dns.Question, 1)
|
m.Question = make([]dns.Question, 1)
|
||||||
if *dnssec || *nsid {
|
if *dnssec || *nsid {
|
||||||
m.SetEdns0(dns.DefaultMsgSize, true)
|
o := new(dns.RR_OPT)
|
||||||
|
o.Hdr.Name = "."
|
||||||
|
o.Hdr.Rrtype = dns.TypeOPT
|
||||||
|
if *dnssec {
|
||||||
|
o.SetDo()
|
||||||
|
o.SetUDPSize(dns.DefaultMsgSize)
|
||||||
|
}
|
||||||
|
if *nsid {
|
||||||
|
o.SetNsid("")
|
||||||
|
}
|
||||||
|
m.Extra = append(m.Extra, o)
|
||||||
|
//m.SetEdns0(dns.DefaultMsgSize, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *fp {
|
if *fp {
|
||||||
startParse(nameserver)
|
startParse(nameserver)
|
||||||
return
|
return
|
||||||
|
|
7
edns.go
7
edns.go
|
@ -111,7 +111,7 @@ func (rr *RR_OPT) Do() bool {
|
||||||
return byte(rr.Hdr.Ttl>>8)&_DO == _DO
|
return byte(rr.Hdr.Ttl>>8)&_DO == _DO
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the DO bit.
|
// SetDo sets the DO (DNSSEC OK) bit.
|
||||||
func (rr *RR_OPT) SetDo() {
|
func (rr *RR_OPT) SetDo() {
|
||||||
b1 := byte(rr.Hdr.Ttl >> 24)
|
b1 := byte(rr.Hdr.Ttl >> 24)
|
||||||
b2 := byte(rr.Hdr.Ttl >> 16)
|
b2 := byte(rr.Hdr.Ttl >> 16)
|
||||||
|
@ -121,12 +121,13 @@ func (rr *RR_OPT) SetDo() {
|
||||||
rr.Hdr.Ttl = uint32(b1)<<24 | uint32(b2)<<16 | uint32(b3)<<8 | uint32(b4)
|
rr.Hdr.Ttl = uint32(b1)<<24 | uint32(b2)<<16 | uint32(b3)<<8 | uint32(b4)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the NSID as hex string.
|
// Nsid returns the NSID as hex character string.
|
||||||
func (rr *RR_OPT) Nsid() string {
|
func (rr *RR_OPT) Nsid() string {
|
||||||
return "NSID: " + rr.Option[0].Data
|
return "NSID: " + rr.Option[0].Data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the NSID from a string which is represented as hex characters.
|
// SetNsid sets the NSID from a hex character string.
|
||||||
|
// Use the empty string when requesting NSID.
|
||||||
func (rr *RR_OPT) SetNsid(hexnsid string) {
|
func (rr *RR_OPT) SetNsid(hexnsid string) {
|
||||||
rr.Option = make([]Option, 1) // TODO(mg) check length first?
|
rr.Option = make([]Option, 1) // TODO(mg) check length first?
|
||||||
rr.Option[0].Code = OptionCodeNSID
|
rr.Option[0].Code = OptionCodeNSID
|
||||||
|
|
20
msg.go
20
msg.go
|
@ -16,7 +16,6 @@ package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
// "fmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"net"
|
"net"
|
||||||
"rand"
|
"rand"
|
||||||
|
@ -318,6 +317,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
|
||||||
//fmt.Fprintf(os.Stderr, "dns: unknown packing slice tag %v\n", f.Tag)
|
//fmt.Fprintf(os.Stderr, "dns: unknown packing slice tag %v\n", f.Tag)
|
||||||
return lenmsg, false
|
return lenmsg, false
|
||||||
case "OPT": // edns
|
case "OPT": // edns
|
||||||
|
// Length of the entire option section
|
||||||
for j := 0; j < val.Field(i).Len(); j++ {
|
for j := 0; j < val.Field(i).Len(); j++ {
|
||||||
element := val.Field(i).Index(j)
|
element := val.Field(i).Index(j)
|
||||||
code := uint16(element.Field(0).Uint())
|
code := uint16(element.Field(0).Uint())
|
||||||
|
@ -327,16 +327,18 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
|
||||||
//fmt.Fprintf(os.Stderr, "dns: failure packing OTP")
|
//fmt.Fprintf(os.Stderr, "dns: failure packing OTP")
|
||||||
return lenmsg, false
|
return lenmsg, false
|
||||||
}
|
}
|
||||||
data := string(h)
|
|
||||||
// Option Code
|
// Option Code
|
||||||
msg[off] = byte(code >> 8)
|
// the rdlength needs to be set somehow
|
||||||
msg[off+1] = byte(code)
|
println("code ", code)
|
||||||
|
println("length ", len(string(h)))
|
||||||
|
println("off ", off)
|
||||||
|
msg[off], msg[off+1] = packUint16(code)
|
||||||
// Length
|
// Length
|
||||||
msg[off+2] = byte(len(data) >> 8)
|
msg[off+2], msg[off+3] = packUint16(uint16(len(string(h))))
|
||||||
msg[off+3] = byte(len(data))
|
off += 4
|
||||||
off += 4
|
|
||||||
copy(msg[off:off+len(data)], []byte(data))
|
copy(msg[off:off+len(string(h))], h)
|
||||||
off += len(data)
|
off += len(string(h))
|
||||||
}
|
}
|
||||||
case "A":
|
case "A":
|
||||||
// It must be a slice of 4, even if it is 16, we encode
|
// It must be a slice of 4, even if it is 16, we encode
|
||||||
|
|
Loading…
Reference in New Issue