BFD 与 BGP
BFD 与 BGP
基本配置
重要
必须配置并建立 BGP 邻居后,BFD 才能从 BGP 获取 BFD 邻居信息,从而发送 BFD 报文。
在 BGP 中开启 BFD。
config router bgp
config neighbor
edit <neighbor-IP-address>
set bfd {enable | disable}
next
end
end网络拓扑

- FW1 与 FW2 建立 IPv4 的 IBGP 邻居。
- BFD 检测失败时,重置 BGP 邻居。
配置步骤
基本网络配置(略)。
在 FW1 和 FW2 的 port2 上分别开启 BFD。
config system interface edit "port2" set bfd enable next end在 FW1 和 FW2 上分别配置 BGP,配置 BGP 邻居,宣告 IPv4 内网网段,在 BGP 邻居中开启 BFD。
FW1: config router bgp set as 10086 set router-id 192.168.12.1 config neighbor edit "192.168.12.2" set bfd enable set remote-as 10086 next end config network edit 1 set prefix 10.10.1.0 255.255.255.0 next end endFW2: config router bgp set as 10086 set router-id 192.168.12.2 config neighbor edit "192.168.12.1" set bfd enable set remote-as 10086 next end config network edit 1 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=08 ifi=4 type=SMFW1 # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc 192.168.12.1 192.168.12.2 UP port2 8/12在 FW1 上查看 BFD 相关日志与抓包(FW2 略),BFD 状态由 INIT 变为 UP。
date=2023-10-20 time=16:31:11 eventtime=1697790670835673328 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,49159,port2,8]: state INIT -> UP local_diag=0x00"
在 FW1 上查看 BGP 邻居与路由状态,邻居状态正常建立,BGP 路由学习正常。
FW1 # get router info bgp summary VRF 0 BGP router identifier 192.168.12.1, local AS number 10086 BGP table version is 2 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 192.168.12.2 4 10086 11 11 1 0 0 00:06:44 1 Total number of neighbors 1 FW1 # get router info routing-table bgp Routing table for VRF=0 B 10.10.2.0/24 [200/0] via 192.168.12.2 (recursive is directly connected, port2), 00:06:27, [1/0]模拟线路问题 10s(10s 后恢复)导致 BFD 中断,中断过程中查看 FW1 上 BFD 邻居消失(因为 BFD DOWN 后重置了 BGP 连接,BFD 邻居信息依赖于 BGP 已建立的邻居信息)。
FW1 # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc在 FW1 上查看 BFD 相关日志,BFD DOWN 后,对应的 BGP 邻居关系跟随 DOWN。local_diag = 0x01(表示 Control Detection Time Expired)。
date=2023-10-20 time=16:39:00 eventtime=1697791140142880643 tz="+0800" logid="0103020300" type="event" subtype="router" level="warning" vd="root" logdesc="BGP neighbor status changed" msg="BGP: %BGP-5-ADJCHANGE: VRF 0 neighbor 192.168.12.2 Down BFD Down; User reset added" date=2023-10-20 time=16:39:00 eventtime=1697791140142553520 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,49160,port2,9]: state UP -> DOWN local_diag=0x01"在 FW1 上查看 BGP 邻居状态,邻居断开,并开始重建 BGP 邻居。
FW1 # get router info bgp summary VRF 0 BGP router identifier 192.168.12.1, local AS number 10086 BGP table version is 3 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 192.168.12.2 4 10086 18 19 0 0 0 never Connect Total number of neighbors 1 FW1 # get router info bgp summary VRF 0 BGP router identifier 192.168.12.1, local AS number 10086 BGP table version is 3 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 192.168.12.2 4 10086 21 22 3 0 0 00:00:27 1 Total number of neighbors 1抓包查看 BFD DOWN 的报文,FW2 发现检测超时,向 FW1 发送 BFD Time Expired 报文,随后两端互相发送 Admin DOWN 的 BFD 控制报文,随后双向 BFD 字段中的 Diagnostic Code 为空,状态为 DOWN。

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

查看 FortiGate 的 BFD 邻居和 BGP 状态。BFD 邻居状态变为 DOWN,但开启 BFD 的 BGP 邻居没有重建。
FW1 # get router info bfd neighbor OurAddress NeighAddress State Interface LDesc/RDesc 192.168.12.1 192.168.12.2 DOWN port2 10/15 FW1 # get router info bgp summary VRF 0 BGP router identifier 192.168.12.1, local AS number 10086 BGP table version is 3 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 192.168.12.2 4 10086 30 31 3 0 0 00:08:37 1 Total number of neighbors 1FW1 上的相关 BFD 日志如下所示,BFD 邻居状态由 UP 变为 DOWN,local_diag = 0x23(表示 Remote peer indicates restarting),路由事件日志中没有 BGP 邻居断开的日志。
date=2023-10-20 time=16:47:15 eventtime=1697791635456872179 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,49161,port2,A]: state UP -> DOWN local_diag=0x23"
注意事项
- Admin 类型的 Down 不会导致 BGP 邻居重建。
- BFD Down 后触发了 BGP 邻居重建,如果 BFD 一直没有 UP,则重建后的 BGP 邻居不会受任何影响,除非再次发生了 BFD 从 UP 到 Down 的状态转换(静态路由不是这样)。