implemented ANY type

This commit is contained in:
Niklas 2020-12-23 18:44:41 +01:00
parent c283d7a108
commit a3ab188219

View File

@ -43,6 +43,18 @@ type configZone struct {
ACL []string `yaml:"acl"` 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) { func loadConfig() (*config, error) {
file, err := ioutil.ReadFile("config.yml") file, err := ioutil.ReadFile("config.yml")
if err != nil { if err != nil {
@ -172,6 +184,13 @@ func createServer(zones []zone, config config, aclList map[string]*net.IPNet) *d
for _, q := range r.Question { for _, q := range r.Question {
rrs := z.rr[q.Qtype] rrs := z.rr[q.Qtype]
// 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]...) m.Answer = append(m.Answer, rrs[q.Name]...)
// Check for wildcard // Check for wildcard
@ -185,12 +204,16 @@ func createServer(zones []zone, config config, aclList map[string]*net.IPNet) *d
m.Answer = append(m.Answer, newRR) m.Answer = append(m.Answer, newRR)
} }
} }
}
// Handle extras // Handle extras
switch q.Qtype { switch q.Qtype {
// Dont handle extra stuff when answering ANY request
// case dns.TypeANY:
// fallthrough
case dns.TypeMX: case dns.TypeMX:
// Resolve MX domains // Resolve MX domains
for _, mxRR := range rrs[q.Name] { for _, mxRR := range m.Answer {
if t, ok := mxRR.(*dns.MX); ok { 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.TypeA][t.Mx]...)
m.Extra = append(m.Extra, z.rr[dns.TypeAAAA][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: case dns.TypeNS:
// Resove NS records // Resove NS records
for _, nsRR := range rrs[q.Name] { for _, nsRR := range m.Answer {
if t, ok := nsRR.(*dns.NS); ok { 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.TypeA][t.Ns]...)
m.Extra = append(m.Extra, z.rr[dns.TypeAAAA][t.Ns]...) m.Extra = append(m.Extra, z.rr[dns.TypeAAAA][t.Ns]...)