implemented ANY type
This commit is contained in:
parent
c283d7a108
commit
a3ab188219
47
coolDns.go
47
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]...)
|
||||
|
Loading…
Reference in New Issue
Block a user