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 struct in_addr
*src
, struct in_addr
*dst
);
130 * Set the local and peer address of the BFD session.
133 * If the address changed the session is removed and must be installed again
134 * with `bfd_sess_install`.
136 * \param bsp BFD session parameters.
137 * \param src local address (optional, can be `NULL`).
138 * \param dst remote address (mandatory).
140 void bfd_sess_set_ipv6_addrs(struct bfd_session_params
*bsp
,
141 struct in6_addr
*src
, struct in6_addr
*dst
);
144 * Configure the BFD session interface.
147 * If the interface changed the session is removed and must be installed again
148 * with `bfd_sess_install`.
150 * \param bsp BFD session parameters.
151 * \param ifname interface name (or `NULL` to remove it).
153 void bfd_sess_set_interface(struct bfd_session_params
*bsp
, const char *ifname
);
156 * Configure the BFD session profile name.
159 * Session profile will only change after a `bfd_sess_install`.
161 * \param bsp BFD session parameters.
162 * \param profile profile name (or `NULL` to remove it).
164 void bfd_sess_set_profile(struct bfd_session_params
*bsp
, const char *profile
);
167 * Configure the BFD session VRF.
170 * If the VRF changed the session is removed and must be installed again
171 * with `bfd_sess_install`.
173 * \param bsp BFD session parameters.
174 * \param vrf_id the VRF identification number.
176 void bfd_sess_set_vrf(struct bfd_session_params
*bsp
, vrf_id_t vrf_id
);
179 * Configure the BFD session single/multi hop setting.
182 * If the TTL changed the session is removed and must be installed again
183 * with `bfd_sess_install`.
185 * \param bsp BFD session parameters.
186 * \param min_ttl minimum TTL value expected (255 for single hop, 254 for
187 * multi hop with single hop, 253 for multi hop with two hops
188 * and so on). See `BFD_SINGLE_HOP_TTL` and
189 * `BFD_MULTI_HOP_MIN_TTL` for defaults.
191 * To simplify things if your protocol only knows the amount of hops it is
192 * better to use `bfd_sess_set_hops` instead.
194 void bfd_sess_set_mininum_ttl(struct bfd_session_params
*bsp
, uint8_t min_ttl
);
196 /** To use single hop the minimum TTL must be set to this. */
197 #define BFD_SINGLE_HOP_TTL 255
198 /** To use multi hop the minimum TTL must be set to this or less. */
199 #define BFD_MULTI_HOP_MIN_TTL 254
202 * This function is the inverted version of `bfd_sess_set_minimum_ttl`.
203 * Instead of receiving the minimum expected TTL, it receives the amount of
204 * hops the protocol will jump.
207 * If the TTL changed the session is removed and must be installed again
208 * with `bfd_sess_install`.
210 * \param bsp BFD session parameters.
211 * \param min_ttl minimum amount of hops expected (1 for single hop, 2 or
212 * more for multi hop).
214 void bfd_sess_set_hop_count(struct bfd_session_params
*bsp
, uint8_t min_ttl
);
217 * Configure the BFD session to set the Control Plane Independent bit.
220 * Session CPI bit will only change after a `bfd_sess_install`.
222 * \param bsp BFD session parameters.
223 * \param enable BFD Control Plane Independent state.
225 void bfd_sess_set_cbit(struct bfd_session_params
*bsp
, bool enable
);
228 * DEPRECATED: please avoid using timers directly and use profiles instead.
230 * Configures the BFD session timers to use. This is specially useful with
231 * `ptm-bfd` which does not support timers.
234 * Session timers will only apply if the session has not been created yet.
235 * If the session is already installed you must uninstall and install again
238 * \param bsp BFD session parameters.
239 * \param detection_multiplier the detection multiplier value.
240 * \param min_rx minimum required receive period.
241 * \param min_tx minimum required transmission period.
243 void bfd_sess_set_timers(struct bfd_session_params
*bsp
,
244 uint8_t detection_multiplier
, uint32_t min_rx
,
248 * Installs or updates the BFD session based on the saved session arguments.
251 * This function has a delayed effect: it will only install/update after
252 * all northbound/CLI command batch finishes.
254 * \param bsp session parameters.
256 void bfd_sess_install(struct bfd_session_params
*bsp
);
259 * Uninstall the BFD session based on the saved session arguments.
262 * This function uninstalls the session immediately (if installed) and cancels
263 * any previous `bfd_sess_install` calls.
265 * \param bsp session parameters.
267 void bfd_sess_uninstall(struct bfd_session_params
*bsp
);
270 * Get BFD session current status.
272 * \param bsp session parameters.
274 * \returns BFD session status data structure.
276 enum bfd_session_state
bfd_sess_status(const struct bfd_session_params
*bsp
);
279 * Get BFD session minimum TTL configured value.
281 * \param bsp session parameters.
283 * \returns configured minimum TTL.
285 uint8_t bfd_sess_minimum_ttl(const struct bfd_session_params
*bsp
);
288 * Inverted version of `bfd_sess_minimum_ttl`. Gets the amount of hops in the
291 * \param bsp session parameters.
293 * \returns configured amount of hops.
295 uint8_t bfd_sess_hop_count(const struct bfd_session_params
*bsp
);
298 * Get BFD session profile configured value.
300 * \param bsp session parameters.
302 * \returns configured profile name (or `NULL` if empty).
304 const char *bfd_sess_profile(const struct bfd_session_params
*bsp
);
307 * Get BFD session addresses.
309 * \param bsp session parameters.
310 * \param family the address family being used (AF_INET or AF_INET6).
311 * \param src source address (optional, may be `NULL`).
312 * \param dst peer address (optional, may be `NULL`).
314 void bfd_sess_addresses(const struct bfd_session_params
*bsp
, int *family
,
315 struct in6_addr
*src
, struct in6_addr
*dst
);
317 * Get BFD session interface name.
319 * \param bsp session parameters.
321 * \returns `NULL` if not set otherwise the interface name.
323 const char *bfd_sess_interface(const struct bfd_session_params
*bsp
);
326 * Get BFD session VRF name.
328 * \param bsp session parameters.
330 * \returns the VRF name.
332 const char *bfd_sess_vrf(const struct bfd_session_params
*bsp
);
335 * Get BFD session VRF ID.
337 * \param bsp session parameters.
339 * \returns the VRF name.
341 vrf_id_t
bfd_sess_vrf_id(const struct bfd_session_params
*bsp
);
344 * Get BFD session control plane independent bit configuration state.
346 * \param bsp session parameters.
348 * \returns `true` if enabled otherwise `false`.
350 bool bfd_sess_cbit(const struct bfd_session_params
*bsp
);
353 * DEPRECATED: please avoid using timers directly and use profiles instead.
355 * Gets the configured timers.
357 * \param bsp BFD session parameters.
358 * \param detection_multiplier the detection multiplier value.
359 * \param min_rx minimum required receive period.
360 * \param min_tx minimum required transmission period.
362 void bfd_sess_timers(const struct bfd_session_params
*bsp
,
363 uint8_t *detection_multiplier
, uint32_t *min_rx
,
367 * Show BFD session configuration and status. If `json` is provided (e.g. not
368 * `NULL`) then information will be inserted in object, otherwise printed to
371 * \param vty Pointer to `vty` for outputting text.
372 * \param json (optional) JSON object pointer.
373 * \param bsp session parameters.
375 void bfd_sess_show(struct vty
*vty
, struct json_object
*json
,
376 struct bfd_session_params
*bsp
);
379 * Initializes the BFD integration library. This function executes the
382 * - Copy the `struct thread_master` pointer to use as "thread" to execute
383 * the BFD session parameters installation.
384 * - Copy the `struct zclient` pointer to install its callbacks.
385 * - Initializes internal data structures.
387 * \param tm normally the daemon main thread event manager.
388 * \param zc the zebra client of the daemon.
390 void bfd_protocol_integration_init(struct zclient
*zc
,
391 struct thread_master
*tm
);
394 * BFD session registration arguments.
396 struct bfd_session_arg
{
401 * - `ZEBRA_BFD_DEST_REGISTER`
402 * - `ZEBRA_BFD_DEST_DEREGISTER`
414 /** Source address. */
416 /** Source address. */
419 /** Multi hop indicator. */
423 /** C bit (Control Plane Independent bit) indicator. */
426 /** Interface name size. */
428 /** Interface name. */
431 /** Daemon or session VRF. */
434 /** Profile name length. */
437 char profile
[BFD_PROFILE_NAME_LEN
];
440 * Deprecation fields: these fields should be removed once `ptm-bfd`
441 * no longer uses this interface.
444 /** Minimum required receive interval (in microseconds). */
446 /** Minimum desired transmission interval (in microseconds). */
448 /** Detection multiplier. */
449 uint32_t detection_multiplier
;
453 * Send a message to BFD daemon through the zebra client.
455 * \param zc the zebra client context.
456 * \param arg the BFD session command arguments.
458 * \returns `-1` on failure otherwise `0`.
460 * \see bfd_session_arg.
462 extern int zclient_bfd_command(struct zclient
*zc
, struct bfd_session_arg
*arg
);
465 * Enables or disables BFD protocol integration API debugging.
467 * \param enable new API debug state.
469 extern void bfd_protocol_integration_set_debug(bool enable
);
472 * Sets shutdown mode so no more events are processed.
474 * This is useful to avoid the event storm that happens caused by network,
475 * interfaces or VRFs removal. It should also avoid some crashes due hanging
476 * pointers left overs by protocol.
478 * \param enable new API shutdown state.
480 extern void bfd_protocol_integration_set_shutdown(bool enable
);
483 * Get API debugging state.
485 extern bool bfd_protocol_integration_debug(void);
488 * Get API shutdown state.
490 extern bool bfd_protocol_integration_shutting_down(void);
496 #endif /* _ZEBRA_BFD_H */