浏览代码

internel/nettest: add SupportsIPv6MulticastDeliveryOnLoopback

Also consolidate platform-dependent helper files.

Updates golang/go#17015.

Change-Id: Ibf09479762029ecc7229ab4bb233138e0d4e69d9
Reviewed-on: https://go-review.googlesource.com/28997
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Mikio Hara 9 年之前
父节点
当前提交
26b81fba4e

+ 0 - 11
internal/nettest/error_stub.go

@@ -1,11 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build nacl plan9
-
-package nettest
-
-func protocolNotSupported(err error) bool {
-	return false
-}

+ 48 - 0
internal/nettest/helper_bsd.go

@@ -0,0 +1,48 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin dragonfly freebsd netbsd openbsd
+
+package nettest
+
+import (
+	"runtime"
+	"strconv"
+	"strings"
+	"syscall"
+)
+
+func supportsIPv6MulticastDeliveryOnLoopback() bool {
+	switch runtime.GOOS {
+	case "freebsd":
+		// See http://www.freebsd.org/cgi/query-pr.cgi?pr=180065.
+		// Even after the fix, it looks like the latest
+		// kernels don't deliver link-local scoped multicast
+		// packets correctly.
+		return false
+	case "darwin":
+		// See http://support.apple.com/kb/HT1633.
+		s, err := syscall.Sysctl("kern.osrelease")
+		if err != nil {
+			return false
+		}
+		ss := strings.Split(s, ".")
+		if len(ss) == 0 {
+			return false
+		}
+		// OS X 10.9 (Darwin 13) or above seems to do the
+		// right thing; preserving the packet header as it's
+		// needed for the checksum calcuration with pseudo
+		// header on loopback multicast delivery process.
+		// If not, you'll probably see what is the slow-acting
+		// kernel crash caused by lazy mbuf corruption.
+		// See ip6_mloopback in netinet6/ip6_output.c.
+		if mjver, err := strconv.Atoi(ss[0]); err != nil || mjver < 13 {
+			return false
+		}
+		return true
+	default:
+		return true
+	}
+}

+ 11 - 0
internal/nettest/helper_nobsd.go

@@ -0,0 +1,11 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build linux solaris
+
+package nettest
+
+func supportsIPv6MulticastDeliveryOnLoopback() bool {
+	return true
+}

+ 0 - 0
internal/nettest/error_posix.go → internal/nettest/helper_posix.go


+ 28 - 0
internal/nettest/helper_stub.go

@@ -0,0 +1,28 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build nacl plan9
+
+package nettest
+
+import (
+	"fmt"
+	"runtime"
+)
+
+func maxOpenFiles() int {
+	return defaultMaxOpenFiles
+}
+
+func supportsRawIPSocket() (string, bool) {
+	return fmt.Sprintf("not supported on %s", runtime.GOOS), false
+}
+
+func supportsIPv6MulticastDeliveryOnLoopback() bool {
+	return false
+}
+
+func protocolNotSupported(err error) bool {
+	return false
+}

+ 13 - 1
internal/nettest/rlimit_unix.go → internal/nettest/helper_unix.go

@@ -6,7 +6,12 @@
 
 package nettest
 
-import "syscall"
+import (
+	"fmt"
+	"os"
+	"runtime"
+	"syscall"
+)
 
 func maxOpenFiles() int {
 	var rlim syscall.Rlimit
@@ -15,3 +20,10 @@ func maxOpenFiles() int {
 	}
 	return int(rlim.Cur)
 }
+
+func supportsRawIPSocket() (string, bool) {
+	if os.Getuid() != 0 {
+		return fmt.Sprintf("must be root on %s", runtime.GOOS), false
+	}
+	return "", true
+}

+ 9 - 3
internal/nettest/stack_windows.go → internal/nettest/helper_windows.go

@@ -10,9 +10,11 @@ import (
 	"syscall"
 )
 
-// SupportsRawIPSocket reports whether the platform supports raw IP
-// sockets.
-func SupportsRawIPSocket() (string, bool) {
+func maxOpenFiles() int {
+	return 4 * defaultMaxOpenFiles /* actually it's 16581375 */
+}
+
+func supportsRawIPSocket() (string, bool) {
 	// From http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548.aspx:
 	// Note: To use a socket of type SOCK_RAW requires administrative privileges.
 	// Users running Winsock applications that use raw sockets must be a member of
@@ -30,3 +32,7 @@ func SupportsRawIPSocket() (string, bool) {
 	syscall.Closesocket(s)
 	return "", true
 }
+
+func supportsIPv6MulticastDeliveryOnLoopback() bool {
+	return true
+}

+ 0 - 9
internal/nettest/rlimit_stub.go

@@ -1,9 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build nacl plan9
-
-package nettest
-
-func maxOpenFiles() int { return defaultMaxOpenFiles }

+ 0 - 7
internal/nettest/rlimit_windows.go

@@ -1,7 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package nettest
-
-func maxOpenFiles() int { return 4 * defaultMaxOpenFiles /* actually it's 16581375 */ }

+ 13 - 0
internal/nettest/stack.go

@@ -29,6 +29,19 @@ func SupportsIPv6() bool {
 	return true
 }
 
+// SupportsRawIPSocket reports whether the platform supports raw IP
+// sockets.
+func SupportsRawIPSocket() (string, bool) {
+	return supportsRawIPSocket()
+}
+
+// SupportsIPv6MulticastDeliveryOnLoopback reports whether the
+// platform supports IPv6 multicast packet delivery on software
+// loopback interface.
+func SupportsIPv6MulticastDeliveryOnLoopback() bool {
+	return supportsIPv6MulticastDeliveryOnLoopback()
+}
+
 // ProtocolNotSupported reports whether err is a protocol not
 // supported error.
 func ProtocolNotSupported(err error) bool {

+ 0 - 18
internal/nettest/stack_stub.go

@@ -1,18 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build nacl plan9
-
-package nettest
-
-import (
-	"fmt"
-	"runtime"
-)
-
-// SupportsRawIPSocket reports whether the platform supports raw IP
-// sockets.
-func SupportsRawIPSocket() (string, bool) {
-	return fmt.Sprintf("not supported on %s", runtime.GOOS), false
-}

+ 0 - 22
internal/nettest/stack_unix.go

@@ -1,22 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build darwin dragonfly freebsd linux netbsd openbsd solaris
-
-package nettest
-
-import (
-	"fmt"
-	"os"
-	"runtime"
-)
-
-// SupportsRawIPSocket reports whether the platform supports raw IP
-// sockets.
-func SupportsRawIPSocket() (string, bool) {
-	if os.Getuid() != 0 {
-		return fmt.Sprintf("must be root on %s", runtime.GOOS), false
-	}
-	return "", true
-}