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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 ospf
*, struct interface
*,
76 struct prefix
*, struct ospf_area
*);
77 static void ospf_network_run_subnet(struct ospf
*, struct connected
*,
78 struct prefix
*, struct ospf_area
*);
79 static int ospf_network_match_iface(const struct connected
*,
80 const struct prefix
*);
81 static void ospf_finish_final(struct ospf
*);
83 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
85 void ospf_router_id_update(struct ospf
*ospf
)
87 struct in_addr router_id
, router_id_old
;
88 struct ospf_interface
*oi
;
89 struct interface
*ifp
;
90 struct listnode
*node
;
93 if (!ospf
->oi_running
) {
94 if (IS_DEBUG_OSPF_EVENT
)
96 "Router ospf not configured -- Router-ID update postponed");
100 if (IS_DEBUG_OSPF_EVENT
)
101 zlog_debug("Router-ID[OLD:%s]: Update",
102 inet_ntoa(ospf
->router_id
));
104 router_id_old
= ospf
->router_id
;
106 /* Select the router ID based on these priorities:
107 1. Statically assigned router ID is always the first choice.
108 2. If there is no statically assigned router ID, then try to stick
109 with the most recent value, since changing router ID's is very
111 3. Last choice: just go with whatever the zebra daemon recommends.
113 if (ospf
->router_id_static
.s_addr
!= 0)
114 router_id
= ospf
->router_id_static
;
115 else if (ospf
->router_id
.s_addr
!= 0)
116 router_id
= ospf
->router_id
;
118 router_id
= router_id_zebra
;
121 if (!IPV4_ADDR_SAME(&router_id_old
, &router_id
)) {
123 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
) {
134 /* Originate each redistributed external route. */
135 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
136 if (ospf
->external_origin
& (1 << type
))
139 ospf_external_lsa_originate_timer
,
141 /* Originate Deafult. */
142 if (ospf
->external_origin
& (1 << ZEBRA_ROUTE_MAX
))
143 thread_add_event(master
,
144 ospf_default_originate_timer
,
147 ospf
->external_origin
= 0;
150 /* Flush (inline) all external LSAs based on the OSPF_LSA_SELF
153 struct route_node
*rn
;
154 struct ospf_lsa
*lsa
;
156 LSDB_LOOP(EXTERNAL_LSDB(ospf
), rn
, lsa
)
157 if (IS_LSA_SELF(lsa
))
158 ospf_lsa_flush_schedule(ospf
, lsa
);
161 ospf
->router_id
= router_id
;
162 if (IS_DEBUG_OSPF_EVENT
)
163 zlog_debug("Router-ID[NEW:%s]: Update",
164 inet_ntoa(ospf
->router_id
));
166 /* Flush (inline) all external LSAs which now match the new
168 need to adjust the OSPF_LSA_SELF flag, so the flush doesnt
170 asserts in ospf_refresher_unregister_lsa(). This step is
172 because the current quagga code does look-up for
174 based on the self router-id alone but expects OSPF_LSA_SELF
178 struct route_node
*rn
;
179 struct ospf_lsa
*lsa
;
181 LSDB_LOOP(EXTERNAL_LSDB(ospf
), rn
, lsa
)
183 /* AdvRouter and Router ID is the same. */
184 if (IPV4_ADDR_SAME(&lsa
->data
->adv_router
,
187 OSPF_LSA_SELF_CHECKED
);
188 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF
);
189 ospf_lsa_flush_schedule(ospf
, lsa
);
194 /* Originate each redistributed external route. */
195 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
196 thread_add_event(master
,
197 ospf_external_lsa_originate_timer
,
199 thread_add_event(master
, ospf_default_originate_timer
, ospf
, 0,
202 /* update router-lsa's for each area */
203 ospf_router_lsa_update(ospf
);
205 /* update ospf_interface's */
206 for (ALL_LIST_ELEMENTS_RO(om
->iflist
, node
, ifp
))
207 ospf_if_update(ospf
, ifp
);
211 /* For OSPF area sort by area id. */
212 static int ospf_area_id_cmp(struct ospf_area
*a1
, struct ospf_area
*a2
)
214 if (ntohl(a1
->area_id
.s_addr
) > ntohl(a2
->area_id
.s_addr
))
216 if (ntohl(a1
->area_id
.s_addr
) < ntohl(a2
->area_id
.s_addr
))
221 /* Allocate new ospf structure. */
222 static struct ospf
*ospf_new(u_short instance
)
226 struct ospf
*new = XCALLOC(MTYPE_OSPF_TOP
, sizeof(struct ospf
));
228 new->instance
= instance
;
229 new->router_id
.s_addr
= htonl(0);
230 new->router_id_static
.s_addr
= htonl(0);
232 new->abr_type
= OSPF_ABR_DEFAULT
;
233 new->oiflist
= list_new();
234 new->vlinks
= list_new();
235 new->areas
= list_new();
236 new->areas
->cmp
= (int (*)(void *, void *))ospf_area_id_cmp
;
237 new->networks
= route_table_init();
238 new->nbr_nbma
= route_table_init();
240 new->lsdb
= ospf_lsdb_new();
242 new->default_originate
= DEFAULT_ORIGINATE_NONE
;
244 new->passive_interface_default
= OSPF_IF_ACTIVE
;
246 new->new_external_route
= route_table_init();
247 new->old_external_route
= route_table_init();
248 new->external_lsas
= route_table_init();
250 new->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
251 new->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
252 new->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
254 /* Distribute parameter init. */
255 for (i
= 0; i
<= ZEBRA_ROUTE_MAX
; i
++) {
258 new->default_metric
= -1;
259 new->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
262 new->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
263 new->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
265 /* SPF timer value init. */
266 new->spf_delay
= OSPF_SPF_DELAY_DEFAULT
;
267 new->spf_holdtime
= OSPF_SPF_HOLDTIME_DEFAULT
;
268 new->spf_max_holdtime
= OSPF_SPF_MAX_HOLDTIME_DEFAULT
;
269 new->spf_hold_multiplier
= 1;
272 new->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
273 new->maxage_lsa
= route_table_init();
274 new->t_maxage_walker
= NULL
;
275 thread_add_timer(master
, ospf_lsa_maxage_walker
, new,
276 OSPF_LSA_MAXAGE_CHECK_INTERVAL
, &new->t_maxage_walker
);
278 /* Distance table init. */
279 new->distance_table
= route_table_init();
281 new->lsa_refresh_queue
.index
= 0;
282 new->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
283 new->t_lsa_refresher
= NULL
;
284 thread_add_timer(master
, ospf_lsa_refresh_walker
, new,
285 new->lsa_refresh_interval
, &new->t_lsa_refresher
);
286 new->lsa_refresher_started
= monotime(NULL
);
288 if ((new->fd
= ospf_sock_init()) < 0) {
290 "ospf_new: fatal error: ospf_sock_init was unable to open "
294 if ((new->ibuf
= stream_new(OSPF_MAX_PACKET_SIZE
+ 1)) == NULL
) {
296 "ospf_new: fatal error: stream_new(%u) failed allocating ibuf",
297 OSPF_MAX_PACKET_SIZE
+ 1);
301 thread_add_read(master
, ospf_read
, new, new->fd
, &new->t_read
);
302 new->oi_write_q
= list_new();
303 new->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
305 /* Enable "log-adjacency-changes" */
306 #if DFLT_OSPF_LOG_ADJACENCY_CHANGES
307 SET_FLAG(new->config
, OSPF_LOG_ADJACENCY_CHANGES
);
315 struct ospf
*ospf_lookup()
317 if (listcount(om
->ospf
) == 0)
320 return listgetdata((struct listnode
*)listhead(om
->ospf
));
323 struct ospf
*ospf_lookup_instance(u_short instance
)
326 struct listnode
*node
, *nnode
;
328 if (listcount(om
->ospf
) == 0)
331 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
332 if ((ospf
->instance
== 0 && instance
== 0)
333 || (ospf
->instance
&& instance
334 && ospf
->instance
== instance
))
340 static int ospf_is_ready(struct ospf
*ospf
)
342 /* OSPF must be on and Router-ID must be configured. */
343 if (!ospf
|| ospf
->router_id
.s_addr
== 0)
349 static void ospf_add(struct ospf
*ospf
)
351 listnode_add(om
->ospf
, ospf
);
354 static void ospf_delete(struct ospf
*ospf
)
356 listnode_delete(om
->ospf
, ospf
);
359 struct ospf
*ospf_get()
363 ospf
= ospf_lookup();
368 if (ospf
->router_id_static
.s_addr
== 0)
369 ospf_router_id_update(ospf
);
371 ospf_opaque_type11_lsa_init(ospf
);
377 struct ospf
*ospf_get_instance(u_short instance
)
381 ospf
= ospf_lookup_instance(instance
);
383 ospf
= ospf_new(instance
);
386 if (ospf
->router_id_static
.s_addr
== 0)
387 ospf_router_id_update(ospf
);
389 ospf_opaque_type11_lsa_init(ospf
);
395 /* Handle the second half of deferred shutdown. This is called either
396 * from the deferred-shutdown timer thread, or directly through
397 * ospf_deferred_shutdown_check.
399 * Function is to cleanup G-R state, if required then call ospf_finish_final
400 * to complete shutdown of this ospf instance. Possibly exit if the
401 * whole process is being shutdown and this was the last OSPF instance.
403 static void ospf_deferred_shutdown_finish(struct ospf
*ospf
)
405 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
406 OSPF_TIMER_OFF(ospf
->t_deferred_shutdown
);
408 ospf_finish_final(ospf
);
410 /* *ospf is now invalid */
412 /* ospfd being shut-down? If so, was this the last ospf instance? */
413 if (CHECK_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
)
414 && (listcount(om
->ospf
) == 0)) {
421 /* Timer thread for G-R */
422 static int ospf_deferred_shutdown_timer(struct thread
*t
)
424 struct ospf
*ospf
= THREAD_ARG(t
);
426 ospf_deferred_shutdown_finish(ospf
);
431 /* Check whether deferred-shutdown must be scheduled, otherwise call
432 * down directly into second-half of instance shutdown.
434 static void ospf_deferred_shutdown_check(struct ospf
*ospf
)
436 unsigned long timeout
;
438 struct ospf_area
*area
;
440 /* deferred shutdown already running? */
441 if (ospf
->t_deferred_shutdown
)
444 /* Should we try push out max-metric LSAs? */
445 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
) {
446 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
447 SET_FLAG(area
->stub_router_state
,
448 OSPF_AREA_ADMIN_STUB_ROUTED
);
450 if (!CHECK_FLAG(area
->stub_router_state
,
451 OSPF_AREA_IS_STUB_ROUTED
))
452 ospf_router_lsa_update_area(area
);
454 timeout
= ospf
->stub_router_shutdown_time
;
456 /* No timer needed */
457 ospf_deferred_shutdown_finish(ospf
);
461 OSPF_TIMER_ON(ospf
->t_deferred_shutdown
, ospf_deferred_shutdown_timer
,
466 /* Shut down the entire process */
467 void ospf_terminate(void)
470 struct listnode
*node
, *nnode
;
472 /* shutdown already in progress */
473 if (CHECK_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
))
476 SET_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
);
478 /* exit immediately if OSPF not actually running */
479 if (listcount(om
->ospf
) == 0)
483 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
486 /* Deliberately go back up, hopefully to thread scheduler, as
487 * One or more ospf_finish()'s may have deferred shutdown to a timer
490 zclient_stop(zclient
);
491 zclient_free(zclient
);
494 void ospf_finish(struct ospf
*ospf
)
496 /* let deferred shutdown decide */
497 ospf_deferred_shutdown_check(ospf
);
499 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
500 * deferred to expiry of G-S timer thread. Return back up, hopefully
501 * to thread scheduler.
506 /* Final cleanup of ospf instance */
507 static void ospf_finish_final(struct ospf
*ospf
)
509 struct route_node
*rn
;
510 struct ospf_nbr_nbma
*nbr_nbma
;
511 struct ospf_lsa
*lsa
;
512 struct interface
*ifp
;
513 struct ospf_interface
*oi
;
514 struct ospf_area
*area
;
515 struct ospf_vl_data
*vl_data
;
516 struct listnode
*node
, *nnode
;
518 u_short instance
= 0;
522 ospf_opaque_type11_lsa_term(ospf
);
524 /* be nice if this worked, but it doesn't */
525 /*ospf_flush_self_originated_lsas_now (ospf);*/
527 /* Unregister redistribution */
528 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
529 struct list
*red_list
;
530 struct ospf_redist
*red
;
532 red_list
= ospf
->redist
[i
];
536 for (ALL_LIST_ELEMENTS(red_list
, node
, nnode
, red
))
537 ospf_redistribute_unset(ospf
, i
, red
->instance
);
539 ospf_redistribute_default_unset(ospf
);
541 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
542 ospf_remove_vls_through_area(ospf
, area
);
544 for (ALL_LIST_ELEMENTS(ospf
->vlinks
, node
, nnode
, vl_data
))
545 ospf_vl_delete(ospf
, vl_data
);
547 list_delete(ospf
->vlinks
);
549 /* Remove any ospf interface config params */
550 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
)) {
551 struct ospf_if_params
*params
;
553 params
= IF_DEF_PARAMS(ifp
);
554 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
555 UNSET_IF_PARAM(params
, if_area
);
558 /* Reset interface. */
559 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
562 /* Clear static neighbors */
563 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
564 if ((nbr_nbma
= rn
->info
)) {
565 OSPF_POLL_TIMER_OFF(nbr_nbma
->t_poll
);
568 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
569 nbr_nbma
->nbr
= NULL
;
573 listnode_delete(nbr_nbma
->oi
->nbr_nbma
,
578 XFREE(MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
581 route_table_finish(ospf
->nbr_nbma
);
583 /* Clear networks and Areas. */
584 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
585 struct ospf_network
*network
;
587 if ((network
= rn
->info
) != NULL
) {
588 ospf_network_free(ospf
, network
);
590 route_unlock_node(rn
);
594 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
595 listnode_delete(ospf
->areas
, area
);
596 ospf_area_free(area
);
599 /* Cancel all timers. */
600 OSPF_TIMER_OFF(ospf
->t_external_lsa
);
601 OSPF_TIMER_OFF(ospf
->t_spf_calc
);
602 OSPF_TIMER_OFF(ospf
->t_ase_calc
);
603 OSPF_TIMER_OFF(ospf
->t_maxage
);
604 OSPF_TIMER_OFF(ospf
->t_maxage_walker
);
605 OSPF_TIMER_OFF(ospf
->t_abr_task
);
606 OSPF_TIMER_OFF(ospf
->t_asbr_check
);
607 OSPF_TIMER_OFF(ospf
->t_distribute_update
);
608 OSPF_TIMER_OFF(ospf
->t_lsa_refresher
);
609 OSPF_TIMER_OFF(ospf
->t_read
);
610 OSPF_TIMER_OFF(ospf
->t_write
);
611 OSPF_TIMER_OFF(ospf
->t_opaque_lsa_self
);
614 stream_free(ospf
->ibuf
);
616 LSDB_LOOP(OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
617 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
618 LSDB_LOOP(EXTERNAL_LSDB(ospf
), rn
, lsa
)
619 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
621 ospf_lsdb_delete_all(ospf
->lsdb
);
622 ospf_lsdb_free(ospf
->lsdb
);
624 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
625 struct ospf_lsa
*lsa
;
627 if ((lsa
= rn
->info
) != NULL
) {
628 ospf_lsa_unlock(&lsa
);
631 route_unlock_node(rn
);
633 route_table_finish(ospf
->maxage_lsa
);
636 ospf_route_table_free(ospf
->old_table
);
637 if (ospf
->new_table
) {
638 ospf_route_delete(ospf
->new_table
);
639 ospf_route_table_free(ospf
->new_table
);
642 ospf_rtrs_free(ospf
->old_rtrs
);
644 ospf_rtrs_free(ospf
->new_rtrs
);
645 if (ospf
->new_external_route
) {
646 ospf_route_delete(ospf
->new_external_route
);
647 ospf_route_table_free(ospf
->new_external_route
);
649 if (ospf
->old_external_route
) {
650 ospf_route_delete(ospf
->old_external_route
);
651 ospf_route_table_free(ospf
->old_external_route
);
653 if (ospf
->external_lsas
) {
654 ospf_ase_external_lsas_finish(ospf
->external_lsas
);
657 list_delete(ospf
->areas
);
659 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
)) {
669 if (ext
->external_info
)
670 for (rn
= route_top(ext
->external_info
); rn
;
671 rn
= route_next(rn
)) {
672 if (rn
->info
== NULL
)
675 XFREE(MTYPE_OSPF_EXTERNAL_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
);
698 /* allocate new OSPF Area object */
699 static struct ospf_area
*ospf_area_new(struct ospf
*ospf
,
700 struct in_addr area_id
)
702 struct ospf_area
*new;
704 /* Allocate new config_network. */
705 new = XCALLOC(MTYPE_OSPF_AREA
, sizeof(struct ospf_area
));
709 new->area_id
= area_id
;
710 new->area_id_fmt
= OSPF_AREA_ID_FMT_DOTTEDQUAD
;
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;
733 static void ospf_area_free(struct ospf_area
*area
)
735 struct route_node
*rn
;
736 struct ospf_lsa
*lsa
;
739 LSDB_LOOP(ROUTER_LSDB(area
), rn
, lsa
)
740 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
741 LSDB_LOOP(NETWORK_LSDB(area
), rn
, lsa
)
742 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
743 LSDB_LOOP(SUMMARY_LSDB(area
), rn
, lsa
)
744 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
745 LSDB_LOOP(ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
746 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
748 LSDB_LOOP(NSSA_LSDB(area
), rn
, lsa
)
749 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
750 LSDB_LOOP(OPAQUE_AREA_LSDB(area
), rn
, lsa
)
751 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
752 LSDB_LOOP(OPAQUE_LINK_LSDB(area
), rn
, lsa
)
753 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
755 ospf_lsdb_delete_all(area
->lsdb
);
756 ospf_lsdb_free(area
->lsdb
);
758 ospf_lsa_unlock(&area
->router_lsa_self
);
760 route_table_finish(area
->ranges
);
761 list_delete(area
->oiflist
);
763 if (EXPORT_NAME(area
))
764 free(EXPORT_NAME(area
));
766 if (IMPORT_NAME(area
))
767 free(IMPORT_NAME(area
));
770 OSPF_TIMER_OFF(area
->t_stub_router
);
771 OSPF_TIMER_OFF(area
->t_opaque_lsa_self
);
773 if (OSPF_IS_AREA_BACKBONE(area
))
774 area
->ospf
->backbone
= NULL
;
776 XFREE(MTYPE_OSPF_AREA
, area
);
779 void ospf_area_check_free(struct ospf
*ospf
, struct in_addr area_id
)
781 struct ospf_area
*area
;
783 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
784 if (area
&& listcount(area
->oiflist
) == 0 && area
->ranges
->top
== NULL
785 && area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
786 && area
->external_routing
== OSPF_AREA_DEFAULT
787 && area
->no_summary
== 0 && area
->default_cost
== 1
788 && EXPORT_NAME(area
) == NULL
&& IMPORT_NAME(area
) == NULL
789 && area
->auth_type
== OSPF_AUTH_NULL
) {
790 listnode_delete(ospf
->areas
, area
);
791 ospf_area_free(area
);
795 struct ospf_area
*ospf_area_get(struct ospf
*ospf
, struct in_addr area_id
)
797 struct ospf_area
*area
;
799 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
801 area
= ospf_area_new(ospf
, area_id
);
802 listnode_add_sort(ospf
->areas
, area
);
803 ospf_check_abr_status(ospf
);
804 if (ospf
->stub_router_admin_set
805 == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
) {
806 SET_FLAG(area
->stub_router_state
,
807 OSPF_AREA_ADMIN_STUB_ROUTED
);
814 struct ospf_area
*ospf_area_lookup_by_area_id(struct ospf
*ospf
,
815 struct in_addr area_id
)
817 struct ospf_area
*area
;
818 struct listnode
*node
;
820 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
821 if (IPV4_ADDR_SAME(&area
->area_id
, &area_id
))
827 void ospf_area_add_if(struct ospf_area
*area
, struct ospf_interface
*oi
)
829 listnode_add(area
->oiflist
, oi
);
832 void ospf_area_del_if(struct ospf_area
*area
, struct ospf_interface
*oi
)
834 listnode_delete(area
->oiflist
, oi
);
838 static void add_ospf_interface(struct connected
*co
, struct ospf_area
*area
)
840 struct ospf_interface
*oi
;
842 oi
= ospf_if_new(area
->ospf
, co
->ifp
, co
->address
);
847 oi
->params
= ospf_lookup_if_params(co
->ifp
, oi
->address
->u
.prefix4
);
848 oi
->output_cost
= ospf_if_get_output_cost(oi
);
850 /* Relate ospf interface to ospf instance. */
851 oi
->ospf
= area
->ospf
;
853 /* update network type as interface flag */
854 /* If network type is specified previously,
855 skip network type setting. */
856 oi
->type
= IF_DEF_PARAMS(co
->ifp
)->type
;
858 /* Add pseudo neighbor. */
859 ospf_nbr_self_reset(oi
, oi
->ospf
->router_id
);
861 ospf_area_add_if(oi
->area
, oi
);
864 * if router_id is not configured, dont bring up
866 * ospf_router_id_update() will call ospf_if_update
867 * whenever r-id is configured instead.
869 if ((area
->ospf
->router_id
.s_addr
!= 0) && if_is_operative(co
->ifp
))
873 static void update_redistributed(struct ospf
*ospf
, int add_to_ospf
)
875 struct route_node
*rn
;
876 struct external_info
*ei
;
877 struct ospf_external
*ext
;
879 if (ospf_is_type_redistributed(ZEBRA_ROUTE_CONNECT
, 0))
880 if ((ext
= ospf_external_lookup(ZEBRA_ROUTE_CONNECT
, 0))
881 && EXTERNAL_INFO(ext
)) {
882 for (rn
= route_top(EXTERNAL_INFO(ext
)); rn
;
883 rn
= route_next(rn
)) {
884 if ((ei
= rn
->info
) != NULL
) {
886 if (ospf_external_info_find_lsa(
888 if (!ospf_distribute_check_connected(
890 ospf_external_lsa_flush(
894 ei
->ifindex
/*, ei->nexthop */);
896 if (!ospf_external_info_find_lsa(
898 if (ospf_distribute_check_connected(
900 ospf_external_lsa_originate(
909 /* Config network statement related functions. */
910 static struct ospf_network
*ospf_network_new(struct in_addr area_id
)
912 struct ospf_network
*new;
913 new = XCALLOC(MTYPE_OSPF_NETWORK
, sizeof(struct ospf_network
));
915 new->area_id
= area_id
;
916 new->area_id_fmt
= OSPF_AREA_ID_FMT_DOTTEDQUAD
;
921 static void ospf_network_free(struct ospf
*ospf
, struct ospf_network
*network
)
923 ospf_area_check_free(ospf
, network
->area_id
);
924 ospf_schedule_abr_task(ospf
);
925 XFREE(MTYPE_OSPF_NETWORK
, network
);
928 int ospf_network_set(struct ospf
*ospf
, struct prefix_ipv4
*p
,
929 struct in_addr area_id
, int df
)
931 struct ospf_network
*network
;
932 struct ospf_area
*area
;
933 struct route_node
*rn
;
935 rn
= route_node_get(ospf
->networks
, (struct prefix
*)p
);
937 /* There is already same network statement. */
938 route_unlock_node(rn
);
942 rn
->info
= network
= ospf_network_new(area_id
);
943 network
->area_id_fmt
= df
;
944 area
= ospf_area_get(ospf
, area_id
);
945 ospf_area_display_format_set(ospf
, area
, df
);
947 /* Run network config now. */
948 ospf_network_run((struct prefix
*)p
, area
);
950 /* Update connected redistribute. */
951 update_redistributed(ospf
, 1); /* interfaces possibly added */
953 ospf_area_check_free(ospf
, area_id
);
958 int ospf_network_unset(struct ospf
*ospf
, struct prefix_ipv4
*p
,
959 struct in_addr area_id
)
961 struct route_node
*rn
;
962 struct ospf_network
*network
;
963 struct listnode
*node
, *nnode
;
964 struct ospf_interface
*oi
;
966 rn
= route_node_lookup(ospf
->networks
, (struct prefix
*)p
);
971 route_unlock_node(rn
);
972 if (!IPV4_ADDR_SAME(&area_id
, &network
->area_id
))
975 ospf_network_free(ospf
, rn
->info
);
977 route_unlock_node(rn
); /* initial reference */
979 /* Find interfaces that are not configured already. */
980 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
)) {
982 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
985 ospf_network_run_subnet(ospf
, oi
->connected
, NULL
, NULL
);
988 /* Update connected redistribute. */
989 update_redistributed(ospf
, 0); /* interfaces possibly removed */
990 ospf_area_check_free(ospf
, area_id
);
995 /* Ensure there's an OSPF instance, as "ip ospf area" enabled OSPF means
996 * there might not be any 'router ospf' config.
998 * Otherwise, doesn't do anything different to ospf_if_update for now
1000 void ospf_interface_area_set(struct interface
*ifp
)
1002 struct ospf
*ospf
= ospf_get();
1004 ospf_if_update(ospf
, ifp
);
1005 /* if_update does a update_redistributed */
1010 void ospf_interface_area_unset(struct interface
*ifp
)
1012 struct route_node
*rn_oi
;
1015 ospf
= ospf_lookup();
1017 return; /* Ospf not ready yet */
1019 /* Find interfaces that may need to be removed. */
1020 for (rn_oi
= route_top(IF_OIFS(ifp
)); rn_oi
;
1021 rn_oi
= route_next(rn_oi
)) {
1022 struct ospf_interface
*oi
;
1024 if ((oi
= rn_oi
->info
) == NULL
)
1027 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1030 ospf_network_run_subnet(ospf
, oi
->connected
, NULL
, NULL
);
1033 /* Update connected redistribute. */
1034 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1037 /* Check whether interface matches given network
1038 * returns: 1, true. 0, false
1040 static int ospf_network_match_iface(const struct connected
*co
,
1041 const struct prefix
*net
)
1043 /* new approach: more elegant and conceptually clean */
1044 return prefix_match_network_statement(net
, CONNECTED_PREFIX(co
));
1047 static void ospf_update_interface_area(struct connected
*co
,
1048 struct ospf_area
*area
)
1050 struct ospf_interface
*oi
= ospf_if_table_lookup(co
->ifp
, co
->address
);
1052 /* nothing to be done case */
1053 if (oi
&& oi
->area
== area
) {
1060 add_ospf_interface(co
, area
);
1063 /* Run OSPF for the given subnet, taking into account the following
1064 * possible sources of area configuration, in the given order of preference:
1066 * - Whether there is interface+address specific area configuration
1067 * - Whether there is a default area for the interface
1068 * - Whether there is an area given as a parameter.
1069 * - If no specific network prefix/area is supplied, whether there's
1070 * a matching network configured.
1072 static void ospf_network_run_subnet(struct ospf
*ospf
, struct connected
*co
,
1074 struct ospf_area
*given_area
)
1076 struct ospf_interface
*oi
;
1077 struct ospf_if_params
*params
;
1078 struct ospf_area
*area
= NULL
;
1079 struct route_node
*rn
;
1082 if (CHECK_FLAG(co
->flags
, ZEBRA_IFA_SECONDARY
))
1085 if (co
->address
->family
!= AF_INET
)
1088 /* Try determine the appropriate area for this interface + address
1089 * Start by checking interface config
1091 params
= ospf_lookup_if_params(co
->ifp
, co
->address
->u
.prefix4
);
1092 if (params
&& OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1093 area
= ospf_area_get(ospf
, params
->if_area
);
1095 params
= IF_DEF_PARAMS(co
->ifp
);
1096 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1097 area
= ospf_area_get(ospf
, params
->if_area
);
1100 /* If we've found an interface and/or addr specific area, then we're
1104 ospf_update_interface_area(co
, area
);
1108 /* Otherwise, only remaining possibility is a matching network statement
1111 assert(given_area
!= NULL
);
1113 /* Which either was supplied as a parameter.. (e.g. cause a new
1114 * network/area was just added)..
1116 if (p
->family
== co
->address
->family
1117 && ospf_network_match_iface(co
, p
))
1118 ospf_update_interface_area(co
, given_area
);
1123 /* Else we have to search the existing network/area config to see
1126 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
1127 if (rn
->info
!= NULL
&& ospf_network_match_iface(co
, &rn
->p
)) {
1128 struct ospf_network
*network
=
1129 (struct ospf_network
*)rn
->info
;
1130 area
= ospf_area_get(ospf
, network
->area_id
);
1131 ospf_update_interface_area(co
, area
);
1135 /* If the subnet isn't in any area, deconfigure */
1136 if (!configed
&& (oi
= ospf_if_table_lookup(co
->ifp
, co
->address
)))
1140 static void ospf_network_run_interface(struct ospf
*ospf
, struct interface
*ifp
,
1142 struct ospf_area
*given_area
)
1144 struct listnode
*cnode
;
1145 struct connected
*co
;
1147 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
1150 /* Network prefix without area is nonsensical */
1152 assert(given_area
!= NULL
);
1154 /* if interface prefix is match specified prefix,
1155 then create socket and join multicast group. */
1156 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, co
))
1157 ospf_network_run_subnet(ospf
, co
, p
, given_area
);
1160 static void ospf_network_run(struct prefix
*p
, struct ospf_area
*area
)
1162 struct interface
*ifp
;
1163 struct listnode
*node
;
1165 /* Schedule Router ID Update. */
1166 if (area
->ospf
->router_id
.s_addr
== 0)
1167 ospf_router_id_update(area
->ospf
);
1169 /* Get target interface. */
1170 for (ALL_LIST_ELEMENTS_RO(om
->iflist
, node
, ifp
))
1171 ospf_network_run_interface(area
->ospf
, ifp
, p
, area
);
1174 void ospf_ls_upd_queue_empty(struct ospf_interface
*oi
)
1176 struct route_node
*rn
;
1177 struct listnode
*node
, *nnode
;
1179 struct ospf_lsa
*lsa
;
1181 /* empty ls update queue */
1182 for (rn
= route_top(oi
->ls_upd_queue
); rn
; rn
= route_next(rn
))
1183 if ((lst
= (struct list
*)rn
->info
)) {
1184 for (ALL_LIST_ELEMENTS(lst
, node
, nnode
, lsa
))
1185 ospf_lsa_unlock(&lsa
); /* oi->ls_upd_queue */
1190 /* remove update event */
1191 if (oi
->t_ls_upd_event
) {
1192 thread_cancel(oi
->t_ls_upd_event
);
1193 oi
->t_ls_upd_event
= NULL
;
1197 void ospf_if_update(struct ospf
*ospf
, struct interface
*ifp
)
1200 ospf
= ospf_lookup();
1202 /* OSPF must be ready. */
1203 if (!ospf_is_ready(ospf
))
1206 ospf_network_run_interface(ospf
, ifp
, NULL
, NULL
);
1208 /* Update connected redistribute. */
1209 update_redistributed(ospf
, 1);
1212 void ospf_remove_vls_through_area(struct ospf
*ospf
, struct ospf_area
*area
)
1214 struct listnode
*node
, *nnode
;
1215 struct ospf_vl_data
*vl_data
;
1217 for (ALL_LIST_ELEMENTS(ospf
->vlinks
, node
, nnode
, vl_data
))
1218 if (IPV4_ADDR_SAME(&vl_data
->vl_area_id
, &area
->area_id
))
1219 ospf_vl_delete(ospf
, vl_data
);
1223 static const struct message ospf_area_type_msg
[] = {
1224 {OSPF_AREA_DEFAULT
, "Default"},
1225 {OSPF_AREA_STUB
, "Stub"},
1226 {OSPF_AREA_NSSA
, "NSSA"},
1229 static void ospf_area_type_set(struct ospf_area
*area
, int type
)
1231 struct listnode
*node
;
1232 struct ospf_interface
*oi
;
1234 if (area
->external_routing
== type
) {
1235 if (IS_DEBUG_OSPF_EVENT
)
1236 zlog_debug("Area[%s]: Types are the same, ignored.",
1237 inet_ntoa(area
->area_id
));
1241 area
->external_routing
= type
;
1243 if (IS_DEBUG_OSPF_EVENT
)
1244 zlog_debug("Area[%s]: Configured as %s",
1245 inet_ntoa(area
->area_id
),
1246 lookup_msg(ospf_area_type_msg
, type
, NULL
));
1248 switch (area
->external_routing
) {
1249 case OSPF_AREA_DEFAULT
:
1250 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1251 if (oi
->nbr_self
!= NULL
) {
1252 UNSET_FLAG(oi
->nbr_self
->options
,
1254 SET_FLAG(oi
->nbr_self
->options
, OSPF_OPTION_E
);
1257 case OSPF_AREA_STUB
:
1258 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1259 if (oi
->nbr_self
!= NULL
) {
1260 if (IS_DEBUG_OSPF_EVENT
)
1262 "setting options on %s accordingly",
1264 UNSET_FLAG(oi
->nbr_self
->options
,
1266 UNSET_FLAG(oi
->nbr_self
->options
,
1268 if (IS_DEBUG_OSPF_EVENT
)
1269 zlog_debug("options set on %s: %x",
1270 IF_NAME(oi
), OPTIONS(oi
));
1273 case OSPF_AREA_NSSA
:
1274 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1275 if (oi
->nbr_self
!= NULL
) {
1277 "setting nssa options on %s accordingly",
1279 UNSET_FLAG(oi
->nbr_self
->options
,
1281 SET_FLAG(oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1282 zlog_debug("options set on %s: %x", IF_NAME(oi
),
1290 ospf_router_lsa_update_area(area
);
1291 ospf_schedule_abr_task(area
->ospf
);
1294 int ospf_area_shortcut_set(struct ospf
*ospf
, struct ospf_area
*area
, int mode
)
1296 if (area
->shortcut_configured
== mode
)
1299 area
->shortcut_configured
= mode
;
1300 ospf_router_lsa_update_area(area
);
1301 ospf_schedule_abr_task(ospf
);
1303 ospf_area_check_free(ospf
, area
->area_id
);
1308 int ospf_area_shortcut_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1310 area
->shortcut_configured
= OSPF_SHORTCUT_DEFAULT
;
1311 ospf_router_lsa_update_area(area
);
1312 ospf_area_check_free(ospf
, area
->area_id
);
1313 ospf_schedule_abr_task(ospf
);
1318 static int ospf_area_vlink_count(struct ospf
*ospf
, struct ospf_area
*area
)
1320 struct ospf_vl_data
*vl
;
1321 struct listnode
*node
;
1324 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl
))
1325 if (IPV4_ADDR_SAME(&vl
->vl_area_id
, &area
->area_id
))
1331 int ospf_area_display_format_set(struct ospf
*ospf
, struct ospf_area
*area
,
1334 area
->area_id_fmt
= df
;
1339 int ospf_area_stub_set(struct ospf
*ospf
, struct in_addr area_id
)
1341 struct ospf_area
*area
;
1343 area
= ospf_area_get(ospf
, area_id
);
1344 if (ospf_area_vlink_count(ospf
, area
))
1347 if (area
->external_routing
!= OSPF_AREA_STUB
)
1348 ospf_area_type_set(area
, OSPF_AREA_STUB
);
1353 int ospf_area_stub_unset(struct ospf
*ospf
, struct in_addr area_id
)
1355 struct ospf_area
*area
;
1357 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1361 if (area
->external_routing
== OSPF_AREA_STUB
)
1362 ospf_area_type_set(area
, OSPF_AREA_DEFAULT
);
1364 ospf_area_check_free(ospf
, area_id
);
1369 int ospf_area_no_summary_set(struct ospf
*ospf
, struct in_addr area_id
)
1371 struct ospf_area
*area
;
1373 area
= ospf_area_get(ospf
, area_id
);
1374 area
->no_summary
= 1;
1379 int ospf_area_no_summary_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 area
->no_summary
= 0;
1388 ospf_area_check_free(ospf
, area_id
);
1393 int ospf_area_nssa_set(struct ospf
*ospf
, struct in_addr area_id
)
1395 struct ospf_area
*area
;
1397 area
= ospf_area_get(ospf
, area_id
);
1398 if (ospf_area_vlink_count(ospf
, area
))
1401 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1402 ospf_area_type_set(area
, OSPF_AREA_NSSA
);
1406 /* set NSSA area defaults */
1407 area
->no_summary
= 0;
1408 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1409 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1410 area
->NSSATranslatorStabilityInterval
= OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1415 int ospf_area_nssa_unset(struct ospf
*ospf
, struct in_addr area_id
)
1417 struct ospf_area
*area
;
1419 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1423 if (area
->external_routing
== OSPF_AREA_NSSA
) {
1425 ospf_area_type_set(area
, OSPF_AREA_DEFAULT
);
1428 ospf_area_check_free(ospf
, area_id
);
1433 int ospf_area_nssa_translator_role_set(struct ospf
*ospf
,
1434 struct in_addr area_id
, int role
)
1436 struct ospf_area
*area
;
1438 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1442 area
->NSSATranslatorRole
= role
;
1448 /* XXX: unused? Leave for symmetry? */
1450 ospf_area_nssa_translator_role_unset (struct ospf
*ospf
,
1451 struct in_addr area_id
)
1453 struct ospf_area
*area
;
1455 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1459 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1461 ospf_area_check_free (ospf
, area_id
);
1467 int ospf_area_export_list_set(struct ospf
*ospf
, struct ospf_area
*area
,
1468 const char *list_name
)
1470 struct access_list
*list
;
1471 list
= access_list_lookup(AFI_IP
, list_name
);
1473 EXPORT_LIST(area
) = list
;
1475 if (EXPORT_NAME(area
))
1476 free(EXPORT_NAME(area
));
1478 EXPORT_NAME(area
) = strdup(list_name
);
1479 ospf_schedule_abr_task(ospf
);
1484 int ospf_area_export_list_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1487 EXPORT_LIST(area
) = 0;
1489 if (EXPORT_NAME(area
))
1490 free(EXPORT_NAME(area
));
1492 EXPORT_NAME(area
) = NULL
;
1494 ospf_area_check_free(ospf
, area
->area_id
);
1496 ospf_schedule_abr_task(ospf
);
1501 int ospf_area_import_list_set(struct ospf
*ospf
, struct ospf_area
*area
,
1504 struct access_list
*list
;
1505 list
= access_list_lookup(AFI_IP
, name
);
1507 IMPORT_LIST(area
) = list
;
1509 if (IMPORT_NAME(area
))
1510 free(IMPORT_NAME(area
));
1512 IMPORT_NAME(area
) = strdup(name
);
1513 ospf_schedule_abr_task(ospf
);
1518 int ospf_area_import_list_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1520 IMPORT_LIST(area
) = 0;
1522 if (IMPORT_NAME(area
))
1523 free(IMPORT_NAME(area
));
1525 IMPORT_NAME(area
) = NULL
;
1526 ospf_area_check_free(ospf
, area
->area_id
);
1528 ospf_schedule_abr_task(ospf
);
1533 int ospf_timers_refresh_set(struct ospf
*ospf
, int interval
)
1537 if (ospf
->lsa_refresh_interval
== interval
)
1540 time_left
= ospf
->lsa_refresh_interval
1541 - (monotime(NULL
) - ospf
->lsa_refresher_started
);
1543 if (time_left
> interval
) {
1544 OSPF_TIMER_OFF(ospf
->t_lsa_refresher
);
1545 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1546 interval
, &ospf
->t_lsa_refresher
);
1548 ospf
->lsa_refresh_interval
= interval
;
1553 int ospf_timers_refresh_unset(struct ospf
*ospf
)
1557 time_left
= ospf
->lsa_refresh_interval
1558 - (monotime(NULL
) - ospf
->lsa_refresher_started
);
1560 if (time_left
> OSPF_LSA_REFRESH_INTERVAL_DEFAULT
) {
1561 OSPF_TIMER_OFF(ospf
->t_lsa_refresher
);
1562 ospf
->t_lsa_refresher
= NULL
;
1563 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1564 OSPF_LSA_REFRESH_INTERVAL_DEFAULT
,
1565 &ospf
->t_lsa_refresher
);
1568 ospf
->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
1574 static struct ospf_nbr_nbma
*ospf_nbr_nbma_new(void)
1576 struct ospf_nbr_nbma
*nbr_nbma
;
1578 nbr_nbma
= XCALLOC(MTYPE_OSPF_NEIGHBOR_STATIC
,
1579 sizeof(struct ospf_nbr_nbma
));
1581 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1582 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1587 static void ospf_nbr_nbma_free(struct ospf_nbr_nbma
*nbr_nbma
)
1589 XFREE(MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
1592 static void ospf_nbr_nbma_delete(struct ospf
*ospf
,
1593 struct ospf_nbr_nbma
*nbr_nbma
)
1595 struct route_node
*rn
;
1596 struct prefix_ipv4 p
;
1599 p
.prefix
= nbr_nbma
->addr
;
1600 p
.prefixlen
= IPV4_MAX_BITLEN
;
1602 rn
= route_node_lookup(ospf
->nbr_nbma
, (struct prefix
*)&p
);
1604 ospf_nbr_nbma_free(rn
->info
);
1606 route_unlock_node(rn
);
1607 route_unlock_node(rn
);
1611 static void ospf_nbr_nbma_down(struct ospf_nbr_nbma
*nbr_nbma
)
1613 OSPF_TIMER_OFF(nbr_nbma
->t_poll
);
1615 if (nbr_nbma
->nbr
) {
1616 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
1617 OSPF_NSM_EVENT_EXECUTE(nbr_nbma
->nbr
, NSM_KillNbr
);
1621 listnode_delete(nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
1624 static void ospf_nbr_nbma_add(struct ospf_nbr_nbma
*nbr_nbma
,
1625 struct ospf_interface
*oi
)
1627 struct ospf_neighbor
*nbr
;
1628 struct route_node
*rn
;
1631 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1634 if (nbr_nbma
->nbr
!= NULL
)
1637 if (IPV4_ADDR_SAME(&oi
->nbr_self
->address
.u
.prefix4
, &nbr_nbma
->addr
))
1641 listnode_add(oi
->nbr_nbma
, nbr_nbma
);
1643 /* Get neighbor information from table. */
1645 p
.prefixlen
= IPV4_MAX_BITLEN
;
1646 p
.u
.prefix4
= nbr_nbma
->addr
;
1648 rn
= route_node_get(oi
->nbrs
, (struct prefix
*)&p
);
1651 nbr
->nbr_nbma
= nbr_nbma
;
1652 nbr_nbma
->nbr
= nbr
;
1654 route_unlock_node(rn
);
1656 nbr
= rn
->info
= ospf_nbr_new(oi
);
1657 nbr
->state
= NSM_Down
;
1658 nbr
->src
= nbr_nbma
->addr
;
1659 nbr
->nbr_nbma
= nbr_nbma
;
1660 nbr
->priority
= nbr_nbma
->priority
;
1663 nbr_nbma
->nbr
= nbr
;
1665 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_Start
);
1669 void ospf_nbr_nbma_if_update(struct ospf
*ospf
, struct ospf_interface
*oi
)
1671 struct ospf_nbr_nbma
*nbr_nbma
;
1672 struct route_node
*rn
;
1673 struct prefix_ipv4 p
;
1675 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1678 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
1679 if ((nbr_nbma
= rn
->info
))
1680 if (nbr_nbma
->oi
== NULL
&& nbr_nbma
->nbr
== NULL
) {
1682 p
.prefix
= nbr_nbma
->addr
;
1683 p
.prefixlen
= IPV4_MAX_BITLEN
;
1685 if (prefix_match(oi
->address
,
1686 (struct prefix
*)&p
))
1687 ospf_nbr_nbma_add(nbr_nbma
, oi
);
1691 struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup(struct ospf
*ospf
,
1692 struct in_addr nbr_addr
)
1694 struct route_node
*rn
;
1695 struct prefix_ipv4 p
;
1698 p
.prefix
= nbr_addr
;
1699 p
.prefixlen
= IPV4_MAX_BITLEN
;
1701 rn
= route_node_lookup(ospf
->nbr_nbma
, (struct prefix
*)&p
);
1703 route_unlock_node(rn
);
1709 struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup_next(struct ospf
*ospf
,
1710 struct in_addr
*addr
, int first
)
1713 struct ospf_nbr_nbma
*nbr_nbma
;
1714 struct listnode
*node
;
1721 for (ALL_LIST_ELEMENTS_RO (ospf
->nbr_nbma
, node
, nbr_nbma
))
1725 *addr
= nbr_nbma
->addr
;
1728 else if (ntohl (nbr_nbma
->addr
.s_addr
) > ntohl (addr
->s_addr
))
1730 *addr
= nbr_nbma
->addr
;
1738 int ospf_nbr_nbma_set(struct ospf
*ospf
, struct in_addr nbr_addr
)
1740 struct ospf_nbr_nbma
*nbr_nbma
;
1741 struct ospf_interface
*oi
;
1742 struct prefix_ipv4 p
;
1743 struct route_node
*rn
;
1744 struct listnode
*node
;
1746 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
1750 nbr_nbma
= ospf_nbr_nbma_new();
1751 nbr_nbma
->addr
= nbr_addr
;
1754 p
.prefix
= nbr_addr
;
1755 p
.prefixlen
= IPV4_MAX_BITLEN
;
1757 rn
= route_node_get(ospf
->nbr_nbma
, (struct prefix
*)&p
);
1759 route_unlock_node(rn
);
1760 rn
->info
= nbr_nbma
;
1762 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
1763 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1764 if (prefix_match(oi
->address
, (struct prefix
*)&p
)) {
1765 ospf_nbr_nbma_add(nbr_nbma
, oi
);
1773 int ospf_nbr_nbma_unset(struct ospf
*ospf
, struct in_addr nbr_addr
)
1775 struct ospf_nbr_nbma
*nbr_nbma
;
1777 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
1778 if (nbr_nbma
== NULL
)
1781 ospf_nbr_nbma_down(nbr_nbma
);
1782 ospf_nbr_nbma_delete(ospf
, nbr_nbma
);
1787 int ospf_nbr_nbma_priority_set(struct ospf
*ospf
, struct in_addr nbr_addr
,
1790 struct ospf_nbr_nbma
*nbr_nbma
;
1792 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
1793 if (nbr_nbma
== NULL
)
1796 if (nbr_nbma
->priority
!= priority
)
1797 nbr_nbma
->priority
= priority
;
1802 int ospf_nbr_nbma_priority_unset(struct ospf
*ospf
, struct in_addr nbr_addr
)
1804 struct ospf_nbr_nbma
*nbr_nbma
;
1806 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
1807 if (nbr_nbma
== NULL
)
1810 if (nbr_nbma
!= OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
1811 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1816 int ospf_nbr_nbma_poll_interval_set(struct ospf
*ospf
, struct in_addr nbr_addr
,
1817 unsigned int interval
)
1819 struct ospf_nbr_nbma
*nbr_nbma
;
1821 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
1822 if (nbr_nbma
== NULL
)
1825 if (nbr_nbma
->v_poll
!= interval
) {
1826 nbr_nbma
->v_poll
= interval
;
1827 if (nbr_nbma
->oi
&& ospf_if_is_up(nbr_nbma
->oi
)) {
1828 OSPF_TIMER_OFF(nbr_nbma
->t_poll
);
1829 OSPF_POLL_TIMER_ON(nbr_nbma
->t_poll
, ospf_poll_timer
,
1837 int ospf_nbr_nbma_poll_interval_unset(struct ospf
*ospf
, struct in_addr addr
)
1839 struct ospf_nbr_nbma
*nbr_nbma
;
1841 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, addr
);
1842 if (nbr_nbma
== NULL
)
1845 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
1846 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1851 void ospf_master_init(struct thread_master
*master
)
1853 memset(&ospf_master
, 0, sizeof(struct ospf_master
));
1856 om
->ospf
= list_new();
1857 om
->master
= master
;