1 /* OSPF version 2 daemon program.
2 Copyright (C) 1999, 2000 Toshiaki Takada
4 This file is part of GNU Zebra.
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
33 #include "sockunion.h" /* for inet_aton () */
39 #include "ospfd/ospfd.h"
40 #include "ospfd/ospf_network.h"
41 #include "ospfd/ospf_interface.h"
42 #include "ospfd/ospf_ism.h"
43 #include "ospfd/ospf_asbr.h"
44 #include "ospfd/ospf_lsa.h"
45 #include "ospfd/ospf_lsdb.h"
46 #include "ospfd/ospf_neighbor.h"
47 #include "ospfd/ospf_nsm.h"
48 #include "ospfd/ospf_spf.h"
49 #include "ospfd/ospf_packet.h"
50 #include "ospfd/ospf_dump.h"
51 #include "ospfd/ospf_zebra.h"
52 #include "ospfd/ospf_abr.h"
53 #include "ospfd/ospf_flood.h"
54 #include "ospfd/ospf_route.h"
55 #include "ospfd/ospf_ase.h"
59 /* OSPF process wide configuration. */
60 static struct ospf_master ospf_master
;
62 /* OSPF process wide configuration pointer to export. */
63 struct ospf_master
*om
;
65 extern struct zclient
*zclient
;
66 extern struct in_addr router_id_zebra
;
69 static void ospf_remove_vls_through_area (struct ospf
*, struct ospf_area
*);
70 static void ospf_network_free (struct ospf
*, struct ospf_network
*);
71 static void ospf_area_free (struct ospf_area
*);
72 static void ospf_network_run (struct prefix
*, struct ospf_area
*);
73 static void ospf_network_run_interface (struct prefix
*, struct ospf_area
*,
75 static int ospf_network_match_iface (const struct connected
*,
76 const struct prefix
*);
77 static void ospf_finish_final (struct ospf
*);
79 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
82 ospf_router_id_update (struct ospf
*ospf
)
84 struct in_addr router_id
, router_id_old
;
85 struct ospf_interface
*oi
;
86 struct interface
*ifp
;
87 struct listnode
*node
;
90 if (!ospf
->oi_running
)
92 if (IS_DEBUG_OSPF_EVENT
)
93 zlog_debug ("Router ospf not configured -- Router-ID update postponed");
97 if (IS_DEBUG_OSPF_EVENT
)
98 zlog_debug ("Router-ID[OLD:%s]: Update", inet_ntoa (ospf
->router_id
));
100 router_id_old
= ospf
->router_id
;
102 /* Select the router ID based on these priorities:
103 1. Statically assigned router ID is always the first choice.
104 2. If there is no statically assigned router ID, then try to stick
105 with the most recent value, since changing router ID's is very
107 3. Last choice: just go with whatever the zebra daemon recommends.
109 if (ospf
->router_id_static
.s_addr
!= 0)
110 router_id
= ospf
->router_id_static
;
111 else if (ospf
->router_id
.s_addr
!= 0)
112 router_id
= ospf
->router_id
;
114 router_id
= router_id_zebra
;
117 if (!IPV4_ADDR_SAME (&router_id_old
, &router_id
))
120 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
122 /* Some nbrs are identified by router_id, these needs
123 * to be rebuilt. Possible optimization would be to do
124 * oi->nbr_self->router_id = router_id for
125 * !(virtual | ptop) links
127 ospf_nbr_self_reset (oi
, router_id
);
130 /* If AS-external-LSA is queued, then flush those LSAs. */
131 if (router_id_old
.s_addr
== 0 && ospf
->external_origin
)
133 /* Originate each redistributed external route. */
134 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
135 if (ospf
->external_origin
& (1 << type
))
136 thread_add_event (master
, ospf_external_lsa_originate_timer
,
138 /* Originate Deafult. */
139 if (ospf
->external_origin
& (1 << ZEBRA_ROUTE_MAX
))
140 thread_add_event (master
, ospf_default_originate_timer
, ospf
, 0);
142 ospf
->external_origin
= 0;
145 /* Flush (inline) all external LSAs based on the OSPF_LSA_SELF flag */
148 struct route_node
*rn
;
149 struct ospf_lsa
*lsa
;
151 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
152 if (IS_LSA_SELF(lsa
))
153 ospf_lsa_flush_schedule(ospf
, lsa
);
156 ospf
->router_id
= router_id
;
157 if (IS_DEBUG_OSPF_EVENT
)
158 zlog_debug ("Router-ID[NEW:%s]: Update", inet_ntoa (ospf
->router_id
));
160 /* Flush (inline) all external LSAs which now match the new router-id,
161 need to adjust the OSPF_LSA_SELF flag, so the flush doesnt hit
162 asserts in ospf_refresher_unregister_lsa(). This step is needed
163 because the current quagga code does look-up for self-originated LSAs
164 based on the self router-id alone but expects OSPF_LSA_SELF to be
168 struct route_node
*rn
;
169 struct ospf_lsa
*lsa
;
171 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
173 /* AdvRouter and Router ID is the same. */
174 if (IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &ospf
->router_id
))
176 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF_CHECKED
);
177 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
178 ospf_lsa_flush_schedule(ospf
, lsa
);
183 /* Originate each redistributed external route. */
184 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
185 thread_add_event (master
, ospf_external_lsa_originate_timer
,
187 thread_add_event (master
, ospf_default_originate_timer
, ospf
, 0);
189 /* update router-lsa's for each area */
190 ospf_router_lsa_update (ospf
);
192 /* update ospf_interface's */
193 for (ALL_LIST_ELEMENTS_RO (om
->iflist
, node
, ifp
))
194 ospf_if_update (ospf
, ifp
);
198 /* For OSPF area sort by area id. */
200 ospf_area_id_cmp (struct ospf_area
*a1
, struct ospf_area
*a2
)
202 if (ntohl (a1
->area_id
.s_addr
) > ntohl (a2
->area_id
.s_addr
))
204 if (ntohl (a1
->area_id
.s_addr
) < ntohl (a2
->area_id
.s_addr
))
209 /* Allocate new ospf structure. */
211 ospf_new (u_short instance
)
215 struct ospf
*new = XCALLOC (MTYPE_OSPF_TOP
, sizeof (struct ospf
));
217 new->instance
= instance
;
218 new->router_id
.s_addr
= htonl (0);
219 new->router_id_static
.s_addr
= htonl (0);
221 new->abr_type
= OSPF_ABR_DEFAULT
;
222 new->oiflist
= list_new ();
223 new->vlinks
= list_new ();
224 new->areas
= list_new ();
225 new->areas
->cmp
= (int (*)(void *, void *)) ospf_area_id_cmp
;
226 new->networks
= route_table_init ();
227 new->nbr_nbma
= route_table_init ();
229 new->lsdb
= ospf_lsdb_new ();
231 new->default_originate
= DEFAULT_ORIGINATE_NONE
;
233 new->passive_interface_default
= OSPF_IF_ACTIVE
;
235 new->new_external_route
= route_table_init ();
236 new->old_external_route
= route_table_init ();
237 new->external_lsas
= route_table_init ();
239 new->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
240 new->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
241 new->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
243 /* Distribute parameter init. */
244 for (i
= 0; i
<= ZEBRA_ROUTE_MAX
; i
++)
248 new->default_metric
= -1;
249 new->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
252 new->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
253 new->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
255 /* SPF timer value init. */
256 new->spf_delay
= OSPF_SPF_DELAY_DEFAULT
;
257 new->spf_holdtime
= OSPF_SPF_HOLDTIME_DEFAULT
;
258 new->spf_max_holdtime
= OSPF_SPF_MAX_HOLDTIME_DEFAULT
;
259 new->spf_hold_multiplier
= 1;
262 new->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
263 new->maxage_lsa
= route_table_init();
264 new->t_maxage_walker
=
265 thread_add_timer (master
, ospf_lsa_maxage_walker
,
266 new, OSPF_LSA_MAXAGE_CHECK_INTERVAL
);
268 /* Distance table init. */
269 new->distance_table
= route_table_init ();
271 new->lsa_refresh_queue
.index
= 0;
272 new->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
273 new->t_lsa_refresher
= thread_add_timer (master
, ospf_lsa_refresh_walker
,
274 new, new->lsa_refresh_interval
);
275 new->lsa_refresher_started
= quagga_monotime ();
277 if ((new->fd
= ospf_sock_init()) < 0)
279 zlog_err("ospf_new: fatal error: ospf_sock_init was unable to open "
283 if ((new->ibuf
= stream_new(OSPF_MAX_PACKET_SIZE
+1)) == NULL
)
285 zlog_err("ospf_new: fatal error: stream_new(%u) failed allocating ibuf",
286 OSPF_MAX_PACKET_SIZE
+1);
289 new->t_read
= thread_add_read (master
, ospf_read
, new, new->fd
);
290 new->oi_write_q
= list_new ();
291 new->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
293 /* Enable "log-adjacency-changes" */
294 SET_FLAG(new->config
, OSPF_LOG_ADJACENCY_CHANGES
);
301 if (listcount (om
->ospf
) == 0)
304 return listgetdata ((struct listnode
*)listhead (om
->ospf
));
308 ospf_lookup_instance (u_short instance
)
311 struct listnode
*node
, *nnode
;
313 if (listcount (om
->ospf
) == 0)
316 for (ALL_LIST_ELEMENTS (om
->ospf
, node
, nnode
, ospf
))
317 if ((ospf
->instance
== 0 && instance
== 0)
318 || (ospf
->instance
&& instance
&& ospf
->instance
== instance
))
325 ospf_add (struct ospf
*ospf
)
327 listnode_add (om
->ospf
, ospf
);
331 ospf_delete (struct ospf
*ospf
)
333 listnode_delete (om
->ospf
, ospf
);
341 ospf
= ospf_lookup ();
347 if (ospf
->router_id_static
.s_addr
== 0)
348 ospf_router_id_update (ospf
);
350 ospf_opaque_type11_lsa_init (ospf
);
357 ospf_get_instance (u_short instance
)
361 ospf
= ospf_lookup_instance (instance
);
364 ospf
= ospf_new (instance
);
367 if (ospf
->router_id_static
.s_addr
== 0)
368 ospf_router_id_update (ospf
);
370 ospf_opaque_type11_lsa_init (ospf
);
376 /* Handle the second half of deferred shutdown. This is called either
377 * from the deferred-shutdown timer thread, or directly through
378 * ospf_deferred_shutdown_check.
380 * Function is to cleanup G-R state, if required then call ospf_finish_final
381 * to complete shutdown of this ospf instance. Possibly exit if the
382 * whole process is being shutdown and this was the last OSPF instance.
385 ospf_deferred_shutdown_finish (struct ospf
*ospf
)
387 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
388 OSPF_TIMER_OFF (ospf
->t_deferred_shutdown
);
390 ospf_finish_final (ospf
);
392 /* *ospf is now invalid */
394 /* ospfd being shut-down? If so, was this the last ospf instance? */
395 if (CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
)
396 && (listcount (om
->ospf
) == 0))
404 /* Timer thread for G-R */
406 ospf_deferred_shutdown_timer (struct thread
*t
)
408 struct ospf
*ospf
= THREAD_ARG(t
);
410 ospf_deferred_shutdown_finish (ospf
);
415 /* Check whether deferred-shutdown must be scheduled, otherwise call
416 * down directly into second-half of instance shutdown.
419 ospf_deferred_shutdown_check (struct ospf
*ospf
)
421 unsigned long timeout
;
423 struct ospf_area
*area
;
425 /* deferred shutdown already running? */
426 if (ospf
->t_deferred_shutdown
)
429 /* Should we try push out max-metric LSAs? */
430 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
432 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, ln
, area
))
434 SET_FLAG (area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
436 if (!CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
437 ospf_router_lsa_update_area (area
);
439 timeout
= ospf
->stub_router_shutdown_time
;
443 /* No timer needed */
444 ospf_deferred_shutdown_finish (ospf
);
448 OSPF_TIMER_ON (ospf
->t_deferred_shutdown
, ospf_deferred_shutdown_timer
,
453 /* Shut down the entire process */
455 ospf_terminate (void)
458 struct listnode
*node
, *nnode
;
460 /* shutdown already in progress */
461 if (CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
))
464 SET_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
);
466 /* exit immediately if OSPF not actually running */
467 if (listcount(om
->ospf
) == 0)
471 for (ALL_LIST_ELEMENTS (om
->ospf
, node
, nnode
, ospf
))
474 /* Deliberately go back up, hopefully to thread scheduler, as
475 * One or more ospf_finish()'s may have deferred shutdown to a timer
481 ospf_finish (struct ospf
*ospf
)
483 /* let deferred shutdown decide */
484 ospf_deferred_shutdown_check (ospf
);
486 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
487 * deferred to expiry of G-S timer thread. Return back up, hopefully
488 * to thread scheduler.
493 /* Final cleanup of ospf instance */
495 ospf_finish_final (struct ospf
*ospf
)
497 struct route_node
*rn
;
498 struct ospf_nbr_nbma
*nbr_nbma
;
499 struct ospf_lsa
*lsa
;
500 struct interface
*ifp
;
501 struct ospf_interface
*oi
;
502 struct ospf_area
*area
;
503 struct ospf_vl_data
*vl_data
;
504 struct listnode
*node
, *nnode
;
506 u_short instance
= 0;
508 ospf_opaque_type11_lsa_term (ospf
);
510 /* be nice if this worked, but it doesn't */
511 /*ospf_flush_self_originated_lsas_now (ospf);*/
513 /* Unregister redistribution */
514 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
516 struct list
*red_list
;
517 struct ospf_redist
*red
;
519 red_list
= ospf
->redist
[i
];
523 for (ALL_LIST_ELEMENTS(red_list
, node
, nnode
, red
))
524 ospf_redistribute_unset (ospf
, i
, red
->instance
);
526 ospf_redistribute_default_unset (ospf
);
528 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
529 ospf_remove_vls_through_area (ospf
, area
);
531 for (ALL_LIST_ELEMENTS (ospf
->vlinks
, node
, nnode
, vl_data
))
532 ospf_vl_delete (ospf
, vl_data
);
534 list_delete (ospf
->vlinks
);
536 /* Remove any ospf interface config params */
537 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
539 struct ospf_if_params
*params
;
541 params
= IF_DEF_PARAMS (ifp
);
542 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
543 UNSET_IF_PARAM (params
, if_area
);
546 /* Reset interface. */
547 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
550 /* Clear static neighbors */
551 for (rn
= route_top (ospf
->nbr_nbma
); rn
; rn
= route_next (rn
))
552 if ((nbr_nbma
= rn
->info
))
554 OSPF_POLL_TIMER_OFF (nbr_nbma
->t_poll
);
558 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
559 nbr_nbma
->nbr
= NULL
;
564 listnode_delete (nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
568 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
571 route_table_finish (ospf
->nbr_nbma
);
573 /* Clear networks and Areas. */
574 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
576 struct ospf_network
*network
;
578 if ((network
= rn
->info
) != NULL
)
580 ospf_network_free (ospf
, network
);
582 route_unlock_node (rn
);
586 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
588 listnode_delete (ospf
->areas
, area
);
589 ospf_area_free (area
);
592 /* Cancel all timers. */
593 OSPF_TIMER_OFF (ospf
->t_external_lsa
);
594 OSPF_TIMER_OFF (ospf
->t_spf_calc
);
595 OSPF_TIMER_OFF (ospf
->t_ase_calc
);
596 OSPF_TIMER_OFF (ospf
->t_maxage
);
597 OSPF_TIMER_OFF (ospf
->t_maxage_walker
);
598 OSPF_TIMER_OFF (ospf
->t_abr_task
);
599 OSPF_TIMER_OFF (ospf
->t_asbr_check
);
600 OSPF_TIMER_OFF (ospf
->t_distribute_update
);
601 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
602 OSPF_TIMER_OFF (ospf
->t_read
);
603 OSPF_TIMER_OFF (ospf
->t_write
);
604 OSPF_TIMER_OFF (ospf
->t_opaque_lsa_self
);
607 stream_free(ospf
->ibuf
);
609 LSDB_LOOP (OPAQUE_AS_LSDB (ospf
), rn
, lsa
)
610 ospf_discard_from_db (ospf
, ospf
->lsdb
, lsa
);
611 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
612 ospf_discard_from_db (ospf
, ospf
->lsdb
, lsa
);
614 ospf_lsdb_delete_all (ospf
->lsdb
);
615 ospf_lsdb_free (ospf
->lsdb
);
617 for (rn
= route_top (ospf
->maxage_lsa
); rn
; rn
= route_next (rn
))
619 struct ospf_lsa
*lsa
;
621 if ((lsa
= rn
->info
) != NULL
)
623 ospf_lsa_unlock (&lsa
);
626 route_unlock_node (rn
);
628 route_table_finish (ospf
->maxage_lsa
);
631 ospf_route_table_free (ospf
->old_table
);
634 ospf_route_delete (ospf
->new_table
);
635 ospf_route_table_free (ospf
->new_table
);
638 ospf_rtrs_free (ospf
->old_rtrs
);
640 ospf_rtrs_free (ospf
->new_rtrs
);
641 if (ospf
->new_external_route
)
643 ospf_route_delete (ospf
->new_external_route
);
644 ospf_route_table_free (ospf
->new_external_route
);
646 if (ospf
->old_external_route
)
648 ospf_route_delete (ospf
->old_external_route
);
649 ospf_route_table_free (ospf
->old_external_route
);
651 if (ospf
->external_lsas
)
653 ospf_ase_external_lsas_finish (ospf
->external_lsas
);
656 list_delete (ospf
->areas
);
658 for (i
= ZEBRA_ROUTE_SYSTEM
; i
<= ZEBRA_ROUTE_MAX
; i
++)
660 struct list
*ext_list
;
661 struct listnode
*node
;
662 struct ospf_external
*ext
;
664 ext_list
= om
->external
[i
];
668 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
))
670 if (ext
->external_info
)
671 for (rn
= route_top (ext
->external_info
); rn
; rn
= route_next (rn
))
673 if (rn
->info
== NULL
)
676 XFREE (MTYPE_OSPF_EXTERNAL_INFO
, rn
->info
);
678 route_unlock_node (rn
);
683 ospf_distance_reset (ospf
);
684 route_table_finish (ospf
->distance_table
);
686 if (!CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
))
687 instance
= ospf
->instance
;
691 XFREE (MTYPE_OSPF_TOP
, ospf
);
693 if (!CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
))
694 ospf_get_instance(instance
);
699 /* allocate new OSPF Area object */
700 static struct ospf_area
*
701 ospf_area_new (struct ospf
*ospf
, struct in_addr area_id
)
703 struct ospf_area
*new;
705 /* Allocate new config_network. */
706 new = XCALLOC (MTYPE_OSPF_AREA
, sizeof (struct ospf_area
));
710 new->area_id
= area_id
;
712 new->external_routing
= OSPF_AREA_DEFAULT
;
713 new->default_cost
= 1;
714 new->auth_type
= OSPF_AUTH_NULL
;
717 new->lsdb
= ospf_lsdb_new ();
719 /* Self-originated LSAs initialize. */
720 new->router_lsa_self
= NULL
;
722 ospf_opaque_type10_lsa_init (new);
724 new->oiflist
= list_new ();
725 new->ranges
= route_table_init ();
727 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
)
728 ospf
->backbone
= new;
734 ospf_area_free (struct ospf_area
*area
)
736 struct route_node
*rn
;
737 struct ospf_lsa
*lsa
;
740 LSDB_LOOP (ROUTER_LSDB (area
), rn
, lsa
)
741 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
742 LSDB_LOOP (NETWORK_LSDB (area
), rn
, lsa
)
743 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
744 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
745 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
746 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
747 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
749 LSDB_LOOP (NSSA_LSDB (area
), rn
, lsa
)
750 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
751 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
752 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
753 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
754 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
756 ospf_lsdb_delete_all (area
->lsdb
);
757 ospf_lsdb_free (area
->lsdb
);
759 ospf_lsa_unlock (&area
->router_lsa_self
);
761 route_table_finish (area
->ranges
);
762 list_delete (area
->oiflist
);
764 if (EXPORT_NAME (area
))
765 free (EXPORT_NAME (area
));
767 if (IMPORT_NAME (area
))
768 free (IMPORT_NAME (area
));
771 OSPF_TIMER_OFF (area
->t_stub_router
);
772 OSPF_TIMER_OFF (area
->t_opaque_lsa_self
);
774 if (OSPF_IS_AREA_BACKBONE (area
))
775 area
->ospf
->backbone
= NULL
;
777 XFREE (MTYPE_OSPF_AREA
, area
);
781 ospf_area_check_free (struct ospf
*ospf
, struct in_addr area_id
)
783 struct ospf_area
*area
;
785 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
787 listcount (area
->oiflist
) == 0 &&
788 area
->ranges
->top
== NULL
&&
789 area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
&&
790 area
->external_routing
== OSPF_AREA_DEFAULT
&&
791 area
->no_summary
== 0 &&
792 area
->default_cost
== 1 &&
793 EXPORT_NAME (area
) == NULL
&&
794 IMPORT_NAME (area
) == NULL
&&
795 area
->auth_type
== OSPF_AUTH_NULL
)
797 listnode_delete (ospf
->areas
, area
);
798 ospf_area_free (area
);
803 ospf_area_get (struct ospf
*ospf
, struct in_addr area_id
, int format
)
805 struct ospf_area
*area
;
807 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
810 area
= ospf_area_new (ospf
, area_id
);
811 area
->format
= format
;
812 listnode_add_sort (ospf
->areas
, area
);
813 ospf_check_abr_status (ospf
);
814 if (ospf
->stub_router_admin_set
== OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
)
816 SET_FLAG (area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
824 ospf_area_lookup_by_area_id (struct ospf
*ospf
, struct in_addr area_id
)
826 struct ospf_area
*area
;
827 struct listnode
*node
;
829 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
830 if (IPV4_ADDR_SAME (&area
->area_id
, &area_id
))
837 ospf_area_add_if (struct ospf_area
*area
, struct ospf_interface
*oi
)
839 listnode_add (area
->oiflist
, oi
);
843 ospf_area_del_if (struct ospf_area
*area
, struct ospf_interface
*oi
)
845 listnode_delete (area
->oiflist
, oi
);
848 static struct ospf_interface
*
849 add_ospf_interface (struct interface
*ifp
, struct ospf_area
*area
,
850 struct connected
*co
)
852 struct ospf_interface
*oi
;
854 oi
= ospf_if_new (area
->ospf
, ifp
, co
->address
);
859 oi
->params
= ospf_lookup_if_params (ifp
, oi
->address
->u
.prefix4
);
860 oi
->output_cost
= ospf_if_get_output_cost (oi
);
862 /* Relate ospf interface to ospf instance. */
863 oi
->ospf
= area
->ospf
;
865 /* update network type as interface flag */
866 /* If network type is specified previously,
867 skip network type setting. */
868 oi
->type
= IF_DEF_PARAMS (ifp
)->type
;
870 /* Add pseudo neighbor. */
871 ospf_nbr_self_reset (oi
, oi
->ospf
->router_id
);
873 ospf_area_add_if (oi
->area
, oi
);
878 static void update_redistributed(struct ospf
*ospf
, int add_to_ospf
)
880 struct route_node
*rn
;
881 struct external_info
*ei
;
882 struct ospf_external
*ext
;
884 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT
, 0))
885 if ((ext
= ospf_external_lookup(ZEBRA_ROUTE_CONNECT
, 0)) &&
888 for (rn
= route_top (EXTERNAL_INFO (ext
));
889 rn
; rn
= route_next (rn
))
891 if ((ei
= rn
->info
) != NULL
)
895 if (ospf_external_info_find_lsa (ospf
, &ei
->p
))
896 if (!ospf_distribute_check_connected (ospf
, ei
))
897 ospf_external_lsa_flush (ospf
, ei
->type
, &ei
->p
,
898 ei
->ifindex
/*, ei->nexthop */);
902 if (!ospf_external_info_find_lsa (ospf
, &ei
->p
))
903 if (ospf_distribute_check_connected (ospf
, ei
))
904 ospf_external_lsa_originate (ospf
, ei
);
912 /* Config network statement related functions. */
913 static struct ospf_network
*
914 ospf_network_new (struct in_addr area_id
, int format
)
916 struct ospf_network
*new;
917 new = XCALLOC (MTYPE_OSPF_NETWORK
, sizeof (struct ospf_network
));
919 new->area_id
= area_id
;
920 new->format
= format
;
926 ospf_network_free (struct ospf
*ospf
, struct ospf_network
*network
)
928 ospf_area_check_free (ospf
, network
->area_id
);
929 ospf_schedule_abr_task (ospf
);
930 XFREE (MTYPE_OSPF_NETWORK
, network
);
934 ospf_network_set (struct ospf
*ospf
, struct prefix_ipv4
*p
,
935 struct in_addr area_id
)
937 struct ospf_network
*network
;
938 struct ospf_area
*area
;
939 struct route_node
*rn
;
940 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
942 rn
= route_node_get (ospf
->networks
, (struct prefix
*)p
);
945 /* There is already same network statement. */
946 route_unlock_node (rn
);
950 rn
->info
= network
= ospf_network_new (area_id
, ret
);
951 area
= ospf_area_get (ospf
, area_id
, ret
);
953 /* Run network config now. */
954 ospf_network_run ((struct prefix
*)p
, area
);
956 /* Update connected redistribute. */
957 update_redistributed(ospf
, 1); /* interfaces possibly added */
959 ospf_area_check_free (ospf
, area_id
);
965 ospf_network_unset (struct ospf
*ospf
, struct prefix_ipv4
*p
,
966 struct in_addr area_id
)
968 struct route_node
*rn
;
969 struct ospf_network
*network
;
970 struct listnode
*node
, *nnode
;
971 struct ospf_interface
*oi
;
973 rn
= route_node_lookup (ospf
->networks
, (struct prefix
*)p
);
978 route_unlock_node (rn
);
979 if (!IPV4_ADDR_SAME (&area_id
, &network
->area_id
))
982 ospf_network_free (ospf
, rn
->info
);
984 route_unlock_node (rn
); /* initial reference */
986 /* Find interfaces that not configured already. */
987 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
990 struct connected
*co
= oi
->connected
;
992 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
995 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
997 if (rn
->info
== NULL
)
1000 if (ospf_network_match_iface(co
,&rn
->p
))
1003 route_unlock_node (rn
);
1011 ospf_area_check_free (ospf
, area_id
);
1015 /* Update connected redistribute. */
1016 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1017 ospf_area_check_free (ospf
, area_id
);
1023 ospf_interface_set (struct interface
*ifp
, struct in_addr area_id
)
1025 struct ospf_area
*area
;
1026 struct listnode
*cnode
;
1027 struct connected
*co
;
1029 struct ospf_if_params
*params
;
1030 struct ospf_interface
*oi
;
1031 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1033 if ((ospf
= ospf_lookup ()) == NULL
)
1034 return 1; /* Ospf not ready yet */
1036 params
= IF_DEF_PARAMS (ifp
);
1038 SET_IF_PARAM (params
, if_area
);
1039 params
->if_area
= area_id
;
1041 area
= ospf_area_get (ospf
, area_id
, ret
);
1043 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, co
))
1045 if (CHECK_FLAG(co
->flags
,ZEBRA_IFA_SECONDARY
))
1048 if (co
->address
->family
== AF_INET
)
1050 oi
= ospf_if_table_lookup(ifp
, co
->address
);
1052 oi
= add_ospf_interface(ifp
, area
, co
);
1054 /* if router_id is not configured, dont bring up
1056 * ospf_router_id_update() will call ospf_if_update
1057 * whenever r-id is configured instead.
1059 if ((area
->ospf
->router_id
.s_addr
!= 0) && if_is_operative (ifp
))
1064 /* Update connected redistribute. */
1065 update_redistributed(ospf
, 1); /* interface possibly added */
1070 ospf_interface_unset (struct interface
*ifp
)
1073 struct ospf_if_params
*params
;
1074 struct listnode
*node
, *nnode
;
1075 struct ospf_interface
*oi
;
1076 struct in_addr area_id
;
1078 ospf
= ospf_lookup ();
1080 return 1; /* Ospf not ready yet */
1082 params
= IF_DEF_PARAMS (ifp
);
1083 UNSET_IF_PARAM (params
, if_area
);
1084 area_id
= params
->if_area
;
1086 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
1088 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1090 if (oi
->ifp
== ifp
) ospf_if_free (oi
);
1093 /* Update connected redistribute. */
1094 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1095 ospf_area_check_free (ospf
, area_id
);
1100 /* Check whether interface matches given network
1101 * returns: 1, true. 0, false
1104 ospf_network_match_iface(const struct connected
*co
, const struct prefix
*net
)
1106 /* new approach: more elegant and conceptually clean */
1107 return prefix_match(net
, CONNECTED_PREFIX(co
));
1111 ospf_network_run_interface (struct prefix
*p
, struct ospf_area
*area
,
1112 struct interface
*ifp
)
1114 struct listnode
*cnode
;
1115 struct connected
*co
;
1117 if (memcmp (ifp
->name
, "VLINK", 5) == 0)
1120 /* if interface prefix is match specified prefix,
1121 then create socket and join multicast group. */
1122 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, co
))
1125 if (CHECK_FLAG(co
->flags
,ZEBRA_IFA_SECONDARY
))
1128 if (p
->family
== co
->address
->family
1129 && ! ospf_if_table_lookup(ifp
, co
->address
)
1130 && ospf_network_match_iface(co
,p
))
1132 struct ospf_interface
*oi
;
1134 oi
= ospf_if_new (area
->ospf
, ifp
, co
->address
);
1139 oi
->params
= ospf_lookup_if_params (ifp
, oi
->address
->u
.prefix4
);
1140 oi
->output_cost
= ospf_if_get_output_cost (oi
);
1142 /* Add pseudo neighbor. */
1143 ospf_nbr_add_self (oi
, oi
->ospf
->router_id
);
1145 /* Relate ospf interface to ospf instance. */
1146 oi
->ospf
= area
->ospf
;
1148 /* update network type as interface flag */
1149 /* If network type is specified previously,
1150 skip network type setting. */
1151 oi
->type
= IF_DEF_PARAMS (ifp
)->type
;
1153 ospf_area_add_if (oi
->area
, oi
);
1155 /* if router_id is not configured, dont bring up
1157 * ospf_router_id_update() will call ospf_if_update
1158 * whenever r-id is configured instead.
1160 if ((area
->ospf
->router_id
.s_addr
!= 0)
1161 && if_is_operative (ifp
))
1168 ospf_network_run (struct prefix
*p
, struct ospf_area
*area
)
1170 struct interface
*ifp
;
1171 struct listnode
*node
;
1173 /* Schedule Router ID Update. */
1174 if (area
->ospf
->router_id
.s_addr
== 0)
1175 ospf_router_id_update (area
->ospf
);
1177 /* Get target interface. */
1178 for (ALL_LIST_ELEMENTS_RO (om
->iflist
, node
, ifp
))
1179 ospf_network_run_interface (p
, area
, ifp
);
1183 ospf_ls_upd_queue_empty (struct ospf_interface
*oi
)
1185 struct route_node
*rn
;
1186 struct listnode
*node
, *nnode
;
1188 struct ospf_lsa
*lsa
;
1190 /* empty ls update queue */
1191 for (rn
= route_top (oi
->ls_upd_queue
); rn
;
1192 rn
= route_next (rn
))
1193 if ((lst
= (struct list
*) rn
->info
))
1195 for (ALL_LIST_ELEMENTS (lst
, node
, nnode
, lsa
))
1196 ospf_lsa_unlock (&lsa
); /* oi->ls_upd_queue */
1201 /* remove update event */
1202 if (oi
->t_ls_upd_event
)
1204 thread_cancel (oi
->t_ls_upd_event
);
1205 oi
->t_ls_upd_event
= NULL
;
1210 ospf_if_update (struct ospf
*ospf
, struct interface
*ifp
)
1212 struct route_node
*rn
;
1213 struct ospf_network
*network
;
1214 struct ospf_area
*area
;
1215 struct ospf_if_params
*params
;
1218 ospf
= ospf_lookup ();
1220 /* OSPF must be on and Router-ID must be configured. */
1221 if (!ospf
|| ospf
->router_id
.s_addr
== 0)
1224 /* Run each netowrk for this interface. */
1225 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
1226 if (rn
->info
!= NULL
)
1228 network
= (struct ospf_network
*) rn
->info
;
1229 area
= ospf_area_get (ospf
, network
->area_id
, network
->format
);
1230 ospf_network_run_interface (&rn
->p
, area
, ifp
);
1233 /* create oif for any new co */
1234 params
= IF_DEF_PARAMS (ifp
);
1235 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1237 ospf_interface_set (ifp
, params
->if_area
);
1242 ospf_remove_vls_through_area (struct ospf
*ospf
, struct ospf_area
*area
)
1244 struct listnode
*node
, *nnode
;
1245 struct ospf_vl_data
*vl_data
;
1247 for (ALL_LIST_ELEMENTS (ospf
->vlinks
, node
, nnode
, vl_data
))
1248 if (IPV4_ADDR_SAME (&vl_data
->vl_area_id
, &area
->area_id
))
1249 ospf_vl_delete (ospf
, vl_data
);
1253 static const struct message ospf_area_type_msg
[] =
1255 { OSPF_AREA_DEFAULT
, "Default" },
1256 { OSPF_AREA_STUB
, "Stub" },
1257 { OSPF_AREA_NSSA
, "NSSA" },
1259 static const int ospf_area_type_msg_max
= OSPF_AREA_TYPE_MAX
;
1262 ospf_area_type_set (struct ospf_area
*area
, int type
)
1264 struct listnode
*node
;
1265 struct ospf_interface
*oi
;
1267 if (area
->external_routing
== type
)
1269 if (IS_DEBUG_OSPF_EVENT
)
1270 zlog_debug ("Area[%s]: Types are the same, ignored.",
1271 inet_ntoa (area
->area_id
));
1275 area
->external_routing
= type
;
1277 if (IS_DEBUG_OSPF_EVENT
)
1278 zlog_debug ("Area[%s]: Configured as %s", inet_ntoa (area
->area_id
),
1279 LOOKUP (ospf_area_type_msg
, type
));
1281 switch (area
->external_routing
)
1283 case OSPF_AREA_DEFAULT
:
1284 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1285 if (oi
->nbr_self
!= NULL
)
1287 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1288 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1291 case OSPF_AREA_STUB
:
1292 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1293 if (oi
->nbr_self
!= NULL
)
1295 if (IS_DEBUG_OSPF_EVENT
)
1296 zlog_debug ("setting options on %s accordingly", IF_NAME (oi
));
1297 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1298 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1299 if (IS_DEBUG_OSPF_EVENT
)
1300 zlog_debug ("options set on %s: %x",
1301 IF_NAME (oi
), OPTIONS (oi
));
1304 case OSPF_AREA_NSSA
:
1305 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1306 if (oi
->nbr_self
!= NULL
)
1308 zlog_debug ("setting nssa options on %s accordingly", IF_NAME (oi
));
1309 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1310 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1311 zlog_debug ("options set on %s: %x", IF_NAME (oi
), OPTIONS (oi
));
1318 ospf_router_lsa_update_area (area
);
1319 ospf_schedule_abr_task (area
->ospf
);
1323 ospf_area_shortcut_set (struct ospf
*ospf
, struct ospf_area
*area
, int mode
)
1325 if (area
->shortcut_configured
== mode
)
1328 area
->shortcut_configured
= mode
;
1329 ospf_router_lsa_update_area (area
);
1330 ospf_schedule_abr_task (ospf
);
1332 ospf_area_check_free (ospf
, area
->area_id
);
1338 ospf_area_shortcut_unset (struct ospf
*ospf
, struct ospf_area
*area
)
1340 area
->shortcut_configured
= OSPF_SHORTCUT_DEFAULT
;
1341 ospf_router_lsa_update_area (area
);
1342 ospf_area_check_free (ospf
, area
->area_id
);
1343 ospf_schedule_abr_task (ospf
);
1349 ospf_area_vlink_count (struct ospf
*ospf
, struct ospf_area
*area
)
1351 struct ospf_vl_data
*vl
;
1352 struct listnode
*node
;
1355 for (ALL_LIST_ELEMENTS_RO (ospf
->vlinks
, node
, vl
))
1356 if (IPV4_ADDR_SAME (&vl
->vl_area_id
, &area
->area_id
))
1363 ospf_area_stub_set (struct ospf
*ospf
, struct in_addr area_id
)
1365 struct ospf_area
*area
;
1366 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1368 area
= ospf_area_get (ospf
, area_id
, format
);
1369 if (ospf_area_vlink_count (ospf
, area
))
1372 if (area
->external_routing
!= OSPF_AREA_STUB
)
1373 ospf_area_type_set (area
, OSPF_AREA_STUB
);
1379 ospf_area_stub_unset (struct ospf
*ospf
, struct in_addr area_id
)
1381 struct ospf_area
*area
;
1383 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1387 if (area
->external_routing
== OSPF_AREA_STUB
)
1388 ospf_area_type_set (area
, OSPF_AREA_DEFAULT
);
1390 ospf_area_check_free (ospf
, area_id
);
1396 ospf_area_no_summary_set (struct ospf
*ospf
, struct in_addr area_id
)
1398 struct ospf_area
*area
;
1399 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1401 area
= ospf_area_get (ospf
, area_id
, format
);
1402 area
->no_summary
= 1;
1408 ospf_area_no_summary_unset (struct ospf
*ospf
, struct in_addr area_id
)
1410 struct ospf_area
*area
;
1412 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1416 area
->no_summary
= 0;
1417 ospf_area_check_free (ospf
, area_id
);
1423 ospf_area_nssa_set (struct ospf
*ospf
, struct in_addr area_id
)
1425 struct ospf_area
*area
;
1426 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1428 area
= ospf_area_get (ospf
, area_id
, format
);
1429 if (ospf_area_vlink_count (ospf
, area
))
1432 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1434 ospf_area_type_set (area
, OSPF_AREA_NSSA
);
1438 /* set NSSA area defaults */
1439 area
->no_summary
= 0;
1440 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1441 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1442 area
->NSSATranslatorStabilityInterval
= OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1448 ospf_area_nssa_unset (struct ospf
*ospf
, struct in_addr area_id
)
1450 struct ospf_area
*area
;
1452 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1456 if (area
->external_routing
== OSPF_AREA_NSSA
)
1459 ospf_area_type_set (area
, OSPF_AREA_DEFAULT
);
1462 ospf_area_check_free (ospf
, area_id
);
1468 ospf_area_nssa_translator_role_set (struct ospf
*ospf
, struct in_addr area_id
,
1471 struct ospf_area
*area
;
1473 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1477 area
->NSSATranslatorRole
= role
;
1483 /* XXX: unused? Leave for symmetry? */
1485 ospf_area_nssa_translator_role_unset (struct ospf
*ospf
,
1486 struct in_addr area_id
)
1488 struct ospf_area
*area
;
1490 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1494 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1496 ospf_area_check_free (ospf
, area_id
);
1503 ospf_area_export_list_set (struct ospf
*ospf
,
1504 struct ospf_area
*area
, const char *list_name
)
1506 struct access_list
*list
;
1507 list
= access_list_lookup (AFI_IP
, list_name
);
1509 EXPORT_LIST (area
) = list
;
1511 if (EXPORT_NAME (area
))
1512 free (EXPORT_NAME (area
));
1514 EXPORT_NAME (area
) = strdup (list_name
);
1515 ospf_schedule_abr_task (ospf
);
1521 ospf_area_export_list_unset (struct ospf
*ospf
, struct ospf_area
* area
)
1524 EXPORT_LIST (area
) = 0;
1526 if (EXPORT_NAME (area
))
1527 free (EXPORT_NAME (area
));
1529 EXPORT_NAME (area
) = NULL
;
1531 ospf_area_check_free (ospf
, area
->area_id
);
1533 ospf_schedule_abr_task (ospf
);
1539 ospf_area_import_list_set (struct ospf
*ospf
, struct ospf_area
*area
,
1542 struct access_list
*list
;
1543 list
= access_list_lookup (AFI_IP
, name
);
1545 IMPORT_LIST (area
) = list
;
1547 if (IMPORT_NAME (area
))
1548 free (IMPORT_NAME (area
));
1550 IMPORT_NAME (area
) = strdup (name
);
1551 ospf_schedule_abr_task (ospf
);
1557 ospf_area_import_list_unset (struct ospf
*ospf
, struct ospf_area
* area
)
1559 IMPORT_LIST (area
) = 0;
1561 if (IMPORT_NAME (area
))
1562 free (IMPORT_NAME (area
));
1564 IMPORT_NAME (area
) = NULL
;
1565 ospf_area_check_free (ospf
, area
->area_id
);
1567 ospf_schedule_abr_task (ospf
);
1573 ospf_timers_refresh_set (struct ospf
*ospf
, int interval
)
1577 if (ospf
->lsa_refresh_interval
== interval
)
1580 time_left
= ospf
->lsa_refresh_interval
-
1581 (quagga_monotime () - ospf
->lsa_refresher_started
);
1583 if (time_left
> interval
)
1585 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
1586 ospf
->t_lsa_refresher
=
1587 thread_add_timer (master
, ospf_lsa_refresh_walker
, ospf
, interval
);
1589 ospf
->lsa_refresh_interval
= interval
;
1595 ospf_timers_refresh_unset (struct ospf
*ospf
)
1599 time_left
= ospf
->lsa_refresh_interval
-
1600 (quagga_monotime () - ospf
->lsa_refresher_started
);
1602 if (time_left
> OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
1604 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
1605 ospf
->t_lsa_refresher
=
1606 thread_add_timer (master
, ospf_lsa_refresh_walker
, ospf
,
1607 OSPF_LSA_REFRESH_INTERVAL_DEFAULT
);
1610 ospf
->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
1616 static struct ospf_nbr_nbma
*
1617 ospf_nbr_nbma_new (void)
1619 struct ospf_nbr_nbma
*nbr_nbma
;
1621 nbr_nbma
= XCALLOC (MTYPE_OSPF_NEIGHBOR_STATIC
,
1622 sizeof (struct ospf_nbr_nbma
));
1624 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1625 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1631 ospf_nbr_nbma_free (struct ospf_nbr_nbma
*nbr_nbma
)
1633 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
1637 ospf_nbr_nbma_delete (struct ospf
*ospf
, struct ospf_nbr_nbma
*nbr_nbma
)
1639 struct route_node
*rn
;
1640 struct prefix_ipv4 p
;
1643 p
.prefix
= nbr_nbma
->addr
;
1644 p
.prefixlen
= IPV4_MAX_BITLEN
;
1646 rn
= route_node_lookup (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1649 ospf_nbr_nbma_free (rn
->info
);
1651 route_unlock_node (rn
);
1652 route_unlock_node (rn
);
1657 ospf_nbr_nbma_down (struct ospf_nbr_nbma
*nbr_nbma
)
1659 OSPF_TIMER_OFF (nbr_nbma
->t_poll
);
1663 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
1664 OSPF_NSM_EVENT_EXECUTE (nbr_nbma
->nbr
, NSM_KillNbr
);
1668 listnode_delete (nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
1672 ospf_nbr_nbma_add (struct ospf_nbr_nbma
*nbr_nbma
,
1673 struct ospf_interface
*oi
)
1675 struct ospf_neighbor
*nbr
;
1676 struct route_node
*rn
;
1679 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1682 if (nbr_nbma
->nbr
!= NULL
)
1685 if (IPV4_ADDR_SAME (&oi
->nbr_self
->address
.u
.prefix4
, &nbr_nbma
->addr
))
1689 listnode_add (oi
->nbr_nbma
, nbr_nbma
);
1691 /* Get neighbor information from table. */
1693 p
.prefixlen
= IPV4_MAX_BITLEN
;
1694 p
.u
.prefix4
= nbr_nbma
->addr
;
1696 rn
= route_node_get (oi
->nbrs
, (struct prefix
*)&p
);
1700 nbr
->nbr_nbma
= nbr_nbma
;
1701 nbr_nbma
->nbr
= nbr
;
1703 route_unlock_node (rn
);
1707 nbr
= rn
->info
= ospf_nbr_new (oi
);
1708 nbr
->state
= NSM_Down
;
1709 nbr
->src
= nbr_nbma
->addr
;
1710 nbr
->nbr_nbma
= nbr_nbma
;
1711 nbr
->priority
= nbr_nbma
->priority
;
1714 nbr_nbma
->nbr
= nbr
;
1716 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_Start
);
1721 ospf_nbr_nbma_if_update (struct ospf
*ospf
, struct ospf_interface
*oi
)
1723 struct ospf_nbr_nbma
*nbr_nbma
;
1724 struct route_node
*rn
;
1725 struct prefix_ipv4 p
;
1727 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1730 for (rn
= route_top (ospf
->nbr_nbma
); rn
; rn
= route_next (rn
))
1731 if ((nbr_nbma
= rn
->info
))
1732 if (nbr_nbma
->oi
== NULL
&& nbr_nbma
->nbr
== NULL
)
1735 p
.prefix
= nbr_nbma
->addr
;
1736 p
.prefixlen
= IPV4_MAX_BITLEN
;
1738 if (prefix_match (oi
->address
, (struct prefix
*)&p
))
1739 ospf_nbr_nbma_add (nbr_nbma
, oi
);
1743 struct ospf_nbr_nbma
*
1744 ospf_nbr_nbma_lookup (struct ospf
*ospf
, struct in_addr nbr_addr
)
1746 struct route_node
*rn
;
1747 struct prefix_ipv4 p
;
1750 p
.prefix
= nbr_addr
;
1751 p
.prefixlen
= IPV4_MAX_BITLEN
;
1753 rn
= route_node_lookup (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1756 route_unlock_node (rn
);
1762 struct ospf_nbr_nbma
*
1763 ospf_nbr_nbma_lookup_next (struct ospf
*ospf
, struct in_addr
*addr
, int first
)
1766 struct ospf_nbr_nbma
*nbr_nbma
;
1767 struct listnode
*node
;
1774 for (ALL_LIST_ELEMENTS_RO (ospf
->nbr_nbma
, node
, nbr_nbma
))
1778 *addr
= nbr_nbma
->addr
;
1781 else if (ntohl (nbr_nbma
->addr
.s_addr
) > ntohl (addr
->s_addr
))
1783 *addr
= nbr_nbma
->addr
;
1792 ospf_nbr_nbma_set (struct ospf
*ospf
, struct in_addr nbr_addr
)
1794 struct ospf_nbr_nbma
*nbr_nbma
;
1795 struct ospf_interface
*oi
;
1796 struct prefix_ipv4 p
;
1797 struct route_node
*rn
;
1798 struct listnode
*node
;
1800 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1804 nbr_nbma
= ospf_nbr_nbma_new ();
1805 nbr_nbma
->addr
= nbr_addr
;
1808 p
.prefix
= nbr_addr
;
1809 p
.prefixlen
= IPV4_MAX_BITLEN
;
1811 rn
= route_node_get (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1813 route_unlock_node (rn
);
1814 rn
->info
= nbr_nbma
;
1816 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
1818 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1819 if (prefix_match (oi
->address
, (struct prefix
*)&p
))
1821 ospf_nbr_nbma_add (nbr_nbma
, oi
);
1830 ospf_nbr_nbma_unset (struct ospf
*ospf
, struct in_addr nbr_addr
)
1832 struct ospf_nbr_nbma
*nbr_nbma
;
1834 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1835 if (nbr_nbma
== NULL
)
1838 ospf_nbr_nbma_down (nbr_nbma
);
1839 ospf_nbr_nbma_delete (ospf
, nbr_nbma
);
1845 ospf_nbr_nbma_priority_set (struct ospf
*ospf
, struct in_addr nbr_addr
,
1848 struct ospf_nbr_nbma
*nbr_nbma
;
1850 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1851 if (nbr_nbma
== NULL
)
1854 if (nbr_nbma
->priority
!= priority
)
1855 nbr_nbma
->priority
= priority
;
1861 ospf_nbr_nbma_priority_unset (struct ospf
*ospf
, struct in_addr nbr_addr
)
1863 struct ospf_nbr_nbma
*nbr_nbma
;
1865 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1866 if (nbr_nbma
== NULL
)
1869 if (nbr_nbma
!= OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
1870 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1876 ospf_nbr_nbma_poll_interval_set (struct ospf
*ospf
, struct in_addr nbr_addr
,
1877 unsigned int interval
)
1879 struct ospf_nbr_nbma
*nbr_nbma
;
1881 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1882 if (nbr_nbma
== NULL
)
1885 if (nbr_nbma
->v_poll
!= interval
)
1887 nbr_nbma
->v_poll
= interval
;
1888 if (nbr_nbma
->oi
&& ospf_if_is_up (nbr_nbma
->oi
))
1890 OSPF_TIMER_OFF (nbr_nbma
->t_poll
);
1891 OSPF_POLL_TIMER_ON (nbr_nbma
->t_poll
, ospf_poll_timer
,
1900 ospf_nbr_nbma_poll_interval_unset (struct ospf
*ospf
, struct in_addr addr
)
1902 struct ospf_nbr_nbma
*nbr_nbma
;
1904 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, addr
);
1905 if (nbr_nbma
== NULL
)
1908 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
1909 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1917 memset (&ospf_master
, 0, sizeof (struct ospf_master
));
1920 om
->ospf
= list_new ();
1921 om
->master
= thread_master_create ();