aboutsummaryrefslogtreecommitdiff
path: root/src/net/conf_test.go
AgeCommit message (Collapse)Author
2026-02-12net: always set the servers field to defaultNSMateusz Poliwczak
When the field is parsed from a file, it would never have len(servers) == 0, lets enforce that and update test cases where we had it wrong. Change-Id: I7fa6ebcf63b9fe20fbbf791113ca948d6a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/743020 Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Sean Liao <sean@liao.dev>
2026-02-02net: don't wait 5 seconds to re-read /etc/resolv.confBrad Fitzpatrick
If a Go process starts up, finds /etc/resolv.conf empty, then the DHCP client writes /etc/resolv.conf, the Go program would find itself broken for up to 5 seconds. We noticed this during integration tests in ephemeral VMs using gokrazy that boot into our application. Change-Id: Ia64c2b5c698a4ee3efc15d8a8f1850c47e531b84 Reviewed-on: https://go-review.googlesource.com/c/go/+/739620 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-26net: don't force cgo resolver for .local subdomain queriesMateusz Poliwczak
The cgo resolver sends DNS queries for .local subdomain lookups, just as we do in the go resolver. We don't need to fallback to the cgo resolver for this domains when nsswitch.conf uses only file and dns modules. This has a benefit that we select a consistent resolver, that is only based on the system configuration, regardless of the queried domain. Updates #63978 Change-Id: I9166103adb94d7ab52992925f413f361130e7c52 GitHub-Last-Rev: e2bc5874cb5c9165e3cc058e9effe36d0ce68cd6 GitHub-Pull-Request: golang/go#63986 Reviewed-on: https://go-review.googlesource.com/c/go/+/540555 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2023-05-11net: don't treat unknown sources as dns when there is a dns sourceMateusz Poliwczak
Change-Id: I3a6c3a804604b1e74a1ea6b66ab2c932a0ac973a GitHub-Last-Rev: ea5403549a51a29a2799674d74425b480253d2f1 GitHub-Pull-Request: golang/go#60025 Reviewed-on: https://go-review.googlesource.com/c/go/+/493236 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-11net: force cgo for myhostname and mdns nss modules for LookupAddr on unixMateusz Poliwczak
Currently there is a small bug in the LookupAddr for unix systems that causes the use of go resolver instead of the cgo one. Example for nss myhostname: func main() { fmt.Println(net.LookupAddr(os.Args[1])) } root@arch:~# cat /etc/nsswitch.conf | grep host hosts: myhostname dns root@arch:~# GODEBUG=netdns=+3 go run main.go 192.168.1.200 go package net: confVal.netCgo = false netGo = false go package net: dynamic selection of DNS resolver go package net: hostLookupOrder() = dns [] lookup 200.1.168.192.in-addr.arpa. on 8.8.8.8:53: no such host root@arch:~# GODEBUG=netdns=go+3 go run main.go 192.168.1.200 go package net: confVal.netCgo = false netGo = true go package net: GODEBUG setting forcing use of Go's resolver go package net: hostLookupOrder() = dns [] lookup 200.1.168.192.in-addr.arpa. on 8.8.8.8:53: no such host root@arch:~# GODEBUG=netdns=cgo+3 go run main.go 192.168.1.200 go package net: confVal.netCgo = true netGo = false go package net: using cgo DNS resolver go package net: hostLookupOrder() = cgo [arch] <nil> The problem come from that we are only checking for hostnames that the myhostname can resolve, but not for the addrs that it can also. man nss-myhostname: Please keep in mind that nss-myhostname (and nss-resolve) also resolve in the other direction — from locally attached IP addresses to hostnames. Change-Id: Ic18a9f99a2214b2938463e9a95f7f3ca5db1c01b GitHub-Last-Rev: ade40fd3e3057de418b9b6a79f79fb9a53fb6c09 GitHub-Pull-Request: golang/go#59921 Reviewed-on: https://go-review.googlesource.com/c/go/+/491235 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
2023-05-02net: don't recheck goosPrefersCgo in hostLookupOrderIan Lance Taylor
We only did it for testing. Remove the single test that required it. Change-Id: Ib6c3a2debfd3f48e95af37f23fdfde847ff87a41 Reviewed-on: https://go-review.googlesource.com/c/go/+/490395 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-04-27net: rewrite and simplify resolver configurationIan Lance Taylor
The resulting code behaves mostly the same. There are some minor differences in error cases when the cgo resolver is not available: instead of just falling back we keep trying to work out the right nsswitch.conf order. Change-Id: I17fadc940528fa2397043ac8f8ed7da3bd7a95c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/487196 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Mateusz Poliwczak <mpoliwczak34@gmail.com>
2022-11-17net: return errNoSuchHost when no entry found in /etc/hosts and order is ↵Mateusz Poliwczak
hostLookupFiles When /etc/nsswitch.conf lists: "hosts: files" then LookupHost returns two nils when no entry inside /etc/hosts is found. Change-Id: I96d68a079dfe009655c84cf0e697ce19a5bb6698 GitHub-Last-Rev: 894f066bbcc7c975f1975bd0d1dcb5726f590bc5 GitHub-Pull-Request: golang/go#56747 Reviewed-on: https://go-review.googlesource.com/c/go/+/450875 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-15net: rewrite nsswitch.conf parsing to work like other parsersIan Lance Taylor
Seems simpler than having two different parsing mechanisms. Change-Id: I4f8468bc025f8e03f59ec9c79b17721581b64eed Reviewed-on: https://go-review.googlesource.com/c/go/+/448855 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-11-15net: use a consistent dnsConfig in hostLookupOrderMateusz Poliwczak
Use the same dnsConfig throughout a DNS lookup operation. Before this CL it was possible to decide to re-read a modified resolv.conf file during the DNS lookup, which could lead to inconsistencies between the lookup order and the name server list. Change-Id: I0689749272b8263268d00b9a9cb4458cd68b23eb GitHub-Last-Rev: 64810a22bc8a7dd5e804b5f5253d11b73942dfe3 GitHub-Pull-Request: golang/go#56690 Reviewed-on: https://go-review.googlesource.com/c/go/+/449337 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-11-11net: handle correctly the _gateway and _outbound hostnames for nss myhostnameMateusz Poliwczak
Fixes #56387 Change-Id: If412134344600caefec425699398522399986d4d GitHub-Last-Rev: f33540ef8f90e9a8c09f3947aba8c01155516d39 GitHub-Pull-Request: golang/go#56388 Reviewed-on: https://go-review.googlesource.com/c/go/+/445075 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-11-10net: auto-reload the /etc/nsswitch.conf on unix systemsMateusz Poliwczak
This change is made to align with the current (recently changed) glibc behaviour, it will allow the hostLookupOrder method to change its decisions on runtime (based on /etc/nsswitch.conf changes). Fixes #56515 Change-Id: I241d67f053b6d2111eebcd67744adee02829166e GitHub-Last-Rev: 82842c127474d5d225d2e9b68568387ee6b0ba04 GitHub-Pull-Request: golang/go#56588 Reviewed-on: https://go-review.googlesource.com/c/go/+/448075 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-10-28all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor)Russ Cox
When these packages are released as part of Go 1.18, Go 1.16 will no longer be supported, so we can remove the +build tags in these files. Ran go fix -fix=buildtag std cmd and then reverted the bootstrapDirs as defined in src/cmd/dist/buildtool.go, which need to continue to build with Go 1.4 for now. Also reverted src/vendor and src/cmd/vendor, which will need to be updated in their own repos first. Manual changes in runtime/pprof/mprof_test.go to adjust line numbers. For #41184. Change-Id: Ic0f93f7091295b6abc76ed5cd6e6746e1280861e Reviewed-on: https://go-review.googlesource.com/c/go/+/344955 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-02-20all: go fmt std cmd (but revert vendor)Russ Cox
Make all our package sources use Go 1.17 gofmt format (adding //go:build lines). Part of //go:build change (#41184). See https://golang.org/design/draft-gobuild Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/294430 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-25net: prefer /etc/hosts over DNS when no /etc/nsswitch.conf is presentNatanael Copa
Do not mimic glibc behavior if /etc/nsswitch.conf is missing. This will will likely be missing on musl libc systems and glibc systems will likely always have it, resulting in localhost lookup being done over DNS rather than from /etc/hosts. Do what makes most sense rather than making any assumption about the libc. Fixes #35305 Change-Id: I20bd7e24131bba8eaa39a20c8950fe552364784d GitHub-Last-Rev: 119409839d37c8c7268f5f6db19c1789d9d96074 GitHub-Pull-Request: golang/go#39685 Reviewed-on: https://go-review.googlesource.com/c/go/+/238629 Run-TryBot: Dan Peterson <dpiddy@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Peterson <dpiddy@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2020-10-20all: update references to symbols moved from os to io/fsRuss Cox
The old os references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. For #41190. Change-Id: I8f9526977867c10a221e2f392f78d7dec073f1bd Reviewed-on: https://go-review.googlesource.com/c/go/+/243907 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2018-06-01all: update comment URLs from HTTP to HTTPS, where possibleTim Cooper
Each URL was manually verified to ensure it did not serve up incorrect content. Change-Id: I4dc846227af95a73ee9a3074d0c379ff0fa955df Reviewed-on: https://go-review.googlesource.com/115798 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2018-03-16net: make Resolver.PreferGo work more as documentedBrad Fitzpatrick
Fixes #24393 Change-Id: I8bcee34cdf30472663d866ed6056301d8445215c Reviewed-on: https://go-review.googlesource.com/100875 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-11-29net: expand nss myhostname fallback detectionDan Peterson
Expand myhostname fallback detection to properly detect the local hostname in addition to other supported special names and suffixes. Fixes #17967 Change-Id: I1fe141fd9838b25886c08b6f2fd325e58be60457 Reviewed-on: https://go-review.googlesource.com/33550 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-05net: fix hostLookupOrder("")Russ Cox
Fixes #13623. Change-Id: I1bd96aa7b6b715e4dbdcf0c37c2d29228df6565c Reviewed-on: https://go-review.googlesource.com/18329 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-04net: allow netgo to use lookup from nsswitch.confVishvananda Ishaya
Change https://golang.org/cl/8945 allowed Go to use its own DNS resolver instead of libc in a number of cases. The code parses nsswitch.conf and attempts to resolve things in the same order. Unfortunately, builds with netgo completely ignore this parsing and always search via hostLookupFilesDNS. This commit modifies the logic to allow binaries built with netgo to parse nsswitch.conf and attempt to resolve using the order specified there. If the parsing results in hostLookupCGo, it falls back to the original hostLookupFilesDNS. Tests are also added to ensure that both the parsing and the fallback work properly. Fixes #14354 Change-Id: Ib079ad03d7036a4ec57f18352a15ba55d933f261 Reviewed-on: https://go-review.googlesource.com/19523 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-03-21all: delete dead test codeDominik Honnef
This deletes unused code and helpers from tests. Change-Id: Ie31d46115f558ceb8da6efbf90c3c204e03b0d7e Reviewed-on: https://go-review.googlesource.com/20927 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-07-09net: add mechanisms to force go or cgo lookup, and to debug default strategyBrad Fitzpatrick
GODEBUG=netdns=1 prints a one-time strategy decision. (cgo or go DNS lookups) GODEBUG=netdns=2 prints the per-lookup strategy as a function of the hostname. The new "netcgo" build tag forces cgo DNS lookups. GODEBUG=netdns=go (or existing build tag "netgo") forces Go DNS resolution. GODEBUG=netdns=cgo (or new build tag "netcgo") forces libc DNS resolution. Options can be combined with e.g. GODEBUG=netdns=go+1 or GODEBUG=netdns=2+cgo. Fixes #11322 Fixes #11450 Change-Id: I7a67e9f759fd0a02320e7803f9ded1638b19e861 Reviewed-on: https://go-review.googlesource.com/11584 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-05-06net: always use cgo for DNS on AndroidBrad Fitzpatrick
Android has (had?) its own local DNS resolver daemon, also my fault: https://android.googlesource.com/platform/system/netd/+/007e987fee7e815e0c4bc820f434a632b7a69a9d And you access that via libc, not DNS. Fixes #10714 Change-Id: Iaff752872ce19bb5c7771ab048fd50e3f72cb73c Reviewed-on: https://go-review.googlesource.com/9793 Reviewed-by: David Crawshaw <crawshaw@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-05-06net: simplify error messages in testsMikio Hara
This change simplifies unnecessarily redundant error messages in tests. There's no need to worry any more because package APIs now return consistent, self-descriptive error values. Alos renames ambiguous test functions and makes use of test tables. Change-Id: I7b61027607c4ae2a3cf605d08d58cf449fa27eb2 Reviewed-on: https://go-review.googlesource.com/9662 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
2015-04-30net: make go DNS use localhost if resolv.conf is missing or emptyAlex A Skinner
Per resolv.conf man page, "If this file does not exist, only the name server on the local machine will be queried." This behavior also occurs if file is present but unreadable, or if no nameservers are listed. Fixes #10566 Change-Id: Id5716da0eae534d5ebfafea111bbc657f302e307 Reviewed-on: https://go-review.googlesource.com/9380 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-23net: use Go's DNS resolver when system configuration permitsBrad Fitzpatrick
If the machine's network configuration files (resolv.conf, nsswitch.conf) don't have any unsupported options, prefer Go's DNS resolver, which doesn't have the cgo & thread over. It means users can have more than 500 DNS requests outstanding (our current limit for cgo lookups) and not have one blocked thread per outstanding request. Discussed in thread https://groups.google.com/d/msg/golang-dev/2ZUi792oztM/Q0rg_DkF5HMJ Change-Id: I3f685d70aff6b47bec30b63e9fba674b20507f95 Reviewed-on: https://go-review.googlesource.com/8945 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>