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 /* API to clean refresh queues and LSAs */
93 static void ospf_free_refresh_queue(struct ospf
*ospf
)
95 for (int i
= 0; i
< OSPF_LSA_REFRESHER_SLOTS
; i
++) {
96 struct list
*list
= ospf
->lsa_refresh_queue
.qs
[i
];
97 struct listnode
*node
, *nnode
;
101 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, lsa
)) {
102 listnode_delete(list
, lsa
);
103 lsa
->refresh_list
= -1;
104 ospf_lsa_unlock(&lsa
);
107 ospf
->lsa_refresh_queue
.qs
[i
] = NULL
;
111 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
113 int p_spaces_compare_func(const struct p_space
*a
, const struct p_space
*b
)
115 if (a
->protected_resource
->type
== OSPF_TI_LFA_LINK_PROTECTION
116 && b
->protected_resource
->type
== OSPF_TI_LFA_LINK_PROTECTION
)
117 return (a
->protected_resource
->link
->link_id
.s_addr
118 - b
->protected_resource
->link
->link_id
.s_addr
);
120 if (a
->protected_resource
->type
== OSPF_TI_LFA_NODE_PROTECTION
121 && b
->protected_resource
->type
== OSPF_TI_LFA_NODE_PROTECTION
)
122 return (a
->protected_resource
->router_id
.s_addr
123 - b
->protected_resource
->router_id
.s_addr
);
125 /* This should not happen */
129 int q_spaces_compare_func(const struct q_space
*a
, const struct q_space
*b
)
131 return (a
->root
->id
.s_addr
- b
->root
->id
.s_addr
);
134 DECLARE_RBTREE_UNIQ(p_spaces
, struct p_space
, p_spaces_item
,
135 p_spaces_compare_func
);
137 void ospf_process_refresh_data(struct ospf
*ospf
, bool reset
)
139 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
140 struct in_addr router_id
, router_id_old
;
141 struct ospf_interface
*oi
;
142 struct interface
*ifp
;
143 struct listnode
*node
, *nnode
;
144 struct ospf_area
*area
;
145 bool rid_change
= false;
147 if (!ospf
->oi_running
) {
148 if (IS_DEBUG_OSPF_EVENT
)
150 "Router ospf not configured -- Router-ID update postponed");
154 if (IS_DEBUG_OSPF_EVENT
)
155 zlog_debug("Router-ID[OLD:%pI4]: Update",
158 router_id_old
= ospf
->router_id
;
160 /* Select the router ID based on these priorities:
161 1. Statically assigned router ID is always the first choice.
162 2. If there is no statically assigned router ID, then try to stick
163 with the most recent value, since changing router ID's is very
165 3. Last choice: just go with whatever the zebra daemon recommends.
167 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
168 router_id
= ospf
->router_id_static
;
169 else if (ospf
->router_id
.s_addr
!= INADDR_ANY
)
170 router_id
= ospf
->router_id
;
172 router_id
= ospf
->router_id_zebra
;
174 if (IS_DEBUG_OSPF_EVENT
)
175 zlog_debug("Router-ID[OLD:%pI4]: Update to %pI4",
176 &ospf
->router_id
, &router_id
);
178 rid_change
= !(IPV4_ADDR_SAME(&router_id_old
, &router_id
));
179 if (rid_change
|| (reset
)) {
180 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
181 /* Some nbrs are identified by router_id, these needs
182 * to be rebuilt. Possible optimization would be to do
183 * oi->nbr_self->router_id = router_id for
184 * !(virtual | ptop) links
186 ospf_nbr_self_reset(oi
, router_id
);
189 * If the old router id was not set, but now it
190 * is and the interface is operative and the
191 * state is ISM_Down we should kick the state
192 * machine as that we processed the interfaces
193 * based upon the network statement( or intf config )
194 * but could not start it at that time.
196 if (if_is_operative(oi
->ifp
) && oi
->state
== ISM_Down
197 && router_id_old
.s_addr
== INADDR_ANY
)
201 /* Flush (inline) all the self originated LSAs */
202 ospf_flush_self_originated_lsas_now(ospf
);
204 ospf
->router_id
= router_id
;
205 if (IS_DEBUG_OSPF_EVENT
)
206 zlog_debug("Router-ID[NEW:%pI4]: Update",
209 /* Flush (inline) all external LSAs which now match the new
211 need to adjust the OSPF_LSA_SELF flag, so the flush doesn't
213 asserts in ospf_refresher_unregister_lsa(). This step is
215 because the current frr code does look-up for
217 based on the self router-id alone but expects OSPF_LSA_SELF
221 struct route_node
*rn
;
222 struct ospf_lsa
*lsa
;
224 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
) {
225 /* AdvRouter and Router ID is the same. */
226 if (IPV4_ADDR_SAME(&lsa
->data
->adv_router
,
227 &ospf
->router_id
) && rid_change
) {
229 OSPF_LSA_SELF_CHECKED
);
230 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF
);
231 ospf_lsa_flush_schedule(ospf
, lsa
);
233 /* The above flush will send immediately
234 * So discard the LSA to originate new
236 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
239 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
240 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
242 ospf_lsdb_delete_all(ospf
->lsdb
);
245 /* Since the LSAs are deleted, need reset the aggr flag */
246 ospf_unset_all_aggr_flag(ospf
);
248 /* Delete the LSDB */
249 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
250 ospf_area_lsdb_discard_delete(area
);
252 /* update router-lsa's for each area */
253 ospf_router_lsa_update(ospf
);
255 /* update ospf_interface's */
256 FOR_ALL_INTERFACES (vrf
, ifp
) {
260 ospf_if_update(ospf
, ifp
);
263 ospf_external_lsa_rid_change(ospf
);
265 #ifdef SUPPORT_OSPF_API
266 ospf_apiserver_clients_notify_router_id_change(router_id
);
270 ospf
->inst_shutdown
= 0;
273 void ospf_router_id_update(struct ospf
*ospf
)
275 ospf_process_refresh_data(ospf
, false);
278 void ospf_process_reset(struct ospf
*ospf
)
280 ospf_process_refresh_data(ospf
, true);
283 void ospf_neighbor_reset(struct ospf
*ospf
, struct in_addr nbr_id
,
286 struct route_node
*rn
;
287 struct ospf_neighbor
*nbr
;
288 struct ospf_interface
*oi
;
289 struct listnode
*node
;
291 /* Clear only a particular nbr with nbr router id as nbr_id */
292 if (nbr_str
!= NULL
) {
293 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
294 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &nbr_id
);
296 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_KillNbr
);
301 /* send Neighbor event KillNbr to all associated neighbors. */
302 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
303 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
305 if (nbr
&& (nbr
!= oi
->nbr_self
))
306 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_KillNbr
);
311 /* For OSPF area sort by area id. */
312 static int ospf_area_id_cmp(struct ospf_area
*a1
, struct ospf_area
*a2
)
314 if (ntohl(a1
->area_id
.s_addr
) > ntohl(a2
->area_id
.s_addr
))
316 if (ntohl(a1
->area_id
.s_addr
) < ntohl(a2
->area_id
.s_addr
))
321 static void ospf_add(struct ospf
*ospf
)
323 listnode_add(om
->ospf
, ospf
);
326 static void ospf_delete(struct ospf
*ospf
)
328 listnode_delete(om
->ospf
, ospf
);
331 struct ospf
*ospf_new_alloc(unsigned short instance
, const char *name
)
334 struct vrf
*vrf
= NULL
;
336 struct ospf
*new = XCALLOC(MTYPE_OSPF_TOP
, sizeof(struct ospf
));
338 new->instance
= instance
;
339 new->router_id
.s_addr
= htonl(0);
340 new->router_id_static
.s_addr
= htonl(0);
342 vrf
= vrf_lookup_by_name(name
);
344 new->vrf_id
= vrf
->vrf_id
;
346 new->vrf_id
= VRF_UNKNOWN
;
348 /* Freed in ospf_finish_final */
349 new->name
= XSTRDUP(MTYPE_OSPF_TOP
, name
);
350 if (IS_DEBUG_OSPF_EVENT
)
352 "%s: Create new ospf instance with vrf_name %s vrf_id %u",
353 __func__
, name
, new->vrf_id
);
356 ospf_vrf_link(new, vrf
);
358 ospf_zebra_vrf_register(new);
360 new->abr_type
= OSPF_ABR_DEFAULT
;
361 new->oiflist
= list_new();
362 new->vlinks
= list_new();
363 new->areas
= list_new();
364 new->areas
->cmp
= (int (*)(void *, void *))ospf_area_id_cmp
;
365 new->networks
= route_table_init();
366 new->nbr_nbma
= route_table_init();
368 new->lsdb
= ospf_lsdb_new();
370 new->default_originate
= DEFAULT_ORIGINATE_NONE
;
372 new->passive_interface_default
= OSPF_IF_ACTIVE
;
374 new->new_external_route
= route_table_init();
375 new->old_external_route
= route_table_init();
376 new->external_lsas
= route_table_init();
378 new->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
379 new->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
380 new->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
382 /* Distribute parameter init. */
383 for (i
= 0; i
<= ZEBRA_ROUTE_MAX
; i
++) {
386 new->default_metric
= -1;
387 new->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
390 new->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
391 new->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
393 /* SPF timer value init. */
394 new->spf_delay
= OSPF_SPF_DELAY_DEFAULT
;
395 new->spf_holdtime
= OSPF_SPF_HOLDTIME_DEFAULT
;
396 new->spf_max_holdtime
= OSPF_SPF_MAX_HOLDTIME_DEFAULT
;
397 new->spf_hold_multiplier
= 1;
400 new->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
401 new->maxage_lsa
= route_table_init();
402 new->t_maxage_walker
= NULL
;
403 thread_add_timer(master
, ospf_lsa_maxage_walker
, new,
404 OSPF_LSA_MAXAGE_CHECK_INTERVAL
, &new->t_maxage_walker
);
406 /* Max paths initialization */
407 new->max_multipath
= MULTIPATH_NUM
;
409 /* Distance table init. */
410 new->distance_table
= route_table_init();
412 new->lsa_refresh_queue
.index
= 0;
413 new->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
414 new->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
415 new->t_lsa_refresher
= NULL
;
416 thread_add_timer(master
, ospf_lsa_refresh_walker
, new,
417 new->lsa_refresh_interval
, &new->t_lsa_refresher
);
418 new->lsa_refresher_started
= monotime(NULL
);
420 new->ibuf
= stream_new(OSPF_MAX_PACKET_SIZE
+ 1);
423 new->oi_write_q
= list_new();
424 new->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
426 new->proactive_arp
= OSPF_PROACTIVE_ARP_DEFAULT
;
428 ospf_gr_helper_instance_init(new);
430 ospf_asbr_external_aggregator_init(new);
432 ospf_opaque_type11_lsa_init(new);
441 /* Allocate new ospf structure. */
442 static struct ospf
*ospf_new(unsigned short instance
, const char *name
)
446 new = ospf_new_alloc(instance
, name
);
449 if (new->vrf_id
== VRF_UNKNOWN
)
452 if ((ospf_sock_init(new)) < 0) {
453 flog_err(EC_LIB_SOCKET
,
454 "%s: ospf_sock_init is unable to open a socket",
459 thread_add_read(master
, ospf_read
, new, new->fd
, &new->t_read
);
462 ospf_router_id_update(new);
465 * Read from non-volatile memory whether this instance is performing a
466 * graceful restart or not.
468 ospf_gr_nvm_read(new);
473 struct ospf
*ospf_lookup_instance(unsigned short instance
)
476 struct listnode
*node
, *nnode
;
478 if (listcount(om
->ospf
) == 0)
481 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
482 if ((ospf
->instance
== 0 && instance
== 0)
483 || (ospf
->instance
&& instance
484 && ospf
->instance
== instance
))
490 static int ospf_is_ready(struct ospf
*ospf
)
492 /* OSPF must be on and Router-ID must be configured. */
493 if (!ospf
|| ospf
->router_id
.s_addr
== INADDR_ANY
)
499 struct ospf
*ospf_lookup_by_inst_name(unsigned short instance
, const char *name
)
501 struct ospf
*ospf
= NULL
;
502 struct listnode
*node
, *nnode
;
504 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
)) {
505 if ((ospf
->instance
== instance
)
506 && ((ospf
->name
== NULL
&& name
== NULL
)
507 || (ospf
->name
&& name
508 && strcmp(ospf
->name
, name
) == 0)))
514 struct ospf
*ospf_lookup(unsigned short instance
, const char *name
)
519 ospf
= ospf_lookup_instance(instance
);
521 ospf
= ospf_lookup_by_inst_name(instance
, name
);
527 struct ospf
*ospf_get(unsigned short instance
, const char *name
, bool *created
)
531 ospf
= ospf_lookup(instance
, name
);
533 *created
= (ospf
== NULL
);
535 ospf
= ospf_new(instance
, name
);
540 struct ospf
*ospf_lookup_by_vrf_id(vrf_id_t vrf_id
)
542 struct vrf
*vrf
= NULL
;
544 vrf
= vrf_lookup_by_id(vrf_id
);
547 return (vrf
->info
) ? (struct ospf
*)vrf
->info
: NULL
;
550 uint32_t ospf_count_area_params(struct ospf
*ospf
)
553 struct interface
*ifp
;
556 if (ospf
->vrf_id
!= VRF_UNKNOWN
) {
557 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
559 FOR_ALL_INTERFACES (vrf
, ifp
) {
560 count
+= ospf_if_count_area_params(ifp
);
567 /* It should only be used when processing incoming info update from zebra.
568 * Other situations, it is not sufficient to lookup the ospf instance by
569 * vrf_name only without using the instance number.
571 static struct ospf
*ospf_lookup_by_name(const char *vrf_name
)
573 struct ospf
*ospf
= NULL
;
574 struct listnode
*node
, *nnode
;
576 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
577 if ((ospf
->name
== NULL
&& vrf_name
== NULL
)
578 || (ospf
->name
&& vrf_name
579 && strcmp(ospf
->name
, vrf_name
) == 0))
584 /* Handle the second half of deferred shutdown. This is called either
585 * from the deferred-shutdown timer thread, or directly through
586 * ospf_deferred_shutdown_check.
588 * Function is to cleanup G-R state, if required then call ospf_finish_final
589 * to complete shutdown of this ospf instance. Possibly exit if the
590 * whole process is being shutdown and this was the last OSPF instance.
592 static void ospf_deferred_shutdown_finish(struct ospf
*ospf
)
594 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
595 THREAD_OFF(ospf
->t_deferred_shutdown
);
597 ospf_finish_final(ospf
);
599 /* *ospf is now invalid */
601 /* ospfd being shut-down? If so, was this the last ospf instance? */
602 if (CHECK_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
)
603 && (listcount(om
->ospf
) == 0)) {
611 /* Timer thread for G-R */
612 static void ospf_deferred_shutdown_timer(struct thread
*t
)
614 struct ospf
*ospf
= THREAD_ARG(t
);
616 ospf_deferred_shutdown_finish(ospf
);
619 /* Check whether deferred-shutdown must be scheduled, otherwise call
620 * down directly into second-half of instance shutdown.
622 static void ospf_deferred_shutdown_check(struct ospf
*ospf
)
624 unsigned long timeout
;
626 struct ospf_area
*area
;
628 /* deferred shutdown already running? */
629 if (ospf
->t_deferred_shutdown
)
632 /* Should we try push out max-metric LSAs? */
633 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
) {
634 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
635 SET_FLAG(area
->stub_router_state
,
636 OSPF_AREA_ADMIN_STUB_ROUTED
);
638 if (!CHECK_FLAG(area
->stub_router_state
,
639 OSPF_AREA_IS_STUB_ROUTED
))
640 ospf_router_lsa_update_area(area
);
642 timeout
= ospf
->stub_router_shutdown_time
;
644 /* No timer needed */
645 ospf_deferred_shutdown_finish(ospf
);
649 OSPF_TIMER_ON(ospf
->t_deferred_shutdown
, ospf_deferred_shutdown_timer
,
654 /* Shut down the entire process */
655 void ospf_terminate(void)
658 struct listnode
*node
, *nnode
;
660 /* shutdown already in progress */
661 if (CHECK_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
))
664 SET_FLAG(om
->options
, OSPF_MASTER_SHUTDOWN
);
666 /* Skip some steps if OSPF not actually running */
667 if (listcount(om
->ospf
) == 0)
670 for (ALL_LIST_ELEMENTS(om
->ospf
, node
, nnode
, ospf
))
674 ospf_gr_helper_stop();
676 /* Cleanup route maps */
679 /* reverse prefix_list_init */
680 prefix_list_add_hook(NULL
);
681 prefix_list_delete_hook(NULL
);
684 /* Cleanup vrf info */
685 ospf_vrf_terminate();
687 /* Deliberately go back up, hopefully to thread scheduler, as
688 * One or more ospf_finish()'s may have deferred shutdown to a timer
691 zclient_stop(zclient
);
692 zclient_free(zclient
);
698 void ospf_finish(struct ospf
*ospf
)
700 /* let deferred shutdown decide */
701 ospf_deferred_shutdown_check(ospf
);
703 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
704 * deferred to expiry of G-S timer thread. Return back up, hopefully
705 * to thread scheduler.
710 /* Final cleanup of ospf instance */
711 static void ospf_finish_final(struct ospf
*ospf
)
713 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
714 struct route_node
*rn
;
715 struct ospf_nbr_nbma
*nbr_nbma
;
716 struct ospf_lsa
*lsa
;
717 struct ospf_interface
*oi
;
718 struct ospf_area
*area
;
719 struct ospf_vl_data
*vl_data
;
720 struct listnode
*node
, *nnode
;
721 struct ospf_redist
*red
;
726 ospf_opaque_type11_lsa_term(ospf
);
728 ospf_opaque_finish();
730 if (!ospf
->gr_info
.prepare_in_progress
)
731 ospf_flush_self_originated_lsas_now(ospf
);
733 /* Unregister redistribution */
734 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
735 struct list
*red_list
;
737 red_list
= ospf
->redist
[i
];
741 for (ALL_LIST_ELEMENTS(red_list
, node
, nnode
, red
)) {
742 ospf_redistribute_unset(ospf
, i
, red
->instance
);
743 ospf_redist_del(ospf
, i
, red
->instance
);
746 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
748 ospf_routemap_unset(red
);
749 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
750 ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
, 0, 0);
753 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
754 ospf_remove_vls_through_area(ospf
, area
);
756 for (ALL_LIST_ELEMENTS(ospf
->vlinks
, node
, nnode
, vl_data
))
757 ospf_vl_delete(ospf
, vl_data
);
759 list_delete(&ospf
->vlinks
);
761 /* shutdown LDP-Sync */
762 if (ospf
->vrf_id
== VRF_DEFAULT
)
763 ospf_ldp_sync_gbl_exit(ospf
, true);
765 /* Reset interface. */
766 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
768 list_delete(&ospf
->oiflist
);
769 ospf
->oi_running
= 0;
771 /* De-Register VRF */
772 ospf_zebra_vrf_deregister(ospf
);
774 /* Clear static neighbors */
775 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
776 if ((nbr_nbma
= rn
->info
)) {
777 THREAD_OFF(nbr_nbma
->t_poll
);
780 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
781 nbr_nbma
->nbr
= NULL
;
785 listnode_delete(nbr_nbma
->oi
->nbr_nbma
,
790 XFREE(MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
793 route_table_finish(ospf
->nbr_nbma
);
795 /* Clear networks and Areas. */
796 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
797 struct ospf_network
*network
;
799 if ((network
= rn
->info
) != NULL
) {
800 ospf_network_free(ospf
, network
);
802 route_unlock_node(rn
);
805 route_table_finish(ospf
->networks
);
807 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
808 listnode_delete(ospf
->areas
, area
);
809 ospf_area_free(area
);
812 /* Cancel all timers. */
813 THREAD_OFF(ospf
->t_read
);
814 THREAD_OFF(ospf
->t_write
);
815 THREAD_OFF(ospf
->t_spf_calc
);
816 THREAD_OFF(ospf
->t_ase_calc
);
817 THREAD_OFF(ospf
->t_orr_calc
);
818 THREAD_OFF(ospf
->t_maxage
);
819 THREAD_OFF(ospf
->t_maxage_walker
);
820 THREAD_OFF(ospf
->t_abr_task
);
821 THREAD_OFF(ospf
->t_asbr_check
);
822 THREAD_OFF(ospf
->t_asbr_nssa_redist_update
);
823 THREAD_OFF(ospf
->t_distribute_update
);
824 THREAD_OFF(ospf
->t_lsa_refresher
);
825 THREAD_OFF(ospf
->t_opaque_lsa_self
);
826 THREAD_OFF(ospf
->t_sr_update
);
827 THREAD_OFF(ospf
->t_default_routemap_timer
);
828 THREAD_OFF(ospf
->t_external_aggr
);
829 THREAD_OFF(ospf
->gr_info
.t_grace_period
);
831 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
832 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
833 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
834 ospf_discard_from_db(ospf
, ospf
->lsdb
, lsa
);
836 ospf_lsdb_delete_all(ospf
->lsdb
);
837 ospf_lsdb_free(ospf
->lsdb
);
839 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
840 if ((lsa
= rn
->info
) != NULL
) {
841 ospf_lsa_unlock(&lsa
);
843 route_unlock_node(rn
);
846 route_table_finish(ospf
->maxage_lsa
);
849 ospf_route_table_free(ospf
->old_table
);
850 if (ospf
->new_table
) {
851 if (!ospf
->gr_info
.prepare_in_progress
)
852 ospf_route_delete(ospf
, ospf
->new_table
);
853 ospf_route_table_free(ospf
->new_table
);
856 ospf_rtrs_free(ospf
->oall_rtrs
);
858 ospf_rtrs_free(ospf
->all_rtrs
);
860 ospf_rtrs_free(ospf
->old_rtrs
);
862 ospf_rtrs_free(ospf
->new_rtrs
);
863 if (ospf
->new_external_route
) {
864 if (!ospf
->gr_info
.prepare_in_progress
)
865 ospf_route_delete(ospf
, ospf
->new_external_route
);
866 ospf_route_table_free(ospf
->new_external_route
);
868 if (ospf
->old_external_route
) {
869 if (!ospf
->gr_info
.prepare_in_progress
)
870 ospf_route_delete(ospf
, ospf
->old_external_route
);
871 ospf_route_table_free(ospf
->old_external_route
);
873 if (ospf
->external_lsas
) {
874 ospf_ase_external_lsas_finish(ospf
->external_lsas
);
877 for (i
= ZEBRA_ROUTE_SYSTEM
; i
<= ZEBRA_ROUTE_MAX
; i
++) {
878 struct list
*ext_list
;
879 struct ospf_external
*ext
;
881 ext_list
= ospf
->external
[i
];
885 for (ALL_LIST_ELEMENTS(ext_list
, node
, nnode
, ext
)) {
886 if (ext
->external_info
)
887 for (rn
= route_top(ext
->external_info
); rn
;
888 rn
= route_next(rn
)) {
889 if (rn
->info
== NULL
)
892 XFREE(MTYPE_OSPF_EXTERNAL_INFO
,
895 route_unlock_node(rn
);
898 ospf_external_del(ospf
, i
, ext
->instance
);
902 ospf_distance_reset(ospf
);
903 route_table_finish(ospf
->distance_table
);
905 /* Release extrenal Aggregator table */
906 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
)) {
907 struct ospf_external_aggr_rt
*aggr
;
912 ospf_external_aggregator_free(aggr
);
914 route_unlock_node(rn
);
918 route_table_finish(ospf
->rt_aggr_tbl
);
921 ospf_free_refresh_queue(ospf
);
923 list_delete(&ospf
->areas
);
924 list_delete(&ospf
->oi_write_q
);
926 /* Reset GR helper data structers */
927 ospf_gr_helper_instance_stop(ospf
);
930 stream_free(ospf
->ibuf
);
932 ospf
->max_multipath
= MULTIPATH_NUM
;
936 ospf_vrf_unlink(ospf
, vrf
);
938 XFREE(MTYPE_OSPF_TOP
, ospf
->name
);
939 XFREE(MTYPE_OSPF_TOP
, ospf
);
943 /* allocate new OSPF Area object */
944 struct ospf_area
*ospf_area_new(struct ospf
*ospf
, struct in_addr area_id
)
946 struct ospf_area
*new;
948 /* Allocate new config_network. */
949 new = XCALLOC(MTYPE_OSPF_AREA
, sizeof(struct ospf_area
));
953 new->area_id
= area_id
;
954 new->area_id_fmt
= OSPF_AREA_ID_FMT_DOTTEDQUAD
;
956 new->external_routing
= OSPF_AREA_DEFAULT
;
957 new->default_cost
= 1;
958 new->auth_type
= OSPF_AUTH_NULL
;
961 new->lsdb
= ospf_lsdb_new();
963 /* Self-originated LSAs initialize. */
964 new->router_lsa_self
= NULL
;
966 ospf_opaque_type10_lsa_init(new);
968 new->oiflist
= list_new();
969 new->ranges
= route_table_init();
971 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
)
972 ospf
->backbone
= new;
977 void ospf_area_lsdb_discard_delete(struct ospf_area
*area
)
979 struct route_node
*rn
;
980 struct ospf_lsa
*lsa
;
982 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
)
983 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
984 LSDB_LOOP (NETWORK_LSDB(area
), rn
, lsa
)
985 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
986 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
987 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
988 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
989 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
991 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
992 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
993 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
994 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
995 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
996 ospf_discard_from_db(area
->ospf
, area
->lsdb
, lsa
);
998 ospf_lsdb_delete_all(area
->lsdb
);
1001 static void ospf_area_free(struct ospf_area
*area
)
1003 ospf_opaque_type10_lsa_term(area
);
1006 ospf_area_lsdb_discard_delete(area
);
1008 ospf_lsdb_free(area
->lsdb
);
1010 ospf_lsa_unlock(&area
->router_lsa_self
);
1012 route_table_finish(area
->ranges
);
1013 list_delete(&area
->oiflist
);
1015 if (EXPORT_NAME(area
))
1016 free(EXPORT_NAME(area
));
1018 if (IMPORT_NAME(area
))
1019 free(IMPORT_NAME(area
));
1022 THREAD_OFF(area
->t_stub_router
);
1023 THREAD_OFF(area
->t_opaque_lsa_self
);
1025 if (OSPF_IS_AREA_BACKBONE(area
))
1026 area
->ospf
->backbone
= NULL
;
1028 XFREE(MTYPE_OSPF_AREA
, area
);
1031 void ospf_area_check_free(struct ospf
*ospf
, struct in_addr area_id
)
1033 struct ospf_area
*area
;
1035 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1036 if (area
&& listcount(area
->oiflist
) == 0 && area
->ranges
->top
== NULL
1037 && !ospf_vl_count(ospf
, area
)
1038 && area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
1039 && area
->external_routing
== OSPF_AREA_DEFAULT
1040 && area
->no_summary
== 0 && area
->default_cost
== 1
1041 && EXPORT_NAME(area
) == NULL
&& IMPORT_NAME(area
) == NULL
1042 && area
->auth_type
== OSPF_AUTH_NULL
) {
1043 listnode_delete(ospf
->areas
, area
);
1044 ospf_area_free(area
);
1048 struct ospf_area
*ospf_area_get(struct ospf
*ospf
, struct in_addr area_id
)
1050 struct ospf_area
*area
;
1052 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1054 area
= ospf_area_new(ospf
, area_id
);
1055 listnode_add_sort(ospf
->areas
, area
);
1056 ospf_check_abr_status(ospf
);
1057 if (ospf
->stub_router_admin_set
1058 == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
) {
1059 SET_FLAG(area
->stub_router_state
,
1060 OSPF_AREA_ADMIN_STUB_ROUTED
);
1067 struct ospf_area
*ospf_area_lookup_by_area_id(struct ospf
*ospf
,
1068 struct in_addr area_id
)
1070 struct ospf_area
*area
;
1071 struct listnode
*node
;
1073 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
1074 if (IPV4_ADDR_SAME(&area
->area_id
, &area_id
))
1080 void ospf_area_add_if(struct ospf_area
*area
, struct ospf_interface
*oi
)
1082 listnode_add(area
->oiflist
, oi
);
1085 void ospf_area_del_if(struct ospf_area
*area
, struct ospf_interface
*oi
)
1087 listnode_delete(area
->oiflist
, oi
);
1091 struct ospf_interface
*add_ospf_interface(struct connected
*co
,
1092 struct ospf_area
*area
)
1094 struct ospf_interface
*oi
;
1096 oi
= ospf_if_new(area
->ospf
, co
->ifp
, co
->address
);
1101 oi
->params
= ospf_lookup_if_params(co
->ifp
, oi
->address
->u
.prefix4
);
1102 oi
->output_cost
= ospf_if_get_output_cost(oi
);
1104 /* Relate ospf interface to ospf instance. */
1105 oi
->ospf
= area
->ospf
;
1107 /* update network type as interface flag */
1108 /* If network type is specified previously,
1109 skip network type setting. */
1110 oi
->type
= IF_DEF_PARAMS(co
->ifp
)->type
;
1111 oi
->ptp_dmvpn
= IF_DEF_PARAMS(co
->ifp
)->ptp_dmvpn
;
1113 /* Add pseudo neighbor. */
1114 ospf_nbr_self_reset(oi
, oi
->ospf
->router_id
);
1116 ospf_area_add_if(oi
->area
, oi
);
1118 /* if LDP-IGP Sync is configured globally inherit config */
1119 ospf_ldp_sync_if_init(oi
);
1122 * if router_id is not configured, don't bring up
1124 * ospf_router_id_update() will call ospf_if_update
1125 * whenever r-id is configured instead.
1127 if ((area
->ospf
->router_id
.s_addr
!= INADDR_ANY
)
1128 && if_is_operative(co
->ifp
))
1134 static void update_redistributed(struct ospf
*ospf
, int add_to_ospf
)
1136 struct route_node
*rn
;
1137 struct external_info
*ei
;
1138 struct ospf_external
*ext
;
1140 if (ospf_is_type_redistributed(ospf
, ZEBRA_ROUTE_CONNECT
, 0)) {
1141 ext
= ospf_external_lookup(ospf
, ZEBRA_ROUTE_CONNECT
, 0);
1142 if ((ext
) && EXTERNAL_INFO(ext
)) {
1143 for (rn
= route_top(EXTERNAL_INFO(ext
)); rn
;
1144 rn
= route_next(rn
)) {
1150 if (ospf_external_info_find_lsa(ospf
,
1152 if (!ospf_redistribute_check(
1154 ospf_external_lsa_flush(
1157 ei
->ifindex
/*, ei->nexthop */);
1159 if (!ospf_external_info_find_lsa(
1161 if (ospf_redistribute_check(
1163 ospf_external_lsa_originate(
1171 /* Config network statement related functions. */
1172 static struct ospf_network
*ospf_network_new(struct in_addr area_id
)
1174 struct ospf_network
*new;
1175 new = XCALLOC(MTYPE_OSPF_NETWORK
, sizeof(struct ospf_network
));
1177 new->area_id
= area_id
;
1178 new->area_id_fmt
= OSPF_AREA_ID_FMT_DOTTEDQUAD
;
1183 static void ospf_network_free(struct ospf
*ospf
, struct ospf_network
*network
)
1185 ospf_area_check_free(ospf
, network
->area_id
);
1186 ospf_schedule_abr_task(ospf
);
1187 XFREE(MTYPE_OSPF_NETWORK
, network
);
1190 int ospf_network_set(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1191 struct in_addr area_id
, int df
)
1193 struct ospf_network
*network
;
1194 struct ospf_area
*area
;
1195 struct route_node
*rn
;
1197 rn
= route_node_get(ospf
->networks
, (struct prefix
*)p
);
1200 route_unlock_node(rn
);
1202 if (IPV4_ADDR_SAME(&area_id
, &network
->area_id
)) {
1205 /* There is already same network statement. */
1210 rn
->info
= network
= ospf_network_new(area_id
);
1211 network
->area_id_fmt
= df
;
1212 area
= ospf_area_get(ospf
, area_id
);
1213 ospf_area_display_format_set(ospf
, area
, df
);
1215 /* Run network config now. */
1216 ospf_network_run((struct prefix
*)p
, area
);
1218 /* Update connected redistribute. */
1219 update_redistributed(ospf
, 1); /* interfaces possibly added */
1221 ospf_area_check_free(ospf
, area_id
);
1226 int ospf_network_unset(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1227 struct in_addr area_id
)
1229 struct route_node
*rn
;
1230 struct ospf_network
*network
;
1231 struct listnode
*node
, *nnode
;
1232 struct ospf_interface
*oi
;
1234 rn
= route_node_lookup(ospf
->networks
, (struct prefix
*)p
);
1239 route_unlock_node(rn
);
1240 if (!IPV4_ADDR_SAME(&area_id
, &network
->area_id
))
1243 ospf_network_free(ospf
, rn
->info
);
1245 route_unlock_node(rn
); /* initial reference */
1247 /* Find interfaces that are not configured already. */
1248 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
)) {
1250 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1253 ospf_network_run_subnet(ospf
, oi
->connected
, NULL
, NULL
);
1256 /* Update connected redistribute. */
1257 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1258 ospf_area_check_free(ospf
, area_id
);
1263 /* Ensure there's an OSPF instance, as "ip ospf area" enabled OSPF means
1264 * there might not be any 'router ospf' config.
1266 * Otherwise, doesn't do anything different to ospf_if_update for now
1268 void ospf_interface_area_set(struct ospf
*ospf
, struct interface
*ifp
)
1273 ospf_if_update(ospf
, ifp
);
1274 /* if_update does a update_redistributed */
1279 void ospf_interface_area_unset(struct ospf
*ospf
, struct interface
*ifp
)
1281 struct route_node
*rn_oi
;
1284 return; /* Ospf not ready yet */
1286 /* Find interfaces that may need to be removed. */
1287 for (rn_oi
= route_top(IF_OIFS(ifp
)); rn_oi
;
1288 rn_oi
= route_next(rn_oi
)) {
1289 struct ospf_interface
*oi
= NULL
;
1291 if ((oi
= rn_oi
->info
) == NULL
)
1294 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
1297 ospf_network_run_subnet(ospf
, oi
->connected
, NULL
, NULL
);
1300 /* Update connected redistribute. */
1301 update_redistributed(ospf
, 0); /* interfaces possibly removed */
1304 /* Check whether interface matches given network
1305 * returns: 1, true. 0, false
1307 static int ospf_network_match_iface(const struct connected
*co
,
1308 const struct prefix
*net
)
1310 /* new approach: more elegant and conceptually clean */
1311 return prefix_match_network_statement(net
, CONNECTED_PREFIX(co
));
1314 static void ospf_update_interface_area(struct connected
*co
,
1315 struct ospf_area
*area
)
1317 struct ospf_interface
*oi
= ospf_if_table_lookup(co
->ifp
, co
->address
);
1319 /* nothing to be done case */
1320 if (oi
&& oi
->area
== area
) {
1327 add_ospf_interface(co
, area
);
1330 /* Run OSPF for the given subnet, taking into account the following
1331 * possible sources of area configuration, in the given order of preference:
1333 * - Whether there is interface+address specific area configuration
1334 * - Whether there is a default area for the interface
1335 * - Whether there is an area given as a parameter.
1336 * - If no specific network prefix/area is supplied, whether there's
1337 * a matching network configured.
1339 static void ospf_network_run_subnet(struct ospf
*ospf
, struct connected
*co
,
1341 struct ospf_area
*given_area
)
1343 struct ospf_interface
*oi
;
1344 struct ospf_if_params
*params
;
1345 struct ospf_area
*area
= NULL
;
1346 struct route_node
*rn
;
1349 if (CHECK_FLAG(co
->flags
, ZEBRA_IFA_SECONDARY
))
1352 if (co
->address
->family
!= AF_INET
)
1355 /* Try determine the appropriate area for this interface + address
1356 * Start by checking interface config
1358 params
= ospf_lookup_if_params(co
->ifp
, co
->address
->u
.prefix4
);
1359 if (params
&& OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1360 area
= ospf_area_get(ospf
, params
->if_area
);
1362 params
= IF_DEF_PARAMS(co
->ifp
);
1363 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
))
1364 area
= ospf_area_get(ospf
, params
->if_area
);
1367 /* If we've found an interface and/or addr specific area, then we're
1371 ospf_update_interface_area(co
, area
);
1375 /* Otherwise, only remaining possibility is a matching network statement
1378 assert(given_area
!= NULL
);
1380 /* Which either was supplied as a parameter.. (e.g. cause a new
1381 * network/area was just added)..
1383 if (p
->family
== co
->address
->family
1384 && ospf_network_match_iface(co
, p
))
1385 ospf_update_interface_area(co
, given_area
);
1390 /* Else we have to search the existing network/area config to see
1393 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
1394 if (rn
->info
!= NULL
&& ospf_network_match_iface(co
, &rn
->p
)) {
1395 struct ospf_network
*network
=
1396 (struct ospf_network
*)rn
->info
;
1397 area
= ospf_area_get(ospf
, network
->area_id
);
1398 ospf_update_interface_area(co
, area
);
1402 /* If the subnet isn't in any area, deconfigure */
1403 if (!configed
&& (oi
= ospf_if_table_lookup(co
->ifp
, co
->address
)))
1407 static void ospf_network_run_interface(struct ospf
*ospf
, struct interface
*ifp
,
1409 struct ospf_area
*given_area
)
1411 struct listnode
*cnode
;
1412 struct connected
*co
;
1414 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
1417 /* Network prefix without area is nonsensical */
1419 assert(given_area
!= NULL
);
1421 /* if interface prefix is match specified prefix,
1422 then create socket and join multicast group. */
1423 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, co
))
1424 ospf_network_run_subnet(ospf
, co
, p
, given_area
);
1427 static void ospf_network_run(struct prefix
*p
, struct ospf_area
*area
)
1429 struct vrf
*vrf
= vrf_lookup_by_id(area
->ospf
->vrf_id
);
1430 struct interface
*ifp
;
1432 /* Schedule Router ID Update. */
1433 if (area
->ospf
->router_id
.s_addr
== INADDR_ANY
)
1434 ospf_router_id_update(area
->ospf
);
1436 /* Get target interface. */
1437 FOR_ALL_INTERFACES (vrf
, ifp
)
1438 ospf_network_run_interface(area
->ospf
, ifp
, p
, area
);
1441 void ospf_ls_upd_queue_empty(struct ospf_interface
*oi
)
1443 struct route_node
*rn
;
1444 struct listnode
*node
, *nnode
;
1446 struct ospf_lsa
*lsa
;
1448 /* empty ls update queue */
1449 for (rn
= route_top(oi
->ls_upd_queue
); rn
; rn
= route_next(rn
))
1450 if ((lst
= (struct list
*)rn
->info
)) {
1451 for (ALL_LIST_ELEMENTS(lst
, node
, nnode
, lsa
))
1452 ospf_lsa_unlock(&lsa
); /* oi->ls_upd_queue */
1457 /* remove update event */
1458 THREAD_OFF(oi
->t_ls_upd_event
);
1461 void ospf_if_update(struct ospf
*ospf
, struct interface
*ifp
)
1467 if (IS_DEBUG_OSPF_EVENT
)
1469 "%s: interface %s vrf %s(%u) ospf vrf %s vrf_id %u router_id %pI4",
1470 __func__
, ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
,
1471 ospf_vrf_id_to_name(ospf
->vrf_id
), ospf
->vrf_id
,
1474 /* OSPF must be ready. */
1475 if (!ospf_is_ready(ospf
))
1478 ospf_network_run_interface(ospf
, ifp
, NULL
, NULL
);
1480 /* Update connected redistribute. */
1481 update_redistributed(ospf
, 1);
1485 void ospf_remove_vls_through_area(struct ospf
*ospf
, struct ospf_area
*area
)
1487 struct listnode
*node
, *nnode
;
1488 struct ospf_vl_data
*vl_data
;
1490 for (ALL_LIST_ELEMENTS(ospf
->vlinks
, node
, nnode
, vl_data
))
1491 if (IPV4_ADDR_SAME(&vl_data
->vl_area_id
, &area
->area_id
))
1492 ospf_vl_delete(ospf
, vl_data
);
1496 static const struct message ospf_area_type_msg
[] = {
1497 {OSPF_AREA_DEFAULT
, "Default"},
1498 {OSPF_AREA_STUB
, "Stub"},
1499 {OSPF_AREA_NSSA
, "NSSA"},
1502 static void ospf_area_type_set(struct ospf_area
*area
, int type
)
1504 struct listnode
*node
;
1505 struct ospf_interface
*oi
;
1507 if (area
->external_routing
== type
) {
1508 if (IS_DEBUG_OSPF_EVENT
)
1509 zlog_debug("Area[%pI4]: Types are the same, ignored.",
1514 area
->external_routing
= type
;
1516 if (IS_DEBUG_OSPF_EVENT
)
1517 zlog_debug("Area[%pI4]: Configured as %s",
1519 lookup_msg(ospf_area_type_msg
, type
, NULL
));
1521 switch (area
->external_routing
) {
1522 case OSPF_AREA_DEFAULT
:
1523 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1524 if (oi
->nbr_self
!= NULL
) {
1525 UNSET_FLAG(oi
->nbr_self
->options
,
1527 SET_FLAG(oi
->nbr_self
->options
, OSPF_OPTION_E
);
1530 case OSPF_AREA_STUB
:
1531 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1532 if (oi
->nbr_self
!= NULL
) {
1533 if (IS_DEBUG_OSPF_EVENT
)
1535 "setting options on %s accordingly",
1537 UNSET_FLAG(oi
->nbr_self
->options
,
1539 UNSET_FLAG(oi
->nbr_self
->options
,
1541 if (IS_DEBUG_OSPF_EVENT
)
1542 zlog_debug("options set on %s: %x",
1543 IF_NAME(oi
), OPTIONS(oi
));
1546 case OSPF_AREA_NSSA
:
1547 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
))
1548 if (oi
->nbr_self
!= NULL
) {
1550 "setting nssa options on %s accordingly",
1552 UNSET_FLAG(oi
->nbr_self
->options
,
1554 SET_FLAG(oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1555 zlog_debug("options set on %s: %x", IF_NAME(oi
),
1563 ospf_router_lsa_update_area(area
);
1564 ospf_schedule_abr_task(area
->ospf
);
1567 int ospf_area_shortcut_set(struct ospf
*ospf
, struct ospf_area
*area
, int mode
)
1569 if (area
->shortcut_configured
== mode
)
1572 area
->shortcut_configured
= mode
;
1573 ospf_router_lsa_update_area(area
);
1574 ospf_schedule_abr_task(ospf
);
1576 ospf_area_check_free(ospf
, area
->area_id
);
1581 int ospf_area_shortcut_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1583 area
->shortcut_configured
= OSPF_SHORTCUT_DEFAULT
;
1584 ospf_router_lsa_update_area(area
);
1585 ospf_area_check_free(ospf
, area
->area_id
);
1586 ospf_schedule_abr_task(ospf
);
1591 static int ospf_area_vlink_count(struct ospf
*ospf
, struct ospf_area
*area
)
1593 struct ospf_vl_data
*vl
;
1594 struct listnode
*node
;
1597 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl
))
1598 if (IPV4_ADDR_SAME(&vl
->vl_area_id
, &area
->area_id
))
1604 int ospf_area_display_format_set(struct ospf
*ospf
, struct ospf_area
*area
,
1607 area
->area_id_fmt
= df
;
1612 int ospf_area_stub_set(struct ospf
*ospf
, struct in_addr area_id
)
1614 struct ospf_area
*area
;
1616 area
= ospf_area_get(ospf
, area_id
);
1617 if (ospf_area_vlink_count(ospf
, area
))
1620 if (area
->external_routing
!= OSPF_AREA_STUB
)
1621 ospf_area_type_set(area
, OSPF_AREA_STUB
);
1626 int ospf_area_stub_unset(struct ospf
*ospf
, struct in_addr area_id
)
1628 struct ospf_area
*area
;
1630 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1634 if (area
->external_routing
== OSPF_AREA_STUB
)
1635 ospf_area_type_set(area
, OSPF_AREA_DEFAULT
);
1637 ospf_area_check_free(ospf
, area_id
);
1642 int ospf_area_no_summary_set(struct ospf
*ospf
, struct in_addr area_id
)
1644 struct ospf_area
*area
;
1646 area
= ospf_area_get(ospf
, area_id
);
1647 area
->no_summary
= 1;
1652 int ospf_area_no_summary_unset(struct ospf
*ospf
, struct in_addr area_id
)
1654 struct ospf_area
*area
;
1656 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1660 area
->no_summary
= 0;
1661 ospf_area_check_free(ospf
, area_id
);
1666 int ospf_area_nssa_no_summary_set(struct ospf
*ospf
, struct in_addr area_id
)
1668 struct ospf_area
*area
;
1670 area
= ospf_area_get(ospf
, area_id
);
1671 if (ospf_area_vlink_count(ospf
, area
))
1674 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1675 ospf_area_type_set(area
, OSPF_AREA_NSSA
);
1677 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1680 ospf_area_no_summary_set(ospf
, area_id
);
1685 int ospf_area_nssa_set(struct ospf
*ospf
, struct in_addr area_id
)
1687 struct ospf_area
*area
;
1689 area
= ospf_area_get(ospf
, area_id
);
1690 if (ospf_area_vlink_count(ospf
, area
))
1693 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1694 ospf_area_type_set(area
, OSPF_AREA_NSSA
);
1697 /* set NSSA area defaults */
1698 area
->no_summary
= 0;
1699 area
->suppress_fa
= 0;
1700 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1701 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1702 area
->NSSATranslatorStabilityInterval
=
1703 OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1708 int ospf_area_nssa_unset(struct ospf
*ospf
, struct in_addr area_id
, int argc
)
1710 struct ospf_area
*area
;
1712 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1716 /* argc < 5 -> 'no area x nssa' */
1717 if (argc
< 5 && area
->external_routing
== OSPF_AREA_NSSA
) {
1719 /* set NSSA area defaults */
1720 area
->no_summary
= 0;
1721 area
->suppress_fa
= 0;
1722 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1723 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1724 area
->NSSATranslatorStabilityInterval
=
1725 OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1726 ospf_area_type_set(area
, OSPF_AREA_DEFAULT
);
1728 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1729 OSPF_NSSA_ROLE_CANDIDATE
);
1732 ospf_area_check_free(ospf
, area_id
);
1737 int ospf_area_nssa_suppress_fa_set(struct ospf
*ospf
, struct in_addr area_id
)
1739 struct ospf_area
*area
;
1741 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1745 area
->suppress_fa
= 1;
1750 int ospf_area_nssa_suppress_fa_unset(struct ospf
*ospf
, struct in_addr area_id
)
1752 struct ospf_area
*area
;
1754 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1758 area
->suppress_fa
= 0;
1763 int ospf_area_nssa_translator_role_set(struct ospf
*ospf
,
1764 struct in_addr area_id
, int role
)
1766 struct ospf_area
*area
;
1768 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1772 if (role
!= area
->NSSATranslatorRole
) {
1773 if ((area
->NSSATranslatorRole
== OSPF_NSSA_ROLE_ALWAYS
)
1774 || (role
== OSPF_NSSA_ROLE_ALWAYS
)) {
1776 * if new role is OSPF_NSSA_ROLE_ALWAYS we need to set
1777 * Nt bit, if the role was OSPF_NSSA_ROLE_ALWAYS we need
1780 area
->NSSATranslatorRole
= role
;
1781 ospf_router_lsa_update_area(area
);
1783 area
->NSSATranslatorRole
= role
;
1789 int ospf_area_export_list_set(struct ospf
*ospf
, struct ospf_area
*area
,
1790 const char *list_name
)
1792 struct access_list
*list
;
1793 list
= access_list_lookup(AFI_IP
, list_name
);
1795 EXPORT_LIST(area
) = list
;
1797 if (EXPORT_NAME(area
))
1798 free(EXPORT_NAME(area
));
1800 EXPORT_NAME(area
) = strdup(list_name
);
1801 ospf_schedule_abr_task(ospf
);
1806 int ospf_area_export_list_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1809 EXPORT_LIST(area
) = 0;
1811 if (EXPORT_NAME(area
))
1812 free(EXPORT_NAME(area
));
1814 EXPORT_NAME(area
) = NULL
;
1816 ospf_area_check_free(ospf
, area
->area_id
);
1818 ospf_schedule_abr_task(ospf
);
1823 int ospf_area_import_list_set(struct ospf
*ospf
, struct ospf_area
*area
,
1826 struct access_list
*list
;
1827 list
= access_list_lookup(AFI_IP
, name
);
1829 IMPORT_LIST(area
) = list
;
1831 if (IMPORT_NAME(area
))
1832 free(IMPORT_NAME(area
));
1834 IMPORT_NAME(area
) = strdup(name
);
1835 ospf_schedule_abr_task(ospf
);
1840 int ospf_area_import_list_unset(struct ospf
*ospf
, struct ospf_area
*area
)
1842 IMPORT_LIST(area
) = 0;
1844 if (IMPORT_NAME(area
))
1845 free(IMPORT_NAME(area
));
1847 IMPORT_NAME(area
) = NULL
;
1848 ospf_area_check_free(ospf
, area
->area_id
);
1850 ospf_schedule_abr_task(ospf
);
1855 int ospf_timers_refresh_set(struct ospf
*ospf
, int interval
)
1859 if (ospf
->lsa_refresh_interval
== interval
)
1862 time_left
= ospf
->lsa_refresh_interval
1863 - (monotime(NULL
) - ospf
->lsa_refresher_started
);
1865 if (time_left
> interval
) {
1866 THREAD_OFF(ospf
->t_lsa_refresher
);
1867 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1868 interval
, &ospf
->t_lsa_refresher
);
1870 ospf
->lsa_refresh_interval
= interval
;
1875 int ospf_timers_refresh_unset(struct ospf
*ospf
)
1879 time_left
= ospf
->lsa_refresh_interval
1880 - (monotime(NULL
) - ospf
->lsa_refresher_started
);
1882 if (time_left
> OSPF_LSA_REFRESH_INTERVAL_DEFAULT
) {
1883 THREAD_OFF(ospf
->t_lsa_refresher
);
1884 ospf
->t_lsa_refresher
= NULL
;
1885 thread_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
1886 OSPF_LSA_REFRESH_INTERVAL_DEFAULT
,
1887 &ospf
->t_lsa_refresher
);
1890 ospf
->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
1896 static struct ospf_nbr_nbma
*ospf_nbr_nbma_new(void)
1898 struct ospf_nbr_nbma
*nbr_nbma
;
1900 nbr_nbma
= XCALLOC(MTYPE_OSPF_NEIGHBOR_STATIC
,
1901 sizeof(struct ospf_nbr_nbma
));
1903 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1904 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1909 static void ospf_nbr_nbma_free(struct ospf_nbr_nbma
*nbr_nbma
)
1911 XFREE(MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
1914 static void ospf_nbr_nbma_delete(struct ospf
*ospf
,
1915 struct ospf_nbr_nbma
*nbr_nbma
)
1917 struct route_node
*rn
;
1918 struct prefix_ipv4 p
;
1921 p
.prefix
= nbr_nbma
->addr
;
1922 p
.prefixlen
= IPV4_MAX_BITLEN
;
1924 rn
= route_node_lookup(ospf
->nbr_nbma
, (struct prefix
*)&p
);
1926 ospf_nbr_nbma_free(rn
->info
);
1928 route_unlock_node(rn
);
1929 route_unlock_node(rn
);
1933 static void ospf_nbr_nbma_down(struct ospf_nbr_nbma
*nbr_nbma
)
1935 THREAD_OFF(nbr_nbma
->t_poll
);
1937 if (nbr_nbma
->nbr
) {
1938 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
1939 OSPF_NSM_EVENT_EXECUTE(nbr_nbma
->nbr
, NSM_KillNbr
);
1943 listnode_delete(nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
1946 static void ospf_nbr_nbma_add(struct ospf_nbr_nbma
*nbr_nbma
,
1947 struct ospf_interface
*oi
)
1949 struct ospf_neighbor
*nbr
;
1950 struct route_node
*rn
;
1953 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1956 if (nbr_nbma
->nbr
!= NULL
)
1959 if (IPV4_ADDR_SAME(&oi
->nbr_self
->address
.u
.prefix4
, &nbr_nbma
->addr
))
1963 listnode_add(oi
->nbr_nbma
, nbr_nbma
);
1965 /* Get neighbor information from table. */
1967 p
.prefixlen
= IPV4_MAX_BITLEN
;
1968 p
.u
.prefix4
= nbr_nbma
->addr
;
1970 rn
= route_node_get(oi
->nbrs
, &p
);
1973 nbr
->nbr_nbma
= nbr_nbma
;
1974 nbr_nbma
->nbr
= nbr
;
1976 route_unlock_node(rn
);
1978 nbr
= rn
->info
= ospf_nbr_new(oi
);
1979 nbr
->state
= NSM_Down
;
1980 nbr
->src
= nbr_nbma
->addr
;
1981 nbr
->nbr_nbma
= nbr_nbma
;
1982 nbr
->priority
= nbr_nbma
->priority
;
1985 nbr_nbma
->nbr
= nbr
;
1987 /* Configure BFD if interface has it. */
1988 ospf_neighbor_bfd_apply(nbr
);
1990 OSPF_NSM_EVENT_EXECUTE(nbr
, NSM_Start
);
1994 void ospf_nbr_nbma_if_update(struct ospf
*ospf
, struct ospf_interface
*oi
)
1996 struct ospf_nbr_nbma
*nbr_nbma
;
1997 struct route_node
*rn
;
1998 struct prefix_ipv4 p
;
2000 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
2003 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
2004 if ((nbr_nbma
= rn
->info
))
2005 if (nbr_nbma
->oi
== NULL
&& nbr_nbma
->nbr
== NULL
) {
2007 p
.prefix
= nbr_nbma
->addr
;
2008 p
.prefixlen
= IPV4_MAX_BITLEN
;
2010 if (prefix_match(oi
->address
,
2011 (struct prefix
*)&p
))
2012 ospf_nbr_nbma_add(nbr_nbma
, oi
);
2016 struct ospf_nbr_nbma
*ospf_nbr_nbma_lookup(struct ospf
*ospf
,
2017 struct in_addr nbr_addr
)
2019 struct route_node
*rn
;
2020 struct prefix_ipv4 p
;
2023 p
.prefix
= nbr_addr
;
2024 p
.prefixlen
= IPV4_MAX_BITLEN
;
2026 rn
= route_node_lookup(ospf
->nbr_nbma
, (struct prefix
*)&p
);
2028 route_unlock_node(rn
);
2034 int ospf_nbr_nbma_set(struct ospf
*ospf
, struct in_addr nbr_addr
)
2036 struct ospf_nbr_nbma
*nbr_nbma
;
2037 struct ospf_interface
*oi
;
2038 struct prefix_ipv4 p
;
2039 struct route_node
*rn
;
2040 struct listnode
*node
;
2042 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2046 nbr_nbma
= ospf_nbr_nbma_new();
2047 nbr_nbma
->addr
= nbr_addr
;
2050 p
.prefix
= nbr_addr
;
2051 p
.prefixlen
= IPV4_MAX_BITLEN
;
2053 rn
= route_node_get(ospf
->nbr_nbma
, (struct prefix
*)&p
);
2055 route_unlock_node(rn
);
2056 rn
->info
= nbr_nbma
;
2058 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
2059 if (oi
->type
== OSPF_IFTYPE_NBMA
)
2060 if (prefix_match(oi
->address
, (struct prefix
*)&p
)) {
2061 ospf_nbr_nbma_add(nbr_nbma
, oi
);
2069 int ospf_nbr_nbma_unset(struct ospf
*ospf
, struct in_addr nbr_addr
)
2071 struct ospf_nbr_nbma
*nbr_nbma
;
2073 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2074 if (nbr_nbma
== NULL
)
2077 ospf_nbr_nbma_down(nbr_nbma
);
2078 ospf_nbr_nbma_delete(ospf
, nbr_nbma
);
2083 int ospf_nbr_nbma_priority_set(struct ospf
*ospf
, struct in_addr nbr_addr
,
2086 struct ospf_nbr_nbma
*nbr_nbma
;
2088 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2089 if (nbr_nbma
== NULL
)
2092 if (nbr_nbma
->priority
!= priority
)
2093 nbr_nbma
->priority
= priority
;
2098 int ospf_nbr_nbma_priority_unset(struct ospf
*ospf
, struct in_addr nbr_addr
)
2100 struct ospf_nbr_nbma
*nbr_nbma
;
2102 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2103 if (nbr_nbma
== NULL
)
2106 if (nbr_nbma
!= OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
2107 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2112 int ospf_nbr_nbma_poll_interval_set(struct ospf
*ospf
, struct in_addr nbr_addr
,
2113 unsigned int interval
)
2115 struct ospf_nbr_nbma
*nbr_nbma
;
2117 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, nbr_addr
);
2118 if (nbr_nbma
== NULL
)
2121 if (nbr_nbma
->v_poll
!= interval
) {
2122 nbr_nbma
->v_poll
= interval
;
2123 if (nbr_nbma
->oi
&& ospf_if_is_up(nbr_nbma
->oi
)) {
2124 THREAD_OFF(nbr_nbma
->t_poll
);
2125 OSPF_POLL_TIMER_ON(nbr_nbma
->t_poll
, ospf_poll_timer
,
2133 int ospf_nbr_nbma_poll_interval_unset(struct ospf
*ospf
, struct in_addr addr
)
2135 struct ospf_nbr_nbma
*nbr_nbma
;
2137 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, addr
);
2138 if (nbr_nbma
== NULL
)
2141 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
2142 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
2147 void ospf_master_init(struct thread_master
*master
)
2149 memset(&ospf_master
, 0, sizeof(ospf_master
));
2152 om
->ospf
= list_new();
2153 om
->master
= master
;
2156 /* Link OSPF instance to VRF. */
2157 void ospf_vrf_link(struct ospf
*ospf
, struct vrf
*vrf
)
2159 ospf
->vrf_id
= vrf
->vrf_id
;
2160 if (vrf
->info
!= (void *)ospf
)
2161 vrf
->info
= (void *)ospf
;
2164 /* Unlink OSPF instance from VRF. */
2165 void ospf_vrf_unlink(struct ospf
*ospf
, struct vrf
*vrf
)
2167 if (vrf
->info
== (void *)ospf
)
2169 ospf
->vrf_id
= VRF_UNKNOWN
;
2172 /* This is hook function for vrf create called as part of vrf_init */
2173 static int ospf_vrf_new(struct vrf
*vrf
)
2175 if (IS_DEBUG_OSPF_EVENT
)
2176 zlog_debug("%s: VRF Created: %s(%u)", __func__
, vrf
->name
,
2182 /* This is hook function for vrf delete call as part of vrf_init */
2183 static int ospf_vrf_delete(struct vrf
*vrf
)
2185 if (IS_DEBUG_OSPF_EVENT
)
2186 zlog_debug("%s: VRF Deletion: %s(%u)", __func__
, vrf
->name
,
2192 static void ospf_set_redist_vrf_bitmaps(struct ospf
*ospf
, bool set
)
2195 struct list
*red_list
;
2197 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
2198 red_list
= ospf
->redist
[type
];
2201 if (IS_DEBUG_OSPF_EVENT
)
2203 "%s: setting redist vrf %d bitmap for type %d",
2204 __func__
, ospf
->vrf_id
, type
);
2206 vrf_bitmap_set(zclient
->redist
[AFI_IP
][type
],
2209 vrf_bitmap_unset(zclient
->redist
[AFI_IP
][type
],
2213 red_list
= ospf
->redist
[DEFAULT_ROUTE
];
2216 vrf_bitmap_set(zclient
->default_information
[AFI_IP
],
2219 vrf_bitmap_unset(zclient
->default_information
[AFI_IP
],
2224 /* Enable OSPF VRF instance */
2225 static int ospf_vrf_enable(struct vrf
*vrf
)
2227 struct ospf
*ospf
= NULL
;
2228 vrf_id_t old_vrf_id
;
2231 if (IS_DEBUG_OSPF_EVENT
)
2232 zlog_debug("%s: VRF %s id %u enabled", __func__
, vrf
->name
,
2235 ospf
= ospf_lookup_by_name(vrf
->name
);
2237 old_vrf_id
= ospf
->vrf_id
;
2238 /* We have instance configured, link to VRF and make it "up". */
2239 ospf_vrf_link(ospf
, vrf
);
2240 if (IS_DEBUG_OSPF_EVENT
)
2242 "%s: ospf linked to vrf %s vrf_id %u (old id %u)",
2243 __func__
, vrf
->name
, ospf
->vrf_id
, old_vrf_id
);
2245 if (old_vrf_id
!= ospf
->vrf_id
) {
2246 ospf_set_redist_vrf_bitmaps(ospf
, true);
2248 /* start zebra redist to us for new vrf */
2249 ospf_zebra_vrf_register(ospf
);
2251 ret
= ospf_sock_init(ospf
);
2252 if (ret
< 0 || ospf
->fd
<= 0)
2254 thread_add_read(master
, ospf_read
, ospf
, ospf
->fd
,
2256 ospf
->oi_running
= 1;
2257 ospf_router_id_update(ospf
);
2264 /* Disable OSPF VRF instance */
2265 static int ospf_vrf_disable(struct vrf
*vrf
)
2267 struct ospf
*ospf
= NULL
;
2268 vrf_id_t old_vrf_id
= VRF_UNKNOWN
;
2270 if (vrf
->vrf_id
== VRF_DEFAULT
)
2273 if (IS_DEBUG_OSPF_EVENT
)
2274 zlog_debug("%s: VRF %s id %d disabled.", __func__
, vrf
->name
,
2277 ospf
= ospf_lookup_by_name(vrf
->name
);
2279 old_vrf_id
= ospf
->vrf_id
;
2281 ospf_zebra_vrf_deregister(ospf
);
2283 ospf_set_redist_vrf_bitmaps(ospf
, false);
2285 /* We have instance configured, unlink
2286 * from VRF and make it "down".
2288 ospf_vrf_unlink(ospf
, vrf
);
2289 ospf
->oi_running
= 0;
2290 if (IS_DEBUG_OSPF_EVENT
)
2291 zlog_debug("%s: ospf old_vrf_id %d unlinked", __func__
,
2293 THREAD_OFF(ospf
->t_read
);
2298 /* Note: This is a callback, the VRF will be deleted by the caller. */
2302 void ospf_vrf_init(void)
2304 vrf_init(ospf_vrf_new
, ospf_vrf_enable
, ospf_vrf_disable
,
2308 void ospf_vrf_terminate(void)
2313 const char *ospf_vrf_id_to_name(vrf_id_t vrf_id
)
2315 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
2317 return vrf
? vrf
->name
: "NIL";
2320 const char *ospf_get_name(const struct ospf
*ospf
)
2325 return VRF_DEFAULT_NAME
;