mirror of
https://github.com/golang/net.git
synced 2026-03-31 18:37:08 +09:00
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>
This commit is contained in:
@@ -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
internal/nettest/helper_bsd.go
Normal file
48
internal/nettest/helper_bsd.go
Normal file
@@ -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
internal/nettest/helper_nobsd.go
Normal file
11
internal/nettest/helper_nobsd.go
Normal file
@@ -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
|
||||
}
|
||||
28
internal/nettest/helper_stub.go
Normal file
28
internal/nettest/helper_stub.go
Normal file
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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 }
|
||||
@@ -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 */ }
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user