]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_gr_helper.h
Merge pull request #7639 from qlyoung/frr-lua
[mirror_frr.git] / ospfd / ospf_gr_helper.h
1 /*
2 * OSPF Graceful Restart helper functions.
3 *
4 * Copyright (C) 2020-21 Vmware, Inc.
5 * Rajesh Kumar Girada
6 *
7 * This file is part of GNU Zebra.
8 *
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
12 * later version.
13 *
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.
18 *
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
22 */
23
24 #ifndef _ZEBRA_OSPF_GR_HELPER_H
25 #define _ZEBRA_OSPF_GR_HELPER_H
26
27 #define OSPF_GR_NOT_HELPER 0
28 #define OSPF_GR_ACTIVE_HELPER 1
29
30 #define OSPF_GR_HELPER_NO_LSACHECK 0
31 #define OSPF_GR_HELPER_LSACHECK 1
32
33 #define OSPF_MAX_GRACE_INTERVAL 1800
34 #define OSPF_MIN_GRACE_INTERVAL 1
35
36 enum ospf_helper_exit_reason {
37 OSPF_GR_HELPER_EXIT_NONE = 0,
38 OSPF_GR_HELPER_INPROGRESS,
39 OSPF_GR_HELPER_TOPO_CHG,
40 OSPF_GR_HELPER_GRACE_TIMEOUT,
41 OSPF_GR_HELPER_COMPLETED
42 };
43
44 enum ospf_gr_restart_reason {
45 OSPF_GR_UNKNOWN_RESTART = 0,
46 OSPF_GR_SW_RESTART = 1,
47 OSPF_GR_SW_UPGRADE = 2,
48 OSPF_GR_SWITCH_REDUNDANT_CARD = 3,
49 OSPF_GR_INVALID_REASON_CODE = 4
50 };
51
52 enum ospf_gr_helper_rejected_reason {
53 OSPF_HELPER_REJECTED_NONE,
54 OSPF_HELPER_SUPPORT_DISABLED,
55 OSPF_HELPER_NOT_A_VALID_NEIGHBOUR,
56 OSPF_HELPER_PLANNED_ONLY_RESTART,
57 OSPF_HELPER_TOPO_CHANGE_RTXMT_LIST,
58 OSPF_HELPER_LSA_AGE_MORE
59 };
60
61 /* Ref RFC3623 appendex-A */
62 /* Grace period TLV */
63 #define GRACE_PERIOD_TYPE 1
64 #define GRACE_PERIOD_LENGTH 4
65
66 struct grace_tlv_graceperiod {
67 struct tlv_header header;
68 uint32_t interval;
69 };
70
71 /* Restart reason TLV */
72 #define RESTART_REASON_TYPE 2
73 #define RESTART_REASON_LENGTH 1
74
75 struct grace_tlv_restart_reason {
76 struct tlv_header header;
77 uint8_t reason;
78 uint8_t reserved[3];
79 };
80
81 /* Restarter ip address TLV */
82 #define RESTARTER_IP_ADDR_TYPE 3
83 #define RESTARTER_IP_ADDR_LEN 4
84
85 struct grace_tlv_restart_addr {
86 struct tlv_header header;
87 struct in_addr addr;
88 };
89
90 struct ospf_helper_info {
91
92 /* Grace interval received from
93 * Restarting Router.
94 */
95 uint32_t recvd_grace_period;
96
97 /* Grace interval used for grace
98 * gracetimer.
99 */
100 uint32_t actual_grace_period;
101
102 /* Grace timer,This Router acts as
103 * helper until this timer until
104 * this timer expires*/
105 struct thread *t_grace_timer;
106
107 /* Helper status */
108 uint32_t gr_helper_status;
109
110 /* Helper exit reason*/
111 enum ospf_helper_exit_reason helper_exit_reason;
112
113 /* Planned/Unplanned restart*/
114 enum ospf_gr_restart_reason gr_restart_reason;
115
116 /* Helper rejected reason */
117 enum ospf_gr_helper_rejected_reason rejected_reason;
118 };
119
120 struct advRtr {
121 struct in_addr advRtrAddr;
122 };
123
124 #define OSPF_HELPER_ENABLE_RTR_COUNT(ospf) (ospf->enable_rtr_list->count)
125
126 /* Check for planned restart */
127 #define OSPF_GR_IS_PLANNED_RESTART(reason) \
128 ((reason == OSPF_GR_SW_RESTART) || (reason == OSPF_GR_SW_UPGRADE))
129
130 /* Check the router is HELPER for current neighbour */
131 #define OSPF_GR_IS_ACTIVE_HELPER(N) \
132 ((N)->gr_helper_info.gr_helper_status == OSPF_GR_ACTIVE_HELPER)
133
134 /* Check the LSA is GRACE LSA */
135 #define IS_GRACE_LSA(lsa) \
136 ((lsa->data->type == OSPF_OPAQUE_LINK_LSA) \
137 && (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)) \
138 == OPAQUE_TYPE_GRACE_LSA))
139
140 /* Check neighbour is in FULL state */
141 #define IS_NBR_STATE_FULL(nbr) (nsm_should_adj(nbr) && (nbr->state == NSM_Full))
142
143 /* Check neighbour is DR_OTHER and state is 2_WAY */
144 #define IS_NBR_STATE_2_WAY_WITH_DROTHER(nbr) \
145 ((ospf_get_nbr_ism_role(nbr) == ISM_DROther) \
146 && (nbr->state == NSM_TwoWay))
147
148 #define OSPF_GR_FALSE false
149 #define OSPF_GR_TRUE true
150
151 #define OSPF_GR_SUCCESS 1
152 #define OSPF_GR_FAILURE 0
153 #define OSPF_GR_INVALID -1
154
155 const char *ospf_exit_reason2str(unsigned int reason);
156 const char *ospf_restart_reason2str(unsigned int reason);
157 const char *ospf_rejected_reason2str(unsigned int reason);
158
159 extern void ospf_gr_helper_init(struct ospf *ospf);
160 extern void ospf_gr_helper_stop(struct ospf *ospf);
161 extern int ospf_process_grace_lsa(struct ospf *ospf, struct ospf_lsa *lsa,
162 struct ospf_neighbor *nbr);
163 extern void ospf_gr_helper_exit(struct ospf_neighbor *nbr,
164 enum ospf_helper_exit_reason reason);
165 extern void ospf_process_maxage_grace_lsa(struct ospf *ospf,
166 struct ospf_lsa *lsa,
167 struct ospf_neighbor *nbr);
168 extern void ospf_helper_handle_topo_chg(struct ospf *ospf,
169 struct ospf_lsa *lsa);
170 extern void ospf_gr_helper_support_set(struct ospf *ospf, bool support);
171 extern void ospf_gr_helper_support_set_per_routerid(struct ospf *ospf,
172 struct in_addr *rid,
173 bool support);
174 extern void ospf_gr_helper_lsa_check_set(struct ospf *ospf, bool lsacheck);
175 extern void ospf_gr_helper_supported_gracetime_set(struct ospf *ospf,
176 uint32_t interval);
177 extern void ospf_gr_helper_set_supported_planned_only_restart(struct ospf *ospf,
178 bool planned_only);
179 #endif /* _ZEBRA_OSPF_HELPER_H */