]> Cypherpunks repositories - gostls13.git/commitdiff
undo CL 4557058 / b4c2ffae7034
authorRuss Cox <rsc@golang.org>
Wed, 1 Jun 2011 19:49:57 +0000 (15:49 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 1 Jun 2011 19:49:57 +0000 (15:49 -0400)
Using the getaddrinfo order is only okay if we
are smart enough to try multiple addresses in Dial.
Since the code does not do that, we must make
the right first choice, regardless of what getaddrinfo
does, and more often that not that means using the
IPv4 address, even on IPv6 systems.  With the CL
applied, gotest fails in package net on OS X.

helix.cam=; gotest
...
--- FAIL: net.TestDialGoogleIPv4 (1.05 seconds)
        -- 74.125.226.179:80 --
        -- www.google.com:80 --
        Dial("tcp", "", "www.google.com:80") = _, dial tcp [2001:4860:800f::69]:80: address family not supported by protocol family
        -- 74.125.226.179:http --
        -- www.google.com:http --
        Dial("tcp", "", "www.google.com:http") = _, dial tcp [2001:4860:800f::69]:80: address family not supported by protocol family
        -- 074.125.226.179:0080 --
        -- [::ffff:74.125.226.179]:80 --
        -- [::ffff:4a7d:e2b3]:80 --
        -- [0:0:0:0:0000:ffff:74.125.226.179]:80 --
        -- [0:0:0:0:000000:ffff:74.125.226.179]:80 --
        -- [0:0:0:0:0:ffff::74.125.226.179]:80 --
FAIL
gotest: "./6.out" failed: exit status 1

««« original CL description
net: name-based destination address selection

getaddrinfo() orders the addresses according to RFC 3484.

This means when IPv6 is working on a host we get results like:
    []string = {"2001:4810::110", "66.117.47.214"}

and when it's not working we get:
    []string = {"66.117.47.214", "2001:4810::110"}

thus can drop firstFavoriteAddr.

This also means /etc/gai.conf works on relevant systems.

R=rsc, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/4557058

»»»

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/4532101

src/pkg/net/iprawsock.go
src/pkg/net/ipsock.go

index 357bc91cfeef15faae06b1fc4288124d91913742..a811027b1c72263a3210459f90a225ccf4fa89f3 100644 (file)
@@ -253,7 +253,7 @@ func hostToIP(net, host string) (ip IP, err os.Error) {
                        err = err1
                        goto Error
                }
-               addr = firstSupportedAddr(filter, addrs)
+               addr = firstFavoriteAddr(filter, addrs)
                if addr == nil {
                        // should not happen
                        err = &AddrError{"LookupHost returned no suitable address", addrs[0]}
index d44a88c965d726bdb170aafbede7e1d25fcbf4f5..0b8c388f15d6ccf6883c164d7efcf378b622228b 100644 (file)
@@ -98,6 +98,23 @@ func favoriteAddrFamily(net string, raddr, laddr sockaddr, mode string) int {
        return syscall.AF_INET6
 }
 
+func firstFavoriteAddr(filter func(IP) IP, addrs []string) (addr IP) {
+       if filter == anyaddr {
+               // We'll take any IP address, but since the dialing code
+               // does not yet try multiple addresses, prefer to use
+               // an IPv4 address if possible.  This is especially relevant
+               // if localhost resolves to [ipv6-localhost, ipv4-localhost].
+               // Too much code assumes localhost == ipv4-localhost.
+               addr = firstSupportedAddr(ipv4only, addrs)
+               if addr == nil {
+                       addr = firstSupportedAddr(anyaddr, addrs)
+               }
+       } else {
+               addr = firstSupportedAddr(filter, addrs)
+       }
+       return
+}
+
 func firstSupportedAddr(filter func(IP) IP, addrs []string) IP {
        for _, s := range addrs {
                if addr := filter(ParseIP(s)); addr != nil {
@@ -276,7 +293,7 @@ func hostPortToIP(net, hostport string) (ip IP, iport int, err os.Error) {
                                err = err1
                                goto Error
                        }
-                       addr = firstSupportedAddr(filter, addrs)
+                       addr = firstFavoriteAddr(filter, addrs)
                        if addr == nil {
                                // should not happen
                                err = &AddrError{"LookupHost returned no suitable address", addrs[0]}