IPSec over TCP 回包异步
IPSec over TCP 回包异步
问题现象
双 WAN 或 SD-WAN Underlay 场景中,如果 IPSec 隧道使用 TCP 传输,IKE TCP 握手可能出现入接口与回包出接口不一致,导致 IPSec over TCP 隧道无法正常建立。
典型现象如下:
FortiGate 有两条 WAN 线路,并将
wan1、wan2加入 SD-WAN。config system sdwan set status enable config zone edit "Underlay" next end config members edit 1 set interface "wan1" set zone "Underlay" set gateway 203.0.113.1 next edit 2 set interface "wan2" set zone "Underlay" set gateway 198.51.100.1 next end end两条 IPSec 隧道分别绑定到不同 WAN 接口,并启用 TCP 传输。
config vpn ipsec phase1-interface edit "to_peer_wan1" set interface "wan1" set ike-version 2 set peertype any set remote-gw 192.0.2.10 set localid "wan1" set transport tcp set network-overlay enable set network-id 1 set psksecret <password> next edit "to_peer_wan2" set interface "wan2" set ike-version 2 set peertype any set remote-gw 192.0.2.10 set localid "wan2" set transport tcp set network-overlay enable set network-id 2 set psksecret <password> next end抓包可以看到,对端发往
wan1地址的 TCPSYN从wan1进入 FortiGate,但 FortiGate 返回的SYN/ACK从wan2发出。# diagnose sniffer packet any "host 192.0.2.10 and tcp port 443" 4 0 l 2025-06-23 03:05:11.766062 wan1 in 192.0.2.10.51717 -> 203.0.113.2.443: syn 164043747 2025-06-23 03:05:11.766215 wan2 out 203.0.113.2.443 -> 192.0.2.10.51717: syn 3416450666 ack 164043748 2025-06-23 03:05:12.780219 wan1 in 192.0.2.10.51717 -> 203.0.113.2.443: syn 164043747 2025-06-23 03:05:12.780281 wan2 out 203.0.113.2.443 -> 192.0.2.10.51717: syn 3416450666 ack 164043748相关信息
示例中使用 TCP 443,实际排查时请替换为当前 VDOM 的
ike-tcp-port。该问题在使用其他ike-tcp-port时也可能出现。
问题原因
在受影响版本中,IPSec over TCP 的本机回包可能没有按收到 TCP 握手的父接口返回,而是重新经过路由或 SD-WAN 选路。双 WAN、等价默认路由或 SD-WAN 成员选择场景下,回包可能被选到另一条 WAN 线路,TCP 三次握手无法完成,IKE over TCP 隧道也无法继续协商。
该问题属于 IKE TCP 协商阶段的回包路径异常,不是普通 IPSec 业务流量的 ESP 分流或健康检查选路问题。
Fortinet 已将该行为归入工程案例 1172040,并在 FortiOS 7.4.9、7.6.4、8.0.0 及之后版本中修复。
解决方法
升级到修复版本
优先升级到 FortiOS 7.4.9、7.6.4、8.0.0 或之后版本。升级后通常不需要针对该问题额外配置策略路由。
临时规避方法
在无法立即升级的版本中,可以为 IPSec over TCP 使用的本地 WAN 源地址创建策略路由,并启用 ike-policy-route,让 IKE 本机流量检查策略路由。
为每个 IPSec over TCP 绑定的父接口配置策略路由,强制对应源地址从原父接口返回。
config router policy edit 1 set src "203.0.113.2/255.255.255.252" set output-device "wan1" next edit 2 set src "198.51.100.2/255.255.255.252" set output-device "wan2" next end提示
上述示例保留了 Fortinet 原始规避思路中的关键条件:使用 WAN 本地地址作为源地址,并将出接口指定为对应父接口。生产环境中,如果当前 FortiOS 版本的
config router policy支持更细的匹配条件,可以按对端地址、TCP 协议和ike-tcp-port进一步收窄匹配范围。启用
ike-policy-route。config system settings set ike-policy-route enable end相关信息
ike-policy-route的作用和注意事项可参考 VPN → IPSec VPN → IKE 流量启用策略路由章节。如已存在旧的 IKE TCP 会话,建议在维护窗口内清理相关会话或重启对应隧道,再重新测试协商。
diagnose sys session filter clear diagnose sys session filter src 203.0.113.2 diagnose sys session filter dst 192.0.2.10 diagnose sys session filter dport 443 diagnose sys session clear diagnose sys session filter clear
结果验证
确认策略路由已经生成,并且没有被 link-monitor 或 SD-WAN 健康检查置为不可用状态。
diagnose firewall proute list重新发起 IPSec over TCP 协商,抓包确认 TCP
SYN与SYN/ACK使用同一条 WAN 线路。diagnose sniffer packet any "host 192.0.2.10 and tcp port 443" 4 0 l相关信息
正常情况下,回包应从收到
SYN的同一父接口发出。2025-06-23 03:08:40.120011 wan1 in 192.0.2.10.51717 -> 203.0.113.2.443: syn 164043747 2025-06-23 03:08:40.120083 wan1 out 203.0.113.2.443 -> 192.0.2.10.51717: syn 3416450666 ack 164043748 2025-06-23 03:08:40.121004 wan1 in 192.0.2.10.51717 -> 203.0.113.2.443: ack 3416450667如果 FortiGate 同时配置了多个 IPSec over TCP 隧道,需要分别验证每个父接口的回包路径。
注意事项
ike-policy-route是全局配置,会影响 FortiGate 本机发出的 IKE 流量查找策略路由的行为,启用前需要确认当前 VDOM 内其他 IPSec 隧道是否依赖默认路由行为。该规避方法只用于修正 IKE TCP 协商回包路径,不用于控制 IPSec 隧道内业务流量的 SD-WAN 选路。
如果一阶段使用
set transport auto,当 UDP 连接失败并回退到 TCP 传输时,也需要关注 TCP 传输阶段是否存在相同的回包异步现象。