Skip to content

TUN inbound: Make udp_fullcone pure side effect free udp connection#5526

Merged
RPRX merged 3 commits intoXTLS:mainfrom
Owersun:tun-udp-connection
Jan 12, 2026
Merged

TUN inbound: Make udp_fullcone pure side effect free udp connection#5526
RPRX merged 3 commits intoXTLS:mainfrom
Owersun:tun-udp-connection

Conversation

@Owersun
Copy link
Collaborator

@Owersun Owersun commented Jan 12, 2026

This makes udp_fullcone usage independent side effect free implementation of net.Conn
This allows to substitute other imeplentations ip stacks could use, but with custom logic allowing FullCone NAT
The code is clearly split to the places it belong, and handler/stack_gvisor/udp_fullcone don't depend on each other and don't know about each others implementation as they should be.
Both stack and connection are nice 200-300 line files.
Connection handling was remove from udp_fullcone and delegated to be part of lifecycle handler should do.
Handler will close connections calling .Close() on net.Conn, when outbound signal that the connection is complete, which will make udp connections close and clean up.
Running for 12 hours with two devices behind a router shows proper gofunc cleanup, keeping the number of running coroutines going up and down with connection number.
Log message of processed connection made more generic "processing connection" with source and destination including network protocol info

…plementing net.Conn

Decouple udp connection from gVisor primitives, making handler/stack/udp_connection implementation independent of each other
@RPRX
Copy link
Member

RPRX commented Jan 12, 2026

为了防止 #5525 (comment) ,顺便把 gVisor 升级到最新稳定版本吧,如果它有稳定版本的话

@Owersun
Copy link
Collaborator Author

Owersun commented Jan 12, 2026

I will try to upgrade the gVisor to latest possible version.
Although it looks like latest gVisor have some breaking changes, some structures were redefined in it.
I will try to find the latest possible version that fits tun/wireguard/other implementations.

@RPRX
Copy link
Member

RPRX commented Jan 12, 2026

你先看一下 latest gVisor 有没有 breaking changes,如果有的话就不放这个 PR 里了,等我合了这个 PR 后你另开一个 PR

@Owersun
Copy link
Collaborator Author

Owersun commented Jan 12, 2026

Opened as separate #5527 to be reviewed separately, due to small modification for proxy/wireguard needed for latest gVisor version.
This PR work fine as with current gVisor, as with new one, so this PR and new PR can be merged/reviewed separately.

@RPRX RPRX merged commit 7726fbe into XTLS:main Jan 12, 2026
39 checks passed
@RPRX
Copy link
Member

RPRX commented Jan 12, 2026

我刚发现你这 UDP 没实现 net.PacketConn,可能全去用 SingleReader 而没有 PacketReader,虽然都用 SingleReader 好像也行

@Owersun
Copy link
Collaborator Author

Owersun commented Jan 12, 2026

我刚发现你这 UDP 没实现 net.PacketConn,可能全去用 SingleReader 而没有 PacketReader,虽然都用 SingleReader 好像也行

I will investigate the difference and which one is better in this specific (UDP) case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants