diff options
Diffstat (limited to 'plugin/dnstap/README.md')
-rw-r--r-- | plugin/dnstap/README.md | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/plugin/dnstap/README.md b/plugin/dnstap/README.md index 67345284f..b2bbd3c0f 100644 --- a/plugin/dnstap/README.md +++ b/plugin/dnstap/README.md @@ -66,28 +66,39 @@ $ dnstap -l 127.0.0.1:6000 ## Using Dnstap in your plugin -~~~ Go -import ( - "github.com/coredns/coredns/plugin/dnstap" - "github.com/coredns/coredns/plugin/dnstap/msg" -) - -func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { - // log client query to Dnstap - if t := dnstap.TapperFromContext(ctx); t != nil { - b := msg.New().Time(time.Now()).Addr(w.RemoteAddr()) - if t.Pack() { - b.Msg(r) - } - if m, err := b.ToClientQuery(); err == nil { - t.TapMessage(m) +In your setup function, check to see if the *dnstap* plugin is loaded: + +~~~ go +c.OnStartup(func() error { + if taph := dnsserver.GetConfig(c).Handler("dnstap"); taph != nil { + if tapPlugin, ok := taph.(dnstap.Dnstap); ok { + f.tapPlugin = &tapPlugin } } + return nil +}) +~~~ +And then in your plugin: + +~~~ go +func (x RandomPlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { + if tapPlugin != nil { + q := new(msg.Msg) + msg.SetQueryTime(q, time.Now()) + msg.SetQueryAddress(q, w.RemoteAddr()) + if tapPlugin.IncludeRawMessage { + buf, _ := r.Pack() // r has been seen packed/unpacked before, this should not fail + q.QueryMessage = buf + } + msg.SetType(q, tap.Message_CLIENT_QUERY) + tapPlugin.TapMessage(q) + } // ... } ~~~ ## See Also -[dnstap.info](https://dnstap.info). +The website [dnstap.info](https://dnstap.info) has info on the dnstap protocol. +The *forward* plugin's `dnstap.go` uses dnstap to tap messages sent to an upstream. |