Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Mar 13, 2024
1 parent 3608a2d commit c11fc3e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
25 changes: 24 additions & 1 deletion internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,29 @@ func (s *Server) prepareLocalResolvers(
return uc, nil
}

// LocalResolversError is an error type for errors during local resolvers setup.
// This is only needed to distinguish these errors from errors returned by
// creating the proxy.
type LocalResolversError struct {
Err error
}

// type check
var _ error = (*LocalResolversError)(nil)

// Error implements the error interface for *localResolversError.
func (err *LocalResolversError) Error() (s string) {
return fmt.Sprintf("creating local resolvers: %s", err.Err)
}

// type check
var _ errors.Wrapper = (*LocalResolversError)(nil)

// Unwrap implements the [errors.Wrapper] interface for *localResolversError.
func (err *LocalResolversError) Unwrap() error {
return err.Err
}

// setupLocalResolvers initializes and sets the resolvers for local addresses.
// It assumes s.serverLock is locked or s not running. It returns the upstream
// configuration used for private PTR resolving, or nil if it's disabled. Note,
Expand All @@ -538,7 +561,7 @@ func (s *Server) setupLocalResolvers(boot upstream.Resolver) (uc *proxy.Upstream
UpstreamConfig: uc,
})
if err != nil {
return nil, fmt.Errorf("creating local resolvers: %w", err)
return nil, &LocalResolversError{Err: err}
}

// TODO(e.burkov): Should we also consider the DNS64 usage?
Expand Down
12 changes: 12 additions & 0 deletions internal/home/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/netutil"
Expand Down Expand Up @@ -157,6 +158,17 @@ func initDNSServer(
}

err = Context.dnsServer.Prepare(dnsConf)

// TODO(e.burkov): Recreate the server with private RDNS disabled. This
// should go away once the private RDNS resolution is moved to the proxy.
var locResErr *dnsforward.LocalResolversError
if errors.As(err, &locResErr) && errors.Is(locResErr.Err, upstream.ErrNoUpstreams) {
log.Info("WARNING: no local resolvers configured while private RDNS " +
"resolution enabled, trying to disable")
dnsConf.UsePrivateRDNS = false
err = Context.dnsServer.Prepare(dnsConf)
}

if err != nil {
return fmt.Errorf("dnsServer.Prepare: %w", err)
}
Expand Down

0 comments on commit c11fc3e

Please sign in to comment.