Преглед на файлове

internal/nettest: make SupportsIPv6 return false on Darwin kernel version 12 or below

The kernel is used in OS X Mountain Lion or below, or iOS version 8 or
below.

Updates golang/go#17015.

Change-Id: I8a849dc2ab4e04535f893b776bf704079cc91977
Reviewed-on: https://go-review.googlesource.com/33250
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Mikio Hara преди 9 години
родител
ревизия
6683f96f09
променени са 5 файла, в които са добавени 40 реда и са изтрити 20 реда
  1. 25 20
      internal/nettest/helper_bsd.go
  2. 4 0
      internal/nettest/helper_nobsd.go
  3. 4 0
      internal/nettest/helper_stub.go
  4. 4 0
      internal/nettest/helper_windows.go
  5. 3 0
      internal/nettest/stack.go

+ 25 - 20
internal/nettest/helper_bsd.go

@@ -13,6 +13,23 @@ import (
 	"syscall"
 	"syscall"
 )
 )
 
 
+var darwinVersion int
+
+func init() {
+	if runtime.GOOS == "darwin" {
+		// See http://support.apple.com/kb/HT1633.
+		s, err := syscall.Sysctl("kern.osrelease")
+		if err != nil {
+			return
+		}
+		ss := strings.Split(s, ".")
+		if len(ss) == 0 {
+			return
+		}
+		darwinVersion, _ = strconv.Atoi(ss[0])
+	}
+}
+
 func supportsIPv6MulticastDeliveryOnLoopback() bool {
 func supportsIPv6MulticastDeliveryOnLoopback() bool {
 	switch runtime.GOOS {
 	switch runtime.GOOS {
 	case "freebsd":
 	case "freebsd":
@@ -22,27 +39,15 @@ func supportsIPv6MulticastDeliveryOnLoopback() bool {
 		// packets correctly.
 		// packets correctly.
 		return false
 		return false
 	case "darwin":
 	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
+		return !causesIPv6Crash()
 	default:
 	default:
 		return true
 		return true
 	}
 	}
 }
 }
+
+func causesIPv6Crash() bool {
+	// We see some kernel crash when running IPv6 with IP-level
+	// options on Darwin kernel version 12 or below.
+	// See golang.org/issues/17015.
+	return darwinVersion < 13
+}

+ 4 - 0
internal/nettest/helper_nobsd.go

@@ -9,3 +9,7 @@ package nettest
 func supportsIPv6MulticastDeliveryOnLoopback() bool {
 func supportsIPv6MulticastDeliveryOnLoopback() bool {
 	return true
 	return true
 }
 }
+
+func causesIPv6Crash() bool {
+	return false
+}

+ 4 - 0
internal/nettest/helper_stub.go

@@ -23,6 +23,10 @@ func supportsIPv6MulticastDeliveryOnLoopback() bool {
 	return false
 	return false
 }
 }
 
 
+func causesIPv6Crash() bool {
+	return false
+}
+
 func protocolNotSupported(err error) bool {
 func protocolNotSupported(err error) bool {
 	return false
 	return false
 }
 }

+ 4 - 0
internal/nettest/helper_windows.go

@@ -36,3 +36,7 @@ func supportsRawIPSocket() (string, bool) {
 func supportsIPv6MulticastDeliveryOnLoopback() bool {
 func supportsIPv6MulticastDeliveryOnLoopback() bool {
 	return true
 	return true
 }
 }
+
+func causesIPv6Crash() bool {
+	return false
+}

+ 3 - 0
internal/nettest/stack.go

@@ -21,6 +21,9 @@ func SupportsIPv4() bool {
 // SupportsIPv6 reports whether the platform supports IPv6 networking
 // SupportsIPv6 reports whether the platform supports IPv6 networking
 // functionality.
 // functionality.
 func SupportsIPv6() bool {
 func SupportsIPv6() bool {
+	if causesIPv6Crash() {
+		return false
+	}
 	ln, err := net.Listen("tcp6", "[::1]:0")
 	ln, err := net.Listen("tcp6", "[::1]:0")
 	if err != nil {
 	if err != nil {
 		return false
 		return false