Skip to content

Commit

Permalink
net: fix TestDialGoogle with -ipv6 when CGO_ENABLED=0
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cixtor committed Apr 16, 2015
1 parent f616af2 commit 57bc7a0
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/net/main_posix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 57bc7a0

Please sign in to comment.