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