1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 1999, 2000 Alex Zinin, Toshiaki Takada
21 #include "ospfd/ospfd.h"
22 #include "ospfd/ospf_interface.h"
23 #include "ospfd/ospf_ism.h"
24 #include "ospfd/ospf_asbr.h"
25 #include "ospfd/ospf_lsa.h"
26 #include "ospfd/ospf_lsdb.h"
27 #include "ospfd/ospf_neighbor.h"
28 #include "ospfd/ospf_nsm.h"
29 #include "ospfd/ospf_spf.h"
30 #include "ospfd/ospf_route.h"
31 #include "ospfd/ospf_ia.h"
32 #include "ospfd/ospf_flood.h"
33 #include "ospfd/ospf_abr.h"
34 #include "ospfd/ospf_ase.h"
35 #include "ospfd/ospf_zebra.h"
36 #include "ospfd/ospf_dump.h"
37 #include "ospfd/ospf_errors.h"
39 static struct ospf_area_range
*ospf_area_range_new(struct prefix_ipv4
*p
)
41 struct ospf_area_range
*range
;
43 range
= XCALLOC(MTYPE_OSPF_AREA_RANGE
, sizeof(struct ospf_area_range
));
44 range
->addr
= p
->prefix
;
45 range
->masklen
= p
->prefixlen
;
46 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
51 static void ospf_area_range_free(struct ospf_area_range
*range
)
53 XFREE(MTYPE_OSPF_AREA_RANGE
, range
);
56 static void ospf_area_range_add(struct ospf_area
*area
,
57 struct ospf_area_range
*range
)
59 struct route_node
*rn
;
63 p
.prefixlen
= range
->masklen
;
64 p
.prefix
= range
->addr
;
67 rn
= route_node_get(area
->ranges
, (struct prefix
*)&p
);
69 route_unlock_node(rn
);
74 static void ospf_area_range_delete(struct ospf_area
*area
,
75 struct route_node
*rn
)
77 struct ospf_area_range
*range
= rn
->info
;
79 if (range
->specifics
!= 0)
80 ospf_delete_discard_route(area
->ospf
, area
->ospf
->new_table
,
81 (struct prefix_ipv4
*)&rn
->p
);
83 ospf_area_range_free(range
);
85 route_unlock_node(rn
);
86 route_unlock_node(rn
);
89 struct ospf_area_range
*ospf_area_range_lookup(struct ospf_area
*area
,
90 struct prefix_ipv4
*p
)
92 struct route_node
*rn
;
94 rn
= route_node_lookup(area
->ranges
, (struct prefix
*)p
);
96 route_unlock_node(rn
);
102 struct ospf_area_range
*ospf_area_range_lookup_next(struct ospf_area
*area
,
103 struct in_addr
*range_net
,
106 struct route_node
*rn
;
107 struct prefix_ipv4 p
;
108 struct ospf_area_range
*find
;
111 p
.prefixlen
= IPV4_MAX_BITLEN
;
112 p
.prefix
= *range_net
;
116 rn
= route_top(area
->ranges
);
118 rn
= route_node_get(area
->ranges
, (struct prefix
*)&p
);
122 for (; rn
; rn
= route_next(rn
))
126 if (rn
&& rn
->info
) {
128 *range_net
= rn
->p
.u
.prefix4
;
129 route_unlock_node(rn
);
135 static struct ospf_area_range
*ospf_area_range_match(struct ospf_area
*area
,
136 struct prefix_ipv4
*p
)
138 struct route_node
*node
;
140 node
= route_node_match(area
->ranges
, (struct prefix
*)p
);
142 route_unlock_node(node
);
148 struct ospf_area_range
*ospf_area_range_match_any(struct ospf
*ospf
,
149 struct prefix_ipv4
*p
)
151 struct ospf_area_range
*range
;
152 struct ospf_area
*area
;
153 struct listnode
*node
;
155 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
156 if ((range
= ospf_area_range_match(area
, p
)))
162 int ospf_area_range_active(struct ospf_area_range
*range
)
164 return range
->specifics
;
167 static int ospf_area_actively_attached(struct ospf_area
*area
)
169 return area
->act_ints
;
172 int ospf_area_range_set(struct ospf
*ospf
, struct in_addr area_id
,
173 struct prefix_ipv4
*p
, int advertise
)
175 struct ospf_area
*area
;
176 struct ospf_area_range
*range
;
178 area
= ospf_area_get(ospf
, area_id
);
182 range
= ospf_area_range_lookup(area
, p
);
184 if (!CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
185 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
186 if ((CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
187 && !CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
188 || (!CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
189 && CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
)))
190 ospf_schedule_abr_task(ospf
);
192 range
= ospf_area_range_new(p
);
193 ospf_area_range_add(area
, range
);
194 ospf_schedule_abr_task(ospf
);
197 if (CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
198 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
200 UNSET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
201 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
207 int ospf_area_range_cost_set(struct ospf
*ospf
, struct in_addr area_id
,
208 struct prefix_ipv4
*p
, uint32_t cost
)
210 struct ospf_area
*area
;
211 struct ospf_area_range
*range
;
213 area
= ospf_area_get(ospf
, area_id
);
217 range
= ospf_area_range_lookup(area
, p
);
221 if (range
->cost_config
!= cost
) {
222 range
->cost_config
= cost
;
223 if (ospf_area_range_active(range
))
224 ospf_schedule_abr_task(ospf
);
230 int ospf_area_range_unset(struct ospf
*ospf
, struct in_addr area_id
,
231 struct prefix_ipv4
*p
)
233 struct ospf_area
*area
;
234 struct route_node
*rn
;
236 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
240 rn
= route_node_lookup(area
->ranges
, (struct prefix
*)p
);
244 if (ospf_area_range_active(rn
->info
))
245 ospf_schedule_abr_task(ospf
);
247 ospf_area_range_delete(area
, rn
);
252 int ospf_area_range_substitute_set(struct ospf
*ospf
, struct in_addr area_id
,
253 struct prefix_ipv4
*p
, struct prefix_ipv4
*s
)
255 struct ospf_area
*area
;
256 struct ospf_area_range
*range
;
258 area
= ospf_area_get(ospf
, area_id
);
259 range
= ospf_area_range_lookup(area
, p
);
262 if (!CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
263 || !CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
264 ospf_schedule_abr_task(ospf
);
266 range
= ospf_area_range_new(p
);
267 ospf_area_range_add(area
, range
);
268 ospf_schedule_abr_task(ospf
);
271 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
272 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
273 range
->subst_addr
= s
->prefix
;
274 range
->subst_masklen
= s
->prefixlen
;
279 int ospf_area_range_substitute_unset(struct ospf
*ospf
, struct in_addr area_id
,
280 struct prefix_ipv4
*p
)
282 struct ospf_area
*area
;
283 struct ospf_area_range
*range
;
285 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
289 range
= ospf_area_range_lookup(area
, p
);
293 if (CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
294 if (ospf_area_range_active(range
))
295 ospf_schedule_abr_task(ospf
);
297 UNSET_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
298 range
->subst_addr
.s_addr
= INADDR_ANY
;
299 range
->subst_masklen
= 0;
304 int ospf_act_bb_connection(struct ospf
*ospf
)
306 struct ospf_interface
*oi
;
307 struct listnode
*node
;
310 if (ospf
->backbone
== NULL
)
313 for (ALL_LIST_ELEMENTS_RO(ospf
->backbone
->oiflist
, node
, oi
)) {
314 struct ospf_neighbor
*nbr
;
315 struct route_node
*rn
;
317 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
322 if (nbr
->state
== NSM_Full
323 || OSPF_GR_IS_ACTIVE_HELPER(nbr
))
331 /* Determine whether this router is elected translator or not for area */
332 static int ospf_abr_nssa_am_elected(struct ospf_area
*area
)
334 struct route_node
*rn
;
335 struct ospf_lsa
*lsa
;
336 struct router_lsa
*rlsa
;
337 struct in_addr
*best
= NULL
;
339 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
) {
341 if (!lsa
|| (lsa
->data
->type
!= OSPF_ROUTER_LSA
)
345 rlsa
= (struct router_lsa
*)lsa
->data
;
347 /* ignore non-ABR routers */
348 if (!IS_ROUTER_LSA_BORDER(rlsa
))
351 /* Router has Nt flag - always translate */
352 if (IS_ROUTER_LSA_NT(rlsa
)) {
353 if (IS_DEBUG_OSPF_NSSA
)
354 zlog_debug("%s: router %pI4 asserts Nt",
355 __func__
, &lsa
->data
->id
);
360 best
= &lsa
->data
->id
;
361 else if (IPV4_ADDR_CMP(&best
->s_addr
, &lsa
->data
->id
.s_addr
)
363 best
= &lsa
->data
->id
;
366 if (IS_DEBUG_OSPF_NSSA
)
367 zlog_debug("%s: best electable ABR is: %pI4", __func__
, best
);
372 if (IPV4_ADDR_CMP(&best
->s_addr
, &area
->ospf
->router_id
.s_addr
) < 0)
378 /* Check NSSA ABR status
379 * assumes there are nssa areas
381 void ospf_abr_nssa_check_status(struct ospf
*ospf
)
383 struct ospf_area
*area
;
384 struct listnode
*lnode
, *nnode
;
386 for (ALL_LIST_ELEMENTS(ospf
->areas
, lnode
, nnode
, area
)) {
387 uint8_t old_state
= area
->NSSATranslatorState
;
389 if (area
->external_routing
!= OSPF_AREA_NSSA
)
392 if (IS_DEBUG_OSPF(nssa
, NSSA
))
393 zlog_debug("%s: checking area %pI4", __func__
,
396 if (!IS_OSPF_ABR(area
->ospf
)) {
397 if (IS_DEBUG_OSPF(nssa
, NSSA
))
398 zlog_debug("%s: not ABR", __func__
);
399 area
->NSSATranslatorState
=
400 OSPF_NSSA_TRANSLATE_DISABLED
;
402 switch (area
->NSSATranslatorRole
) {
403 case OSPF_NSSA_ROLE_NEVER
:
404 /* We never Translate Type-7 LSA. */
405 /* TODO: check previous state and flush? */
406 if (IS_DEBUG_OSPF(nssa
, NSSA
))
407 zlog_debug("%s: never translate",
409 area
->NSSATranslatorState
=
410 OSPF_NSSA_TRANSLATE_DISABLED
;
413 case OSPF_NSSA_ROLE_ALWAYS
:
414 /* We always translate if we are an ABR
415 * TODO: originate new LSAs if state change?
416 * or let the nssa abr task take care of it?
418 if (IS_DEBUG_OSPF(nssa
, NSSA
))
419 zlog_debug("%s: translate always",
421 area
->NSSATranslatorState
=
422 OSPF_NSSA_TRANSLATE_ENABLED
;
425 case OSPF_NSSA_ROLE_CANDIDATE
:
426 /* We are a candidate for Translation */
427 if (ospf_abr_nssa_am_elected(area
) > 0) {
428 area
->NSSATranslatorState
=
429 OSPF_NSSA_TRANSLATE_ENABLED
;
430 if (IS_DEBUG_OSPF(nssa
, NSSA
))
432 "%s: elected translator",
435 area
->NSSATranslatorState
=
436 OSPF_NSSA_TRANSLATE_DISABLED
;
437 if (IS_DEBUG_OSPF(nssa
, NSSA
))
438 zlog_debug("%s: not elected",
445 * All NSSA border routers must set the E-bit in the Type-1
447 * of their directly attached non-stub areas, even when they are
451 if (old_state
!= area
->NSSATranslatorState
) {
452 if (old_state
== OSPF_NSSA_TRANSLATE_DISABLED
)
453 ospf_asbr_status_update(ospf
,
454 ++ospf
->redistribute
);
455 else if (area
->NSSATranslatorState
456 == OSPF_NSSA_TRANSLATE_DISABLED
)
457 ospf_asbr_status_update(ospf
,
458 --ospf
->redistribute
);
463 /* Check area border router status. */
464 void ospf_check_abr_status(struct ospf
*ospf
)
466 struct ospf_area
*area
;
467 struct listnode
*node
, *nnode
;
468 int bb_configured
= 0;
469 int bb_act_attached
= 0;
470 int areas_configured
= 0;
471 int areas_act_attached
= 0;
472 uint8_t new_flags
= ospf
->flags
;
474 if (IS_DEBUG_OSPF_EVENT
)
475 zlog_debug("%s: Start", __func__
);
477 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
478 if (listcount(area
->oiflist
)) {
481 if (OSPF_IS_AREA_BACKBONE(area
))
485 if (ospf_area_actively_attached(area
)) {
486 areas_act_attached
++;
488 if (OSPF_IS_AREA_BACKBONE(area
))
493 if (IS_DEBUG_OSPF_EVENT
) {
494 zlog_debug("%s: looked through areas", __func__
);
495 zlog_debug("%s: bb_configured: %d", __func__
, bb_configured
);
496 zlog_debug("%s: bb_act_attached: %d", __func__
,
498 zlog_debug("%s: areas_configured: %d", __func__
,
500 zlog_debug("%s: areas_act_attached: %d", __func__
,
504 switch (ospf
->abr_type
) {
505 case OSPF_ABR_SHORTCUT
:
507 if (areas_act_attached
> 1)
508 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
510 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
514 if ((areas_act_attached
> 1) && bb_configured
)
515 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
517 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
521 if ((areas_configured
> 1) && bb_act_attached
)
522 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
524 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
530 if (new_flags
!= ospf
->flags
) {
531 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_ABR_STATUS_CHANGE
);
532 if (IS_DEBUG_OSPF_EVENT
)
533 zlog_debug("%s: new router flags: %x", __func__
,
535 ospf
->flags
= new_flags
;
536 ospf_router_lsa_update(ospf
);
540 static void ospf_abr_update_aggregate(struct ospf_area_range
*range
,
541 struct ospf_route
* or,
542 struct ospf_area
*area
)
544 if (IS_DEBUG_OSPF_EVENT
)
545 zlog_debug("%s: Start", __func__
);
547 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)
548 && (range
->cost
!= OSPF_STUB_MAX_METRIC_SUMMARY_COST
)) {
549 range
->cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
550 if (IS_DEBUG_OSPF_EVENT
)
551 zlog_debug("%s: use summary max-metric 0x%08x",
552 __func__
, range
->cost
);
553 } else if (range
->cost_config
!= OSPF_AREA_RANGE_COST_UNSPEC
) {
554 if (IS_DEBUG_OSPF_EVENT
)
555 zlog_debug("%s: use configured cost %d", __func__
,
558 range
->cost
= range
->cost_config
;
560 if (range
->specifics
== 0) {
561 if (IS_DEBUG_OSPF_EVENT
)
562 zlog_debug("%s: use or->cost %d", __func__
,
565 range
->cost
= or->cost
; /* 1st time get 1st cost */
568 if (or->cost
> range
->cost
) {
569 if (IS_DEBUG_OSPF_EVENT
)
570 zlog_debug("%s: update to %d", __func__
,
573 range
->cost
= or->cost
;
580 static void set_metric(struct ospf_lsa
*lsa
, uint32_t metric
)
582 struct summary_lsa
*header
;
584 metric
= htonl(metric
);
585 mp
= (uint8_t *)&metric
;
587 header
= (struct summary_lsa
*)lsa
->data
;
588 memcpy(header
->metric
, mp
, 3);
591 /* ospf_abr_translate_nssa */
592 static int ospf_abr_translate_nssa(struct ospf_area
*area
, struct ospf_lsa
*lsa
)
594 /* Incoming Type-7 or later aggregated Type-7
596 * LSA is skipped if P-bit is off.
597 * LSA is aggregated if within range.
599 * The Type-7 is translated, Installed/Approved as a Type-5 into
600 * global LSDB, then Flooded through AS
602 * Later, any Unapproved Translated Type-5's are flushed/discarded
605 struct ospf_lsa
*old
= NULL
, *new = NULL
;
606 struct as_external_lsa
*ext7
;
607 struct prefix_ipv4 p
;
609 if (!CHECK_FLAG(lsa
->data
->options
, OSPF_OPTION_NP
)) {
610 if (IS_DEBUG_OSPF_NSSA
)
611 zlog_debug("%s: LSA Id %pI4, P-bit off, NO Translation",
612 __func__
, &lsa
->data
->id
);
616 if (IS_DEBUG_OSPF_NSSA
)
617 zlog_debug("%s: LSA Id %pI4, TRANSLATING 7 to 5", __func__
,
620 ext7
= (struct as_external_lsa
*)(lsa
->data
);
621 p
.prefix
= lsa
->data
->id
;
622 p
.prefixlen
= ip_masklen(ext7
->mask
);
624 if (ext7
->e
[0].fwd_addr
.s_addr
== OSPF_DEFAULT_DESTINATION
) {
625 if (IS_DEBUG_OSPF_NSSA
)
627 "%s: LSA Id %pI4, Forward address is 0, NO Translation",
628 __func__
, &lsa
->data
->id
);
632 /* try find existing AS-External LSA for this prefix */
633 old
= ospf_external_info_find_lsa(area
->ospf
, &p
);
635 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_IN_MAXAGE
)) {
636 /* if type-7 is removed, remove old translated type-5 lsa */
638 UNSET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
639 if (IS_DEBUG_OSPF_NSSA
)
641 "%s: remove old translated LSA id %pI4",
642 __func__
, &old
->data
->id
);
644 /* if type-7 is removed and type-5 does not exist, do not
649 if (old
&& CHECK_FLAG(old
->flags
, OSPF_LSA_APPROVED
)) {
650 if (IS_DEBUG_OSPF_NSSA
)
652 "%s: found old translated LSA Id %pI4, refreshing",
653 __func__
, &old
->data
->id
);
656 new = ospf_translated_nssa_refresh(area
->ospf
, lsa
, old
);
658 if (IS_DEBUG_OSPF_NSSA
)
660 "%s: could not refresh translated LSA Id %pI4",
661 __func__
, &old
->data
->id
);
664 /* no existing external route for this LSA Id
665 * originate translated LSA
668 if (ospf_translated_nssa_originate(area
->ospf
, lsa
, old
)
670 if (IS_DEBUG_OSPF_NSSA
)
672 "%s: Could not translate Type-7 for %pI4 to Type-5",
673 __func__
, &lsa
->data
->id
);
678 /* Area where Aggregate testing will be inserted, just like summary
680 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
685 static void ospf_abr_translate_nssa_range(struct prefix_ipv4
*p
, uint32_t cost
)
687 /* The Type-7 is created from the aggregated prefix and forwarded
688 for lsa installation and flooding... to be added... */
691 void ospf_abr_announce_network_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
692 struct ospf_area
*area
)
694 struct ospf_lsa
*lsa
, *old
= NULL
;
695 struct summary_lsa
*sl
= NULL
;
698 if (IS_DEBUG_OSPF_EVENT
)
699 zlog_debug("%s: Start", __func__
);
701 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
702 full_cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
706 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_SUMMARY_LSA
, p
,
707 area
->ospf
->router_id
);
709 if (IS_DEBUG_OSPF_EVENT
)
710 zlog_debug("%s: old summary found", __func__
);
712 sl
= (struct summary_lsa
*)old
->data
;
714 if (IS_DEBUG_OSPF_EVENT
)
715 zlog_debug("%s: old metric: %d, new metric: %d",
716 __func__
, GET_METRIC(sl
->metric
), cost
);
718 if ((GET_METRIC(sl
->metric
) == full_cost
)
719 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
720 /* unchanged. simply reapprove it */
721 if (IS_DEBUG_OSPF_EVENT
)
722 zlog_debug("%s: old summary approved",
724 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
726 /* LSA is changed, refresh it */
727 if (IS_DEBUG_OSPF_EVENT
)
728 zlog_debug("%s: refreshing summary", __func__
);
729 set_metric(old
, full_cost
);
730 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
733 flog_warn(EC_OSPF_LSA_MISSING
,
734 "%s: Could not refresh %pFX to %pI4",
735 __func__
, (struct prefix
*)p
,
740 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
741 /* This will flood through area. */
744 if (IS_DEBUG_OSPF_EVENT
)
745 zlog_debug("%s: creating new summary", __func__
);
746 lsa
= ospf_summary_lsa_originate(p
, full_cost
, area
);
747 /* This will flood through area. */
750 flog_warn(EC_OSPF_LSA_MISSING
,
751 "%s: Could not originate %pFX to %pi4",
752 __func__
, (struct prefix
*)p
,
757 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
758 if (IS_DEBUG_OSPF_EVENT
)
759 zlog_debug("%s: flooding new version of summary",
763 if (IS_DEBUG_OSPF_EVENT
)
764 zlog_debug("%s: Stop", __func__
);
767 static int ospf_abr_nexthops_belong_to_area(struct ospf_route
* or,
768 struct ospf_area
*area
)
770 struct listnode
*node
, *nnode
;
771 struct ospf_path
*path
;
772 struct ospf_interface
*oi
;
774 for (ALL_LIST_ELEMENTS_RO(or->paths
, node
, path
))
775 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, nnode
, oi
))
776 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
782 static int ospf_abr_should_accept(struct prefix_ipv4
*p
, struct ospf_area
*area
)
784 if (IMPORT_NAME(area
)) {
785 if (IMPORT_LIST(area
) == NULL
)
787 access_list_lookup(AFI_IP
, IMPORT_NAME(area
));
789 if (IMPORT_LIST(area
))
790 if (access_list_apply(IMPORT_LIST(area
), p
)
798 static int ospf_abr_plist_in_check(struct ospf_area
*area
,
799 struct ospf_route
* or,
800 struct prefix_ipv4
*p
)
802 if (PREFIX_NAME_IN(area
)) {
803 if (PREFIX_LIST_IN(area
) == NULL
)
804 PREFIX_LIST_IN(area
) = prefix_list_lookup(
805 AFI_IP
, PREFIX_NAME_IN(area
));
806 if (PREFIX_LIST_IN(area
))
807 if (prefix_list_apply(PREFIX_LIST_IN(area
), p
)
814 static int ospf_abr_plist_out_check(struct ospf_area
*area
,
815 struct ospf_route
* or,
816 struct prefix_ipv4
*p
)
818 if (PREFIX_NAME_OUT(area
)) {
819 if (PREFIX_LIST_OUT(area
) == NULL
)
820 PREFIX_LIST_OUT(area
) = prefix_list_lookup(
821 AFI_IP
, PREFIX_NAME_OUT(area
));
822 if (PREFIX_LIST_OUT(area
))
823 if (prefix_list_apply(PREFIX_LIST_OUT(area
), p
)
830 static void ospf_abr_announce_network(struct ospf
*ospf
, struct prefix_ipv4
*p
,
831 struct ospf_route
* or)
833 struct ospf_area_range
*range
;
834 struct ospf_area
*area
, *or_area
;
835 struct listnode
*node
;
837 if (IS_DEBUG_OSPF_EVENT
)
838 zlog_debug("%s: Start", __func__
);
840 or_area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
843 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
844 if (IS_DEBUG_OSPF_EVENT
)
845 zlog_debug("%s: looking at area %pI4", __func__
,
848 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
851 if (ospf_abr_nexthops_belong_to_area(or, area
))
854 if (!ospf_abr_should_accept(p
, area
)) {
855 if (IS_DEBUG_OSPF_EVENT
)
857 "%s: prefix %pFX was denied by import-list",
862 if (!ospf_abr_plist_in_check(area
, or, p
)) {
863 if (IS_DEBUG_OSPF_EVENT
)
865 "%s: prefix %pFX was denied by prefix-list",
870 if (area
->external_routing
!= OSPF_AREA_DEFAULT
871 && area
->no_summary
) {
872 if (IS_DEBUG_OSPF_EVENT
)
874 "%s: area %pI4 is stub and no_summary",
875 __func__
, &area
->area_id
);
879 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
880 if (IS_DEBUG_OSPF_EVENT
)
882 "%s: this is inter-area route to %pFX",
885 if (!OSPF_IS_AREA_BACKBONE(area
))
886 ospf_abr_announce_network_to_area(p
, or->cost
,
890 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
891 if (IS_DEBUG_OSPF_EVENT
)
893 "%s: this is intra-area route to %pFX",
895 if ((range
= ospf_area_range_match(or_area
, p
))
896 && !ospf_area_is_transit(area
))
897 ospf_abr_update_aggregate(range
, or, area
);
899 ospf_abr_announce_network_to_area(p
, or->cost
,
905 static int ospf_abr_should_announce(struct ospf
*ospf
, struct prefix_ipv4
*p
,
906 struct ospf_route
* or)
908 struct ospf_area
*area
;
910 area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
914 if (EXPORT_NAME(area
)) {
915 if (EXPORT_LIST(area
) == NULL
)
917 access_list_lookup(AFI_IP
, EXPORT_NAME(area
));
919 if (EXPORT_LIST(area
))
920 if (access_list_apply(EXPORT_LIST(area
), p
)
928 static void ospf_abr_process_nssa_translates(struct ospf
*ospf
)
930 /* Scan through all NSSA_LSDB records for all areas;
932 If P-bit is on, translate all Type-7's to 5's and aggregate or
933 flood install as approved in Type-5 LSDB with XLATE Flag on
934 later, do same for all aggregates... At end, DISCARD all
935 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
936 struct listnode
*node
;
937 struct ospf_area
*area
;
938 struct route_node
*rn
;
939 struct ospf_lsa
*lsa
;
941 if (IS_DEBUG_OSPF_NSSA
)
942 zlog_debug("%s: Start", __func__
);
944 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
945 if (!area
->NSSATranslatorState
)
946 continue; /* skip if not translator */
948 if (area
->external_routing
!= OSPF_AREA_NSSA
)
949 continue; /* skip if not Nssa Area */
951 if (IS_DEBUG_OSPF_NSSA
)
952 zlog_debug("%s(): looking at area %pI4", __func__
,
955 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
956 ospf_abr_translate_nssa(area
, lsa
);
959 if (IS_DEBUG_OSPF_NSSA
)
960 zlog_debug("%s: Stop", __func__
);
963 static void ospf_abr_process_network_rt(struct ospf
*ospf
,
964 struct route_table
*rt
)
966 struct ospf_area
*area
;
967 struct ospf_route
* or ;
968 struct route_node
*rn
;
970 if (IS_DEBUG_OSPF_EVENT
)
971 zlog_debug("%s: Start", __func__
);
973 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
974 if ((or = rn
->info
) == NULL
)
977 if (!(area
= ospf_area_lookup_by_area_id(ospf
,
978 or->u
.std
.area_id
))) {
979 if (IS_DEBUG_OSPF_EVENT
)
981 "%s: area %pI4 no longer exists", __func__
,
986 if (IS_DEBUG_OSPF_EVENT
)
987 zlog_debug("%s: this is a route to %pFX", __func__
,
989 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
) {
990 if (IS_DEBUG_OSPF_EVENT
)
992 "%s: this is an External router, skipping",
997 if (or->cost
>= OSPF_LS_INFINITY
) {
998 if (IS_DEBUG_OSPF_EVENT
)
1000 "%s: this route's cost is infinity, skipping",
1005 if (or->type
== OSPF_DESTINATION_DISCARD
) {
1006 if (IS_DEBUG_OSPF_EVENT
)
1008 "%s: this is a discard entry, skipping",
1014 or->path_type
== OSPF_PATH_INTRA_AREA
1015 && !ospf_abr_should_announce(
1016 ospf
, (struct prefix_ipv4
*)&rn
->p
,
1018 if (IS_DEBUG_OSPF_EVENT
)
1019 zlog_debug("%s: denied by export-list",
1025 or->path_type
== OSPF_PATH_INTRA_AREA
1026 && !ospf_abr_plist_out_check(
1028 (struct prefix_ipv4
*)&rn
->p
)) {
1029 if (IS_DEBUG_OSPF_EVENT
)
1030 zlog_debug("%s: denied by prefix-list",
1035 if ((or->path_type
== OSPF_PATH_INTER_AREA
)
1036 && !OSPF_IS_AREA_ID_BACKBONE(or->u
.std
.area_id
)) {
1037 if (IS_DEBUG_OSPF_EVENT
)
1039 "%s: this route is not backbone one, skipping",
1045 if ((ospf
->abr_type
== OSPF_ABR_CISCO
)
1046 || (ospf
->abr_type
== OSPF_ABR_IBM
))
1048 if (!ospf_act_bb_connection(ospf
) &&
1049 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1050 if (IS_DEBUG_OSPF_EVENT
)
1052 "%s: ALT ABR: No BB connection, skip not intra-area routes",
1057 if (IS_DEBUG_OSPF_EVENT
)
1058 zlog_debug("%s: announcing", __func__
);
1059 ospf_abr_announce_network(ospf
, (struct prefix_ipv4
*)&rn
->p
,
1063 if (IS_DEBUG_OSPF_EVENT
)
1064 zlog_debug("%s: Stop", __func__
);
1067 static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
1068 struct ospf_area
*area
)
1070 struct ospf_lsa
*lsa
, *old
= NULL
;
1071 struct summary_lsa
*slsa
= NULL
;
1073 if (IS_DEBUG_OSPF_EVENT
)
1074 zlog_debug("%s: Start", __func__
);
1076 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
,
1077 area
->ospf
->router_id
);
1079 if (IS_DEBUG_OSPF_EVENT
)
1080 zlog_debug("%s: old summary found", __func__
);
1081 slsa
= (struct summary_lsa
*)old
->data
;
1083 if (IS_DEBUG_OSPF_EVENT
)
1084 zlog_debug("%s: old metric: %d, new metric: %d",
1085 __func__
, GET_METRIC(slsa
->metric
), cost
);
1088 if (old
&& (GET_METRIC(slsa
->metric
) == cost
)
1089 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
1090 if (IS_DEBUG_OSPF_EVENT
)
1091 zlog_debug("%s: old summary approved", __func__
);
1092 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
1094 if (IS_DEBUG_OSPF_EVENT
)
1095 zlog_debug("%s: 2.2", __func__
);
1098 set_metric(old
, cost
);
1099 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
1101 lsa
= ospf_summary_asbr_lsa_originate(p
, cost
, area
);
1103 flog_warn(EC_OSPF_LSA_MISSING
,
1104 "%s: Could not refresh/originate %pFX to %pI4",
1105 __func__
, (struct prefix
*)p
,
1110 if (IS_DEBUG_OSPF_EVENT
)
1111 zlog_debug("%s: flooding new version of summary",
1115 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new
1117 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1119 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1120 /* ospf_flood_through_area (area, NULL, lsa);*/
1123 if (IS_DEBUG_OSPF_EVENT
)
1124 zlog_debug("%s: Stop", __func__
);
1128 static void ospf_abr_announce_rtr(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1129 struct ospf_route
* or)
1131 struct listnode
*node
;
1132 struct ospf_area
*area
;
1134 if (IS_DEBUG_OSPF_EVENT
)
1135 zlog_debug("%s: Start", __func__
);
1137 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1138 if (IS_DEBUG_OSPF_EVENT
)
1139 zlog_debug("%s: looking at area %pI4", __func__
,
1142 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
1145 if (ospf_abr_nexthops_belong_to_area(or, area
))
1148 /* RFC3101: Do not generate ASBR type 4 LSA if NSSA ABR */
1149 if (or->u
.std
.external_routing
== OSPF_AREA_NSSA
) {
1150 if (IS_DEBUG_OSPF_EVENT
)
1152 "%s: do not generate LSA Type-4 %pI4 from NSSA",
1153 __func__
, &p
->prefix
);
1157 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
1158 if (IS_DEBUG_OSPF_EVENT
)
1160 "%s: area %pI4 doesn't support external routing",
1161 __func__
, &area
->area_id
);
1165 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
1166 if (IS_DEBUG_OSPF_EVENT
)
1168 "%s: this is inter-area route to %pI4",
1169 __func__
, &p
->prefix
);
1170 if (!OSPF_IS_AREA_BACKBONE(area
))
1171 ospf_abr_announce_rtr_to_area(p
, or->cost
,
1175 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
1176 if (IS_DEBUG_OSPF_EVENT
)
1178 "%s: this is intra-area route to %pI4",
1179 __func__
, &p
->prefix
);
1180 ospf_abr_announce_rtr_to_area(p
, or->cost
, area
);
1184 if (IS_DEBUG_OSPF_EVENT
)
1185 zlog_debug("%s: Stop", __func__
);
1188 static void ospf_abr_process_router_rt(struct ospf
*ospf
,
1189 struct route_table
*rt
)
1191 struct ospf_route
* or ;
1192 struct route_node
*rn
;
1195 if (IS_DEBUG_OSPF_EVENT
)
1196 zlog_debug("%s: Start", __func__
);
1198 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1199 struct listnode
*node
, *nnode
;
1201 struct ospf_route
*best
= NULL
;
1203 if (rn
->info
== NULL
)
1208 if (IS_DEBUG_OSPF_EVENT
)
1209 zlog_debug("%s: this is a route to %pI4", __func__
,
1212 for (ALL_LIST_ELEMENTS(l
, node
, nnode
, or)) {
1213 if (!ospf_area_lookup_by_area_id(ospf
,
1214 or->u
.std
.area_id
)) {
1215 if (IS_DEBUG_OSPF_EVENT
)
1217 "%s: area %pI4 no longer exists", __func__
,
1218 &or->u
.std
.area_id
);
1223 if (!CHECK_FLAG(or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
)) {
1224 if (IS_DEBUG_OSPF_EVENT
)
1226 "%s: This is not an ASBR, skipping",
1232 best
= ospf_find_asbr_route(
1233 ospf
, rt
, (struct prefix_ipv4
*)&rn
->p
);
1241 if (IS_DEBUG_OSPF_EVENT
)
1243 "%s: This route is not the best among possible, skipping",
1249 or->path_type
== OSPF_PATH_INTER_AREA
1250 && !OSPF_IS_AREA_ID_BACKBONE(
1251 or->u
.std
.area_id
)) {
1252 if (IS_DEBUG_OSPF_EVENT
)
1254 "%s: This route is not a backbone one, skipping",
1259 if (or->cost
>= OSPF_LS_INFINITY
) {
1260 if (IS_DEBUG_OSPF_EVENT
)
1262 "%s: This route has LS_INFINITY metric, skipping",
1267 if (ospf
->abr_type
== OSPF_ABR_CISCO
1268 || ospf
->abr_type
== OSPF_ABR_IBM
)
1269 if (!ospf_act_bb_connection(ospf
) &&
1270 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1271 if (IS_DEBUG_OSPF_EVENT
)
1273 "%s: ALT ABR: No BB connection, skip not intra-area routes",
1278 ospf_abr_announce_rtr(ospf
,
1279 (struct prefix_ipv4
*)&rn
->p
, or);
1283 if (IS_DEBUG_OSPF_EVENT
)
1284 zlog_debug("%s: Stop", __func__
);
1288 ospf_abr_unapprove_translates(struct ospf
*ospf
) /* For NSSA Translations */
1290 struct ospf_lsa
*lsa
;
1291 struct route_node
*rn
;
1293 if (IS_DEBUG_OSPF_NSSA
)
1294 zlog_debug("%s: Start", __func__
);
1296 /* NSSA Translator is not checked, because it may have gone away,
1297 and we would want to flush any residuals anyway */
1299 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1300 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) {
1301 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1302 if (IS_DEBUG_OSPF_NSSA
)
1303 zlog_debug("%s: approved unset on link id %pI4",
1304 __func__
, &lsa
->data
->id
);
1307 if (IS_DEBUG_OSPF_NSSA
)
1308 zlog_debug("%s: Stop", __func__
);
1311 static void ospf_abr_unapprove_summaries(struct ospf
*ospf
)
1313 struct listnode
*node
;
1314 struct ospf_area
*area
;
1315 struct route_node
*rn
;
1316 struct ospf_lsa
*lsa
;
1318 if (IS_DEBUG_OSPF_EVENT
)
1319 zlog_debug("%s: Start", __func__
);
1321 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1322 if (IS_DEBUG_OSPF_EVENT
)
1323 zlog_debug("%s: considering area %pI4", __func__
,
1325 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1326 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1327 if (IS_DEBUG_OSPF_EVENT
)
1329 "%s: approved unset on summary link id %pI4",
1330 __func__
, &lsa
->data
->id
);
1331 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1334 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1335 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1336 if (IS_DEBUG_OSPF_EVENT
)
1338 "%s: approved unset on asbr-summary link id %pI4",
1339 __func__
, &lsa
->data
->id
);
1340 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1344 if (IS_DEBUG_OSPF_EVENT
)
1345 zlog_debug("%s: Stop", __func__
);
1348 static void ospf_abr_prepare_aggregates(struct ospf
*ospf
)
1350 struct listnode
*node
;
1351 struct route_node
*rn
;
1352 struct ospf_area_range
*range
;
1353 struct ospf_area
*area
;
1355 if (IS_DEBUG_OSPF_EVENT
)
1356 zlog_debug("%s: Start", __func__
);
1358 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1359 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1360 if ((range
= rn
->info
) != NULL
) {
1362 range
->specifics
= 0;
1366 if (IS_DEBUG_OSPF_EVENT
)
1367 zlog_debug("%s: Stop", __func__
);
1370 static void ospf_abr_announce_aggregates(struct ospf
*ospf
)
1372 struct ospf_area
*area
, *ar
;
1373 struct ospf_area_range
*range
;
1374 struct route_node
*rn
;
1376 struct listnode
*node
, *n
;
1378 if (IS_DEBUG_OSPF_EVENT
)
1379 zlog_debug("%s: Start", __func__
);
1381 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1382 if (IS_DEBUG_OSPF_EVENT
)
1383 zlog_debug("%s: looking at area %pI4", __func__
,
1386 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1387 if ((range
= rn
->info
)) {
1388 if (!CHECK_FLAG(range
->flags
,
1389 OSPF_AREA_RANGE_ADVERTISE
)) {
1390 if (IS_DEBUG_OSPF_EVENT
)
1392 "%s: discarding suppress-ranges",
1398 p
.u
.prefix4
= range
->addr
;
1399 p
.prefixlen
= range
->masklen
;
1401 if (IS_DEBUG_OSPF_EVENT
)
1402 zlog_debug("%s: this is range: %pFX",
1405 if (CHECK_FLAG(range
->flags
,
1406 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1408 p
.u
.prefix4
= range
->subst_addr
;
1409 p
.prefixlen
= range
->subst_masklen
;
1412 if (range
->specifics
) {
1413 if (IS_DEBUG_OSPF_EVENT
)
1414 zlog_debug("%s: active range",
1417 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
,
1422 /* We do not check nexthops
1424 intra-area routes can be
1428 /* backbone routes are not
1430 when announced into transit
1433 if (ospf_area_is_transit(ar
)
1434 && OSPF_IS_AREA_BACKBONE(
1436 if (IS_DEBUG_OSPF_EVENT
)
1438 "%s: Skipping announcement of BB aggregate into a transit area",
1442 ospf_abr_announce_network_to_area(
1451 if (IS_DEBUG_OSPF_EVENT
)
1452 zlog_debug("%s: Stop", __func__
);
1456 ospf_abr_send_nssa_aggregates(struct ospf
*ospf
) /* temporarily turned off */
1458 struct listnode
*node
; /*, n; */
1459 struct ospf_area
*area
; /*, *ar; */
1460 struct route_node
*rn
;
1461 struct ospf_area_range
*range
;
1462 struct prefix_ipv4 p
;
1464 if (IS_DEBUG_OSPF_NSSA
)
1465 zlog_debug("%s: Start", __func__
);
1467 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1468 if (!area
->NSSATranslatorState
)
1471 if (IS_DEBUG_OSPF_NSSA
)
1472 zlog_debug("%s: looking at area %pI4", __func__
,
1475 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
)) {
1476 if (rn
->info
== NULL
)
1481 if (!CHECK_FLAG(range
->flags
,
1482 OSPF_AREA_RANGE_ADVERTISE
)) {
1483 if (IS_DEBUG_OSPF_NSSA
)
1485 "%s: discarding suppress-ranges",
1491 p
.prefix
= range
->addr
;
1492 p
.prefixlen
= range
->masklen
;
1494 if (IS_DEBUG_OSPF_NSSA
)
1495 zlog_debug("%s: this is range: %pFX", __func__
,
1498 if (CHECK_FLAG(range
->flags
,
1499 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1501 p
.prefix
= range
->subst_addr
;
1502 p
.prefixlen
= range
->subst_masklen
;
1505 if (range
->specifics
) {
1506 if (IS_DEBUG_OSPF_NSSA
)
1507 zlog_debug("%s: active range",
1510 /* Fetch LSA-Type-7 from aggregate prefix, and
1512 * translate, Install (as Type-5), Approve, and
1515 ospf_abr_translate_nssa_range(&p
, range
->cost
);
1517 } /* all area ranges*/
1520 if (IS_DEBUG_OSPF_NSSA
)
1521 zlog_debug("%s: Stop", __func__
);
1524 static void ospf_abr_announce_stub_defaults(struct ospf
*ospf
)
1526 struct listnode
*node
;
1527 struct ospf_area
*area
;
1528 struct prefix_ipv4 p
;
1530 if (!IS_OSPF_ABR(ospf
))
1533 if (IS_DEBUG_OSPF_EVENT
)
1534 zlog_debug("%s: Start", __func__
);
1537 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1540 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1541 if (IS_DEBUG_OSPF_EVENT
)
1542 zlog_debug("%s: looking at area %pI4", __func__
,
1545 if ((area
->external_routing
!= OSPF_AREA_STUB
)
1546 && (area
->external_routing
!= OSPF_AREA_NSSA
))
1549 if (OSPF_IS_AREA_BACKBONE(area
))
1550 continue; /* Sanity Check */
1552 if (IS_DEBUG_OSPF_EVENT
)
1553 zlog_debug("%s: announcing 0.0.0.0/0 to area %pI4",
1554 __func__
, &area
->area_id
);
1555 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1558 if (IS_DEBUG_OSPF_EVENT
)
1559 zlog_debug("%s: Stop", __func__
);
1562 /** @brief Function to check and generate indication
1563 * LSA for area on which we received
1564 * indication LSA flush.
1565 * @param Ospf instance.
1566 * @param Area on which indication lsa flush is to be generated.
1569 void ospf_generate_indication_lsa(struct ospf
*ospf
, struct ospf_area
*area
)
1571 bool area_fr_not_supp
= false;
1573 /* Check if you have any area which doesn't support
1577 area_fr_not_supp
= ospf_check_fr_enabled_all(ospf
) ? false : true;
1579 /* If any one of the area doestn't support FR, generate
1580 * indication LSA on behalf of that area.
1583 if (area_fr_not_supp
&& !area
->fr_info
.area_ind_lsa_recvd
&&
1584 !area
->fr_info
.indication_lsa_self
&&
1585 !area
->fr_info
.area_dc_clear
) {
1587 struct prefix_ipv4 p
;
1588 struct ospf_lsa
*new;
1591 p
.prefix
= ospf
->router_id
;
1592 p
.prefixlen
= IPV4_MAX_BITLEN
;
1594 new = ospf_summary_asbr_lsa_originate(&p
, OSPF_LS_INFINITY
,
1597 zlog_debug("%s: Indication lsa originate failed",
1601 /* save the indication lsa for that area */
1602 area
->fr_info
.indication_lsa_self
= new;
1606 /** @brief Function to receive and process indication LSA
1608 * @param lsa being flushed.
1611 void ospf_recv_indication_lsa_flush(struct ospf_lsa
*lsa
)
1613 if (!IS_LSA_SELF(lsa
) && IS_LSA_MAXAGE(lsa
) &&
1614 ospf_check_indication_lsa(lsa
)) {
1615 lsa
->area
->fr_info
.area_ind_lsa_recvd
= false;
1617 OSPF_LOG_INFO("%s: Received an ind lsa: %pI4 area %pI4",
1618 __func__
, &lsa
->data
->id
, &lsa
->area
->area_id
);
1620 if (!IS_OSPF_ABR(lsa
->area
->ospf
))
1623 /* If the LSA received is a indication LSA with maxage on
1624 * the network, then check and regenerate indication
1625 * LSA if any of our areas don't support flood reduction.
1627 ospf_generate_indication_lsa(lsa
->area
->ospf
, lsa
->area
);
1631 /** @brief Function to generate indication LSAs.
1632 * @param Ospf instance.
1633 * @param Area on behalf of which indication
1634 * LSA is generated LSA.
1637 void ospf_abr_generate_indication_lsa(struct ospf
*ospf
,
1638 const struct ospf_area
*area
)
1640 struct ospf_lsa
*new;
1641 struct listnode
*node
;
1642 struct ospf_area
*o_area
;
1644 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, o_area
)) {
1648 if (o_area
->fr_info
.indication_lsa_self
||
1649 o_area
->fr_info
.area_ind_lsa_recvd
||
1650 o_area
->fr_info
.area_dc_clear
) {
1651 /* if the area has already received an
1652 * indication LSA or if area already has
1653 * LSAs with DC bit 0 other than
1654 * indication LSA then don't generate
1655 * indication LSA in those areas.
1657 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
1658 "Area %pI4 has LSAs with dc bit clear",
1664 struct prefix_ipv4 p
;
1667 p
.prefix
= ospf
->router_id
;
1668 p
.prefixlen
= IPV4_MAX_BITLEN
;
1670 new = ospf_summary_asbr_lsa_originate(
1671 &p
, OSPF_LS_INFINITY
, o_area
);
1674 "%s: Indication lsa originate Failed",
1678 /* save the indication lsa for that area */
1679 o_area
->fr_info
.indication_lsa_self
= new;
1684 /** @brief Flush the indication LSA from all the areas
1686 * @param Ospf instance.
1689 void ospf_flush_indication_lsas(struct ospf
*ospf
)
1691 struct ospf_area
*area
;
1692 struct listnode
*node
;
1694 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1695 if (area
->fr_info
.indication_lsa_self
) {
1697 "Flushing ind lsa: %pI4 area %pI4",
1698 &area
->fr_info
.indication_lsa_self
->data
->id
,
1700 ospf_schedule_lsa_flush_area(
1701 area
, area
->fr_info
.indication_lsa_self
);
1702 area
->fr_info
.indication_lsa_self
= NULL
;
1707 /** @brief Check if flood reduction is enabled on
1709 * @param Ospf instance.
1712 bool ospf_check_fr_enabled_all(struct ospf
*ospf
)
1714 const struct ospf_area
*area
;
1715 struct listnode
*node
;
1717 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
1718 if (!ospf_check_area_fr_enabled(area
))
1724 /** @brief Abr function to check conditions for generation
1725 * of indication. LSAs/announcing non-DNA routers
1730 static void ospf_abr_announce_non_dna_routers(struct thread
*thread
)
1732 struct ospf_area
*area
;
1733 struct listnode
*node
;
1734 struct ospf
*ospf
= THREAD_ARG(thread
);
1736 THREAD_OFF(ospf
->t_abr_fr
);
1738 if (!IS_OSPF_ABR(ospf
))
1741 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
, "%s(): Start", __func__
);
1743 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1744 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
1745 "%s: Area %pI4 FR enabled: %d", __func__
,
1746 &area
->area_id
, area
->fr_info
.enabled
);
1748 IS_DEBUG_OSPF_EVENT
,
1749 "LSA with DC bit clear: %d Recived indication LSA: %d",
1750 area
->fr_info
.area_dc_clear
,
1751 area
->fr_info
.area_ind_lsa_recvd
);
1752 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
, "FR state change: %d",
1753 area
->fr_info
.state_changed
);
1754 if (!OSPF_IS_AREA_BACKBONE(area
) &&
1755 area
->fr_info
.area_dc_clear
) {
1756 /* rfc4136 rfc1793: Suppose if the abr is connected to
1757 * a regular non-backbone OSPF area, Furthermore if
1758 * the area has LSAs with the DC-bit clear, other
1759 * than indication-LSAs. Then originate indication-LSAs
1760 * into all other directly-connected "regular" areas,
1761 * including the backbone area.
1763 ospf_abr_generate_indication_lsa(ospf
, area
);
1766 if (OSPF_IS_AREA_BACKBONE(area
) &&
1767 (area
->fr_info
.area_dc_clear
||
1768 area
->fr_info
.area_ind_lsa_recvd
)) {
1769 /* rfc4136 rfc1793: Suppose if the abr is connected to
1770 * backbone OSPF area. Furthermore, if backbone has
1771 * LSAs with the DC-bit clear that are either
1772 * a) not indication-LSAs or indication-LSAs or
1773 * b) indication-LSAs that have been originated by
1775 * then originate indication-LSAs into all other
1776 * directly-connected "regular" non-backbone areas.
1778 ospf_abr_generate_indication_lsa(ospf
, area
);
1781 if (area
->fr_info
.enabled
&& area
->fr_info
.state_changed
&&
1782 area
->fr_info
.indication_lsa_self
) {
1783 /* Ospf area flood reduction state changed
1784 * area now supports flood reduction.
1785 * check if all other areas support flood reduction
1786 * if yes then flush indication LSAs generated in
1789 if (ospf_check_fr_enabled_all(ospf
))
1790 ospf_flush_indication_lsas(ospf
);
1792 area
->fr_info
.state_changed
= false;
1795 /* If previously we had generated indication lsa
1796 * but now area has lsas with dc bit set to 0
1797 * apart from indication lsa, we'll clear indication lsa
1799 if (area
->fr_info
.area_dc_clear
&&
1800 area
->fr_info
.indication_lsa_self
) {
1801 ospf_schedule_lsa_flush_area(
1802 area
, area
->fr_info
.indication_lsa_self
);
1803 area
->fr_info
.indication_lsa_self
= NULL
;
1807 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
, "%s(): Stop", __func__
);
1810 static int ospf_abr_remove_unapproved_translates_apply(struct ospf
*ospf
,
1811 struct ospf_lsa
*lsa
)
1813 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1814 && !CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
)) {
1815 zlog_info("%s: removing unapproved translates, ID: %pI4",
1816 __func__
, &lsa
->data
->id
);
1818 /* FLUSH THROUGHOUT AS */
1819 ospf_lsa_flush_as(ospf
, lsa
);
1821 /* DISCARD from LSDB */
1826 static void ospf_abr_remove_unapproved_translates(struct ospf
*ospf
)
1828 struct route_node
*rn
;
1829 struct ospf_lsa
*lsa
;
1831 /* All AREA PROCESS should have APPROVED necessary LSAs */
1832 /* Remove any left over and not APPROVED */
1833 if (IS_DEBUG_OSPF_NSSA
)
1834 zlog_debug("%s: Start", __func__
);
1836 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1837 ospf_abr_remove_unapproved_translates_apply(ospf
, lsa
);
1839 if (IS_DEBUG_OSPF_NSSA
)
1840 zlog_debug("%s: Stop", __func__
);
1843 static void ospf_abr_remove_unapproved_summaries(struct ospf
*ospf
)
1845 struct listnode
*node
;
1846 struct ospf_area
*area
;
1847 struct route_node
*rn
;
1848 struct ospf_lsa
*lsa
;
1850 if (IS_DEBUG_OSPF_EVENT
)
1851 zlog_debug("%s: Start", __func__
);
1853 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1854 if (IS_DEBUG_OSPF_EVENT
)
1855 zlog_debug("%s: looking at area %pI4", __func__
,
1858 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1859 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1860 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1861 ospf_lsa_flush_area(lsa
, area
);
1863 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1864 if (ospf_lsa_is_self_originated(ospf
, lsa
) &&
1865 !CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
) &&
1866 /* Do not remove indication LSAs while
1867 * flushing unapproved summaries.
1869 !ospf_check_indication_lsa(lsa
))
1870 ospf_lsa_flush_area(lsa
, area
);
1873 if (IS_DEBUG_OSPF_EVENT
)
1874 zlog_debug("%s: Stop", __func__
);
1877 static void ospf_abr_manage_discard_routes(struct ospf
*ospf
)
1879 struct listnode
*node
, *nnode
;
1880 struct route_node
*rn
;
1881 struct ospf_area
*area
;
1882 struct ospf_area_range
*range
;
1884 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
1885 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1886 if ((range
= rn
->info
) != NULL
)
1887 if (CHECK_FLAG(range
->flags
,
1888 OSPF_AREA_RANGE_ADVERTISE
)) {
1889 if (range
->specifics
)
1890 ospf_add_discard_route(
1891 ospf
, ospf
->new_table
,
1896 ospf_delete_discard_route(
1897 ospf
, ospf
->new_table
,
1903 /* This is the function taking care about ABR NSSA, i.e. NSSA
1904 Translator, -LSA aggregation and flooding. For all NSSAs
1906 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1907 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1910 Any received Type-5s are legal for an ABR, else illegal for IR.
1911 Received Type-7s are installed, by area, with incoming P-bit. They
1912 are flooded; if the Elected NSSA Translator, then P-bit off.
1914 Additionally, this ABR will place "translated type-7's" into the
1915 Type-5 LSDB in order to keep track of APPROVAL or not.
1917 It will scan through every area, looking for Type-7 LSAs with P-Bit
1918 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1919 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1922 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1923 left over are FLUSHED and DISCARDED.
1925 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1926 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1928 static void ospf_abr_nssa_task(struct ospf
*ospf
) /* called only if any_nssa */
1930 if (ospf
->gr_info
.restart_in_progress
)
1933 if (IS_DEBUG_OSPF_NSSA
)
1934 zlog_debug("Check for NSSA-ABR Tasks():");
1936 if (!IS_OSPF_ABR(ospf
))
1942 /* Each area must confirm TranslatorRole */
1943 if (IS_DEBUG_OSPF_NSSA
)
1944 zlog_debug("%s: Start", __func__
);
1946 /* For all Global Entries flagged "local-translate", unset APPROVED */
1947 if (IS_DEBUG_OSPF_NSSA
)
1948 zlog_debug("%s: unapprove translates", __func__
);
1950 ospf_abr_unapprove_translates(ospf
);
1952 /* RESET all Ranges in every Area, same as summaries */
1953 if (IS_DEBUG_OSPF_NSSA
)
1954 zlog_debug("%s: NSSA initialize aggregates", __func__
);
1955 ospf_abr_prepare_aggregates(ospf
); /*TURNED OFF just for now */
1957 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1958 * Aggregate as Type-7
1959 * Install or Approve in Type-5 Global LSDB
1961 if (IS_DEBUG_OSPF_NSSA
)
1962 zlog_debug("%s: process translates", __func__
);
1963 ospf_abr_process_nssa_translates(ospf
);
1965 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1967 * Scan Type-7's for aggregates, translate to Type-5's,
1968 * Install/Flood/Approve
1970 if (IS_DEBUG_OSPF_NSSA
)
1971 zlog_debug("%s: send NSSA aggregates", __func__
);
1972 ospf_abr_send_nssa_aggregates(ospf
); /*TURNED OFF FOR NOW */
1974 /* Send any NSSA defaults as Type-5
1975 *if (IS_DEBUG_OSPF_NSSA)
1976 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1977 *ospf_abr_announce_nssa_defaults (ospf);
1978 * havnt a clue what above is supposed to do.
1981 /* Flush any unapproved previous translates from Global Data Base */
1982 if (IS_DEBUG_OSPF_NSSA
)
1983 zlog_debug("%s: remove unapproved translates", __func__
);
1984 ospf_abr_remove_unapproved_translates(ospf
);
1986 ospf_abr_manage_discard_routes(ospf
); /* same as normal...discard */
1988 if (IS_DEBUG_OSPF_NSSA
)
1989 zlog_debug("%s: Stop", __func__
);
1992 /* This is the function taking care about ABR stuff, i.e.
1993 summary-LSA origination and flooding. */
1994 void ospf_abr_task(struct ospf
*ospf
)
1996 if (ospf
->gr_info
.restart_in_progress
)
1999 if (IS_DEBUG_OSPF_EVENT
)
2000 zlog_debug("%s: Start", __func__
);
2002 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
) {
2003 if (IS_DEBUG_OSPF_EVENT
)
2004 zlog_debug("%s: Routing tables are not yet ready",
2009 if (IS_DEBUG_OSPF_EVENT
)
2010 zlog_debug("%s: unapprove summaries", __func__
);
2011 ospf_abr_unapprove_summaries(ospf
);
2013 if (IS_DEBUG_OSPF_EVENT
)
2014 zlog_debug("%s: prepare aggregates", __func__
);
2015 ospf_abr_prepare_aggregates(ospf
);
2017 if (IS_OSPF_ABR(ospf
)) {
2018 if (IS_DEBUG_OSPF_EVENT
)
2019 zlog_debug("%s: process network RT", __func__
);
2020 ospf_abr_process_network_rt(ospf
, ospf
->new_table
);
2022 if (IS_DEBUG_OSPF_EVENT
)
2023 zlog_debug("%s: process router RT", __func__
);
2024 ospf_abr_process_router_rt(ospf
, ospf
->new_rtrs
);
2026 if (IS_DEBUG_OSPF_EVENT
)
2027 zlog_debug("%s: announce aggregates", __func__
);
2028 ospf_abr_announce_aggregates(ospf
);
2030 if (IS_DEBUG_OSPF_EVENT
)
2031 zlog_debug("%s: announce stub defaults", __func__
);
2032 ospf_abr_announce_stub_defaults(ospf
);
2034 if (ospf
->fr_configured
) {
2035 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
2036 "%s(): announce non-DNArouters",
2039 * Schedule indication lsa generation timer,
2040 * giving time for route synchronization in
2044 master
, ospf_abr_announce_non_dna_routers
, ospf
,
2045 OSPF_ABR_DNA_TIMER
, &ospf
->t_abr_fr
);
2049 if (IS_DEBUG_OSPF_EVENT
)
2050 zlog_debug("%s: remove unapproved summaries", __func__
);
2051 ospf_abr_remove_unapproved_summaries(ospf
);
2053 ospf_abr_manage_discard_routes(ospf
);
2055 if (IS_DEBUG_OSPF_EVENT
)
2056 zlog_debug("%s: Stop", __func__
);
2059 static void ospf_abr_task_timer(struct thread
*thread
)
2061 struct ospf
*ospf
= THREAD_ARG(thread
);
2063 ospf
->t_abr_task
= 0;
2065 if (IS_DEBUG_OSPF_EVENT
)
2066 zlog_debug("Running ABR task on timer");
2068 ospf_check_abr_status(ospf
);
2069 ospf_abr_nssa_check_status(ospf
);
2071 ospf_abr_task(ospf
);
2072 ospf_abr_nssa_task(ospf
); /* if nssa-abr, then scan Type-7 LSDB */
2075 void ospf_schedule_abr_task(struct ospf
*ospf
)
2077 if (IS_DEBUG_OSPF_EVENT
)
2078 zlog_debug("Scheduling ABR task");
2080 thread_add_timer(master
, ospf_abr_task_timer
, ospf
, OSPF_ABR_TASK_DELAY
,