EDNS0: implement RFC 7314

Add the new option code.
This commit is contained in:
Miek Gieben 2014-07-21 19:31:28 +01:00
parent 9af5c1f8a8
commit a71489b611
2 changed files with 31 additions and 4 deletions

View File

@ -114,6 +114,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
* 6891 - EDNS0 update
* 6895 - DNS IANA considerations
* 7043 - EUI48/EUI64 records
* 7314 - DNS (EDNS) EXPIRE Option
* xxxx - URI record (draft)
* xxxx - EDNS0 DNS Update Lease (draft)
* xxxx - Algorithm-Signal (draft)
@ -129,7 +130,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
* Support for on-the-fly-signing or check how to do it;
* Ratelimiting? server side (RRL);
* Make a srv.Stop() that stops the server;
* Make a srv.Shutdown() that stops the server;
* privatekey.Precompute() when signing?
* Last remaining RRs: APL, ATMA, A6, KEY, SIG and NXT;
* CAA parsing is broken;

32
edns.go
View File

@ -46,7 +46,7 @@ const (
EDNS0N3U = 0x7 // NSEC3 Hash Understood
EDNS0SUBNET = 0x8 // client-subnet (RFC6891)
EDNS0EXPIRE = 0x9 // EDNS0 expire
EDNS0SUBNETDRAFT = 0x50fa // client-subnet draft: http://tools.ietf.org/html/draft-vandergaast-edns-client-subnet-01
EDNS0SUBNETDRAFT = 0x50fa // Don't use! Use EDNS0SUBNET
_DO = 1 << 7 // dnssec ok
)
@ -335,6 +335,9 @@ type EDNS0_UL struct {
Lease uint32
}
func (e *EDNS0_UL) Option() uint16 { return EDNS0UL }
func (e *EDNS0_UL) String() string { return strconv.FormatUint(uint64(e.Lease), 10) }
// Copied: http://golang.org/src/pkg/net/dnsmsg.go
func (e *EDNS0_UL) pack() ([]byte, error) {
b := make([]byte, 4)
@ -345,7 +348,6 @@ func (e *EDNS0_UL) pack() ([]byte, error) {
return b, nil
}
func (e *EDNS0_UL) Option() uint16 { return EDNS0UL }
func (e *EDNS0_UL) unpack(b []byte) error {
if len(b) < 4 {
return ErrBuf
@ -353,7 +355,6 @@ func (e *EDNS0_UL) unpack(b []byte) error {
e.Lease = uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
return nil
}
func (e *EDNS0_UL) String() string { return strconv.FormatUint(uint64(e.Lease), 10) }
// Long Lived Queries: http://tools.ietf.org/html/draft-sekar-dns-llq-01
// Implemented for completeness, as the EDNS0 type code is assigned.
@ -471,3 +472,28 @@ func (e *EDNS0_N3U) String() string {
}
return s
}
type EDNS0_EXPIRE struct {
Code uint16 // Always EDNS0EXPIRE
Expire uint32
}
func (e *EDNS0_EXPIRE) Option() uint16 { return EDNS0EXPIRE }
func (e *EDNS0_EXPIRE) String() string { return strconv.FormatUint(uint64(e.Expire), 10) }
func (e *EDNS0_EXPIRE) pack() ([]byte, error) {
b := make([]byte, 4)
b[0] = byte(e.Expire >> 24)
b[1] = byte(e.Expire >> 16)
b[2] = byte(e.Expire >> 8)
b[3] = byte(e.Expire)
return b, nil
}
func (e *EDNS0_EXPIRE) unpack(b []byte) error {
if len(b) < 4 {
return ErrBuf
}
e.Expire = uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
return nil
}