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_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
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
77 #define OSPF_LS_REFRESH_SHIFT (60 * 15)
78 #define OSPF_LS_REFRESH_JITTER 60
83 struct route_table
*external_info
;
86 /* OSPF master for system wide configuration and variables. */
92 /* OSPF thread master. */
93 struct thread_master
*master
;
95 /* Zebra interface list. */
98 /* Redistributed external information. */
99 struct list
*external
[ZEBRA_ROUTE_MAX
+ 1];
100 #define EXTERNAL_INFO(E) (E->external_info)
102 /* Various OSPF global configuration. */
104 #define OSPF_MASTER_SHUTDOWN (1 << 0) /* deferred-shutdown */
111 /* Redistribute metric info. */
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. */
119 /* For redistribute route map. */
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)
129 /* OSPF instance structure. */
132 /* OSPF's running state based on the '[no] router ospf [<instance>]' config. */
135 /* OSPF instance ID */
138 /* OSPF Router ID. */
139 struct in_addr router_id
; /* Configured automatically. */
140 struct in_addr router_id_static
; /* Configured manually. */
142 /* ABR/ASBR internal flags. */
144 #define OSPF_FLAG_ABR 0x0001
145 #define OSPF_FLAG_ASBR 0x0002
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
157 u_char anyNSSA
; /* Bump for every NSSA attached. */
159 /* Configured variables. */
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)
166 /* Opaque-LSA administrative flags. */
168 #define OPAQUE_OPERATION_READY_BIT (1 << 0)
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
178 #define OSPF_STUB_MAX_METRIC_SUMMARY_COST 0x00ff0000
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) */
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 */
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. */
201 struct list
*oiflist
; /* ospf interfaces */
202 u_char passive_interface_default
; /* passive-interface default */
204 /* LSDB of AS-external-LSAs. */
205 struct ospf_lsdb
*lsdb
;
208 int external_origin
; /* AS-external-LSA origin flag. */
209 int ase_calc
; /* ASE calculation flag. */
211 struct list
*opaque_lsa_self
; /* Type-11 Opaque-LSAs */
213 /* Routing tables. */
214 struct route_table
*old_table
; /* Old routing table. */
215 struct route_table
*new_table
; /* Current routing table. */
217 struct route_table
*old_rtrs
; /* Old ABR/ASBR RT. */
218 struct route_table
*new_rtrs
; /* New ABR/ASBR RT. */
220 struct route_table
*new_external_route
; /* New External Route. */
221 struct route_table
*old_external_route
; /* Old External Route. */
223 struct route_table
*external_lsas
; /* Database of external LSAs,
224 prefix is LSA's adv. network*/
227 struct timeval ts_spf
; /* SPF calculation time stamp. */
228 struct timeval ts_spf_duration
; /* Execution time of last SPF */
230 struct route_table
*maxage_lsa
; /* List of MaxAge LSA for deletion. */
231 int redistribute
; /* Num of redistributed protocols. */
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. */
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. */
246 struct thread
*t_deferred_shutdown
; /* deferred/stub-router shutdown timer*/
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
;
253 unsigned int maxsndbuflen
;
255 struct list
*oi_write_q
;
257 /* Distribute lists out of other route sources. */
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
266 /* OSPF redistribute configuration */
267 struct list
*redist
[ZEBRA_ROUTE_MAX
+ 1];
269 /* Redistribute tag info. */
270 u_short dtag
[ZEBRA_ROUTE_MAX
+ 1]; //Pending: cant configure as of now
272 int default_metric
; /* Default metric for redistribute. */
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)
280 struct list
*qs
[OSPF_LSA_REFRESHER_SLOTS
];
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
;
288 /* Distance parameter. */
290 u_char distance_intra
;
291 u_char distance_inter
;
292 u_char distance_external
;
294 /* Statistics for LSA origination. */
295 u_int32_t lsa_originate_count
;
297 /* Statistics for LSA used for new instantiation. */
298 u_int32_t rx_lsa_count
;
300 /* Counter of "ip ospf area x.x.x.x" */
301 u_int32_t if_ospf_cli_count
;
303 struct route_table
*distance_table
;
306 /* OSPF area structure. */
312 /* Zebra interface list belonging to the area. */
313 struct list
*oiflist
;
316 struct in_addr area_id
;
318 /* Area ID format. */
320 #define OSPF_AREA_ID_FORMAT_ADDRESS 1
321 #define OSPF_AREA_ID_FORMAT_DECIMAL 2
324 struct list
*address_range
;
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. */
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
;
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. */
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 */
358 /* Area related LSDBs[Type1-4]. */
359 struct ospf_lsdb
*lsdb
;
361 /* Self-originated LSAs. */
362 struct ospf_lsa
*router_lsa_self
;
363 struct list
*opaque_lsa_self
; /* Type-10 Opaque-LSAs */
365 /* Area announce list. */
369 struct access_list
*list
;
371 #define EXPORT_NAME(A) (A)->_export.name
372 #define EXPORT_LIST(A) (A)->_export.list
374 /* Area acceptance list. */
378 struct access_list
*list
;
380 #define IMPORT_NAME(A) (A)->import.name
381 #define IMPORT_LIST(A) (A)->import.list
383 /* Type 3 LSA Area prefix-list. */
387 struct prefix_list
*list
;
389 #define PREFIX_LIST_IN(A) (A)->plist_in.list
390 #define PREFIX_NAME_IN(A) (A)->plist_in.name
395 struct prefix_list
*list
;
397 #define PREFIX_LIST_OUT(A) (A)->plist_out.list
398 #define PREFIX_NAME_OUT(A) (A)->plist_out.name
400 /* Shortest Path Tree. */
404 struct thread
*t_stub_router
; /* Stub-router timer */
405 struct thread
*t_opaque_lsa_self
; /* Type-10 Opaque-LSAs origin. */
407 /* Statistics field. */
408 u_int32_t spf_calculation
; /* SPF Calculation Count. */
411 struct timeval ts_spf
; /* SPF calculation time stamp. */
414 u_int32_t abr_count
; /* ABR router in this area. */
415 u_int32_t asbr_count
; /* ASBR router in this area. */
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. */
423 /* OSPF config network structure. */
427 struct in_addr area_id
;
431 /* OSPF NBMA neighbor structure. */
434 /* Neighbor IP address. */
437 /* OSPF interface. */
438 struct ospf_interface
*oi
;
440 /* OSPF neighbor structure. */
441 struct ospf_neighbor
*nbr
;
443 /* Neighbor priority. */
446 /* Poll timer value. */
449 /* Poll timer thread. */
450 struct thread
*t_poll
;
453 u_int32_t state_change
;
457 #define OSPF_AREA_SAME(X,Y) \
458 (memcmp ((X->area_id), (Y->area_id), IPV4_MAX_BYTELEN) == 0)
460 #define IS_OSPF_ABR(O) ((O)->flags & OSPF_FLAG_ABR)
461 #define IS_OSPF_ASBR(O) ((O)->flags & OSPF_FLAG_ASBR)
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)
467 # define ROUNDUP(val, gran) roundup(val, gran)
469 # define ROUNDUP(val, gran) (((val) - 1 | (gran) - 1) + 1)
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)
477 #define OSPF_TIMER_ON(T,F,V) \
480 (T) = thread_add_timer (master, (F), ospf, (V)); \
483 #define OSPF_AREA_TIMER_ON(T,F,V) \
486 (T) = thread_add_timer (master, (F), area, (V)); \
489 #define OSPF_POLL_TIMER_ON(T,F,V) \
492 (T) = thread_add_timer (master, (F), nbr_nbma, (V)); \
495 #define OSPF_POLL_TIMER_OFF(X) OSPF_TIMER_OFF((X))
497 #define OSPF_TIMER_OFF(X) \
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
;
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
*,
533 extern int ospf_network_unset (struct ospf
*, struct prefix_ipv4
*,
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
,
543 extern int ospf_area_export_list_set (struct ospf
*, struct ospf_area
*,
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
*,
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
,
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
*,
568 extern struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup_next (struct ospf
*,
571 extern int ospf_oi_count (struct interface
*);
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
*,
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
*);
580 extern void ospf_route_map_init (void);
581 extern void ospf_snmp_init (void);
583 extern void ospf_master_init (void);
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 */