Skip to content

tun inbound 中的 udp_timeout timer 在收到远端入站(tun 发出)包时未被正确重置 #3817

@asbai

Description

@asbai

操作系统

Linux

系统版本

6.6.73 #0 SMP Mon Feb 3 23:09:37 2025 mips GNU/Linux

安装类型

sing-box 原始命令行程序

如果您使用图形客户端程序,请提供该程序版本。

No response

版本

sing-box version
sing-box version 1.12.22

Environment: go1.25.7 linux/mipsle
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale
Revision: f63091d14d8984d53dc9a5563cb72af978b9779e
CGO: disabled

描述

tun inbound 中的 udp_timeout timer 只对从本机发出(进入 tun)的 UDP 包重置。相反,在收到远端入站(tun 发出)包时未被正确重置。

这导致执行 iperf3 -c .... -u -t 0 -R 等只有 UDP 回包,本机不向外发包的场景下, UDP NAT 条目错误地过期。

重现方式

  1. 部署一个最简环境,客户端:
{
  "log": {
    "level": "warn",
    "timestamp": true
  },
  "inbounds": [
    {
      "type": "redirect",
      "tag": "tcp-in",
      "listen": "0.0.0.0",
      "listen_port": 1800,
      "sniff": false
    },
    {
      "type": "tun",
      "tag": "tun-in",
      "interface_name": "tun0",
      "address": ["198.18.0.1/30"],
      "stack": "system",
      "auto_route": false,
      "strict_route": false,
      "sniff": false,
      "udp_timeout": "1m",
      "platform": {
        "http_proxy": {
          "enabled": false
        }
      }
    }
  ],
  "outbounds": [
    {
      "type": "vless",
      "tag": "proxy",
      "server": "....",
      "server_port": 1234,
      "uuid": "xxxx",
      "packet_encoding": "xudp"
    }
  ],
  "route": {
    "auto_detect_interface": true,
    "final": "proxy"
  }
}

并配置路由将希望的流量重定向到 tun。

server 端可以是任意 vless inbound + direct outbound daemon,比如 xray。

  1. server 端启动 iperf3

  2. client 端 iperf3 -c .... -u -t 0 (不加 -R),此时永不超时。

  3. client 端 加 -R iperf3 -c .... -u -t 0 -R 此时 80s(1.12.17)- 100s(1.12.22版)即超时。server 端 iperf3 返回:iperf3: error - unable to write to stream socket: Connection refused

  4. 调高客户端 tun inbound 中的 “udp_timeout” 配置,问题可明显缓解。例如:调整到 "5m",则至少 320s 后才会超时。

日志

支持我们

完整性要求

  • 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
  • 我保证提供了可以在本地重现该问题的服务器、客户端配置文件与流程,而不是一个脱敏的复杂客户端配置文件。
  • 我保证提供了可用于重现我报告的错误的最简配置,而不是依赖远程服务器、TUN、图形界面客户端或者其他闭源软件。
  • 我保证提供了完整的配置文件与日志,而不是出于对自身智力的自信而仅提供了部分认为有用的部分。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions