From 51f8588eb999429eb2181f1897742fa503c17a51 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 31 May 2021 10:27:51 -0300 Subject: [PATCH] ospfd: fix GR helper initialization and termination Since a single ospfd process can have multiple OSPF interfaces configured, we need to separate the global GR initialization and termination from per-instance initialization and termination. Signed-off-by: Renato Westphal --- ospfd/ospf_gr_helper.c | 42 +++++++++++++++++++++++++++++++++--------- ospfd/ospf_gr_helper.h | 6 ++++-- ospfd/ospf_main.c | 1 + ospfd/ospfd.c | 7 +++++-- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/ospfd/ospf_gr_helper.c b/ospfd/ospf_gr_helper.c index a25057a27f..8ee4207b04 100644 --- a/ospfd/ospf_gr_helper.c +++ b/ospfd/ospf_gr_helper.c @@ -159,10 +159,8 @@ const char *ospf_rejected_reason2str(unsigned int reason) * Returns: * Nothing */ -void ospf_gr_helper_init(struct ospf *ospf) +void ospf_gr_helper_instance_init(struct ospf *ospf) { - int rc; - if (IS_DEBUG_OSPF_GR_HELPER) zlog_debug("%s, GR Helper init.", __func__); @@ -176,6 +174,37 @@ void ospf_gr_helper_init(struct ospf *ospf) ospf->enable_rtr_list = hash_create(ospf_enable_rtr_hash_key, ospf_enable_rtr_hash_cmp, "OSPF enable router hash"); +} + +/* + * De-Initialize GR helper config data structures. + * + * OSPF + * OSPF pointer + * + * Returns: + * Nothing + */ +void ospf_gr_helper_instance_stop(struct ospf *ospf) +{ + if (IS_DEBUG_OSPF_GR_HELPER) + zlog_debug("%s, GR helper deinit.", __func__); + + ospf_enable_rtr_hash_destroy(ospf); +} + +/* + * Initialize GR helper config data structures. + * + * Returns: + * Nothing + */ +void ospf_gr_helper_init(void) +{ + int rc; + + if (IS_DEBUG_OSPF_GR_HELPER) + zlog_debug("%s, GR Helper init.", __func__); rc = ospf_register_opaque_functab( OSPF_OPAQUE_LINK_LSA, OPAQUE_TYPE_GRACE_LSA, NULL, NULL, NULL, @@ -191,20 +220,15 @@ void ospf_gr_helper_init(struct ospf *ospf) /* * De-Initialize GR helper config data structures. * - * OSPF - * OSPF pointer - * * Returns: * Nothing */ -void ospf_gr_helper_stop(struct ospf *ospf) +void ospf_gr_helper_stop(void) { if (IS_DEBUG_OSPF_GR_HELPER) zlog_debug("%s, GR helper deinit.", __func__); - ospf_enable_rtr_hash_destroy(ospf); - ospf_delete_opaque_functab(OSPF_OPAQUE_LINK_LSA, OPAQUE_TYPE_GRACE_LSA); } diff --git a/ospfd/ospf_gr_helper.h b/ospfd/ospf_gr_helper.h index c355bb4f3d..bd6d1d7462 100644 --- a/ospfd/ospf_gr_helper.h +++ b/ospfd/ospf_gr_helper.h @@ -156,8 +156,10 @@ const char *ospf_exit_reason2str(unsigned int reason); const char *ospf_restart_reason2str(unsigned int reason); const char *ospf_rejected_reason2str(unsigned int reason); -extern void ospf_gr_helper_init(struct ospf *ospf); -extern void ospf_gr_helper_stop(struct ospf *ospf); +extern void ospf_gr_helper_instance_init(struct ospf *ospf); +extern void ospf_gr_helper_instance_stop(struct ospf *ospf); +extern void ospf_gr_helper_init(void); +extern void ospf_gr_helper_stop(void); extern int ospf_process_grace_lsa(struct ospf *ospf, struct ospf_lsa *lsa, struct ospf_neighbor *nbr); extern void ospf_gr_helper_exit(struct ospf_neighbor *nbr, diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index 91ba3044fe..d94de12994 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -225,6 +225,7 @@ int main(int argc, char **argv) ospf_route_map_init(); ospf_opaque_init(); + ospf_gr_helper_init(); /* OSPF errors init */ ospf_error_init(); diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 38c0ca2b67..106ce3bd7d 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -386,7 +386,7 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name) new->proactive_arp = OSPF_PROACTIVE_ARP_DEFAULT; - ospf_gr_helper_init(new); + ospf_gr_helper_instance_init(new); ospf_asbr_external_aggregator_init(new); @@ -651,6 +651,9 @@ void ospf_terminate(void) for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf)) ospf_finish(ospf); + /* Cleanup GR */ + ospf_gr_helper_stop(); + /* Cleanup route maps */ route_map_finish(); @@ -900,7 +903,7 @@ static void ospf_finish_final(struct ospf *ospf) list_delete(&ospf->oi_write_q); /* Reset GR helper data structers */ - ospf_gr_helper_stop(ospf); + ospf_gr_helper_instance_stop(ospf); close(ospf->fd); stream_free(ospf->ibuf); -- 2.39.5