plugin/forward: fix broken tap plugins when dnstap plugins specified (#5890)

* plugin/forward: fix broken tap plugins when dnstap plugins specified

---------

Signed-off-by: Gerhard Tan <gwohau.tan@gmail.com>
This commit is contained in:
Gerhard Tan
2023-01-31 03:38:15 +08:00
committed by GitHub
parent 68b2aa6708
commit b7279d1f66
5 changed files with 60 additions and 13 deletions

View File

@@ -14,9 +14,6 @@ import (
// toDnstap will send the forward and received message to the dnstap plugin.
func toDnstap(f *Forward, host string, state request.Request, opts options, reply *dns.Msg, start time.Time) {
// Query
q := new(tap.Message)
msg.SetQueryTime(q, start)
h, p, _ := net.SplitHostPort(host) // this is preparsed and can't err here
port, _ := strconv.ParseUint(p, 10, 32) // same here
ip := net.ParseIP(h)
@@ -34,12 +31,14 @@ func toDnstap(f *Forward, host string, state request.Request, opts options, repl
ta = &net.TCPAddr{IP: ip, Port: int(port)}
}
// Forwarder dnstap messages are from the perspective of the downstream server
// (upstream is the forward server)
msg.SetQueryAddress(q, state.W.RemoteAddr())
msg.SetResponseAddress(q, ta)
for _, t := range f.tapPlugins {
// Query
q := new(tap.Message)
msg.SetQueryTime(q, start)
// Forwarder dnstap messages are from the perspective of the downstream server
// (upstream is the forward server)
msg.SetQueryAddress(q, state.W.RemoteAddr())
msg.SetResponseAddress(q, ta)
if t.IncludeRawMessage {
buf, _ := state.Req.Pack()
q.QueryMessage = buf