mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	EDNS: return error on wrong version. (#95)
Split up the previous changes a bit. This PR only returns the expected error when the received packet has the wrong EDNS version. EDNS0 handling in the middleware needs a nicer abstraction, like ReflectEdns() or something.
This commit is contained in:
		| @@ -12,10 +12,10 @@ import ( | ||||
| 	"net" | ||||
| 	"os" | ||||
| 	"runtime" | ||||
| 	"strconv" | ||||
| 	"sync" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/miekg/coredns/middleware" | ||||
| 	"github.com/miekg/coredns/middleware/chaos" | ||||
| 	"github.com/miekg/coredns/middleware/prometheus" | ||||
|  | ||||
| @@ -279,6 +279,14 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) { | ||||
| 		} | ||||
| 	}() | ||||
|  | ||||
| 	if m, err := middleware.Edns0Version(r); err != nil { // Wrong EDNS version, return at once. | ||||
| 		qtype := dns.Type(r.Question[0].Qtype).String() | ||||
| 		rc := middleware.RcodeToString(dns.RcodeBadVers) | ||||
| 		metrics.Report(dropped, qtype, rc, m.Len(), time.Now()) | ||||
| 		w.WriteMsg(m) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	// Execute the optional request callback if it exists | ||||
| 	if s.ReqCallback != nil && s.ReqCallback(w, r) { | ||||
| 		return | ||||
| @@ -332,12 +340,7 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) { | ||||
| // of the specified HTTP status code. | ||||
| func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rcode int) { | ||||
| 	qtype := dns.Type(r.Question[0].Qtype).String() | ||||
|  | ||||
| 	// this code is duplicated a few times, TODO(miek) | ||||
| 	rc := dns.RcodeToString[rcode] | ||||
| 	if rc == "" { | ||||
| 		rc = "RCODE" + strconv.Itoa(rcode) | ||||
| 	} | ||||
| 	rc := middleware.RcodeToString(rcode) | ||||
|  | ||||
| 	answer := new(dns.Msg) | ||||
| 	answer.SetRcode(r, rcode) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user