]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_gr.h
ospf6d: introduce support for Graceful Restart (restarting mode)
[mirror_frr.git] / ospf6d / ospf6_gr.h
1 /*
2 * OSPF6 Graceful Retsart helper functions.
3 *
4 * Copyright (C) 2021-22 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 OSPF6_GR_H
25 #define OSPF6_GR_H
26
27 #define OSPF6_GR_NOT_HELPER 0
28 #define OSPF6_GR_ACTIVE_HELPER 1
29
30 #define OSPF6_GR_HELPER_NO_LSACHECK 0
31 #define OSPF6_GR_HELPER_LSACHECK 1
32
33 #define OSPF6_MAX_GRACE_INTERVAL 1800
34 #define OSPF6_MIN_GRACE_INTERVAL 1
35 #define OSPF6_DFLT_GRACE_INTERVAL 120
36
37 /* Forward declaration(s). */
38 struct ospf6_neighbor;
39
40 /* Debug option */
41 extern unsigned char conf_debug_ospf6_gr;
42
43 #define OSPF6_DEBUG_GR 0x01
44
45 #define OSPF6_DEBUG_GR_ON() (conf_debug_ospf6_gr |= OSPF6_DEBUG_GR)
46
47 #define OSPF6_DEBUG_GR_OFF() (conf_debug_ospf6_gr &= ~OSPF6_DEBUG_GR)
48
49 #define IS_DEBUG_OSPF6_GR conf_debug_ospf6_gr
50
51
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
58 };
59
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
66 };
67
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,
76 };
77
78 #ifdef roundup
79 #define ROUNDUP(val, gran) roundup(val, gran)
80 #else /* roundup */
81 #define ROUNDUP(val, gran) (((val)-1 | (gran)-1) + 1)
82 #endif /* roundup */
83
84 /*
85 * Generic TLV (type, length, value) macros
86 */
87 struct tlv_header {
88 uint16_t type; /* Type of Value */
89 uint16_t length; /* Length of Value portion only, in bytes */
90 };
91
92 #define TLV_HDR_SIZE (sizeof(struct tlv_header))
93
94 #define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(uint32_t)))
95
96 #define TLV_SIZE(tlvh) (TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh))
97
98 #define TLV_HDR_TOP(lsah) \
99 (struct tlv_header *)((char *)(lsah) + OSPF6_LSA_HEADER_SIZE)
100
101 #define TLV_HDR_NEXT(tlvh) \
102 (struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh))
103
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;
110 uint32_t interval;
111 };
112 #define GRACE_PERIOD_TLV_SIZE sizeof(struct grace_tlv_graceperiod)
113
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;
119 uint8_t reason;
120 uint8_t reserved[3];
121 };
122 #define GRACE_RESTART_REASON_TLV_SIZE sizeof(struct grace_tlv_restart_reason)
123
124 #define OSPF6_GRACE_LSA_MIN_SIZE \
125 GRACE_PERIOD_TLV_SIZE + GRACE_RESTART_REASON_TLV_SIZE
126
127 struct ospf6_grace_lsa {
128 struct grace_tlv_graceperiod tlv_period;
129 struct grace_tlv_restart_reason tlv_reason;
130 };
131
132 struct advRtr {
133 in_addr_t advRtrAddr;
134 };
135
136 #define OSPF6_HELPER_ENABLE_RTR_COUNT(ospf) \
137 (ospf6->ospf6_helper_cfg.enable_rtr_list->count)
138
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))
142
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)
146
147 /* Check the LSA is GRACE LSA */
148 #define IS_GRACE_LSA(lsa) (ntohs(lsa->header->type) == OSPF6_LSTYPE_GRACE_LSA)
149
150 /* Check neighbour is in FULL state */
151 #define IS_NBR_STATE_FULL(nbr) (nbr->state == OSPF6_NEIGHBOR_FULL)
152
153 extern const char *ospf6_exit_reason_desc[];
154 extern const char *ospf6_restart_reason_desc[];
155 extern const char *ospf6_rejected_reason_desc[];
156
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);
172
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);
177
178 #endif /* OSPF6_GR_H */