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