mirror of
https://github.com/coredns/coredns.git
synced 2026-06-02 23:30:25 -04:00
plugin/forward: Forward NODATA responses to Next handler (#8065)
This commit is contained in:
@@ -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 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user