From a71489b611edec79031f3911a07e706897594c31 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 21 Jul 2014 19:31:28 +0100 Subject: [PATCH] EDNS0: implement RFC 7314 Add the new option code. --- README.md | 3 ++- edns.go | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 27cd7387..3c04d625 100644 --- a/README.md +++ b/README.md @@ -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; diff --git a/edns.go b/edns.go index 127f37ee..f075719b 100644 --- a/edns.go +++ b/edns.go @@ -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 +}