Skip to content

Commit

Permalink
ospfd: rework BFD integration
Browse files Browse the repository at this point in the history
Use new BFD API to integrate with OSPFv2.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  • Loading branch information
rzalamena committed Mar 23, 2021
1 parent cab054b commit 659f4e4
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 344 deletions.
427 changes: 111 additions & 316 deletions ospfd/ospf_bfd.c

Large diffs are not rendered by default.

31 changes: 19 additions & 12 deletions ospfd/ospf_bfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
12 changes: 7 additions & 5 deletions ospfd/ospf_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions ospfd/ospf_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion ospfd/ospf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <zebra.h>

#include <lib/version.h>
#include "bfd.h"
#include "getopt.h"
#include "thread.h"
#include "prefix.h"
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions ospfd/ospf_neighbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <zebra.h>

#include "lib/bfd.h"
#include "linklist.h"
#include "prefix.h"
#include "memory.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ospfd/ospf_neighbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion ospfd/ospf_nsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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? */
}
Expand Down
7 changes: 4 additions & 3 deletions ospfd/ospf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -11716,7 +11717,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. */
Expand Down
4 changes: 4 additions & 0 deletions ospfd/ospfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 659f4e4

Please sign in to comment.