diff options
Diffstat (limited to 'plugin/dnstap/handler.go')
-rw-r--r-- | plugin/dnstap/handler.go | 68 |
1 files changed, 11 insertions, 57 deletions
diff --git a/plugin/dnstap/handler.go b/plugin/dnstap/handler.go index 0dde3a346..7451d63f0 100644 --- a/plugin/dnstap/handler.go +++ b/plugin/dnstap/handler.go @@ -5,7 +5,7 @@ import ( "time" "github.com/coredns/coredns/plugin" - "github.com/coredns/coredns/plugin/dnstap/taprw" + "github.com/coredns/coredns/plugin/dnstap/dnstapio" tap "github.com/dnstap/golang-dnstap" "github.com/miekg/dns" @@ -14,75 +14,29 @@ import ( // Dnstap is the dnstap handler. type Dnstap struct { Next plugin.Handler - IO IORoutine + io dnstapio.Tapper - // Set to true to include the relevant raw DNS message into the dnstap messages. - JoinRawMessage bool + // IncludeRawMessage will include the raw DNS message into the dnstap messages if true. + IncludeRawMessage bool } -type ( - // IORoutine is the dnstap I/O thread as defined by: <http://dnstap.info/Architecture>. - IORoutine interface { - Dnstap(tap.Dnstap) - } - // Tapper is implemented by the Context passed by the dnstap handler. - Tapper interface { - TapMessage(message *tap.Message) - Pack() bool - } -) - -// 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" -) - -// TapMessage implements Tapper. +// TapMessage sends the message m to the dnstap interface. func (h Dnstap) TapMessage(m *tap.Message) { t := tap.Dnstap_MESSAGE - h.IO.Dnstap(tap.Dnstap{ - Type: &t, - Message: m, - }) -} - -// Pack returns true if the raw DNS message should be included into the dnstap messages. -func (h Dnstap) Pack() bool { - return h.JoinRawMessage + h.io.Dnstap(tap.Dnstap{Type: &t, Message: m}) } // 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) { - - // 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) - newCtx = ContextWithTapper(newCtx, h) - - rw := &taprw.ResponseWriter{ + rw := &ResponseWriter{ ResponseWriter: w, - Tapper: &h, + Dnstap: h, Query: r, - Send: &sendOption, - QueryEpoch: time.Now(), - } - - code, err := plugin.NextOrFailure(h.Name(), h.Next, newCtx, rw, r) - if err != nil { - // ignore dnstap errors - return code, err - } - - if err = rw.DnstapError(); err != nil { - return code, plugin.Error("dnstap", err) + QueryTime: time.Now(), } - return code, nil + return plugin.NextOrFailure(h.Name(), h.Next, ctx, rw, r) } -// Name returns dnstap. +// Name implements the plugin.Plugin interface. func (h Dnstap) Name() string { return "dnstap" } |