Commit 57bc7a04 authored by Mikio Hara's avatar Mikio Hara

net: fix TestDialGoogle with -ipv6 when CGO_ENABLED=0

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/8743Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent f616af23
......@@ -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
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment