mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user