3 * Copyright (C) 1998, 99, 2000 Kunihiro Ishiguro, Toshiaki Takada
5 * This file is part of GNU Zebra.
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
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.
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
23 #ifndef _ZEBRA_OSPFD_H
24 #define _ZEBRA_OSPFD_H
32 #define OSPF_VERSION 2
34 /* VTY port number. */
35 #define OSPF_VTY_PORT 2604
37 /* IP TTL for OSPF protocol. */
39 #define OSPF_VL_IP_TTL 100
41 /* Default configuration file name for ospfd. */
42 #define OSPF_DEFAULT_CONFIG "ospfd.conf"
44 #define OSPF_NSSA_TRANS_STABLE_DEFAULT 40
46 #define OSPF_ALLSPFROUTERS 0xe0000005 /* 224.0.0.5 */
47 #define OSPF_ALLDROUTERS 0xe0000006 /* 224.0.0.6 */
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
62 #define OSPF_OPTION_T 0x01 /* TOS. */
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
70 /* OSPF Database Description flags. */
71 #define OSPF_DD_FLAG_MS 0x01
72 #define OSPF_DD_FLAG_M 0x02
73 #define OSPF_DD_FLAG_I 0x04
74 #define OSPF_DD_FLAG_ALL 0x07
76 #define OSPF_LS_REFRESH_SHIFT (60 * 15)
77 #define OSPF_LS_REFRESH_JITTER 60
79 /* OSPF master for system wide configuration and variables. */
85 /* OSPF thread master. */
86 struct thread_master
*master
;
88 /* Zebra interface list. */
91 /* Redistributed external information. */
92 struct route_table
*external_info
[ZEBRA_ROUTE_MAX
+ 1];
93 #define EXTERNAL_INFO(T) om->external_info[T]
95 /* OSPF start time. */
98 /* Various OSPF global configuration. */
100 #define OSPF_MASTER_SHUTDOWN (1 << 0) /* deferred-shutdown */
103 /* OSPF instance structure. */
106 /* OSPF Router ID. */
107 struct in_addr router_id
; /* Configured automatically. */
108 struct in_addr router_id_static
; /* Configured manually. */
110 /* ABR/ASBR internal flags. */
112 #define OSPF_FLAG_ABR 0x0001
113 #define OSPF_FLAG_ASBR 0x0002
117 #define OSPF_ABR_UNKNOWN 0
118 #define OSPF_ABR_STAND 1
119 #define OSPF_ABR_IBM 2
120 #define OSPF_ABR_CISCO 3
121 #define OSPF_ABR_SHORTCUT 4
122 #define OSPF_ABR_DEFAULT OSPF_ABR_CISCO
125 u_char anyNSSA
; /* Bump for every NSSA attached. */
127 /* Configured variables. */
129 #define OSPF_RFC1583_COMPATIBLE (1 << 0)
130 #define OSPF_OPAQUE_CAPABLE (1 << 2)
131 #define OSPF_LOG_ADJACENCY_CHANGES (1 << 3)
132 #define OSPF_LOG_ADJACENCY_DETAIL (1 << 4)
134 #ifdef HAVE_OPAQUE_LSA
135 /* Opaque-LSA administrative flags. */
137 #define OPAQUE_OPERATION_READY_BIT (1 << 0)
138 #define OPAQUE_BLOCK_TYPE_09_LSA_BIT (1 << 1)
139 #define OPAQUE_BLOCK_TYPE_10_LSA_BIT (1 << 2)
140 #define OPAQUE_BLOCK_TYPE_11_LSA_BIT (1 << 3)
141 #endif /* HAVE_OPAQUE_LSA */
143 /* RFC3137 stub router. Configured time to stay stub / max-metric */
144 unsigned int stub_router_startup_time
; /* seconds */
145 unsigned int stub_router_shutdown_time
; /* seconds */
146 #define OSPF_STUB_ROUTER_UNCONFIGURED 0
147 u_char stub_router_admin_set
;
148 #define OSPF_STUB_ROUTER_ADMINISTRATIVE_SET 1
149 #define OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET 0
151 #define OSPF_STUB_MAX_METRIC_SUMMARY_COST 0x00ff0000
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 */
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. */
170 struct list
*oiflist
; /* ospf interfaces */
171 u_char passive_interface_default
; /* passive-interface default */
173 /* LSDB of AS-external-LSAs. */
174 struct ospf_lsdb
*lsdb
;
177 int external_origin
; /* AS-external-LSA origin flag. */
178 int ase_calc
; /* ASE calculation flag. */
180 #ifdef HAVE_OPAQUE_LSA
181 struct list
*opaque_lsa_self
; /* Type-11 Opaque-LSAs */
182 #endif /* HAVE_OPAQUE_LSA */
184 /* Routing tables. */
185 struct route_table
*old_table
; /* Old routing table. */
186 struct route_table
*new_table
; /* Current routing table. */
188 struct route_table
*old_rtrs
; /* Old ABR/ASBR RT. */
189 struct route_table
*new_rtrs
; /* New ABR/ASBR RT. */
191 struct route_table
*new_external_route
; /* New External Route. */
192 struct route_table
*old_external_route
; /* Old External Route. */
194 struct route_table
*external_lsas
; /* Database of external LSAs,
195 prefix is LSA's adv. network*/
198 struct timeval ts_spf
; /* SPF calculation time stamp. */
200 struct route_table
*maxage_lsa
; /* List of MaxAge LSA for deletion. */
201 int redistribute
; /* Num of redistributed protocols. */
204 struct thread
*t_abr_task
; /* ABR task timer. */
205 struct thread
*t_asbr_check
; /* ASBR check timer. */
206 struct thread
*t_distribute_update
; /* Distirbute list update timer. */
207 struct thread
*t_spf_calc
; /* SPF calculation timer. */
208 struct thread
*t_ase_calc
; /* ASE calculation timer. */
209 struct thread
*t_external_lsa
; /* AS-external-LSA origin timer. */
210 #ifdef HAVE_OPAQUE_LSA
211 struct thread
*t_opaque_lsa_self
; /* Type-11 Opaque-LSAs origin event. */
212 #endif /* HAVE_OPAQUE_LSA */
214 #define OSFP_LSA_MAXAGE_REMOVE_DELAY_DEFAULT 60
215 unsigned int maxage_delay
; /* Delay on Maxage remover timer, sec */
216 struct thread
*t_maxage
; /* MaxAge LSA remover timer. */
217 #define OSPF_LSA_MAXAGE_CHECK_INTERVAL 30
218 struct thread
*t_maxage_walker
; /* MaxAge LSA checking timer. */
220 struct thread
*t_deferred_shutdown
; /* deferred/stub-router shutdown timer*/
222 struct thread
*t_write
;
223 struct thread
*t_read
;
225 unsigned int maxsndbuflen
;
227 struct list
*oi_write_q
;
229 /* Distribute lists out of other route sources. */
233 struct access_list
*list
;
234 } dlist
[ZEBRA_ROUTE_MAX
];
235 #define DISTRIBUTE_NAME(O,T) (O)->dlist[T].name
236 #define DISTRIBUTE_LIST(O,T) (O)->dlist[T].list
238 /* Redistribute metric info. */
241 int type
; /* External metric type (E1 or E2). */
242 int value
; /* Value for static metric (24-bit).
243 -1 means metric value is not set. */
244 } dmetric
[ZEBRA_ROUTE_MAX
+ 1];
246 /* For redistribute route map. */
250 struct route_map
*map
;
251 } route_map
[ZEBRA_ROUTE_MAX
+ 1]; /* +1 is for default-information */
252 #define ROUTEMAP_NAME(O,T) (O)->route_map[T].name
253 #define ROUTEMAP(O,T) (O)->route_map[T].map
255 int default_metric
; /* Default metric for redistribute. */
257 #define OSPF_LSA_REFRESHER_GRANULARITY 10
258 #define OSPF_LSA_REFRESHER_SLOTS ((OSPF_LS_REFRESH_TIME + \
259 OSPF_LS_REFRESH_SHIFT)/10 + 1)
263 struct list
*qs
[OSPF_LSA_REFRESHER_SLOTS
];
266 struct thread
*t_lsa_refresher
;
267 time_t lsa_refresher_started
;
268 #define OSPF_LSA_REFRESH_INTERVAL_DEFAULT 10
269 u_int16_t lsa_refresh_interval
;
271 /* Distance parameter. */
273 u_char distance_intra
;
274 u_char distance_inter
;
275 u_char distance_external
;
277 /* Statistics for LSA origination. */
278 u_int32_t lsa_originate_count
;
280 /* Statistics for LSA used for new instantiation. */
281 u_int32_t rx_lsa_count
;
283 struct route_table
*distance_table
;
286 /* OSPF area structure. */
292 /* Zebra interface list belonging to the area. */
293 struct list
*oiflist
;
296 struct in_addr area_id
;
298 /* Area ID format. */
300 #define OSPF_AREA_ID_FORMAT_ADDRESS 1
301 #define OSPF_AREA_ID_FORMAT_DECIMAL 2
304 struct list
*address_range
;
306 /* Configured variables. */
307 int external_routing
; /* ExternalRoutingCapability. */
308 #define OSPF_AREA_DEFAULT 0
309 #define OSPF_AREA_STUB 1
310 #define OSPF_AREA_NSSA 2
311 #define OSPF_AREA_TYPE_MAX 3
312 int no_summary
; /* Don't inject summaries into stub.*/
313 int shortcut_configured
; /* Area configured as shortcut. */
314 #define OSPF_SHORTCUT_DEFAULT 0
315 #define OSPF_SHORTCUT_ENABLE 1
316 #define OSPF_SHORTCUT_DISABLE 2
317 int shortcut_capability
; /* Other ABRs agree on S-bit */
318 u_int32_t default_cost
; /* StubDefaultCost. */
319 int auth_type
; /* Authentication type. */
322 u_char NSSATranslatorRole
; /* NSSA configured role */
323 #define OSPF_NSSA_ROLE_NEVER 0
324 #define OSPF_NSSA_ROLE_CANDIDATE 1
325 #define OSPF_NSSA_ROLE_ALWAYS 2
326 u_char NSSATranslatorState
; /* NSSA operational role */
327 #define OSPF_NSSA_TRANSLATE_DISABLED 0
328 #define OSPF_NSSA_TRANSLATE_ENABLED 1
329 int NSSATranslatorStabilityInterval
;
331 u_char transit
; /* TransitCapability. */
332 #define OSPF_TRANSIT_FALSE 0
333 #define OSPF_TRANSIT_TRUE 1
334 struct route_table
*ranges
; /* Configured Area Ranges. */
336 /* RFC3137 stub router state flags for area */
337 u_char stub_router_state
;
338 #define OSPF_AREA_ADMIN_STUB_ROUTED (1 << 0) /* admin stub-router set */
339 #define OSPF_AREA_IS_STUB_ROUTED (1 << 1) /* stub-router active */
340 #define OSPF_AREA_WAS_START_STUB_ROUTED (1 << 2) /* startup SR was done */
342 /* Area related LSDBs[Type1-4]. */
343 struct ospf_lsdb
*lsdb
;
345 /* Self-originated LSAs. */
346 struct ospf_lsa
*router_lsa_self
;
347 #ifdef HAVE_OPAQUE_LSA
348 struct list
*opaque_lsa_self
; /* Type-10 Opaque-LSAs */
349 #endif /* HAVE_OPAQUE_LSA */
351 /* Area announce list. */
355 struct access_list
*list
;
357 #define EXPORT_NAME(A) (A)->_export.name
358 #define EXPORT_LIST(A) (A)->_export.list
360 /* Area acceptance list. */
364 struct access_list
*list
;
366 #define IMPORT_NAME(A) (A)->import.name
367 #define IMPORT_LIST(A) (A)->import.list
369 /* Type 3 LSA Area prefix-list. */
373 struct prefix_list
*list
;
375 #define PREFIX_LIST_IN(A) (A)->plist_in.list
376 #define PREFIX_NAME_IN(A) (A)->plist_in.name
381 struct prefix_list
*list
;
383 #define PREFIX_LIST_OUT(A) (A)->plist_out.list
384 #define PREFIX_NAME_OUT(A) (A)->plist_out.name
386 /* Shortest Path Tree. */
390 struct thread
*t_stub_router
; /* Stub-router timer */
391 #ifdef HAVE_OPAQUE_LSA
392 struct thread
*t_opaque_lsa_self
; /* Type-10 Opaque-LSAs origin. */
393 #endif /* HAVE_OPAQUE_LSA */
395 /* Statistics field. */
396 u_int32_t spf_calculation
; /* SPF Calculation Count. */
399 u_int32_t abr_count
; /* ABR router in this area. */
400 u_int32_t asbr_count
; /* ASBR router in this area. */
403 u_int32_t act_ints
; /* Active interfaces. */
404 u_int32_t full_nbrs
; /* Fully adjacent neighbors. */
405 u_int32_t full_vls
; /* Fully adjacent virtual neighbors. */
408 /* OSPF config network structure. */
412 struct in_addr area_id
;
416 /* OSPF NBMA neighbor structure. */
419 /* Neighbor IP address. */
422 /* OSPF interface. */
423 struct ospf_interface
*oi
;
425 /* OSPF neighbor structure. */
426 struct ospf_neighbor
*nbr
;
428 /* Neighbor priority. */
431 /* Poll timer value. */
434 /* Poll timer thread. */
435 struct thread
*t_poll
;
438 u_int32_t state_change
;
442 #define OSPF_AREA_SAME(X,Y) \
443 (memcmp ((X->area_id), (Y->area_id), IPV4_MAX_BYTELEN) == 0)
445 #define IS_OSPF_ABR(O) ((O)->flags & OSPF_FLAG_ABR)
446 #define IS_OSPF_ASBR(O) ((O)->flags & OSPF_FLAG_ASBR)
448 #define OSPF_IS_AREA_ID_BACKBONE(I) ((I).s_addr == OSPF_AREA_BACKBONE)
449 #define OSPF_IS_AREA_BACKBONE(A) OSPF_IS_AREA_ID_BACKBONE ((A)->area_id)
452 # define ROUNDUP(val, gran) roundup(val, gran)
454 # define ROUNDUP(val, gran) (((val) - 1 | (gran) - 1) + 1)
457 #define LSA_OPTIONS_GET(area) \
458 (((area)->external_routing == OSPF_AREA_DEFAULT) ? OSPF_OPTION_E : 0)
459 #define LSA_OPTIONS_NSSA_GET(area) \
460 (((area)->external_routing == OSPF_AREA_NSSA) ? OSPF_OPTION_NP : 0)
462 #define OSPF_TIMER_ON(T,F,V) \
465 (T) = thread_add_timer (master, (F), ospf, (V)); \
468 #define OSPF_AREA_TIMER_ON(T,F,V) \
471 (T) = thread_add_timer (master, (F), area, (V)); \
474 #define OSPF_POLL_TIMER_ON(T,F,V) \
477 (T) = thread_add_timer (master, (F), nbr_nbma, (V)); \
480 #define OSPF_POLL_TIMER_OFF(X) OSPF_TIMER_OFF((X))
482 #define OSPF_TIMER_OFF(X) \
491 /* Extern variables. */
492 extern struct ospf_master
*om
;
493 extern const struct message ospf_ism_state_msg
[];
494 extern const struct message ospf_nsm_state_msg
[];
495 extern const struct message ospf_lsa_type_msg
[];
496 extern const struct message ospf_link_state_id_type_msg
[];
497 extern const struct message ospf_network_type_msg
[];
498 extern const int ospf_ism_state_msg_max
;
499 extern const int ospf_nsm_state_msg_max
;
500 extern const int ospf_lsa_type_msg_max
;
501 extern const int ospf_link_state_id_type_msg_max
;
502 extern const int ospf_redistributed_proto_max
;
503 extern const int ospf_network_type_msg_max
;
504 extern struct zclient
*zclient
;
505 extern struct thread_master
*master
;
506 extern int ospf_zlog
;
509 extern const char *ospf_redist_string(u_int route_type
);
510 extern struct ospf
*ospf_lookup (void);
511 extern struct ospf
*ospf_get (void);
512 extern void ospf_finish (struct ospf
*);
513 extern void ospf_router_id_update (struct ospf
*ospf
);
514 extern int ospf_network_set (struct ospf
*, struct prefix_ipv4
*,
516 extern int ospf_network_unset (struct ospf
*, struct prefix_ipv4
*,
518 extern int ospf_area_stub_set (struct ospf
*, struct in_addr
);
519 extern int ospf_area_stub_unset (struct ospf
*, struct in_addr
);
520 extern int ospf_area_no_summary_set (struct ospf
*, struct in_addr
);
521 extern int ospf_area_no_summary_unset (struct ospf
*, struct in_addr
);
522 extern int ospf_area_nssa_set (struct ospf
*, struct in_addr
);
523 extern int ospf_area_nssa_unset (struct ospf
*, struct in_addr
);
524 extern int ospf_area_nssa_translator_role_set (struct ospf
*, struct in_addr
,
526 extern int ospf_area_export_list_set (struct ospf
*, struct ospf_area
*,
528 extern int ospf_area_export_list_unset (struct ospf
*, struct ospf_area
*);
529 extern int ospf_area_import_list_set (struct ospf
*, struct ospf_area
*,
531 extern int ospf_area_import_list_unset (struct ospf
*, struct ospf_area
*);
532 extern int ospf_area_shortcut_set (struct ospf
*, struct ospf_area
*, int);
533 extern int ospf_area_shortcut_unset (struct ospf
*, struct ospf_area
*);
534 extern int ospf_timers_refresh_set (struct ospf
*, int);
535 extern int ospf_timers_refresh_unset (struct ospf
*);
536 extern int ospf_nbr_nbma_set (struct ospf
*, struct in_addr
);
537 extern int ospf_nbr_nbma_unset (struct ospf
*, struct in_addr
);
538 extern int ospf_nbr_nbma_priority_set (struct ospf
*, struct in_addr
, u_char
);
539 extern int ospf_nbr_nbma_priority_unset (struct ospf
*, struct in_addr
);
540 extern int ospf_nbr_nbma_poll_interval_set (struct ospf
*, struct in_addr
,
542 extern int ospf_nbr_nbma_poll_interval_unset (struct ospf
*, struct in_addr
);
543 extern void ospf_prefix_list_update (struct prefix_list
*);
544 extern void ospf_init (void);
545 extern void ospf_if_update (struct ospf
*, struct interface
*);
546 extern void ospf_ls_upd_queue_empty (struct ospf_interface
*);
547 extern void ospf_terminate (void);
548 extern void ospf_nbr_nbma_if_update (struct ospf
*, struct ospf_interface
*);
549 extern struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup (struct ospf
*,
551 extern struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup_next (struct ospf
*,
554 extern int ospf_oi_count (struct interface
*);
556 extern struct ospf_area
*ospf_area_get (struct ospf
*, struct in_addr
, int);
557 extern void ospf_area_check_free (struct ospf
*, struct in_addr
);
558 extern struct ospf_area
*ospf_area_lookup_by_area_id (struct ospf
*,
560 extern void ospf_area_add_if (struct ospf_area
*, struct ospf_interface
*);
561 extern void ospf_area_del_if (struct ospf_area
*, struct ospf_interface
*);
563 extern void ospf_route_map_init (void);
564 extern void ospf_snmp_init (void);
566 extern void ospf_master_init (void);
568 #endif /* _ZEBRA_OSPFD_H */