plugin/forward: Forward NODATA responses to Next handler (#8065)

This commit is contained in:
Jöran Malek
2026-05-27 02:15:46 +02:00
committed by GitHub
parent 17142359e0
commit eb49f402cc
4 changed files with 109 additions and 0 deletions

View File

@@ -44,6 +44,7 @@ type Forward struct {
ignored []string
nextAlternateRcodes []int
nextOnNodata bool
tlsConfig *tls.Config
tlsServerName string
@@ -245,6 +246,14 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
}
}
if f.nextOnNodata && f.Next != nil {
if ret.Rcode == dns.RcodeSuccess && isEmpty(ret) {
if _, ok := f.Next.(*Forward); ok {
return plugin.NextOrFailure(f.Name(), f.Next, ctx, w, r)
}
}
}
w.WriteMsg(ret)
return 0, nil
}
@@ -277,6 +286,19 @@ func (f *Forward) isAllowedDomain(name string) bool {
return true
}
func isEmpty(r *dns.Msg) bool {
if len(r.Answer) == 0 {
return true
}
for _, r := range r.Answer {
if r != nil {
return false
}
}
return true
}
// ForceTCP returns if TCP is forced to be used even when the request comes in over UDP.
func (f *Forward) ForceTCP() bool { return f.opts.ForceTCP }