author | Mikio Hara
<mikioh.mikioh@gmail.com> 2016-09-12 21:03:54 UTC |
committer | Mikio Hara
<mikioh.mikioh@gmail.com> 2016-09-14 08:42:56 UTC |
parent | 749a502dd1eaf3e5bfd4f8956748c502357c0bbe |
internal/nettest/error_stub.go | +0 | -11 |
internal/nettest/helper_bsd.go | +48 | -0 |
internal/nettest/helper_nobsd.go | +11 | -0 |
internal/nettest/{error_posix.go => helper_posix.go} | +0 | -0 |
internal/nettest/helper_stub.go | +28 | -0 |
internal/nettest/{rlimit_unix.go => helper_unix.go} | +13 | -1 |
internal/nettest/{stack_windows.go => helper_windows.go} | +9 | -3 |
internal/nettest/rlimit_stub.go | +0 | -9 |
internal/nettest/rlimit_windows.go | +0 | -7 |
internal/nettest/stack.go | +13 | -0 |
internal/nettest/stack_stub.go | +0 | -18 |
internal/nettest/stack_unix.go | +0 | -22 |
diff --git a/internal/nettest/error_stub.go b/internal/nettest/error_stub.go deleted file mode 100644 index 3c74d81..0000000 --- a/internal/nettest/error_stub.go +++ /dev/null @@ -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 -} diff --git a/internal/nettest/helper_bsd.go b/internal/nettest/helper_bsd.go new file mode 100644 index 0000000..b2308a0 --- /dev/null +++ b/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 + } +} diff --git a/internal/nettest/helper_nobsd.go b/internal/nettest/helper_nobsd.go new file mode 100644 index 0000000..a42b807 --- /dev/null +++ b/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 +} diff --git a/internal/nettest/error_posix.go b/internal/nettest/helper_posix.go similarity index 100% rename from internal/nettest/error_posix.go rename to internal/nettest/helper_posix.go diff --git a/internal/nettest/helper_stub.go b/internal/nettest/helper_stub.go new file mode 100644 index 0000000..22d4935 --- /dev/null +++ b/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 +} diff --git a/internal/nettest/rlimit_unix.go b/internal/nettest/helper_unix.go similarity index 67% rename from internal/nettest/rlimit_unix.go rename to internal/nettest/helper_unix.go index eb4312c..ed13e44 100644 --- a/internal/nettest/rlimit_unix.go +++ b/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 +} diff --git a/internal/nettest/stack_windows.go b/internal/nettest/helper_windows.go similarity index 83% rename from internal/nettest/stack_windows.go rename to internal/nettest/helper_windows.go index a21f499..b0a6a30 100644 --- a/internal/nettest/stack_windows.go +++ b/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 +} diff --git a/internal/nettest/rlimit_stub.go b/internal/nettest/rlimit_stub.go deleted file mode 100644 index 102bef9..0000000 --- a/internal/nettest/rlimit_stub.go +++ /dev/null @@ -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 } diff --git a/internal/nettest/rlimit_windows.go b/internal/nettest/rlimit_windows.go deleted file mode 100644 index de927b5..0000000 --- a/internal/nettest/rlimit_windows.go +++ /dev/null @@ -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 */ } diff --git a/internal/nettest/stack.go b/internal/nettest/stack.go index e07c015..86de277 100644 --- a/internal/nettest/stack.go +++ b/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 { diff --git a/internal/nettest/stack_stub.go b/internal/nettest/stack_stub.go deleted file mode 100644 index 1b5fde1..0000000 --- a/internal/nettest/stack_stub.go +++ /dev/null @@ -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 -} diff --git a/internal/nettest/stack_unix.go b/internal/nettest/stack_unix.go deleted file mode 100644 index af89229..0000000 --- a/internal/nettest/stack_unix.go +++ /dev/null @@ -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 -}