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"`
|
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,25 +184,36 @@ 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]
|
||||||
|
|
||||||
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
|
// Check for wildcard
|
||||||
if len(m.Answer) == 0 {
|
if len(m.Answer) == 0 {
|
||||||
parts := dns.SplitDomainName(q.Name)[1:]
|
parts := dns.SplitDomainName(q.Name)[1:]
|
||||||
searchDomain := "*." + dns.Fqdn(strings.Join(parts, "."))
|
searchDomain := "*." + dns.Fqdn(strings.Join(parts, "."))
|
||||||
foundDomain := rrs[searchDomain]
|
foundDomain := rrs[searchDomain]
|
||||||
for _, rr := range foundDomain {
|
for _, rr := range foundDomain {
|
||||||
newRR := rr
|
newRR := rr
|
||||||
newRR.Header().Name = q.Name
|
newRR.Header().Name = q.Name
|
||||||
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]...)
|
||||||
|
Loading…
Reference in New Issue
Block a user