1
0
mirror of https://github.com/golang/go synced 2024-09-30 18:08:33 -06:00
Commit Graph

87 Commits

Author SHA1 Message Date
Troels Thomsen
6a3d4be3b8 net: Forget lookups for canceled contexts
A sequential lookup using any non-canceled context has a risk of
returning the result of the previous lookup for a canceled context (i.e.
an error).

This is already prevented for timed out context by forgetting the host
immediately and extending this to also compare the error to
`context.Canceled` resolves this issue.

Fixes #22724

Change-Id: I7aafa1459a0de4dc5c4332988fbea23cbf4dba07
Reviewed-on: https://go-review.googlesource.com/77670
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-15 22:34:55 +00:00
Marvin Stenger
90d71fe99e all: revert "all: prefer strings.IndexByte over strings.Index"
This reverts https://golang.org/cl/65930.

Fixes #22148

Change-Id: Ie0712621ed89c43bef94417fc32de9af77607760
Reviewed-on: https://go-review.googlesource.com/68430
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-05 23:19:10 +00:00
Marvin Stenger
f22ba1f247 all: prefer strings.IndexByte over strings.Index
strings.IndexByte was introduced in go1.2 and it can be used
effectively wherever the second argument to strings.Index is
exactly one byte long.

This avoids generating unnecessary string symbols and saves
a few calls to strings.Index.

Change-Id: I1ab5edb7c4ee9058084cfa57cbcc267c2597e793
Reviewed-on: https://go-review.googlesource.com/65930
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-25 17:35:41 +00:00
Mikio Hara
6694a6888b net: delay IP protocol stack-snooping system calls
This change delays IP protocol stack-snooping system calls until the
start of connection setup for the better experience with some system
call auditing, such as seccomp on Linux. See #16789 for examples.

Also updates the documentation on favoriteAddrFamily, which is the
owner of stack-snooping system calls.

Fixes #16789.

Change-Id: I4af27bc1ed06ffb1f657b6f6381c328c1f41c66c
Reviewed-on: https://go-review.googlesource.com/40750
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-04-15 22:22:09 +00:00
Matthew Dempsky
2f9dee9293 net: make LookupCNAME's native behavior match its cgo behavior
Fixes #18172.

Change-Id: I4a21fb5c0753cced025a03d88a6dd1aa3ee01d05
Reviewed-on: https://go-review.googlesource.com/34650
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2016-12-20 17:38:29 +00:00
Mikio Hara
69b7fe1a90 net: deflake TestLookupNonLDH
Fixes #17623.

Change-Id: I4717e8399f955c9be7ba19108bb0bcc108187c04
Reviewed-on: https://go-review.googlesource.com/32147
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-28 22:20:20 +00:00
Russ Cox
fa90f9b909 net: there are no invalid domain names anymore
The Go resolver reports invalid domain name for '!!!.local',
but that is allowed by multicast DNS. In general we can't predict
what future relaxations might come along, and libc resolvers
do not distinguish 'no such host' from 'invalid name', so stop
making that distinction here too. Always use 'no such host'.

Fixes #12421.

Change-Id: I8f22604767ec9e270434e483da52b337833bad71
Reviewed-on: https://go-review.googlesource.com/31468
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-10-24 15:37:26 +00:00
Brad Fitzpatrick
2bc5f1258e net: add Resolver type, Dialer.Resolver, and DefaultResolver
The new Resolver type (a struct) has 9 Lookup methods, all taking a
context.Context.

There's now a new DefaultResolver global, like http's
DefaultTransport and DefaultClient.

net.Dialer now has an optional Resolver field to set the Resolver.

This also does finishes some resolver cleanup internally, deleting
lookupIPMerge and renaming lookupIPContext into Resolver.LookupIPAddr.

The Resolver currently doesn't let you tweak much, but it's a struct
specifically so we can add knobs in the future. Currently I just added
a bool to force the pure Go resolver. In the future we could let
people provide an interface to implement the methods, or add a Timeout
time.Duration, which would wrap all provided contexts in a
context.WithTimeout.

