From cd52c44c009dad73ad65e0f0daf7855095121cdb Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 31 May 2021 10:27:51 -0300 Subject: ospfd: rename the graceful restart header Both the GR helper code and the upcoming GR restarting code are going to share a lot of definitions. As such, rename ospf_gr_helper.h to ospf_gr.h, which will be the central point of all GR definitions and prototypes. Signed-off-by: Renato Westphal --- ospfd/ospf_gr.h | 182 +++++++++++++++++++++++++++++++++++++++++++++++++ ospfd/ospf_gr_helper.c | 2 +- ospfd/ospf_gr_helper.h | 181 ------------------------------------------------ ospfd/ospf_neighbor.c | 2 +- ospfd/ospf_neighbor.h | 2 +- ospfd/ospf_packet.c | 2 +- ospfd/ospfd.c | 2 +- ospfd/subdir.am | 2 +- 8 files changed, 188 insertions(+), 187 deletions(-) create mode 100644 ospfd/ospf_gr.h delete mode 100644 ospfd/ospf_gr_helper.h (limited to 'ospfd') diff --git a/ospfd/ospf_gr.h b/ospfd/ospf_gr.h new file mode 100644 index 000000000..2106e0f5c --- /dev/null +++ b/ospfd/ospf_gr.h @@ -0,0 +1,182 @@ +/* + * 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 + */ + +#ifndef _ZEBRA_OSPF_GR_H +#define _ZEBRA_OSPF_GR_H + +#define OSPF_GR_NOT_HELPER 0 +#define OSPF_GR_ACTIVE_HELPER 1 + +#define OSPF_GR_HELPER_NO_LSACHECK 0 +#define OSPF_GR_HELPER_LSACHECK 1 + +#define OSPF_MAX_GRACE_INTERVAL 1800 +#define OSPF_MIN_GRACE_INTERVAL 1 + +enum ospf_helper_exit_reason { + OSPF_GR_HELPER_EXIT_NONE = 0, + OSPF_GR_HELPER_INPROGRESS, + OSPF_GR_HELPER_TOPO_CHG, + OSPF_GR_HELPER_GRACE_TIMEOUT, + OSPF_GR_HELPER_COMPLETED +}; + +enum ospf_gr_restart_reason { + OSPF_GR_UNKNOWN_RESTART = 0, + OSPF_GR_SW_RESTART = 1, + OSPF_GR_SW_UPGRADE = 2, + OSPF_GR_SWITCH_REDUNDANT_CARD = 3, + OSPF_GR_INVALID_REASON_CODE = 4 +}; + +enum ospf_gr_helper_rejected_reason { + OSPF_HELPER_REJECTED_NONE, + OSPF_HELPER_SUPPORT_DISABLED, + OSPF_HELPER_NOT_A_VALID_NEIGHBOUR, + OSPF_HELPER_PLANNED_ONLY_RESTART, + OSPF_HELPER_TOPO_CHANGE_RTXMT_LIST, + OSPF_HELPER_LSA_AGE_MORE +}; + +/* Ref RFC3623 appendex-A */ +/* Grace period TLV */ +#define GRACE_PERIOD_TYPE 1 +#define GRACE_PERIOD_LENGTH 4 + +struct grace_tlv_graceperiod { + struct tlv_header header; + uint32_t interval; +}; + +/* Restart reason TLV */ +#define RESTART_REASON_TYPE 2 +#define RESTART_REASON_LENGTH 1 + +struct grace_tlv_restart_reason { + struct tlv_header header; + uint8_t reason; + uint8_t reserved[3]; +}; + +/* Restarter ip address TLV */ +#define RESTARTER_IP_ADDR_TYPE 3 +#define RESTARTER_IP_ADDR_LEN 4 + +struct grace_tlv_restart_addr { + struct tlv_header header; + struct in_addr addr; +}; + +struct ospf_helper_info { + + /* Grace interval received from + * Restarting Router. + */ + uint32_t recvd_grace_period; + + /* Grace interval used for grace + * gracetimer. + */ + uint32_t actual_grace_period; + + /* Grace timer,This Router acts as + * helper until this timer until + * this timer expires. + */ + struct thread *t_grace_timer; + + /* Helper status */ + uint32_t gr_helper_status; + + /* Helper exit reason*/ + enum ospf_helper_exit_reason helper_exit_reason; + + /* Planned/Unplanned restart*/ + enum ospf_gr_restart_reason gr_restart_reason; + + /* Helper rejected reason */ + enum ospf_gr_helper_rejected_reason rejected_reason; +}; + +struct advRtr { + struct in_addr advRtrAddr; +}; + +#define OSPF_HELPER_ENABLE_RTR_COUNT(ospf) (ospf->enable_rtr_list->count) + +/* Check for planned restart */ +#define OSPF_GR_IS_PLANNED_RESTART(reason) \ + ((reason == OSPF_GR_SW_RESTART) || (reason == OSPF_GR_SW_UPGRADE)) + +/* Check the router is HELPER for current neighbour */ +#define OSPF_GR_IS_ACTIVE_HELPER(N) \ + ((N)->gr_helper_info.gr_helper_status == OSPF_GR_ACTIVE_HELPER) + +/* Check the LSA is GRACE LSA */ +#define IS_GRACE_LSA(lsa) \ + ((lsa->data->type == OSPF_OPAQUE_LINK_LSA) \ + && (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)) \ + == OPAQUE_TYPE_GRACE_LSA)) + +/* Check neighbour is in FULL state */ +#define IS_NBR_STATE_FULL(nbr) (nsm_should_adj(nbr) && (nbr->state == NSM_Full)) + +/* Check neighbour is DR_OTHER and state is 2_WAY */ +#define IS_NBR_STATE_2_WAY_WITH_DROTHER(nbr) \ + ((ospf_get_nbr_ism_role(nbr) == ISM_DROther) \ + && (nbr->state == NSM_TwoWay)) + +#define OSPF_GR_FALSE false +#define OSPF_GR_TRUE true + +#define OSPF_GR_SUCCESS 1 +#define OSPF_GR_FAILURE 0 +#define OSPF_GR_INVALID -1 + +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_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, + enum ospf_helper_exit_reason reason); +extern void ospf_process_maxage_grace_lsa(struct ospf *ospf, + struct ospf_lsa *lsa, + struct ospf_neighbor *nbr); +extern void ospf_helper_handle_topo_chg(struct ospf *ospf, + struct ospf_lsa *lsa); +extern void ospf_gr_helper_support_set(struct ospf *ospf, bool support); +extern void ospf_gr_helper_support_set_per_routerid(struct ospf *ospf, + struct in_addr *rid, + bool support); +extern void ospf_gr_helper_lsa_check_set(struct ospf *ospf, bool lsacheck); +extern void ospf_gr_helper_supported_gracetime_set(struct ospf *ospf, + uint32_t interval); +extern void ospf_gr_helper_set_supported_planned_only_restart(struct ospf *ospf, + bool planned_only); +#endif /* _ZEBRA_OSPF_GR_H */ diff --git a/ospfd/ospf_gr_helper.c b/ospfd/ospf_gr_helper.c index 1465ed139..7d0c229af 100644 --- a/ospfd/ospf_gr_helper.c +++ b/ospfd/ospf_gr_helper.c @@ -48,7 +48,7 @@ #include "ospfd/ospf_errors.h" #include "ospfd/ospf_nsm.h" #include "ospfd/ospf_ism.h" -#include "ospfd/ospf_gr_helper.h" +#include "ospfd/ospf_gr.h" static const char * const ospf_exit_reason_desc[] = { "Unknown reason", diff --git a/ospfd/ospf_gr_helper.h b/ospfd/ospf_gr_helper.h deleted file mode 100644 index bd6d1d746..000000000 --- a/ospfd/ospf_gr_helper.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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 - */ - -#ifndef _ZEBRA_OSPF_GR_HELPER_H -#define _ZEBRA_OSPF_GR_HELPER_H - -#define OSPF_GR_NOT_HELPER 0 -#define OSPF_GR_ACTIVE_HELPER 1 - -#define OSPF_GR_HELPER_NO_LSACHECK 0 -#define OSPF_GR_HELPER_LSACHECK 1 - -#define OSPF_MAX_GRACE_INTERVAL 1800 -#define OSPF_MIN_GRACE_INTERVAL 1 - -enum ospf_helper_exit_reason { - OSPF_GR_HELPER_EXIT_NONE = 0, - OSPF_GR_HELPER_INPROGRESS, - OSPF_GR_HELPER_TOPO_CHG, - OSPF_GR_HELPER_GRACE_TIMEOUT, - OSPF_GR_HELPER_COMPLETED -}; - -enum ospf_gr_restart_reason { - OSPF_GR_UNKNOWN_RESTART = 0, - OSPF_GR_SW_RESTART = 1, - OSPF_GR_SW_UPGRADE = 2, - OSPF_GR_SWITCH_REDUNDANT_CARD = 3, - OSPF_GR_INVALID_REASON_CODE = 4 -}; - -enum ospf_gr_helper_rejected_reason { - OSPF_HELPER_REJECTED_NONE, - OSPF_HELPER_SUPPORT_DISABLED, - OSPF_HELPER_NOT_A_VALID_NEIGHBOUR, - OSPF_HELPER_PLANNED_ONLY_RESTART, - OSPF_HELPER_TOPO_CHANGE_RTXMT_LIST, - OSPF_HELPER_LSA_AGE_MORE -}; - -/* Ref RFC3623 appendex-A */ -/* Grace period TLV */ -#define GRACE_PERIOD_TYPE 1 -#define GRACE_PERIOD_LENGTH 4 - -struct grace_tlv_graceperiod { - struct tlv_header header; - uint32_t interval; -}; - -/* Restart reason TLV */ -#define RESTART_REASON_TYPE 2 -#define RESTART_REASON_LENGTH 1 - -struct grace_tlv_restart_reason { - struct tlv_header header; - uint8_t reason; - uint8_t reserved[3]; -}; - -/* Restarter ip address TLV */ -#define RESTARTER_IP_ADDR_TYPE 3 -#define RESTARTER_IP_ADDR_LEN 4 - -struct grace_tlv_restart_addr { - struct tlv_header header; - struct in_addr addr; -}; - -struct ospf_helper_info { - - /* Grace interval received from - * Restarting Router. - */ - uint32_t recvd_grace_period; - - /* Grace interval used for grace - * gracetimer. - */ - uint32_t actual_grace_period; - - /* Grace timer,This Router acts as - * helper until this timer until - * this timer expires*/ - struct thread *t_grace_timer; - - /* Helper status */ - uint32_t gr_helper_status; - - /* Helper exit reason*/ - enum ospf_helper_exit_reason helper_exit_reason; - - /* Planned/Unplanned restart*/ - enum ospf_gr_restart_reason gr_restart_reason; - - /* Helper rejected reason */ - enum ospf_gr_helper_rejected_reason rejected_reason; -}; - -struct advRtr { - struct in_addr advRtrAddr; -}; - -#define OSPF_HELPER_ENABLE_RTR_COUNT(ospf) (ospf->enable_rtr_list->count) - -/* Check for planned restart */ -#define OSPF_GR_IS_PLANNED_RESTART(reason) \ - ((reason == OSPF_GR_SW_RESTART) || (reason == OSPF_GR_SW_UPGRADE)) - -/* Check the router is HELPER for current neighbour */ -#define OSPF_GR_IS_ACTIVE_HELPER(N) \ - ((N)->gr_helper_info.gr_helper_status == OSPF_GR_ACTIVE_HELPER) - -/* Check the LSA is GRACE LSA */ -#define IS_GRACE_LSA(lsa) \ - ((lsa->data->type == OSPF_OPAQUE_LINK_LSA) \ - && (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)) \ - == OPAQUE_TYPE_GRACE_LSA)) - -/* Check neighbour is in FULL state */ -#define IS_NBR_STATE_FULL(nbr) (nsm_should_adj(nbr) && (nbr->state == NSM_Full)) - -/* Check neighbour is DR_OTHER and state is 2_WAY */ -#define IS_NBR_STATE_2_WAY_WITH_DROTHER(nbr) \ - ((ospf_get_nbr_ism_role(nbr) == ISM_DROther) \ - && (nbr->state == NSM_TwoWay)) - -#define OSPF_GR_FALSE false -#define OSPF_GR_TRUE true - -#define OSPF_GR_SUCCESS 1 -#define OSPF_GR_FAILURE 0 -#define OSPF_GR_INVALID -1 - -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_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, - enum ospf_helper_exit_reason reason); -extern void ospf_process_maxage_grace_lsa(struct ospf *ospf, - struct ospf_lsa *lsa, - struct ospf_neighbor *nbr); -extern void ospf_helper_handle_topo_chg(struct ospf *ospf, - struct ospf_lsa *lsa); -extern void ospf_gr_helper_support_set(struct ospf *ospf, bool support); -extern void ospf_gr_helper_support_set_per_routerid(struct ospf *ospf, - struct in_addr *rid, - bool support); -extern void ospf_gr_helper_lsa_check_set(struct ospf *ospf, bool lsacheck); -extern void ospf_gr_helper_supported_gracetime_set(struct ospf *ospf, - uint32_t interval); -extern void ospf_gr_helper_set_supported_planned_only_restart(struct ospf *ospf, - bool planned_only); -#endif /* _ZEBRA_OSPF_HELPER_H */ diff --git a/ospfd/ospf_neighbor.c b/ospfd/ospf_neighbor.c index 8725497f2..98fb54d82 100644 --- a/ospfd/ospf_neighbor.c +++ b/ospfd/ospf_neighbor.c @@ -44,7 +44,7 @@ #include "ospfd/ospf_flood.h" #include "ospfd/ospf_dump.h" #include "ospfd/ospf_bfd.h" -#include "ospfd/ospf_gr_helper.h" +#include "ospfd/ospf_gr.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 diff --git a/ospfd/ospf_neighbor.h b/ospfd/ospf_neighbor.h index 2ce6d6755..433b13615 100644 --- a/ospfd/ospf_neighbor.h +++ b/ospfd/ospf_neighbor.h @@ -22,7 +22,7 @@ #ifndef _ZEBRA_OSPF_NEIGHBOR_H #define _ZEBRA_OSPF_NEIGHBOR_H -#include +#include #include /* Neighbor Data Structure */ diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index e3a8eabda..743db7002 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -54,7 +54,7 @@ #include "ospfd/ospf_dump.h" #include "ospfd/ospf_errors.h" #include "ospfd/ospf_zebra.h" -#include "ospfd/ospf_gr_helper.h" +#include "ospfd/ospf_gr.h" /* * OSPF Fragmentation / fragmented writes diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index e95ee55e6..a4b50e0c3 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -60,7 +60,7 @@ #include "ospfd/ospf_flood.h" #include "ospfd/ospf_ase.h" #include "ospfd/ospf_ldp_sync.h" -#include "ospfd/ospf_gr_helper.h" +#include "ospfd/ospf_gr.h" DEFINE_QOBJ_TYPE(ospf); diff --git a/ospfd/subdir.am b/ospfd/subdir.am index 574e0e3bd..51254391f 100644 --- a/ospfd/subdir.am +++ b/ospfd/subdir.am @@ -100,6 +100,7 @@ noinst_HEADERS += \ ospfd/ospf_network.h \ ospfd/ospf_packet.h \ ospfd/ospf_ri.h \ + ospfd/ospf_gr.h \ ospfd/ospf_route.h \ ospfd/ospf_routemap_nb.h \ ospfd/ospf_spf.h \ @@ -108,7 +109,6 @@ 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) -- cgit v1.2.3