]> git.proxmox.com Git - mirror_frr.git/blob - doc/user/flowspec.rst
Merge pull request #2599 from pacovn/PVS-Studio_Array_overrun
[mirror_frr.git] / doc / user / flowspec.rst
1 .. _flowspec:
2
3 Flowspec
4 ========
5
6 .. _features-of-the-current-implementation-flowspec:
7
8 Overview
9 ---------
10
11 Flowspec introduces a new :abbr:`NLRI (Network Layer Reachability Information)`
12 encoding format that is used to distribute traffic rule flow specifications.
13 Basically, instead of simply relying on destination IP address for IP prefixes,
14 the IP prefix is replaced by a n-tuple consisting of a rule. That rule can be a
15 more or less complex combination of the following:
16
17
18 - Network source/destination (can be one or the other, or both).
19 - Layer 4 information for UDP/TCP : source port, destination port, or any port.
20 - Layer 4 information for ICMP type and ICMP code.
21 - Layer 4 information for TCP Flags.
22 - Layer 3 information : DSCP value, Protocol type, packet length, fragmentation.
23 - Misc layer 4 TCP flags.
24
25 A combination of the above rules is applied for traffic filtering. This is
26 encoded as part of specific BGP extended communities and the action can range
27 from the obvious rerouting (to nexthop or to separate VRF) to shaping, or
28 discard.
29
30 The following IETF drafts and RFCs have been used to implement FRR Flowspec:
31
32 - :rfc:`5575`
33 - [Draft IETF IDR Flowspec redirect IP]_
34
35 .. _design-principles-flowspec:
36
37 Design Principles
38 -----------------
39
40 FRR implements the Flowspec client side, that is to say that BGP is able to
41 receive Flowspec entries, but is not able to act as manager and send Flowspec
42 entries.
43
44 Linux provides the following mechanisms to implement policy based routing:
45
46 - Filtering the traffic with ``Netfilter``.
47 ``Netfilter`` provides a set of tools like ``ipset`` and ``iptables`` that are
48 powerful enough to be able to filter such Flowspec filter rule.
49
50 - using non standard routing tables via ``iproute2`` (via the ``ip rule``
51 command provided by ``iproute2``).
52 ``iproute2`` is already used by FRR's :ref:`pbr` daemon which provides basic
53 policy based routing based on IP source and destination criterion.
54
55 Below example is an illustration of what Flowspec will inject in the underlying
56 system:
57
58 .. code-block:: shell
59
60 # linux shell
61 ipset create match0x102 hash:net,net counters
62 ipset add match0x102 32.0.0.0/16,40.0.0.0/16
63 iptables -N match0x102 -t mangle
64 iptables -A match0x102 -t mangle -j MARK --set-mark 102
65 iptables -A match0x102 -t mangle -j ACCEPT
66 iptables -i ntfp3 -t mangle -I PREROUTING -m set --match-set match0x102
67 src,dst -g match0x102
68 ip rule add fwmark 102 lookup 102
69 ip route add 40.0.0.0/16 via 44.0.0.2 table 102
70
71 For handling an incoming Flowspec entry, the following workflow is applied:
72
73 - incoming Flowspec entries are handled by *bgpd*, stored in the BGP RIB.
74 - Flowspec entry is installed according to its complexity.
75
76 It will be installed if one of the following filtering action is seen on the BGP
77 extended community: either redirect IP, or redirect VRF, in conjunction with
78 rate option, for redirecting traffic. Or rate option set to 0, for discarding
79 traffic.
80
81 According to the degree of complexity of the Flowspec entry, it will be
82 installed in *zebra* RIB. For more information about what is supported in the
83 FRR implementation as rule, see :ref:`flowspec-known-issues` chapter. Flowspec
84 entry is split in several parts before being sent to *zebra*.
85
86 - *zebra* daemon receives the policy routing configuration
87
88 Policy Based Routing entities necessary to policy route the traffic in the
89 underlying system, are received by *zebra*. Two filtering contexts will be
90 created or appended in ``Netfilter``: ``ipset`` and ``iptable`` context. The
91 former is used to define an IP filter based on multiple criterium. For instance,
92 an ipset ``net:net`` is based on two ip addresses, while ``net,port,net`` is
93 based on two ip addresses and one port ( for ICMP, UDP, or TCP). The way the
94 filtering is used ( for example, is src port or dst port used ?) is defined by
95 the latter filtering context. ``iptable`` command will reference the ``ipset``
96 context and will tell how to filter and what to do. In our case, a marker will
97 be set to indicate ``iproute2`` where to forward the traffic to. Sometimes, for
98 dropping action, there is no need to add a marker; the ``iptable`` will tell to
99 drop all packets matching the ``ipset`` entry.
100
101 Configuration guide
102 -------------------
103
104 In order to configure an IPv4 Flowspec engine, use the following configuration.
105 As of today, it is only possible to configure Flowspec on the default VRF.
106
107 .. code-block:: frr
108
109 router bgp <AS>
110 neighbor <A.B.C.D> remote-as <remoteAS>
111 address-family ipv4 flowspec
112 neighbor <A.B.C.D> activate
113 exit
114 exit
115
116 You can see Flowspec entries, by using one of the following show commands:
117
118 .. index:: show bgp ipv4 flowspec [detail | A.B.C.D]
119 .. clicmd:: show bgp ipv4 flowspec [detail | A.B.C.D]
120
121
122 Per-Interface Configuration
123 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
124
125 One nice feature to use is the ability to apply Flowspec to a specific
126 interface, instead of applying it to the whole machine. Despite the following
127 IETF draft [Draft IETF IDR Flowspec Interface Set]_ is not implemented, it is
128 possible to manually limit Flowspec application to some incoming interfaces.
129 Actually, not using it can result to some unexpected behaviour like accounting
130 twice the traffic, or slow down the traffic (filtering costs). To limit Flowspec
131 to one specific interface, use the following command, under
132 `flowspec address-family` node.
133
134 .. index:: [no] local-install <IFNAME | any>
135 .. clicmd:: [no] local-install <IFNAME | any>
136
137 By default, Flowspec is activated on all interfaces. Installing it to a named
138 interface will result in allowing only this interface. Conversely, enabling any
139 interface will flush all previously configured interfaces.
140
141 VRF redirection
142 ^^^^^^^^^^^^^^^
143
144 Another nice feature to configure is the ability to redirect traffic to a
145 separate VRF. This feature does not go against the ability to configure Flowspec
146 only on default VRF. Actually, when you receive incoming BGP flowspec entries on
147 that default VRF, you can redirect traffic to an other VRF.
148
149 As a reminder, BGP flowspec entries have a BGP extended community that contains
150 a Route Target. Finding out a local VRF based on Route Target consists in the
151 following:
152
153 - A configuration of each VRF must be done, with its Route Target set
154 Each VRF is being configured within a BGP VRF instance with its own Route
155 Target list. Route Target accepted format matches the following:
156 ``A.B.C.D:U16``, or ``U16:U32``, ``U32:U16``.
157
158 - The first VRF with the matching Route Target will be selected to route traffic
159 to. Use the following command under ipv4 unicast address-family node
160
161 .. index:: [no] rt redirect import RTLIST...
162 .. clicmd:: [no] rt redirect import RTLIST...
163
164 In order to illustrate, if the Route Target configured in the Flowspec entry is
165 E.F.G.H:II, then a BGP VRF instance with the same Route Target will be set set.
166 That VRF will then be selected. The below full configuration example depicts how
167 Route Targets are configured and how VRFs and cross VRF configuration is done.
168 Note that the VRF are mapped on Linux Network Namespaces. For data traffic to
169 cross VRF boundaries, virtual ethernet interfaces are created with private IP
170 adressing scheme.
171
172 .. code-block:: frr
173
174 router bgp <ASx>
175 neighbor <A.B.C.D> remote-as <ASz>
176 address-family ipv4 flowspec
177 neighbor A.B.C.D activate
178 exit
179 exit
180 router bgp <ASy> vrf vrf2
181 address-family ipv4 unicast
182 rt redirect import <E.F.G.H:II>
183 exit
184 exit
185
186 Flowspec Monitor and troubleshooting
187 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
188
189 You can monitor policy-routing objects by using one of the following commands.
190 Those command rely on the filtering contexts configured from BGP, and get the
191 statistics information retrieved from the underlying system. In other words,
192 those statistics are retrieved from ``Netfilter``.
193
194 .. index:: show pbr ipset IPSETNAME | iptable
195 .. clicmd:: show pbr ipset IPSETNAME | iptable
196
197 ``IPSETNAME`` is the policy routing object name created by ``ipset``.
198 About rule contexts, it is possible to know which rule has been configured to
199 policy-route some specific traffic. The :clicmd:`show pbr iptable` command
200 displays for forwarded traffic, which table is used. Then it is easy to use that
201 table identifier to dump the routing table that the forwarded traffic will
202 match.
203
204 .. code-block:: frr
205
206 show ip route table TABLEID
207
208 ``TABLEID`` is the table number identifier referencing the non standard routing
209 table used in this example.
210 You can troubleshoot Flowspec, or BGP policy based routing. For instance, if you
211 encounter some issues when decoding a Flowspec entry, you should enable
212 :clicmd:`debug bgp flowspec`.
213
214 .. index:: [no] debug bgp flowspec
215 .. clicmd:: [no] debug bgp flowspec
216
217 If you fail to apply the flowspec entry into *zebra*, there should be some
218 relationship with policy routing mechanism. Here, :clicmd:`debug bgp pbr error`
219 could help.
220
221 .. index:: [no] debug bgp pbr [error]
222 .. clicmd:: [no] debug bgp pbr [error]
223
224 To get information about policy routing contexts created/removed, only use
225 :clicmd:`debug bgp pbr` command.
226
227 Ensuring that a Flowspec entry has been correctly installed and that incoming
228 traffic is policy-routed correctly can be checked like illustrated below. First
229 of all, you must check whether the Flowspec entry has been installed or not.
230
231 .. code-block:: frr
232
233 CLI# show bgp ipv4 flowspec 5.5.5.2/32
234 BGP flowspec entry: (flags 0x418)
235 Destination Address 5.5.5.2/32
236 IP Protocol = 17
237 Destination Port >= 50 , <= 90
238 FS:redirect VRF RT:255.255.255.255:255
239 received for 18:41:37
240 installed in PBR (match0x271ce00)
241
242 This means that the Flowspec entry has been installed in a `iptable`
243 named `match0x271ce00`. Once you have confirmation it is installed, you can
244 check whether you find the associate entry by executing following command. You
245 can also check whether incoming traffic has been matched by looking at counter
246 line.
247
248 .. code-block:: frr
249
250 CLI# show pbr ipset match0x271ce00
251 IPset match0x271ce00 type net,port
252 to 5.5.5.0/24:proto 6:80-120 (8)
253 pkts 1000, bytes 1000000
254 to 5.5.5.2:proto 17:50-90 (5)
255 pkts 1692918, bytes 157441374
256
257 As you can see, the entry is present. note that an `iptable` entry can be used
258 to host several Flowspec entries. In order to know where the matching traffic is
259 redirected to, you have to look at the policy routing rules. The policy-routing
260 is done by forwarding traffic to a routing table number. That routing table
261 number is reached by using a `iptable`. The relationship between the routing
262 table number and the incoming traffic is a MARKER that is set by the IPtable
263 referencing the IPSet. In Flowspec case, `iptable` referencing the `ipset`
264 context have the same name. So it is easy to know which routing table is used by
265 issuing following command:
266
267 .. code-block:: frr
268
269 CLI# show pbr iptable
270 IPtable match0x271ce00 action redirect (5)
271 pkts 1700000, bytes 158000000
272 table 257, fwmark 257
273 ...
274
275 As you can see, by using following Linux commands, the MARKER `0x101` is present
276 in both ``iptable`` and ``ip rule`` contexts.
277
278 .. code-block:: shell
279
280 # iptables -t mangle --list match0x271ce00 -v
281 Chain match0x271ce00 (1 references)
282 pkts bytes target prot opt in out source destination
283 1700K 158M MARK all -- any any anywhere anywhere
284 MARK set 0x101
285 1700K 158M ACCEPT all -- any any anywhere anywhere
286
287 # ip rule list
288 0:from all lookup local
289 0:from all fwmark 0x101 lookup 257
290 32766:from all lookup main
291 32767:from all lookup default
292
293 This allows us to see where the traffic is forwarded to.
294
295 .. _flowspec-known-issues:
296
297 Limitations / Known issues
298 --------------------------
299
300 As you can see, Flowspec is rich and can be very complex.
301 As of today, not all Flowspec rules will be able to be converted into Policy
302 Based Routing actions.
303
304 - The ``Netfilter`` driver is not integrated into FRR yet. Not having this piece
305 of code prevents from injecting flowspec entries into the underlying system.
306
307 - There are some limitations around filtering contexts
308
309 If I take example of UDP ports, or TCP ports in Flowspec, the information
310 can be a range of ports, or a unique value. This case is handled.
311 However, complexity can be increased, if the flow is a combination of a list
312 of range of ports and an enumerate of unique values. Here this case is not
313 handled. Similarly, it is not possible to create a filter for both src port
314 and dst port. For instance, filter on src port from [1-1000] and dst port =
315 80. The same kind of complexity is not possible for packet length, ICMP type,
316 ICMP code.
317
318 There are some other known issues:
319
320 - The validation procedure depicted in :rfc:`5575` is not available.
321
322 This validation procedure has not been implemented, as this feature was not
323 used in the existing setups you shared wih us.
324
325 - The filtering action shaper value, if positive, is not used to apply shaping.
326
327 If value is positive, the traffic is redirected to the wished destination,
328 without any other action configured by Flowspec.
329 It is recommended to configure Quality of Service if needed, more globally on
330 a per interface basis.
331
332 - upon crash or unknown event, *zebra* may not have time to flush pbr contexts.
333
334 That is to say ``ipset``, ``iptable`` and ``ip rule`` contexts. This is also a
335 consequence due to the fact that ip rule / ipset / iptables are not discovered
336 at startup (not able to read appropriate contexts coming from Flowspec).
337
338 Appendix
339 --------
340
341 More information with a public presentation that explains the design of Flowspec
342 inside FRRouting.
343
344 [Presentation]_
345
346 .. [Draft IETF IDR Flowspec redirect IP] <https://tools.ietf.org/id/draft-ietf-idr-flowspec-redirect-ip-02.txt>
347 .. [Draft IETF IDR Flowspec Interface Set] <https://tools.ietf.org/id/draft-ietf-idr-flowspec-interfaceset-03.txt>
348 .. [Presentation] <https://docs.google.com/presentation/d/1ekQygUAG5yvQ3wWUyrw4Wcag0LgmbW1kV02IWcU4iUg/edit#slide=id.g378f0e1b5e_1_44>