Skip to content

Commit

Permalink
Add idea for forward based on:
Browse files Browse the repository at this point in the history
    coredns#6549 (comment)

This still needs some work and especially tests
  • Loading branch information
dihmandrake committed May 3, 2024
1 parent a7ed346 commit 49b5b3e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugin/forward/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type Forward struct {
from string
ignored []string

alternateRcodes []int

tlsConfig *tls.Config
tlsServerName string
maxfails uint32
Expand Down Expand Up @@ -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.alternateRcodes {
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
}
Expand Down
16 changes: 16 additions & 0 deletions plugin/forward/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/coredns/caddy"
Expand Down Expand Up @@ -289,7 +290,22 @@ func parseBlock(c *caddy.Controller, f *Forward) error {
}
f.ErrLimitExceeded = errors.New("concurrent queries exceeded maximum " + c.Val())
f.maxConcurrent = int64(n)
case "alternate":
args := c.RemainingArgs()
if len(args) == 0 {
return c.ArgErr()
}

for _, rcode := range args {
var rc int
var ok bool

if rc, ok = dns.StringToRcode[strings.ToUpper(rcode)]; !ok {
return fmt.Errorf("%s is not a valid rcode", rcode)
}

f.alternateRcodes = append(f.alternateRcodes, rc)
}
default:
return c.Errf("unknown property '%s'", c.Val())
}
Expand Down

0 comments on commit 49b5b3e

Please sign in to comment.