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

@@ -39,25 +39,27 @@ func toDnstap(f *Forward, host string, state request.Request, opts options, repl
msg.SetQueryAddress(q, state.W.RemoteAddr())
msg.SetResponseAddress(q, ta)
if f.tapPlugin.IncludeRawMessage {
buf, _ := state.Req.Pack()
q.QueryMessage = buf
}
msg.SetType(q, tap.Message_FORWARDER_QUERY)
f.tapPlugin.TapMessage(q)
// Response
if reply != nil {
r := new(tap.Message)
if f.tapPlugin.IncludeRawMessage {
buf, _ := reply.Pack()
r.ResponseMessage = buf
for _, t := range f.tapPlugins {
if t.IncludeRawMessage {
buf, _ := state.Req.Pack()
q.QueryMessage = buf
}
msg.SetType(q, tap.Message_FORWARDER_QUERY)
t.TapMessage(q)
// Response
if reply != nil {
r := new(tap.Message)
if t.IncludeRawMessage {
buf, _ := reply.Pack()
r.ResponseMessage = buf
}
msg.SetQueryTime(r, start)
msg.SetQueryAddress(r, state.W.RemoteAddr())
msg.SetResponseAddress(r, ta)
msg.SetResponseTime(r, time.Now())
msg.SetType(r, tap.Message_FORWARDER_RESPONSE)
t.TapMessage(r)
}
msg.SetQueryTime(r, start)
msg.SetQueryAddress(r, state.W.RemoteAddr())
msg.SetResponseAddress(r, ta)
msg.SetResponseTime(r, time.Now())
msg.SetType(r, tap.Message_FORWARDER_RESPONSE)
f.tapPlugin.TapMessage(r)
}
}

View File

@@ -49,7 +49,7 @@ type Forward struct {
// the maximum allowed (maxConcurrent)
ErrLimitExceeded error
tapPlugin *dnstap.Dnstap // when the dnstap plugin is loaded, we use to this to send messages out.
tapPlugins []*dnstap.Dnstap // when dnstap plugins are loaded, we use to this to send messages out.
Next plugin.Handler
}
@@ -150,7 +150,7 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
child.Finish()
}
if f.tapPlugin != nil {
if len(f.tapPlugins) != 0 {
toDnstap(f, proxy.addr, state, opts, ret, start)
}

View File

@@ -52,7 +52,7 @@ func setup(c *caddy.Controller) error {
c.OnStartup(func() error {
if taph := dnsserver.GetConfig(c).Handler("dnstap"); taph != nil {
if tapPlugin, ok := taph.(dnstap.Dnstap); ok {
f.tapPlugin = &tapPlugin
f.tapPlugins = append(f.tapPlugins, &tapPlugin)
}
}
return nil