Sockopt: Use Windows syscall (#4581)
Some checks are pending
Build docker image / build-image (push) Waiting to run
Build and Release for Windows 7 / build (win7-32, 386, windows) (push) Waiting to run
Build and Release for Windows 7 / build (win7-64, amd64, windows) (push) Waiting to run
Build and Release / build (amd64, darwin, ) (push) Waiting to run
Build and Release / build (amd64, freebsd, ) (push) Waiting to run
Build and Release / build (amd64, linux, ) (push) Waiting to run
Build and Release / build (amd64, openbsd, ) (push) Waiting to run
Build and Release / build (amd64, windows, ) (push) Waiting to run
Build and Release / build (arm, 5, linux) (push) Waiting to run
Build and Release / build (arm, 6, linux) (push) Waiting to run
Build and Release / build (arm, 7, freebsd) (push) Waiting to run
Build and Release / build (arm, 7, linux) (push) Waiting to run
Build and Release / build (arm, 7, openbsd) (push) Waiting to run
Build and Release / build (arm, 7, windows) (push) Waiting to run
Build and Release / build (arm64, android) (push) Waiting to run
Build and Release / build (arm64, darwin) (push) Waiting to run
Build and Release / build (arm64, freebsd) (push) Waiting to run
Build and Release / build (arm64, linux) (push) Waiting to run
Build and Release / build (arm64, openbsd) (push) Waiting to run
Build and Release / build (arm64, windows) (push) Waiting to run
Build and Release / build (loong64, linux) (push) Waiting to run
Build and Release / build (mips, linux) (push) Waiting to run
Build and Release / build (mips64, linux) (push) Waiting to run
Build and Release / build (mips64le, linux) (push) Waiting to run
Build and Release / build (mipsle, linux) (push) Waiting to run
Build and Release / build (ppc64, linux) (push) Waiting to run
Build and Release / build (ppc64le, linux) (push) Waiting to run
Build and Release / build (riscv64, linux) (push) Waiting to run
Build and Release / build (s390x, linux) (push) Waiting to run
Build and Release / build (386, freebsd, ) (push) Waiting to run
Build and Release / build (386, linux, ) (push) Waiting to run
Build and Release / build (386, openbsd, ) (push) Waiting to run
Build and Release / build (386, windows, ) (push) Waiting to run
Test / test (macos-latest) (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
Test / test (windows-latest) (push) Waiting to run

This commit is contained in:
xqzr
2025-04-07 23:50:07 +08:00
committed by GitHub
parent 2d3126b752
commit 78a1e37e89

View File

@@ -13,9 +13,6 @@ const (
TCP_FASTOPEN = 15 TCP_FASTOPEN = 15
IP_UNICAST_IF = 31 IP_UNICAST_IF = 31
IPV6_UNICAST_IF = 31 IPV6_UNICAST_IF = 31
IP_MULTICAST_IF = 9
IPV6_MULTICAST_IF = 9
IPV6_V6ONLY = 27
) )
func setTFO(fd syscall.Handle, tfo int) error { func setTFO(fd syscall.Handle, tfo int) error {
@@ -44,14 +41,14 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IP, IP_UNICAST_IF, int(idx)); err != nil { if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IP, IP_UNICAST_IF, int(idx)); err != nil {
return errors.New("failed to set IP_UNICAST_IF").Base(err) return errors.New("failed to set IP_UNICAST_IF").Base(err)
} }
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IP, IP_MULTICAST_IF, int(idx)); err != nil { if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, int(idx)); err != nil {
return errors.New("failed to set IP_MULTICAST_IF").Base(err) return errors.New("failed to set IP_MULTICAST_IF").Base(err)
} }
} else { } else {
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, IPV6_UNICAST_IF, inf.Index); err != nil { if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, IPV6_UNICAST_IF, inf.Index); err != nil {
return errors.New("failed to set IPV6_UNICAST_IF").Base(err) return errors.New("failed to set IPV6_UNICAST_IF").Base(err)
} }
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, IPV6_MULTICAST_IF, inf.Index); err != nil { if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_IF, inf.Index); err != nil {
return errors.New("failed to set IPV6_MULTICAST_IF").Base(err) return errors.New("failed to set IPV6_MULTICAST_IF").Base(err)
} }
} }
@@ -92,7 +89,7 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
} }
if config.V6Only { if config.V6Only {
if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, IPV6_V6ONLY, 1); err != nil { if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 1); err != nil {
return errors.New("failed to set IPV6_V6ONLY").Base(err) return errors.New("failed to set IPV6_V6ONLY").Base(err)
} }
} }