Commit 468d5b57 authored by Miek Gieben's avatar Miek Gieben Committed by GitHub

core: export ClientWrite (#849)

Make ClientWrite available for middleware to use.
parent 760e6670
...@@ -205,7 +205,7 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ...@@ -205,7 +205,7 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
if h, ok := s.zones[string(b[:l])]; ok { if h, ok := s.zones[string(b[:l])]; ok {
if r.Question[0].Qtype != dns.TypeDS { if r.Question[0].Qtype != dns.TypeDS {
rcode, _ := h.middlewareChain.ServeDNS(ctx, w, r) rcode, _ := h.middlewareChain.ServeDNS(ctx, w, r)
if rcodeNoClientWrite(rcode) { if !middleware.ClientWrite(rcode) {
DefaultErrorFunc(w, r, rcode) DefaultErrorFunc(w, r, rcode)
} }
return return
...@@ -226,7 +226,7 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ...@@ -226,7 +226,7 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
if dshandler != nil { if dshandler != nil {
// DS request, and we found a zone, use the handler for the query // DS request, and we found a zone, use the handler for the query
rcode, _ := dshandler.middlewareChain.ServeDNS(ctx, w, r) rcode, _ := dshandler.middlewareChain.ServeDNS(ctx, w, r)
if rcodeNoClientWrite(rcode) { if !middleware.ClientWrite(rcode) {
DefaultErrorFunc(w, r, rcode) DefaultErrorFunc(w, r, rcode)
} }
return return
...@@ -235,7 +235,7 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ...@@ -235,7 +235,7 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
// Wildcard match, if we have found nothing try the root zone as a last resort. // Wildcard match, if we have found nothing try the root zone as a last resort.
if h, ok := s.zones["."]; ok { if h, ok := s.zones["."]; ok {
rcode, _ := h.middlewareChain.ServeDNS(ctx, w, r) rcode, _ := h.middlewareChain.ServeDNS(ctx, w, r)
if rcodeNoClientWrite(rcode) { if !middleware.ClientWrite(rcode) {
DefaultErrorFunc(w, r, rcode) DefaultErrorFunc(w, r, rcode)
} }
return return
...@@ -282,20 +282,6 @@ func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rc int) { ...@@ -282,20 +282,6 @@ func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rc int) {
w.WriteMsg(answer) w.WriteMsg(answer)
} }
func rcodeNoClientWrite(rcode int) bool {
switch rcode {
case dns.RcodeServerFailure:
fallthrough
case dns.RcodeRefused:
fallthrough
case dns.RcodeFormatError:
fallthrough
case dns.RcodeNotImplemented:
return true
}
return false
}
const ( const (
tcp = 0 tcp = 0
udp = 1 udp = 1
......
...@@ -82,5 +82,21 @@ func NextOrFailure(name string, next Handler, ctx context.Context, w dns.Respons ...@@ -82,5 +82,21 @@ func NextOrFailure(name string, next Handler, ctx context.Context, w dns.Respons
return dns.RcodeServerFailure, Error(name, errors.New("no next middleware found")) return dns.RcodeServerFailure, Error(name, errors.New("no next middleware found"))
} }
// ClientWrite returns true if the response has been written to the client.
// Each middleware to adhire to this protocol.
func ClientWrite(rcode int) bool {
switch rcode {
case dns.RcodeServerFailure:
fallthrough
case dns.RcodeRefused:
fallthrough
case dns.RcodeFormatError:
fallthrough
case dns.RcodeNotImplemented:
return false
}
return true
}
// Namespace is the namespace used for the metrics. // Namespace is the namespace used for the metrics.
const Namespace = "coredns" const Namespace = "coredns"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment