Completely fix EDNS0

This commit is contained in:
Miek Gieben 2010-12-30 18:42:40 +01:00
parent ec2e732ad3
commit acdab89120
4 changed files with 29 additions and 16 deletions

3
TODO
View File

@ -1,14 +1,13 @@
Todo:
* DNSSEC validation
* NSEC(3) secure denial of existence
* Unknown RRs
* fix os.Erros usage, add DNSSEC related errors
* AXFR/IXFR support
* IDN?
* Unknown RRs?
* query-time, server in string ouput of dns.Msg
Issues:
* completely fix EDNS
* shortened ipv6 addresses are not parsed correctly
* quoted quotes in txt records
* Convience functions?

View File

@ -15,12 +15,13 @@ import (
func main() {
var dnssec *bool = flag.Bool("dnssec", false, "Set the DO (DNSSEC OK) bit and set the bufsize to 4096")
var port *string = flag.String("port", "53", "Set the query port")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [@server] [qtype] [qclass] [name ...]\n", os.Args[0])
flag.PrintDefaults()
}
nameserver := "127.0.0.1" // Default nameserver
nameserver := "@127.0.0.1" // Default nameserver
qtype := uint16(dns.TypeA) // Default qtype
qclass := uint16(dns.ClassINET) // Default qclass
var qname []string
@ -53,12 +54,14 @@ FLAGS:
}
r := new(resolver.Resolver)
r.Timeout = 2
r.Port = *port
r.Attempts = 1
qr := resolver.NewQuerier(r)
// @server may be a name, resolv that
var err os.Error
_, addr, err := net.LookupHost(string([]byte(nameserver)[1:])) //chop off @
nameserver = string([]byte(nameserver)[1:]) // chop off @
_, addr, err := net.LookupHost(nameserver)
if err == nil {
r.Servers = addr
} else {

1
dns.go
View File

@ -8,6 +8,7 @@
// * 1982 - Serial Arithmetic
// * 1034/1035
// * 2671 - EDNS
// * 3225 - DO bit (DNSSEC OK)
// * 4033/4034/4035 - DNSSEC + validation functions
// * 5011 - NSID
// * IP6 support

34
edns.go
View File

@ -6,10 +6,10 @@ import (
// EDNS0 Options and Do bit
const (
OptionCodeLLQ = 1 // Not used
OptionCodeUL = 2 // Not used
OptionCodeNSID = 3 // NSID, RFC5001
_DO = 1 << 7 // dnssec ok
OptionCodeLLQ = 1 // Not used
OptionCodeUL = 2 // Not used
OptionCodeNSID = 3 // NSID, RFC5001
_DO = 1 << 7 // dnssec ok
)
// An ENDS0 option rdata element.
@ -70,19 +70,29 @@ func (rr *RR_OPT) UDPSize(size uint16, set bool) uint16 {
return rr.Hdr.Class
}
/* from RFC 3225
+0 (MSB) +1 (LSB)
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
0: | EXTENDED-RCODE | VERSION |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
2: |DO| Z |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*/
// Set/Get the DoBit
func (rr *RR_OPT) DoBit(do, set bool) bool {
// rr.TTL last 2 bytes, left most bit
// See line 239 in msg.go for TTL encoding
if set {
leftbyte := byte(rr.Hdr.Ttl >> 24)
leftbyte = leftbyte | _DO
rr.Hdr.Ttl = uint32(leftbyte << 24)
b1 := byte(rr.Hdr.Ttl >> 24)
b2 := byte(rr.Hdr.Ttl >> 16)
b3 := byte(rr.Hdr.Ttl >> 8)
b4 := byte(rr.Hdr.Ttl)
b3 |= _DO // Set it
rr.Hdr.Ttl = uint32(b1)<<24 | uint32(b2)<<16 | uint32(b3)<<8 | uint32(b4)
return true
} else {
// jaja?? TODO(MG)
leftbyte := byte(rr.Hdr.Ttl >> 24)
return leftbyte&_DO == 1
b3 := byte(rr.Hdr.Ttl >> 8)
return b3&_DO == _DO
}
return true // dead code, bug in Go
}