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
f636930c
Commit
f636930c
authored
Feb 06, 2018
by
Paul Greenberg
Committed by
Miek Gieben
Feb 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin/rewrite: rewrite responses for all record types (#1460) (#1463)
parent
367ed65f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
2 deletions
+71
-2
plugin/rewrite/reverter.go
plugin/rewrite/reverter.go
+2
-2
plugin/rewrite/reverter_test.go
plugin/rewrite/reverter_test.go
+59
-0
plugin/test/helpers.go
plugin/test/helpers.go
+10
-0
No files found.
plugin/rewrite/reverter.go
View file @
f636930c
...
@@ -38,7 +38,7 @@ func (r *ResponseReverter) WriteMsg(res *dns.Msg) error {
...
@@ -38,7 +38,7 @@ func (r *ResponseReverter) WriteMsg(res *dns.Msg) error {
res
.
Question
[
0
]
=
r
.
originalQuestion
res
.
Question
[
0
]
=
r
.
originalQuestion
if
r
.
ResponseRewrite
{
if
r
.
ResponseRewrite
{
for
_
,
rr
:=
range
res
.
Answer
{
for
_
,
rr
:=
range
res
.
Answer
{
name
:=
rr
.
(
*
dns
.
A
)
.
Hdr
.
Name
name
:=
rr
.
Header
()
.
Name
for
_
,
rule
:=
range
r
.
ResponseRules
{
for
_
,
rule
:=
range
r
.
ResponseRules
{
regexGroups
:=
rule
.
Pattern
.
FindStringSubmatch
(
name
)
regexGroups
:=
rule
.
Pattern
.
FindStringSubmatch
(
name
)
if
len
(
regexGroups
)
==
0
{
if
len
(
regexGroups
)
==
0
{
...
@@ -53,7 +53,7 @@ func (r *ResponseReverter) WriteMsg(res *dns.Msg) error {
...
@@ -53,7 +53,7 @@ func (r *ResponseReverter) WriteMsg(res *dns.Msg) error {
}
}
name
=
s
name
=
s
}
}
rr
.
(
*
dns
.
A
)
.
Hdr
.
Name
=
name
rr
.
Header
()
.
Name
=
name
}
}
}
}
return
r
.
ResponseWriter
.
WriteMsg
(
res
)
return
r
.
ResponseWriter
.
WriteMsg
(
res
)
...
...
plugin/rewrite/reverter_test.go
0 → 100644
View file @
f636930c
package
rewrite
import
(
"testing"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
"golang.org/x/net/context"
)
func
TestResponseReverter
(
t
*
testing
.
T
)
{
rules
:=
[]
Rule
{}
r
,
_
:=
newNameRule
(
"stop"
,
"regex"
,
`(core)\.(dns)\.(rocks)`
,
"{2}.{1}.{3}"
,
"answer"
,
"name"
,
`(dns)\.(core)\.(rocks)`
,
"{2}.{1}.{3}"
)
rules
=
append
(
rules
,
r
)
tests
:=
[]
struct
{
from
string
fromType
uint16
answer
[]
dns
.
RR
to
string
toType
uint16
noRevert
bool
}{
{
"core.dns.rocks"
,
dns
.
TypeA
,
[]
dns
.
RR
{
test
.
A
(
"dns.core.rocks. 5 IN A 10.0.0.1"
)},
"core.dns.rocks"
,
dns
.
TypeA
,
false
},
{
"core.dns.rocks"
,
dns
.
TypeSRV
,
[]
dns
.
RR
{
test
.
SRV
(
"dns.core.rocks. 5 IN SRV 0 100 100 srv1.dns.core.rocks."
)},
"core.dns.rocks"
,
dns
.
TypeSRV
,
false
},
{
"core.dns.rocks"
,
dns
.
TypeA
,
[]
dns
.
RR
{
test
.
A
(
"core.dns.rocks. 5 IN A 10.0.0.1"
)},
"dns.core.rocks."
,
dns
.
TypeA
,
true
},
{
"core.dns.rocks"
,
dns
.
TypeSRV
,
[]
dns
.
RR
{
test
.
SRV
(
"core.dns.rocks. 5 IN SRV 0 100 100 srv1.dns.core.rocks."
)},
"dns.core.rocks."
,
dns
.
TypeSRV
,
true
},
{
"core.dns.rocks"
,
dns
.
TypeHINFO
,
[]
dns
.
RR
{
test
.
HINFO
(
"core.dns.rocks. 5 HINFO INTEL-64
\"
RHEL 7.4
\"
"
)},
"core.dns.rocks"
,
dns
.
TypeHINFO
,
false
},
{
"core.dns.rocks"
,
dns
.
TypeA
,
[]
dns
.
RR
{
test
.
A
(
"dns.core.rocks. 5 IN A 10.0.0.1"
),
test
.
A
(
"dns.core.rocks. 5 IN A 10.0.0.2"
),
},
"core.dns.rocks"
,
dns
.
TypeA
,
false
},
}
ctx
:=
context
.
TODO
()
for
i
,
tc
:=
range
tests
{
m
:=
new
(
dns
.
Msg
)
m
.
SetQuestion
(
tc
.
from
,
tc
.
fromType
)
m
.
Question
[
0
]
.
Qclass
=
dns
.
ClassINET
m
.
Answer
=
tc
.
answer
rw
:=
Rewrite
{
Next
:
plugin
.
HandlerFunc
(
msgPrinter
),
Rules
:
rules
,
noRevert
:
tc
.
noRevert
,
}
rec
:=
dnstest
.
NewRecorder
(
&
test
.
ResponseWriter
{})
rw
.
ServeDNS
(
ctx
,
rec
,
m
)
resp
:=
rec
.
Msg
if
resp
.
Question
[
0
]
.
Name
!=
tc
.
to
{
t
.
Errorf
(
"Test %d: Expected Name to be %q but was %q"
,
i
,
tc
.
to
,
resp
.
Question
[
0
]
.
Name
)
}
if
resp
.
Question
[
0
]
.
Qtype
!=
tc
.
toType
{
t
.
Errorf
(
"Test %d: Expected Type to be '%d' but was '%d'"
,
i
,
tc
.
toType
,
resp
.
Question
[
0
]
.
Qtype
)
}
}
}
plugin/test/helpers.go
View file @
f636930c
...
@@ -81,6 +81,9 @@ func PTR(rr string) *dns.PTR { r, _ := dns.NewRR(rr); return r.(*dns.PTR) }
...
@@ -81,6 +81,9 @@ func PTR(rr string) *dns.PTR { r, _ := dns.NewRR(rr); return r.(*dns.PTR) }
// TXT returns a TXT record from rr. It panics on errors.
// TXT returns a TXT record from rr. It panics on errors.
func
TXT
(
rr
string
)
*
dns
.
TXT
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
TXT
)
}
func
TXT
(
rr
string
)
*
dns
.
TXT
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
TXT
)
}
// HINFO returns a HINFO record from rr. It panics on errors.
func
HINFO
(
rr
string
)
*
dns
.
HINFO
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
HINFO
)
}
// MX returns an MX record from rr. It panics on errors.
// MX returns an MX record from rr. It panics on errors.
func
MX
(
rr
string
)
*
dns
.
MX
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
MX
)
}
func
MX
(
rr
string
)
*
dns
.
MX
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
MX
)
}
...
@@ -215,6 +218,13 @@ func Section(t *testing.T, tc Case, sec sect, rr []dns.RR) bool {
...
@@ -215,6 +218,13 @@ func Section(t *testing.T, tc Case, sec sect, rr []dns.RR) bool {
return
false
return
false
}
}
}
}
case
*
dns
.
HINFO
:
if
x
.
Cpu
!=
section
[
i
]
.
(
*
dns
.
HINFO
)
.
Cpu
{
t
.
Errorf
(
"rr %d should have a Cpu of %s, but has %s"
,
i
,
section
[
i
]
.
(
*
dns
.
HINFO
)
.
Cpu
,
x
.
Cpu
)
}
if
x
.
Os
!=
section
[
i
]
.
(
*
dns
.
HINFO
)
.
Os
{
t
.
Errorf
(
"rr %d should have a Os of %s, but has %s"
,
i
,
section
[
i
]
.
(
*
dns
.
HINFO
)
.
Os
,
x
.
Os
)
}
case
*
dns
.
SOA
:
case
*
dns
.
SOA
:
tt
:=
section
[
i
]
.
(
*
dns
.
SOA
)
tt
:=
section
[
i
]
.
(
*
dns
.
SOA
)
if
x
.
Ns
!=
tt
.
Ns
{
if
x
.
Ns
!=
tt
.
Ns
{
...
...
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