aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikio Hara <mikioh.mikioh@gmail.com>2015-01-28 12:12:10 +0900
committerMikio Hara <mikioh.mikioh@gmail.com>2015-01-29 21:56:33 +0000
commit99928beb6ba3314731e30aead268586162663c38 (patch)
treeb5dffe582b146ccb4c9bfc9315be45f9a0735c7d
parent1439fec22846d745c88fdb5a1ab8a0a673e93be8 (diff)
downloadnet-99928beb6ba3314731e30aead268586162663c38.tar.gz
ipv4: make use of nettest.SupportsRawIPSocket
Change-Id: I12b41d16b49415081242e06b25a7106a4a0c0442 Reviewed-on: https://go-review.googlesource.com/3402 Reviewed-by: Ian Lance Taylor <iant@golang.org>
-rw-r--r--ipv4/icmp_test.go6
-rw-r--r--ipv4/multicast_test.go8
-rw-r--r--ipv4/multicastlistener_test.go9
-rw-r--r--ipv4/multicastsockopt_test.go10
-rw-r--r--ipv4/unicast_test.go8
-rw-r--r--ipv4/unicastsockopt_test.go10
6 files changed, 25 insertions, 26 deletions
diff --git a/ipv4/icmp_test.go b/ipv4/icmp_test.go
index d398f5b..ce0040d 100644
--- a/ipv4/icmp_test.go
+++ b/ipv4/icmp_test.go
@@ -6,11 +6,11 @@ package ipv4_test
import (
"net"
- "os"
"reflect"
"runtime"
"testing"
+ "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv4"
)
@@ -66,8 +66,8 @@ func TestSetICMPFilter(t *testing.T) {
default:
t.Skipf("not supported on %q", runtime.GOOS)
}
- if os.Getuid() != 0 {
- t.Skip("must be root")
+ if m, ok := nettest.SupportsRawIPSocket(); !ok {
+ t.Skip(m)
}
c, err := net.ListenPacket("ip4:icmp", "127.0.0.1")
diff --git a/ipv4/multicast_test.go b/ipv4/multicast_test.go
index d9f3f0d..ceece24 100644
--- a/ipv4/multicast_test.go
+++ b/ipv4/multicast_test.go
@@ -122,8 +122,8 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
case "nacl", "plan9", "solaris", "windows":
t.Skipf("not supported on %q", runtime.GOOS)
}
- if os.Getuid() != 0 {
- t.Skip("must be root")
+ if m, ok := nettest.SupportsRawIPSocket(); !ok {
+ t.Skip(m)
}
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
if ifi == nil {
@@ -229,8 +229,8 @@ func TestRawConnReadWriteMulticastICMP(t *testing.T) {
if testing.Short() {
t.Skip("to avoid external network")
}
- if os.Getuid() != 0 {
- t.Skip("must be root")
+ if m, ok := nettest.SupportsRawIPSocket(); !ok {
+ t.Skip(m)
}
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
if ifi == nil {
diff --git a/ipv4/multicastlistener_test.go b/ipv4/multicastlistener_test.go
index f9d7791..fd6dd75 100644
--- a/ipv4/multicastlistener_test.go
+++ b/ipv4/multicastlistener_test.go
@@ -6,7 +6,6 @@ package ipv4_test
import (
"net"
- "os"
"runtime"
"testing"
@@ -163,8 +162,8 @@ func TestIPSingleRawConnWithSingleGroupListener(t *testing.T) {
if testing.Short() {
t.Skip("to avoid external network")
}
- if os.Getuid() != 0 {
- t.Skip("must be root")
+ if m, ok := nettest.SupportsRawIPSocket(); !ok {
+ t.Skip(m)
}
c, err := net.ListenPacket("ip4:icmp", "0.0.0.0") // wildcard address
@@ -208,8 +207,8 @@ func TestIPPerInterfaceSingleRawConnWithSingleGroupListener(t *testing.T) {
if testing.Short() {
t.Skip("to avoid external network")
}
- if os.Getuid() != 0 {
- t.Skip("must be root")
+ if m, ok := nettest.SupportsRawIPSocket(); !ok {
+ t.Skip(m)
}
gaddr := net.IPAddr{IP: net.IPv4(224, 0, 0, 254)} // see RFC 4727
diff --git a/ipv4/multicastsockopt_test.go b/ipv4/multicastsockopt_test.go
index 7235d68..9f599fa 100644
--- a/ipv4/multicastsockopt_test.go
+++ b/ipv4/multicastsockopt_test.go
@@ -6,7 +6,6 @@ package ipv4_test
import (
"net"
- "os"
"runtime"
"testing"
@@ -35,9 +34,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 == "ip4" && os.Getuid() != 0 {
- t.Log("must be root")
+ if tt.net == "ip4" && !ok {
+ t.Log(m)
continue
}
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
@@ -69,8 +69,8 @@ func TestRawConnMulticastSocketOptions(t *testing.T) {
case "nacl", "plan9", "solaris":
t.Skipf("not supported on %q", runtime.GOOS)
}
- if os.Getuid() != 0 {
- t.Skip("must be root")
+ if m, ok := nettest.SupportsRawIPSocket(); !ok {
+ t.Skip(m)
}
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
if ifi == nil {
diff --git a/ipv4/unicast_test.go b/ipv4/unicast_test.go
index dfe8b72..05f7902 100644
--- a/ipv4/unicast_test.go
+++ b/ipv4/unicast_test.go
@@ -79,8 +79,8 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
case "nacl", "plan9", "solaris", "windows":
t.Skipf("not supported on %q", runtime.GOOS)
}
- if os.Getuid() != 0 {
- t.Skip("must be root")
+ if m, ok := nettest.SupportsRawIPSocket(); !ok {
+ t.Skip(m)
}
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
if ifi == nil {
@@ -162,8 +162,8 @@ func TestRawConnReadWriteUnicastICMP(t *testing.T) {
case "nacl", "plan9", "solaris", "windows":
t.Skipf("not supported on %q", runtime.GOOS)
}
- if os.Getuid() != 0 {
- t.Skip("must be root")
+ if m, ok := nettest.SupportsRawIPSocket(); !ok {
+ t.Skip(m)
}
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
if ifi == nil {
diff --git a/ipv4/unicastsockopt_test.go b/ipv4/unicastsockopt_test.go
index 7474510..eefa15d 100644
--- a/ipv4/unicastsockopt_test.go
+++ b/ipv4/unicastsockopt_test.go
@@ -6,7 +6,6 @@ package ipv4_test
import (
"net"
- "os"
"runtime"
"testing"
@@ -62,9 +61,10 @@ func TestPacketConnUnicastSocketOptions(t *testing.T) {
t.Skipf("not available on %q", runtime.GOOS)
}
+ m, ok := nettest.SupportsRawIPSocket()
for _, tt := range packetConnUnicastSocketOptionTests {
- if tt.net == "ip4" && os.Getuid() != 0 {
- t.Log("must be root")
+ if tt.net == "ip4" && !ok {
+ t.Log(m)
continue
}
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
@@ -82,8 +82,8 @@ func TestRawConnUnicastSocketOptions(t *testing.T) {
case "nacl", "plan9", "solaris":
t.Skipf("not supported on %q", runtime.GOOS)
}
- if os.Getuid() != 0 {
- t.Skip("must be root")
+ if m, ok := nettest.SupportsRawIPSocket(); !ok {
+ t.Skip(m)
}
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
if ifi == nil {