// required to use the go resolver. The provided Resolver is optional.
// This will report true if the cgo resolver is not available.
func (c *conf) mustUseGoResolver(r *Resolver) bool {
- return c.netGo || r.preferGo() || !cgoAvailable
+ if !cgoAvailable {
+ return true
+ }
+
+ if runtime.GOOS == "plan9" {
+ // TODO(bradfitz): for now we only permit use of the PreferGo
+ // implementation when there's a non-nil Resolver with a
+ // non-nil Dialer. This is a sign that they the code is trying
+ // to use their DNS-speaking net.Conn (such as an in-memory
+ // DNS cache) and they don't want to actually hit the network.
+ // Once we add support for looking the default DNS servers
+ // from plan9, though, then we can relax this.
+ if r == nil || r.Dial == nil {
+ return false
+ }
+ }
+
+ return c.netGo || r.preferGo()
}
// addrLookupOrder determines which strategy to use to resolve addresses.
// goLookupIP is the native Go implementation of LookupIP.
// The libc versions are in cgo_*.go.
-func (r *Resolver) goLookupIP(ctx context.Context, network, host string) (addrs []IPAddr, err error) {
- order, conf := systemConf().hostLookupOrder(r, host)
+func (r *Resolver) goLookupIP(ctx context.Context, network, host string, order hostLookupOrder, conf *dnsConfig) (addrs []IPAddr, err error) {
addrs, _, err = r.goLookupIPCNAMEOrder(ctx, network, host, order, conf)
return
}
return
}
-// preferGoOverPlan9 reports whether the resolver should use the
-// "PreferGo" implementation rather than asking plan9 services
-// for the answers.
-func (r *Resolver) preferGoOverPlan9() bool {
- _, _, res := r.preferGoOverPlan9WithOrderAndConf()
- return res
-}
-
-func (r *Resolver) preferGoOverPlan9WithOrderAndConf() (hostLookupOrder, *dnsConfig, bool) {
- order, conf := systemConf().hostLookupOrder(r, "") // name is unused
-
- // TODO(bradfitz): for now we only permit use of the PreferGo
- // implementation when there's a non-nil Resolver with a
- // non-nil Dialer. This is a sign that they the code is trying
- // to use their DNS-speaking net.Conn (such as an in-memory
- // DNS cache) and they don't want to actually hit the network.
- // Once we add support for looking the default DNS servers
- // from plan9, though, then we can relax this.
- return order, conf, order != hostLookupCgo && r != nil && r.Dial != nil
-}
-
func (r *Resolver) lookupIP(ctx context.Context, network, host string) (addrs []IPAddr, err error) {
- if r.preferGoOverPlan9() {
- return r.goLookupIP(ctx, network, host)
+ if order, conf := systemConf().hostLookupOrder(r, host); order != hostLookupCgo {
+ return r.goLookupIP(ctx, network, host, order, conf)
}
+
lits, err := r.lookupHost(ctx, host)
if err != nil {
return
}
func (r *Resolver) lookupCNAME(ctx context.Context, name string) (cname string, err error) {
- if order, conf, preferGo := r.preferGoOverPlan9WithOrderAndConf(); preferGo {
+ if order, conf := systemConf().hostLookupOrder(r, name); order != hostLookupCgo {
return r.goLookupCNAME(ctx, name, order, conf)
}
}
func (r *Resolver) lookupSRV(ctx context.Context, service, proto, name string) (cname string, addrs []*SRV, err error) {
- if r.preferGoOverPlan9() {
+ if systemConf().mustUseGoResolver(r) {
return r.goLookupSRV(ctx, service, proto, name)
}
var target string
}
func (r *Resolver) lookupMX(ctx context.Context, name string) (mx []*MX, err error) {
- if r.preferGoOverPlan9() {
+ if systemConf().mustUseGoResolver(r) {
return r.goLookupMX(ctx, name)
}
lines, err := queryDNS(ctx, name, "mx")
}
func (r *Resolver) lookupNS(ctx context.Context, name string) (ns []*NS, err error) {
- if r.preferGoOverPlan9() {
+ if systemConf().mustUseGoResolver(r) {
return r.goLookupNS(ctx, name)
}
lines, err := queryDNS(ctx, name, "ns")
}
func (r *Resolver) lookupTXT(ctx context.Context, name string) (txt []string, err error) {
- if r.preferGoOverPlan9() {
+ if systemConf().mustUseGoResolver(r) {
return r.goLookupTXT(ctx, name)
}
lines, err := queryDNS(ctx, name, "txt")
}
func (r *Resolver) lookupAddr(ctx context.Context, addr string) (name []string, err error) {
- if order, conf, preferGo := r.preferGoOverPlan9WithOrderAndConf(); preferGo {
+ if order, conf := systemConf().addrLookupOrder(r, addr); order != hostLookupCgo {
return r.goLookupPTR(ctx, addr, order, conf)
}
arpa, err := reverseaddr(addr)
}
func (r *Resolver) lookupIP(ctx context.Context, network, host string) (addrs []IPAddr, err error) {
- if r.preferGo() {
- return r.goLookupIP(ctx, network, host)
- }
order, conf := systemConf().hostLookupOrder(r, host)
if order == hostLookupCgo {
return cgoLookupIP(ctx, network, host)
return addrs, nil
}
-// preferGoOverWindows reports whether the resolver should use the
-// pure Go implementation rather than making win32 calls to ask the
-// kernel for its answer.
-func (r *Resolver) preferGoOverWindows() bool {
- conf := systemConf()
- order, _ := conf.hostLookupOrder(r, "") // name is unused
- return order != hostLookupCgo
-}
-
func (r *Resolver) lookupIP(ctx context.Context, network, name string) ([]IPAddr, error) {
- if r.preferGoOverWindows() {
- return r.goLookupIP(ctx, network, name)
+ if order, conf := systemConf().hostLookupOrder(r, name); order != hostLookupCgo {
+ return r.goLookupIP(ctx, network, name, order, conf)
}
+
// TODO(bradfitz,brainman): use ctx more. See TODO below.
var family int32 = syscall.AF_UNSPEC
}
func (r *Resolver) lookupPort(ctx context.Context, network, service string) (int, error) {
- if r.preferGoOverWindows() {
+ if systemConf().mustUseGoResolver(r) {
return lookupPortMap(network, service)
}
}
func (r *Resolver) lookupCNAME(ctx context.Context, name string) (string, error) {
- if order, conf := systemConf().hostLookupOrder(r, ""); order != hostLookupCgo {
+ if order, conf := systemConf().hostLookupOrder(r, name); order != hostLookupCgo {
return r.goLookupCNAME(ctx, name, order, conf)
}
}
func (r *Resolver) lookupSRV(ctx context.Context, service, proto, name string) (string, []*SRV, error) {
- if r.preferGoOverWindows() {
+ if systemConf().mustUseGoResolver(r) {
return r.goLookupSRV(ctx, service, proto, name)
}
// TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this.
}
func (r *Resolver) lookupMX(ctx context.Context, name string) ([]*MX, error) {
- if r.preferGoOverWindows() {
+ if systemConf().mustUseGoResolver(r) {
return r.goLookupMX(ctx, name)
}
// TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this.
}
func (r *Resolver) lookupNS(ctx context.Context, name string) ([]*NS, error) {
- if r.preferGoOverWindows() {
+ if systemConf().mustUseGoResolver(r) {
return r.goLookupNS(ctx, name)
}
// TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this.
}
func (r *Resolver) lookupTXT(ctx context.Context, name string) ([]string, error) {
- if r.preferGoOverWindows() {
+ if systemConf().mustUseGoResolver(r) {
return r.goLookupTXT(ctx, name)
}
// TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this.
}
func (r *Resolver) lookupAddr(ctx context.Context, addr string) ([]string, error) {
- if order, conf := systemConf().hostLookupOrder(r, ""); order != hostLookupCgo {
+ if order, conf := systemConf().addrLookupOrder(r, addr); order != hostLookupCgo {
return r.goLookupPTR(ctx, addr, order, conf)
}