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