Skip to content

Commit 440c931

Browse files
Bryan Millsgopherbot
Bryan Mills
authored andcommitted
Revert "net: permit use of Resolver.PreferGo, netgo on Windows and Plan 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 <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Than McIntosh <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 78fb1d0 commit 440c931

16 files changed

+293
-838
lines changed

src/net/addrselect.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build unix
6+
57
// Minimal RFC 6724 address selection.
68

79
package net

src/net/cgo_stub.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ package net
88

99
import "context"
1010

11+
func init() { netGo = true }
12+
1113
type addrinfoErrno int
1214

1315
func (eai addrinfoErrno) Error() string { return "<nil>" }

src/net/conf.go

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !js
5+
//go:build unix
66

77
package net
88

@@ -21,7 +21,7 @@ type conf struct {
2121
forceCgoLookupHost bool
2222

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

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

6453
if confVal.dnsDebugLevel > 0 {
6554
defer func() {
66-
if confVal.dnsDebugLevel > 1 {
67-
println("go package net: confVal.netCgo =", confVal.netCgo, " netGo =", confVal.netGo)
68-
}
6955
switch {
7056
case confVal.netGo:
7157
if netGo {
@@ -89,10 +75,6 @@ func initConfVal() {
8975
return
9076
}
9177

92-
if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
93-
return
94-
}
95-
9678
// If any environment-specified resolver options are specified,
9779
// force cgo. Note that LOCALDOMAIN can change behavior merely
9880
// by being specified with the empty string.
@@ -147,19 +129,7 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde
147129
}
148130
fallbackOrder := hostLookupCgo
149131
if c.netGo || r.preferGo() {
150-
switch c.goos {
151-
case "windows":
152-
// TODO(bradfitz): implement files-based
153-
// lookup on Windows too? I guess /etc/hosts
154-
// kinda exists on Windows. But for now, only
155-
// do DNS.
156-
fallbackOrder = hostLookupDNS
157-
default:
158-
fallbackOrder = hostLookupFilesDNS
159-
}
160-
}
161-
if c.goos == "windows" || c.goos == "plan9" {
162-
return fallbackOrder
132+
fallbackOrder = hostLookupFilesDNS
163133
}
164134
if c.forceCgoLookupHost || c.resolv.unknownOpt || c.goos == "android" {
165135
return fallbackOrder

src/net/dnsclient_unix.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !js
5+
//go:build unix
66

77
// DNS client: see RFC 1035.
88
// Has to be linked into package net for Dial.
@@ -20,7 +20,6 @@ import (
2020
"internal/itoa"
2121
"io"
2222
"os"
23-
"runtime"
2423
"sync"
2524
"time"
2625

@@ -379,21 +378,12 @@ func (conf *resolverConfig) tryUpdate(name string) {
379378
}
380379
conf.lastChecked = now
381380

382-
switch runtime.GOOS {
383-
case "windows":
384-
// There's no file on disk, so don't bother checking
385-
// and failing.
386-
//
387-
// The Windows implementation of dnsReadConfig (called
388-
// below) ignores the name.
389-
default:
390-
var mtime time.Time
391-
if fi, err := os.Stat(name); err == nil {
392-
mtime = fi.ModTime()
393-
}
394-
if mtime.Equal(conf.dnsConfig.mtime) {
395-
return
396-
}
381+
var mtime time.Time
382+
if fi, err := os.Stat(name); err == nil {
383+
mtime = fi.ModTime()
384+
}
385+
if mtime.Equal(conf.dnsConfig.mtime) {
386+
return
397387
}
398388

399389
dnsConf := dnsReadConfig(name)

src/net/dnsconfig.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/net/dnsconfig_unix.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,40 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !js && !windows
5+
//go:build unix
66

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

99
package net
1010

1111
import (
1212
"internal/bytealg"
13+
"os"
14+
"sync/atomic"
1315
"time"
1416
)
1517

18+
var (
19+
defaultNS = []string{"127.0.0.1:53", "[::1]:53"}
20+
getHostname = os.Hostname // variable for testing
21+
)
22+
23+
type dnsConfig struct {
24+
servers []string // server addresses (in host:port form) to use
25+
search []string // rooted suffixes to append to local name
26+
ndots int // number of dots in name to trigger absolute lookup
27+
timeout time.Duration // wait before giving up on a query, including retries
28+
attempts int // lost packets before giving up on server
29+
rotate bool // round robin among servers
30+
unknownOpt bool // anything unknown was encountered
31+
lookup []string // OpenBSD top-level database "lookup" order
32+
err error // any error that occurs during open of resolv.conf
33+
mtime time.Time // time of resolv.conf modification
34+
soffset uint32 // used by serverOffset
35+
singleRequest bool // use sequential A and AAAA queries instead of parallel queries
36+
useTCP bool // force usage of TCP for DNS resolutions
37+
}
38+
1639
// See resolv.conf(5) on a Linux machine.
1740
func dnsReadConfig(filename string) *dnsConfig {
1841
conf := &dnsConfig{
@@ -133,6 +156,17 @@ func dnsReadConfig(filename string) *dnsConfig {
133156
return conf
134157
}
135158

159+
// serverOffset returns an offset that can be used to determine
160+
// indices of servers in c.servers when making queries.
161+
// When the rotate option is enabled, this offset increases.
162+
// Otherwise it is always 0.
163+
func (c *dnsConfig) serverOffset() uint32 {
164+
if c.rotate {
165+
return atomic.AddUint32(&c.soffset, 1) - 1 // return 0 to start
166+
}
167+
return 0
168+
}
169+
136170
func dnsDefaultSearch() []string {
137171
hn, err := getHostname()
138172
if err != nil {

src/net/dnsconfig_windows.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)