]>
git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_lsa.h
2 * OSPF Link State Advertisement
3 * Copyright (C) 1999, 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
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
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.
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
22 #ifndef _ZEBRA_OSPF_LSA_H
23 #define _ZEBRA_OSPF_LSA_H
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
33 /* OSPF LSA Range definition. */
34 #define OSPF_MIN_LSA 1 /* begin range here */
35 #define OSPF_MAX_LSA 12
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
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
56 /* AS-external-LSA refresh method. */
57 #define LSA_REFRESH_IF_CHANGED 0
58 #define LSA_REFRESH_FORCE 1
60 /* OSPF LSA header. */
66 struct in_addr adv_router
;
76 /* LSA origination flag. */
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
88 /* LSA data. and size */
89 struct lsa_header
*data
;
92 /* Received time stamp. */
93 struct timeval tv_recv
;
95 /* Last time it was originated */
96 struct timeval tv_orig
;
98 /* All of reference count, also lock to remove. */
101 /* Flags for the SPF calculation. */
104 /* References to this LSA in neighbor retransmission lists*/
105 int retransmit_counter
;
107 /* Area the LSA belongs to, may be NULL if AS-external-LSA. */
108 struct ospf_area
*area
;
111 struct ospf_lsdb
*lsdb
;
116 /* Refreshement List or Queue */
119 /* For Type-9 Opaque-LSAs */
120 struct ospf_interface
*oi
;
125 /*For topo chg detection in HELPER role*/
126 bool to_be_acknowledged
;
128 /* send maxage with no data */
129 bool opaque_zero_len_delete
;
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
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 */
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)
151 /* OSPF Router-LSA Link information. */
152 struct router_lsa_link
{
153 struct in_addr link_id
;
154 struct in_addr link_data
;
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. */
172 struct lsa_header header
;
177 struct in_addr link_id
;
178 struct in_addr link_data
;
185 /* OSPF Network-LSAs structure. */
186 #define OSPF_NETWORK_LSA_MIN_SIZE 8U /* w/1 router-ID */
188 struct lsa_header header
;
190 struct in_addr routers
[1];
193 /* OSPF Summary-LSAs structure. */
194 #define OSPF_SUMMARY_LSA_MIN_SIZE 8U /* w/1 TOS metric block */
196 struct lsa_header header
;
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
;
210 struct in_addr fwd_addr
;
215 enum lsid_status
{ LSID_AVAILABLE
= 0, LSID_CHANGE
, LSID_NOT_AVAILABLE
};
217 #include "ospfd/ospf_opaque.h"
220 #define GET_METRIC(x) get_metric(x)
221 #define IS_EXTERNAL_METRIC(x) ((x) & 0x80)
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))
231 #define OSPF_LSA_UPDATE_DELAY 2
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))
239 /* XXX: Eek, time functions, similar are in lib/thread.c */
240 extern struct timeval
int2tv(int);
241 extern struct timeval
msec2tv(int);
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
*);
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
,
252 extern struct ospf_neighbor
*ospf_nbr_lookup_ptop(struct ospf_interface
*);
253 extern int ospf_check_nbr_status(struct ospf
*);
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
*);
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
*);
274 extern void ospf_network_lsa_update(struct ospf_interface
*);
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
*,
282 extern struct ospf_lsa
*ospf_lsa_install(struct ospf
*, struct ospf_interface
*,
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 */);
290 extern struct in_addr
ospf_get_ip_from_ifp(struct ospf_interface
*);
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
,
298 extern struct ospf_lsa
*ospf_lsa_lookup_by_id(struct ospf_area
*, uint32_t,
300 extern struct ospf_lsa
*ospf_lsa_lookup_by_adv_rid(struct ospf_area
*area
,
303 extern struct ospf_lsa
*ospf_lsa_lookup_by_mpls_te_rid(struct ospf_area
*area
,
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
*);
313 extern int ospf_lsa_is_self_originated(struct ospf
*, struct ospf_lsa
*);
315 extern struct ospf_lsa
*ospf_lsa_lookup_by_prefix(struct ospf_lsdb
*, uint8_t,
316 struct prefix_ipv4
*,
319 extern void ospf_lsa_maxage(struct ospf
*, struct ospf_lsa
*);
320 extern uint32_t get_metric(uint8_t *);
322 extern void ospf_lsa_maxage_walker(struct thread
*thread
);
323 extern struct ospf_lsa
*ospf_lsa_refresh(struct ospf
*, struct ospf_lsa
*);
325 extern void ospf_external_lsa_refresh_default(struct ospf
*);
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
*,
331 struct external_info
*, int,
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
*);
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
);
344 extern void ospf_lsa_maxage_delete(struct ospf
*, struct ospf_lsa
*);
346 extern void ospf_discard_from_db(struct ospf
*, struct ospf_lsdb
*,
349 extern int metric_type(struct ospf
*, uint8_t, unsigned short);
350 extern int metric_value(struct ospf
*, uint8_t, unsigned short);
352 extern char link_info_set(struct stream
**s
, struct in_addr id
,
353 struct in_addr data
, uint8_t type
, uint8_t tos
,
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
,
368 extern void ospf_maxage_lsa_remover(struct thread
*thread
);
369 #endif /* _ZEBRA_OSPF_LSA_H */