1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

add socksopt bindToDevice, rxtxbuf for linux

This commit is contained in:
Shelikhoo 2022-01-16 22:32:23 +00:00 committed by Xiaokang Wang (Shelikhoo)
parent ccab22b863
commit eb0b52fdfa

View File

@ -82,6 +82,32 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
}
}
if config.BindToDevice != "" {
if err := unix.BindToDevice(int(fd), config.BindToDevice); err != nil {
return newError("failed to set SO_BINDTODEVICE").Base(err)
}
}
if config.SocketTxBufSize != 0 {
syscallTarget := unix.SO_SNDBUF
if config.SocketForceBufSize {
syscallTarget = unix.SO_SNDBUFFORCE
}
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, syscallTarget, int(config.SocketTxBufSize)); err != nil {
return newError("failed to set SO_SNDBUF/SO_SNDBUFFORCE").Base(err)
}
}
if config.SocketRxBufSize != 0 {
syscallTarget := unix.SO_RCVBUF
if config.SocketForceBufSize {
syscallTarget = unix.SO_RCVBUFFORCE
}
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, syscallTarget, int(config.SocketRxBufSize)); err != nil {
return newError("failed to set SO_RCVBUF/SO_RCVBUFFORCE").Base(err)
}
}
return nil
}
@ -134,6 +160,31 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
}
}
if config.BindToDevice != "" {
if err := unix.BindToDevice(int(fd), config.BindToDevice); err != nil {
return newError("failed to set SO_BINDTODEVICE").Base(err)
}
}
if config.SocketTxBufSize != 0 {
syscallTarget := unix.SO_SNDBUF
if config.SocketForceBufSize {
syscallTarget = unix.SO_SNDBUFFORCE
}
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, syscallTarget, int(config.SocketTxBufSize)); err != nil {
return newError("failed to set SO_SNDBUF/SO_SNDBUFFORCE").Base(err)
}
}
if config.SocketRxBufSize != 0 {
syscallTarget := unix.SO_RCVBUF
if config.SocketForceBufSize {
syscallTarget = unix.SO_RCVBUFFORCE
}
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, syscallTarget, int(config.SocketRxBufSize)); err != nil {
return newError("failed to set SO_RCVBUF/SO_RCVBUFFORCE").Base(err)
}
}
return nil
}