Skip to content

Commit 230f714

Browse files
authored
UDP buffer size override with CHISEL_UDP_MAX_SIZE environment variable (#367)
1 parent dd19bc6 commit 230f714

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

share/tunnel/tunnel_in_proxy_udp.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ func listenUDP(l *cio.Logger, sshTun sshTunnel, remote *settings.Remote) (*udpLi
4545
sshTun: sshTun,
4646
remote: remote,
4747
inbound: conn,
48+
maxMTU: settings.EnvInt("UDP_MAX_SIZE", 9012),
4849
}
50+
u.Debugf("UDP max size: %d bytes", u.maxMTU)
4951
return u, nil
5052
}
5153

@@ -57,6 +59,7 @@ type udpListener struct {
5759
outboundMut sync.Mutex
5860
outbound *udpChannel
5961
sent, recv int64
62+
maxMTU int
6063
}
6164

6265
func (u *udpListener) run(ctx context.Context) error {
@@ -80,8 +83,7 @@ func (u *udpListener) run(ctx context.Context) error {
8083
}
8184

8285
func (u *udpListener) runInbound(ctx context.Context) error {
83-
const maxMTU = 9012
84-
buff := make([]byte, maxMTU)
86+
buff := make([]byte, u.maxMTU)
8587
for !isDone(ctx) {
8688
//read from inbound udp
8789
u.inbound.SetReadDeadline(time.Now().Add(time.Second))

share/tunnel/tunnel_out_ssh_udp.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func (t *Tunnel) handleUDP(l *cio.Logger, rwc io.ReadWriteCloser, hostPort strin
2727
c: rwc,
2828
},
2929
udpConns: conns,
30+
maxMTU: settings.EnvInt("UDP_MAX_SIZE", 9012),
3031
}
32+
h.Debugf("UDP max size: %d bytes", h.maxMTU)
3133
for {
3234
p := udpPacket{}
3335
if err := h.handleWrite(&p); err != nil {
@@ -41,6 +43,7 @@ type udpHandler struct {
4143
hostPort string
4244
*udpChannel
4345
*udpConns
46+
maxMTU int
4447
}
4548

4649
func (h *udpHandler) handleWrite(p *udpPacket) error {
@@ -77,8 +80,7 @@ func (h *udpHandler) handleWrite(p *udpPacket) error {
7780
func (h *udpHandler) handleRead(p *udpPacket, conn *udpConn) {
7881
//ensure connection is cleaned up
7982
defer h.udpConns.remove(conn.id)
80-
const maxMTU = 9012
81-
buff := make([]byte, maxMTU)
83+
buff := make([]byte, h.maxMTU)
8284
for {
8385
//response must arrive within 15 seconds
8486
deadline := settings.EnvDuration("UDP_DEADLINE", 15*time.Second)

0 commit comments

Comments
 (0)