plugin/dnstap: Fix behavior when multiple dnstap plugins specified (#5773)

* fix multiple dnstap plugins behavior

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver
2022-11-28 10:33:31 -05:00
committed by GitHub
parent c4dd9d50f1
commit 04a30198c3
6 changed files with 220 additions and 121 deletions

View File

@@ -61,6 +61,15 @@ dnstap /tmp/dnstap.sock {
}
~~~
You can use _dnstap_ more than once to define multiple taps. The following logs information including the
wire-format DNS message about client requests and responses to */tmp/dnstap.sock*,
and also sends client requests and responses without wire-format DNS messages to a remote FQDN.
~~~ txt
dnstap /tmp/dnstap.sock full
dnstap tcp://example.com:6000
~~~
## Command Line Tool
Dnstap has a command line tool that can be used to inspect the logging. The tool can be found
@@ -86,13 +95,15 @@ $ dnstap -l 127.0.0.1:6000
## Using Dnstap in your plugin
In your setup function, check to see if the *dnstap* plugin is loaded:
In your setup function, collect and store a list of all *dnstap* plugins loaded in the config:
~~~ go
x := &ExamplePlugin{}
c.OnStartup(func() error {
if taph := dnsserver.GetConfig(c).Handler("dnstap"); taph != nil {
if tapPlugin, ok := taph.(dnstap.Dnstap); ok {
f.tapPlugin = &tapPlugin
x.tapPlugins = append(x.tapPlugins, &tapPlugin)
}
}
return nil
@@ -102,8 +113,13 @@ c.OnStartup(func() error {
And then in your plugin:
~~~ go
func (x RandomPlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
if tapPlugin != nil {
import (
github.com/coredns/coredns/plugin/dnstap/msg
tap "github.com/dnstap/golang-dnstap"
)
func (x ExamplePlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
for _, tapPlugin := range x.tapPlugins {
q := new(msg.Msg)
msg.SetQueryTime(q, time.Now())
msg.SetQueryAddress(q, w.RemoteAddr())