From 06bc3110d3845a40a6853609cef401304a6f1874 Mon Sep 17 00:00:00 2001 From: rgirada Date: Fri, 21 Aug 2020 10:03:05 -0700 Subject: [PATCH] ospfd: ospf GR helper initialization Description: 1. Graceful restart helper init/de-init. 2. Defining dedicated memory for helper. Signed-off-by: Rajesh Girada --- ospfd/ospf_dump.c | 2 + ospfd/ospf_gr_helper.c | 136 +++++++++++++++++++++++++++++++++++++++++ ospfd/ospf_gr_helper.h | 9 ++- ospfd/ospf_memory.c | 1 + ospfd/ospf_memory.h | 1 + ospfd/ospf_neighbor.c | 11 ++++ ospfd/ospfd.c | 6 ++ ospfd/subdir.am | 3 + 8 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 ospfd/ospf_gr_helper.c diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c index e8798e023e..66caf84436 100644 --- a/ospfd/ospf_dump.c +++ b/ospfd/ospf_dump.c @@ -55,6 +55,7 @@ unsigned long conf_debug_ospf_ext = 0; unsigned long conf_debug_ospf_sr = 0; unsigned long conf_debug_ospf_defaultinfo = 0; unsigned long conf_debug_ospf_ldp_sync = 0; +unsigned long conf_debug_ospf_gr = 0; /* Enable debug option variables -- valid only session. */ unsigned long term_debug_ospf_packet[5] = {0, 0, 0, 0, 0}; @@ -69,6 +70,7 @@ unsigned long term_debug_ospf_ext = 0; unsigned long term_debug_ospf_sr = 0; unsigned long term_debug_ospf_defaultinfo; unsigned long term_debug_ospf_ldp_sync; +unsigned long term_debug_ospf_gr = 0; const char *ospf_redist_string(unsigned int route_type) { diff --git a/ospfd/ospf_gr_helper.c b/ospfd/ospf_gr_helper.c new file mode 100644 index 0000000000..8bb740a155 --- /dev/null +++ b/ospfd/ospf_gr_helper.c @@ -0,0 +1,136 @@ +/* + * OSPF Graceful Restart helper functions. + * + * Copyright (C) 2020-21 Vmware, Inc. + * Rajesh Kumar Girada + * + * This file is part of GNU Zebra. + * + * GNU Zebra is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * GNU Zebra is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "thread.h" +#include "memory.h" +#include "linklist.h" +#include "prefix.h" +#include "if.h" +#include "table.h" +#include "vty.h" +#include "filter.h" +#include "log.h" +#include "jhash.h" + +#include "ospfd/ospfd.h" +#include "ospfd/ospf_interface.h" +#include "ospfd/ospf_asbr.h" +#include "ospfd/ospf_lsa.h" +#include "ospfd/ospf_lsdb.h" +#include "ospfd/ospf_neighbor.h" +#include "ospfd/ospf_spf.h" +#include "ospfd/ospf_flood.h" +#include "ospfd/ospf_route.h" +#include "ospfd/ospf_zebra.h" +#include "ospfd/ospf_dump.h" +#include "ospfd/ospf_errors.h" +#include "ospfd/ospf_nsm.h" +#include "ospfd/ospf_ism.h" +#include "ospfd/ospf_gr_helper.h" + + +static unsigned int ospf_enable_rtr_hash_key(const void *data) +{ + const struct advRtr *rtr = data; + + return jhash_1word(rtr->advRtrAddr.s_addr, 0); +} + +static bool ospf_enable_rtr_hash_cmp(const void *d1, const void *d2) +{ + const struct advRtr *rtr1 = (struct advRtr *)d1; + const struct advRtr *rtr2 = (struct advRtr *)d2; + + return (rtr1->advRtrAddr.s_addr == rtr2->advRtrAddr.s_addr); +} + +static void *ospf_enable_rtr_hash_alloc(void *p) +{ + struct advRtr *rid; + + rid = XCALLOC(MTYPE_OSPF_GR_HELPER, sizeof(struct advRtr)); + rid->advRtrAddr.s_addr = ((struct in_addr *)p)->s_addr; + + return rid; +} + +static void ospf_disable_rtr_hash_free(void *rtr) +{ + XFREE(MTYPE_OSPF_GR_HELPER, rtr); +} + +static void ospf_enable_rtr_hash_destroy(struct ospf *ospf) +{ + if (ospf->enable_rtr_list == NULL) + return; + + hash_clean(ospf->enable_rtr_list, ospf_disable_rtr_hash_free); + hash_free(ospf->enable_rtr_list); + ospf->enable_rtr_list = NULL; +} + +/* + * Initialize GR helper config data structures. + * + * OSPF + * OSPF pointer + * + * Returns: + * Nothing + */ +void ospf_gr_helper_init(struct ospf *ospf) +{ + if (IS_DEBUG_OSPF_GR_HELPER) + zlog_debug("%s, GR Helper init.", __PRETTY_FUNCTION__); + + ospf->is_helper_supported = OSPF_FALSE; + ospf->strict_lsa_check = OSPF_TRUE; + ospf->only_planned_restart = OSPF_FALSE; + ospf->supported_grace_time = OSPF_MAX_GRACE_INTERVAL; + ospf->last_exit_reason = OSPF_GR_HELPER_EXIT_NONE; + ospf->active_restarter_cnt = 0; + + 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_stop(struct ospf *ospf) +{ + + if (IS_DEBUG_OSPF_GR_HELPER) + zlog_debug("%s, GR helper deinit.", __PRETTY_FUNCTION__); + + ospf_enable_rtr_hash_destroy(ospf); +} diff --git a/ospfd/ospf_gr_helper.h b/ospfd/ospf_gr_helper.h index 8cf9f3ab76..ac41243253 100644 --- a/ospfd/ospf_gr_helper.h +++ b/ospfd/ospf_gr_helper.h @@ -21,8 +21,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _ZEBRA_OSPF_HELPER_H -#define _ZEBRA_OSPF_HELPER_H +#ifndef _ZEBRA_OSPF_GR_HELPER_H +#define _ZEBRA_OSPF_GR_HELPER_H #define OSPF_GR_NOT_HELPER 0 #define OSPF_GR_ACTIVE_HELPER 1 @@ -151,4 +151,7 @@ struct advRtr { #define OSPF_GR_SUCCESS 1 #define OSPF_GR_FAILURE 0 #define OSPF_GR_INVALID -1 -#endif /* _ZEBRA_OSPF_HELPER_H */ + +extern void ospf_gr_helper_init(struct ospf *); +extern void ospf_gr_helper_stop(struct ospf *ospf); +#endif /* _ZEBRA_OSPF_GR_HELPER_H */ diff --git a/ospfd/ospf_memory.c b/ospfd/ospf_memory.c index c4dc0136ed..d102fddf86 100644 --- a/ospfd/ospf_memory.c +++ b/ospfd/ospf_memory.c @@ -56,3 +56,4 @@ DEFINE_MTYPE(OSPFD, OSPF_ROUTER_INFO, "OSPF Router Info parameters") DEFINE_MTYPE(OSPFD, OSPF_PCE_PARAMS, "OSPF PCE parameters") DEFINE_MTYPE(OSPFD, OSPF_EXT_PARAMS, "OSPF Extended parameters") DEFINE_MTYPE(OSPFD, OSPF_SR_PARAMS, "OSPF Segment Routing parameters") +DEFINE_MTYPE(OSPFD, OSPF_GR_HELPER, "OSPF Graceful Restart Helper") diff --git a/ospfd/ospf_memory.h b/ospfd/ospf_memory.h index 861de64c25..58f23aa9c7 100644 --- a/ospfd/ospf_memory.h +++ b/ospfd/ospf_memory.h @@ -55,5 +55,6 @@ DECLARE_MTYPE(OSPF_ROUTER_INFO) DECLARE_MTYPE(OSPF_PCE_PARAMS) DECLARE_MTYPE(OSPF_SR_PARAMS) DECLARE_MTYPE(OSPF_EXT_PARAMS) +DECLARE_MTYPE(OSPF_GR_HELPER) #endif /* _QUAGGA_OSPF_MEMORY_H */ diff --git a/ospfd/ospf_neighbor.c b/ospfd/ospf_neighbor.c index 46dfc505ef..b0ff40afe5 100644 --- a/ospfd/ospf_neighbor.c +++ b/ospfd/ospf_neighbor.c @@ -43,6 +43,7 @@ #include "ospfd/ospf_flood.h" #include "ospfd/ospf_dump.h" #include "ospfd/ospf_bfd.h" +#include "ospfd/ospf_gr_helper.h" /* Fill in the the 'key' as appropriate to retrieve the entry for nbr * from the ospf_interface's nbrs table. Indexed by interface address @@ -99,6 +100,14 @@ 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; + nbr->gr_helper_info.gr_helper_status = OSPF_GR_NOT_HELPER; + nbr->gr_helper_info.helper_exit_reason = OSPF_GR_HELPER_EXIT_NONE; + nbr->gr_helper_info.gr_restart_reason = OSPF_GR_UNKNOWN_RESTART; + return nbr; } @@ -142,6 +151,8 @@ void ospf_nbr_free(struct ospf_neighbor *nbr) ospf_bfd_info_free(&nbr->bfd_info); + OSPF_NSM_TIMER_OFF(nbr->gr_helper_info.t_grace_timer); + nbr->oi = NULL; XFREE(MTYPE_OSPF_NEIGHBOR, nbr); } diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index cc5839a810..aa063a0759 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -59,6 +59,7 @@ #include "ospfd/ospf_flood.h" #include "ospfd/ospf_ase.h" #include "ospfd/ospf_ldp_sync.h" +#include "ospfd/ospf_gr_helper.h" DEFINE_QOBJ_TYPE(ospf) @@ -309,6 +310,8 @@ static struct ospf *ospf_new(unsigned short instance, const char *name) new->proactive_arp = OSPF_PROACTIVE_ARP_DEFAULT; + ospf_gr_helper_init(new); + QOBJ_REG(new, ospf); new->fd = -1; @@ -766,6 +769,9 @@ static void ospf_finish_final(struct ospf *ospf) list_delete(&ospf->areas); list_delete(&ospf->oi_write_q); + /* Reset GR helper data structers */ + ospf_gr_helper_stop(ospf); + close(ospf->fd); stream_free(ospf->ibuf); ospf->fd = -1; diff --git a/ospfd/subdir.am b/ospfd/subdir.am index 236b76a1f7..2a59a62521 100644 --- a/ospfd/subdir.am +++ b/ospfd/subdir.am @@ -56,6 +56,7 @@ ospfd_libfrrospf_a_SOURCES = \ ospfd/ospf_vty.c \ ospfd/ospf_zebra.c \ ospfd/ospfd.c \ + ospfd/ospf_gr_helper.c \ # end if OSPFD @@ -77,6 +78,7 @@ endif clippy_scan += \ ospfd/ospf_vty.c \ ospfd/ospf_ldp_sync.c \ + ospfd/ospf_dump.c \ # end noinst_HEADERS += \ @@ -101,6 +103,7 @@ noinst_HEADERS += \ ospfd/ospf_te.h \ ospfd/ospf_vty.h \ ospfd/ospf_zebra.h \ + ospfd/ospf_gr_helper.h \ # end ospfd_ospfd_LDADD = ospfd/libfrrospf.a lib/libfrr.la $(LIBCAP) $(LIBM) -- 2.39.5