aboutsummaryrefslogtreecommitdiff
path: root/middleware/autopath/autopath.go
diff options
context:
space:
mode:
Diffstat (limited to 'middleware/autopath/autopath.go')
-rw-r--r--middleware/autopath/autopath.go36
1 files changed, 17 insertions, 19 deletions
diff --git a/middleware/autopath/autopath.go b/middleware/autopath/autopath.go
index 2c581eadd..d3a8c84d2 100644
--- a/middleware/autopath/autopath.go
+++ b/middleware/autopath/autopath.go
@@ -33,7 +33,7 @@ func (m Middleware ) AutoPath(state request.Request) []string {
*/
import (
- "errors"
+ "log"
"github.com/coredns/coredns/middleware"
"github.com/coredns/coredns/middleware/pkg/dnsutil"
@@ -61,35 +61,33 @@ type AutoPath struct {
// ServeDNS implements the middleware.Handle interface.
func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
state := request.Request{W: w, Req: r}
- if state.QClass() != dns.ClassINET {
- return dns.RcodeServerFailure, middleware.Error(a.Name(), errors.New("can only deal with ClassINET"))
- }
zone := middleware.Zones(a.Zones).Matches(state.Name())
if zone == "" {
return middleware.NextOrFailure(a.Name(), a.Next, ctx, w, r)
}
- // Check if autopath should be done, searchFunc takes precedence over the local configured
- // search path.
+ // Check if autopath should be done, searchFunc takes precedence over the local configured search path.
var err error
searchpath := a.search
+
if a.searchFunc != nil {
searchpath = a.searchFunc(state)
- if len(searchpath) == 0 {
- return middleware.NextOrFailure(a.Name(), a.Next, ctx, w, r)
- }
}
- match := a.FirstInSearchPath(state.Name())
- if !match {
+ if len(searchpath) == 0 {
+ log.Printf("[WARNING] No search path available for autopath")
+ return middleware.NextOrFailure(a.Name(), a.Next, ctx, w, r)
+ }
+
+ if !firstInSearchPath(state.Name(), searchpath) {
return middleware.NextOrFailure(a.Name(), a.Next, ctx, w, r)
}
origQName := state.QName()
// Establish base name of the query. I.e what was originally asked.
- base, err := dnsutil.TrimZone(state.QName(), a.search[0]) // TODO(miek): we loose the original case of the query here.
+ base, err := dnsutil.TrimZone(state.QName(), searchpath[0]) // TODO(miek): we loose the original case of the query here.
if err != nil {
return dns.RcodeServerFailure, err
}
@@ -140,16 +138,16 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
return firstRcode, firstErr
}
-// FirstInSearchPath checks if name is equal to are a sibling of the first element in the search path.
-func (a *AutoPath) FirstInSearchPath(name string) bool {
- if name == a.search[0] {
+// Name implements the Handler interface.
+func (a *AutoPath) Name() string { return "autopath" }
+
+// firstInSearchPath checks if name is equal to are a sibling of the first element in the search path.
+func firstInSearchPath(name string, searchpath []string) bool {
+ if name == searchpath[0] {
return true
}
- if dns.IsSubDomain(a.search[0], name) {
+ if dns.IsSubDomain(searchpath[0], name) {
return true
}
return false
}
-
-// Name implements the Handler interface.
-func (a *AutoPath) Name() string { return "autopath" }