diff --git a/share/tunnel/tunnel_in_proxy_udp.go b/share/tunnel/tunnel_in_proxy_udp.go index 35811c50..3f3fa8be 100644 --- a/share/tunnel/tunnel_in_proxy_udp.go +++ b/share/tunnel/tunnel_in_proxy_udp.go @@ -45,7 +45,9 @@ func listenUDP(l *cio.Logger, sshTun sshTunnel, remote *settings.Remote) (*udpLi sshTun: sshTun, remote: remote, inbound: conn, + maxMTU: settings.EnvInt("UDP_MAX_SIZE", 9012), } + u.Debugf("UDP max size: %d bytes", u.maxMTU) return u, nil } @@ -57,6 +59,7 @@ type udpListener struct { outboundMut sync.Mutex outbound *udpChannel sent, recv int64 + maxMTU int } func (u *udpListener) run(ctx context.Context) error { @@ -80,8 +83,7 @@ func (u *udpListener) run(ctx context.Context) error { } func (u *udpListener) runInbound(ctx context.Context) error { - const maxMTU = 9012 - buff := make([]byte, maxMTU) + buff := make([]byte, u.maxMTU) for !isDone(ctx) { //read from inbound udp u.inbound.SetReadDeadline(time.Now().Add(time.Second)) diff --git a/share/tunnel/tunnel_out_ssh_udp.go b/share/tunnel/tunnel_out_ssh_udp.go index 20a10a63..d3c4c62f 100644 --- a/share/tunnel/tunnel_out_ssh_udp.go +++ b/share/tunnel/tunnel_out_ssh_udp.go @@ -27,7 +27,9 @@ func (t *Tunnel) handleUDP(l *cio.Logger, rwc io.ReadWriteCloser, hostPort strin c: rwc, }, udpConns: conns, + maxMTU: settings.EnvInt("UDP_MAX_SIZE", 9012), } + h.Debugf("UDP max size: %d bytes", h.maxMTU) for { p := udpPacket{} if err := h.handleWrite(&p); err != nil { @@ -41,6 +43,7 @@ type udpHandler struct { hostPort string *udpChannel *udpConns + maxMTU int } func (h *udpHandler) handleWrite(p *udpPacket) error { @@ -77,8 +80,7 @@ func (h *udpHandler) handleWrite(p *udpPacket) error { func (h *udpHandler) handleRead(p *udpPacket, conn *udpConn) { //ensure connection is cleaned up defer h.udpConns.remove(conn.id) - const maxMTU = 9012 - buff := make([]byte, maxMTU) + buff := make([]byte, h.maxMTU) for { //response must arrive within 15 seconds deadline := settings.EnvDuration("UDP_DEADLINE", 15*time.Second)