Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
2cad04ec
Commit
2cad04ec
authored
Feb 16, 2018
by
Chris O'Haver
Committed by
Miek Gieben
Feb 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin/template: add upstream option (#1529)
* add upstream * docs * tests
parent
ba573c0f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
1 deletion
+33
-1
plugin/template/README.md
plugin/template/README.md
+4
-0
plugin/template/setup.go
plugin/template/setup.go
+8
-0
plugin/template/setup_test.go
plugin/template/setup_test.go
+14
-0
plugin/template/template.go
plugin/template/template.go
+7
-1
No files found.
plugin/template/README.md
View file @
2cad04ec
...
@@ -18,6 +18,7 @@ template CLASS TYPE [ZONE...] {
...
@@ -18,6 +18,7 @@ template CLASS TYPE [ZONE...] {
[authority RR]
[authority RR]
[...]
[...]
[rcode CODE]
[rcode CODE]
[upstream [ADDRESS...]]
[fallthrough [ZONE...]]
[fallthrough [ZONE...]]
}
}
~~~
~~~
...
@@ -29,6 +30,9 @@ template CLASS TYPE [ZONE...] {
...
@@ -29,6 +30,9 @@ template CLASS TYPE [ZONE...] {
*
`answer|additional|authority`
**RR**
A
[
RFC 1035
](
https://tools.ietf.org/html/rfc1035#section-5
)
style resource record fragment
*
`answer|additional|authority`
**RR**
A
[
RFC 1035
](
https://tools.ietf.org/html/rfc1035#section-5
)
style resource record fragment
built by a
[
Go template
](
https://golang.org/pkg/text/template/
)
that contains the reply.
built 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`
.
*
`rcode`
**CODE**
A response code (
`NXDOMAIN, SERVFAIL, ...`
). The default is
`SUCCESS`
.
*
`upstream`
[
**ADDRESS**
...] defines the upstream resolvers used for resolving CNAME.
If no
**ADDRESS**
is given, CoreDNS will resolve CNAMEs against itself.
**ADDRESS**
can be an IP, an IP:port, or a path to a file structured like resolv.conf.
*
`fallthrough`
Continue with the next plugin if the zone matched but no regex matched.
*
`fallthrough`
Continue with the next plugin if the zone matched but no regex matched.
If specific zones are listed (for example
`in-addr.arpa`
and
`ip6.arpa`
), then only queries for
If specific zones are listed (for example
`in-addr.arpa`
and
`ip6.arpa`
), then only queries for
those zones will be subject to fallthrough.
those zones will be subject to fallthrough.
...
...
plugin/template/setup.go
View file @
2cad04ec
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/mholt/caddy"
"github.com/mholt/caddy"
"github.com/miekg/dns"
"github.com/miekg/dns"
...
@@ -142,6 +143,13 @@ func templateParse(c *caddy.Controller) (handler Handler, err error) {
...
@@ -142,6 +143,13 @@ func templateParse(c *caddy.Controller) (handler Handler, err error) {
case
"fallthrough"
:
case
"fallthrough"
:
t
.
fall
.
SetZonesFromArgs
(
c
.
RemainingArgs
())
t
.
fall
.
SetZonesFromArgs
(
c
.
RemainingArgs
())
case
"upstream"
:
args
:=
c
.
RemainingArgs
()
u
,
err
:=
upstream
.
NewUpstream
(
args
)
if
err
!=
nil
{
return
handler
,
err
}
t
.
upstream
=
u
default
:
default
:
return
handler
,
c
.
ArgErr
()
return
handler
,
c
.
ArgErr
()
}
}
...
...
plugin/template/setup_test.go
View file @
2cad04ec
...
@@ -133,6 +133,20 @@ func TestSetupParse(t *testing.T) {
...
@@ -133,6 +133,20 @@ func TestSetupParse(t *testing.T) {
}`
,
}`
,
false
,
false
,
},
},
{
`template ANY ANY up.stream.local {
answer "up.stream.local 5 IN CNAME up.river.local"
upstream
}`
,
false
,
},
{
`template ANY ANY up.stream.local {
answer "up.stream.local 5 IN CNAME up.river.local"
upstream invalid-upstream-argument
}`
,
true
,
},
}
}
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
c
:=
caddy
.
NewTestController
(
"dns"
,
test
.
inputFileRules
)
c
:=
caddy
.
NewTestController
(
"dns"
,
test
.
inputFileRules
)
...
...
plugin/template/template.go
View file @
2cad04ec
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/fall"
"github.com/coredns/coredns/plugin/pkg/fall"
"github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/coredns/coredns/request"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
"github.com/miekg/dns"
...
@@ -32,6 +33,7 @@ type template struct {
...
@@ -32,6 +33,7 @@ type template struct {
qclass
uint16
qclass
uint16
qtype
uint16
qtype
uint16
fall
fall
.
F
fall
fall
.
F
upstream
upstream
.
Upstream
}
}
type
templateData
struct
{
type
templateData
struct
{
...
@@ -48,7 +50,7 @@ type templateData struct {
...
@@ -48,7 +50,7 @@ type templateData struct {
// ServeDNS implements the plugin.Handler interface.
// ServeDNS implements the plugin.Handler interface.
func
(
h
Handler
)
ServeDNS
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
func
(
h
Handler
)
ServeDNS
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
state
:=
request
.
Request
{
W
:
w
,
Req
:
r
}
state
:=
request
.
Request
{
W
:
w
,
Req
:
r
,
Context
:
ctx
}
zone
:=
plugin
.
Zones
(
h
.
Zones
)
.
Matches
(
state
.
Name
())
zone
:=
plugin
.
Zones
(
h
.
Zones
)
.
Matches
(
state
.
Name
())
if
zone
==
""
{
if
zone
==
""
{
...
@@ -81,6 +83,10 @@ func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
...
@@ -81,6 +83,10 @@ func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
return
dns
.
RcodeServerFailure
,
err
return
dns
.
RcodeServerFailure
,
err
}
}
msg
.
Answer
=
append
(
msg
.
Answer
,
rr
)
msg
.
Answer
=
append
(
msg
.
Answer
,
rr
)
if
rr
.
Header
()
.
Rrtype
==
dns
.
TypeCNAME
{
up
,
_
:=
template
.
upstream
.
Lookup
(
state
,
rr
.
(
*
dns
.
CNAME
)
.
Target
,
dns
.
TypeA
)
msg
.
Answer
=
append
(
msg
.
Answer
,
up
.
Answer
...
)
}
}
}
for
_
,
additional
:=
range
template
.
additional
{
for
_
,
additional
:=
range
template
.
additional
{
rr
,
err
:=
executeRRTemplate
(
"additional"
,
additional
,
data
)
rr
,
err
:=
executeRRTemplate
(
"additional"
,
additional
,
data
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment