]> git.proxmox.com Git - mirror_frr.git/blob - bfdd/bfd.h
Merge pull request #13082 from inspurSDN/bugfix_zebra_crash_rebooting
[mirror_frr.git] / bfdd / bfd.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*********************************************************************
3 * Copyright 2014,2015,2016,2017 Cumulus Networks, Inc. All rights reserved.
4 *
5 * bfd.h: implements the BFD protocol.
6 */
7
8 #ifndef _BFD_H_
9 #define _BFD_H_
10
11 #include <netinet/in.h>
12
13 #include <stdbool.h>
14 #include <stdarg.h>
15 #include <stdint.h>
16
17 #include "lib/hash.h"
18 #include "lib/libfrr.h"
19 #include "lib/qobj.h"
20 #include "lib/queue.h"
21 #include "lib/vrf.h"
22
23 #include "bfdctl.h"
24
25 #ifdef BFD_DEBUG
26 #define BFDD_JSON_CONV_OPTIONS (JSON_C_TO_STRING_PRETTY)
27 #else
28 #define BFDD_JSON_CONV_OPTIONS (0)
29 #endif
30
31 DECLARE_MGROUP(BFDD);
32 DECLARE_MTYPE(BFDD_CONTROL);
33 DECLARE_MTYPE(BFDD_NOTIFICATION);
34
35 struct bfd_timers {
36 uint32_t desired_min_tx;
37 uint32_t required_min_rx;
38 uint32_t required_min_echo;
39 };
40
41 struct bfd_discrs {
42 uint32_t my_discr;
43 uint32_t remote_discr;
44 };
45
46 /*
47 * Format of control packet. From section 4)
48 */
49 struct bfd_pkt {
50 union {
51 uint32_t byteFields;
52 struct {
53 uint8_t diag;
54 uint8_t flags;
55 uint8_t detect_mult;
56 uint8_t len;
57 };
58 };
59 struct bfd_discrs discrs;
60 struct bfd_timers timers;
61 };
62
63 /*
64 * Format of Echo packet.
65 */
66 struct bfd_echo_pkt {
67 union {
68 uint32_t byteFields;
69 struct {
70 uint8_t ver;
71 uint8_t len;
72 uint16_t reserved;
73 };
74 };
75 uint32_t my_discr;
76 uint64_t time_sent_sec;
77 uint64_t time_sent_usec;
78 };
79
80
81 /* Macros for manipulating control packets */
82 #define BFD_VERMASK 0x03
83 #define BFD_DIAGMASK 0x1F
84 #define BFD_GETVER(diag) ((diag >> 5) & BFD_VERMASK)
85 #define BFD_SETVER(diag, val) ((diag) |= (val & BFD_VERMASK) << 5)
86 #define BFD_VERSION 1
87 #define BFD_PBIT 0x20
88 #define BFD_FBIT 0x10
89 #define BFD_CBIT 0x08
90 #define BFD_ABIT 0x04
91 #define BFD_DEMANDBIT 0x02
92 #define BFD_SETDEMANDBIT(flags, val) \
93 { \
94 if ((val)) \
95 flags |= BFD_DEMANDBIT; \
96 }
97 #define BFD_SETPBIT(flags, val) \
98 { \
99 if ((val)) \
100 flags |= BFD_PBIT; \
101 }
102 #define BFD_GETPBIT(flags) (flags & BFD_PBIT)
103 #define BFD_SETFBIT(flags, val) \
104 { \
105 if ((val)) \
106 flags |= BFD_FBIT; \
107 }
108 #define BFD_GETFBIT(flags) (flags & BFD_FBIT)
109 #define BFD_SETSTATE(flags, val) \
110 { \
111 if ((val)) \
112 flags |= (val & 0x3) << 6; \
113 }
114 #define BFD_GETSTATE(flags) ((flags >> 6) & 0x3)
115 #define BFD_SETCBIT(flags, val) \
116 { \
117 if ((val)) \
118 flags |= val; \
119 }
120 #define BFD_GETCBIT(flags) (flags & BFD_FBIT)
121 #define BFD_ECHO_VERSION 1
122 #define BFD_ECHO_PKT_LEN sizeof(struct bfd_echo_pkt)
123
124 enum bfd_diagnosticis {
125 BD_OK = 0,
126 /* Control Detection Time Expired. */
127 BD_CONTROL_EXPIRED = 1,
128 /* Echo Function Failed. */
129 BD_ECHO_FAILED = 2,
130 /* Neighbor Signaled Session Down. */
131 BD_NEIGHBOR_DOWN = 3,
132 /* Forwarding Plane Reset. */
133 BD_FORWARDING_RESET = 4,
134 /* Path Down. */
135 BD_PATH_DOWN = 5,
136 /* Concatenated Path Down. */
137 BD_CONCATPATH_DOWN = 6,
138 /* Administratively Down. */
139 BD_ADMIN_DOWN = 7,
140 /* Reverse Concatenated Path Down. */
141 BD_REVCONCATPATH_DOWN = 8,
142 /* 9..31: reserved. */
143 };
144
145 /* BFD session flags */
146 enum bfd_session_flags {
147 BFD_SESS_FLAG_NONE = 0,
148 BFD_SESS_FLAG_ECHO = 1 << 0, /* BFD Echo functionality */
149 BFD_SESS_FLAG_ECHO_ACTIVE = 1 << 1, /* BFD Echo Packets are being sent
150 * actively
151 */
152 BFD_SESS_FLAG_MH = 1 << 2, /* BFD Multi-hop session */
153 BFD_SESS_FLAG_IPV6 = 1 << 4, /* BFD IPv6 session */
154 BFD_SESS_FLAG_SEND_EVT_ACTIVE = 1 << 5, /* send event timer active */
155 BFD_SESS_FLAG_SEND_EVT_IGNORE = 1 << 6, /* ignore send event when timer
156 * expires
157 */
158 BFD_SESS_FLAG_SHUTDOWN = 1 << 7, /* disable BGP peer function */
159 BFD_SESS_FLAG_CONFIG = 1 << 8, /* Session configured with bfd NB API */
160 BFD_SESS_FLAG_CBIT = 1 << 9, /* CBIT is set */
161 BFD_SESS_FLAG_PASSIVE = 1 << 10, /* Passive mode */
162 BFD_SESS_FLAG_MAC_SET = 1 << 11, /* MAC of peer known */
163 };
164
165 /*
166 * BFD session hash key.
167 *
168 * This structure must not have any padding bytes because their value is
169 * unspecified after the struct assignment. Even when all fields of two keys
170 * are the same, if the padding bytes are different, then the calculated hash
171 * value is different, and the hash lookup will fail.
172 *
173 * Currently, the structure fields are correctly aligned, and the "packed"
174 * attribute is added as a precaution. "family" and "mhop" fields are two-bytes
175 * to eliminate unaligned memory access to "peer" and "local".
176 */
177 struct bfd_key {
178 uint16_t family;
179 uint16_t mhop;
180 struct in6_addr peer;
181 struct in6_addr local;
182 char ifname[INTERFACE_NAMSIZ];
183 char vrfname[VRF_NAMSIZ];
184 } __attribute__((packed));
185
186 struct bfd_session_stats {
187 uint64_t rx_ctrl_pkt;
188 uint64_t tx_ctrl_pkt;
189 uint64_t rx_echo_pkt;
190 uint64_t tx_echo_pkt;
191 uint64_t session_up;
192 uint64_t session_down;
193 uint64_t znotification;
194 };
195
196 /**
197 * BFD session profile to override default configurations.
198 */
199 struct bfd_profile {
200 /** Profile name. */
201 char name[64];
202
203 /** Session detection multiplier. */
204 uint8_t detection_multiplier;
205 /** Desired transmission interval (in microseconds). */
206 uint32_t min_tx;
207 /** Minimum required receive interval (in microseconds). */
208 uint32_t min_rx;
209 /** Administrative state. */
210 bool admin_shutdown;
211 /** Passive mode. */
212 bool passive;
213 /** Minimum expected TTL value. */
214 uint8_t minimum_ttl;
215
216 /** Echo mode (only applies to single hop). */
217 bool echo_mode;
218 /** Desired echo transmission interval (in microseconds). */
219 uint32_t min_echo_tx;
220 /** Minimum required echo receive interval (in microseconds). */
221 uint32_t min_echo_rx;
222
223 /** Profile list entry. */
224 TAILQ_ENTRY(bfd_profile) entry;
225 };
226
227 /** Profile list type. */
228 TAILQ_HEAD(bfdproflist, bfd_profile);
229
230 /* bfd_session shortcut label forwarding. */
231 struct peer_label;
232
233 struct bfd_config_timers {
234 uint32_t desired_min_tx;
235 uint32_t required_min_rx;
236 uint32_t desired_min_echo_tx;
237 uint32_t required_min_echo_rx;
238 };
239
240 #define BFD_RTT_SAMPLE 8
241
242 /*
243 * Session state information
244 */
245 struct bfd_session {
246
247 /* protocol state per RFC 5880*/
248 uint8_t ses_state;
249 struct bfd_discrs discrs;
250 uint8_t local_diag;
251 uint8_t demand_mode;
252 uint8_t detect_mult;
253 uint8_t remote_detect_mult;
254 uint8_t mh_ttl;
255 uint8_t remote_cbit;
256
257 /** BFD profile name. */
258 char *profile_name;
259 /** BFD pre configured profile. */
260 struct bfd_profile *profile;
261 /** BFD peer configuration (without profile). */
262 struct bfd_profile peer_profile;
263
264 /* Timers */
265 struct bfd_config_timers timers;
266 struct bfd_timers cur_timers;
267 uint64_t detect_TO;
268 struct event *echo_recvtimer_ev;
269 struct event *recvtimer_ev;
270 uint64_t xmt_TO;
271 uint64_t echo_xmt_TO;
272 struct event *xmttimer_ev;
273 struct event *echo_xmttimer_ev;
274 uint64_t echo_detect_TO;
275
276 /* software object state */
277 uint8_t polling;
278
279 /* This and the localDiscr are the keys to state info */
280 struct bfd_key key;
281 struct peer_label *pl;
282
283 struct bfd_dplane_ctx *bdc;
284 struct sockaddr_any local_address;
285 uint8_t peer_hw_addr[ETH_ALEN];
286 struct interface *ifp;
287 struct vrf *vrf;
288
289 int sock;
290
291 /* BFD session flags */
292 enum bfd_session_flags flags;
293
294 struct bfd_session_stats stats;
295
296 struct timeval uptime; /* last up time */
297 struct timeval downtime; /* last down time */
298
299 /* Remote peer data (for debugging mostly) */
300 uint8_t remote_diag;
301 struct bfd_timers remote_timers;
302
303 uint64_t refcount; /* number of pointers referencing this. */
304
305 uint8_t rtt_valid; /* number of valid samples */
306 uint8_t rtt_index; /* last index added */
307 uint64_t rtt[BFD_RTT_SAMPLE]; /* RRT in usec for echo to be looped */
308 };
309
310 struct peer_label {
311 TAILQ_ENTRY(peer_label) pl_entry;
312
313 struct bfd_session *pl_bs;
314 char pl_label[MAXNAMELEN];
315 };
316 TAILQ_HEAD(pllist, peer_label);
317
318 struct bfd_diag_str_list {
319 const char *str;
320 int type;
321 };
322
323 struct bfd_state_str_list {
324 const char *str;
325 int type;
326 };
327
328 struct bfd_session_observer {
329 struct bfd_session *bso_bs;
330 char bso_entryname[MAXNAMELEN];
331 struct prefix bso_addr;
332
333 TAILQ_ENTRY(bfd_session_observer) bso_entry;
334 };
335 TAILQ_HEAD(obslist, bfd_session_observer);
336
337
338 /* States defined per 4.1 */
339 #define PTM_BFD_ADM_DOWN 0
340 #define PTM_BFD_DOWN 1
341 #define PTM_BFD_INIT 2
342 #define PTM_BFD_UP 3
343
344
345 /* Various constants */
346 /* Retrieved from ptm_timer.h from Cumulus PTM sources. */
347 #define BFD_DEF_DEMAND 0
348 #define BFD_DEFDETECTMULT 3
349 #define BFD_DEFDESIREDMINTX (300 * 1000) /* microseconds. */
350 #define BFD_DEFREQUIREDMINRX (300 * 1000) /* microseconds. */
351 #define BFD_DEF_DES_MIN_ECHO_TX (50 * 1000) /* microseconds. */
352 #define BFD_DEF_REQ_MIN_ECHO_RX (50 * 1000) /* microseconds. */
353 #define BFD_DEF_SLOWTX (1000 * 1000) /* microseconds. */
354 /** Minimum multi hop TTL. */
355 #define BFD_DEF_MHOP_TTL 254
356 #define BFD_PKT_LEN 24 /* Length of control packet */
357 #define BFD_TTL_VAL 255
358 #define BFD_RCV_TTL_VAL 1
359 #define BFD_TOS_VAL 0xC0
360 #define BFD_PKT_INFO_VAL 1
361 #define BFD_IPV6_PKT_INFO_VAL 1
362 #define BFD_IPV6_ONLY_VAL 1
363 #define BFD_SRCPORTINIT 49152
364 #define BFD_SRCPORTMAX 65535
365 #define BFD_DEFDESTPORT 3784
366 #define BFD_DEF_ECHO_PORT 3785
367 #define BFD_DEF_MHOP_DEST_PORT 4784
368
369 /*
370 * control.c
371 *
372 * Daemon control code to speak with local consumers.
373 */
374
375 /* See 'bfdctrl.h' for client protocol definitions. */
376
377 struct bfd_control_buffer {
378 size_t bcb_left;
379 size_t bcb_pos;
380 union {
381 struct bfd_control_msg *bcb_bcm;
382 uint8_t *bcb_buf;
383 };
384 };
385
386 struct bfd_control_queue {
387 TAILQ_ENTRY(bfd_control_queue) bcq_entry;
388
389 struct bfd_control_buffer bcq_bcb;
390 };
391 TAILQ_HEAD(bcqueue, bfd_control_queue);
392
393 struct bfd_notify_peer {
394 TAILQ_ENTRY(bfd_notify_peer) bnp_entry;
395
396 struct bfd_session *bnp_bs;
397 };
398 TAILQ_HEAD(bnplist, bfd_notify_peer);
399
400 struct bfd_control_socket {
401 TAILQ_ENTRY(bfd_control_socket) bcs_entry;
402
403 int bcs_sd;
404 struct event *bcs_ev;
405 struct event *bcs_outev;
406 struct bcqueue bcs_bcqueue;
407
408 /* Notification data */
409 uint64_t bcs_notify;
410 struct bnplist bcs_bnplist;
411
412 enum bc_msg_version bcs_version;
413 enum bc_msg_type bcs_type;
414
415 /* Message buffering */
416 struct bfd_control_buffer bcs_bin;
417 struct bfd_control_buffer *bcs_bout;
418 };
419 TAILQ_HEAD(bcslist, bfd_control_socket);
420
421 int control_init(const char *path);
422 void control_shutdown(void);
423 int control_notify(struct bfd_session *bs, uint8_t notify_state);
424 int control_notify_config(const char *op, struct bfd_session *bs);
425 void control_accept(struct event *t);
426
427
428 /*
429 * bfdd.c
430 *
431 * Daemon specific code.
432 */
433 struct bfd_vrf_global {
434 int bg_shop;
435 int bg_mhop;
436 int bg_shop6;
437 int bg_mhop6;
438 int bg_echo;
439 int bg_echov6;
440 struct vrf *vrf;
441
442 struct event *bg_ev[6];
443 };
444
445 /* Forward declaration of data plane context struct. */
446 struct bfd_dplane_ctx;
447 TAILQ_HEAD(dplane_queue, bfd_dplane_ctx);
448
449 struct bfd_global {
450 int bg_csock;
451 struct event *bg_csockev;
452 struct bcslist bg_bcslist;
453
454 struct pllist bg_pllist;
455
456 struct obslist bg_obslist;
457
458 struct zebra_privs_t bfdd_privs;
459
460 /**
461 * Daemon is exit()ing? Use this to avoid actions that expect a
462 * running system or to avoid unnecessary operations when quitting.
463 */
464 bool bg_shutdown;
465
466 /* Distributed BFD items. */
467 bool bg_use_dplane;
468 int bg_dplane_sock;
469 struct event *bg_dplane_sockev;
470 struct dplane_queue bg_dplaneq;
471
472 /* Debug options. */
473 /* Show distributed BFD debug messages. */
474 bool debug_dplane;
475 /* Show all peer state changes events. */
476 bool debug_peer_event;
477 /*
478 * Show zebra message exchanges:
479 * - Interface add/delete.
480 * - Local address add/delete.
481 * - VRF add/delete.
482 */
483 bool debug_zebra;
484 /*
485 * Show network level debug information:
486 * - Echo packets without session.
487 * - Unavailable peer sessions.
488 * - Network system call failures.
489 */
490 bool debug_network;
491 };
492
493 extern struct bfd_global bglobal;
494 extern const struct bfd_diag_str_list diag_list[];
495 extern const struct bfd_state_str_list state_list[];
496
497 void socket_close(int *s);
498
499
500 /*
501 * config.c
502 *
503 * Contains the code related with loading/reloading configuration.
504 */
505 int parse_config(const char *fname);
506 int config_request_add(const char *jsonstr);
507 int config_request_del(const char *jsonstr);
508 char *config_response(const char *status, const char *error);
509 char *config_notify(struct bfd_session *bs);
510 char *config_notify_config(const char *op, struct bfd_session *bs);
511
512 typedef int (*bpc_handle)(struct bfd_peer_cfg *, void *arg);
513 int config_notify_request(struct bfd_control_socket *bcs, const char *jsonstr,
514 bpc_handle bh);
515
516 struct peer_label *pl_new(const char *label, struct bfd_session *bs);
517 struct peer_label *pl_find(const char *label);
518 void pl_free(struct peer_label *pl);
519
520
521 /*
522 * logging - alias to zebra log
523 */
524 #define zlog_fatal(msg, ...) \
525 do { \
526 zlog_err(msg, ##__VA_ARGS__); \
527 assert(!msg); \
528 abort(); \
529 } while (0)
530
531
532 /*
533 * bfd_packet.c
534 *
535 * Contains the code related with receiving/seding, packing/unpacking BFD data.
536 */
537 int bp_set_ttlv6(int sd, uint8_t value);
538 int bp_set_ttl(int sd, uint8_t value);
539 int bp_set_tosv6(int sd, uint8_t value);
540 int bp_set_tos(int sd, uint8_t value);
541 int bp_bind_dev(int sd, const char *dev);
542
543 int bp_udp_shop(const struct vrf *vrf);
544 int bp_udp_mhop(const struct vrf *vrf);
545 int bp_udp6_shop(const struct vrf *vrf);
546 int bp_udp6_mhop(const struct vrf *vrf);
547 int bp_peer_socket(const struct bfd_session *bs);
548 int bp_peer_socketv6(const struct bfd_session *bs);
549 int bp_echo_socket(const struct vrf *vrf);
550 int bp_echov6_socket(const struct vrf *vrf);
551
552 void ptm_bfd_snd(struct bfd_session *bfd, int fbit);
553 void ptm_bfd_echo_snd(struct bfd_session *bfd);
554 void ptm_bfd_echo_fp_snd(struct bfd_session *bfd);
555
556 void bfd_recv_cb(struct event *t);
557
558
559 /*
560 * event.c
561 *
562 * Contains the code related with event loop.
563 */
564 typedef void (*bfd_ev_cb)(struct event *t);
565
566 void bfd_recvtimer_update(struct bfd_session *bs);
567 void bfd_echo_recvtimer_update(struct bfd_session *bs);
568 void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter);
569 void bfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter);
570
571 void bfd_xmttimer_delete(struct bfd_session *bs);
572 void bfd_echo_xmttimer_delete(struct bfd_session *bs);
573 void bfd_recvtimer_delete(struct bfd_session *bs);
574 void bfd_echo_recvtimer_delete(struct bfd_session *bs);
575
576 void bfd_recvtimer_assign(struct bfd_session *bs, bfd_ev_cb cb, int sd);
577 void bfd_echo_recvtimer_assign(struct bfd_session *bs, bfd_ev_cb cb, int sd);
578 void bfd_xmttimer_assign(struct bfd_session *bs, bfd_ev_cb cb);
579 void bfd_echo_xmttimer_assign(struct bfd_session *bs, bfd_ev_cb cb);
580
581
582 /*
583 * bfd.c
584 *
585 * BFD protocol specific code.
586 */
587 int bfd_session_enable(struct bfd_session *bs);
588 void bfd_session_disable(struct bfd_session *bs);
589 struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc);
590 int ptm_bfd_sess_del(struct bfd_peer_cfg *bpc);
591 void ptm_bfd_sess_dn(struct bfd_session *bfd, uint8_t diag);
592 void ptm_bfd_sess_up(struct bfd_session *bfd);
593 void ptm_bfd_echo_stop(struct bfd_session *bfd);
594 void ptm_bfd_echo_start(struct bfd_session *bfd);
595 void ptm_bfd_xmt_TO(struct bfd_session *bfd, int fbit);
596 void ptm_bfd_start_xmt_timer(struct bfd_session *bfd, bool is_echo);
597 struct bfd_session *ptm_bfd_sess_find(struct bfd_pkt *cp,
598 struct sockaddr_any *peer,
599 struct sockaddr_any *local,
600 struct interface *ifp,
601 vrf_id_t vrfid,
602 bool is_mhop);
603
604 struct bfd_session *bs_peer_find(struct bfd_peer_cfg *bpc);
605 int bfd_session_update_label(struct bfd_session *bs, const char *nlabel);
606 void bfd_set_polling(struct bfd_session *bs);
607 void bs_state_handler(struct bfd_session *bs, int nstate);
608 void bs_echo_timer_handler(struct bfd_session *bs);
609 void bs_final_handler(struct bfd_session *bs);
610 void bs_set_slow_timers(struct bfd_session *bs);
611 const char *satostr(const struct sockaddr_any *sa);
612 const char *diag2str(uint8_t diag);
613 int strtosa(const char *addr, struct sockaddr_any *sa);
614 void integer2timestr(uint64_t time, char *buf, size_t buflen);
615 const char *bs_to_string(const struct bfd_session *bs);
616
617 int bs_observer_add(struct bfd_session *bs);
618 void bs_observer_del(struct bfd_session_observer *bso);
619
620 void bs_to_bpc(struct bfd_session *bs, struct bfd_peer_cfg *bpc);
621
622 void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer,
623 struct sockaddr_any *local, bool mhop, const char *ifname,
624 const char *vrfname);
625 struct bfd_session *bfd_session_new(void);
626 struct bfd_session *bs_registrate(struct bfd_session *bs);
627 void bfd_session_free(struct bfd_session *bs);
628 const struct bfd_session *bfd_session_next(const struct bfd_session *bs,
629 bool mhop);
630 void bfd_sessions_remove_manual(void);
631 void bfd_profiles_remove(void);
632 void bfd_rtt_init(struct bfd_session *bfd);
633
634 /**
635 * Set the BFD session echo state.
636 *
637 * \param bs the BFD session.
638 * \param echo the echo operational state.
639 */
640 void bfd_set_echo(struct bfd_session *bs, bool echo);
641
642 /**
643 * Set the BFD session functional state.
644 *
645 * \param bs the BFD session.
646 * \param shutdown the operational value.
647 */
648 void bfd_set_shutdown(struct bfd_session *bs, bool shutdown);
649
650 /**
651 * Set the BFD session passive mode.
652 *
653 * \param bs the BFD session.
654 * \param passive the passive mode.
655 */
656 void bfd_set_passive_mode(struct bfd_session *bs, bool passive);
657
658 /**
659 * Picks the BFD session configuration from the appropriated source:
660 * if using the default peer configuration prefer profile (if it exists),
661 * otherwise use session.
662 *
663 * \param bs the BFD session.
664 */
665 void bfd_session_apply(struct bfd_session *bs);
666
667 /* BFD hash data structures interface */
668 void bfd_initialize(void);
669 void bfd_shutdown(void);
670 void bfd_vrf_init(void);
671 void bfd_vrf_terminate(void);
672 struct bfd_vrf_global *bfd_vrf_look_by_session(struct bfd_session *bfd);
673 struct bfd_session *bfd_id_lookup(uint32_t id);
674 struct bfd_session *bfd_key_lookup(struct bfd_key key);
675
676 struct bfd_session *bfd_id_delete(uint32_t id);
677 struct bfd_session *bfd_key_delete(struct bfd_key key);
678
679 bool bfd_id_insert(struct bfd_session *bs);
680 bool bfd_key_insert(struct bfd_session *bs);
681
682 typedef void (*hash_iter_func)(struct hash_bucket *hb, void *arg);
683 void bfd_id_iterate(hash_iter_func hif, void *arg);
684 void bfd_key_iterate(hash_iter_func hif, void *arg);
685
686 unsigned long bfd_get_session_count(void);
687
688 /* Export callback functions for `event.c`. */
689 extern struct event_loop *master;
690
691 void bfd_recvtimer_cb(struct event *t);
692 void bfd_echo_recvtimer_cb(struct event *t);
693 void bfd_xmt_cb(struct event *t);
694 void bfd_echo_xmt_cb(struct event *t);
695
696 extern struct in6_addr zero_addr;
697
698 /**
699 * Creates a new profile entry and insert into the global list.
700 *
701 * \param name the BFD profile name.
702 *
703 * \returns `NULL` if it already exists otherwise the new entry.
704 */
705 struct bfd_profile *bfd_profile_new(const char *name);
706
707 /**
708 * Search for configured BFD profiles (profile name is case insensitive).
709 *
710 * \param name the BFD profile name.
711 *
712 * \returns `NULL` if it doesn't exist otherwise the entry.
713 */
714 struct bfd_profile *bfd_profile_lookup(const char *name);
715
716 /**
717 * Removes profile from list and free memory.
718 *
719 * \param bp the BFD profile.
720 */
721 void bfd_profile_free(struct bfd_profile *bp);
722
723 /**
724 * Apply a profile configuration to an existing BFD session. The non default
725 * values will not be overridden.
726 *
727 * NOTE: if the profile doesn't exist yet, then the profile will be applied
728 * once it begins to exist.
729 *
730 * \param profile_name the BFD profile name.
731 * \param bs the BFD session.
732 */
733 void bfd_profile_apply(const char *profname, struct bfd_session *bs);
734
735 /**
736 * Remove any applied profile from session and revert the session
737 * configuration.
738 *
739 * \param bs the BFD session.
740 */
741 void bfd_profile_remove(struct bfd_session *bs);
742
743 /**
744 * Apply new profile values to sessions using it.
745 *
746 * \param[in] bp the BFD profile that got updated.
747 */
748 void bfd_profile_update(struct bfd_profile *bp);
749
750 /*
751 * bfdd_vty.c
752 *
753 * BFD daemon vty shell commands.
754 */
755 void bfdd_vty_init(void);
756
757
758 /*
759 * bfdd_cli.c
760 *
761 * BFD daemon CLI implementation.
762 */
763 void bfdd_cli_init(void);
764
765
766 /*
767 * ptm_adapter.c
768 */
769 void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv);
770 void bfdd_zclient_stop(void);
771 void bfdd_zclient_unregister(vrf_id_t vrf_id);
772 void bfdd_zclient_register(vrf_id_t vrf_id);
773 void bfdd_sessions_enable_vrf(struct vrf *vrf);
774 void bfdd_sessions_disable_vrf(struct vrf *vrf);
775
776 int ptm_bfd_notify(struct bfd_session *bs, uint8_t notify_state);
777
778 /*
779 * dplane.c
780 */
781
782 /**
783 * Initialize BFD data plane infrastructure for distributed BFD implementation.
784 *
785 * \param sa socket address.
786 * \param salen socket address structure length.
787 * \param client `true` means connecting socket, `false` listening socket.
788 */
789 void bfd_dplane_init(const struct sockaddr *sa, socklen_t salen, bool client);
790
791 /**
792 * Attempts to delegate the BFD session liveness detection to hardware.
793 *
794 * \param bs the BFD session data structure.
795 *
796 * \returns
797 * `0` on success and BFD daemon should do nothing or `-1` on failure
798 * and we should fallback to software implementation.
799 */
800 int bfd_dplane_add_session(struct bfd_session *bs);
801
802 /**
803 * Send new session settings to data plane.
804 *
805 * \param bs the BFD session to update.
806 */
807 int bfd_dplane_update_session(const struct bfd_session *bs);
808
809 /**
810 * Deletes session from data plane.
811 *
812 * \param bs the BFD session to delete.
813 *
814 * \returns `0` on success otherwise `-1`.
815 */
816 int bfd_dplane_delete_session(struct bfd_session *bs);
817
818 /**
819 * Asks the data plane for updated counters and update the session data
820 * structure.
821 *
822 * \param bs the BFD session that needs updating.
823 *
824 * \returns `0` on success otherwise `-1` on failure.
825 */
826 int bfd_dplane_update_session_counters(struct bfd_session *bs);
827
828 void bfd_dplane_show_counters(struct vty *vty);
829
830 #endif /* _BFD_H_ */