]>
Commit | Line | Data |
---|---|---|
7f342629 DS |
1 | /** |
2 | * bfd.h: BFD definitions and structures | |
3 | * | |
4 | * @copyright Copyright (C) 2015 Cumulus Networks, Inc. | |
5 | * | |
6 | * This file is part of GNU Zebra. | |
7 | * | |
8 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * GNU Zebra is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
896014f4 DL |
18 | * You should have received a copy of the GNU General Public License along |
19 | * with this program; see the file COPYING; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
7f342629 DS |
21 | */ |
22 | ||
23 | #ifndef _ZEBRA_BFD_H | |
24 | #define _ZEBRA_BFD_H | |
25 | ||
68fe91d6 | 26 | #include "lib/json.h" |
43e52561 | 27 | #include "lib/zclient.h" |
68fe91d6 | 28 | |
5e244469 RW |
29 | #ifdef __cplusplus |
30 | extern "C" { | |
31 | #endif | |
32 | ||
7f342629 DS |
33 | #define BFD_DEF_MIN_RX 300 |
34 | #define BFD_MIN_MIN_RX 50 | |
35 | #define BFD_MAX_MIN_RX 60000 | |
36 | #define BFD_DEF_MIN_TX 300 | |
37 | #define BFD_MIN_MIN_TX 50 | |
38 | #define BFD_MAX_MIN_TX 60000 | |
39 | #define BFD_DEF_DETECT_MULT 3 | |
40 | #define BFD_MIN_DETECT_MULT 2 | |
41 | #define BFD_MAX_DETECT_MULT 255 | |
42 | ||
7555dc61 S |
43 | #define BFD_STATUS_UNKNOWN (1 << 0) /* BFD session status never received */ |
44 | #define BFD_STATUS_DOWN (1 << 1) /* BFD session status is down */ | |
45 | #define BFD_STATUS_UP (1 << 2) /* BFD session status is up */ | |
46 | #define BFD_STATUS_ADMIN_DOWN (1 << 3) /* BFD session is admin down */ | |
47 | ||
18322efd RZ |
48 | #define BFD_PROFILE_NAME_LEN 64 |
49 | ||
d62a17ae | 50 | const char *bfd_get_status_str(int status); |
68fe91d6 | 51 | |
0945d5ed PG |
52 | extern void bfd_client_sendmsg(struct zclient *zclient, int command, |
53 | vrf_id_t vrf_id); | |
055c4dfc | 54 | |
18322efd RZ |
55 | /* |
56 | * BFD new API. | |
57 | */ | |
58 | ||
a099abe5 RZ |
59 | /* Forward declaration of argument struct. */ |
60 | struct bfd_session_params; | |
61 | ||
62 | /** Session state definitions. */ | |
63 | enum bfd_session_state { | |
64 | /** Session state is unknown or not initialized. */ | |
65 | BSS_UNKNOWN = BFD_STATUS_UNKNOWN, | |
66 | /** Local or remote peer administratively shutdown the session. */ | |
67 | BSS_ADMIN_DOWN = BFD_STATUS_ADMIN_DOWN, | |
68 | /** Session is down. */ | |
69 | BSS_DOWN = BFD_STATUS_DOWN, | |
70 | /** Session is up and working correctly. */ | |
71 | BSS_UP = BFD_STATUS_UP, | |
72 | }; | |
73 | ||
74 | /** BFD session status information */ | |
75 | struct bfd_session_status { | |
76 | /** Current session state. */ | |
77 | enum bfd_session_state state; | |
78 | /** Previous session state. */ | |
79 | enum bfd_session_state previous_state; | |
80 | /** Remote Control Plane Independent bit state. */ | |
81 | bool remote_cbit; | |
82 | /** Last event occurrence. */ | |
83 | time_t last_event; | |
84 | }; | |
85 | ||
86 | /** | |
87 | * Session status update callback. | |
88 | * | |
89 | * \param bsp BFD session parameters. | |
90 | * \param bss BFD session status. | |
91 | * \param arg application independent data. | |
92 | */ | |
93 | typedef void (*bsp_status_update)(struct bfd_session_params *bsp, | |
94 | const struct bfd_session_status *bss, | |
95 | void *arg); | |
96 | ||
97 | /** | |
98 | * Allocates and initializes the session parameters. | |
99 | * | |
ac506cb2 | 100 | * \param updatecb status update notification callback. |
a099abe5 RZ |
101 | * \param args application independent data. |
102 | * | |
103 | * \returns pointer to configuration storage. | |
104 | */ | |
105 | struct bfd_session_params *bfd_sess_new(bsp_status_update updatecb, void *args); | |
106 | ||
107 | /** | |
108 | * Uninstall session if installed and free resources allocated by the | |
109 | * parameters. Already sets pointer to `NULL` to avoid dangling references. | |
110 | * | |
111 | * \param bsp session parameters. | |
112 | */ | |
113 | void bfd_sess_free(struct bfd_session_params **bsp); | |
114 | ||
a099abe5 RZ |
115 | /** |
116 | * Set the local and peer address of the BFD session. | |
117 | * | |
ac506cb2 RZ |
118 | * NOTE: |
119 | * If the address changed the session is removed and must be installed again | |
120 | * with `bfd_sess_install`. | |
121 | * | |
a099abe5 RZ |
122 | * \param bsp BFD session parameters. |
123 | * \param src local address (optional, can be `NULL`). | |
124 | * \param dst remote address (mandatory). | |
125 | */ | |
126 | void bfd_sess_set_ipv4_addrs(struct bfd_session_params *bsp, | |
ca30ac7f RZ |
127 | const struct in_addr *src, |
128 | const struct in_addr *dst); | |
a099abe5 RZ |
129 | |
130 | /** | |
131 | * Set the local and peer address of the BFD session. | |
132 | * | |
ac506cb2 RZ |
133 | * NOTE: |
134 | * If the address changed the session is removed and must be installed again | |
135 | * with `bfd_sess_install`. | |
136 | * | |
a099abe5 RZ |
137 | * \param bsp BFD session parameters. |
138 | * \param src local address (optional, can be `NULL`). | |
139 | * \param dst remote address (mandatory). | |
140 | */ | |
141 | void bfd_sess_set_ipv6_addrs(struct bfd_session_params *bsp, | |
ca30ac7f RZ |
142 | const struct in6_addr *src, |
143 | const struct in6_addr *dst); | |
a099abe5 RZ |
144 | |
145 | /** | |
146 | * Configure the BFD session interface. | |
147 | * | |
ac506cb2 RZ |
148 | * NOTE: |
149 | * If the interface changed the session is removed and must be installed again | |
150 | * with `bfd_sess_install`. | |
151 | * | |
a099abe5 RZ |
152 | * \param bsp BFD session parameters. |
153 | * \param ifname interface name (or `NULL` to remove it). | |
154 | */ | |
155 | void bfd_sess_set_interface(struct bfd_session_params *bsp, const char *ifname); | |
156 | ||
157 | /** | |
158 | * Configure the BFD session profile name. | |
159 | * | |
ac506cb2 RZ |
160 | * NOTE: |
161 | * Session profile will only change after a `bfd_sess_install`. | |
162 | * | |
a099abe5 RZ |
163 | * \param bsp BFD session parameters. |
164 | * \param profile profile name (or `NULL` to remove it). | |
165 | */ | |
166 | void bfd_sess_set_profile(struct bfd_session_params *bsp, const char *profile); | |
167 | ||
168 | /** | |
169 | * Configure the BFD session VRF. | |
170 | * | |
ac506cb2 RZ |
171 | * NOTE: |
172 | * If the VRF changed the session is removed and must be installed again | |
173 | * with `bfd_sess_install`. | |
174 | * | |
a099abe5 RZ |
175 | * \param bsp BFD session parameters. |
176 | * \param vrf_id the VRF identification number. | |
177 | */ | |
178 | void bfd_sess_set_vrf(struct bfd_session_params *bsp, vrf_id_t vrf_id); | |
179 | ||
180 | /** | |
181 | * Configure the BFD session single/multi hop setting. | |
182 | * | |
ac506cb2 | 183 | * NOTE: |
92f85e65 IR |
184 | * If the number of hops is changed the session is removed and must be |
185 | * installed again with `bfd_sess_install`. | |
ac506cb2 | 186 | * |
a099abe5 | 187 | * \param bsp BFD session parameters. |
92f85e65 IR |
188 | * \param hops maximum amount of hops expected (1 for single hop, 2 or |
189 | * more for multi hop). | |
a099abe5 | 190 | */ |
92f85e65 | 191 | void bfd_sess_set_hop_count(struct bfd_session_params *bsp, uint8_t hops); |
a099abe5 RZ |
192 | |
193 | /** | |
194 | * Configure the BFD session to set the Control Plane Independent bit. | |
195 | * | |
ac506cb2 RZ |
196 | * NOTE: |
197 | * Session CPI bit will only change after a `bfd_sess_install`. | |
198 | * | |
a099abe5 RZ |
199 | * \param bsp BFD session parameters. |
200 | * \param enable BFD Control Plane Independent state. | |
201 | */ | |
202 | void bfd_sess_set_cbit(struct bfd_session_params *bsp, bool enable); | |
203 | ||
204 | /** | |
205 | * DEPRECATED: please avoid using timers directly and use profiles instead. | |
206 | * | |
207 | * Configures the BFD session timers to use. This is specially useful with | |
208 | * `ptm-bfd` which does not support timers. | |
209 | * | |
ac506cb2 RZ |
210 | * NOTE: |
211 | * Session timers will only apply if the session has not been created yet. | |
212 | * If the session is already installed you must uninstall and install again | |
213 | * to take effect. | |
214 | * | |
a099abe5 RZ |
215 | * \param bsp BFD session parameters. |
216 | * \param detection_multiplier the detection multiplier value. | |
217 | * \param min_rx minimum required receive period. | |
218 | * \param min_tx minimum required transmission period. | |
219 | */ | |
220 | void bfd_sess_set_timers(struct bfd_session_params *bsp, | |
221 | uint8_t detection_multiplier, uint32_t min_rx, | |
222 | uint32_t min_tx); | |
223 | ||
224 | /** | |
225 | * Installs or updates the BFD session based on the saved session arguments. | |
226 | * | |
ac506cb2 RZ |
227 | * NOTE: |
228 | * This function has a delayed effect: it will only install/update after | |
229 | * all northbound/CLI command batch finishes. | |
230 | * | |
a099abe5 RZ |
231 | * \param bsp session parameters. |
232 | */ | |
233 | void bfd_sess_install(struct bfd_session_params *bsp); | |
234 | ||
235 | /** | |
236 | * Uninstall the BFD session based on the saved session arguments. | |
237 | * | |
ac506cb2 RZ |
238 | * NOTE: |
239 | * This function uninstalls the session immediately (if installed) and cancels | |
240 | * any previous `bfd_sess_install` calls. | |
241 | * | |
a099abe5 RZ |
242 | * \param bsp session parameters. |
243 | */ | |
244 | void bfd_sess_uninstall(struct bfd_session_params *bsp); | |
245 | ||
246 | /** | |
247 | * Get BFD session current status. | |
248 | * | |
249 | * \param bsp session parameters. | |
250 | * | |
251 | * \returns BFD session status data structure. | |
252 | */ | |
253 | enum bfd_session_state bfd_sess_status(const struct bfd_session_params *bsp); | |
254 | ||
255 | /** | |
92f85e65 | 256 | * Get BFD session amount of hops configured value. |
a099abe5 RZ |
257 | * |
258 | * \param bsp session parameters. | |
259 | * | |
260 | * \returns configured amount of hops. | |
261 | */ | |
262 | uint8_t bfd_sess_hop_count(const struct bfd_session_params *bsp); | |
263 | ||
264 | /** | |
265 | * Get BFD session profile configured value. | |
266 | * | |
267 | * \param bsp session parameters. | |
268 | * | |
269 | * \returns configured profile name (or `NULL` if empty). | |
270 | */ | |
271 | const char *bfd_sess_profile(const struct bfd_session_params *bsp); | |
272 | ||
273 | /** | |
274 | * Get BFD session addresses. | |
275 | * | |
276 | * \param bsp session parameters. | |
277 | * \param family the address family being used (AF_INET or AF_INET6). | |
278 | * \param src source address (optional, may be `NULL`). | |
279 | * \param dst peer address (optional, may be `NULL`). | |
280 | */ | |
281 | void bfd_sess_addresses(const struct bfd_session_params *bsp, int *family, | |
282 | struct in6_addr *src, struct in6_addr *dst); | |
283 | /** | |
284 | * Get BFD session interface name. | |
285 | * | |
286 | * \param bsp session parameters. | |
287 | * | |
288 | * \returns `NULL` if not set otherwise the interface name. | |
289 | */ | |
290 | const char *bfd_sess_interface(const struct bfd_session_params *bsp); | |
291 | ||
292 | /** | |
293 | * Get BFD session VRF name. | |
294 | * | |
295 | * \param bsp session parameters. | |
296 | * | |
297 | * \returns the VRF name. | |
298 | */ | |
299 | const char *bfd_sess_vrf(const struct bfd_session_params *bsp); | |
300 | ||
301 | /** | |
302 | * Get BFD session VRF ID. | |
303 | * | |
304 | * \param bsp session parameters. | |
305 | * | |
306 | * \returns the VRF name. | |
307 | */ | |
308 | vrf_id_t bfd_sess_vrf_id(const struct bfd_session_params *bsp); | |
309 | ||
310 | /** | |
311 | * Get BFD session control plane independent bit configuration state. | |
312 | * | |
313 | * \param bsp session parameters. | |
314 | * | |
315 | * \returns `true` if enabled otherwise `false`. | |
316 | */ | |
317 | bool bfd_sess_cbit(const struct bfd_session_params *bsp); | |
318 | ||
319 | /** | |
320 | * DEPRECATED: please avoid using timers directly and use profiles instead. | |
321 | * | |
322 | * Gets the configured timers. | |
323 | * | |
324 | * \param bsp BFD session parameters. | |
325 | * \param detection_multiplier the detection multiplier value. | |
326 | * \param min_rx minimum required receive period. | |
327 | * \param min_tx minimum required transmission period. | |
328 | */ | |
329 | void bfd_sess_timers(const struct bfd_session_params *bsp, | |
330 | uint8_t *detection_multiplier, uint32_t *min_rx, | |
331 | uint32_t *min_tx); | |
332 | ||
333 | /** | |
334 | * Show BFD session configuration and status. If `json` is provided (e.g. not | |
335 | * `NULL`) then information will be inserted in object, otherwise printed to | |
336 | * `vty`. | |
337 | * | |
338 | * \param vty Pointer to `vty` for outputting text. | |
339 | * \param json (optional) JSON object pointer. | |
340 | * \param bsp session parameters. | |
341 | */ | |
342 | void bfd_sess_show(struct vty *vty, struct json_object *json, | |
343 | struct bfd_session_params *bsp); | |
344 | ||
345 | /** | |
346 | * Initializes the BFD integration library. This function executes the | |
347 | * following actions: | |
348 | * | |
349 | * - Copy the `struct thread_master` pointer to use as "thread" to execute | |
350 | * the BFD session parameters installation. | |
351 | * - Copy the `struct zclient` pointer to install its callbacks. | |
352 | * - Initializes internal data structures. | |
353 | * | |
354 | * \param tm normally the daemon main thread event manager. | |
355 | * \param zc the zebra client of the daemon. | |
356 | */ | |
357 | void bfd_protocol_integration_init(struct zclient *zc, | |
358 | struct thread_master *tm); | |
359 | ||
18322efd RZ |
360 | /** |
361 | * BFD session registration arguments. | |
362 | */ | |
363 | struct bfd_session_arg { | |
364 | /** | |
365 | * BFD command. | |
366 | * | |
367 | * Valid commands: | |
368 | * - `ZEBRA_BFD_DEST_REGISTER` | |
369 | * - `ZEBRA_BFD_DEST_DEREGISTER` | |
370 | */ | |
371 | int32_t command; | |
372 | ||
373 | /** | |
374 | * BFD family type. | |
375 | * | |
376 | * Supported types: | |
377 | * - `AF_INET` | |
378 | * - `AF_INET6`. | |
379 | */ | |
380 | uint32_t family; | |
381 | /** Source address. */ | |
382 | struct in6_addr src; | |
383 | /** Source address. */ | |
384 | struct in6_addr dst; | |
385 | ||
386 | /** Multi hop indicator. */ | |
387 | uint8_t mhop; | |
03ff0db1 | 388 | /** Expected hops. */ |
389 | uint8_t hops; | |
18322efd RZ |
390 | /** C bit (Control Plane Independent bit) indicator. */ |
391 | uint8_t cbit; | |
392 | ||
393 | /** Interface name size. */ | |
394 | uint8_t ifnamelen; | |
395 | /** Interface name. */ | |
396 | char ifname[64]; | |
397 | ||
398 | /** Daemon or session VRF. */ | |
399 | vrf_id_t vrf_id; | |
400 | ||
401 | /** Profile name length. */ | |
402 | uint8_t profilelen; | |
403 | /** Profile name. */ | |
404 | char profile[BFD_PROFILE_NAME_LEN]; | |
405 | ||
406 | /* | |
407 | * Deprecation fields: these fields should be removed once `ptm-bfd` | |
408 | * no longer uses this interface. | |
409 | */ | |
410 | ||
411 | /** Minimum required receive interval (in microseconds). */ | |
412 | uint32_t min_rx; | |
413 | /** Minimum desired transmission interval (in microseconds). */ | |
414 | uint32_t min_tx; | |
415 | /** Detection multiplier. */ | |
416 | uint32_t detection_multiplier; | |
18322efd RZ |
417 | }; |
418 | ||
419 | /** | |
420 | * Send a message to BFD daemon through the zebra client. | |
421 | * | |
422 | * \param zc the zebra client context. | |
423 | * \param arg the BFD session command arguments. | |
424 | * | |
425 | * \returns `-1` on failure otherwise `0`. | |
426 | * | |
427 | * \see bfd_session_arg. | |
428 | */ | |
429 | extern int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *arg); | |
430 | ||
a099abe5 RZ |
431 | /** |
432 | * Enables or disables BFD protocol integration API debugging. | |
433 | * | |
434 | * \param enable new API debug state. | |
435 | */ | |
436 | extern void bfd_protocol_integration_set_debug(bool enable); | |
437 | ||
438 | /** | |
439 | * Sets shutdown mode so no more events are processed. | |
440 | * | |
441 | * This is useful to avoid the event storm that happens caused by network, | |
442 | * interfaces or VRFs removal. It should also avoid some crashes due hanging | |
443 | * pointers left overs by protocol. | |
444 | * | |
445 | * \param enable new API shutdown state. | |
446 | */ | |
447 | extern void bfd_protocol_integration_set_shutdown(bool enable); | |
448 | ||
449 | /** | |
450 | * Get API debugging state. | |
451 | */ | |
452 | extern bool bfd_protocol_integration_debug(void); | |
453 | ||
454 | /** | |
455 | * Get API shutdown state. | |
456 | */ | |
457 | extern bool bfd_protocol_integration_shutting_down(void); | |
458 | ||
5e244469 RW |
459 | #ifdef __cplusplus |
460 | } | |
461 | #endif | |
462 | ||
7f342629 | 463 | #endif /* _ZEBRA_BFD_H */ |