net/dns/resolver: unexport Resolve and ResolveReverse.

They're only used internally and in tests, and have surprising
semantics in that they only resolve MagicDNS names, not upstream
resolver queries.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2021-03-31 23:35:26 -07:00
parent cdeb8d6816
commit dbe4f6f42d
2 changed files with 9 additions and 9 deletions

View File

@ -171,10 +171,10 @@ func (r *Resolver) NextResponse() (packet []byte, to netaddr.IPPort, err error)
}
}
// Resolve maps a given domain name to the IP address of the host that owns it,
// resolve maps a given domain name to the IP address of the host that owns it,
// if the IP address conforms to the DNS resource type given by tp (one of A, AAAA, ALL).
// The domain name must be in canonical form (with a trailing period).
func (r *Resolver) Resolve(domain string, tp dns.Type) (netaddr.IP, dns.RCode, error) {
func (r *Resolver) resolve(domain string, tp dns.Type) (netaddr.IP, dns.RCode, error) {
r.mu.Lock()
dnsMap := r.dnsMap
r.mu.Unlock()
@ -240,9 +240,9 @@ func (r *Resolver) Resolve(domain string, tp dns.Type) (netaddr.IP, dns.RCode, e
}
}
// ResolveReverse returns the unique domain name that maps to the given address.
// resolveReverse returns the unique domain name that maps to the given address.
// The returned domain name is in canonical form (with a trailing period).
func (r *Resolver) ResolveReverse(ip netaddr.IP) (string, dns.RCode, error) {
func (r *Resolver) resolveReverse(ip netaddr.IP) (string, dns.RCode, error) {
r.mu.Lock()
dnsMap := r.dnsMap
r.mu.Unlock()
@ -567,7 +567,7 @@ func (r *Resolver) respondReverse(query []byte, name string, resp *response) ([]
}
var err error
resp.Name, resp.Header.RCode, err = r.ResolveReverse(ip)
resp.Name, resp.Header.RCode, err = r.resolveReverse(ip)
if err != nil {
r.logf("resolving rdns: %v", ip, err)
}
@ -607,7 +607,7 @@ func (r *Resolver) respond(query []byte) ([]byte, error) {
return r.respondReverse(query, name, resp)
}
resp.IP, resp.Header.RCode, err = r.Resolve(name, resp.Question.Type)
resp.IP, resp.Header.RCode, err = r.resolve(name, resp.Question.Type)
// This return code is special: it requests forwarding.
if resp.Header.RCode == dns.RCodeRefused {
return nil, errNotOurName

View File

@ -223,7 +223,7 @@ func TestResolve(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ip, code, err := r.Resolve(tt.qname, tt.qtype)
ip, code, err := r.resolve(tt.qname, tt.qtype)
if err != nil {
t.Errorf("err = %v; want nil", err)
}
@ -260,7 +260,7 @@ func TestResolveReverse(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
name, code, err := r.ResolveReverse(tt.ip)
name, code, err := r.resolveReverse(tt.ip)
if err != nil {
t.Errorf("err = %v; want nil", err)
}
@ -476,7 +476,7 @@ func TestConcurrentSetMap(t *testing.T) {
}()
go func() {
defer wg.Done()
r.Resolve("test1.ipn.dev", dns.TypeA)
r.resolve("test1.ipn.dev", dns.TypeA)
}()
wg.Wait()
}