From 5cb0ede24d635ae70163096f3119b99b72887786 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Thu, 24 Oct 2024 15:27:09 +0300 Subject: [PATCH] feat: handle root A --- internal/dns/query.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/dns/query.go b/internal/dns/query.go index f3e0420..3962d84 100644 --- a/internal/dns/query.go +++ b/internal/dns/query.go @@ -49,8 +49,20 @@ func parseQuery(m *dns.Msg, r *dns.Msg) { } func handleARecord(q *dns.Question, m *dns.Msg, r *dns.Msg) { - if index := strings.IndexByte(q.Name, '.'); index >= 0 { - aRecord, err := db.FetchDomainARecord(strings.ToLower(q.Name[:index])) + qName := strings.ToLower(q.Name) + + // TODO: This is probably not a great way to handle this, but it is what it is. For now. + // "Root" Domain A. + if qName == config.FeluConfig.Domain { + m.Answer = append(m.Answer, &dns.A{ + Hdr: dns.RR_Header{Name: q.Name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 60}, + A: net.ParseIP(config.FeluConfig.IPv4), + }) + return + } + + if index := strings.IndexByte(qName, '.'); index >= 0 { + aRecord, err := db.FetchDomainARecord(qName[:index]) if err != nil { m.SetRcode(r, dns.RcodeNameError) } else { -- 2.44.1