mirror of
https://github.com/golang/go
synced 2024-11-16 19:34:48 -07:00
net: use the lookupOrder for go resolver LookupAddr
To mach the cgo version behaviour and the LookupHost (go resolver).
Change-Id: I7dc3424d508a62e67f20c7810743399c35a9b60c
GitHub-Last-Rev: 29924c13a6
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>
This commit is contained in:
parent
aff2f4a724
commit
2e7d864f43
@ -810,21 +810,33 @@ func (r *Resolver) goLookupCNAME(ctx context.Context, host string, order hostLoo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// goLookupPTR is the native Go implementation of LookupAddr.
|
// goLookupPTR is the native Go implementation of LookupAddr.
|
||||||
// Used only if cgoLookupPTR refuses to handle the request (that is,
|
func (r *Resolver) goLookupPTR(ctx context.Context, addr string, order hostLookupOrder, conf *dnsConfig) ([]string, error) {
|
||||||
// only if cgoLookupPTR is the stub in cgo_stub.go).
|
if order == hostLookupFiles || order == hostLookupFilesDNS {
|
||||||
// Normally we let cgo use the C library resolver instead of depending
|
names := lookupStaticAddr(addr)
|
||||||
// on our lookup code, so that Go and C get the same answers.
|
if len(names) > 0 {
|
||||||
func (r *Resolver) goLookupPTR(ctx context.Context, addr string, conf *dnsConfig) ([]string, error) {
|
return names, nil
|
||||||
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)
|
arpa, err := reverseaddr(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p, server, err := r.lookup(ctx, arpa, dnsmessage.TypePTR, conf)
|
p, server, err := r.lookup(ctx, arpa, dnsmessage.TypePTR, conf)
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
var ptrs []string
|
var ptrs []string
|
||||||
@ -862,5 +874,6 @@ func (r *Resolver) goLookupPTR(ctx context.Context, addr string, conf *dnsConfig
|
|||||||
ptrs = append(ptrs, ptr.PTR.String())
|
ptrs = append(ptrs, ptr.PTR.String())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ptrs, nil
|
return ptrs, nil
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
func (r *Resolver) lookupAddr(ctx context.Context, addr string) (name []string, err error) {
|
||||||
if _, conf, preferGo := r.preferGoOverPlan9WithOrderAndConf(); preferGo {
|
if order, conf, preferGo := r.preferGoOverPlan9WithOrderAndConf(); preferGo {
|
||||||
return r.goLookupPTR(ctx, addr, conf)
|
return r.goLookupPTR(ctx, addr, order, conf)
|
||||||
}
|
}
|
||||||
arpa, err := reverseaddr(addr)
|
arpa, err := reverseaddr(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -121,7 +121,7 @@ func (r *Resolver) lookupAddr(ctx context.Context, addr string) ([]string, error
|
|||||||
if order == hostLookupCgo {
|
if order == hostLookupCgo {
|
||||||
return cgoLookupPTR(ctx, addr)
|
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
|
// concurrentThreadsLimit returns the number of threads we permit to
|
||||||
|
@ -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) {
|
func (r *Resolver) lookupAddr(ctx context.Context, addr string) ([]string, error) {
|
||||||
if r.preferGoOverWindows() {
|
if order, conf := systemConf().hostLookupOrder(r, ""); order != hostLookupCgo {
|
||||||
return r.goLookupPTR(ctx, addr, nil)
|
return r.goLookupPTR(ctx, addr, order, conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this.
|
// TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this.
|
||||||
|
Loading…
Reference in New Issue
Block a user