helper_bsd.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build darwin dragonfly freebsd netbsd openbsd
  5. package nettest
  6. import (
  7. "runtime"
  8. "strconv"
  9. "strings"
  10. "syscall"
  11. )
  12. func supportsIPv6MulticastDeliveryOnLoopback() bool {
  13. switch runtime.GOOS {
  14. case "freebsd":
  15. // See http://www.freebsd.org/cgi/query-pr.cgi?pr=180065.
  16. // Even after the fix, it looks like the latest
  17. // kernels don't deliver link-local scoped multicast
  18. // packets correctly.
  19. return false
  20. case "darwin":
  21. // See http://support.apple.com/kb/HT1633.
  22. s, err := syscall.Sysctl("kern.osrelease")
  23. if err != nil {
  24. return false
  25. }
  26. ss := strings.Split(s, ".")
  27. if len(ss) == 0 {
  28. return false
  29. }
  30. // OS X 10.9 (Darwin 13) or above seems to do the
  31. // right thing; preserving the packet header as it's
  32. // needed for the checksum calcuration with pseudo
  33. // header on loopback multicast delivery process.
  34. // If not, you'll probably see what is the slow-acting
  35. // kernel crash caused by lazy mbuf corruption.
  36. // See ip6_mloopback in netinet6/ip6_output.c.
  37. if mjver, err := strconv.Atoi(ss[0]); err != nil || mjver < 13 {
  38. return false
  39. }
  40. return true
  41. default:
  42. return true
  43. }
  44. }