Skip to content

Commit

Permalink
Merge joohoi#264 to our fork
Browse files Browse the repository at this point in the history
Co-authored-by: İlteriş Yağıztegin Eroğlu <[email protected]>
Signed-off-by: İlteriş Yağıztegin Eroğlu <[email protected]>
  • Loading branch information
Yannik and linuxgemini committed Feb 9, 2022
1 parent eee1c6a commit 86dfdfb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func (d *DNSServer) readQuery(m *dns.Msg, remoteAddr net.Addr) {
}
m.MsgHdr.Authoritative = authoritative
if authoritative {
if m.MsgHdr.Rcode == dns.RcodeNameError {
if m.MsgHdr.Rcode == dns.RcodeNameError ||
(m.MsgHdr.Rcode == dns.RcodeSuccess && len(m.Answer) == 0) {
m.Ns = append(m.Ns, d.SOA)
}
}
Expand Down Expand Up @@ -161,6 +162,17 @@ func (d *DNSServer) answeringForDomain(name string) bool {
_, ok := d.Domains[strings.ToLower(name)]
return ok
}
// hasTxtForDomain checks if we have txt records for a domain
func (d *DNSServer) hasTxtForDomain(q dns.Question) bool {
subdomain := sanitizeDomainQuestion(q.Name)
txts, err := d.DB.GetTXTForDomain(subdomain)
if err != nil {
log.WithFields(log.Fields{"error": err.Error()}).Debug("Error while trying to get record")
return false
}
return len(txts) > 0
}


func (d *DNSServer) isAuthoritative(q dns.Question) bool {
if d.answeringForDomain(q.Name) {
Expand Down Expand Up @@ -197,7 +209,7 @@ func (d *DNSServer) answer(q dns.Question, remoteAddr net.Addr) ([]dns.RR, int,
var err error
var txtRRs []dns.RR
var authoritative = d.isAuthoritative(q)
if !d.isOwnChallenge(q.Name) && !d.answeringForDomain(q.Name) {
if !d.isOwnChallenge(q.Name) && !d.answeringForDomain(q.Name) && !d.hasTxtForDomain(q) {
rcode = dns.RcodeNameError
}
r, _ := d.getRecord(q)
Expand Down

0 comments on commit 86dfdfb

Please sign in to comment.