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
b85c6788
Commit
b85c6788
authored
Nov 29, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:miekg/coredns
parents
eb8158ff
8c8b37a3
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
120 additions
and
44 deletions
+120
-44
middleware/etcd/README.md
middleware/etcd/README.md
+2
-2
middleware/etcd/debug_test.go
middleware/etcd/debug_test.go
+0
-16
middleware/etcd/handler.go
middleware/etcd/handler.go
+3
-2
middleware/httpproxy/README.md
middleware/httpproxy/README.md
+21
-0
middleware/httpproxy/google.go
middleware/httpproxy/google.go
+30
-10
middleware/httpproxy/proxy.go
middleware/httpproxy/proxy.go
+2
-2
middleware/httpproxy/setup_test.go
middleware/httpproxy/setup_test.go
+4
-2
middleware/httpproxy/tls.go
middleware/httpproxy/tls.go
+2
-1
middleware/metrics/handler.go
middleware/metrics/handler.go
+1
-1
middleware/metrics/vars/report.go
middleware/metrics/vars/report.go
+2
-2
middleware/pkg/debug/debug.go
middleware/pkg/debug/debug.go
+20
-0
middleware/pkg/debug/debug_test.go
middleware/pkg/debug/debug_test.go
+21
-0
middleware/pkg/dnsrecorder/recorder.go
middleware/pkg/dnsrecorder/recorder.go
+4
-4
middleware/pkg/replacer/replacer.go
middleware/pkg/replacer/replacer.go
+1
-1
middleware/root/root_test.go
middleware/root/root_test.go
+3
-0
request/request.go
request/request.go
+4
-1
No files found.
middleware/etcd/README.md
View file @
b85c6788
...
...
@@ -37,7 +37,7 @@ etcd [ZONES...] {
*
**ENDPOINT**
the etcd endpoints. Defaults to "http://localhost:2397".
*
`upstream`
upstream resolvers to be used resolve external names found in etcd (think CNAMEs)
pointing to external names. If you want CoreDNS to act as a proxy for clients, you'll need to add
the proxy middleware.
**
ADDRESS
*
can be an IP address, and IP:port or a string pointing to a file
the proxy middleware.
**ADDRESS*
*
can be an IP address, and IP:port or a string pointing to a file
that is structured as /etc/resolv.conf.
*
`tls`
followed the cert, key and the CA's cert filenames.
*
`debug`
allows for debug queries. Prefix the name with
`o-o.debug.`
to retrieve extra information in the
...
...
@@ -127,7 +127,7 @@ Or with *debug* queries enabled:
When debug queries are enabled CoreDNS will return errors and etcd records encountered during the resolution
process in the response. The general form looks like this:
skydns.test.skydns.dom.a.
30
0 CH TXT "127.0.0.1:0(10,0,,false)[0,]"
skydns.test.skydns.dom.a. 0 CH TXT "127.0.0.1:0(10,0,,false)[0,]"
This shows the complete key as the owername, the rdata of the TXT record has:
`host:port(priority,weight,txt content,mail)[targetstrip,group]`
.
...
...
middleware/etcd/debug_test.go
View file @
b85c6788
...
...
@@ -4,7 +4,6 @@ package etcd
import
(
"sort"
"strings"
"testing"
"github.com/miekg/coredns/middleware/etcd/msg"
...
...
@@ -14,21 +13,6 @@ import (
"github.com/miekg/dns"
)
func
TestIsDebug
(
t
*
testing
.
T
)
{
if
ok
:=
isDebug
(
"o-o.debug.miek.nl."
);
ok
!=
"miek.nl."
{
t
.
Errorf
(
"expected o-o.debug.miek.nl. to be debug"
)
}
if
ok
:=
isDebug
(
strings
.
ToLower
(
"o-o.Debug.miek.nl."
));
ok
!=
"miek.nl."
{
t
.
Errorf
(
"expected o-o.Debug.miek.nl. to be debug"
)
}
if
ok
:=
isDebug
(
"i-o.debug.miek.nl."
);
ok
!=
""
{
t
.
Errorf
(
"expected i-o.Debug.miek.nl. to be non-debug"
)
}
if
ok
:=
isDebug
(
strings
.
ToLower
(
"i-o.Debug."
));
ok
!=
""
{
t
.
Errorf
(
"expected o-o.Debug. to be non-debug"
)
}
}
func
TestDebugLookup
(
t
*
testing
.
T
)
{
etc
:=
newEtcdMiddleware
()
etc
.
Debugging
=
true
...
...
middleware/etcd/handler.go
View file @
b85c6788
...
...
@@ -5,6 +5,7 @@ import (
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/pkg/debug"
"github.com/miekg/coredns/middleware/pkg/dnsutil"
"github.com/miekg/coredns/request"
...
...
@@ -21,10 +22,10 @@ func (e *Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
}
name
:=
state
.
Name
()
if
e
.
Debugging
{
if
debug
:=
isDebug
(
name
);
de
bug
!=
""
{
if
bug
:=
debug
.
IsDebug
(
name
);
bug
!=
""
{
opt
.
Debug
=
r
.
Question
[
0
]
.
Name
state
.
Clear
()
state
.
Req
.
Question
[
0
]
.
Name
=
de
bug
state
.
Req
.
Question
[
0
]
.
Name
=
bug
}
}
...
...
middleware/httpproxy/README.md
View file @
b85c6788
...
...
@@ -48,3 +48,24 @@ proxy . dns.google.com {
upstream /etc/resolv.conf
}
~~~
## Debug queries
Debug queries are enabled by default and currently there is no way to turn them off. When CoreDNS
receives a debug queries (i.e. the name is prefixed with
`o-o.debug.`
a TXT record with Comment from
`dns.google.com`
is added. Note this is not always set, but sometimes you'll see:
`dig @localhost -p 1053 mx o-o.debug.example.org`
:
~~~
txt
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;o-o.debug.example.org. IN MX
;; AUTHORITY SECTION:
example.org. 1799 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2016110711 7200 3600 1209600 3600
;; ADDITIONAL SECTION:
. 0 CH TXT "Response from 199.43.133.53"
~~~
middleware/httpproxy/google.go
View file @
b85c6788
...
...
@@ -12,7 +12,9 @@ import (
"sync/atomic"
"time"
"github.com/miekg/coredns/middleware/pkg/debug"
"github.com/miekg/coredns/middleware/proxy"
"github.com/miekg/coredns/request"
"github.com/miekg/dns"
)
...
...
@@ -30,11 +32,17 @@ type google struct {
func
newGoogle
()
*
google
{
return
&
google
{
client
:
newClient
(
ghost
),
quit
:
make
(
chan
bool
)}
}
func
(
g
*
google
)
Exchange
(
req
*
dns
.
Msg
)
(
*
dns
.
Msg
,
error
)
{
func
(
g
*
google
)
Exchange
(
state
request
.
Request
)
(
*
dns
.
Msg
,
error
)
{
v
:=
url
.
Values
{}
v
.
Set
(
"name"
,
req
.
Question
[
0
]
.
Name
)
v
.
Set
(
"type"
,
fmt
.
Sprintf
(
"%d"
,
req
.
Question
[
0
]
.
Qtype
))
v
.
Set
(
"name"
,
state
.
Name
())
v
.
Set
(
"type"
,
fmt
.
Sprintf
(
"%d"
,
state
.
QType
()))
optDebug
:=
false
if
bug
:=
debug
.
IsDebug
(
state
.
Name
());
bug
!=
""
{
optDebug
=
true
v
.
Set
(
"name"
,
bug
)
}
start
:=
time
.
Now
()
...
...
@@ -60,12 +68,20 @@ func (g *google) Exchange(req *dns.Msg) (*dns.Msg, error) {
return
nil
,
err
}
m
,
err
:=
toMsg
(
gm
)
m
,
debug
,
err
:=
toMsg
(
gm
)
if
err
!=
nil
{
return
nil
,
err
}
m
.
Id
=
req
.
Id
if
optDebug
{
// reset question
m
.
Question
[
0
]
.
Name
=
state
.
QName
()
// prepend debug RR to the additional section
m
.
Extra
=
append
([]
dns
.
RR
{
debug
},
m
.
Extra
...
)
}
m
.
Id
=
state
.
Req
.
Id
return
m
,
nil
}
...
...
@@ -223,8 +239,11 @@ func (g *google) do(addr, json string) ([]byte, error) {
return
buf
,
nil
}
func
toMsg
(
g
*
googleMsg
)
(
*
dns
.
Msg
,
error
)
{
// toMsg converts a googleMsg into the dns message. The returned RR is the comment disquised as a TXT
// record.
func
toMsg
(
g
*
googleMsg
)
(
*
dns
.
Msg
,
dns
.
RR
,
error
)
{
m
:=
new
(
dns
.
Msg
)
m
.
Response
=
true
m
.
Rcode
=
g
.
Status
m
.
Truncated
=
g
.
TC
m
.
RecursionDesired
=
g
.
RD
...
...
@@ -243,23 +262,24 @@ func toMsg(g *googleMsg) (*dns.Msg, error) {
for
i
:=
0
;
i
<
len
(
m
.
Answer
);
i
++
{
m
.
Answer
[
i
],
err
=
toRR
(
g
.
Answer
[
i
])
if
err
!=
nil
{
return
nil
,
err
return
nil
,
nil
,
err
}
}
for
i
:=
0
;
i
<
len
(
m
.
Ns
);
i
++
{
m
.
Ns
[
i
],
err
=
toRR
(
g
.
Authority
[
i
])
if
err
!=
nil
{
return
nil
,
err
return
nil
,
nil
,
err
}
}
for
i
:=
0
;
i
<
len
(
m
.
Extra
);
i
++
{
m
.
Extra
[
i
],
err
=
toRR
(
g
.
Additional
[
i
])
if
err
!=
nil
{
return
nil
,
err
return
nil
,
nil
,
err
}
}
return
m
,
nil
txt
,
_
:=
dns
.
NewRR
(
". 0 CH TXT "
+
g
.
Comment
)
return
m
,
txt
,
nil
}
func
toRR
(
g
googleRR
)
(
dns
.
RR
,
error
)
{
...
...
middleware/httpproxy/proxy.go
View file @
b85c6788
...
...
@@ -27,9 +27,9 @@ func (p *Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
start
:=
time
.
Now
()
state
:=
request
.
Request
{
W
:
w
,
Req
:
r
}
reply
,
backendErr
:=
p
.
e
.
Exchange
(
r
)
reply
,
backendErr
:=
p
.
e
.
Exchange
(
state
)
if
backendErr
==
nil
{
if
backendErr
==
nil
&&
reply
!=
nil
{
state
.
SizeAndDo
(
reply
)
w
.
WriteMsg
(
reply
)
...
...
middleware/httpproxy/setup_test.go
View file @
b85c6788
...
...
@@ -2,6 +2,7 @@ package httpproxy
import
(
"io/ioutil"
"log"
"os"
"strings"
"testing"
...
...
@@ -9,7 +10,9 @@ import (
"github.com/mholt/caddy"
)
func
TestSetupChaos
(
t
*
testing
.
T
)
{
func
TestSetupHttpproxy
(
t
*
testing
.
T
)
{
log
.
SetOutput
(
ioutil
.
Discard
)
tests
:=
[]
struct
{
input
string
shouldErr
bool
...
...
@@ -55,7 +58,6 @@ func TestSetupChaos(t *testing.T) {
}
if
err
!=
nil
{
t
.
Logf
(
"%q"
,
err
)
if
!
test
.
shouldErr
{
t
.
Errorf
(
"Test %d: Expected no error but found one for input %s. Error was: %v"
,
i
,
test
.
input
,
err
)
}
...
...
middleware/httpproxy/tls.go
View file @
b85c6788
...
...
@@ -5,13 +5,14 @@ import (
"net/http"
"time"
"github.com/miekg/coredns/request"
"github.com/miekg/dns"
)
// Exchanger is an interface that specifies a type implementing a DNS resolver that
// uses a HTTPS server.
type
Exchanger
interface
{
Exchange
(
*
dns
.
Msg
)
(
*
dns
.
Msg
,
error
)
Exchange
(
request
.
Request
)
(
*
dns
.
Msg
,
error
)
SetUpstream
(
*
simpleUpstream
)
error
OnStartup
()
error
...
...
middleware/metrics/handler.go
View file @
b85c6788
...
...
@@ -25,7 +25,7 @@ func (m *Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
rw
:=
dnsrecorder
.
New
(
w
)
status
,
err
:=
m
.
Next
.
ServeDNS
(
ctx
,
rw
,
r
)
vars
.
Report
(
state
,
zone
,
rcode
.
ToString
(
rw
.
Rcode
),
rw
.
Size
,
rw
.
Start
)
vars
.
Report
(
state
,
zone
,
rcode
.
ToString
(
rw
.
Rcode
),
rw
.
Len
,
rw
.
Start
)
return
status
,
err
}
...
...
middleware/metrics/vars/report.go
View file @
b85c6788
...
...
@@ -10,7 +10,7 @@ import (
// Report reports the metrics data associcated with request.
func
Report
(
req
request
.
Request
,
zone
,
rcode
string
,
size
int
,
start
time
.
Time
)
{
// Proto and Family
// Proto and Family
.
net
:=
req
.
Proto
()
fam
:=
"1"
if
req
.
Family
()
==
2
{
...
...
@@ -33,7 +33,7 @@ func Report(req request.Request, zone, rcode string, size int, start time.Time)
}
ResponseSize
.
WithLabelValues
(
zone
,
net
)
.
Observe
(
float64
(
size
))
RequestSize
.
WithLabelValues
(
zone
,
net
)
.
Observe
(
float64
(
req
.
Size
()))
RequestSize
.
WithLabelValues
(
zone
,
net
)
.
Observe
(
float64
(
req
.
Len
()))
ResponseRcode
.
WithLabelValues
(
zone
,
rcode
)
.
Inc
()
}
...
...
middleware/
etcd
/debug.go
→
middleware/
pkg/debug
/debug.go
View file @
b85c6788
package
etcd
package
debug
import
"strings"
const
debug
Name
=
"o-o.debug."
const
Name
=
"o-o.debug."
//
i
sDebug checks if name is a debugging name, i.e. starts with o-o.debug.
// it return the empty string if it is not a debug message, otherwise it will return the
//
I
sDebug checks if name is a debugging name, i.e. starts with o-o.debug.
// it return
s
the empty string if it is not a debug message, otherwise it will return the
// name with o-o.debug. stripped off. Must be called with name lowercased.
func
i
sDebug
(
name
string
)
string
{
if
len
(
name
)
==
len
(
debug
Name
)
{
func
I
sDebug
(
name
string
)
string
{
if
len
(
name
)
==
len
(
Name
)
{
return
""
}
name
=
strings
.
ToLower
(
name
)
debug
:=
strings
.
HasPrefix
(
name
,
debug
Name
)
debug
:=
strings
.
HasPrefix
(
name
,
Name
)
if
!
debug
{
return
""
}
return
name
[
len
(
debug
Name
)
:
]
return
name
[
len
(
Name
)
:
]
}
middleware/pkg/debug/debug_test.go
0 → 100644
View file @
b85c6788
package
debug
import
(
"strings"
"testing"
)
func
TestIsDebug
(
t
*
testing
.
T
)
{
if
ok
:=
IsDebug
(
"o-o.debug.miek.nl."
);
ok
!=
"miek.nl."
{
t
.
Errorf
(
"expected o-o.debug.miek.nl. to be debug"
)
}
if
ok
:=
IsDebug
(
strings
.
ToLower
(
"o-o.Debug.miek.nl."
));
ok
!=
"miek.nl."
{
t
.
Errorf
(
"expected o-o.Debug.miek.nl. to be debug"
)
}
if
ok
:=
IsDebug
(
"i-o.debug.miek.nl."
);
ok
!=
""
{
t
.
Errorf
(
"expected i-o.Debug.miek.nl. to be non-debug"
)
}
if
ok
:=
IsDebug
(
strings
.
ToLower
(
"i-o.Debug."
));
ok
!=
""
{
t
.
Errorf
(
"expected o-o.Debug. to be non-debug"
)
}
}
middleware/pkg/dnsrecorder/recorder.go
View file @
b85c6788
...
...
@@ -16,7 +16,7 @@ import (
type
Recorder
struct
{
dns
.
ResponseWriter
Rcode
int
Size
int
Len
int
Msg
*
dns
.
Msg
Start
time
.
Time
}
...
...
@@ -39,16 +39,16 @@ func (r *Recorder) WriteMsg(res *dns.Msg) error {
r
.
Rcode
=
res
.
Rcode
// We may get called multiple times (axfr for instance).
// Save the last message, but add the sizes.
r
.
Size
+=
res
.
Len
()
r
.
Len
+=
res
.
Len
()
r
.
Msg
=
res
return
r
.
ResponseWriter
.
WriteMsg
(
res
)
}
// Write is a wrapper that records the
size
of the message that gets written.
// Write is a wrapper that records the
length
of the message that gets written.
func
(
r
*
Recorder
)
Write
(
buf
[]
byte
)
(
int
,
error
)
{
n
,
err
:=
r
.
ResponseWriter
.
Write
(
buf
)
if
err
==
nil
{
r
.
Size
+=
n
r
.
Len
+=
n
}
return
n
,
err
}
...
...
middleware/pkg/replacer/replacer.go
View file @
b85c6788
...
...
@@ -53,7 +53,7 @@ func New(r *dns.Msg, rr *dnsrecorder.Recorder, emptyValue string) Replacer {
rcode
=
strconv
.
Itoa
(
rr
.
Rcode
)
}
rep
.
replacements
[
"{rcode}"
]
=
rcode
rep
.
replacements
[
"{size}"
]
=
strconv
.
Itoa
(
rr
.
Size
)
rep
.
replacements
[
"{size}"
]
=
strconv
.
Itoa
(
rr
.
Len
)
rep
.
replacements
[
"{duration}"
]
=
time
.
Since
(
rr
.
Start
)
.
String
()
}
...
...
middleware/root/root_test.go
View file @
b85c6788
...
...
@@ -3,6 +3,7 @@ package root
import
(
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
...
...
@@ -14,6 +15,8 @@ import (
)
func
TestRoot
(
t
*
testing
.
T
)
{
log
.
SetOutput
(
ioutil
.
Discard
)
// Predefined error substrings
parseErrContent
:=
"Parse error:"
unableToAccessErrContent
:=
"Unable to access root path"
...
...
request/request.go
View file @
b85c6788
...
...
@@ -106,7 +106,10 @@ func (r *Request) Do() bool {
return
false
}
// Size returns if UDP buffer size advertised in the requests OPT record.
// Len returns the length in bytes in the request.
func
(
r
*
Request
)
Len
()
int
{
return
r
.
Req
.
Len
()
}
// Size returns if buffer size *advertised* in the requests OPT record.
// Or when the request was over TCP, we return the maximum allowed size of 64K.
func
(
r
*
Request
)
Size
()
int
{
if
r
.
size
!=
0
{
...
...
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