mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-13 04:24:09 +08:00
Revert: udp-rlybuf option
As a low-level networking tool, tun2socks should be able to handle UDP packets of all possible sizes. This reverts commit fb9ca95909
.
This commit is contained in:
@@ -22,7 +22,6 @@ ENV PROXY=direct://
|
|||||||
ENV MTU=9000
|
ENV MTU=9000
|
||||||
ENV RESTAPI=
|
ENV RESTAPI=
|
||||||
ENV UDP_TIMEOUT=
|
ENV UDP_TIMEOUT=
|
||||||
ENV UDP_RLYBUF=
|
|
||||||
ENV TCP_SNDBUF=
|
ENV TCP_SNDBUF=
|
||||||
ENV TCP_RCVBUF=
|
ENV TCP_RCVBUF=
|
||||||
ENV TCP_AUTO_TUNING=
|
ENV TCP_AUTO_TUNING=
|
||||||
|
@@ -133,14 +133,6 @@ func general(k *Key) error {
|
|||||||
}
|
}
|
||||||
tunnel.SetUDPTimeout(k.UDPTimeout)
|
tunnel.SetUDPTimeout(k.UDPTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
if k.UDPRelayBufferSize != "" {
|
|
||||||
size, err := units.RAMInBytes(k.UDPRelayBufferSize)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
tunnel.SetUDPRelayBufferSize(int(size))
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,7 +14,6 @@ type Key struct {
|
|||||||
TCPSendBufferSize string `yaml:"tcp-send-buffer-size"`
|
TCPSendBufferSize string `yaml:"tcp-send-buffer-size"`
|
||||||
TCPReceiveBufferSize string `yaml:"tcp-receive-buffer-size"`
|
TCPReceiveBufferSize string `yaml:"tcp-receive-buffer-size"`
|
||||||
TCPWaitTimeout time.Duration `yaml:"tcp-wait-timeout"`
|
TCPWaitTimeout time.Duration `yaml:"tcp-wait-timeout"`
|
||||||
UDPRelayBufferSize string `yaml:"udp-relay-buffer-size"`
|
|
||||||
UDPTimeout time.Duration `yaml:"udp-timeout"`
|
UDPTimeout time.Duration `yaml:"udp-timeout"`
|
||||||
TUNPreUp string `yaml:"tun-pre-up"`
|
TUNPreUp string `yaml:"tun-pre-up"`
|
||||||
TUNPostUp string `yaml:"tun-post-up"`
|
TUNPostUp string `yaml:"tun-post-up"`
|
||||||
|
1
main.go
1
main.go
@@ -35,7 +35,6 @@ func init() {
|
|||||||
flag.StringVar(&key.RestAPI, "restapi", "", "HTTP statistic server listen address")
|
flag.StringVar(&key.RestAPI, "restapi", "", "HTTP statistic server listen address")
|
||||||
flag.StringVar(&key.TCPSendBufferSize, "tcp-sndbuf", "", "Set TCP send buffer size for netstack")
|
flag.StringVar(&key.TCPSendBufferSize, "tcp-sndbuf", "", "Set TCP send buffer size for netstack")
|
||||||
flag.StringVar(&key.TCPReceiveBufferSize, "tcp-rcvbuf", "", "Set TCP receive buffer size for netstack")
|
flag.StringVar(&key.TCPReceiveBufferSize, "tcp-rcvbuf", "", "Set TCP receive buffer size for netstack")
|
||||||
flag.StringVar(&key.UDPRelayBufferSize, "udp-rlybuf", "", "Set UDP relay buffer size for tunnel")
|
|
||||||
flag.BoolVar(&key.TCPModerateReceiveBuffer, "tcp-auto-tuning", false, "Enable TCP receive buffer auto-tuning")
|
flag.BoolVar(&key.TCPModerateReceiveBuffer, "tcp-auto-tuning", false, "Enable TCP receive buffer auto-tuning")
|
||||||
flag.DurationVar(&key.TCPWaitTimeout, "tcp-wait-timeout", 0, "Set timeout before closing each TCP connection")
|
flag.DurationVar(&key.TCPWaitTimeout, "tcp-wait-timeout", 0, "Set timeout before closing each TCP connection")
|
||||||
flag.StringVar(&key.TUNPreUp, "tun-pre-up", "", "Execute a command before TUN device setup")
|
flag.StringVar(&key.TUNPreUp, "tun-pre-up", "", "Execute a command before TUN device setup")
|
||||||
|
@@ -15,22 +15,13 @@ import (
|
|||||||
"github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"
|
"github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// _udpSessionTimeout is the default timeout for each UDP session.
|
||||||
// _udpSessionTimeout is the default timeout for each UDP session.
|
var _udpSessionTimeout = 60 * time.Second
|
||||||
_udpSessionTimeout = 60 * time.Second
|
|
||||||
|
|
||||||
// _udpRelayBufferSize is the default size for UDP packets relay.
|
|
||||||
_udpRelayBufferSize = 16 << 10
|
|
||||||
)
|
|
||||||
|
|
||||||
func SetUDPTimeout(t time.Duration) {
|
func SetUDPTimeout(t time.Duration) {
|
||||||
_udpSessionTimeout = t
|
_udpSessionTimeout = t
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetUDPRelayBufferSize(size int) {
|
|
||||||
_udpRelayBufferSize = size
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Port Restricted NAT support.
|
// TODO: Port Restricted NAT support.
|
||||||
func handleUDPConn(uc adapter.UDPConn) {
|
func handleUDPConn(uc adapter.UDPConn) {
|
||||||
defer uc.Close()
|
defer uc.Close()
|
||||||
@@ -93,7 +84,7 @@ func relayPacket(left net.PacketConn, right net.PacketConn, to net.Addr) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func copyPacketBuffer(dst net.PacketConn, src net.PacketConn, to net.Addr, timeout time.Duration) error {
|
func copyPacketBuffer(dst net.PacketConn, src net.PacketConn, to net.Addr, timeout time.Duration) error {
|
||||||
buf := pool.Get(_udpRelayBufferSize)
|
buf := pool.Get(pool.MaxSegmentSize)
|
||||||
defer pool.Put(buf)
|
defer pool.Put(buf)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
Reference in New Issue
Block a user