Fixes #16672

Change-Id: I7ba1f886704f06def7b6b5c4da9809db51bc1495
Reviewed-on: https://go-review.googlesource.com/29440
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-21 18:35:40 +00:00
Brad Fitzpatrick
74190735be net: make LookupPort and lookupProtocol work on nacl
Also, flesh out the baked-in /etc/services table for LookupPort a bit.

This services map moves from a unix-specific file to a portable file
where nacl can use it.

Also, remove the duplicated entries in the protocol map in different
cases, and just canonicalize the input before looking in the map. Now
it handles any case, including MiXeD cAse.

In the process, add a test that service names for LookupPort are case
insensitive. They were on Windows, but not cgo. Now there's a test and
they're case insensitive in all 3+ paths. Maybe it breaks plan9. We'll
see.

Fixes #17045

Change-Id: Idce7d68703f371727c7505cda03a32bd842298cd
Reviewed-on: https://go-review.googlesource.com/28951
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
2016-09-11 04:19:25 +00:00
Ian Lance Taylor
68697a3e82 net: don't run TestLookupDotsWithLocalSource in short mode
Do run it on the builders, though.

Fixes #15881.

Change-Id: Ie42204d553cb18547ffd6441afc261717bbd9205
Reviewed-on: https://go-review.googlesource.com/24111
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-06-14 22:50:09 +00:00
Mikio Hara
82ec4cd79f net: don't crash DNS flood test on darwin
Also renames the test function to TestDNSFlood.

Updates #15659.

Change-Id: Ia562004c43bcc19c2fee9440321c27b591f85da5
Reviewed-on: https://go-review.googlesource.com/23077
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-05-21 00:23:53 +00:00
Mikio Hara
6de34e6e25 net: deflake TestLookupPort on Android
Looks like some version of Android still fails with "servname not
supported for ai_socktype". It probably doesn't support
ai_socktype=SOCK_STREAM.

Updates #14576.

Change-Id: I77ecff147d5b759e3281b3798c60f150a4aab811
Reviewed-on: https://go-review.googlesource.com/23194
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-05-18 08:18:56 +00:00
Mikio Hara
7b597f4d92 net: deflake TestLookupPort for embedded, security-hardened platforms
Fixes #14576.

Change-Id: I760907c67c97cb827cf48ba7eb0bb2f4f8d4d790
Reviewed-on: https://go-review.googlesource.com/23111
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-05-17 21:51:18 +00:00
Brad Fitzpatrick
7c5c6645d2 net: skip more flaky net tests on flaky net builders
e.g. https://storage.googleapis.com/go-build-log/9b937dd8/linux-arm_df54a25a.log

Change-Id: Ic5864c7bd840b4f0c6341f919fcbcd5c708b14e7
Reviewed-on: https://go-review.googlesource.com/22881
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
2016-05-06 19:23:29 +00:00
Brad Fitzpatrick
1ff57143af net: ignore network failures on some builders
We run the external network tests on builders, but some of our
builders have less-than-ideal DNS connectivity. This change continues
to run the tests on all builders, but marks certain builders as flaky
(network-wise), and only validates their DNS results if they got DNS
results.

Change-Id: I826dc2a6f6da55add89ae9c6db892b3b2f7b526b
Reviewed-on: https://go-review.googlesource.com/22852
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-05-06 17:24:09 +00:00
Morten Siebuhr
002c69e05d net: fix looking up port numbers starting with numbers.
LookupPort() correctly parses service names beginning with numerals by
implementing a new parser, mainly taken from strconv/atoi.go.

Also testes some previously undefined behaviours around port numbers
larger than 65535 that previously could lead to some tests fail with
EOPNOTSUPP (Operation Not Supported).

Fixes #14322

Change-Id: I1b90dbed434494723e261d84e73fe705e5c0507a
Reviewed-on: https://go-review.googlesource.com/19720
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2016-04-15 23:11:47 +00:00
Brad Fitzpatrick
b6b4004d5a net: context plumbing, add Dialer.DialContext
For #12580 (http.Transport tracing/analytics)
Updates #13021

