dnstap: uses pointer receiver for small response writer (#6644)

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Takeshi Yoneda 2024-04-27 04:08:47 +09:00 committed by GitHub
parent 4531515f2b
commit a7ed346585
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View file

@ -27,7 +27,7 @@ type Dnstap struct {
} }
// TapMessage sends the message m to the dnstap interface, without populating "Extra" field. // TapMessage sends the message m to the dnstap interface, without populating "Extra" field.
func (h Dnstap) TapMessage(m *tap.Message) { func (h *Dnstap) TapMessage(m *tap.Message) {
if h.ExtraFormat == "" { if h.ExtraFormat == "" {
h.tapWithExtra(m, nil) h.tapWithExtra(m, nil)
} else { } else {
@ -36,7 +36,7 @@ func (h Dnstap) TapMessage(m *tap.Message) {
} }
// TapMessageWithMetadata sends the message m to the dnstap interface, with "Extra" field being populated. // TapMessageWithMetadata sends the message m to the dnstap interface, with "Extra" field being populated.
func (h Dnstap) TapMessageWithMetadata(ctx context.Context, m *tap.Message, state request.Request) { func (h *Dnstap) TapMessageWithMetadata(ctx context.Context, m *tap.Message, state request.Request) {
if h.ExtraFormat == "" { if h.ExtraFormat == "" {
h.tapWithExtra(m, nil) h.tapWithExtra(m, nil)
return return
@ -45,12 +45,12 @@ func (h Dnstap) TapMessageWithMetadata(ctx context.Context, m *tap.Message, stat
h.tapWithExtra(m, []byte(extraStr)) h.tapWithExtra(m, []byte(extraStr))
} }
func (h Dnstap) tapWithExtra(m *tap.Message, extra []byte) { func (h *Dnstap) tapWithExtra(m *tap.Message, extra []byte) {
t := tap.Dnstap_MESSAGE t := tap.Dnstap_MESSAGE
h.io.Dnstap(&tap.Dnstap{Type: &t, Message: m, Identity: h.Identity, Version: h.Version, Extra: extra}) h.io.Dnstap(&tap.Dnstap{Type: &t, Message: m, Identity: h.Identity, Version: h.Version, Extra: extra})
} }
func (h Dnstap) tapQuery(ctx context.Context, w dns.ResponseWriter, query *dns.Msg, queryTime time.Time) { func (h *Dnstap) tapQuery(ctx context.Context, w dns.ResponseWriter, query *dns.Msg, queryTime time.Time) {
q := new(tap.Message) q := new(tap.Message)
msg.SetQueryTime(q, queryTime) msg.SetQueryTime(q, queryTime)
msg.SetQueryAddress(q, w.RemoteAddr()) msg.SetQueryAddress(q, w.RemoteAddr())
@ -65,7 +65,7 @@ func (h Dnstap) tapQuery(ctx context.Context, w dns.ResponseWriter, query *dns.M
} }
// ServeDNS logs the client query and response to dnstap and passes the dnstap Context. // ServeDNS logs the client query and response to dnstap and passes the dnstap Context.
func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { func (h *Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
rw := &ResponseWriter{ rw := &ResponseWriter{
ResponseWriter: w, ResponseWriter: w,
Dnstap: h, Dnstap: h,
@ -82,4 +82,4 @@ func (h Dnstap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
} }
// Name implements the plugin.Plugin interface. // Name implements the plugin.Plugin interface.
func (h Dnstap) Name() string { return "dnstap" } func (h *Dnstap) Name() string { return "dnstap" }

View file

@ -17,7 +17,7 @@ type ResponseWriter struct {
query *dns.Msg query *dns.Msg
ctx context.Context ctx context.Context
dns.ResponseWriter dns.ResponseWriter
Dnstap *Dnstap
} }
// WriteMsg writes back the response to the client and THEN works on logging the request and response to dnstap. // WriteMsg writes back the response to the client and THEN works on logging the request and response to dnstap.