diff --git a/ipv6/icmp_test.go b/ipv6/icmp_test.go index 76e02dc8..d0c8089c 100644 --- a/ipv6/icmp_test.go +++ b/ipv6/icmp_test.go @@ -6,11 +6,11 @@ package ipv6_test import ( "net" - "os" "reflect" "runtime" "testing" + "golang.org/x/net/internal/nettest" "golang.org/x/net/ipv6" ) @@ -67,8 +67,8 @@ func TestSetICMPFilter(t *testing.T) { if !supportsIPv6 { t.Skip("ipv6 is not supported") } - if os.Getuid() != 0 { - t.Skip("must be root") + if m, ok := nettest.SupportsRawIPSocket(); !ok { + t.Skip(m) } c, err := net.ListenPacket("ip6:ipv6-icmp", "::1") diff --git a/ipv6/multicast_test.go b/ipv6/multicast_test.go index 768f404c..0c1ac20a 100644 --- a/ipv6/multicast_test.go +++ b/ipv6/multicast_test.go @@ -140,8 +140,8 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) { if !supportsIPv6 { t.Skip("ipv6 is not supported") } - if os.Getuid() != 0 { - t.Skip("must be root") + if m, ok := nettest.SupportsRawIPSocket(); !ok { + t.Skip(m) } ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback) if ifi == nil { diff --git a/ipv6/multicastlistener_test.go b/ipv6/multicastlistener_test.go index 78393bfa..41e7235e 100644 --- a/ipv6/multicastlistener_test.go +++ b/ipv6/multicastlistener_test.go @@ -7,7 +7,6 @@ package ipv6_test import ( "fmt" "net" - "os" "runtime" "testing" @@ -164,8 +163,8 @@ func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) { if !supportsIPv6 { t.Skip("ipv6 is not supported") } - if os.Getuid() != 0 { - t.Skip("must be root") + if m, ok := nettest.SupportsRawIPSocket(); !ok { + t.Skip(m) } c, err := net.ListenPacket("ip6:ipv6-icmp", "::") // wildcard address @@ -208,8 +207,8 @@ func TestIPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) { if !supportsIPv6 { t.Skip("ipv6 is not supported") } - if os.Getuid() != 0 { - t.Skip("must be root") + if m, ok := nettest.SupportsRawIPSocket(); !ok { + t.Skip(m) } gaddr := net.IPAddr{IP: net.ParseIP("ff02::114")} // see RFC 4727 diff --git a/ipv6/multicastsockopt_test.go b/ipv6/multicastsockopt_test.go index 72e68a03..bf59750c 100644 --- a/ipv6/multicastsockopt_test.go +++ b/ipv6/multicastsockopt_test.go @@ -6,7 +6,6 @@ package ipv6_test import ( "net" - "os" "runtime" "testing" @@ -38,9 +37,10 @@ func TestPacketConnMulticastSocketOptions(t *testing.T) { t.Skipf("not available on %q", runtime.GOOS) } + m, ok := nettest.SupportsRawIPSocket() for _, tt := range packetConnMulticastSocketOptionTests { - if tt.net == "ip6" && os.Getuid() != 0 { - t.Log("must be root") + if tt.net == "ip6" && !ok { + t.Log(m) continue } c, err := net.ListenPacket(tt.net+tt.proto, tt.addr) diff --git a/ipv6/sockopt_test.go b/ipv6/sockopt_test.go index 96048bfb..7dd95c71 100644 --- a/ipv6/sockopt_test.go +++ b/ipv6/sockopt_test.go @@ -7,7 +7,6 @@ package ipv6_test import ( "fmt" "net" - "os" "runtime" "testing" @@ -102,8 +101,8 @@ func TestPacketConnChecksum(t *testing.T) { if !supportsIPv6 { t.Skip("ipv6 is not supported") } - if os.Getuid() != 0 { - t.Skip("must be root") + if m, ok := nettest.SupportsRawIPSocket(); !ok { + t.Skip(m) } c, err := net.ListenPacket(fmt.Sprintf("ip6:%d", iana.ProtocolOSPFIGP), "::") // OSPF for IPv6 diff --git a/ipv6/unicast_test.go b/ipv6/unicast_test.go index 6394965a..30660cd0 100644 --- a/ipv6/unicast_test.go +++ b/ipv6/unicast_test.go @@ -89,8 +89,8 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) { if !supportsIPv6 { t.Skip("ipv6 is not supported") } - if os.Getuid() != 0 { - t.Skip("must be root") + if m, ok := nettest.SupportsRawIPSocket(); !ok { + t.Skip(m) } c, err := net.ListenPacket("ip6:ipv6-icmp", "::1") diff --git a/ipv6/unicastsockopt_test.go b/ipv6/unicastsockopt_test.go index 97e71a76..51448d45 100644 --- a/ipv6/unicastsockopt_test.go +++ b/ipv6/unicastsockopt_test.go @@ -6,11 +6,11 @@ package ipv6_test import ( "net" - "os" "runtime" "testing" "golang.org/x/net/internal/iana" + "golang.org/x/net/internal/nettest" "golang.org/x/net/ipv6" ) @@ -59,9 +59,11 @@ func TestPacketConnUnicastSocketOptions(t *testing.T) { t.Skip("ipv6 is not supported") } + m, ok := nettest.SupportsRawIPSocket() for _, tt := range packetConnUnicastSocketOptionTests { - if tt.net == "ip6" && os.Getuid() != 0 { - t.Skip("must be root") + if tt.net == "ip6" && !ok { + t.Log(m) + continue } c, err := net.ListenPacket(tt.net+tt.proto, tt.addr) if err != nil {