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