blob: be806212c4488b6950f995593e0fd48ddc9cad15 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * OSPFd main header.
3 * Copyright (C) 1998, 99, 2000 Kunihiro Ishiguro, 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_OSPFD_H
24#define _ZEBRA_OSPFD_H
25
26#include "filter.h"
27
28#define OSPF_VERSION 2
29
30/* Default protocol, port number. */
31#ifndef IPPROTO_OSPFIGP
32#define IPPROTO_OSPFIGP 89
33#endif /* IPPROTO_OSPFIGP */
34
paul68980082003-03-25 05:07:42 +000035/* IP precedence. */
36#ifndef IPTOS_PREC_INTERNETCONTROL
37#define IPTOS_PREC_INTERNETCONTROL 0xC0
38#endif /* IPTOS_PREC_INTERNETCONTROL */
39
paul718e3742002-12-13 20:15:29 +000040/* VTY port number. */
41#define OSPF_VTY_PORT 2604
42#define OSPF_VTYSH_PATH "/tmp/.ospfd"
43
44/* IP TTL for OSPF protocol. */
45#define OSPF_IP_TTL 1
46#define OSPF_VL_IP_TTL 100
47
48/* Default configuration file name for ospfd. */
49#define OSPF_DEFAULT_CONFIG "ospfd.conf"
50
51/* Architectual Constants */
52#ifdef DEBUG
53#define OSPF_LS_REFRESH_TIME 60
54#else
55#define OSPF_LS_REFRESH_TIME 1800
56#endif
57#define OSPF_MIN_LS_INTERVAL 5
58#define OSPF_MIN_LS_ARRIVAL 1
59#define OSPF_LSA_MAXAGE 3600
60#define OSPF_CHECK_AGE 300
61#define OSPF_LSA_MAXAGE_DIFF 900
62#define OSPF_LS_INFINITY 0xffffff
63#define OSPF_DEFAULT_DESTINATION 0x00000000 /* 0.0.0.0 */
64#define OSPF_INITIAL_SEQUENCE_NUMBER 0x80000001
65#define OSPF_MAX_SEQUENCE_NUMBER 0x7fffffff
66
67#define OSPF_LSA_MAXAGE_CHECK_INTERVAL 30
68
69#define OSPF_ALLSPFROUTERS 0xe0000005 /* 224.0.0.5 */
70#define OSPF_ALLDROUTERS 0xe0000006 /* 224.0.0.6 */
71
72#ifdef HAVE_NSSA
73#define OSPF_LOOPer 0x7f000000 /* 127.0.0.0 */
74#endif /* HAVE_NSSA */
75
76#define OSPF_AREA_BACKBONE 0x00000000 /* 0.0.0.0 */
77
78/* OSPF Authentication Type. */
79#define OSPF_AUTH_NULL 0
80#define OSPF_AUTH_SIMPLE 1
81#define OSPF_AUTH_CRYPTOGRAPHIC 2
82/* For Interface authentication setting default */
83#define OSPF_AUTH_NOTSET -1
84/* For the consumption and sanity of the command handler */
85/* DO NIOT REMOVE!!! Need to detect whether a value has
86 been given or not in VLink command handlers */
87#define OSPF_AUTH_CMD_NOTSEEN -2
88
89/* OSPF SPF timer values. */
90#define OSPF_SPF_DELAY_DEFAULT 5
91#define OSPF_SPF_HOLDTIME_DEFAULT 10
92
93/* OSPF interface default values. */
94#define OSPF_OUTPUT_COST_DEFAULT 10
95#define OSPF_ROUTER_DEAD_INTERVAL_DEFAULT 40
96#define OSPF_HELLO_INTERVAL_DEFAULT 10
97#define OSPF_ROUTER_PRIORITY_DEFAULT 1
98#define OSPF_RETRANSMIT_INTERVAL_DEFAULT 5
99#define OSPF_TRANSMIT_DELAY_DEFAULT 1
100#define OSPF_DEFAULT_BANDWIDTH 10000 /* Kbps */
101
102#define OSPF_DEFAULT_REF_BANDWIDTH 100000 /* Kbps */
103
104#define OSPF_POLL_INTERVAL_DEFAULT 60
105#define OSPF_NEIGHBOR_PRIORITY_DEFAULT 0
106
107/* OSPF options. */
108#define OSPF_OPTION_T 0x01 /* TOS. */
109#define OSPF_OPTION_E 0x02
110#define OSPF_OPTION_MC 0x04
111#define OSPF_OPTION_NP 0x08
112#define OSPF_OPTION_EA 0x10
113#define OSPF_OPTION_DC 0x20
114#define OSPF_OPTION_O 0x40
115
116/* OSPF Database Description flags. */
117#define OSPF_DD_FLAG_MS 0x01
118#define OSPF_DD_FLAG_M 0x02
119#define OSPF_DD_FLAG_I 0x04
120#define OSPF_DD_FLAG_ALL 0x07
121
122/* Timer value. */
123#define OSPF_ROUTER_ID_UPDATE_DELAY 1
124
125#define OSPF_LS_REFRESH_SHIFT (60 * 15)
126#define OSPF_LS_REFRESH_JITTER 60
127
128/* OSPF instance structure. */
129struct ospf
130{
131 /* OSPF Router ID. */
132 struct in_addr router_id; /* Configured automatically. */
133 struct in_addr router_id_static; /* Configured manually. */
134
135 /* ABR/ASBR internal flags. */
136 u_char flags;
137#define OSPF_FLAG_ABR 0x0001
138#define OSPF_FLAG_ASBR 0x0002
139
140 /* ABR type. */
141 u_char abr_type;
142#define OSPF_ABR_UNKNOWN 0
143#define OSPF_ABR_STAND 1
144#define OSPF_ABR_IBM 2
145#define OSPF_ABR_CISCO 3
146#define OSPF_ABR_SHORTCUT 4
147
148 /* NSSA ABR */
149 u_char anyNSSA; /* Bump for every NSSA attached. */
150
151 /* Configured variables. */
152 u_char config;
153#define OSPF_RFC1583_COMPATIBLE (1 << 0)
154#define OSPF_OPAQUE_CAPABLE (1 << 2)
155
156#ifdef HAVE_OPAQUE_LSA
157 /* Opaque-LSA administrative flags. */
158 u_char opaque;
159#define OPAQUE_OPERATION_READY_BIT (1 << 0)
160#define OPAQUE_BLOCK_TYPE_09_LSA_BIT (1 << 1)
161#define OPAQUE_BLOCK_TYPE_10_LSA_BIT (1 << 2)
162#define OPAQUE_BLOCK_TYPE_11_LSA_BIT (1 << 3)
163#endif /* HAVE_OPAQUE_LSA */
164
165 int spf_delay; /* SPF delay time. */
166 int spf_holdtime; /* SPF hold time. */
167 int default_originate; /* Default information originate. */
168#define DEFAULT_ORIGINATE_NONE 0
169#define DEFAULT_ORIGINATE_ZEBRA 1
170#define DEFAULT_ORIGINATE_ALWAYS 2
171 u_int32_t ref_bandwidth; /* Reference Bandwidth (Kbps). */
172 struct route_table *networks; /* OSPF config networks. */
173 list vlinks; /* Configured Virtual-Links. */
174 list areas; /* OSPF areas. */
175 struct route_table *nbr_nbma;
176 struct ospf_area *backbone; /* Pointer to the Backbone Area. */
177
178 list iflist; /* Zebra derived interfaces. */
179 list oiflist; /* ospf interfaces */
180
181 /* LSDB of AS-external-LSAs. */
182 struct ospf_lsdb *lsdb;
183
184 /* Redistributed external information. */
185 struct route_table *external_info[ZEBRA_ROUTE_MAX + 1];
186#define EXTERNAL_INFO(T) ospf_top->external_info[T]
187
188 /* Flags. */
189 int external_origin; /* AS-external-LSA origin flag. */
190 int ase_calc; /* ASE calculation flag. */
191
192#ifdef HAVE_OPAQUE_LSA
193 list opaque_lsa_self; /* Type-11 Opaque-LSAs */
194#endif /* HAVE_OPAQUE_LSA */
195
196 /* Routing tables. */
197 struct route_table *old_table; /* Old routing table. */
198 struct route_table *new_table; /* Current routing table. */
199
200 struct route_table *old_rtrs; /* Old ABR/ASBR RT. */
201 struct route_table *new_rtrs; /* New ABR/ASBR RT. */
202
203 struct route_table *new_external_route; /* New External Route. */
204 struct route_table *old_external_route; /* Old External Route. */
205
206 struct route_table *external_lsas; /* Database of external LSAs,
207 prefix is LSA's adv. network*/
208
209 /* Time stamps. */
210 time_t ts_spf; /* SPF calculation time stamp. */
211
212 list maxage_lsa; /* List of MaxAge LSA for deletion. */
213 int redistribute; /* Num of redistributed protocols. */
214
215 /* Threads. */
216 struct thread *t_router_id_update; /* Router ID update timer. */
217 struct thread *t_router_lsa_update; /* router-LSA update timer. */
218 struct thread *t_abr_task; /* ABR task timer. */
219 struct thread *t_asbr_check; /* ASBR check timer. */
220 struct thread *t_distribute_update; /* Distirbute list update timer. */
221 struct thread *t_spf_calc; /* SPF calculation timer. */
222 struct thread *t_ase_calc; /* ASE calculation timer. */
223 struct thread *t_external_lsa; /* AS-external-LSA origin timer. */
224#ifdef HAVE_OPAQUE_LSA
225 struct thread *t_opaque_lsa_self; /* Type-11 Opaque-LSAs origin event. */
226#endif /* HAVE_OPAQUE_LSA */
227 struct thread *t_maxage; /* MaxAge LSA remover timer. */
228 struct thread *t_maxage_walker; /* MaxAge LSA checking timer. */
229
230 struct thread *t_write;
231 struct thread *t_read;
232 int fd;
233 list oi_write_q;
234
235 /* Distribute lists out of other route sources. */
236 struct
237 {
238 char *name;
239 struct access_list *list;
240 } dlist[ZEBRA_ROUTE_MAX];
241#define DISTRIBUTE_NAME(T) ospf_top->dlist[T].name
242#define DISTRIBUTE_LIST(T) ospf_top->dlist[T].list
243
244 /* Redistribute metric info. */
245 struct
246 {
247 int type; /* External metric type (E1 or E2). */
248 int value; /* Value for static metric (24-bit).
249 -1 means metric value is not set. */
250 } dmetric [ZEBRA_ROUTE_MAX + 1];
251
252 /* For redistribute route map. */
253 struct
254 {
255 char *name;
256 struct route_map *map;
257 } route_map [ZEBRA_ROUTE_MAX + 1]; /* +1 is for default-information */
258#define ROUTEMAP_NAME(T) ospf_top->route_map[T].name
259#define ROUTEMAP(T) ospf_top->route_map[T].map
260
261 int default_metric; /* Default metric for redistribute. */
262
263#define OSPF_LSA_REFRESHER_GRANULARITY 10
264#define OSPF_LSA_REFRESHER_SLOTS ((OSPF_LS_REFRESH_TIME + \
265 OSPF_LS_REFRESH_SHIFT)/10 + 1)
266 struct
267 {
268 u_int16_t index;
269 list qs[OSPF_LSA_REFRESHER_SLOTS];
270 } lsa_refresh_queue;
271
272 struct thread *t_lsa_refresher;
273 time_t lsa_refresher_started;
274#define OSPF_LSA_REFRESH_INTERVAL_DEFAULT 10
275 u_int16_t lsa_refresh_interval;
276
277 /* Distance parameter. */
278 u_char distance_all;
279 u_char distance_intra;
280 u_char distance_inter;
281 u_char distance_external;
282
283 /* Statistics for LSA origination. */
284 u_int32_t lsa_originate_count;
285
286 /* Statistics for LSA used for new instantiation. */
287 u_int32_t rx_lsa_count;
288
289 struct route_table *distance_table;
290};
291
292/* OSPF area structure. */
293struct ospf_area
294{
295 /* OSPF instance. */
paul68980082003-03-25 05:07:42 +0000296 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000297
298 /* Zebra interface list belonging to the area. */
299 list oiflist;
300
301 /* Area ID. */
302 struct in_addr area_id;
303
304 /* Area ID format. */
305 char format;
306#define OSPF_AREA_ID_FORMAT_ADDRESS 1
307#define OSPF_AREA_ID_FORMAT_DECIMAL 2
308
309 /* Address range. */
310 list address_range;
311
312 /* Configured variables. */
313 int external_routing; /* ExternalRoutingCapability. */
314#define OSPF_AREA_DEFAULT 0
315#define OSPF_AREA_STUB 1
316#define OSPF_AREA_NSSA 2
317#define OSPF_AREA_TYPE_MAX 3
318 int no_summary; /* Don't inject summaries into stub.*/
319 int shortcut_configured; /* Area configured as shortcut. */
320#define OSPF_SHORTCUT_DEFAULT 0
321#define OSPF_SHORTCUT_ENABLE 1
322#define OSPF_SHORTCUT_DISABLE 2
323 int shortcut_capability; /* Other ABRs agree on S-bit */
324 u_int32_t default_cost; /* StubDefaultCost. */
325 int auth_type; /* Authentication type. */
326
327 u_char NSSATranslatorRole; /* NSSA Role during configuration */
328#define OSPF_NSSA_ROLE_NEVER 0
329#define OSPF_NSSA_ROLE_ALWAYS 1
330#define OSPF_NSSA_ROLE_CANDIDATE 2
331 u_char NSSATranslator; /* NSSA Role after election process */
332
333 u_char transit; /* TransitCapability. */
334#define OSPF_TRANSIT_FALSE 0
335#define OSPF_TRANSIT_TRUE 1
336 struct route_table *ranges; /* Configured Area Ranges. */
337
338 /* Area related LSDBs[Type1-4]. */
339 struct ospf_lsdb *lsdb;
340
341 /* Self-originated LSAs. */
342 struct ospf_lsa *router_lsa_self;
343#ifdef HAVE_OPAQUE_LSA
344 list opaque_lsa_self; /* Type-10 Opaque-LSAs */
345#endif /* HAVE_OPAQUE_LSA */
346
347 /* Area announce list. */
348 struct
349 {
350 char *name;
351 struct access_list *list;
352 } export;
353#define EXPORT_NAME(A) (A)->export.name
354#define EXPORT_LIST(A) (A)->export.list
355
356 /* Area acceptance list. */
357 struct
358 {
359 char *name;
360 struct access_list *list;
361 } import;
362#define IMPORT_NAME(A) (A)->import.name
363#define IMPORT_LIST(A) (A)->import.list
364
365 /* Type 3 LSA Area prefix-list. */
366 struct
367 {
368 char *name;
369 struct prefix_list *list;
370 } plist_in;
371#define PREFIX_LIST_IN(A) (A)->plist_in.list
372#define PREFIX_NAME_IN(A) (A)->plist_in.name
373
374 struct
375 {
376 char *name;
377 struct prefix_list *list;
378 } plist_out;
379#define PREFIX_LIST_OUT(A) (A)->plist_out.list
380#define PREFIX_NAME_OUT(A) (A)->plist_out.name
381
382 /* Shortest Path Tree. */
383 struct vertex *spf;
384
385 /* Threads. */
386 struct thread *t_router_lsa_self;/* Self-originated router-LSA timer. */
387#ifdef HAVE_OPAQUE_LSA
388 struct thread *t_opaque_lsa_self; /* Type-10 Opaque-LSAs origin. */
389#endif /* HAVE_OPAQUE_LSA */
390
391 /* Statistics field. */
392 u_int32_t spf_calculation; /* SPF Calculation Count. */
393
394 /* Router count. */
395 u_int32_t abr_count; /* ABR router in this area. */
396 u_int32_t asbr_count; /* ASBR router in this area. */
397
398 /* Counters. */
399 u_int32_t act_ints; /* Active interfaces. */
400 u_int32_t full_nbrs; /* Fully adjacent neighbors. */
401 u_int32_t full_vls; /* Fully adjacent virtual neighbors. */
402};
403
404/* OSPF config network structure. */
405struct ospf_network
406{
407 /* Area ID. */
408 struct in_addr area_id;
409 int format;
410};
411
412/* OSPF NBMA neighbor structure. */
413struct ospf_nbr_nbma
414{
415 /* Neighbor IP address. */
416 struct in_addr addr;
417
418 /* OSPF interface. */
419 struct ospf_interface *oi;
420
421 /* OSPF neighbor structure. */
422 struct ospf_neighbor *nbr;
423
424 /* Neighbor priority. */
425 u_char priority;
426
427 /* Poll timer value. */
428 u_int32_t v_poll;
429
430 /* Poll timer thread. */
431 struct thread *t_poll;
432
433 /* State change. */
434 u_int32_t state_change;
435};
436
437/* Macro. */
438#define OSPF_AREA_SAME(X,Y) \
439 (memcmp ((X->area_id), (Y->area_id), IPV4_MAX_BYTELEN) == 0)
440
441#define OSPF_IS_ABR (ospf_top->flags & OSPF_FLAG_ABR)
442#define OSPF_IS_ASBR (ospf_top->flags & OSPF_FLAG_ASBR)
443
444#define OSPF_IS_AREA_ID_BACKBONE(I) ((I).s_addr == OSPF_AREA_BACKBONE)
445#define OSPF_IS_AREA_BACKBONE(A) OSPF_IS_AREA_ID_BACKBONE ((A)->area_id)
446
447#ifdef roundup
448# define ROUNDUP(val, gran) roundup(val, gran)
449#else /* roundup */
450# define ROUNDUP(val, gran) (((val) - 1 | (gran) - 1) + 1)
451#endif /* roundup */
452
453#define LSA_OPTIONS_GET(area) \
454 (((area)->external_routing == OSPF_AREA_DEFAULT) ? OSPF_OPTION_E : 0)
455#ifdef HAVE_NSSA
456#define LSA_NSSA_GET(area) \
457 (((area)->external_routing == OSPF_AREA_NSSA) ? \
458 (area)->NSSATranslator : 0)
459#endif /* HAVE_NSSA */
460
461#define OSPF_TIMER_ON(T,F,V) \
462 do { \
463 if (!(T)) \
paul68980082003-03-25 05:07:42 +0000464 (T) = thread_add_timer (master, (F), ospf, (V)); \
paul718e3742002-12-13 20:15:29 +0000465 } while (0)
466
467#define OSPF_AREA_TIMER_ON(T,F,V) \
468 do { \
469 if (!(T)) \
470 (T) = thread_add_timer (master, (F), area, (V)); \
471 } while (0)
472
473#define OSPF_POLL_TIMER_ON(T,F,V) \
474 do { \
475 if (!(T)) \
476 (T) = thread_add_timer (master, (F), nbr_nbma, (V)); \
477 } while (0)
478
479#define OSPF_POLL_TIMER_OFF(X) OSPF_TIMER_OFF((X))
480
481#define OSPF_TIMER_OFF(X) \
482 do { \
483 if (X) \
484 { \
485 thread_cancel (X); \
486 (X) = NULL; \
487 } \
488 } while (0)
489
paul718e3742002-12-13 20:15:29 +0000490/* Messages */
491extern struct message ospf_ism_state_msg[];
492extern struct message ospf_nsm_state_msg[];
493extern struct message ospf_lsa_type_msg[];
494extern struct message ospf_link_state_id_type_msg[];
495extern struct message ospf_redistributed_proto[];
496extern struct message ospf_network_type_msg[];
497extern int ospf_ism_state_msg_max;
498extern int ospf_nsm_state_msg_max;
499extern int ospf_lsa_type_msg_max;
500extern int ospf_link_state_id_type_msg_max;
501extern int ospf_redistributed_proto_max;
502extern int ospf_network_type_msg_max;
503extern struct zclient *zclient;
504extern struct thread_master *master;
505extern struct ospf *ospf_top;
506extern int ospf_zlog;
507
508/* Prototypes. */
509struct ospf *ospf_get ();
510void ospf_finish (struct ospf *);
511int ospf_router_id_update_timer (struct thread *);
512void ospf_router_id_update ();
paul570f7592003-01-25 06:47:41 +0000513int ospf_network_match_iface (struct connected *, struct prefix *);
paul718e3742002-12-13 20:15:29 +0000514int ospf_network_set (struct ospf *, struct prefix_ipv4 *, struct in_addr);
515int ospf_network_unset (struct ospf *, struct prefix_ipv4 *, struct in_addr);
516int ospf_area_stub_set (struct ospf *, struct in_addr);
517int ospf_area_stub_unset (struct ospf *, struct in_addr);
518int ospf_area_no_summary_set (struct ospf *, struct in_addr);
519int ospf_area_no_summary_unset (struct ospf *, struct in_addr);
520int ospf_area_nssa_set (struct ospf *, struct in_addr);
521int ospf_area_nssa_unset (struct ospf *, struct in_addr);
522int ospf_area_nssa_translator_role_set (struct ospf *, struct in_addr, int);
paul68980082003-03-25 05:07:42 +0000523int ospf_area_export_list_set (struct ospf *, struct ospf_area *, char *);
524int ospf_area_export_list_unset (struct ospf *, struct ospf_area *);
525int ospf_area_import_list_set (struct ospf *, struct ospf_area *, char *);
526int ospf_area_import_list_unset (struct ospf *, struct ospf_area *);
527int ospf_area_shortcut_set (struct ospf *, struct ospf_area *, int);
528int ospf_area_shortcut_unset (struct ospf *, struct ospf_area *);
paul718e3742002-12-13 20:15:29 +0000529int ospf_timers_spf_set (struct ospf *, u_int32_t, u_int32_t);
530int ospf_timers_spf_unset (struct ospf *);
531int ospf_timers_refresh_set (struct ospf *, int);
532int ospf_timers_refresh_unset (struct ospf *);
533int ospf_nbr_nbma_set (struct ospf *, struct in_addr);
534int ospf_nbr_nbma_unset (struct ospf *, struct in_addr);
535int ospf_nbr_nbma_priority_set (struct ospf *, struct in_addr, u_char);
536int ospf_nbr_nbma_priority_unset (struct ospf *, struct in_addr);
537int ospf_nbr_nbma_poll_interval_set (struct ospf *, struct in_addr, int);
538int ospf_nbr_nbma_poll_interval_unset (struct ospf *, struct in_addr);
539void ospf_prefix_list_update (struct prefix_list *);
540void ospf_init ();
paul68980082003-03-25 05:07:42 +0000541void ospf_if_update (struct ospf *);
paul718e3742002-12-13 20:15:29 +0000542void ospf_ls_upd_queue_empty (struct ospf_interface *);
543void ospf_terminate ();
paul68980082003-03-25 05:07:42 +0000544void ospf_nbr_nbma_if_update (struct ospf *, struct ospf_interface *);
paul718e3742002-12-13 20:15:29 +0000545struct ospf_nbr_nbma *ospf_nbr_nbma_lookup (struct ospf *, struct in_addr);
paul68980082003-03-25 05:07:42 +0000546struct ospf_nbr_nbma *ospf_nbr_nbma_lookup_next (struct ospf *,
547 struct in_addr *, int);
paul718e3742002-12-13 20:15:29 +0000548int ospf_oi_count (struct interface *);
549
paul68980082003-03-25 05:07:42 +0000550struct ospf_area *ospf_area_get (struct ospf *, struct in_addr, int);
551void ospf_area_check_free (struct ospf *, struct in_addr);
552struct ospf_area *ospf_area_lookup_by_area_id (struct ospf *, struct in_addr);
paul718e3742002-12-13 20:15:29 +0000553void ospf_area_add_if (struct ospf_area *, struct ospf_interface *);
554void ospf_area_del_if (struct ospf_area *, struct ospf_interface *);
555
556void ospf_route_map_init ();
557void ospf_snmp_init ();
558
559#endif /* _ZEBRA_OSPFD_H */