summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2021-03-24 08:36:48 +0100
committerGitHub <noreply@github.com>2021-03-24 08:36:48 +0100
commit09e2d8ed97310687a87068e9f8173555b3abee70 (patch)
treea6fd1520fc806612fef40e6c49fc4e70535450b3
parentMerge pull request #8184 from opensourcerouting/bfd-bgp-napi (diff)
parentospfd: fix checkpatch warnings (diff)
downloadfrr-09e2d8ed97310687a87068e9f8173555b3abee70.tar.xz
frr-09e2d8ed97310687a87068e9f8173555b3abee70.zip
Merge pull request #8203 from opensourcerouting/ospf-bfd-napi
ospfd,doc,topotests: rework OSPFv2 BFD integrantion
-rw-r--r--doc/user/bfd.rst5
-rw-r--r--doc/user/ospfd.rst6
-rw-r--r--ospfd/ospf_bfd.c474
-rw-r--r--ospfd/ospf_bfd.h31
-rw-r--r--ospfd/ospf_dump.c44
-rw-r--r--ospfd/ospf_dump.h3
-rw-r--r--ospfd/ospf_interface.c12
-rw-r--r--ospfd/ospf_interface.h13
-rw-r--r--ospfd/ospf_main.c4
-rw-r--r--ospfd/ospf_neighbor.c8
-rw-r--r--ospfd/ospf_neighbor.h2
-rw-r--r--ospfd/ospf_nsm.c3
-rw-r--r--ospfd/ospf_vty.c7
-rw-r--r--ospfd/ospfd.c4
-rw-r--r--tests/topotests/bfd-profiles-topo1/r1/bfd-peers-initial.json4
-rw-r--r--tests/topotests/bfd-profiles-topo1/r1/ospfd.conf2
-rw-r--r--tests/topotests/bfd-profiles-topo1/r6/bfd-peers-initial.json4
17 files changed, 277 insertions, 349 deletions
diff --git a/doc/user/bfd.rst b/doc/user/bfd.rst
index 7d136b183..6f797f7cc 100644
--- a/doc/user/bfd.rst
+++ b/doc/user/bfd.rst
@@ -313,6 +313,11 @@ The following commands are available inside the interface configuration node.
a new neighbor is found a BFD peer is created to monitor the link
status for fast convergence.
+.. clicmd:: ip ospf bfd profile BFDPROF
+
+ Same as command ``ip ospf bfd``, but applies the BFD profile to the sessions
+ it creates or that already exist.
+
.. _bfd-ospf6-peer-config:
diff --git a/doc/user/ospfd.rst b/doc/user/ospfd.rst
index 251070448..64ce85503 100644
--- a/doc/user/ospfd.rst
+++ b/doc/user/ospfd.rst
@@ -968,6 +968,12 @@ TI-LFA requires a proper Segment Routing configuration.
Debugging OSPF
==============
+.. clicmd:: debug ospf bfd
+
+ Enable or disable debugging for BFD events. This will show BFD integration
+ library messages and OSPF BFD integration messages that are mostly state
+ transitions and validation problems.
+
.. clicmd:: debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv) [detail]
diff --git a/ospfd/ospf_bfd.c b/ospfd/ospf_bfd.c
index a9bc9069d..b202cd01f 100644
--- a/ospfd/ospf_bfd.c
+++ b/ospfd/ospf_bfd.c
@@ -23,6 +23,7 @@
#include <zebra.h>
#include "command.h"
+#include "json.h"
#include "linklist.h"
#include "memory.h"
#include "prefix.h"
@@ -44,48 +45,7 @@
#include "ospf_dump.h"
#include "ospf_vty.h"
-extern struct zclient *zclient;
-
-/*
- * ospf_bfd_info_free - Free BFD info structure
- */
-void ospf_bfd_info_free(void **bfd_info)
-{
- bfd_info_free((struct bfd_info **)bfd_info);
-}
-
-/*
- * ospf_bfd_reg_dereg_nbr - Register/Deregister a neighbor with BFD through
- * zebra for starting/stopping the monitoring of
- * the neighbor rechahability.
- */
-static void ospf_bfd_reg_dereg_nbr(struct ospf_neighbor *nbr, int command)
-{
- struct ospf_interface *oi = nbr->oi;
- struct interface *ifp = oi->ifp;
- struct ospf_if_params *params;
- struct bfd_info *bfd_info;
- int cbit;
-
- /* Check if BFD is enabled */
- params = IF_DEF_PARAMS(ifp);
-
- /* Check if BFD is enabled */
- if (!params->bfd_info)
- return;
- bfd_info = (struct bfd_info *)params->bfd_info;
-
- if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
- zlog_debug("%s nbr (%pI4) with BFD. OSPF vrf %s",
- bfd_get_command_dbg_str(command),
- &nbr->src,
- ospf_vrf_id_to_name(oi->ospf->vrf_id));
-
- cbit = CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_CBIT_ON);
-
- bfd_peer_sendmsg(zclient, bfd_info, AF_INET, &nbr->src, NULL, ifp->name,
- 0, 0, cbit, command, 0, oi->ospf->vrf_id);
-}
+DEFINE_MTYPE_STATIC(OSPFD, BFD_CONFIG, "BFD configuration data");
/*
* ospf_bfd_trigger_event - Neighbor is registered/deregistered with BFD when
@@ -94,293 +54,155 @@ static void ospf_bfd_reg_dereg_nbr(struct ospf_neighbor *nbr, int command)
void ospf_bfd_trigger_event(struct ospf_neighbor *nbr, int old_state, int state)
{
if ((old_state < NSM_TwoWay) && (state >= NSM_TwoWay))
- ospf_bfd_reg_dereg_nbr(nbr, ZEBRA_BFD_DEST_REGISTER);
+ bfd_sess_install(nbr->bfd_session);
else if ((old_state >= NSM_TwoWay) && (state < NSM_TwoWay))
- ospf_bfd_reg_dereg_nbr(nbr, ZEBRA_BFD_DEST_DEREGISTER);
+ bfd_sess_uninstall(nbr->bfd_session);
}
-/*
- * ospf_bfd_reg_dereg_all_nbr - Register/Deregister all neighbors associated
- * with a interface with BFD through
- * zebra for starting/stopping the monitoring of
- * the neighbor rechahability.
- */
-static int ospf_bfd_reg_dereg_all_nbr(struct interface *ifp, int command)
+static void ospf_bfd_session_change(struct bfd_session_params *bsp,
+ const struct bfd_session_status *bss,
+ void *arg)
{
- struct ospf_interface *oi;
- struct route_table *nbrs;
- struct ospf_neighbor *nbr;
- struct route_node *irn;
- struct route_node *nrn;
-
- for (irn = route_top(IF_OIFS(ifp)); irn; irn = route_next(irn)) {
- if ((oi = irn->info) == NULL)
- continue;
+ struct ospf_neighbor *nbr = arg;
- if ((nbrs = oi->nbrs) == NULL)
- continue;
-
- for (nrn = route_top(nbrs); nrn; nrn = route_next(nrn)) {
- if ((nbr = nrn->info) == NULL || nbr == oi->nbr_self)
- continue;
-
- if (command != ZEBRA_BFD_DEST_DEREGISTER)
- ospf_bfd_info_nbr_create(oi, nbr);
- else
- bfd_info_free(
- (struct bfd_info **)&nbr->bfd_info);
-
- if (nbr->state < NSM_TwoWay)
- continue;
+ /* BFD peer went down. */
+ if (bss->state == BFD_STATUS_DOWN
+ && bss->previous_state == BFD_STATUS_UP) {
+ if (IS_DEBUG_OSPF(bfd, BFD_LIB))
+ zlog_debug("%s: NSM[%s:%pI4]: BFD Down", __func__,
+ IF_NAME(nbr->oi), &nbr->address.u.prefix4);
- ospf_bfd_reg_dereg_nbr(nbr, command);
- }
+ OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_InactivityTimer);
}
- return 0;
+ /* BFD peer went up. */
+ if (bss->state == BSS_UP && bss->previous_state == BSS_DOWN)
+ if (IS_DEBUG_OSPF(bfd, BFD_LIB))
+ zlog_debug("%s: NSM[%s:%pI4]: BFD Up", __func__,
+ IF_NAME(nbr->oi), &nbr->address.u.prefix4);
}
-/*
- * ospf_bfd_nbr_replay - Replay all the neighbors that have BFD enabled
- * to zebra
- */
-static int ospf_bfd_nbr_replay(ZAPI_CALLBACK_ARGS)
+void ospf_neighbor_bfd_apply(struct ospf_neighbor *nbr)
{
- struct listnode *inode, *node, *onode;
- struct ospf *ospf;
- struct ospf_interface *oi;
- struct route_table *nbrs;
- struct route_node *rn;
- struct ospf_neighbor *nbr;
- struct ospf_if_params *params;
+ struct ospf_interface *oi = nbr->oi;
+ struct ospf_if_params *oip = IF_DEF_PARAMS(oi->ifp);
- if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) {
- zlog_debug("Zebra: BFD Dest replay request");
+ /* BFD configuration was removed. */
+ if (oip->bfd_config == NULL) {
+ bfd_sess_free(&nbr->bfd_session);
+ return;
}
- /* Send the client registration */
- bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER, vrf_id);
-
- /* Replay the neighbor, if BFD is enabled in OSPF */
- for (ALL_LIST_ELEMENTS(om->ospf, node, onode, ospf)) {
- for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, inode, oi)) {
- if ((nbrs = oi->nbrs) == NULL)
- continue;
-
- params = IF_DEF_PARAMS(oi->ifp);
- if (!params->bfd_info)
- continue;
-
- for (rn = route_top(nbrs); rn; rn = route_next(rn)) {
- if ((nbr = rn->info) == NULL
- || nbr == oi->nbr_self)
- continue;
+ /* New BFD session. */
+ if (nbr->bfd_session == NULL) {
+ nbr->bfd_session = bfd_sess_new(ospf_bfd_session_change, nbr);
+ bfd_sess_set_ipv4_addrs(nbr->bfd_session, NULL, &nbr->src);
+ bfd_sess_set_interface(nbr->bfd_session, oi->ifp->name);
+ bfd_sess_set_vrf(nbr->bfd_session, oi->ospf->vrf_id);
+ bfd_sess_enable(nbr->bfd_session, true);
+ }
- if (nbr->state < NSM_TwoWay)
- continue;
+ /* Set new configuration. */
+ bfd_sess_set_timers(nbr->bfd_session,
+ oip->bfd_config->detection_multiplier,
+ oip->bfd_config->min_rx, oip->bfd_config->min_tx);
+ bfd_sess_set_profile(nbr->bfd_session, oip->bfd_config->profile);
- if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
- zlog_debug("Replaying nbr (%pI4) to BFD",
- &nbr->src);
+ /* Don't start sessions on down OSPF sessions. */
+ if (nbr->state < NSM_TwoWay)
+ return;
- ospf_bfd_reg_dereg_nbr(nbr,
- ZEBRA_BFD_DEST_UPDATE);
- }
- }
- }
- return 0;
+ bfd_sess_install(nbr->bfd_session);
}
-/*
- * ospf_bfd_interface_dest_update - Find the neighbor for which the BFD status
- * has changed and bring down the neighbor
- * connectivity if the BFD status changed to
- * down.
- */
-static int ospf_bfd_interface_dest_update(ZAPI_CALLBACK_ARGS)
+static void ospf_interface_bfd_apply(struct interface *ifp)
{
- struct interface *ifp;
struct ospf_interface *oi;
- struct ospf_if_params *params;
- struct ospf_neighbor *nbr = NULL;
- struct route_node *node;
- struct route_node *n_node;
- struct prefix p, src_p;
- int status;
- int old_status;
- struct bfd_info *bfd_info;
- struct timeval tv;
-
- ifp = bfd_get_peer_info(zclient->ibuf, &p, &src_p, &status, NULL,
- vrf_id);
-
- if ((ifp == NULL) || (p.family != AF_INET))
- return 0;
-
- if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
- zlog_debug("Zebra: interface %s bfd destination %pFX %s",
- ifp->name, &p, bfd_get_status_str(status));
-
- params = IF_DEF_PARAMS(ifp);
- if (!params->bfd_info)
- return 0;
-
- for (node = route_top(IF_OIFS(ifp)); node; node = route_next(node)) {
- if ((oi = node->info) == NULL)
- continue;
-
- /* walk the neighbor list for point-to-point network */
- if (oi->type == OSPF_IFTYPE_POINTOPOINT) {
- for (n_node = route_top(oi->nbrs); n_node;
- n_node = route_next(n_node)) {
- nbr = n_node->info;
- if (nbr) {
- /* skip myself */
- if (nbr == oi->nbr_self) {
- nbr = NULL;
- continue;
- }
-
- /* Found the matching neighbor */
- if (nbr->src.s_addr ==
- p.u.prefix4.s_addr)
- break;
- }
- }
- } else {
- nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &p.u.prefix4);
- }
+ struct route_table *nbrs;
+ struct ospf_neighbor *nbr;
+ struct route_node *irn;
+ struct route_node *nrn;
- if (!nbr || !nbr->bfd_info)
+ /* Iterate over all interfaces and set neighbors BFD session. */
+ for (irn = route_top(IF_OIFS(ifp)); irn; irn = route_next(irn)) {
+ if ((oi = irn->info) == NULL)
continue;
-
- bfd_info = (struct bfd_info *)nbr->bfd_info;
- if (bfd_info->status == status)
+ if ((nbrs = oi->nbrs) == NULL)
continue;
+ for (nrn = route_top(nbrs); nrn; nrn = route_next(nrn)) {
+ if ((nbr = nrn->info) == NULL || nbr == oi->nbr_self)
+ continue;
- old_status = bfd_info->status;
- BFD_SET_CLIENT_STATUS(bfd_info->status, status);
- monotime(&tv);
- bfd_info->last_update = tv.tv_sec;
-
- if ((status == BFD_STATUS_DOWN)
- && (old_status == BFD_STATUS_UP)) {
- if (IS_DEBUG_OSPF(nsm, NSM_EVENTS))
- zlog_debug("NSM[%s:%pI4]: BFD Down",
- IF_NAME(nbr->oi),
- &nbr->address.u.prefix4);
-
- OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_InactivityTimer);
- }
- if ((status == BFD_STATUS_UP)
- && (old_status == BFD_STATUS_DOWN)) {
- if (IS_DEBUG_OSPF(nsm, NSM_EVENTS))
- zlog_debug("NSM[%s:%pI4]: BFD Up",
- IF_NAME(nbr->oi),
- &nbr->address.u.prefix4);
+ ospf_neighbor_bfd_apply(nbr);
}
}
-
- return 0;
}
-/*
- * ospf_bfd_info_nbr_create - Create/update BFD information for a neighbor.
- */
-void ospf_bfd_info_nbr_create(struct ospf_interface *oi,
- struct ospf_neighbor *nbr)
+static void ospf_interface_enable_bfd(struct interface *ifp)
{
- struct bfd_info *oi_bfd_info;
- struct bfd_info *nbr_bfd_info;
- struct interface *ifp = oi->ifp;
- struct ospf_if_params *params;
-
- /* Check if BFD is enabled */
- params = IF_DEF_PARAMS(ifp);
+ struct ospf_if_params *oip = IF_DEF_PARAMS(ifp);
- /* Check if BFD is enabled */
- if (!params->bfd_info)
+ if (oip->bfd_config)
return;
- oi_bfd_info = (struct bfd_info *)params->bfd_info;
- if (!nbr->bfd_info)
- nbr->bfd_info = bfd_info_create();
+ /* Allocate memory for configurations and set defaults. */
+ oip->bfd_config = XCALLOC(MTYPE_BFD_CONFIG, sizeof(*oip->bfd_config));
+ oip->bfd_config->detection_multiplier = BFD_DEF_DETECT_MULT;
+ oip->bfd_config->min_rx = BFD_DEF_MIN_RX;
+ oip->bfd_config->min_tx = BFD_DEF_MIN_TX;
+}
- nbr_bfd_info = (struct bfd_info *)nbr->bfd_info;
- nbr_bfd_info->detect_mult = oi_bfd_info->detect_mult;
- nbr_bfd_info->desired_min_tx = oi_bfd_info->desired_min_tx;
- nbr_bfd_info->required_min_rx = oi_bfd_info->required_min_rx;
+void ospf_interface_disable_bfd(struct interface *ifp,
+ struct ospf_if_params *oip)
+{
+ XFREE(MTYPE_BFD_CONFIG, oip->bfd_config);
+ ospf_interface_bfd_apply(ifp);
}
/*
* ospf_bfd_write_config - Write the interface BFD configuration.
*/
-void ospf_bfd_write_config(struct vty *vty, struct ospf_if_params *params)
-
+void ospf_bfd_write_config(struct vty *vty, const struct ospf_if_params *params
+ __attribute__((unused)))
{
#if HAVE_BFDD == 0
- struct bfd_info *bfd_info;
-#endif /* ! HAVE_BFDD */
-
- if (!params->bfd_info)
- return;
-
-#if HAVE_BFDD == 0
- bfd_info = (struct bfd_info *)params->bfd_info;
-
if (CHECK_FLAG(bfd_info->flags, BFD_FLAG_PARAM_CFG))
- vty_out(vty, " ip ospf bfd %d %d %d\n", bfd_info->detect_mult,
- bfd_info->required_min_rx, bfd_info->desired_min_tx);
+ vty_out(vty, " ip ospf bfd %d %d %d\n",
+ params->bfd_config->detection_multiplier,
+ params->bfd_config->min_rx, params->bfd_config->min_tx);
else
#endif /* ! HAVE_BFDD */
vty_out(vty, " ip ospf bfd\n");
-}
-/*
- * ospf_bfd_show_info - Show BFD info structure
- */
-void ospf_bfd_show_info(struct vty *vty, void *bfd_info, json_object *json_obj,
- bool use_json, int param_only)
-{
- if (param_only)
- bfd_show_param(vty, (struct bfd_info *)bfd_info, 1, 0, use_json,
- json_obj);
- else
- bfd_show_info(vty, (struct bfd_info *)bfd_info, 0, 1, use_json,
- json_obj);
+ if (params->bfd_config->profile[0])
+ vty_out(vty, " ip ospf bfd profile %s\n",
+ params->bfd_config->profile);
}
-/*
- * ospf_bfd_interface_show - Show the interface BFD configuration.
- */
-void ospf_bfd_interface_show(struct vty *vty, struct interface *ifp,
- json_object *json_interface_sub, bool use_json)
+void ospf_interface_bfd_show(struct vty *vty, const struct interface *ifp,
+ struct json_object *json)
{
- struct ospf_if_params *params;
-
- params = IF_DEF_PARAMS(ifp);
+ struct ospf_if_params *params = IF_DEF_PARAMS(ifp);
+ struct bfd_configuration *bfd_config = params->bfd_config;
+ struct json_object *json_bfd;
- ospf_bfd_show_info(vty, params->bfd_info, json_interface_sub, use_json,
- 1);
-}
-
-/*
- * ospf_bfd_if_param_set - Set the configured BFD paramter values for
- * interface.
- */
-static void ospf_bfd_if_param_set(struct interface *ifp, uint32_t min_rx,
- uint32_t min_tx, uint8_t detect_mult,
- int defaults)
-{
- struct ospf_if_params *params;
- int command = 0;
-
- params = IF_DEF_PARAMS(ifp);
+ if (bfd_config == NULL)
+ return;
- bfd_set_param((struct bfd_info **)&(params->bfd_info), min_rx, min_tx,
- detect_mult, NULL, defaults, &command);
- if (command)
- ospf_bfd_reg_dereg_all_nbr(ifp, command);
+ if (json) {
+ json_bfd = json_object_new_object();
+ json_object_int_add(json_bfd, "detectionMultiplier",
+ bfd_config->detection_multiplier);
+ json_object_int_add(json_bfd, "rxMinInterval",
+ bfd_config->min_rx);
+ json_object_int_add(json_bfd, "txMinInterval",
+ bfd_config->min_tx);
+ json_object_object_add(json, "peerBfdInfo", json_bfd);
+ } else
+ vty_out(vty,
+ " BFD: Detect Multiplier: %d, Min Rx interval: %d, Min Tx interval: %d\n",
+ bfd_config->detection_multiplier, bfd_config->min_rx,
+ bfd_config->min_tx);
}
DEFUN (ip_ospf_bfd,
@@ -391,17 +213,8 @@ DEFUN (ip_ospf_bfd,
"Enables BFD support\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
- struct ospf_if_params *params;
- struct bfd_info *bfd_info;
-
- assert(ifp);
- params = IF_DEF_PARAMS(ifp);
- bfd_info = params->bfd_info;
-
- if (!bfd_info || !CHECK_FLAG(bfd_info->flags, BFD_FLAG_PARAM_CFG))
- ospf_bfd_if_param_set(ifp, BFD_DEF_MIN_RX, BFD_DEF_MIN_TX,
- BFD_DEF_DETECT_MULT, 1);
-
+ ospf_interface_enable_bfd(ifp);
+ ospf_interface_bfd_apply(ifp);
return CMD_SUCCESS;
}
@@ -421,23 +234,63 @@ DEFUN(
"Desired min transmit interval\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
+ struct ospf_if_params *params;
int idx_number = 3;
int idx_number_2 = 4;
int idx_number_3 = 5;
- uint32_t rx_val;
- uint32_t tx_val;
- uint8_t dm_val;
- int ret;
- assert(ifp);
+ ospf_interface_enable_bfd(ifp);
+
+ params = IF_DEF_PARAMS(ifp);
+ params->bfd_config->detection_multiplier =
+ strtol(argv[idx_number]->arg, NULL, 10);
+ params->bfd_config->min_rx = strtol(argv[idx_number_2]->arg, NULL, 10);
+ params->bfd_config->min_tx = strtol(argv[idx_number_3]->arg, NULL, 10);
+
+ ospf_interface_bfd_apply(ifp);
+
+ return CMD_SUCCESS;
+}
- if ((ret = bfd_validate_param(
- vty, argv[idx_number]->arg, argv[idx_number_2]->arg,
- argv[idx_number_3]->arg, &dm_val, &rx_val, &tx_val))
- != CMD_SUCCESS)
- return ret;
+DEFUN (ip_ospf_bfd_prof,
+ ip_ospf_bfd_prof_cmd,
+ "ip ospf bfd profile BFDPROF",
+ "IP Information\n"
+ "OSPF interface commands\n"
+ "Enables BFD support\n"
+ BFD_PROFILE_STR
+ BFD_PROFILE_NAME_STR)
+{
+ VTY_DECLVAR_CONTEXT(interface, ifp);
+ struct ospf_if_params *params;
+ int idx_prof = 4;
- ospf_bfd_if_param_set(ifp, rx_val, tx_val, dm_val, 0);
+ ospf_interface_enable_bfd(ifp);
+ params = IF_DEF_PARAMS(ifp);
+ strlcpy(params->bfd_config->profile, argv[idx_prof]->arg,
+ sizeof(params->bfd_config->profile));
+ ospf_interface_bfd_apply(ifp);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_ip_ospf_bfd_prof,
+ no_ip_ospf_bfd_prof_cmd,
+ "no ip ospf bfd profile [BFDPROF]",
+ NO_STR
+ "IP Information\n"
+ "OSPF interface commands\n"
+ "Enables BFD support\n"
+ BFD_PROFILE_STR
+ BFD_PROFILE_NAME_STR)
+{
+ VTY_DECLVAR_CONTEXT(interface, ifp);
+ struct ospf_if_params *params;
+
+ ospf_interface_enable_bfd(ifp);
+ params = IF_DEF_PARAMS(ifp);
+ params->bfd_config->profile[0] = 0;
+ ospf_interface_bfd_apply(ifp);
return CMD_SUCCESS;
}
@@ -461,29 +314,18 @@ DEFUN (no_ip_ospf_bfd,
)
{
VTY_DECLVAR_CONTEXT(interface, ifp);
- struct ospf_if_params *params;
-
- assert(ifp);
-
- params = IF_DEF_PARAMS(ifp);
- if (params->bfd_info) {
- ospf_bfd_reg_dereg_all_nbr(ifp, ZEBRA_BFD_DEST_DEREGISTER);
- bfd_info_free(&(params->bfd_info));
- }
-
+ ospf_interface_disable_bfd(ifp, IF_DEF_PARAMS(ifp));
return CMD_SUCCESS;
}
-void ospf_bfd_init(void)
+void ospf_bfd_init(struct thread_master *tm)
{
- bfd_gbl_init();
-
- /* Initialize BFD client functions */
- zclient->interface_bfd_dest_update = ospf_bfd_interface_dest_update;
- zclient->bfd_dest_replay = ospf_bfd_nbr_replay;
+ bfd_protocol_integration_init(zclient, tm);
/* Install BFD command */
install_element(INTERFACE_NODE, &ip_ospf_bfd_cmd);
install_element(INTERFACE_NODE, &ip_ospf_bfd_param_cmd);
+ install_element(INTERFACE_NODE, &ip_ospf_bfd_prof_cmd);
+ install_element(INTERFACE_NODE, &no_ip_ospf_bfd_prof_cmd);
install_element(INTERFACE_NODE, &no_ip_ospf_bfd_cmd);
}
diff --git a/ospfd/ospf_bfd.h b/ospfd/ospf_bfd.h
index 74385d326..9393c839f 100644
--- a/ospfd/ospf_bfd.h
+++ b/ospfd/ospf_bfd.h
@@ -23,27 +23,34 @@
#ifndef _ZEBRA_OSPF_BFD_H
#define _ZEBRA_OSPF_BFD_H
+#include "ospfd/ospf_interface.h"
#include "json.h"
-extern void ospf_bfd_init(void);
+extern void ospf_bfd_init(struct thread_master *tm);
extern void ospf_bfd_write_config(struct vty *vty,
- struct ospf_if_params *params);
+ const struct ospf_if_params *params);
extern void ospf_bfd_trigger_event(struct ospf_neighbor *nbr, int old_state,
int state);
-extern void ospf_bfd_interface_show(struct vty *vty, struct interface *ifp,
- json_object *json_interface_sub,
- bool use_json);
-
-extern void ospf_bfd_info_nbr_create(struct ospf_interface *oi,
- struct ospf_neighbor *nbr);
+/**
+ * Legacy information: it is the peers who actually have this information
+ * and the protocol should not need to know about timers.
+ */
+extern void ospf_interface_bfd_show(struct vty *vty,
+ const struct interface *ifp,
+ struct json_object *json);
-extern void ospf_bfd_show_info(struct vty *vty, void *bfd_info,
- json_object *json_obj, bool use_json,
- int param_only);
+/**
+ * Disables interface BFD configuration and remove settings from all peers.
+ */
+extern void ospf_interface_disable_bfd(struct interface *ifp,
+ struct ospf_if_params *oip);
-extern void ospf_bfd_info_free(void **bfd_info);
+/**
+ * Create/update BFD session for this OSPF neighbor.
+ */
+extern void ospf_neighbor_bfd_apply(struct ospf_neighbor *nbr);
#endif /* _ZEBRA_OSPF_BFD_H */
diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c
index 19829d454..2442f2e78 100644
--- a/ospfd/ospf_dump.c
+++ b/ospfd/ospf_dump.c
@@ -21,6 +21,7 @@
#include <zebra.h>
+#include "lib/bfd.h"
#include "monotime.h"
#include "linklist.h"
#include "thread.h"
@@ -60,6 +61,7 @@ unsigned long conf_debug_ospf_ti_lfa = 0;
unsigned long conf_debug_ospf_defaultinfo = 0;
unsigned long conf_debug_ospf_ldp_sync = 0;
unsigned long conf_debug_ospf_gr = 0;
+unsigned long conf_debug_ospf_bfd;
/* Enable debug option variables -- valid only session. */
unsigned long term_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
@@ -76,6 +78,7 @@ unsigned long term_debug_ospf_ti_lfa = 0;
unsigned long term_debug_ospf_defaultinfo;
unsigned long term_debug_ospf_ldp_sync;
unsigned long term_debug_ospf_gr = 0;
+unsigned long term_debug_ospf_bfd;
const char *ospf_redist_string(unsigned int route_type)
{
@@ -1563,6 +1566,31 @@ DEFPY (debug_ospf_gr,
return CMD_SUCCESS;
}
+DEFPY(debug_ospf_bfd, debug_ospf_bfd_cmd,
+ "[no] debug ospf bfd",
+ NO_STR
+ DEBUG_STR
+ OSPF_STR
+ "Bidirection Forwarding Detection\n")
+{
+ if (vty->node == CONFIG_NODE) {
+ if (no) {
+ bfd_protocol_integration_set_debug(false);
+ CONF_DEBUG_OFF(bfd, BFD_LIB);
+ } else {
+ bfd_protocol_integration_set_debug(true);
+ CONF_DEBUG_ON(bfd, BFD_LIB);
+ }
+ }
+
+ if (no)
+ TERM_DEBUG_OFF(bfd, BFD_LIB);
+ else
+ TERM_DEBUG_ON(bfd, BFD_LIB);
+
+ return CMD_SUCCESS;
+}
+
DEFUN (no_debug_ospf,
no_debug_ospf_cmd,
"no debug ospf",
@@ -1594,6 +1622,10 @@ DEFUN (no_debug_ospf,
DEBUG_OFF(defaultinfo, DEFAULTINFO);
DEBUG_OFF(ldp_sync, LDP_SYNC);
+ /* BFD debugging is two parts: OSPF and library. */
+ DEBUG_OFF(bfd, BFD_LIB);
+ bfd_protocol_integration_set_debug(false);
+
for (i = 0; i < 5; i++)
DEBUG_PACKET_OFF(i, flag);
}
@@ -1621,6 +1653,7 @@ DEFUN (no_debug_ospf,
TERM_DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
TERM_DEBUG_OFF(defaultinfo, DEFAULTINFO);
TERM_DEBUG_OFF(ldp_sync, LDP_SYNC);
+ TERM_DEBUG_OFF(bfd, BFD_LIB);
return CMD_SUCCESS;
}
@@ -1730,6 +1763,10 @@ static int show_debugging_ospf_common(struct vty *vty)
if (IS_DEBUG_OSPF(gr, GR_HELPER) == OSPF_DEBUG_GR_HELPER)
vty_out(vty, " OSPF Graceful Restart Helper debugging is on\n");
+ if (IS_DEBUG_OSPF(bfd, BFD_LIB) == OSPF_DEBUG_BFD_LIB)
+ vty_out(vty,
+ " OSPF BFD integration library debugging is on\n");
+
vty_out(vty, "\n");
return CMD_SUCCESS;
@@ -1917,6 +1954,11 @@ static int config_write_debug(struct vty *vty)
write = 1;
}
+ if (IS_CONF_DEBUG_OSPF(bfd, BFD_LIB) == OSPF_DEBUG_BFD_LIB) {
+ vty_out(vty, "debug ospf%s bfd\n", str);
+ write = 1;
+ }
+
return write;
}
@@ -1949,6 +1991,7 @@ void ospf_debug_init(void)
install_element(ENABLE_NODE, &no_debug_ospf_default_info_cmd);
install_element(ENABLE_NODE, &no_debug_ospf_ldp_sync_cmd);
install_element(ENABLE_NODE, &debug_ospf_gr_cmd);
+ install_element(ENABLE_NODE, &debug_ospf_bfd_cmd);
install_element(ENABLE_NODE, &show_debugging_ospf_instance_cmd);
install_element(ENABLE_NODE, &debug_ospf_packet_cmd);
@@ -1992,6 +2035,7 @@ void ospf_debug_init(void)
install_element(CONFIG_NODE, &no_debug_ospf_default_info_cmd);
install_element(CONFIG_NODE, &no_debug_ospf_ldp_sync_cmd);
install_element(CONFIG_NODE, &debug_ospf_gr_cmd);
+ install_element(CONFIG_NODE, &debug_ospf_bfd_cmd);
install_element(CONFIG_NODE, &debug_ospf_instance_nsm_cmd);
install_element(CONFIG_NODE, &debug_ospf_instance_lsa_cmd);
diff --git a/ospfd/ospf_dump.h b/ospfd/ospf_dump.h
index c4c560666..b1c1d02a5 100644
--- a/ospfd/ospf_dump.h
+++ b/ospfd/ospf_dump.h
@@ -67,6 +67,8 @@
#define OSPF_DEBUG_GR_HELPER 0x01
#define OSPF_DEBUG_GR 0x03
+#define OSPF_DEBUG_BFD_LIB 0x01
+
/* Macro for setting debug option. */
#define CONF_DEBUG_PACKET_ON(a, b) conf_debug_ospf_packet[a] |= (b)
#define CONF_DEBUG_PACKET_OFF(a, b) conf_debug_ospf_packet[a] &= ~(b)
@@ -140,6 +142,7 @@ extern unsigned long term_debug_ospf_ti_lfa;
extern unsigned long term_debug_ospf_defaultinfo;
extern unsigned long term_debug_ospf_ldp_sync;
extern unsigned long term_debug_ospf_gr;
+extern unsigned long term_debug_ospf_bfd;
/* Message Strings. */
extern char *ospf_lsa_type_str[];
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 0161f05d7..d494f0fbc 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -35,6 +35,7 @@
#include "ldp_sync.h"
#include "ospfd/ospfd.h"
+#include "ospfd/ospf_bfd.h"
#include "ospfd/ospf_spf.h"
#include "ospfd/ospf_interface.h"
#include "ospfd/ospf_ism.h"
@@ -545,10 +546,11 @@ static struct ospf_if_params *ospf_new_if_params(void)
return oip;
}
-void ospf_del_if_params(struct ospf_if_params *oip)
+static void ospf_del_if_params(struct interface *ifp,
+ struct ospf_if_params *oip)
{
list_delete(&oip->auth_crypt);
- bfd_info_free(&(oip->bfd_info));
+ ospf_interface_disable_bfd(ifp, oip);
ldp_sync_info_free(&(oip->ldp_sync_info));
XFREE(MTYPE_OSPF_IF_PARAMS, oip);
}
@@ -582,7 +584,7 @@ void ospf_free_if_params(struct interface *ifp, struct in_addr addr)
&& !OSPF_IF_PARAM_CONFIGURED(oip, auth_type)
&& !OSPF_IF_PARAM_CONFIGURED(oip, if_area)
&& listcount(oip->auth_crypt) == 0) {
- ospf_del_if_params(oip);
+ ospf_del_if_params(ifp, oip);
rn->info = NULL;
route_unlock_node(rn);
}
@@ -696,10 +698,10 @@ static int ospf_if_delete_hook(struct interface *ifp)
for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
if (rn->info)
- ospf_del_if_params(rn->info);
+ ospf_del_if_params(ifp, rn->info);
route_table_finish(IF_OIFS_PARAMS(ifp));
- ospf_del_if_params((struct ospf_if_params *)IF_DEF_PARAMS(ifp));
+ ospf_del_if_params(ifp, IF_DEF_PARAMS(ifp));
XFREE(MTYPE_OSPF_IF_INFO, ifp->info);
return rc;
diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h
index 2f146c06f..a9534f543 100644
--- a/ospfd/ospf_interface.h
+++ b/ospfd/ospf_interface.h
@@ -22,6 +22,7 @@
#ifndef _ZEBRA_OSPF_INTERFACE_H
#define _ZEBRA_OSPF_INTERFACE_H
+#include "lib/bfd.h"
#include "qobj.h"
#include "hook.h"
#include "ospfd/ospf_packet.h"
@@ -104,7 +105,16 @@ struct ospf_if_params {
uint32_t network_lsa_seqnum; /* Network LSA seqnum */
/* BFD configuration */
- struct bfd_info *bfd_info;
+ struct bfd_configuration {
+ /** BFD session detection multiplier. */
+ uint8_t detection_multiplier;
+ /** BFD session minimum required receive interval. */
+ uint32_t min_rx;
+ /** BFD session minimum required transmission interval. */
+ uint32_t min_tx;
+ /** BFD profile. */
+ char profile[BFD_PROFILE_NAME_LEN];
+ } *bfd_config;
/* MPLS LDP-IGP Sync configuration */
struct ldp_sync_info *ldp_sync_info;
@@ -285,7 +295,6 @@ extern struct ospf_if_params *ospf_lookup_if_params(struct interface *,
struct in_addr);
extern struct ospf_if_params *ospf_get_if_params(struct interface *,
struct in_addr);
-extern void ospf_del_if_params(struct ospf_if_params *);
extern void ospf_free_if_params(struct interface *, struct in_addr);
extern void ospf_if_update_params(struct interface *, struct in_addr);
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index 9ae2e8b04..d23dea0ca 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -22,6 +22,7 @@
#include <zebra.h>
#include <lib/version.h>
+#include "bfd.h"
#include "getopt.h"
#include "thread.h"
#include "prefix.h"
@@ -98,6 +99,7 @@ static void sighup(void)
static void sigint(void)
{
zlog_notice("Terminating on signal");
+ bfd_protocol_integration_set_shutdown(true);
ospf_terminate();
exit(0);
}
@@ -214,7 +216,7 @@ int main(int argc, char **argv)
ospf_vty_clear_init();
/* OSPF BFD init */
- ospf_bfd_init();
+ ospf_bfd_init(master);
/* OSPF LDP IGP Sync init */
ospf_ldp_sync_init();
diff --git a/ospfd/ospf_neighbor.c b/ospfd/ospf_neighbor.c
index 2fa43923a..a1b35b2fc 100644
--- a/ospfd/ospf_neighbor.c
+++ b/ospfd/ospf_neighbor.c
@@ -21,6 +21,7 @@
#include <zebra.h>
+#include "lib/bfd.h"
#include "linklist.h"
#include "prefix.h"
#include "memory.h"
@@ -99,8 +100,6 @@ struct ospf_neighbor *ospf_nbr_new(struct ospf_interface *oi)
nbr->crypt_seqnum = 0;
- ospf_bfd_info_nbr_create(oi, nbr);
-
/* Initialize GR Helper info*/
nbr->gr_helper_info.recvd_grace_period = 0;
nbr->gr_helper_info.actual_grace_period = 0;
@@ -149,7 +148,7 @@ void ospf_nbr_free(struct ospf_neighbor *nbr)
/* Cancel all events. */ /* Thread lookup cost would be negligible. */
thread_cancel_event(master, nbr);
- ospf_bfd_info_free(&nbr->bfd_info);
+ bfd_sess_free(&nbr->bfd_session);
OSPF_NSM_TIMER_OFF(nbr->gr_helper_info.t_grace_timer);
@@ -458,6 +457,9 @@ static struct ospf_neighbor *ospf_nbr_add(struct ospf_interface *oi,
if (ntohs(ospfh->auth_type) == OSPF_AUTH_CRYPTOGRAPHIC)
nbr->crypt_seqnum = ospfh->u.crypt.crypt_seqnum;
+ /* Configure BFD if interface has it. */
+ ospf_neighbor_bfd_apply(nbr);
+
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("NSM[%s:%pI4]: start", IF_NAME(oi),
&nbr->router_id);
diff --git a/ospfd/ospf_neighbor.h b/ospfd/ospf_neighbor.h
index 758693e28..2ce6d6755 100644
--- a/ospfd/ospf_neighbor.h
+++ b/ospfd/ospf_neighbor.h
@@ -88,7 +88,7 @@ struct ospf_neighbor {
uint32_t state_change; /* NSM state change counter */
/* BFD information */
- void *bfd_info;
+ struct bfd_session_params *bfd_session;
/* ospf graceful restart HELPER info */
struct ospf_helper_info gr_helper_info;
diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c
index ca33fd4e1..006c4888a 100644
--- a/ospfd/ospf_nsm.c
+++ b/ospfd/ospf_nsm.c
@@ -761,7 +761,8 @@ static void nsm_change_state(struct ospf_neighbor *nbr, int state)
if (state == NSM_Down)
nbr->crypt_seqnum = 0;
- ospf_bfd_trigger_event(nbr, old_state, state);
+ if (nbr->bfd_session)
+ ospf_bfd_trigger_event(nbr, old_state, state);
/* Preserve old status? */
}
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 626d553fe..e6835ffc7 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -3776,7 +3776,8 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
" Neighbor Count is %d, Adjacent neighbor count is %d\n",
ospf_nbr_count(oi, 0),
ospf_nbr_count(oi, NSM_Full));
- ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json);
+
+ ospf_interface_bfd_show(vty, ifp, json_interface_sub);
/* OSPF Authentication information */
ospf_interface_auth_show(vty, oi, json_interface_sub, use_json);
@@ -5282,7 +5283,7 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
.helper_exit_reason));
}
- ospf_bfd_show_info(vty, nbr->bfd_info, json_neigh, use_json, 0);
+ bfd_sess_show(vty, json_neigh, nbr->bfd_session);
if (use_json)
json_object_array_add(json_neigh_array, json_neigh);
@@ -11686,7 +11687,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
}
/* bfd print. */
- if (params && params->bfd_info)
+ if (params && params->bfd_config)
ospf_bfd_write_config(vty, params);
/* MTU ignore print. */
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 1a1861fc5..9856e6013 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -42,6 +42,7 @@
#include "ldp_sync.h"
#include "ospfd/ospfd.h"
+#include "ospfd/ospf_bfd.h"
#include "ospfd/ospf_network.h"
#include "ospfd/ospf_interface.h"
#include "ospfd/ospf_ism.h"
@@ -1931,6 +1932,9 @@ static void ospf_nbr_nbma_add(struct ospf_nbr_nbma *nbr_nbma,
nbr_nbma->nbr = nbr;
+ /* Configure BFD if interface has it. */
+ ospf_neighbor_bfd_apply(nbr);
+
OSPF_NSM_EVENT_EXECUTE(nbr, NSM_Start);
}
}
diff --git a/tests/topotests/bfd-profiles-topo1/r1/bfd-peers-initial.json b/tests/topotests/bfd-profiles-topo1/r1/bfd-peers-initial.json
index bab24c4fa..86a7e5139 100644
--- a/tests/topotests/bfd-profiles-topo1/r1/bfd-peers-initial.json
+++ b/tests/topotests/bfd-profiles-topo1/r1/bfd-peers-initial.json
@@ -6,14 +6,14 @@
"interface": "r1-eth1",
"multihop": false,
"peer": "172.16.100.2",
- "receive-interval": 300,
+ "receive-interval": 800,
"remote-detect-multiplier": 3,
"remote-diagnostic": "ok",
"remote-id": "*",
"remote-receive-interval": 300,
"remote-transmit-interval": 300,
"status": "up",
- "transmit-interval": 300,
+ "transmit-interval": 800,
"uptime": "*",
"vrf": "default"
},
diff --git a/tests/topotests/bfd-profiles-topo1/r1/ospfd.conf b/tests/topotests/bfd-profiles-topo1/r1/ospfd.conf
index 4798d17c4..fcea5d48f 100644
--- a/tests/topotests/bfd-profiles-topo1/r1/ospfd.conf
+++ b/tests/topotests/bfd-profiles-topo1/r1/ospfd.conf
@@ -2,7 +2,7 @@ interface r1-eth1
ip ospf area 0
ip ospf hello-interval 2
ip ospf dead-interval 10
- ip ospf bfd
+ ip ospf bfd profile slowtx
!
router ospf
ospf router-id 10.254.254.1
diff --git a/tests/topotests/bfd-profiles-topo1/r6/bfd-peers-initial.json b/tests/topotests/bfd-profiles-topo1/r6/bfd-peers-initial.json
index 4e6fa869b..ec973eb36 100644
--- a/tests/topotests/bfd-profiles-topo1/r6/bfd-peers-initial.json
+++ b/tests/topotests/bfd-profiles-topo1/r6/bfd-peers-initial.json
@@ -10,8 +10,8 @@
"remote-detect-multiplier": 3,
"remote-diagnostic": "ok",
"remote-id": "*",
- "remote-receive-interval": 300,
- "remote-transmit-interval": 300,
+ "remote-receive-interval": 800,
+ "remote-transmit-interval": 800,
"status": "up",
"transmit-interval": 300,
"uptime": "*",