Skip to content

Commit

Permalink
dnsforward: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Sep 25, 2023
1 parent 23d6970 commit cad1e4e
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions internal/dnsforward/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,9 @@ func (s *Server) getDNSConfig() (c *jsonDNSConfig) {
upstreamMode = "parallel"
}

defLocalPTRUps := []string{}
uc, err := s.prepareLocalUpstreamConfig(s.sysResolvers.Get(), nil, nil)
defPTRUps, err := s.defaultLocalPTRUpstreams()
if err != nil {
log.Error("dnsforward: getting system upstream config: %s", err)
} else {
for _, u := range uc.Upstreams {
defLocalPTRUps = append(defLocalPTRUps, u.Address())
}

if err = uc.Close(); err != nil {
log.Error("dnsforward: closing system upstream config: %s", err)
}
log.Error("dnsforward: %s", err)
}

return &jsonDNSConfig{
Expand All @@ -180,11 +171,30 @@ func (s *Server) getDNSConfig() (c *jsonDNSConfig) {
ResolveClients: &resolveClients,
UsePrivateRDNS: &usePrivateRDNS,
LocalPTRUpstreams: &localPTRUpstreams,
DefaultLocalPTRUpstreams: defLocalPTRUps,
DefaultLocalPTRUpstreams: defPTRUps,
DisabledUntil: protectionDisabledUntil,
}
}

// defaultLocalPTRUpstreams returns the list of default local PTR resolvers
// filtered of AdGuard Home's own DNS server addresses. It may appear empty.
func (s *Server) defaultLocalPTRUpstreams() (ups []string, err error) {
s.serverLock.RLock()
defer s.serverLock.RUnlock()

uc, err := s.prepareLocalUpstreamConfig(s.sysResolvers.Get(), nil, nil)
if err != nil {
return nil, fmt.Errorf("getting system upstream config: %w", err)
}
defer func() { err = errors.Join(err, uc.Close()) }()

for _, u := range uc.Upstreams {
ups = append(ups, u.Address())
}

return ups, nil
}

// handleGetConfig handles requests to the GET /control/dns_info endpoint.
func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) {
resp := s.getDNSConfig()
Expand Down

0 comments on commit cad1e4e

Please sign in to comment.