2 * OSPF6 Graceful Retsart helper functions.
4 * Copyright (C) 2021-22 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
27 #define OSPF6_GR_NOT_HELPER 0
28 #define OSPF6_GR_ACTIVE_HELPER 1
30 #define OSPF6_GR_HELPER_NO_LSACHECK 0
31 #define OSPF6_GR_HELPER_LSACHECK 1
33 #define OSPF6_MAX_GRACE_INTERVAL 1800
34 #define OSPF6_MIN_GRACE_INTERVAL 1
35 #define OSPF6_DFLT_GRACE_INTERVAL 120
37 /* Forward declaration(s). */
38 struct ospf6_neighbor
;
41 extern unsigned char conf_debug_ospf6_gr
;
43 #define OSPF6_DEBUG_GR 0x01
45 #define OSPF6_DEBUG_GR_ON() (conf_debug_ospf6_gr |= OSPF6_DEBUG_GR)
47 #define OSPF6_DEBUG_GR_OFF() (conf_debug_ospf6_gr &= ~OSPF6_DEBUG_GR)
49 #define IS_DEBUG_OSPF6_GR conf_debug_ospf6_gr
52 enum ospf6_helper_exit_reason
{
53 OSPF6_GR_HELPER_EXIT_NONE
= 0,
54 OSPF6_GR_HELPER_INPROGRESS
,
55 OSPF6_GR_HELPER_TOPO_CHG
,
56 OSPF6_GR_HELPER_GRACE_TIMEOUT
,
57 OSPF6_GR_HELPER_COMPLETED
60 enum ospf6_gr_restart_reason
{
61 OSPF6_GR_UNKNOWN_RESTART
= 0,
62 OSPF6_GR_SW_RESTART
= 1,
63 OSPF6_GR_SW_UPGRADE
= 2,
64 OSPF6_GR_SWITCH_REDUNDANT_CARD
= 3,
65 OSPF6_GR_INVALID_REASON_CODE
= 4
68 enum ospf6_gr_helper_rejected_reason
{
69 OSPF6_HELPER_REJECTED_NONE
,
70 OSPF6_HELPER_SUPPORT_DISABLED
,
71 OSPF6_HELPER_NOT_A_VALID_NEIGHBOUR
,
72 OSPF6_HELPER_PLANNED_ONLY_RESTART
,
73 OSPF6_HELPER_TOPO_CHANGE_RTXMT_LIST
,
74 OSPF6_HELPER_LSA_AGE_MORE
,
75 OSPF6_HELPER_RESTARTING
,
79 #define ROUNDUP(val, gran) roundup(val, gran)
81 #define ROUNDUP(val, gran) (((val)-1 | (gran)-1) + 1)
85 * Generic TLV (type, length, value) macros
88 uint16_t type
; /* Type of Value */
89 uint16_t length
; /* Length of Value portion only, in bytes */
92 #define TLV_HDR_SIZE (sizeof(struct tlv_header))
94 #define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(uint32_t)))
96 #define TLV_SIZE(tlvh) (uint32_t)(TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh))
98 #define TLV_HDR_TOP(lsah) \
99 (struct tlv_header *)((char *)(lsah) + OSPF6_LSA_HEADER_SIZE)
101 #define TLV_HDR_NEXT(tlvh) \
102 (struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh))
104 /* Ref RFC5187 appendix-A */
105 /* Grace period TLV */
106 #define GRACE_PERIOD_TYPE 1
107 #define GRACE_PERIOD_LENGTH 4
108 struct grace_tlv_graceperiod
{
109 struct tlv_header header
;
112 #define GRACE_PERIOD_TLV_SIZE sizeof(struct grace_tlv_graceperiod)
114 /* Restart reason TLV */
115 #define RESTART_REASON_TYPE 2
116 #define RESTART_REASON_LENGTH 1
117 struct grace_tlv_restart_reason
{
118 struct tlv_header header
;
122 #define GRACE_RESTART_REASON_TLV_SIZE sizeof(struct grace_tlv_restart_reason)
124 #define OSPF6_GRACE_LSA_MIN_SIZE \
125 GRACE_PERIOD_TLV_SIZE + GRACE_RESTART_REASON_TLV_SIZE
127 struct ospf6_grace_lsa
{
128 struct grace_tlv_graceperiod tlv_period
;
129 struct grace_tlv_restart_reason tlv_reason
;
133 in_addr_t advRtrAddr
;
136 #define OSPF6_HELPER_ENABLE_RTR_COUNT(ospf) \
137 (ospf6->ospf6_helper_cfg.enable_rtr_list->count)
139 /* Check , it is a planned restart */
140 #define OSPF6_GR_IS_PLANNED_RESTART(reason) \
141 ((reason == OSPF6_GR_SW_RESTART) || (reason == OSPF6_GR_SW_UPGRADE))
143 /* Check the router is HELPER for current neighbour */
144 #define OSPF6_GR_IS_ACTIVE_HELPER(N) \
145 ((N)->gr_helper_info.gr_helper_status == OSPF6_GR_ACTIVE_HELPER)
147 /* Check the LSA is GRACE LSA */
148 #define IS_GRACE_LSA(lsa) (ntohs(lsa->header->type) == OSPF6_LSTYPE_GRACE_LSA)
150 /* Check neighbour is in FULL state */
151 #define IS_NBR_STATE_FULL(nbr) (nbr->state == OSPF6_NEIGHBOR_FULL)
153 extern const char *ospf6_exit_reason_desc
[];
154 extern const char *ospf6_restart_reason_desc
[];
155 extern const char *ospf6_rejected_reason_desc
[];
157 extern void ospf6_gr_helper_config_init(void);
158 extern void ospf6_gr_helper_init(struct ospf6
*ospf6
);
159 extern void ospf6_gr_helper_deinit(struct ospf6
*ospf6
);
160 extern void ospf6_gr_helper_exit(struct ospf6_neighbor
*nbr
,
161 enum ospf6_helper_exit_reason reason
);
162 extern int ospf6_process_grace_lsa(struct ospf6
*ospf6
, struct ospf6_lsa
*lsa
,
163 struct ospf6_neighbor
*nbr
);
164 extern void ospf6_process_maxage_grace_lsa(struct ospf6
*ospf
,
165 struct ospf6_lsa
*lsa
,
166 struct ospf6_neighbor
*nbr
);
167 extern void ospf6_helper_handle_topo_chg(struct ospf6
*ospf6
,
168 struct ospf6_lsa
*lsa
);
169 extern int config_write_ospf6_gr(struct vty
*vty
, struct ospf6
*ospf6
);
170 extern int config_write_ospf6_gr_helper(struct vty
*vty
, struct ospf6
*ospf6
);
171 extern int config_write_ospf6_debug_gr_helper(struct vty
*vty
);
173 extern void ospf6_gr_check_lsdb_consistency(struct ospf6
*ospf
,
174 struct ospf6_area
*area
);
175 extern void ospf6_gr_nvm_read(struct ospf6
*ospf
);
176 extern void ospf6_gr_init(void);
178 #endif /* OSPF6_GR_H */