mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
Add alternate option to forward plugin (#6681)
Allows the forward plugin to execute the next plugin based on the return code. Similar to the externally mainted alternate plugin https://github.com/coredns/alternate Based on the idea of chrisohaver@ in #6549 (comment) Also incoperated the request to rename `alternate` to `next` as an option I am having issues adding a proper test for functionality. Primarily, I do not know the code base enough and having multiple `dnstest.NewServer` with ResponseWriter does not work. From my testing these are "Singletons'' and only the last defined response writer is used for all servers Signed-off-by: Jasper Bernhardt <jasper.bernhardt@live.de>
This commit is contained in:
@@ -43,6 +43,8 @@ type Forward struct {
|
||||
from string
|
||||
ignored []string
|
||||
|
||||
nextAlternateRcodes []int
|
||||
|
||||
tlsConfig *tls.Config
|
||||
tlsServerName string
|
||||
maxfails uint32
|
||||
@@ -194,6 +196,15 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// Check if we have an alternate Rcode defined, check if we match on the code
|
||||
for _, alternateRcode := range f.nextAlternateRcodes {
|
||||
if alternateRcode == ret.Rcode && f.Next != nil { // In case we do not have a Next handler, just continue normally
|
||||
if _, ok := f.Next.(*Forward); ok { // Only continue if the next forwarder is also a Forworder
|
||||
return plugin.NextOrFailure(f.Name(), f.Next, ctx, w, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w.WriteMsg(ret)
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user