Skip to content

Commit

Permalink
Don't continue to next handler on match domains
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal committed Dec 12, 2024
1 parent 8a71b7e commit 2ff4d54
Showing 1 changed file with 0 additions and 17 deletions.
17 changes: 0 additions & 17 deletions client/internal/dns/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,18 @@ func (u *upstreamResolverBase) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
u.failsCount.Add(1)
log.WithError(err).WithField("upstream", upstream).
Error("got other error while querying the upstream")
u.continueToNextHandler(w, r, fmt.Sprintf("upstream query error: %v", err))
return
}

if rm == nil {
log.WithError(err).WithField("upstream", upstream).
Warn("no response from upstream")
u.continueToNextHandler(w, r, "no response from upstream")
return
}
// those checks need to be independent of each other due to memory address issues
if !rm.Response {
log.WithError(err).WithField("upstream", upstream).
Warn("no response from upstream")
u.continueToNextHandler(w, r, "invalid response from upstream")
return
}

Expand All @@ -146,22 +143,8 @@ func (u *upstreamResolverBase) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
}
u.failsCount.Add(1)
log.Error("all queries to the upstream nameservers failed with timeout")
u.continueToNextHandler(w, r, "all upstream queries failed")
}

// continueToNextHandler signals the handler chain to try the next handler
func (u *upstreamResolverBase) continueToNextHandler(w dns.ResponseWriter, r *dns.Msg, reason string) {
log.Debugf("continuing to next handler for %s: %s", r.Question[0].Name, reason)
resp := new(dns.Msg)
resp.SetRcode(r, dns.RcodeNameError)
resp.MsgHdr.Zero = true // Signal to continue
if err := w.WriteMsg(resp); err != nil {
log.Errorf("failed writing DNS continue response: %v", err)
}
}

// Rest of the code remains the same...

// checkUpstreamFails counts fails and disables or enables upstream resolving
//
// If fails count is greater that failsTillDeact, upstream resolving
Expand Down

0 comments on commit 2ff4d54

Please sign in to comment.