diff options
author | 2021-01-21 02:00:27 -0700 | |
---|---|---|
committer | 2021-01-21 10:00:27 +0100 | |
commit | eba74389c407cee059e7be707f463ae091bf2fd1 (patch) | |
tree | 042b5cfbb3b88611f5ef536e4fe967a30303470e /plugin/dnstap/handler.go | |
parent | 8b2ff6c3889e0c23dceef4b10a1b1de58e463cb9 (diff) | |
download | coredns-eba74389c407cee059e7be707f463ae091bf2fd1.tar.gz coredns-eba74389c407cee059e7be707f463ae091bf2fd1.tar.zst coredns-eba74389c407cee059e7be707f463ae091bf2fd1.zip |
Fix #4395, fix out of order messages and fix forward perspective. (#4396)
Signed-off-by: Frank Riley <fhriley@gmail.com>
Diffstat (limited to 'plugin/dnstap/handler.go')
-rw-r--r-- | plugin/dnstap/handler.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/plugin/dnstap/handler.go b/plugin/dnstap/handler.go index b31508b81..1ae0e3c62 100644 --- a/plugin/dnstap/handler.go +++ b/plugin/dnstap/handler.go @@ -5,6 +5,7 @@ import ( "time" "github.com/coredns/coredns/plugin" + "github.com/coredns/coredns/plugin/dnstap/msg" tap "github.com/dnstap/golang-dnstap" "github.com/miekg/dns" @@ -25,6 +26,19 @@ func (h Dnstap) TapMessage(m *tap.Message) { 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. func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { rw := &ResponseWriter{ @@ -34,6 +48,10 @@ func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) 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) } |