]>
Commit | Line | Data |
---|---|---|
7f342629 DS |
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 | * | |
896014f4 DL |
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 | |
7f342629 DS |
21 | */ |
22 | ||
23 | #ifndef _ZEBRA_BFD_H | |
24 | #define _ZEBRA_BFD_H | |
25 | ||
68fe91d6 | 26 | #include "lib/json.h" |
43e52561 | 27 | #include "lib/zclient.h" |
68fe91d6 | 28 | |
5e244469 RW |
29 | #ifdef __cplusplus |
30 | extern "C" { | |
31 | #endif | |
32 | ||
7f342629 DS |
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 | ||
567b877d | 43 | #define BFD_GBL_FLAG_IN_SHUTDOWN (1 << 0) /* The daemon in shutdown */ |
d62a17ae | 44 | struct bfd_gbl { |
d7c0a89a | 45 | uint16_t flags; |
567b877d | 46 | }; |
47 | ||
7f342629 DS |
48 | #define BFD_FLAG_PARAM_CFG (1 << 0) /* parameters have been configured */ |
49 | #define BFD_FLAG_BFD_REG (1 << 1) /* Peer registered with BFD */ | |
986aa00f | 50 | #define BFD_FLAG_BFD_TYPE_MULTIHOP (1 << 2) /* Peer registered with BFD as multihop */ |
9beff0bd | 51 | #define BFD_FLAG_BFD_CBIT_ON (1 << 3) /* Peer registered with CBIT set to on */ |
dcffea69 | 52 | #define BFD_FLAG_BFD_CHECK_CONTROLPLANE (1 << 4) /* BFD and controlplane daemon are linked */ |
7f342629 | 53 | |
7555dc61 S |
54 | #define BFD_STATUS_UNKNOWN (1 << 0) /* BFD session status never received */ |
55 | #define BFD_STATUS_DOWN (1 << 1) /* BFD session status is down */ | |
56 | #define BFD_STATUS_UP (1 << 2) /* BFD session status is up */ | |
57 | #define BFD_STATUS_ADMIN_DOWN (1 << 3) /* BFD session is admin down */ | |
58 | ||
18322efd RZ |
59 | #define BFD_PROFILE_NAME_LEN 64 |
60 | ||
7555dc61 S |
61 | #define BFD_SET_CLIENT_STATUS(current_status, new_status) \ |
62 | do { \ | |
63 | (current_status) = \ | |
64 | (((new_status) == BFD_STATUS_ADMIN_DOWN) ? \ | |
65 | BFD_STATUS_DOWN : (new_status));\ | |
66 | } while (0) | |
68fe91d6 | 67 | |
986aa00f | 68 | enum bfd_sess_type { |
d62a17ae | 69 | BFD_TYPE_NOT_CONFIGURED, |
70 | BFD_TYPE_SINGLEHOP, | |
71 | BFD_TYPE_MULTIHOP | |
986aa00f | 72 | }; |
73 | ||
d62a17ae | 74 | struct bfd_info { |
d7c0a89a QY |
75 | uint16_t flags; |
76 | uint8_t detect_mult; | |
77 | uint32_t desired_min_tx; | |
78 | uint32_t required_min_rx; | |
d62a17ae | 79 | time_t last_update; |
d7c0a89a | 80 | uint8_t status; |
d62a17ae | 81 | enum bfd_sess_type type; |
18322efd | 82 | char profile[BFD_PROFILE_NAME_LEN]; |
7f342629 DS |
83 | }; |
84 | ||
d62a17ae | 85 | extern struct bfd_info *bfd_info_create(void); |
7f342629 | 86 | |
d62a17ae | 87 | extern void bfd_info_free(struct bfd_info **bfd_info); |
7f342629 | 88 | |
d62a17ae | 89 | extern int bfd_validate_param(struct vty *vty, const char *dm_str, |
90 | const char *rx_str, const char *tx_str, | |
d7c0a89a QY |
91 | uint8_t *dm_val, uint32_t *rx_val, |
92 | uint32_t *tx_val); | |
7f342629 | 93 | |
d7c0a89a | 94 | extern void bfd_set_param(struct bfd_info **bfd_info, uint32_t min_rx, |
4affdba7 G |
95 | uint32_t min_tx, uint8_t detect_mult, |
96 | const char *profile, int defaults, int *command); | |
d62a17ae | 97 | extern void bfd_peer_sendmsg(struct zclient *zclient, struct bfd_info *bfd_info, |
98 | int family, void *dst_ip, void *src_ip, | |
9beff0bd PG |
99 | char *if_name, int ttl, int multihop, int cbit, |
100 | int command, int set_flag, vrf_id_t vrf_id); | |
7f342629 | 101 | |
d62a17ae | 102 | extern const char *bfd_get_command_dbg_str(int command); |
7f342629 | 103 | |
d62a17ae | 104 | extern struct interface *bfd_get_peer_info(struct stream *s, struct prefix *dp, |
105 | struct prefix *sp, int *status, | |
9beff0bd | 106 | int *remote_cbit, |
d62a17ae | 107 | vrf_id_t vrf_id); |
68fe91d6 | 108 | |
d62a17ae | 109 | const char *bfd_get_status_str(int status); |
68fe91d6 | 110 | |
d62a17ae | 111 | extern void bfd_show_param(struct vty *vty, struct bfd_info *bfd_info, |
9f049418 | 112 | int bfd_tag, int extra_space, bool use_json, |
d62a17ae | 113 | json_object *json_obj); |
68fe91d6 | 114 | |
d62a17ae | 115 | extern void bfd_show_info(struct vty *vty, struct bfd_info *bfd_info, |
9f049418 | 116 | int multihop, int extra_space, bool use_json, |
d62a17ae | 117 | json_object *json_obj); |
7f342629 | 118 | |
0945d5ed PG |
119 | extern void bfd_client_sendmsg(struct zclient *zclient, int command, |
120 | vrf_id_t vrf_id); | |
055c4dfc | 121 | |
d62a17ae | 122 | extern void bfd_gbl_init(void); |
567b877d | 123 | |
d62a17ae | 124 | extern void bfd_gbl_exit(void); |
567b877d | 125 | |
18322efd RZ |
126 | |
127 | /* | |
128 | * BFD new API. | |
129 | */ | |
130 | ||
a099abe5 RZ |
131 | /* Forward declaration of argument struct. */ |
132 | struct bfd_session_params; | |
133 | ||
134 | /** Session state definitions. */ | |
135 | enum bfd_session_state { | |
136 | /** Session state is unknown or not initialized. */ | |
137 | BSS_UNKNOWN = BFD_STATUS_UNKNOWN, | |
138 | /** Local or remote peer administratively shutdown the session. */ | |
139 | BSS_ADMIN_DOWN = BFD_STATUS_ADMIN_DOWN, | |
140 | /** Session is down. */ | |
141 | BSS_DOWN = BFD_STATUS_DOWN, | |
142 | /** Session is up and working correctly. */ | |
143 | BSS_UP = BFD_STATUS_UP, | |
144 | }; | |
145 | ||
146 | /** BFD session status information */ | |
147 | struct bfd_session_status { | |
148 | /** Current session state. */ | |
149 | enum bfd_session_state state; | |
150 | /** Previous session state. */ | |
151 | enum bfd_session_state previous_state; | |
152 | /** Remote Control Plane Independent bit state. */ | |
153 | bool remote_cbit; | |
154 | /** Last event occurrence. */ | |
155 | time_t last_event; | |
156 | }; | |
157 | ||
158 | /** | |
159 | * Session status update callback. | |
160 | * | |
161 | * \param bsp BFD session parameters. | |
162 | * \param bss BFD session status. | |
163 | * \param arg application independent data. | |
164 | */ | |
165 | typedef void (*bsp_status_update)(struct bfd_session_params *bsp, | |
166 | const struct bfd_session_status *bss, | |
167 | void *arg); | |
168 | ||
169 | /** | |
170 | * Allocates and initializes the session parameters. | |
171 | * | |
172 | * \param updatedb status update notification callback. | |
173 | * \param args application independent data. | |
174 | * | |
175 | * \returns pointer to configuration storage. | |
176 | */ | |
177 | struct bfd_session_params *bfd_sess_new(bsp_status_update updatecb, void *args); | |
178 | ||
179 | /** | |
180 | * Uninstall session if installed and free resources allocated by the | |
181 | * parameters. Already sets pointer to `NULL` to avoid dangling references. | |
182 | * | |
183 | * \param bsp session parameters. | |
184 | */ | |
185 | void bfd_sess_free(struct bfd_session_params **bsp); | |
186 | ||
a099abe5 RZ |
187 | /** |
188 | * Set the local and peer address of the BFD session. | |
189 | * | |
190 | * \param bsp BFD session parameters. | |
191 | * \param src local address (optional, can be `NULL`). | |
192 | * \param dst remote address (mandatory). | |
193 | */ | |
194 | void bfd_sess_set_ipv4_addrs(struct bfd_session_params *bsp, | |
195 | struct in_addr *src, struct in_addr *dst); | |
196 | ||
197 | /** | |
198 | * Set the local and peer address of the BFD session. | |
199 | * | |
200 | * \param bsp BFD session parameters. | |
201 | * \param src local address (optional, can be `NULL`). | |
202 | * \param dst remote address (mandatory). | |
203 | */ | |
204 | void bfd_sess_set_ipv6_addrs(struct bfd_session_params *bsp, | |
205 | struct in6_addr *src, struct in6_addr *dst); | |
206 | ||
207 | /** | |
208 | * Configure the BFD session interface. | |
209 | * | |
210 | * \param bsp BFD session parameters. | |
211 | * \param ifname interface name (or `NULL` to remove it). | |
212 | */ | |
213 | void bfd_sess_set_interface(struct bfd_session_params *bsp, const char *ifname); | |
214 | ||
215 | /** | |
216 | * Configure the BFD session profile name. | |
217 | * | |
218 | * \param bsp BFD session parameters. | |
219 | * \param profile profile name (or `NULL` to remove it). | |
220 | */ | |
221 | void bfd_sess_set_profile(struct bfd_session_params *bsp, const char *profile); | |
222 | ||
223 | /** | |
224 | * Configure the BFD session VRF. | |
225 | * | |
226 | * \param bsp BFD session parameters. | |
227 | * \param vrf_id the VRF identification number. | |
228 | */ | |
229 | void bfd_sess_set_vrf(struct bfd_session_params *bsp, vrf_id_t vrf_id); | |
230 | ||
231 | /** | |
232 | * Configure the BFD session single/multi hop setting. | |
233 | * | |
234 | * \param bsp BFD session parameters. | |
235 | * \param min_ttl minimum TTL value expected (255 for single hop, 254 for | |
236 | * multi hop with single hop, 253 for multi hop with two hops | |
237 | * and so on). See `BFD_SINGLE_HOP_TTL` and | |
238 | * `BFD_MULTI_HOP_MIN_TTL` for defaults. | |
239 | * | |
240 | * To simplify things if your protocol only knows the amount of hops it is | |
241 | * better to use `bfd_sess_set_hops` instead. | |
242 | */ | |
243 | void bfd_sess_set_mininum_ttl(struct bfd_session_params *bsp, uint8_t min_ttl); | |
244 | ||
245 | /** To use single hop the minimum TTL must be set to this. */ | |
246 | #define BFD_SINGLE_HOP_TTL 255 | |
247 | /** To use multi hop the minimum TTL must be set to this or less. */ | |
248 | #define BFD_MULTI_HOP_MIN_TTL 254 | |
249 | ||
250 | /** | |
251 | * This function is the inverted version of `bfd_sess_set_minimum_ttl`. | |
252 | * Instead of receiving the minimum expected TTL, it receives the amount of | |
253 | * hops the protocol will jump. | |
254 | * | |
255 | * \param bsp BFD session parameters. | |
256 | * \param min_ttl minimum amount of hops expected (1 for single hop, 2 or | |
257 | * more for multi hop). | |
258 | */ | |
259 | void bfd_sess_set_hop_count(struct bfd_session_params *bsp, uint8_t min_ttl); | |
260 | ||
261 | /** | |
262 | * Configure the BFD session to set the Control Plane Independent bit. | |
263 | * | |
264 | * \param bsp BFD session parameters. | |
265 | * \param enable BFD Control Plane Independent state. | |
266 | */ | |
267 | void bfd_sess_set_cbit(struct bfd_session_params *bsp, bool enable); | |
268 | ||
269 | /** | |
270 | * DEPRECATED: please avoid using timers directly and use profiles instead. | |
271 | * | |
272 | * Configures the BFD session timers to use. This is specially useful with | |
273 | * `ptm-bfd` which does not support timers. | |
274 | * | |
275 | * \param bsp BFD session parameters. | |
276 | * \param detection_multiplier the detection multiplier value. | |
277 | * \param min_rx minimum required receive period. | |
278 | * \param min_tx minimum required transmission period. | |
279 | */ | |
280 | void bfd_sess_set_timers(struct bfd_session_params *bsp, | |
281 | uint8_t detection_multiplier, uint32_t min_rx, | |
282 | uint32_t min_tx); | |
283 | ||
284 | /** | |
285 | * Installs or updates the BFD session based on the saved session arguments. | |
286 | * | |
287 | * \param bsp session parameters. | |
288 | */ | |
289 | void bfd_sess_install(struct bfd_session_params *bsp); | |
290 | ||
291 | /** | |
292 | * Uninstall the BFD session based on the saved session arguments. | |
293 | * | |
294 | * \param bsp session parameters. | |
295 | */ | |
296 | void bfd_sess_uninstall(struct bfd_session_params *bsp); | |
297 | ||
298 | /** | |
299 | * Get BFD session current status. | |
300 | * | |
301 | * \param bsp session parameters. | |
302 | * | |
303 | * \returns BFD session status data structure. | |
304 | */ | |
305 | enum bfd_session_state bfd_sess_status(const struct bfd_session_params *bsp); | |
306 | ||
307 | /** | |
308 | * Get BFD session minimum TTL configured value. | |
309 | * | |
310 | * \param bsp session parameters. | |
311 | * | |
312 | * \returns configured minimum TTL. | |
313 | */ | |
314 | uint8_t bfd_sess_minimum_ttl(const struct bfd_session_params *bsp); | |
315 | ||
316 | /** | |
317 | * Inverted version of `bfd_sess_minimum_ttl`. Gets the amount of hops in the | |
318 | * way to the peer. | |
319 | * | |
320 | * \param bsp session parameters. | |
321 | * | |
322 | * \returns configured amount of hops. | |
323 | */ | |
324 | uint8_t bfd_sess_hop_count(const struct bfd_session_params *bsp); | |
325 | ||
326 | /** | |
327 | * Get BFD session profile configured value. | |
328 | * | |
329 | * \param bsp session parameters. | |
330 | * | |
331 | * \returns configured profile name (or `NULL` if empty). | |
332 | */ | |
333 | const char *bfd_sess_profile(const struct bfd_session_params *bsp); | |
334 | ||
335 | /** | |
336 | * Get BFD session addresses. | |
337 | * | |
338 | * \param bsp session parameters. | |
339 | * \param family the address family being used (AF_INET or AF_INET6). | |
340 | * \param src source address (optional, may be `NULL`). | |
341 | * \param dst peer address (optional, may be `NULL`). | |
342 | */ | |
343 | void bfd_sess_addresses(const struct bfd_session_params *bsp, int *family, | |
344 | struct in6_addr *src, struct in6_addr *dst); | |
345 | /** | |
346 | * Get BFD session interface name. | |
347 | * | |
348 | * \param bsp session parameters. | |
349 | * | |
350 | * \returns `NULL` if not set otherwise the interface name. | |
351 | */ | |
352 | const char *bfd_sess_interface(const struct bfd_session_params *bsp); | |
353 | ||
354 | /** | |
355 | * Get BFD session VRF name. | |
356 | * | |
357 | * \param bsp session parameters. | |
358 | * | |
359 | * \returns the VRF name. | |
360 | */ | |
361 | const char *bfd_sess_vrf(const struct bfd_session_params *bsp); | |
362 | ||
363 | /** | |
364 | * Get BFD session VRF ID. | |
365 | * | |
366 | * \param bsp session parameters. | |
367 | * | |
368 | * \returns the VRF name. | |
369 | */ | |
370 | vrf_id_t bfd_sess_vrf_id(const struct bfd_session_params *bsp); | |
371 | ||
372 | /** | |
373 | * Get BFD session control plane independent bit configuration state. | |
374 | * | |
375 | * \param bsp session parameters. | |
376 | * | |
377 | * \returns `true` if enabled otherwise `false`. | |
378 | */ | |
379 | bool bfd_sess_cbit(const struct bfd_session_params *bsp); | |
380 | ||
381 | /** | |
382 | * DEPRECATED: please avoid using timers directly and use profiles instead. | |
383 | * | |
384 | * Gets the configured timers. | |
385 | * | |
386 | * \param bsp BFD session parameters. | |
387 | * \param detection_multiplier the detection multiplier value. | |
388 | * \param min_rx minimum required receive period. | |
389 | * \param min_tx minimum required transmission period. | |
390 | */ | |
391 | void bfd_sess_timers(const struct bfd_session_params *bsp, | |
392 | uint8_t *detection_multiplier, uint32_t *min_rx, | |
393 | uint32_t *min_tx); | |
394 | ||
395 | /** | |
396 | * Show BFD session configuration and status. If `json` is provided (e.g. not | |
397 | * `NULL`) then information will be inserted in object, otherwise printed to | |
398 | * `vty`. | |
399 | * | |
400 | * \param vty Pointer to `vty` for outputting text. | |
401 | * \param json (optional) JSON object pointer. | |
402 | * \param bsp session parameters. | |
403 | */ | |
404 | void bfd_sess_show(struct vty *vty, struct json_object *json, | |
405 | struct bfd_session_params *bsp); | |
406 | ||
407 | /** | |
408 | * Initializes the BFD integration library. This function executes the | |
409 | * following actions: | |
410 | * | |
411 | * - Copy the `struct thread_master` pointer to use as "thread" to execute | |
412 | * the BFD session parameters installation. | |
413 | * - Copy the `struct zclient` pointer to install its callbacks. | |
414 | * - Initializes internal data structures. | |
415 | * | |
416 | * \param tm normally the daemon main thread event manager. | |
417 | * \param zc the zebra client of the daemon. | |
418 | */ | |
419 | void bfd_protocol_integration_init(struct zclient *zc, | |
420 | struct thread_master *tm); | |
421 | ||
18322efd RZ |
422 | /** |
423 | * BFD session registration arguments. | |
424 | */ | |
425 | struct bfd_session_arg { | |
426 | /** | |
427 | * BFD command. | |
428 | * | |
429 | * Valid commands: | |
430 | * - `ZEBRA_BFD_DEST_REGISTER` | |
431 | * - `ZEBRA_BFD_DEST_DEREGISTER` | |
432 | */ | |
433 | int32_t command; | |
434 | ||
435 | /** | |
436 | * BFD family type. | |
437 | * | |
438 | * Supported types: | |
439 | * - `AF_INET` | |
440 | * - `AF_INET6`. | |
441 | */ | |
442 | uint32_t family; | |
443 | /** Source address. */ | |
444 | struct in6_addr src; | |
445 | /** Source address. */ | |
446 | struct in6_addr dst; | |
447 | ||
448 | /** Multi hop indicator. */ | |
449 | uint8_t mhop; | |
450 | /** Expected TTL. */ | |
451 | uint8_t ttl; | |
452 | /** C bit (Control Plane Independent bit) indicator. */ | |
453 | uint8_t cbit; | |
454 | ||
455 | /** Interface name size. */ | |
456 | uint8_t ifnamelen; | |
457 | /** Interface name. */ | |
458 | char ifname[64]; | |
459 | ||
460 | /** Daemon or session VRF. */ | |
461 | vrf_id_t vrf_id; | |
462 | ||
463 | /** Profile name length. */ | |
464 | uint8_t profilelen; | |
465 | /** Profile name. */ | |
466 | char profile[BFD_PROFILE_NAME_LEN]; | |
467 | ||
468 | /* | |
469 | * Deprecation fields: these fields should be removed once `ptm-bfd` | |
470 | * no longer uses this interface. | |
471 | */ | |
472 | ||
473 | /** Minimum required receive interval (in microseconds). */ | |
474 | uint32_t min_rx; | |
475 | /** Minimum desired transmission interval (in microseconds). */ | |
476 | uint32_t min_tx; | |
477 | /** Detection multiplier. */ | |
478 | uint32_t detection_multiplier; | |
479 | ||
480 | /** BFD client information output. */ | |
481 | struct bfd_info *bfd_info; | |
482 | ||
483 | /** Write registration indicator. */ | |
484 | uint8_t set_flag; | |
485 | }; | |
486 | ||
487 | /** | |
488 | * Send a message to BFD daemon through the zebra client. | |
489 | * | |
490 | * \param zc the zebra client context. | |
491 | * \param arg the BFD session command arguments. | |
492 | * | |
493 | * \returns `-1` on failure otherwise `0`. | |
494 | * | |
495 | * \see bfd_session_arg. | |
496 | */ | |
497 | extern int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *arg); | |
498 | ||
a099abe5 RZ |
499 | /** |
500 | * Enables or disables BFD protocol integration API debugging. | |
501 | * | |
502 | * \param enable new API debug state. | |
503 | */ | |
504 | extern void bfd_protocol_integration_set_debug(bool enable); | |
505 | ||
506 | /** | |
507 | * Sets shutdown mode so no more events are processed. | |
508 | * | |
509 | * This is useful to avoid the event storm that happens caused by network, | |
510 | * interfaces or VRFs removal. It should also avoid some crashes due hanging | |
511 | * pointers left overs by protocol. | |
512 | * | |
513 | * \param enable new API shutdown state. | |
514 | */ | |
515 | extern void bfd_protocol_integration_set_shutdown(bool enable); | |
516 | ||
517 | /** | |
518 | * Get API debugging state. | |
519 | */ | |
520 | extern bool bfd_protocol_integration_debug(void); | |
521 | ||
522 | /** | |
523 | * Get API shutdown state. | |
524 | */ | |
525 | extern bool bfd_protocol_integration_shutting_down(void); | |
526 | ||
5e244469 RW |
527 | #ifdef __cplusplus |
528 | } | |
529 | #endif | |
530 | ||
7f342629 | 531 | #endif /* _ZEBRA_BFD_H */ |