blob: 6d10e645d84b3ef2d4650ba46da01b78cccb6364 [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
93 /* References to this LSA in neighbor retransmission lists*/
94 int retransmit_counter;
95
96 /* Area the LSA belongs to, may be NULL if AS-external-LSA. */
97 struct ospf_area *area;
98
99 /* Parent LSDB. */
100 struct ospf_lsdb *lsdb;
101
102 /* Related Route. */
103 void *route;
104
105 /* Refreshement List or Queue */
106 int refresh_list;
107
108#ifdef HAVE_OPAQUE_LSA
109 /* For Type-9 Opaque-LSAs, reference to ospf-interface is required. */
110 struct ospf_interface *oi;
111#endif /* HAVE_OPAQUE_LSA */
112};
113
114/* OSPF LSA Link Type. */
115#define LSA_LINK_TYPE_POINTOPOINT 1
116#define LSA_LINK_TYPE_TRANSIT 2
117#define LSA_LINK_TYPE_STUB 3
118#define LSA_LINK_TYPE_VIRTUALLINK 4
119
120/* OSPF Router LSA Flag. */
121#define ROUTER_LSA_BORDER 0x01 /* The router is an ABR */
122#define ROUTER_LSA_EXTERNAL 0x02 /* The router is an ASBR */
123#define ROUTER_LSA_VIRTUAL 0x04 /* The router has a VL in this area */
paul0c9491b2003-06-22 08:23:01 +0000124#define ROUTER_LSA_NT 0x10 /* The routers always translates Type-7 */
paul718e3742002-12-13 20:15:29 +0000125#define ROUTER_LSA_SHORTCUT 0x20 /* Shortcut-ABR specific flag */
126
127#define IS_ROUTER_LSA_VIRTUAL(x) ((x)->flags & ROUTER_LSA_VIRTUAL)
128#define IS_ROUTER_LSA_EXTERNAL(x) ((x)->flags & ROUTER_LSA_EXTERNAL)
129#define IS_ROUTER_LSA_BORDER(x) ((x)->flags & ROUTER_LSA_BORDER)
130#define IS_ROUTER_LSA_SHORTCUT(x) ((x)->flags & ROUTER_LSA_SHORTCUT)
paul0c9491b2003-06-22 08:23:01 +0000131#define IS_ROUTER_LSA_NT(x) ((x)->flags & ROUTER_LSA_NT)
paul718e3742002-12-13 20:15:29 +0000132
133/* OSPF Router-LSA Link information. */
134struct router_lsa_link
135{
136 struct in_addr link_id;
137 struct in_addr link_data;
138 struct
139 {
140 u_char type;
141 u_char tos_count;
142 u_int16_t metric;
143 } m[1];
144};
145
146/* OSPF Router-LSAs structure. */
147struct router_lsa
148{
149 struct lsa_header header;
150 u_char flags;
151 u_char zero;
152 u_int16_t links;
153 struct
154 {
155 struct in_addr link_id;
156 struct in_addr link_data;
157 u_char type;
158 u_char tos;
159 u_int16_t metric;
160 } link[1];
161};
162
163/* OSPF Network-LSAs structure. */
164struct network_lsa
165{
166 struct lsa_header header;
167 struct in_addr mask;
168 struct in_addr routers[1];
169};
170
171/* OSPF Summary-LSAs structure. */
172struct summary_lsa
173{
174 struct lsa_header header;
175 struct in_addr mask;
176 u_char tos;
177 u_char metric[3];
178};
179
180/* OSPF AS-external-LSAs structure. */
181struct as_external_lsa
182{
183 struct lsa_header header;
184 struct in_addr mask;
185 struct
186 {
187 u_char tos;
188 u_char metric[3];
189 struct in_addr fwd_addr;
190 u_int32_t route_tag;
191 } e[1];
192};
193
194#ifdef HAVE_OPAQUE_LSA
195#include "ospfd/ospf_opaque.h"
196#endif /* HAVE_OPAQUE_LSA */
197
198/* Macros. */
199#define GET_METRIC(x) get_metric(x)
200#define IS_EXTERNAL_METRIC(x) ((x) & 0x80)
201
202#define GET_AGE(x) (ntohs ((x)->data->ls_age) + time (NULL) - (x)->tv_recv)
203#define LS_AGE(x) (OSPF_LSA_MAXAGE < get_age(x) ? \
204 OSPF_LSA_MAXAGE : get_age(x))
205#define IS_LSA_SELF(L) (CHECK_FLAG ((L)->flags, OSPF_LSA_SELF))
206#define IS_LSA_MAXAGE(L) (LS_AGE ((L)) == OSPF_LSA_MAXAGE)
207
paul718e3742002-12-13 20:15:29 +0000208#define OSPF_LSA_UPDATE_DELAY 2
209
210#define OSPF_LSA_UPDATE_TIMER_ON(T,F) \
211 if (!(T)) \
212 (T) = thread_add_timer (master, (F), 0, 2)
213
214struct ospf_route;
215struct ospf_lsdb;
216
217/* Prototypes. */
218struct timeval tv_adjust (struct timeval);
219int tv_ceil (struct timeval);
220int tv_floor (struct timeval);
221struct timeval int2tv (int);
222struct timeval tv_add (struct timeval, struct timeval);
223struct timeval tv_sub (struct timeval, struct timeval);
224int tv_cmp (struct timeval, struct timeval);
225
226int get_age (struct ospf_lsa *);
227u_int16_t ospf_lsa_checksum (struct lsa_header *);
228
229struct stream;
paul68980082003-03-25 05:07:42 +0000230const char *dump_lsa_key (struct ospf_lsa *);
231u_int32_t lsa_seqnum_increment (struct ospf_lsa *);
232void lsa_header_set (struct stream *, u_char, u_char, struct in_addr,
233 struct in_addr);
234struct ospf_neighbor *ospf_nbr_lookup_ptop (struct ospf_interface *);
paul718e3742002-12-13 20:15:29 +0000235
236/* Prototype for LSA primitive. */
237struct ospf_lsa *ospf_lsa_new ();
238struct ospf_lsa *ospf_lsa_dup ();
paul68980082003-03-25 05:07:42 +0000239void ospf_lsa_free (struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000240struct ospf_lsa *ospf_lsa_lock (struct ospf_lsa *);
241void ospf_lsa_unlock (struct ospf_lsa *);
242void ospf_lsa_discard (struct ospf_lsa *);
243
244struct lsa_header *ospf_lsa_data_new (size_t);
245struct lsa_header *ospf_lsa_data_dup (struct lsa_header *);
246void ospf_lsa_data_free (struct lsa_header *);
247
248/* Prototype for various LSAs */
249struct ospf_lsa *ospf_router_lsa_originate (struct ospf_area *);
250int ospf_router_lsa_update_timer (struct thread *);
251void ospf_router_lsa_timer_add (struct ospf_area *);
252
253int ospf_network_lsa_refresh (struct ospf_lsa *, struct ospf_interface *);
254void ospf_network_lsa_timer_add (struct ospf_interface *);
255
256struct ospf_lsa *ospf_summary_lsa_originate (struct prefix_ipv4 *, u_int32_t,
257 struct ospf_area *);
258struct ospf_lsa *ospf_summary_asbr_lsa_originate (struct prefix_ipv4 *,
259 u_int32_t,
260 struct ospf_area *);
paul68980082003-03-25 05:07:42 +0000261struct ospf_lsa *ospf_summary_lsa_refresh (struct ospf *, struct ospf_lsa *);
262struct ospf_lsa *ospf_summary_asbr_lsa_refresh (struct ospf *, struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000263
paul68980082003-03-25 05:07:42 +0000264struct ospf_lsa *ospf_lsa_install (struct ospf *,
265 struct ospf_interface *, struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000266
paul645878f2003-04-13 21:42:11 +0000267void ospf_nssa_lsa_flush (struct ospf *ospf, struct prefix_ipv4 *p);
paul68980082003-03-25 05:07:42 +0000268void ospf_external_lsa_flush (struct ospf *, u_char, struct prefix_ipv4 *,
paul718e3742002-12-13 20:15:29 +0000269 unsigned int, struct in_addr);
270
paul68980082003-03-25 05:07:42 +0000271struct in_addr ospf_get_ip_from_ifp (struct ospf_interface *);
paul718e3742002-12-13 20:15:29 +0000272
paul68980082003-03-25 05:07:42 +0000273struct ospf_lsa *ospf_external_lsa_originate (struct ospf *, struct external_info *);
paul718e3742002-12-13 20:15:29 +0000274int ospf_external_lsa_originate_timer (struct thread *);
275struct ospf_lsa *ospf_lsa_lookup (struct ospf_area *, u_int32_t,
276 struct in_addr, struct in_addr);
pauld4a53d52003-07-12 21:30:57 +0000277struct ospf_lsa *ospf_lsa_lookup_by_id (struct ospf_area *,
278 u_int32_t,
279 struct in_addr);
paul718e3742002-12-13 20:15:29 +0000280struct ospf_lsa *ospf_lsa_lookup_by_header (struct ospf_area *,
281 struct lsa_header *);
282int ospf_lsa_more_recent (struct ospf_lsa *, struct ospf_lsa *);
283int ospf_lsa_different (struct ospf_lsa *, struct ospf_lsa *);
paul68980082003-03-25 05:07:42 +0000284void ospf_flush_self_originated_lsas_now (struct ospf *);
paul718e3742002-12-13 20:15:29 +0000285
paul68980082003-03-25 05:07:42 +0000286int ospf_lsa_is_self_originated (struct ospf *, struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000287
paul68980082003-03-25 05:07:42 +0000288struct ospf_lsa *ospf_lsa_lookup_by_prefix (struct ospf_lsdb *, u_char,
289 struct prefix_ipv4 *,
290 struct in_addr);
paul718e3742002-12-13 20:15:29 +0000291
paul68980082003-03-25 05:07:42 +0000292void ospf_lsa_maxage (struct ospf *, struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000293u_int32_t get_metric (u_char *);
294
295int ospf_lsa_maxage_walker (struct thread *);
296
paul68980082003-03-25 05:07:42 +0000297void ospf_external_lsa_refresh_default (struct ospf *);
paul718e3742002-12-13 20:15:29 +0000298
paul68980082003-03-25 05:07:42 +0000299void ospf_external_lsa_refresh_type (struct ospf *, u_char, int);
300void ospf_external_lsa_refresh (struct ospf *, struct ospf_lsa *,
301 struct external_info *, int);
302struct in_addr ospf_lsa_unique_id (struct ospf *, struct ospf_lsdb *, u_char,
paul718e3742002-12-13 20:15:29 +0000303 struct prefix_ipv4 *);
304void ospf_schedule_lsa_flood_area (struct ospf_area *, struct ospf_lsa *);
305void ospf_schedule_lsa_flush_area (struct ospf_area *, struct ospf_lsa *);
306
307void ospf_refresher_register_lsa (struct ospf *, struct ospf_lsa *);
308void ospf_refresher_unregister_lsa (struct ospf *, struct ospf_lsa *);
309int ospf_lsa_refresh_walker (struct thread *);
310
paul68980082003-03-25 05:07:42 +0000311void ospf_lsa_maxage_delete (struct ospf *, struct ospf_lsa *);
paul718e3742002-12-13 20:15:29 +0000312
paul68980082003-03-25 05:07:42 +0000313void ospf_discard_from_db (struct ospf *, struct ospf_lsdb *, struct ospf_lsa*);
paul718e3742002-12-13 20:15:29 +0000314int is_prefix_default (struct prefix_ipv4 *);
315
paul68980082003-03-25 05:07:42 +0000316int metric_type (struct ospf *, u_char);
317int metric_value (struct ospf *, u_char);
318
paul68980082003-03-25 05:07:42 +0000319struct in_addr ospf_get_nssa_ip (struct ospf_area *);
pauld4a53d52003-07-12 21:30:57 +0000320int ospf_translated_nssa_compare (struct ospf_lsa *, struct ospf_lsa *);
321struct ospf_lsa *ospf_translated_nssa_refresh (struct ospf *, struct ospf_lsa *,
322 struct ospf_lsa *);
323struct ospf_lsa *ospf_translated_nssa_originate (struct ospf *, struct ospf_lsa *);
paulf2c80652002-12-13 21:44:27 +0000324
paul718e3742002-12-13 20:15:29 +0000325#endif /* _ZEBRA_OSPF_LSA_H */