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 if (ospf
->backbone
== NULL
)
324 return ospf
->backbone
->full_nbrs
;
327 /* Determine whether this router is elected translator or not for area */
328 static int ospf_abr_nssa_am_elected(struct ospf_area
*area
)
330 struct route_node
*rn
;
331 struct ospf_lsa
*lsa
;
332 struct router_lsa
*rlsa
;
333 struct in_addr
*best
= NULL
;
335 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
) {
337 if (!lsa
|| (lsa
->data
->type
!= OSPF_ROUTER_LSA
)
341 rlsa
= (struct router_lsa
*)lsa
->data
;
343 /* ignore non-ABR routers */
344 if (!IS_ROUTER_LSA_BORDER(rlsa
))
347 /* Router has Nt flag - always translate */
348 if (IS_ROUTER_LSA_NT(rlsa
)) {
349 if (IS_DEBUG_OSPF_NSSA
)
351 "ospf_abr_nssa_am_elected: "
352 "router %s asserts Nt",
353 inet_ntoa(lsa
->data
->id
));
358 best
= &lsa
->data
->id
;
359 else if (IPV4_ADDR_CMP(&best
->s_addr
, &lsa
->data
->id
.s_addr
)
361 best
= &lsa
->data
->id
;
364 if (IS_DEBUG_OSPF_NSSA
)
366 "ospf_abr_nssa_am_elected: best electable ABR is: %s",
367 (best
) ? inet_ntoa(*best
) : "<none>");
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 static 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
))
394 "ospf_abr_nssa_check_status: "
396 inet_ntoa(area
->area_id
));
398 if (!IS_OSPF_ABR(area
->ospf
)) {
399 if (IS_DEBUG_OSPF(nssa
, NSSA
))
401 "ospf_abr_nssa_check_status: "
403 area
->NSSATranslatorState
=
404 OSPF_NSSA_TRANSLATE_DISABLED
;
406 switch (area
->NSSATranslatorRole
) {
407 case OSPF_NSSA_ROLE_NEVER
:
408 /* We never Translate Type-7 LSA. */
409 /* TODO: check previous state and flush? */
410 if (IS_DEBUG_OSPF(nssa
, NSSA
))
412 "ospf_abr_nssa_check_status: "
414 area
->NSSATranslatorState
=
415 OSPF_NSSA_TRANSLATE_DISABLED
;
418 case OSPF_NSSA_ROLE_ALWAYS
:
419 /* We always translate if we are an ABR
420 * TODO: originate new LSAs if state change?
421 * or let the nssa abr task take care of it?
423 if (IS_DEBUG_OSPF(nssa
, NSSA
))
425 "ospf_abr_nssa_check_status: "
427 area
->NSSATranslatorState
=
428 OSPF_NSSA_TRANSLATE_ENABLED
;
431 case OSPF_NSSA_ROLE_CANDIDATE
:
432 /* We are a candidate for Translation */
433 if (ospf_abr_nssa_am_elected(area
) > 0) {
434 area
->NSSATranslatorState
=
435 OSPF_NSSA_TRANSLATE_ENABLED
;
436 if (IS_DEBUG_OSPF(nssa
, NSSA
))
438 "ospf_abr_nssa_check_status: "
439 "elected translator");
441 area
->NSSATranslatorState
=
442 OSPF_NSSA_TRANSLATE_DISABLED
;
443 if (IS_DEBUG_OSPF(nssa
, NSSA
))
445 "ospf_abr_nssa_check_status: "
452 * All NSSA border routers must set the E-bit in the Type-1
454 * of their directly attached non-stub areas, even when they are
458 if (old_state
!= area
->NSSATranslatorState
) {
459 if (old_state
== OSPF_NSSA_TRANSLATE_DISABLED
)
460 ospf_asbr_status_update(ospf
,
461 ++ospf
->redistribute
);
462 else if (area
->NSSATranslatorState
463 == OSPF_NSSA_TRANSLATE_DISABLED
)
464 ospf_asbr_status_update(ospf
,
465 --ospf
->redistribute
);
470 /* Check area border router status. */
471 void ospf_check_abr_status(struct ospf
*ospf
)
473 struct ospf_area
*area
;
474 struct listnode
*node
, *nnode
;
475 int bb_configured
= 0;
476 int bb_act_attached
= 0;
477 int areas_configured
= 0;
478 int areas_act_attached
= 0;
479 uint8_t new_flags
= ospf
->flags
;
481 if (IS_DEBUG_OSPF_EVENT
)
482 zlog_debug("ospf_check_abr_status(): Start");
484 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
485 if (listcount(area
->oiflist
)) {
488 if (OSPF_IS_AREA_BACKBONE(area
))
492 if (ospf_area_actively_attached(area
)) {
493 areas_act_attached
++;
495 if (OSPF_IS_AREA_BACKBONE(area
))
500 if (IS_DEBUG_OSPF_EVENT
) {
501 zlog_debug("ospf_check_abr_status(): looked through areas");
502 zlog_debug("ospf_check_abr_status(): bb_configured: %d",
504 zlog_debug("ospf_check_abr_status(): bb_act_attached: %d",
506 zlog_debug("ospf_check_abr_status(): areas_configured: %d",
508 zlog_debug("ospf_check_abr_status(): areas_act_attached: %d",
512 switch (ospf
->abr_type
) {
513 case OSPF_ABR_SHORTCUT
:
515 if (areas_act_attached
> 1)
516 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
518 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
522 if ((areas_act_attached
> 1) && bb_configured
)
523 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
525 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
529 if ((areas_configured
> 1) && bb_act_attached
)
530 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
532 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
538 if (new_flags
!= ospf
->flags
) {
539 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_ABR_STATUS_CHANGE
);
540 if (IS_DEBUG_OSPF_EVENT
)
542 "ospf_check_abr_status(): new router flags: %x",
544 ospf
->flags
= new_flags
;
545 ospf_router_lsa_update(ospf
);
549 static void ospf_abr_update_aggregate(struct ospf_area_range
*range
,
550 struct ospf_route
* or,
551 struct ospf_area
*area
)
553 if (IS_DEBUG_OSPF_EVENT
)
554 zlog_debug("ospf_abr_update_aggregate(): Start");
556 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)
557 && (range
->cost
!= OSPF_STUB_MAX_METRIC_SUMMARY_COST
)) {
558 range
->cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
559 if (IS_DEBUG_OSPF_EVENT
)
561 "ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
563 } else if (range
->cost_config
!= OSPF_AREA_RANGE_COST_UNSPEC
) {
564 if (IS_DEBUG_OSPF_EVENT
)
566 "ospf_abr_update_aggregate(): use configured cost %d",
569 range
->cost
= range
->cost_config
;
571 if (range
->specifics
== 0) {
572 if (IS_DEBUG_OSPF_EVENT
)
574 "ospf_abr_update_aggregate(): use or->cost %d",
577 range
->cost
= or->cost
; /* 1st time get 1st cost */
580 if (or->cost
> range
->cost
) {
581 if (IS_DEBUG_OSPF_EVENT
)
583 "ospf_abr_update_aggregate(): update to %d",
586 range
->cost
= or->cost
;
593 static void set_metric(struct ospf_lsa
*lsa
, uint32_t metric
)
595 struct summary_lsa
*header
;
597 metric
= htonl(metric
);
598 mp
= (uint8_t *)&metric
;
600 header
= (struct summary_lsa
*)lsa
->data
;
601 memcpy(header
->metric
, mp
, 3);
604 /* ospf_abr_translate_nssa */
605 static int ospf_abr_translate_nssa(struct ospf_area
*area
, struct ospf_lsa
*lsa
)
607 /* Incoming Type-7 or later aggregated Type-7
609 * LSA is skipped if P-bit is off.
610 * LSA is aggregated if within range.
612 * The Type-7 is translated, Installed/Approved as a Type-5 into
613 * global LSDB, then Flooded through AS
615 * Later, any Unapproved Translated Type-5's are flushed/discarded
618 struct ospf_lsa
*old
= NULL
, *new = NULL
;
619 struct as_external_lsa
*ext7
;
620 struct prefix_ipv4 p
;
622 if (!CHECK_FLAG(lsa
->data
->options
, OSPF_OPTION_NP
)) {
623 if (IS_DEBUG_OSPF_NSSA
)
625 "ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
626 inet_ntoa(lsa
->data
->id
));
630 if (IS_DEBUG_OSPF_NSSA
)
632 "ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
633 inet_ntoa(lsa
->data
->id
));
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 "ospf_abr_translate_nssa(): LSA Id %s, "
643 "Forward address is 0, NO Translation",
644 inet_ntoa(lsa
->data
->id
));
648 /* try find existing AS-External LSA for this prefix */
650 old
= ospf_external_info_find_lsa(area
->ospf
, &p
);
653 if (IS_DEBUG_OSPF_NSSA
)
655 "ospf_abr_translate_nssa(): "
656 "found old translated LSA Id %s, refreshing",
657 inet_ntoa(old
->data
->id
));
660 new = ospf_translated_nssa_refresh(area
->ospf
, lsa
, old
);
662 if (IS_DEBUG_OSPF_NSSA
)
664 "ospf_abr_translate_nssa(): "
665 "could not refresh translated LSA Id %s",
666 inet_ntoa(old
->data
->id
));
669 /* no existing external route for this LSA Id
670 * originate translated LSA
673 if (ospf_translated_nssa_originate(area
->ospf
, lsa
) == NULL
) {
674 if (IS_DEBUG_OSPF_NSSA
)
676 "ospf_abr_translate_nssa(): Could not translate "
677 "Type-7 for %s to Type-5",
678 inet_ntoa(lsa
->data
->id
));
683 /* Area where Aggregate testing will be inserted, just like summary
685 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
690 static void ospf_abr_translate_nssa_range(struct prefix_ipv4
*p
, uint32_t cost
)
692 /* The Type-7 is created from the aggregated prefix and forwarded
693 for lsa installation and flooding... to be added... */
696 void ospf_abr_announce_network_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
697 struct ospf_area
*area
)
699 struct ospf_lsa
*lsa
, *old
= NULL
;
700 struct summary_lsa
*sl
= NULL
;
703 if (IS_DEBUG_OSPF_EVENT
)
704 zlog_debug("ospf_abr_announce_network_to_area(): Start");
706 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
707 full_cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
711 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_SUMMARY_LSA
,
712 (struct prefix_ipv4
*)p
,
713 area
->ospf
->router_id
);
715 if (IS_DEBUG_OSPF_EVENT
)
717 "ospf_abr_announce_network_to_area(): old summary found");
719 sl
= (struct summary_lsa
*)old
->data
;
721 if (IS_DEBUG_OSPF_EVENT
)
723 "ospf_abr_announce_network_to_area(): "
724 "old metric: %d, new metric: %d",
725 GET_METRIC(sl
->metric
), cost
);
727 if ((GET_METRIC(sl
->metric
) == full_cost
)
728 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
729 /* unchanged. simply reapprove it */
730 if (IS_DEBUG_OSPF_EVENT
)
732 "ospf_abr_announce_network_to_area(): "
733 "old summary approved");
734 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
736 /* LSA is changed, refresh it */
737 if (IS_DEBUG_OSPF_EVENT
)
739 "ospf_abr_announce_network_to_area(): "
740 "refreshing summary");
741 set_metric(old
, full_cost
);
742 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
745 char buf
[PREFIX2STR_BUFFER
];
747 prefix2str((struct prefix
*)p
, buf
,
749 flog_warn(EC_OSPF_LSA_MISSING
,
750 "%s: Could not refresh %s to %s",
752 inet_ntoa(area
->area_id
));
756 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
757 /* This will flood through area. */
760 if (IS_DEBUG_OSPF_EVENT
)
762 "ospf_abr_announce_network_to_area(): "
763 "creating new summary");
764 lsa
= ospf_summary_lsa_originate((struct prefix_ipv4
*)p
,
766 /* This will flood through area. */
769 char buf
[PREFIX2STR_BUFFER
];
771 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
772 flog_warn(EC_OSPF_LSA_MISSING
,
773 "%s: Could not originate %s to %s", __func__
,
774 buf
, inet_ntoa(area
->area_id
));
778 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
779 if (IS_DEBUG_OSPF_EVENT
)
781 "ospf_abr_announce_network_to_area(): "
782 "flooding new version of summary");
785 if (IS_DEBUG_OSPF_EVENT
)
786 zlog_debug("ospf_abr_announce_network_to_area(): Stop");
789 static int ospf_abr_nexthops_belong_to_area(struct ospf_route
* or,
790 struct ospf_area
*area
)
792 struct listnode
*node
, *nnode
;
793 struct ospf_path
*path
;
794 struct ospf_interface
*oi
;
796 for (ALL_LIST_ELEMENTS_RO(or->paths
, node
, path
))
797 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, nnode
, oi
))
798 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
804 static int ospf_abr_should_accept(struct prefix_ipv4
*p
, struct ospf_area
*area
)
806 if (IMPORT_NAME(area
)) {
807 if (IMPORT_LIST(area
) == NULL
)
809 access_list_lookup(AFI_IP
, IMPORT_NAME(area
));
811 if (IMPORT_LIST(area
))
812 if (access_list_apply(IMPORT_LIST(area
), p
)
820 static int ospf_abr_plist_in_check(struct ospf_area
*area
,
821 struct ospf_route
* or,
822 struct prefix_ipv4
*p
)
824 if (PREFIX_NAME_IN(area
)) {
825 if (PREFIX_LIST_IN(area
) == NULL
)
826 PREFIX_LIST_IN(area
) = prefix_list_lookup(
827 AFI_IP
, PREFIX_NAME_IN(area
));
828 if (PREFIX_LIST_IN(area
))
829 if (prefix_list_apply(PREFIX_LIST_IN(area
), p
)
836 static int ospf_abr_plist_out_check(struct ospf_area
*area
,
837 struct ospf_route
* or,
838 struct prefix_ipv4
*p
)
840 if (PREFIX_NAME_OUT(area
)) {
841 if (PREFIX_LIST_OUT(area
) == NULL
)
842 PREFIX_LIST_OUT(area
) = prefix_list_lookup(
843 AFI_IP
, PREFIX_NAME_OUT(area
));
844 if (PREFIX_LIST_OUT(area
))
845 if (prefix_list_apply(PREFIX_LIST_OUT(area
), p
)
852 static void ospf_abr_announce_network(struct ospf
*ospf
, struct prefix_ipv4
*p
,
853 struct ospf_route
* or)
855 struct ospf_area_range
*range
;
856 struct ospf_area
*area
, *or_area
;
857 struct listnode
*node
;
859 if (IS_DEBUG_OSPF_EVENT
)
860 zlog_debug("ospf_abr_announce_network(): Start");
862 or_area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
865 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
866 if (IS_DEBUG_OSPF_EVENT
)
868 "ospf_abr_announce_network(): looking at area %s",
869 inet_ntoa(area
->area_id
));
871 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
874 if (ospf_abr_nexthops_belong_to_area(or, area
))
877 if (!ospf_abr_should_accept(p
, area
)) {
878 if (IS_DEBUG_OSPF_EVENT
)
880 "ospf_abr_announce_network(): "
881 "prefix %s/%d was denied by import-list",
882 inet_ntoa(p
->prefix
), p
->prefixlen
);
886 if (!ospf_abr_plist_in_check(area
, or, p
)) {
887 if (IS_DEBUG_OSPF_EVENT
)
889 "ospf_abr_announce_network(): "
890 "prefix %s/%d was denied by prefix-list",
891 inet_ntoa(p
->prefix
), p
->prefixlen
);
895 if (area
->external_routing
!= OSPF_AREA_DEFAULT
896 && area
->no_summary
) {
897 if (IS_DEBUG_OSPF_EVENT
)
899 "ospf_abr_announce_network(): "
900 "area %s is stub and no_summary",
901 inet_ntoa(area
->area_id
));
905 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
906 if (IS_DEBUG_OSPF_EVENT
)
908 "ospf_abr_announce_network(): this is "
909 "inter-area route to %s/%d",
910 inet_ntoa(p
->prefix
), p
->prefixlen
);
912 if (!OSPF_IS_AREA_BACKBONE(area
))
913 ospf_abr_announce_network_to_area(p
, or->cost
,
917 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
918 if (IS_DEBUG_OSPF_EVENT
)
920 "ospf_abr_announce_network(): "
921 "this is intra-area route to %s/%d",
922 inet_ntoa(p
->prefix
), p
->prefixlen
);
923 if ((range
= ospf_area_range_match(or_area
, p
))
924 && !ospf_area_is_transit(area
))
925 ospf_abr_update_aggregate(range
, or, area
);
927 ospf_abr_announce_network_to_area(p
, or->cost
,
933 static int ospf_abr_should_announce(struct ospf
*ospf
, struct prefix_ipv4
*p
,
934 struct ospf_route
* or)
936 struct ospf_area
*area
;
938 area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
942 if (EXPORT_NAME(area
)) {
943 if (EXPORT_LIST(area
) == NULL
)
945 access_list_lookup(AFI_IP
, EXPORT_NAME(area
));
947 if (EXPORT_LIST(area
))
948 if (access_list_apply(EXPORT_LIST(area
), p
)
956 static void ospf_abr_process_nssa_translates(struct ospf
*ospf
)
958 /* Scan through all NSSA_LSDB records for all areas;
960 If P-bit is on, translate all Type-7's to 5's and aggregate or
961 flood install as approved in Type-5 LSDB with XLATE Flag on
962 later, do same for all aggregates... At end, DISCARD all
963 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
964 struct listnode
*node
;
965 struct ospf_area
*area
;
966 struct route_node
*rn
;
967 struct ospf_lsa
*lsa
;
969 if (IS_DEBUG_OSPF_NSSA
)
970 zlog_debug("ospf_abr_process_nssa_translates(): Start");
972 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
973 if (!area
->NSSATranslatorState
)
974 continue; /* skip if not translator */
976 if (area
->external_routing
!= OSPF_AREA_NSSA
)
977 continue; /* skip if not Nssa Area */
979 if (IS_DEBUG_OSPF_NSSA
)
981 "ospf_abr_process_nssa_translates(): "
982 "looking at area %s",
983 inet_ntoa(area
->area_id
));
985 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
986 ospf_abr_translate_nssa(area
, lsa
);
989 if (IS_DEBUG_OSPF_NSSA
)
990 zlog_debug("ospf_abr_process_nssa_translates(): Stop");
993 static void ospf_abr_process_network_rt(struct ospf
*ospf
,
994 struct route_table
*rt
)
996 struct ospf_area
*area
;
997 struct ospf_route
* or ;
998 struct route_node
*rn
;
1000 if (IS_DEBUG_OSPF_EVENT
)
1001 zlog_debug("ospf_abr_process_network_rt(): Start");
1003 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1004 if ((or = rn
->info
) == NULL
)
1007 if (!(area
= ospf_area_lookup_by_area_id(ospf
,
1008 or->u
.std
.area_id
))) {
1009 if (IS_DEBUG_OSPF_EVENT
)
1011 "ospf_abr_process_network_rt(): area %s no longer exists",
1012 inet_ntoa(or->u
.std
.area_id
));
1016 if (IS_DEBUG_OSPF_EVENT
)
1018 "ospf_abr_process_network_rt(): this is a route to %s/%d",
1019 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
1020 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
) {
1021 if (IS_DEBUG_OSPF_EVENT
)
1023 "ospf_abr_process_network_rt(): "
1024 "this is an External router, skipping");
1028 if (or->cost
>= OSPF_LS_INFINITY
) {
1029 if (IS_DEBUG_OSPF_EVENT
)
1031 "ospf_abr_process_network_rt():"
1032 " this route's cost is infinity, skipping");
1036 if (or->type
== OSPF_DESTINATION_DISCARD
) {
1037 if (IS_DEBUG_OSPF_EVENT
)
1039 "ospf_abr_process_network_rt():"
1040 " this is a discard entry, skipping");
1045 or->path_type
== OSPF_PATH_INTRA_AREA
1046 && !ospf_abr_should_announce(
1047 ospf
, (struct prefix_ipv4
*)&rn
->p
,
1049 if (IS_DEBUG_OSPF_EVENT
)
1051 "ospf_abr_process_network_rt(): denied by export-list");
1056 or->path_type
== OSPF_PATH_INTRA_AREA
1057 && !ospf_abr_plist_out_check(
1059 (struct prefix_ipv4
*)&rn
->p
)) {
1060 if (IS_DEBUG_OSPF_EVENT
)
1062 "ospf_abr_process_network_rt(): denied by prefix-list");
1066 if ((or->path_type
== OSPF_PATH_INTER_AREA
)
1067 && !OSPF_IS_AREA_ID_BACKBONE(or->u
.std
.area_id
)) {
1068 if (IS_DEBUG_OSPF_EVENT
)
1070 "ospf_abr_process_network_rt():"
1071 " this is route is not backbone one, skipping");
1076 if ((ospf
->abr_type
== OSPF_ABR_CISCO
)
1077 || (ospf
->abr_type
== OSPF_ABR_IBM
))
1079 if (!ospf_act_bb_connection(ospf
) &&
1080 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1081 if (IS_DEBUG_OSPF_EVENT
)
1083 "ospf_abr_process_network_rt(): ALT ABR: "
1084 "No BB connection, skip not intra-area routes");
1088 if (IS_DEBUG_OSPF_EVENT
)
1089 zlog_debug("ospf_abr_process_network_rt(): announcing");
1090 ospf_abr_announce_network(ospf
, (struct prefix_ipv4
*)&rn
->p
,
1094 if (IS_DEBUG_OSPF_EVENT
)
1095 zlog_debug("ospf_abr_process_network_rt(): Stop");
1098 static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
1099 struct ospf_area
*area
)
1101 struct ospf_lsa
*lsa
, *old
= NULL
;
1102 struct summary_lsa
*slsa
= NULL
;
1104 if (IS_DEBUG_OSPF_EVENT
)
1105 zlog_debug("ospf_abr_announce_rtr_to_area(): Start");
1107 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
,
1108 area
->ospf
->router_id
);
1110 if (IS_DEBUG_OSPF_EVENT
)
1112 "ospf_abr_announce_rtr_to_area(): old summary found");
1113 slsa
= (struct summary_lsa
*)old
->data
;
1115 if (IS_DEBUG_OSPF_EVENT
)
1117 "ospf_abr_announce_network_to_area(): "
1118 "old metric: %d, new metric: %d",
1119 GET_METRIC(slsa
->metric
), cost
);
1122 if (old
&& (GET_METRIC(slsa
->metric
) == cost
)
1123 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
1124 if (IS_DEBUG_OSPF_EVENT
)
1126 "ospf_abr_announce_rtr_to_area(): old summary approved");
1127 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
1129 if (IS_DEBUG_OSPF_EVENT
)
1130 zlog_debug("ospf_abr_announce_rtr_to_area(): 2.2");
1133 set_metric(old
, cost
);
1134 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
1136 lsa
= ospf_summary_asbr_lsa_originate(p
, cost
, area
);
1138 char buf
[PREFIX2STR_BUFFER
];
1140 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
1141 flog_warn(EC_OSPF_LSA_MISSING
,
1142 "%s: Could not refresh/originate %s to %s",
1143 __func__
, buf
, inet_ntoa(area
->area_id
));
1147 if (IS_DEBUG_OSPF_EVENT
)
1149 "ospf_abr_announce_rtr_to_area(): "
1150 "flooding new version of summary");
1153 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new
1155 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1157 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1158 /* ospf_flood_through_area (area, NULL, lsa);*/
1161 if (IS_DEBUG_OSPF_EVENT
)
1162 zlog_debug("ospf_abr_announce_rtr_to_area(): Stop");
1166 static void ospf_abr_announce_rtr(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1167 struct ospf_route
* or)
1169 struct listnode
*node
;
1170 struct ospf_area
*area
;
1172 if (IS_DEBUG_OSPF_EVENT
)
1173 zlog_debug("ospf_abr_announce_rtr(): Start");
1175 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1176 if (IS_DEBUG_OSPF_EVENT
)
1178 "ospf_abr_announce_rtr(): looking at area %s",
1179 inet_ntoa(area
->area_id
));
1181 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
1184 if (ospf_abr_nexthops_belong_to_area(or, area
))
1187 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
1188 if (IS_DEBUG_OSPF_EVENT
)
1190 "ospf_abr_announce_rtr(): "
1191 "area %s doesn't support external routing",
1192 inet_ntoa(area
->area_id
));
1196 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
1197 if (IS_DEBUG_OSPF_EVENT
)
1199 "ospf_abr_announce_rtr(): "
1200 "this is inter-area route to %s",
1201 inet_ntoa(p
->prefix
));
1202 if (!OSPF_IS_AREA_BACKBONE(area
))
1203 ospf_abr_announce_rtr_to_area(p
, or->cost
,
1207 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
1208 if (IS_DEBUG_OSPF_EVENT
)
1210 "ospf_abr_announce_rtr(): "
1211 "this is intra-area route to %s",
1212 inet_ntoa(p
->prefix
));
1213 ospf_abr_announce_rtr_to_area(p
, or->cost
, area
);
1217 if (IS_DEBUG_OSPF_EVENT
)
1218 zlog_debug("ospf_abr_announce_rtr(): Stop");
1221 static void ospf_abr_process_router_rt(struct ospf
*ospf
,
1222 struct route_table
*rt
)
1224 struct ospf_route
* or ;
1225 struct route_node
*rn
;
1228 if (IS_DEBUG_OSPF_EVENT
)
1229 zlog_debug("ospf_abr_process_router_rt(): Start");
1231 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1232 struct listnode
*node
, *nnode
;
1234 struct ospf_route
*best
= NULL
;
1236 if (rn
->info
== NULL
)
1241 if (IS_DEBUG_OSPF_EVENT
)
1243 "ospf_abr_process_router_rt(): this is a route to %s",
1244 inet_ntoa(rn
->p
.u
.prefix4
));
1246 for (ALL_LIST_ELEMENTS(l
, node
, nnode
, or)) {
1247 if (!ospf_area_lookup_by_area_id(ospf
,
1248 or->u
.std
.area_id
)) {
1249 if (IS_DEBUG_OSPF_EVENT
)
1251 "ospf_abr_process_router_rt(): area %s no longer exists",
1252 inet_ntoa(or->u
.std
.area_id
));
1257 if (!CHECK_FLAG(or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
)) {
1258 if (IS_DEBUG_OSPF_EVENT
)
1260 "ospf_abr_process_router_rt(): "
1261 "This is not an ASBR, skipping");
1266 best
= ospf_find_asbr_route(
1267 ospf
, rt
, (struct prefix_ipv4
*)&rn
->p
);
1275 if (IS_DEBUG_OSPF_EVENT
)
1277 "ospf_abr_process_router_rt(): "
1278 "This route is not the best among possible, skipping");
1283 or->path_type
== OSPF_PATH_INTER_AREA
1284 && !OSPF_IS_AREA_ID_BACKBONE(
1285 or->u
.std
.area_id
)) {
1286 if (IS_DEBUG_OSPF_EVENT
)
1288 "ospf_abr_process_router_rt(): "
1289 "This route is not a backbone one, skipping");
1293 if (or->cost
>= OSPF_LS_INFINITY
) {
1294 if (IS_DEBUG_OSPF_EVENT
)
1296 "ospf_abr_process_router_rt(): "
1297 "This route has LS_INFINITY metric, skipping");
1301 if (ospf
->abr_type
== OSPF_ABR_CISCO
1302 || ospf
->abr_type
== OSPF_ABR_IBM
)
1303 if (!ospf_act_bb_connection(ospf
) &&
1304 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1305 if (IS_DEBUG_OSPF_EVENT
)
1307 "ospf_abr_process_network_rt(): ALT ABR: "
1308 "No BB connection, skip not intra-area routes");
1312 ospf_abr_announce_rtr(ospf
,
1313 (struct prefix_ipv4
*)&rn
->p
, or);
1317 if (IS_DEBUG_OSPF_EVENT
)
1318 zlog_debug("ospf_abr_process_router_rt(): Stop");
1322 ospf_abr_unapprove_translates(struct ospf
*ospf
) /* For NSSA Translations */
1324 struct ospf_lsa
*lsa
;
1325 struct route_node
*rn
;
1327 if (IS_DEBUG_OSPF_NSSA
)
1328 zlog_debug("ospf_abr_unapprove_translates(): Start");
1330 /* NSSA Translator is not checked, because it may have gone away,
1331 and we would want to flush any residuals anyway */
1333 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1334 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) {
1335 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1336 if (IS_DEBUG_OSPF_NSSA
)
1338 "ospf_abr_unapprove_translates(): "
1339 "approved unset on link id %s",
1340 inet_ntoa(lsa
->data
->id
));
1343 if (IS_DEBUG_OSPF_NSSA
)
1344 zlog_debug("ospf_abr_unapprove_translates(): Stop");
1347 static void ospf_abr_unapprove_summaries(struct ospf
*ospf
)
1349 struct listnode
*node
;
1350 struct ospf_area
*area
;
1351 struct route_node
*rn
;
1352 struct ospf_lsa
*lsa
;
1354 if (IS_DEBUG_OSPF_EVENT
)
1355 zlog_debug("ospf_abr_unapprove_summaries(): Start");
1357 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1358 if (IS_DEBUG_OSPF_EVENT
)
1360 "ospf_abr_unapprove_summaries(): "
1361 "considering area %s",
1362 inet_ntoa(area
->area_id
));
1363 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1364 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1365 if (IS_DEBUG_OSPF_EVENT
)
1367 "ospf_abr_unapprove_summaries(): "
1368 "approved unset on summary link id %s",
1369 inet_ntoa(lsa
->data
->id
));
1370 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1373 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1374 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1375 if (IS_DEBUG_OSPF_EVENT
)
1377 "ospf_abr_unapprove_summaries(): "
1378 "approved unset on asbr-summary link id %s",
1379 inet_ntoa(lsa
->data
->id
));
1380 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1384 if (IS_DEBUG_OSPF_EVENT
)
1385 zlog_debug("ospf_abr_unapprove_summaries(): Stop");
1388 static void ospf_abr_prepare_aggregates(struct ospf
*ospf
)
1390 struct listnode
*node
;
1391 struct route_node
*rn
;
1392 struct ospf_area_range
*range
;
1393 struct ospf_area
*area
;
1395 if (IS_DEBUG_OSPF_EVENT
)
1396 zlog_debug("ospf_abr_prepare_aggregates(): Start");
1398 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1399 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1400 if ((range
= rn
->info
) != NULL
) {
1402 range
->specifics
= 0;
1406 if (IS_DEBUG_OSPF_EVENT
)
1407 zlog_debug("ospf_abr_prepare_aggregates(): Stop");
1410 static void ospf_abr_announce_aggregates(struct ospf
*ospf
)
1412 struct ospf_area
*area
, *ar
;
1413 struct ospf_area_range
*range
;
1414 struct route_node
*rn
;
1416 struct listnode
*node
, *n
;
1418 if (IS_DEBUG_OSPF_EVENT
)
1419 zlog_debug("ospf_abr_announce_aggregates(): Start");
1421 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1422 if (IS_DEBUG_OSPF_EVENT
)
1424 "ospf_abr_announce_aggregates(): looking at area %s",
1425 inet_ntoa(area
->area_id
));
1427 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1428 if ((range
= rn
->info
)) {
1429 if (!CHECK_FLAG(range
->flags
,
1430 OSPF_AREA_RANGE_ADVERTISE
)) {
1431 if (IS_DEBUG_OSPF_EVENT
)
1433 "ospf_abr_announce_aggregates():"
1434 " discarding suppress-ranges");
1439 p
.u
.prefix4
= range
->addr
;
1440 p
.prefixlen
= range
->masklen
;
1442 if (IS_DEBUG_OSPF_EVENT
)
1444 "ospf_abr_announce_aggregates():"
1445 " this is range: %s/%d",
1446 inet_ntoa(p
.u
.prefix4
),
1449 if (CHECK_FLAG(range
->flags
,
1450 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1452 p
.u
.prefix4
= range
->subst_addr
;
1453 p
.prefixlen
= range
->subst_masklen
;
1456 if (range
->specifics
) {
1457 if (IS_DEBUG_OSPF_EVENT
)
1459 "ospf_abr_announce_aggregates(): active range");
1461 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
,
1466 /* We do not check nexthops
1468 intra-area routes can be
1472 /* backbone routes are not
1474 when announced into transit
1477 if (ospf_area_is_transit(ar
)
1478 && OSPF_IS_AREA_BACKBONE(
1480 if (IS_DEBUG_OSPF_EVENT
)
1482 "ospf_abr_announce_aggregates(): Skipping "
1483 "announcement of BB aggregate into"
1487 ospf_abr_announce_network_to_area(
1496 if (IS_DEBUG_OSPF_EVENT
)
1497 zlog_debug("ospf_abr_announce_aggregates(): Stop");
1501 ospf_abr_send_nssa_aggregates(struct ospf
*ospf
) /* temporarily turned off */
1503 struct listnode
*node
; /*, n; */
1504 struct ospf_area
*area
; /*, *ar; */
1505 struct route_node
*rn
;
1506 struct ospf_area_range
*range
;
1507 struct prefix_ipv4 p
;
1509 if (IS_DEBUG_OSPF_NSSA
)
1510 zlog_debug("ospf_abr_send_nssa_aggregates(): Start");
1512 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1513 if (!area
->NSSATranslatorState
)
1516 if (IS_DEBUG_OSPF_NSSA
)
1518 "ospf_abr_send_nssa_aggregates(): looking at area %s",
1519 inet_ntoa(area
->area_id
));
1521 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
)) {
1522 if (rn
->info
== NULL
)
1527 if (!CHECK_FLAG(range
->flags
,
1528 OSPF_AREA_RANGE_ADVERTISE
)) {
1529 if (IS_DEBUG_OSPF_NSSA
)
1531 "ospf_abr_send_nssa_aggregates():"
1532 " discarding suppress-ranges");
1537 p
.prefix
= range
->addr
;
1538 p
.prefixlen
= range
->masklen
;
1540 if (IS_DEBUG_OSPF_NSSA
)
1542 "ospf_abr_send_nssa_aggregates():"
1543 " this is range: %s/%d",
1544 inet_ntoa(p
.prefix
), p
.prefixlen
);
1546 if (CHECK_FLAG(range
->flags
,
1547 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1549 p
.prefix
= range
->subst_addr
;
1550 p
.prefixlen
= range
->subst_masklen
;
1553 if (range
->specifics
) {
1554 if (IS_DEBUG_OSPF_NSSA
)
1556 "ospf_abr_send_nssa_aggregates(): active range");
1558 /* Fetch LSA-Type-7 from aggregate prefix, and
1560 * translate, Install (as Type-5), Approve, and
1563 ospf_abr_translate_nssa_range(&p
, range
->cost
);
1565 } /* all area ranges*/
1568 if (IS_DEBUG_OSPF_NSSA
)
1569 zlog_debug("ospf_abr_send_nssa_aggregates(): Stop");
1572 static void ospf_abr_announce_stub_defaults(struct ospf
*ospf
)
1574 struct listnode
*node
;
1575 struct ospf_area
*area
;
1576 struct prefix_ipv4 p
;
1578 if (!IS_OSPF_ABR(ospf
))
1581 if (IS_DEBUG_OSPF_EVENT
)
1582 zlog_debug("ospf_abr_announce_stub_defaults(): Start");
1585 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1588 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1589 if (IS_DEBUG_OSPF_EVENT
)
1591 "ospf_abr_announce_stub_defaults(): looking at area %s",
1592 inet_ntoa(area
->area_id
));
1594 if ((area
->external_routing
!= OSPF_AREA_STUB
)
1595 && (area
->external_routing
!= OSPF_AREA_NSSA
))
1598 if (OSPF_IS_AREA_BACKBONE(area
))
1599 continue; /* Sanity Check */
1601 if (IS_DEBUG_OSPF_EVENT
)
1603 "ospf_abr_announce_stub_defaults(): "
1604 "announcing 0.0.0.0/0 to area %s",
1605 inet_ntoa(area
->area_id
));
1606 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1609 if (IS_DEBUG_OSPF_EVENT
)
1610 zlog_debug("ospf_abr_announce_stub_defaults(): Stop");
1613 static int ospf_abr_remove_unapproved_translates_apply(struct ospf
*ospf
,
1614 struct ospf_lsa
*lsa
)
1616 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1617 && !CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
)) {
1619 "ospf_abr_remove_unapproved_translates(): "
1620 "removing unapproved translates, ID: %s",
1621 inet_ntoa(lsa
->data
->id
));
1623 /* FLUSH THROUGHOUT AS */
1624 ospf_lsa_flush_as(ospf
, lsa
);
1626 /* DISCARD from LSDB */
1631 static void ospf_abr_remove_unapproved_translates(struct ospf
*ospf
)
1633 struct route_node
*rn
;
1634 struct ospf_lsa
*lsa
;
1636 /* All AREA PROCESS should have APPROVED necessary LSAs */
1637 /* Remove any left over and not APPROVED */
1638 if (IS_DEBUG_OSPF_NSSA
)
1639 zlog_debug("ospf_abr_remove_unapproved_translates(): Start");
1641 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1642 ospf_abr_remove_unapproved_translates_apply(ospf
, lsa
);
1644 if (IS_DEBUG_OSPF_NSSA
)
1645 zlog_debug("ospf_abr_remove_unapproved_translates(): Stop");
1648 static void ospf_abr_remove_unapproved_summaries(struct ospf
*ospf
)
1650 struct listnode
*node
;
1651 struct ospf_area
*area
;
1652 struct route_node
*rn
;
1653 struct ospf_lsa
*lsa
;
1655 if (IS_DEBUG_OSPF_EVENT
)
1656 zlog_debug("ospf_abr_remove_unapproved_summaries(): Start");
1658 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1659 if (IS_DEBUG_OSPF_EVENT
)
1661 "ospf_abr_remove_unapproved_summaries(): "
1662 "looking at area %s",
1663 inet_ntoa(area
->area_id
));
1665 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1666 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1667 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1668 ospf_lsa_flush_area(lsa
, area
);
1670 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1671 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1672 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1673 ospf_lsa_flush_area(lsa
, area
);
1676 if (IS_DEBUG_OSPF_EVENT
)
1677 zlog_debug("ospf_abr_remove_unapproved_summaries(): Stop");
1680 static void ospf_abr_manage_discard_routes(struct ospf
*ospf
)
1682 struct listnode
*node
, *nnode
;
1683 struct route_node
*rn
;
1684 struct ospf_area
*area
;
1685 struct ospf_area_range
*range
;
1687 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
1688 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1689 if ((range
= rn
->info
) != NULL
)
1690 if (CHECK_FLAG(range
->flags
,
1691 OSPF_AREA_RANGE_ADVERTISE
)) {
1692 if (range
->specifics
)
1693 ospf_add_discard_route(
1694 ospf
, ospf
->new_table
,
1699 ospf_delete_discard_route(
1700 ospf
, ospf
->new_table
,
1706 /* This is the function taking care about ABR NSSA, i.e. NSSA
1707 Translator, -LSA aggregation and flooding. For all NSSAs
1709 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1710 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1713 Any received Type-5s are legal for an ABR, else illegal for IR.
1714 Received Type-7s are installed, by area, with incoming P-bit. They
1715 are flooded; if the Elected NSSA Translator, then P-bit off.
1717 Additionally, this ABR will place "translated type-7's" into the
1718 Type-5 LSDB in order to keep track of APPROVAL or not.
1720 It will scan through every area, looking for Type-7 LSAs with P-Bit
1721 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1722 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1725 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1726 left over are FLUSHED and DISCARDED.
1728 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1729 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1731 static void ospf_abr_nssa_task(struct ospf
*ospf
) /* called only if any_nssa */
1733 if (IS_DEBUG_OSPF_NSSA
)
1734 zlog_debug("Check for NSSA-ABR Tasks():");
1736 if (!IS_OSPF_ABR(ospf
))
1742 /* Each area must confirm TranslatorRole */
1743 if (IS_DEBUG_OSPF_NSSA
)
1744 zlog_debug("ospf_abr_nssa_task(): Start");
1746 /* For all Global Entries flagged "local-translate", unset APPROVED */
1747 if (IS_DEBUG_OSPF_NSSA
)
1748 zlog_debug("ospf_abr_nssa_task(): unapprove translates");
1750 ospf_abr_unapprove_translates(ospf
);
1752 /* RESET all Ranges in every Area, same as summaries */
1753 if (IS_DEBUG_OSPF_NSSA
)
1754 zlog_debug("ospf_abr_nssa_task(): NSSA initialize aggregates");
1755 ospf_abr_prepare_aggregates(ospf
); /*TURNED OFF just for now */
1757 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1758 * Aggregate as Type-7
1759 * Install or Approve in Type-5 Global LSDB
1761 if (IS_DEBUG_OSPF_NSSA
)
1762 zlog_debug("ospf_abr_nssa_task(): process translates");
1763 ospf_abr_process_nssa_translates(ospf
);
1765 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1767 * Scan Type-7's for aggregates, translate to Type-5's,
1768 * Install/Flood/Approve
1770 if (IS_DEBUG_OSPF_NSSA
)
1771 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1772 ospf_abr_send_nssa_aggregates(ospf
); /*TURNED OFF FOR NOW */
1774 /* Send any NSSA defaults as Type-5
1775 *if (IS_DEBUG_OSPF_NSSA)
1776 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1777 *ospf_abr_announce_nssa_defaults (ospf);
1778 * havnt a clue what above is supposed to do.
1781 /* Flush any unapproved previous translates from Global Data Base */
1782 if (IS_DEBUG_OSPF_NSSA
)
1784 "ospf_abr_nssa_task(): remove unapproved translates");
1785 ospf_abr_remove_unapproved_translates(ospf
);
1787 ospf_abr_manage_discard_routes(ospf
); /* same as normal...discard */
1789 if (IS_DEBUG_OSPF_NSSA
)
1790 zlog_debug("ospf_abr_nssa_task(): Stop");
1793 /* This is the function taking care about ABR stuff, i.e.
1794 summary-LSA origination and flooding. */
1795 void ospf_abr_task(struct ospf
*ospf
)
1797 if (IS_DEBUG_OSPF_EVENT
)
1798 zlog_debug("ospf_abr_task(): Start");
1800 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
) {
1801 if (IS_DEBUG_OSPF_EVENT
)
1803 "ospf_abr_task(): Routing tables are not yet ready");
1807 if (IS_DEBUG_OSPF_EVENT
)
1808 zlog_debug("ospf_abr_task(): unapprove summaries");
1809 ospf_abr_unapprove_summaries(ospf
);
1811 if (IS_DEBUG_OSPF_EVENT
)
1812 zlog_debug("ospf_abr_task(): prepare aggregates");
1813 ospf_abr_prepare_aggregates(ospf
);
1815 if (IS_OSPF_ABR(ospf
)) {
1816 if (IS_DEBUG_OSPF_EVENT
)
1817 zlog_debug("ospf_abr_task(): process network RT");
1818 ospf_abr_process_network_rt(ospf
, ospf
->new_table
);
1820 if (IS_DEBUG_OSPF_EVENT
)
1821 zlog_debug("ospf_abr_task(): process router RT");
1822 ospf_abr_process_router_rt(ospf
, ospf
->new_rtrs
);
1824 if (IS_DEBUG_OSPF_EVENT
)
1825 zlog_debug("ospf_abr_task(): announce aggregates");
1826 ospf_abr_announce_aggregates(ospf
);
1828 if (IS_DEBUG_OSPF_EVENT
)
1829 zlog_debug("ospf_abr_task(): announce stub defaults");
1830 ospf_abr_announce_stub_defaults(ospf
);
1833 if (IS_DEBUG_OSPF_EVENT
)
1834 zlog_debug("ospf_abr_task(): remove unapproved summaries");
1835 ospf_abr_remove_unapproved_summaries(ospf
);
1837 ospf_abr_manage_discard_routes(ospf
);
1839 if (IS_DEBUG_OSPF_EVENT
)
1840 zlog_debug("ospf_abr_task(): Stop");
1843 static int ospf_abr_task_timer(struct thread
*thread
)
1845 struct ospf
*ospf
= THREAD_ARG(thread
);
1847 ospf
->t_abr_task
= 0;
1849 if (IS_DEBUG_OSPF_EVENT
)
1850 zlog_debug("Running ABR task on timer");
1852 ospf_check_abr_status(ospf
);
1853 ospf_abr_nssa_check_status(ospf
);
1855 ospf_abr_task(ospf
);
1856 ospf_abr_nssa_task(ospf
); /* if nssa-abr, then scan Type-7 LSDB */
1861 void ospf_schedule_abr_task(struct ospf
*ospf
)
1863 if (IS_DEBUG_OSPF_EVENT
)
1864 zlog_debug("Scheduling ABR task");
1866 thread_add_timer(master
, ospf_abr_task_timer
, ospf
, OSPF_ABR_TASK_DELAY
,