Repository navigation
fix: support IPv6-disabled Windows (error 1168) - #215
Conversation
Three fixes for machines with IPv6 disabled via DisabledComponents=0xFFFFFFFF: 1. Move metric(1) from builder to post-build: tun-rs set_interface_metric iterates AF_INET then AF_INET6; GetIpInterfaceEntry(AF_INET6) returns ERROR_NOT_FOUND(1168) when IPv6 is disabled, failing the entire build_async(). Now set_metric is called after build, ignoring IPv6 errors. 2. Make virtual IPv6 optional: add_address_v6 and VirtualIpv6Routes fail with 1168 on IPv6-disabled machines. Added ipv6_unavailable flag to DeviceState; first failure sets the flag and skips all subsequent IPv6 configuration with a warning, without blocking IPv4 networking. 3. Increase start timeout from 30s to 120s: hardened enterprise machines with multiple NDIS filter drivers (ESET, Sangfor VPN, etc.) can take 30-45s for Wintun PnP install + filter binding. The old 30s limit killed successfully-completed startups. Added a progress log line.
|
测试用例没有改,可以改一下吗 |
ErrorKind::AddrNotAvailable maps to EADDRNOTAVAIL, not EAFNOSUPPORT, so the previous Unix check missed the intended error and matched an unrelated one. Use libc::EAFNOSUPPORT for the platform value and cover both Windows and Unix branches with unit tests.
|
感谢 review。已补充 关于 Linux/macOS CI 上失败的 4 个测试( 想请您确认倾向哪种处理方式: |
问题
Windows 系统通过
DisabledComponents = 0xFFFFFFFF完全禁用 IPv6 时(企业安全基线常见),VNT Desktop 的 TUN/TAP 模式 100% 复现创建 TUN 失败: 找不到元素 (os error 1168),导致组网无法启动。根因
IPv6 被禁用后,新建的 Wintun 网卡没有 IPv6 的 IP 接口行(
GetIpInterfaceEntry(AF_INET6)返回ERROR_NOT_FOUND)。VNT 有三处硬依赖 IPv6 可用:builder.metric(1):tun-rs 2.8.12 的set_interface_metric()遍历[AF_INET, AF_INET6],IPv6 的GetIpInterfaceEntry失败即?返回错误,导致整个build_async()失败。虚拟 IPv6 地址/路由:
set_network()调用add_address_v6()和VirtualIpv6Routes::apply(),CreateUnicastIpAddressEntry在没有 IPv6 接口行时返回 1168。30 秒启动超时:加固企业机器上 Wintun PnP 安装 + NDIS 过滤器绑定实测可达 30~45 秒,30 秒上限会把"刚好完成"的启动误杀。
修复
1. metric 从 build 阶段移到建卡后(
vnt-core/src/tun/general.rs)删除
builder.metric(1),改为建卡后调用dev.set_metric(1),失败只记 debug 日志。IPv4 跃点仍然生效(tun-rs 先处理 AF_INET),IPv6 不可用时忽略错误。与同函数中set_mtu的处理风格一致。2. 虚拟 IPv6 视为可选增强(
vnt-core/src/tun/general.rs)DeviceState新增ipv6_unavailable: bool,首次add_address_v6失败时置位is_ipv6_unavailable()判断错误码:Windows 用raw_os_error(1168/50/10047),Unix 用ErrorKind::AddrNotAvailable设置虚拟IPv6失败,不掩盖真实故障3. 启动超时从 30s 放宽到 120s(
vnt-web/src/service_http.rs)提取
START_READY_TIMEOUT常量,从 30 秒放宽到 120 秒,保留上限防止真卡死。建卡前补一条进度日志"等待注册并创建虚拟网卡"。实测验证
修复后在故障机器(Windows 11 24H2, IPv6 完全禁用)上验证:
建议上游修复 tun-rs
tun-rs的set_interface_metric在某个地址族不存在时不应让整个 metric 设置失败:改动范围
vnt-core/src/tun/general.rs:+79/−32vnt-web/src/service_http.rs:+13/−1不改动配置格式、IPC 协议、错误文案,无兼容性影响。启用 IPv6 的机器行为完全不变。