]>
Commit | Line | Data |
---|---|---|
1 | // SPDX-License-Identifier: GPL-2.0-or-later | |
2 | /* | |
3 | * OSPF Link State Advertisement | |
4 | * Copyright (C) 1999, 2000 Toshiaki Takada | |
5 | */ | |
6 | ||
7 | #ifndef _ZEBRA_OSPF_LSA_H | |
8 | #define _ZEBRA_OSPF_LSA_H | |
9 | ||
10 | #include "stream.h" | |
11 | ||
12 | /* OSPF LSA Default metric values */ | |
13 | #define DEFAULT_DEFAULT_METRIC 20 | |
14 | #define DEFAULT_DEFAULT_ORIGINATE_METRIC 10 | |
15 | #define DEFAULT_DEFAULT_ALWAYS_METRIC 1 | |
16 | #define DEFAULT_METRIC_TYPE EXTERNAL_METRIC_TYPE_2 | |
17 | ||
18 | /* OSPF LSA Range definition. */ | |
19 | #define OSPF_MIN_LSA 1 /* begin range here */ | |
20 | #define OSPF_MAX_LSA 12 | |
21 | ||
22 | /* OSPF LSA Type definition. */ | |
23 | #define OSPF_UNKNOWN_LSA 0 | |
24 | #define OSPF_ROUTER_LSA 1 | |
25 | #define OSPF_NETWORK_LSA 2 | |
26 | #define OSPF_SUMMARY_LSA 3 | |
27 | #define OSPF_ASBR_SUMMARY_LSA 4 | |
28 | #define OSPF_AS_EXTERNAL_LSA 5 | |
29 | #define OSPF_GROUP_MEMBER_LSA 6 /* Not supported. */ | |
30 | #define OSPF_AS_NSSA_LSA 7 | |
31 | #define OSPF_EXTERNAL_ATTRIBUTES_LSA 8 /* Not supported. */ | |
32 | #define OSPF_OPAQUE_LINK_LSA 9 | |
33 | #define OSPF_OPAQUE_AREA_LSA 10 | |
34 | #define OSPF_OPAQUE_AS_LSA 11 | |
35 | ||
36 | #define OSPF_LSA_HEADER_SIZE 20U | |
37 | #define OSPF_ROUTER_LSA_LINK_SIZE 12U | |
38 | #define OSPF_ROUTER_LSA_TOS_SIZE 4U | |
39 | #define OSPF_MAX_LSA_SIZE 1500U | |
40 | ||
41 | /* AS-external-LSA refresh method. */ | |
42 | #define LSA_REFRESH_IF_CHANGED 0 | |
43 | #define LSA_REFRESH_FORCE 1 | |
44 | ||
45 | /* OSPF LSA header. */ | |
46 | struct lsa_header { | |
47 | uint16_t ls_age; | |
48 | #define DO_NOT_AGE 0x8000 | |
49 | uint8_t options; | |
50 | uint8_t type; | |
51 | struct in_addr id; | |
52 | struct in_addr adv_router; | |
53 | uint32_t ls_seqnum; | |
54 | uint16_t checksum; | |
55 | uint16_t length; | |
56 | }; | |
57 | ||
58 | struct vertex; | |
59 | ||
60 | /* OSPF LSA. */ | |
61 | struct ospf_lsa { | |
62 | /* LSA origination flag. */ | |
63 | uint8_t flags; | |
64 | #define OSPF_LSA_SELF 0x01 | |
65 | #define OSPF_LSA_SELF_CHECKED 0x02 | |
66 | #define OSPF_LSA_RECEIVED 0x04 | |
67 | #define OSPF_LSA_APPROVED 0x08 | |
68 | #define OSPF_LSA_DISCARD 0x10 | |
69 | #define OSPF_LSA_LOCAL_XLT 0x20 | |
70 | #define OSPF_LSA_PREMATURE_AGE 0x40 | |
71 | #define OSPF_LSA_IN_MAXAGE 0x80 | |
72 | ||
73 | /* LSA data. and size */ | |
74 | struct lsa_header *data; | |
75 | size_t size; | |
76 | ||
77 | /* Received time stamp. */ | |
78 | struct timeval tv_recv; | |
79 | ||
80 | /* Last time it was originated */ | |
81 | struct timeval tv_orig; | |
82 | ||
83 | /* All of reference count, also lock to remove. */ | |
84 | int lock; | |
85 | ||
86 | /* Flags for the SPF calculation. */ | |
87 | struct vertex *stat; | |
88 | ||
89 | /* References to this LSA in neighbor retransmission lists*/ | |
90 | int retransmit_counter; | |
91 | ||
92 | /* Area the LSA belongs to, may be NULL if AS-external-LSA. */ | |
93 | struct ospf_area *area; | |
94 | ||
95 | /* Parent LSDB. */ | |
96 | struct ospf_lsdb *lsdb; | |
97 | ||
98 | /* Related Route. */ | |
99 | void *route; | |
100 | ||
101 | /* Refreshement List or Queue */ | |
102 | int refresh_list; | |
103 | ||
104 | /* For Type-9 Opaque-LSAs */ | |
105 | struct ospf_interface *oi; | |
106 | ||
107 | /* VRF Id */ | |
108 | vrf_id_t vrf_id; | |
109 | ||
110 | /*For topo chg detection in HELPER role*/ | |
111 | bool to_be_acknowledged; | |
112 | ||
113 | /* send maxage with no data */ | |
114 | bool opaque_zero_len_delete; | |
115 | }; | |
116 | ||
117 | /* OSPF LSA Link Type. */ | |
118 | #define LSA_LINK_TYPE_POINTOPOINT 1 | |
119 | #define LSA_LINK_TYPE_TRANSIT 2 | |
120 | #define LSA_LINK_TYPE_STUB 3 | |
121 | #define LSA_LINK_TYPE_VIRTUALLINK 4 | |
122 | ||
123 | /* OSPF Router LSA Flag. */ | |
124 | #define ROUTER_LSA_BORDER 0x01 /* The router is an ABR */ | |
125 | #define ROUTER_LSA_EXTERNAL 0x02 /* The router is an ASBR */ | |
126 | #define ROUTER_LSA_VIRTUAL 0x04 /* The router has a VL in this area */ | |
127 | #define ROUTER_LSA_NT 0x10 /* The routers always translates Type-7 */ | |
128 | #define ROUTER_LSA_SHORTCUT 0x20 /* Shortcut-ABR specific flag */ | |
129 | ||
130 | #define IS_ROUTER_LSA_VIRTUAL(x) ((x)->flags & ROUTER_LSA_VIRTUAL) | |
131 | #define IS_ROUTER_LSA_EXTERNAL(x) ((x)->flags & ROUTER_LSA_EXTERNAL) | |
132 | #define IS_ROUTER_LSA_BORDER(x) ((x)->flags & ROUTER_LSA_BORDER) | |
133 | #define IS_ROUTER_LSA_SHORTCUT(x) ((x)->flags & ROUTER_LSA_SHORTCUT) | |
134 | #define IS_ROUTER_LSA_NT(x) ((x)->flags & ROUTER_LSA_NT) | |
135 | ||
136 | /* OSPF Router-LSA Link information. */ | |
137 | struct router_lsa_link { | |
138 | struct in_addr link_id; | |
139 | struct in_addr link_data; | |
140 | struct { | |
141 | uint8_t type; | |
142 | uint8_t tos_count; | |
143 | uint16_t metric; | |
144 | } m[1]; | |
145 | }; | |
146 | ||
147 | /* OSPF Router-LSAs structure. */ | |
148 | #define OSPF_ROUTER_LSA_MIN_SIZE 4U /* w/0 link descriptors */ | |
149 | /* There is an edge case, when number of links in a Router-LSA may be 0 without | |
150 | breaking the specification. A router, which has no other links to backbone | |
151 | area besides one virtual link, will not put any VL descriptor blocks into | |
152 | the Router-LSA generated for area 0 until a full adjacency over the VL is | |
153 | reached (RFC2328 12.4.1.3). In this case the Router-LSA initially received | |
154 | by the other end of the VL will have 0 link descriptor blocks, but soon will | |
155 | be replaced with the next revision having 1 descriptor block. */ | |
156 | struct router_lsa { | |
157 | struct lsa_header header; | |
158 | uint8_t flags; | |
159 | uint8_t zero; | |
160 | uint16_t links; | |
161 | struct router_link { | |
162 | struct in_addr link_id; | |
163 | struct in_addr link_data; | |
164 | uint8_t type; | |
165 | uint8_t tos; | |
166 | uint16_t metric; | |
167 | } link[1]; | |
168 | }; | |
169 | ||
170 | /* OSPF Network-LSAs structure. */ | |
171 | #define OSPF_NETWORK_LSA_MIN_SIZE 8U /* w/1 router-ID */ | |
172 | struct network_lsa { | |
173 | struct lsa_header header; | |
174 | struct in_addr mask; | |
175 | struct in_addr routers[1]; | |
176 | }; | |
177 | ||
178 | /* OSPF Summary-LSAs structure. */ | |
179 | #define OSPF_SUMMARY_LSA_MIN_SIZE 8U /* w/1 TOS metric block */ | |
180 | struct summary_lsa { | |
181 | struct lsa_header header; | |
182 | struct in_addr mask; | |
183 | uint8_t tos; | |
184 | uint8_t metric[3]; | |
185 | }; | |
186 | ||
187 | /* OSPF AS-external-LSAs structure. */ | |
188 | #define OSPF_AS_EXTERNAL_LSA_MIN_SIZE 16U /* w/1 TOS forwarding block */ | |
189 | struct as_external_lsa { | |
190 | struct lsa_header header; | |
191 | struct in_addr mask; | |
192 | struct as_route { | |
193 | uint8_t tos; | |
194 | uint8_t metric[3]; | |
195 | struct in_addr fwd_addr; | |
196 | uint32_t route_tag; | |
197 | } e[1]; | |
198 | }; | |
199 | ||
200 | enum lsid_status { LSID_AVAILABLE = 0, LSID_CHANGE, LSID_NOT_AVAILABLE }; | |
201 | ||
202 | #include "ospfd/ospf_opaque.h" | |
203 | ||
204 | /* Macros. */ | |
205 | #define GET_METRIC(x) get_metric(x) | |
206 | #define IS_EXTERNAL_METRIC(x) ((x) & 0x80) | |
207 | ||
208 | #define GET_AGE(x) (ntohs ((x)->data->ls_age) + time (NULL) - (x)->tv_recv) | |
209 | #define LS_AGE(x) (OSPF_LSA_MAXAGE < get_age(x) ? OSPF_LSA_MAXAGE : get_age(x)) | |
210 | #define IS_LSA_SELF(L) (CHECK_FLAG ((L)->flags, OSPF_LSA_SELF)) | |
211 | #define IS_LSA_MAXAGE(L) (LS_AGE ((L)) == OSPF_LSA_MAXAGE) | |
212 | #define IS_LSA_MAX_SEQ(L) \ | |
213 | ((L)->data->ls_seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER)) | |
214 | ||
215 | #define OSPF_LSA_UPDATE_DELAY 2 | |
216 | ||
217 | #define CHECK_LSA_TYPE_1_TO_5_OR_7(type) \ | |
218 | ((type == OSPF_ROUTER_LSA) || (type == OSPF_NETWORK_LSA) \ | |
219 | || (type == OSPF_SUMMARY_LSA) || (type == OSPF_ASBR_SUMMARY_LSA) \ | |
220 | || (type == OSPF_AS_EXTERNAL_LSA) || (type == OSPF_AS_NSSA_LSA)) | |
221 | ||
222 | #define OSPF_FR_CONFIG(o, a) \ | |
223 | (o->fr_configured || ((a != NULL) ? a->fr_info.configured : 0)) | |
224 | ||
225 | /* Prototypes. */ | |
226 | /* XXX: Eek, time functions, similar are in lib/thread.c */ | |
227 | extern struct timeval int2tv(int); | |
228 | extern struct timeval msec2tv(int); | |
229 | ||
230 | extern int get_age(struct ospf_lsa *); | |
231 | extern uint16_t ospf_lsa_checksum(struct lsa_header *); | |
232 | extern int ospf_lsa_checksum_valid(struct lsa_header *); | |
233 | extern int ospf_lsa_refresh_delay(struct ospf_lsa *); | |
234 | ||
235 | extern const char *dump_lsa_key(struct ospf_lsa *); | |
236 | extern uint32_t lsa_seqnum_increment(struct ospf_lsa *); | |
237 | extern void lsa_header_set(struct stream *, uint8_t, uint8_t, struct in_addr, | |
238 | struct in_addr); | |
239 | extern struct ospf_neighbor *ospf_nbr_lookup_ptop(struct ospf_interface *); | |
240 | extern int ospf_check_nbr_status(struct ospf *); | |
241 | ||
242 | /* Prototype for LSA primitive. */ | |
243 | extern struct ospf_lsa *ospf_lsa_new(void); | |
244 | extern struct ospf_lsa *ospf_lsa_new_and_data(size_t size); | |
245 | extern struct ospf_lsa *ospf_lsa_dup(struct ospf_lsa *); | |
246 | extern void ospf_lsa_free(struct ospf_lsa *); | |
247 | extern struct ospf_lsa *ospf_lsa_lock(struct ospf_lsa *); | |
248 | extern void ospf_lsa_unlock(struct ospf_lsa **); | |
249 | extern void ospf_lsa_discard(struct ospf_lsa *); | |
250 | extern int ospf_lsa_flush_schedule(struct ospf *, struct ospf_lsa *); | |
251 | extern struct lsa_header *ospf_lsa_data_new(size_t); | |
252 | extern struct lsa_header *ospf_lsa_data_dup(struct lsa_header *); | |
253 | extern void ospf_lsa_data_free(struct lsa_header *); | |
254 | ||
255 | /* Prototype for various LSAs */ | |
256 | extern void ospf_router_lsa_body_set(struct stream **s, struct ospf_area *area); | |
257 | extern uint8_t router_lsa_flags(struct ospf_area *area); | |
258 | extern int ospf_router_lsa_update(struct ospf *); | |
259 | extern int ospf_router_lsa_update_area(struct ospf_area *); | |
260 | ||
261 | extern void ospf_network_lsa_update(struct ospf_interface *); | |
262 | ||
263 | extern struct ospf_lsa * | |
264 | ospf_summary_lsa_originate(struct prefix_ipv4 *, uint32_t, struct ospf_area *); | |
265 | extern struct ospf_lsa *ospf_summary_asbr_lsa_originate(struct prefix_ipv4 *, | |
266 | uint32_t, | |
267 | struct ospf_area *); | |
268 | ||
269 | extern struct ospf_lsa *ospf_lsa_install(struct ospf *, struct ospf_interface *, | |
270 | struct ospf_lsa *); | |
271 | ||
272 | extern void ospf_nssa_lsa_flush(struct ospf *ospf, struct prefix_ipv4 *p); | |
273 | extern void ospf_external_lsa_flush(struct ospf *, uint8_t, | |
274 | struct prefix_ipv4 *, | |
275 | ifindex_t /* , struct in_addr nexthop */); | |
276 | ||
277 | extern struct in_addr ospf_get_ip_from_ifp(struct ospf_interface *); | |
278 | ||
279 | extern struct ospf_lsa *ospf_external_lsa_originate(struct ospf *, | |
280 | struct external_info *); | |
281 | extern struct ospf_lsa *ospf_nssa_lsa_originate(struct ospf_area *area, | |
282 | struct external_info *ei); | |
283 | extern struct ospf_lsa *ospf_nssa_lsa_refresh(struct ospf_area *area, | |
284 | struct ospf_lsa *lsa, | |
285 | struct external_info *ei); | |
286 | extern void ospf_external_lsa_rid_change(struct ospf *ospf); | |
287 | extern struct ospf_lsa *ospf_lsa_lookup(struct ospf *ospf, struct ospf_area *, | |
288 | uint32_t, struct in_addr, | |
289 | struct in_addr); | |
290 | extern struct ospf_lsa *ospf_lsa_lookup_by_id(struct ospf_area *, uint32_t, | |
291 | struct in_addr); | |
292 | extern struct ospf_lsa *ospf_lsa_lookup_by_header(struct ospf_area *, | |
293 | struct lsa_header *); | |
294 | extern int ospf_lsa_more_recent(struct ospf_lsa *, struct ospf_lsa *); | |
295 | extern int ospf_lsa_different(struct ospf_lsa *, struct ospf_lsa *, | |
296 | bool ignore_rcvd_flag); | |
297 | extern void ospf_flush_self_originated_lsas_now(struct ospf *); | |
298 | ||
299 | extern int ospf_lsa_is_self_originated(struct ospf *, struct ospf_lsa *); | |
300 | ||
301 | extern struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *, uint8_t, | |
302 | struct prefix_ipv4 *, | |
303 | struct in_addr); | |
304 | ||
305 | extern void ospf_lsa_maxage(struct ospf *, struct ospf_lsa *); | |
306 | extern uint32_t get_metric(uint8_t *); | |
307 | ||
308 | extern void ospf_lsa_maxage_walker(struct event *thread); | |
309 | extern struct ospf_lsa *ospf_lsa_refresh(struct ospf *, struct ospf_lsa *); | |
310 | ||
311 | extern void ospf_external_lsa_refresh_default(struct ospf *); | |
312 | ||
313 | extern void ospf_external_lsa_refresh_type(struct ospf *, uint8_t, | |
314 | unsigned short, int); | |
315 | extern struct ospf_lsa *ospf_external_lsa_refresh(struct ospf *, | |
316 | struct ospf_lsa *, | |
317 | struct external_info *, int, | |
318 | bool aggr); | |
319 | extern enum lsid_status ospf_lsa_unique_id(struct ospf *ospf, | |
320 | struct ospf_lsdb *lsdb, | |
321 | uint8_t type, struct prefix_ipv4 *p, | |
322 | struct in_addr *addr); | |
323 | extern void ospf_schedule_lsa_flood_area(struct ospf_area *, struct ospf_lsa *); | |
324 | extern void ospf_schedule_lsa_flush_area(struct ospf_area *, struct ospf_lsa *); | |
325 | ||
326 | extern void ospf_refresher_register_lsa(struct ospf *, struct ospf_lsa *); | |
327 | extern void ospf_refresher_unregister_lsa(struct ospf *, struct ospf_lsa *); | |
328 | extern void ospf_lsa_refresh_walker(struct event *thread); | |
329 | ||
330 | extern void ospf_lsa_maxage_delete(struct ospf *, struct ospf_lsa *); | |
331 | ||
332 | extern void ospf_discard_from_db(struct ospf *, struct ospf_lsdb *, | |
333 | struct ospf_lsa *); | |
334 | ||
335 | extern int metric_type(struct ospf *, uint8_t, unsigned short); | |
336 | extern int metric_value(struct ospf *, uint8_t, unsigned short); | |
337 | ||
338 | extern char link_info_set(struct stream **s, struct in_addr id, | |
339 | struct in_addr data, uint8_t type, uint8_t tos, | |
340 | uint16_t cost); | |
341 | ||
342 | extern struct in_addr ospf_get_nssa_ip(struct ospf_area *); | |
343 | extern int ospf_translated_nssa_compare(struct ospf_lsa *, struct ospf_lsa *); | |
344 | extern struct ospf_lsa *ospf_translated_nssa_refresh(struct ospf *ospf, | |
345 | struct ospf_lsa *type7, | |
346 | struct ospf_lsa *type5); | |
347 | extern struct ospf_lsa *ospf_translated_nssa_originate(struct ospf *ospf, | |
348 | struct ospf_lsa *type7, | |
349 | struct ospf_lsa *type5); | |
350 | extern void ospf_check_and_gen_init_seq_lsa(struct ospf_interface *oi, | |
351 | struct ospf_lsa *lsa); | |
352 | extern void ospf_flush_lsa_from_area(struct ospf *ospf, struct in_addr area_id, | |
353 | int type); | |
354 | extern void ospf_maxage_lsa_remover(struct event *thread); | |
355 | extern bool ospf_check_dna_lsa(const struct ospf_lsa *lsa); | |
356 | extern void ospf_refresh_area_self_lsas(struct ospf_area *area); | |
357 | ||
358 | /** @brief Check if the LSA is an indication LSA. | |
359 | * @param lsa pointer. | |
360 | * @return true or false based on lsa info. | |
361 | */ | |
362 | static inline bool ospf_check_indication_lsa(struct ospf_lsa *lsa) | |
363 | { | |
364 | struct summary_lsa *sl = NULL; | |
365 | ||
366 | if (lsa->data->type == OSPF_ASBR_SUMMARY_LSA) { | |
367 | sl = (struct summary_lsa *)lsa->data; | |
368 | if ((GET_METRIC(sl->metric) == OSPF_LS_INFINITY) && | |
369 | !CHECK_FLAG(lsa->data->options, OSPF_OPTION_DC)) | |
370 | return true; | |
371 | } | |
372 | ||
373 | return false; | |
374 | } | |
375 | #endif /* _ZEBRA_OSPF_LSA_H */ |