2 * bfd.h: BFD definitions and structures
4 * @copyright Copyright (C) 2015 Cumulus Networks, Inc.
6 * This file is part of GNU Zebra.
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
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.
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
27 #include "lib/zclient.h"
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
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 */
48 #define BFD_PROFILE_NAME_LEN 64
50 const char *bfd_get_status_str(int status
);
52 extern void bfd_client_sendmsg(struct zclient
*zclient
, int command
,
59 /* Forward declaration of argument struct. */
60 struct bfd_session_params
;
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
,
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. */
82 /** Last event occurrence. */
87 * Session status update callback.
89 * \param bsp BFD session parameters.
90 * \param bss BFD session status.
91 * \param arg application independent data.
93 typedef void (*bsp_status_update
)(struct bfd_session_params
*bsp
,
94 const struct bfd_session_status
*bss
,
98 * Allocates and initializes the session parameters.
100 * \param updatecb status update notification callback.
101 * \param args application independent data.
103 * \returns pointer to configuration storage.
105 struct bfd_session_params
*bfd_sess_new(bsp_status_update updatecb
, void *args
);
108 * Uninstall session if installed and free resources allocated by the
109 * parameters. Already sets pointer to `NULL` to avoid dangling references.
111 * \param bsp session parameters.
113 void bfd_sess_free(struct bfd_session_params
**bsp
);
116 * Set the local and peer address of the BFD session.
119 * If the address changed the session is removed and must be installed again
120 * with `bfd_sess_install`.
122 * \param bsp BFD session parameters.
123 * \param src local address (optional, can be `NULL`).
124 * \param dst remote address (mandatory).
126 void bfd_sess_set_ipv4_addrs(struct bfd_session_params
*bsp
,
127 const struct in_addr
*src
,
128 const struct in_addr
*dst
);
131 * Set the local and peer address of the BFD session.
134 * If the address changed the session is removed and must be installed again
135 * with `bfd_sess_install`.
137 * \param bsp BFD session parameters.
138 * \param src local address (optional, can be `NULL`).
139 * \param dst remote address (mandatory).
141 void bfd_sess_set_ipv6_addrs(struct bfd_session_params
*bsp
,
142 const struct in6_addr
*src
,
143 const struct in6_addr
*dst
);
146 * Configure the BFD session interface.
149 * If the interface changed the session is removed and must be installed again
150 * with `bfd_sess_install`.
152 * \param bsp BFD session parameters.
153 * \param ifname interface name (or `NULL` to remove it).
155 void bfd_sess_set_interface(struct bfd_session_params
*bsp
, const char *ifname
);
158 * Configure the BFD session profile name.
161 * Session profile will only change after a `bfd_sess_install`.
163 * \param bsp BFD session parameters.
164 * \param profile profile name (or `NULL` to remove it).
166 void bfd_sess_set_profile(struct bfd_session_params
*bsp
, const char *profile
);
169 * Configure the BFD session VRF.
172 * If the VRF changed the session is removed and must be installed again
173 * with `bfd_sess_install`.
175 * \param bsp BFD session parameters.
176 * \param vrf_id the VRF identification number.
178 void bfd_sess_set_vrf(struct bfd_session_params
*bsp
, vrf_id_t vrf_id
);
181 * Configure the BFD session single/multi hop setting.
184 * If the number of hops is changed the session is removed and must be
185 * installed again with `bfd_sess_install`.
187 * \param bsp BFD session parameters.
188 * \param hops maximum amount of hops expected (1 for single hop, 2 or
189 * more for multi hop).
191 void bfd_sess_set_hop_count(struct bfd_session_params
*bsp
, uint8_t hops
);
194 * Configure the BFD session to set the Control Plane Independent bit.
197 * Session CPI bit will only change after a `bfd_sess_install`.
199 * \param bsp BFD session parameters.
200 * \param enable BFD Control Plane Independent state.
202 void bfd_sess_set_cbit(struct bfd_session_params
*bsp
, bool enable
);
205 * DEPRECATED: please avoid using timers directly and use profiles instead.
207 * Configures the BFD session timers to use. This is specially useful with
208 * `ptm-bfd` which does not support timers.
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
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.
220 void bfd_sess_set_timers(struct bfd_session_params
*bsp
,
221 uint8_t detection_multiplier
, uint32_t min_rx
,
225 * Installs or updates the BFD session based on the saved session arguments.
228 * This function has a delayed effect: it will only install/update after
229 * all northbound/CLI command batch finishes.
231 * \param bsp session parameters.
233 void bfd_sess_install(struct bfd_session_params
*bsp
);
236 * Uninstall the BFD session based on the saved session arguments.
239 * This function uninstalls the session immediately (if installed) and cancels
240 * any previous `bfd_sess_install` calls.
242 * \param bsp session parameters.
244 void bfd_sess_uninstall(struct bfd_session_params
*bsp
);
247 * Get BFD session current status.
249 * \param bsp session parameters.
251 * \returns BFD session status data structure.
253 enum bfd_session_state
bfd_sess_status(const struct bfd_session_params
*bsp
);
256 * Get BFD session amount of hops configured value.
258 * \param bsp session parameters.
260 * \returns configured amount of hops.
262 uint8_t bfd_sess_hop_count(const struct bfd_session_params
*bsp
);
265 * Get BFD session profile configured value.
267 * \param bsp session parameters.
269 * \returns configured profile name (or `NULL` if empty).
271 const char *bfd_sess_profile(const struct bfd_session_params
*bsp
);
274 * Get BFD session addresses.
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`).
281 void bfd_sess_addresses(const struct bfd_session_params
*bsp
, int *family
,
282 struct in6_addr
*src
, struct in6_addr
*dst
);
284 * Get BFD session interface name.
286 * \param bsp session parameters.
288 * \returns `NULL` if not set otherwise the interface name.
290 const char *bfd_sess_interface(const struct bfd_session_params
*bsp
);
293 * Get BFD session VRF name.
295 * \param bsp session parameters.
297 * \returns the VRF name.
299 const char *bfd_sess_vrf(const struct bfd_session_params
*bsp
);
302 * Get BFD session VRF ID.
304 * \param bsp session parameters.
306 * \returns the VRF name.
308 vrf_id_t
bfd_sess_vrf_id(const struct bfd_session_params
*bsp
);
311 * Get BFD session control plane independent bit configuration state.
313 * \param bsp session parameters.
315 * \returns `true` if enabled otherwise `false`.
317 bool bfd_sess_cbit(const struct bfd_session_params
*bsp
);
320 * DEPRECATED: please avoid using timers directly and use profiles instead.
322 * Gets the configured timers.
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.
329 void bfd_sess_timers(const struct bfd_session_params
*bsp
,
330 uint8_t *detection_multiplier
, uint32_t *min_rx
,
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
338 * \param vty Pointer to `vty` for outputting text.
339 * \param json (optional) JSON object pointer.
340 * \param bsp session parameters.
342 void bfd_sess_show(struct vty
*vty
, struct json_object
*json
,
343 struct bfd_session_params
*bsp
);
346 * Initializes the BFD integration library. This function executes the
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.
354 * \param tm normally the daemon main thread event manager.
355 * \param zc the zebra client of the daemon.
357 void bfd_protocol_integration_init(struct zclient
*zc
,
358 struct thread_master
*tm
);
361 * BFD session registration arguments.
363 struct bfd_session_arg
{
368 * - `ZEBRA_BFD_DEST_REGISTER`
369 * - `ZEBRA_BFD_DEST_DEREGISTER`
381 /** Source address. */
383 /** Source address. */
386 /** Multi hop indicator. */
388 /** Expected hops. */
390 /** C bit (Control Plane Independent bit) indicator. */
393 /** Interface name size. */
395 /** Interface name. */
398 /** Daemon or session VRF. */
401 /** Profile name length. */
404 char profile
[BFD_PROFILE_NAME_LEN
];
407 * Deprecation fields: these fields should be removed once `ptm-bfd`
408 * no longer uses this interface.
411 /** Minimum required receive interval (in microseconds). */
413 /** Minimum desired transmission interval (in microseconds). */
415 /** Detection multiplier. */
416 uint32_t detection_multiplier
;
420 * Send a message to BFD daemon through the zebra client.
422 * \param zc the zebra client context.
423 * \param arg the BFD session command arguments.
425 * \returns `-1` on failure otherwise `0`.
427 * \see bfd_session_arg.
429 extern int zclient_bfd_command(struct zclient
*zc
, struct bfd_session_arg
*arg
);
432 * Enables or disables BFD protocol integration API debugging.
434 * \param enable new API debug state.
436 extern void bfd_protocol_integration_set_debug(bool enable
);
439 * Sets shutdown mode so no more events are processed.
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.
445 * \param enable new API shutdown state.
447 extern void bfd_protocol_integration_set_shutdown(bool enable
);
450 * Get API debugging state.
452 extern bool bfd_protocol_integration_debug(void);
455 * Get API shutdown state.
457 extern bool bfd_protocol_integration_shutting_down(void);
463 #endif /* _ZEBRA_BFD_H */