Skip to content

fix(tun): preserve Windows UDP process-bypass mappings - #61

Merged
acking-you merged 2 commits into
devfrom
fix/tun-udp-endpoint
Oct 28, 2026
Merged

acking-you merged 2 commits into
devfrom
fix/tun-udp-endpoint

Conversation

@acking-you

@acking-you acking-you commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Windows TUN 按进程绕过时,原先每个 UDP 目标分别创建物理 socket,导致同一应用源端点访问 STUN 与 P2P 对端时源端口不同。本 PR 引入按应用源端点复用的 UDP 映射,并更新实际行为与边界说明。

Closes #58

变更

  • 将 deps/tun2proxy 固定到已合并的 tun2proxy #15 默认分支提交 c403d02a697cfbd00690edab6c650cec8e8690c5。已确认 squash 提交的 tree 与通过验证的 PR 头 9457d20 完全一致。
  • 共享未连接 UDP socket,按已联系的真实对端分发回复并保留原始 Fake-IP。快照读取与应用串行化,只比较 owner 指纹的相等性;出口读取当前值,只按对应地址族接口索引判断是否需要重建。
  • 同步端点关闭与发送/回包注入,覆盖空闲映射的策略撤销;为原生表分配增长余量并按端口索引,临时查表失败保留现有映射最多 6 秒。
  • 去除 256-peer 上限,使用全局会话和排队预算;目标冲突或池容量不足时回退隔离 socket。禁用共享 socket 的 UDP ICMP reset 通知。
  • README 和 client-usage 说明归属歧义、时间戳碰撞、IPv6 wildcard、隔离回退、建立期间复核失败以及流超时后的入站限制。

兼容性

无加密线协议、C FFI ABI、Flutter 源码或依赖版本变化。仅 Windows 进程绕过的非 DNS 单播 UDP 使用共享映射;其他路径保持既有处理。

PID+绑定时间是尽力而为的指纹,同进程同端口快速重绑可能不可区分。初始归属不明确时使用原有隔离路径;建立期间归属变化或无法复核时拒绝新流,避免沿用不确定进程的绕过权限。物理映射可保留 120 秒,但回复仅投递到仍活跃的目标流。

验证

固定 Rust nightly-2026-10-26,Windows x64:

cargo test --manifest-path deps/tun2proxy/Cargo.toml --all-features
cargo clippy --manifest-path deps/tun2proxy/Cargo.toml --all-targets --all-features -- -D warnings
cargo fmt --manifest-path deps/tun2proxy/Cargo.toml -- --check
cargo clippy -p proxy-crypto -p proxy-core -p proxy-client -p proxy-server -p proxy-tui -p proxy-ffi --all-targets --all-features --no-deps -- -D warnings
cargo fmt -p proxy-crypto -p proxy-core -p proxy-client -p proxy-server -p proxy-tui -p proxy-ffi -- --check
cargo test --workspace
.\scripts\windows\stage-ui-native.ps1 -Configuration Debug
.\scripts\windows\build-ui-explicit-msvc.ps1 -Configuration Debug -VisualStudioPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools"
# from ui/flutter (FVM Flutter 3.47.8):
fvm flutter analyze --no-fatal-infos --no-pub
fvm flutter test --no-pub
  • 子模块:119 项通过、4 项忽略;17 项远程 CI 检查全部通过。
  • 主仓:286 项通过、6 项忽略;严格 Clippy 与格式检查通过。
  • Flutter:analyze 无问题,204 项通过、7 项跳过。
  • 9 个 UDP 池测试覆盖真实 Windows 归属与内存 TUN 转发、Fake-IP/空包/分片、300-peer fanout、不可达对端、时间回拨、出口变化、旧快照顺序、短暂失败、资源压力与空闲策略撤销。
  • Windows Debug bundle 完整,包含 http_proxy.dll、wintun.dll、Flutter 运行库、插件及辅助程序。构建、暂存及 bundle 中的原生 DLL SHA-256 一致:6649B08DF16CEC14781041046A0587EFA624B3C39D68833C4776CAFCD81E85AF。
  • 本机 Flutter 插件 symlink 无法用于 CMake,因此该次构建临时将生成的插件路径指向现有 Pub 缓存,构建后逐字节恢复;未提交生成文件或二进制产物。

手机公网 P2P 尚未复测;本机源端口稳定不代表所有 NAT 环境都能直连。

@acking-you
acking-you marked this pull request as ready for review October 28, 2026 16:16
@acking-you acking-you changed the title fix(tun): preserve Windows UDP bypass mappings for STUN/P2P fix(tun): preserve Windows UDP process-bypass mappings Oct 28, 2026
@acking-you
acking-you merged commit c85087f into dev Oct 28, 2026
3 checks passed
@acking-you
acking-you deleted the fix/tun-udp-endpoint branch October 28, 2026 16:40
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.

bug: Windows TUN 进程绕过按目标重建 UDP socket,破坏 IPv4 STUN/P2P 端口映射

1 participant