BFD 与 OSPF
BFD 与 OSPF
基本配置
重要
必须配置并建立 OSPF 邻居后,BFD 才能从 OSPF 获取 BFD 邻居信息,从而发送 BFD 报文。
在 OPSF 中开启 BFD。
config router {ospf | ospf6} set bfd {enable | disable} end也可以在特定的 OSPF 接口下开启 BFD。
config router {ospf | ospf6} set bfd enable config {ospf-interface | ospf6-interface} edit <ID> set bfd {global | enable | disable} set area-id <IP address> next end end- global:继承 config router ospf/ospf6 下的 BFD 开关配置(注意不是继承 config system setting 下的 BFD 开关配置)。
- enable:仅在此接口下开启 BFD,覆盖 config router ospf/ospf6 下的 BFD 开关配置。
- disable:在此接口下关闭 BFD,覆盖 config router ospf/ospf6 下的 BFD 开关配置。
网络拓扑

- FW1 与 FW2 建立 IPv4 的 OSPF 邻居。
- BFD 检测失败时,重置 OSPF 邻居。
配置步骤
基本网络配置(略)。
在 FW1 和 FW2 的 port2 上分别开启 BFD。
config system interface edit "port2" set bfd enable next end在 FW1 和 FW2 上分别配置 OSPF,配置 OSPF 邻居,宣告 IPv4 内网网段,在 OSPF 接口 port2 上开启 BFD。
FW1: config router ospf set router-id 192.168.12.1 config area edit 0.0.0.0 next end config ospf-interface edit "port2" set interface "port2" set bfd enable next end config network edit 1 set prefix 192.168.12.0 255.255.255.0 next edit 2 set prefix 10.10.1.0 255.255.255.0 next end endFW2: config router ospf set router-id 192.168.12.2 config area edit 0.0.0.0 next end config ospf-interface edit "port2" set interface "port2" set bfd enable next end config network edit 1 set prefix 192.168.12.0 255.255.255.0 next edit 2 set prefix 10.10.2.0 255.255.255.0 next end end
结果验证
在 FW1 上查看 BFD 邻居状态均为 UP(FW2 略)。
FW1 # get router info bfd requests BFD Peer Requests: client types(ct in 0x): 01=external 02=static 04=ospf 08=bgp 10=pim-sm src=192.168.12.1 dst=192.168.12.2 ct=04 ifi=4 type=SFW1 # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc 192.168.12.1 192.168.12.2 UP port2 1/4在 FW1 上查看 BFD 相关日志与抓包(FW2 略),BFD 状态由 INIT 变为 UP。
date=2023-10-20 time=15:45:27 eventtime=1697787926746001101 tz="+0800" logid="0103020304" type="event" subtype="router" level="warning" vd="root" logdesc="Routing log warning" msg="BFD: BFD session[192.168.12.1->192.168.12.2,49152,port2,1]: state DOWN -> UP local_diag=0x00"
在 FW1 上查看 OSPF 邻居与路由状态,邻居状态正常建立,OSPF 路由学习正常。
FW1 # get router info ospf neighbor OSPF process 0, VRF 0: Neighbor ID Pri State Dead Time Address Interface 192.168.12.2 1 Full/DR 00:00:31 192.168.12.2 port2 FW1 # get router info routing-table ospf Routing table for VRF=0 O 10.10.2.0/24 [110/2] via 192.168.12.2, port2, 00:02:50, [1/0]模拟线路问题 10s(10s 后恢复)导致 BFD 中断,查看 FW1 上 BFD 邻居消失(因为 BFD DOWN 后重置了 OSPF 连接,BFD 邻居信息依赖于 OSPF 已建立的邻居信息)。
FW1 # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc在 FW1 上查看 BFD 相关日志,BFD DOWN 后,对应的 OSPF 邻居关系跟随 DOWN。local_diag = 0x01(表示 Control Detection Time Expired)。
date=2023-10-20 time=16:06:30 eventtime=1697789190283253338 tz="+0800" logid="0103020302" type="event" subtype="router" level="warning" vd="root" logdesc="OSPF neighbor status changed" msg="OSPF: %OSPF-5-ADJCHANGE: neighbor port2:192.168.12.1-192.168.12.2 Down " date=2023-10-20 time=16:06:30 eventtime=1697789190282633679 tz="+0800" logid="0103020304" type="event" subtype="router" level="warning" vd="root" logdesc="Routing log warning" msg="BFD: BFD session[192.168.12.1->192.168.12.2,49156,port2,5]: state UP -> DOWN local_diag=0x01"在 FW1 上查看 OSPF 邻居状态,邻居断开,并开始重建 OSPF 邻居。
FW1 # get router info ospf neighbor OSPF process 0, VRF 0: Neighbor ID Pri State Dead Time Address Interface 192.168.12.2 1 Init/DROther 00:00:39 192.168.12.2 port2 FW1 # get router info ospf neighbor OSPF process 0, VRF 0: Neighbor ID Pri State Dead Time Address Interface 192.168.12.2 1 Full/Backup 00:00:37 192.168.12.2 port2抓包查看 BFD DOWN 的报文,FW2 发现检测超时,向 FW1 发送 BFD Time Expired 报文,随后两端互相发送 Admin DOWN 的 BFD 控制报文,随后双向 BFD 字段中的 Diagnostic Code 为空,状态为 DOWN。

关闭 FW2(由 FortiGate 模拟)的 BFD 功能,FW2 会向 FW1 发送 Administratively Down 类型的 BFD 通知。

查看 FortiGate 的 BFD 邻居和 OSPF 状态。BFD 邻居状态变为 DOWN,但开启 BFD 的 OSPF 邻居没有重建。
FW1 # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc 192.168.12.1 192.168.12.2 DOWN port2 7/11 FW1 # get router info ospf neighbor OSPF process 0, VRF 0: Neighbor ID Pri State Dead Time Address Interface 192.168.12.2 1 Full/DR 00:00:35 192.168.12.2 port2FW1 上的相关 BFD 日志如下所示,BFD 邻居状态由 UP 变为 DOWN,local_diag = 0x23(表示 Remote peer indicates restarting),路由事件日志中没有 OSPF 邻居断开的日志。
date=2023-10-20 time=16:15:15 eventtime=1697789715008917984 tz="+0800" logid="0103020304" type="event" subtype="router" level="warning" vd="root" logdesc="Routing log warning" msg="BFD: BFD session[192.168.12.1->192.168.12.2,49158,port2,7]: state UP -> DOWN local_diag=0x23"注意事项
- Admin 类型的 Down 不会导致 OSPF 邻居重建。
- BFD Down 后触发了 OSPF 邻居重建,如果 BFD 一直没有 UP,则重建后的 OSPF 邻居不会受任何影响,除非再次发生了 BFD 从 UP 到 Down 的状态转换(静态路由不是这样)。