FRR BGP协议分析9 -- FLOW SPEC

Flowspec引入了一种新的NLRI 编码格式,用于分发流量规则流规范。基本上,IP前缀不是简单地依赖于IP前缀的目标IP地址,而是由包含规则的n元组替换。该规则可以是或多或少复杂的以下组合:

  • 网络源/目标(可以是一个或另一个,或两者)。
  • UDP / TCP的第4层信息:源端口,目标端口或任何端口。
  • ICMP类型和ICMP代码的第4层信息。
  • TCP标志的第4层信息。
  • 第3层信息:DSCP值,协议类型,数据包长度,分段。
  • 其他第4层TCP标志。

上述规则的组合适用于流量过滤。这被编码为特定BGP扩展社区的一部分,其行动可以从明显的重新路由(到nexthop或单独的VRF)到整形或丢弃。

 

12种match和action

 

BGP Flowspec NLRI Type

Matching Field (IPv6)

Matching Field (IPv4)

Input Value

Type1

IPv6 destination address

IPv4 destination address

Prefix length

Type2

IPv6 source address

IPv4 source address

Prefix length

Type3

IPv6 next header

IPv4 protocol

Multi-value range

Type4

IPv6 source or destination port

IPv4 source or destination port

Multi-value range

Type5

IPv6 destination port

IPv4 destination port

Multi-value range

Type6

IPv6 source port

IPv4 source port

Multi-value range

Type7

IPv6 ICMP type

IPv4 ICMP type

Multi-value range

Type8

IPv6 ICMP code

IPv4 ICMP code

Multi-value range

Type9

IPv6 TCP flags

IPv4 TCP flags (2 bytes include reserved bits)

Bit mask

Type10

IPv6 packet length

IPv4 packet length

Multi-value range

Type11

IPv6 traffic class

IPv4 DSCP

Multi-value range

Type12

Reserved

IPv4 fragment bits

Bit mask

 

Type 1: Destination prefix component

https://i-blog.csdnimg.cn/blog_migrate/a7ac3c16dda73809b92e8ff7ca7ec1e7.png

Type 2: Source prefix component

https://i-blog.csdnimg.cn/blog_migrate/6dcf661023fa302691337669a32aff93.png

Type 3: IP Protocol component

https://i-blog.csdnimg.cn/blog_migrate/498d484d89dd4b5ffbdeca4de78746d7.png The option byte is defined as following:
-    E bit: end of option (Must be set to 1 for the last Option)
-    A bit: AND bit, if set the operation between several [option/value] is AND, if unset the operation is a logical OR. Never set for the first Option
-    Len: If 0 the following value is encoded in 1 byte ; if 1 the following value is encoded in 2 bytes
-    Lt bit: less than comparison between the Data and the given value
-    Gt bit: greater than comparison between the Data and the given value
-    Eq bit: equal comparison between the Data and the given value

Type 4: Port number component

https://i-blog.csdnimg.cn/blog_migrate/019525c6043b7a43f14396e740cf46d7.png

 Type 5: Destination port number component

https://i-blog.csdnimg.cn/blog_migrate/04034da638f88b648bf4d7a743d2b03b.png

Type 6: Source port number component

https://i-blog.csdnimg.cn/blog_migrate/2a7031f1c2d71668e54c7ee1ea4c9c0e.png

 Type 7: ICMP Type component

https://i-blog.csdnimg.cn/blog_migrate/8bbcd6b9131bd0f2522f762db72f98c6.png

Type 8: ICMP Code component

https://i-blog.csdnimg.cn/blog_migrate/db8604e6f2145293a304a27305fc000b.png
 

Type 9: TCP Flags component

https://i-blog.csdnimg.cn/blog_migrate/cee2b40c058c5e088375f4ff3d2b1555.png

The option byte is defined as following:
-    E bit: end of option (Must be set to 1 for the last Option)
-    A bit: AND bit, if set the operation between several [option/value] is AND, if unset the operation is a logical OR. Never set for the first Option
-    Len: If 0 the following value is encoded in 1 byte ; if 1 the following value is encoded in 2 bytes
-    NOT bit: logical negation operation between Data and the given value
-    m bit: match operation between the Data and the given value

Type 10: Packet Length component

https://i-blog.csdnimg.cn/blog_migrate/bf4d54e9ff87b6ccf2b5ad4f1027215f.png

Type 11: DSCP Value component

https://i-blog.csdnimg.cn/blog_migrate/e37f485e53ec9c7e7fb271e4ca6a8902.png

Type 12: Fragment component

https://i-blog.csdnimg.cn/blog_migrate/0de0ce97a64bc34d99f60476a0e3800b.png

After the flow definition, Traffic Actions (rules) are encoded as Extended Community Attribute (see RFC 4360)

https://i-blog.csdnimg.cn/blog_migrate/ba74b8e64f50683399a55bf8bcad29f7.png
There are 4 types of “Action”, each of them has a dedicated Extended Community TYPE. The tab below lists the current Actions available:

https://i-blog.csdnimg.cn/blog_migrate/5df4b450e62cab2168a486c4b835748d.png

Traffic-rate action:
Used for discard or rate-limit a specific flow. Discard action is actually a rate equal to zero. The remaining 4 octets carry the rate (in Bytes/sec) information.

https://i-blog.csdnimg.cn/blog_migrate/4b828e4b8f89d05e32745a3874198d1c.png

Traffic-action action:
Used to trigger specific processing the corresponding flow. Only the last 2 Bits of the 6 bytes are currently defined as following:

https://i-blog.csdnimg.cn/blog_migrate/e05670d1c5b3d2b196cc7dd08e47d055.png

-    Terminal Action (bit 47): When this bit is set, the traffic filtering engine will apply any subsequent filtering rules (as defined by the ordering procedure). If not set, the evaluation of the traffic filter stops when this rule is applied.
-    Sample (bit 46): Enables traffic sampling and logging for this flow specification.

Redirect action:
Traffic redirection allows to specify a
“route-target” community which will be handled by the router to redirect a Flow to a specific VRF.

https://i-blog.csdnimg.cn/blog_migrate/a9aa06fa97d30a06b67eb2a6c9f72198.png
Traffic-marking action:
Used to force a flow to be re-writted with a specific DSCP value when it leaves the routers.

https://i-blog.csdnimg.cn/blog_migrate/05adbf0d72e43562318b7dfa7c9f53c9.png

客户端处理流程

FRR实现了Flowspec客户端,也就是说BGP能够接收Flowspec条目,但不能充当管理器并发送Flowspec条目,FRR使用linux提供的PBR实现了下发的策略。

  • 使用过滤流量Netfilter。 Netfilter提供了一组类似的工具ipset和iptables那些强大到足以能够过滤等流程规格过滤规则。
  • 通过iproute2(通过 提供的命令)使用非标准路由表。 已经被FRR的PBR守护进程使用,该守护进程基于IP源和目的地标准提供基于策略的基本路由。

 

基本配置

router bgp <ASx>
 neighbor <A.B.C.D> remote-as <ASz>
 address-family ipv4 flowspec
  neighbor A.B.C.D activate

调试命令

show bgp ipv4 flowspec [detail | A.B.C.D]
show pbr ipset IPSETNAME | iptable
show ip route table TABLEID
[no] debug bgp flowspec
[no] debug bgp pbr [error]

 

收包处理流程

bgp_process_packet 处理BGP 收到的报文,FLOW SPEC是update的消息,
----调用bgp_update_receive处理update消息
---- bgp_attr_parse 解析update消息的attr
      ---- bgp_attr_ext_communities 解析 BGP_ATTR_EXT_COMMUNITIES 扩展属性为str,里面涉及flow spec的4种action,解析后存放在attr->ecommunity里面
      ---- bgp_mp_reach_parse解析BGP_ATTR_MP_REACH_NLRI属性,里面有flow spec的12种match,存放在struct bgp_nlri的nlri里面
---- bgp_nlri_parse 继续解析NLRI
     ---- bgp_nlri_parse_flowspec 解析flow spec的nlri,IPV6不支持??需要支持要修改什么?
          ---- bgp_fs_nlri_validate 解析flow spec的12种match 属性的合法性
          ---- bgp_update 这个函数有点庞大,的继续看
             ---- bgp_process
---- bgp_process_wq
     ---- bgp_process_main_one
    ---- bgp_zebra_announce
               ----bgp_pbr_update_entry  flowspec调用PBR 实现策略
bgp_pbr_update_entry
---- bgp_pbr_build_and_validate_entry 解析、填充flowspec的match和action
---- bgp_pbr_handle_entry 解析填充完成后,调用这个函数下发bgp pbr的策略
     ACTION_TRAFFICRATE 限速、ACTION_TRAFFIC_ACTION、ACTION_MARKING dscp当前的PBR是没有显示下发的。
     bgp_pbr_policyroute_add_to_zebra其余的支持的调用实现下发策略到zebra
     ---- bgp_pbr_policyroute_add_to_zebra_unit
          ---- bgp_send_pbr_ipset_match
          ---- bgp_send_pbr_ipset_entry_match

          ---- bgp_send_pbr_iptable

 

FRR 只支持FLOW SPEC的客户端,FRR是利用PBR实现的,PBR怎么实现的,后续再来补充

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值