Make the loopback buffers configurable

This commit is contained in:
notsure2 2023-01-05 18:49:27 +02:00
parent 786607d31e
commit 4a989ccd14
1 changed files with 23 additions and 15 deletions

View File

@ -17,15 +17,17 @@ import (
) )
type RawConfig struct { type RawConfig struct {
ProxyBook map[string][]string ProxyBook map[string][]string
BindAddr []string BindAddr []string
BypassUID [][]byte BypassUID [][]byte
RedirAddr string RedirAddr string
PrivateKey []byte PrivateKey []byte
AdminUID []byte AdminUID []byte
DatabasePath string DatabasePath string
KeepAlive int KeepAlive int
CncMode bool CncMode bool
LoopbackTcpSendBuffer int
LoopbackTcpReceiveBuffer int
} }
// State type stores the global state of the program // State type stores the global state of the program
@ -175,14 +177,20 @@ func InitState(preParse RawConfig, worldState common.WorldState) (sta *State, er
} }
return c.Control(func(fd uintptr) { return c.Control(func(fd uintptr) {
err := syscall.SetsockoptInt(platformfd(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF, 32*1024) if preParse.LoopbackTcpSendBuffer > 0 {
if err != nil { log.Debugf("Setting loopback connection tcp send buffer: %d", preParse.LoopbackTcpSendBuffer)
log.Println("setsocketopt SO_SNDBUF: ", err) err := syscall.SetsockoptInt(platformfd(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF, preParse.LoopbackTcpSendBuffer)
if err != nil {
log.Errorf("setsocketopt SO_SNDBUF: %s\n", err)
}
} }
err = syscall.SetsockoptInt(platformfd(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, 32*1024) if preParse.LoopbackTcpReceiveBuffer > 0 {
if err != nil { log.Debugf("Setting loopback connection tcp receive buffer: %d", preParse.LoopbackTcpReceiveBuffer)
log.Println("setsocketopt SO_RCVBUF: ", err) err = syscall.SetsockoptInt(platformfd(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, preParse.LoopbackTcpReceiveBuffer)
if err != nil {
log.Errorf("setsocketopt SO_RCVBUF: %s\n", err)
}
} }
}) })
} }