diff --git a/coolDns.go b/coolDns.go index 1d4b429..c753141 100644 --- a/coolDns.go +++ b/coolDns.go @@ -7,6 +7,7 @@ import ( "os" "os/signal" "strconv" + "strings" "syscall" "github.com/miekg/dns" @@ -161,15 +162,26 @@ func createServer(zones []zone, config config, aclList map[string]*net.IPNet) *d // maybe only support one question per query like most servers do it ??? for _, q := range r.Question { - rr := z.rr[q.Qtype] + rrs := z.rr[q.Qtype] - m.Answer = append(m.Answer, rr[q.Name]...) + 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 { + rr.Header().Name = q.Name + m.Answer = append(m.Answer, rr) + } + } // Handle extras switch q.Qtype { case dns.TypeMX: // Resolve MX domains - for _, mxRR := range rr[q.Name] { + for _, mxRR := range rrs[q.Name] { 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]...) @@ -190,7 +202,7 @@ func createServer(zones []zone, config config, aclList map[string]*net.IPNet) *d } case dns.TypeNS: // Resove NS records - for _, nsRR := range rr[q.Name] { + for _, nsRR := range rrs[q.Name] { 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]...) diff --git a/zonefile.txt b/zonefile.txt index 600b05f..24ac715 100644 --- a/zonefile.txt +++ b/zonefile.txt @@ -16,3 +16,5 @@ wwwtest IN CNAME www ; wwwtest.example.com is another a mail IN A 192.0.2.3 ; IPv4 address for mail.example.com mail2 IN A 192.0.2.4 ; IPv4 address for mail2.example.com mail3 IN A 192.0.2.5 ; IPv4 address for mail3.example.com +*.www IN A 192.1.0.1 +a.www IN A 192.1.0.11 \ No newline at end of file