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