diff options
Diffstat (limited to 'att script/4(v6 DDoS)/code/辅助权威服务器/plugin/dnstap/writer.go')
| -rw-r--r-- | att script/4(v6 DDoS)/code/辅助权威服务器/plugin/dnstap/writer.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/att script/4(v6 DDoS)/code/辅助权威服务器/plugin/dnstap/writer.go b/att script/4(v6 DDoS)/code/辅助权威服务器/plugin/dnstap/writer.go new file mode 100644 index 0000000..9278fcc --- /dev/null +++ b/att script/4(v6 DDoS)/code/辅助权威服务器/plugin/dnstap/writer.go @@ -0,0 +1,39 @@ +package dnstap + +import ( + "ohmydns2/plugin/dnstap/msg" + "time" + + tap "github.com/dnstap/golang-dnstap" + "github.com/miekg/dns" +) + +// ResponseWriter captures the client response and logs the query to dnstap. +type ResponseWriter struct { + queryTime time.Time + query *dns.Msg + dns.ResponseWriter + Dnstap +} + +// WriteMsg writes back the response to the client and THEN works on logging the request and response to dnstap. +func (w *ResponseWriter) WriteMsg(resp *dns.Msg) error { + err := w.ResponseWriter.WriteMsg(resp) + if err != nil { + return err + } + + r := new(tap.Message) + msg.SetQueryTime(r, w.queryTime) + msg.SetResponseTime(r, time.Now()) + msg.SetQueryAddress(r, w.RemoteAddr()) + + if w.IncludeRawMessage { + buf, _ := resp.Pack() + r.ResponseMessage = buf + } + + msg.SetType(r, tap.Message_CLIENT_RESPONSE) + w.TapMessage(r) + return nil +} |
