From 034f791cf85670b06a2b57c62ca0a815af839c67 Mon Sep 17 00:00:00 2001 From: Brian Shea <67546897+brian5hea@users.noreply.github.com> Date: Thu, 20 Aug 2020 02:41:45 -0400 Subject: [PATCH] answer queries with no matching handler with RcodeRefused (#1151) * answer queries with no matching handler with RcodeRefused * update documentation * mark HandleFailed deprecated * add handleRefused and use it to answer requests matching no handler * silence noise maker Co-authored-by: Brian --- serve_mux.go | 4 ++-- server.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/serve_mux.go b/serve_mux.go index aadb0bf0..e7f36e22 100644 --- a/serve_mux.go +++ b/serve_mux.go @@ -91,7 +91,7 @@ func (mux *ServeMux) HandleRemove(pattern string) { // are redirected to the parent zone (if that is also registered), // otherwise the child gets the query. // -// If no handler is found, or there is no question, a standard SERVFAIL +// If no handler is found, or there is no question, a standard REFUSED // message is returned func (mux *ServeMux) ServeDNS(w ResponseWriter, req *Msg) { var h Handler @@ -102,7 +102,7 @@ func (mux *ServeMux) ServeDNS(w ResponseWriter, req *Msg) { if h != nil { h.ServeDNS(w, req) } else { - HandleFailed(w, req) + handleRefused(w, req) } } diff --git a/server.go b/server.go index 3cf1a024..77b43dea 100644 --- a/server.go +++ b/server.go @@ -78,7 +78,15 @@ type response struct { writer Writer // writer to output the raw DNS bits } +// handleRefused returns a HandlerFunc that returns REFUSED for every request it gets. +func handleRefused(w ResponseWriter, r *Msg) { + m := new(Msg) + m.SetRcode(r, RcodeRefused) + w.WriteMsg(m) +} + // HandleFailed returns a HandlerFunc that returns SERVFAIL for every request it gets. +// Deprecated: This function is going away. func HandleFailed(w ResponseWriter, r *Msg) { m := new(Msg) m.SetRcode(r, RcodeServerFailure)