1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* OSPF version 2 daemon program.
3 * Copyright (C) 1999, 2000 Toshiaki Takada
18 #include "sockunion.h" /* for inet_aton () */
26 #include "lib_errors.h"
29 #include "ospfd/ospfd.h"
30 #include "ospfd/ospf_bfd.h"
31 #include "ospfd/ospf_network.h"
32 #include "ospfd/ospf_interface.h"
33 #include "ospfd/ospf_ism.h"
34 #include "ospfd/ospf_asbr.h"
35 #include "ospfd/ospf_lsa.h"
36 #include "ospfd/ospf_lsdb.h"
37 #include "ospfd/ospf_neighbor.h"
38 #include "ospfd/ospf_nsm.h"
39 #include "ospfd/ospf_spf.h"
40 #include "ospfd/ospf_packet.h"
41 #include "ospfd/ospf_dump.h"
42 #include "ospfd/ospf_route.h"
43 #include "ospfd/ospf_zebra.h"
44 #include "ospfd/ospf_abr.h"
45 #include "ospfd/ospf_flood.h"
46 #include "ospfd/ospf_ase.h"
47 #include "ospfd/ospf_ldp_sync.h"
48 #include "ospfd/ospf_gr.h"
49 #include "ospfd/ospf_apiserver.h"
52 DEFINE_QOBJ_TYPE(ospf
);
54 /* OSPF process wide configuration. */
55 static struct ospf_master ospf_master
;
57 /* OSPF process wide configuration pointer to export. */
58 struct ospf_master
*om
;
60 unsigned short ospf_instance
;
62 extern struct zclient
*zclient
;
65 static void ospf_remove_vls_through_area(struct ospf
*, struct ospf_area
*);
66 static void ospf_network_free(struct ospf
*, struct ospf_network
*);
67 static void ospf_area_free(struct ospf_area
*);
68 static void ospf_network_run(struct prefix
*, struct ospf_area
*);
69 static void ospf_network_run_interface(struct ospf
*, struct interface
*,
70 struct prefix
*, struct ospf_area
*);
71 static void ospf_network_run_subnet(struct ospf
*, struct connected
*,
72 struct prefix
*, struct ospf_area
*);
73 static int ospf_network_match_iface(const struct connected
*,
74 const struct prefix
*);
75 static void ospf_finish_final(struct ospf
*);
77 /* API to clean refresh queues and LSAs */
78 static void ospf_free_refresh_queue(struct ospf
*ospf
)
80 for (int i
= 0; i
< OSPF_LSA_REFRESHER_SLOTS
; i
++) {
81 struct list
*list
= ospf
->lsa_refresh_queue
.qs
[i
];
82 struct listnode
*node
, *nnode
;
86 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, lsa
)) {
87 listnode_delete(list
, lsa
);
88 lsa
->refresh_list
= -1;
89 ospf_lsa_unlock(&lsa
);
92 ospf
->lsa_refresh_queue
.qs
[i
] = NULL
;
96 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
98 int p_spaces_compare_func(const struct p_space
*a
, const struct p_space
*b
)
100 if (a
->protected_resource
->type
== OSPF_TI_LFA_LINK_PROTECTION
101 && b
->protected_resource
->type
== OSPF_TI_LFA_LINK_PROTECTION
)
102 return (a
->protected_resource
->link
->link_id
.s_addr
103 - b
->protected_resource
->link
->link_id
.s_addr
);
105 if (a
->protected_resource
->type
== OSPF_TI_LFA_NODE_PROTECTION
106 && b
->protected_resource
->type
== OSPF_TI_LFA_NODE_PROTECTION
)
107 return (a
->protected_resource
->router_id
.s_addr
108 - b
->protected_resource
->router_id
.s_addr
);
110 /* This should not happen */
114 int q_spaces_compare_func(const struct q_space
*a
, const struct q_space
*b
)
116 return (a
->root
->id
.s_addr
- b
->root
->id
.s_addr
);
119 DECLARE_RBTREE_UNIQ(p_spaces
, struct p_space
, p_spaces_item
,
120 p_spaces_compare_func
);
122 void ospf_process_refresh_data(struct ospf
*ospf
, bool reset
)
124 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
125 struct in_addr router_id
, router_id_old
;
126 struct ospf_interface
*oi
;
127 struct interface
*ifp
;
128 struct listnode
*node
, *nnode
;
129 struct ospf_area
*area
;
130 bool rid_change
= false;
132 if (!ospf
->oi_running
) {
133 if (IS_DEBUG_OSPF_EVENT
)
135 "Router ospf not configured -- Router-ID update postponed");
139 if (IS_DEBUG_OSPF_EVENT
)
140 zlog_debug("Router-ID[OLD:%pI4]: Update",
143 router_id_old
= ospf
->router_id
;
145 /* Select the router ID based on these priorities:
146 1. Statically assigned router ID is always the first choice.
147 2. If there is no statically assigned router ID, then try to stick
148 with the most recent value, since changing router ID's is very
150 3. Last choice: just go with whatever the zebra daemon recommends.
152 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
153 router_id
= ospf
->router_id_static
;
154 else if (ospf
->router_id
.s_addr
!= INADDR_ANY
)
155 router_id
= ospf
->router_id
;
157 router_id
= ospf
->router_id_zebra
;
159 if (IS_DEBUG_OSPF_EVENT
)
160 zlog_debug("Router-ID[OLD:%pI4]: Update to %pI4",
161 &ospf
->router_id
, &router_id
);
163 rid_change
= !(IPV4_ADDR_SAME(&router_id_old
, &router_id
));
164 if (rid_change
|| (reset
)) {
165 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
166 /* Some nbrs are identified by router_id, these needs
167 * to be rebuilt. Possible optimization would be to do
168 * oi->nbr_self->router_id = router_id for
169 * !(virtual | ptop) links
171 ospf_nbr_self_reset(oi
, router_id
);
174 * If the old router id was not set, but now it
175 * is and the interface is operative and the
176 * state is ISM_Down we should kick the state
177 * machine as that we processed the interfaces
178 * based upon the network statement( or intf config )
179 * but could not start it at that time.
181 if (if_is_operative(oi
->ifp
) && oi
->state
== ISM_Down
182 && router_id_old
.s_addr
== INADDR_ANY
)
186 /* Flush (inline) all the self originated LSAs */
187 ospf_flush_self_originated_lsas_now(ospf
);
189 ospf
->router_id
= router_id
;
190 if (IS_DEBUG_OSPF_EVENT
)
191 zlog_debug("Router-ID[NEW:%pI4]: Update",
194 /* Flush (inline) all external LSAs which now match the new
196 need to adjust the OSPF_LSA_SELF flag, so the flush doesn't
198 asserts in ospf_refresher_unregister_lsa(). This step is
200 because the current frr code does look-up for
202 based on the self router-id alone but expects OSPF_LSA_SELF
206 struct route_node
*rn
;
207 struct ospf_lsa
*lsa
;
209 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
) {
210 /* AdvRouter and Router ID is the same. */
211 if (IPV4_ADDR_SAME(&lsa
->data
->adv_router
,
212 &ospf
->router_id
) && rid_change
) {
214 OSPF_LSA_SELF_CHECKED
);
215 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF
);
216 ospf_lsa_flush_schedule(ospf
, lsa
);
218 /* The above flush will send immediately
219 * So discard the LSA to originate new
221 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
224 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
225 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
227 ospf_lsdb_delete_all(ospf
->lsdb
);
230 /* Since the LSAs are deleted, need reset the aggr flag */
231 ospf_unset_all_aggr_flag(ospf
);
233 /* Delete the LSDB */
234 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
235 ospf_area_lsdb_discard_delete(area
);
237 /* update router-lsa's for each area */
238 ospf_router_lsa_update(ospf
);
240 /* update ospf_interface's */
241 FOR_ALL_INTERFACES (vrf
, ifp
) {
245 ospf_if_update(ospf
, ifp
);
248 ospf_external_lsa_rid_change(ospf
);
250 #ifdef SUPPORT_OSPF_API
251 ospf_apiserver_clients_notify_router_id_change(router_id
);
255 ospf
->inst_shutdown
= 0;
258 void ospf_router_id_update(struct ospf
*ospf
)
260 ospf_process_refresh_data(ospf
, false);
263 void ospf_process_reset(struct ospf
*ospf
)
265 ospf_process_refresh_data(ospf
, true);
268 void ospf_neighbor_reset(struct ospf
*ospf
, struct in_addr nbr_id
,
271 struct route_node
*rn
;
272 struct ospf_neighbor
*nbr
;
273 struct ospf_interface
*oi
;
274 struct listnode
*node
;
276 /* Clear only a particular nbr with nbr router id as nbr_id */
277 if (nbr_str
!= NULL
) {
278 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
279 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &nbr_id
);
281 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_KillNbr
);
286 /* send Neighbor event KillNbr to all associated neighbors. */
287 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
288 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
290 if (nbr
&& (nbr
!= oi
->nbr_self
))
291 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_KillNbr
);
296 /* For OSPF area sort by area id. */
297 static int ospf_area_id_cmp(struct ospf_area
*a1
, struct ospf_area
*a2
)
299 if (ntohl(a1
->area_id
.s_addr
) > ntohl(a2
->area_id
.s_addr
))
301 if (ntohl(a1
->area_id
.s_addr
) < ntohl(a2
->area_id
.s_addr
))
306 static void ospf_add(struct ospf
*ospf
)
308 listnode_add(om
->ospf
, ospf
);
311 static void ospf_delete(struct ospf
*ospf
)
313 listnode_delete(om
->ospf
, ospf
);
316 struct ospf
*ospf_new_alloc(unsigned short instance
, const char *name
)
319 struct vrf
*vrf
= NULL
;
321 struct ospf
*new = XCALLOC(MTYPE_OSPF_TOP
, sizeof(struct ospf
));
323 new->instance
= instance
;
324 new->router_id
.s_addr
= htonl(0);
325 new->router_id_static
.s_addr
= htonl(0);
327 vrf
= vrf_lookup_by_name(name
);
329 new->vrf_id
= vrf
->vrf_id
;
331 new->vrf_id
= VRF_UNKNOWN
;
333 /* Freed in ospf_finish_final */
334 new->name
= XSTRDUP(MTYPE_OSPF_TOP
, name
);
335 if (IS_DEBUG_OSPF_EVENT
)
337 "%s: Create new ospf instance with vrf_name %s vrf_id %u",
338 __func__
, name
, new->vrf_id
);
341 ospf_vrf_link(new, vrf
);
343 ospf_zebra_vrf_register(new);
345 new->abr_type
= OSPF_ABR_DEFAULT
;
346 new->oiflist
= list_new();
347 new->vlinks
= list_new();
348 new->areas
= list_new();
349 new->areas
->cmp
= (int (*)(void *, void *))ospf_area_id_cmp
;
350 new->networks
= route_table_init();
351 new->nbr_nbma
= route_table_init();
353 new->lsdb
= ospf_lsdb_new();
355 new->default_originate
= DEFAULT_ORIGINATE_NONE
;
357 new->passive_interface_default
= OSPF_IF_ACTIVE
;
359 new->new_external_route
= route_table_init();
360 new->old_external_route
= route_table_init();
361 new->external_lsas
= route_table_init();
363 new->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
364 new->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
365 new->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
367 /* Distribute parameter init. */
368 for (i
= 0; i
<= ZEBRA_ROUTE_MAX
; i
++) {
371 new->default_metric
= -1;
372 new->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
375 new->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
376 new->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
378 /* SPF timer value init. */
379 new->spf_delay
= OSPF_SPF_DELAY_DEFAULT
;
380 new->spf_holdtime
= OSPF_SPF_HOLDTIME_DEFAULT
;
381 new->spf_max_holdtime
= OSPF_SPF_MAX_HOLDTIME_DEFAULT
;
382 new->spf_hold_multiplier
= 1;
385 new->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
386 new->maxage_lsa
= route_table_init();
387 new->t_maxage_walker
= NULL
;
388 thread_add_timer(master
, ospf_lsa_maxage_walker
, new,
389 OSPF_LSA_MAXAGE_CHECK_INTERVAL
, &new->t_maxage_walker
);
391 /* Max paths initialization */
392 new->max_multipath
= MULTIPATH_NUM
;
394 /* Distance table init. */
395 new->distance_table
= route_table_init();
397 new->lsa_refresh_queue
.index
= 0;
398 new->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
399 new->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
400 new->t_lsa_refresher
= NULL
;
401 thread_add_timer(master
, ospf_lsa_refresh_walker
, new,
402 new->lsa_refresh_interval
, &new->t_lsa_refresher
);
403 new->lsa_refresher_started
= monotime(NULL
);
405 new->ibuf
= stream_new(OSPF_MAX_PACKET_SIZE
+ 1);
408 new->oi_write_q
= list_new();
409 new->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
411 new->proactive_arp
= OSPF_PROACTIVE_ARP_DEFAULT
;
413 ospf_gr_helper_instance_init(new);
415 ospf_asbr_external_aggregator_init(new);
417 ospf_opaque_type11_lsa_init(new);
426 /* Allocate new ospf structure. */
427 static struct ospf
*ospf_new(unsigned short instance
, const char *name
)
431 new = ospf_new_alloc(instance
, name
);
434 if (new->vrf_id
== VRF_UNKNOWN
)
437 if ((ospf_sock_init(new)) < 0) {
438 flog_err(EC_LIB_SOCKET
,
439 "%s: ospf_sock_init is unable to open a socket",
444 thread_add_read(master
, ospf_read
, new, new->fd
, &new->t_read
);
447 ospf_router_id_update(new);
450 * Read from non-volatile memory whether this instance is performing a
451 * graceful restart or not.
453 ospf_gr_nvm_read(new);
458 struct ospf
*ospf_lookup_instance(unsigned short instance
)
461 struct listnode
*node
, *nnode
;
463 if (listcount(om
->ospf
) == 0)
466 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
467 if ((ospf
->instance
== 0 && instance
== 0)
468 || (ospf
->instance
&& instance
469 && ospf
->instance
== instance
))
475 static int ospf_is_ready(struct ospf
*ospf
)
477 /* OSPF must be on and Router-ID must be configured. */
478 if (!ospf
|| ospf
->router_id
.s_addr
== INADDR_ANY
)
484 struct ospf
*ospf_lookup_by_inst_name(unsigned short instance
, const char *name
)
486 struct ospf
*ospf
= NULL
;
487 struct listnode
*node
, *nnode
;
489 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
)) {
490 if ((ospf
->instance
== instance
)
491 && ((ospf
->name
== NULL
&& name
== NULL
)
492 || (ospf
->name
&& name
493 && strcmp(ospf
->name
, name
) == 0)))
499 struct ospf
*ospf_lookup(unsigned short instance
, const char *name
)
504 ospf
= ospf_lookup_instance(instance
);
506 ospf
= ospf_lookup_by_inst_name(instance
, name
);
512 struct ospf
*ospf_get(unsigned short instance
, const char *name
, bool *created
)
516 ospf
= ospf_lookup(instance
, name
);
518 *created
= (ospf
== NULL
);
520 ospf
= ospf_new(instance
, name
);
525 struct ospf
*ospf_lookup_by_vrf_id(vrf_id_t vrf_id
)
527 struct vrf
*vrf
= NULL
;
529 vrf
= vrf_lookup_by_id(vrf_id
);
532 return (vrf
->info
) ? (struct ospf
*)vrf
->info
: NULL
;
535 uint32_t ospf_count_area_params(struct ospf
*ospf
)
538 struct interface
*ifp
;
541 if (ospf
->vrf_id
!= VRF_UNKNOWN
) {
542 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
544 FOR_ALL_INTERFACES (vrf
, ifp
) {
545 count
+= ospf_if_count_area_params(ifp
);
552 /* It should only be used when processing incoming info update from zebra.
553 * Other situations, it is not sufficient to lookup the ospf instance by
554 * vrf_name only without using the instance number.
556 static struct ospf
*ospf_lookup_by_name(const char *vrf_name
)
558 struct ospf
*ospf
= NULL
;
559 struct listnode
*node
, *nnode
;
561 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
562 if ((ospf
->name
== NULL
&& vrf_name
== NULL
)
563 || (ospf
->name
&& vrf_name
564 && strcmp(ospf
->name
, vrf_name
) == 0))
569 /* Handle the second half of deferred shutdown. This is called either
570 * from the deferred-shutdown timer thread, or directly through
571 * ospf_deferred_shutdown_check.
573 * Function is to cleanup G-R state, if required then call ospf_finish_final
574 * to complete shutdown of this ospf instance. Possibly exit if the
575 * whole process is being shutdown and this was the last OSPF instance.
577 static void ospf_deferred_shutdown_finish(struct ospf
*ospf
)
579 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
580 THREAD_OFF(ospf
->t_deferred_shutdown
);
582 ospf_finish_final(ospf
);
584 /* *ospf is now invalid */
586 /* ospfd being shut-down? If so, was this the last ospf instance? */
587 if (CHECK_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
)
588 && (listcount(om
->ospf
) == 0)) {
596 /* Timer thread for G-R */
597 static void ospf_deferred_shutdown_timer(struct thread
*t
)
599 struct ospf
*ospf
= THREAD_ARG(t
);
601 ospf_deferred_shutdown_finish(ospf
);
604 /* Check whether deferred-shutdown must be scheduled, otherwise call
605 * down directly into second-half of instance shutdown.
607 static void ospf_deferred_shutdown_check(struct ospf
*ospf
)
609 unsigned long timeout
;
611 struct ospf_area
*area
;
613 /* deferred shutdown already running? */
614 if (ospf
->t_deferred_shutdown
)
617 /* Should we try push out max-metric LSAs? */
618 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
) {
619 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
620 SET_FLAG(area
->stub_router_state
,
621 OSPF_AREA_ADMIN_STUB_ROUTED
);
623 if (!CHECK_FLAG(area
->stub_router_state
,
624 OSPF_AREA_IS_STUB_ROUTED
))
625 ospf_router_lsa_update_area(area
);
627 timeout
= ospf
->stub_router_shutdown_time
;
629 /* No timer needed */
630 ospf_deferred_shutdown_finish(ospf
);
634 OSPF_TIMER_ON(ospf
->t_deferred_shutdown
, ospf_deferred_shutdown_timer
,
639 /* Shut down the entire process */
640 void ospf_terminate(void)
643 struct listnode
*node
, *nnode
;
645 /* shutdown already in progress */
646 if (CHECK_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
))
649 SET_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
);
651 /* Skip some steps if OSPF not actually running */
652 if (listcount(om
->ospf
) == 0)
655 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
659 ospf_gr_helper_stop();
661 /* Cleanup route maps */
664 /* reverse prefix_list_init */
665 prefix_list_add_hook(NULL
);
666 prefix_list_delete_hook(NULL
);
669 /* Cleanup vrf info */
670 ospf_vrf_terminate();
672 /* Deliberately go back up, hopefully to thread scheduler, as
673 * One or more ospf_finish()'s may have deferred shutdown to a timer
676 zclient_stop(zclient
);
677 zclient_free(zclient
);
683 void ospf_finish(struct ospf
*ospf
)
685 /* let deferred shutdown decide */
686 ospf_deferred_shutdown_check(ospf
);
688 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
689 * deferred to expiry of G-S timer thread. Return back up, hopefully
690 * to thread scheduler.
695 /* Final cleanup of ospf instance */
696 static void ospf_finish_final(struct ospf
*ospf
)
698 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
699 struct route_node
*rn
;
700 struct ospf_nbr_nbma
*nbr_nbma
;
701 struct ospf_lsa
*lsa
;
702 struct ospf_interface
*oi
;
703 struct ospf_area
*area
;
704 struct ospf_vl_data
*vl_data
;
705 struct listnode
*node
, *nnode
;
706 struct ospf_redist
*red
;
711 ospf_opaque_type11_lsa_term(ospf
);
713 ospf_opaque_finish();
715 if (!ospf
->gr_info
.prepare_in_progress
)
716 ospf_flush_self_originated_lsas_now(ospf
);
718 /* Unregister redistribution */
719 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
720 struct list
*red_list
;
722 red_list
= ospf
->redist
[i
];
726 for (ALL_LIST_ELEMENTS(red_list
, node
, nnode
, red
)) {
727 ospf_redistribute_unset(ospf
, i
, red
->instance
);
728 ospf_redist_del(ospf
, i
, red
->instance
);
731 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
733 ospf_routemap_unset(red
);
734 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
735 ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
, 0, 0);
738 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
739 ospf_remove_vls_through_area(ospf
, area
);
741 for (ALL_LIST_ELEMENTS(ospf
->vlinks
, node
, nnode
, vl_data
))
742 ospf_vl_delete(ospf
, vl_data
);
744 list_delete(&ospf
->vlinks
);
746 /* shutdown LDP-Sync */
747 if (ospf
->vrf_id
== VRF_DEFAULT
)
748 ospf_ldp_sync_gbl_exit(ospf
, true);
750 /* Reset interface. */
751 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
753 list_delete(&ospf
->oiflist
);
754 ospf
->oi_running
= 0;
756 /* De-Register VRF */
757 ospf_zebra_vrf_deregister(ospf
);
759 /* Clear static neighbors */
760 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
761 if ((nbr_nbma
= rn
->info
)) {
762 THREAD_OFF(nbr_nbma
->t_poll
);
765 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
766 nbr_nbma
->nbr
= NULL
;
770 listnode_delete(nbr_nbma
->oi
->nbr_nbma
,
775 XFREE(MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
778 route_table_finish(ospf
->nbr_nbma
);
780 /* Clear networks and Areas. */
781 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
782 struct ospf_network
*network
;
784 if ((network
= rn
->info
) != NULL
) {
785 ospf_network_free(ospf
, network
);
787 route_unlock_node(rn
);
790 route_table_finish(ospf
->networks
);
792 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
793 listnode_delete(ospf
->areas
, area
);
794 ospf_area_free(area
);
797 /* Cancel all timers. */
798 THREAD_OFF(ospf
->t_read
);
799 THREAD_OFF(ospf
->t_write
);
800 THREAD_OFF(ospf
->t_spf_calc
);
801 THREAD_OFF(ospf
->t_ase_calc
);
802 THREAD_OFF(ospf
->t_maxage
);
803 THREAD_OFF(ospf
->t_maxage_walker
);
804 THREAD_OFF(ospf
->t_abr_task
);
805 THREAD_OFF(ospf
->t_asbr_check
);
806 THREAD_OFF(ospf
->t_asbr_nssa_redist_update
);
807 THREAD_OFF(ospf
->t_distribute_update
);
808 THREAD_OFF(ospf
->t_lsa_refresher
);
809 THREAD_OFF(ospf
->t_opaque_lsa_self
);
810 THREAD_OFF(ospf
->t_sr_update
);
811 THREAD_OFF(ospf
->t_default_routemap_timer
);
812 THREAD_OFF(ospf
->t_external_aggr
);
813 THREAD_OFF(ospf
->gr_info
.t_grace_period
);
815 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
816 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
817 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
818 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
820 ospf_lsdb_delete_all(ospf
->lsdb
);
821 ospf_lsdb_free(ospf
->lsdb
);
823 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
824 if ((lsa
= rn
->info
) != NULL
) {
825 ospf_lsa_unlock(&lsa
);
827 route_unlock_node(rn
);
830 route_table_finish(ospf
->maxage_lsa
);
833 ospf_route_table_free(ospf
->old_table
);
834 if (ospf
->new_table
) {
835 if (!ospf
->gr_info
.prepare_in_progress
)
836 ospf_route_delete(ospf
, ospf
->new_table
);
837 ospf_route_table_free(ospf
->new_table
);
840 ospf_rtrs_free(ospf
->oall_rtrs
);
842 ospf_rtrs_free(ospf
->all_rtrs
);
844 ospf_rtrs_free(ospf
->old_rtrs
);
846 ospf_rtrs_free(ospf
->new_rtrs
);
847 if (ospf
->new_external_route
) {
848 if (!ospf
->gr_info
.prepare_in_progress
)
849 ospf_route_delete(ospf
, ospf
->new_external_route
);
850 ospf_route_table_free(ospf
->new_external_route
);
852 if (ospf
->old_external_route
) {
853 if (!ospf
->gr_info
.prepare_in_progress
)
854 ospf_route_delete(ospf
, ospf
->old_external_route
);
855 ospf_route_table_free(ospf
->old_external_route
);
857 if (ospf
->external_lsas
) {
858 ospf_ase_external_lsas_finish(ospf
->external_lsas
);
861 for (i
= ZEBRA_ROUTE_SYSTEM
; i
<= ZEBRA_ROUTE_MAX
; i
++) {
862 struct list
*ext_list
;
863 struct ospf_external
*ext
;
865 ext_list
= ospf
->external
[i
];
869 for (ALL_LIST_ELEMENTS(ext_list
, node
, nnode
, ext
)) {
870 if (ext
->external_info
)
871 for (rn
= route_top(ext
->external_info
); rn
;
872 rn
= route_next(rn
)) {
873 if (rn
->info
== NULL
)
876 XFREE(MTYPE_OSPF_EXTERNAL_INFO
,
879 route_unlock_node(rn
);
882 ospf_external_del(ospf
, i
, ext
->instance
);
886 ospf_distance_reset(ospf
);
887 route_table_finish(ospf
->distance_table
);
889 /* Release extrenal Aggregator table */
890 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
)) {
891 struct ospf_external_aggr_rt
*aggr
;
896 ospf_external_aggregator_free(aggr
);
898 route_unlock_node(rn
);
902 route_table_finish(ospf
->rt_aggr_tbl
);
905 ospf_free_refresh_queue(ospf
);
907 list_delete(&ospf
->areas
);
908 list_delete(&ospf
->oi_write_q
);
910 /* Reset GR helper data structers */
911 ospf_gr_helper_instance_stop(ospf
);
914 stream_free(ospf
->ibuf
);
916 ospf
->max_multipath
= MULTIPATH_NUM
;
920 ospf_vrf_unlink(ospf
, vrf
);
922 XFREE(MTYPE_OSPF_TOP
, ospf
->name
);
923 XFREE(MTYPE_OSPF_TOP
, ospf
);
927 /* allocate new OSPF Area object */
928 struct ospf_area
*ospf_area_new(struct ospf
*ospf
, struct in_addr area_id
)
930 struct ospf_area
*new;
932 /* Allocate new config_network. */
933 new = XCALLOC(MTYPE_OSPF_AREA
, sizeof(struct ospf_area
));
937 new->area_id
= area_id
;
938 new->area_id_fmt
= OSPF_AREA_ID_FMT_DOTTEDQUAD
;
940 new->external_routing
= OSPF_AREA_DEFAULT
;
941 new->default_cost
= 1;
942 new->auth_type
= OSPF_AUTH_NULL
;
945 new->lsdb
= ospf_lsdb_new();
947 /* Self-originated LSAs initialize. */
948 new->router_lsa_self
= NULL
;
950 ospf_opaque_type10_lsa_init(new);
952 new->oiflist
= list_new();
953 new->ranges
= route_table_init();
955 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
)
956 ospf
->backbone
= new;
961 void ospf_area_lsdb_discard_delete(struct ospf_area
*area
)
963 struct route_node
*rn
;
964 struct ospf_lsa
*lsa
;
966 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
)
967 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
968 LSDB_LOOP (NETWORK_LSDB(area
), rn
, lsa
)
969 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
970 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
971 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
972 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
973 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
975 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
976 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
977 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
978 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
979 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
980 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
982 ospf_lsdb_delete_all(area
->lsdb
);
985 static void ospf_area_free(struct ospf_area
*area
)
987 ospf_opaque_type10_lsa_term(area
);
990 ospf_area_lsdb_discard_delete(area
);
992 ospf_lsdb_free(area
->lsdb
);
994 ospf_lsa_unlock(&area
->router_lsa_self
);
996 route_table_finish(area
->ranges
);
997 list_delete(&area
->oiflist
);
999 if (EXPORT_NAME(area
))
1000 free(EXPORT_NAME(area
));
1002 if (IMPORT_NAME(area
))
1003 free(IMPORT_NAME(area
));
1006 THREAD_OFF(area
->t_stub_router
);
1007 THREAD_OFF(area
->t_opaque_lsa_self
);
1009 if (OSPF_IS_AREA_BACKBONE(area
))
1010 area
->ospf
->backbone
= NULL
;
1012 XFREE(MTYPE_OSPF_AREA
, area
);
1015 void ospf_area_check_free(struct ospf
*ospf
, struct in_addr area_id
)
1017 struct ospf_area
*area
;
1019 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1020 if (area
&& listcount(area
->oiflist
) == 0 && area
->ranges
->top
== NULL
1021 && !ospf_vl_count(ospf
, area
)
1022 && area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
1023 && area
->external_routing
== OSPF_AREA_DEFAULT
1024 && area
->no_summary
== 0 && area
->default_cost
== 1
1025 && EXPORT_NAME(area
) == NULL
&& IMPORT_NAME(area
) == NULL
1026 && area
->auth_type
== OSPF_AUTH_NULL
) {
1027 listnode_delete(ospf
->areas
, area
);
1028 ospf_area_free(area
);
1032 struct ospf_area
*ospf_area_get(struct ospf
*ospf
, struct in_addr area_id
)
1034 struct ospf_area
*area
;
1036 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1038 area
= ospf_area_new(ospf
, area_id
);
1039 listnode_add_sort(ospf
->areas
, area
);
1040 ospf_check_abr_status(ospf
);
1041 if (ospf
->stub_router_admin_set
1042 == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
) {
1043 SET_FLAG(area
->stub_router_state
,
1044 OSPF_AREA_ADMIN_STUB_ROUTED
);
1051 struct ospf_area
*ospf_area_lookup_by_area_id(struct ospf
*ospf
,
1052 struct in_addr area_id
)
1054 struct ospf_area
*area
;
1055 struct listnode
*node
;
1057 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
1058 if (IPV4_ADDR_SAME(&area
->area_id
, &area_id
))
1064 void ospf_area_add_if(struct ospf_area
*area
, struct ospf_interface
*oi
)
1066 listnode_add(area
->oiflist
, oi
);
1069 void ospf_area_del_if(struct ospf_area
*area
, struct ospf_interface
*oi
)
1071 listnode_delete(area
->oiflist
, oi
);
1075 struct ospf_interface
*add_ospf_interface(struct connected
*co
,
1076 struct ospf_area
*area
)
1078 struct ospf_interface
*oi
;
1080 oi
= ospf_if_new(area
->ospf
, co
->ifp
, co
->address
);
1085 oi
->params
= ospf_lookup_if_params(co
->ifp
, oi
->address
->u
.prefix4
);
1086 oi
->output_cost
= ospf_if_get_output_cost(oi
);
1088 /* Relate ospf interface to ospf instance. */
1089 oi
->ospf
= area
->ospf
;
1091 /* update network type as interface flag */
1092 /* If network type is specified previously,
1093 skip network type setting. */
1094 oi
->type
= IF_DEF_PARAMS(co
->ifp
)->type
;
1095 oi
->ptp_dmvpn
= IF_DEF_PARAMS(co
->ifp
)->ptp_dmvpn
;
1097 /* Add pseudo neighbor. */
1098 ospf_nbr_self_reset(oi
, oi
->ospf
->router_id
);
1100 ospf_area_add_if(oi
->area
, oi
);
1102 /* if LDP-IGP Sync is configured globally inherit config */
1103 ospf_ldp_sync_if_init(oi
);
1106 * if router_id is not configured, don't bring up
1108 * ospf_router_id_update() will call ospf_if_update
1109 * whenever r-id is configured instead.
1111 if ((area
->ospf
->router_id
.s_addr
!= INADDR_ANY
)
1112 && if_is_operative(co
->ifp
))
1118 static void update_redistributed(struct ospf
*ospf
, int add_to_ospf
)
1120 struct route_node
*rn
;
1121 struct external_info
*ei
;
1122 struct ospf_external
*ext
;
1124 if (ospf_is_type_redistributed(ospf
, ZEBRA_ROUTE_CONNECT
, 0)) {
1125 ext
= ospf_external_lookup(ospf
, ZEBRA_ROUTE_CONNECT
, 0);
1126 if ((ext
) && EXTERNAL_INFO(ext
)) {
1127 for (rn
= route_top(EXTERNAL_INFO(ext
)); rn
;
1128 rn
= route_next(rn
)) {
1134 if (ospf_external_info_find_lsa(ospf
,
1136 if (!ospf_redistribute_check(
1138 ospf_external_lsa_flush(
1141 ei
->ifindex
/*, ei->nexthop */);
1143 if (!ospf_external_info_find_lsa(
1145 if (ospf_redistribute_check(
1147 ospf_external_lsa_originate(
1155 /* Config network statement related functions. */
1156 static struct ospf_network
*ospf_network_new(struct in_addr area_id
)
1158 struct ospf_network
*new;
1159 new = XCALLOC(MTYPE_OSPF_NETWORK
, sizeof(struct ospf_network
));
1161 new->area_id
= area_id
;
1162 new->area_id_fmt
= OSPF_AREA_ID_FMT_DOTTEDQUAD
;
1167 static void ospf_network_free(struct ospf
*ospf
, struct ospf_network
*network
)
1169 ospf_area_check_free(ospf
, network
->area_id
);
1170 ospf_schedule_abr_task(ospf
);
1171 XFREE(MTYPE_OSPF_NETWORK
, network
);
1174 int ospf_network_set(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1175 struct in_addr area_id
, int df
)
1177 struct ospf_network
*network
;
1178 struct ospf_area
*area
;
1179 struct route_node
*rn
;
1181 rn
= route_node_get(ospf
->networks
, (struct prefix
*)p
);
1184 route_unlock_node(rn
);
1186 if (IPV4_ADDR_SAME(&area_id
, &network
->area_id
)) {
1189 /* There is already same network statement. */
1194 rn
->info
= network
= ospf_network_new(area_id
);
1195 network
->area_id_fmt
= df
;
1196 area
= ospf_area_get(ospf
, area_id
);
1197 ospf_area_display_format_set(ospf
, area
, df
);
1199 /* Run network config now. */
1200 ospf_network_run((struct prefix
*)p
, area
);
1202 /* Update connected redistribute. */
1203 update_redistributed(ospf
, 1); /* interfaces possibly added */
1205 ospf_area_check_free(ospf
, area_id
);
1210 int ospf_network_unset(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1211 struct in_addr area_id
)
1213 struct route_node
*rn
;
1214 struct ospf_network
*network
;
1215 struct listnode
*node
, *nnode
;
1216 struct ospf_interface
*oi
;
1218 rn
= route_node_lookup(ospf
->networks
, (struct prefix
*)p
);
1223 route_unlock_node(rn
);
1224 if (!IPV4_ADDR_SAME(&area_id
, &network
->area_id
))
1227 ospf_network_free(ospf
, rn
->info
);
1229 route_unlock_node(rn
); /* initial reference */
1231 /* Find interfaces that are not configured already. */
1232 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
)) {
1234 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1237 ospf_network_run_subnet(ospf
, oi
->connected
, NULL
, NULL
);
1240 /* Update connected redistribute. */
1241 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1242 ospf_area_check_free(ospf
, area_id
);
1247 /* Ensure there's an OSPF instance, as "ip ospf area" enabled OSPF means
1248 * there might not be any 'router ospf' config.
1250 * Otherwise, doesn't do anything different to ospf_if_update for now
1252 void ospf_interface_area_set(struct ospf
*ospf
, struct interface
*ifp
)
1257 ospf_if_update(ospf
, ifp
);
1258 /* if_update does a update_redistributed */
1263 void ospf_interface_area_unset(struct ospf
*ospf
, struct interface
*ifp
)
1265 struct route_node
*rn_oi
;
1268 return; /* Ospf not ready yet */
1270 /* Find interfaces that may need to be removed. */
1271 for (rn_oi
= route_top(IF_OIFS(ifp
)); rn_oi
;
1272 rn_oi
= route_next(rn_oi
)) {
1273 struct ospf_interface
*oi
= NULL
;
1275 if ((oi
= rn_oi
->info
) == NULL
)
1278 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1281 ospf_network_run_subnet(ospf
, oi
->connected
, NULL
, NULL
);
1284 /* Update connected redistribute. */
1285 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1288 /* Check whether interface matches given network
1289 * returns: 1, true. 0, false
1291 static int ospf_network_match_iface(const struct connected
*co
,
1292 const struct prefix
*net
)
1294 /* new approach: more elegant and conceptually clean */
1295 return prefix_match_network_statement(net
, CONNECTED_PREFIX(co
));
1298 static void ospf_update_interface_area(struct connected
*co
,
1299 struct ospf_area
*area
)
1301 struct ospf_interface
*oi
= ospf_if_table_lookup(co
->ifp
, co
->address
);
1303 /* nothing to be done case */
1304 if (oi
&& oi
->area
== area
) {
1311 add_ospf_interface(co
, area
);
1314 /* Run OSPF for the given subnet, taking into account the following
1315 * possible sources of area configuration, in the given order of preference:
1317 * - Whether there is interface+address specific area configuration
1318 * - Whether there is a default area for the interface
1319 * - Whether there is an area given as a parameter.
1320 * - If no specific network prefix/area is supplied, whether there's
1321 * a matching network configured.
1323 static void ospf_network_run_subnet(struct ospf
*ospf
, struct connected
*co
,
1325 struct ospf_area
*given_area
)
1327 struct ospf_interface
*oi
;
1328 struct ospf_if_params
*params
;
1329 struct ospf_area
*area
= NULL
;
1330 struct route_node
*rn
;
1333 if (CHECK_FLAG(co
->flags
, ZEBRA_IFA_SECONDARY
))
1336 if (co
->address
->family
!= AF_INET
)
1339 /* Try determine the appropriate area for this interface + address
1340 * Start by checking interface config
1342 params
= ospf_lookup_if_params(co
->ifp
, co
->address
->u
.prefix4
);
1343 if (params
&& OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1344 area
= ospf_area_get(ospf
, params
->if_area
);
1346 params
= IF_DEF_PARAMS(co
->ifp
);
1347 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1348 area
= ospf_area_get(ospf
, params
->if_area
);
1351 /* If we've found an interface and/or addr specific area, then we're
1355 ospf_update_interface_area(co
, area
);
1359 /* Otherwise, only remaining possibility is a matching network statement
1362 assert(given_area
!= NULL
);
1364 /* Which either was supplied as a parameter.. (e.g. cause a new
1365 * network/area was just added)..
1367 if (p
->family
== co
->address
->family
1368 && ospf_network_match_iface(co
, p
))
1369 ospf_update_interface_area(co
, given_area
);
1374 /* Else we have to search the existing network/area config to see
1377 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
1378 if (rn
->info
!= NULL
&& ospf_network_match_iface(co
, &rn
->p
)) {
1379 struct ospf_network
*network
=
1380 (struct ospf_network
*)rn
->info
;
1381 area
= ospf_area_get(ospf
, network
->area_id
);
1382 ospf_update_interface_area(co
, area
);
1386 /* If the subnet isn't in any area, deconfigure */
1387 if (!configed
&& (oi
= ospf_if_table_lookup(co
->ifp
, co
->address
)))
1391 static void ospf_network_run_interface(struct ospf
*ospf
, struct interface
*ifp
,
1393 struct ospf_area
*given_area
)
1395 struct listnode
*cnode
;
1396 struct connected
*co
;
1398 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
1401 /* Network prefix without area is nonsensical */
1403 assert(given_area
!= NULL
);
1405 /* if interface prefix is match specified prefix,
1406 then create socket and join multicast group. */
1407 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, co
))
1408 ospf_network_run_subnet(ospf
, co
, p
, given_area
);
1411 static void ospf_network_run(struct prefix
*p
, struct ospf_area
*area
)
1413 struct vrf
*vrf
= vrf_lookup_by_id(area
->ospf
->vrf_id
);
1414 struct interface
*ifp
;
1416 /* Schedule Router ID Update. */
1417 if (area
->ospf
->router_id
.s_addr
== INADDR_ANY
)
1418 ospf_router_id_update(area
->ospf
);
1420 /* Get target interface. */
1421 FOR_ALL_INTERFACES (vrf
, ifp
)
1422 ospf_network_run_interface(area
->ospf
, ifp
, p
, area
);
1425 void ospf_ls_upd_queue_empty(struct ospf_interface
*oi
)
1427 struct route_node
*rn
;
1428 struct listnode
*node
, *nnode
;
1430 struct ospf_lsa
*lsa
;
1432 /* empty ls update queue */
1433 for (rn
= route_top(oi
->ls_upd_queue
); rn
; rn
= route_next(rn
))
1434 if ((lst
= (struct list
*)rn
->info
)) {
1435 for (ALL_LIST_ELEMENTS(lst
, node
, nnode
, lsa
))
1436 ospf_lsa_unlock(&lsa
); /* oi->ls_upd_queue */
1441 /* remove update event */
1442 THREAD_OFF(oi
->t_ls_upd_event
);
1445 void ospf_if_update(struct ospf
*ospf
, struct interface
*ifp
)
1451 if (IS_DEBUG_OSPF_EVENT
)
1453 "%s: interface %s vrf %s(%u) ospf vrf %s vrf_id %u router_id %pI4",
1454 __func__
, ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
,
1455 ospf_vrf_id_to_name(ospf
->vrf_id
), ospf
->vrf_id
,
1458 /* OSPF must be ready. */
1459 if (!ospf_is_ready(ospf
))
1462 ospf_network_run_interface(ospf
, ifp
, NULL
, NULL
);
1464 /* Update connected redistribute. */
1465 update_redistributed(ospf
, 1);
1469 void ospf_remove_vls_through_area(struct ospf
*ospf
, struct ospf_area
*area
)
1471 struct listnode
*node
, *nnode
;
1472 struct ospf_vl_data
*vl_data
;
1474 for (ALL_LIST_ELEMENTS(ospf
->vlinks
, node
, nnode
, vl_data
))
1475 if (IPV4_ADDR_SAME(&vl_data
->vl_area_id
, &area
->area_id
))
1476 ospf_vl_delete(ospf
, vl_data
);
1480 static const struct message ospf_area_type_msg
[] = {
1481 {OSPF_AREA_DEFAULT
, "Default"},
1482 {OSPF_AREA_STUB
, "Stub"},
1483 {OSPF_AREA_NSSA
, "NSSA"},
1486 static void ospf_area_type_set(struct ospf_area
*area
, int type
)
1488 struct listnode
*node
;
1489 struct ospf_interface
*oi
;
1491 if (area
->external_routing
== type
) {
1492 if (IS_DEBUG_OSPF_EVENT
)
1493 zlog_debug("Area[%pI4]: Types are the same, ignored.",
1498 area
->external_routing
= type
;
1500 if (IS_DEBUG_OSPF_EVENT
)
1501 zlog_debug("Area[%pI4]: Configured as %s",
1503 lookup_msg(ospf_area_type_msg
, type
, NULL
));
1505 switch (area
->external_routing
) {
1506 case OSPF_AREA_DEFAULT
:
1507 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1508 if (oi
->nbr_self
!= NULL
) {
1509 UNSET_FLAG(oi
->nbr_self
->options
,
1511 SET_FLAG(oi
->nbr_self
->options
, OSPF_OPTION_E
);
1514 case OSPF_AREA_STUB
:
1515 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1516 if (oi
->nbr_self
!= NULL
) {
1517 if (IS_DEBUG_OSPF_EVENT
)
1519 "setting options on %s accordingly",
1521 UNSET_FLAG(oi
->nbr_self
->options
,
1523 UNSET_FLAG(oi
->nbr_self
->options
,
1525 if (IS_DEBUG_OSPF_EVENT
)
1526 zlog_debug("options set on %s: %x",
1527 IF_NAME(oi
), OPTIONS(oi
));
1530 case OSPF_AREA_NSSA
:
1531 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1532 if (oi
->nbr_self
!= NULL
) {
1534 "setting nssa options on %s accordingly",
1536 UNSET_FLAG(oi
->nbr_self
->options
,
1538 SET_FLAG(oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1539 zlog_debug("options set on %s: %x", IF_NAME(oi
),
1547 ospf_router_lsa_update_area(area
);
1548 ospf_schedule_abr_task(area
->ospf
);
1551 int ospf_area_shortcut_set(struct ospf
*ospf
, struct ospf_area
*area
, int mode
)
1553 if (area
->shortcut_configured
== mode
)
1556 area
->shortcut_configured
= mode
;
1557 ospf_router_lsa_update_area(area
);
1558 ospf_schedule_abr_task(ospf
);
1560 ospf_area_check_free(ospf
, area
->area_id
);
1565 int ospf_area_shortcut_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1567 area
->shortcut_configured
= OSPF_SHORTCUT_DEFAULT
;
1568 ospf_router_lsa_update_area(area
);
1569 ospf_area_check_free(ospf
, area
->area_id
);
1570 ospf_schedule_abr_task(ospf
);
1575 static int ospf_area_vlink_count(struct ospf
*ospf
, struct ospf_area
*area
)
1577 struct ospf_vl_data
*vl
;
1578 struct listnode
*node
;
1581 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl
))
1582 if (IPV4_ADDR_SAME(&vl
->vl_area_id
, &area
->area_id
))
1588 int ospf_area_display_format_set(struct ospf
*ospf
, struct ospf_area
*area
,
1591 area
->area_id_fmt
= df
;
1596 int ospf_area_stub_set(struct ospf
*ospf
, struct in_addr area_id
)
1598 struct ospf_area
*area
;
1600 area
= ospf_area_get(ospf
, area_id
);
1601 if (ospf_area_vlink_count(ospf
, area
))
1604 if (area
->external_routing
!= OSPF_AREA_STUB
)
1605 ospf_area_type_set(area
, OSPF_AREA_STUB
);
1610 int ospf_area_stub_unset(struct ospf
*ospf
, struct in_addr area_id
)
1612 struct ospf_area
*area
;
1614 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1618 if (area
->external_routing
== OSPF_AREA_STUB
)
1619 ospf_area_type_set(area
, OSPF_AREA_DEFAULT
);
1621 ospf_area_check_free(ospf
, area_id
);
1626 int ospf_area_no_summary_set(struct ospf
*ospf
, struct in_addr area_id
)
1628 struct ospf_area
*area
;
1630 area
= ospf_area_get(ospf
, area_id
);
1631 area
->no_summary
= 1;
1636 int ospf_area_no_summary_unset(struct ospf
*ospf
, struct in_addr area_id
)
1638 struct ospf_area
*area
;
1640 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1644 area
->no_summary
= 0;
1645 ospf_area_check_free(ospf
, area_id
);
1650 int ospf_area_nssa_no_summary_set(struct ospf
*ospf
, struct in_addr area_id
)
1652 struct ospf_area
*area
;
1654 area
= ospf_area_get(ospf
, area_id
);
1655 if (ospf_area_vlink_count(ospf
, area
))
1658 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1659 ospf_area_type_set(area
, OSPF_AREA_NSSA
);
1661 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1664 ospf_area_no_summary_set(ospf
, area_id
);
1669 int ospf_area_nssa_set(struct ospf
*ospf
, struct in_addr area_id
)
1671 struct ospf_area
*area
;
1673 area
= ospf_area_get(ospf
, area_id
);
1674 if (ospf_area_vlink_count(ospf
, area
))
1677 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1678 ospf_area_type_set(area
, OSPF_AREA_NSSA
);
1681 /* set NSSA area defaults */
1682 area
->no_summary
= 0;
1683 area
->suppress_fa
= 0;
1684 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1685 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1686 area
->NSSATranslatorStabilityInterval
=
1687 OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1692 int ospf_area_nssa_unset(struct ospf
*ospf
, struct in_addr area_id
, int argc
)
1694 struct ospf_area
*area
;
1696 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1700 /* argc < 5 -> 'no area x nssa' */
1701 if (argc
< 5 && area
->external_routing
== OSPF_AREA_NSSA
) {
1703 /* set NSSA area defaults */
1704 area
->no_summary
= 0;
1705 area
->suppress_fa
= 0;
1706 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1707 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1708 area
->NSSATranslatorStabilityInterval
=
1709 OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1710 ospf_area_type_set(area
, OSPF_AREA_DEFAULT
);
1712 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1713 OSPF_NSSA_ROLE_CANDIDATE
);
1716 ospf_area_check_free(ospf
, area_id
);
1721 int ospf_area_nssa_suppress_fa_set(struct ospf
*ospf
, struct in_addr area_id
)
1723 struct ospf_area
*area
;
1725 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1729 area
->suppress_fa
= 1;
1734 int ospf_area_nssa_suppress_fa_unset(struct ospf
*ospf
, struct in_addr area_id
)
1736 struct ospf_area
*area
;
1738 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1742 area
->suppress_fa
= 0;
1747 int ospf_area_nssa_translator_role_set(struct ospf
*ospf
,
1748 struct in_addr area_id
, int role
)
1750 struct ospf_area
*area
;
1752 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1756 if (role
!= area
->NSSATranslatorRole
) {
1757 if ((area
->NSSATranslatorRole
== OSPF_NSSA_ROLE_ALWAYS
)
1758 || (role
== OSPF_NSSA_ROLE_ALWAYS
)) {
1760 * if new role is OSPF_NSSA_ROLE_ALWAYS we need to set
1761 * Nt bit, if the role was OSPF_NSSA_ROLE_ALWAYS we need
1764 area
->NSSATranslatorRole
= role
;
1765 ospf_router_lsa_update_area(area
);
1767 area
->NSSATranslatorRole
= role
;
1773 int ospf_area_export_list_set(struct ospf
*ospf
, struct ospf_area
*area
,
1774 const char *list_name
)
1776 struct access_list
*list
;
1777 list
= access_list_lookup(AFI_IP
, list_name
);
1779 EXPORT_LIST(area
) = list
;
1781 if (EXPORT_NAME(area
))
1782 free(EXPORT_NAME(area
));
1784 EXPORT_NAME(area
) = strdup(list_name
);
1785 ospf_schedule_abr_task(ospf
);
1790 int ospf_area_export_list_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1793 EXPORT_LIST(area
) = 0;
1795 if (EXPORT_NAME(area
))
1796 free(EXPORT_NAME(area
));
1798 EXPORT_NAME(area
) = NULL
;
1800 ospf_area_check_free(ospf
, area
->area_id
);
1802 ospf_schedule_abr_task(ospf
);
1807 int ospf_area_import_list_set(struct ospf
*ospf
, struct ospf_area
*area
,
1810 struct access_list
*list
;
1811 list
= access_list_lookup(AFI_IP
, name
);
1813 IMPORT_LIST(area
) = list
;
1815 if (IMPORT_NAME(area
))
1816 free(IMPORT_NAME(area
));
1818 IMPORT_NAME(area
) = strdup(name
);
1819 ospf_schedule_abr_task(ospf
);
1824 int ospf_area_import_list_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1826 IMPORT_LIST(area
) = 0;
1828 if (IMPORT_NAME(area
))
1829 free(IMPORT_NAME(area
));
1831 IMPORT_NAME(area
) = NULL
;
1832 ospf_area_check_free(ospf
, area
->area_id
);
1834 ospf_schedule_abr_task(ospf
);
1839 int ospf_timers_refresh_set(struct ospf
*ospf
, int interval
)
1843 if (ospf
->lsa_refresh_interval
== interval
)
1846 time_left
= ospf
->lsa_refresh_interval
1847 - (monotime(NULL
) - ospf
->lsa_refresher_started
);
1849 if (time_left
> interval
) {
1850 THREAD_OFF(ospf
->t_lsa_refresher
);
1851 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1852 interval
, &ospf
->t_lsa_refresher
);
1854 ospf
->lsa_refresh_interval
= interval
;
1859 int ospf_timers_refresh_unset(struct ospf
*ospf
)
1863 time_left
= ospf
->lsa_refresh_interval
1864 - (monotime(NULL
) - ospf
->lsa_refresher_started
);
1866 if (time_left
> OSPF_LSA_REFRESH_INTERVAL_DEFAULT
) {
1867 THREAD_OFF(ospf
->t_lsa_refresher
);
1868 ospf
->t_lsa_refresher
= NULL
;
1869 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1870 OSPF_LSA_REFRESH_INTERVAL_DEFAULT
,
1871 &ospf
->t_lsa_refresher
);
1874 ospf
->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
1880 static struct ospf_nbr_nbma
*ospf_nbr_nbma_new(void)
1882 struct ospf_nbr_nbma
*nbr_nbma
;
1884 nbr_nbma
= XCALLOC(MTYPE_OSPF_NEIGHBOR_STATIC
,
1885 sizeof(struct ospf_nbr_nbma
));
1887 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1888 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1893 static void ospf_nbr_nbma_free(struct ospf_nbr_nbma
*nbr_nbma
)
1895 XFREE(MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
1898 static void ospf_nbr_nbma_delete(struct ospf
*ospf
,
1899 struct ospf_nbr_nbma
*nbr_nbma
)
1901 struct route_node
*rn
;
1902 struct prefix_ipv4 p
;
1905 p
.prefix
= nbr_nbma
->addr
;
1906 p
.prefixlen
= IPV4_MAX_BITLEN
;
1908 rn
= route_node_lookup(ospf
->nbr_nbma
, (struct prefix
*)&p
);
1910 ospf_nbr_nbma_free(rn
->info
);
1912 route_unlock_node(rn
);
1913 route_unlock_node(rn
);
1917 static void ospf_nbr_nbma_down(struct ospf_nbr_nbma
*nbr_nbma
)
1919 THREAD_OFF(nbr_nbma
->t_poll
);
1921 if (nbr_nbma
->nbr
) {
1922 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
1923 OSPF_NSM_EVENT_EXECUTE(nbr_nbma
->nbr
, NSM_KillNbr
);
1927 listnode_delete(nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
1930 static void ospf_nbr_nbma_add(struct ospf_nbr_nbma
*nbr_nbma
,
1931 struct ospf_interface
*oi
)
1933 struct ospf_neighbor
*nbr
;
1934 struct route_node
*rn
;
1937 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1940 if (nbr_nbma
->nbr
!= NULL
)
1943 if (IPV4_ADDR_SAME(&oi
->nbr_self
->address
.u
.prefix4
, &nbr_nbma
->addr
))
1947 listnode_add(oi
->nbr_nbma
, nbr_nbma
);
1949 /* Get neighbor information from table. */
1951 p
.prefixlen
= IPV4_MAX_BITLEN
;
1952 p
.u
.prefix4
= nbr_nbma
->addr
;
1954 rn
= route_node_get(oi
->nbrs
, &p
);
1957 nbr
->nbr_nbma
= nbr_nbma
;
1958 nbr_nbma
->nbr
= nbr
;
1960 route_unlock_node(rn
);
1962 nbr
= rn
->info
= ospf_nbr_new(oi
);
1963 nbr
->state
= NSM_Down
;
1964 nbr
->src
= nbr_nbma
->addr
;
1965 nbr
->nbr_nbma
= nbr_nbma
;
1966 nbr
->priority
= nbr_nbma
->priority
;
1969 nbr_nbma
->nbr
= nbr
;
1971 /* Configure BFD if interface has it. */
1972 ospf_neighbor_bfd_apply(nbr
);
1974 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_Start
);
1978 void ospf_nbr_nbma_if_update(struct ospf
*ospf
, struct ospf_interface
*oi
)
1980 struct ospf_nbr_nbma
*nbr_nbma
;
1981 struct route_node
*rn
;
1982 struct prefix_ipv4 p
;
1984 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1987 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
1988 if ((nbr_nbma
= rn
->info
))
1989 if (nbr_nbma
->oi
== NULL
&& nbr_nbma
->nbr
== NULL
) {
1991 p
.prefix
= nbr_nbma
->addr
;
1992 p
.prefixlen
= IPV4_MAX_BITLEN
;
1994 if (prefix_match(oi
->address
,
1995 (struct prefix
*)&p
))
1996 ospf_nbr_nbma_add(nbr_nbma
, oi
);
2000 struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup(struct ospf
*ospf
,
2001 struct in_addr nbr_addr
)
2003 struct route_node
*rn
;
2004 struct prefix_ipv4 p
;
2007 p
.prefix
= nbr_addr
;
2008 p
.prefixlen
= IPV4_MAX_BITLEN
;
2010 rn
= route_node_lookup(ospf
->nbr_nbma
, (struct prefix
*)&p
);
2012 route_unlock_node(rn
);
2018 int ospf_nbr_nbma_set(struct ospf
*ospf
, struct in_addr nbr_addr
)
2020 struct ospf_nbr_nbma
*nbr_nbma
;
2021 struct ospf_interface
*oi
;
2022 struct prefix_ipv4 p
;
2023 struct route_node
*rn
;
2024 struct listnode
*node
;
2026 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2030 nbr_nbma
= ospf_nbr_nbma_new();
2031 nbr_nbma
->addr
= nbr_addr
;
2034 p
.prefix
= nbr_addr
;
2035 p
.prefixlen
= IPV4_MAX_BITLEN
;
2037 rn
= route_node_get(ospf
->nbr_nbma
, (struct prefix
*)&p
);
2039 route_unlock_node(rn
);
2040 rn
->info
= nbr_nbma
;
2042 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
2043 if (oi
->type
== OSPF_IFTYPE_NBMA
)
2044 if (prefix_match(oi
->address
, (struct prefix
*)&p
)) {
2045 ospf_nbr_nbma_add(nbr_nbma
, oi
);
2053 int ospf_nbr_nbma_unset(struct ospf
*ospf
, struct in_addr nbr_addr
)
2055 struct ospf_nbr_nbma
*nbr_nbma
;
2057 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2058 if (nbr_nbma
== NULL
)
2061 ospf_nbr_nbma_down(nbr_nbma
);
2062 ospf_nbr_nbma_delete(ospf
, nbr_nbma
);
2067 int ospf_nbr_nbma_priority_set(struct ospf
*ospf
, struct in_addr nbr_addr
,
2070 struct ospf_nbr_nbma
*nbr_nbma
;
2072 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2073 if (nbr_nbma
== NULL
)
2076 if (nbr_nbma
->priority
!= priority
)
2077 nbr_nbma
->priority
= priority
;
2082 int ospf_nbr_nbma_priority_unset(struct ospf
*ospf
, struct in_addr nbr_addr
)
2084 struct ospf_nbr_nbma
*nbr_nbma
;
2086 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2087 if (nbr_nbma
== NULL
)
2090 if (nbr_nbma
!= OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
2091 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2096 int ospf_nbr_nbma_poll_interval_set(struct ospf
*ospf
, struct in_addr nbr_addr
,
2097 unsigned int interval
)
2099 struct ospf_nbr_nbma
*nbr_nbma
;
2101 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2102 if (nbr_nbma
== NULL
)
2105 if (nbr_nbma
->v_poll
!= interval
) {
2106 nbr_nbma
->v_poll
= interval
;
2107 if (nbr_nbma
->oi
&& ospf_if_is_up(nbr_nbma
->oi
)) {
2108 THREAD_OFF(nbr_nbma
->t_poll
);
2109 OSPF_POLL_TIMER_ON(nbr_nbma
->t_poll
, ospf_poll_timer
,
2117 int ospf_nbr_nbma_poll_interval_unset(struct ospf
*ospf
, struct in_addr addr
)
2119 struct ospf_nbr_nbma
*nbr_nbma
;
2121 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, addr
);
2122 if (nbr_nbma
== NULL
)
2125 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
2126 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
2131 void ospf_master_init(struct thread_master
*master
)
2133 memset(&ospf_master
, 0, sizeof(ospf_master
));
2136 om
->ospf
= list_new();
2137 om
->master
= master
;
2140 /* Link OSPF instance to VRF. */
2141 void ospf_vrf_link(struct ospf
*ospf
, struct vrf
*vrf
)
2143 ospf
->vrf_id
= vrf
->vrf_id
;
2144 if (vrf
->info
!= (void *)ospf
)
2145 vrf
->info
= (void *)ospf
;
2148 /* Unlink OSPF instance from VRF. */
2149 void ospf_vrf_unlink(struct ospf
*ospf
, struct vrf
*vrf
)
2151 if (vrf
->info
== (void *)ospf
)
2153 ospf
->vrf_id
= VRF_UNKNOWN
;
2156 /* This is hook function for vrf create called as part of vrf_init */
2157 static int ospf_vrf_new(struct vrf
*vrf
)
2159 if (IS_DEBUG_OSPF_EVENT
)
2160 zlog_debug("%s: VRF Created: %s(%u)", __func__
, vrf
->name
,
2166 /* This is hook function for vrf delete call as part of vrf_init */
2167 static int ospf_vrf_delete(struct vrf
*vrf
)
2169 if (IS_DEBUG_OSPF_EVENT
)
2170 zlog_debug("%s: VRF Deletion: %s(%u)", __func__
, vrf
->name
,
2176 static void ospf_set_redist_vrf_bitmaps(struct ospf
*ospf
, bool set
)
2179 struct list
*red_list
;
2181 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
2182 red_list
= ospf
->redist
[type
];
2185 if (IS_DEBUG_OSPF_EVENT
)
2187 "%s: setting redist vrf %d bitmap for type %d",
2188 __func__
, ospf
->vrf_id
, type
);
2190 vrf_bitmap_set(zclient
->redist
[AFI_IP
][type
],
2193 vrf_bitmap_unset(zclient
->redist
[AFI_IP
][type
],
2197 red_list
= ospf
->redist
[DEFAULT_ROUTE
];
2200 vrf_bitmap_set(zclient
->default_information
[AFI_IP
],
2203 vrf_bitmap_unset(zclient
->default_information
[AFI_IP
],
2208 /* Enable OSPF VRF instance */
2209 static int ospf_vrf_enable(struct vrf
*vrf
)
2211 struct ospf
*ospf
= NULL
;
2212 vrf_id_t old_vrf_id
;
2215 if (IS_DEBUG_OSPF_EVENT
)
2216 zlog_debug("%s: VRF %s id %u enabled", __func__
, vrf
->name
,
2219 ospf
= ospf_lookup_by_name(vrf
->name
);
2221 old_vrf_id
= ospf
->vrf_id
;
2222 /* We have instance configured, link to VRF and make it "up". */
2223 ospf_vrf_link(ospf
, vrf
);
2224 if (IS_DEBUG_OSPF_EVENT
)
2226 "%s: ospf linked to vrf %s vrf_id %u (old id %u)",
2227 __func__
, vrf
->name
, ospf
->vrf_id
, old_vrf_id
);
2229 if (old_vrf_id
!= ospf
->vrf_id
) {
2230 ospf_set_redist_vrf_bitmaps(ospf
, true);
2232 /* start zebra redist to us for new vrf */
2233 ospf_zebra_vrf_register(ospf
);
2235 ret
= ospf_sock_init(ospf
);
2236 if (ret
< 0 || ospf
->fd
<= 0)
2238 thread_add_read(master
, ospf_read
, ospf
, ospf
->fd
,
2240 ospf
->oi_running
= 1;
2241 ospf_router_id_update(ospf
);
2248 /* Disable OSPF VRF instance */
2249 static int ospf_vrf_disable(struct vrf
*vrf
)
2251 struct ospf
*ospf
= NULL
;
2252 vrf_id_t old_vrf_id
= VRF_UNKNOWN
;
2254 if (vrf
->vrf_id
== VRF_DEFAULT
)
2257 if (IS_DEBUG_OSPF_EVENT
)
2258 zlog_debug("%s: VRF %s id %d disabled.", __func__
, vrf
->name
,
2261 ospf
= ospf_lookup_by_name(vrf
->name
);
2263 old_vrf_id
= ospf
->vrf_id
;
2265 ospf_zebra_vrf_deregister(ospf
);
2267 ospf_set_redist_vrf_bitmaps(ospf
, false);
2269 /* We have instance configured, unlink
2270 * from VRF and make it "down".
2272 ospf_vrf_unlink(ospf
, vrf
);
2273 ospf
->oi_running
= 0;
2274 if (IS_DEBUG_OSPF_EVENT
)
2275 zlog_debug("%s: ospf old_vrf_id %d unlinked", __func__
,
2277 THREAD_OFF(ospf
->t_read
);
2282 /* Note: This is a callback, the VRF will be deleted by the caller. */
2286 void ospf_vrf_init(void)
2288 vrf_init(ospf_vrf_new
, ospf_vrf_enable
, ospf_vrf_disable
,
2292 void ospf_vrf_terminate(void)
2297 const char *ospf_vrf_id_to_name(vrf_id_t vrf_id
)
2299 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
2301 return vrf
? vrf
->name
: "NIL";
2304 const char *ospf_get_name(const struct ospf
*ospf
)
2309 return VRF_DEFAULT_NAME
;