blob: 952ca7746f8a04ce1ea32fda9d6431fe3c7db19a [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#ifndef _ZEBRA_OSPF_LSA_H
24#define _ZEBRA_OSPF_LSA_H
25
26/* OSPF LSA Range definition. */
27#define OSPF_MIN_LSA 1 /* begin range here */
28#if defined (HAVE_OPAQUE_LSA)
29#define OSPF_MAX_LSA 12
paul718e3742002-12-13 20:15:29 +000030#else
hassobeebba72004-06-20 21:00:27 +000031#define OSPF_MAX_LSA 8
paul718e3742002-12-13 20:15:29 +000032#endif
33
34/* OSPF LSA Type definition. */
35#define OSPF_UNKNOWN_LSA 0
36#define OSPF_ROUTER_LSA 1
37#define OSPF_NETWORK_LSA 2
38#define OSPF_SUMMARY_LSA 3
39#define OSPF_ASBR_SUMMARY_LSA 4
40#define OSPF_AS_EXTERNAL_LSA 5
41#define OSPF_GROUP_MEMBER_LSA 6 /* Not supported. */
42#define OSPF_AS_NSSA_LSA 7
43#define OSPF_EXTERNAL_ATTRIBUTES_LSA 8 /* Not supported. */
44#define OSPF_OPAQUE_LINK_LSA 9
45#define OSPF_OPAQUE_AREA_LSA 10
46#define OSPF_OPAQUE_AS_LSA 11
47
paul6c835672004-10-11 11:00:30 +000048#define OSPF_LSA_HEADER_SIZE 20U
49#define OSPF_MAX_LSA_SIZE 1500U
paul718e3742002-12-13 20:15:29 +000050
51/* AS-external-LSA refresh method. */
52#define LSA_REFRESH_IF_CHANGED 0
53#define LSA_REFRESH_FORCE 1
54
55/* OSPF LSA header. */
56struct lsa_header
57{
58 u_int16_t ls_age;
59 u_char options;
60 u_char type;
61 struct in_addr id;
62 struct in_addr adv_router;
paul6c835672004-10-11 11:00:30 +000063 u_int32_t ls_seqnum;
paul718e3742002-12-13 20:15:29 +000064 u_int16_t checksum;
65 u_int16_t length;
66};
67
68/* OSPF LSA. */
69struct ospf_lsa
70{
71 /* LSA origination flag. */
72 u_char flags;
73#define OSPF_LSA_SELF 0x01
74#define OSPF_LSA_SELF_CHECKED 0x02
75#define OSPF_LSA_RECEIVED 0x04
76#define OSPF_LSA_APPROVED 0x08
77#define OSPF_LSA_DISCARD 0x10
paul718e3742002-12-13 20:15:29 +000078#define OSPF_LSA_LOCAL_XLT 0x20
paul7ddf1d62003-10-13 09:06:46 +000079#define OSPF_LSA_PREMATURE_AGE 0x40
paul718e3742002-12-13 20:15:29 +000080
81 /* LSA data. */
82 struct lsa_header *data;
83
84 /* Received time stamp. */
85 struct timeval tv_recv;
86
87 /* Last time it was originated */
88 struct timeval tv_orig;
89
90 /* All of reference count, also lock to remove. */
91 int lock;
92
hasso462f20d2005-02-23 11:29:02 +000093 /* Flags for the SPF calculation. */
94 int stat;
95 #define LSA_SPF_NOT_EXPLORED -1
96 #define LSA_SPF_IN_SPFTREE -2
97 /* If stat >= 0, stat is LSA position in candidates heap. */
98
paul718e3742002-12-13 20:15:29 +000099 /* References to this LSA in neighbor retransmission lists*/
100 int retransmit_counter;
101
102 /* Area the LSA belongs to, may be NULL if AS-external-LSA. */
103 struct ospf_area *area;
104
105 /* Parent LSDB. */
106 struct ospf_lsdb *lsdb;
107
108 /* Related Route. */
109 void *route;
110
111 /* Refreshement List or Queue */
112 int refresh_list;
113
114#ifdef HAVE_OPAQUE_LSA
115 /* For Type-9 Opaque-LSAs, reference to ospf-interface is required. */
116 struct ospf_interface *oi;
117#endif /* HAVE_OPAQUE_LSA */
118};
119
120/* OSPF LSA Link Type. */
121#define LSA_LINK_TYPE_POINTOPOINT 1
122#define LSA_LINK_TYPE_TRANSIT 2
123#define LSA_LINK_TYPE_STUB 3
124#define LSA_LINK_TYPE_VIRTUALLINK 4
125
126/* OSPF Router LSA Flag. */
127#define ROUTER_LSA_BORDER 0x01 /* The router is an ABR */
128#define ROUTER_LSA_EXTERNAL 0x02 /* The router is an ASBR */
129#define ROUTER_LSA_VIRTUAL 0x04 /* The router has a VL in this area */
paul0c9491b2003-06-22 08:23:01 +0000130#define ROUTER_LSA_NT 0x10 /* The routers always translates Type-7 */
paul718e3742002-12-13 20:15:29 +0000131#define ROUTER_LSA_SHORTCUT 0x20 /* Shortcut-ABR specific flag */
132
133#define IS_ROUTER_LSA_VIRTUAL(x) ((x)->flags & ROUTER_LSA_VIRTUAL)
134#define IS_ROUTER_LSA_EXTERNAL(x) ((x)->flags & ROUTER_LSA_EXTERNAL)
135#define IS_ROUTER_LSA_BORDER(x) ((x)->flags & ROUTER_LSA_BORDER)
136#define IS_ROUTER_LSA_SHORTCUT(x) ((x)->flags & ROUTER_LSA_SHORTCUT)
paul0c9491b2003-06-22 08:23:01 +0000137#define IS_ROUTER_LSA_NT(x) ((x)->flags & ROUTER_LSA_NT)
paul718e3742002-12-13 20:15:29 +0000138
139/* OSPF Router-LSA Link information. */
140struct router_lsa_link
141{
142 struct in_addr link_id;
143 struct in_addr link_data;
144 struct
145 {
146 u_char type;
147 u_char tos_count;
148 u_int16_t metric;
149 } m[1];
150};
151
152/* OSPF Router-LSAs structure. */
153struct router_lsa
154{
155 struct lsa_header header;
156 u_char flags;
157 u_char zero;
158 u_int16_t links;
159 struct
160 {
161 struct in_addr link_id;
162 struct in_addr link_data;
163 u_char type;
164 u_char tos;
165 u_int16_t metric;
166 } link[1];
167};
168
169/* OSPF Network-LSAs structure. */
170struct network_lsa
171{
172 struct lsa_header header;
173 struct in_addr mask;
174 struct in_addr routers[1];
175};
176
177/* OSPF Summary-LSAs structure. */
178struct summary_lsa
179{
180 struct lsa_header header;
181 struct in_addr mask;
182 u_char tos;
183 u_char metric[3];
184};
185
186/* OSPF AS-external-LSAs structure. */
187struct as_external_lsa
188{
189 struct lsa_header header;
190 struct in_addr mask;
191 struct
192 {
193 u_char tos;
194 u_char metric[3];
195 struct in_addr fwd_addr;
196 u_int32_t route_tag;
197 } e[1];
198};
199
200#ifdef HAVE_OPAQUE_LSA
201#include "ospfd/ospf_opaque.h"
202#endif /* HAVE_OPAQUE_LSA */
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)
209#define LS_AGE(x) (OSPF_LSA_MAXAGE < get_age(x) ? \
210 OSPF_LSA_MAXAGE : get_age(x))
211#define IS_LSA_SELF(L) (CHECK_FLAG ((L)->flags, OSPF_LSA_SELF))
212#define IS_LSA_MAXAGE(L) (LS_AGE ((L)) == OSPF_LSA_MAXAGE)
213
paul718e3742002-12-13 20:15:29 +0000214#define OSPF_LSA_UPDATE_DELAY 2
215
216#define OSPF_LSA_UPDATE_TIMER_ON(T,F) \
217 if (!(T)) \
218 (T) = thread_add_timer (master, (F), 0, 2)
219
220struct ospf_route;
221struct ospf_lsdb;
222
223/* Prototypes. */
224struct timeval tv_adjust (struct timeval);
225int tv_ceil (struct timeval);
226int tv_floor (struct timeval);
227struct timeval int2tv (int);
228struct timeval tv_add (struct timeval, struct timeval);
229struct timeval tv_sub (struct timeval, struct timeval);
230int tv_cmp (struct timeval, struct timeval);
231
232int get_age (struct ospf_lsa *);
233u_int16_t ospf_lsa_checksum (struct lsa_header *);
234
235struct stream;
paul68980082003-03-25 05:07:42 +0000236const char *dump_lsa_key (struct ospf_lsa *);
237u_int32_t lsa_seqnum_increment (struct ospf_lsa *);
238void lsa_header_set (struct stream *, u_char, u_char, struct in_addr,
239 struct in_addr);
240struct ospf_neighbor *ospf_nbr_lookup_ptop (struct ospf_interface *);
paul718e3742002-12-13 20:15:29 +0000241
242/* Prototype for LSA primitive. */
243struct ospf_lsa *ospf_lsa_new ();
244struct ospf_lsa *ospf_lsa_dup ();
paul68980082003-03-25 05:07:42 +0000245void ospf_lsa_free (struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000246struct ospf_lsa *ospf_lsa_lock (struct ospf_lsa *);
247void ospf_lsa_unlock (struct ospf_lsa *);
248void ospf_lsa_discard (struct ospf_lsa *);
249
250struct lsa_header *ospf_lsa_data_new (size_t);
251struct lsa_header *ospf_lsa_data_dup (struct lsa_header *);
252void ospf_lsa_data_free (struct lsa_header *);
253
254/* Prototype for various LSAs */
255struct ospf_lsa *ospf_router_lsa_originate (struct ospf_area *);
256int ospf_router_lsa_update_timer (struct thread *);
257void ospf_router_lsa_timer_add (struct ospf_area *);
258
259int ospf_network_lsa_refresh (struct ospf_lsa *, struct ospf_interface *);
260void ospf_network_lsa_timer_add (struct ospf_interface *);
261
262struct ospf_lsa *ospf_summary_lsa_originate (struct prefix_ipv4 *, u_int32_t,
263 struct ospf_area *);
264struct ospf_lsa *ospf_summary_asbr_lsa_originate (struct prefix_ipv4 *,
265 u_int32_t,
266 struct ospf_area *);
paul68980082003-03-25 05:07:42 +0000267struct ospf_lsa *ospf_summary_lsa_refresh (struct ospf *, struct ospf_lsa *);
268struct ospf_lsa *ospf_summary_asbr_lsa_refresh (struct ospf *, struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000269
paul68980082003-03-25 05:07:42 +0000270struct ospf_lsa *ospf_lsa_install (struct ospf *,
271 struct ospf_interface *, struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000272
paul645878f2003-04-13 21:42:11 +0000273void ospf_nssa_lsa_flush (struct ospf *ospf, struct prefix_ipv4 *p);
paul68980082003-03-25 05:07:42 +0000274void ospf_external_lsa_flush (struct ospf *, u_char, struct prefix_ipv4 *,
paul718e3742002-12-13 20:15:29 +0000275 unsigned int, struct in_addr);
276
paul68980082003-03-25 05:07:42 +0000277struct in_addr ospf_get_ip_from_ifp (struct ospf_interface *);
paul718e3742002-12-13 20:15:29 +0000278
paul68980082003-03-25 05:07:42 +0000279struct ospf_lsa *ospf_external_lsa_originate (struct ospf *, struct external_info *);
paul718e3742002-12-13 20:15:29 +0000280int ospf_external_lsa_originate_timer (struct thread *);
281struct ospf_lsa *ospf_lsa_lookup (struct ospf_area *, u_int32_t,
282 struct in_addr, struct in_addr);
pauld4a53d52003-07-12 21:30:57 +0000283struct ospf_lsa *ospf_lsa_lookup_by_id (struct ospf_area *,
284 u_int32_t,
285 struct in_addr);
paul718e3742002-12-13 20:15:29 +0000286struct ospf_lsa *ospf_lsa_lookup_by_header (struct ospf_area *,
287 struct lsa_header *);
288int ospf_lsa_more_recent (struct ospf_lsa *, struct ospf_lsa *);
289int ospf_lsa_different (struct ospf_lsa *, struct ospf_lsa *);
paul68980082003-03-25 05:07:42 +0000290void ospf_flush_self_originated_lsas_now (struct ospf *);
paul718e3742002-12-13 20:15:29 +0000291
paul68980082003-03-25 05:07:42 +0000292int ospf_lsa_is_self_originated (struct ospf *, struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000293
paul68980082003-03-25 05:07:42 +0000294struct ospf_lsa *ospf_lsa_lookup_by_prefix (struct ospf_lsdb *, u_char,
295 struct prefix_ipv4 *,
296 struct in_addr);
paul718e3742002-12-13 20:15:29 +0000297
paul68980082003-03-25 05:07:42 +0000298void ospf_lsa_maxage (struct ospf *, struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000299u_int32_t get_metric (u_char *);
300
301int ospf_lsa_maxage_walker (struct thread *);
302
paul68980082003-03-25 05:07:42 +0000303void ospf_external_lsa_refresh_default (struct ospf *);
paul718e3742002-12-13 20:15:29 +0000304
paul68980082003-03-25 05:07:42 +0000305void ospf_external_lsa_refresh_type (struct ospf *, u_char, int);
306void ospf_external_lsa_refresh (struct ospf *, struct ospf_lsa *,
307 struct external_info *, int);
308struct in_addr ospf_lsa_unique_id (struct ospf *, struct ospf_lsdb *, u_char,
paul718e3742002-12-13 20:15:29 +0000309 struct prefix_ipv4 *);
310void ospf_schedule_lsa_flood_area (struct ospf_area *, struct ospf_lsa *);
311void ospf_schedule_lsa_flush_area (struct ospf_area *, struct ospf_lsa *);
312
313void ospf_refresher_register_lsa (struct ospf *, struct ospf_lsa *);
314void ospf_refresher_unregister_lsa (struct ospf *, struct ospf_lsa *);
315int ospf_lsa_refresh_walker (struct thread *);
316
paul68980082003-03-25 05:07:42 +0000317void ospf_lsa_maxage_delete (struct ospf *, struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000318
paul68980082003-03-25 05:07:42 +0000319void ospf_discard_from_db (struct ospf *, struct ospf_lsdb *, struct ospf_lsa*);
paul718e3742002-12-13 20:15:29 +0000320int is_prefix_default (struct prefix_ipv4 *);
321
paul68980082003-03-25 05:07:42 +0000322int metric_type (struct ospf *, u_char);
323int metric_value (struct ospf *, u_char);
324
paul68980082003-03-25 05:07:42 +0000325struct in_addr ospf_get_nssa_ip (struct ospf_area *);
pauld4a53d52003-07-12 21:30:57 +0000326int ospf_translated_nssa_compare (struct ospf_lsa *, struct ospf_lsa *);
327struct ospf_lsa *ospf_translated_nssa_refresh (struct ospf *, struct ospf_lsa *,
328 struct ospf_lsa *);
329struct ospf_lsa *ospf_translated_nssa_originate (struct ospf *, struct ospf_lsa *);
paulf2c80652002-12-13 21:44:27 +0000330
paul718e3742002-12-13 20:15:29 +0000331#endif /* _ZEBRA_OSPF_LSA_H */