Change-Id: I126e494a7bd872e42c388ecb58499ecbf0f014cc
Reviewed-on: https://go-review.googlesource.com/22101
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2016-04-15 22:48:12 +00:00
Mikio Hara
ed7cd2546e net: make use of internal/testenv package
Change-Id: I6644081df495cb92b3d208f867066f9acb08946f
Reviewed-on: https://go-review.googlesource.com/22074
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-04-14 06:13:45 +00:00
Burcu Dogan
fcb23249b2 net: skip TestLookupPort on android with netgo
/etc/services is not available on Android. The pure Go implementation
of LookupPort will never succeed on Android. Skipping the test.

Updates #14576.

Change-Id: I707ac24aea3f988656b95b1816ee5c9690106985
Reviewed-on: https://go-review.googlesource.com/20154
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-03 02:52:18 +00:00
Mikio Hara
e8b53c92b8 net: enable TestLookupDotsWithRemoteSource on builders
Change-Id: I2609660b10a16ec2a256fc9c8e046ba4ae67963f
Reviewed-on: https://go-review.googlesource.com/18880
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-23 10:20:58 +00:00
Mikio Hara
4f40182240 net: fix TestLookupDotsWithLocalSource
Fixes #14050.

Change-Id: I2d9c32213b0da35703edf28f92ed3efb23325921
Reviewed-on: https://go-review.googlesource.com/18792
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-01-23 01:28:06 +00:00
Mikio Hara
ceeb52d862 net: LookupAddr("127.0.0.1") is "localhost" not "localhost." on Plan 9 and Windows
This change applies the fix for #13564 to Plan 9 and Windows.
Also enables Lookup API test cases on builders.

Updates #13564.

Change-Id: I863f03c7cb6fbe58b3a55223bfa0ac5f9bf9c3df
Reviewed-on: https://go-review.googlesource.com/18559
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-01-13 14:02:22 +00:00
Russ Cox
6b9298a2c5 net: LookupAddr("127.0.0.1") is "localhost" not "localhost."
Fixes #13564.

Change-Id: I30c827ef4a112fee21b8493a67d0227109e35072
Reviewed-on: https://go-review.googlesource.com/18384
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-08 03:14:47 +00:00
Brad Fitzpatrick
5a88e54fda net: make LookupPort with empty service mean 0
Fixes #13610

Change-Id: I9c8f924dc1ad515a9697291e981ece34fdbec8b7
Reviewed-on: https://go-review.googlesource.com/17755
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-12-14 20:41:36 +00:00
Mikio Hara
d2ca451873 net: adjust Lookup API test cases
This change makes existing Lookup API test cases conform to the new
return value form that all the Lookup APIs except LookupTXT must return
a single or multiple absolute domain names.

Updates #12189.
Fixes #12193.

Change-Id: I03ca09be5bff80e818fbcdc26039daa33d5440a8
Reviewed-on: https://go-review.googlesource.com/17411
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-12-05 06:19:47 +00:00
Mikio Hara
8854bdbd76 net: fix parsing literal IPv6 address with zone identifier when using cgo
Parsing literal IPv6 address with zone identifier is already supported
when not using cgo. This change enables it when using cgo too.

Fixes #12241.

Change-Id: I3ed78c9e750e75eff0dae76ba8608df39503cf85
Reviewed-on: https://go-review.googlesource.com/17215
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2015-12-04 02:50:00 +00:00
Mikio Hara
175bfda49f net: fix typo in test
Change-Id: Ibc55e98c43cebe5a21ab3b280489e1bce6405b8b
Reviewed-on: https://go-review.googlesource.com/17218
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-11-29 22:06:08 +00:00
Mikio Hara
4d6a69f227 net: force LookupAddr results to be rooted DNS paths even in the case of local source
The builtin name resolver using various resolution techniques is a bit
complicated and we sometimes fotget to take care of all the go and cgo
code paths and exchanging information to local and remote sources. This
change makes LookupAddr return absolute domain names even in the case of
local source.

