aboutsummaryrefslogtreecommitdiff
path: root/plugin/template
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-01-09 21:48:32 +0000
committerGravatar GitHub <noreply@github.com> 2018-01-09 21:48:32 +0000
commita19ea63d3a719a98104c74a776afd71d5d94490a (patch)
tree64f50a028e0a9060718389935efa2cce004e5e59 /plugin/template
parent0091e1c9dc0ee093471b8e0d91133ac3c9a51581 (diff)
downloadcoredns-a19ea63d3a719a98104c74a776afd71d5d94490a.tar.gz
coredns-a19ea63d3a719a98104c74a776afd71d5d94490a.tar.zst
coredns-a19ea63d3a719a98104c74a776afd71d5d94490a.zip
plugin/template: small tweaks (#1366)
Small README updates, and fallthrough fixes (using less code)
Diffstat (limited to 'plugin/template')
-rw-r--r--plugin/template/README.md7
-rw-r--r--plugin/template/metrics.go2
-rw-r--r--plugin/template/setup.go7
-rw-r--r--plugin/template/template.go4
-rw-r--r--plugin/template/template_test.go77
5 files changed, 46 insertions, 51 deletions
diff --git a/plugin/template/README.md b/plugin/template/README.md
index c951cac83..13e6137b4 100644
--- a/plugin/template/README.md
+++ b/plugin/template/README.md
@@ -15,8 +15,8 @@ template CLASS TYPE [ZONE...] {
[additional RR]
[authority RR]
[...]
- [rcode responsecode]
- [fallthrough [fallthrough zone...]]
+ [rcode CODE]
+ [fallthrough [ZONE...]]
}
~~~
@@ -28,7 +28,8 @@ template CLASS TYPE [ZONE...] {
build by a [Go template](https://golang.org/pkg/text/template/) that contains the reply.
* `rcode` **CODE** A response code (`NXDOMAIN, SERVFAIL, ...`). The default is `SUCCESS`.
* `fallthrough` Continue with the next plugin if the zone matched but no regex did not match.
-* `fallthrough zone` One or more zones that may fall through to other plugins. Defaults to all zones of the template.
+ If specific zones are listed (for example `in-addr.arpa` and `ip6.arpa`), then only queries for
+ those zones will be subject to fallthrough.
At least one `answer` or `rcode` directive is needed (e.g. `rcode NXDOMAIN`).
diff --git a/plugin/template/metrics.go b/plugin/template/metrics.go
index a963b3a31..4cdaa5321 100644
--- a/plugin/template/metrics.go
+++ b/plugin/template/metrics.go
@@ -6,8 +6,8 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
- "github.com/mholt/caddy"
+ "github.com/mholt/caddy"
"github.com/prometheus/client_golang/prometheus"
)
diff --git a/plugin/template/setup.go b/plugin/template/setup.go
index 2065ef649..616531e49 100644
--- a/plugin/template/setup.go
+++ b/plugin/template/setup.go
@@ -140,12 +140,7 @@ func templateParse(c *caddy.Controller) (handler Handler, err error) {
t.rcode = rcode
case "fallthrough":
- args := c.RemainingArgs()
- if len(args) > 0 {
- t.fthrough.SetZonesFromArgs(c.RemainingArgs())
- } else {
- t.fthrough.SetZonesFromArgs(zones)
- }
+ t.fall.SetZonesFromArgs(c.RemainingArgs())
default:
return handler, c.ArgErr()
diff --git a/plugin/template/template.go b/plugin/template/template.go
index b11292dbd..a45ed0610 100644
--- a/plugin/template/template.go
+++ b/plugin/template/template.go
@@ -31,7 +31,7 @@ type template struct {
authority []*gotmpl.Template
qclass uint16
qtype uint16
- fthrough fall.F
+ fall fall.F
}
type templateData struct {
@@ -177,5 +177,5 @@ func (t template) match(state request.Request, zone string) (templateData, bool,
return data, true, false
}
- return data, false, t.fthrough.Through(state.Name())
+ return data, false, t.fall.Through(state.Name())
}
diff --git a/plugin/template/template_test.go b/plugin/template/template_test.go
index a815e8c7c..0a89be744 100644
--- a/plugin/template/template_test.go
+++ b/plugin/template/template_test.go
@@ -5,26 +5,25 @@ import (
"fmt"
"regexp"
"testing"
-
- "github.com/coredns/coredns/plugin/test"
- "github.com/mholt/caddy"
-
gotmpl "text/template"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/pkg/fall"
+ "github.com/coredns/coredns/plugin/test"
+
+ "github.com/mholt/caddy"
"github.com/miekg/dns"
)
func TestHandler(t *testing.T) {
rcodeFallthrough := 3841 // reserved for private use, used to indicate a fallthrough
exampleDomainATemplate := template{
- regex: []*regexp.Regexp{regexp.MustCompile("(^|[.])ip-10-(?P<b>[0-9]*)-(?P<c>[0-9]*)-(?P<d>[0-9]*)[.]example[.]$")},
- answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }} 60 IN A 10.{{ .Group.b }}.{{ .Group.c }}.{{ .Group.d }}"))},
- qclass: dns.ClassANY,
- qtype: dns.TypeANY,
- fthrough: fall.F{Zones: []string{"."}},
- zones: []string{"."},
+ regex: []*regexp.Regexp{regexp.MustCompile("(^|[.])ip-10-(?P<b>[0-9]*)-(?P<c>[0-9]*)-(?P<d>[0-9]*)[.]example[.]$")},
+ answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }} 60 IN A 10.{{ .Group.b }}.{{ .Group.c }}.{{ .Group.d }}"))},
+ qclass: dns.ClassANY,
+ qtype: dns.TypeANY,
+ fall: fall.F{Zones: []string{"."}},
+ zones: []string{"."},
}
exampleDomainANSTemplate := template{
regex: []*regexp.Regexp{regexp.MustCompile("(^|[.])ip-10-(?P<b>[0-9]*)-(?P<c>[0-9]*)-(?P<d>[0-9]*)[.]example[.]$")},
@@ -33,7 +32,7 @@ func TestHandler(t *testing.T) {
authority: []*gotmpl.Template{gotmpl.Must(gotmpl.New("authority").Parse("example. IN NS ns0.example.com."))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
- fthrough: fall.F{Zones: []string{"."}},
+ fall: fall.F{Zones: []string{"."}},
zones: []string{"."},
}
exampleDomainMXTemplate := template{
@@ -42,48 +41,48 @@ func TestHandler(t *testing.T) {
additional: []*gotmpl.Template{gotmpl.Must(gotmpl.New("additional").Parse("{{ .Name }} 60 IN A 10.{{ .Group.b }}.{{ .Group.c }}.{{ .Group.d }}"))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
- fthrough: fall.F{Zones: []string{"."}},
+ fall: fall.F{Zones: []string{"."}},
zones: []string{"."},
}
invalidDomainTemplate := template{
- regex: []*regexp.Regexp{regexp.MustCompile("[.]invalid[.]$")},
- rcode: dns.RcodeNameError,
- answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("invalid. 60 {{ .Class }} SOA a.invalid. b.invalid. (1 60 60 60 60)"))},
- qclass: dns.ClassANY,
- qtype: dns.TypeANY,
- fthrough: fall.F{Zones: []string{"."}},
- zones: []string{"."},
+ regex: []*regexp.Regexp{regexp.MustCompile("[.]invalid[.]$")},
+ rcode: dns.RcodeNameError,
+ answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("invalid. 60 {{ .Class }} SOA a.invalid. b.invalid. (1 60 60 60 60)"))},
+ qclass: dns.ClassANY,
+ qtype: dns.TypeANY,
+ fall: fall.F{Zones: []string{"."}},
+ zones: []string{"."},
}
rcodeServfailTemplate := template{
- regex: []*regexp.Regexp{regexp.MustCompile(".*")},
- rcode: dns.RcodeServerFailure,
- qclass: dns.ClassANY,
- qtype: dns.TypeANY,
- fthrough: fall.F{Zones: []string{"."}},
- zones: []string{"."},
+ regex: []*regexp.Regexp{regexp.MustCompile(".*")},
+ rcode: dns.RcodeServerFailure,
+ qclass: dns.ClassANY,
+ qtype: dns.TypeANY,
+ fall: fall.F{Zones: []string{"."}},
+ zones: []string{"."},
}
brokenTemplate := template{
- regex: []*regexp.Regexp{regexp.MustCompile("[.]example[.]$")},
- answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }} 60 IN TXT \"{{ index .Match 2 }}\""))},
- qclass: dns.ClassANY,
- qtype: dns.TypeANY,
- fthrough: fall.F{Zones: []string{"."}},
- zones: []string{"."},
+ regex: []*regexp.Regexp{regexp.MustCompile("[.]example[.]$")},
+ answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }} 60 IN TXT \"{{ index .Match 2 }}\""))},
+ qclass: dns.ClassANY,
+ qtype: dns.TypeANY,
+ fall: fall.F{Zones: []string{"."}},
+ zones: []string{"."},
}
nonRRTemplate := template{
- regex: []*regexp.Regexp{regexp.MustCompile("[.]example[.]$")},
- answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }}"))},
- qclass: dns.ClassANY,
- qtype: dns.TypeANY,
- fthrough: fall.F{Zones: []string{"."}},
- zones: []string{"."},
+ regex: []*regexp.Regexp{regexp.MustCompile("[.]example[.]$")},
+ answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }}"))},
+ qclass: dns.ClassANY,
+ qtype: dns.TypeANY,
+ fall: fall.F{Zones: []string{"."}},
+ zones: []string{"."},
}
nonRRAdditionalTemplate := template{
regex: []*regexp.Regexp{regexp.MustCompile("[.]example[.]$")},
additional: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }}"))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
- fthrough: fall.F{Zones: []string{"."}},
+ fall: fall.F{Zones: []string{"."}},
zones: []string{"."},
}
nonRRAuthoritativeTemplate := template{
@@ -91,7 +90,7 @@ func TestHandler(t *testing.T) {
authority: []*gotmpl.Template{gotmpl.Must(gotmpl.New("authority").Parse("{{ .Name }}"))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
- fthrough: fall.F{Zones: []string{"."}},
+ fall: fall.F{Zones: []string{"."}},
zones: []string{"."},
}