From a3ab188219e4c1e71b0474f0b55e25bfc9965982 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 23 Dec 2020 18:44:41 +0100 Subject: [PATCH] implemented ANY type --- coolDns.go | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/coolDns.go b/coolDns.go index 09f281e..22026f7 100644 --- a/coolDns.go +++ b/coolDns.go @@ -43,6 +43,18 @@ type configZone struct { ACL []string `yaml:"acl"` } +var anyRecordTypes = []uint16{ + dns.TypeSOA, + dns.TypeA, + dns.TypeAAAA, + dns.TypeNS, + dns.TypeCNAME, + dns.TypeMX, + dns.TypeTXT, + dns.TypeSRV, + dns.TypeCAA, +} + func loadConfig() (*config, error) { file, err := ioutil.ReadFile("config.yml") if err != nil { @@ -172,25 +184,36 @@ func createServer(zones []zone, config config, aclList map[string]*net.IPNet) *d for _, q := range r.Question { rrs := z.rr[q.Qtype] - m.Answer = append(m.Answer, rrs[q.Name]...) + // Handle ANY + if q.Qtype == dns.TypeANY { + for _, rrType := range anyRecordTypes { + m.Answer = append(m.Answer, z.rr[rrType][q.Name]...) + } + } else { + // Handle any other type + m.Answer = append(m.Answer, rrs[q.Name]...) - // Check for wildcard - if len(m.Answer) == 0 { - parts := dns.SplitDomainName(q.Name)[1:] - searchDomain := "*." + dns.Fqdn(strings.Join(parts, ".")) - foundDomain := rrs[searchDomain] - for _, rr := range foundDomain { - newRR := rr - newRR.Header().Name = q.Name - m.Answer = append(m.Answer, newRR) + // Check for wildcard + if len(m.Answer) == 0 { + parts := dns.SplitDomainName(q.Name)[1:] + searchDomain := "*." + dns.Fqdn(strings.Join(parts, ".")) + foundDomain := rrs[searchDomain] + for _, rr := range foundDomain { + newRR := rr + newRR.Header().Name = q.Name + m.Answer = append(m.Answer, newRR) + } } } // Handle extras switch q.Qtype { + // Dont handle extra stuff when answering ANY request + // case dns.TypeANY: + // fallthrough case dns.TypeMX: // Resolve MX domains - for _, mxRR := range rrs[q.Name] { + for _, mxRR := range m.Answer { if t, ok := mxRR.(*dns.MX); ok { m.Extra = append(m.Extra, z.rr[dns.TypeA][t.Mx]...) m.Extra = append(m.Extra, z.rr[dns.TypeAAAA][t.Mx]...) @@ -211,7 +234,7 @@ func createServer(zones []zone, config config, aclList map[string]*net.IPNet) *d } case dns.TypeNS: // Resove NS records - for _, nsRR := range rrs[q.Name] { + for _, nsRR := range m.Answer { if t, ok := nsRR.(*dns.NS); ok { m.Extra = append(m.Extra, z.rr[dns.TypeA][t.Ns]...) m.Extra = append(m.Extra, z.rr[dns.TypeAAAA][t.Ns]...)