summaryrefslogtreecommitdiffstats
path: root/lib/bfd.h
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2020-08-26 22:08:41 +0200
committerRafael Zalamena <rzalamena@opensourcerouting.org>2021-03-23 16:40:09 +0100
commita099abe55b9b4cc53ef7c19a11042a5e3b70ccb3 (patch)
tree7ddb38a99c5506f4c8c169ecdf0d90f898b10bb3 /lib/bfd.h
parentMerge pull request #8253 from opensourcerouting/topotest-python3-backports (diff)
downloadfrr-a099abe55b9b4cc53ef7c19a11042a5e3b70ccb3.tar.xz
frr-a099abe55b9b4cc53ef7c19a11042a5e3b70ccb3.zip
lib: new BFD integration API
New BFD protocol integration API with abstractions to fix most common protocol integration errors: - Set address family together with the source/destination addresses - Set the TTL together with the single/multi hop option - Set/unset profile/interface easily - Keep the arguments so we don't have to rebuild them every time - Install/uninstall functions that keep track of current state so the daemon doesn't have to - Reinstall when critical configuration changes (address, multi hop etc...) - Reconfigure BFD when the daemon restarts automatically - Automatically calls the user defined callback for session update - Shutdown handler for all protocols Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'lib/bfd.h')
-rw-r--r--lib/bfd.h327
1 files changed, 327 insertions, 0 deletions
diff --git a/lib/bfd.h b/lib/bfd.h
index ceab4628b..1325f86a3 100644
--- a/lib/bfd.h
+++ b/lib/bfd.h
@@ -128,6 +128,305 @@ extern void bfd_gbl_exit(void);
* BFD new API.
*/
+/* Forward declaration of argument struct. */
+struct bfd_session_params;
+
+/** Session state definitions. */
+enum bfd_session_state {
+ /** Session state is unknown or not initialized. */
+ BSS_UNKNOWN = BFD_STATUS_UNKNOWN,
+ /** Local or remote peer administratively shutdown the session. */
+ BSS_ADMIN_DOWN = BFD_STATUS_ADMIN_DOWN,
+ /** Session is down. */
+ BSS_DOWN = BFD_STATUS_DOWN,
+ /** Session is up and working correctly. */
+ BSS_UP = BFD_STATUS_UP,
+};
+
+/** BFD session status information */
+struct bfd_session_status {
+ /** Current session state. */
+ enum bfd_session_state state;
+ /** Previous session state. */
+ enum bfd_session_state previous_state;
+ /** Remote Control Plane Independent bit state. */
+ bool remote_cbit;
+ /** Last event occurrence. */
+ time_t last_event;
+};
+
+/**
+ * Session status update callback.
+ *
+ * \param bsp BFD session parameters.
+ * \param bss BFD session status.
+ * \param arg application independent data.
+ */
+typedef void (*bsp_status_update)(struct bfd_session_params *bsp,
+ const struct bfd_session_status *bss,
+ void *arg);
+
+/**
+ * Allocates and initializes the session parameters.
+ *
+ * \param updatedb status update notification callback.
+ * \param args application independent data.
+ *
+ * \returns pointer to configuration storage.
+ */
+struct bfd_session_params *bfd_sess_new(bsp_status_update updatecb, void *args);
+
+/**
+ * Uninstall session if installed and free resources allocated by the
+ * parameters. Already sets pointer to `NULL` to avoid dangling references.
+ *
+ * \param bsp session parameters.
+ */
+void bfd_sess_free(struct bfd_session_params **bsp);
+
+/**
+ * Enable/disable session installation.
+ *
+ * \param bsp session parameters.
+ * \param enable knob variable.
+ */
+void bfd_sess_enable(struct bfd_session_params *bsp, bool enable);
+
+/**
+ * Set the local and peer address of the BFD session.
+ *
+ * \param bsp BFD session parameters.
+ * \param src local address (optional, can be `NULL`).
+ * \param dst remote address (mandatory).
+ */
+void bfd_sess_set_ipv4_addrs(struct bfd_session_params *bsp,
+ struct in_addr *src, struct in_addr *dst);
+
+/**
+ * Set the local and peer address of the BFD session.
+ *
+ * \param bsp BFD session parameters.
+ * \param src local address (optional, can be `NULL`).
+ * \param dst remote address (mandatory).
+ */
+void bfd_sess_set_ipv6_addrs(struct bfd_session_params *bsp,
+ struct in6_addr *src, struct in6_addr *dst);
+
+/**
+ * Configure the BFD session interface.
+ *
+ * \param bsp BFD session parameters.
+ * \param ifname interface name (or `NULL` to remove it).
+ */
+void bfd_sess_set_interface(struct bfd_session_params *bsp, const char *ifname);
+
+/**
+ * Configure the BFD session profile name.
+ *
+ * \param bsp BFD session parameters.
+ * \param profile profile name (or `NULL` to remove it).
+ */
+void bfd_sess_set_profile(struct bfd_session_params *bsp, const char *profile);
+
+/**
+ * Configure the BFD session VRF.
+ *
+ * \param bsp BFD session parameters.
+ * \param vrf_id the VRF identification number.
+ */
+void bfd_sess_set_vrf(struct bfd_session_params *bsp, vrf_id_t vrf_id);
+
+/**
+ * Configure the BFD session single/multi hop setting.
+ *
+ * \param bsp BFD session parameters.
+ * \param min_ttl minimum TTL value expected (255 for single hop, 254 for
+ * multi hop with single hop, 253 for multi hop with two hops
+ * and so on). See `BFD_SINGLE_HOP_TTL` and
+ * `BFD_MULTI_HOP_MIN_TTL` for defaults.
+ *
+ * To simplify things if your protocol only knows the amount of hops it is
+ * better to use `bfd_sess_set_hops` instead.
+ */
+void bfd_sess_set_mininum_ttl(struct bfd_session_params *bsp, uint8_t min_ttl);
+
+/** To use single hop the minimum TTL must be set to this. */
+#define BFD_SINGLE_HOP_TTL 255
+/** To use multi hop the minimum TTL must be set to this or less. */
+#define BFD_MULTI_HOP_MIN_TTL 254
+
+/**
+ * This function is the inverted version of `bfd_sess_set_minimum_ttl`.
+ * Instead of receiving the minimum expected TTL, it receives the amount of
+ * hops the protocol will jump.
+ *
+ * \param bsp BFD session parameters.
+ * \param min_ttl minimum amount of hops expected (1 for single hop, 2 or
+ * more for multi hop).
+ */
+void bfd_sess_set_hop_count(struct bfd_session_params *bsp, uint8_t min_ttl);
+
+/**
+ * Configure the BFD session to set the Control Plane Independent bit.
+ *
+ * \param bsp BFD session parameters.
+ * \param enable BFD Control Plane Independent state.
+ */
+void bfd_sess_set_cbit(struct bfd_session_params *bsp, bool enable);
+
+/**
+ * DEPRECATED: please avoid using timers directly and use profiles instead.
+ *
+ * Configures the BFD session timers to use. This is specially useful with
+ * `ptm-bfd` which does not support timers.
+ *
+ * \param bsp BFD session parameters.
+ * \param detection_multiplier the detection multiplier value.
+ * \param min_rx minimum required receive period.
+ * \param min_tx minimum required transmission period.
+ */
+void bfd_sess_set_timers(struct bfd_session_params *bsp,
+ uint8_t detection_multiplier, uint32_t min_rx,
+ uint32_t min_tx);
+
+/**
+ * Installs or updates the BFD session based on the saved session arguments.
+ *
+ * \param bsp session parameters.
+ */
+void bfd_sess_install(struct bfd_session_params *bsp);
+
+/**
+ * Uninstall the BFD session based on the saved session arguments.
+ *
+ * \param bsp session parameters.
+ */
+void bfd_sess_uninstall(struct bfd_session_params *bsp);
+
+/**
+ * Get BFD session current status.
+ *
+ * \param bsp session parameters.
+ *
+ * \returns BFD session status data structure.
+ */
+enum bfd_session_state bfd_sess_status(const struct bfd_session_params *bsp);
+
+/**
+ * Get BFD session minimum TTL configured value.
+ *
+ * \param bsp session parameters.
+ *
+ * \returns configured minimum TTL.
+ */
+uint8_t bfd_sess_minimum_ttl(const struct bfd_session_params *bsp);
+
+/**
+ * Inverted version of `bfd_sess_minimum_ttl`. Gets the amount of hops in the
+ * way to the peer.
+ *
+ * \param bsp session parameters.
+ *
+ * \returns configured amount of hops.
+ */
+uint8_t bfd_sess_hop_count(const struct bfd_session_params *bsp);
+
+/**
+ * Get BFD session profile configured value.
+ *
+ * \param bsp session parameters.
+ *
+ * \returns configured profile name (or `NULL` if empty).
+ */
+const char *bfd_sess_profile(const struct bfd_session_params *bsp);
+
+/**
+ * Get BFD session addresses.
+ *
+ * \param bsp session parameters.
+ * \param family the address family being used (AF_INET or AF_INET6).
+ * \param src source address (optional, may be `NULL`).
+ * \param dst peer address (optional, may be `NULL`).
+ */
+void bfd_sess_addresses(const struct bfd_session_params *bsp, int *family,
+ struct in6_addr *src, struct in6_addr *dst);
+/**
+ * Get BFD session interface name.
+ *
+ * \param bsp session parameters.
+ *
+ * \returns `NULL` if not set otherwise the interface name.
+ */
+const char *bfd_sess_interface(const struct bfd_session_params *bsp);
+
+/**
+ * Get BFD session VRF name.
+ *
+ * \param bsp session parameters.
+ *
+ * \returns the VRF name.
+ */
+const char *bfd_sess_vrf(const struct bfd_session_params *bsp);
+
+/**
+ * Get BFD session VRF ID.
+ *
+ * \param bsp session parameters.
+ *
+ * \returns the VRF name.
+ */
+vrf_id_t bfd_sess_vrf_id(const struct bfd_session_params *bsp);
+
+/**
+ * Get BFD session control plane independent bit configuration state.
+ *
+ * \param bsp session parameters.
+ *
+ * \returns `true` if enabled otherwise `false`.
+ */
+bool bfd_sess_cbit(const struct bfd_session_params *bsp);
+
+/**
+ * DEPRECATED: please avoid using timers directly and use profiles instead.
+ *
+ * Gets the configured timers.
+ *
+ * \param bsp BFD session parameters.
+ * \param detection_multiplier the detection multiplier value.
+ * \param min_rx minimum required receive period.
+ * \param min_tx minimum required transmission period.
+ */
+void bfd_sess_timers(const struct bfd_session_params *bsp,
+ uint8_t *detection_multiplier, uint32_t *min_rx,
+ uint32_t *min_tx);
+
+/**
+ * Show BFD session configuration and status. If `json` is provided (e.g. not
+ * `NULL`) then information will be inserted in object, otherwise printed to
+ * `vty`.
+ *
+ * \param vty Pointer to `vty` for outputting text.
+ * \param json (optional) JSON object pointer.
+ * \param bsp session parameters.
+ */
+void bfd_sess_show(struct vty *vty, struct json_object *json,
+ struct bfd_session_params *bsp);
+
+/**
+ * Initializes the BFD integration library. This function executes the
+ * following actions:
+ *
+ * - Copy the `struct thread_master` pointer to use as "thread" to execute
+ * the BFD session parameters installation.
+ * - Copy the `struct zclient` pointer to install its callbacks.
+ * - Initializes internal data structures.
+ *
+ * \param tm normally the daemon main thread event manager.
+ * \param zc the zebra client of the daemon.
+ */
+void bfd_protocol_integration_init(struct zclient *zc,
+ struct thread_master *tm);
+
/**
* BFD session registration arguments.
*/
@@ -205,6 +504,34 @@ struct bfd_session_arg {
*/
extern int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *arg);
+/**
+ * Enables or disables BFD protocol integration API debugging.
+ *
+ * \param enable new API debug state.
+ */
+extern void bfd_protocol_integration_set_debug(bool enable);
+
+/**
+ * Sets shutdown mode so no more events are processed.
+ *
+ * This is useful to avoid the event storm that happens caused by network,
+ * interfaces or VRFs removal. It should also avoid some crashes due hanging
+ * pointers left overs by protocol.
+ *
+ * \param enable new API shutdown state.
+ */
+extern void bfd_protocol_integration_set_shutdown(bool enable);
+
+/**
+ * Get API debugging state.
+ */
+extern bool bfd_protocol_integration_debug(void);
+
+/**
+ * Get API shutdown state.
+ */
+extern bool bfd_protocol_integration_shutting_down(void);
+
#ifdef __cplusplus
}
#endif