]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_lsa.h
*: Rename `struct thread` to `struct event`
[mirror_frr.git] / ospfd / ospf_lsa.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/*
3 * OSPF Link State Advertisement
4 * Copyright (C) 1999, 2000 Toshiaki Takada
718e3744 5 */
6
7#ifndef _ZEBRA_OSPF_LSA_H
8#define _ZEBRA_OSPF_LSA_H
9
4dadc291 10#include "stream.h"
11
236e900c
QY
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
718e3744 18/* OSPF LSA Range definition. */
19#define OSPF_MIN_LSA 1 /* begin range here */
718e3744 20#define OSPF_MAX_LSA 12
718e3744 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
779adb01 36#define OSPF_LSA_HEADER_SIZE 20U
37#define OSPF_ROUTER_LSA_LINK_SIZE 12U
05b7709d 38#define OSPF_ROUTER_LSA_TOS_SIZE 4U
779adb01 39#define OSPF_MAX_LSA_SIZE 1500U
718e3744 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. */
d62a17ae 46struct lsa_header {
d7c0a89a 47 uint16_t ls_age;
ee09fbc0 48#define DO_NOT_AGE 0x8000
d7c0a89a
QY
49 uint8_t options;
50 uint8_t type;
d62a17ae 51 struct in_addr id;
52 struct in_addr adv_router;
d7c0a89a
QY
53 uint32_t ls_seqnum;
54 uint16_t checksum;
55 uint16_t length;
718e3744 56};
57
c971918a
DL
58struct vertex;
59
718e3744 60/* OSPF LSA. */
d62a17ae 61struct ospf_lsa {
62 /* LSA origination flag. */
405e1c84
DA
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
718e3744 72
8db278b5 73 /* LSA data. and size */
d62a17ae 74 struct lsa_header *data;
8db278b5 75 size_t size;
718e3744 76
d62a17ae 77 /* Received time stamp. */
78 struct timeval tv_recv;
718e3744 79
d62a17ae 80 /* Last time it was originated */
81 struct timeval tv_orig;
718e3744 82
d62a17ae 83 /* All of reference count, also lock to remove. */
84 int lock;
718e3744 85
d62a17ae 86 /* Flags for the SPF calculation. */
c971918a 87 struct vertex *stat;
718e3744 88
d62a17ae 89 /* References to this LSA in neighbor retransmission lists*/
90 int retransmit_counter;
718e3744 91
d62a17ae 92 /* Area the LSA belongs to, may be NULL if AS-external-LSA. */
93 struct ospf_area *area;
718e3744 94
d62a17ae 95 /* Parent LSDB. */
96 struct ospf_lsdb *lsdb;
718e3744 97
d62a17ae 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;
b5a8894d
CS
106
107 /* VRF Id */
108 vrf_id_t vrf_id;
ad686992 109
110 /*For topo chg detection in HELPER role*/
111 bool to_be_acknowledged;
2f30cb25
LB
112
113 /* send maxage with no data */
114 bool opaque_zero_len_delete;
718e3744 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 */
0c9491b3 127#define ROUTER_LSA_NT 0x10 /* The routers always translates Type-7 */
718e3744 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)
0c9491b3 134#define IS_ROUTER_LSA_NT(x) ((x)->flags & ROUTER_LSA_NT)
718e3744 135
136/* OSPF Router-LSA Link information. */
d62a17ae 137struct router_lsa_link {
138 struct in_addr link_id;
139 struct in_addr link_data;
140 struct {
d7c0a89a
QY
141 uint8_t type;
142 uint8_t tos_count;
143 uint16_t metric;
d62a17ae 144 } m[1];
718e3744 145};
146
147/* OSPF Router-LSAs structure. */
a25a44db
DO
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. */
d62a17ae 156struct router_lsa {
157 struct lsa_header header;
d7c0a89a
QY
158 uint8_t flags;
159 uint8_t zero;
160 uint16_t links;
8db278b5 161 struct router_link {
d62a17ae 162 struct in_addr link_id;
163 struct in_addr link_data;
d7c0a89a
QY
164 uint8_t type;
165 uint8_t tos;
166 uint16_t metric;
d62a17ae 167 } link[1];
718e3744 168};
169
170/* OSPF Network-LSAs structure. */
4e31de79 171#define OSPF_NETWORK_LSA_MIN_SIZE 8U /* w/1 router-ID */
d62a17ae 172struct network_lsa {
173 struct lsa_header header;
174 struct in_addr mask;
175 struct in_addr routers[1];
718e3744 176};
177
178/* OSPF Summary-LSAs structure. */
4e31de79 179#define OSPF_SUMMARY_LSA_MIN_SIZE 8U /* w/1 TOS metric block */
d62a17ae 180struct summary_lsa {
181 struct lsa_header header;
182 struct in_addr mask;
d7c0a89a
QY
183 uint8_t tos;
184 uint8_t metric[3];
718e3744 185};
186
187/* OSPF AS-external-LSAs structure. */
4e31de79 188#define OSPF_AS_EXTERNAL_LSA_MIN_SIZE 16U /* w/1 TOS forwarding block */
d62a17ae 189struct as_external_lsa {
190 struct lsa_header header;
191 struct in_addr mask;
8db278b5 192 struct as_route {
d7c0a89a
QY
193 uint8_t tos;
194 uint8_t metric[3];
d62a17ae 195 struct in_addr fwd_addr;
d7c0a89a 196 uint32_t route_tag;
d62a17ae 197 } e[1];
718e3744 198};
199
a8c22275 200enum lsid_status { LSID_AVAILABLE = 0, LSID_CHANGE, LSID_NOT_AVAILABLE };
201
718e3744 202#include "ospfd/ospf_opaque.h"
718e3744 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)
d62a17ae 209#define LS_AGE(x) (OSPF_LSA_MAXAGE < get_age(x) ? OSPF_LSA_MAXAGE : get_age(x))
718e3744 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)
44d1115a
MR
212#define IS_LSA_MAX_SEQ(L) \
213 ((L)->data->ls_seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER))
718e3744 214
718e3744 215#define OSPF_LSA_UPDATE_DELAY 2
216
df074ec3 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
ee09fbc0
MN
222#define OSPF_FR_CONFIG(o, a) \
223 (o->fr_configured || ((a != NULL) ? a->fr_info.configured : 0))
224
718e3744 225/* Prototypes. */
4dadc291 226/* XXX: Eek, time functions, similar are in lib/thread.c */
d62a17ae 227extern struct timeval int2tv(int);
228extern struct timeval msec2tv(int);
4dadc291 229
d62a17ae 230extern int get_age(struct ospf_lsa *);
d7c0a89a 231extern uint16_t ospf_lsa_checksum(struct lsa_header *);
d62a17ae 232extern int ospf_lsa_checksum_valid(struct lsa_header *);
233extern int ospf_lsa_refresh_delay(struct ospf_lsa *);
4dadc291 234
d62a17ae 235extern const char *dump_lsa_key(struct ospf_lsa *);
d7c0a89a
QY
236extern uint32_t lsa_seqnum_increment(struct ospf_lsa *);
237extern void lsa_header_set(struct stream *, uint8_t, uint8_t, struct in_addr,
d62a17ae 238 struct in_addr);
239extern struct ospf_neighbor *ospf_nbr_lookup_ptop(struct ospf_interface *);
240extern int ospf_check_nbr_status(struct ospf *);
718e3744 241
242/* Prototype for LSA primitive. */
d62a17ae 243extern struct ospf_lsa *ospf_lsa_new(void);
5b3d4186 244extern struct ospf_lsa *ospf_lsa_new_and_data(size_t size);
d62a17ae 245extern struct ospf_lsa *ospf_lsa_dup(struct ospf_lsa *);
246extern void ospf_lsa_free(struct ospf_lsa *);
247extern struct ospf_lsa *ospf_lsa_lock(struct ospf_lsa *);
248extern void ospf_lsa_unlock(struct ospf_lsa **);
249extern void ospf_lsa_discard(struct ospf_lsa *);
250extern int ospf_lsa_flush_schedule(struct ospf *, struct ospf_lsa *);
251extern struct lsa_header *ospf_lsa_data_new(size_t);
252extern struct lsa_header *ospf_lsa_data_dup(struct lsa_header *);
253extern void ospf_lsa_data_free(struct lsa_header *);
718e3744 254
255/* Prototype for various LSAs */
7fd0729f
G
256extern void ospf_router_lsa_body_set(struct stream **s, struct ospf_area *area);
257extern uint8_t router_lsa_flags(struct ospf_area *area);
d62a17ae 258extern int ospf_router_lsa_update(struct ospf *);
259extern int ospf_router_lsa_update_area(struct ospf_area *);
260
261extern void ospf_network_lsa_update(struct ospf_interface *);
262
263extern struct ospf_lsa *
d7c0a89a 264ospf_summary_lsa_originate(struct prefix_ipv4 *, uint32_t, struct ospf_area *);
d62a17ae 265extern struct ospf_lsa *ospf_summary_asbr_lsa_originate(struct prefix_ipv4 *,
d7c0a89a 266 uint32_t,
d62a17ae 267 struct ospf_area *);
268
269extern struct ospf_lsa *ospf_lsa_install(struct ospf *, struct ospf_interface *,
270 struct ospf_lsa *);
271
272extern void ospf_nssa_lsa_flush(struct ospf *ospf, struct prefix_ipv4 *p);
d7c0a89a
QY
273extern void ospf_external_lsa_flush(struct ospf *, uint8_t,
274 struct prefix_ipv4 *,
d62a17ae 275 ifindex_t /* , struct in_addr nexthop */);
276
277extern struct in_addr ospf_get_ip_from_ifp(struct ospf_interface *);
278
279extern struct ospf_lsa *ospf_external_lsa_originate(struct ospf *,
280 struct external_info *);
fa3c7c7e 281extern void ospf_external_lsa_rid_change(struct ospf *ospf);
b5a8894d 282extern struct ospf_lsa *ospf_lsa_lookup(struct ospf *ospf, struct ospf_area *,
d7c0a89a 283 uint32_t, struct in_addr,
b5a8894d 284 struct in_addr);
d7c0a89a 285extern struct ospf_lsa *ospf_lsa_lookup_by_id(struct ospf_area *, uint32_t,
d62a17ae 286 struct in_addr);
287extern struct ospf_lsa *ospf_lsa_lookup_by_header(struct ospf_area *,
288 struct lsa_header *);
289extern int ospf_lsa_more_recent(struct ospf_lsa *, struct ospf_lsa *);
1bb2674c
RW
290extern int ospf_lsa_different(struct ospf_lsa *, struct ospf_lsa *,
291 bool ignore_rcvd_flag);
d62a17ae 292extern void ospf_flush_self_originated_lsas_now(struct ospf *);
293
294extern int ospf_lsa_is_self_originated(struct ospf *, struct ospf_lsa *);
295
d7c0a89a 296extern struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *, uint8_t,
d62a17ae 297 struct prefix_ipv4 *,
298 struct in_addr);
299
300extern void ospf_lsa_maxage(struct ospf *, struct ospf_lsa *);
d7c0a89a 301extern uint32_t get_metric(uint8_t *);
d62a17ae 302
e6685141 303extern void ospf_lsa_maxage_walker(struct event *thread);
d62a17ae 304extern struct ospf_lsa *ospf_lsa_refresh(struct ospf *, struct ospf_lsa *);
305
306extern void ospf_external_lsa_refresh_default(struct ospf *);
307
d7c0a89a
QY
308extern void ospf_external_lsa_refresh_type(struct ospf *, uint8_t,
309 unsigned short, int);
d62a17ae 310extern struct ospf_lsa *ospf_external_lsa_refresh(struct ospf *,
311 struct ospf_lsa *,
63f0e941 312 struct external_info *, int,
313 bool aggr);
a8c22275 314extern 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);
d62a17ae 318extern void ospf_schedule_lsa_flood_area(struct ospf_area *, struct ospf_lsa *);
319extern void ospf_schedule_lsa_flush_area(struct ospf_area *, struct ospf_lsa *);
320
321extern void ospf_refresher_register_lsa(struct ospf *, struct ospf_lsa *);
322extern void ospf_refresher_unregister_lsa(struct ospf *, struct ospf_lsa *);
e6685141 323extern void ospf_lsa_refresh_walker(struct event *thread);
d62a17ae 324
325extern void ospf_lsa_maxage_delete(struct ospf *, struct ospf_lsa *);
326
327extern void ospf_discard_from_db(struct ospf *, struct ospf_lsdb *,
328 struct ospf_lsa *);
d62a17ae 329
d7c0a89a
QY
330extern int metric_type(struct ospf *, uint8_t, unsigned short);
331extern int metric_value(struct ospf *, uint8_t, unsigned short);
d62a17ae 332
7fd0729f
G
333extern char link_info_set(struct stream **s, struct in_addr id,
334 struct in_addr data, uint8_t type, uint8_t tos,
335 uint16_t cost);
336
d62a17ae 337extern struct in_addr ospf_get_nssa_ip(struct ospf_area *);
338extern int ospf_translated_nssa_compare(struct ospf_lsa *, struct ospf_lsa *);
c317eddb 339extern struct ospf_lsa *ospf_translated_nssa_refresh(struct ospf *ospf,
340 struct ospf_lsa *type7,
341 struct ospf_lsa *type5);
342extern struct ospf_lsa *ospf_translated_nssa_originate(struct ospf *ospf,
343 struct ospf_lsa *type7,
344 struct ospf_lsa *type5);
3cb62bb3
MR
345extern void ospf_check_and_gen_init_seq_lsa(struct ospf_interface *oi,
346 struct ospf_lsa *lsa);
44445dee
S
347extern void ospf_flush_lsa_from_area(struct ospf *ospf, struct in_addr area_id,
348 int type);
e6685141 349extern void ospf_maxage_lsa_remover(struct event *thread);
ee09fbc0
MN
350extern bool ospf_check_dna_lsa(const struct ospf_lsa *lsa);
351extern void ospf_refresh_area_self_lsas(struct ospf_area *area);
352
353/** @brief Check if the LSA is an indication LSA.
354 * @param lsa pointer.
355 * @return true or false based on lsa info.
356 */
357static inline bool ospf_check_indication_lsa(struct ospf_lsa *lsa)
358{
359 struct summary_lsa *sl = NULL;
360
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))
365 return true;
366 }
367
368 return false;
369}
718e3744 370#endif /* _ZEBRA_OSPF_LSA_H */