only one question per query
This commit is contained in:
parent
a71b619763
commit
7f40a04638
104
coolDns.go
104
coolDns.go
@ -278,65 +278,69 @@ func handleRequest(w dns.ResponseWriter, r *dns.Msg, zone zoneView) {
|
|||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
m.Authoritative = true
|
m.Authoritative = true
|
||||||
|
|
||||||
// maybe only support one question per query like most servers do it ???
|
// Only support one question per query because all the other server also does that
|
||||||
for _, q := range r.Question {
|
if len(r.Question) != 1 {
|
||||||
rrs := zone.rr[q.Qtype]
|
rcodeRequest(w, r, dns.RcodeServerFailure)
|
||||||
|
}
|
||||||
|
|
||||||
// Handle ANY
|
q := r.Question[0]
|
||||||
if q.Qtype == dns.TypeANY {
|
|
||||||
for _, rrType := range anyRecordTypes {
|
|
||||||
m.Answer = append(m.Answer, zone.rr[rrType][q.Name]...)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Handle any other type
|
|
||||||
m.Answer = append(m.Answer, rrs[q.Name]...)
|
|
||||||
|
|
||||||
// Check for wildcard
|
rrs := zone.rr[q.Qtype]
|
||||||
if len(m.Answer) == 0 {
|
|
||||||
parts := dns.SplitDomainName(q.Name)[1:]
|
// Handle ANY
|
||||||
searchDomain := "*." + dns.Fqdn(strings.Join(parts, "."))
|
if q.Qtype == dns.TypeANY {
|
||||||
foundDomain := rrs[searchDomain]
|
for _, rrType := range anyRecordTypes {
|
||||||
for _, rr := range foundDomain {
|
m.Answer = append(m.Answer, zone.rr[rrType][q.Name]...)
|
||||||
newRR := rr
|
}
|
||||||
newRR.Header().Name = q.Name
|
} else {
|
||||||
m.Answer = append(m.Answer, newRR)
|
// 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle extras
|
// Handle extras
|
||||||
switch q.Qtype {
|
switch q.Qtype {
|
||||||
// Dont handle extra stuff when answering ANY request
|
// Dont handle extra stuff when answering ANY request
|
||||||
// case dns.TypeANY:
|
// case dns.TypeANY:
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case dns.TypeMX:
|
case dns.TypeMX:
|
||||||
// Resolve MX domains
|
// Resolve MX domains
|
||||||
for _, mxRR := range m.Answer {
|
for _, mxRR := range m.Answer {
|
||||||
if t, ok := mxRR.(*dns.MX); ok {
|
if t, ok := mxRR.(*dns.MX); ok {
|
||||||
m.Extra = append(m.Extra, zone.rr[dns.TypeA][t.Mx]...)
|
m.Extra = append(m.Extra, zone.rr[dns.TypeA][t.Mx]...)
|
||||||
m.Extra = append(m.Extra, zone.rr[dns.TypeAAAA][t.Mx]...)
|
m.Extra = append(m.Extra, zone.rr[dns.TypeAAAA][t.Mx]...)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case dns.TypeA, dns.TypeAAAA:
|
}
|
||||||
if len(m.Answer) == 0 {
|
case dns.TypeA, dns.TypeAAAA:
|
||||||
// no A or AAAA found. Look for CNAME
|
if len(m.Answer) == 0 {
|
||||||
m.Answer = append(m.Answer, zone.rr[dns.TypeCNAME][q.Name]...)
|
// no A or AAAA found. Look for CNAME
|
||||||
if len(m.Answer) != 0 {
|
m.Answer = append(m.Answer, zone.rr[dns.TypeCNAME][q.Name]...)
|
||||||
// Resolve CNAME
|
if len(m.Answer) != 0 {
|
||||||
for _, nameRR := range m.Answer {
|
// Resolve CNAME
|
||||||
if t, ok := nameRR.(*dns.CNAME); ok {
|
for _, nameRR := range m.Answer {
|
||||||
m.Answer = append(m.Answer, zone.rr[q.Qtype][t.Target]...)
|
if t, ok := nameRR.(*dns.CNAME); ok {
|
||||||
}
|
m.Answer = append(m.Answer, zone.rr[q.Qtype][t.Target]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case dns.TypeNS:
|
}
|
||||||
// Resove NS records
|
case dns.TypeNS:
|
||||||
for _, nsRR := range m.Answer {
|
// Resove NS records
|
||||||
if t, ok := nsRR.(*dns.NS); ok {
|
for _, nsRR := range m.Answer {
|
||||||
m.Extra = append(m.Extra, zone.rr[dns.TypeA][t.Ns]...)
|
if t, ok := nsRR.(*dns.NS); ok {
|
||||||
m.Extra = append(m.Extra, zone.rr[dns.TypeAAAA][t.Ns]...)
|
m.Extra = append(m.Extra, zone.rr[dns.TypeA][t.Ns]...)
|
||||||
}
|
m.Extra = append(m.Extra, zone.rr[dns.TypeAAAA][t.Ns]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user