Import Upstream version 1.2.2
[quagga-debian.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 /* OSPF master for system wide configuration and variables. */
81 struct ospf_master
82 {
83   /* OSPF instance. */
84   struct list *ospf;
85
86   /* OSPF thread master. */
87   struct thread_master *master;
88
89   /* Zebra interface list. */
90   struct list *iflist;
91
92   /* Redistributed external information. */
93   struct route_table *external_info[ZEBRA_ROUTE_MAX + 1];
94 #define EXTERNAL_INFO(T)      om->external_info[T]
95
96   /* OSPF start time. */
97   time_t start_time;
98
99   /* Various OSPF global configuration. */
100   u_char options;
101 #define OSPF_MASTER_SHUTDOWN (1 << 0) /* deferred-shutdown */  
102 };
103
104 /* OSPF instance structure. */
105 struct ospf
106 {
107   /* OSPF Router ID. */
108   struct in_addr router_id;             /* Configured automatically. */
109   struct in_addr router_id_static;      /* Configured manually. */
110
111   /* ABR/ASBR internal flags. */
112   u_char flags;
113 #define OSPF_FLAG_ABR           0x0001
114 #define OSPF_FLAG_ASBR          0x0002
115
116   /* ABR type. */
117   u_char abr_type;
118 #define OSPF_ABR_UNKNOWN        0
119 #define OSPF_ABR_STAND          1
120 #define OSPF_ABR_IBM            2
121 #define OSPF_ABR_CISCO          3
122 #define OSPF_ABR_SHORTCUT       4
123 #define OSPF_ABR_DEFAULT        OSPF_ABR_CISCO
124
125   /* NSSA ABR */
126   u_char anyNSSA;               /* Bump for every NSSA attached. */
127
128   /* Configured variables. */
129   u_char config;
130 #define OSPF_RFC1583_COMPATIBLE         (1 << 0)
131 #define OSPF_OPAQUE_CAPABLE             (1 << 2)
132 #define OSPF_LOG_ADJACENCY_CHANGES      (1 << 3)
133 #define OSPF_LOG_ADJACENCY_DETAIL       (1 << 4)
134
135   /* Opaque-LSA administrative flags. */
136   u_char opaque;
137 #define OPAQUE_OPERATION_READY_BIT      (1 << 0)
138
139   /* RFC3137 stub router. Configured time to stay stub / max-metric */
140   unsigned int stub_router_startup_time;        /* seconds */
141   unsigned int stub_router_shutdown_time;       /* seconds */
142 #define OSPF_STUB_ROUTER_UNCONFIGURED     0
143   u_char       stub_router_admin_set;
144 #define OSPF_STUB_ROUTER_ADMINISTRATIVE_SET     1
145 #define OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET   0
146
147 #define OSPF_STUB_MAX_METRIC_SUMMARY_COST       0x00ff0000
148
149   /* LSA timers */
150   unsigned int min_ls_interval; /* minimum delay between LSAs (in msec) */
151   unsigned int min_ls_arrival; /* minimum interarrival time between LSAs (in msec) */
152
153   /* SPF parameters */
154   unsigned int spf_delay;               /* SPF delay time. */
155   unsigned int spf_holdtime;            /* SPF hold time. */
156   unsigned int spf_max_holdtime;        /* SPF maximum-holdtime */
157   unsigned int spf_hold_multiplier;     /* Adaptive multiplier for hold time */
158   
159   int default_originate;                /* Default information originate. */
160 #define DEFAULT_ORIGINATE_NONE          0
161 #define DEFAULT_ORIGINATE_ZEBRA         1
162 #define DEFAULT_ORIGINATE_ALWAYS        2
163   u_int32_t ref_bandwidth;              /* Reference Bandwidth (Kbps). */
164   struct route_table *networks;         /* OSPF config networks. */
165   struct list *vlinks;                  /* Configured Virtual-Links. */
166   struct list *areas;                   /* OSPF areas. */
167   struct route_table *nbr_nbma;
168   struct ospf_area *backbone;           /* Pointer to the Backbone Area. */
169
170   struct list *oiflist;                 /* ospf interfaces */
171   u_char passive_interface_default;     /* passive-interface default */
172
173   /* LSDB of AS-external-LSAs. */
174   struct ospf_lsdb *lsdb;
175   
176   /* Flags. */
177   int external_origin;                  /* AS-external-LSA origin flag. */
178   int ase_calc;                         /* ASE calculation flag. */
179
180   struct list *opaque_lsa_self;         /* Type-11 Opaque-LSAs */
181
182   /* Routing tables. */
183   struct route_table *old_table;        /* Old routing table. */
184   struct route_table *new_table;        /* Current routing table. */
185
186   struct route_table *old_rtrs;         /* Old ABR/ASBR RT. */
187   struct route_table *new_rtrs;         /* New ABR/ASBR RT. */
188
189   struct route_table *new_external_route;   /* New External Route. */
190   struct route_table *old_external_route;   /* Old External Route. */
191   
192   struct route_table *external_lsas;    /* Database of external LSAs,
193                                            prefix is LSA's adv. network*/
194
195   /* Time stamps */
196   struct timeval ts_spf;                /* SPF calculation time stamp. */
197   struct timeval ts_spf_duration;       /* Execution time of last SPF */
198
199   struct route_table *maxage_lsa;       /* List of MaxAge LSA for deletion. */
200   int redistribute;                     /* Num of redistributed protocols. */
201
202   /* Threads. */
203   struct thread *t_abr_task;            /* ABR task timer. */
204   struct thread *t_asbr_check;          /* ASBR check timer. */
205   struct thread *t_distribute_update;   /* Distirbute list update timer. */
206   struct thread *t_spf_calc;            /* SPF calculation timer. */
207   struct thread *t_ase_calc;            /* ASE calculation timer. */
208   struct thread *t_external_lsa;        /* AS-external-LSA origin timer. */
209   struct thread *t_opaque_lsa_self;     /* Type-11 Opaque-LSAs origin event. */
210
211   unsigned int maxage_delay;            /* Delay on Maxage remover timer, sec */
212   struct thread *t_maxage;              /* MaxAge LSA remover timer. */
213   struct thread *t_maxage_walker;       /* MaxAge LSA checking timer. */
214
215   struct thread *t_deferred_shutdown;   /* deferred/stub-router shutdown timer*/
216
217   struct thread *t_write;
218   struct thread *t_read;
219   int fd;
220   unsigned int maxsndbuflen;
221   struct stream *ibuf;
222   struct list *oi_write_q;
223   
224   /* Distribute lists out of other route sources. */
225   struct 
226   {
227     char *name;
228     struct access_list *list;
229   } dlist[ZEBRA_ROUTE_MAX];
230 #define DISTRIBUTE_NAME(O,T)    (O)->dlist[T].name
231 #define DISTRIBUTE_LIST(O,T)    (O)->dlist[T].list
232
233   /* Redistribute metric info. */
234   struct 
235   {
236     int type;                   /* External metric type (E1 or E2).  */
237     int value;                  /* Value for static metric (24-bit).
238                                    -1 means metric value is not set. */
239   } dmetric [ZEBRA_ROUTE_MAX + 1];
240
241   /* Redistribute tag info. */
242   route_tag_t dtag [ZEBRA_ROUTE_MAX + 1];
243
244   /* For redistribute route map. */
245   struct
246   {
247     char *name;
248     struct route_map *map;
249   } route_map [ZEBRA_ROUTE_MAX + 1]; /* +1 is for default-information */
250 #define ROUTEMAP_NAME(O,T)   (O)->route_map[T].name
251 #define ROUTEMAP(O,T)        (O)->route_map[T].map
252   
253   int default_metric;           /* Default metric for redistribute. */
254
255 #define OSPF_LSA_REFRESHER_GRANULARITY 10
256 #define OSPF_LSA_REFRESHER_SLOTS ((OSPF_LS_REFRESH_TIME + \
257                                   OSPF_LS_REFRESH_SHIFT)/10 + 1)
258   struct
259   {
260     u_int16_t index;
261     struct list *qs[OSPF_LSA_REFRESHER_SLOTS];
262   } lsa_refresh_queue;
263   
264   struct thread *t_lsa_refresher;
265   time_t lsa_refresher_started;
266 #define OSPF_LSA_REFRESH_INTERVAL_DEFAULT 10
267   u_int16_t lsa_refresh_interval;
268   
269   /* Distance parameter. */
270   u_char distance_all;
271   u_char distance_intra;
272   u_char distance_inter;
273   u_char distance_external;
274
275   /* Statistics for LSA origination. */
276   u_int32_t lsa_originate_count;
277
278   /* Statistics for LSA used for new instantiation. */
279   u_int32_t rx_lsa_count;
280  
281   struct route_table *distance_table;
282 };
283
284 /* OSPF area structure. */
285 struct ospf_area
286 {
287   /* OSPF instance. */
288   struct ospf *ospf;
289
290   /* Zebra interface list belonging to the area. */
291   struct list *oiflist;
292
293   /* Area ID. */
294   struct in_addr area_id;
295
296   /* Area ID format. */
297   char format;
298 #define OSPF_AREA_ID_FORMAT_ADDRESS         1
299 #define OSPF_AREA_ID_FORMAT_DECIMAL         2
300
301   /* Address range. */
302   struct list *address_range;
303
304   /* Configured variables. */
305   int external_routing;                 /* ExternalRoutingCapability. */
306 #define OSPF_AREA_DEFAULT       0
307 #define OSPF_AREA_STUB          1
308 #define OSPF_AREA_NSSA          2
309 #define OSPF_AREA_TYPE_MAX      3
310   int no_summary;                       /* Don't inject summaries into stub.*/
311   int shortcut_configured;              /* Area configured as shortcut. */
312 #define OSPF_SHORTCUT_DEFAULT   0
313 #define OSPF_SHORTCUT_ENABLE    1
314 #define OSPF_SHORTCUT_DISABLE   2
315   int shortcut_capability;              /* Other ABRs agree on S-bit */
316   u_int32_t default_cost;               /* StubDefaultCost. */
317   int auth_type;                        /* Authentication type. */
318   
319
320   u_char NSSATranslatorRole;          /* NSSA configured role */
321 #define OSPF_NSSA_ROLE_NEVER     0
322 #define OSPF_NSSA_ROLE_CANDIDATE 1
323 #define OSPF_NSSA_ROLE_ALWAYS    2
324   u_char NSSATranslatorState;              /* NSSA operational role */
325 #define OSPF_NSSA_TRANSLATE_DISABLED 0
326 #define OSPF_NSSA_TRANSLATE_ENABLED  1
327   int NSSATranslatorStabilityInterval;
328   
329   u_char transit;                       /* TransitCapability. */
330 #define OSPF_TRANSIT_FALSE      0
331 #define OSPF_TRANSIT_TRUE       1
332   struct route_table *ranges;           /* Configured Area Ranges. */
333   
334   /* RFC3137 stub router state flags for area */
335   u_char stub_router_state;
336 #define OSPF_AREA_ADMIN_STUB_ROUTED     (1 << 0) /* admin stub-router set */
337 #define OSPF_AREA_IS_STUB_ROUTED        (1 << 1) /* stub-router active */
338 #define OSPF_AREA_WAS_START_STUB_ROUTED (1 << 2) /* startup SR was done */
339   
340   /* Area related LSDBs[Type1-4]. */
341   struct ospf_lsdb *lsdb;
342
343   /* Self-originated LSAs. */
344   struct ospf_lsa *router_lsa_self;
345   struct list *opaque_lsa_self;         /* Type-10 Opaque-LSAs */
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_stub_router;    /* Stub-router timer */
387   struct thread *t_opaque_lsa_self;     /* Type-10 Opaque-LSAs origin. */
388
389   /* Statistics field. */
390   u_int32_t spf_calculation;    /* SPF Calculation Count. */
391
392   /* Time stamps. */
393   struct timeval ts_spf;                /* SPF calculation time stamp. */
394
395   /* Router count. */
396   u_int32_t abr_count;          /* ABR router in this area. */
397   u_int32_t asbr_count;         /* ASBR router in this area. */
398
399   /* Counters. */
400   u_int32_t act_ints;           /* Active interfaces. */
401   u_int32_t full_nbrs;          /* Fully adjacent neighbors. */
402   u_int32_t full_vls;           /* Fully adjacent virtual neighbors. */
403 };
404
405 /* OSPF config network structure. */
406 struct ospf_network
407 {
408   /* Area ID. */
409   struct in_addr area_id;
410   int format;
411 };
412
413 /* OSPF NBMA neighbor structure. */
414 struct ospf_nbr_nbma
415 {
416   /* Neighbor IP address. */
417   struct in_addr addr;
418
419   /* OSPF interface. */
420   struct ospf_interface *oi;
421
422   /* OSPF neighbor structure. */
423   struct ospf_neighbor *nbr;
424
425   /* Neighbor priority. */
426   u_char priority;
427
428   /* Poll timer value. */
429   u_int32_t v_poll;
430
431   /* Poll timer thread. */
432   struct thread *t_poll;
433
434   /* State change. */
435   u_int32_t state_change;
436 };
437
438 /* Macro. */
439 #define OSPF_AREA_SAME(X,Y) \
440         (memcmp ((X->area_id), (Y->area_id), IPV4_MAX_BYTELEN) == 0)
441
442 #define IS_OSPF_ABR(O)          ((O)->flags & OSPF_FLAG_ABR)
443 #define IS_OSPF_ASBR(O)         ((O)->flags & OSPF_FLAG_ASBR)
444
445 #define OSPF_IS_AREA_ID_BACKBONE(I) ((I).s_addr == OSPF_AREA_BACKBONE)
446 #define OSPF_IS_AREA_BACKBONE(A) OSPF_IS_AREA_ID_BACKBONE ((A)->area_id)
447
448 #ifdef roundup
449 #  define ROUNDUP(val, gran)    roundup(val, gran)
450 #else /* roundup */
451 #  define ROUNDUP(val, gran)    (((val) - 1 | (gran) - 1) + 1)
452 #endif /* roundup */
453
454 #define LSA_OPTIONS_GET(area) \
455         (((area)->external_routing == OSPF_AREA_DEFAULT) ? OSPF_OPTION_E : 0)
456 #define LSA_OPTIONS_NSSA_GET(area) \
457         (((area)->external_routing == OSPF_AREA_NSSA)  ? OSPF_OPTION_NP : 0)
458
459 #define OSPF_TIMER_ON(T,F,V)                                                  \
460     do {                                                                      \
461       if (!(T))                                                               \
462         (T) = thread_add_timer (master, (F), ospf, (V));                      \
463     } while (0)
464
465 #define OSPF_AREA_TIMER_ON(T,F,V)                                             \
466     do {                                                                      \
467       if (!(T))                                                               \
468         (T) = thread_add_timer (master, (F), area, (V));                      \
469     } while (0)
470
471 #define OSPF_POLL_TIMER_ON(T,F,V)                                             \
472     do {                                                                      \
473       if (!(T))                                                               \
474         (T) = thread_add_timer (master, (F), nbr_nbma, (V));                  \
475     } while (0)
476
477 #define OSPF_POLL_TIMER_OFF(X)          OSPF_TIMER_OFF((X))
478
479 #define OSPF_TIMER_OFF(X)                                                     \
480     do {                                                                      \
481       if (X)                                                                  \
482         {                                                                     \
483           thread_cancel (X);                                                  \
484           (X) = NULL;                                                         \
485         }                                                                     \
486     } while (0)
487
488 /* Extern variables. */
489 extern struct ospf_master *om;
490 extern const struct message ospf_ism_state_msg[];
491 extern const struct message ospf_nsm_state_msg[];
492 extern const struct message ospf_lsa_type_msg[];
493 extern const struct message ospf_link_state_id_type_msg[];
494 extern const struct message ospf_network_type_msg[];
495 extern const int ospf_ism_state_msg_max;
496 extern const int ospf_nsm_state_msg_max;
497 extern const int ospf_lsa_type_msg_max;
498 extern const int ospf_link_state_id_type_msg_max;
499 extern const int ospf_redistributed_proto_max;
500 extern const int ospf_network_type_msg_max;
501 extern struct zclient *zclient;
502 extern struct thread_master *master;
503 extern int ospf_zlog;
504
505 /* Prototypes. */
506 extern const char *ospf_redist_string(u_int route_type);
507 extern struct ospf *ospf_lookup (void);
508 extern struct ospf *ospf_get (void);
509 extern void ospf_finish (struct ospf *);
510 extern void ospf_router_id_update (struct ospf *ospf);
511 extern int ospf_network_set (struct ospf *, struct prefix_ipv4 *,
512                              struct in_addr);
513 extern int ospf_network_unset (struct ospf *, struct prefix_ipv4 *,
514                                struct in_addr);
515 extern int ospf_area_stub_set (struct ospf *, struct in_addr);
516 extern int ospf_area_stub_unset (struct ospf *, struct in_addr);
517 extern int ospf_area_no_summary_set (struct ospf *, struct in_addr);
518 extern int ospf_area_no_summary_unset (struct ospf *, struct in_addr);
519 extern int ospf_area_nssa_set (struct ospf *, struct in_addr);
520 extern int ospf_area_nssa_unset (struct ospf *, struct in_addr);
521 extern int ospf_area_nssa_translator_role_set (struct ospf *, struct in_addr,
522                                                int);
523 extern int ospf_area_export_list_set (struct ospf *, struct ospf_area *,
524                                       const char *);
525 extern int ospf_area_export_list_unset (struct ospf *, struct ospf_area *);
526 extern int ospf_area_import_list_set (struct ospf *, struct ospf_area *,
527                                       const char *);
528 extern int ospf_area_import_list_unset (struct ospf *, struct ospf_area *);
529 extern int ospf_area_shortcut_set (struct ospf *, struct ospf_area *, int);
530 extern int ospf_area_shortcut_unset (struct ospf *, struct ospf_area *);
531 extern int ospf_timers_refresh_set (struct ospf *, int);
532 extern int ospf_timers_refresh_unset (struct ospf *);
533 extern int ospf_nbr_nbma_set (struct ospf *, struct in_addr);
534 extern int ospf_nbr_nbma_unset (struct ospf *, struct in_addr);
535 extern int ospf_nbr_nbma_priority_set (struct ospf *, struct in_addr, u_char);
536 extern int ospf_nbr_nbma_priority_unset (struct ospf *, struct in_addr);
537 extern int ospf_nbr_nbma_poll_interval_set (struct ospf *, struct in_addr,
538                                             unsigned int);
539 extern int ospf_nbr_nbma_poll_interval_unset (struct ospf *, struct in_addr);
540 extern void ospf_prefix_list_update (struct prefix_list *);
541 extern void ospf_init (void);
542 extern void ospf_if_update (struct ospf *, struct interface *);
543 extern void ospf_ls_upd_queue_empty (struct ospf_interface *);
544 extern void ospf_terminate (void);
545 extern void ospf_nbr_nbma_if_update (struct ospf *, struct ospf_interface *);
546 extern struct ospf_nbr_nbma *ospf_nbr_nbma_lookup (struct ospf *,
547                                                    struct in_addr);
548 extern struct ospf_nbr_nbma *ospf_nbr_nbma_lookup_next (struct ospf *,
549                                                         struct in_addr *,
550                                                         int);
551 extern int ospf_oi_count (struct interface *);
552
553 extern struct ospf_area *ospf_area_get (struct ospf *, struct in_addr, int);
554 extern void ospf_area_check_free (struct ospf *, struct in_addr);
555 extern struct ospf_area *ospf_area_lookup_by_area_id (struct ospf *,
556                                                       struct in_addr);
557 extern void ospf_area_add_if (struct ospf_area *, struct ospf_interface *);
558 extern void ospf_area_del_if (struct ospf_area *, struct ospf_interface *);
559
560 extern void ospf_interface_area_set (struct interface *);
561 extern void ospf_interface_area_unset (struct interface *);
562
563 extern void ospf_route_map_init (void);
564 extern void ospf_snmp_init (void);
565
566 extern void ospf_master_init (void);
567
568 #endif /* _ZEBRA_OSPFD_H */