Skip to content

Commit 341cd08

Browse files
authored
Merge 29924c1 into 81a31f5
2 parents 81a31f5 + 29924c1 commit 341cd08

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

src/net/dnsclient_unix.go

+21-8
Original file line numberDiff line numberDiff line change
@@ -810,21 +810,33 @@ func (r *Resolver) goLookupCNAME(ctx context.Context, host string, order hostLoo
810810
}
811811

812812
// goLookupPTR is the native Go implementation of LookupAddr.
813-
// Used only if cgoLookupPTR refuses to handle the request (that is,
814-
// only if cgoLookupPTR is the stub in cgo_stub.go).
815-
// Normally we let cgo use the C library resolver instead of depending
816-
// on our lookup code, so that Go and C get the same answers.
817-
func (r *Resolver) goLookupPTR(ctx context.Context, addr string, conf *dnsConfig) ([]string, error) {
818-
names := lookupStaticAddr(addr)
819-
if len(names) > 0 {
820-
return names, nil
813+
func (r *Resolver) goLookupPTR(ctx context.Context, addr string, order hostLookupOrder, conf *dnsConfig) ([]string, error) {
814+
if order == hostLookupFiles || order == hostLookupFilesDNS {
815+
names := lookupStaticAddr(addr)
816+
if len(names) > 0 {
817+
return names, nil
818+
}
819+
820+
if order == hostLookupFiles {
821+
return nil, &DNSError{Err: errNoSuchHost.Error(), Name: addr, IsNotFound: true}
822+
}
821823
}
824+
822825
arpa, err := reverseaddr(addr)
823826
if err != nil {
824827
return nil, err
825828
}
826829
p, server, err := r.lookup(ctx, arpa, dnsmessage.TypePTR, conf)
827830
if err != nil {
831+
var dnsErr *DNSError
832+
if errors.As(err, &dnsErr) && dnsErr.IsNotFound {
833+
if order == hostLookupDNSFiles {
834+
names := lookupStaticAddr(addr)
835+
if len(names) > 0 {
836+
return names, nil
837+
}
838+
}
839+
}
828840
return nil, err
829841
}
830842
var ptrs []string
@@ -862,5 +874,6 @@ func (r *Resolver) goLookupPTR(ctx context.Context, addr string, conf *dnsConfig
862874
ptrs = append(ptrs, ptr.PTR.String())
863875

864876
}
877+
865878
return ptrs, nil
866879
}

src/net/lookup_plan9.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ func (r *Resolver) lookupTXT(ctx context.Context, name string) (txt []string, er
361361
}
362362

363363
func (r *Resolver) lookupAddr(ctx context.Context, addr string) (name []string, err error) {
364-
if _, conf, preferGo := r.preferGoOverPlan9WithOrderAndConf(); preferGo {
365-
return r.goLookupPTR(ctx, addr, conf)
364+
if order, conf, preferGo := r.preferGoOverPlan9WithOrderAndConf(); preferGo {
365+
return r.goLookupPTR(ctx, addr, order, conf)
366366
}
367367
arpa, err := reverseaddr(addr)
368368
if err != nil {

src/net/lookup_unix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (r *Resolver) lookupAddr(ctx context.Context, addr string) ([]string, error
121121
if order == hostLookupCgo {
122122
return cgoLookupPTR(ctx, addr)
123123
}
124-
return r.goLookupPTR(ctx, addr, conf)
124+
return r.goLookupPTR(ctx, addr, order, conf)
125125
}
126126

127127
// concurrentThreadsLimit returns the number of threads we permit to

src/net/lookup_windows.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ func (r *Resolver) lookupTXT(ctx context.Context, name string) ([]string, error)
374374
}
375375

376376
func (r *Resolver) lookupAddr(ctx context.Context, addr string) ([]string, error) {
377-
if r.preferGoOverWindows() {
378-
return r.goLookupPTR(ctx, addr, nil)
377+
if order, conf := systemConf().hostLookupOrder(r, ""); order != hostLookupCgo {
378+
return r.goLookupPTR(ctx, addr, order, conf)
379379
}
380380

381381
// TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this.

0 commit comments

Comments
 (0)