]> Cypherpunks repositories - gostls13.git/commitdiff
net: use the lookupOrder for go resolver LookupAddr
authorMateusz Poliwczak <mpoliwczak34@gmail.com>
Sun, 7 May 2023 13:51:15 +0000 (13:51 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 11 May 2023 16:11:07 +0000 (16:11 +0000)
To mach the cgo version behaviour and the LookupHost (go resolver).

Change-Id: I7dc3424d508a62e67f20c7810743399c35a9b60c
GitHub-Last-Rev: 29924c13a6c0598bf58b7fc3fae74b10bab0f0ee
GitHub-Pull-Request: golang/go#60024
Reviewed-on: https://go-review.googlesource.com/c/go/+/493235
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/net/dnsclient_unix.go
src/net/lookup_plan9.go
src/net/lookup_unix.go
src/net/lookup_windows.go

index 6923f6a4a78145f93cf39212a93d6e3af3744e0f..f3c075c83fd2a080f4c133a8012eedde9db8dfad 100644 (file)
@@ -810,21 +810,33 @@ func (r *Resolver) goLookupCNAME(ctx context.Context, host string, order hostLoo
 }
 
 // goLookupPTR is the native Go implementation of LookupAddr.
-// Used only if cgoLookupPTR refuses to handle the request (that is,
-// only if cgoLookupPTR is the stub in cgo_stub.go).
-// Normally we let cgo use the C library resolver instead of depending
-// on our lookup code, so that Go and C get the same answers.
-func (r *Resolver) goLookupPTR(ctx context.Context, addr string, conf *dnsConfig) ([]string, error) {
-       names := lookupStaticAddr(addr)
-       if len(names) > 0 {
-               return names, nil
+func (r *Resolver) goLookupPTR(ctx context.Context, addr string, order hostLookupOrder, conf *dnsConfig) ([]string, error) {
+       if order == hostLookupFiles || order == hostLookupFilesDNS {
+               names := lookupStaticAddr(addr)
+               if len(names) > 0 {
+                       return names, nil
+               }
+
+               if order == hostLookupFiles {
+                       return nil, &DNSError{Err: errNoSuchHost.Error(), Name: addr, IsNotFound: true}
+               }
        }
+
        arpa, err := reverseaddr(addr)
        if err != nil {
                return nil, err
        }
        p, server, err := r.lookup(ctx, arpa, dnsmessage.TypePTR, conf)
        if err != nil {
+               var dnsErr *DNSError
+               if errors.As(err, &dnsErr) && dnsErr.IsNotFound {
+                       if order == hostLookupDNSFiles {
+                               names := lookupStaticAddr(addr)
+                               if len(names) > 0 {
+                                       return names, nil
+                               }
+                       }
+               }
                return nil, err
        }
        var ptrs []string
@@ -862,5 +874,6 @@ func (r *Resolver) goLookupPTR(ctx context.Context, addr string, conf *dnsConfig
                ptrs = append(ptrs, ptr.PTR.String())
 
        }
+
        return ptrs, nil
 }
index 7c423bfff6f4e70852e85553485882baa6d58f7b..5404b996e449395c89dcec49226af27dd3351260 100644 (file)
@@ -361,8 +361,8 @@ func (r *Resolver) lookupTXT(ctx context.Context, name string) (txt []string, er
 }
 
 func (r *Resolver) lookupAddr(ctx context.Context, addr string) (name []string, err error) {
-       if _, conf, preferGo := r.preferGoOverPlan9WithOrderAndConf(); preferGo {
-               return r.goLookupPTR(ctx, addr, conf)
+       if order, conf, preferGo := r.preferGoOverPlan9WithOrderAndConf(); preferGo {
+               return r.goLookupPTR(ctx, addr, order, conf)
        }
        arpa, err := reverseaddr(addr)
        if err != nil {
index 6607b5996a0965a718b8b1a7790adaeac7e38368..ad35551f9d5c27dfd81189d8fac784eadb2680c7 100644 (file)
@@ -121,7 +121,7 @@ func (r *Resolver) lookupAddr(ctx context.Context, addr string) ([]string, error
        if order == hostLookupCgo {
                return cgoLookupPTR(ctx, addr)
        }
-       return r.goLookupPTR(ctx, addr, conf)
+       return r.goLookupPTR(ctx, addr, order, conf)
 }
 
 // concurrentThreadsLimit returns the number of threads we permit to
index 9f88d828543ee97669e382fa887ec6069ad78995..33d5ac5fb45d6a39c3f917b51dc6740bf8274add 100644 (file)
@@ -374,8 +374,8 @@ func (r *Resolver) lookupTXT(ctx context.Context, name string) ([]string, error)
 }
 
 func (r *Resolver) lookupAddr(ctx context.Context, addr string) ([]string, error) {
-       if r.preferGoOverWindows() {
-               return r.goLookupPTR(ctx, addr, nil)
+       if order, conf := systemConf().hostLookupOrder(r, ""); order != hostLookupCgo {
+               return r.goLookupPTR(ctx, addr, order, conf)
        }
 
        // TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this.