mirror of
https://github.com/coredns/coredns.git
synced 2025-11-19 10:22:17 -05:00
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user