BFD 与静态路由
BFD 与静态路由
当静态路由开启 BFD 后,BFD 检测到 BFD 邻居故障时,BFD 会从路由表中删除静态路由,如果路由的目的地恢复,则 BFD 将路由在路由表中恢复。
举例:添加两条目的相同但下一跳不同的启用 BFD 的静态路由。如果其中一条路由具有较高优先级,则所有匹配流量都使用该路由。如果 BFD 检测到高优先级路由到网关的链路故障,则将高优先级路由从路由表中删除,所有匹配的流量都使用低优先级路由。如果较高优先级路由到网关的链路恢复正常,BFD 会将该路由重新添加到路由表中,所有匹配的流量都会切换为使用较高优先级路由。
FortiGate 的 BFD 同时支持 IPv4 和 IPv6 的静态路由。
基本配置
当 BFD 被静态路由引用时,需要通过配置 BFD 邻居来让 BFD 协议获取 BFD 邻居信息。
config router {bfd | bfd6}
config neighbor
edit <IP-address>
set interface <interface-name>
next
end
endconfig router {static | static6}
edit <sequence-number>
set bfd {enable | disable}
set device <gateway-out-interface>
next
end网络拓扑

- FortiGate 与 Router1 建立 OSPF 邻居,并重发布静态路由。
- FortiGate 与 Router2(ISP)之间使用静态路由,并开启 BFD,当 BFD 检测 UP 时,静态路由存在于 FortiGate 的路由表,会被重发布到 OSPF;当 BFD 检测 DOWN 时,删除 FortiGate 上开启 BFD 的静态路由,不会重分发到 OSPF。
- Router1 配置与 FortiGate 的 OSPF 邻居。(略)
配置步骤
配置网络接口 IP(略)。
配置 FortiGate 与 Router1 建立 OSPF 邻居,并重发布静态路由。
config router ospf set router-id 192.168.12.2 config area edit 0.0.0.0 next end config network edit 1 set prefix 192.168.12.0 255.255.255.0 next end config redistribute "static" set status enable end end在 FortiGate 的 port3 上开启 BFD,配置 BFD 邻居为 Router2(ISP),并配置静态路由,去往 ISP 的两条静态路由开启 BFD,去往内部网络的路由不开启 BFD。
config system interface edit "port3" set ip 192.168.13.2 255.255.255.0 set bfd enable next end config router bfd config neighbor edit 192.168.13.1 set interface "port3" next end end config router static edit 1 set dst 223.5.5.5 255.255.255.255 set gateway 192.168.13.1 set device "port3" set bfd enable next edit 2 set dst 114.114.114.114 255.255.255.255 set gateway 192.168.13.1 set device "port3" next edit 3 set dst 10.10.1.0 255.255.255.0 set gateway 192.168.12.1 set device "port2" next end
结果验证
在 Router2 还未配置 BFD 的状态下,查看 FortiGate 的 BFD 邻居和静态路由状态。BFD 邻居状态为 DOWN,开启 BFD 的静态路由未放入路由表,未开启 BFD 的静态路由被放入路由表。
重要
与动态路由(如 OSPF 和 BGP)不同,静态路由引用 BFD 时,静态路由是否放入路由表依赖于相关的 BFD 邻居状态,BFD 邻居状态为 UP 时将开启 BFD 的相关静态路由放入路由表,BFD 邻居状态为 DOWN 时将开启 BFD 的相关静态路由从路由表中移除(具体信息可见本章节最后的注意事项)。
FortiGate # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc 192.168.13.2 192.168.13.1 DOWN port3 1/1 FortiGate # get router info routing-table all Routing table for VRF=0 S 10.10.1.0/24 [10/0] via 192.168.12.1, port2, [1/0] S 114.114.114.114/32 [10/0] via 192.168.13.1, port3, [1/0] C 192.168.12.0/24 is directly connected, port2 C 192.168.13.0/24 is directly connected, port3在 Router2(ISP)上开启 BFD 功能后,再次查看 FortiGate 的 BFD 邻居和静态路由状态。BFD 邻居状态为 UP,开启 BFD 的静态路由被放入路由表。
FortiGate # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc 192.168.13.2 192.168.13.1 UP port3 1/1 FortiGate # get router info routing-table all Routing table for VRF=0 S 10.10.1.0/24 [10/0] via 192.168.12.1, port2, [1/0] S 114.114.114.114/32 [10/0] via 192.168.13.1, port3, [1/0] C 192.168.12.0/24 is directly connected, port2 C 192.168.13.0/24 is directly connected, port3 S 223.5.5.5/32 [10/0] via 192.168.13.1, port3, [1/0]FortiGate 上的相关 BFD 日志与抓包如下所示,BFD 邻居状态由 Init 变为 UP。
date=2023-10-19 time=11:28:21 eventtime=1697686101603684308 tz="+0800" logid="0103020304" type="event" subtype="router" level="warning" vd="root" logdesc="Routing log warning" msg="BFD: BFD session[192.168.13.2->192.168.13.1,49152,port3,1]: state INIT -> UP local_diag=0x00"
模拟 FortiGate 与 Router2 之间的线路异常,查看 FortiGate 的 BFD 邻居和静态路由状态。BFD 邻居状态为 DOWN,开启 BFD 的静态路由未放入路由表,未开启 BFD 的静态路由仍然存在于路由表。
FortiGate # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc 192.168.13.2 192.168.13.1 DOWN port3 1/1 FortiGate # get router info routing-table all Routing table for VRF=0 S 10.10.1.0/24 [10/0] via 192.168.12.1, port2, [1/0] S 114.114.114.114/32 [10/0] via 192.168.13.1, port3, [1/0] C 192.168.12.0/24 is directly connected, port2 C 192.168.13.0/24 is directly connected, port3FortiGate 上的相关 BFD 日志与抓包如下所示,BFD 邻居状态由 UP 变为 DWON,local_diag = 0x01(表示 Control Detection Time Expired)。
date=2023-10-19 time=15:06:50 eventtime=1697699210346884501 tz="+0800" logid="0103020304" type="event" subtype="router" level="warning" vd="root" logdesc="Routing log warning" msg="BFD: BFD session[192.168.13.2->192.168.13.1,49152,port3,1]: state UP -> DOWN local_diag=0x01"
恢复 FortiGate 与 Router2 之间的线路,查看 FortiGate 的 BFD 邻居和静态路由状态。BFD 邻居状态变为 UP,开启 BFD 的静态路由被放入路由表。
FortiGate # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc 192.168.13.2 192.168.13.1 UP port3 1/1 FortiGate # get router info routing-table all Routing table for VRF=0 S 10.10.1.0/24 [10/0] via 192.168.12.1, port2, [1/0] S 114.114.114.114/32 [10/0] via 192.168.13.1, port3, [1/0] C 192.168.12.0/24 is directly connected, port2 C 192.168.13.0/24 is directly connected, port3 S 223.5.5.5/32 [10/0] via 192.168.13.1, port3, [1/0]FortiGate 上的相关 BFD 日志与抓包如下所示,BFD 邻居状态由 INIT 变为 UP。
date=2023-10-19 time=15:54:03 eventtime=1697702043275319216 tz="+0800" logid="0103020304" type="event" subtype="router" level="warning" vd="root" logdesc="Routing log warning" msg="BFD: BFD session[192.168.13.2->192.168.13.1,49152,port3,1]: state INIT -> UP local_diag=0x00"
关闭 Router2(由 FortiGate 模拟)的 BFD 功能,Router2 会向 FortiGate 发送 Administratively Down 类型的 BFD 通知。

