Juniper Junos FIB-Filter 实战:精细控制向硬件转发表安装的 BGP 路由

通常情况下,交换机将控制平面(RIB)优选的路由直接下发至硬件转发表(FIB)是合理且必需的。然而在实际 IDC 与运营商接入场景中,往往会遇到这样的矛盾:下游客户需要接收完整的 BGP 路由表(Full Table),但接入层的 L3 交换机硬件 TCAM/FIB 容量却无法容纳全表。

如果为了避开交换机而让客户直接跨越交换机建立多跳 BGP 会话,一旦流量回传经过该交换机就极易引发路由环路或黑洞。此时最优雅的解法,是在 Juniper 交换机上使用 FIB-Filter(forwarding-table export 策略)——控制平面 inet.0 正常收发全部 BGP 路由,仅将默认路由与客户自身路由写入硬件 FIB。

实验拓扑与 RIB/FIB 过滤架构

Juniper vQFX FIB-Filter 实验拓扑与 RIB/FIB 过滤流水线:CSR AS 65533 向 vQFX-RE AS 65534 通告默认路由与 10.10-10.14/32,Customer AS 65532 通告 192.168.192.168/32,fib-policy 仅允许默认路由和客户路由下发至 PFE 硬件 FIB
图 1:Juniper vQFX(AS 65534)FIB-Filter 实验拓扑与控制面 RIB(inet.0)→ 数据面 FIB(default.inet)策略过滤流程

实验核心需求

  • 保护交换机硬件 FIB:vQFX FIB 容量有限,禁止安装上游 CSR(AS 65533)发来的明细路由(10.10.10.10/32 ~ 10.14.14.14/32),仅保留默认路由 0.0.0.0/0;
  • 保留 BGP 路由透传能力:vQFX 仍需在控制面完整接收上游路由并正常通告给下游 Customer 路由器(AS 65532);
  • 防止回程环路:vQFX 必须把 Customer 通告的客户路由(192.168.192.168/32)安装进硬件 FIB,确保去往客户网段的流量精确送达下游而非匹配默认路由指回上游。

配置前基线检查:未过滤时的 RIB 与硬件 FIB

基础 ASN 与接口 IP 配置完成后,先查看未启用 FIB-Filter 时 vqfx-re 的 BGP 路由表(inet.0)、硬件转发表(default.inet)以及下游客户接收情况:

root@vqfx-re> show route protocol bgp

