Browse Source

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.
pull/248/head
xjasonlyu 2 years ago
parent
commit
b809f89411
  1. 1
      Dockerfile
  2. 8
      engine/engine.go
  3. 1
      engine/key.go
  4. 1
      main.go
  5. 15
      tunnel/udp.go

1
Dockerfile

@ -22,7 +22,6 @@ ENV PROXY=direct://
ENV MTU=9000
ENV RESTAPI=
ENV UDP_TIMEOUT=
ENV UDP_RLYBUF=
ENV TCP_SNDBUF=
ENV TCP_RCVBUF=
ENV TCP_AUTO_TUNING=

8
engine/engine.go

@ -133,14 +133,6 @@ func general(k *Key) error {
}
tunnel.SetUDPTimeout(k.UDPTimeout)
}
if k.UDPRelayBufferSize != "" {
size, err := units.RAMInBytes(k.UDPRelayBufferSize)
if err != nil {
return err
}
tunnel.SetUDPRelayBufferSize(int(size))
}
return nil
}

1
engine/key.go

@ -14,7 +14,6 @@ type Key struct {
TCPSendBufferSize string `yaml:"tcp-send-buffer-size"`
TCPReceiveBufferSize string `yaml:"tcp-receive-buffer-size"`
TCPWaitTimeout time.Duration `yaml:"tcp-wait-timeout"`
UDPRelayBufferSize string `yaml:"udp-relay-buffer-size"`
UDPTimeout time.Duration `yaml:"udp-timeout"`
TUNPreUp string `yaml:"tun-pre-up"`
TUNPostUp string `yaml:"tun-post-up"`

1
main.go

@ -35,7 +35,6 @@ func init() {
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.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.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")

15
tunnel/udp.go

@ -15,22 +15,13 @@ import (
"github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"
)
var (
// _udpSessionTimeout is the default timeout for each UDP session.
_udpSessionTimeout = 60 * time.Second
// _udpRelayBufferSize is the default size for UDP packets relay.
_udpRelayBufferSize = 16 << 10
)
// _udpSessionTimeout is the default timeout for each UDP session.
var _udpSessionTimeout = 60 * time.Second
func SetUDPTimeout(t time.Duration) {
_udpSessionTimeout = t
}
func SetUDPRelayBufferSize(size int) {
_udpRelayBufferSize = size
}
// TODO: Port Restricted NAT support.
func handleUDPConn(uc adapter.UDPConn) {
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 {
buf := pool.Get(_udpRelayBufferSize)
buf := pool.Get(pool.MaxSegmentSize)
defer pool.Put(buf)
for {

Loading…
Cancel
Save