Updates #12189.
Fixes #12240.

Change-Id: Icdd3375bcddc7f5d4d3b24f134d93815073736fc
Reviewed-on: https://go-review.googlesource.com/17216
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-11-28 08:43:55 +00:00
Mikio Hara
91977d07fe net: move TestLookupPort into lookup_test.go
No code changes.

Change-Id: Ibbba7c86007d74b853fb59aa742f87783bd69503
Reviewed-on: https://go-review.googlesource.com/16541
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-11-21 02:59:54 +00:00
Russ Cox
18d27b2d75 net: force LookupAddr results to be rooted DNS paths when using cgo
Go 1.4 and before have always returned DNS names with a trailing dot
for reverse lookups, as they do for basically all other routines returning
DNS names. Go 1.4 and before always implemented LookupAddr using
pure Go (not C library calls).

Go 1.5 added the ability to make a C library call to implement LookupAddr.
Unfortunately the C library call returns a DNS name without a trailing dot
(an unrooted name), meaning that if turn off cgo during make.bash then
you still get the rooted name but with cgo on you get an unrooted name.
The unrooted name is inconsistent with the pure Go implementation
and with all previous Go releases, so change it to a rooted name.

Fixes #12189.

Change-Id: I3d6b72277c121fe085ea6af30e5fe8019fc490ad
Reviewed-on: https://go-review.googlesource.com/13697
Reviewed-by: Rob Pike <r@golang.org>
2015-08-19 04:20:27 +00:00
Mikio Hara
99f5f796d9 net: allow LookupAddr to use getnameinfo when cgo is enabled
This change allows LookupAddr to use getnameinfo through cgo for working
together with various name services other than DNS.

Fixes #7855.

Change-Id: I5b3b4aefe3d1b904541c3350865734d8cbb1c1c4
Reviewed-on: https://go-review.googlesource.com/3420
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-06-17 00:28:31 +00:00
Mikio Hara
7eec656bfd net: fix the series of TestLookup and external tests
On Windows, we need to make sure that the node under test has external
connectivity.

Fixes #10795.

Change-Id: I99f2336180c7b56474fa90a4a6cdd5a6c4dd3805
Reviewed-on: https://go-review.googlesource.com/10006
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-05-20 07:54:37 +00:00
Mikio Hara
f77e10fb2e net: simplify error messages in tests
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-05-06 09:25:08 +00:00
Mikio Hara
5a83f06c21 net: deflake dual IP stack tests
This change deflakes TestDialerDualStackFDLeak, TestDialerDualStack,
TestResolve{TCP,UDP,IP}Addr by removing external dependencies.

Fixes #8764.

Change-Id: I5cca0a93776cf05652e0e6a4a4ff4af392ccb885
Reviewed-on: https://go-review.googlesource.com/8485
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-07 13:32:28 +00:00
Mikio Hara
52c84c34fd net: move test flags into main_test.go
Also updates the comments on test flags.

Change-Id: I8dbd90270e08728ab309ab88a3030e0f8e547175
Reviewed-on: https://go-review.googlesource.com/8394
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-02 09:07:24 +00:00
Mikio Hara
a456801615 net: remove redundant test case for lookupIP with threadLimit
There is no reason to have the redundant test case TestDNSThreadLimt
because TestLookupIPDeadline does cover what we need to test with
-dnsflood flag and more.

Also this CL moves TestLookupIPDeadline into lookup_test.go to avoid
abusing to control the order of test case execution by using file name.

Change-Id: Ib417d7d3411c59d9352c03c996704d584368dc62
Reviewed-on: https://go-review.googlesource.com/2204
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-01-01 05:20:16 +00:00
Russ Cox
c007ce824d build: move package sources from src/pkg to src
Preparation was in CL 134570043.
This CL contains only the effect of 'hg mv src/pkg/* src'.
For more about the move, see golang.org/s/go14nopkg.
2014-09-08 00:08:51 -04:00