blob: 54a53c6fe921f8e94eb537ecd935bfddea6346ce [file] [log] [blame]
Nathan Skrzypczakd4a70642021-10-08 14:01:27 +02001.. _bfd_doc:
2
3BFD module
4==========
5
6Overview
7--------
8
9Bidirectional Forwarding Detection in VPP currently supports single-hop
10UDP transport based on RFC 5880 and RFC 5881.
11
12Usage
13-----
14
15General usage
16~~~~~~~~~~~~~
17
18BFD sessions are created using APIs only. The following CLIs are
19implemented, which call the APIs to manipulate the BFD:
20
21Show commands:
22^^^^^^^^^^^^^^
23
24 show bfd [keys|sessions|echo-source]
25
26Show the existing keys, sessions or echo-source.
27
28Key manipulation
29^^^^^^^^^^^^^^^^
30
31Create a new key or modify an existing key
32''''''''''''''''''''''''''''''''''''''''''
33
34 bfd key set conf-key-id type <keyed-sha1|meticulous-keyed-sha1>
35 secret
36
37Parameters:
38
39- conf-key-id - local configuration key ID, used to uniquely identify
40 this key
41- type - type of the key
42- secret - shared secret (hex data)
43
44Example:
45
46 bfd key set conf-key-id 2368880803 type meticulous-keyed-sha1 secret
47 69d685b0d990cdba46872706dc
48
49Notes:
50
51- in-use key cannot be modified
52
53Delete an existing key
54''''''''''''''''''''''
55
56 bfd key del conf-key-id
57
58Parameters:
59
60- conf-key-id - local configuration key ID, used to uniquely identify
61 this key
62
63Example:
64
65 bfd key del conf-key-id 2368880803
66
67Notes:
68
69- in-use key cannot be deleted
70
71Create a new (plain or authenticated) BFD session
72'''''''''''''''''''''''''''''''''''''''''''''''''
73
74 bfd udp session add interface local-addr
75
76 .. raw:: html
77
78 <address>
79
80 peer-addr
81
82 .. raw:: html
83
84 <address>
85
86 desired-min-tx required-min-rx detect-mult [ conf-key-id bfd-key-id ]
87
88Parameters:
89
90- interface - interface to which this session is tied to
91- local-addr - local address (ipv4 or ipv6)
92- peer-addr - peer address (ipv4 or ipv6, must match local-addr family)
93- desired-min-tx - desired minimum tx interval (microseconds)
94- required-min-rx - required minimum rx interval (microseconds)
95- detect-mult - detect multiplier (must be non-zero)
96- conf-key-id - local configuration key ID
97- bfd-key-id - BFD key ID, as carried in BFD control frames
98
99Example:
100
101 bfd udp session add interface pg0 local-addr fd01:1::1 peer-addr
102 fd01:1::2 desired-min-tx 100000 required-min-rx 100000 detect-mult 3
103 conf-key-id 1029559112 bfd-key-id 13
104
105Notes:
106
107- if conf-key-id and bfd-key-id are not specified, session is
108 non-authenticated
109- desired-min-tx controls desired transmission rate of both control
110 frames and echo packets
111
112Modify BFD session
113''''''''''''''''''
114
115 bfd udp session mod interface local-addr
116
117 .. raw:: html
118
119 <address>
120
121 peer-addr
122
123 .. raw:: html
124
125 <address>
126
127 desired-min-tx required-min-rx detect-mult
128
129Parameters:
130
131- interface - interface to which this session is tied to
132- local-addr - local address (ipv4 or ipv6)
133- peer-addr - peer address (ipv4 or ipv6, must match local-addr family)
134- desired-min-tx - desired minimum tx interval (microseconds)
135- required-min-rx - required minimum rx interval (microseconds)
136- detect-mult - detect multiplier (must be non-zero)
137
138Example:
139
140 bfd udp session mod interface pg0 local-addr 172.16.1.1 peer-addr
141 172.16.1.2 desired-min-tx 300000 required-min-rx 200000 detect-mult
142 12
143
144Notes:
145
146- desired-min-tx controls desired transmission rate of both control
147 frames and echo packets
148
149Delete an existing BFD session
150''''''''''''''''''''''''''''''
151
152 bfd udp session del interface local-addr
153
154 .. raw:: html
155
156 <address>
157
158 peer-addr
159
160 .. raw:: html
161
162 <address>
163
164Parameters:
165
166- interface - interface to which this session is tied to
167- local-addr - local address (ipv4 or ipv6)
168- peer-addr - peer address (ipv4 or ipv6, must match local-addr family)
169
170Example:
171
172 bfd udp session del interface pg0 local-addr 172.16.1.1 peer-addr
173 172.16.1.2
174
175Set session admin-up or admin-down
176''''''''''''''''''''''''''''''''''
177
178 bfd udp session set-flags interface local-addr
179
180 .. raw:: html
181
182 <address>
183
184 peer-addr
185
186 .. raw:: html
187
188 <address>
189
190 admin <up|down>
191
192Parameters:
193
194- interface - interface to which this session is tied to
195- local-addr - local address (ipv4 or ipv6)
196- peer-addr - peer address (ipv4 or ipv6, must match local-addr family)
197- admin - up/down based on desired action
198
199Example:
200
201 bfd udp session set-flags admin down interface pg0 local-addr
202 172.16.1.1 peer-addr 172.16.1.2
203
204Activate/change authentication for existing session
205'''''''''''''''''''''''''''''''''''''''''''''''''''
206
207 bfd udp session auth activate interface local-addr
208
209 .. raw:: html
210
211 <address>
212
213 peer-addr
214
215 .. raw:: html
216
217 <address>
218
219 conf-key-id bfd-key-id [ delayed <yes|no> ]
220
221Parameters:
222
223- interface - interface to which this session is tied to
224- local-addr - local address (ipv4 or ipv6)
225- peer-addr - peer address (ipv4 or ipv6, must match local-addr family)
226- conf-key-id - local configuration key ID
227- bfd-key-id - BFD key ID, as carried in BFD control frames
228- delayed - is yes then this action is delayed until the peer performs
229 the same action
230
231Example:
232
233 bfd udp session auth activate interface pg0 local-addr 172.16.1.1
234 peer-addr 172.16.1.2 conf-key-id 540928695 bfd-key-id 239 delayed yes
235
236Notes:
237
238- see `Delayed option <#delayed-option>`__ for more information
239
240Deactivate authentication for existing session
241''''''''''''''''''''''''''''''''''''''''''''''
242
243 bfd udp session auth deactivate interface local-addr
244
245 .. raw:: html
246
247 <address>
248
249 peer-addr
250
251 .. raw:: html
252
253 <address>
254
255 [ delayed <yes|no> ]
256
257Parameters:
258
259- interface - interface to which this session is tied to
260- local-addr - local address (ipv4 or ipv6)
261- peer-addr - peer address (ipv4 or ipv6, must match local-addr family)
262- delayed - is yes then this action is delayed until the peer performs
263 the same action
264
265Example:
266
267 bfd udp session auth deactivate interface pg0 local-addr 172.16.1.1
268 peer-addr 172.16.1.2
269
270Notes:
271
272- see `Delayed option <#delayed-option>`__ for more information
273
274Set echo-source interface
275'''''''''''''''''''''''''
276
277 bfd udp echo-source set interface
278
279Parameters:
280
281- interface - interface used for getting source address for echo
282 packets
283
284Example:
285
286 bfd udp echo-source set interface loop0
287
288Delete echo-source interface
289''''''''''''''''''''''''''''
290
291 bfd udp echo-source del
292
293Example:
294
295 bfd udp echo-source del
296
297Authentication
298~~~~~~~~~~~~~~
299
300BFD sessions should be authenticated for security purposes. SHA1 and
301meticulous SHA1 authentication is supported by VPP. First,
302authentication keys are configured in VPP and afterwards they can be
303used by sessions.
304
305There are two key IDs in the scope of BFD session:
306
307- configuration key ID is the internal unique key ID inside VPP and is
308 never communicated to any peer, it serves only the purpose of
309 identifying the key
310- BFD key ID is the key ID carried in BFD control frames and is used
311 for verifying authentication
312
313Turning auth on/off
314^^^^^^^^^^^^^^^^^^^
315
316Authentication can be turned on or off at any time. Care must be taken
317however, to either synchronize the authentication manipulation with
318peer’s actions to avoid the session going down.
319
320Delayed option
321''''''''''''''
322
323Delayed option is useful for synchronizing authentication changes with a
324peer. If it’s specified, then authentication change is not performed
325immediately. In this case, VPP continues to transmit packets using the
326old authentication method (unauthenticated or using old sha1 key). If a
327packet is received, which does not pass the current authentication, then
328VPP tries to authenticate it using the new method (which might be none,
329if deactivating authentication) and if it passes, then the new
330authentication method is put in use.
331
332The recommended procedure for enabling/changing/disabling session
333authentication is:
334
3351. perform authentication change on vpp’s side with delayed option set
336 to yes
3372. perform authentication change on peer’s side (without delayed option)
338
339Notes:
340
341- if both peers use delayed option at the same time, the change will
342 never be carried out, since none of the peers will see any packet
343 with the new authentication which could trigger the change
344- remote peer does not need to support or even be aware of this
345 mechanism for it to work properly
346
347Echo function
348~~~~~~~~~~~~~
349
350Echo function is used by VPP whenever a peer declares the willingness to
351support it, echo-source is set and it contains a usable subnet (see
352below). When echo function is switched on, the required min rx interval
353advertised to peer is set to 1 second (or the configured value, if its
354higher).
355
356Echo source address
357^^^^^^^^^^^^^^^^^^^
358
359Because echo packets are only looped back (and not processed in any way)
360by a peer, it’s necessary to set the source address in a way which
361avoids packet drop due to spoofing protection by VPP. Per RFC, the
362source address should not be in the subnet set on the interface over
363which the echo packets are sent. Also, it must not be any VPP-local
364address, otherwise the packet gets dropped on receipt by VPP. The
365solution is to create a loopback interface with a (private) IPv4/IPv6
366subnet assigned as echo-source. The BFD then picks an unused address
367from the subnet by flipping the last bit and uses that as source address
368in the echo packets, thus meeting RFC recommendation while avoiding
369spoofing protection.
370
371Example: if 10.10.10.3/31 is the subnet, then 10.10.10.2 will be used as
372source address in (IPv4) echo packets
373
374Demand mode
375~~~~~~~~~~~
376
377Demand mode is respected by VPP, but not used locally. The only scenario
378when demand mode could make sense currently is when echo is active.
379Because echo packets are inherently insecure against an adversary
380looping them back a poll sequence would be required for slow periodic
381connectivity verification anyway. It’s more efficient to just ask the
382remote peer to send slow periodic control frames without VPP initiating
383periodic poll sequences.
384
385Admin-down
386~~~~~~~~~~
387
388Session may be put admin-down at any time. This immediately causes the
389state to be changed to AdminDown and remain so unless the session is put
390admin-up.
391
392BFD implementation notes
393------------------------
394
395Because BFD can work over different transport layers, the BFD code is
396separated into core BFD functionality - main module implemented in
397bfd_main.c and transport-specific code implemented in bfd_udp.c.
398
399Main module
400~~~~~~~~~~~
401
402Main module is responsible for handling all the BFD functionality
403defined in RFC 5880.
404
405Internal API
406^^^^^^^^^^^^
407
408Internal APIs defined in bfd_main.h are called from transport-specific
409code to create/modify/delete
410
411Packet receipt
412^^^^^^^^^^^^^^
413
414When a packet is received by the transport layer, it is forwarded to
415main module (to main thread) via an RPC call. At this point, the
416authentication has been verified, so the packet is consumed, session
417parameters are updated accordingly and state change (if applicable).
418Based on these, the timeouts are adjusted if required and an event is
419sent to the process node to wake up and recalculate sleep time.
420
421Packet transmit
422^^^^^^^^^^^^^^^
423
424Main module allocates a vlib_buffer_t, creates the required BFD frame
425(control or echo in it), then calls the transport layer to add the
426transport layer. Then a frame containing the buffer to the appropriate
427node is created and enqueued.
428
429Process node
430^^^^^^^^^^^^
431
432Main module implements one process node which is a simple loop. The
433process node gets next timeout from the timer wheel, sleeps until the
434timeout expires and then calls a timeout routine which drives the state
435machine for each session which timed out. The sleep is interrupted
436externally via vlib event, when a session is added or modified in a way
437which might require timer wheel manipulation. In this case the caller
438inserts the necessary timeout to timer wheel and then signals the
439process node to wake up early, handle possible timeouts and recalculate
440the sleep time again.
441
442State machine
443^^^^^^^^^^^^^
444
445Default state of BFD session when created is Down, per RFC 5880. State
446changes to Init, Up or Down based on events like received state from
447peer and timeouts. The session state can be set AdminDown using a binary
448API, which prevents it from going to any other state, until this
449limitation is removed. This state is advertised to peers in slow
450periodic control frames.
451
452For each session, the following timeouts are maintained:
453
4541. tx timeout - used for sending out control frames
4552. rx timeout - used for detecting session timeout
4563. echo tx timeout - used for sending out echo frames
4574. echo rx timeout - used for detecting session timeout based on echo
458
459These timeouts are maintained in cpu clocks and recalculated when
460appropriate (e.g. rx timeout is bumped when a packet is received,
461keeping the session alive). Only the earliest timeout is inserted into
462the timer wheel at a time and timer wheel events are never deleted,
463rather spurious events are ignored. This allows efficient operation,
464like not inserting events into timing wheel for each packet received or
465ignoring left-over events in case a bfd session gets removed and a new
466one is recreated with the same session index.
467
468Authentication keys management
469^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
470
471Authentication keys are managed internally in a pool, with each key
472tracking it’s use count. The removal/modification is only allowed if the
473key is not in use.
474
475UDP module
476~~~~~~~~~~
477
478UDP module is responsible for:
479
4801. public APIs/CLIs to configure BFD over UDP.
4812. support code called by main module to encapsulate/decapsulate BFD
482 packets
483
484This module implements two graph nodes - for consuming ipv4 and ipv6
485packets target at BFD ports 3874 and 3875.
486
487.. _packet-receipt-1:
488
489Packet receipt
490^^^^^^^^^^^^^^
491
492BFD packet receipt receipt starts in the bfd udp graph nodes. Since the
493code needs to verify IP/UDP header data, it relies on ip4-local (and
494ip6-local) nodes to store pointers to the appropriate headers. First,
495your discriminator is extracted from BFD packet and used to lookup the
496existing session. In case it’s zero, the pair of IP addresses and
497sw_if_index is used to lookup session. Then, main module is called to
498verify the authentication, if present. Afterwards a check is made if the
499IP/UDP headers are correct. If yes, then an RPC call is made to the main
500thread to consume the packet and take action upon it.
501
502Packet transmission
503^^^^^^^^^^^^^^^^^^^
504
505When process node decides that there is a need to transmit the packet,
506it creates a buffer, fills the BFD frame data in and calls the UDP
507module to add the transport layer. This is a simple operation for the
508control frames consisting of just adding UDP/IP headers based on session
509data. For echo frames, an additional step, looking at the echo-source
510interface and picking and address is performed and if this fails, then
511the packet cannot be transmitted and an error is returned to main
512thread.