implemented wildcards

This commit is contained in:
Niklas 2020-12-22 22:13:32 +01:00
parent f77c41c13d
commit fb5e3eb26d
2 changed files with 18 additions and 4 deletions

View File

@ -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]...)

View File

@ -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