From e650aae18be9a84f9cc7e56aeaa2ab33848173d0 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Wed, 22 Dec 2010 10:30:41 +0100 Subject: [PATCH] EDNS impl. Needs more work, especially in the handling of the RR.Hdr which is diff. for EDNS rrs --- Makefile | 1 + edns | 11 ----------- edns.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ types.go | 34 ---------------------------------- 4 files changed, 52 insertions(+), 45 deletions(-) delete mode 100644 edns create mode 100644 edns.go diff --git a/Makefile b/Makefile index f92b0c71..0b822cd7 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ GOFILES=\ msg.go\ resolver.go \ types.go\ + edns.go \ include $(GOROOT)/src/Make.pkg diff --git a/edns b/edns deleted file mode 100644 index a6c1d0cd..00000000 --- a/edns +++ /dev/null @@ -1,11 +0,0 @@ -EDNS - -edns is just an rr in the additional section. So define it like that. -However you can set all kind of stuff in the RR, which are not allowed -for other RR's. - -Create some helper function that use it. udp size, stuff like that -version is always 0 - -set_nsid rfc -set_do rfc3225.txt diff --git a/edns.go b/edns.go new file mode 100644 index 00000000..0190eabd --- /dev/null +++ b/edns.go @@ -0,0 +1,51 @@ +package dns + +// This is the base layer for ENDS, in practise +// You'll only need to set updsize, do bit + + +const ( + OptionCodeLLQ = 1 + OptionCodeUL = 2 + OptionCodeNSID = 3 + // EDNS flag bits (put in Z section) + _DO = 1 << 15 // dnssec ok +) + +// Need PackOption I guess?? TODO +type Edns0Option struct { + Code uint16 +// Length uint16 + Data string "hex" // len(data) is must be encode in packet +} + +// EDNS extended RR. +type EDNS0_Header struct { + Name string "extended-name" + Opt uint16 // was type + 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 +} + +type RR_EDNS0 struct { + Hdr RR_Header // this must become a EDNS0_Header + Option []Edns0Option +} + +func (rr *RR_EDNS0) Header() *RR_Header { + return &rr.Hdr +} + +func (rr *RR_EDNS0) String() string { + var s string + for _, o := range rr.Option { + switch o.Code { + case OptionCodeNSID: + s += "NSID: " + o.Data + } + } + return s +} diff --git a/types.go b/types.go index 6877d796..907c157d 100644 --- a/types.go +++ b/types.go @@ -69,10 +69,6 @@ const ( RcodeNameError = 3 RcodeNotImplemented = 4 RcodeRefused = 5 - - // Edns0 options - EdnsNsidCode = 3 - EdnsNsidLength = 1 ) // The wire format for the DNS packet header. @@ -92,8 +88,6 @@ const ( _Z = 1 << 6 // Z _AD = 1 << 5 // authticated data _CD = 1 << 4 // checking disabled - // EDNS flag bits - _DO = 1 << 15 // dnssec ok ) const ( @@ -123,21 +117,6 @@ func (q *Question) String() string { return s } -/* -// EDNS extended RR. -type EDNS0_Header struct { - Name string "extended-name" - Opt uint16 // was type - UDPSize uint16 // was class - ExtendedRcode uint8 // was TTL - Version uint8 // was TTL -// Flags uint16 // was TTL - Dnssec_ok bool - Rdlength uint16 -} -*/ - - // DNS responses (resource records). // There are many types of messages, // but they all share the same header. @@ -179,19 +158,6 @@ type RR interface { String() string } -type RR_EDNS0 struct { - Hdr RR_Header "edns" -// Option []Edns "edns" TODO -} - -func (rr *RR_EDNS0) Header() *RR_Header { - return &rr.Hdr -} - -func (rr *RR_EDNS0) String() string { - return "BOE" -} - type RR_CNAME struct { Hdr RR_Header Cname string "domain-name"