net: adjust dual stack support on dragonfly
As mentioned in
http://gitweb.dragonflybsd.org/dragonfly.git/commit/727ccde8cce813911d885b7f6ed749dcea68a886,
DragonFly BSD is dropping support for IPv6 IPv4-mapped address.
Unfortunately, on some released versions we see the kernels pretend to
support the feature but actually not (unless tweaking some kernel states
via sysctl.)
To avoid unpredictable behavior, the net package assumes that all
DragonFly BSD kernels don't support IPv6 IPv4-mapped address.
Fixes #10764.
Change-Id: Ic7af3651e0372ec03774432fbb6b2eb0c455e994
Reviewed-on: https://go-review.googlesource.com/10071
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/src/net/ipsock_posix.go b/src/net/ipsock_posix.go
index 56b9872..83eaf85 100644
--- a/src/net/ipsock_posix.go
+++ b/src/net/ipsock_posix.go
@@ -9,10 +9,18 @@
package net
import (
+ "runtime"
"syscall"
"time"
)
+// BUG(rsc,mikio): On DragonFly BSD and OpenBSD, listening on the
+// "tcp" and "udp" networks does not listen for both IPv4 and IPv6
+// connections. This is due to the fact that IPv4 traffic will not be
+// routed to an IPv6 socket - two separate sockets are required if
+// both address families are to be supported.
+// See inet6(4) for details.
+
func probeIPv4Stack() bool {
s, err := socketFunc(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
switch err {
@@ -41,13 +49,28 @@
var probes = []struct {
laddr TCPAddr
value int
- ok bool
}{
// IPv6 communication capability
{laddr: TCPAddr{IP: ParseIP("::1")}, value: 1},
// IPv6 IPv4-mapped address communication capability
{laddr: TCPAddr{IP: IPv4(127, 0, 0, 1)}, value: 0},
}
+ var supps [2]bool
+ switch runtime.GOOS {
+ case "dragonfly", "openbsd":
+ // Some released versions of DragonFly BSD pretend to
+ // accept IPV6_V6ONLY=0 successfully, but the state
+ // still stays IPV6_V6ONLY=1. Eventually DragonFly BSD
+ // stops preteding, but the transition period would
+ // cause unpredictable behavior and we need to avoid
+ // it.
+ //
+ // OpenBSD also doesn't support IPV6_V6ONLY=0 but it
+ // never pretends to accept IPV6_V6OLY=0. It always
+ // returns an error and we don't need to probe the
+ // capability.
+ probes = probes[:1]
+ }
for i := range probes {
s, err := socketFunc(syscall.AF_INET6, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
@@ -63,10 +86,10 @@
if err := syscall.Bind(s, sa); err != nil {
continue
}
- probes[i].ok = true
+ supps[i] = true
}
- return probes[0].ok, probes[1].ok
+ return supps[0], supps[1]
}
// favoriteAddrFamily returns the appropriate address family to