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 along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef _ZEBRA_OSPFD_H
23 #define _ZEBRA_OSPFD_H
33 #include "ospf_memory.h"
34 #include "ospf_dump_api.h"
36 #define OSPF_VERSION 2
38 /* VTY port number. */
39 #define OSPF_VTY_PORT 2604
41 /* IP TTL for OSPF protocol. */
43 #define OSPF_VL_IP_TTL 100
45 /* Default configuration file name for ospfd. */
46 #define OSPF_DEFAULT_CONFIG "ospfd.conf"
48 #define OSPF_NSSA_TRANS_STABLE_DEFAULT 40
50 #define OSPF_ALLSPFROUTERS 0xe0000005 /* 224.0.0.5 */
51 #define OSPF_ALLDROUTERS 0xe0000006 /* 224.0.0.6 */
53 /* OSPF Authentication Type. */
54 #define OSPF_AUTH_NULL 0
55 #define OSPF_AUTH_SIMPLE 1
56 #define OSPF_AUTH_CRYPTOGRAPHIC 2
57 /* For Interface authentication setting default */
58 #define OSPF_AUTH_NOTSET -1
59 /* For the consumption and sanity of the command handler */
60 /* DO NIOT REMOVE!!! Need to detect whether a value has
61 been given or not in VLink command handlers */
62 #define OSPF_AUTH_CMD_NOTSEEN -2
65 #define OSPF_OPTION_MT 0x01 /* M/T */
66 #define OSPF_OPTION_E 0x02
67 #define OSPF_OPTION_MC 0x04
68 #define OSPF_OPTION_NP 0x08
69 #define OSPF_OPTION_EA 0x10
70 #define OSPF_OPTION_DC 0x20
71 #define OSPF_OPTION_O 0x40
72 #define OSPF_OPTION_DN 0x80
74 /* OSPF Database Description flags. */
75 #define OSPF_DD_FLAG_MS 0x01
76 #define OSPF_DD_FLAG_M 0x02
77 #define OSPF_DD_FLAG_I 0x04
78 #define OSPF_DD_FLAG_ALL 0x07
80 #define OSPF_LS_REFRESH_SHIFT (60 * 15)
81 #define OSPF_LS_REFRESH_JITTER 60
83 struct ospf_external
{
85 struct route_table
*external_info
;
88 /* OSPF master for system wide configuration and variables. */
93 /* OSPF thread master. */
94 struct thread_master
*master
;
96 /* Various OSPF global configuration. */
98 #define OSPF_MASTER_SHUTDOWN (1 << 0) /* deferred-shutdown */
104 /* Redistribute metric info. */
106 int type
; /* External metric type (E1 or E2). */
107 int value
; /* Value for static metric (24-bit).
108 -1 means metric value is not set. */
111 /* For redistribute route map. */
114 struct route_map
*map
;
115 } route_map
; /* +1 is for default-information */
116 #define ROUTEMAP_NAME(R) (R->route_map.name)
117 #define ROUTEMAP(R) (R->route_map.map)
120 /* OSPF instance structure. */
122 /* OSPF's running state based on the '[no] router ospf [<instance>]'
126 /* OSPF instance ID */
129 /* OSPF Router ID. */
130 struct in_addr router_id
; /* Configured automatically. */
131 struct in_addr router_id_static
; /* Configured manually. */
132 struct in_addr router_id_zebra
;
134 vrf_id_t vrf_id
; /* VRF Id */
135 char *name
; /* VRF name */
137 /* ABR/ASBR internal flags. */
139 #define OSPF_FLAG_ABR 0x0001
140 #define OSPF_FLAG_ASBR 0x0002
144 #define OSPF_ABR_UNKNOWN 0
145 #define OSPF_ABR_STAND 1
146 #define OSPF_ABR_IBM 2
147 #define OSPF_ABR_CISCO 3
148 #define OSPF_ABR_SHORTCUT 4
149 #define OSPF_ABR_DEFAULT OSPF_ABR_CISCO
152 u_char anyNSSA
; /* Bump for every NSSA attached. */
154 /* Configured variables. */
156 #define OSPF_RFC1583_COMPATIBLE (1 << 0)
157 #define OSPF_OPAQUE_CAPABLE (1 << 2)
158 #define OSPF_LOG_ADJACENCY_CHANGES (1 << 3)
159 #define OSPF_LOG_ADJACENCY_DETAIL (1 << 4)
161 /* Opaque-LSA administrative flags. */
163 #define OPAQUE_OPERATION_READY_BIT (1 << 0)
165 /* RFC3137 stub router. Configured time to stay stub / max-metric */
166 unsigned int stub_router_startup_time
; /* seconds */
167 unsigned int stub_router_shutdown_time
; /* seconds */
169 /* clang-format off */
170 #define OSPF_STUB_ROUTER_UNCONFIGURED 0
171 u_char stub_router_admin_set
;
172 #define OSPF_STUB_ROUTER_ADMINISTRATIVE_SET 1
173 #define OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET 0
175 #define OSPF_STUB_MAX_METRIC_SUMMARY_COST 0x00ff0000
178 unsigned int min_ls_interval
; /* minimum delay between LSAs (in msec) */
179 unsigned int min_ls_arrival
; /* minimum interarrival time between LSAs
183 unsigned int spf_delay
; /* SPF delay time. */
184 unsigned int spf_holdtime
; /* SPF hold time. */
185 unsigned int spf_max_holdtime
; /* SPF maximum-holdtime */
187 spf_hold_multiplier
; /* Adaptive multiplier for hold time */
189 int default_originate
; /* Default information originate. */
191 /* clang-format off */
192 #define DEFAULT_ORIGINATE_NONE 0
193 #define DEFAULT_ORIGINATE_ZEBRA 1
194 #define DEFAULT_ORIGINATE_ALWAYS 2
195 u_int32_t ref_bandwidth
; /* Reference Bandwidth (Kbps). */
196 struct route_table
*networks
; /* OSPF config networks. */
197 struct list
*vlinks
; /* Configured Virtual-Links. */
198 struct list
*areas
; /* OSPF areas. */
199 struct route_table
*nbr_nbma
;
200 struct ospf_area
*backbone
; /* Pointer to the Backbone Area. */
202 struct list
*oiflist
; /* ospf interfaces */
203 u_char passive_interface_default
; /* passive-interface default */
205 /* LSDB of AS-external-LSAs. */
206 struct ospf_lsdb
*lsdb
;
209 int external_origin
; /* AS-external-LSA origin flag. */
210 int ase_calc
; /* ASE calculation flag. */
212 struct list
*opaque_lsa_self
; /* Type-11 Opaque-LSAs */
214 /* Routing tables. */
215 struct route_table
*old_table
; /* Old routing table. */
216 struct route_table
*new_table
; /* Current routing table. */
218 struct route_table
*old_rtrs
; /* Old ABR/ASBR RT. */
219 struct route_table
*new_rtrs
; /* New ABR/ASBR RT. */
221 struct route_table
*new_external_route
; /* New External Route. */
222 struct route_table
*old_external_route
; /* Old External Route. */
224 struct route_table
*external_lsas
; /* Database of external LSAs,
225 prefix is LSA's adv. network*/
228 struct timeval ts_spf
; /* SPF calculation time stamp. */
229 struct timeval ts_spf_duration
; /* Execution time of last SPF */
231 struct route_table
*maxage_lsa
; /* List of MaxAge LSA for deletion. */
232 int redistribute
; /* Num of redistributed protocols. */
235 struct thread
*t_abr_task
; /* ABR task timer. */
236 struct thread
*t_asbr_check
; /* ASBR check timer. */
237 struct thread
*t_distribute_update
; /* Distirbute list update timer. */
238 struct thread
*t_spf_calc
; /* SPF calculation timer. */
239 struct thread
*t_ase_calc
; /* ASE calculation timer. */
240 struct thread
*t_external_lsa
; /* AS-external-LSA origin timer. */
242 *t_opaque_lsa_self
; /* Type-11 Opaque-LSAs origin event. */
244 unsigned int maxage_delay
; /* Delay on Maxage remover timer, sec */
245 struct thread
*t_maxage
; /* MaxAge LSA remover timer. */
246 struct thread
*t_maxage_walker
; /* MaxAge LSA checking timer. */
249 *t_deferred_shutdown
; /* deferred/stub-router shutdown timer*/
251 struct thread
*t_write
;
252 #define OSPF_WRITE_INTERFACE_COUNT_DEFAULT 20
253 int write_oi_count
; /* Num of packets sent per thread invocation */
254 struct thread
*t_read
;
257 struct list
*oi_write_q
;
259 /* Distribute lists out of other route sources. */
262 struct access_list
*list
;
263 } dlist
[ZEBRA_ROUTE_MAX
];
264 #define DISTRIBUTE_NAME(O,T) (O)->dlist[T].name
265 #define DISTRIBUTE_LIST(O,T) (O)->dlist[T].list
267 /* OSPF redistribute configuration */
268 struct list
*redist
[ZEBRA_ROUTE_MAX
+ 1];
270 /* Redistribute tag info. */
272 dtag
[ZEBRA_ROUTE_MAX
+ 1]; // Pending: cant configure as of now
274 int default_metric
; /* Default metric for redistribute. */
276 #define OSPF_LSA_REFRESHER_GRANULARITY 10
277 #define OSPF_LSA_REFRESHER_SLOTS \
278 ((OSPF_LS_REFRESH_TIME + OSPF_LS_REFRESH_SHIFT) \
279 / OSPF_LSA_REFRESHER_GRANULARITY \
283 struct list
*qs
[OSPF_LSA_REFRESHER_SLOTS
];
286 struct thread
*t_lsa_refresher
;
287 time_t lsa_refresher_started
;
288 #define OSPF_LSA_REFRESH_INTERVAL_DEFAULT 10
289 u_int16_t lsa_refresh_interval
;
291 /* Distance parameter. */
293 u_char distance_intra
;
294 u_char distance_inter
;
295 u_char distance_external
;
297 /* Statistics for LSA origination. */
298 u_int32_t lsa_originate_count
;
300 /* Statistics for LSA used for new instantiation. */
301 u_int32_t rx_lsa_count
;
303 /* Counter of "ip ospf area x.x.x.x" */
304 u_int32_t if_ospf_cli_count
;
306 struct route_table
*distance_table
;
308 /* Used during ospf instance going down send LSDB
309 * update to neighbors immediatly */
310 uint8_t inst_shutdown
;
312 /* Redistributed external information. */
313 struct list
*external
[ZEBRA_ROUTE_MAX
+ 1];
314 #define EXTERNAL_INFO(E) (E->external_info)
318 DECLARE_QOBJ_TYPE(ospf
)
320 /* OSPF area structure. */
325 /* Zebra interface list belonging to the area. */
326 struct list
*oiflist
;
329 struct in_addr area_id
;
331 /* Area ID format. */
333 #define OSPF_AREA_ID_FMT_DOTTEDQUAD 1
334 #define OSPF_AREA_ID_FMT_DECIMAL 2
337 struct list
*address_range
;
339 /* Configured variables. */
340 int external_routing
; /* ExternalRoutingCapability. */
341 int no_summary
; /* Don't inject summaries into stub.*/
342 int shortcut_configured
; /* Area configured as shortcut. */
344 /* clang-format off */
345 #define OSPF_SHORTCUT_DEFAULT 0
346 #define OSPF_SHORTCUT_ENABLE 1
347 #define OSPF_SHORTCUT_DISABLE 2
348 int shortcut_capability
; /* Other ABRs agree on S-bit */
349 u_int32_t default_cost
; /* StubDefaultCost. */
350 int auth_type
; /* Authentication type. */
353 u_char NSSATranslatorRole
; /* NSSA configured role */
355 /* clang-format off */
356 #define OSPF_NSSA_ROLE_NEVER 0
357 #define OSPF_NSSA_ROLE_CANDIDATE 1
358 #define OSPF_NSSA_ROLE_ALWAYS 2
359 u_char NSSATranslatorState
; /* NSSA operational role */
361 /* clang-format off */
362 #define OSPF_NSSA_TRANSLATE_DISABLED 0
363 #define OSPF_NSSA_TRANSLATE_ENABLED 1
364 int NSSATranslatorStabilityInterval
;
366 u_char transit
; /* TransitCapability. */
368 /* clang-format off */
369 #define OSPF_TRANSIT_FALSE 0
370 #define OSPF_TRANSIT_TRUE 1
371 struct route_table
*ranges
; /* Configured Area Ranges. */
373 /* RFC3137 stub router state flags for area */
374 u_char stub_router_state
;
375 #define OSPF_AREA_ADMIN_STUB_ROUTED (1 << 0) /* admin stub-router set */
376 #define OSPF_AREA_IS_STUB_ROUTED (1 << 1) /* stub-router active */
377 #define OSPF_AREA_WAS_START_STUB_ROUTED (1 << 2) /* startup SR was done */
378 /* Area related LSDBs[Type1-4]. */
379 struct ospf_lsdb
*lsdb
;
381 /* Self-originated LSAs. */
382 struct ospf_lsa
*router_lsa_self
;
383 struct list
*opaque_lsa_self
; /* Type-10 Opaque-LSAs */
385 /* Area announce list. */
388 struct access_list
*list
;
390 #define EXPORT_NAME(A) (A)->_export.name
391 #define EXPORT_LIST(A) (A)->_export.list
393 /* Area acceptance list. */
396 struct access_list
*list
;
398 #define IMPORT_NAME(A) (A)->import.name
399 #define IMPORT_LIST(A) (A)->import.list
401 /* Type 3 LSA Area prefix-list. */
404 struct prefix_list
*list
;
406 #define PREFIX_LIST_IN(A) (A)->plist_in.list
407 #define PREFIX_NAME_IN(A) (A)->plist_in.name
411 struct prefix_list
*list
;
413 #define PREFIX_LIST_OUT(A) (A)->plist_out.list
414 #define PREFIX_NAME_OUT(A) (A)->plist_out.name
416 /* Shortest Path Tree. */
420 struct thread
*t_stub_router
; /* Stub-router timer */
421 struct thread
*t_opaque_lsa_self
; /* Type-10 Opaque-LSAs origin. */
423 /* Statistics field. */
424 u_int32_t spf_calculation
; /* SPF Calculation Count. */
427 struct timeval ts_spf
; /* SPF calculation time stamp. */
430 u_int32_t abr_count
; /* ABR router in this area. */
431 u_int32_t asbr_count
; /* ASBR router in this area. */
434 u_int32_t act_ints
; /* Active interfaces. */
435 u_int32_t full_nbrs
; /* Fully adjacent neighbors. */
436 u_int32_t full_vls
; /* Fully adjacent virtual neighbors. */
439 /* OSPF config network structure. */
440 struct ospf_network
{
442 struct in_addr area_id
;
446 /* OSPF NBMA neighbor structure. */
447 struct ospf_nbr_nbma
{
448 /* Neighbor IP address. */
451 /* OSPF interface. */
452 struct ospf_interface
*oi
;
454 /* OSPF neighbor structure. */
455 struct ospf_neighbor
*nbr
;
457 /* Neighbor priority. */
460 /* Poll timer value. */
463 /* Poll timer thread. */
464 struct thread
*t_poll
;
467 u_int32_t state_change
;
471 #define OSPF_AREA_SAME(X, Y) \
472 (memcmp((X->area_id), (Y->area_id), IPV4_MAX_BYTELEN) == 0)
474 #define IS_OSPF_ABR(O) ((O)->flags & OSPF_FLAG_ABR)
475 #define IS_OSPF_ASBR(O) ((O)->flags & OSPF_FLAG_ASBR)
477 #define OSPF_IS_AREA_ID_BACKBONE(I) ((I).s_addr == OSPF_AREA_BACKBONE)
478 #define OSPF_IS_AREA_BACKBONE(A) OSPF_IS_AREA_ID_BACKBONE ((A)->area_id)
481 # define ROUNDUP(val, gran) roundup(val, gran)
483 # define ROUNDUP(val, gran) (((val) - 1 | (gran) - 1) + 1)
486 #define LSA_OPTIONS_GET(area) \
487 (((area)->external_routing == OSPF_AREA_DEFAULT) ? OSPF_OPTION_E : 0)
488 #define LSA_OPTIONS_NSSA_GET(area) \
489 (((area)->external_routing == OSPF_AREA_NSSA) ? OSPF_OPTION_NP : 0)
491 #define OSPF_TIMER_ON(T,F,V) thread_add_timer (master,(F),ospf,(V),&(T))
492 #define OSPF_AREA_TIMER_ON(T,F,V) thread_add_timer (master, (F), area, (V), &(T))
493 #define OSPF_POLL_TIMER_ON(T,F,V) thread_add_timer (master, (F), nbr_nbma, (V), &(T))
494 #define OSPF_POLL_TIMER_OFF(X) OSPF_TIMER_OFF((X))
495 #define OSPF_TIMER_OFF(X) \
503 /* Extern variables. */
504 extern struct ospf_master
*om
;
505 extern const int ospf_redistributed_proto_max
;
506 extern struct zclient
*zclient
;
507 extern struct thread_master
*master
;
508 extern int ospf_zlog
;
509 extern struct zebra_privs_t ospfd_privs
;
512 extern const char *ospf_redist_string(u_int route_type
);
513 extern struct ospf
*ospf_lookup_instance(u_short
);
514 extern struct ospf
*ospf_get(u_short instance
, const char *name
);
515 extern struct ospf
*ospf_get_instance(u_short
);
516 extern struct ospf
*ospf_lookup_by_inst_name(u_short instance
,
518 extern struct ospf
*ospf_lookup_by_vrf_id(vrf_id_t vrf_id
);
519 extern void ospf_finish(struct ospf
*);
520 extern void ospf_router_id_update(struct ospf
*ospf
);
521 extern int ospf_network_set(struct ospf
*, struct prefix_ipv4
*, struct in_addr
,
523 extern int ospf_network_unset(struct ospf
*, struct prefix_ipv4
*,
525 extern int ospf_area_display_format_set(struct ospf
*, struct ospf_area
*area
,
527 extern int ospf_area_stub_set(struct ospf
*, struct in_addr
);
528 extern int ospf_area_stub_unset(struct ospf
*, struct in_addr
);
529 extern int ospf_area_no_summary_set(struct ospf
*, struct in_addr
);
530 extern int ospf_area_no_summary_unset(struct ospf
*, struct in_addr
);
531 extern int ospf_area_nssa_set(struct ospf
*, struct in_addr
);
532 extern int ospf_area_nssa_unset(struct ospf
*, struct in_addr
, int);
533 extern int ospf_area_nssa_translator_role_set(struct ospf
*, struct in_addr
,
535 extern int ospf_area_export_list_set(struct ospf
*, struct ospf_area
*,
537 extern int ospf_area_export_list_unset(struct ospf
*, struct ospf_area
*);
538 extern int ospf_area_import_list_set(struct ospf
*, struct ospf_area
*,
540 extern int ospf_area_import_list_unset(struct ospf
*, struct ospf_area
*);
541 extern int ospf_area_shortcut_set(struct ospf
*, struct ospf_area
*, int);
542 extern int ospf_area_shortcut_unset(struct ospf
*, struct ospf_area
*);
543 extern int ospf_timers_refresh_set(struct ospf
*, int);
544 extern int ospf_timers_refresh_unset(struct ospf
*);
545 extern int ospf_nbr_nbma_set(struct ospf
*, struct in_addr
);
546 extern int ospf_nbr_nbma_unset(struct ospf
*, struct in_addr
);
547 extern int ospf_nbr_nbma_priority_set(struct ospf
*, struct in_addr
, u_char
);
548 extern int ospf_nbr_nbma_priority_unset(struct ospf
*, struct in_addr
);
549 extern int ospf_nbr_nbma_poll_interval_set(struct ospf
*, struct in_addr
,
551 extern int ospf_nbr_nbma_poll_interval_unset(struct ospf
*, struct in_addr
);
552 extern void ospf_prefix_list_update(struct prefix_list
*);
553 extern void ospf_init(void);
554 extern void ospf_if_update(struct ospf
*, struct interface
*);
555 extern void ospf_ls_upd_queue_empty(struct ospf_interface
*);
556 extern void ospf_terminate(void);
557 extern void ospf_nbr_nbma_if_update(struct ospf
*, struct ospf_interface
*);
558 extern struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup(struct ospf
*,
560 extern struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup_next(struct ospf
*,
561 struct in_addr
*, int);
562 extern int ospf_oi_count(struct interface
*);
564 extern struct ospf_area
*ospf_area_get(struct ospf
*, struct in_addr
);
565 extern void ospf_area_check_free(struct ospf
*, struct in_addr
);
566 extern struct ospf_area
*ospf_area_lookup_by_area_id(struct ospf
*,
568 extern void ospf_area_add_if(struct ospf_area
*, struct ospf_interface
*);
569 extern void ospf_area_del_if(struct ospf_area
*, struct ospf_interface
*);
571 extern void ospf_interface_area_set(struct ospf
*, struct interface
*);
572 extern void ospf_interface_area_unset(struct ospf
*, struct interface
*);
574 extern void ospf_route_map_init(void);
576 extern void ospf_master_init(struct thread_master
*master
);
577 extern void ospf_vrf_init(void);
578 extern void ospf_vrf_terminate(void);
579 extern void ospf_vrf_link(struct ospf
*ospf
, struct vrf
*vrf
);
580 extern void ospf_vrf_unlink(struct ospf
*ospf
, struct vrf
*vrf
);
581 const char *ospf_vrf_id_to_name(vrf_id_t vrf_id
);
582 int ospf_area_nssa_no_summary_set(struct ospf
*, struct in_addr
);
584 #endif /* _ZEBRA_OSPFD_H */