mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-18 18:36:11 -05:00
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package internet
|
|
|
|
import (
|
|
"syscall"
|
|
)
|
|
|
|
const (
|
|
// For incoming connections.
|
|
TCP_FASTOPEN = 23
|
|
// For out-going connections.
|
|
TCP_FASTOPEN_CONNECT = 30
|
|
)
|
|
|
|
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
|
|
if config.Mark != 0 {
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, int(config.Mark)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if isTCPSocket(network) {
|
|
switch config.Tfo {
|
|
case SocketConfig_Enable:
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN_CONNECT, 1); err != nil {
|
|
return err
|
|
}
|
|
case SocketConfig_Disable:
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN_CONNECT, 0); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
|
|
if isTCPSocket(network) {
|
|
switch config.Tfo {
|
|
case SocketConfig_Enable:
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN, 1); err != nil {
|
|
return err
|
|
}
|
|
case SocketConfig_Disable:
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN, 0); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|