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
eba74389
Commit
eba74389
authored
Jan 21, 2021
by
Frank Riley
Committed by
GitHub
Jan 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #4395, fix out of order messages and fix forward perspective. (#4396)
Signed-off-by:
Frank Riley
<
fhriley@gmail.com
>
parent
8b2ff6c3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
14 deletions
+24
-14
plugin/dnstap/handler.go
plugin/dnstap/handler.go
+18
-0
plugin/dnstap/writer.go
plugin/dnstap/writer.go
+0
-12
plugin/forward/dnstap.go
plugin/forward/dnstap.go
+6
-2
No files found.
plugin/dnstap/handler.go
View file @
eba74389
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"time"
"time"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/dnstap/msg"
tap
"github.com/dnstap/golang-dnstap"
tap
"github.com/dnstap/golang-dnstap"
"github.com/miekg/dns"
"github.com/miekg/dns"
...
@@ -25,6 +26,19 @@ func (h Dnstap) TapMessage(m *tap.Message) {
...
@@ -25,6 +26,19 @@ func (h Dnstap) TapMessage(m *tap.Message) {
h
.
io
.
Dnstap
(
tap
.
Dnstap
{
Type
:
&
t
,
Message
:
m
})
h
.
io
.
Dnstap
(
tap
.
Dnstap
{
Type
:
&
t
,
Message
:
m
})
}
}
func
(
h
Dnstap
)
tapQuery
(
w
dns
.
ResponseWriter
,
query
*
dns
.
Msg
,
queryTime
time
.
Time
)
{
q
:=
new
(
tap
.
Message
)
msg
.
SetQueryTime
(
q
,
queryTime
)
msg
.
SetQueryAddress
(
q
,
w
.
RemoteAddr
())
if
h
.
IncludeRawMessage
{
buf
,
_
:=
query
.
Pack
()
q
.
QueryMessage
=
buf
}
msg
.
SetType
(
q
,
tap
.
Message_CLIENT_QUERY
)
h
.
TapMessage
(
q
)
}
// ServeDNS logs the client query and response to dnstap and passes the dnstap Context.
// ServeDNS logs the client query and response to dnstap and passes the dnstap Context.
func
(
h
Dnstap
)
ServeDNS
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
func
(
h
Dnstap
)
ServeDNS
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
rw
:=
&
ResponseWriter
{
rw
:=
&
ResponseWriter
{
...
@@ -34,6 +48,10 @@ func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
...
@@ -34,6 +48,10 @@ func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
queryTime
:
time
.
Now
(),
queryTime
:
time
.
Now
(),
}
}
// The query tap message should be sent before sending the query to the
// forwarder. Otherwise, the tap messages will come out out of order.
h
.
tapQuery
(
w
,
r
,
rw
.
queryTime
)
return
plugin
.
NextOrFailure
(
h
.
Name
(),
h
.
Next
,
ctx
,
rw
,
r
)
return
plugin
.
NextOrFailure
(
h
.
Name
(),
h
.
Next
,
ctx
,
rw
,
r
)
}
}
...
...
plugin/dnstap/writer.go
View file @
eba74389
...
@@ -19,18 +19,6 @@ type ResponseWriter struct {
...
@@ -19,18 +19,6 @@ type ResponseWriter struct {
// WriteMsg writes back the response to the client and THEN works on logging the request and response to dnstap.
// WriteMsg writes back the response to the client and THEN works on logging the request and response to dnstap.
func
(
w
*
ResponseWriter
)
WriteMsg
(
resp
*
dns
.
Msg
)
error
{
func
(
w
*
ResponseWriter
)
WriteMsg
(
resp
*
dns
.
Msg
)
error
{
err
:=
w
.
ResponseWriter
.
WriteMsg
(
resp
)
err
:=
w
.
ResponseWriter
.
WriteMsg
(
resp
)
q
:=
new
(
tap
.
Message
)
msg
.
SetQueryTime
(
q
,
w
.
queryTime
)
msg
.
SetQueryAddress
(
q
,
w
.
RemoteAddr
())
if
w
.
IncludeRawMessage
{
buf
,
_
:=
w
.
query
.
Pack
()
q
.
QueryMessage
=
buf
}
msg
.
SetType
(
q
,
tap
.
Message_CLIENT_QUERY
)
w
.
TapMessage
(
q
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
plugin/forward/dnstap.go
View file @
eba74389
...
@@ -34,7 +34,10 @@ func toDnstap(f *Forward, host string, state request.Request, opts options, repl
...
@@ -34,7 +34,10 @@ func toDnstap(f *Forward, host string, state request.Request, opts options, repl
ta
=
&
net
.
TCPAddr
{
IP
:
ip
,
Port
:
int
(
port
)}
ta
=
&
net
.
TCPAddr
{
IP
:
ip
,
Port
:
int
(
port
)}
}
}
msg
.
SetQueryAddress
(
q
,
ta
)
// Forwarder dnstap messages are from the perspective of the downstream server
// (upstream is the forward server)
msg
.
SetQueryAddress
(
q
,
state
.
W
.
RemoteAddr
())
msg
.
SetResponseAddress
(
q
,
ta
)
if
f
.
tapPlugin
.
IncludeRawMessage
{
if
f
.
tapPlugin
.
IncludeRawMessage
{
buf
,
_
:=
state
.
Req
.
Pack
()
buf
,
_
:=
state
.
Req
.
Pack
()
...
@@ -51,7 +54,8 @@ func toDnstap(f *Forward, host string, state request.Request, opts options, repl
...
@@ -51,7 +54,8 @@ func toDnstap(f *Forward, host string, state request.Request, opts options, repl
r
.
ResponseMessage
=
buf
r
.
ResponseMessage
=
buf
}
}
msg
.
SetQueryTime
(
r
,
start
)
msg
.
SetQueryTime
(
r
,
start
)
msg
.
SetQueryAddress
(
r
,
ta
)
msg
.
SetQueryAddress
(
r
,
state
.
W
.
RemoteAddr
())
msg
.
SetResponseAddress
(
r
,
ta
)
msg
.
SetResponseTime
(
r
,
time
.
Now
())
msg
.
SetResponseTime
(
r
,
time
.
Now
())
msg
.
SetType
(
r
,
tap
.
Message_FORWARDER_RESPONSE
)
msg
.
SetType
(
r
,
tap
.
Message_FORWARDER_RESPONSE
)
f
.
tapPlugin
.
TapMessage
(
r
)
f
.
tapPlugin
.
TapMessage
(
r
)
...
...
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