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 () */
40 #include "ospfd/ospfd.h"
41 #include "ospfd/ospf_network.h"
42 #include "ospfd/ospf_interface.h"
43 #include "ospfd/ospf_ism.h"
44 #include "ospfd/ospf_asbr.h"
45 #include "ospfd/ospf_lsa.h"
46 #include "ospfd/ospf_lsdb.h"
47 #include "ospfd/ospf_neighbor.h"
48 #include "ospfd/ospf_nsm.h"
49 #include "ospfd/ospf_spf.h"
50 #include "ospfd/ospf_packet.h"
51 #include "ospfd/ospf_dump.h"
52 #include "ospfd/ospf_zebra.h"
53 #include "ospfd/ospf_abr.h"
54 #include "ospfd/ospf_flood.h"
55 #include "ospfd/ospf_route.h"
56 #include "ospfd/ospf_ase.h"
59 DEFINE_QOBJ_TYPE(ospf
)
61 /* OSPF process wide configuration. */
62 static struct ospf_master ospf_master
;
64 /* OSPF process wide configuration pointer to export. */
65 struct ospf_master
*om
;
67 extern struct zclient
*zclient
;
68 extern struct in_addr router_id_zebra
;
71 static void ospf_remove_vls_through_area (struct ospf
*, struct ospf_area
*);
72 static void ospf_network_free (struct ospf
*, struct ospf_network
*);
73 static void ospf_area_free (struct ospf_area
*);
74 static void ospf_network_run (struct prefix
*, struct ospf_area
*);
75 static void ospf_network_run_interface (struct prefix
*, struct ospf_area
*,
77 static int ospf_network_match_iface (const struct connected
*,
78 const struct prefix
*);
79 static void ospf_finish_final (struct ospf
*);
81 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
84 ospf_router_id_update (struct ospf
*ospf
)
86 struct in_addr router_id
, router_id_old
;
87 struct ospf_interface
*oi
;
88 struct interface
*ifp
;
89 struct listnode
*node
;
92 if (!ospf
->oi_running
)
94 if (IS_DEBUG_OSPF_EVENT
)
95 zlog_debug ("Router ospf not configured -- Router-ID update postponed");
99 if (IS_DEBUG_OSPF_EVENT
)
100 zlog_debug ("Router-ID[OLD:%s]: Update", inet_ntoa (ospf
->router_id
));
102 router_id_old
= ospf
->router_id
;
104 /* Select the router ID based on these priorities:
105 1. Statically assigned router ID is always the first choice.
106 2. If there is no statically assigned router ID, then try to stick
107 with the most recent value, since changing router ID's is very
109 3. Last choice: just go with whatever the zebra daemon recommends.
111 if (ospf
->router_id_static
.s_addr
!= 0)
112 router_id
= ospf
->router_id_static
;
113 else if (ospf
->router_id
.s_addr
!= 0)
114 router_id
= ospf
->router_id
;
116 router_id
= router_id_zebra
;
119 if (!IPV4_ADDR_SAME (&router_id_old
, &router_id
))
122 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
124 /* Some nbrs are identified by router_id, these needs
125 * to be rebuilt. Possible optimization would be to do
126 * oi->nbr_self->router_id = router_id for
127 * !(virtual | ptop) links
129 ospf_nbr_self_reset (oi
, router_id
);
132 /* If AS-external-LSA is queued, then flush those LSAs. */
133 if (router_id_old
.s_addr
== 0 && ospf
->external_origin
)
135 /* Originate each redistributed external route. */
136 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
137 if (ospf
->external_origin
& (1 << type
))
138 thread_add_event(master
, ospf_external_lsa_originate_timer
,
140 /* Originate Deafult. */
141 if (ospf
->external_origin
& (1 << ZEBRA_ROUTE_MAX
))
142 thread_add_event(master
, ospf_default_originate_timer
, ospf
, 0,
145 ospf
->external_origin
= 0;
148 /* Flush (inline) all external LSAs based on the OSPF_LSA_SELF flag */
151 struct route_node
*rn
;
152 struct ospf_lsa
*lsa
;
154 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
155 if (IS_LSA_SELF(lsa
))
156 ospf_lsa_flush_schedule(ospf
, lsa
);
159 ospf
->router_id
= router_id
;
160 if (IS_DEBUG_OSPF_EVENT
)
161 zlog_debug ("Router-ID[NEW:%s]: Update", inet_ntoa (ospf
->router_id
));
163 /* Flush (inline) all external LSAs which now match the new router-id,
164 need to adjust the OSPF_LSA_SELF flag, so the flush doesnt hit
165 asserts in ospf_refresher_unregister_lsa(). This step is needed
166 because the current quagga code does look-up for self-originated LSAs
167 based on the self router-id alone but expects OSPF_LSA_SELF to be
171 struct route_node
*rn
;
172 struct ospf_lsa
*lsa
;
174 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
176 /* AdvRouter and Router ID is the same. */
177 if (IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &ospf
->router_id
))
179 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF_CHECKED
);
180 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
181 ospf_lsa_flush_schedule(ospf
, lsa
);
186 /* Originate each redistributed external route. */
187 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
188 thread_add_event(master
, ospf_external_lsa_originate_timer
, ospf
,
190 thread_add_event(master
, ospf_default_originate_timer
, ospf
, 0, NULL
);
192 /* update router-lsa's for each area */
193 ospf_router_lsa_update (ospf
);
195 /* update ospf_interface's */
196 for (ALL_LIST_ELEMENTS_RO (om
->iflist
, node
, ifp
))
197 ospf_if_update (ospf
, ifp
);
201 /* For OSPF area sort by area id. */
203 ospf_area_id_cmp (struct ospf_area
*a1
, struct ospf_area
*a2
)
205 if (ntohl (a1
->area_id
.s_addr
) > ntohl (a2
->area_id
.s_addr
))
207 if (ntohl (a1
->area_id
.s_addr
) < ntohl (a2
->area_id
.s_addr
))
212 /* Allocate new ospf structure. */
214 ospf_new (u_short instance
)
218 struct ospf
*new = XCALLOC (MTYPE_OSPF_TOP
, sizeof (struct ospf
));
220 new->instance
= instance
;
221 new->router_id
.s_addr
= htonl (0);
222 new->router_id_static
.s_addr
= htonl (0);
224 new->abr_type
= OSPF_ABR_DEFAULT
;
225 new->oiflist
= list_new ();
226 new->vlinks
= list_new ();
227 new->areas
= list_new ();
228 new->areas
->cmp
= (int (*)(void *, void *)) ospf_area_id_cmp
;
229 new->networks
= route_table_init ();
230 new->nbr_nbma
= route_table_init ();
232 new->lsdb
= ospf_lsdb_new ();
234 new->default_originate
= DEFAULT_ORIGINATE_NONE
;
236 new->passive_interface_default
= OSPF_IF_ACTIVE
;
238 new->new_external_route
= route_table_init ();
239 new->old_external_route
= route_table_init ();
240 new->external_lsas
= route_table_init ();
242 new->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
243 new->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
244 new->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
246 /* Distribute parameter init. */
247 for (i
= 0; i
<= ZEBRA_ROUTE_MAX
; i
++)
251 new->default_metric
= -1;
252 new->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
255 new->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
256 new->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
258 /* SPF timer value init. */
259 new->spf_delay
= OSPF_SPF_DELAY_DEFAULT
;
260 new->spf_holdtime
= OSPF_SPF_HOLDTIME_DEFAULT
;
261 new->spf_max_holdtime
= OSPF_SPF_MAX_HOLDTIME_DEFAULT
;
262 new->spf_hold_multiplier
= 1;
265 new->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
266 new->maxage_lsa
= route_table_init();
267 new->t_maxage_walker
=
268 thread_add_timer(master
, ospf_lsa_maxage_walker
, new,
269 OSPF_LSA_MAXAGE_CHECK_INTERVAL
, NULL
);
271 /* Distance table init. */
272 new->distance_table
= route_table_init ();
274 new->lsa_refresh_queue
.index
= 0;
275 new->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
276 new->t_lsa_refresher
= thread_add_timer(master
, ospf_lsa_refresh_walker
,
277 new, new->lsa_refresh_interval
,
279 new->lsa_refresher_started
= monotime(NULL
);
281 if ((new->fd
= ospf_sock_init()) < 0)
283 zlog_err("ospf_new: fatal error: ospf_sock_init was unable to open "
287 if ((new->ibuf
= stream_new(OSPF_MAX_PACKET_SIZE
+1)) == NULL
)
289 zlog_err("ospf_new: fatal error: stream_new(%u) failed allocating ibuf",
290 OSPF_MAX_PACKET_SIZE
+1);
293 new->t_read
= thread_add_read(master
, ospf_read
, new, new->fd
, NULL
);
294 new->oi_write_q
= list_new ();
295 new->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
297 /* Enable "log-adjacency-changes" */
298 #if DFLT_OSPF_LOG_ADJACENCY_CHANGES
299 SET_FLAG(new->config
, OSPF_LOG_ADJACENCY_CHANGES
);
302 QOBJ_REG (new, ospf
);
310 if (listcount (om
->ospf
) == 0)
313 return listgetdata ((struct listnode
*)listhead (om
->ospf
));
317 ospf_lookup_instance (u_short instance
)
320 struct listnode
*node
, *nnode
;
322 if (listcount (om
->ospf
) == 0)
325 for (ALL_LIST_ELEMENTS (om
->ospf
, node
, nnode
, ospf
))
326 if ((ospf
->instance
== 0 && instance
== 0)
327 || (ospf
->instance
&& instance
&& ospf
->instance
== instance
))
334 ospf_add (struct ospf
*ospf
)
336 listnode_add (om
->ospf
, ospf
);
340 ospf_delete (struct ospf
*ospf
)
342 listnode_delete (om
->ospf
, ospf
);
350 ospf
= ospf_lookup ();
356 if (ospf
->router_id_static
.s_addr
== 0)
357 ospf_router_id_update (ospf
);
359 ospf_opaque_type11_lsa_init (ospf
);
366 ospf_get_instance (u_short instance
)
370 ospf
= ospf_lookup_instance (instance
);
373 ospf
= ospf_new (instance
);
376 if (ospf
->router_id_static
.s_addr
== 0)
377 ospf_router_id_update (ospf
);
379 ospf_opaque_type11_lsa_init (ospf
);
385 /* Handle the second half of deferred shutdown. This is called either
386 * from the deferred-shutdown timer thread, or directly through
387 * ospf_deferred_shutdown_check.
389 * Function is to cleanup G-R state, if required then call ospf_finish_final
390 * to complete shutdown of this ospf instance. Possibly exit if the
391 * whole process is being shutdown and this was the last OSPF instance.
394 ospf_deferred_shutdown_finish (struct ospf
*ospf
)
396 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
397 OSPF_TIMER_OFF (ospf
->t_deferred_shutdown
);
399 ospf_finish_final (ospf
);
401 /* *ospf is now invalid */
403 /* ospfd being shut-down? If so, was this the last ospf instance? */
404 if (CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
)
405 && (listcount (om
->ospf
) == 0))
413 /* Timer thread for G-R */
415 ospf_deferred_shutdown_timer (struct thread
*t
)
417 struct ospf
*ospf
= THREAD_ARG(t
);
419 ospf_deferred_shutdown_finish (ospf
);
424 /* Check whether deferred-shutdown must be scheduled, otherwise call
425 * down directly into second-half of instance shutdown.
428 ospf_deferred_shutdown_check (struct ospf
*ospf
)
430 unsigned long timeout
;
432 struct ospf_area
*area
;
434 /* deferred shutdown already running? */
435 if (ospf
->t_deferred_shutdown
)
438 /* Should we try push out max-metric LSAs? */
439 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
441 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, ln
, area
))
443 SET_FLAG (area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
445 if (!CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
446 ospf_router_lsa_update_area (area
);
448 timeout
= ospf
->stub_router_shutdown_time
;
452 /* No timer needed */
453 ospf_deferred_shutdown_finish (ospf
);
457 OSPF_TIMER_ON (ospf
->t_deferred_shutdown
, ospf_deferred_shutdown_timer
,
462 /* Shut down the entire process */
464 ospf_terminate (void)
467 struct listnode
*node
, *nnode
;
469 /* shutdown already in progress */
470 if (CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
))
473 SET_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
);
475 /* exit immediately if OSPF not actually running */
476 if (listcount(om
->ospf
) == 0)
480 for (ALL_LIST_ELEMENTS (om
->ospf
, node
, nnode
, ospf
))
483 /* Deliberately go back up, hopefully to thread scheduler, as
484 * One or more ospf_finish()'s may have deferred shutdown to a timer
490 ospf_finish (struct ospf
*ospf
)
492 /* let deferred shutdown decide */
493 ospf_deferred_shutdown_check (ospf
);
495 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
496 * deferred to expiry of G-S timer thread. Return back up, hopefully
497 * to thread scheduler.
502 /* Final cleanup of ospf instance */
504 ospf_finish_final (struct ospf
*ospf
)
506 struct route_node
*rn
;
507 struct ospf_nbr_nbma
*nbr_nbma
;
508 struct ospf_lsa
*lsa
;
509 struct interface
*ifp
;
510 struct ospf_interface
*oi
;
511 struct ospf_area
*area
;
512 struct ospf_vl_data
*vl_data
;
513 struct listnode
*node
, *nnode
;
515 u_short instance
= 0;
519 ospf_opaque_type11_lsa_term (ospf
);
521 /* be nice if this worked, but it doesn't */
522 /*ospf_flush_self_originated_lsas_now (ospf);*/
524 /* Unregister redistribution */
525 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
527 struct list
*red_list
;
528 struct ospf_redist
*red
;
530 red_list
= ospf
->redist
[i
];
534 for (ALL_LIST_ELEMENTS(red_list
, node
, nnode
, red
))
535 ospf_redistribute_unset (ospf
, i
, red
->instance
);
537 ospf_redistribute_default_unset (ospf
);
539 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
540 ospf_remove_vls_through_area (ospf
, area
);
542 for (ALL_LIST_ELEMENTS (ospf
->vlinks
, node
, nnode
, vl_data
))
543 ospf_vl_delete (ospf
, vl_data
);
545 list_delete (ospf
->vlinks
);
547 /* Remove any ospf interface config params */
548 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
550 struct ospf_if_params
*params
;
552 params
= IF_DEF_PARAMS (ifp
);
553 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
554 UNSET_IF_PARAM (params
, if_area
);
557 /* Reset interface. */
558 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
561 /* Clear static neighbors */
562 for (rn
= route_top (ospf
->nbr_nbma
); rn
; rn
= route_next (rn
))
563 if ((nbr_nbma
= rn
->info
))
565 OSPF_POLL_TIMER_OFF (nbr_nbma
->t_poll
);
569 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
570 nbr_nbma
->nbr
= NULL
;
575 listnode_delete (nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
579 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
582 route_table_finish (ospf
->nbr_nbma
);
584 /* Clear networks and Areas. */
585 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
587 struct ospf_network
*network
;
589 if ((network
= rn
->info
) != NULL
)
591 ospf_network_free (ospf
, network
);
593 route_unlock_node (rn
);
597 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
599 listnode_delete (ospf
->areas
, area
);
600 ospf_area_free (area
);
603 /* Cancel all timers. */
604 OSPF_TIMER_OFF (ospf
->t_external_lsa
);
605 OSPF_TIMER_OFF (ospf
->t_spf_calc
);
606 OSPF_TIMER_OFF (ospf
->t_ase_calc
);
607 OSPF_TIMER_OFF (ospf
->t_maxage
);
608 OSPF_TIMER_OFF (ospf
->t_maxage_walker
);
609 OSPF_TIMER_OFF (ospf
->t_abr_task
);
610 OSPF_TIMER_OFF (ospf
->t_asbr_check
);
611 OSPF_TIMER_OFF (ospf
->t_distribute_update
);
612 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
613 OSPF_TIMER_OFF (ospf
->t_read
);
614 OSPF_TIMER_OFF (ospf
->t_write
);
615 OSPF_TIMER_OFF (ospf
->t_opaque_lsa_self
);
618 stream_free(ospf
->ibuf
);
620 LSDB_LOOP (OPAQUE_AS_LSDB (ospf
), rn
, lsa
)
621 ospf_discard_from_db (ospf
, ospf
->lsdb
, lsa
);
622 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
623 ospf_discard_from_db (ospf
, ospf
->lsdb
, lsa
);
625 ospf_lsdb_delete_all (ospf
->lsdb
);
626 ospf_lsdb_free (ospf
->lsdb
);
628 for (rn
= route_top (ospf
->maxage_lsa
); rn
; rn
= route_next (rn
))
630 struct ospf_lsa
*lsa
;
632 if ((lsa
= rn
->info
) != NULL
)
634 ospf_lsa_unlock (&lsa
);
637 route_unlock_node (rn
);
639 route_table_finish (ospf
->maxage_lsa
);
642 ospf_route_table_free (ospf
->old_table
);
645 ospf_route_delete (ospf
->new_table
);
646 ospf_route_table_free (ospf
->new_table
);
649 ospf_rtrs_free (ospf
->old_rtrs
);
651 ospf_rtrs_free (ospf
->new_rtrs
);
652 if (ospf
->new_external_route
)
654 ospf_route_delete (ospf
->new_external_route
);
655 ospf_route_table_free (ospf
->new_external_route
);
657 if (ospf
->old_external_route
)
659 ospf_route_delete (ospf
->old_external_route
);
660 ospf_route_table_free (ospf
->old_external_route
);
662 if (ospf
->external_lsas
)
664 ospf_ase_external_lsas_finish (ospf
->external_lsas
);
667 list_delete (ospf
->areas
);
669 for (i
= ZEBRA_ROUTE_SYSTEM
; i
<= ZEBRA_ROUTE_MAX
; i
++)
671 struct list
*ext_list
;
672 struct listnode
*node
;
673 struct ospf_external
*ext
;
675 ext_list
= om
->external
[i
];
679 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
))
681 if (ext
->external_info
)
682 for (rn
= route_top (ext
->external_info
); rn
; rn
= route_next (rn
))
684 if (rn
->info
== NULL
)
687 XFREE (MTYPE_OSPF_EXTERNAL_INFO
, rn
->info
);
689 route_unlock_node (rn
);
694 ospf_distance_reset (ospf
);
695 route_table_finish (ospf
->distance_table
);
697 if (!CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
))
698 instance
= ospf
->instance
;
702 XFREE (MTYPE_OSPF_TOP
, ospf
);
704 if (!CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
))
705 ospf_get_instance(instance
);
710 /* allocate new OSPF Area object */
711 static struct ospf_area
*
712 ospf_area_new (struct ospf
*ospf
, struct in_addr area_id
)
714 struct ospf_area
*new;
716 /* Allocate new config_network. */
717 new = XCALLOC (MTYPE_OSPF_AREA
, sizeof (struct ospf_area
));
721 new->area_id
= area_id
;
723 new->external_routing
= OSPF_AREA_DEFAULT
;
724 new->default_cost
= 1;
725 new->auth_type
= OSPF_AUTH_NULL
;
728 new->lsdb
= ospf_lsdb_new ();
730 /* Self-originated LSAs initialize. */
731 new->router_lsa_self
= NULL
;
733 ospf_opaque_type10_lsa_init (new);
735 new->oiflist
= list_new ();
736 new->ranges
= route_table_init ();
738 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
)
739 ospf
->backbone
= new;
745 ospf_area_free (struct ospf_area
*area
)
747 struct route_node
*rn
;
748 struct ospf_lsa
*lsa
;
751 LSDB_LOOP (ROUTER_LSDB (area
), rn
, lsa
)
752 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
753 LSDB_LOOP (NETWORK_LSDB (area
), rn
, lsa
)
754 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
755 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
756 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
757 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
758 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
760 LSDB_LOOP (NSSA_LSDB (area
), rn
, lsa
)
761 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
762 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
763 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
764 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
765 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
767 ospf_lsdb_delete_all (area
->lsdb
);
768 ospf_lsdb_free (area
->lsdb
);
770 ospf_lsa_unlock (&area
->router_lsa_self
);
772 route_table_finish (area
->ranges
);
773 list_delete (area
->oiflist
);
775 if (EXPORT_NAME (area
))
776 free (EXPORT_NAME (area
));
778 if (IMPORT_NAME (area
))
779 free (IMPORT_NAME (area
));
782 OSPF_TIMER_OFF (area
->t_stub_router
);
783 OSPF_TIMER_OFF (area
->t_opaque_lsa_self
);
785 if (OSPF_IS_AREA_BACKBONE (area
))
786 area
->ospf
->backbone
= NULL
;
788 XFREE (MTYPE_OSPF_AREA
, area
);
792 ospf_area_check_free (struct ospf
*ospf
, struct in_addr area_id
)
794 struct ospf_area
*area
;
796 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
798 listcount (area
->oiflist
) == 0 &&
799 area
->ranges
->top
== NULL
&&
800 area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
&&
801 area
->external_routing
== OSPF_AREA_DEFAULT
&&
802 area
->no_summary
== 0 &&
803 area
->default_cost
== 1 &&
804 EXPORT_NAME (area
) == NULL
&&
805 IMPORT_NAME (area
) == NULL
&&
806 area
->auth_type
== OSPF_AUTH_NULL
)
808 listnode_delete (ospf
->areas
, area
);
809 ospf_area_free (area
);
814 ospf_area_get (struct ospf
*ospf
, struct in_addr area_id
, int format
)
816 struct ospf_area
*area
;
818 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
821 area
= ospf_area_new (ospf
, area_id
);
822 area
->format
= format
;
823 listnode_add_sort (ospf
->areas
, area
);
824 ospf_check_abr_status (ospf
);
825 if (ospf
->stub_router_admin_set
== OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
)
827 SET_FLAG (area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
835 ospf_area_lookup_by_area_id (struct ospf
*ospf
, struct in_addr area_id
)
837 struct ospf_area
*area
;
838 struct listnode
*node
;
840 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
841 if (IPV4_ADDR_SAME (&area
->area_id
, &area_id
))
848 ospf_area_add_if (struct ospf_area
*area
, struct ospf_interface
*oi
)
850 listnode_add (area
->oiflist
, oi
);
854 ospf_area_del_if (struct ospf_area
*area
, struct ospf_interface
*oi
)
856 listnode_delete (area
->oiflist
, oi
);
859 static struct ospf_interface
*
860 add_ospf_interface (struct interface
*ifp
, struct ospf_area
*area
,
861 struct connected
*co
)
863 struct ospf_interface
*oi
;
865 oi
= ospf_if_new (area
->ospf
, ifp
, co
->address
);
870 oi
->params
= ospf_lookup_if_params (ifp
, oi
->address
->u
.prefix4
);
871 oi
->output_cost
= ospf_if_get_output_cost (oi
);
873 /* Relate ospf interface to ospf instance. */
874 oi
->ospf
= area
->ospf
;
876 /* update network type as interface flag */
877 /* If network type is specified previously,
878 skip network type setting. */
879 oi
->type
= IF_DEF_PARAMS (ifp
)->type
;
881 /* Add pseudo neighbor. */
882 ospf_nbr_self_reset (oi
, oi
->ospf
->router_id
);
884 ospf_area_add_if (oi
->area
, oi
);
889 static void update_redistributed(struct ospf
*ospf
, int add_to_ospf
)
891 struct route_node
*rn
;
892 struct external_info
*ei
;
893 struct ospf_external
*ext
;
895 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT
, 0))
896 if ((ext
= ospf_external_lookup(ZEBRA_ROUTE_CONNECT
, 0)) &&
899 for (rn
= route_top (EXTERNAL_INFO (ext
));
900 rn
; rn
= route_next (rn
))
902 if ((ei
= rn
->info
) != NULL
)
906 if (ospf_external_info_find_lsa (ospf
, &ei
->p
))
907 if (!ospf_distribute_check_connected (ospf
, ei
))
908 ospf_external_lsa_flush (ospf
, ei
->type
, &ei
->p
,
909 ei
->ifindex
/*, ei->nexthop */);
913 if (!ospf_external_info_find_lsa (ospf
, &ei
->p
))
914 if (ospf_distribute_check_connected (ospf
, ei
))
915 ospf_external_lsa_originate (ospf
, ei
);
923 /* Config network statement related functions. */
924 static struct ospf_network
*
925 ospf_network_new (struct in_addr area_id
, int format
)
927 struct ospf_network
*new;
928 new = XCALLOC (MTYPE_OSPF_NETWORK
, sizeof (struct ospf_network
));
930 new->area_id
= area_id
;
931 new->format
= format
;
937 ospf_network_free (struct ospf
*ospf
, struct ospf_network
*network
)
939 ospf_area_check_free (ospf
, network
->area_id
);
940 ospf_schedule_abr_task (ospf
);
941 XFREE (MTYPE_OSPF_NETWORK
, network
);
945 ospf_network_set (struct ospf
*ospf
, struct prefix_ipv4
*p
,
946 struct in_addr area_id
)
948 struct ospf_network
*network
;
949 struct ospf_area
*area
;
950 struct route_node
*rn
;
951 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
953 rn
= route_node_get (ospf
->networks
, (struct prefix
*)p
);
956 /* There is already same network statement. */
957 route_unlock_node (rn
);
961 rn
->info
= network
= ospf_network_new (area_id
, ret
);
962 area
= ospf_area_get (ospf
, area_id
, ret
);
964 /* Run network config now. */
965 ospf_network_run ((struct prefix
*)p
, area
);
967 /* Update connected redistribute. */
968 update_redistributed(ospf
, 1); /* interfaces possibly added */
970 ospf_area_check_free (ospf
, area_id
);
976 ospf_network_unset (struct ospf
*ospf
, struct prefix_ipv4
*p
,
977 struct in_addr area_id
)
979 struct route_node
*rn
;
980 struct ospf_network
*network
;
981 struct listnode
*node
, *nnode
;
982 struct ospf_interface
*oi
;
984 rn
= route_node_lookup (ospf
->networks
, (struct prefix
*)p
);
989 route_unlock_node (rn
);
990 if (!IPV4_ADDR_SAME (&area_id
, &network
->area_id
))
993 ospf_network_free (ospf
, rn
->info
);
995 route_unlock_node (rn
); /* initial reference */
997 /* Find interfaces that not configured already. */
998 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
1001 struct connected
*co
= oi
->connected
;
1003 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1006 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
1008 if (rn
->info
== NULL
)
1011 if (ospf_network_match_iface(co
,&rn
->p
))
1014 route_unlock_node (rn
);
1022 ospf_area_check_free (ospf
, area_id
);
1026 /* Update connected redistribute. */
1027 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1028 ospf_area_check_free (ospf
, area_id
);
1034 ospf_interface_set (struct interface
*ifp
, struct in_addr area_id
)
1036 struct ospf_area
*area
;
1037 struct listnode
*cnode
;
1038 struct connected
*co
;
1040 struct ospf_if_params
*params
;
1041 struct ospf_interface
*oi
;
1042 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1044 if ((ospf
= ospf_lookup ()) == NULL
)
1045 return 1; /* Ospf not ready yet */
1047 params
= IF_DEF_PARAMS (ifp
);
1049 SET_IF_PARAM (params
, if_area
);
1050 params
->if_area
= area_id
;
1052 area
= ospf_area_get (ospf
, area_id
, ret
);
1054 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, co
))
1056 if (CHECK_FLAG(co
->flags
,ZEBRA_IFA_SECONDARY
))
1059 if (co
->address
->family
== AF_INET
)
1061 oi
= ospf_if_table_lookup(ifp
, co
->address
);
1063 oi
= add_ospf_interface(ifp
, area
, co
);
1065 /* if router_id is not configured, dont bring up
1067 * ospf_router_id_update() will call ospf_if_update
1068 * whenever r-id is configured instead.
1070 if ((area
->ospf
->router_id
.s_addr
!= 0) && if_is_operative (ifp
))
1075 /* Update connected redistribute. */
1076 update_redistributed(ospf
, 1); /* interface possibly added */
1081 ospf_interface_unset (struct interface
*ifp
)
1084 struct ospf_if_params
*params
;
1085 struct listnode
*node
, *nnode
;
1086 struct ospf_interface
*oi
;
1087 struct in_addr area_id
;
1089 ospf
= ospf_lookup ();
1091 return 1; /* Ospf not ready yet */
1093 params
= IF_DEF_PARAMS (ifp
);
1094 UNSET_IF_PARAM (params
, if_area
);
1095 area_id
= params
->if_area
;
1097 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
1099 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1101 if (oi
->ifp
== ifp
) ospf_if_free (oi
);
1104 /* Update connected redistribute. */
1105 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1106 ospf_area_check_free (ospf
, area_id
);
1111 /* Check whether interface matches given network
1112 * returns: 1, true. 0, false
1115 ospf_network_match_iface(const struct connected
*co
, const struct prefix
*net
)
1117 /* new approach: more elegant and conceptually clean */
1118 return prefix_match(net
, CONNECTED_PREFIX(co
));
1122 ospf_network_run_interface (struct prefix
*p
, struct ospf_area
*area
,
1123 struct interface
*ifp
)
1125 struct listnode
*cnode
;
1126 struct connected
*co
;
1128 if (memcmp (ifp
->name
, "VLINK", 5) == 0)
1131 /* if interface prefix is match specified prefix,
1132 then create socket and join multicast group. */
1133 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, co
))
1136 if (CHECK_FLAG(co
->flags
,ZEBRA_IFA_SECONDARY
))
1139 if (p
->family
== co
->address
->family
1140 && ! ospf_if_table_lookup(ifp
, co
->address
)
1141 && ospf_network_match_iface(co
,p
))
1143 struct ospf_interface
*oi
;
1145 oi
= ospf_if_new (area
->ospf
, ifp
, co
->address
);
1150 oi
->params
= ospf_lookup_if_params (ifp
, oi
->address
->u
.prefix4
);
1151 oi
->output_cost
= ospf_if_get_output_cost (oi
);
1153 /* Add pseudo neighbor. */
1154 ospf_nbr_add_self (oi
, oi
->ospf
->router_id
);
1156 /* Relate ospf interface to ospf instance. */
1157 oi
->ospf
= area
->ospf
;
1159 /* update network type as interface flag */
1160 /* If network type is specified previously,
1161 skip network type setting. */
1162 oi
->type
= IF_DEF_PARAMS (ifp
)->type
;
1164 ospf_area_add_if (oi
->area
, oi
);
1166 /* if router_id is not configured, dont bring up
1168 * ospf_router_id_update() will call ospf_if_update
1169 * whenever r-id is configured instead.
1171 if ((area
->ospf
->router_id
.s_addr
!= 0)
1172 && if_is_operative (ifp
))
1179 ospf_network_run (struct prefix
*p
, struct ospf_area
*area
)
1181 struct interface
*ifp
;
1182 struct listnode
*node
;
1184 /* Schedule Router ID Update. */
1185 if (area
->ospf
->router_id
.s_addr
== 0)
1186 ospf_router_id_update (area
->ospf
);
1188 /* Get target interface. */
1189 for (ALL_LIST_ELEMENTS_RO (om
->iflist
, node
, ifp
))
1190 ospf_network_run_interface (p
, area
, ifp
);
1194 ospf_ls_upd_queue_empty (struct ospf_interface
*oi
)
1196 struct route_node
*rn
;
1197 struct listnode
*node
, *nnode
;
1199 struct ospf_lsa
*lsa
;
1201 /* empty ls update queue */
1202 for (rn
= route_top (oi
->ls_upd_queue
); rn
;
1203 rn
= route_next (rn
))
1204 if ((lst
= (struct list
*) rn
->info
))
1206 for (ALL_LIST_ELEMENTS (lst
, node
, nnode
, lsa
))
1207 ospf_lsa_unlock (&lsa
); /* oi->ls_upd_queue */
1212 /* remove update event */
1213 if (oi
->t_ls_upd_event
)
1215 thread_cancel (oi
->t_ls_upd_event
);
1216 oi
->t_ls_upd_event
= NULL
;
1221 ospf_if_update (struct ospf
*ospf
, struct interface
*ifp
)
1223 struct route_node
*rn
;
1224 struct ospf_network
*network
;
1225 struct ospf_area
*area
;
1226 struct ospf_if_params
*params
;
1229 ospf
= ospf_lookup ();
1231 /* OSPF must be on and Router-ID must be configured. */
1232 if (!ospf
|| ospf
->router_id
.s_addr
== 0)
1235 /* Run each netowrk for this interface. */
1236 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
1237 if (rn
->info
!= NULL
)
1239 network
= (struct ospf_network
*) rn
->info
;
1240 area
= ospf_area_get (ospf
, network
->area_id
, network
->format
);
1241 ospf_network_run_interface (&rn
->p
, area
, ifp
);
1244 /* create oif for any new co */
1245 params
= IF_DEF_PARAMS (ifp
);
1246 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1248 ospf_interface_set (ifp
, params
->if_area
);
1253 ospf_remove_vls_through_area (struct ospf
*ospf
, struct ospf_area
*area
)
1255 struct listnode
*node
, *nnode
;
1256 struct ospf_vl_data
*vl_data
;
1258 for (ALL_LIST_ELEMENTS (ospf
->vlinks
, node
, nnode
, vl_data
))
1259 if (IPV4_ADDR_SAME (&vl_data
->vl_area_id
, &area
->area_id
))
1260 ospf_vl_delete (ospf
, vl_data
);
1264 static const struct message ospf_area_type_msg
[] =
1266 { OSPF_AREA_DEFAULT
, "Default" },
1267 { OSPF_AREA_STUB
, "Stub" },
1268 { OSPF_AREA_NSSA
, "NSSA" },
1270 static const int ospf_area_type_msg_max
= OSPF_AREA_TYPE_MAX
;
1273 ospf_area_type_set (struct ospf_area
*area
, int type
)
1275 struct listnode
*node
;
1276 struct ospf_interface
*oi
;
1278 if (area
->external_routing
== type
)
1280 if (IS_DEBUG_OSPF_EVENT
)
1281 zlog_debug ("Area[%s]: Types are the same, ignored.",
1282 inet_ntoa (area
->area_id
));
1286 area
->external_routing
= type
;
1288 if (IS_DEBUG_OSPF_EVENT
)
1289 zlog_debug ("Area[%s]: Configured as %s", inet_ntoa (area
->area_id
),
1290 LOOKUP (ospf_area_type_msg
, type
));
1292 switch (area
->external_routing
)
1294 case OSPF_AREA_DEFAULT
:
1295 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1296 if (oi
->nbr_self
!= NULL
)
1298 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1299 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1302 case OSPF_AREA_STUB
:
1303 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1304 if (oi
->nbr_self
!= NULL
)
1306 if (IS_DEBUG_OSPF_EVENT
)
1307 zlog_debug ("setting options on %s accordingly", IF_NAME (oi
));
1308 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1309 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1310 if (IS_DEBUG_OSPF_EVENT
)
1311 zlog_debug ("options set on %s: %x",
1312 IF_NAME (oi
), OPTIONS (oi
));
1315 case OSPF_AREA_NSSA
:
1316 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1317 if (oi
->nbr_self
!= NULL
)
1319 zlog_debug ("setting nssa options on %s accordingly", IF_NAME (oi
));
1320 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1321 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1322 zlog_debug ("options set on %s: %x", IF_NAME (oi
), OPTIONS (oi
));
1329 ospf_router_lsa_update_area (area
);
1330 ospf_schedule_abr_task (area
->ospf
);
1334 ospf_area_shortcut_set (struct ospf
*ospf
, struct ospf_area
*area
, int mode
)
1336 if (area
->shortcut_configured
== mode
)
1339 area
->shortcut_configured
= mode
;
1340 ospf_router_lsa_update_area (area
);
1341 ospf_schedule_abr_task (ospf
);
1343 ospf_area_check_free (ospf
, area
->area_id
);
1349 ospf_area_shortcut_unset (struct ospf
*ospf
, struct ospf_area
*area
)
1351 area
->shortcut_configured
= OSPF_SHORTCUT_DEFAULT
;
1352 ospf_router_lsa_update_area (area
);
1353 ospf_area_check_free (ospf
, area
->area_id
);
1354 ospf_schedule_abr_task (ospf
);
1360 ospf_area_vlink_count (struct ospf
*ospf
, struct ospf_area
*area
)
1362 struct ospf_vl_data
*vl
;
1363 struct listnode
*node
;
1366 for (ALL_LIST_ELEMENTS_RO (ospf
->vlinks
, node
, vl
))
1367 if (IPV4_ADDR_SAME (&vl
->vl_area_id
, &area
->area_id
))
1374 ospf_area_stub_set (struct ospf
*ospf
, struct in_addr area_id
)
1376 struct ospf_area
*area
;
1377 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1379 area
= ospf_area_get (ospf
, area_id
, format
);
1380 if (ospf_area_vlink_count (ospf
, area
))
1383 if (area
->external_routing
!= OSPF_AREA_STUB
)
1384 ospf_area_type_set (area
, OSPF_AREA_STUB
);
1390 ospf_area_stub_unset (struct ospf
*ospf
, struct in_addr area_id
)
1392 struct ospf_area
*area
;
1394 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1398 if (area
->external_routing
== OSPF_AREA_STUB
)
1399 ospf_area_type_set (area
, OSPF_AREA_DEFAULT
);
1401 ospf_area_check_free (ospf
, area_id
);
1407 ospf_area_no_summary_set (struct ospf
*ospf
, struct in_addr area_id
)
1409 struct ospf_area
*area
;
1410 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1412 area
= ospf_area_get (ospf
, area_id
, format
);
1413 area
->no_summary
= 1;
1419 ospf_area_no_summary_unset (struct ospf
*ospf
, struct in_addr area_id
)
1421 struct ospf_area
*area
;
1423 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1427 area
->no_summary
= 0;
1428 ospf_area_check_free (ospf
, area_id
);
1434 ospf_area_nssa_set (struct ospf
*ospf
, struct in_addr area_id
)
1436 struct ospf_area
*area
;
1437 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1439 area
= ospf_area_get (ospf
, area_id
, format
);
1440 if (ospf_area_vlink_count (ospf
, area
))
1443 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1445 ospf_area_type_set (area
, OSPF_AREA_NSSA
);
1449 /* set NSSA area defaults */
1450 area
->no_summary
= 0;
1451 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1452 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1453 area
->NSSATranslatorStabilityInterval
= OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1459 ospf_area_nssa_unset (struct ospf
*ospf
, struct in_addr area_id
)
1461 struct ospf_area
*area
;
1463 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1467 if (area
->external_routing
== OSPF_AREA_NSSA
)
1470 ospf_area_type_set (area
, OSPF_AREA_DEFAULT
);
1473 ospf_area_check_free (ospf
, area_id
);
1479 ospf_area_nssa_translator_role_set (struct ospf
*ospf
, struct in_addr area_id
,
1482 struct ospf_area
*area
;
1484 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1488 area
->NSSATranslatorRole
= role
;
1494 /* XXX: unused? Leave for symmetry? */
1496 ospf_area_nssa_translator_role_unset (struct ospf
*ospf
,
1497 struct in_addr area_id
)
1499 struct ospf_area
*area
;
1501 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1505 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1507 ospf_area_check_free (ospf
, area_id
);
1514 ospf_area_export_list_set (struct ospf
*ospf
,
1515 struct ospf_area
*area
, const char *list_name
)
1517 struct access_list
*list
;
1518 list
= access_list_lookup (AFI_IP
, list_name
);
1520 EXPORT_LIST (area
) = list
;
1522 if (EXPORT_NAME (area
))
1523 free (EXPORT_NAME (area
));
1525 EXPORT_NAME (area
) = strdup (list_name
);
1526 ospf_schedule_abr_task (ospf
);
1532 ospf_area_export_list_unset (struct ospf
*ospf
, struct ospf_area
* area
)
1535 EXPORT_LIST (area
) = 0;
1537 if (EXPORT_NAME (area
))
1538 free (EXPORT_NAME (area
));
1540 EXPORT_NAME (area
) = NULL
;
1542 ospf_area_check_free (ospf
, area
->area_id
);
1544 ospf_schedule_abr_task (ospf
);
1550 ospf_area_import_list_set (struct ospf
*ospf
, struct ospf_area
*area
,
1553 struct access_list
*list
;
1554 list
= access_list_lookup (AFI_IP
, name
);
1556 IMPORT_LIST (area
) = list
;
1558 if (IMPORT_NAME (area
))
1559 free (IMPORT_NAME (area
));
1561 IMPORT_NAME (area
) = strdup (name
);
1562 ospf_schedule_abr_task (ospf
);
1568 ospf_area_import_list_unset (struct ospf
*ospf
, struct ospf_area
* area
)
1570 IMPORT_LIST (area
) = 0;
1572 if (IMPORT_NAME (area
))
1573 free (IMPORT_NAME (area
));
1575 IMPORT_NAME (area
) = NULL
;
1576 ospf_area_check_free (ospf
, area
->area_id
);
1578 ospf_schedule_abr_task (ospf
);
1584 ospf_timers_refresh_set (struct ospf
*ospf
, int interval
)
1588 if (ospf
->lsa_refresh_interval
== interval
)
1591 time_left
= ospf
->lsa_refresh_interval
-
1592 (monotime(NULL
) - ospf
->lsa_refresher_started
);
1594 if (time_left
> interval
)
1596 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
1597 ospf
->t_lsa_refresher
=
1598 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
, interval
,
1601 ospf
->lsa_refresh_interval
= interval
;
1607 ospf_timers_refresh_unset (struct ospf
*ospf
)
1611 time_left
= ospf
->lsa_refresh_interval
-
1612 (monotime(NULL
) - ospf
->lsa_refresher_started
);
1614 if (time_left
> OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
1616 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
1617 ospf
->t_lsa_refresher
=
1618 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1619 OSPF_LSA_REFRESH_INTERVAL_DEFAULT
, NULL
);
1622 ospf
->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
1628 static struct ospf_nbr_nbma
*
1629 ospf_nbr_nbma_new (void)
1631 struct ospf_nbr_nbma
*nbr_nbma
;
1633 nbr_nbma
= XCALLOC (MTYPE_OSPF_NEIGHBOR_STATIC
,
1634 sizeof (struct ospf_nbr_nbma
));
1636 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1637 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1643 ospf_nbr_nbma_free (struct ospf_nbr_nbma
*nbr_nbma
)
1645 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
1649 ospf_nbr_nbma_delete (struct ospf
*ospf
, struct ospf_nbr_nbma
*nbr_nbma
)
1651 struct route_node
*rn
;
1652 struct prefix_ipv4 p
;
1655 p
.prefix
= nbr_nbma
->addr
;
1656 p
.prefixlen
= IPV4_MAX_BITLEN
;
1658 rn
= route_node_lookup (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1661 ospf_nbr_nbma_free (rn
->info
);
1663 route_unlock_node (rn
);
1664 route_unlock_node (rn
);
1669 ospf_nbr_nbma_down (struct ospf_nbr_nbma
*nbr_nbma
)
1671 OSPF_TIMER_OFF (nbr_nbma
->t_poll
);
1675 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
1676 OSPF_NSM_EVENT_EXECUTE (nbr_nbma
->nbr
, NSM_KillNbr
);
1680 listnode_delete (nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
1684 ospf_nbr_nbma_add (struct ospf_nbr_nbma
*nbr_nbma
,
1685 struct ospf_interface
*oi
)
1687 struct ospf_neighbor
*nbr
;
1688 struct route_node
*rn
;
1691 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1694 if (nbr_nbma
->nbr
!= NULL
)
1697 if (IPV4_ADDR_SAME (&oi
->nbr_self
->address
.u
.prefix4
, &nbr_nbma
->addr
))
1701 listnode_add (oi
->nbr_nbma
, nbr_nbma
);
1703 /* Get neighbor information from table. */
1705 p
.prefixlen
= IPV4_MAX_BITLEN
;
1706 p
.u
.prefix4
= nbr_nbma
->addr
;
1708 rn
= route_node_get (oi
->nbrs
, (struct prefix
*)&p
);
1712 nbr
->nbr_nbma
= nbr_nbma
;
1713 nbr_nbma
->nbr
= nbr
;
1715 route_unlock_node (rn
);
1719 nbr
= rn
->info
= ospf_nbr_new (oi
);
1720 nbr
->state
= NSM_Down
;
1721 nbr
->src
= nbr_nbma
->addr
;
1722 nbr
->nbr_nbma
= nbr_nbma
;
1723 nbr
->priority
= nbr_nbma
->priority
;
1726 nbr_nbma
->nbr
= nbr
;
1728 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_Start
);
1733 ospf_nbr_nbma_if_update (struct ospf
*ospf
, struct ospf_interface
*oi
)
1735 struct ospf_nbr_nbma
*nbr_nbma
;
1736 struct route_node
*rn
;
1737 struct prefix_ipv4 p
;
1739 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1742 for (rn
= route_top (ospf
->nbr_nbma
); rn
; rn
= route_next (rn
))
1743 if ((nbr_nbma
= rn
->info
))
1744 if (nbr_nbma
->oi
== NULL
&& nbr_nbma
->nbr
== NULL
)
1747 p
.prefix
= nbr_nbma
->addr
;
1748 p
.prefixlen
= IPV4_MAX_BITLEN
;
1750 if (prefix_match (oi
->address
, (struct prefix
*)&p
))
1751 ospf_nbr_nbma_add (nbr_nbma
, oi
);
1755 struct ospf_nbr_nbma
*
1756 ospf_nbr_nbma_lookup (struct ospf
*ospf
, struct in_addr nbr_addr
)
1758 struct route_node
*rn
;
1759 struct prefix_ipv4 p
;
1762 p
.prefix
= nbr_addr
;
1763 p
.prefixlen
= IPV4_MAX_BITLEN
;
1765 rn
= route_node_lookup (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1768 route_unlock_node (rn
);
1774 struct ospf_nbr_nbma
*
1775 ospf_nbr_nbma_lookup_next (struct ospf
*ospf
, struct in_addr
*addr
, int first
)
1778 struct ospf_nbr_nbma
*nbr_nbma
;
1779 struct listnode
*node
;
1786 for (ALL_LIST_ELEMENTS_RO (ospf
->nbr_nbma
, node
, nbr_nbma
))
1790 *addr
= nbr_nbma
->addr
;
1793 else if (ntohl (nbr_nbma
->addr
.s_addr
) > ntohl (addr
->s_addr
))
1795 *addr
= nbr_nbma
->addr
;
1804 ospf_nbr_nbma_set (struct ospf
*ospf
, struct in_addr nbr_addr
)
1806 struct ospf_nbr_nbma
*nbr_nbma
;
1807 struct ospf_interface
*oi
;
1808 struct prefix_ipv4 p
;
1809 struct route_node
*rn
;
1810 struct listnode
*node
;
1812 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1816 nbr_nbma
= ospf_nbr_nbma_new ();
1817 nbr_nbma
->addr
= nbr_addr
;
1820 p
.prefix
= nbr_addr
;
1821 p
.prefixlen
= IPV4_MAX_BITLEN
;
1823 rn
= route_node_get (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1825 route_unlock_node (rn
);
1826 rn
->info
= nbr_nbma
;
1828 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
1830 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1831 if (prefix_match (oi
->address
, (struct prefix
*)&p
))
1833 ospf_nbr_nbma_add (nbr_nbma
, oi
);
1842 ospf_nbr_nbma_unset (struct ospf
*ospf
, struct in_addr nbr_addr
)
1844 struct ospf_nbr_nbma
*nbr_nbma
;
1846 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1847 if (nbr_nbma
== NULL
)
1850 ospf_nbr_nbma_down (nbr_nbma
);
1851 ospf_nbr_nbma_delete (ospf
, nbr_nbma
);
1857 ospf_nbr_nbma_priority_set (struct ospf
*ospf
, struct in_addr nbr_addr
,
1860 struct ospf_nbr_nbma
*nbr_nbma
;
1862 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1863 if (nbr_nbma
== NULL
)
1866 if (nbr_nbma
->priority
!= priority
)
1867 nbr_nbma
->priority
= priority
;
1873 ospf_nbr_nbma_priority_unset (struct ospf
*ospf
, struct in_addr nbr_addr
)
1875 struct ospf_nbr_nbma
*nbr_nbma
;
1877 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1878 if (nbr_nbma
== NULL
)
1881 if (nbr_nbma
!= OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
1882 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1888 ospf_nbr_nbma_poll_interval_set (struct ospf
*ospf
, struct in_addr nbr_addr
,
1889 unsigned int interval
)
1891 struct ospf_nbr_nbma
*nbr_nbma
;
1893 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1894 if (nbr_nbma
== NULL
)
1897 if (nbr_nbma
->v_poll
!= interval
)
1899 nbr_nbma
->v_poll
= interval
;
1900 if (nbr_nbma
->oi
&& ospf_if_is_up (nbr_nbma
->oi
))
1902 OSPF_TIMER_OFF (nbr_nbma
->t_poll
);
1903 OSPF_POLL_TIMER_ON (nbr_nbma
->t_poll
, ospf_poll_timer
,
1912 ospf_nbr_nbma_poll_interval_unset (struct ospf
*ospf
, struct in_addr addr
)
1914 struct ospf_nbr_nbma
*nbr_nbma
;
1916 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, addr
);
1917 if (nbr_nbma
== NULL
)
1920 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
1921 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1927 ospf_master_init (struct thread_master
*master
)
1929 memset (&ospf_master
, 0, sizeof (struct ospf_master
));
1932 om
->ospf
= list_new ();
1933 om
->master
= master
;