2 * OSPF Graceful Restart helper functions.
4 * Copyright (C) 2020-21 Vmware, Inc.
7 * This file is part of GNU Zebra.
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #ifndef _ZEBRA_OSPF_GR_H
25 #define _ZEBRA_OSPF_GR_H
27 #define OSPF_GR_NOT_HELPER 0
28 #define OSPF_GR_ACTIVE_HELPER 1
30 #define OSPF_GR_HELPER_NO_LSACHECK 0
31 #define OSPF_GR_HELPER_LSACHECK 1
33 #define OSPF_MAX_GRACE_INTERVAL 1800
34 #define OSPF_MIN_GRACE_INTERVAL 1
35 #define OSPF_DFLT_GRACE_INTERVAL 120
37 enum ospf_helper_exit_reason
{
38 OSPF_GR_HELPER_EXIT_NONE
= 0,
39 OSPF_GR_HELPER_INPROGRESS
,
40 OSPF_GR_HELPER_TOPO_CHG
,
41 OSPF_GR_HELPER_GRACE_TIMEOUT
,
42 OSPF_GR_HELPER_COMPLETED
45 enum ospf_gr_restart_reason
{
46 OSPF_GR_UNKNOWN_RESTART
= 0,
47 OSPF_GR_SW_RESTART
= 1,
48 OSPF_GR_SW_UPGRADE
= 2,
49 OSPF_GR_SWITCH_REDUNDANT_CARD
= 3,
50 OSPF_GR_INVALID_REASON_CODE
= 4
53 enum ospf_gr_helper_rejected_reason
{
54 OSPF_HELPER_REJECTED_NONE
,
55 OSPF_HELPER_SUPPORT_DISABLED
,
56 OSPF_HELPER_NOT_A_VALID_NEIGHBOUR
,
57 OSPF_HELPER_PLANNED_ONLY_RESTART
,
58 OSPF_HELPER_TOPO_CHANGE_RTXMT_LIST
,
59 OSPF_HELPER_LSA_AGE_MORE
,
60 OSPF_HELPER_RESTARTING
,
63 /* Ref RFC3623 appendex-A */
64 /* Grace period TLV */
65 #define GRACE_PERIOD_TYPE 1
66 #define GRACE_PERIOD_LENGTH 4
68 struct grace_tlv_graceperiod
{
69 struct tlv_header header
;
73 /* Restart reason TLV */
74 #define RESTART_REASON_TYPE 2
75 #define RESTART_REASON_LENGTH 1
77 struct grace_tlv_restart_reason
{
78 struct tlv_header header
;
83 /* Restarter ip address TLV */
84 #define RESTARTER_IP_ADDR_TYPE 3
85 #define RESTARTER_IP_ADDR_LEN 4
87 struct grace_tlv_restart_addr
{
88 struct tlv_header header
;
92 struct ospf_helper_info
{
94 /* Grace interval received from
97 uint32_t recvd_grace_period
;
99 /* Grace interval used for grace
102 uint32_t actual_grace_period
;
104 /* Grace timer,This Router acts as
105 * helper until this timer until
106 * this timer expires.
108 struct thread
*t_grace_timer
;
111 uint32_t gr_helper_status
;
113 /* Helper exit reason*/
114 enum ospf_helper_exit_reason helper_exit_reason
;
116 /* Planned/Unplanned restart*/
117 enum ospf_gr_restart_reason gr_restart_reason
;
119 /* Helper rejected reason */
120 enum ospf_gr_helper_rejected_reason rejected_reason
;
124 struct in_addr advRtrAddr
;
127 #define OSPF_HELPER_ENABLE_RTR_COUNT(ospf) (ospf->enable_rtr_list->count)
129 /* Check for planned restart */
130 #define OSPF_GR_IS_PLANNED_RESTART(reason) \
131 ((reason == OSPF_GR_SW_RESTART) || (reason == OSPF_GR_SW_UPGRADE))
133 /* Check the router is HELPER for current neighbour */
134 #define OSPF_GR_IS_ACTIVE_HELPER(N) \
135 ((N)->gr_helper_info.gr_helper_status == OSPF_GR_ACTIVE_HELPER)
137 /* Check the LSA is GRACE LSA */
138 #define IS_GRACE_LSA(lsa) \
139 ((lsa->data->type == OSPF_OPAQUE_LINK_LSA) \
140 && (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)) \
141 == OPAQUE_TYPE_GRACE_LSA))
143 /* Check neighbour is in FULL state */
144 #define IS_NBR_STATE_FULL(nbr) (nsm_should_adj(nbr) && (nbr->state == NSM_Full))
146 /* Check neighbour is DR_OTHER and state is 2_WAY */
147 #define IS_NBR_STATE_2_WAY_WITH_DROTHER(nbr) \
148 ((ospf_get_nbr_ism_role(nbr) == ISM_DROther) \
149 && (nbr->state == NSM_TwoWay))
151 #define OSPF_GR_FALSE false
152 #define OSPF_GR_TRUE true
154 #define OSPF_GR_SUCCESS 1
155 #define OSPF_GR_FAILURE 0
156 #define OSPF_GR_INVALID -1
158 const char *ospf_exit_reason2str(unsigned int reason
);
159 const char *ospf_restart_reason2str(unsigned int reason
);
160 const char *ospf_rejected_reason2str(unsigned int reason
);
162 extern void ospf_gr_helper_instance_init(struct ospf
*ospf
);
163 extern void ospf_gr_helper_instance_stop(struct ospf
*ospf
);
164 extern void ospf_gr_helper_init(void);
165 extern void ospf_gr_helper_stop(void);
166 extern int ospf_process_grace_lsa(struct ospf
*ospf
, struct ospf_lsa
*lsa
,
167 struct ospf_neighbor
*nbr
);
168 extern void ospf_gr_helper_exit(struct ospf_neighbor
*nbr
,
169 enum ospf_helper_exit_reason reason
);
170 extern void ospf_process_maxage_grace_lsa(struct ospf
*ospf
,
171 struct ospf_lsa
*lsa
,
172 struct ospf_neighbor
*nbr
);
173 extern void ospf_helper_handle_topo_chg(struct ospf
*ospf
,
174 struct ospf_lsa
*lsa
);
175 extern void ospf_gr_helper_support_set(struct ospf
*ospf
, bool support
);
176 extern void ospf_gr_helper_support_set_per_routerid(struct ospf
*ospf
,
179 extern void ospf_gr_helper_lsa_check_set(struct ospf
*ospf
, bool lsacheck
);
180 extern void ospf_gr_helper_supported_gracetime_set(struct ospf
*ospf
,
182 extern void ospf_gr_helper_set_supported_planned_only_restart(struct ospf
*ospf
,
185 extern void ospf_gr_check_lsdb_consistency(struct ospf
*ospf
,
186 struct ospf_area
*area
);
187 extern void ospf_gr_check_adjs(struct ospf
*ospf
);
188 extern void ospf_gr_nvm_read(struct ospf
*ospf
);
189 extern void ospf_gr_init(void);
191 #endif /* _ZEBRA_OSPF_GR_H */