small patch for EDNS0 cookie support (#350)
* Add EDNS0 Cookie (option 10) support. * Add EDNS0 Cookie processing. * Fix nits. * Add EDNS0 cookie support mention.
This commit is contained in:
parent
de1d5dd281
commit
b534177a1a
|
@ -62,7 +62,7 @@ Send pull request if you want to be listed here.
|
|||
* Server side programming (mimicking the net/http package);
|
||||
* Client side programming;
|
||||
* DNSSEC: signing, validating and key generation for DSA, RSA and ECDSA;
|
||||
* EDNS0, NSID;
|
||||
* EDNS0, NSID, Cookies;
|
||||
* AXFR/IXFR;
|
||||
* TSIG, SIG(0);
|
||||
* DNS over TLS: optional encrypted connection between client and server;
|
||||
|
@ -141,6 +141,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
|
|||
* 7553 - URI record
|
||||
* xxxx - EDNS0 DNS Update Lease (draft)
|
||||
* yyyy - DNS over TLS: Initiation and Performance Considerations (draft)
|
||||
* xxxx - Domain Name System (DNS) Cookies (draft-ietf-dnsop-cookies)
|
||||
|
||||
## Loosely based upon
|
||||
|
||||
|
|
29
edns.go
29
edns.go
|
@ -17,6 +17,7 @@ const (
|
|||
EDNS0N3U = 0x7 // NSEC3 Hash Understood
|
||||
EDNS0SUBNET = 0x8 // client-subnet (RFC6891)
|
||||
EDNS0EXPIRE = 0x9 // EDNS0 expire
|
||||
EDNS0COOKIE = 0xa // EDNS0 Cookie
|
||||
EDNS0SUBNETDRAFT = 0x50fa // Don't use! Use EDNS0SUBNET
|
||||
EDNS0LOCALSTART = 0xFDE9 // Beginning of range reserved for local/experimental use (RFC6891)
|
||||
EDNS0LOCALEND = 0xFFFE // End of range reserved for local/experimental use (RFC6891)
|
||||
|
@ -56,6 +57,8 @@ func (rr *OPT) String() string {
|
|||
if o.(*EDNS0_SUBNET).DraftOption {
|
||||
s += " (draft)"
|
||||
}
|
||||
case *EDNS0_COOKIE:
|
||||
s += "\n; COOKIE: " + o.String()
|
||||
case *EDNS0_UL:
|
||||
s += "\n; UPDATE LEASE: " + o.String()
|
||||
case *EDNS0_LLQ:
|
||||
|
@ -286,6 +289,32 @@ func (e *EDNS0_SUBNET) String() (s string) {
|
|||
return
|
||||
}
|
||||
|
||||
// The Cookie EDNS0 option
|
||||
//
|
||||
//o := new(dns.OPT)
|
||||
//o.Hdr.Name = "."
|
||||
//o.Hdr.Rrtype = dns.TypeOPT
|
||||
//e := new(dns.EDNS0_COOKIE)
|
||||
//e.Code = dns.EDNS0COOKIE
|
||||
//e.Cookie = "24a5ac.."
|
||||
//o.Option = append(o.Option, e)
|
||||
type EDNS0_COOKIE struct {
|
||||
Code uint16 // Always EDNS0COOKIE
|
||||
Cookie string // Hex-encoded cookie data
|
||||
}
|
||||
|
||||
func (e *EDNS0_COOKIE) pack() ([]byte, error) {
|
||||
h, err := hex.DecodeString(e.Cookie)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func (e *EDNS0_COOKIE) Option() uint16 { return EDNS0COOKIE }
|
||||
func (e *EDNS0_COOKIE) unpack(b []byte) error { e.Cookie = hex.EncodeToString(b); return nil }
|
||||
func (e *EDNS0_COOKIE) String() string { return e.Cookie }
|
||||
|
||||
// The EDNS0_UL (Update Lease) (draft RFC) option is used to tell the server to set
|
||||
// an expiration on an update RR. This is helpful for clients that cannot clean
|
||||
// up after themselves. This is a draft RFC and more information can be found at
|
||||
|
|
7
msg.go
7
msg.go
|
@ -953,6 +953,13 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
|
|||
if code == EDNS0SUBNETDRAFT {
|
||||
e.DraftOption = true
|
||||
}
|
||||
case EDNS0COOKIE:
|
||||
e := new(EDNS0_COOKIE)
|
||||
if err := e.unpack(msg[off1 : off1+int(optlen)]); err != nil {
|
||||
return lenmsg, err
|
||||
}
|
||||
edns = append(edns, e)
|
||||
off = off1 + int(optlen)
|
||||
case EDNS0UL:
|
||||
e := new(EDNS0_UL)
|
||||
if err := e.unpack(msg[off1 : off1+int(optlen)]); err != nil {
|
||||
|
|
Loading…
Reference in New Issue