]>
git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_lsa.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * OSPF Link State Advertisement
4 * Copyright (C) 1999, 2000 Toshiaki Takada
7 #ifndef _ZEBRA_OSPF_LSA_H
8 #define _ZEBRA_OSPF_LSA_H
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
18 /* OSPF LSA Range definition. */
19 #define OSPF_MIN_LSA 1 /* begin range here */
20 #define OSPF_MAX_LSA 12
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
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
41 /* AS-external-LSA refresh method. */
42 #define LSA_REFRESH_IF_CHANGED 0
43 #define LSA_REFRESH_FORCE 1
45 /* OSPF LSA header. */
48 #define DO_NOT_AGE 0x8000
52 struct in_addr adv_router
;
62 /* LSA origination flag. */
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
73 /* LSA data. and size */
74 struct lsa_header
*data
;
77 /* Received time stamp. */
78 struct timeval tv_recv
;
80 /* Last time it was originated */
81 struct timeval tv_orig
;
83 /* All of reference count, also lock to remove. */
86 /* Flags for the SPF calculation. */
89 /* References to this LSA in neighbor retransmission lists*/
90 int retransmit_counter
;
92 /* Area the LSA belongs to, may be NULL if AS-external-LSA. */
93 struct ospf_area
*area
;
96 struct ospf_lsdb
*lsdb
;
101 /* Refreshement List or Queue */
104 /* For Type-9 Opaque-LSAs */
105 struct ospf_interface
*oi
;
110 /*For topo chg detection in HELPER role*/
111 bool to_be_acknowledged
;
113 /* send maxage with no data */
114 bool opaque_zero_len_delete
;
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
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 */
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)
136 /* OSPF Router-LSA Link information. */
137 struct router_lsa_link
{
138 struct in_addr link_id
;
139 struct in_addr link_data
;
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. */
157 struct lsa_header header
;
162 struct in_addr link_id
;
163 struct in_addr link_data
;
170 /* OSPF Network-LSAs structure. */
171 #define OSPF_NETWORK_LSA_MIN_SIZE 8U /* w/1 router-ID */
173 struct lsa_header header
;
175 struct in_addr routers
[1];
178 /* OSPF Summary-LSAs structure. */
179 #define OSPF_SUMMARY_LSA_MIN_SIZE 8U /* w/1 TOS metric block */
181 struct lsa_header header
;
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
;
195 struct in_addr fwd_addr
;
200 enum lsid_status
{ LSID_AVAILABLE
= 0, LSID_CHANGE
, LSID_NOT_AVAILABLE
};
202 #include "ospfd/ospf_opaque.h"
205 #define GET_METRIC(x) get_metric(x)
206 #define IS_EXTERNAL_METRIC(x) ((x) & 0x80)
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))
215 #define OSPF_LSA_UPDATE_DELAY 2
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))
222 #define OSPF_FR_CONFIG(o, a) \
223 (o->fr_configured || ((a != NULL) ? a->fr_info.configured : 0))
226 /* XXX: Eek, time functions, similar are in lib/thread.c */
227 extern struct timeval
int2tv(int);
228 extern struct timeval
msec2tv(int);
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
*);
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
,
239 extern struct ospf_neighbor
*ospf_nbr_lookup_ptop(struct ospf_interface
*);
240 extern int ospf_check_nbr_status(struct ospf
*);
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
*);
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
*);
261 extern void ospf_network_lsa_update(struct ospf_interface
*);
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
*,
269 extern struct ospf_lsa
*ospf_lsa_install(struct ospf
*, struct ospf_interface
*,
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 */);
277 extern struct in_addr
ospf_get_ip_from_ifp(struct ospf_interface
*);
279 extern struct ospf_lsa
*ospf_external_lsa_originate(struct ospf
*,
280 struct external_info
*);
281 extern void ospf_external_lsa_rid_change(struct ospf
*ospf
);
282 extern struct ospf_lsa
*ospf_lsa_lookup(struct ospf
*ospf
, struct ospf_area
*,
283 uint32_t, struct in_addr
,
285 extern struct ospf_lsa
*ospf_lsa_lookup_by_id(struct ospf_area
*, uint32_t,
287 extern struct ospf_lsa
*ospf_lsa_lookup_by_header(struct ospf_area
*,
288 struct lsa_header
*);
289 extern int ospf_lsa_more_recent(struct ospf_lsa
*, struct ospf_lsa
*);
290 extern int ospf_lsa_different(struct ospf_lsa
*, struct ospf_lsa
*,
291 bool ignore_rcvd_flag
);
292 extern void ospf_flush_self_originated_lsas_now(struct ospf
*);
294 extern int ospf_lsa_is_self_originated(struct ospf
*, struct ospf_lsa
*);
296 extern struct ospf_lsa
*ospf_lsa_lookup_by_prefix(struct ospf_lsdb
*, uint8_t,
297 struct prefix_ipv4
*,
300 extern void ospf_lsa_maxage(struct ospf
*, struct ospf_lsa
*);
301 extern uint32_t get_metric(uint8_t *);
303 extern void ospf_lsa_maxage_walker(struct thread
*thread
);
304 extern struct ospf_lsa
*ospf_lsa_refresh(struct ospf
*, struct ospf_lsa
*);
306 extern void ospf_external_lsa_refresh_default(struct ospf
*);
308 extern void ospf_external_lsa_refresh_type(struct ospf
*, uint8_t,
309 unsigned short, int);
310 extern struct ospf_lsa
*ospf_external_lsa_refresh(struct ospf
*,
312 struct external_info
*, int,
314 extern enum lsid_status
ospf_lsa_unique_id(struct ospf
*ospf
,
315 struct ospf_lsdb
*lsdb
,
316 uint8_t type
, struct prefix_ipv4
*p
,
317 struct in_addr
*addr
);
318 extern void ospf_schedule_lsa_flood_area(struct ospf_area
*, struct ospf_lsa
*);
319 extern void ospf_schedule_lsa_flush_area(struct ospf_area
*, struct ospf_lsa
*);
321 extern void ospf_refresher_register_lsa(struct ospf
*, struct ospf_lsa
*);
322 extern void ospf_refresher_unregister_lsa(struct ospf
*, struct ospf_lsa
*);
323 extern void ospf_lsa_refresh_walker(struct thread
*thread
);
325 extern void ospf_lsa_maxage_delete(struct ospf
*, struct ospf_lsa
*);
327 extern void ospf_discard_from_db(struct ospf
*, struct ospf_lsdb
*,
330 extern int metric_type(struct ospf
*, uint8_t, unsigned short);
331 extern int metric_value(struct ospf
*, uint8_t, unsigned short);
333 extern char link_info_set(struct stream
**s
, struct in_addr id
,
334 struct in_addr data
, uint8_t type
, uint8_t tos
,
337 extern struct in_addr
ospf_get_nssa_ip(struct ospf_area
*);
338 extern int ospf_translated_nssa_compare(struct ospf_lsa
*, struct ospf_lsa
*);
339 extern struct ospf_lsa
*ospf_translated_nssa_refresh(struct ospf
*ospf
,
340 struct ospf_lsa
*type7
,
341 struct ospf_lsa
*type5
);
342 extern struct ospf_lsa
*ospf_translated_nssa_originate(struct ospf
*ospf
,
343 struct ospf_lsa
*type7
,
344 struct ospf_lsa
*type5
);
345 extern void ospf_check_and_gen_init_seq_lsa(struct ospf_interface
*oi
,
346 struct ospf_lsa
*lsa
);
347 extern void ospf_flush_lsa_from_area(struct ospf
*ospf
, struct in_addr area_id
,
349 extern void ospf_maxage_lsa_remover(struct thread
*thread
);
350 extern bool ospf_check_dna_lsa(const struct ospf_lsa
*lsa
);
351 extern void ospf_refresh_area_self_lsas(struct ospf_area
*area
);
353 /** @brief Check if the LSA is an indication LSA.
354 * @param lsa pointer.
355 * @return true or false based on lsa info.
357 static inline bool ospf_check_indication_lsa(struct ospf_lsa
*lsa
)
359 struct summary_lsa
*sl
= NULL
;
361 if (lsa
->data
->type
== OSPF_ASBR_SUMMARY_LSA
) {
362 sl
= (struct summary_lsa
*)lsa
->data
;
363 if ((GET_METRIC(sl
->metric
) == OSPF_LS_INFINITY
) &&
364 !CHECK_FLAG(lsa
->data
->options
, OSPF_OPTION_DC
))
370 #endif /* _ZEBRA_OSPF_LSA_H */