mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-25 03:36:41 +00:00
Fix linter
This commit is contained in:
@@ -102,56 +102,57 @@ func (u *upstreamResolver) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
|||||||
|
|
||||||
for _, upstream := range u.upstreamServers {
|
for _, upstream := range u.upstreamServers {
|
||||||
var (
|
var (
|
||||||
err error
|
exchangeErr error
|
||||||
t time.Duration
|
t time.Duration
|
||||||
rm *dns.Msg
|
rm *dns.Msg
|
||||||
)
|
)
|
||||||
|
|
||||||
upstreamExchangeClient := &dns.Client{}
|
upstreamExchangeClient := &dns.Client{}
|
||||||
if runtime.GOOS != "ios" {
|
if runtime.GOOS != "ios" {
|
||||||
ctx, cancel := context.WithTimeout(u.ctx, u.upstreamTimeout)
|
ctx, cancel := context.WithTimeout(u.ctx, u.upstreamTimeout)
|
||||||
rm, t, err = upstreamExchangeClient.ExchangeContext(ctx, r, upstream)
|
rm, t, exchangeErr = upstreamExchangeClient.ExchangeContext(ctx, r, upstream)
|
||||||
cancel()
|
cancel()
|
||||||
} else {
|
} else {
|
||||||
upstreamHost, _, err := net.SplitHostPort(upstream)
|
upstreamHost, _, err := net.SplitHostPort(upstream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("error while parsing upstream host: %s", err)
|
log.Errorf("error while parsing upstream host: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
upstreamIP := net.ParseIP(upstreamHost)
|
upstreamIP := net.ParseIP(upstreamHost)
|
||||||
if u.lNet.Contains(upstreamIP) || net.IP.IsPrivate(upstreamIP) {
|
if u.lNet.Contains(upstreamIP) || net.IP.IsPrivate(upstreamIP) {
|
||||||
log.Debugf("using private client to query upstream: %s", upstream)
|
log.Debugf("using private client to query upstream: %s", upstream)
|
||||||
upstreamExchangeClient = u.getClientPrivate()
|
upstreamExchangeClient = u.getClientPrivate()
|
||||||
}
|
}
|
||||||
rm, t, err = upstreamExchangeClient.Exchange(r, upstream)
|
rm, t, exchangeErr = upstreamExchangeClient.Exchange(r, upstream)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if exchangeErr != nil {
|
||||||
if err == context.DeadlineExceeded || isTimeout(err) {
|
if exchangeErr == context.DeadlineExceeded || isTimeout(exchangeErr) {
|
||||||
log.WithError(err).WithField("upstream", upstream).
|
log.WithError(exchangeErr).WithField("upstream", upstream).
|
||||||
Warn("got an error while connecting to upstream")
|
Warn("got an error while connecting to upstream")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
u.failsCount.Add(1)
|
u.failsCount.Add(1)
|
||||||
log.WithError(err).WithField("upstream", upstream).
|
log.WithError(exchangeErr).WithField("upstream", upstream).
|
||||||
Error("got other error while querying the upstream")
|
Error("got other error while querying the upstream")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if rm == nil {
|
if rm == nil {
|
||||||
log.WithError(err).WithField("upstream", upstream).
|
log.WithError(exchangeErr).WithField("upstream", upstream).
|
||||||
Warn("no response from upstream")
|
Warn("no response from upstream")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// those checks need to be independent of each other due to memory address issues
|
// those checks need to be independent of each other due to memory address issues
|
||||||
if !rm.Response {
|
if !rm.Response {
|
||||||
log.WithError(err).WithField("upstream", upstream).
|
log.WithError(exchangeErr).WithField("upstream", upstream).
|
||||||
Warn("no response from upstream")
|
Warn("no response from upstream")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Tracef("took %s to query the upstream %s", t, upstream)
|
log.Tracef("took %s to query the upstream %s", t, upstream)
|
||||||
|
|
||||||
err = w.WriteMsg(rm)
|
err := w.WriteMsg(rm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("got an error while writing the upstream resolver response")
|
log.WithError(err).Error("got an error while writing the upstream resolver response")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user