aboutsummaryrefslogtreecommitdiff
path: root/plugin/dnstap/handler.go
diff options
context:
space:
mode:
authorGravatar Thong Huynh <thuynh@infoblox.com> 2017-09-29 13:38:01 -0700
committerGravatar John Belamaric <jbelamaric@infoblox.com> 2017-09-29 16:38:01 -0400
commit2f9c42d82ec5e2edd475e8166547ad7a89ca4f1d (patch)
treed423845f03cdc86bf52f2648d43c5e20f3603f38 /plugin/dnstap/handler.go
parent4b3a430ff2e6a39278eebd1493936c3a8a161fa0 (diff)
downloadcoredns-2f9c42d82ec5e2edd475e8166547ad7a89ca4f1d.tar.gz
coredns-2f9c42d82ec5e2edd475e8166547ad7a89ca4f1d.tar.zst
coredns-2f9c42d82ec5e2edd475e8166547ad7a89ca4f1d.zip
Enable dnstap plugin to insert other plugin's specific data into extra field of tap.Dnstap message (#1101)
* Add custom data into dnstap context * Fix error and fix UT compile errors * Add UTs * Change as per review comments. Use boolean to indicate which Dnstap message to send out * Merge with master and fix lint warning * Remove newline * Fix review comments
Diffstat (limited to 'plugin/dnstap/handler.go')
-rw-r--r--plugin/dnstap/handler.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/plugin/dnstap/handler.go b/plugin/dnstap/handler.go
index b6a8afbe7..63838492c 100644
--- a/plugin/dnstap/handler.go
+++ b/plugin/dnstap/handler.go
@@ -36,6 +36,14 @@ type (
}
)
+// ContextKey defines the type of key that is used to save data into the context
+type ContextKey string
+
+const (
+ // DnstapSendOption specifies the Dnstap message to be send. Default is sent all.
+ 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)
@@ -64,10 +72,16 @@ func (h Dnstap) TapBuilder() msg.Builder {
// 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) {
- rw := &taprw.ResponseWriter{ResponseWriter: w, Tapper: &h, Query: r}
+
+ // Add send option into context so other plugin can decide on which DNSTap
+ // message to be sent out
+ sendOption := taprw.SendOption{Cq: true, Cr: true}
+ newCtx := context.WithValue(ctx, DnstapSendOption, &sendOption)
+
+ rw := &taprw.ResponseWriter{ResponseWriter: w, Tapper: &h, Query: r, Send: &sendOption}
rw.QueryEpoch()
- code, err := plugin.NextOrFailure(h.Name(), h.Next, tapContext{ctx, h}, rw, r)
+ code, err := plugin.NextOrFailure(h.Name(), h.Next, tapContext{newCtx, h}, rw, r)
if err != nil {
// ignore dnstap errors
return code, err