3 * Copyright (C) 1999, 2000 Alex Zinin, Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 #include "ospfd/ospfd.h"
37 #include "ospfd/ospf_interface.h"
38 #include "ospfd/ospf_ism.h"
39 #include "ospfd/ospf_asbr.h"
40 #include "ospfd/ospf_lsa.h"
41 #include "ospfd/ospf_lsdb.h"
42 #include "ospfd/ospf_neighbor.h"
43 #include "ospfd/ospf_nsm.h"
44 #include "ospfd/ospf_spf.h"
45 #include "ospfd/ospf_route.h"
46 #include "ospfd/ospf_ia.h"
47 #include "ospfd/ospf_flood.h"
48 #include "ospfd/ospf_abr.h"
49 #include "ospfd/ospf_ase.h"
50 #include "ospfd/ospf_zebra.h"
51 #include "ospfd/ospf_dump.h"
52 #include "ospfd/ospf_errors.h"
54 static struct ospf_area_range
*ospf_area_range_new(struct prefix_ipv4
*p
)
56 struct ospf_area_range
*range
;
58 range
= XCALLOC(MTYPE_OSPF_AREA_RANGE
, sizeof(struct ospf_area_range
));
59 range
->addr
= p
->prefix
;
60 range
->masklen
= p
->prefixlen
;
61 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
66 static void ospf_area_range_free(struct ospf_area_range
*range
)
68 XFREE(MTYPE_OSPF_AREA_RANGE
, range
);
71 static void ospf_area_range_add(struct ospf_area
*area
,
72 struct ospf_area_range
*range
)
74 struct route_node
*rn
;
78 p
.prefixlen
= range
->masklen
;
79 p
.prefix
= range
->addr
;
82 rn
= route_node_get(area
->ranges
, (struct prefix
*)&p
);
84 route_unlock_node(rn
);
89 static void ospf_area_range_delete(struct ospf_area
*area
,
90 struct route_node
*rn
)
92 struct ospf_area_range
*range
= rn
->info
;
94 if (range
->specifics
!= 0)
95 ospf_delete_discard_route(area
->ospf
, area
->ospf
->new_table
,
96 (struct prefix_ipv4
*)&rn
->p
);
98 ospf_area_range_free(range
);
100 route_unlock_node(rn
);
101 route_unlock_node(rn
);
104 struct ospf_area_range
*ospf_area_range_lookup(struct ospf_area
*area
,
105 struct prefix_ipv4
*p
)
107 struct route_node
*rn
;
109 rn
= route_node_lookup(area
->ranges
, (struct prefix
*)p
);
111 route_unlock_node(rn
);
117 struct ospf_area_range
*ospf_area_range_lookup_next(struct ospf_area
*area
,
118 struct in_addr
*range_net
,
121 struct route_node
*rn
;
122 struct prefix_ipv4 p
;
123 struct ospf_area_range
*find
;
126 p
.prefixlen
= IPV4_MAX_BITLEN
;
127 p
.prefix
= *range_net
;
131 rn
= route_top(area
->ranges
);
133 rn
= route_node_get(area
->ranges
, (struct prefix
*)&p
);
137 for (; rn
; rn
= route_next(rn
))
141 if (rn
&& rn
->info
) {
143 *range_net
= rn
->p
.u
.prefix4
;
144 route_unlock_node(rn
);
150 static struct ospf_area_range
*ospf_area_range_match(struct ospf_area
*area
,
151 struct prefix_ipv4
*p
)
153 struct route_node
*node
;
155 node
= route_node_match(area
->ranges
, (struct prefix
*)p
);
157 route_unlock_node(node
);
163 struct ospf_area_range
*ospf_area_range_match_any(struct ospf
*ospf
,
164 struct prefix_ipv4
*p
)
166 struct ospf_area_range
*range
;
167 struct ospf_area
*area
;
168 struct listnode
*node
;
170 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
171 if ((range
= ospf_area_range_match(area
, p
)))
177 int ospf_area_range_active(struct ospf_area_range
*range
)
179 return range
->specifics
;
182 static int ospf_area_actively_attached(struct ospf_area
*area
)
184 return area
->act_ints
;
187 int ospf_area_range_set(struct ospf
*ospf
, struct in_addr area_id
,
188 struct prefix_ipv4
*p
, int advertise
)
190 struct ospf_area
*area
;
191 struct ospf_area_range
*range
;
193 area
= ospf_area_get(ospf
, area_id
);
197 range
= ospf_area_range_lookup(area
, p
);
199 if (!CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
200 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
201 if ((CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
202 && !CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
203 || (!CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
204 && CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
)))
205 ospf_schedule_abr_task(ospf
);
207 range
= ospf_area_range_new(p
);
208 ospf_area_range_add(area
, range
);
209 ospf_schedule_abr_task(ospf
);
212 if (CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
213 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
215 UNSET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
216 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
222 int ospf_area_range_cost_set(struct ospf
*ospf
, struct in_addr area_id
,
223 struct prefix_ipv4
*p
, uint32_t cost
)
225 struct ospf_area
*area
;
226 struct ospf_area_range
*range
;
228 area
= ospf_area_get(ospf
, area_id
);
232 range
= ospf_area_range_lookup(area
, p
);
236 if (range
->cost_config
!= cost
) {
237 range
->cost_config
= cost
;
238 if (ospf_area_range_active(range
))
239 ospf_schedule_abr_task(ospf
);
245 int ospf_area_range_unset(struct ospf
*ospf
, struct in_addr area_id
,
246 struct prefix_ipv4
*p
)
248 struct ospf_area
*area
;
249 struct route_node
*rn
;
251 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
255 rn
= route_node_lookup(area
->ranges
, (struct prefix
*)p
);
259 if (ospf_area_range_active(rn
->info
))
260 ospf_schedule_abr_task(ospf
);
262 ospf_area_range_delete(area
, rn
);
267 int ospf_area_range_substitute_set(struct ospf
*ospf
, struct in_addr area_id
,
268 struct prefix_ipv4
*p
, struct prefix_ipv4
*s
)
270 struct ospf_area
*area
;
271 struct ospf_area_range
*range
;
273 area
= ospf_area_get(ospf
, area_id
);
274 range
= ospf_area_range_lookup(area
, p
);
277 if (!CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
278 || !CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
279 ospf_schedule_abr_task(ospf
);
281 range
= ospf_area_range_new(p
);
282 ospf_area_range_add(area
, range
);
283 ospf_schedule_abr_task(ospf
);
286 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
287 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
288 range
->subst_addr
= s
->prefix
;
289 range
->subst_masklen
= s
->prefixlen
;
294 int ospf_area_range_substitute_unset(struct ospf
*ospf
, struct in_addr area_id
,
295 struct prefix_ipv4
*p
)
297 struct ospf_area
*area
;
298 struct ospf_area_range
*range
;
300 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
304 range
= ospf_area_range_lookup(area
, p
);
308 if (CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
309 if (ospf_area_range_active(range
))
310 ospf_schedule_abr_task(ospf
);
312 UNSET_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
313 range
->subst_addr
.s_addr
= INADDR_ANY
;
314 range
->subst_masklen
= 0;
319 int ospf_act_bb_connection(struct ospf
*ospf
)
321 struct ospf_interface
*oi
;
322 struct listnode
*node
;
325 if (ospf
->backbone
== NULL
)
328 for (ALL_LIST_ELEMENTS_RO(ospf
->backbone
->oiflist
, node
, oi
)) {
329 struct ospf_neighbor
*nbr
;
330 struct route_node
*rn
;
332 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
337 if (nbr
->state
== NSM_Full
338 || OSPF_GR_IS_ACTIVE_HELPER(nbr
))
346 /* Determine whether this router is elected translator or not for area */
347 static int ospf_abr_nssa_am_elected(struct ospf_area
*area
)
349 struct route_node
*rn
;
350 struct ospf_lsa
*lsa
;
351 struct router_lsa
*rlsa
;
352 struct in_addr
*best
= NULL
;
354 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
) {
356 if (!lsa
|| (lsa
->data
->type
!= OSPF_ROUTER_LSA
)
360 rlsa
= (struct router_lsa
*)lsa
->data
;
362 /* ignore non-ABR routers */
363 if (!IS_ROUTER_LSA_BORDER(rlsa
))
366 /* Router has Nt flag - always translate */
367 if (IS_ROUTER_LSA_NT(rlsa
)) {
368 if (IS_DEBUG_OSPF_NSSA
)
369 zlog_debug("%s: router %pI4 asserts Nt",
370 __func__
, &lsa
->data
->id
);
375 best
= &lsa
->data
->id
;
376 else if (IPV4_ADDR_CMP(&best
->s_addr
, &lsa
->data
->id
.s_addr
)
378 best
= &lsa
->data
->id
;
381 if (IS_DEBUG_OSPF_NSSA
)
382 zlog_debug("%s: best electable ABR is: %pI4", __func__
, best
);
387 if (IPV4_ADDR_CMP(&best
->s_addr
, &area
->ospf
->router_id
.s_addr
) < 0)
393 /* Check NSSA ABR status
394 * assumes there are nssa areas
396 void ospf_abr_nssa_check_status(struct ospf
*ospf
)
398 struct ospf_area
*area
;
399 struct listnode
*lnode
, *nnode
;
401 for (ALL_LIST_ELEMENTS(ospf
->areas
, lnode
, nnode
, area
)) {
402 uint8_t old_state
= area
->NSSATranslatorState
;
404 if (area
->external_routing
!= OSPF_AREA_NSSA
)
407 if (IS_DEBUG_OSPF(nssa
, NSSA
))
408 zlog_debug("%s: checking area %pI4", __func__
,
411 if (!IS_OSPF_ABR(area
->ospf
)) {
412 if (IS_DEBUG_OSPF(nssa
, NSSA
))
413 zlog_debug("%s: not ABR", __func__
);
414 area
->NSSATranslatorState
=
415 OSPF_NSSA_TRANSLATE_DISABLED
;
417 switch (area
->NSSATranslatorRole
) {
418 case OSPF_NSSA_ROLE_NEVER
:
419 /* We never Translate Type-7 LSA. */
420 /* TODO: check previous state and flush? */
421 if (IS_DEBUG_OSPF(nssa
, NSSA
))
422 zlog_debug("%s: never translate",
424 area
->NSSATranslatorState
=
425 OSPF_NSSA_TRANSLATE_DISABLED
;
428 case OSPF_NSSA_ROLE_ALWAYS
:
429 /* We always translate if we are an ABR
430 * TODO: originate new LSAs if state change?
431 * or let the nssa abr task take care of it?
433 if (IS_DEBUG_OSPF(nssa
, NSSA
))
434 zlog_debug("%s: translate always",
436 area
->NSSATranslatorState
=
437 OSPF_NSSA_TRANSLATE_ENABLED
;
440 case OSPF_NSSA_ROLE_CANDIDATE
:
441 /* We are a candidate for Translation */
442 if (ospf_abr_nssa_am_elected(area
) > 0) {
443 area
->NSSATranslatorState
=
444 OSPF_NSSA_TRANSLATE_ENABLED
;
445 if (IS_DEBUG_OSPF(nssa
, NSSA
))
447 "%s: elected translator",
450 area
->NSSATranslatorState
=
451 OSPF_NSSA_TRANSLATE_DISABLED
;
452 if (IS_DEBUG_OSPF(nssa
, NSSA
))
453 zlog_debug("%s: not elected",
460 * All NSSA border routers must set the E-bit in the Type-1
462 * of their directly attached non-stub areas, even when they are
466 if (old_state
!= area
->NSSATranslatorState
) {
467 if (old_state
== OSPF_NSSA_TRANSLATE_DISABLED
)
468 ospf_asbr_status_update(ospf
,
469 ++ospf
->redistribute
);
470 else if (area
->NSSATranslatorState
471 == OSPF_NSSA_TRANSLATE_DISABLED
)
472 ospf_asbr_status_update(ospf
,
473 --ospf
->redistribute
);
478 /* Check area border router status. */
479 void ospf_check_abr_status(struct ospf
*ospf
)
481 struct ospf_area
*area
;
482 struct listnode
*node
, *nnode
;
483 int bb_configured
= 0;
484 int bb_act_attached
= 0;
485 int areas_configured
= 0;
486 int areas_act_attached
= 0;
487 uint8_t new_flags
= ospf
->flags
;
489 if (IS_DEBUG_OSPF_EVENT
)
490 zlog_debug("%s: Start", __func__
);
492 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
493 if (listcount(area
->oiflist
)) {
496 if (OSPF_IS_AREA_BACKBONE(area
))
500 if (ospf_area_actively_attached(area
)) {
501 areas_act_attached
++;
503 if (OSPF_IS_AREA_BACKBONE(area
))
508 if (IS_DEBUG_OSPF_EVENT
) {
509 zlog_debug("%s: looked through areas", __func__
);
510 zlog_debug("%s: bb_configured: %d", __func__
, bb_configured
);
511 zlog_debug("%s: bb_act_attached: %d", __func__
,
513 zlog_debug("%s: areas_configured: %d", __func__
,
515 zlog_debug("%s: areas_act_attached: %d", __func__
,
519 switch (ospf
->abr_type
) {
520 case OSPF_ABR_SHORTCUT
:
522 if (areas_act_attached
> 1)
523 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
525 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
529 if ((areas_act_attached
> 1) && bb_configured
)
530 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
532 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
536 if ((areas_configured
> 1) && bb_act_attached
)
537 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
539 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
545 if (new_flags
!= ospf
->flags
) {
546 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_ABR_STATUS_CHANGE
);
547 if (IS_DEBUG_OSPF_EVENT
)
548 zlog_debug("%s: new router flags: %x", __func__
,
550 ospf
->flags
= new_flags
;
551 ospf_router_lsa_update(ospf
);
555 static void ospf_abr_update_aggregate(struct ospf_area_range
*range
,
556 struct ospf_route
* or,
557 struct ospf_area
*area
)
559 if (IS_DEBUG_OSPF_EVENT
)
560 zlog_debug("%s: Start", __func__
);
562 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)
563 && (range
->cost
!= OSPF_STUB_MAX_METRIC_SUMMARY_COST
)) {
564 range
->cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
565 if (IS_DEBUG_OSPF_EVENT
)
566 zlog_debug("%s: use summary max-metric 0x%08x",
567 __func__
, range
->cost
);
568 } else if (range
->cost_config
!= OSPF_AREA_RANGE_COST_UNSPEC
) {
569 if (IS_DEBUG_OSPF_EVENT
)
570 zlog_debug("%s: use configured cost %d", __func__
,
573 range
->cost
= range
->cost_config
;
575 if (range
->specifics
== 0) {
576 if (IS_DEBUG_OSPF_EVENT
)
577 zlog_debug("%s: use or->cost %d", __func__
,
580 range
->cost
= or->cost
; /* 1st time get 1st cost */
583 if (or->cost
> range
->cost
) {
584 if (IS_DEBUG_OSPF_EVENT
)
585 zlog_debug("%s: update to %d", __func__
,
588 range
->cost
= or->cost
;
595 static void set_metric(struct ospf_lsa
*lsa
, uint32_t metric
)
597 struct summary_lsa
*header
;
599 metric
= htonl(metric
);
600 mp
= (uint8_t *)&metric
;
602 header
= (struct summary_lsa
*)lsa
->data
;
603 memcpy(header
->metric
, mp
, 3);
606 /* ospf_abr_translate_nssa */
607 static int ospf_abr_translate_nssa(struct ospf_area
*area
, struct ospf_lsa
*lsa
)
609 /* Incoming Type-7 or later aggregated Type-7
611 * LSA is skipped if P-bit is off.
612 * LSA is aggregated if within range.
614 * The Type-7 is translated, Installed/Approved as a Type-5 into
615 * global LSDB, then Flooded through AS
617 * Later, any Unapproved Translated Type-5's are flushed/discarded
620 struct ospf_lsa
*old
= NULL
, *new = NULL
;
621 struct as_external_lsa
*ext7
;
622 struct prefix_ipv4 p
;
624 if (!CHECK_FLAG(lsa
->data
->options
, OSPF_OPTION_NP
)) {
625 if (IS_DEBUG_OSPF_NSSA
)
626 zlog_debug("%s: LSA Id %pI4, P-bit off, NO Translation",
627 __func__
, &lsa
->data
->id
);
631 if (IS_DEBUG_OSPF_NSSA
)
632 zlog_debug("%s: LSA Id %pI4, TRANSLATING 7 to 5", __func__
,
635 ext7
= (struct as_external_lsa
*)(lsa
->data
);
636 p
.prefix
= lsa
->data
->id
;
637 p
.prefixlen
= ip_masklen(ext7
->mask
);
639 if (ext7
->e
[0].fwd_addr
.s_addr
== OSPF_DEFAULT_DESTINATION
) {
640 if (IS_DEBUG_OSPF_NSSA
)
642 "%s: LSA Id %pI4, Forward address is 0, NO Translation",
643 __func__
, &lsa
->data
->id
);
647 /* try find existing AS-External LSA for this prefix */
648 old
= ospf_external_info_find_lsa(area
->ospf
, &p
);
650 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_IN_MAXAGE
)) {
651 /* if type-7 is removed, remove old translated type-5 lsa */
653 UNSET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
654 if (IS_DEBUG_OSPF_NSSA
)
656 "%s: remove old translated LSA id %pI4",
657 __func__
, &old
->data
->id
);
659 /* if type-7 is removed and type-5 does not exist, do not
664 if (old
&& CHECK_FLAG(old
->flags
, OSPF_LSA_APPROVED
)) {
665 if (IS_DEBUG_OSPF_NSSA
)
667 "%s: found old translated LSA Id %pI4, refreshing",
668 __func__
, &old
->data
->id
);
671 new = ospf_translated_nssa_refresh(area
->ospf
, lsa
, old
);
673 if (IS_DEBUG_OSPF_NSSA
)
675 "%s: could not refresh translated LSA Id %pI4",
676 __func__
, &old
->data
->id
);
679 /* no existing external route for this LSA Id
680 * originate translated LSA
683 if (ospf_translated_nssa_originate(area
->ospf
, lsa
, old
)
685 if (IS_DEBUG_OSPF_NSSA
)
687 "%s: Could not translate Type-7 for %pI4 to Type-5",
688 __func__
, &lsa
->data
->id
);
693 /* Area where Aggregate testing will be inserted, just like summary
695 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
700 static void ospf_abr_translate_nssa_range(struct prefix_ipv4
*p
, uint32_t cost
)
702 /* The Type-7 is created from the aggregated prefix and forwarded
703 for lsa installation and flooding... to be added... */
706 void ospf_abr_announce_network_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
707 struct ospf_area
*area
)
709 struct ospf_lsa
*lsa
, *old
= NULL
;
710 struct summary_lsa
*sl
= NULL
;
713 if (IS_DEBUG_OSPF_EVENT
)
714 zlog_debug("%s: Start", __func__
);
716 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
717 full_cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
721 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_SUMMARY_LSA
, p
,
722 area
->ospf
->router_id
);
724 if (IS_DEBUG_OSPF_EVENT
)
725 zlog_debug("%s: old summary found", __func__
);
727 sl
= (struct summary_lsa
*)old
->data
;
729 if (IS_DEBUG_OSPF_EVENT
)
730 zlog_debug("%s: old metric: %d, new metric: %d",
731 __func__
, GET_METRIC(sl
->metric
), cost
);
733 if ((GET_METRIC(sl
->metric
) == full_cost
)
734 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
735 /* unchanged. simply reapprove it */
736 if (IS_DEBUG_OSPF_EVENT
)
737 zlog_debug("%s: old summary approved",
739 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
741 /* LSA is changed, refresh it */
742 if (IS_DEBUG_OSPF_EVENT
)
743 zlog_debug("%s: refreshing summary", __func__
);
744 set_metric(old
, full_cost
);
745 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
748 flog_warn(EC_OSPF_LSA_MISSING
,
749 "%s: Could not refresh %pFX to %pI4",
750 __func__
, (struct prefix
*)p
,
755 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
756 /* This will flood through area. */
759 if (IS_DEBUG_OSPF_EVENT
)
760 zlog_debug("%s: creating new summary", __func__
);
761 lsa
= ospf_summary_lsa_originate(p
, full_cost
, area
);
762 /* This will flood through area. */
765 flog_warn(EC_OSPF_LSA_MISSING
,
766 "%s: Could not originate %pFX to %pi4",
767 __func__
, (struct prefix
*)p
,
772 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
773 if (IS_DEBUG_OSPF_EVENT
)
774 zlog_debug("%s: flooding new version of summary",
778 if (IS_DEBUG_OSPF_EVENT
)
779 zlog_debug("%s: Stop", __func__
);
782 static int ospf_abr_nexthops_belong_to_area(struct ospf_route
* or,
783 struct ospf_area
*area
)
785 struct listnode
*node
, *nnode
;
786 struct ospf_path
*path
;
787 struct ospf_interface
*oi
;
789 for (ALL_LIST_ELEMENTS_RO(or->paths
, node
, path
))
790 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, nnode
, oi
))
791 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
797 static int ospf_abr_should_accept(struct prefix_ipv4
*p
, struct ospf_area
*area
)
799 if (IMPORT_NAME(area
)) {
800 if (IMPORT_LIST(area
) == NULL
)
802 access_list_lookup(AFI_IP
, IMPORT_NAME(area
));
804 if (IMPORT_LIST(area
))
805 if (access_list_apply(IMPORT_LIST(area
), p
)
813 static int ospf_abr_plist_in_check(struct ospf_area
*area
,
814 struct ospf_route
* or,
815 struct prefix_ipv4
*p
)
817 if (PREFIX_NAME_IN(area
)) {
818 if (PREFIX_LIST_IN(area
) == NULL
)
819 PREFIX_LIST_IN(area
) = prefix_list_lookup(
820 AFI_IP
, PREFIX_NAME_IN(area
));
821 if (PREFIX_LIST_IN(area
))
822 if (prefix_list_apply(PREFIX_LIST_IN(area
), p
)
829 static int ospf_abr_plist_out_check(struct ospf_area
*area
,
830 struct ospf_route
* or,
831 struct prefix_ipv4
*p
)
833 if (PREFIX_NAME_OUT(area
)) {
834 if (PREFIX_LIST_OUT(area
) == NULL
)
835 PREFIX_LIST_OUT(area
) = prefix_list_lookup(
836 AFI_IP
, PREFIX_NAME_OUT(area
));
837 if (PREFIX_LIST_OUT(area
))
838 if (prefix_list_apply(PREFIX_LIST_OUT(area
), p
)
845 static void ospf_abr_announce_network(struct ospf
*ospf
, struct prefix_ipv4
*p
,
846 struct ospf_route
* or)
848 struct ospf_area_range
*range
;
849 struct ospf_area
*area
, *or_area
;
850 struct listnode
*node
;
852 if (IS_DEBUG_OSPF_EVENT
)
853 zlog_debug("%s: Start", __func__
);
855 or_area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
858 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
859 if (IS_DEBUG_OSPF_EVENT
)
860 zlog_debug("%s: looking at area %pI4", __func__
,
863 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
866 if (ospf_abr_nexthops_belong_to_area(or, area
))
869 if (!ospf_abr_should_accept(p
, area
)) {
870 if (IS_DEBUG_OSPF_EVENT
)
872 "%s: prefix %pFX was denied by import-list",
877 if (!ospf_abr_plist_in_check(area
, or, p
)) {
878 if (IS_DEBUG_OSPF_EVENT
)
880 "%s: prefix %pFX was denied by prefix-list",
885 if (area
->external_routing
!= OSPF_AREA_DEFAULT
886 && area
->no_summary
) {
887 if (IS_DEBUG_OSPF_EVENT
)
889 "%s: area %pI4 is stub and no_summary",
890 __func__
, &area
->area_id
);
894 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
895 if (IS_DEBUG_OSPF_EVENT
)
897 "%s: this is inter-area route to %pFX",
900 if (!OSPF_IS_AREA_BACKBONE(area
))
901 ospf_abr_announce_network_to_area(p
, or->cost
,
905 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
906 if (IS_DEBUG_OSPF_EVENT
)
908 "%s: this is intra-area route to %pFX",
910 if ((range
= ospf_area_range_match(or_area
, p
))
911 && !ospf_area_is_transit(area
))
912 ospf_abr_update_aggregate(range
, or, area
);
914 ospf_abr_announce_network_to_area(p
, or->cost
,
920 static int ospf_abr_should_announce(struct ospf
*ospf
, struct prefix_ipv4
*p
,
921 struct ospf_route
* or)
923 struct ospf_area
*area
;
925 area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
929 if (EXPORT_NAME(area
)) {
930 if (EXPORT_LIST(area
) == NULL
)
932 access_list_lookup(AFI_IP
, EXPORT_NAME(area
));
934 if (EXPORT_LIST(area
))
935 if (access_list_apply(EXPORT_LIST(area
), p
)
943 static void ospf_abr_process_nssa_translates(struct ospf
*ospf
)
945 /* Scan through all NSSA_LSDB records for all areas;
947 If P-bit is on, translate all Type-7's to 5's and aggregate or
948 flood install as approved in Type-5 LSDB with XLATE Flag on
949 later, do same for all aggregates... At end, DISCARD all
950 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
951 struct listnode
*node
;
952 struct ospf_area
*area
;
953 struct route_node
*rn
;
954 struct ospf_lsa
*lsa
;
956 if (IS_DEBUG_OSPF_NSSA
)
957 zlog_debug("%s: Start", __func__
);
959 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
960 if (!area
->NSSATranslatorState
)
961 continue; /* skip if not translator */
963 if (area
->external_routing
!= OSPF_AREA_NSSA
)
964 continue; /* skip if not Nssa Area */
966 if (IS_DEBUG_OSPF_NSSA
)
967 zlog_debug("%s(): looking at area %pI4", __func__
,
970 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
971 ospf_abr_translate_nssa(area
, lsa
);
974 if (IS_DEBUG_OSPF_NSSA
)
975 zlog_debug("%s: Stop", __func__
);
978 static void ospf_abr_process_network_rt(struct ospf
*ospf
,
979 struct route_table
*rt
)
981 struct ospf_area
*area
;
982 struct ospf_route
* or ;
983 struct route_node
*rn
;
985 if (IS_DEBUG_OSPF_EVENT
)
986 zlog_debug("%s: Start", __func__
);
988 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
989 if ((or = rn
->info
) == NULL
)
992 if (!(area
= ospf_area_lookup_by_area_id(ospf
,
993 or->u
.std
.area_id
))) {
994 if (IS_DEBUG_OSPF_EVENT
)
996 "%s: area %pI4 no longer exists", __func__
,
1001 if (IS_DEBUG_OSPF_EVENT
)
1002 zlog_debug("%s: this is a route to %pFX", __func__
,
1004 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
) {
1005 if (IS_DEBUG_OSPF_EVENT
)
1007 "%s: this is an External router, skipping",
1012 if (or->cost
>= OSPF_LS_INFINITY
) {
1013 if (IS_DEBUG_OSPF_EVENT
)
1015 "%s: this route's cost is infinity, skipping",
1020 if (or->type
== OSPF_DESTINATION_DISCARD
) {
1021 if (IS_DEBUG_OSPF_EVENT
)
1023 "%s: this is a discard entry, skipping",
1029 or->path_type
== OSPF_PATH_INTRA_AREA
1030 && !ospf_abr_should_announce(
1031 ospf
, (struct prefix_ipv4
*)&rn
->p
,
1033 if (IS_DEBUG_OSPF_EVENT
)
1034 zlog_debug("%s: denied by export-list",
1040 or->path_type
== OSPF_PATH_INTRA_AREA
1041 && !ospf_abr_plist_out_check(
1043 (struct prefix_ipv4
*)&rn
->p
)) {
1044 if (IS_DEBUG_OSPF_EVENT
)
1045 zlog_debug("%s: denied by prefix-list",
1050 if ((or->path_type
== OSPF_PATH_INTER_AREA
)
1051 && !OSPF_IS_AREA_ID_BACKBONE(or->u
.std
.area_id
)) {
1052 if (IS_DEBUG_OSPF_EVENT
)
1054 "%s: this route is not backbone one, skipping",
1060 if ((ospf
->abr_type
== OSPF_ABR_CISCO
)
1061 || (ospf
->abr_type
== OSPF_ABR_IBM
))
1063 if (!ospf_act_bb_connection(ospf
) &&
1064 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1065 if (IS_DEBUG_OSPF_EVENT
)
1067 "%s: ALT ABR: No BB connection, skip not intra-area routes",
1072 if (IS_DEBUG_OSPF_EVENT
)
1073 zlog_debug("%s: announcing", __func__
);
1074 ospf_abr_announce_network(ospf
, (struct prefix_ipv4
*)&rn
->p
,
1078 if (IS_DEBUG_OSPF_EVENT
)
1079 zlog_debug("%s: Stop", __func__
);
1082 static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
1083 struct ospf_area
*area
)
1085 struct ospf_lsa
*lsa
, *old
= NULL
;
1086 struct summary_lsa
*slsa
= NULL
;
1088 if (IS_DEBUG_OSPF_EVENT
)
1089 zlog_debug("%s: Start", __func__
);
1091 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
,
1092 area
->ospf
->router_id
);
1094 if (IS_DEBUG_OSPF_EVENT
)
1095 zlog_debug("%s: old summary found", __func__
);
1096 slsa
= (struct summary_lsa
*)old
->data
;
1098 if (IS_DEBUG_OSPF_EVENT
)
1099 zlog_debug("%s: old metric: %d, new metric: %d",
1100 __func__
, GET_METRIC(slsa
->metric
), cost
);
1103 if (old
&& (GET_METRIC(slsa
->metric
) == cost
)
1104 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
1105 if (IS_DEBUG_OSPF_EVENT
)
1106 zlog_debug("%s: old summary approved", __func__
);
1107 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
1109 if (IS_DEBUG_OSPF_EVENT
)
1110 zlog_debug("%s: 2.2", __func__
);
1113 set_metric(old
, cost
);
1114 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
1116 lsa
= ospf_summary_asbr_lsa_originate(p
, cost
, area
);
1118 flog_warn(EC_OSPF_LSA_MISSING
,
1119 "%s: Could not refresh/originate %pFX to %pI4",
1120 __func__
, (struct prefix
*)p
,
1125 if (IS_DEBUG_OSPF_EVENT
)
1126 zlog_debug("%s: flooding new version of summary",
1130 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new
1132 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1134 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1135 /* ospf_flood_through_area (area, NULL, lsa);*/
1138 if (IS_DEBUG_OSPF_EVENT
)
1139 zlog_debug("%s: Stop", __func__
);
1143 static void ospf_abr_announce_rtr(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1144 struct ospf_route
* or)
1146 struct listnode
*node
;
1147 struct ospf_area
*area
;
1149 if (IS_DEBUG_OSPF_EVENT
)
1150 zlog_debug("%s: Start", __func__
);
1152 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1153 if (IS_DEBUG_OSPF_EVENT
)
1154 zlog_debug("%s: looking at area %pI4", __func__
,
1157 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
1160 if (ospf_abr_nexthops_belong_to_area(or, area
))
1163 /* RFC3101: Do not generate ASBR type 4 LSA if NSSA ABR */
1164 if (or->u
.std
.external_routing
== OSPF_AREA_NSSA
) {
1165 if (IS_DEBUG_OSPF_EVENT
)
1167 "%s: do not generate LSA Type-4 %pI4 from NSSA",
1168 __func__
, &p
->prefix
);
1172 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
1173 if (IS_DEBUG_OSPF_EVENT
)
1175 "%s: area %pI4 doesn't support external routing",
1176 __func__
, &area
->area_id
);
1180 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
1181 if (IS_DEBUG_OSPF_EVENT
)
1183 "%s: this is inter-area route to %pI4",
1184 __func__
, &p
->prefix
);
1185 if (!OSPF_IS_AREA_BACKBONE(area
))
1186 ospf_abr_announce_rtr_to_area(p
, or->cost
,
1190 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
1191 if (IS_DEBUG_OSPF_EVENT
)
1193 "%s: this is intra-area route to %pI4",
1194 __func__
, &p
->prefix
);
1195 ospf_abr_announce_rtr_to_area(p
, or->cost
, area
);
1199 if (IS_DEBUG_OSPF_EVENT
)
1200 zlog_debug("%s: Stop", __func__
);
1203 static void ospf_abr_process_router_rt(struct ospf
*ospf
,
1204 struct route_table
*rt
)
1206 struct ospf_route
* or ;
1207 struct route_node
*rn
;
1210 if (IS_DEBUG_OSPF_EVENT
)
1211 zlog_debug("%s: Start", __func__
);
1213 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1214 struct listnode
*node
, *nnode
;
1216 struct ospf_route
*best
= NULL
;
1218 if (rn
->info
== NULL
)
1223 if (IS_DEBUG_OSPF_EVENT
)
1224 zlog_debug("%s: this is a route to %pI4", __func__
,
1227 for (ALL_LIST_ELEMENTS(l
, node
, nnode
, or)) {
1228 if (!ospf_area_lookup_by_area_id(ospf
,
1229 or->u
.std
.area_id
)) {
1230 if (IS_DEBUG_OSPF_EVENT
)
1232 "%s: area %pI4 no longer exists", __func__
,
1233 &or->u
.std
.area_id
);
1238 if (!CHECK_FLAG(or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
)) {
1239 if (IS_DEBUG_OSPF_EVENT
)
1241 "%s: This is not an ASBR, skipping",
1247 best
= ospf_find_asbr_route(
1248 ospf
, rt
, (struct prefix_ipv4
*)&rn
->p
);
1256 if (IS_DEBUG_OSPF_EVENT
)
1258 "%s: This route is not the best among possible, skipping",
1264 or->path_type
== OSPF_PATH_INTER_AREA
1265 && !OSPF_IS_AREA_ID_BACKBONE(
1266 or->u
.std
.area_id
)) {
1267 if (IS_DEBUG_OSPF_EVENT
)
1269 "%s: This route is not a backbone one, skipping",
1274 if (or->cost
>= OSPF_LS_INFINITY
) {
1275 if (IS_DEBUG_OSPF_EVENT
)
1277 "%s: This route has LS_INFINITY metric, skipping",
1282 if (ospf
->abr_type
== OSPF_ABR_CISCO
1283 || ospf
->abr_type
== OSPF_ABR_IBM
)
1284 if (!ospf_act_bb_connection(ospf
) &&
1285 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1286 if (IS_DEBUG_OSPF_EVENT
)
1288 "%s: ALT ABR: No BB connection, skip not intra-area routes",
1293 ospf_abr_announce_rtr(ospf
,
1294 (struct prefix_ipv4
*)&rn
->p
, or);
1298 if (IS_DEBUG_OSPF_EVENT
)
1299 zlog_debug("%s: Stop", __func__
);
1303 ospf_abr_unapprove_translates(struct ospf
*ospf
) /* For NSSA Translations */
1305 struct ospf_lsa
*lsa
;
1306 struct route_node
*rn
;
1308 if (IS_DEBUG_OSPF_NSSA
)
1309 zlog_debug("%s: Start", __func__
);
1311 /* NSSA Translator is not checked, because it may have gone away,
1312 and we would want to flush any residuals anyway */
1314 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1315 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) {
1316 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1317 if (IS_DEBUG_OSPF_NSSA
)
1318 zlog_debug("%s: approved unset on link id %pI4",
1319 __func__
, &lsa
->data
->id
);
1322 if (IS_DEBUG_OSPF_NSSA
)
1323 zlog_debug("%s: Stop", __func__
);
1326 static void ospf_abr_unapprove_summaries(struct ospf
*ospf
)
1328 struct listnode
*node
;
1329 struct ospf_area
*area
;
1330 struct route_node
*rn
;
1331 struct ospf_lsa
*lsa
;
1333 if (IS_DEBUG_OSPF_EVENT
)
1334 zlog_debug("%s: Start", __func__
);
1336 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1337 if (IS_DEBUG_OSPF_EVENT
)
1338 zlog_debug("%s: considering area %pI4", __func__
,
1340 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1341 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1342 if (IS_DEBUG_OSPF_EVENT
)
1344 "%s: approved unset on summary link id %pI4",
1345 __func__
, &lsa
->data
->id
);
1346 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1349 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1350 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1351 if (IS_DEBUG_OSPF_EVENT
)
1353 "%s: approved unset on asbr-summary link id %pI4",
1354 __func__
, &lsa
->data
->id
);
1355 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1359 if (IS_DEBUG_OSPF_EVENT
)
1360 zlog_debug("%s: Stop", __func__
);
1363 static void ospf_abr_prepare_aggregates(struct ospf
*ospf
)
1365 struct listnode
*node
;
1366 struct route_node
*rn
;
1367 struct ospf_area_range
*range
;
1368 struct ospf_area
*area
;
1370 if (IS_DEBUG_OSPF_EVENT
)
1371 zlog_debug("%s: Start", __func__
);
1373 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1374 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1375 if ((range
= rn
->info
) != NULL
) {
1377 range
->specifics
= 0;
1381 if (IS_DEBUG_OSPF_EVENT
)
1382 zlog_debug("%s: Stop", __func__
);
1385 static void ospf_abr_announce_aggregates(struct ospf
*ospf
)
1387 struct ospf_area
*area
, *ar
;
1388 struct ospf_area_range
*range
;
1389 struct route_node
*rn
;
1391 struct listnode
*node
, *n
;
1393 if (IS_DEBUG_OSPF_EVENT
)
1394 zlog_debug("%s: Start", __func__
);
1396 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1397 if (IS_DEBUG_OSPF_EVENT
)
1398 zlog_debug("%s: looking at area %pI4", __func__
,
1401 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1402 if ((range
= rn
->info
)) {
1403 if (!CHECK_FLAG(range
->flags
,
1404 OSPF_AREA_RANGE_ADVERTISE
)) {
1405 if (IS_DEBUG_OSPF_EVENT
)
1407 "%s: discarding suppress-ranges",
1413 p
.u
.prefix4
= range
->addr
;
1414 p
.prefixlen
= range
->masklen
;
1416 if (IS_DEBUG_OSPF_EVENT
)
1417 zlog_debug("%s: this is range: %pFX",
1420 if (CHECK_FLAG(range
->flags
,
1421 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1423 p
.u
.prefix4
= range
->subst_addr
;
1424 p
.prefixlen
= range
->subst_masklen
;
1427 if (range
->specifics
) {
1428 if (IS_DEBUG_OSPF_EVENT
)
1429 zlog_debug("%s: active range",
1432 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
,
1437 /* We do not check nexthops
1439 intra-area routes can be
1443 /* backbone routes are not
1445 when announced into transit
1448 if (ospf_area_is_transit(ar
)
1449 && OSPF_IS_AREA_BACKBONE(
1451 if (IS_DEBUG_OSPF_EVENT
)
1453 "%s: Skipping announcement of BB aggregate into a transit area",
1457 ospf_abr_announce_network_to_area(
1466 if (IS_DEBUG_OSPF_EVENT
)
1467 zlog_debug("%s: Stop", __func__
);
1471 ospf_abr_send_nssa_aggregates(struct ospf
*ospf
) /* temporarily turned off */
1473 struct listnode
*node
; /*, n; */
1474 struct ospf_area
*area
; /*, *ar; */
1475 struct route_node
*rn
;
1476 struct ospf_area_range
*range
;
1477 struct prefix_ipv4 p
;
1479 if (IS_DEBUG_OSPF_NSSA
)
1480 zlog_debug("%s: Start", __func__
);
1482 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1483 if (!area
->NSSATranslatorState
)
1486 if (IS_DEBUG_OSPF_NSSA
)
1487 zlog_debug("%s: looking at area %pI4", __func__
,
1490 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
)) {
1491 if (rn
->info
== NULL
)
1496 if (!CHECK_FLAG(range
->flags
,
1497 OSPF_AREA_RANGE_ADVERTISE
)) {
1498 if (IS_DEBUG_OSPF_NSSA
)
1500 "%s: discarding suppress-ranges",
1506 p
.prefix
= range
->addr
;
1507 p
.prefixlen
= range
->masklen
;
1509 if (IS_DEBUG_OSPF_NSSA
)
1510 zlog_debug("%s: this is range: %pFX", __func__
,
1513 if (CHECK_FLAG(range
->flags
,
1514 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1516 p
.prefix
= range
->subst_addr
;
1517 p
.prefixlen
= range
->subst_masklen
;
1520 if (range
->specifics
) {
1521 if (IS_DEBUG_OSPF_NSSA
)
1522 zlog_debug("%s: active range",
1525 /* Fetch LSA-Type-7 from aggregate prefix, and
1527 * translate, Install (as Type-5), Approve, and
1530 ospf_abr_translate_nssa_range(&p
, range
->cost
);
1532 } /* all area ranges*/
1535 if (IS_DEBUG_OSPF_NSSA
)
1536 zlog_debug("%s: Stop", __func__
);
1539 static void ospf_abr_announce_stub_defaults(struct ospf
*ospf
)
1541 struct listnode
*node
;
1542 struct ospf_area
*area
;
1543 struct prefix_ipv4 p
;
1545 if (!IS_OSPF_ABR(ospf
))
1548 if (IS_DEBUG_OSPF_EVENT
)
1549 zlog_debug("%s: Start", __func__
);
1552 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1555 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1556 if (IS_DEBUG_OSPF_EVENT
)
1557 zlog_debug("%s: looking at area %pI4", __func__
,
1560 if ((area
->external_routing
!= OSPF_AREA_STUB
)
1561 && (area
->external_routing
!= OSPF_AREA_NSSA
))
1564 if (OSPF_IS_AREA_BACKBONE(area
))
1565 continue; /* Sanity Check */
1567 if (IS_DEBUG_OSPF_EVENT
)
1568 zlog_debug("%s: announcing 0.0.0.0/0 to area %pI4",
1569 __func__
, &area
->area_id
);
1570 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1573 if (IS_DEBUG_OSPF_EVENT
)
1574 zlog_debug("%s: Stop", __func__
);
1577 static int ospf_abr_remove_unapproved_translates_apply(struct ospf
*ospf
,
1578 struct ospf_lsa
*lsa
)
1580 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1581 && !CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
)) {
1582 zlog_info("%s: removing unapproved translates, ID: %pI4",
1583 __func__
, &lsa
->data
->id
);
1585 /* FLUSH THROUGHOUT AS */
1586 ospf_lsa_flush_as(ospf
, lsa
);
1588 /* DISCARD from LSDB */
1593 static void ospf_abr_remove_unapproved_translates(struct ospf
*ospf
)
1595 struct route_node
*rn
;
1596 struct ospf_lsa
*lsa
;
1598 /* All AREA PROCESS should have APPROVED necessary LSAs */
1599 /* Remove any left over and not APPROVED */
1600 if (IS_DEBUG_OSPF_NSSA
)
1601 zlog_debug("%s: Start", __func__
);
1603 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1604 ospf_abr_remove_unapproved_translates_apply(ospf
, lsa
);
1606 if (IS_DEBUG_OSPF_NSSA
)
1607 zlog_debug("%s: Stop", __func__
);
1610 static void ospf_abr_remove_unapproved_summaries(struct ospf
*ospf
)
1612 struct listnode
*node
;
1613 struct ospf_area
*area
;
1614 struct route_node
*rn
;
1615 struct ospf_lsa
*lsa
;
1617 if (IS_DEBUG_OSPF_EVENT
)
1618 zlog_debug("%s: Start", __func__
);
1620 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1621 if (IS_DEBUG_OSPF_EVENT
)
1622 zlog_debug("%s: looking at area %pI4", __func__
,
1625 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1626 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1627 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1628 ospf_lsa_flush_area(lsa
, area
);
1630 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1631 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1632 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1633 ospf_lsa_flush_area(lsa
, area
);
1636 if (IS_DEBUG_OSPF_EVENT
)
1637 zlog_debug("%s: Stop", __func__
);
1640 static void ospf_abr_manage_discard_routes(struct ospf
*ospf
)
1642 struct listnode
*node
, *nnode
;
1643 struct route_node
*rn
;
1644 struct ospf_area
*area
;
1645 struct ospf_area_range
*range
;
1647 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
1648 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1649 if ((range
= rn
->info
) != NULL
)
1650 if (CHECK_FLAG(range
->flags
,
1651 OSPF_AREA_RANGE_ADVERTISE
)) {
1652 if (range
->specifics
)
1653 ospf_add_discard_route(
1654 ospf
, ospf
->new_table
,
1659 ospf_delete_discard_route(
1660 ospf
, ospf
->new_table
,
1666 /* This is the function taking care about ABR NSSA, i.e. NSSA
1667 Translator, -LSA aggregation and flooding. For all NSSAs
1669 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1670 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1673 Any received Type-5s are legal for an ABR, else illegal for IR.
1674 Received Type-7s are installed, by area, with incoming P-bit. They
1675 are flooded; if the Elected NSSA Translator, then P-bit off.
1677 Additionally, this ABR will place "translated type-7's" into the
1678 Type-5 LSDB in order to keep track of APPROVAL or not.
1680 It will scan through every area, looking for Type-7 LSAs with P-Bit
1681 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1682 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1685 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1686 left over are FLUSHED and DISCARDED.
1688 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1689 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1691 static void ospf_abr_nssa_task(struct ospf
*ospf
) /* called only if any_nssa */
1693 if (ospf
->gr_info
.restart_in_progress
)
1696 if (IS_DEBUG_OSPF_NSSA
)
1697 zlog_debug("Check for NSSA-ABR Tasks():");
1699 if (!IS_OSPF_ABR(ospf
))
1705 /* Each area must confirm TranslatorRole */
1706 if (IS_DEBUG_OSPF_NSSA
)
1707 zlog_debug("%s: Start", __func__
);
1709 /* For all Global Entries flagged "local-translate", unset APPROVED */
1710 if (IS_DEBUG_OSPF_NSSA
)
1711 zlog_debug("%s: unapprove translates", __func__
);
1713 ospf_abr_unapprove_translates(ospf
);
1715 /* RESET all Ranges in every Area, same as summaries */
1716 if (IS_DEBUG_OSPF_NSSA
)
1717 zlog_debug("%s: NSSA initialize aggregates", __func__
);
1718 ospf_abr_prepare_aggregates(ospf
); /*TURNED OFF just for now */
1720 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1721 * Aggregate as Type-7
1722 * Install or Approve in Type-5 Global LSDB
1724 if (IS_DEBUG_OSPF_NSSA
)
1725 zlog_debug("%s: process translates", __func__
);
1726 ospf_abr_process_nssa_translates(ospf
);
1728 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1730 * Scan Type-7's for aggregates, translate to Type-5's,
1731 * Install/Flood/Approve
1733 if (IS_DEBUG_OSPF_NSSA
)
1734 zlog_debug("%s: send NSSA aggregates", __func__
);
1735 ospf_abr_send_nssa_aggregates(ospf
); /*TURNED OFF FOR NOW */
1737 /* Send any NSSA defaults as Type-5
1738 *if (IS_DEBUG_OSPF_NSSA)
1739 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1740 *ospf_abr_announce_nssa_defaults (ospf);
1741 * havnt a clue what above is supposed to do.
1744 /* Flush any unapproved previous translates from Global Data Base */
1745 if (IS_DEBUG_OSPF_NSSA
)
1746 zlog_debug("%s: remove unapproved translates", __func__
);
1747 ospf_abr_remove_unapproved_translates(ospf
);
1749 ospf_abr_manage_discard_routes(ospf
); /* same as normal...discard */
1751 if (IS_DEBUG_OSPF_NSSA
)
1752 zlog_debug("%s: Stop", __func__
);
1755 /* This is the function taking care about ABR stuff, i.e.
1756 summary-LSA origination and flooding. */
1757 void ospf_abr_task(struct ospf
*ospf
)
1759 if (ospf
->gr_info
.restart_in_progress
)
1762 if (IS_DEBUG_OSPF_EVENT
)
1763 zlog_debug("%s: Start", __func__
);
1765 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
) {
1766 if (IS_DEBUG_OSPF_EVENT
)
1767 zlog_debug("%s: Routing tables are not yet ready",
1772 if (IS_DEBUG_OSPF_EVENT
)
1773 zlog_debug("%s: unapprove summaries", __func__
);
1774 ospf_abr_unapprove_summaries(ospf
);
1776 if (IS_DEBUG_OSPF_EVENT
)
1777 zlog_debug("%s: prepare aggregates", __func__
);
1778 ospf_abr_prepare_aggregates(ospf
);
1780 if (IS_OSPF_ABR(ospf
)) {
1781 if (IS_DEBUG_OSPF_EVENT
)
1782 zlog_debug("%s: process network RT", __func__
);
1783 ospf_abr_process_network_rt(ospf
, ospf
->new_table
);
1785 if (IS_DEBUG_OSPF_EVENT
)
1786 zlog_debug("%s: process router RT", __func__
);
1787 ospf_abr_process_router_rt(ospf
, ospf
->new_rtrs
);
1789 if (IS_DEBUG_OSPF_EVENT
)
1790 zlog_debug("%s: announce aggregates", __func__
);
1791 ospf_abr_announce_aggregates(ospf
);
1793 if (IS_DEBUG_OSPF_EVENT
)
1794 zlog_debug("%s: announce stub defaults", __func__
);
1795 ospf_abr_announce_stub_defaults(ospf
);
1798 if (IS_DEBUG_OSPF_EVENT
)
1799 zlog_debug("%s: remove unapproved summaries", __func__
);
1800 ospf_abr_remove_unapproved_summaries(ospf
);
1802 ospf_abr_manage_discard_routes(ospf
);
1804 if (IS_DEBUG_OSPF_EVENT
)
1805 zlog_debug("%s: Stop", __func__
);
1808 static void ospf_abr_task_timer(struct thread
*thread
)
1810 struct ospf
*ospf
= THREAD_ARG(thread
);
1812 ospf
->t_abr_task
= 0;
1814 if (IS_DEBUG_OSPF_EVENT
)
1815 zlog_debug("Running ABR task on timer");
1817 ospf_check_abr_status(ospf
);
1818 ospf_abr_nssa_check_status(ospf
);
1820 ospf_abr_task(ospf
);
1821 ospf_abr_nssa_task(ospf
); /* if nssa-abr, then scan Type-7 LSDB */
1824 void ospf_schedule_abr_task(struct ospf
*ospf
)
1826 if (IS_DEBUG_OSPF_EVENT
)
1827 zlog_debug("Scheduling ABR task");
1829 thread_add_timer(master
, ospf_abr_task_timer
, ospf
, OSPF_ABR_TASK_DELAY
,