DEVELOPMENT ENVIRONMENT

~liljamo/felu

5cb0ede24d635ae70163096f3119b99b72887786 — Jonni Liljamo 28 days ago 4f502ff
feat: handle root A
1 files changed, 14 insertions(+), 2 deletions(-)

M internal/dns/query.go
M internal/dns/query.go => internal/dns/query.go +14 -2
@@ 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 {