查看 FortiGate 的 BFD 邻居和静态路由状态。BFD 邻居状态变为 DOWN,但开启 BFD 的静态路由没有从路由表中移除。
FortiGate # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc 192.168.13.2 192.168.13.1 DOWN port3 1/1 FortiGate # get router info routing-table all Routing table for VRF=0 S 10.10.1.0/24 [10/0] via 192.168.12.1, port2, [1/0] S 114.114.114.114/32 [10/0] via 192.168.13.1, port3, [1/0] C 192.168.12.0/24 is directly connected, port2 C 192.168.13.0/24 is directly connected, port3 C 192.168.100.0/24 is directly connected, port1 S 223.5.5.5/32 [10/0] via 192.168.13.1, port3, [1/0]FortiGate 上的相关 BFD 日志与抓包如下所示,BFD 邻居状态由 UP 变为 DOWN,local_diag = 0x23(表示 Remote peer indicates restarting)。
date=2023-10-19 time=16:45:50 eventtime=1697705150213670782 tz="+0800" logid="0103020304" type="event" subtype="router" level="warning" vd="root" logdesc="Routing log warning" msg="BFD: BFD session[192.168.13.2->192.168.13.1,49152,port3,1]: state UP -> DOWN local_diag=0x23"注意事项
- 与动态路由协议(如 OSPF 和 BGP)不同,静态路由没有对等体邻居发现的方法。因此,当配置了 BFD 时,静态路由网关的可达性完全取决于指定邻居的 BFD 会话的状态。
- 当 BFD 邻居状态为 DOWN,就认为静态路由的网关不可达,相关静态路由不会被安装在路由表中(不需要 BFD 邻居状态有一个从 UP → DOWN 的过程)。
- 当 BFD 邻居状态为 UP,就认为静态路由的网关可达,相关静态路由会被安装在路由表中。
- 这是为了防止在 FortiGate 在 HA 环境下,BFD 邻居状态为 DOWN 时,主备切换后,新主机将原主机已经从路由表中移除的静态路由错误地放入路由表。
- 由于以上 BFD 与静态路由之间的特性,
- 对于动态路由(如 OSPF 和 BGP),BFD 必须要有一个从 UP → DOWN 的状态转换,才会执行邻居关系的重置。
- 当开启 BFD 的静态路由已经放入路由表后,邻居不是因为链路故障 DOWN,。