inet.0: 13 destinations, 13 routes (13 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

0.0.0.0/0          *[BGP/170] 00:00:49, localpref 100
                      AS path: 65533 I, validation-state: unverified
                    > to 192.1.2.1 via xe-0/0/2.0
10.10.10.10/32     *[BGP/170] 00:02:58, MED 0, localpref 100
                      AS path: 65533 I, validation-state: unverified
                    > to 192.1.2.1 via xe-0/0/2.0
10.11.11.11/32     *[BGP/170] 00:02:29, MED 0, localpref 100
                      AS path: 65533 I, validation-state: unverified
                    > to 192.1.2.1 via xe-0/0/2.0
10.12.12.12/32     *[BGP/170] 00:02:29, MED 0, localpref 100
                      AS path: 65533 I, validation-state: unverified
                    > to 192.1.2.1 via xe-0/0/2.0
10.13.13.13/32     *[BGP/170] 00:02:29, MED 0, localpref 100
                      AS path: 65533 I, validation-state: unverified
                    > to 192.1.2.1 via xe-0/0/2.0
10.14.14.14/32     *[BGP/170] 00:01:58, MED 0, localpref 100
                      AS path: 65533 I, validation-state: unverified
                    > to 192.1.2.1 via xe-0/0/2.0
192.168.192.168/32 *[BGP/170] 00:00:17, MED 0, localpref 100
                      AS path: 65532 I, validation-state: unverified
                    > to 192.0.1.2 via irb.1

root@vqfx-re> show route forwarding-table table default family inet
Routing table: default.inet
Internet:
Destination        Type RtRef Next hop           Type Index    NhRef Netif
default            user     0 50:0:0:1:0:1       ucst     1720     9 xe-0/0/2.0
default            perm     0                    rjct       51     1
0.0.0.0/32         perm     0                    dscd       49     1
10.10.10.10/32     user     0 192.1.2.1          ucst     1720     9 xe-0/0/2.0
10.11.11.11/32     user     0 192.1.2.1          ucst     1720     9 xe-0/0/2.0
10.12.12.12/32     user     0 192.1.2.1          ucst     1720     9 xe-0/0/2.0
10.13.13.13/32     user     0 192.1.2.1          ucst     1720     9 xe-0/0/2.0
10.14.14.14/32     user     0 192.1.2.1          ucst     1720     9 xe-0/0/2.0
169.254.0.0/24     intf     0                    rslv      323     1 em1.0
169.254.0.0/32     dest     0 169.254.0.0        recv      321     1 em1.0
169.254.0.1/32     dest     1 50:0:0:4:0:1       ucst      336     2 em1.0
169.254.0.2/32     intf     0 169.254.0.2        locl      322     2
169.254.0.2/32     dest     0 169.254.0.2        locl      322     2
169.254.0.255/32   dest     0 169.254.0.255      bcst      320     1 em1.0
192.0.1.0/24       intf     0                    rslv     1710     1 irb.1
192.0.1.0/32       dest     0 192.0.1.0          recv     1708     1 irb.1
192.0.1.1/32       intf     0 192.0.1.1          locl     1709     2
192.0.1.1/32       dest     0 192.0.1.1          locl     1709     2
192.0.1.2/32       dest     1 50:0:0:5:0:0       ucst     1719     4 xe-0/0/1.0
192.0.1.255/32     dest     0 192.0.1.255        bcst     1707     1 irb.1
192.1.2.0/24       intf     0                    rslv     1715     1 xe-0/0/2.0
192.1.2.0/32       dest     0 192.1.2.0          recv     1713     1 xe-0/0/2.0
192.1.2.1/32       dest     1 50:0:0:1:0:1       ucst     1720     9 xe-0/0/2.0
192.1.2.2/32       intf     0 192.1.2.2          locl     1714     2
192.1.2.2/32       dest     0 192.1.2.2          locl     1714     2
192.1.2.255/32     dest     0 192.1.2.255        bcst     1712     1 xe-0/0/2.0
192.168.192.168/32 user     0 192.0.1.2          ucst     1719     4 xe-0/0/1.0
224.0.0.0/4        perm     0                    mdsc       50     1
224.0.0.1/32       perm     0 224.0.0.1          mcst       46     1
255.255.255.255/32 perm     0                    bcst       47     1
customer#show ip b


     Network          Next Hop            Metric LocPrf Weight Path
 *>   0.0.0.0          192.0.1.1                              0 65534 65533 i
 *>   10.10.10.10/32   192.0.1.1                              0 65534 65533 i
 *>   10.11.11.11/32   192.0.1.1                              0 65534 65533 i
 *>   10.12.12.12/32   192.0.1.1                              0 65534 65533 i
 *>   10.13.13.13/32   192.0.1.1                              0 65534 65533 i
 *>   10.14.14.14/32   192.0.1.1                              0 65534 65533 i
 *>   192.168.192.168/32
                      0.0.0.0                  0         32768 i

upstream#ping 192.168.192.168 source 10.10.10.10
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.192.168, timeout is 2 seconds:
Packet sent with a source address of 10.10.10.10
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 24/49/101 ms

可以看到,未配置过滤前上游的 10.10.10.10/32 ~ 10.14.14.14/32 已全部被写入 vQFX 的硬件转发表;在真实互联网全表环境下,这会直接撑爆交换机 FIB 并引发硬件不稳定甚至宕机。

配置 Junos FIB-Filter(Community 标记 + Forwarding-Table Export)

配置思路非常清晰:先通过 BGP import 策略为客户路由打上专属社区属性 customer,再在 routing-options forwarding-table 下挂载 export fib-policy,只放行 0.0.0.0/0 exact 与携带 customer Community 的 BGP 路由,其余外部路由一律拒绝下发至 FIB:

root@vqfx-re> show policy-options policy-statement customer-import
term customer-community-tag {
    then {
        community add customer;
        accept;
    }
}
// 定义收到的路由的community,将客户的路由打上 "customer" 社区属性。

root@vqfx-re> show policy-options policy-statement fib-policy
term default {
    from {
        route-filter 0.0.0.0/0 exact;
    }
    then accept;
}
term customer {
    from {
        protocol bgp;
        community customer;
    }
    then accept;
}
term last {
    then reject;
}
// 定义 FIB filter 规则,只接受默认路由,以及通过 BGP 发过来的客户路由。将这些路由安装进入转发表,其他路由拒绝。

root@vqfx-re> show configuration protocols bgp group external neighbor 192.0.1.2
import customer-import;
export accept-all;
peer-as 65532;
// 在 session 上应用上面写好的 import policy,为客户的路由打上社区属性。

root@vqfx-re> show configuration routing-options forwarding-table
export fib-policy;
// 为 FIB 配置 export filter

过滤后验证:FIB 瘦身与 BGP 全表透传均正常

提交配置后,再次查看 vQFX 的硬件转发表 default.inet,可以看到 10.10.10.10/32 ~ 10.14.14.14/32 已彻底从硬件 FIB 中剔除,仅保留了默认路由 default、直连/接口路由以及客户路由 192.168.192.168/32:

root@vqfx-re> show route forwarding-table table default family inet
Routing table: default.inet
Internet:
Destination        Type RtRef Next hop           Type Index    NhRef Netif
default            user     0 50:0:0:1:0:1       ucst     1720     4 xe-0/0/2.0
default            perm     0                    rjct       51     1
0.0.0.0/32         perm     0                    dscd       49     1
169.254.0.0/24     intf     0                    rslv      323     1 em1.0
169.254.0.0/32     dest     0 169.254.0.0        recv      321     1 em1.0
169.254.0.1/32     dest     1 50:0:0:4:0:1       ucst      336     2 em1.0
169.254.0.2/32     intf     0 169.254.0.2        locl      322     2
169.254.0.2/32     dest     0 169.254.0.2        locl      322     2
169.254.0.255/32   dest     0 169.254.0.255      bcst      320     1 em1.0
192.0.1.0/24       intf     0                    rslv     1710     1 irb.1
192.0.1.0/32       dest     0 192.0.1.0          recv     1708     1 irb.1
192.0.1.1/32       intf     0 192.0.1.1          locl     1709     2
192.0.1.1/32       dest     0 192.0.1.1          locl     1709     2
192.0.1.2/32       dest     1 50:0:0:5:0:0       ucst     1719     4 xe-0/0/1.0
192.0.1.255/32     dest     0 192.0.1.255        bcst     1707     1 irb.1
192.1.2.0/24       intf     0                    rslv     1715     1 xe-0/0/2.0
192.1.2.0/32       dest     0 192.1.2.0          recv     1713     1 xe-0/0/2.0
192.1.2.1/32       dest     1 50:0:0:1:0:1       ucst     1720     4 xe-0/0/2.0
192.1.2.2/32       intf     0 192.1.2.2          locl     1714     2
192.1.2.2/32       dest     0 192.1.2.2          locl     1714     2
192.1.2.255/32     dest     0 192.1.2.255        bcst     1712     1 xe-0/0/2.0
192.168.192.168/32 user     0 192.0.1.2          ucst     1719     4 xe-0/0/1.0
224.0.0.0/4        perm     0                    mdsc       50     1
224.0.0.1/32       perm     0 224.0.0.1          mcst       46     1
255.255.255.255/32 perm     0                    bcst       47     1

同时检查下游客户路由器接收的 BGP 表与端到端业务 ping 测试:

customer#show ip bgp

     Network          Next Hop            Metric LocPrf Weight Path
 *>   0.0.0.0          192.0.1.1                              0 65534 65533 i
 *>   10.10.10.10/32   192.0.1.1                              0 65534 65533 i
 *>   10.11.11.11/32   192.0.1.1                              0 65534 65533 i
 *>   10.12.12.12/32   192.0.1.1                              0 65534 65533 i
 *>   10.13.13.13/32   192.0.1.1                              0 65534 65533 i
 *>   10.14.14.14/32   192.0.1.1                              0 65534 65533 i
 *>   192.168.192.168/32
                      0.0.0.0                  0         32768 i

customer#ping 10.10.10.10 source 192.168.192.168
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.10.10.10, timeout is 2 seconds:
Packet sent with a source address of 192.168.192.168
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 21/32/67 ms
customer#

核心原理总结

  • 本地直连与接口路由豁免:Junos forwarding-table export 策略仅过滤从 RIB(如 inet.0)向 PFE 转发表下发的路由,不会影响设备本地自动生成的直连(intf)、接收(dest)及管理接口路由;
  • 不影响 BGP 路由反射与对外通告:因为 BGP 始终基于 RIB 中的最优路径(Active Best Route)执行 export 策略通告给邻居,所以即使明细路由被拦截在 FIB 之外,下游客户依然能完整拿到全表,且数据面通过默认路由无环直达上游。

Leave a Comment

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。