DEVELOPMENT ENVIRONMENT

~liljamo/felu

2f76e37d59f15d556726964414f5b16a397a2fe6 — Jonni Liljamo a month ago 6f7f908
feat: improve logging in parseQuery
1 files changed, 11 insertions(+), 2 deletions(-)

M internal/dns/query.go
M internal/dns/query.go => internal/dns/query.go +11 -2
@@ 18,16 18,25 @@ import (

func parseQuery(m *dns.Msg, r *dns.Msg) {
	for _, q := range m.Question {
		slog.Info("Got Query",
			slog.Any("id", r.Id),
			slog.String("type", dns.TypeToString[q.Qtype]),
			slog.String("qname", q.Name),
		)

		switch q.Qtype {
		case dns.TypeA:
			handleARecord(&q, m, r)
		}

		slog.Info("Responding to Query",
			slog.Any("id", r.Id),
			slog.String("rcode", dns.RcodeToString[m.Rcode]),
		)
	}
}

func handleARecord(q *dns.Question, m *dns.Msg, r *dns.Msg) {
	slog.Info("A Record Query", slog.String("qname", q.Name))

	if index := strings.IndexByte(q.Name, '.'); index >= 0 {
		aRecord, err := db.FetchDomainARecord(strings.ToLower(q.Name[:index]))
		if err != nil {