Skip to content

Commit

Permalink
dnsforward: fix http private rdns
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Apr 15, 2024
1 parent ff7c715 commit 851a1a3
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions internal/dnsforward/http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dnsforward

import (
"cmp"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -332,6 +333,28 @@ func (req *jsonDNSConfig) checkBootstrap() (err error) {
return nil
}

// checkPrivateRDNS returns an error if the configuration of the private RDNS is
// not valid.
func (req *jsonDNSConfig) checkPrivateRDNS(
ownAddrs addrPortSet,
sysResolvers SystemResolvers,
privateNets netutil.SubnetSet,
) (err error) {
if (req.UsePrivateRDNS == nil || !*req.UsePrivateRDNS) && req.LocalPTRUpstreams == nil {
return nil
}

addrs := cmp.Or(req.LocalPTRUpstreams, &[]string{})

uc, err := newPrivateConfig(*addrs, ownAddrs, sysResolvers, privateNets, &upstream.Options{})
err = errors.WithDeferred(err, uc.Close())
if err != nil {
return fmt.Errorf("private upstream servers: %w", err)
}

return nil
}

// validateUpstreamDNSServers returns an error if any field of req is invalid.
func (req *jsonDNSConfig) validateUpstreamDNSServers(
ownAddrs addrPortSet,
Expand All @@ -349,12 +372,10 @@ func (req *jsonDNSConfig) validateUpstreamDNSServers(
}
}

if addrs := req.LocalPTRUpstreams; addrs != nil {
uc, err = newPrivateConfig(*addrs, ownAddrs, sysResolvers, privateNets, opts)
err = errors.WithDeferred(err, uc.Close())
if err != nil {
return fmt.Errorf("private upstream servers: %w", err)
}
err = req.checkPrivateRDNS(ownAddrs, sysResolvers, privateNets)
if err != nil {
// Don't wrap the error since it's informative enough as is.
return err
}

err = req.checkBootstrap()
Expand Down Expand Up @@ -440,7 +461,7 @@ func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) {
// TODO(e.burkov): Consider prebuilding this set on startup.
ourAddrs, err := s.conf.ourAddrsSet()
if err != nil {
// TODO(e.burkov): !! Put into openapi
// TODO(e.burkov): Put into openapi
aghhttp.Error(r, w, http.StatusInternalServerError, "getting our addresses: %s", err)

return
Expand Down

0 comments on commit 851a1a3

Please sign in to comment.