From 57bc7a043405c7e7215360f5fd1b80df6f56bb43 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Fri, 10 Apr 2015 17:24:43 +0900 Subject: [PATCH] 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/8743 Reviewed-by: Ian Lance Taylor --- src/net/main_posix_test.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/net/main_posix_test.go b/src/net/main_posix_test.go index da80ff03c8..ead311c3cd 100644 --- a/src/net/main_posix_test.go +++ b/src/net/main_posix_test.go @@ -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 } } -- 2.48.1