Skip to content

Commit

Permalink
Revert "net: permit use of Resolver.PreferGo, netgo on Windows and Pl…
Browse files Browse the repository at this point in the history
…an 9"

This reverts CL 400654.

Reason for revert: broke net.TestGoLookupIP on the darwin-amd64-nocgo builder.

Updates #33097.

Change-Id: Idaf94eda88c9d4401e667a4d31c00ce376d91909
Reviewed-on: https://go-review.googlesource.com/c/go/+/401754
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
Bryan Mills authored and gopherbot committed Apr 22, 2022
1 parent 78fb1d0 commit 440c931
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 838 deletions.
2 changes: 2 additions & 0 deletions src/net/addrselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix

// Minimal RFC 6724 address selection.

package net
Expand Down
2 changes: 2 additions & 0 deletions src/net/cgo_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package net

import "context"

func init() { netGo = true }

type addrinfoErrno int

func (eai addrinfoErrno) Error() string { return "<nil>" }
Expand Down
36 changes: 3 additions & 33 deletions src/net/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build unix

package net

Expand All @@ -21,7 +21,7 @@ type conf struct {
forceCgoLookupHost bool

netGo bool // go DNS resolution forced
netCgo bool // non-go DNS resolution forced (cgo, or win32)
netCgo bool // cgo DNS resolution forced

// machine has an /etc/mdns.allow file
hasMDNSAllow bool
Expand Down Expand Up @@ -49,23 +49,9 @@ func initConfVal() {
confVal.dnsDebugLevel = debugLevel
confVal.netGo = netGo || dnsMode == "go"
confVal.netCgo = netCgo || dnsMode == "cgo"
if !confVal.netGo && !confVal.netCgo && (runtime.GOOS == "windows" || runtime.GOOS == "plan9") {
// Neither of these platforms actually use cgo.
//
// The meaning of "cgo" mode in the net package is
// really "the native OS way", which for libc meant
// cgo on the original platforms that motivated
// PreferGo support before Windows and Plan9 got support,
// at which time the GODEBUG=netdns=go and GODEBUG=netdns=cgo
// names were already kinda locked in.
confVal.netCgo = true
}

if confVal.dnsDebugLevel > 0 {
defer func() {
if confVal.dnsDebugLevel > 1 {
println("go package net: confVal.netCgo =", confVal.netCgo, " netGo =", confVal.netGo)
}
switch {
case confVal.netGo:
if netGo {
Expand All @@ -89,10 +75,6 @@ func initConfVal() {
return
}

if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
return
}

// If any environment-specified resolver options are specified,
// force cgo. Note that LOCALDOMAIN can change behavior merely
// by being specified with the empty string.
Expand Down Expand Up @@ -147,19 +129,7 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde
}
fallbackOrder := hostLookupCgo
if c.netGo || r.preferGo() {
switch c.goos {
case "windows":
// TODO(bradfitz): implement files-based
// lookup on Windows too? I guess /etc/hosts
// kinda exists on Windows. But for now, only
// do DNS.
fallbackOrder = hostLookupDNS
default:
fallbackOrder = hostLookupFilesDNS
}
}
if c.goos == "windows" || c.goos == "plan9" {
return fallbackOrder
fallbackOrder = hostLookupFilesDNS
}
if c.forceCgoLookupHost || c.resolv.unknownOpt || c.goos == "android" {
return fallbackOrder
Expand Down
24 changes: 7 additions & 17 deletions src/net/dnsclient_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build unix

// DNS client: see RFC 1035.
// Has to be linked into package net for Dial.
Expand All @@ -20,7 +20,6 @@ import (
"internal/itoa"
"io"
"os"
"runtime"
"sync"
"time"

Expand Down Expand Up @@ -379,21 +378,12 @@ func (conf *resolverConfig) tryUpdate(name string) {
}
conf.lastChecked = now

switch runtime.GOOS {
case "windows":
// There's no file on disk, so don't bother checking
// and failing.
//
// The Windows implementation of dnsReadConfig (called
// below) ignores the name.
default:
var mtime time.Time
if fi, err := os.Stat(name); err == nil {
mtime = fi.ModTime()
}
if mtime.Equal(conf.dnsConfig.mtime) {
return
}
var mtime time.Time
if fi, err := os.Stat(name); err == nil {
mtime = fi.ModTime()
}
if mtime.Equal(conf.dnsConfig.mtime) {
return
}

dnsConf := dnsReadConfig(name)
Expand Down
43 changes: 0 additions & 43 deletions src/net/dnsconfig.go

This file was deleted.

36 changes: 35 additions & 1 deletion src/net/dnsconfig_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,40 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js && !windows
//go:build unix

// Read system DNS config from /etc/resolv.conf

package net

import (
"internal/bytealg"
"os"
"sync/atomic"
"time"
)

var (
defaultNS = []string{"127.0.0.1:53", "[::1]:53"}
getHostname = os.Hostname // variable for testing
)

type dnsConfig struct {
servers []string // server addresses (in host:port form) to use
search []string // rooted suffixes to append to local name
ndots int // number of dots in name to trigger absolute lookup
timeout time.Duration // wait before giving up on a query, including retries
attempts int // lost packets before giving up on server
rotate bool // round robin among servers
unknownOpt bool // anything unknown was encountered
lookup []string // OpenBSD top-level database "lookup" order
err error // any error that occurs during open of resolv.conf
mtime time.Time // time of resolv.conf modification
soffset uint32 // used by serverOffset
singleRequest bool // use sequential A and AAAA queries instead of parallel queries
useTCP bool // force usage of TCP for DNS resolutions
}

// See resolv.conf(5) on a Linux machine.
func dnsReadConfig(filename string) *dnsConfig {
conf := &dnsConfig{
Expand Down Expand Up @@ -133,6 +156,17 @@ func dnsReadConfig(filename string) *dnsConfig {
return conf
}

// serverOffset returns an offset that can be used to determine
// indices of servers in c.servers when making queries.
// When the rotate option is enabled, this offset increases.
// Otherwise it is always 0.
func (c *dnsConfig) serverOffset() uint32 {
if c.rotate {
return atomic.AddUint32(&c.soffset, 1) - 1 // return 0 to start
}
return 0
}

func dnsDefaultSearch() []string {
hn, err := getHostname()
if err != nil {
Expand Down
58 changes: 0 additions & 58 deletions src/net/dnsconfig_windows.go

This file was deleted.

Loading

0 comments on commit 440c931

Please sign in to comment.