]>
Commit | Line | Data |
---|---|---|
e9e2c950 RZ |
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" | |
80edb675 | 34 | #include "lib/vrf.h" |
e9e2c950 RZ |
35 | |
36 | #include "bfdctl.h" | |
37 | ||
e9e2c950 RZ |
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 | ||
bf8d3d6a DL |
44 | DECLARE_MGROUP(BFDD); |
45 | DECLARE_MTYPE(BFDD_CONTROL); | |
46 | DECLARE_MTYPE(BFDD_NOTIFICATION); | |
e9e2c950 RZ |
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 | |
e9e2c950 RZ |
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) | |
9beff0bd PG |
127 | #define BFD_SETCBIT(flags, val) \ |
128 | { \ | |
129 | if ((val)) \ | |
130 | flags |= val; \ | |
131 | } | |
132 | #define BFD_GETCBIT(flags) (flags & BFD_FBIT) | |
e9e2c950 RZ |
133 | #define BFD_ECHO_VERSION 1 |
134 | #define BFD_ECHO_PKT_LEN sizeof(struct bfd_echo_pkt) | |
e9e2c950 | 135 | |
40675ea9 RZ |
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 | ||
e9e2c950 RZ |
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 */ | |
e9e2c950 RZ |
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 */ | |
6bdb4a42 | 171 | BFD_SESS_FLAG_CONFIG = 1 << 8, /* Session configured with bfd NB API */ |
9beff0bd | 172 | BFD_SESS_FLAG_CBIT = 1 << 9, /* CBIT is set */ |
1a2e2fff | 173 | BFD_SESS_FLAG_PASSIVE = 1 << 10, /* Passive mode */ |
e9e2c950 RZ |
174 | }; |
175 | ||
e9e2c950 | 176 | /* BFD session hash keys */ |
79b4a6fc RZ |
177 | struct bfd_key { |
178 | uint16_t family; | |
179 | uint8_t mhop; | |
180 | struct in6_addr peer; | |
181 | struct in6_addr local; | |
182 | char ifname[MAXNAMELEN]; | |
183 | char vrfname[MAXNAMELEN]; | |
e9e2c950 RZ |
184 | }; |
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; | |
0684c9b1 RZ |
191 | uint64_t session_up; |
192 | uint64_t session_down; | |
193 | uint64_t znotification; | |
e9e2c950 RZ |
194 | }; |
195 | ||
ccc9ada8 RZ |
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; | |
1a2e2fff RZ |
211 | /** Passive mode. */ |
212 | bool passive; | |
262e1d25 RZ |
213 | /** Minimum expected TTL value. */ |
214 | uint8_t minimum_ttl; | |
ccc9ada8 RZ |
215 | |
216 | /** Echo mode (only applies to single hop). */ | |
217 | bool echo_mode; | |
4df3e31c IR |
218 | /** Desired echo transmission interval (in microseconds). */ |
219 | uint32_t min_echo_tx; | |
ccc9ada8 RZ |
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 | ||
e9e2c950 RZ |
230 | /* bfd_session shortcut label forwarding. */ |
231 | struct peer_label; | |
232 | ||
4df3e31c IR |
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 | ||
e9e2c950 RZ |
240 | /* |
241 | * Session state information | |
242 | */ | |
243 | struct bfd_session { | |
244 | ||
245 | /* protocol state per RFC 5880*/ | |
246 | uint8_t ses_state; | |
247 | struct bfd_discrs discrs; | |
248 | uint8_t local_diag; | |
249 | uint8_t demand_mode; | |
250 | uint8_t detect_mult; | |
251 | uint8_t remote_detect_mult; | |
252 | uint8_t mh_ttl; | |
9beff0bd | 253 | uint8_t remote_cbit; |
e9e2c950 | 254 | |
ccc9ada8 RZ |
255 | /** BFD profile name. */ |
256 | char *profile_name; | |
257 | /** BFD pre configured profile. */ | |
258 | struct bfd_profile *profile; | |
259 | /** BFD peer configuration (without profile). */ | |
260 | struct bfd_profile peer_profile; | |
261 | ||
e9e2c950 | 262 | /* Timers */ |
4df3e31c | 263 | struct bfd_config_timers timers; |
f43b9368 | 264 | struct bfd_timers cur_timers; |
e9e2c950 RZ |
265 | uint64_t detect_TO; |
266 | struct thread *echo_recvtimer_ev; | |
267 | struct thread *recvtimer_ev; | |
268 | uint64_t xmt_TO; | |
269 | uint64_t echo_xmt_TO; | |
270 | struct thread *xmttimer_ev; | |
271 | struct thread *echo_xmttimer_ev; | |
272 | uint64_t echo_detect_TO; | |
273 | ||
274 | /* software object state */ | |
275 | uint8_t polling; | |
276 | ||
277 | /* This and the localDiscr are the keys to state info */ | |
79b4a6fc | 278 | struct bfd_key key; |
e9e2c950 | 279 | struct peer_label *pl; |
e9e2c950 | 280 | |
230aefe2 | 281 | struct bfd_dplane_ctx *bdc; |
e9e2c950 | 282 | struct sockaddr_any local_address; |
80edb675 | 283 | struct interface *ifp; |
b333abc2 | 284 | struct vrf *vrf; |
79b4a6fc RZ |
285 | |
286 | int sock; | |
e9e2c950 RZ |
287 | |
288 | /* BFD session flags */ | |
289 | enum bfd_session_flags flags; | |
290 | ||
e9e2c950 | 291 | struct bfd_session_stats stats; |
e9e2c950 RZ |
292 | |
293 | struct timeval uptime; /* last up time */ | |
294 | struct timeval downtime; /* last down time */ | |
295 | ||
296 | /* Remote peer data (for debugging mostly) */ | |
297 | uint8_t remote_diag; | |
298 | struct bfd_timers remote_timers; | |
299 | ||
300 | uint64_t refcount; /* number of pointers referencing this. */ | |
e9e2c950 | 301 | }; |
e9e2c950 RZ |
302 | |
303 | struct peer_label { | |
304 | TAILQ_ENTRY(peer_label) pl_entry; | |
305 | ||
306 | struct bfd_session *pl_bs; | |
307 | char pl_label[MAXNAMELEN]; | |
308 | }; | |
309 | TAILQ_HEAD(pllist, peer_label); | |
310 | ||
311 | struct bfd_diag_str_list { | |
312 | const char *str; | |
313 | int type; | |
314 | }; | |
315 | ||
316 | struct bfd_state_str_list { | |
317 | const char *str; | |
318 | int type; | |
319 | }; | |
320 | ||
d245e522 RZ |
321 | struct bfd_session_observer { |
322 | struct bfd_session *bso_bs; | |
ced291de RZ |
323 | char bso_entryname[MAXNAMELEN]; |
324 | struct prefix bso_addr; | |
d245e522 RZ |
325 | |
326 | TAILQ_ENTRY(bfd_session_observer) bso_entry; | |
327 | }; | |
328 | TAILQ_HEAD(obslist, bfd_session_observer); | |
329 | ||
e9e2c950 RZ |
330 | |
331 | /* States defined per 4.1 */ | |
332 | #define PTM_BFD_ADM_DOWN 0 | |
333 | #define PTM_BFD_DOWN 1 | |
334 | #define PTM_BFD_INIT 2 | |
335 | #define PTM_BFD_UP 3 | |
336 | ||
337 | ||
338 | /* Various constants */ | |
339 | /* Retrieved from ptm_timer.h from Cumulus PTM sources. */ | |
e9e2c950 RZ |
340 | #define BFD_DEF_DEMAND 0 |
341 | #define BFD_DEFDETECTMULT 3 | |
33400b46 RZ |
342 | #define BFD_DEFDESIREDMINTX (300 * 1000) /* microseconds. */ |
343 | #define BFD_DEFREQUIREDMINRX (300 * 1000) /* microseconds. */ | |
4df3e31c IR |
344 | #define BFD_DEF_DES_MIN_ECHO_TX (50 * 1000) /* microseconds. */ |
345 | #define BFD_DEF_REQ_MIN_ECHO_RX (50 * 1000) /* microseconds. */ | |
33400b46 | 346 | #define BFD_DEF_SLOWTX (1000 * 1000) /* microseconds. */ |
262e1d25 RZ |
347 | /** Minimum multi hop TTL. */ |
348 | #define BFD_DEF_MHOP_TTL 254 | |
e9e2c950 RZ |
349 | #define BFD_PKT_LEN 24 /* Length of control packet */ |
350 | #define BFD_TTL_VAL 255 | |
351 | #define BFD_RCV_TTL_VAL 1 | |
352 | #define BFD_TOS_VAL 0xC0 | |
353 | #define BFD_PKT_INFO_VAL 1 | |
354 | #define BFD_IPV6_PKT_INFO_VAL 1 | |
355 | #define BFD_IPV6_ONLY_VAL 1 | |
545d3f70 RZ |
356 | #define BFD_SRCPORTINIT 49152 |
357 | #define BFD_SRCPORTMAX 65535 | |
e9e2c950 RZ |
358 | #define BFD_DEFDESTPORT 3784 |
359 | #define BFD_DEF_ECHO_PORT 3785 | |
360 | #define BFD_DEF_MHOP_DEST_PORT 4784 | |
e9e2c950 RZ |
361 | |
362 | /* | |
363 | * control.c | |
364 | * | |
365 | * Daemon control code to speak with local consumers. | |
366 | */ | |
367 | ||
368 | /* See 'bfdctrl.h' for client protocol definitions. */ | |
369 | ||
370 | struct bfd_control_buffer { | |
371 | size_t bcb_left; | |
372 | size_t bcb_pos; | |
373 | union { | |
374 | struct bfd_control_msg *bcb_bcm; | |
375 | uint8_t *bcb_buf; | |
376 | }; | |
377 | }; | |
378 | ||
379 | struct bfd_control_queue { | |
380 | TAILQ_ENTRY(bfd_control_queue) bcq_entry; | |
381 | ||
382 | struct bfd_control_buffer bcq_bcb; | |
383 | }; | |
384 | TAILQ_HEAD(bcqueue, bfd_control_queue); | |
385 | ||
386 | struct bfd_notify_peer { | |
387 | TAILQ_ENTRY(bfd_notify_peer) bnp_entry; | |
388 | ||
389 | struct bfd_session *bnp_bs; | |
390 | }; | |
391 | TAILQ_HEAD(bnplist, bfd_notify_peer); | |
392 | ||
393 | struct bfd_control_socket { | |
394 | TAILQ_ENTRY(bfd_control_socket) bcs_entry; | |
395 | ||
396 | int bcs_sd; | |
397 | struct thread *bcs_ev; | |
398 | struct thread *bcs_outev; | |
399 | struct bcqueue bcs_bcqueue; | |
400 | ||
401 | /* Notification data */ | |
402 | uint64_t bcs_notify; | |
403 | struct bnplist bcs_bnplist; | |
404 | ||
405 | enum bc_msg_version bcs_version; | |
406 | enum bc_msg_type bcs_type; | |
407 | ||
408 | /* Message buffering */ | |
409 | struct bfd_control_buffer bcs_bin; | |
410 | struct bfd_control_buffer *bcs_bout; | |
411 | }; | |
412 | TAILQ_HEAD(bcslist, bfd_control_socket); | |
413 | ||
414 | int control_init(const char *path); | |
415 | void control_shutdown(void); | |
7555dc61 | 416 | int control_notify(struct bfd_session *bs, uint8_t notify_state); |
e9e2c950 RZ |
417 | int control_notify_config(const char *op, struct bfd_session *bs); |
418 | int control_accept(struct thread *t); | |
419 | ||
420 | ||
421 | /* | |
422 | * bfdd.c | |
423 | * | |
424 | * Daemon specific code. | |
425 | */ | |
7bcadbae | 426 | struct bfd_vrf_global { |
e9e2c950 RZ |
427 | int bg_shop; |
428 | int bg_mhop; | |
429 | int bg_shop6; | |
430 | int bg_mhop6; | |
431 | int bg_echo; | |
2f11c53f | 432 | int bg_echov6; |
7bcadbae PG |
433 | struct vrf *vrf; |
434 | ||
e9e2c950 | 435 | struct thread *bg_ev[6]; |
7bcadbae | 436 | }; |
e9e2c950 | 437 | |
230aefe2 RZ |
438 | /* Forward declaration of data plane context struct. */ |
439 | struct bfd_dplane_ctx; | |
440 | TAILQ_HEAD(dplane_queue, bfd_dplane_ctx); | |
441 | ||
7bcadbae | 442 | struct bfd_global { |
e9e2c950 RZ |
443 | int bg_csock; |
444 | struct thread *bg_csockev; | |
445 | struct bcslist bg_bcslist; | |
446 | ||
447 | struct pllist bg_pllist; | |
d245e522 RZ |
448 | |
449 | struct obslist bg_obslist; | |
f21536d2 PG |
450 | |
451 | struct zebra_privs_t bfdd_privs; | |
48da2c31 | 452 | |
f3e1d224 RZ |
453 | /** |
454 | * Daemon is exit()ing? Use this to avoid actions that expect a | |
455 | * running system or to avoid unnecessary operations when quitting. | |
456 | */ | |
457 | bool bg_shutdown; | |
458 | ||
230aefe2 RZ |
459 | /* Distributed BFD items. */ |
460 | bool bg_use_dplane; | |
461 | int bg_dplane_sock; | |
462 | struct thread *bg_dplane_sockev; | |
463 | struct dplane_queue bg_dplaneq; | |
464 | ||
48da2c31 | 465 | /* Debug options. */ |
230aefe2 RZ |
466 | /* Show distributed BFD debug messages. */ |
467 | bool debug_dplane; | |
48da2c31 RZ |
468 | /* Show all peer state changes events. */ |
469 | bool debug_peer_event; | |
470 | /* | |
471 | * Show zebra message exchanges: | |
472 | * - Interface add/delete. | |
473 | * - Local address add/delete. | |
474 | * - VRF add/delete. | |
475 | */ | |
476 | bool debug_zebra; | |
477 | /* | |
478 | * Show network level debug information: | |
479 | * - Echo packets without session. | |
480 | * - Unavailable peer sessions. | |
481 | * - Network system call failures. | |
482 | */ | |
483 | bool debug_network; | |
e9e2c950 | 484 | }; |
48da2c31 | 485 | |
e9e2c950 | 486 | extern struct bfd_global bglobal; |
2b64873d DL |
487 | extern const struct bfd_diag_str_list diag_list[]; |
488 | extern const struct bfd_state_str_list state_list[]; | |
e9e2c950 RZ |
489 | |
490 | void socket_close(int *s); | |
491 | ||
492 | ||
493 | /* | |
494 | * config.c | |
495 | * | |
496 | * Contains the code related with loading/reloading configuration. | |
497 | */ | |
498 | int parse_config(const char *fname); | |
499 | int config_request_add(const char *jsonstr); | |
500 | int config_request_del(const char *jsonstr); | |
501 | char *config_response(const char *status, const char *error); | |
502 | char *config_notify(struct bfd_session *bs); | |
503 | char *config_notify_config(const char *op, struct bfd_session *bs); | |
504 | ||
505 | typedef int (*bpc_handle)(struct bfd_peer_cfg *, void *arg); | |
506 | int config_notify_request(struct bfd_control_socket *bcs, const char *jsonstr, | |
507 | bpc_handle bh); | |
508 | ||
509 | struct peer_label *pl_new(const char *label, struct bfd_session *bs); | |
510 | struct peer_label *pl_find(const char *label); | |
511 | void pl_free(struct peer_label *pl); | |
512 | ||
513 | ||
514 | /* | |
d85b048d | 515 | * logging - alias to zebra log |
e9e2c950 | 516 | */ |
259b64eb | 517 | #define zlog_fatal(msg, ...) \ |
d85b048d | 518 | do { \ |
259b64eb | 519 | zlog_err(msg, ##__VA_ARGS__); \ |
d85b048d DL |
520 | assert(!msg); \ |
521 | abort(); \ | |
522 | } while (0) | |
e9e2c950 | 523 | |
e9e2c950 RZ |
524 | |
525 | /* | |
526 | * bfd_packet.c | |
527 | * | |
528 | * Contains the code related with receiving/seding, packing/unpacking BFD data. | |
529 | */ | |
6e01e275 RZ |
530 | int bp_set_ttlv6(int sd, uint8_t value); |
531 | int bp_set_ttl(int sd, uint8_t value); | |
532 | int bp_set_tosv6(int sd, uint8_t value); | |
533 | int bp_set_tos(int sd, uint8_t value); | |
e9e2c950 RZ |
534 | int bp_bind_dev(int sd, const char *dev); |
535 | ||
4a9feb66 RZ |
536 | int bp_udp_shop(const struct vrf *vrf); |
537 | int bp_udp_mhop(const struct vrf *vrf); | |
538 | int bp_udp6_shop(const struct vrf *vrf); | |
539 | int bp_udp6_mhop(const struct vrf *vrf); | |
9f37770f RZ |
540 | int bp_peer_socket(const struct bfd_session *bs); |
541 | int bp_peer_socketv6(const struct bfd_session *bs); | |
4a9feb66 RZ |
542 | int bp_echo_socket(const struct vrf *vrf); |
543 | int bp_echov6_socket(const struct vrf *vrf); | |
e9e2c950 RZ |
544 | |
545 | void ptm_bfd_snd(struct bfd_session *bfd, int fbit); | |
546 | void ptm_bfd_echo_snd(struct bfd_session *bfd); | |
547 | ||
548 | int bfd_recv_cb(struct thread *t); | |
549 | ||
e9e2c950 RZ |
550 | |
551 | /* | |
552 | * event.c | |
553 | * | |
554 | * Contains the code related with event loop. | |
555 | */ | |
556 | typedef void (*bfd_ev_cb)(struct thread *t); | |
557 | ||
558 | void bfd_recvtimer_update(struct bfd_session *bs); | |
559 | void bfd_echo_recvtimer_update(struct bfd_session *bs); | |
560 | void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter); | |
561 | void bfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter); | |
562 | ||
563 | void bfd_xmttimer_delete(struct bfd_session *bs); | |
564 | void bfd_echo_xmttimer_delete(struct bfd_session *bs); | |
565 | void bfd_recvtimer_delete(struct bfd_session *bs); | |
566 | void bfd_echo_recvtimer_delete(struct bfd_session *bs); | |
567 | ||
568 | void bfd_recvtimer_assign(struct bfd_session *bs, bfd_ev_cb cb, int sd); | |
569 | void bfd_echo_recvtimer_assign(struct bfd_session *bs, bfd_ev_cb cb, int sd); | |
570 | void bfd_xmttimer_assign(struct bfd_session *bs, bfd_ev_cb cb); | |
571 | void bfd_echo_xmttimer_assign(struct bfd_session *bs, bfd_ev_cb cb); | |
572 | ||
573 | ||
574 | /* | |
575 | * bfd.c | |
576 | * | |
577 | * BFD protocol specific code. | |
578 | */ | |
9f37770f RZ |
579 | int bfd_session_enable(struct bfd_session *bs); |
580 | void bfd_session_disable(struct bfd_session *bs); | |
e9e2c950 | 581 | struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc); |
bc50bcc8 PG |
582 | int ptm_bfd_sess_del(struct bfd_peer_cfg *bpc); |
583 | void ptm_bfd_sess_dn(struct bfd_session *bfd, uint8_t diag); | |
584 | void ptm_bfd_sess_up(struct bfd_session *bfd); | |
8bd859f6 | 585 | void ptm_bfd_echo_stop(struct bfd_session *bfd); |
e9e2c950 RZ |
586 | void ptm_bfd_echo_start(struct bfd_session *bfd); |
587 | void ptm_bfd_xmt_TO(struct bfd_session *bfd, int fbit); | |
588 | void ptm_bfd_start_xmt_timer(struct bfd_session *bfd, bool is_echo); | |
9f37770f RZ |
589 | struct bfd_session *ptm_bfd_sess_find(struct bfd_pkt *cp, |
590 | struct sockaddr_any *peer, | |
591 | struct sockaddr_any *local, | |
592 | ifindex_t ifindex, vrf_id_t vrfid, | |
593 | bool is_mhop); | |
e9e2c950 RZ |
594 | |
595 | struct bfd_session *bs_peer_find(struct bfd_peer_cfg *bpc); | |
596 | int bfd_session_update_label(struct bfd_session *bs, const char *nlabel); | |
d3f3a2c4 | 597 | void bfd_set_polling(struct bfd_session *bs); |
9f37770f RZ |
598 | void bs_state_handler(struct bfd_session *bs, int nstate); |
599 | void bs_echo_timer_handler(struct bfd_session *bs); | |
600 | void bs_final_handler(struct bfd_session *bs); | |
b912b189 | 601 | void bs_set_slow_timers(struct bfd_session *bs); |
6e10bd97 | 602 | const char *satostr(const struct sockaddr_any *sa); |
e9e2c950 RZ |
603 | const char *diag2str(uint8_t diag); |
604 | int strtosa(const char *addr, struct sockaddr_any *sa); | |
605 | void integer2timestr(uint64_t time, char *buf, size_t buflen); | |
79b4a6fc | 606 | const char *bs_to_string(const struct bfd_session *bs); |
e9e2c950 | 607 | |
9f37770f RZ |
608 | int bs_observer_add(struct bfd_session *bs); |
609 | void bs_observer_del(struct bfd_session_observer *bso); | |
d245e522 | 610 | |
79b4a6fc RZ |
611 | void bs_to_bpc(struct bfd_session *bs, struct bfd_peer_cfg *bpc); |
612 | ||
014cab13 RZ |
613 | void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer, |
614 | struct sockaddr_any *local, bool mhop, const char *ifname, | |
615 | const char *vrfname); | |
616 | struct bfd_session *bfd_session_new(void); | |
617 | struct bfd_session *bs_registrate(struct bfd_session *bs); | |
618 | void bfd_session_free(struct bfd_session *bs); | |
adc26455 RZ |
619 | const struct bfd_session *bfd_session_next(const struct bfd_session *bs, |
620 | bool mhop); | |
2a573ff6 | 621 | void bfd_sessions_remove_manual(void); |
adc26455 | 622 | |
4d12e1f9 RZ |
623 | /** |
624 | * Set the BFD session echo state. | |
625 | * | |
626 | * \param bs the BFD session. | |
627 | * \param echo the echo operational state. | |
628 | */ | |
629 | void bfd_set_echo(struct bfd_session *bs, bool echo); | |
630 | ||
631 | /** | |
632 | * Set the BFD session functional state. | |
633 | * | |
634 | * \param bs the BFD session. | |
635 | * \param shutdown the operational value. | |
636 | */ | |
637 | void bfd_set_shutdown(struct bfd_session *bs, bool shutdown); | |
638 | ||
1a2e2fff RZ |
639 | /** |
640 | * Set the BFD session passive mode. | |
641 | * | |
642 | * \param bs the BFD session. | |
643 | * \param passive the passive mode. | |
644 | */ | |
645 | void bfd_set_passive_mode(struct bfd_session *bs, bool passive); | |
646 | ||
4e38f82a RZ |
647 | /** |
648 | * Picks the BFD session configuration from the appropriated source: | |
649 | * if using the default peer configuration prefer profile (if it exists), | |
650 | * otherwise use session. | |
651 | * | |
652 | * \param bs the BFD session. | |
653 | */ | |
654 | void bfd_session_apply(struct bfd_session *bs); | |
655 | ||
e9e2c950 RZ |
656 | /* BFD hash data structures interface */ |
657 | void bfd_initialize(void); | |
658 | void bfd_shutdown(void); | |
9fc0bc5c | 659 | void bfd_vrf_init(void); |
7bcadbae PG |
660 | void bfd_vrf_terminate(void); |
661 | struct bfd_vrf_global *bfd_vrf_look_by_session(struct bfd_session *bfd); | |
e9e2c950 | 662 | struct bfd_session *bfd_id_lookup(uint32_t id); |
79b4a6fc | 663 | struct bfd_session *bfd_key_lookup(struct bfd_key key); |
e9e2c950 RZ |
664 | |
665 | struct bfd_session *bfd_id_delete(uint32_t id); | |
79b4a6fc | 666 | struct bfd_session *bfd_key_delete(struct bfd_key key); |
e9e2c950 RZ |
667 | |
668 | bool bfd_id_insert(struct bfd_session *bs); | |
79b4a6fc | 669 | bool bfd_key_insert(struct bfd_session *bs); |
e9e2c950 | 670 | |
e3b78da8 | 671 | typedef void (*hash_iter_func)(struct hash_bucket *hb, void *arg); |
e9e2c950 | 672 | void bfd_id_iterate(hash_iter_func hif, void *arg); |
79b4a6fc | 673 | void bfd_key_iterate(hash_iter_func hif, void *arg); |
e9e2c950 | 674 | |
fa6e709f S |
675 | unsigned long bfd_get_session_count(void); |
676 | ||
e9e2c950 RZ |
677 | /* Export callback functions for `event.c`. */ |
678 | extern struct thread_master *master; | |
679 | ||
680 | int bfd_recvtimer_cb(struct thread *t); | |
681 | int bfd_echo_recvtimer_cb(struct thread *t); | |
682 | int bfd_xmt_cb(struct thread *t); | |
683 | int bfd_echo_xmt_cb(struct thread *t); | |
684 | ||
79b4a6fc RZ |
685 | extern struct in6_addr zero_addr; |
686 | ||
ccc9ada8 RZ |
687 | /** |
688 | * Creates a new profile entry and insert into the global list. | |
689 | * | |
690 | * \param name the BFD profile name. | |
691 | * | |
692 | * \returns `NULL` if it already exists otherwise the new entry. | |
693 | */ | |
694 | struct bfd_profile *bfd_profile_new(const char *name); | |
695 | ||
696 | /** | |
697 | * Search for configured BFD profiles (profile name is case insensitive). | |
698 | * | |
699 | * \param name the BFD profile name. | |
700 | * | |
701 | * \returns `NULL` if it doesn't exist otherwise the entry. | |
702 | */ | |
703 | struct bfd_profile *bfd_profile_lookup(const char *name); | |
704 | ||
705 | /** | |
706 | * Removes profile from list and free memory. | |
707 | * | |
708 | * \param bp the BFD profile. | |
709 | */ | |
710 | void bfd_profile_free(struct bfd_profile *bp); | |
711 | ||
712 | /** | |
713 | * Apply a profile configuration to an existing BFD session. The non default | |
714 | * values will not be overriden. | |
715 | * | |
716 | * NOTE: if the profile doesn't exist yet, then the profile will be applied | |
717 | * once it begins to exist. | |
718 | * | |
719 | * \param profile_name the BFD profile name. | |
720 | * \param bs the BFD session. | |
721 | */ | |
722 | void bfd_profile_apply(const char *profname, struct bfd_session *bs); | |
723 | ||
724 | /** | |
725 | * Remove any applied profile from session and revert the session | |
726 | * configuration. | |
727 | * | |
728 | * \param bs the BFD session. | |
729 | */ | |
730 | void bfd_profile_remove(struct bfd_session *bs); | |
731 | ||
732 | /** | |
733 | * Apply new profile values to sessions using it. | |
734 | * | |
735 | * \param[in] bp the BFD profile that got updated. | |
736 | */ | |
737 | void bfd_profile_update(struct bfd_profile *bp); | |
e9e2c950 | 738 | |
c2f29cf3 RZ |
739 | /* |
740 | * bfdd_vty.c | |
741 | * | |
742 | * BFD daemon vty shell commands. | |
743 | */ | |
744 | void bfdd_vty_init(void); | |
745 | ||
746 | ||
adc26455 RZ |
747 | /* |
748 | * bfdd_cli.c | |
749 | * | |
750 | * BFD daemon CLI implementation. | |
751 | */ | |
752 | void bfdd_cli_init(void); | |
753 | ||
754 | ||
d3af6147 RZ |
755 | /* |
756 | * ptm_adapter.c | |
757 | */ | |
758 | void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv); | |
759 | void bfdd_zclient_stop(void); | |
54aadda1 PG |
760 | void bfdd_zclient_unregister(vrf_id_t vrf_id); |
761 | void bfdd_zclient_register(vrf_id_t vrf_id); | |
d24af713 PG |
762 | void bfdd_sessions_enable_vrf(struct vrf *vrf); |
763 | void bfdd_sessions_disable_vrf(struct vrf *vrf); | |
f06e248c | 764 | void bfd_session_update_vrf_name(struct bfd_session *bs, struct vrf *vrf); |
d3af6147 | 765 | |
7555dc61 | 766 | int ptm_bfd_notify(struct bfd_session *bs, uint8_t notify_state); |
d3af6147 | 767 | |
230aefe2 RZ |
768 | /* |
769 | * dplane.c | |
770 | */ | |
771 | ||
772 | /** | |
773 | * Initialize BFD data plane infrastructure for distributed BFD implementation. | |
774 | * | |
6655b43d RZ |
775 | * \param sa socket address. |
776 | * \param salen socket address structure length. | |
777 | * \param client `true` means connecting socket, `false` listening socket. | |
230aefe2 | 778 | */ |
6655b43d | 779 | void bfd_dplane_init(const struct sockaddr *sa, socklen_t salen, bool client); |
230aefe2 | 780 | |
efd04d60 RZ |
781 | /** |
782 | * Attempts to delegate the BFD session liveness detection to hardware. | |
783 | * | |
784 | * \param bs the BFD session data structure. | |
785 | * | |
786 | * \returns | |
787 | * `0` on success and BFD daemon should do nothing or `-1` on failure | |
788 | * and we should fallback to software implementation. | |
789 | */ | |
790 | int bfd_dplane_add_session(struct bfd_session *bs); | |
791 | ||
792 | /** | |
793 | * Send new session settings to data plane. | |
794 | * | |
795 | * \param bs the BFD session to update. | |
796 | */ | |
797 | int bfd_dplane_update_session(const struct bfd_session *bs); | |
798 | ||
799 | /** | |
800 | * Deletes session from data plane. | |
801 | * | |
802 | * \param bs the BFD session to delete. | |
803 | * | |
804 | * \returns `0` on success otherwise `-1`. | |
805 | */ | |
806 | int bfd_dplane_delete_session(struct bfd_session *bs); | |
807 | ||
400632a9 RZ |
808 | /** |
809 | * Asks the data plane for updated counters and update the session data | |
810 | * structure. | |
811 | * | |
812 | * \param bs the BFD session that needs updating. | |
813 | * | |
814 | * \returns `0` on success otherwise `-1` on failure. | |
815 | */ | |
816 | int bfd_dplane_update_session_counters(struct bfd_session *bs); | |
817 | ||
818 | void bfd_dplane_show_counters(struct vty *vty); | |
819 | ||
e9e2c950 | 820 | #endif /* _BFD_H_ */ |