]> Cypherpunks repositories - gostls13.git/commitdiff
net: fix TestDialGoogle with -ipv6 when CGO_ENABLED=0
authorMikio Hara <mikioh.mikioh@gmail.com>
Fri, 10 Apr 2015 08:24:43 +0000 (17:24 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Thu, 16 Apr 2015 00:44:52 +0000 (00:44 +0000)
Under some dial tests that require external network connectivity, we
must prevent application traffic but must not interfere with control
plane traffic such as DNS message exchange. But test helper function
disableSocketConnect prevents both application and control plane traffic
unconditionally and makes some dial tests with -ipv6 fail when
CGO_ENABLED=0.

This change makes disableSocketConnect take a look at not only address
family but socket type for fixing some dial tests with -ipv6 when
CGO_ENBALED=0.

Change-Id: I32241d9592d31483424bb5e69cb4d56f3fc20312
Reviewed-on: https://go-review.googlesource.com/8743
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/main_posix_test.go

index da80ff03c8f68e8b4bafc78b410e084f34622d0a..ead311c3cddb7d8862586ac36570ab6f855291d3 100644 (file)
@@ -20,12 +20,28 @@ func disableSocketConnect(network string) {
        ss := strings.Split(network, ":")
        sw.Set(socktest.FilterConnect, func(so *socktest.Status) (socktest.AfterFilter, error) {
                switch ss[0] {
-               case "tcp4", "udp4", "ip4":
-                       if so.Cookie.Family() == syscall.AF_INET {
+               case "tcp4":
+                       if so.Cookie.Family() == syscall.AF_INET && so.Cookie.Type() == syscall.SOCK_STREAM {
                                return nil, syscall.EHOSTUNREACH
                        }
-               case "tcp6", "udp6", "ip6":
-                       if so.Cookie.Family() == syscall.AF_INET6 {
+               case "udp4":
+                       if so.Cookie.Family() == syscall.AF_INET && so.Cookie.Type() == syscall.SOCK_DGRAM {
+                               return nil, syscall.EHOSTUNREACH
+                       }
+               case "ip4":
+                       if so.Cookie.Family() == syscall.AF_INET && so.Cookie.Type() == syscall.SOCK_RAW {
+                               return nil, syscall.EHOSTUNREACH
+                       }
+               case "tcp6":
+                       if so.Cookie.Family() == syscall.AF_INET6 && so.Cookie.Type() == syscall.SOCK_STREAM {
+                               return nil, syscall.EHOSTUNREACH
+                       }
+               case "udp6":
+                       if so.Cookie.Family() == syscall.AF_INET6 && so.Cookie.Type() == syscall.SOCK_DGRAM {
+                               return nil, syscall.EHOSTUNREACH
+                       }
+               case "ip6":
+                       if so.Cookie.Family() == syscall.AF_INET6 && so.Cookie.Type() == syscall.SOCK_RAW {
                                return nil, syscall.EHOSTUNREACH
                        }
                }