aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Maxime Guyot <Miouge1@users.noreply.github.com> 2020-08-10 10:38:18 +0200
committerGravatar GitHub <noreply@github.com> 2020-08-10 10:38:18 +0200
commitb3d08f9b2140f3c6e54c05368319404472e1a431 (patch)
treed1e097d47ec22f9b9f8e138456f8bcf7ea21754d /plugin
parent7d5f5b87a4fb310d442f7ef0d52e3fead0e10d39 (diff)
downloadcoredns-b3d08f9b2140f3c6e54c05368319404472e1a431.tar.gz
coredns-b3d08f9b2140f3c6e54c05368319404472e1a431.tar.zst
coredns-b3d08f9b2140f3c6e54c05368319404472e1a431.zip
plugin/template: Add client IP data (#4034)
Signed-off-by: Maxime Guyot <maxime@root314.com>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/template/README.md1
-rw-r--r--plugin/template/template.go3
-rw-r--r--plugin/template/template_test.go27
3 files changed, 30 insertions, 1 deletions
diff --git a/plugin/template/README.md b/plugin/template/README.md
index 654de86c9..6d0d3b27e 100644
--- a/plugin/template/README.md
+++ b/plugin/template/README.md
@@ -48,6 +48,7 @@ Each resource record is a full-featured [Go template](https://golang.org/pkg/tex
* `.Group` a map of the named capture groups.
* `.Message` the complete incoming DNS message.
* `.Question` the matched question section.
+* `.Remote` client’s IP address
* `.Meta` a function that takes a metadata name and returns the value, if the
metadata plugin is enabled. For example, `.Meta "kubernetes/client-namespace"`
diff --git a/plugin/template/template.go b/plugin/template/template.go
index 4940dc9f4..7f26349d5 100644
--- a/plugin/template/template.go
+++ b/plugin/template/template.go
@@ -48,6 +48,7 @@ type templateData struct {
Type string
Message *dns.Msg
Question *dns.Question
+ Remote string
md map[string]metadata.Func
}
@@ -145,7 +146,7 @@ func executeRRTemplate(server, section string, template *gotmpl.Template, data *
func (t template) match(ctx context.Context, state request.Request) (*templateData, bool, bool) {
q := state.Req.Question[0]
- data := &templateData{md: metadata.ValueFuncs(ctx)}
+ data := &templateData{md: metadata.ValueFuncs(ctx), Remote: state.IP()}
zone := plugin.Zones(t.zones).Matches(state.Name())
if zone == "" {
diff --git a/plugin/template/template_test.go b/plugin/template/template_test.go
index 7e8f988f2..d26012298 100644
--- a/plugin/template/template_test.go
+++ b/plugin/template/template_test.go
@@ -25,6 +25,14 @@ func TestHandler(t *testing.T) {
fall: fall.Root,
zones: []string{"."},
}
+ exampleDomainIPATemplate := template{
+ regex: []*regexp.Regexp{regexp.MustCompile(".*")},
+ answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }} 60 IN A {{ .Remote }}"))},
+ qclass: dns.ClassINET,
+ qtype: dns.TypeA,
+ fall: fall.Root,
+ zones: []string{"."},
+ }
exampleDomainANSTemplate := 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 }}"))},
@@ -197,6 +205,25 @@ func TestHandler(t *testing.T) {
},
},
{
+ name: "ExampleIPMatch",
+ tmpl: exampleDomainIPATemplate,
+ qclass: dns.ClassINET,
+ qtype: dns.TypeA,
+ qname: "test.example.",
+ verifyResponse: func(r *dns.Msg) error {
+ if len(r.Answer) != 1 {
+ return fmt.Errorf("expected 1 answer, got %v", len(r.Answer))
+ }
+ if r.Answer[0].Header().Rrtype != dns.TypeA {
+ return fmt.Errorf("expected an A record answer, got %v", dns.TypeToString[r.Answer[0].Header().Rrtype])
+ }
+ if r.Answer[0].(*dns.A).A.String() != "10.240.0.1" {
+ return fmt.Errorf("expected an A record for 10.95.12.8, got %v", r.Answer[0].String())
+ }
+ return nil
+ },
+ },
+ {
name: "ExampleDomainMatch",
tmpl: exampleDomainATemplate,
qclass: dns.ClassINET,
Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/www/public/assets/fonts (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2021-11-19Fix blog example (#1910)Gravatar Matthew Phillips 1-1/+1
2021-11-19Version Packages (next) (#1907)astro@0.21.0-next.10Gravatar github-actions[bot] 23-21/+28
2021-11-19Remove further dependence on vite package (#1906)Gravatar Matthew Phillips 3-5/+9
2021-11-19Version Packages (next) (#1904)astro@0.21.0-next.9Gravatar github-actions[bot] 23-21/+30
2021-11-19Remove OSX \x00 workaround (#1901)Gravatar Matthew Phillips 2-5/+5
2021-11-19Resolve vite client modules to vendored vite (#1903)Gravatar Matthew Phillips 2-2/+7
2021-11-19[ci] yarn formatGravatar matthewp 1-3/+3
2021-11-19Add Debug tests (#1882)Gravatar Matthew Phillips 4-0/+62
2021-11-19[ci] collect statsGravatar FredKSchott 1-0/+1
2021-11-19Version Packages (next) (#1881)astro@0.21.0-next.8@astrojs/renderer-vue@0.2.0-next.2Gravatar github-actions[bot] 25-23/+42
2021-11-18Improve HMR (#1896)Gravatar Drew Powers 2-10/+18
2021-11-18update depsGravatar Fred K. Schott 5-352/+65
2021-11-18fix #1778Gravatar Fred K. Schott 2-1/+8
2021-11-18Update compiler (#1869)Gravatar Nate Moore 3-11/+6
2021-11-18remove unused remark dependency (#1894)Gravatar Fred K. Schott 2-245/+13
2021-11-18Improve error messages (#1875)Gravatar Drew Powers 39-61/+448
2021-11-18pin astro compiler to older versionGravatar Fred K. Schott 2-5/+5
2021-11-18Update yarn.lock to reflect the state of the package.json files (#1892)Gravatar Jonathan Neal 5-1300/+1000
2021-11-19[ci] yarn formatGravatar FredKSchott 1-5/+3