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