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"
64 #include "ospfd/ospf_apiserver.h"
67 DEFINE_QOBJ_TYPE(ospf
);
69 /* OSPF process wide configuration. */
70 static struct ospf_master ospf_master
;
72 /* OSPF process wide configuration pointer to export. */
73 struct ospf_master
*om
;
75 unsigned short ospf_instance
;
77 extern struct zclient
*zclient
;
80 static void ospf_remove_vls_through_area(struct ospf
*, struct ospf_area
*);
81 static void ospf_network_free(struct ospf
*, struct ospf_network
*);
82 static void ospf_area_free(struct ospf_area
*);
83 static void ospf_network_run(struct prefix
*, struct ospf_area
*);
84 static void ospf_network_run_interface(struct ospf
*, struct interface
*,
85 struct prefix
*, struct ospf_area
*);
86 static void ospf_network_run_subnet(struct ospf
*, struct connected
*,
87 struct prefix
*, struct ospf_area
*);
88 static int ospf_network_match_iface(const struct connected
*,
89 const struct prefix
*);
90 static void ospf_finish_final(struct ospf
*);
92 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
94 int p_spaces_compare_func(const struct p_space
*a
, const struct p_space
*b
)
96 if (a
->protected_resource
->type
== OSPF_TI_LFA_LINK_PROTECTION
97 && b
->protected_resource
->type
== OSPF_TI_LFA_LINK_PROTECTION
)
98 return (a
->protected_resource
->link
->link_id
.s_addr
99 - b
->protected_resource
->link
->link_id
.s_addr
);
101 if (a
->protected_resource
->type
== OSPF_TI_LFA_NODE_PROTECTION
102 && b
->protected_resource
->type
== OSPF_TI_LFA_NODE_PROTECTION
)
103 return (a
->protected_resource
->router_id
.s_addr
104 - b
->protected_resource
->router_id
.s_addr
);
106 /* This should not happen */
110 int q_spaces_compare_func(const struct q_space
*a
, const struct q_space
*b
)
112 return (a
->root
->id
.s_addr
- b
->root
->id
.s_addr
);
115 DECLARE_RBTREE_UNIQ(p_spaces
, struct p_space
, p_spaces_item
,
116 p_spaces_compare_func
);
118 void ospf_process_refresh_data(struct ospf
*ospf
, bool reset
)
120 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
121 struct in_addr router_id
, router_id_old
;
122 struct ospf_interface
*oi
;
123 struct interface
*ifp
;
124 struct listnode
*node
, *nnode
;
125 struct ospf_area
*area
;
126 bool rid_change
= false;
128 if (!ospf
->oi_running
) {
129 if (IS_DEBUG_OSPF_EVENT
)
131 "Router ospf not configured -- Router-ID update postponed");
135 if (IS_DEBUG_OSPF_EVENT
)
136 zlog_debug("Router-ID[OLD:%pI4]: Update",
139 router_id_old
= ospf
->router_id
;
141 /* Select the router ID based on these priorities:
142 1. Statically assigned router ID is always the first choice.
143 2. If there is no statically assigned router ID, then try to stick
144 with the most recent value, since changing router ID's is very
146 3. Last choice: just go with whatever the zebra daemon recommends.
148 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
149 router_id
= ospf
->router_id_static
;
150 else if (ospf
->router_id
.s_addr
!= INADDR_ANY
)
151 router_id
= ospf
->router_id
;
153 router_id
= ospf
->router_id_zebra
;
155 if (IS_DEBUG_OSPF_EVENT
)
156 zlog_debug("Router-ID[OLD:%pI4]: Update to %pI4",
157 &ospf
->router_id
, &router_id
);
159 rid_change
= !(IPV4_ADDR_SAME(&router_id_old
, &router_id
));
160 if (rid_change
|| (reset
)) {
161 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
162 /* Some nbrs are identified by router_id, these needs
163 * to be rebuilt. Possible optimization would be to do
164 * oi->nbr_self->router_id = router_id for
165 * !(virtual | ptop) links
167 ospf_nbr_self_reset(oi
, router_id
);
170 * If the old router id was not set, but now it
171 * is and the interface is operative and the
172 * state is ISM_Down we should kick the state
173 * machine as that we processed the interfaces
174 * based upon the network statement( or intf config )
175 * but could not start it at that time.
177 if (if_is_operative(oi
->ifp
) && oi
->state
== ISM_Down
178 && router_id_old
.s_addr
== INADDR_ANY
)
182 /* Flush (inline) all the self originated LSAs */
183 ospf_flush_self_originated_lsas_now(ospf
);
185 ospf
->router_id
= router_id
;
186 if (IS_DEBUG_OSPF_EVENT
)
187 zlog_debug("Router-ID[NEW:%pI4]: Update",
190 /* Flush (inline) all external LSAs which now match the new
192 need to adjust the OSPF_LSA_SELF flag, so the flush doesn't
194 asserts in ospf_refresher_unregister_lsa(). This step is
196 because the current frr code does look-up for
198 based on the self router-id alone but expects OSPF_LSA_SELF
202 struct route_node
*rn
;
203 struct ospf_lsa
*lsa
;
205 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
) {
206 /* AdvRouter and Router ID is the same. */
207 if (IPV4_ADDR_SAME(&lsa
->data
->adv_router
,
208 &ospf
->router_id
) && rid_change
) {
210 OSPF_LSA_SELF_CHECKED
);
211 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF
);
212 ospf_lsa_flush_schedule(ospf
, lsa
);
214 /* The above flush will send immediately
215 * So discard the LSA to originate new
217 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
220 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
221 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
223 ospf_lsdb_delete_all(ospf
->lsdb
);
226 /* Since the LSAs are deleted, need reset the aggr flag */
227 ospf_unset_all_aggr_flag(ospf
);
229 /* Delete the LSDB */
230 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
231 ospf_area_lsdb_discard_delete(area
);
233 /* update router-lsa's for each area */
234 ospf_router_lsa_update(ospf
);
236 /* update ospf_interface's */
237 FOR_ALL_INTERFACES (vrf
, ifp
) {
241 ospf_if_update(ospf
, ifp
);
244 ospf_external_lsa_rid_change(ospf
);
246 #ifdef SUPPORT_OSPF_API
247 ospf_apiserver_clients_notify_router_id_change(router_id
);
251 ospf
->inst_shutdown
= 0;
254 void ospf_router_id_update(struct ospf
*ospf
)
256 ospf_process_refresh_data(ospf
, false);
259 void ospf_process_reset(struct ospf
*ospf
)
261 ospf_process_refresh_data(ospf
, true);
264 void ospf_neighbor_reset(struct ospf
*ospf
, struct in_addr nbr_id
,
267 struct route_node
*rn
;
268 struct ospf_neighbor
*nbr
;
269 struct ospf_interface
*oi
;
270 struct listnode
*node
;
272 /* Clear only a particular nbr with nbr router id as nbr_id */
273 if (nbr_str
!= NULL
) {
274 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
275 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &nbr_id
);
277 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_KillNbr
);
282 /* send Neighbor event KillNbr to all associated neighbors. */
283 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
284 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
286 if (nbr
&& (nbr
!= oi
->nbr_self
))
287 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_KillNbr
);
292 /* For OSPF area sort by area id. */
293 static int ospf_area_id_cmp(struct ospf_area
*a1
, struct ospf_area
*a2
)
295 if (ntohl(a1
->area_id
.s_addr
) > ntohl(a2
->area_id
.s_addr
))
297 if (ntohl(a1
->area_id
.s_addr
) < ntohl(a2
->area_id
.s_addr
))
302 static void ospf_add(struct ospf
*ospf
)
304 listnode_add(om
->ospf
, ospf
);
307 static void ospf_delete(struct ospf
*ospf
)
309 listnode_delete(om
->ospf
, ospf
);
312 struct ospf
*ospf_new_alloc(unsigned short instance
, const char *name
)
315 struct vrf
*vrf
= NULL
;
317 struct ospf
*new = XCALLOC(MTYPE_OSPF_TOP
, sizeof(struct ospf
));
319 new->instance
= instance
;
320 new->router_id
.s_addr
= htonl(0);
321 new->router_id_static
.s_addr
= htonl(0);
323 vrf
= vrf_lookup_by_name(name
);
325 new->vrf_id
= vrf
->vrf_id
;
327 new->vrf_id
= VRF_UNKNOWN
;
329 /* Freed in ospf_finish_final */
330 new->name
= XSTRDUP(MTYPE_OSPF_TOP
, name
);
331 if (IS_DEBUG_OSPF_EVENT
)
333 "%s: Create new ospf instance with vrf_name %s vrf_id %u",
334 __func__
, name
, new->vrf_id
);
337 ospf_vrf_link(new, vrf
);
339 ospf_zebra_vrf_register(new);
341 new->abr_type
= OSPF_ABR_DEFAULT
;
342 new->oiflist
= list_new();
343 new->vlinks
= list_new();
344 new->areas
= list_new();
345 new->areas
->cmp
= (int (*)(void *, void *))ospf_area_id_cmp
;
346 new->networks
= route_table_init();
347 new->nbr_nbma
= route_table_init();
349 new->lsdb
= ospf_lsdb_new();
351 new->default_originate
= DEFAULT_ORIGINATE_NONE
;
353 new->passive_interface_default
= OSPF_IF_ACTIVE
;
355 new->new_external_route
= route_table_init();
356 new->old_external_route
= route_table_init();
357 new->external_lsas
= route_table_init();
359 new->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
360 new->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
361 new->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
363 /* Distribute parameter init. */
364 for (i
= 0; i
<= ZEBRA_ROUTE_MAX
; i
++) {
367 new->default_metric
= -1;
368 new->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
371 new->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
372 new->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
374 /* SPF timer value init. */
375 new->spf_delay
= OSPF_SPF_DELAY_DEFAULT
;
376 new->spf_holdtime
= OSPF_SPF_HOLDTIME_DEFAULT
;
377 new->spf_max_holdtime
= OSPF_SPF_MAX_HOLDTIME_DEFAULT
;
378 new->spf_hold_multiplier
= 1;
381 new->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
382 new->maxage_lsa
= route_table_init();
383 new->t_maxage_walker
= NULL
;
384 thread_add_timer(master
, ospf_lsa_maxage_walker
, new,
385 OSPF_LSA_MAXAGE_CHECK_INTERVAL
, &new->t_maxage_walker
);
387 /* Max paths initialization */
388 new->max_multipath
= MULTIPATH_NUM
;
390 /* Distance table init. */
391 new->distance_table
= route_table_init();
393 new->lsa_refresh_queue
.index
= 0;
394 new->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
395 new->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
396 new->t_lsa_refresher
= NULL
;
397 thread_add_timer(master
, ospf_lsa_refresh_walker
, new,
398 new->lsa_refresh_interval
, &new->t_lsa_refresher
);
399 new->lsa_refresher_started
= monotime(NULL
);
401 new->ibuf
= stream_new(OSPF_MAX_PACKET_SIZE
+ 1);
404 new->oi_write_q
= list_new();
405 new->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
407 new->proactive_arp
= OSPF_PROACTIVE_ARP_DEFAULT
;
409 ospf_gr_helper_instance_init(new);
411 ospf_asbr_external_aggregator_init(new);
413 ospf_opaque_type11_lsa_init(new);
422 /* Allocate new ospf structure. */
423 static struct ospf
*ospf_new(unsigned short instance
, const char *name
)
427 new = ospf_new_alloc(instance
, name
);
430 if (new->vrf_id
== VRF_UNKNOWN
)
433 if ((ospf_sock_init(new)) < 0) {
434 flog_err(EC_LIB_SOCKET
,
435 "%s: ospf_sock_init is unable to open a socket",
440 thread_add_read(master
, ospf_read
, new, new->fd
, &new->t_read
);
443 ospf_router_id_update(new);
446 * Read from non-volatile memory whether this instance is performing a
447 * graceful restart or not.
449 ospf_gr_nvm_read(new);
454 struct ospf
*ospf_lookup_instance(unsigned short instance
)
457 struct listnode
*node
, *nnode
;
459 if (listcount(om
->ospf
) == 0)
462 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
463 if ((ospf
->instance
== 0 && instance
== 0)
464 || (ospf
->instance
&& instance
465 && ospf
->instance
== instance
))
471 static int ospf_is_ready(struct ospf
*ospf
)
473 /* OSPF must be on and Router-ID must be configured. */
474 if (!ospf
|| ospf
->router_id
.s_addr
== INADDR_ANY
)
480 struct ospf
*ospf_lookup_by_inst_name(unsigned short instance
, const char *name
)
482 struct ospf
*ospf
= NULL
;
483 struct listnode
*node
, *nnode
;
485 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
)) {
486 if ((ospf
->instance
== instance
)
487 && ((ospf
->name
== NULL
&& name
== NULL
)
488 || (ospf
->name
&& name
489 && strcmp(ospf
->name
, name
) == 0)))
495 struct ospf
*ospf_lookup(unsigned short instance
, const char *name
)
500 ospf
= ospf_lookup_instance(instance
);
502 ospf
= ospf_lookup_by_inst_name(instance
, name
);
508 struct ospf
*ospf_get(unsigned short instance
, const char *name
, bool *created
)
512 ospf
= ospf_lookup(instance
, name
);
514 *created
= (ospf
== NULL
);
516 ospf
= ospf_new(instance
, name
);
521 struct ospf
*ospf_lookup_by_vrf_id(vrf_id_t vrf_id
)
523 struct vrf
*vrf
= NULL
;
525 vrf
= vrf_lookup_by_id(vrf_id
);
528 return (vrf
->info
) ? (struct ospf
*)vrf
->info
: NULL
;
531 uint32_t ospf_count_area_params(struct ospf
*ospf
)
534 struct interface
*ifp
;
537 if (ospf
->vrf_id
!= VRF_UNKNOWN
) {
538 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
540 FOR_ALL_INTERFACES (vrf
, ifp
) {
541 count
+= ospf_if_count_area_params(ifp
);
548 /* It should only be used when processing incoming info update from zebra.
549 * Other situations, it is not sufficient to lookup the ospf instance by
550 * vrf_name only without using the instance number.
552 static struct ospf
*ospf_lookup_by_name(const char *vrf_name
)
554 struct ospf
*ospf
= NULL
;
555 struct listnode
*node
, *nnode
;
557 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
558 if ((ospf
->name
== NULL
&& vrf_name
== NULL
)
559 || (ospf
->name
&& vrf_name
560 && strcmp(ospf
->name
, vrf_name
) == 0))
565 /* Handle the second half of deferred shutdown. This is called either
566 * from the deferred-shutdown timer thread, or directly through
567 * ospf_deferred_shutdown_check.
569 * Function is to cleanup G-R state, if required then call ospf_finish_final
570 * to complete shutdown of this ospf instance. Possibly exit if the
571 * whole process is being shutdown and this was the last OSPF instance.
573 static void ospf_deferred_shutdown_finish(struct ospf
*ospf
)
575 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
576 THREAD_OFF(ospf
->t_deferred_shutdown
);
578 ospf_finish_final(ospf
);
580 /* *ospf is now invalid */
582 /* ospfd being shut-down? If so, was this the last ospf instance? */
583 if (CHECK_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
)
584 && (listcount(om
->ospf
) == 0)) {
592 /* Timer thread for G-R */
593 static void ospf_deferred_shutdown_timer(struct thread
*t
)
595 struct ospf
*ospf
= THREAD_ARG(t
);
597 ospf_deferred_shutdown_finish(ospf
);
600 /* Check whether deferred-shutdown must be scheduled, otherwise call
601 * down directly into second-half of instance shutdown.
603 static void ospf_deferred_shutdown_check(struct ospf
*ospf
)
605 unsigned long timeout
;
607 struct ospf_area
*area
;
609 /* deferred shutdown already running? */
610 if (ospf
->t_deferred_shutdown
)
613 /* Should we try push out max-metric LSAs? */
614 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
) {
615 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
616 SET_FLAG(area
->stub_router_state
,
617 OSPF_AREA_ADMIN_STUB_ROUTED
);
619 if (!CHECK_FLAG(area
->stub_router_state
,
620 OSPF_AREA_IS_STUB_ROUTED
))
621 ospf_router_lsa_update_area(area
);
623 timeout
= ospf
->stub_router_shutdown_time
;
625 /* No timer needed */
626 ospf_deferred_shutdown_finish(ospf
);
630 OSPF_TIMER_ON(ospf
->t_deferred_shutdown
, ospf_deferred_shutdown_timer
,
635 /* Shut down the entire process */
636 void ospf_terminate(void)
639 struct listnode
*node
, *nnode
;
641 /* shutdown already in progress */
642 if (CHECK_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
))
645 SET_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
);
647 /* Skip some steps if OSPF not actually running */
648 if (listcount(om
->ospf
) == 0)
651 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
655 ospf_gr_helper_stop();
657 /* Cleanup route maps */
660 /* reverse prefix_list_init */
661 prefix_list_add_hook(NULL
);
662 prefix_list_delete_hook(NULL
);
665 /* Cleanup vrf info */
666 ospf_vrf_terminate();
668 /* Deliberately go back up, hopefully to thread scheduler, as
669 * One or more ospf_finish()'s may have deferred shutdown to a timer
672 zclient_stop(zclient
);
673 zclient_free(zclient
);
679 void ospf_finish(struct ospf
*ospf
)
681 /* let deferred shutdown decide */
682 ospf_deferred_shutdown_check(ospf
);
684 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
685 * deferred to expiry of G-S timer thread. Return back up, hopefully
686 * to thread scheduler.
691 /* Final cleanup of ospf instance */
692 static void ospf_finish_final(struct ospf
*ospf
)
694 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
695 struct route_node
*rn
;
696 struct ospf_nbr_nbma
*nbr_nbma
;
697 struct ospf_lsa
*lsa
;
698 struct ospf_interface
*oi
;
699 struct ospf_area
*area
;
700 struct ospf_vl_data
*vl_data
;
701 struct listnode
*node
, *nnode
;
702 struct ospf_redist
*red
;
707 ospf_opaque_type11_lsa_term(ospf
);
709 ospf_opaque_finish();
711 if (!ospf
->gr_info
.prepare_in_progress
)
712 ospf_flush_self_originated_lsas_now(ospf
);
714 /* Unregister redistribution */
715 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
716 struct list
*red_list
;
718 red_list
= ospf
->redist
[i
];
722 for (ALL_LIST_ELEMENTS(red_list
, node
, nnode
, red
)) {
723 ospf_redistribute_unset(ospf
, i
, red
->instance
);
724 ospf_redist_del(ospf
, i
, red
->instance
);
727 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
729 ospf_routemap_unset(red
);
730 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
731 ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
, 0, 0);
734 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
735 ospf_remove_vls_through_area(ospf
, area
);
737 for (ALL_LIST_ELEMENTS(ospf
->vlinks
, node
, nnode
, vl_data
))
738 ospf_vl_delete(ospf
, vl_data
);
740 list_delete(&ospf
->vlinks
);
742 /* shutdown LDP-Sync */
743 if (ospf
->vrf_id
== VRF_DEFAULT
)
744 ospf_ldp_sync_gbl_exit(ospf
, true);
746 /* Reset interface. */
747 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
749 list_delete(&ospf
->oiflist
);
750 ospf
->oi_running
= 0;
752 /* De-Register VRF */
753 ospf_zebra_vrf_deregister(ospf
);
755 /* Clear static neighbors */
756 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
757 if ((nbr_nbma
= rn
->info
)) {
758 THREAD_OFF(nbr_nbma
->t_poll
);
761 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
762 nbr_nbma
->nbr
= NULL
;
766 listnode_delete(nbr_nbma
->oi
->nbr_nbma
,
771 XFREE(MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
774 route_table_finish(ospf
->nbr_nbma
);
776 /* Clear networks and Areas. */
777 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
778 struct ospf_network
*network
;
780 if ((network
= rn
->info
) != NULL
) {
781 ospf_network_free(ospf
, network
);
783 route_unlock_node(rn
);
786 route_table_finish(ospf
->networks
);
788 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
789 listnode_delete(ospf
->areas
, area
);
790 ospf_area_free(area
);
793 /* Cancel all timers. */
794 THREAD_OFF(ospf
->t_read
);
795 THREAD_OFF(ospf
->t_write
);
796 THREAD_OFF(ospf
->t_spf_calc
);
797 THREAD_OFF(ospf
->t_ase_calc
);
798 THREAD_OFF(ospf
->t_orr_calc
);
799 THREAD_OFF(ospf
->t_maxage
);
800 THREAD_OFF(ospf
->t_maxage_walker
);
801 THREAD_OFF(ospf
->t_abr_task
);
802 THREAD_OFF(ospf
->t_asbr_check
);
803 THREAD_OFF(ospf
->t_asbr_nssa_redist_update
);
804 THREAD_OFF(ospf
->t_distribute_update
);
805 THREAD_OFF(ospf
->t_lsa_refresher
);
806 THREAD_OFF(ospf
->t_opaque_lsa_self
);
807 THREAD_OFF(ospf
->t_sr_update
);
808 THREAD_OFF(ospf
->t_default_routemap_timer
);
809 THREAD_OFF(ospf
->t_external_aggr
);
810 THREAD_OFF(ospf
->gr_info
.t_grace_period
);
812 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
813 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
814 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
815 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
817 ospf_lsdb_delete_all(ospf
->lsdb
);
818 ospf_lsdb_free(ospf
->lsdb
);
820 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
821 if ((lsa
= rn
->info
) != NULL
) {
822 ospf_lsa_unlock(&lsa
);
824 route_unlock_node(rn
);
827 route_table_finish(ospf
->maxage_lsa
);
830 ospf_route_table_free(ospf
->old_table
);
831 if (ospf
->new_table
) {
832 if (!ospf
->gr_info
.prepare_in_progress
)
833 ospf_route_delete(ospf
, ospf
->new_table
);
834 ospf_route_table_free(ospf
->new_table
);
837 ospf_rtrs_free(ospf
->old_rtrs
);
839 ospf_rtrs_free(ospf
->new_rtrs
);
840 if (ospf
->new_external_route
) {
841 if (!ospf
->gr_info
.prepare_in_progress
)
842 ospf_route_delete(ospf
, ospf
->new_external_route
);
843 ospf_route_table_free(ospf
->new_external_route
);
845 if (ospf
->old_external_route
) {
846 if (!ospf
->gr_info
.prepare_in_progress
)
847 ospf_route_delete(ospf
, ospf
->old_external_route
);
848 ospf_route_table_free(ospf
->old_external_route
);
850 if (ospf
->external_lsas
) {
851 ospf_ase_external_lsas_finish(ospf
->external_lsas
);
854 for (i
= ZEBRA_ROUTE_SYSTEM
; i
<= ZEBRA_ROUTE_MAX
; i
++) {
855 struct list
*ext_list
;
856 struct ospf_external
*ext
;
858 ext_list
= ospf
->external
[i
];
862 for (ALL_LIST_ELEMENTS(ext_list
, node
, nnode
, ext
)) {
863 if (ext
->external_info
)
864 for (rn
= route_top(ext
->external_info
); rn
;
865 rn
= route_next(rn
)) {
866 if (rn
->info
== NULL
)
869 XFREE(MTYPE_OSPF_EXTERNAL_INFO
,
872 route_unlock_node(rn
);
875 ospf_external_del(ospf
, i
, ext
->instance
);
879 ospf_distance_reset(ospf
);
880 route_table_finish(ospf
->distance_table
);
882 /* Release extrenal Aggregator table */
883 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
)) {
884 struct ospf_external_aggr_rt
*aggr
;
889 ospf_external_aggregator_free(aggr
);
891 route_unlock_node(rn
);
895 route_table_finish(ospf
->rt_aggr_tbl
);
898 list_delete(&ospf
->areas
);
899 list_delete(&ospf
->oi_write_q
);
901 /* Reset GR helper data structers */
902 ospf_gr_helper_instance_stop(ospf
);
905 stream_free(ospf
->ibuf
);
907 ospf
->max_multipath
= MULTIPATH_NUM
;
911 ospf_vrf_unlink(ospf
, vrf
);
913 XFREE(MTYPE_OSPF_TOP
, ospf
->name
);
914 XFREE(MTYPE_OSPF_TOP
, ospf
);
918 /* allocate new OSPF Area object */
919 struct ospf_area
*ospf_area_new(struct ospf
*ospf
, struct in_addr area_id
)
921 struct ospf_area
*new;
923 /* Allocate new config_network. */
924 new = XCALLOC(MTYPE_OSPF_AREA
, sizeof(struct ospf_area
));
928 new->area_id
= area_id
;
929 new->area_id_fmt
= OSPF_AREA_ID_FMT_DOTTEDQUAD
;
931 new->external_routing
= OSPF_AREA_DEFAULT
;
932 new->default_cost
= 1;
933 new->auth_type
= OSPF_AUTH_NULL
;
936 new->lsdb
= ospf_lsdb_new();
938 /* Self-originated LSAs initialize. */
939 new->router_lsa_self
= NULL
;
941 ospf_opaque_type10_lsa_init(new);
943 new->oiflist
= list_new();
944 new->ranges
= route_table_init();
946 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
)
947 ospf
->backbone
= new;
952 void ospf_area_lsdb_discard_delete(struct ospf_area
*area
)
954 struct route_node
*rn
;
955 struct ospf_lsa
*lsa
;
957 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
)
958 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
959 LSDB_LOOP (NETWORK_LSDB(area
), rn
, lsa
)
960 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
961 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
962 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
963 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
964 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
966 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
967 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
968 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
969 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
970 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
971 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
973 ospf_lsdb_delete_all(area
->lsdb
);
976 static void ospf_area_free(struct ospf_area
*area
)
978 ospf_opaque_type10_lsa_term(area
);
981 ospf_area_lsdb_discard_delete(area
);
983 ospf_lsdb_free(area
->lsdb
);
985 ospf_lsa_unlock(&area
->router_lsa_self
);
987 route_table_finish(area
->ranges
);
988 list_delete(&area
->oiflist
);
990 if (EXPORT_NAME(area
))
991 free(EXPORT_NAME(area
));
993 if (IMPORT_NAME(area
))
994 free(IMPORT_NAME(area
));
997 THREAD_OFF(area
->t_stub_router
);
998 THREAD_OFF(area
->t_opaque_lsa_self
);
1000 if (OSPF_IS_AREA_BACKBONE(area
))
1001 area
->ospf
->backbone
= NULL
;
1003 XFREE(MTYPE_OSPF_AREA
, area
);
1006 void ospf_area_check_free(struct ospf
*ospf
, struct in_addr area_id
)
1008 struct ospf_area
*area
;
1010 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1011 if (area
&& listcount(area
->oiflist
) == 0 && area
->ranges
->top
== NULL
1012 && !ospf_vl_count(ospf
, area
)
1013 && area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
1014 && area
->external_routing
== OSPF_AREA_DEFAULT
1015 && area
->no_summary
== 0 && area
->default_cost
== 1
1016 && EXPORT_NAME(area
) == NULL
&& IMPORT_NAME(area
) == NULL
1017 && area
->auth_type
== OSPF_AUTH_NULL
) {
1018 listnode_delete(ospf
->areas
, area
);
1019 ospf_area_free(area
);
1023 struct ospf_area
*ospf_area_get(struct ospf
*ospf
, struct in_addr area_id
)
1025 struct ospf_area
*area
;
1027 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1029 area
= ospf_area_new(ospf
, area_id
);
1030 listnode_add_sort(ospf
->areas
, area
);
1031 ospf_check_abr_status(ospf
);
1032 if (ospf
->stub_router_admin_set
1033 == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
) {
1034 SET_FLAG(area
->stub_router_state
,
1035 OSPF_AREA_ADMIN_STUB_ROUTED
);
1042 struct ospf_area
*ospf_area_lookup_by_area_id(struct ospf
*ospf
,
1043 struct in_addr area_id
)
1045 struct ospf_area
*area
;
1046 struct listnode
*node
;
1048 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
1049 if (IPV4_ADDR_SAME(&area
->area_id
, &area_id
))
1055 void ospf_area_add_if(struct ospf_area
*area
, struct ospf_interface
*oi
)
1057 listnode_add(area
->oiflist
, oi
);
1060 void ospf_area_del_if(struct ospf_area
*area
, struct ospf_interface
*oi
)
1062 listnode_delete(area
->oiflist
, oi
);
1066 struct ospf_interface
*add_ospf_interface(struct connected
*co
,
1067 struct ospf_area
*area
)
1069 struct ospf_interface
*oi
;
1071 oi
= ospf_if_new(area
->ospf
, co
->ifp
, co
->address
);
1076 oi
->params
= ospf_lookup_if_params(co
->ifp
, oi
->address
->u
.prefix4
);
1077 oi
->output_cost
= ospf_if_get_output_cost(oi
);
1079 /* Relate ospf interface to ospf instance. */
1080 oi
->ospf
= area
->ospf
;
1082 /* update network type as interface flag */
1083 /* If network type is specified previously,
1084 skip network type setting. */
1085 oi
->type
= IF_DEF_PARAMS(co
->ifp
)->type
;
1086 oi
->ptp_dmvpn
= IF_DEF_PARAMS(co
->ifp
)->ptp_dmvpn
;
1088 /* Add pseudo neighbor. */
1089 ospf_nbr_self_reset(oi
, oi
->ospf
->router_id
);
1091 ospf_area_add_if(oi
->area
, oi
);
1093 /* if LDP-IGP Sync is configured globally inherit config */
1094 ospf_ldp_sync_if_init(oi
);
1097 * if router_id is not configured, don't bring up
1099 * ospf_router_id_update() will call ospf_if_update
1100 * whenever r-id is configured instead.
1102 if ((area
->ospf
->router_id
.s_addr
!= INADDR_ANY
)
1103 && if_is_operative(co
->ifp
))
1109 static void update_redistributed(struct ospf
*ospf
, int add_to_ospf
)
1111 struct route_node
*rn
;
1112 struct external_info
*ei
;
1113 struct ospf_external
*ext
;
1115 if (ospf_is_type_redistributed(ospf
, ZEBRA_ROUTE_CONNECT
, 0)) {
1116 ext
= ospf_external_lookup(ospf
, ZEBRA_ROUTE_CONNECT
, 0);
1117 if ((ext
) && EXTERNAL_INFO(ext
)) {
1118 for (rn
= route_top(EXTERNAL_INFO(ext
)); rn
;
1119 rn
= route_next(rn
)) {
1125 if (ospf_external_info_find_lsa(ospf
,
1127 if (!ospf_redistribute_check(
1129 ospf_external_lsa_flush(
1132 ei
->ifindex
/*, ei->nexthop */);
1134 if (!ospf_external_info_find_lsa(
1136 if (ospf_redistribute_check(
1138 ospf_external_lsa_originate(
1146 /* Config network statement related functions. */
1147 static struct ospf_network
*ospf_network_new(struct in_addr area_id
)
1149 struct ospf_network
*new;
1150 new = XCALLOC(MTYPE_OSPF_NETWORK
, sizeof(struct ospf_network
));
1152 new->area_id
= area_id
;
1153 new->area_id_fmt
= OSPF_AREA_ID_FMT_DOTTEDQUAD
;
1158 static void ospf_network_free(struct ospf
*ospf
, struct ospf_network
*network
)
1160 ospf_area_check_free(ospf
, network
->area_id
);
1161 ospf_schedule_abr_task(ospf
);
1162 XFREE(MTYPE_OSPF_NETWORK
, network
);
1165 int ospf_network_set(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1166 struct in_addr area_id
, int df
)
1168 struct ospf_network
*network
;
1169 struct ospf_area
*area
;
1170 struct route_node
*rn
;
1172 rn
= route_node_get(ospf
->networks
, (struct prefix
*)p
);
1175 route_unlock_node(rn
);
1177 if (IPV4_ADDR_SAME(&area_id
, &network
->area_id
)) {
1180 /* There is already same network statement. */
1185 rn
->info
= network
= ospf_network_new(area_id
);
1186 network
->area_id_fmt
= df
;
1187 area
= ospf_area_get(ospf
, area_id
);
1188 ospf_area_display_format_set(ospf
, area
, df
);
1190 /* Run network config now. */
1191 ospf_network_run((struct prefix
*)p
, area
);
1193 /* Update connected redistribute. */
1194 update_redistributed(ospf
, 1); /* interfaces possibly added */
1196 ospf_area_check_free(ospf
, area_id
);
1201 int ospf_network_unset(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1202 struct in_addr area_id
)
1204 struct route_node
*rn
;
1205 struct ospf_network
*network
;
1206 struct listnode
*node
, *nnode
;
1207 struct ospf_interface
*oi
;
1209 rn
= route_node_lookup(ospf
->networks
, (struct prefix
*)p
);
1214 route_unlock_node(rn
);
1215 if (!IPV4_ADDR_SAME(&area_id
, &network
->area_id
))
1218 ospf_network_free(ospf
, rn
->info
);
1220 route_unlock_node(rn
); /* initial reference */
1222 /* Find interfaces that are not configured already. */
1223 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
)) {
1225 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1228 ospf_network_run_subnet(ospf
, oi
->connected
, NULL
, NULL
);
1231 /* Update connected redistribute. */
1232 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1233 ospf_area_check_free(ospf
, area_id
);
1238 /* Ensure there's an OSPF instance, as "ip ospf area" enabled OSPF means
1239 * there might not be any 'router ospf' config.
1241 * Otherwise, doesn't do anything different to ospf_if_update for now
1243 void ospf_interface_area_set(struct ospf
*ospf
, struct interface
*ifp
)
1248 ospf_if_update(ospf
, ifp
);
1249 /* if_update does a update_redistributed */
1254 void ospf_interface_area_unset(struct ospf
*ospf
, struct interface
*ifp
)
1256 struct route_node
*rn_oi
;
1259 return; /* Ospf not ready yet */
1261 /* Find interfaces that may need to be removed. */
1262 for (rn_oi
= route_top(IF_OIFS(ifp
)); rn_oi
;
1263 rn_oi
= route_next(rn_oi
)) {
1264 struct ospf_interface
*oi
= NULL
;
1266 if ((oi
= rn_oi
->info
) == NULL
)
1269 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1272 ospf_network_run_subnet(ospf
, oi
->connected
, NULL
, NULL
);
1275 /* Update connected redistribute. */
1276 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1279 /* Check whether interface matches given network
1280 * returns: 1, true. 0, false
1282 static int ospf_network_match_iface(const struct connected
*co
,
1283 const struct prefix
*net
)
1285 /* new approach: more elegant and conceptually clean */
1286 return prefix_match_network_statement(net
, CONNECTED_PREFIX(co
));
1289 static void ospf_update_interface_area(struct connected
*co
,
1290 struct ospf_area
*area
)
1292 struct ospf_interface
*oi
= ospf_if_table_lookup(co
->ifp
, co
->address
);
1294 /* nothing to be done case */
1295 if (oi
&& oi
->area
== area
) {
1302 add_ospf_interface(co
, area
);
1305 /* Run OSPF for the given subnet, taking into account the following
1306 * possible sources of area configuration, in the given order of preference:
1308 * - Whether there is interface+address specific area configuration
1309 * - Whether there is a default area for the interface
1310 * - Whether there is an area given as a parameter.
1311 * - If no specific network prefix/area is supplied, whether there's
1312 * a matching network configured.
1314 static void ospf_network_run_subnet(struct ospf
*ospf
, struct connected
*co
,
1316 struct ospf_area
*given_area
)
1318 struct ospf_interface
*oi
;
1319 struct ospf_if_params
*params
;
1320 struct ospf_area
*area
= NULL
;
1321 struct route_node
*rn
;
1324 if (CHECK_FLAG(co
->flags
, ZEBRA_IFA_SECONDARY
))
1327 if (co
->address
->family
!= AF_INET
)
1330 /* Try determine the appropriate area for this interface + address
1331 * Start by checking interface config
1333 params
= ospf_lookup_if_params(co
->ifp
, co
->address
->u
.prefix4
);
1334 if (params
&& OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1335 area
= ospf_area_get(ospf
, params
->if_area
);
1337 params
= IF_DEF_PARAMS(co
->ifp
);
1338 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1339 area
= ospf_area_get(ospf
, params
->if_area
);
1342 /* If we've found an interface and/or addr specific area, then we're
1346 ospf_update_interface_area(co
, area
);
1350 /* Otherwise, only remaining possibility is a matching network statement
1353 assert(given_area
!= NULL
);
1355 /* Which either was supplied as a parameter.. (e.g. cause a new
1356 * network/area was just added)..
1358 if (p
->family
== co
->address
->family
1359 && ospf_network_match_iface(co
, p
))
1360 ospf_update_interface_area(co
, given_area
);
1365 /* Else we have to search the existing network/area config to see
1368 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
1369 if (rn
->info
!= NULL
&& ospf_network_match_iface(co
, &rn
->p
)) {
1370 struct ospf_network
*network
=
1371 (struct ospf_network
*)rn
->info
;
1372 area
= ospf_area_get(ospf
, network
->area_id
);
1373 ospf_update_interface_area(co
, area
);
1377 /* If the subnet isn't in any area, deconfigure */
1378 if (!configed
&& (oi
= ospf_if_table_lookup(co
->ifp
, co
->address
)))
1382 static void ospf_network_run_interface(struct ospf
*ospf
, struct interface
*ifp
,
1384 struct ospf_area
*given_area
)
1386 struct listnode
*cnode
;
1387 struct connected
*co
;
1389 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
1392 /* Network prefix without area is nonsensical */
1394 assert(given_area
!= NULL
);
1396 /* if interface prefix is match specified prefix,
1397 then create socket and join multicast group. */
1398 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, co
))
1399 ospf_network_run_subnet(ospf
, co
, p
, given_area
);
1402 static void ospf_network_run(struct prefix
*p
, struct ospf_area
*area
)
1404 struct vrf
*vrf
= vrf_lookup_by_id(area
->ospf
->vrf_id
);
1405 struct interface
*ifp
;
1407 /* Schedule Router ID Update. */
1408 if (area
->ospf
->router_id
.s_addr
== INADDR_ANY
)
1409 ospf_router_id_update(area
->ospf
);
1411 /* Get target interface. */
1412 FOR_ALL_INTERFACES (vrf
, ifp
)
1413 ospf_network_run_interface(area
->ospf
, ifp
, p
, area
);
1416 void ospf_ls_upd_queue_empty(struct ospf_interface
*oi
)
1418 struct route_node
*rn
;
1419 struct listnode
*node
, *nnode
;
1421 struct ospf_lsa
*lsa
;
1423 /* empty ls update queue */
1424 for (rn
= route_top(oi
->ls_upd_queue
); rn
; rn
= route_next(rn
))
1425 if ((lst
= (struct list
*)rn
->info
)) {
1426 for (ALL_LIST_ELEMENTS(lst
, node
, nnode
, lsa
))
1427 ospf_lsa_unlock(&lsa
); /* oi->ls_upd_queue */
1432 /* remove update event */
1433 THREAD_OFF(oi
->t_ls_upd_event
);
1436 void ospf_if_update(struct ospf
*ospf
, struct interface
*ifp
)
1442 if (IS_DEBUG_OSPF_EVENT
)
1444 "%s: interface %s vrf %s(%u) ospf vrf %s vrf_id %u router_id %pI4",
1445 __func__
, ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
,
1446 ospf_vrf_id_to_name(ospf
->vrf_id
), ospf
->vrf_id
,
1449 /* OSPF must be ready. */
1450 if (!ospf_is_ready(ospf
))
1453 ospf_network_run_interface(ospf
, ifp
, NULL
, NULL
);
1455 /* Update connected redistribute. */
1456 update_redistributed(ospf
, 1);
1460 void ospf_remove_vls_through_area(struct ospf
*ospf
, struct ospf_area
*area
)
1462 struct listnode
*node
, *nnode
;
1463 struct ospf_vl_data
*vl_data
;
1465 for (ALL_LIST_ELEMENTS(ospf
->vlinks
, node
, nnode
, vl_data
))
1466 if (IPV4_ADDR_SAME(&vl_data
->vl_area_id
, &area
->area_id
))
1467 ospf_vl_delete(ospf
, vl_data
);
1471 static const struct message ospf_area_type_msg
[] = {
1472 {OSPF_AREA_DEFAULT
, "Default"},
1473 {OSPF_AREA_STUB
, "Stub"},
1474 {OSPF_AREA_NSSA
, "NSSA"},
1477 static void ospf_area_type_set(struct ospf_area
*area
, int type
)
1479 struct listnode
*node
;
1480 struct ospf_interface
*oi
;
1482 if (area
->external_routing
== type
) {
1483 if (IS_DEBUG_OSPF_EVENT
)
1484 zlog_debug("Area[%pI4]: Types are the same, ignored.",
1489 area
->external_routing
= type
;
1491 if (IS_DEBUG_OSPF_EVENT
)
1492 zlog_debug("Area[%pI4]: Configured as %s",
1494 lookup_msg(ospf_area_type_msg
, type
, NULL
));
1496 switch (area
->external_routing
) {
1497 case OSPF_AREA_DEFAULT
:
1498 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1499 if (oi
->nbr_self
!= NULL
) {
1500 UNSET_FLAG(oi
->nbr_self
->options
,
1502 SET_FLAG(oi
->nbr_self
->options
, OSPF_OPTION_E
);
1505 case OSPF_AREA_STUB
:
1506 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1507 if (oi
->nbr_self
!= NULL
) {
1508 if (IS_DEBUG_OSPF_EVENT
)
1510 "setting options on %s accordingly",
1512 UNSET_FLAG(oi
->nbr_self
->options
,
1514 UNSET_FLAG(oi
->nbr_self
->options
,
1516 if (IS_DEBUG_OSPF_EVENT
)
1517 zlog_debug("options set on %s: %x",
1518 IF_NAME(oi
), OPTIONS(oi
));
1521 case OSPF_AREA_NSSA
:
1522 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1523 if (oi
->nbr_self
!= NULL
) {
1525 "setting nssa options on %s accordingly",
1527 UNSET_FLAG(oi
->nbr_self
->options
,
1529 SET_FLAG(oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1530 zlog_debug("options set on %s: %x", IF_NAME(oi
),
1538 ospf_router_lsa_update_area(area
);
1539 ospf_schedule_abr_task(area
->ospf
);
1542 int ospf_area_shortcut_set(struct ospf
*ospf
, struct ospf_area
*area
, int mode
)
1544 if (area
->shortcut_configured
== mode
)
1547 area
->shortcut_configured
= mode
;
1548 ospf_router_lsa_update_area(area
);
1549 ospf_schedule_abr_task(ospf
);
1551 ospf_area_check_free(ospf
, area
->area_id
);
1556 int ospf_area_shortcut_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1558 area
->shortcut_configured
= OSPF_SHORTCUT_DEFAULT
;
1559 ospf_router_lsa_update_area(area
);
1560 ospf_area_check_free(ospf
, area
->area_id
);
1561 ospf_schedule_abr_task(ospf
);
1566 static int ospf_area_vlink_count(struct ospf
*ospf
, struct ospf_area
*area
)
1568 struct ospf_vl_data
*vl
;
1569 struct listnode
*node
;
1572 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl
))
1573 if (IPV4_ADDR_SAME(&vl
->vl_area_id
, &area
->area_id
))
1579 int ospf_area_display_format_set(struct ospf
*ospf
, struct ospf_area
*area
,
1582 area
->area_id_fmt
= df
;
1587 int ospf_area_stub_set(struct ospf
*ospf
, struct in_addr area_id
)
1589 struct ospf_area
*area
;
1591 area
= ospf_area_get(ospf
, area_id
);
1592 if (ospf_area_vlink_count(ospf
, area
))
1595 if (area
->external_routing
!= OSPF_AREA_STUB
)
1596 ospf_area_type_set(area
, OSPF_AREA_STUB
);
1601 int ospf_area_stub_unset(struct ospf
*ospf
, struct in_addr area_id
)
1603 struct ospf_area
*area
;
1605 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1609 if (area
->external_routing
== OSPF_AREA_STUB
)
1610 ospf_area_type_set(area
, OSPF_AREA_DEFAULT
);
1612 ospf_area_check_free(ospf
, area_id
);
1617 int ospf_area_no_summary_set(struct ospf
*ospf
, struct in_addr area_id
)
1619 struct ospf_area
*area
;
1621 area
= ospf_area_get(ospf
, area_id
);
1622 area
->no_summary
= 1;
1627 int ospf_area_no_summary_unset(struct ospf
*ospf
, struct in_addr area_id
)
1629 struct ospf_area
*area
;
1631 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1635 area
->no_summary
= 0;
1636 ospf_area_check_free(ospf
, area_id
);
1641 int ospf_area_nssa_no_summary_set(struct ospf
*ospf
, struct in_addr area_id
)
1643 struct ospf_area
*area
;
1645 area
= ospf_area_get(ospf
, area_id
);
1646 if (ospf_area_vlink_count(ospf
, area
))
1649 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1650 ospf_area_type_set(area
, OSPF_AREA_NSSA
);
1652 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1655 ospf_area_no_summary_set(ospf
, area_id
);
1660 int ospf_area_nssa_set(struct ospf
*ospf
, struct in_addr area_id
)
1662 struct ospf_area
*area
;
1664 area
= ospf_area_get(ospf
, area_id
);
1665 if (ospf_area_vlink_count(ospf
, area
))
1668 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1669 ospf_area_type_set(area
, OSPF_AREA_NSSA
);
1672 /* set NSSA area defaults */
1673 area
->no_summary
= 0;
1674 area
->suppress_fa
= 0;
1675 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1676 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1677 area
->NSSATranslatorStabilityInterval
=
1678 OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1683 int ospf_area_nssa_unset(struct ospf
*ospf
, struct in_addr area_id
, int argc
)
1685 struct ospf_area
*area
;
1687 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1691 /* argc < 5 -> 'no area x nssa' */
1692 if (argc
< 5 && area
->external_routing
== OSPF_AREA_NSSA
) {
1694 /* set NSSA area defaults */
1695 area
->no_summary
= 0;
1696 area
->suppress_fa
= 0;
1697 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1698 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1699 area
->NSSATranslatorStabilityInterval
=
1700 OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1701 ospf_area_type_set(area
, OSPF_AREA_DEFAULT
);
1703 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1704 OSPF_NSSA_ROLE_CANDIDATE
);
1707 ospf_area_check_free(ospf
, area_id
);
1712 int ospf_area_nssa_suppress_fa_set(struct ospf
*ospf
, struct in_addr area_id
)
1714 struct ospf_area
*area
;
1716 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1720 area
->suppress_fa
= 1;
1725 int ospf_area_nssa_suppress_fa_unset(struct ospf
*ospf
, struct in_addr area_id
)
1727 struct ospf_area
*area
;
1729 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1733 area
->suppress_fa
= 0;
1738 int ospf_area_nssa_translator_role_set(struct ospf
*ospf
,
1739 struct in_addr area_id
, int role
)
1741 struct ospf_area
*area
;
1743 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1747 if (role
!= area
->NSSATranslatorRole
) {
1748 if ((area
->NSSATranslatorRole
== OSPF_NSSA_ROLE_ALWAYS
)
1749 || (role
== OSPF_NSSA_ROLE_ALWAYS
)) {
1751 * if new role is OSPF_NSSA_ROLE_ALWAYS we need to set
1752 * Nt bit, if the role was OSPF_NSSA_ROLE_ALWAYS we need
1755 area
->NSSATranslatorRole
= role
;
1756 ospf_router_lsa_update_area(area
);
1758 area
->NSSATranslatorRole
= role
;
1764 int ospf_area_export_list_set(struct ospf
*ospf
, struct ospf_area
*area
,
1765 const char *list_name
)
1767 struct access_list
*list
;
1768 list
= access_list_lookup(AFI_IP
, list_name
);
1770 EXPORT_LIST(area
) = list
;
1772 if (EXPORT_NAME(area
))
1773 free(EXPORT_NAME(area
));
1775 EXPORT_NAME(area
) = strdup(list_name
);
1776 ospf_schedule_abr_task(ospf
);
1781 int ospf_area_export_list_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1784 EXPORT_LIST(area
) = 0;
1786 if (EXPORT_NAME(area
))
1787 free(EXPORT_NAME(area
));
1789 EXPORT_NAME(area
) = NULL
;
1791 ospf_area_check_free(ospf
, area
->area_id
);
1793 ospf_schedule_abr_task(ospf
);
1798 int ospf_area_import_list_set(struct ospf
*ospf
, struct ospf_area
*area
,
1801 struct access_list
*list
;
1802 list
= access_list_lookup(AFI_IP
, name
);
1804 IMPORT_LIST(area
) = list
;
1806 if (IMPORT_NAME(area
))
1807 free(IMPORT_NAME(area
));
1809 IMPORT_NAME(area
) = strdup(name
);
1810 ospf_schedule_abr_task(ospf
);
1815 int ospf_area_import_list_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1817 IMPORT_LIST(area
) = 0;
1819 if (IMPORT_NAME(area
))
1820 free(IMPORT_NAME(area
));
1822 IMPORT_NAME(area
) = NULL
;
1823 ospf_area_check_free(ospf
, area
->area_id
);
1825 ospf_schedule_abr_task(ospf
);
1830 int ospf_timers_refresh_set(struct ospf
*ospf
, int interval
)
1834 if (ospf
->lsa_refresh_interval
== interval
)
1837 time_left
= ospf
->lsa_refresh_interval
1838 - (monotime(NULL
) - ospf
->lsa_refresher_started
);
1840 if (time_left
> interval
) {
1841 THREAD_OFF(ospf
->t_lsa_refresher
);
1842 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1843 interval
, &ospf
->t_lsa_refresher
);
1845 ospf
->lsa_refresh_interval
= interval
;
1850 int ospf_timers_refresh_unset(struct ospf
*ospf
)
1854 time_left
= ospf
->lsa_refresh_interval
1855 - (monotime(NULL
) - ospf
->lsa_refresher_started
);
1857 if (time_left
> OSPF_LSA_REFRESH_INTERVAL_DEFAULT
) {
1858 THREAD_OFF(ospf
->t_lsa_refresher
);
1859 ospf
->t_lsa_refresher
= NULL
;
1860 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1861 OSPF_LSA_REFRESH_INTERVAL_DEFAULT
,
1862 &ospf
->t_lsa_refresher
);
1865 ospf
->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
1871 static struct ospf_nbr_nbma
*ospf_nbr_nbma_new(void)
1873 struct ospf_nbr_nbma
*nbr_nbma
;
1875 nbr_nbma
= XCALLOC(MTYPE_OSPF_NEIGHBOR_STATIC
,
1876 sizeof(struct ospf_nbr_nbma
));
1878 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1879 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1884 static void ospf_nbr_nbma_free(struct ospf_nbr_nbma
*nbr_nbma
)
1886 XFREE(MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
1889 static void ospf_nbr_nbma_delete(struct ospf
*ospf
,
1890 struct ospf_nbr_nbma
*nbr_nbma
)
1892 struct route_node
*rn
;
1893 struct prefix_ipv4 p
;
1896 p
.prefix
= nbr_nbma
->addr
;
1897 p
.prefixlen
= IPV4_MAX_BITLEN
;
1899 rn
= route_node_lookup(ospf
->nbr_nbma
, (struct prefix
*)&p
);
1901 ospf_nbr_nbma_free(rn
->info
);
1903 route_unlock_node(rn
);
1904 route_unlock_node(rn
);
1908 static void ospf_nbr_nbma_down(struct ospf_nbr_nbma
*nbr_nbma
)
1910 THREAD_OFF(nbr_nbma
->t_poll
);
1912 if (nbr_nbma
->nbr
) {
1913 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
1914 OSPF_NSM_EVENT_EXECUTE(nbr_nbma
->nbr
, NSM_KillNbr
);
1918 listnode_delete(nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
1921 static void ospf_nbr_nbma_add(struct ospf_nbr_nbma
*nbr_nbma
,
1922 struct ospf_interface
*oi
)
1924 struct ospf_neighbor
*nbr
;
1925 struct route_node
*rn
;
1928 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1931 if (nbr_nbma
->nbr
!= NULL
)
1934 if (IPV4_ADDR_SAME(&oi
->nbr_self
->address
.u
.prefix4
, &nbr_nbma
->addr
))
1938 listnode_add(oi
->nbr_nbma
, nbr_nbma
);
1940 /* Get neighbor information from table. */
1942 p
.prefixlen
= IPV4_MAX_BITLEN
;
1943 p
.u
.prefix4
= nbr_nbma
->addr
;
1945 rn
= route_node_get(oi
->nbrs
, &p
);
1948 nbr
->nbr_nbma
= nbr_nbma
;
1949 nbr_nbma
->nbr
= nbr
;
1951 route_unlock_node(rn
);
1953 nbr
= rn
->info
= ospf_nbr_new(oi
);
1954 nbr
->state
= NSM_Down
;
1955 nbr
->src
= nbr_nbma
->addr
;
1956 nbr
->nbr_nbma
= nbr_nbma
;
1957 nbr
->priority
= nbr_nbma
->priority
;
1960 nbr_nbma
->nbr
= nbr
;
1962 /* Configure BFD if interface has it. */
1963 ospf_neighbor_bfd_apply(nbr
);
1965 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_Start
);
1969 void ospf_nbr_nbma_if_update(struct ospf
*ospf
, struct ospf_interface
*oi
)
1971 struct ospf_nbr_nbma
*nbr_nbma
;
1972 struct route_node
*rn
;
1973 struct prefix_ipv4 p
;
1975 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1978 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
1979 if ((nbr_nbma
= rn
->info
))
1980 if (nbr_nbma
->oi
== NULL
&& nbr_nbma
->nbr
== NULL
) {
1982 p
.prefix
= nbr_nbma
->addr
;
1983 p
.prefixlen
= IPV4_MAX_BITLEN
;
1985 if (prefix_match(oi
->address
,
1986 (struct prefix
*)&p
))
1987 ospf_nbr_nbma_add(nbr_nbma
, oi
);
1991 struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup(struct ospf
*ospf
,
1992 struct in_addr nbr_addr
)
1994 struct route_node
*rn
;
1995 struct prefix_ipv4 p
;
1998 p
.prefix
= nbr_addr
;
1999 p
.prefixlen
= IPV4_MAX_BITLEN
;
2001 rn
= route_node_lookup(ospf
->nbr_nbma
, (struct prefix
*)&p
);
2003 route_unlock_node(rn
);
2009 int ospf_nbr_nbma_set(struct ospf
*ospf
, struct in_addr nbr_addr
)
2011 struct ospf_nbr_nbma
*nbr_nbma
;
2012 struct ospf_interface
*oi
;
2013 struct prefix_ipv4 p
;
2014 struct route_node
*rn
;
2015 struct listnode
*node
;
2017 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2021 nbr_nbma
= ospf_nbr_nbma_new();
2022 nbr_nbma
->addr
= nbr_addr
;
2025 p
.prefix
= nbr_addr
;
2026 p
.prefixlen
= IPV4_MAX_BITLEN
;
2028 rn
= route_node_get(ospf
->nbr_nbma
, (struct prefix
*)&p
);
2030 route_unlock_node(rn
);
2031 rn
->info
= nbr_nbma
;
2033 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
2034 if (oi
->type
== OSPF_IFTYPE_NBMA
)
2035 if (prefix_match(oi
->address
, (struct prefix
*)&p
)) {
2036 ospf_nbr_nbma_add(nbr_nbma
, oi
);
2044 int ospf_nbr_nbma_unset(struct ospf
*ospf
, struct in_addr nbr_addr
)
2046 struct ospf_nbr_nbma
*nbr_nbma
;
2048 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2049 if (nbr_nbma
== NULL
)
2052 ospf_nbr_nbma_down(nbr_nbma
);
2053 ospf_nbr_nbma_delete(ospf
, nbr_nbma
);
2058 int ospf_nbr_nbma_priority_set(struct ospf
*ospf
, struct in_addr nbr_addr
,
2061 struct ospf_nbr_nbma
*nbr_nbma
;
2063 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2064 if (nbr_nbma
== NULL
)
2067 if (nbr_nbma
->priority
!= priority
)
2068 nbr_nbma
->priority
= priority
;
2073 int ospf_nbr_nbma_priority_unset(struct ospf
*ospf
, struct in_addr nbr_addr
)
2075 struct ospf_nbr_nbma
*nbr_nbma
;
2077 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2078 if (nbr_nbma
== NULL
)
2081 if (nbr_nbma
!= OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
2082 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2087 int ospf_nbr_nbma_poll_interval_set(struct ospf
*ospf
, struct in_addr nbr_addr
,
2088 unsigned int interval
)
2090 struct ospf_nbr_nbma
*nbr_nbma
;
2092 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2093 if (nbr_nbma
== NULL
)
2096 if (nbr_nbma
->v_poll
!= interval
) {
2097 nbr_nbma
->v_poll
= interval
;
2098 if (nbr_nbma
->oi
&& ospf_if_is_up(nbr_nbma
->oi
)) {
2099 THREAD_OFF(nbr_nbma
->t_poll
);
2100 OSPF_POLL_TIMER_ON(nbr_nbma
->t_poll
, ospf_poll_timer
,
2108 int ospf_nbr_nbma_poll_interval_unset(struct ospf
*ospf
, struct in_addr addr
)
2110 struct ospf_nbr_nbma
*nbr_nbma
;
2112 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, addr
);
2113 if (nbr_nbma
== NULL
)
2116 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
2117 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
2122 void ospf_master_init(struct thread_master
*master
)
2124 memset(&ospf_master
, 0, sizeof(ospf_master
));
2127 om
->ospf
= list_new();
2128 om
->master
= master
;
2131 /* Link OSPF instance to VRF. */
2132 void ospf_vrf_link(struct ospf
*ospf
, struct vrf
*vrf
)
2134 ospf
->vrf_id
= vrf
->vrf_id
;
2135 if (vrf
->info
!= (void *)ospf
)
2136 vrf
->info
= (void *)ospf
;
2139 /* Unlink OSPF instance from VRF. */
2140 void ospf_vrf_unlink(struct ospf
*ospf
, struct vrf
*vrf
)
2142 if (vrf
->info
== (void *)ospf
)
2144 ospf
->vrf_id
= VRF_UNKNOWN
;
2147 /* This is hook function for vrf create called as part of vrf_init */
2148 static int ospf_vrf_new(struct vrf
*vrf
)
2150 if (IS_DEBUG_OSPF_EVENT
)
2151 zlog_debug("%s: VRF Created: %s(%u)", __func__
, vrf
->name
,
2157 /* This is hook function for vrf delete call as part of vrf_init */
2158 static int ospf_vrf_delete(struct vrf
*vrf
)
2160 if (IS_DEBUG_OSPF_EVENT
)
2161 zlog_debug("%s: VRF Deletion: %s(%u)", __func__
, vrf
->name
,
2167 static void ospf_set_redist_vrf_bitmaps(struct ospf
*ospf
, bool set
)
2170 struct list
*red_list
;
2172 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
2173 red_list
= ospf
->redist
[type
];
2176 if (IS_DEBUG_OSPF_EVENT
)
2178 "%s: setting redist vrf %d bitmap for type %d",
2179 __func__
, ospf
->vrf_id
, type
);
2181 vrf_bitmap_set(zclient
->redist
[AFI_IP
][type
],
2184 vrf_bitmap_unset(zclient
->redist
[AFI_IP
][type
],
2188 red_list
= ospf
->redist
[DEFAULT_ROUTE
];
2191 vrf_bitmap_set(zclient
->default_information
[AFI_IP
],
2194 vrf_bitmap_unset(zclient
->default_information
[AFI_IP
],
2199 /* Enable OSPF VRF instance */
2200 static int ospf_vrf_enable(struct vrf
*vrf
)
2202 struct ospf
*ospf
= NULL
;
2203 vrf_id_t old_vrf_id
;
2206 if (IS_DEBUG_OSPF_EVENT
)
2207 zlog_debug("%s: VRF %s id %u enabled", __func__
, vrf
->name
,
2210 ospf
= ospf_lookup_by_name(vrf
->name
);
2212 old_vrf_id
= ospf
->vrf_id
;
2213 /* We have instance configured, link to VRF and make it "up". */
2214 ospf_vrf_link(ospf
, vrf
);
2215 if (IS_DEBUG_OSPF_EVENT
)
2217 "%s: ospf linked to vrf %s vrf_id %u (old id %u)",
2218 __func__
, vrf
->name
, ospf
->vrf_id
, old_vrf_id
);
2220 if (old_vrf_id
!= ospf
->vrf_id
) {
2221 ospf_set_redist_vrf_bitmaps(ospf
, true);
2223 /* start zebra redist to us for new vrf */
2224 ospf_zebra_vrf_register(ospf
);
2226 ret
= ospf_sock_init(ospf
);
2227 if (ret
< 0 || ospf
->fd
<= 0)
2229 thread_add_read(master
, ospf_read
, ospf
, ospf
->fd
,
2231 ospf
->oi_running
= 1;
2232 ospf_router_id_update(ospf
);
2239 /* Disable OSPF VRF instance */
2240 static int ospf_vrf_disable(struct vrf
*vrf
)
2242 struct ospf
*ospf
= NULL
;
2243 vrf_id_t old_vrf_id
= VRF_UNKNOWN
;
2245 if (vrf
->vrf_id
== VRF_DEFAULT
)
2248 if (IS_DEBUG_OSPF_EVENT
)
2249 zlog_debug("%s: VRF %s id %d disabled.", __func__
, vrf
->name
,
2252 ospf
= ospf_lookup_by_name(vrf
->name
);
2254 old_vrf_id
= ospf
->vrf_id
;
2256 ospf_zebra_vrf_deregister(ospf
);
2258 ospf_set_redist_vrf_bitmaps(ospf
, false);
2260 /* We have instance configured, unlink
2261 * from VRF and make it "down".
2263 ospf_vrf_unlink(ospf
, vrf
);
2264 ospf
->oi_running
= 0;
2265 if (IS_DEBUG_OSPF_EVENT
)
2266 zlog_debug("%s: ospf old_vrf_id %d unlinked", __func__
,
2268 THREAD_OFF(ospf
->t_read
);
2273 /* Note: This is a callback, the VRF will be deleted by the caller. */
2277 void ospf_vrf_init(void)
2279 vrf_init(ospf_vrf_new
, ospf_vrf_enable
, ospf_vrf_disable
,
2283 void ospf_vrf_terminate(void)
2288 const char *ospf_vrf_id_to_name(vrf_id_t vrf_id
)
2290 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
2292 return vrf
? vrf
->name
: "NIL";
2295 const char *ospf_get_name(const struct ospf
*ospf
)
2300 return VRF_DEFAULT_NAME
;