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
f798d18b
Commit
f798d18b
authored
Mar 13, 2019
by
Stefan Budeanu
Committed by
Miek Gieben
Mar 13, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix context passing (#2681)
parent
26e4026e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
8 deletions
+26
-8
plugin/dnstap/context_test.go
plugin/dnstap/context_test.go
+1
-1
plugin/dnstap/gocontext.go
plugin/dnstap/gocontext.go
+23
-0
plugin/dnstap/handler.go
plugin/dnstap/handler.go
+2
-7
No files found.
plugin/dnstap/context_test.go
View file @
f798d18b
...
@@ -6,7 +6,7 @@ import (
...
@@ -6,7 +6,7 @@ import (
)
)
func
TestDnstapContext
(
t
*
testing
.
T
)
{
func
TestDnstapContext
(
t
*
testing
.
T
)
{
ctx
:=
tapContext
{
context
.
TODO
(),
Dnstap
{}}
ctx
:=
ContextWithTapper
(
context
.
TODO
(),
Dnstap
{})
tapper
:=
TapperFromContext
(
ctx
)
tapper
:=
TapperFromContext
(
ctx
)
if
tapper
==
nil
{
if
tapper
==
nil
{
...
...
plugin/dnstap/gocontext.go
0 → 100644
View file @
f798d18b
package
dnstap
import
"context"
type
contextKey
struct
{}
var
dnstapKey
=
contextKey
{}
// ContextWithTapper returns a new `context.Context` that holds a reference to
// `t`'s Tapper.
func
ContextWithTapper
(
ctx
context
.
Context
,
t
Tapper
)
context
.
Context
{
return
context
.
WithValue
(
ctx
,
dnstapKey
,
t
)
}
// TapperFromContext returns the `Tapper` previously associated with `ctx`, or
// `nil` if no such `Tapper` could be found.
func
TapperFromContext
(
ctx
context
.
Context
)
Tapper
{
val
:=
ctx
.
Value
(
dnstapKey
)
if
sp
,
ok
:=
val
.
(
Tapper
);
ok
{
return
sp
}
return
nil
}
plugin/dnstap/handler.go
View file @
f798d18b
...
@@ -44,12 +44,6 @@ const (
...
@@ -44,12 +44,6 @@ const (
DnstapSendOption
ContextKey
=
"dnstap-send-option"
DnstapSendOption
ContextKey
=
"dnstap-send-option"
)
)
// TapperFromContext will return a Tapper if the dnstap plugin is enabled.
func
TapperFromContext
(
ctx
context
.
Context
)
(
t
Tapper
)
{
t
,
_
=
ctx
.
(
Tapper
)
return
}
// TapMessage implements Tapper.
// TapMessage implements Tapper.
func
(
h
Dnstap
)
TapMessage
(
m
*
tap
.
Message
)
{
func
(
h
Dnstap
)
TapMessage
(
m
*
tap
.
Message
)
{
t
:=
tap
.
Dnstap_MESSAGE
t
:=
tap
.
Dnstap_MESSAGE
...
@@ -71,6 +65,7 @@ func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
...
@@ -71,6 +65,7 @@ func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
// message to be sent out
// message to be sent out
sendOption
:=
taprw
.
SendOption
{
Cq
:
true
,
Cr
:
true
}
sendOption
:=
taprw
.
SendOption
{
Cq
:
true
,
Cr
:
true
}
newCtx
:=
context
.
WithValue
(
ctx
,
DnstapSendOption
,
&
sendOption
)
newCtx
:=
context
.
WithValue
(
ctx
,
DnstapSendOption
,
&
sendOption
)
newCtx
=
ContextWithTapper
(
newCtx
,
h
)
rw
:=
&
taprw
.
ResponseWriter
{
rw
:=
&
taprw
.
ResponseWriter
{
ResponseWriter
:
w
,
ResponseWriter
:
w
,
...
@@ -80,7 +75,7 @@ func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
...
@@ -80,7 +75,7 @@ func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
QueryEpoch
:
time
.
Now
(),
QueryEpoch
:
time
.
Now
(),
}
}
code
,
err
:=
plugin
.
NextOrFailure
(
h
.
Name
(),
h
.
Next
,
tapContext
{
newCtx
,
h
}
,
rw
,
r
)
code
,
err
:=
plugin
.
NextOrFailure
(
h
.
Name
(),
h
.
Next
,
newCtx
,
rw
,
r
)
if
err
!=
nil
{
if
err
!=
nil
{
// ignore dnstap errors
// ignore dnstap errors
return
code
,
err
return
code
,
err
...
...
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