MCPcopy
hub / github.com/AdguardTeam/dnsproxy / selectUpstreams

Method selectUpstreams

proxy/proxy.go:549–579  ·  view source on GitHub ↗

selectUpstreams returns the upstreams to use for the specified host. It firstly considers custom upstreams if those aren't empty and then the configured ones. The returned slice may be empty or nil.

(d *DNSContext)

Source from the content-addressed store, hash-verified

547// firstly considers custom upstreams if those aren't empty and then the
548// configured ones. The returned slice may be empty or nil.
549func (p *Proxy) selectUpstreams(d *DNSContext) (upstreams []upstream.Upstream, isPrivate bool) {
550 q := d.Req.Question[0]
551 host := q.Name
552
553 if d.RequestedPrivateRDNS != (netip.Prefix{}) || p.shouldStripDNS64(d.Req) {
554 // Use private upstreams.
555 private := p.PrivateRDNSUpstreamConfig
556 if p.UsePrivateRDNS && d.IsPrivateClient && private != nil {
557 // This may only be a PTR, SOA, and NS request.
558 upstreams = private.getUpstreamsForDomain(host)
559 }
560
561 return upstreams, true
562 }
563
564 getUpstreams := (*UpstreamConfig).getUpstreamsForDomain
565 if q.Qtype == dns.TypeDS {
566 getUpstreams = (*UpstreamConfig).getUpstreamsForDS
567 }
568
569 if custom := d.CustomUpstreamConfig; custom != nil {
570 // Try to use custom.
571 upstreams = getUpstreams(custom.upstream, host)
572 if len(upstreams) > 0 {
573 return upstreams, false
574 }
575 }
576
577 // Use configured.
578 return getUpstreams(p.UpstreamConfig, host), false
579}
580
581// replyFromUpstream tries to resolve the request via configured upstream
582// servers. It returns true if the response actually came from an upstream.

Callers 1

replyFromUpstreamMethod · 0.95

Calls 2

shouldStripDNS64Method · 0.95
getUpstreamsForDomainMethod · 0.80

Tested by

no test coverage detected