2010-12-22 20:30:41 +11:00
|
|
|
package dns
|
|
|
|
|
2010-12-28 00:31:31 +11:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2010-12-31 00:13:28 +11:00
|
|
|
// EDNS0 Options and Do bit
|
2010-12-22 20:30:41 +11:00
|
|
|
const (
|
2010-12-31 04:42:40 +11:00
|
|
|
OptionCodeLLQ = 1 // Not used
|
|
|
|
OptionCodeUL = 2 // Not used
|
|
|
|
OptionCodeNSID = 3 // NSID, RFC5001
|
|
|
|
_DO = 1 << 7 // dnssec ok
|
2010-12-22 20:30:41 +11:00
|
|
|
)
|
|
|
|
|
2010-12-25 23:09:27 +11:00
|
|
|
// An ENDS0 option rdata element.
|
2010-12-22 22:26:50 +11:00
|
|
|
type Option struct {
|
2010-12-23 21:02:01 +11:00
|
|
|
Code uint16
|
|
|
|
Data string "hex"
|
2010-12-22 20:30:41 +11:00
|
|
|
}
|
|
|
|
|
2010-12-28 19:41:54 +11:00
|
|
|
/*
|
|
|
|
* EDNS extended RR.
|
|
|
|
* 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
|
|
|
|
*/
|
2010-12-22 20:30:41 +11:00
|
|
|
|
2010-12-23 06:53:18 +11:00
|
|
|
type RR_OPT struct {
|
2010-12-27 19:58:45 +11:00
|
|
|
Hdr RR_Header
|
2010-12-28 00:31:31 +11:00
|
|
|
Option []Option "OPT" // Tag is used in pack and unpack
|
2010-12-27 19:58:45 +11:00
|
|
|
}
|
|
|
|
|
2010-12-23 06:53:18 +11:00
|
|
|
func (rr *RR_OPT) Header() *RR_Header {
|
2010-12-23 21:02:01 +11:00
|
|
|
return &rr.Hdr
|
2010-12-22 20:30:41 +11:00
|
|
|
}
|
|
|
|
|
2010-12-23 06:53:18 +11:00
|
|
|
func (rr *RR_OPT) String() string {
|
2010-12-28 00:31:31 +11:00
|
|
|
s := ";; EDNS: version " + strconv.Itoa(int(rr.Version(0, false))) + "; "
|
|
|
|
if rr.DoBit(false, false) {
|
|
|
|
s += "flags: do; "
|
|
|
|
} else {
|
|
|
|
s += "flags: ; "
|
|
|
|
}
|
|
|
|
s += "udp: " + strconv.Itoa(int(rr.UDPSize(0, false))) + ";"
|
|
|
|
|
2010-12-23 21:02:01 +11:00
|
|
|
for _, o := range rr.Option {
|
|
|
|
switch o.Code {
|
|
|
|
case OptionCodeNSID:
|
2010-12-28 00:31:31 +11:00
|
|
|
s += " nsid: " + o.Data + ";"
|
2010-12-23 21:02:01 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return s
|
2010-12-22 20:30:41 +11:00
|
|
|
}
|
2010-12-24 00:27:04 +11:00
|
|
|
|
2010-12-31 00:13:28 +11:00
|
|
|
// Set the version of edns
|
2010-12-28 00:31:31 +11:00
|
|
|
func (rr *RR_OPT) Version(v uint8, set bool) uint8 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2010-12-31 00:13:28 +11:00
|
|
|
// Set/Get the UDP buffer size
|
2010-12-28 00:31:31 +11:00
|
|
|
func (rr *RR_OPT) UDPSize(size uint16, set bool) uint16 {
|
|
|
|
if set {
|
|
|
|
rr.Hdr.Class = size
|
|
|
|
}
|
|
|
|
return rr.Hdr.Class
|
2010-12-24 00:27:04 +11:00
|
|
|
}
|
|
|
|
|
2010-12-31 04:42:40 +11:00
|
|
|
|
|
|
|
/* from RFC 3225
|
|
|
|
+0 (MSB) +1 (LSB)
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
|
|
|
0: | EXTENDED-RCODE | VERSION |
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
|
|
|
2: |DO| Z |
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
|
|
|
*/
|
|
|
|
|
2010-12-31 01:22:13 +11:00
|
|
|
// Set/Get the DoBit
|
2010-12-24 00:27:04 +11:00
|
|
|
func (rr *RR_OPT) DoBit(do, set bool) bool {
|
2010-12-28 00:31:31 +11:00
|
|
|
if set {
|
2010-12-31 04:42:40 +11:00
|
|
|
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)
|
2010-12-28 00:31:31 +11:00
|
|
|
return true
|
|
|
|
} else {
|
2011-01-02 08:40:55 +11:00
|
|
|
return byte(rr.Hdr.Ttl >> 8) &_DO == _DO
|
2010-12-28 00:31:31 +11:00
|
|
|
}
|
|
|
|
return true // dead code, bug in Go
|
2010-12-24 00:27:04 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
// when set is true, set the nsid, otherwise get it
|
|
|
|
func (rr *RR_OPT) Nsid(nsid string, set bool) string {
|
2010-12-28 00:31:31 +11:00
|
|
|
// RR.Option[0] to be set
|
|
|
|
return ""
|
2010-12-24 00:27:04 +11:00
|
|
|
}
|