1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * OSPF6 Graceful Retsart helper functions.
5 * Copyright (C) 2021-22 Vmware, Inc.
12 #define OSPF6_GR_NOT_HELPER 0
13 #define OSPF6_GR_ACTIVE_HELPER 1
15 #define OSPF6_GR_HELPER_NO_LSACHECK 0
16 #define OSPF6_GR_HELPER_LSACHECK 1
18 #define OSPF6_MAX_GRACE_INTERVAL 1800
19 #define OSPF6_MIN_GRACE_INTERVAL 1
20 #define OSPF6_DFLT_GRACE_INTERVAL 120
22 /* Forward declaration(s). */
23 struct ospf6_neighbor
;
26 extern unsigned char conf_debug_ospf6_gr
;
28 #define OSPF6_DEBUG_GR 0x01
30 #define OSPF6_DEBUG_GR_ON() (conf_debug_ospf6_gr |= OSPF6_DEBUG_GR)
32 #define OSPF6_DEBUG_GR_OFF() (conf_debug_ospf6_gr &= ~OSPF6_DEBUG_GR)
34 #define IS_DEBUG_OSPF6_GR conf_debug_ospf6_gr
37 enum ospf6_helper_exit_reason
{
38 OSPF6_GR_HELPER_EXIT_NONE
= 0,
39 OSPF6_GR_HELPER_INPROGRESS
,
40 OSPF6_GR_HELPER_TOPO_CHG
,
41 OSPF6_GR_HELPER_GRACE_TIMEOUT
,
42 OSPF6_GR_HELPER_COMPLETED
45 enum ospf6_gr_restart_reason
{
46 OSPF6_GR_UNKNOWN_RESTART
= 0,
47 OSPF6_GR_SW_RESTART
= 1,
48 OSPF6_GR_SW_UPGRADE
= 2,
49 OSPF6_GR_SWITCH_REDUNDANT_CARD
= 3,
50 OSPF6_GR_INVALID_REASON_CODE
= 4
53 enum ospf6_gr_helper_rejected_reason
{
54 OSPF6_HELPER_REJECTED_NONE
,
55 OSPF6_HELPER_SUPPORT_DISABLED
,
56 OSPF6_HELPER_NOT_A_VALID_NEIGHBOUR
,
57 OSPF6_HELPER_PLANNED_ONLY_RESTART
,
58 OSPF6_HELPER_TOPO_CHANGE_RTXMT_LIST
,
59 OSPF6_HELPER_LSA_AGE_MORE
,
60 OSPF6_HELPER_RESTARTING
,
64 #define ROUNDUP(val, gran) roundup(val, gran)
66 #define ROUNDUP(val, gran) (((val)-1 | (gran)-1) + 1)
70 * Generic TLV (type, length, value) macros
73 uint16_t type
; /* Type of Value */
74 uint16_t length
; /* Length of Value portion only, in bytes */
77 #define TLV_HDR_SIZE (sizeof(struct tlv_header))
79 #define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(uint32_t)))
81 #define TLV_SIZE(tlvh) (uint32_t)(TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh))
83 #define TLV_HDR_TOP(lsah) \
84 (struct tlv_header *)((char *)(lsah) + OSPF6_LSA_HEADER_SIZE)
86 #define TLV_HDR_NEXT(tlvh) \
87 (struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh))
89 /* Ref RFC5187 appendix-A */
90 /* Grace period TLV */
91 #define GRACE_PERIOD_TYPE 1
92 #define GRACE_PERIOD_LENGTH 4
93 struct grace_tlv_graceperiod
{
94 struct tlv_header header
;
97 #define GRACE_PERIOD_TLV_SIZE sizeof(struct grace_tlv_graceperiod)
99 /* Restart reason TLV */
100 #define RESTART_REASON_TYPE 2
101 #define RESTART_REASON_LENGTH 1
102 struct grace_tlv_restart_reason
{
103 struct tlv_header header
;
107 #define GRACE_RESTART_REASON_TLV_SIZE sizeof(struct grace_tlv_restart_reason)
109 #define OSPF6_GRACE_LSA_MIN_SIZE \
110 GRACE_PERIOD_TLV_SIZE + GRACE_RESTART_REASON_TLV_SIZE
112 struct ospf6_grace_lsa
{
113 struct grace_tlv_graceperiod tlv_period
;
114 struct grace_tlv_restart_reason tlv_reason
;
118 in_addr_t advRtrAddr
;
121 #define OSPF6_HELPER_ENABLE_RTR_COUNT(ospf) \
122 (ospf6->ospf6_helper_cfg.enable_rtr_list->count)
124 /* Check , it is a planned restart */
125 #define OSPF6_GR_IS_PLANNED_RESTART(reason) \
126 ((reason == OSPF6_GR_SW_RESTART) || (reason == OSPF6_GR_SW_UPGRADE))
128 /* Check the router is HELPER for current neighbour */
129 #define OSPF6_GR_IS_ACTIVE_HELPER(N) \
130 ((N)->gr_helper_info.gr_helper_status == OSPF6_GR_ACTIVE_HELPER)
132 /* Check the LSA is GRACE LSA */
133 #define IS_GRACE_LSA(lsa) (ntohs(lsa->header->type) == OSPF6_LSTYPE_GRACE_LSA)
135 /* Check neighbour is in FULL state */
136 #define IS_NBR_STATE_FULL(nbr) (nbr->state == OSPF6_NEIGHBOR_FULL)
138 extern const char *ospf6_exit_reason_desc
[];
139 extern const char *ospf6_restart_reason_desc
[];
140 extern const char *ospf6_rejected_reason_desc
[];
142 extern void ospf6_gr_helper_config_init(void);
143 extern void ospf6_gr_helper_init(struct ospf6
*ospf6
);
144 extern void ospf6_gr_helper_deinit(struct ospf6
*ospf6
);
145 extern void ospf6_gr_helper_exit(struct ospf6_neighbor
*nbr
,
146 enum ospf6_helper_exit_reason reason
);
147 extern int ospf6_process_grace_lsa(struct ospf6
*ospf6
, struct ospf6_lsa
*lsa
,
148 struct ospf6_neighbor
*nbr
);
149 extern void ospf6_process_maxage_grace_lsa(struct ospf6
*ospf
,
150 struct ospf6_lsa
*lsa
,
151 struct ospf6_neighbor
*nbr
);
152 extern void ospf6_helper_handle_topo_chg(struct ospf6
*ospf6
,
153 struct ospf6_lsa
*lsa
);
154 extern int config_write_ospf6_gr(struct vty
*vty
, struct ospf6
*ospf6
);
155 extern int config_write_ospf6_gr_helper(struct vty
*vty
, struct ospf6
*ospf6
);
156 extern int config_write_ospf6_debug_gr_helper(struct vty
*vty
);
158 extern void ospf6_gr_check_lsdb_consistency(struct ospf6
*ospf
,
159 struct ospf6_area
*area
);
160 extern void ospf6_gr_nvm_read(struct ospf6
*ospf
);
161 extern void ospf6_gr_init(void);
163 #endif /* OSPF6_GR_H */