aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/net/ipsock_posix.go8
-rw-r--r--src/net/ipsock_test.go21
2 files changed, 28 insertions, 1 deletions
diff --git a/src/net/ipsock_posix.go b/src/net/ipsock_posix.go
index e34e9fe3d6..1d5e8ef226 100644
--- a/src/net/ipsock_posix.go
+++ b/src/net/ipsock_posix.go
@@ -70,7 +70,13 @@ func (p *ipStackCapabilities) probe() {
continue
}
if err := syscall.Bind(s, sa); err != nil {
- continue
+ // If the bind was denied by a security policy (BPF, seccomp,
+ // SELinux, etc.), the kernel still supports IPv6 — the socket
+ // was created and setsockopt succeeded. Only treat errors like
+ // EADDRNOTAVAIL as lack of support. See go.dev/issue/77430.
+ if err != syscall.EPERM && err != syscall.EACCES {
+ continue
+ }
}
if i == 0 {
p.ipv6Enabled = true
diff --git a/src/net/ipsock_test.go b/src/net/ipsock_test.go
index aede354844..887bbda5fa 100644
--- a/src/net/ipsock_test.go
+++ b/src/net/ipsock_test.go
@@ -6,6 +6,7 @@ package net
import (
"reflect"
+ "runtime"
"testing"
)
@@ -280,3 +281,23 @@ func TestAddrListPartition(t *testing.T) {
}
}
}
+
+func TestListenIPv6WildcardAddr(t *testing.T) {
+ if runtime.GOOS == "js" || runtime.GOOS == "wasip1" {
+ t.Skip("fake networking does not implement [::] wildcard address assertions")
+ }
+ if !supportsIPv6() {
+ t.Skip("IPv6 not supported")
+ }
+
+ ln, err := Listen("tcp", "[::]:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer ln.Close()
+
+ addr := ln.Addr().(*TCPAddr)
+ if addr.IP.To4() != nil {
+ t.Errorf("Listen(\"tcp\", \"[::]:0\") bound to %v, want IPv6 address", addr)
+ }
+}