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:
parent
ccab22b863
commit
eb0b52fdfa
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user