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