Commit 26b81fba authored by Mikio Hara's avatar Mikio Hara

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: 's avatarIan Lance Taylor <iant@golang.org>
parent 749a502d
// 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
}
}
// Copyright 2015 The Go Authors. All rights reserved.
// 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 nacl plan9
// +build linux solaris
package nettest
func maxOpenFiles() int { return defaultMaxOpenFiles }
func supportsIPv6MulticastDeliveryOnLoopback() bool {
return true
}
......@@ -6,6 +6,23 @@
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
}
......@@ -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
}
......@@ -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
}
// 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 */ }
......@@ -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 {
......
// 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
}
// 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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment