]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_lsa.h
Merge pull request #12830 from anlancs/fix/doc-ripd-rst
[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
QY
47 uint16_t ls_age;
48 uint8_t options;
49 uint8_t type;
d62a17ae 50 struct in_addr id;
51 struct in_addr adv_router;
d7c0a89a
QY
52 uint32_t ls_seqnum;
53 uint16_t checksum;
54 uint16_t length;
718e3744 55};
56
c971918a
DL
57struct vertex;
58
718e3744 59/* OSPF LSA. */
d62a17ae 60struct ospf_lsa {
61 /* LSA origination flag. */
405e1c84
DA
62 uint8_t flags;
63#define OSPF_LSA_SELF 0x01
64#define OSPF_LSA_SELF_CHECKED 0x02
65#define OSPF_LSA_RECEIVED 0x04
66#define OSPF_LSA_APPROVED 0x08
67#define OSPF_LSA_DISCARD 0x10
68#define OSPF_LSA_LOCAL_XLT 0x20
69#define OSPF_LSA_PREMATURE_AGE 0x40
70#define OSPF_LSA_IN_MAXAGE 0x80
718e3744 71
8db278b5 72 /* LSA data. and size */
d62a17ae 73 struct lsa_header *data;
8db278b5 74 size_t size;
718e3744 75
d62a17ae 76 /* Received time stamp. */
77 struct timeval tv_recv;
718e3744 78
d62a17ae 79 /* Last time it was originated */
80 struct timeval tv_orig;
718e3744 81
d62a17ae 82 /* All of reference count, also lock to remove. */
83 int lock;
718e3744 84
d62a17ae 85 /* Flags for the SPF calculation. */
c971918a 86 struct vertex *stat;
718e3744 87
d62a17ae 88 /* References to this LSA in neighbor retransmission lists*/
89 int retransmit_counter;
718e3744 90
d62a17ae 91 /* Area the LSA belongs to, may be NULL if AS-external-LSA. */
92 struct ospf_area *area;
718e3744 93
d62a17ae 94 /* Parent LSDB. */
95 struct ospf_lsdb *lsdb;
718e3744 96
d62a17ae 97 /* Related Route. */
98 void *route;
99
100 /* Refreshement List or Queue */
101 int refresh_list;
102
103 /* For Type-9 Opaque-LSAs */
104 struct ospf_interface *oi;
b5a8894d
CS
105
106 /* VRF Id */
107 vrf_id_t vrf_id;
ad686992 108
109 /*For topo chg detection in HELPER role*/
110 bool to_be_acknowledged;
2f30cb25
LB
111
112 /* send maxage with no data */
113 bool opaque_zero_len_delete;
718e3744 114};
115
116/* OSPF LSA Link Type. */
117#define LSA_LINK_TYPE_POINTOPOINT 1
118#define LSA_LINK_TYPE_TRANSIT 2
119#define LSA_LINK_TYPE_STUB 3
120#define LSA_LINK_TYPE_VIRTUALLINK 4
121
122/* OSPF Router LSA Flag. */
123#define ROUTER_LSA_BORDER 0x01 /* The router is an ABR */
124#define ROUTER_LSA_EXTERNAL 0x02 /* The router is an ASBR */
125#define ROUTER_LSA_VIRTUAL 0x04 /* The router has a VL in this area */
0c9491b3 126#define ROUTER_LSA_NT 0x10 /* The routers always translates Type-7 */
718e3744 127#define ROUTER_LSA_SHORTCUT 0x20 /* Shortcut-ABR specific flag */
128
129#define IS_ROUTER_LSA_VIRTUAL(x) ((x)->flags & ROUTER_LSA_VIRTUAL)
130#define IS_ROUTER_LSA_EXTERNAL(x) ((x)->flags & ROUTER_LSA_EXTERNAL)
131#define IS_ROUTER_LSA_BORDER(x) ((x)->flags & ROUTER_LSA_BORDER)
132#define IS_ROUTER_LSA_SHORTCUT(x) ((x)->flags & ROUTER_LSA_SHORTCUT)
0c9491b3 133#define IS_ROUTER_LSA_NT(x) ((x)->flags & ROUTER_LSA_NT)
718e3744 134
135/* OSPF Router-LSA Link information. */
d62a17ae 136struct router_lsa_link {
137 struct in_addr link_id;
138 struct in_addr link_data;
139 struct {
d7c0a89a
QY
140 uint8_t type;
141 uint8_t tos_count;
142 uint16_t metric;
d62a17ae 143 } m[1];
718e3744 144};
145
146/* OSPF Router-LSAs structure. */
a25a44db
DO
147#define OSPF_ROUTER_LSA_MIN_SIZE 4U /* w/0 link descriptors */
148/* There is an edge case, when number of links in a Router-LSA may be 0 without
149 breaking the specification. A router, which has no other links to backbone
150 area besides one virtual link, will not put any VL descriptor blocks into
151 the Router-LSA generated for area 0 until a full adjacency over the VL is
152 reached (RFC2328 12.4.1.3). In this case the Router-LSA initially received
153 by the other end of the VL will have 0 link descriptor blocks, but soon will
154 be replaced with the next revision having 1 descriptor block. */
d62a17ae 155struct router_lsa {
156 struct lsa_header header;
d7c0a89a
QY
157 uint8_t flags;
158 uint8_t zero;
159 uint16_t links;
8db278b5 160 struct router_link {
d62a17ae 161 struct in_addr link_id;
162 struct in_addr link_data;
d7c0a89a
QY
163 uint8_t type;
164 uint8_t tos;
165 uint16_t metric;
d62a17ae 166 } link[1];
718e3744 167};
168
169/* OSPF Network-LSAs structure. */
4e31de79 170#define OSPF_NETWORK_LSA_MIN_SIZE 8U /* w/1 router-ID */
d62a17ae 171struct network_lsa {
172 struct lsa_header header;
173 struct in_addr mask;
174 struct in_addr routers[1];
718e3744 175};
176
177/* OSPF Summary-LSAs structure. */
4e31de79 178#define OSPF_SUMMARY_LSA_MIN_SIZE 8U /* w/1 TOS metric block */
d62a17ae 179struct summary_lsa {
180 struct lsa_header header;
181 struct in_addr mask;
d7c0a89a
QY
182 uint8_t tos;
183 uint8_t metric[3];
718e3744 184};
185
186/* OSPF AS-external-LSAs structure. */
4e31de79 187#define OSPF_AS_EXTERNAL_LSA_MIN_SIZE 16U /* w/1 TOS forwarding block */
d62a17ae 188struct as_external_lsa {
189 struct lsa_header header;
190 struct in_addr mask;
8db278b5 191 struct as_route {
d7c0a89a
QY
192 uint8_t tos;
193 uint8_t metric[3];
d62a17ae 194 struct in_addr fwd_addr;
d7c0a89a 195 uint32_t route_tag;
d62a17ae 196 } e[1];
718e3744 197};
198
a8c22275 199enum lsid_status { LSID_AVAILABLE = 0, LSID_CHANGE, LSID_NOT_AVAILABLE };
200
718e3744 201#include "ospfd/ospf_opaque.h"
718e3744 202
203/* Macros. */
204#define GET_METRIC(x) get_metric(x)
205#define IS_EXTERNAL_METRIC(x) ((x) & 0x80)
206
207#define GET_AGE(x) (ntohs ((x)->data->ls_age) + time (NULL) - (x)->tv_recv)
d62a17ae 208#define LS_AGE(x) (OSPF_LSA_MAXAGE < get_age(x) ? OSPF_LSA_MAXAGE : get_age(x))
718e3744 209#define IS_LSA_SELF(L) (CHECK_FLAG ((L)->flags, OSPF_LSA_SELF))
210#define IS_LSA_MAXAGE(L) (LS_AGE ((L)) == OSPF_LSA_MAXAGE)
44d1115a
MR
211#define IS_LSA_MAX_SEQ(L) \
212 ((L)->data->ls_seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER))
718e3744 213
718e3744 214#define OSPF_LSA_UPDATE_DELAY 2
215
df074ec3 216#define CHECK_LSA_TYPE_1_TO_5_OR_7(type) \
217 ((type == OSPF_ROUTER_LSA) || (type == OSPF_NETWORK_LSA) \
218 || (type == OSPF_SUMMARY_LSA) || (type == OSPF_ASBR_SUMMARY_LSA) \
219 || (type == OSPF_AS_EXTERNAL_LSA) || (type == OSPF_AS_NSSA_LSA))
220
718e3744 221/* Prototypes. */
4dadc291 222/* XXX: Eek, time functions, similar are in lib/thread.c */
d62a17ae 223extern struct timeval int2tv(int);
224extern struct timeval msec2tv(int);
4dadc291 225
d62a17ae 226extern int get_age(struct ospf_lsa *);
d7c0a89a 227extern uint16_t ospf_lsa_checksum(struct lsa_header *);
d62a17ae 228extern int ospf_lsa_checksum_valid(struct lsa_header *);
229extern int ospf_lsa_refresh_delay(struct ospf_lsa *);
4dadc291 230
d62a17ae 231extern const char *dump_lsa_key(struct ospf_lsa *);
d7c0a89a
QY
232extern uint32_t lsa_seqnum_increment(struct ospf_lsa *);
233extern void lsa_header_set(struct stream *, uint8_t, uint8_t, struct in_addr,
d62a17ae 234 struct in_addr);
235extern struct ospf_neighbor *ospf_nbr_lookup_ptop(struct ospf_interface *);
236extern int ospf_check_nbr_status(struct ospf *);
718e3744 237
238/* Prototype for LSA primitive. */
d62a17ae 239extern struct ospf_lsa *ospf_lsa_new(void);
5b3d4186 240extern struct ospf_lsa *ospf_lsa_new_and_data(size_t size);
d62a17ae 241extern struct ospf_lsa *ospf_lsa_dup(struct ospf_lsa *);
242extern void ospf_lsa_free(struct ospf_lsa *);
243extern struct ospf_lsa *ospf_lsa_lock(struct ospf_lsa *);
244extern void ospf_lsa_unlock(struct ospf_lsa **);
245extern void ospf_lsa_discard(struct ospf_lsa *);
246extern int ospf_lsa_flush_schedule(struct ospf *, struct ospf_lsa *);
247extern struct lsa_header *ospf_lsa_data_new(size_t);
248extern struct lsa_header *ospf_lsa_data_dup(struct lsa_header *);
249extern void ospf_lsa_data_free(struct lsa_header *);
718e3744 250
251/* Prototype for various LSAs */
7fd0729f
G
252extern void ospf_router_lsa_body_set(struct stream **s, struct ospf_area *area);
253extern uint8_t router_lsa_flags(struct ospf_area *area);
d62a17ae 254extern int ospf_router_lsa_update(struct ospf *);
255extern int ospf_router_lsa_update_area(struct ospf_area *);
256
257extern void ospf_network_lsa_update(struct ospf_interface *);
258
259extern struct ospf_lsa *
d7c0a89a 260ospf_summary_lsa_originate(struct prefix_ipv4 *, uint32_t, struct ospf_area *);
d62a17ae 261extern struct ospf_lsa *ospf_summary_asbr_lsa_originate(struct prefix_ipv4 *,
d7c0a89a 262 uint32_t,
d62a17ae 263 struct ospf_area *);
264
265extern struct ospf_lsa *ospf_lsa_install(struct ospf *, struct ospf_interface *,
266 struct ospf_lsa *);
267
268extern void ospf_nssa_lsa_flush(struct ospf *ospf, struct prefix_ipv4 *p);
d7c0a89a
QY
269extern void ospf_external_lsa_flush(struct ospf *, uint8_t,
270 struct prefix_ipv4 *,
d62a17ae 271 ifindex_t /* , struct in_addr nexthop */);
272
273extern struct in_addr ospf_get_ip_from_ifp(struct ospf_interface *);
274
275extern struct ospf_lsa *ospf_external_lsa_originate(struct ospf *,
276 struct external_info *);
fa3c7c7e 277extern void ospf_external_lsa_rid_change(struct ospf *ospf);
b5a8894d 278extern struct ospf_lsa *ospf_lsa_lookup(struct ospf *ospf, struct ospf_area *,
d7c0a89a 279 uint32_t, struct in_addr,
b5a8894d 280 struct in_addr);
d7c0a89a 281extern struct ospf_lsa *ospf_lsa_lookup_by_id(struct ospf_area *, uint32_t,
d62a17ae 282 struct in_addr);
283extern struct ospf_lsa *ospf_lsa_lookup_by_header(struct ospf_area *,
284 struct lsa_header *);
285extern int ospf_lsa_more_recent(struct ospf_lsa *, struct ospf_lsa *);
1bb2674c
RW
286extern int ospf_lsa_different(struct ospf_lsa *, struct ospf_lsa *,
287 bool ignore_rcvd_flag);
d62a17ae 288extern void ospf_flush_self_originated_lsas_now(struct ospf *);
289
290extern int ospf_lsa_is_self_originated(struct ospf *, struct ospf_lsa *);
291
d7c0a89a 292extern struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *, uint8_t,
d62a17ae 293 struct prefix_ipv4 *,
294 struct in_addr);
295
296extern void ospf_lsa_maxage(struct ospf *, struct ospf_lsa *);
d7c0a89a 297extern uint32_t get_metric(uint8_t *);
d62a17ae 298
cc9f21da 299extern void ospf_lsa_maxage_walker(struct thread *thread);
d62a17ae 300extern struct ospf_lsa *ospf_lsa_refresh(struct ospf *, struct ospf_lsa *);
301
302extern void ospf_external_lsa_refresh_default(struct ospf *);
303
d7c0a89a
QY
304extern void ospf_external_lsa_refresh_type(struct ospf *, uint8_t,
305 unsigned short, int);
d62a17ae 306extern struct ospf_lsa *ospf_external_lsa_refresh(struct ospf *,
307 struct ospf_lsa *,
63f0e941 308 struct external_info *, int,
309 bool aggr);
a8c22275 310extern enum lsid_status ospf_lsa_unique_id(struct ospf *ospf,
311 struct ospf_lsdb *lsdb,
312 uint8_t type, struct prefix_ipv4 *p,
313 struct in_addr *addr);
d62a17ae 314extern void ospf_schedule_lsa_flood_area(struct ospf_area *, struct ospf_lsa *);
315extern void ospf_schedule_lsa_flush_area(struct ospf_area *, struct ospf_lsa *);
316
317extern void ospf_refresher_register_lsa(struct ospf *, struct ospf_lsa *);
318extern void ospf_refresher_unregister_lsa(struct ospf *, struct ospf_lsa *);
cc9f21da 319extern void ospf_lsa_refresh_walker(struct thread *thread);
d62a17ae 320
321extern void ospf_lsa_maxage_delete(struct ospf *, struct ospf_lsa *);
322
323extern void ospf_discard_from_db(struct ospf *, struct ospf_lsdb *,
324 struct ospf_lsa *);
d62a17ae 325
d7c0a89a
QY
326extern int metric_type(struct ospf *, uint8_t, unsigned short);
327extern int metric_value(struct ospf *, uint8_t, unsigned short);
d62a17ae 328
7fd0729f
G
329extern char link_info_set(struct stream **s, struct in_addr id,
330 struct in_addr data, uint8_t type, uint8_t tos,
331 uint16_t cost);
332
d62a17ae 333extern struct in_addr ospf_get_nssa_ip(struct ospf_area *);
334extern int ospf_translated_nssa_compare(struct ospf_lsa *, struct ospf_lsa *);
c317eddb 335extern struct ospf_lsa *ospf_translated_nssa_refresh(struct ospf *ospf,
336 struct ospf_lsa *type7,
337 struct ospf_lsa *type5);
338extern struct ospf_lsa *ospf_translated_nssa_originate(struct ospf *ospf,
339 struct ospf_lsa *type7,
340 struct ospf_lsa *type5);
3cb62bb3
MR
341extern void ospf_check_and_gen_init_seq_lsa(struct ospf_interface *oi,
342 struct ospf_lsa *lsa);
44445dee
S
343extern void ospf_flush_lsa_from_area(struct ospf *ospf, struct in_addr area_id,
344 int type);
b345a3d9 345extern void ospf_maxage_lsa_remover(struct thread *thread);
718e3744 346#endif /* _ZEBRA_OSPF_LSA_H */