Easier way to dnstap? (#1496)

* Easier way to dnstap?

* Remove unnecessary function parameter from Tapper

* golint

* golint 2

* Proxy dnstap tests

* README.md & doc

* net.IP

* Proxy test was incorrect

* Small changes

* Update README.md

* Was not reporting dnstap errors + test

* Wasn't working at all, now it's ok

* Thanks Travis
This commit is contained in:
varyoo
2018-03-01 03:19:01 +01:00
committed by Miek Gieben
parent f697b33283
commit 6bb08ffee4
12 changed files with 274 additions and 255 deletions

View File

@@ -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 err := tapper.TapMessage(b.ToOutsideQuery(tap.Message_FORWARDER_QUERY)); err != nil {
if tapper.Pack() {
b.Msg(state.Req)
}
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
}