mirror of
https://github.com/coredns/coredns.git
synced 2025-11-14 16:02:16 -05:00
Enable dnstap plugin to insert other plugin's specific data into extra field of tap.Dnstap message (#1101)
* Add custom data into dnstap context * Fix error and fix UT compile errors * Add UTs * Change as per review comments. Use boolean to indicate which Dnstap message to send out * Merge with master and fix lint warning * Remove newline * Fix review comments
This commit is contained in:
committed by
John Belamaric
parent
4b3a430ff2
commit
2f9c42d82e
@@ -11,6 +11,13 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// SendOption stores the flag to indicate whether a certain DNSTap message to
|
||||
// be sent out or not.
|
||||
type SendOption struct {
|
||||
Cq bool
|
||||
Cr bool
|
||||
}
|
||||
|
||||
// Tapper is what ResponseWriter needs to log to dnstap.
|
||||
type Tapper interface {
|
||||
TapMessage(m *tap.Message) error
|
||||
@@ -19,12 +26,14 @@ type Tapper interface {
|
||||
|
||||
// ResponseWriter captures the client response and logs the query to dnstap.
|
||||
// Single request use.
|
||||
// SendOption configures Dnstap to selectively send Dnstap messages. Default is send all.
|
||||
type ResponseWriter struct {
|
||||
queryEpoch uint64
|
||||
Query *dns.Msg
|
||||
dns.ResponseWriter
|
||||
Tapper
|
||||
err error
|
||||
err error
|
||||
Send *SendOption
|
||||
}
|
||||
|
||||
// DnstapError check if a dnstap error occurred during Write and returns it.
|
||||
@@ -46,28 +55,32 @@ func (w *ResponseWriter) WriteMsg(resp *dns.Msg) (writeErr error) {
|
||||
|
||||
b := w.TapBuilder()
|
||||
b.TimeSec = w.queryEpoch
|
||||
if err := func() (err error) {
|
||||
err = b.AddrMsg(w.ResponseWriter.RemoteAddr(), w.Query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return w.TapMessage(b.ToClientQuery())
|
||||
}(); err != nil {
|
||||
w.err = fmt.Errorf("client query: %s", err)
|
||||
// don't forget to call DnstapError later
|
||||
}
|
||||
|
||||
if writeErr == nil {
|
||||
if w.Send == nil || w.Send.Cq {
|
||||
if err := func() (err error) {
|
||||
b.TimeSec = writeEpoch
|
||||
if err = b.Msg(resp); err != nil {
|
||||
err = b.AddrMsg(w.ResponseWriter.RemoteAddr(), w.Query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return w.TapMessage(b.ToClientResponse())
|
||||
return w.TapMessage(b.ToClientQuery())
|
||||
}(); err != nil {
|
||||
w.err = fmt.Errorf("client response: %s", err)
|
||||
w.err = fmt.Errorf("client query: %s", err)
|
||||
// don't forget to call DnstapError later
|
||||
}
|
||||
}
|
||||
|
||||
if w.Send == nil || w.Send.Cr {
|
||||
if writeErr == nil {
|
||||
if err := func() (err error) {
|
||||
b.TimeSec = writeEpoch
|
||||
if err = b.Msg(resp); err != nil {
|
||||
return
|
||||
}
|
||||
return w.TapMessage(b.ToClientResponse())
|
||||
}(); err != nil {
|
||||
w.err = fmt.Errorf("client response: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user