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 () */
41 #include "lib_errors.h"
44 #include "ospfd/ospfd.h"
45 #include "ospfd/ospf_bfd.h"
46 #include "ospfd/ospf_network.h"
47 #include "ospfd/ospf_interface.h"
48 #include "ospfd/ospf_ism.h"
49 #include "ospfd/ospf_asbr.h"
50 #include "ospfd/ospf_lsa.h"
51 #include "ospfd/ospf_lsdb.h"
52 #include "ospfd/ospf_neighbor.h"
53 #include "ospfd/ospf_nsm.h"
54 #include "ospfd/ospf_spf.h"
55 #include "ospfd/ospf_packet.h"
56 #include "ospfd/ospf_dump.h"
57 #include "ospfd/ospf_route.h"
58 #include "ospfd/ospf_zebra.h"
59 #include "ospfd/ospf_abr.h"
60 #include "ospfd/ospf_flood.h"
61 #include "ospfd/ospf_ase.h"
62 #include "ospfd/ospf_ldp_sync.h"
63 #include "ospfd/ospf_gr.h"
66 DEFINE_QOBJ_TYPE(ospf
);
68 /* OSPF process wide configuration. */
69 static struct ospf_master ospf_master
;
71 /* OSPF process wide configuration pointer to export. */
72 struct ospf_master
*om
;
74 unsigned short ospf_instance
;
76 extern struct zclient
*zclient
;
79 static void ospf_remove_vls_through_area(struct ospf
*, struct ospf_area
*);
80 static void ospf_network_free(struct ospf
*, struct ospf_network
*);
81 static void ospf_area_free(struct ospf_area
*);
82 static void ospf_network_run(struct prefix
*, struct ospf_area
*);
83 static void ospf_network_run_interface(struct ospf
*, struct interface
*,
84 struct prefix
*, struct ospf_area
*);
85 static void ospf_network_run_subnet(struct ospf
*, struct connected
*,
86 struct prefix
*, struct ospf_area
*);
87 static int ospf_network_match_iface(const struct connected
*,
88 const struct prefix
*);
89 static void ospf_finish_final(struct ospf
*);
91 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
93 int p_spaces_compare_func(const struct p_space
*a
, const struct p_space
*b
)
95 if (a
->protected_resource
->type
== OSPF_TI_LFA_LINK_PROTECTION
96 && b
->protected_resource
->type
== OSPF_TI_LFA_LINK_PROTECTION
)
97 return (a
->protected_resource
->link
->link_id
.s_addr
98 - b
->protected_resource
->link
->link_id
.s_addr
);
100 if (a
->protected_resource
->type
== OSPF_TI_LFA_NODE_PROTECTION
101 && b
->protected_resource
->type
== OSPF_TI_LFA_NODE_PROTECTION
)
102 return (a
->protected_resource
->router_id
.s_addr
103 - b
->protected_resource
->router_id
.s_addr
);
105 /* This should not happen */
109 int q_spaces_compare_func(const struct q_space
*a
, const struct q_space
*b
)
111 return (a
->root
->id
.s_addr
- b
->root
->id
.s_addr
);
114 DECLARE_RBTREE_UNIQ(p_spaces
, struct p_space
, p_spaces_item
,
115 p_spaces_compare_func
);
117 void ospf_process_refresh_data(struct ospf
*ospf
, bool reset
)
119 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
120 struct in_addr router_id
, router_id_old
;
121 struct ospf_interface
*oi
;
122 struct interface
*ifp
;
123 struct listnode
*node
, *nnode
;
124 struct ospf_area
*area
;
125 bool rid_change
= false;
127 if (!ospf
->oi_running
) {
128 if (IS_DEBUG_OSPF_EVENT
)
130 "Router ospf not configured -- Router-ID update postponed");
134 if (IS_DEBUG_OSPF_EVENT
)
135 zlog_debug("Router-ID[OLD:%pI4]: Update",
138 router_id_old
= ospf
->router_id
;
140 /* Select the router ID based on these priorities:
141 1. Statically assigned router ID is always the first choice.
142 2. If there is no statically assigned router ID, then try to stick
143 with the most recent value, since changing router ID's is very
145 3. Last choice: just go with whatever the zebra daemon recommends.
147 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
148 router_id
= ospf
->router_id_static
;
149 else if (ospf
->router_id
.s_addr
!= INADDR_ANY
)
150 router_id
= ospf
->router_id
;
152 router_id
= ospf
->router_id_zebra
;
154 if (IS_DEBUG_OSPF_EVENT
)
155 zlog_debug("Router-ID[OLD:%pI4]: Update to %pI4",
156 &ospf
->router_id
, &router_id
);
158 rid_change
= !(IPV4_ADDR_SAME(&router_id_old
, &router_id
));
159 if (rid_change
|| (reset
)) {
160 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
161 /* Some nbrs are identified by router_id, these needs
162 * to be rebuilt. Possible optimization would be to do
163 * oi->nbr_self->router_id = router_id for
164 * !(virtual | ptop) links
166 ospf_nbr_self_reset(oi
, router_id
);
169 * If the old router id was not set, but now it
170 * is and the interface is operative and the
171 * state is ISM_Down we should kick the state
172 * machine as that we processed the interfaces
173 * based upon the network statement( or intf config )
174 * but could not start it at that time.
176 if (if_is_operative(oi
->ifp
) && oi
->state
== ISM_Down
177 && router_id_old
.s_addr
== INADDR_ANY
)
181 /* Flush (inline) all the self originated LSAs */
182 ospf_flush_self_originated_lsas_now(ospf
);
184 ospf
->router_id
= router_id
;
185 if (IS_DEBUG_OSPF_EVENT
)
186 zlog_debug("Router-ID[NEW:%pI4]: Update",
189 /* Flush (inline) all external LSAs which now match the new
191 need to adjust the OSPF_LSA_SELF flag, so the flush doesn't
193 asserts in ospf_refresher_unregister_lsa(). This step is
195 because the current frr code does look-up for
197 based on the self router-id alone but expects OSPF_LSA_SELF
201 struct route_node
*rn
;
202 struct ospf_lsa
*lsa
;
204 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
) {
205 /* AdvRouter and Router ID is the same. */
206 if (IPV4_ADDR_SAME(&lsa
->data
->adv_router
,
207 &ospf
->router_id
) && rid_change
) {
209 OSPF_LSA_SELF_CHECKED
);
210 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF
);
211 ospf_lsa_flush_schedule(ospf
, lsa
);
213 /* The above flush will send immediately
214 * So discard the LSA to originate new
216 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
219 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
220 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
222 ospf_lsdb_delete_all(ospf
->lsdb
);
225 /* Since the LSAs are deleted, need reset the aggr flag */
226 ospf_unset_all_aggr_flag(ospf
);
228 /* Delete the LSDB */
229 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
230 ospf_area_lsdb_discard_delete(area
);
232 /* update router-lsa's for each area */
233 ospf_router_lsa_update(ospf
);
235 /* update ospf_interface's */
236 FOR_ALL_INTERFACES (vrf
, ifp
) {
240 ospf_if_update(ospf
, ifp
);
243 ospf_external_lsa_rid_change(ospf
);
246 ospf
->inst_shutdown
= 0;
249 void ospf_router_id_update(struct ospf
*ospf
)
251 ospf_process_refresh_data(ospf
, false);
254 void ospf_process_reset(struct ospf
*ospf
)
256 ospf_process_refresh_data(ospf
, true);
259 void ospf_neighbor_reset(struct ospf
*ospf
, struct in_addr nbr_id
,
262 struct route_node
*rn
;
263 struct ospf_neighbor
*nbr
;
264 struct ospf_interface
*oi
;
265 struct listnode
*node
;
267 /* Clear only a particular nbr with nbr router id as nbr_id */
268 if (nbr_str
!= NULL
) {
269 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
270 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &nbr_id
);
272 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_KillNbr
);
277 /* send Neighbor event KillNbr to all associated neighbors. */
278 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
279 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
281 if (nbr
&& (nbr
!= oi
->nbr_self
))
282 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_KillNbr
);
287 /* For OSPF area sort by area id. */
288 static int ospf_area_id_cmp(struct ospf_area
*a1
, struct ospf_area
*a2
)
290 if (ntohl(a1
->area_id
.s_addr
) > ntohl(a2
->area_id
.s_addr
))
292 if (ntohl(a1
->area_id
.s_addr
) < ntohl(a2
->area_id
.s_addr
))
297 static void ospf_add(struct ospf
*ospf
)
299 listnode_add(om
->ospf
, ospf
);
302 static void ospf_delete(struct ospf
*ospf
)
304 listnode_delete(om
->ospf
, ospf
);
307 struct ospf
*ospf_new_alloc(unsigned short instance
, const char *name
)
310 struct vrf
*vrf
= NULL
;
312 struct ospf
*new = XCALLOC(MTYPE_OSPF_TOP
, sizeof(struct ospf
));
314 new->instance
= instance
;
315 new->router_id
.s_addr
= htonl(0);
316 new->router_id_static
.s_addr
= htonl(0);
318 vrf
= vrf_lookup_by_name(name
);
320 new->vrf_id
= vrf
->vrf_id
;
322 new->vrf_id
= VRF_UNKNOWN
;
324 /* Freed in ospf_finish_final */
325 new->name
= XSTRDUP(MTYPE_OSPF_TOP
, name
);
326 if (IS_DEBUG_OSPF_EVENT
)
328 "%s: Create new ospf instance with vrf_name %s vrf_id %u",
329 __func__
, name
, new->vrf_id
);
332 ospf_vrf_link(new, vrf
);
334 ospf_zebra_vrf_register(new);
336 new->abr_type
= OSPF_ABR_DEFAULT
;
337 new->oiflist
= list_new();
338 new->vlinks
= list_new();
339 new->areas
= list_new();
340 new->areas
->cmp
= (int (*)(void *, void *))ospf_area_id_cmp
;
341 new->networks
= route_table_init();
342 new->nbr_nbma
= route_table_init();
344 new->lsdb
= ospf_lsdb_new();
346 new->default_originate
= DEFAULT_ORIGINATE_NONE
;
348 new->passive_interface_default
= OSPF_IF_ACTIVE
;
350 new->new_external_route
= route_table_init();
351 new->old_external_route
= route_table_init();
352 new->external_lsas
= route_table_init();
354 new->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
355 new->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
356 new->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
358 /* Distribute parameter init. */
359 for (i
= 0; i
<= ZEBRA_ROUTE_MAX
; i
++) {
362 new->default_metric
= -1;
363 new->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
366 new->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
367 new->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
369 /* SPF timer value init. */
370 new->spf_delay
= OSPF_SPF_DELAY_DEFAULT
;
371 new->spf_holdtime
= OSPF_SPF_HOLDTIME_DEFAULT
;
372 new->spf_max_holdtime
= OSPF_SPF_MAX_HOLDTIME_DEFAULT
;
373 new->spf_hold_multiplier
= 1;
376 new->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
377 new->maxage_lsa
= route_table_init();
378 new->t_maxage_walker
= NULL
;
379 thread_add_timer(master
, ospf_lsa_maxage_walker
, new,
380 OSPF_LSA_MAXAGE_CHECK_INTERVAL
, &new->t_maxage_walker
);
382 /* Max paths initialization */
383 new->max_multipath
= MULTIPATH_NUM
;
385 /* Distance table init. */
386 new->distance_table
= route_table_init();
388 new->lsa_refresh_queue
.index
= 0;
389 new->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
390 new->t_lsa_refresher
= NULL
;
391 thread_add_timer(master
, ospf_lsa_refresh_walker
, new,
392 new->lsa_refresh_interval
, &new->t_lsa_refresher
);
393 new->lsa_refresher_started
= monotime(NULL
);
395 new->ibuf
= stream_new(OSPF_MAX_PACKET_SIZE
+ 1);
398 new->oi_write_q
= list_new();
399 new->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
401 new->proactive_arp
= OSPF_PROACTIVE_ARP_DEFAULT
;
403 ospf_gr_helper_instance_init(new);
405 ospf_asbr_external_aggregator_init(new);
407 ospf_opaque_type11_lsa_init(new);
416 /* Allocate new ospf structure. */
417 static struct ospf
*ospf_new(unsigned short instance
, const char *name
)
421 new = ospf_new_alloc(instance
, name
);
424 if (new->vrf_id
== VRF_UNKNOWN
)
427 if ((ospf_sock_init(new)) < 0) {
428 flog_err(EC_LIB_SOCKET
,
429 "%s: ospf_sock_init is unable to open a socket",
434 thread_add_read(master
, ospf_read
, new, new->fd
, &new->t_read
);
437 ospf_router_id_update(new);
440 * Read from non-volatile memory whether this instance is performing a
441 * graceful restart or not.
443 ospf_gr_nvm_read(new);
448 struct ospf
*ospf_lookup_instance(unsigned short instance
)
451 struct listnode
*node
, *nnode
;
453 if (listcount(om
->ospf
) == 0)
456 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
457 if ((ospf
->instance
== 0 && instance
== 0)
458 || (ospf
->instance
&& instance
459 && ospf
->instance
== instance
))
465 static int ospf_is_ready(struct ospf
*ospf
)
467 /* OSPF must be on and Router-ID must be configured. */
468 if (!ospf
|| ospf
->router_id
.s_addr
== INADDR_ANY
)
474 struct ospf
*ospf_lookup_by_inst_name(unsigned short instance
, const char *name
)
476 struct ospf
*ospf
= NULL
;
477 struct listnode
*node
, *nnode
;
479 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
)) {
480 if ((ospf
->instance
== instance
)
481 && ((ospf
->name
== NULL
&& name
== NULL
)
482 || (ospf
->name
&& name
483 && strcmp(ospf
->name
, name
) == 0)))
489 struct ospf
*ospf_lookup(unsigned short instance
, const char *name
)
494 ospf
= ospf_lookup_instance(instance
);
496 ospf
= ospf_lookup_by_inst_name(instance
, name
);
502 struct ospf
*ospf_get(unsigned short instance
, const char *name
, bool *created
)
506 ospf
= ospf_lookup(instance
, name
);
508 *created
= (ospf
== NULL
);
510 ospf
= ospf_new(instance
, name
);
515 struct ospf
*ospf_lookup_by_vrf_id(vrf_id_t vrf_id
)
517 struct vrf
*vrf
= NULL
;
519 vrf
= vrf_lookup_by_id(vrf_id
);
522 return (vrf
->info
) ? (struct ospf
*)vrf
->info
: NULL
;
525 uint32_t ospf_count_area_params(struct ospf
*ospf
)
528 struct interface
*ifp
;
531 if (ospf
->vrf_id
!= VRF_UNKNOWN
) {
532 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
534 FOR_ALL_INTERFACES (vrf
, ifp
) {
535 count
+= ospf_if_count_area_params(ifp
);
542 /* It should only be used when processing incoming info update from zebra.
543 * Other situations, it is not sufficient to lookup the ospf instance by
544 * vrf_name only without using the instance number.
546 static struct ospf
*ospf_lookup_by_name(const char *vrf_name
)
548 struct ospf
*ospf
= NULL
;
549 struct listnode
*node
, *nnode
;
551 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
552 if ((ospf
->name
== NULL
&& vrf_name
== NULL
)
553 || (ospf
->name
&& vrf_name
554 && strcmp(ospf
->name
, vrf_name
) == 0))
559 /* Handle the second half of deferred shutdown. This is called either
560 * from the deferred-shutdown timer thread, or directly through
561 * ospf_deferred_shutdown_check.
563 * Function is to cleanup G-R state, if required then call ospf_finish_final
564 * to complete shutdown of this ospf instance. Possibly exit if the
565 * whole process is being shutdown and this was the last OSPF instance.
567 static void ospf_deferred_shutdown_finish(struct ospf
*ospf
)
569 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
570 OSPF_TIMER_OFF(ospf
->t_deferred_shutdown
);
572 ospf_finish_final(ospf
);
574 /* *ospf is now invalid */
576 /* ospfd being shut-down? If so, was this the last ospf instance? */
577 if (CHECK_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
)
578 && (listcount(om
->ospf
) == 0)) {
586 /* Timer thread for G-R */
587 static int ospf_deferred_shutdown_timer(struct thread
*t
)
589 struct ospf
*ospf
= THREAD_ARG(t
);
591 ospf_deferred_shutdown_finish(ospf
);
596 /* Check whether deferred-shutdown must be scheduled, otherwise call
597 * down directly into second-half of instance shutdown.
599 static void ospf_deferred_shutdown_check(struct ospf
*ospf
)
601 unsigned long timeout
;
603 struct ospf_area
*area
;
605 /* deferred shutdown already running? */
606 if (ospf
->t_deferred_shutdown
)
609 /* Should we try push out max-metric LSAs? */
610 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
) {
611 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
612 SET_FLAG(area
->stub_router_state
,
613 OSPF_AREA_ADMIN_STUB_ROUTED
);
615 if (!CHECK_FLAG(area
->stub_router_state
,
616 OSPF_AREA_IS_STUB_ROUTED
))
617 ospf_router_lsa_update_area(area
);
619 timeout
= ospf
->stub_router_shutdown_time
;
621 /* No timer needed */
622 ospf_deferred_shutdown_finish(ospf
);
626 OSPF_TIMER_ON(ospf
->t_deferred_shutdown
, ospf_deferred_shutdown_timer
,
631 /* Shut down the entire process */
632 void ospf_terminate(void)
635 struct listnode
*node
, *nnode
;
637 /* shutdown already in progress */
638 if (CHECK_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
))
641 SET_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
);
643 /* Skip some steps if OSPF not actually running */
644 if (listcount(om
->ospf
) == 0)
647 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
651 ospf_gr_helper_stop();
653 /* Cleanup route maps */
656 /* reverse prefix_list_init */
657 prefix_list_add_hook(NULL
);
658 prefix_list_delete_hook(NULL
);
661 /* Cleanup vrf info */
662 ospf_vrf_terminate();
664 /* Deliberately go back up, hopefully to thread scheduler, as
665 * One or more ospf_finish()'s may have deferred shutdown to a timer
668 zclient_stop(zclient
);
669 zclient_free(zclient
);
675 void ospf_finish(struct ospf
*ospf
)
677 /* let deferred shutdown decide */
678 ospf_deferred_shutdown_check(ospf
);
680 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
681 * deferred to expiry of G-S timer thread. Return back up, hopefully
682 * to thread scheduler.
687 /* Final cleanup of ospf instance */
688 static void ospf_finish_final(struct ospf
*ospf
)
690 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
691 struct route_node
*rn
;
692 struct ospf_nbr_nbma
*nbr_nbma
;
693 struct ospf_lsa
*lsa
;
694 struct ospf_interface
*oi
;
695 struct ospf_area
*area
;
696 struct ospf_vl_data
*vl_data
;
697 struct listnode
*node
, *nnode
;
698 struct ospf_redist
*red
;
703 ospf_opaque_type11_lsa_term(ospf
);
705 ospf_opaque_finish();
707 if (!ospf
->gr_info
.prepare_in_progress
)
708 ospf_flush_self_originated_lsas_now(ospf
);
710 /* Unregister redistribution */
711 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
712 struct list
*red_list
;
714 red_list
= ospf
->redist
[i
];
718 for (ALL_LIST_ELEMENTS(red_list
, node
, nnode
, red
)) {
719 ospf_redistribute_unset(ospf
, i
, red
->instance
);
720 ospf_redist_del(ospf
, i
, red
->instance
);
723 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
725 ospf_routemap_unset(red
);
726 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
727 ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
, 0, 0);
730 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
731 ospf_remove_vls_through_area(ospf
, area
);
733 for (ALL_LIST_ELEMENTS(ospf
->vlinks
, node
, nnode
, vl_data
))
734 ospf_vl_delete(ospf
, vl_data
);
736 list_delete(&ospf
->vlinks
);
738 /* shutdown LDP-Sync */
739 if (ospf
->vrf_id
== VRF_DEFAULT
)
740 ospf_ldp_sync_gbl_exit(ospf
, true);
742 /* Reset interface. */
743 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
745 list_delete(&ospf
->oiflist
);
746 ospf
->oi_running
= 0;
748 /* De-Register VRF */
749 ospf_zebra_vrf_deregister(ospf
);
751 /* Clear static neighbors */
752 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
753 if ((nbr_nbma
= rn
->info
)) {
754 OSPF_POLL_TIMER_OFF(nbr_nbma
->t_poll
);
757 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
758 nbr_nbma
->nbr
= NULL
;
762 listnode_delete(nbr_nbma
->oi
->nbr_nbma
,
767 XFREE(MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
770 route_table_finish(ospf
->nbr_nbma
);
772 /* Clear networks and Areas. */
773 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
774 struct ospf_network
*network
;
776 if ((network
= rn
->info
) != NULL
) {
777 ospf_network_free(ospf
, network
);
779 route_unlock_node(rn
);
782 route_table_finish(ospf
->networks
);
784 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
785 listnode_delete(ospf
->areas
, area
);
786 ospf_area_free(area
);
789 /* Cancel all timers. */
790 OSPF_TIMER_OFF(ospf
->t_read
);
791 OSPF_TIMER_OFF(ospf
->t_write
);
792 OSPF_TIMER_OFF(ospf
->t_spf_calc
);
793 OSPF_TIMER_OFF(ospf
->t_ase_calc
);
794 OSPF_TIMER_OFF(ospf
->t_maxage
);
795 OSPF_TIMER_OFF(ospf
->t_maxage_walker
);
796 OSPF_TIMER_OFF(ospf
->t_abr_task
);
797 OSPF_TIMER_OFF(ospf
->t_asbr_check
);
798 OSPF_TIMER_OFF(ospf
->t_asbr_nssa_redist_update
);
799 OSPF_TIMER_OFF(ospf
->t_distribute_update
);
800 OSPF_TIMER_OFF(ospf
->t_lsa_refresher
);
801 OSPF_TIMER_OFF(ospf
->t_opaque_lsa_self
);
802 OSPF_TIMER_OFF(ospf
->t_sr_update
);
803 OSPF_TIMER_OFF(ospf
->t_default_routemap_timer
);
804 OSPF_TIMER_OFF(ospf
->t_external_aggr
);
805 OSPF_TIMER_OFF(ospf
->gr_info
.t_grace_period
);
807 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
808 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
809 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
810 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
812 ospf_lsdb_delete_all(ospf
->lsdb
);
813 ospf_lsdb_free(ospf
->lsdb
);
815 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
816 if ((lsa
= rn
->info
) != NULL
) {
817 ospf_lsa_unlock(&lsa
);
819 route_unlock_node(rn
);
822 route_table_finish(ospf
->maxage_lsa
);
825 ospf_route_table_free(ospf
->old_table
);
826 if (ospf
->new_table
) {
827 if (!ospf
->gr_info
.prepare_in_progress
)
828 ospf_route_delete(ospf
, ospf
->new_table
);
829 ospf_route_table_free(ospf
->new_table
);
832 ospf_rtrs_free(ospf
->old_rtrs
);
834 ospf_rtrs_free(ospf
->new_rtrs
);
835 if (ospf
->new_external_route
) {
836 if (!ospf
->gr_info
.prepare_in_progress
)
837 ospf_route_delete(ospf
, ospf
->new_external_route
);
838 ospf_route_table_free(ospf
->new_external_route
);
840 if (ospf
->old_external_route
) {
841 if (!ospf
->gr_info
.prepare_in_progress
)
842 ospf_route_delete(ospf
, ospf
->old_external_route
);
843 ospf_route_table_free(ospf
->old_external_route
);
845 if (ospf
->external_lsas
) {
846 ospf_ase_external_lsas_finish(ospf
->external_lsas
);
849 for (i
= ZEBRA_ROUTE_SYSTEM
; i
<= ZEBRA_ROUTE_MAX
; i
++) {
850 struct list
*ext_list
;
851 struct ospf_external
*ext
;
853 ext_list
= ospf
->external
[i
];
857 for (ALL_LIST_ELEMENTS(ext_list
, node
, nnode
, ext
)) {
858 if (ext
->external_info
)
859 for (rn
= route_top(ext
->external_info
); rn
;
860 rn
= route_next(rn
)) {
861 if (rn
->info
== NULL
)
864 XFREE(MTYPE_OSPF_EXTERNAL_INFO
,
867 route_unlock_node(rn
);
870 ospf_external_del(ospf
, i
, ext
->instance
);
874 ospf_distance_reset(ospf
);
875 route_table_finish(ospf
->distance_table
);
877 /* Release extrenal Aggregator table */
878 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
)) {
879 struct ospf_external_aggr_rt
*aggr
;
884 ospf_external_aggregator_free(aggr
);
886 route_unlock_node(rn
);
890 route_table_finish(ospf
->rt_aggr_tbl
);
893 list_delete(&ospf
->areas
);
894 list_delete(&ospf
->oi_write_q
);
896 /* Reset GR helper data structers */
897 ospf_gr_helper_instance_stop(ospf
);
900 stream_free(ospf
->ibuf
);
902 ospf
->max_multipath
= MULTIPATH_NUM
;
906 ospf_vrf_unlink(ospf
, vrf
);
908 XFREE(MTYPE_OSPF_TOP
, ospf
->name
);
909 XFREE(MTYPE_OSPF_TOP
, ospf
);
913 /* allocate new OSPF Area object */
914 struct ospf_area
*ospf_area_new(struct ospf
*ospf
, struct in_addr area_id
)
916 struct ospf_area
*new;
918 /* Allocate new config_network. */
919 new = XCALLOC(MTYPE_OSPF_AREA
, sizeof(struct ospf_area
));
923 new->area_id
= area_id
;
924 new->area_id_fmt
= OSPF_AREA_ID_FMT_DOTTEDQUAD
;
926 new->external_routing
= OSPF_AREA_DEFAULT
;
927 new->default_cost
= 1;
928 new->auth_type
= OSPF_AUTH_NULL
;
931 new->lsdb
= ospf_lsdb_new();
933 /* Self-originated LSAs initialize. */
934 new->router_lsa_self
= NULL
;
936 ospf_opaque_type10_lsa_init(new);
938 new->oiflist
= list_new();
939 new->ranges
= route_table_init();
941 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
)
942 ospf
->backbone
= new;
947 void ospf_area_lsdb_discard_delete(struct ospf_area
*area
)
949 struct route_node
*rn
;
950 struct ospf_lsa
*lsa
;
952 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
)
953 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
954 LSDB_LOOP (NETWORK_LSDB(area
), rn
, lsa
)
955 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
956 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
957 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
958 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
959 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
961 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
962 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
963 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
964 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
965 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
966 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
968 ospf_lsdb_delete_all(area
->lsdb
);
971 static void ospf_area_free(struct ospf_area
*area
)
973 ospf_opaque_type10_lsa_term(area
);
976 ospf_area_lsdb_discard_delete(area
);
978 ospf_lsdb_free(area
->lsdb
);
980 ospf_lsa_unlock(&area
->router_lsa_self
);
982 route_table_finish(area
->ranges
);
983 list_delete(&area
->oiflist
);
985 if (EXPORT_NAME(area
))
986 free(EXPORT_NAME(area
));
988 if (IMPORT_NAME(area
))
989 free(IMPORT_NAME(area
));
992 OSPF_TIMER_OFF(area
->t_stub_router
);
993 OSPF_TIMER_OFF(area
->t_opaque_lsa_self
);
995 if (OSPF_IS_AREA_BACKBONE(area
))
996 area
->ospf
->backbone
= NULL
;
998 XFREE(MTYPE_OSPF_AREA
, area
);
1001 void ospf_area_check_free(struct ospf
*ospf
, struct in_addr area_id
)
1003 struct ospf_area
*area
;
1005 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1006 if (area
&& listcount(area
->oiflist
) == 0 && area
->ranges
->top
== NULL
1007 && !ospf_vl_count(ospf
, area
)
1008 && area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
1009 && area
->external_routing
== OSPF_AREA_DEFAULT
1010 && area
->no_summary
== 0 && area
->default_cost
== 1
1011 && EXPORT_NAME(area
) == NULL
&& IMPORT_NAME(area
) == NULL
1012 && area
->auth_type
== OSPF_AUTH_NULL
) {
1013 listnode_delete(ospf
->areas
, area
);
1014 ospf_area_free(area
);
1018 struct ospf_area
*ospf_area_get(struct ospf
*ospf
, struct in_addr area_id
)
1020 struct ospf_area
*area
;
1022 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1024 area
= ospf_area_new(ospf
, area_id
);
1025 listnode_add_sort(ospf
->areas
, area
);
1026 ospf_check_abr_status(ospf
);
1027 if (ospf
->stub_router_admin_set
1028 == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
) {
1029 SET_FLAG(area
->stub_router_state
,
1030 OSPF_AREA_ADMIN_STUB_ROUTED
);
1037 struct ospf_area
*ospf_area_lookup_by_area_id(struct ospf
*ospf
,
1038 struct in_addr area_id
)
1040 struct ospf_area
*area
;
1041 struct listnode
*node
;
1043 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
1044 if (IPV4_ADDR_SAME(&area
->area_id
, &area_id
))
1050 void ospf_area_add_if(struct ospf_area
*area
, struct ospf_interface
*oi
)
1052 listnode_add(area
->oiflist
, oi
);
1055 void ospf_area_del_if(struct ospf_area
*area
, struct ospf_interface
*oi
)
1057 listnode_delete(area
->oiflist
, oi
);
1061 struct ospf_interface
*add_ospf_interface(struct connected
*co
,
1062 struct ospf_area
*area
)
1064 struct ospf_interface
*oi
;
1066 oi
= ospf_if_new(area
->ospf
, co
->ifp
, co
->address
);
1071 oi
->params
= ospf_lookup_if_params(co
->ifp
, oi
->address
->u
.prefix4
);
1072 oi
->output_cost
= ospf_if_get_output_cost(oi
);
1074 /* Relate ospf interface to ospf instance. */
1075 oi
->ospf
= area
->ospf
;
1077 /* update network type as interface flag */
1078 /* If network type is specified previously,
1079 skip network type setting. */
1080 oi
->type
= IF_DEF_PARAMS(co
->ifp
)->type
;
1081 oi
->ptp_dmvpn
= IF_DEF_PARAMS(co
->ifp
)->ptp_dmvpn
;
1083 /* Add pseudo neighbor. */
1084 ospf_nbr_self_reset(oi
, oi
->ospf
->router_id
);
1086 ospf_area_add_if(oi
->area
, oi
);
1088 /* if LDP-IGP Sync is configured globally inherit config */
1089 ospf_ldp_sync_if_init(oi
);
1092 * if router_id is not configured, dont bring up
1094 * ospf_router_id_update() will call ospf_if_update
1095 * whenever r-id is configured instead.
1097 if ((area
->ospf
->router_id
.s_addr
!= INADDR_ANY
)
1098 && if_is_operative(co
->ifp
))
1104 static void update_redistributed(struct ospf
*ospf
, int add_to_ospf
)
1106 struct route_node
*rn
;
1107 struct external_info
*ei
;
1108 struct ospf_external
*ext
;
1110 if (ospf_is_type_redistributed(ospf
, ZEBRA_ROUTE_CONNECT
, 0)) {
1111 ext
= ospf_external_lookup(ospf
, ZEBRA_ROUTE_CONNECT
, 0);
1112 if ((ext
) && EXTERNAL_INFO(ext
)) {
1113 for (rn
= route_top(EXTERNAL_INFO(ext
)); rn
;
1114 rn
= route_next(rn
)) {
1120 if (ospf_external_info_find_lsa(ospf
,
1122 if (!ospf_redistribute_check(
1124 ospf_external_lsa_flush(
1127 ei
->ifindex
/*, ei->nexthop */);
1129 if (!ospf_external_info_find_lsa(
1131 if (ospf_redistribute_check(
1133 ospf_external_lsa_originate(
1141 /* Config network statement related functions. */
1142 static struct ospf_network
*ospf_network_new(struct in_addr area_id
)
1144 struct ospf_network
*new;
1145 new = XCALLOC(MTYPE_OSPF_NETWORK
, sizeof(struct ospf_network
));
1147 new->area_id
= area_id
;
1148 new->area_id_fmt
= OSPF_AREA_ID_FMT_DOTTEDQUAD
;
1153 static void ospf_network_free(struct ospf
*ospf
, struct ospf_network
*network
)
1155 ospf_area_check_free(ospf
, network
->area_id
);
1156 ospf_schedule_abr_task(ospf
);
1157 XFREE(MTYPE_OSPF_NETWORK
, network
);
1160 int ospf_network_set(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1161 struct in_addr area_id
, int df
)
1163 struct ospf_network
*network
;
1164 struct ospf_area
*area
;
1165 struct route_node
*rn
;
1167 rn
= route_node_get(ospf
->networks
, (struct prefix
*)p
);
1170 route_unlock_node(rn
);
1172 if (IPV4_ADDR_SAME(&area_id
, &network
->area_id
)) {
1175 /* There is already same network statement. */
1180 rn
->info
= network
= ospf_network_new(area_id
);
1181 network
->area_id_fmt
= df
;
1182 area
= ospf_area_get(ospf
, area_id
);
1183 ospf_area_display_format_set(ospf
, area
, df
);
1185 /* Run network config now. */
1186 ospf_network_run((struct prefix
*)p
, area
);
1188 /* Update connected redistribute. */
1189 update_redistributed(ospf
, 1); /* interfaces possibly added */
1191 ospf_area_check_free(ospf
, area_id
);
1196 int ospf_network_unset(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1197 struct in_addr area_id
)
1199 struct route_node
*rn
;
1200 struct ospf_network
*network
;
1201 struct listnode
*node
, *nnode
;
1202 struct ospf_interface
*oi
;
1204 rn
= route_node_lookup(ospf
->networks
, (struct prefix
*)p
);
1209 route_unlock_node(rn
);
1210 if (!IPV4_ADDR_SAME(&area_id
, &network
->area_id
))
1213 ospf_network_free(ospf
, rn
->info
);
1215 route_unlock_node(rn
); /* initial reference */
1217 /* Find interfaces that are not configured already. */
1218 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
)) {
1220 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1223 ospf_network_run_subnet(ospf
, oi
->connected
, NULL
, NULL
);
1226 /* Update connected redistribute. */
1227 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1228 ospf_area_check_free(ospf
, area_id
);
1233 /* Ensure there's an OSPF instance, as "ip ospf area" enabled OSPF means
1234 * there might not be any 'router ospf' config.
1236 * Otherwise, doesn't do anything different to ospf_if_update for now
1238 void ospf_interface_area_set(struct ospf
*ospf
, struct interface
*ifp
)
1243 ospf_if_update(ospf
, ifp
);
1244 /* if_update does a update_redistributed */
1249 void ospf_interface_area_unset(struct ospf
*ospf
, struct interface
*ifp
)
1251 struct route_node
*rn_oi
;
1254 return; /* Ospf not ready yet */
1256 /* Find interfaces that may need to be removed. */
1257 for (rn_oi
= route_top(IF_OIFS(ifp
)); rn_oi
;
1258 rn_oi
= route_next(rn_oi
)) {
1259 struct ospf_interface
*oi
= NULL
;
1261 if ((oi
= rn_oi
->info
) == NULL
)
1264 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1267 ospf_network_run_subnet(ospf
, oi
->connected
, NULL
, NULL
);
1270 /* Update connected redistribute. */
1271 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1274 /* Check whether interface matches given network
1275 * returns: 1, true. 0, false
1277 static int ospf_network_match_iface(const struct connected
*co
,
1278 const struct prefix
*net
)
1280 /* new approach: more elegant and conceptually clean */
1281 return prefix_match_network_statement(net
, CONNECTED_PREFIX(co
));
1284 static void ospf_update_interface_area(struct connected
*co
,
1285 struct ospf_area
*area
)
1287 struct ospf_interface
*oi
= ospf_if_table_lookup(co
->ifp
, co
->address
);
1289 /* nothing to be done case */
1290 if (oi
&& oi
->area
== area
) {
1297 add_ospf_interface(co
, area
);
1300 /* Run OSPF for the given subnet, taking into account the following
1301 * possible sources of area configuration, in the given order of preference:
1303 * - Whether there is interface+address specific area configuration
1304 * - Whether there is a default area for the interface
1305 * - Whether there is an area given as a parameter.
1306 * - If no specific network prefix/area is supplied, whether there's
1307 * a matching network configured.
1309 static void ospf_network_run_subnet(struct ospf
*ospf
, struct connected
*co
,
1311 struct ospf_area
*given_area
)
1313 struct ospf_interface
*oi
;
1314 struct ospf_if_params
*params
;
1315 struct ospf_area
*area
= NULL
;
1316 struct route_node
*rn
;
1319 if (CHECK_FLAG(co
->flags
, ZEBRA_IFA_SECONDARY
))
1322 if (co
->address
->family
!= AF_INET
)
1325 /* Try determine the appropriate area for this interface + address
1326 * Start by checking interface config
1328 params
= ospf_lookup_if_params(co
->ifp
, co
->address
->u
.prefix4
);
1329 if (params
&& OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1330 area
= ospf_area_get(ospf
, params
->if_area
);
1332 params
= IF_DEF_PARAMS(co
->ifp
);
1333 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1334 area
= ospf_area_get(ospf
, params
->if_area
);
1337 /* If we've found an interface and/or addr specific area, then we're
1341 ospf_update_interface_area(co
, area
);
1345 /* Otherwise, only remaining possibility is a matching network statement
1348 assert(given_area
!= NULL
);
1350 /* Which either was supplied as a parameter.. (e.g. cause a new
1351 * network/area was just added)..
1353 if (p
->family
== co
->address
->family
1354 && ospf_network_match_iface(co
, p
))
1355 ospf_update_interface_area(co
, given_area
);
1360 /* Else we have to search the existing network/area config to see
1363 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
1364 if (rn
->info
!= NULL
&& ospf_network_match_iface(co
, &rn
->p
)) {
1365 struct ospf_network
*network
=
1366 (struct ospf_network
*)rn
->info
;
1367 area
= ospf_area_get(ospf
, network
->area_id
);
1368 ospf_update_interface_area(co
, area
);
1372 /* If the subnet isn't in any area, deconfigure */
1373 if (!configed
&& (oi
= ospf_if_table_lookup(co
->ifp
, co
->address
)))
1377 static void ospf_network_run_interface(struct ospf
*ospf
, struct interface
*ifp
,
1379 struct ospf_area
*given_area
)
1381 struct listnode
*cnode
;
1382 struct connected
*co
;
1384 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
1387 /* Network prefix without area is nonsensical */
1389 assert(given_area
!= NULL
);
1391 /* if interface prefix is match specified prefix,
1392 then create socket and join multicast group. */
1393 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, co
))
1394 ospf_network_run_subnet(ospf
, co
, p
, given_area
);
1397 static void ospf_network_run(struct prefix
*p
, struct ospf_area
*area
)
1399 struct vrf
*vrf
= vrf_lookup_by_id(area
->ospf
->vrf_id
);
1400 struct interface
*ifp
;
1402 /* Schedule Router ID Update. */
1403 if (area
->ospf
->router_id
.s_addr
== INADDR_ANY
)
1404 ospf_router_id_update(area
->ospf
);
1406 /* Get target interface. */
1407 FOR_ALL_INTERFACES (vrf
, ifp
)
1408 ospf_network_run_interface(area
->ospf
, ifp
, p
, area
);
1411 void ospf_ls_upd_queue_empty(struct ospf_interface
*oi
)
1413 struct route_node
*rn
;
1414 struct listnode
*node
, *nnode
;
1416 struct ospf_lsa
*lsa
;
1418 /* empty ls update queue */
1419 for (rn
= route_top(oi
->ls_upd_queue
); rn
; rn
= route_next(rn
))
1420 if ((lst
= (struct list
*)rn
->info
)) {
1421 for (ALL_LIST_ELEMENTS(lst
, node
, nnode
, lsa
))
1422 ospf_lsa_unlock(&lsa
); /* oi->ls_upd_queue */
1427 /* remove update event */
1428 thread_cancel(&oi
->t_ls_upd_event
);
1431 void ospf_if_update(struct ospf
*ospf
, struct interface
*ifp
)
1437 if (IS_DEBUG_OSPF_EVENT
)
1439 "%s: interface %s vrf %s(%u) ospf vrf %s vrf_id %u router_id %pI4",
1440 __func__
, ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
,
1441 ospf_vrf_id_to_name(ospf
->vrf_id
), ospf
->vrf_id
,
1444 /* OSPF must be ready. */
1445 if (!ospf_is_ready(ospf
))
1448 ospf_network_run_interface(ospf
, ifp
, NULL
, NULL
);
1450 /* Update connected redistribute. */
1451 update_redistributed(ospf
, 1);
1455 void ospf_remove_vls_through_area(struct ospf
*ospf
, struct ospf_area
*area
)
1457 struct listnode
*node
, *nnode
;
1458 struct ospf_vl_data
*vl_data
;
1460 for (ALL_LIST_ELEMENTS(ospf
->vlinks
, node
, nnode
, vl_data
))
1461 if (IPV4_ADDR_SAME(&vl_data
->vl_area_id
, &area
->area_id
))
1462 ospf_vl_delete(ospf
, vl_data
);
1466 static const struct message ospf_area_type_msg
[] = {
1467 {OSPF_AREA_DEFAULT
, "Default"},
1468 {OSPF_AREA_STUB
, "Stub"},
1469 {OSPF_AREA_NSSA
, "NSSA"},
1472 static void ospf_area_type_set(struct ospf_area
*area
, int type
)
1474 struct listnode
*node
;
1475 struct ospf_interface
*oi
;
1477 if (area
->external_routing
== type
) {
1478 if (IS_DEBUG_OSPF_EVENT
)
1479 zlog_debug("Area[%pI4]: Types are the same, ignored.",
1484 area
->external_routing
= type
;
1486 if (IS_DEBUG_OSPF_EVENT
)
1487 zlog_debug("Area[%pI4]: Configured as %s",
1489 lookup_msg(ospf_area_type_msg
, type
, NULL
));
1491 switch (area
->external_routing
) {
1492 case OSPF_AREA_DEFAULT
:
1493 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1494 if (oi
->nbr_self
!= NULL
) {
1495 UNSET_FLAG(oi
->nbr_self
->options
,
1497 SET_FLAG(oi
->nbr_self
->options
, OSPF_OPTION_E
);
1500 case OSPF_AREA_STUB
:
1501 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1502 if (oi
->nbr_self
!= NULL
) {
1503 if (IS_DEBUG_OSPF_EVENT
)
1505 "setting options on %s accordingly",
1507 UNSET_FLAG(oi
->nbr_self
->options
,
1509 UNSET_FLAG(oi
->nbr_self
->options
,
1511 if (IS_DEBUG_OSPF_EVENT
)
1512 zlog_debug("options set on %s: %x",
1513 IF_NAME(oi
), OPTIONS(oi
));
1516 case OSPF_AREA_NSSA
:
1517 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1518 if (oi
->nbr_self
!= NULL
) {
1520 "setting nssa options on %s accordingly",
1522 UNSET_FLAG(oi
->nbr_self
->options
,
1524 SET_FLAG(oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1525 zlog_debug("options set on %s: %x", IF_NAME(oi
),
1533 ospf_router_lsa_update_area(area
);
1534 ospf_schedule_abr_task(area
->ospf
);
1537 int ospf_area_shortcut_set(struct ospf
*ospf
, struct ospf_area
*area
, int mode
)
1539 if (area
->shortcut_configured
== mode
)
1542 area
->shortcut_configured
= mode
;
1543 ospf_router_lsa_update_area(area
);
1544 ospf_schedule_abr_task(ospf
);
1546 ospf_area_check_free(ospf
, area
->area_id
);
1551 int ospf_area_shortcut_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1553 area
->shortcut_configured
= OSPF_SHORTCUT_DEFAULT
;
1554 ospf_router_lsa_update_area(area
);
1555 ospf_area_check_free(ospf
, area
->area_id
);
1556 ospf_schedule_abr_task(ospf
);
1561 static int ospf_area_vlink_count(struct ospf
*ospf
, struct ospf_area
*area
)
1563 struct ospf_vl_data
*vl
;
1564 struct listnode
*node
;
1567 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl
))
1568 if (IPV4_ADDR_SAME(&vl
->vl_area_id
, &area
->area_id
))
1574 int ospf_area_display_format_set(struct ospf
*ospf
, struct ospf_area
*area
,
1577 area
->area_id_fmt
= df
;
1582 int ospf_area_stub_set(struct ospf
*ospf
, struct in_addr area_id
)
1584 struct ospf_area
*area
;
1586 area
= ospf_area_get(ospf
, area_id
);
1587 if (ospf_area_vlink_count(ospf
, area
))
1590 if (area
->external_routing
!= OSPF_AREA_STUB
)
1591 ospf_area_type_set(area
, OSPF_AREA_STUB
);
1596 int ospf_area_stub_unset(struct ospf
*ospf
, struct in_addr area_id
)
1598 struct ospf_area
*area
;
1600 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1604 if (area
->external_routing
== OSPF_AREA_STUB
)
1605 ospf_area_type_set(area
, OSPF_AREA_DEFAULT
);
1607 ospf_area_check_free(ospf
, area_id
);
1612 int ospf_area_no_summary_set(struct ospf
*ospf
, struct in_addr area_id
)
1614 struct ospf_area
*area
;
1616 area
= ospf_area_get(ospf
, area_id
);
1617 area
->no_summary
= 1;
1622 int ospf_area_no_summary_unset(struct ospf
*ospf
, struct in_addr area_id
)
1624 struct ospf_area
*area
;
1626 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1630 area
->no_summary
= 0;
1631 ospf_area_check_free(ospf
, area_id
);
1636 int ospf_area_nssa_no_summary_set(struct ospf
*ospf
, struct in_addr area_id
)
1638 struct ospf_area
*area
;
1640 area
= ospf_area_get(ospf
, area_id
);
1641 if (ospf_area_vlink_count(ospf
, area
))
1644 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1645 ospf_area_type_set(area
, OSPF_AREA_NSSA
);
1647 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1650 ospf_area_no_summary_set(ospf
, area_id
);
1655 int ospf_area_nssa_set(struct ospf
*ospf
, struct in_addr area_id
)
1657 struct ospf_area
*area
;
1659 area
= ospf_area_get(ospf
, area_id
);
1660 if (ospf_area_vlink_count(ospf
, area
))
1663 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1664 ospf_area_type_set(area
, OSPF_AREA_NSSA
);
1667 /* set NSSA area defaults */
1668 area
->no_summary
= 0;
1669 area
->suppress_fa
= 0;
1670 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1671 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1672 area
->NSSATranslatorStabilityInterval
=
1673 OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1678 int ospf_area_nssa_unset(struct ospf
*ospf
, struct in_addr area_id
, int argc
)
1680 struct ospf_area
*area
;
1682 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1686 /* argc < 5 -> 'no area x nssa' */
1687 if (argc
< 5 && area
->external_routing
== OSPF_AREA_NSSA
) {
1689 /* set NSSA area defaults */
1690 area
->no_summary
= 0;
1691 area
->suppress_fa
= 0;
1692 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1693 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1694 area
->NSSATranslatorStabilityInterval
=
1695 OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1696 ospf_area_type_set(area
, OSPF_AREA_DEFAULT
);
1698 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1699 OSPF_NSSA_ROLE_CANDIDATE
);
1702 ospf_area_check_free(ospf
, area_id
);
1707 int ospf_area_nssa_suppress_fa_set(struct ospf
*ospf
, struct in_addr area_id
)
1709 struct ospf_area
*area
;
1711 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1715 area
->suppress_fa
= 1;
1720 int ospf_area_nssa_suppress_fa_unset(struct ospf
*ospf
, struct in_addr area_id
)
1722 struct ospf_area
*area
;
1724 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1728 area
->suppress_fa
= 0;
1733 int ospf_area_nssa_translator_role_set(struct ospf
*ospf
,
1734 struct in_addr area_id
, int role
)
1736 struct ospf_area
*area
;
1738 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1742 if (role
!= area
->NSSATranslatorRole
) {
1743 if ((area
->NSSATranslatorRole
== OSPF_NSSA_ROLE_ALWAYS
)
1744 || (role
== OSPF_NSSA_ROLE_ALWAYS
)) {
1746 * if new role is OSPF_NSSA_ROLE_ALWAYS we need to set
1747 * Nt bit, if the role was OSPF_NSSA_ROLE_ALWAYS we need
1750 area
->NSSATranslatorRole
= role
;
1751 ospf_router_lsa_update_area(area
);
1753 area
->NSSATranslatorRole
= role
;
1759 int ospf_area_export_list_set(struct ospf
*ospf
, struct ospf_area
*area
,
1760 const char *list_name
)
1762 struct access_list
*list
;
1763 list
= access_list_lookup(AFI_IP
, list_name
);
1765 EXPORT_LIST(area
) = list
;
1767 if (EXPORT_NAME(area
))
1768 free(EXPORT_NAME(area
));
1770 EXPORT_NAME(area
) = strdup(list_name
);
1771 ospf_schedule_abr_task(ospf
);
1776 int ospf_area_export_list_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1779 EXPORT_LIST(area
) = 0;
1781 if (EXPORT_NAME(area
))
1782 free(EXPORT_NAME(area
));
1784 EXPORT_NAME(area
) = NULL
;
1786 ospf_area_check_free(ospf
, area
->area_id
);
1788 ospf_schedule_abr_task(ospf
);
1793 int ospf_area_import_list_set(struct ospf
*ospf
, struct ospf_area
*area
,
1796 struct access_list
*list
;
1797 list
= access_list_lookup(AFI_IP
, name
);
1799 IMPORT_LIST(area
) = list
;
1801 if (IMPORT_NAME(area
))
1802 free(IMPORT_NAME(area
));
1804 IMPORT_NAME(area
) = strdup(name
);
1805 ospf_schedule_abr_task(ospf
);
1810 int ospf_area_import_list_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1812 IMPORT_LIST(area
) = 0;
1814 if (IMPORT_NAME(area
))
1815 free(IMPORT_NAME(area
));
1817 IMPORT_NAME(area
) = NULL
;
1818 ospf_area_check_free(ospf
, area
->area_id
);
1820 ospf_schedule_abr_task(ospf
);
1825 int ospf_timers_refresh_set(struct ospf
*ospf
, int interval
)
1829 if (ospf
->lsa_refresh_interval
== interval
)
1832 time_left
= ospf
->lsa_refresh_interval
1833 - (monotime(NULL
) - ospf
->lsa_refresher_started
);
1835 if (time_left
> interval
) {
1836 OSPF_TIMER_OFF(ospf
->t_lsa_refresher
);
1837 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1838 interval
, &ospf
->t_lsa_refresher
);
1840 ospf
->lsa_refresh_interval
= interval
;
1845 int ospf_timers_refresh_unset(struct ospf
*ospf
)
1849 time_left
= ospf
->lsa_refresh_interval
1850 - (monotime(NULL
) - ospf
->lsa_refresher_started
);
1852 if (time_left
> OSPF_LSA_REFRESH_INTERVAL_DEFAULT
) {
1853 OSPF_TIMER_OFF(ospf
->t_lsa_refresher
);
1854 ospf
->t_lsa_refresher
= NULL
;
1855 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1856 OSPF_LSA_REFRESH_INTERVAL_DEFAULT
,
1857 &ospf
->t_lsa_refresher
);
1860 ospf
->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
1866 static struct ospf_nbr_nbma
*ospf_nbr_nbma_new(void)
1868 struct ospf_nbr_nbma
*nbr_nbma
;
1870 nbr_nbma
= XCALLOC(MTYPE_OSPF_NEIGHBOR_STATIC
,
1871 sizeof(struct ospf_nbr_nbma
));
1873 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1874 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1879 static void ospf_nbr_nbma_free(struct ospf_nbr_nbma
*nbr_nbma
)
1881 XFREE(MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
1884 static void ospf_nbr_nbma_delete(struct ospf
*ospf
,
1885 struct ospf_nbr_nbma
*nbr_nbma
)
1887 struct route_node
*rn
;
1888 struct prefix_ipv4 p
;
1891 p
.prefix
= nbr_nbma
->addr
;
1892 p
.prefixlen
= IPV4_MAX_BITLEN
;
1894 rn
= route_node_lookup(ospf
->nbr_nbma
, (struct prefix
*)&p
);
1896 ospf_nbr_nbma_free(rn
->info
);
1898 route_unlock_node(rn
);
1899 route_unlock_node(rn
);
1903 static void ospf_nbr_nbma_down(struct ospf_nbr_nbma
*nbr_nbma
)
1905 OSPF_TIMER_OFF(nbr_nbma
->t_poll
);
1907 if (nbr_nbma
->nbr
) {
1908 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
1909 OSPF_NSM_EVENT_EXECUTE(nbr_nbma
->nbr
, NSM_KillNbr
);
1913 listnode_delete(nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
1916 static void ospf_nbr_nbma_add(struct ospf_nbr_nbma
*nbr_nbma
,
1917 struct ospf_interface
*oi
)
1919 struct ospf_neighbor
*nbr
;
1920 struct route_node
*rn
;
1923 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1926 if (nbr_nbma
->nbr
!= NULL
)
1929 if (IPV4_ADDR_SAME(&oi
->nbr_self
->address
.u
.prefix4
, &nbr_nbma
->addr
))
1933 listnode_add(oi
->nbr_nbma
, nbr_nbma
);
1935 /* Get neighbor information from table. */
1937 p
.prefixlen
= IPV4_MAX_BITLEN
;
1938 p
.u
.prefix4
= nbr_nbma
->addr
;
1940 rn
= route_node_get(oi
->nbrs
, &p
);
1943 nbr
->nbr_nbma
= nbr_nbma
;
1944 nbr_nbma
->nbr
= nbr
;
1946 route_unlock_node(rn
);
1948 nbr
= rn
->info
= ospf_nbr_new(oi
);
1949 nbr
->state
= NSM_Down
;
1950 nbr
->src
= nbr_nbma
->addr
;
1951 nbr
->nbr_nbma
= nbr_nbma
;
1952 nbr
->priority
= nbr_nbma
->priority
;
1955 nbr_nbma
->nbr
= nbr
;
1957 /* Configure BFD if interface has it. */
1958 ospf_neighbor_bfd_apply(nbr
);
1960 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_Start
);
1964 void ospf_nbr_nbma_if_update(struct ospf
*ospf
, struct ospf_interface
*oi
)
1966 struct ospf_nbr_nbma
*nbr_nbma
;
1967 struct route_node
*rn
;
1968 struct prefix_ipv4 p
;
1970 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1973 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
1974 if ((nbr_nbma
= rn
->info
))
1975 if (nbr_nbma
->oi
== NULL
&& nbr_nbma
->nbr
== NULL
) {
1977 p
.prefix
= nbr_nbma
->addr
;
1978 p
.prefixlen
= IPV4_MAX_BITLEN
;
1980 if (prefix_match(oi
->address
,
1981 (struct prefix
*)&p
))
1982 ospf_nbr_nbma_add(nbr_nbma
, oi
);
1986 struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup(struct ospf
*ospf
,
1987 struct in_addr nbr_addr
)
1989 struct route_node
*rn
;
1990 struct prefix_ipv4 p
;
1993 p
.prefix
= nbr_addr
;
1994 p
.prefixlen
= IPV4_MAX_BITLEN
;
1996 rn
= route_node_lookup(ospf
->nbr_nbma
, (struct prefix
*)&p
);
1998 route_unlock_node(rn
);
2004 int ospf_nbr_nbma_set(struct ospf
*ospf
, struct in_addr nbr_addr
)
2006 struct ospf_nbr_nbma
*nbr_nbma
;
2007 struct ospf_interface
*oi
;
2008 struct prefix_ipv4 p
;
2009 struct route_node
*rn
;
2010 struct listnode
*node
;
2012 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2016 nbr_nbma
= ospf_nbr_nbma_new();
2017 nbr_nbma
->addr
= nbr_addr
;
2020 p
.prefix
= nbr_addr
;
2021 p
.prefixlen
= IPV4_MAX_BITLEN
;
2023 rn
= route_node_get(ospf
->nbr_nbma
, (struct prefix
*)&p
);
2025 route_unlock_node(rn
);
2026 rn
->info
= nbr_nbma
;
2028 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
2029 if (oi
->type
== OSPF_IFTYPE_NBMA
)
2030 if (prefix_match(oi
->address
, (struct prefix
*)&p
)) {
2031 ospf_nbr_nbma_add(nbr_nbma
, oi
);
2039 int ospf_nbr_nbma_unset(struct ospf
*ospf
, struct in_addr nbr_addr
)
2041 struct ospf_nbr_nbma
*nbr_nbma
;
2043 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2044 if (nbr_nbma
== NULL
)
2047 ospf_nbr_nbma_down(nbr_nbma
);
2048 ospf_nbr_nbma_delete(ospf
, nbr_nbma
);
2053 int ospf_nbr_nbma_priority_set(struct ospf
*ospf
, struct in_addr nbr_addr
,
2056 struct ospf_nbr_nbma
*nbr_nbma
;
2058 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2059 if (nbr_nbma
== NULL
)
2062 if (nbr_nbma
->priority
!= priority
)
2063 nbr_nbma
->priority
= priority
;
2068 int ospf_nbr_nbma_priority_unset(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
!= OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
2077 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2082 int ospf_nbr_nbma_poll_interval_set(struct ospf
*ospf
, struct in_addr nbr_addr
,
2083 unsigned int interval
)
2085 struct ospf_nbr_nbma
*nbr_nbma
;
2087 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2088 if (nbr_nbma
== NULL
)
2091 if (nbr_nbma
->v_poll
!= interval
) {
2092 nbr_nbma
->v_poll
= interval
;
2093 if (nbr_nbma
->oi
&& ospf_if_is_up(nbr_nbma
->oi
)) {
2094 OSPF_TIMER_OFF(nbr_nbma
->t_poll
);
2095 OSPF_POLL_TIMER_ON(nbr_nbma
->t_poll
, ospf_poll_timer
,
2103 int ospf_nbr_nbma_poll_interval_unset(struct ospf
*ospf
, struct in_addr addr
)
2105 struct ospf_nbr_nbma
*nbr_nbma
;
2107 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, addr
);
2108 if (nbr_nbma
== NULL
)
2111 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
2112 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
2117 void ospf_master_init(struct thread_master
*master
)
2119 memset(&ospf_master
, 0, sizeof(struct ospf_master
));
2122 om
->ospf
= list_new();
2123 om
->master
= master
;
2126 /* Link OSPF instance to VRF. */
2127 void ospf_vrf_link(struct ospf
*ospf
, struct vrf
*vrf
)
2129 ospf
->vrf_id
= vrf
->vrf_id
;
2130 if (vrf
->info
!= (void *)ospf
)
2131 vrf
->info
= (void *)ospf
;
2134 /* Unlink OSPF instance from VRF. */
2135 void ospf_vrf_unlink(struct ospf
*ospf
, struct vrf
*vrf
)
2137 if (vrf
->info
== (void *)ospf
)
2139 ospf
->vrf_id
= VRF_UNKNOWN
;
2142 /* This is hook function for vrf create called as part of vrf_init */
2143 static int ospf_vrf_new(struct vrf
*vrf
)
2145 if (IS_DEBUG_OSPF_EVENT
)
2146 zlog_debug("%s: VRF Created: %s(%u)", __func__
, vrf
->name
,
2152 /* This is hook function for vrf delete call as part of vrf_init */
2153 static int ospf_vrf_delete(struct vrf
*vrf
)
2155 if (IS_DEBUG_OSPF_EVENT
)
2156 zlog_debug("%s: VRF Deletion: %s(%u)", __func__
, vrf
->name
,
2162 static void ospf_set_redist_vrf_bitmaps(struct ospf
*ospf
, bool set
)
2165 struct list
*red_list
;
2167 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
2168 red_list
= ospf
->redist
[type
];
2171 if (IS_DEBUG_OSPF_EVENT
)
2173 "%s: setting redist vrf %d bitmap for type %d",
2174 __func__
, ospf
->vrf_id
, type
);
2176 vrf_bitmap_set(zclient
->redist
[AFI_IP
][type
],
2179 vrf_bitmap_unset(zclient
->redist
[AFI_IP
][type
],
2183 red_list
= ospf
->redist
[DEFAULT_ROUTE
];
2186 vrf_bitmap_set(zclient
->default_information
[AFI_IP
],
2189 vrf_bitmap_unset(zclient
->default_information
[AFI_IP
],
2194 /* Enable OSPF VRF instance */
2195 static int ospf_vrf_enable(struct vrf
*vrf
)
2197 struct ospf
*ospf
= NULL
;
2198 vrf_id_t old_vrf_id
;
2201 if (IS_DEBUG_OSPF_EVENT
)
2202 zlog_debug("%s: VRF %s id %u enabled", __func__
, vrf
->name
,
2205 ospf
= ospf_lookup_by_name(vrf
->name
);
2207 old_vrf_id
= ospf
->vrf_id
;
2208 /* We have instance configured, link to VRF and make it "up". */
2209 ospf_vrf_link(ospf
, vrf
);
2210 if (IS_DEBUG_OSPF_EVENT
)
2212 "%s: ospf linked to vrf %s vrf_id %u (old id %u)",
2213 __func__
, vrf
->name
, ospf
->vrf_id
, old_vrf_id
);
2215 if (old_vrf_id
!= ospf
->vrf_id
) {
2216 ospf_set_redist_vrf_bitmaps(ospf
, true);
2218 /* start zebra redist to us for new vrf */
2219 ospf_zebra_vrf_register(ospf
);
2221 ret
= ospf_sock_init(ospf
);
2222 if (ret
< 0 || ospf
->fd
<= 0)
2224 thread_add_read(master
, ospf_read
, ospf
, ospf
->fd
,
2226 ospf
->oi_running
= 1;
2227 ospf_router_id_update(ospf
);
2234 /* Disable OSPF VRF instance */
2235 static int ospf_vrf_disable(struct vrf
*vrf
)
2237 struct ospf
*ospf
= NULL
;
2238 vrf_id_t old_vrf_id
= VRF_UNKNOWN
;
2240 if (vrf
->vrf_id
== VRF_DEFAULT
)
2243 if (IS_DEBUG_OSPF_EVENT
)
2244 zlog_debug("%s: VRF %s id %d disabled.", __func__
, vrf
->name
,
2247 ospf
= ospf_lookup_by_name(vrf
->name
);
2249 old_vrf_id
= ospf
->vrf_id
;
2251 ospf_zebra_vrf_deregister(ospf
);
2253 ospf_set_redist_vrf_bitmaps(ospf
, false);
2255 /* We have instance configured, unlink
2256 * from VRF and make it "down".
2258 ospf_vrf_unlink(ospf
, vrf
);
2259 ospf
->oi_running
= 0;
2260 if (IS_DEBUG_OSPF_EVENT
)
2261 zlog_debug("%s: ospf old_vrf_id %d unlinked", __func__
,
2263 thread_cancel(&ospf
->t_read
);
2268 /* Note: This is a callback, the VRF will be deleted by the caller. */
2272 void ospf_vrf_init(void)
2274 vrf_init(ospf_vrf_new
, ospf_vrf_enable
, ospf_vrf_disable
,
2278 void ospf_vrf_terminate(void)
2283 const char *ospf_vrf_id_to_name(vrf_id_t vrf_id
)
2285 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
2287 return vrf
? vrf
->name
: "NIL";
2290 const char *ospf_get_name(const struct ospf
*ospf
)
2295 return VRF_DEFAULT_NAME
;