diff options
Diffstat (limited to 'plugin/proxy')
-rw-r--r-- | plugin/proxy/dnstap.go | 26 | ||||
-rw-r--r-- | plugin/proxy/dnstap_test.go | 6 |
2 files changed, 17 insertions, 15 deletions
diff --git a/plugin/proxy/dnstap.go b/plugin/proxy/dnstap.go index 430b43847..9633060b8 100644 --- a/plugin/proxy/dnstap.go +++ b/plugin/proxy/dnstap.go @@ -4,6 +4,7 @@ import ( "time" "github.com/coredns/coredns/plugin/dnstap" + "github.com/coredns/coredns/plugin/dnstap/msg" "github.com/coredns/coredns/request" tap "github.com/dnstap/golang-dnstap" @@ -18,11 +19,7 @@ func toDnstap(ctx context.Context, host string, ex Exchanger, state request.Requ } // Query - b := tapper.TapBuilder() - b.TimeSec = uint64(start.Unix()) - if err := b.HostPort(host); err != nil { - return err - } + b := msg.New().Time(start).HostPort(host) t := ex.Transport() if t == "" { @@ -34,21 +31,26 @@ func toDnstap(ctx context.Context, host string, ex Exchanger, state request.Requ b.SocketProto = tap.SocketProtocol_UDP } - if err := b.Msg(state.Req); err != nil { - return err + if tapper.Pack() { + b.Msg(state.Req) } - - if err := tapper.TapMessage(b.ToOutsideQuery(tap.Message_FORWARDER_QUERY)); err != nil { + m, err := b.ToOutsideQuery(tap.Message_FORWARDER_QUERY) + if err != nil { return err } + tapper.TapMessage(m) // Response if reply != nil { - b.TimeSec = uint64(time.Now().Unix()) - if err := b.Msg(reply); err != nil { + if tapper.Pack() { + b.Msg(reply) + } + m, err := b.Time(time.Now()).ToOutsideResponse(tap.Message_FORWARDER_RESPONSE) + if err != nil { return err } - return tapper.TapMessage(b.ToOutsideResponse(tap.Message_FORWARDER_RESPONSE)) + tapper.TapMessage(m) } + return nil } diff --git a/plugin/proxy/dnstap_test.go b/plugin/proxy/dnstap_test.go index 6ed0c61ed..83696921a 100644 --- a/plugin/proxy/dnstap_test.go +++ b/plugin/proxy/dnstap_test.go @@ -14,9 +14,9 @@ import ( "golang.org/x/net/context" ) -func testCase(t *testing.T, ex Exchanger, q, r *dns.Msg, datq, datr *msg.Data) { - tapq := datq.ToOutsideQuery(tap.Message_FORWARDER_QUERY) - tapr := datr.ToOutsideResponse(tap.Message_FORWARDER_RESPONSE) +func testCase(t *testing.T, ex Exchanger, q, r *dns.Msg, datq, datr *msg.Builder) { + tapq, _ := datq.ToOutsideQuery(tap.Message_FORWARDER_QUERY) + tapr, _ := datr.ToOutsideResponse(tap.Message_FORWARDER_RESPONSE) ctx := test.Context{} err := toDnstap(&ctx, "10.240.0.1:40212", ex, request.Request{W: &mwtest.ResponseWriter{}, Req: q}, r, time.Now()) |