openwrt
openwrt copied to clipboard
端口转发 UDP 存在泄漏
仅限于 udp
简单来说是因为 socat 转发 udp 需要加上 -T
启动参数,否则每个 udp 请求就会多一个进程无法自行关闭
可自行修改 /etc/init.d/socat
解决
-T<timeout>
Total inactivity timeout: when socat is already in the transfer loop and nothing has happened for <timeout> [timeval] seconds (no data arrived, no interrupt occurred...) then it terminates. Useful with protocols like UDP that cannot transfer EOF.
这转发的问题,确实没遇到。截图发过来看看。
真正爆的时候往往 ssh/网页 已经连不上了,我只勉强留了这张
简单复现一下(比如转发 dns)
可以使用 ps | grep '/var/etc/socat' | grep -v grep
查看 socat 的所有进程
每个 UDP Session 都会多个 1000KiB 的 fork 进程,因为没有设置
-T
参数所以永远不会自行结束除非重启 socat 服务
我自己根据需求改了 /etc/init.d/socat
TCP/UDP 都要加上这个参数的,建议干脆做个可配置的选项(因为 UDP 是无连接的所以更容易出现问题)
新版本 加了参数,具体 你再试试。可以用 大吉的端口转发。