]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_lsa.h
tools: improve explanation of 'wrap' options
[mirror_frr.git] / ospf6d / ospf6_lsa.h
1 /*
2 * Copyright (C) 2003 Yasuhiro Ohara
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef OSPF6_LSA_H
22 #define OSPF6_LSA_H
23 #include "ospf6_top.h"
24 #include "lib/json.h"
25
26 /* Debug option */
27 #define OSPF6_LSA_DEBUG 0x01
28 #define OSPF6_LSA_DEBUG_ORIGINATE 0x02
29 #define OSPF6_LSA_DEBUG_EXAMIN 0x04
30 #define OSPF6_LSA_DEBUG_FLOOD 0x08
31 #define OSPF6_LSA_DEBUG_ALL \
32 (OSPF6_LSA_DEBUG | OSPF6_LSA_DEBUG_ORIGINATE | OSPF6_LSA_DEBUG_EXAMIN \
33 | OSPF6_LSA_DEBUG_FLOOD)
34 #define OSPF6_LSA_DEBUG_AGGR 0x10
35
36 /* OSPF LSA Default metric values */
37 #define DEFAULT_DEFAULT_METRIC 20
38 #define DEFAULT_DEFAULT_ORIGINATE_METRIC 10
39 #define DEFAULT_DEFAULT_ALWAYS_METRIC 1
40 #define DEFAULT_METRIC_TYPE 2
41
42 #define IS_OSPF6_DEBUG_LSA(name) \
43 (ospf6_lstype_debug(htons(OSPF6_LSTYPE_##name)) & OSPF6_LSA_DEBUG)
44 #define IS_OSPF6_DEBUG_ORIGINATE(name) \
45 (ospf6_lstype_debug(htons(OSPF6_LSTYPE_##name)) \
46 & OSPF6_LSA_DEBUG_ORIGINATE)
47 #define IS_OSPF6_DEBUG_EXAMIN(name) \
48 (ospf6_lstype_debug(htons(OSPF6_LSTYPE_##name)) \
49 & OSPF6_LSA_DEBUG_EXAMIN)
50 #define IS_OSPF6_DEBUG_LSA_TYPE(type) \
51 (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG)
52 #define IS_OSPF6_DEBUG_ORIGINATE_TYPE(type) \
53 (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG_ORIGINATE)
54 #define IS_OSPF6_DEBUG_EXAMIN_TYPE(type) \
55 (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG_EXAMIN)
56 #define IS_OSPF6_DEBUG_FLOOD_TYPE(type) \
57 (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG_FLOOD)
58 #define IS_OSPF6_DEBUG_AGGR \
59 (ospf6_lstype_debug(OSPF6_LSTYPE_AS_EXTERNAL) & OSPF6_LSA_DEBUG_AGGR) \
60
61 /* LSA definition */
62
63 #define OSPF6_MAX_LSASIZE 4096
64
65 /* Type */
66 #define OSPF6_LSTYPE_UNKNOWN 0x0000
67 #define OSPF6_LSTYPE_ROUTER 0x2001
68 #define OSPF6_LSTYPE_NETWORK 0x2002
69 #define OSPF6_LSTYPE_INTER_PREFIX 0x2003
70 #define OSPF6_LSTYPE_INTER_ROUTER 0x2004
71 #define OSPF6_LSTYPE_AS_EXTERNAL 0x4005
72 #define OSPF6_LSTYPE_GROUP_MEMBERSHIP 0x2006
73 #define OSPF6_LSTYPE_TYPE_7 0x2007
74 #define OSPF6_LSTYPE_LINK 0x0008
75 #define OSPF6_LSTYPE_INTRA_PREFIX 0x2009
76 #define OSPF6_LSTYPE_GRACE_LSA 0x000b
77 #define OSPF6_LSTYPE_SIZE 0x000c
78
79 /* Masks for LS Type : RFC 2740 A.4.2.1 "LS type" */
80 #define OSPF6_LSTYPE_UBIT_MASK 0x8000
81 #define OSPF6_LSTYPE_SCOPE_MASK 0x6000
82 #define OSPF6_LSTYPE_FCODE_MASK 0x1fff
83
84 /* LSA scope */
85 #define OSPF6_SCOPE_LINKLOCAL 0x0000
86 #define OSPF6_SCOPE_AREA 0x2000
87 #define OSPF6_SCOPE_AS 0x4000
88 #define OSPF6_SCOPE_RESERVED 0x6000
89
90 /* XXX U-bit handling should be treated here */
91 #define OSPF6_LSA_SCOPE(type) (ntohs(type) & OSPF6_LSTYPE_SCOPE_MASK)
92
93 /* LSA Header */
94 #define OSPF6_LSA_HEADER_SIZE 20U
95 struct ospf6_lsa_header {
96 uint16_t age; /* LS age */
97 uint16_t type; /* LS type */
98 in_addr_t id; /* Link State ID */
99 in_addr_t adv_router; /* Advertising Router */
100 uint32_t seqnum; /* LS sequence number */
101 uint16_t checksum; /* LS checksum */
102 uint16_t length; /* LSA length */
103 };
104
105 #define OSPF6_LSA_HEADER_END(h) ((caddr_t)(h) + sizeof(struct ospf6_lsa_header))
106 #define OSPF6_LSA_SIZE(h) (ntohs(((struct ospf6_lsa_header *)(h))->length))
107 #define OSPF6_LSA_END(h) \
108 ((caddr_t)(h) + ntohs(((struct ospf6_lsa_header *)(h))->length))
109 #define OSPF6_LSA_IS_TYPE(t, L) \
110 ((L)->header->type == htons(OSPF6_LSTYPE_##t) ? 1 : 0)
111 #define OSPF6_LSA_IS_SAME(L1, L2) \
112 ((L1)->header->adv_router == (L2)->header->adv_router \
113 && (L1)->header->id == (L2)->header->id \
114 && (L1)->header->type == (L2)->header->type)
115 #define OSPF6_LSA_IS_MATCH(t, i, a, L) \
116 ((L)->header->adv_router == (a) && (L)->header->id == (i) \
117 && (L)->header->type == (t))
118 #define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2)
119 #define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == OSPF_LSA_MAXAGE)
120 #define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
121 #define OSPF6_LSA_IS_SEQWRAP(L) ((L)->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER + 1))
122
123
124 struct ospf6_lsa {
125 char name[64]; /* dump string */
126
127 struct route_node *rn;
128
129 unsigned char lock; /* reference counter */
130 unsigned char flag; /* special meaning (e.g. floodback) */
131
132 struct timeval birth; /* tv_sec when LS age 0 */
133 struct timeval originated; /* used by MinLSInterval check */
134 struct timeval received; /* used by MinLSArrival check */
135 struct timeval installed;
136
137 struct thread *expire;
138 struct thread *refresh; /* For self-originated LSA */
139
140 int retrans_count;
141
142 struct ospf6_lsdb *lsdb;
143
144 in_addr_t external_lsa_id;
145
146 /* lsa instance */
147 struct ospf6_lsa_header *header;
148
149 /*For topo chg detection in HELPER role*/
150 bool tobe_acknowledged;
151 };
152
153 #define OSPF6_LSA_HEADERONLY 0x01
154 #define OSPF6_LSA_FLOODBACK 0x02
155 #define OSPF6_LSA_DUPLICATE 0x04
156 #define OSPF6_LSA_IMPLIEDACK 0x08
157 #define OSPF6_LSA_UNAPPROVED 0x10
158 #define OSPF6_LSA_SEQWRAPPED 0x20
159 #define OSPF6_LSA_FLUSH 0x40
160
161 struct ospf6_lsa_handler {
162 uint16_t lh_type; /* host byte order */
163 const char *lh_name;
164 const char *lh_short_name;
165 int (*lh_show)(struct vty *, struct ospf6_lsa *, json_object *json_obj,
166 bool use_json);
167 char *(*lh_get_prefix_str)(struct ospf6_lsa *, char *buf, int buflen,
168 int pos);
169
170 uint8_t lh_debug;
171 };
172
173 #define OSPF6_LSA_IS_KNOWN(t) \
174 (ospf6_get_lsa_handler(t)->lh_type != OSPF6_LSTYPE_UNKNOWN ? 1 : 0)
175
176 /* Macro for LSA Origination */
177 /* addr is (struct prefix *) */
178 #define CONTINUE_IF_ADDRESS_LINKLOCAL(debug, addr) \
179 if (IN6_IS_ADDR_LINKLOCAL(&(addr)->u.prefix6)) { \
180 if (debug) \
181 zlog_debug("Filter out Linklocal: %pFX", addr); \
182 continue; \
183 }
184
185 #define CONTINUE_IF_ADDRESS_UNSPECIFIED(debug, addr) \
186 if (IN6_IS_ADDR_UNSPECIFIED(&(addr)->u.prefix6)) { \
187 if (debug) \
188 zlog_debug("Filter out Unspecified: %pFX", addr); \
189 continue; \
190 }
191
192 #define CONTINUE_IF_ADDRESS_LOOPBACK(debug, addr) \
193 if (IN6_IS_ADDR_LOOPBACK(&(addr)->u.prefix6)) { \
194 if (debug) \
195 zlog_debug("Filter out Loopback: %pFX", addr); \
196 continue; \
197 }
198
199 #define CONTINUE_IF_ADDRESS_V4COMPAT(debug, addr) \
200 if (IN6_IS_ADDR_V4COMPAT(&(addr)->u.prefix6)) { \
201 if (debug) \
202 zlog_debug("Filter out V4Compat: %pFX", addr); \
203 continue; \
204 }
205
206 #define CONTINUE_IF_ADDRESS_V4MAPPED(debug, addr) \
207 if (IN6_IS_ADDR_V4MAPPED(&(addr)->u.prefix6)) { \
208 if (debug) \
209 zlog_debug("Filter out V4Mapped: %pFX", addr); \
210 continue; \
211 }
212
213 #define CHECK_LSA_TOPO_CHG_ELIGIBLE(type) \
214 ((type == OSPF6_LSTYPE_ROUTER) \
215 || (type == OSPF6_LSTYPE_NETWORK) \
216 || (type == OSPF6_LSTYPE_INTER_PREFIX) \
217 || (type == OSPF6_LSTYPE_INTER_ROUTER) \
218 || (type == OSPF6_LSTYPE_AS_EXTERNAL) \
219 || (type == OSPF6_LSTYPE_TYPE_7) \
220 || (type == OSPF6_LSTYPE_INTRA_PREFIX))
221
222 /* Function Prototypes */
223 extern const char *ospf6_lstype_name(uint16_t type);
224 extern const char *ospf6_lstype_short_name(uint16_t type);
225 extern uint8_t ospf6_lstype_debug(uint16_t type);
226 extern int metric_type(struct ospf6 *ospf6, int type, uint8_t instance);
227 extern int metric_value(struct ospf6 *ospf6, int type, uint8_t instance);
228 extern int ospf6_lsa_is_differ(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
229 extern int ospf6_lsa_is_changed(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
230 extern uint16_t ospf6_lsa_age_current(struct ospf6_lsa *lsa);
231 extern void ospf6_lsa_age_update_to_send(struct ospf6_lsa *lsa,
232 uint32_t transdelay);
233 extern void ospf6_lsa_premature_aging(struct ospf6_lsa *lsa);
234 extern int ospf6_lsa_compare(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
235
236 extern char *ospf6_lsa_printbuf(struct ospf6_lsa *lsa, char *buf, int size);
237 extern void ospf6_lsa_header_print_raw(struct ospf6_lsa_header *header);
238 extern void ospf6_lsa_header_print(struct ospf6_lsa *lsa);
239 extern void ospf6_lsa_show_summary_header(struct vty *vty);
240 extern void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa,
241 json_object *json, bool use_json);
242 extern void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa,
243 json_object *json, bool use_json);
244 extern void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa,
245 json_object *json, bool use_json);
246 extern void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
247 json_object *json, bool use_json);
248
249 extern struct ospf6_lsa *ospf6_lsa_alloc(size_t lsa_length);
250 extern struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header);
251 extern struct ospf6_lsa *
252 ospf6_lsa_create_headeronly(struct ospf6_lsa_header *header);
253 extern void ospf6_lsa_delete(struct ospf6_lsa *lsa);
254 extern struct ospf6_lsa *ospf6_lsa_copy(struct ospf6_lsa *lsa);
255
256 extern struct ospf6_lsa *ospf6_lsa_lock(struct ospf6_lsa *lsa);
257 extern struct ospf6_lsa *ospf6_lsa_unlock(struct ospf6_lsa *lsa);
258
259 extern void ospf6_lsa_expire(struct thread *thread);
260 extern void ospf6_lsa_refresh(struct thread *thread);
261
262 extern unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header *lsah);
263 extern int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *lsah);
264 extern int ospf6_lsa_prohibited_duration(uint16_t type, uint32_t id,
265 uint32_t adv_router, void *scope);
266
267 extern void ospf6_install_lsa_handler(struct ospf6_lsa_handler *handler);
268 extern struct ospf6_lsa_handler *ospf6_get_lsa_handler(uint16_t type);
269 extern void ospf6_lsa_debug_set_all(bool val);
270
271 extern void ospf6_lsa_init(void);
272 extern void ospf6_lsa_terminate(void);
273
274 extern int config_write_ospf6_debug_lsa(struct vty *vty);
275 extern void install_element_ospf6_debug_lsa(void);
276 extern void ospf6_lsa_age_set(struct ospf6_lsa *lsa);
277 extern void ospf6_flush_self_originated_lsas_now(struct ospf6 *ospf6);
278 extern struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa);
279 struct ospf6_lsa *ospf6_find_external_lsa(struct ospf6 *ospf6,
280 struct prefix *p);
281 #endif /* OSPF6_LSA_H */