diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2017-06-07 21:01:48 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-06-08 22:20:17 +0000 |
| commit | 78cf0e56ce5372ed3bf81e41e4ab23f68d3eaa77 (patch) | |
| tree | d61bde4e5b2ada25cbbe4be22d30792d2cb6dd5e /src/net/ipsock.go | |
| parent | d8a7990ffad9aebfb7261df7afb3049da4a09986 (diff) | |
| download | go-78cf0e56ce5372ed3bf81e41e4ab23f68d3eaa77.tar.xz | |
net: make Dial("tcp", ln.Addr().String()) work even with bad IPv6 config
Some machines can be configured (or came/come configured) in such a
state that IPv6 only half works: you can bind on [::]:n but not
connect back to it.
This implements a fallback such that it's guaranteed that this pattern
works:
ln, err := Listen("tcp", ":0")
...
addr := ln.Addr().String() // "[::]:n"
c, err := Dial("tcp", addr)
... which is also now tested. It will first try to dial "[::]:n", as
before, but if that dial fails, it will also try "0.0.0.0:n".
Fixes #18806 (contains more details)
Fixes #20611 (I was going to fix nacl later, but it was easy enough)
Change-Id: I1107eb197e902ae8185c781ad1bc4e2bc61d1f4c
Reviewed-on: https://go-review.googlesource.com/45088
Reviewed-by: Paul Marks <pmarks@google.com>
Diffstat (limited to 'src/net/ipsock.go')
| -rw-r--r-- | src/net/ipsock.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/net/ipsock.go b/src/net/ipsock.go index ade6eab62a..6049692d37 100644 --- a/src/net/ipsock.go +++ b/src/net/ipsock.go @@ -254,6 +254,13 @@ func (r *Resolver) internetAddrList(ctx context.Context, net, addr string) (addr ips = []IPAddr{{IP: ip}} } else if ip, zone := parseIPv6(host, true); ip != nil { ips = []IPAddr{{IP: ip, Zone: zone}} + // Issue 18806: if the machine has halfway configured + // IPv6 such that it can bind on "::" (IPv6unspecified) + // but not connect back to that same address, fall + // back to dialing 0.0.0.0. + if ip.Equal(IPv6unspecified) { + ips = append(ips, IPAddr{IP: IPv4zero}) + } } else { // Try as a DNS name. ips, err = r.LookupIPAddr(ctx, host) |
