]> git.proxmox.com Git - mirror_frr.git/blob - lib/bfd.h
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / lib / bfd.h
1 /**
2 * bfd.h: BFD definitions and structures
3 *
4 * @copyright Copyright (C) 2015 Cumulus Networks, Inc.
5 *
6 * This file is part of GNU Zebra.
7 *
8 * GNU Zebra is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * GNU Zebra is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifndef _ZEBRA_BFD_H
24 #define _ZEBRA_BFD_H
25
26 #include "lib/json.h"
27 #include "lib/zclient.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #define BFD_DEF_MIN_RX 300
34 #define BFD_MIN_MIN_RX 50
35 #define BFD_MAX_MIN_RX 60000
36 #define BFD_DEF_MIN_TX 300
37 #define BFD_MIN_MIN_TX 50
38 #define BFD_MAX_MIN_TX 60000
39 #define BFD_DEF_DETECT_MULT 3
40 #define BFD_MIN_DETECT_MULT 2
41 #define BFD_MAX_DETECT_MULT 255
42
43 #define BFD_STATUS_UNKNOWN (1 << 0) /* BFD session status never received */
44 #define BFD_STATUS_DOWN (1 << 1) /* BFD session status is down */
45 #define BFD_STATUS_UP (1 << 2) /* BFD session status is up */
46 #define BFD_STATUS_ADMIN_DOWN (1 << 3) /* BFD session is admin down */
47
48 #define BFD_PROFILE_NAME_LEN 64
49
50 const char *bfd_get_status_str(int status);
51
52 extern void bfd_client_sendmsg(struct zclient *zclient, int command,
53 vrf_id_t vrf_id);
54
55 /*
56 * BFD new API.
57 */
58
59 /* Forward declaration of argument struct. */
60 struct bfd_session_params;
61
62 /** Session state definitions. */
63 enum bfd_session_state {
64 /** Session state is unknown or not initialized. */
65 BSS_UNKNOWN = BFD_STATUS_UNKNOWN,
66 /** Local or remote peer administratively shutdown the session. */
67 BSS_ADMIN_DOWN = BFD_STATUS_ADMIN_DOWN,
68 /** Session is down. */
69 BSS_DOWN = BFD_STATUS_DOWN,
70 /** Session is up and working correctly. */
71 BSS_UP = BFD_STATUS_UP,
72 };
73
74 /** BFD session status information */
75 struct bfd_session_status {
76 /** Current session state. */
77 enum bfd_session_state state;
78 /** Previous session state. */
79 enum bfd_session_state previous_state;
80 /** Remote Control Plane Independent bit state. */
81 bool remote_cbit;
82 /** Last event occurrence. */
83 time_t last_event;
84 };
85
86 /**
87 * Session status update callback.
88 *
89 * \param bsp BFD session parameters.
90 * \param bss BFD session status.
91 * \param arg application independent data.
92 */
93 typedef void (*bsp_status_update)(struct bfd_session_params *bsp,
94 const struct bfd_session_status *bss,
95 void *arg);
96
97 /**
98 * Allocates and initializes the session parameters.
99 *
100 * \param updatecb status update notification callback.
101 * \param args application independent data.
102 *
103 * \returns pointer to configuration storage.
104 */
105 struct bfd_session_params *bfd_sess_new(bsp_status_update updatecb, void *args);
106
107 /**
108 * Uninstall session if installed and free resources allocated by the
109 * parameters. Already sets pointer to `NULL` to avoid dangling references.
110 *
111 * \param bsp session parameters.
112 */
113 void bfd_sess_free(struct bfd_session_params **bsp);
114
115 /**
116 * Set the local and peer address of the BFD session.
117 *
118 * NOTE:
119 * If the address changed the session is removed and must be installed again
120 * with `bfd_sess_install`.
121 *
122 * \param bsp BFD session parameters.
123 * \param src local address (optional, can be `NULL`).
124 * \param dst remote address (mandatory).
125 */
126 void bfd_sess_set_ipv4_addrs(struct bfd_session_params *bsp,
127 const struct in_addr *src,
128 const struct in_addr *dst);
129
130 /**
131 * Set the local and peer address of the BFD session.
132 *
133 * NOTE:
134 * If the address changed the session is removed and must be installed again
135 * with `bfd_sess_install`.
136 *
137 * \param bsp BFD session parameters.
138 * \param src local address (optional, can be `NULL`).
139 * \param dst remote address (mandatory).
140 */
141 void bfd_sess_set_ipv6_addrs(struct bfd_session_params *bsp,
142 const struct in6_addr *src,
143 const struct in6_addr *dst);
144
145 /**
146 * Configure the BFD session interface.
147 *
148 * NOTE:
149 * If the interface changed the session is removed and must be installed again
150 * with `bfd_sess_install`.
151 *
152 * \param bsp BFD session parameters.
153 * \param ifname interface name (or `NULL` to remove it).
154 */
155 void bfd_sess_set_interface(struct bfd_session_params *bsp, const char *ifname);
156
157 /**
158 * Configure the BFD session profile name.
159 *
160 * NOTE:
161 * Session profile will only change after a `bfd_sess_install`.
162 *
163 * \param bsp BFD session parameters.
164 * \param profile profile name (or `NULL` to remove it).
165 */
166 void bfd_sess_set_profile(struct bfd_session_params *bsp, const char *profile);
167
168 /**
169 * Configure the BFD session VRF.
170 *
171 * NOTE:
172 * If the VRF changed the session is removed and must be installed again
173 * with `bfd_sess_install`.
174 *
175 * \param bsp BFD session parameters.
176 * \param vrf_id the VRF identification number.
177 */
178 void bfd_sess_set_vrf(struct bfd_session_params *bsp, vrf_id_t vrf_id);
179
180 /**
181 * Configure the BFD session single/multi hop setting.
182 *
183 * NOTE:
184 * If the number of hops is changed the session is removed and must be
185 * installed again with `bfd_sess_install`.
186 *
187 * \param bsp BFD session parameters.
188 * \param hops maximum amount of hops expected (1 for single hop, 2 or
189 * more for multi hop).
190 */
191 void bfd_sess_set_hop_count(struct bfd_session_params *bsp, uint8_t hops);
192
193 /**
194 * Configure the BFD session to set the Control Plane Independent bit.
195 *
196 * NOTE:
197 * Session CPI bit will only change after a `bfd_sess_install`.
198 *
199 * \param bsp BFD session parameters.
200 * \param enable BFD Control Plane Independent state.
201 */
202 void bfd_sess_set_cbit(struct bfd_session_params *bsp, bool enable);
203
204 /**
205 * DEPRECATED: please avoid using timers directly and use profiles instead.
206 *
207 * Configures the BFD session timers to use. This is specially useful with
208 * `ptm-bfd` which does not support timers.
209 *
210 * NOTE:
211 * Session timers will only apply if the session has not been created yet.
212 * If the session is already installed you must uninstall and install again
213 * to take effect.
214 *
215 * \param bsp BFD session parameters.
216 * \param detection_multiplier the detection multiplier value.
217 * \param min_rx minimum required receive period.
218 * \param min_tx minimum required transmission period.
219 */
220 void bfd_sess_set_timers(struct bfd_session_params *bsp,
221 uint8_t detection_multiplier, uint32_t min_rx,
222 uint32_t min_tx);
223
224 /**
225 * Configures the automatic source selection for the BFD session.
226 *
227 * NOTE:
228 * Setting this configuration will override the IP source value set by
229 * `bfd_sess_set_ipv4_addrs` or `bfd_sess_set_ipv6_addrs`.
230 *
231 * \param bsp BFD session parameters
232 * \param enable BFD automatic source selection state.
233 */
234 void bfd_sess_set_auto_source(struct bfd_session_params *bsp, bool enable);
235
236 /**
237 * Installs or updates the BFD session based on the saved session arguments.
238 *
239 * NOTE:
240 * This function has a delayed effect: it will only install/update after
241 * all northbound/CLI command batch finishes.
242 *
243 * \param bsp session parameters.
244 */
245 void bfd_sess_install(struct bfd_session_params *bsp);
246
247 /**
248 * Uninstall the BFD session based on the saved session arguments.
249 *
250 * NOTE:
251 * This function uninstalls the session immediately (if installed) and cancels
252 * any previous `bfd_sess_install` calls.
253 *
254 * \param bsp session parameters.
255 */
256 void bfd_sess_uninstall(struct bfd_session_params *bsp);
257
258 /**
259 * Get BFD session current status.
260 *
261 * \param bsp session parameters.
262 *
263 * \returns BFD session status data structure.
264 */
265 enum bfd_session_state bfd_sess_status(const struct bfd_session_params *bsp);
266
267 /**
268 * Get BFD session amount of hops configured value.
269 *
270 * \param bsp session parameters.
271 *
272 * \returns configured amount of hops.
273 */
274 uint8_t bfd_sess_hop_count(const struct bfd_session_params *bsp);
275
276 /**
277 * Get BFD session profile configured value.
278 *
279 * \param bsp session parameters.
280 *
281 * \returns configured profile name (or `NULL` if empty).
282 */
283 const char *bfd_sess_profile(const struct bfd_session_params *bsp);
284
285 /**
286 * Get BFD session addresses.
287 *
288 * \param bsp session parameters.
289 * \param family the address family being used (AF_INET or AF_INET6).
290 * \param src source address (optional, may be `NULL`).
291 * \param dst peer address (optional, may be `NULL`).
292 */
293 void bfd_sess_addresses(const struct bfd_session_params *bsp, int *family,
294 struct in6_addr *src, struct in6_addr *dst);
295 /**
296 * Get BFD session interface name.
297 *
298 * \param bsp session parameters.
299 *
300 * \returns `NULL` if not set otherwise the interface name.
301 */
302 const char *bfd_sess_interface(const struct bfd_session_params *bsp);
303
304 /**
305 * Get BFD session VRF name.
306 *
307 * \param bsp session parameters.
308 *
309 * \returns the VRF name.
310 */
311 const char *bfd_sess_vrf(const struct bfd_session_params *bsp);
312
313 /**
314 * Get BFD session VRF ID.
315 *
316 * \param bsp session parameters.
317 *
318 * \returns the VRF name.
319 */
320 vrf_id_t bfd_sess_vrf_id(const struct bfd_session_params *bsp);
321
322 /**
323 * Get BFD session control plane independent bit configuration state.
324 *
325 * \param bsp session parameters.
326 *
327 * \returns `true` if enabled otherwise `false`.
328 */
329 bool bfd_sess_cbit(const struct bfd_session_params *bsp);
330
331 /**
332 * DEPRECATED: please avoid using timers directly and use profiles instead.
333 *
334 * Gets the configured timers.
335 *
336 * \param bsp BFD session parameters.
337 * \param detection_multiplier the detection multiplier value.
338 * \param min_rx minimum required receive period.
339 * \param min_tx minimum required transmission period.
340 */
341 void bfd_sess_timers(const struct bfd_session_params *bsp,
342 uint8_t *detection_multiplier, uint32_t *min_rx,
343 uint32_t *min_tx);
344
345 /**
346 * Gets the automatic source selection state.
347 */
348 bool bfd_sess_auto_source(const struct bfd_session_params *bsp);
349
350 /**
351 * Show BFD session configuration and status. If `json` is provided (e.g. not
352 * `NULL`) then information will be inserted in object, otherwise printed to
353 * `vty`.
354 *
355 * \param vty Pointer to `vty` for outputting text.
356 * \param json (optional) JSON object pointer.
357 * \param bsp session parameters.
358 */
359 void bfd_sess_show(struct vty *vty, struct json_object *json,
360 struct bfd_session_params *bsp);
361
362 /**
363 * Initializes the BFD integration library. This function executes the
364 * following actions:
365 *
366 * - Copy the `struct thread_master` pointer to use as "thread" to execute
367 * the BFD session parameters installation.
368 * - Copy the `struct zclient` pointer to install its callbacks.
369 * - Initializes internal data structures.
370 *
371 * \param tm normally the daemon main thread event manager.
372 * \param zc the zebra client of the daemon.
373 */
374 void bfd_protocol_integration_init(struct zclient *zc,
375 struct thread_master *tm);
376
377 /**
378 * BFD session registration arguments.
379 */
380 struct bfd_session_arg {
381 /**
382 * BFD command.
383 *
384 * Valid commands:
385 * - `ZEBRA_BFD_DEST_REGISTER`
386 * - `ZEBRA_BFD_DEST_DEREGISTER`
387 */
388 int32_t command;
389
390 /**
391 * BFD family type.
392 *
393 * Supported types:
394 * - `AF_INET`
395 * - `AF_INET6`.
396 */
397 uint32_t family;
398 /** Source address. */
399 struct in6_addr src;
400 /** Source address. */
401 struct in6_addr dst;
402
403 /** Multi hop indicator. */
404 uint8_t mhop;
405 /** Expected hops. */
406 uint8_t hops;
407 /** C bit (Control Plane Independent bit) indicator. */
408 uint8_t cbit;
409
410 /** Interface name size. */
411 uint8_t ifnamelen;
412 /** Interface name. */
413 char ifname[64];
414
415 /** Daemon or session VRF. */
416 vrf_id_t vrf_id;
417
418 /** Profile name length. */
419 uint8_t profilelen;
420 /** Profile name. */
421 char profile[BFD_PROFILE_NAME_LEN];
422
423 /*
424 * Deprecation fields: these fields should be removed once `ptm-bfd`
425 * no longer uses this interface.
426 */
427
428 /** Minimum required receive interval (in microseconds). */
429 uint32_t min_rx;
430 /** Minimum desired transmission interval (in microseconds). */
431 uint32_t min_tx;
432 /** Detection multiplier. */
433 uint32_t detection_multiplier;
434 };
435
436 /**
437 * Send a message to BFD daemon through the zebra client.
438 *
439 * \param zc the zebra client context.
440 * \param arg the BFD session command arguments.
441 *
442 * \returns `-1` on failure otherwise `0`.
443 *
444 * \see bfd_session_arg.
445 */
446 extern int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *arg);
447
448 /**
449 * Enables or disables BFD protocol integration API debugging.
450 *
451 * \param enable new API debug state.
452 */
453 extern void bfd_protocol_integration_set_debug(bool enable);
454
455 /**
456 * Sets shutdown mode so no more events are processed.
457 *
458 * This is useful to avoid the event storm that happens caused by network,
459 * interfaces or VRFs removal. It should also avoid some crashes due hanging
460 * pointers left overs by protocol.
461 *
462 * \param enable new API shutdown state.
463 */
464 extern void bfd_protocol_integration_set_shutdown(bool enable);
465
466 /**
467 * Get API debugging state.
468 */
469 extern bool bfd_protocol_integration_debug(void);
470
471 /**
472 * Get API shutdown state.
473 */
474 extern bool bfd_protocol_integration_shutting_down(void);
475
476 /* Update nexthop-tracking (nht) information for BFD auto source selection.
477 * The function must be called from the daemon callback function
478 * that deals with the ZEBRA_NEXTHOP_UPDATE zclient command
479 */
480 extern int bfd_nht_update(const struct prefix *match,
481 const struct zapi_route *route);
482
483 #ifdef __cplusplus
484 }
485 #endif
486
487 #endif /* _ZEBRA_BFD_H */