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
= 0;
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 ((new = ospf_translated_nssa_originate(area
->ospf
, lsa
))
675 if (IS_DEBUG_OSPF_NSSA
)
677 "ospf_abr_translate_nssa(): Could not translate "
678 "Type-7 for %s to Type-5",
679 inet_ntoa(lsa
->data
->id
));
684 /* Area where Aggregate testing will be inserted, just like summary
686 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
691 static void ospf_abr_translate_nssa_range(struct prefix_ipv4
*p
, uint32_t cost
)
693 /* The Type-7 is created from the aggregated prefix and forwarded
694 for lsa installation and flooding... to be added... */
697 void ospf_abr_announce_network_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
698 struct ospf_area
*area
)
700 struct ospf_lsa
*lsa
, *old
= NULL
;
701 struct summary_lsa
*sl
= NULL
;
704 if (IS_DEBUG_OSPF_EVENT
)
705 zlog_debug("ospf_abr_announce_network_to_area(): Start");
707 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
708 full_cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
712 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_SUMMARY_LSA
,
713 (struct prefix_ipv4
*)p
,
714 area
->ospf
->router_id
);
716 if (IS_DEBUG_OSPF_EVENT
)
718 "ospf_abr_announce_network_to_area(): old summary found");
720 sl
= (struct summary_lsa
*)old
->data
;
722 if (IS_DEBUG_OSPF_EVENT
)
724 "ospf_abr_announce_network_to_area(): "
725 "old metric: %d, new metric: %d",
726 GET_METRIC(sl
->metric
), cost
);
728 if ((GET_METRIC(sl
->metric
) == full_cost
)
729 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
730 /* unchanged. simply reapprove it */
731 if (IS_DEBUG_OSPF_EVENT
)
733 "ospf_abr_announce_network_to_area(): "
734 "old summary approved");
735 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
737 /* LSA is changed, refresh it */
738 if (IS_DEBUG_OSPF_EVENT
)
740 "ospf_abr_announce_network_to_area(): "
741 "refreshing summary");
742 set_metric(old
, full_cost
);
743 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
746 char buf
[PREFIX2STR_BUFFER
];
748 prefix2str((struct prefix
*)p
, buf
,
750 flog_warn(EC_OSPF_LSA_MISSING
,
751 "%s: Could not refresh %s to %s",
753 inet_ntoa(area
->area_id
));
757 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
758 /* This will flood through area. */
761 if (IS_DEBUG_OSPF_EVENT
)
763 "ospf_abr_announce_network_to_area(): "
764 "creating new summary");
765 lsa
= ospf_summary_lsa_originate((struct prefix_ipv4
*)p
,
767 /* This will flood through area. */
770 char buf
[PREFIX2STR_BUFFER
];
772 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
773 flog_warn(EC_OSPF_LSA_MISSING
,
774 "%s: Could not originate %s to %s", __func__
,
775 buf
, inet_ntoa(area
->area_id
));
779 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
780 if (IS_DEBUG_OSPF_EVENT
)
782 "ospf_abr_announce_network_to_area(): "
783 "flooding new version of summary");
786 if (IS_DEBUG_OSPF_EVENT
)
787 zlog_debug("ospf_abr_announce_network_to_area(): Stop");
790 static int ospf_abr_nexthops_belong_to_area(struct ospf_route
* or,
791 struct ospf_area
*area
)
793 struct listnode
*node
, *nnode
;
794 struct ospf_path
*path
;
795 struct ospf_interface
*oi
;
797 for (ALL_LIST_ELEMENTS_RO(or->paths
, node
, path
))
798 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, nnode
, oi
))
799 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
805 static int ospf_abr_should_accept(struct prefix_ipv4
*p
, struct ospf_area
*area
)
807 if (IMPORT_NAME(area
)) {
808 if (IMPORT_LIST(area
) == NULL
)
810 access_list_lookup(AFI_IP
, IMPORT_NAME(area
));
812 if (IMPORT_LIST(area
))
813 if (access_list_apply(IMPORT_LIST(area
), p
)
821 static int ospf_abr_plist_in_check(struct ospf_area
*area
,
822 struct ospf_route
* or,
823 struct prefix_ipv4
*p
)
825 if (PREFIX_NAME_IN(area
)) {
826 if (PREFIX_LIST_IN(area
) == NULL
)
827 PREFIX_LIST_IN(area
) = prefix_list_lookup(
828 AFI_IP
, PREFIX_NAME_IN(area
));
829 if (PREFIX_LIST_IN(area
))
830 if (prefix_list_apply(PREFIX_LIST_IN(area
), p
)
837 static int ospf_abr_plist_out_check(struct ospf_area
*area
,
838 struct ospf_route
* or,
839 struct prefix_ipv4
*p
)
841 if (PREFIX_NAME_OUT(area
)) {
842 if (PREFIX_LIST_OUT(area
) == NULL
)
843 PREFIX_LIST_OUT(area
) = prefix_list_lookup(
844 AFI_IP
, PREFIX_NAME_OUT(area
));
845 if (PREFIX_LIST_OUT(area
))
846 if (prefix_list_apply(PREFIX_LIST_OUT(area
), p
)
853 static void ospf_abr_announce_network(struct ospf
*ospf
, struct prefix_ipv4
*p
,
854 struct ospf_route
* or)
856 struct ospf_area_range
*range
;
857 struct ospf_area
*area
, *or_area
;
858 struct listnode
*node
;
860 if (IS_DEBUG_OSPF_EVENT
)
861 zlog_debug("ospf_abr_announce_network(): Start");
863 or_area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
866 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
867 if (IS_DEBUG_OSPF_EVENT
)
869 "ospf_abr_announce_network(): looking at area %s",
870 inet_ntoa(area
->area_id
));
872 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
875 if (ospf_abr_nexthops_belong_to_area(or, area
))
878 if (!ospf_abr_should_accept(p
, area
)) {
879 if (IS_DEBUG_OSPF_EVENT
)
881 "ospf_abr_announce_network(): "
882 "prefix %s/%d was denied by import-list",
883 inet_ntoa(p
->prefix
), p
->prefixlen
);
887 if (!ospf_abr_plist_in_check(area
, or, p
)) {
888 if (IS_DEBUG_OSPF_EVENT
)
890 "ospf_abr_announce_network(): "
891 "prefix %s/%d was denied by prefix-list",
892 inet_ntoa(p
->prefix
), p
->prefixlen
);
896 if (area
->external_routing
!= OSPF_AREA_DEFAULT
897 && area
->no_summary
) {
898 if (IS_DEBUG_OSPF_EVENT
)
900 "ospf_abr_announce_network(): "
901 "area %s is stub and no_summary",
902 inet_ntoa(area
->area_id
));
906 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
907 if (IS_DEBUG_OSPF_EVENT
)
909 "ospf_abr_announce_network(): this is "
910 "inter-area route to %s/%d",
911 inet_ntoa(p
->prefix
), p
->prefixlen
);
913 if (!OSPF_IS_AREA_BACKBONE(area
))
914 ospf_abr_announce_network_to_area(p
, or->cost
,
918 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
919 if (IS_DEBUG_OSPF_EVENT
)
921 "ospf_abr_announce_network(): "
922 "this is intra-area route to %s/%d",
923 inet_ntoa(p
->prefix
), p
->prefixlen
);
924 if ((range
= ospf_area_range_match(or_area
, p
))
925 && !ospf_area_is_transit(area
))
926 ospf_abr_update_aggregate(range
, or, area
);
928 ospf_abr_announce_network_to_area(p
, or->cost
,
934 static int ospf_abr_should_announce(struct ospf
*ospf
, struct prefix_ipv4
*p
,
935 struct ospf_route
* or)
937 struct ospf_area
*area
;
939 area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
943 if (EXPORT_NAME(area
)) {
944 if (EXPORT_LIST(area
) == NULL
)
946 access_list_lookup(AFI_IP
, EXPORT_NAME(area
));
948 if (EXPORT_LIST(area
))
949 if (access_list_apply(EXPORT_LIST(area
), p
)
957 static void ospf_abr_process_nssa_translates(struct ospf
*ospf
)
959 /* Scan through all NSSA_LSDB records for all areas;
961 If P-bit is on, translate all Type-7's to 5's and aggregate or
962 flood install as approved in Type-5 LSDB with XLATE Flag on
963 later, do same for all aggregates... At end, DISCARD all
964 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
965 struct listnode
*node
;
966 struct ospf_area
*area
;
967 struct route_node
*rn
;
968 struct ospf_lsa
*lsa
;
970 if (IS_DEBUG_OSPF_NSSA
)
971 zlog_debug("ospf_abr_process_nssa_translates(): Start");
973 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
974 if (!area
->NSSATranslatorState
)
975 continue; /* skip if not translator */
977 if (area
->external_routing
!= OSPF_AREA_NSSA
)
978 continue; /* skip if not Nssa Area */
980 if (IS_DEBUG_OSPF_NSSA
)
982 "ospf_abr_process_nssa_translates(): "
983 "looking at area %s",
984 inet_ntoa(area
->area_id
));
986 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
987 ospf_abr_translate_nssa(area
, lsa
);
990 if (IS_DEBUG_OSPF_NSSA
)
991 zlog_debug("ospf_abr_process_nssa_translates(): Stop");
994 static void ospf_abr_process_network_rt(struct ospf
*ospf
,
995 struct route_table
*rt
)
997 struct ospf_area
*area
;
998 struct ospf_route
* or ;
999 struct route_node
*rn
;
1001 if (IS_DEBUG_OSPF_EVENT
)
1002 zlog_debug("ospf_abr_process_network_rt(): Start");
1004 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1005 if ((or = rn
->info
) == NULL
)
1008 if (!(area
= ospf_area_lookup_by_area_id(ospf
,
1009 or->u
.std
.area_id
))) {
1010 if (IS_DEBUG_OSPF_EVENT
)
1012 "ospf_abr_process_network_rt(): area %s no longer exists",
1013 inet_ntoa(or->u
.std
.area_id
));
1017 if (IS_DEBUG_OSPF_EVENT
)
1019 "ospf_abr_process_network_rt(): this is a route to %s/%d",
1020 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
1021 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
) {
1022 if (IS_DEBUG_OSPF_EVENT
)
1024 "ospf_abr_process_network_rt(): "
1025 "this is an External router, skipping");
1029 if (or->cost
>= OSPF_LS_INFINITY
) {
1030 if (IS_DEBUG_OSPF_EVENT
)
1032 "ospf_abr_process_network_rt():"
1033 " this route's cost is infinity, skipping");
1037 if (or->type
== OSPF_DESTINATION_DISCARD
) {
1038 if (IS_DEBUG_OSPF_EVENT
)
1040 "ospf_abr_process_network_rt():"
1041 " this is a discard entry, skipping");
1046 or->path_type
== OSPF_PATH_INTRA_AREA
1047 && !ospf_abr_should_announce(
1048 ospf
, (struct prefix_ipv4
*)&rn
->p
,
1050 if (IS_DEBUG_OSPF_EVENT
)
1052 "ospf_abr_process_network_rt(): denied by export-list");
1057 or->path_type
== OSPF_PATH_INTRA_AREA
1058 && !ospf_abr_plist_out_check(
1060 (struct prefix_ipv4
*)&rn
->p
)) {
1061 if (IS_DEBUG_OSPF_EVENT
)
1063 "ospf_abr_process_network_rt(): denied by prefix-list");
1067 if ((or->path_type
== OSPF_PATH_INTER_AREA
)
1068 && !OSPF_IS_AREA_ID_BACKBONE(or->u
.std
.area_id
)) {
1069 if (IS_DEBUG_OSPF_EVENT
)
1071 "ospf_abr_process_network_rt():"
1072 " this is route is not backbone one, skipping");
1077 if ((ospf
->abr_type
== OSPF_ABR_CISCO
)
1078 || (ospf
->abr_type
== OSPF_ABR_IBM
))
1080 if (!ospf_act_bb_connection(ospf
) &&
1081 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1082 if (IS_DEBUG_OSPF_EVENT
)
1084 "ospf_abr_process_network_rt(): ALT ABR: "
1085 "No BB connection, skip not intra-area routes");
1089 if (IS_DEBUG_OSPF_EVENT
)
1090 zlog_debug("ospf_abr_process_network_rt(): announcing");
1091 ospf_abr_announce_network(ospf
, (struct prefix_ipv4
*)&rn
->p
,
1095 if (IS_DEBUG_OSPF_EVENT
)
1096 zlog_debug("ospf_abr_process_network_rt(): Stop");
1099 static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
1100 struct ospf_area
*area
)
1102 struct ospf_lsa
*lsa
, *old
= NULL
;
1103 struct summary_lsa
*slsa
= NULL
;
1105 if (IS_DEBUG_OSPF_EVENT
)
1106 zlog_debug("ospf_abr_announce_rtr_to_area(): Start");
1108 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
,
1109 area
->ospf
->router_id
);
1111 if (IS_DEBUG_OSPF_EVENT
)
1113 "ospf_abr_announce_rtr_to_area(): old summary found");
1114 slsa
= (struct summary_lsa
*)old
->data
;
1116 if (IS_DEBUG_OSPF_EVENT
)
1118 "ospf_abr_announce_network_to_area(): "
1119 "old metric: %d, new metric: %d",
1120 GET_METRIC(slsa
->metric
), cost
);
1123 if (old
&& (GET_METRIC(slsa
->metric
) == cost
)
1124 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
1125 if (IS_DEBUG_OSPF_EVENT
)
1127 "ospf_abr_announce_rtr_to_area(): old summary approved");
1128 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
1130 if (IS_DEBUG_OSPF_EVENT
)
1131 zlog_debug("ospf_abr_announce_rtr_to_area(): 2.2");
1134 set_metric(old
, cost
);
1135 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
1137 lsa
= ospf_summary_asbr_lsa_originate(p
, cost
, area
);
1139 char buf
[PREFIX2STR_BUFFER
];
1141 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
1142 flog_warn(EC_OSPF_LSA_MISSING
,
1143 "%s: Could not refresh/originate %s to %s",
1144 __func__
, buf
, inet_ntoa(area
->area_id
));
1148 if (IS_DEBUG_OSPF_EVENT
)
1150 "ospf_abr_announce_rtr_to_area(): "
1151 "flooding new version of summary");
1154 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new
1156 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1158 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1159 /* ospf_flood_through_area (area, NULL, lsa);*/
1162 if (IS_DEBUG_OSPF_EVENT
)
1163 zlog_debug("ospf_abr_announce_rtr_to_area(): Stop");
1167 static void ospf_abr_announce_rtr(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1168 struct ospf_route
* or)
1170 struct listnode
*node
;
1171 struct ospf_area
*area
;
1173 if (IS_DEBUG_OSPF_EVENT
)
1174 zlog_debug("ospf_abr_announce_rtr(): Start");
1176 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1177 if (IS_DEBUG_OSPF_EVENT
)
1179 "ospf_abr_announce_rtr(): looking at area %s",
1180 inet_ntoa(area
->area_id
));
1182 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
1185 if (ospf_abr_nexthops_belong_to_area(or, area
))
1188 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
1189 if (IS_DEBUG_OSPF_EVENT
)
1191 "ospf_abr_announce_rtr(): "
1192 "area %s doesn't support external routing",
1193 inet_ntoa(area
->area_id
));
1197 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
1198 if (IS_DEBUG_OSPF_EVENT
)
1200 "ospf_abr_announce_rtr(): "
1201 "this is inter-area route to %s",
1202 inet_ntoa(p
->prefix
));
1203 if (!OSPF_IS_AREA_BACKBONE(area
))
1204 ospf_abr_announce_rtr_to_area(p
, or->cost
,
1208 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
1209 if (IS_DEBUG_OSPF_EVENT
)
1211 "ospf_abr_announce_rtr(): "
1212 "this is intra-area route to %s",
1213 inet_ntoa(p
->prefix
));
1214 ospf_abr_announce_rtr_to_area(p
, or->cost
, area
);
1218 if (IS_DEBUG_OSPF_EVENT
)
1219 zlog_debug("ospf_abr_announce_rtr(): Stop");
1222 static void ospf_abr_process_router_rt(struct ospf
*ospf
,
1223 struct route_table
*rt
)
1225 struct ospf_route
* or ;
1226 struct route_node
*rn
;
1229 if (IS_DEBUG_OSPF_EVENT
)
1230 zlog_debug("ospf_abr_process_router_rt(): Start");
1232 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1233 struct listnode
*node
, *nnode
;
1235 struct ospf_route
*best
= NULL
;
1237 if (rn
->info
== NULL
)
1242 if (IS_DEBUG_OSPF_EVENT
)
1244 "ospf_abr_process_router_rt(): this is a route to %s",
1245 inet_ntoa(rn
->p
.u
.prefix4
));
1247 for (ALL_LIST_ELEMENTS(l
, node
, nnode
, or)) {
1248 if (!ospf_area_lookup_by_area_id(ospf
,
1249 or->u
.std
.area_id
)) {
1250 if (IS_DEBUG_OSPF_EVENT
)
1252 "ospf_abr_process_router_rt(): area %s no longer exists",
1253 inet_ntoa(or->u
.std
.area_id
));
1258 if (!CHECK_FLAG(or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
)) {
1259 if (IS_DEBUG_OSPF_EVENT
)
1261 "ospf_abr_process_router_rt(): "
1262 "This is not an ASBR, skipping");
1267 best
= ospf_find_asbr_route(
1268 ospf
, rt
, (struct prefix_ipv4
*)&rn
->p
);
1276 if (IS_DEBUG_OSPF_EVENT
)
1278 "ospf_abr_process_router_rt(): "
1279 "This route is not the best among possible, skipping");
1284 or->path_type
== OSPF_PATH_INTER_AREA
1285 && !OSPF_IS_AREA_ID_BACKBONE(
1286 or->u
.std
.area_id
)) {
1287 if (IS_DEBUG_OSPF_EVENT
)
1289 "ospf_abr_process_router_rt(): "
1290 "This route is not a backbone one, skipping");
1294 if (or->cost
>= OSPF_LS_INFINITY
) {
1295 if (IS_DEBUG_OSPF_EVENT
)
1297 "ospf_abr_process_router_rt(): "
1298 "This route has LS_INFINITY metric, skipping");
1302 if (ospf
->abr_type
== OSPF_ABR_CISCO
1303 || ospf
->abr_type
== OSPF_ABR_IBM
)
1304 if (!ospf_act_bb_connection(ospf
) &&
1305 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1306 if (IS_DEBUG_OSPF_EVENT
)
1308 "ospf_abr_process_network_rt(): ALT ABR: "
1309 "No BB connection, skip not intra-area routes");
1313 ospf_abr_announce_rtr(ospf
,
1314 (struct prefix_ipv4
*)&rn
->p
, or);
1318 if (IS_DEBUG_OSPF_EVENT
)
1319 zlog_debug("ospf_abr_process_router_rt(): Stop");
1323 ospf_abr_unapprove_translates(struct ospf
*ospf
) /* For NSSA Translations */
1325 struct ospf_lsa
*lsa
;
1326 struct route_node
*rn
;
1328 if (IS_DEBUG_OSPF_NSSA
)
1329 zlog_debug("ospf_abr_unapprove_translates(): Start");
1331 /* NSSA Translator is not checked, because it may have gone away,
1332 and we would want to flush any residuals anyway */
1334 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1335 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) {
1336 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1337 if (IS_DEBUG_OSPF_NSSA
)
1339 "ospf_abr_unapprove_translates(): "
1340 "approved unset on link id %s",
1341 inet_ntoa(lsa
->data
->id
));
1344 if (IS_DEBUG_OSPF_NSSA
)
1345 zlog_debug("ospf_abr_unapprove_translates(): Stop");
1348 static void ospf_abr_unapprove_summaries(struct ospf
*ospf
)
1350 struct listnode
*node
;
1351 struct ospf_area
*area
;
1352 struct route_node
*rn
;
1353 struct ospf_lsa
*lsa
;
1355 if (IS_DEBUG_OSPF_EVENT
)
1356 zlog_debug("ospf_abr_unapprove_summaries(): Start");
1358 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1359 if (IS_DEBUG_OSPF_EVENT
)
1361 "ospf_abr_unapprove_summaries(): "
1362 "considering area %s",
1363 inet_ntoa(area
->area_id
));
1364 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1365 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1366 if (IS_DEBUG_OSPF_EVENT
)
1368 "ospf_abr_unapprove_summaries(): "
1369 "approved unset on summary link id %s",
1370 inet_ntoa(lsa
->data
->id
));
1371 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1374 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1375 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1376 if (IS_DEBUG_OSPF_EVENT
)
1378 "ospf_abr_unapprove_summaries(): "
1379 "approved unset on asbr-summary link id %s",
1380 inet_ntoa(lsa
->data
->id
));
1381 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1385 if (IS_DEBUG_OSPF_EVENT
)
1386 zlog_debug("ospf_abr_unapprove_summaries(): Stop");
1389 static void ospf_abr_prepare_aggregates(struct ospf
*ospf
)
1391 struct listnode
*node
;
1392 struct route_node
*rn
;
1393 struct ospf_area_range
*range
;
1394 struct ospf_area
*area
;
1396 if (IS_DEBUG_OSPF_EVENT
)
1397 zlog_debug("ospf_abr_prepare_aggregates(): Start");
1399 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1400 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1401 if ((range
= rn
->info
) != NULL
) {
1403 range
->specifics
= 0;
1407 if (IS_DEBUG_OSPF_EVENT
)
1408 zlog_debug("ospf_abr_prepare_aggregates(): Stop");
1411 static void ospf_abr_announce_aggregates(struct ospf
*ospf
)
1413 struct ospf_area
*area
, *ar
;
1414 struct ospf_area_range
*range
;
1415 struct route_node
*rn
;
1417 struct listnode
*node
, *n
;
1419 if (IS_DEBUG_OSPF_EVENT
)
1420 zlog_debug("ospf_abr_announce_aggregates(): Start");
1422 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1423 if (IS_DEBUG_OSPF_EVENT
)
1425 "ospf_abr_announce_aggregates(): looking at area %s",
1426 inet_ntoa(area
->area_id
));
1428 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1429 if ((range
= rn
->info
)) {
1430 if (!CHECK_FLAG(range
->flags
,
1431 OSPF_AREA_RANGE_ADVERTISE
)) {
1432 if (IS_DEBUG_OSPF_EVENT
)
1434 "ospf_abr_announce_aggregates():"
1435 " discarding suppress-ranges");
1440 p
.u
.prefix4
= range
->addr
;
1441 p
.prefixlen
= range
->masklen
;
1443 if (IS_DEBUG_OSPF_EVENT
)
1445 "ospf_abr_announce_aggregates():"
1446 " this is range: %s/%d",
1447 inet_ntoa(p
.u
.prefix4
),
1450 if (CHECK_FLAG(range
->flags
,
1451 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1453 p
.u
.prefix4
= range
->subst_addr
;
1454 p
.prefixlen
= range
->subst_masklen
;
1457 if (range
->specifics
) {
1458 if (IS_DEBUG_OSPF_EVENT
)
1460 "ospf_abr_announce_aggregates(): active range");
1462 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
,
1467 /* We do not check nexthops
1469 intra-area routes can be
1473 /* backbone routes are not
1475 when announced into transit
1478 if (ospf_area_is_transit(ar
)
1479 && OSPF_IS_AREA_BACKBONE(
1481 if (IS_DEBUG_OSPF_EVENT
)
1483 "ospf_abr_announce_aggregates(): Skipping "
1484 "announcement of BB aggregate into"
1488 ospf_abr_announce_network_to_area(
1497 if (IS_DEBUG_OSPF_EVENT
)
1498 zlog_debug("ospf_abr_announce_aggregates(): Stop");
1502 ospf_abr_send_nssa_aggregates(struct ospf
*ospf
) /* temporarily turned off */
1504 struct listnode
*node
; /*, n; */
1505 struct ospf_area
*area
; /*, *ar; */
1506 struct route_node
*rn
;
1507 struct ospf_area_range
*range
;
1508 struct prefix_ipv4 p
;
1510 if (IS_DEBUG_OSPF_NSSA
)
1511 zlog_debug("ospf_abr_send_nssa_aggregates(): Start");
1513 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1514 if (!area
->NSSATranslatorState
)
1517 if (IS_DEBUG_OSPF_NSSA
)
1519 "ospf_abr_send_nssa_aggregates(): looking at area %s",
1520 inet_ntoa(area
->area_id
));
1522 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
)) {
1523 if (rn
->info
== NULL
)
1528 if (!CHECK_FLAG(range
->flags
,
1529 OSPF_AREA_RANGE_ADVERTISE
)) {
1530 if (IS_DEBUG_OSPF_NSSA
)
1532 "ospf_abr_send_nssa_aggregates():"
1533 " discarding suppress-ranges");
1538 p
.prefix
= range
->addr
;
1539 p
.prefixlen
= range
->masklen
;
1541 if (IS_DEBUG_OSPF_NSSA
)
1543 "ospf_abr_send_nssa_aggregates():"
1544 " this is range: %s/%d",
1545 inet_ntoa(p
.prefix
), p
.prefixlen
);
1547 if (CHECK_FLAG(range
->flags
,
1548 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1550 p
.prefix
= range
->subst_addr
;
1551 p
.prefixlen
= range
->subst_masklen
;
1554 if (range
->specifics
) {
1555 if (IS_DEBUG_OSPF_NSSA
)
1557 "ospf_abr_send_nssa_aggregates(): active range");
1559 /* Fetch LSA-Type-7 from aggregate prefix, and
1561 * translate, Install (as Type-5), Approve, and
1564 ospf_abr_translate_nssa_range(&p
, range
->cost
);
1566 } /* all area ranges*/
1569 if (IS_DEBUG_OSPF_NSSA
)
1570 zlog_debug("ospf_abr_send_nssa_aggregates(): Stop");
1573 static void ospf_abr_announce_stub_defaults(struct ospf
*ospf
)
1575 struct listnode
*node
;
1576 struct ospf_area
*area
;
1577 struct prefix_ipv4 p
;
1579 if (!IS_OSPF_ABR(ospf
))
1582 if (IS_DEBUG_OSPF_EVENT
)
1583 zlog_debug("ospf_abr_announce_stub_defaults(): Start");
1586 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1589 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1590 if (IS_DEBUG_OSPF_EVENT
)
1592 "ospf_abr_announce_stub_defaults(): looking at area %s",
1593 inet_ntoa(area
->area_id
));
1595 if ((area
->external_routing
!= OSPF_AREA_STUB
)
1596 && (area
->external_routing
!= OSPF_AREA_NSSA
))
1599 if (OSPF_IS_AREA_BACKBONE(area
))
1600 continue; /* Sanity Check */
1602 if (IS_DEBUG_OSPF_EVENT
)
1604 "ospf_abr_announce_stub_defaults(): "
1605 "announcing 0.0.0.0/0 to area %s",
1606 inet_ntoa(area
->area_id
));
1607 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1610 if (IS_DEBUG_OSPF_EVENT
)
1611 zlog_debug("ospf_abr_announce_stub_defaults(): Stop");
1614 static int ospf_abr_remove_unapproved_translates_apply(struct ospf
*ospf
,
1615 struct ospf_lsa
*lsa
)
1617 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1618 && !CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
)) {
1620 "ospf_abr_remove_unapproved_translates(): "
1621 "removing unapproved translates, ID: %s",
1622 inet_ntoa(lsa
->data
->id
));
1624 /* FLUSH THROUGHOUT AS */
1625 ospf_lsa_flush_as(ospf
, lsa
);
1627 /* DISCARD from LSDB */
1632 static void ospf_abr_remove_unapproved_translates(struct ospf
*ospf
)
1634 struct route_node
*rn
;
1635 struct ospf_lsa
*lsa
;
1637 /* All AREA PROCESS should have APPROVED necessary LSAs */
1638 /* Remove any left over and not APPROVED */
1639 if (IS_DEBUG_OSPF_NSSA
)
1640 zlog_debug("ospf_abr_remove_unapproved_translates(): Start");
1642 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1643 ospf_abr_remove_unapproved_translates_apply(ospf
, lsa
);
1645 if (IS_DEBUG_OSPF_NSSA
)
1646 zlog_debug("ospf_abr_remove_unapproved_translates(): Stop");
1649 static void ospf_abr_remove_unapproved_summaries(struct ospf
*ospf
)
1651 struct listnode
*node
;
1652 struct ospf_area
*area
;
1653 struct route_node
*rn
;
1654 struct ospf_lsa
*lsa
;
1656 if (IS_DEBUG_OSPF_EVENT
)
1657 zlog_debug("ospf_abr_remove_unapproved_summaries(): Start");
1659 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1660 if (IS_DEBUG_OSPF_EVENT
)
1662 "ospf_abr_remove_unapproved_summaries(): "
1663 "looking at area %s",
1664 inet_ntoa(area
->area_id
));
1666 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1667 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1668 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1669 ospf_lsa_flush_area(lsa
, area
);
1671 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1672 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1673 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1674 ospf_lsa_flush_area(lsa
, area
);
1677 if (IS_DEBUG_OSPF_EVENT
)
1678 zlog_debug("ospf_abr_remove_unapproved_summaries(): Stop");
1681 static void ospf_abr_manage_discard_routes(struct ospf
*ospf
)
1683 struct listnode
*node
, *nnode
;
1684 struct route_node
*rn
;
1685 struct ospf_area
*area
;
1686 struct ospf_area_range
*range
;
1688 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
1689 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1690 if ((range
= rn
->info
) != NULL
)
1691 if (CHECK_FLAG(range
->flags
,
1692 OSPF_AREA_RANGE_ADVERTISE
)) {
1693 if (range
->specifics
)
1694 ospf_add_discard_route(
1695 ospf
, ospf
->new_table
,
1700 ospf_delete_discard_route(
1701 ospf
, ospf
->new_table
,
1707 /* This is the function taking care about ABR NSSA, i.e. NSSA
1708 Translator, -LSA aggregation and flooding. For all NSSAs
1710 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1711 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1714 Any received Type-5s are legal for an ABR, else illegal for IR.
1715 Received Type-7s are installed, by area, with incoming P-bit. They
1716 are flooded; if the Elected NSSA Translator, then P-bit off.
1718 Additionally, this ABR will place "translated type-7's" into the
1719 Type-5 LSDB in order to keep track of APPROVAL or not.
1721 It will scan through every area, looking for Type-7 LSAs with P-Bit
1722 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1723 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1726 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1727 left over are FLUSHED and DISCARDED.
1729 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1730 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1732 static void ospf_abr_nssa_task(struct ospf
*ospf
) /* called only if any_nssa */
1734 if (IS_DEBUG_OSPF_NSSA
)
1735 zlog_debug("Check for NSSA-ABR Tasks():");
1737 if (!IS_OSPF_ABR(ospf
))
1743 /* Each area must confirm TranslatorRole */
1744 if (IS_DEBUG_OSPF_NSSA
)
1745 zlog_debug("ospf_abr_nssa_task(): Start");
1747 /* For all Global Entries flagged "local-translate", unset APPROVED */
1748 if (IS_DEBUG_OSPF_NSSA
)
1749 zlog_debug("ospf_abr_nssa_task(): unapprove translates");
1751 ospf_abr_unapprove_translates(ospf
);
1753 /* RESET all Ranges in every Area, same as summaries */
1754 if (IS_DEBUG_OSPF_NSSA
)
1755 zlog_debug("ospf_abr_nssa_task(): NSSA initialize aggregates");
1756 ospf_abr_prepare_aggregates(ospf
); /*TURNED OFF just for now */
1758 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1759 * Aggregate as Type-7
1760 * Install or Approve in Type-5 Global LSDB
1762 if (IS_DEBUG_OSPF_NSSA
)
1763 zlog_debug("ospf_abr_nssa_task(): process translates");
1764 ospf_abr_process_nssa_translates(ospf
);
1766 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1768 * Scan Type-7's for aggregates, translate to Type-5's,
1769 * Install/Flood/Approve
1771 if (IS_DEBUG_OSPF_NSSA
)
1772 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1773 ospf_abr_send_nssa_aggregates(ospf
); /*TURNED OFF FOR NOW */
1775 /* Send any NSSA defaults as Type-5
1776 *if (IS_DEBUG_OSPF_NSSA)
1777 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1778 *ospf_abr_announce_nssa_defaults (ospf);
1779 * havnt a clue what above is supposed to do.
1782 /* Flush any unapproved previous translates from Global Data Base */
1783 if (IS_DEBUG_OSPF_NSSA
)
1785 "ospf_abr_nssa_task(): remove unapproved translates");
1786 ospf_abr_remove_unapproved_translates(ospf
);
1788 ospf_abr_manage_discard_routes(ospf
); /* same as normal...discard */
1790 if (IS_DEBUG_OSPF_NSSA
)
1791 zlog_debug("ospf_abr_nssa_task(): Stop");
1794 /* This is the function taking care about ABR stuff, i.e.
1795 summary-LSA origination and flooding. */
1796 void ospf_abr_task(struct ospf
*ospf
)
1798 if (IS_DEBUG_OSPF_EVENT
)
1799 zlog_debug("ospf_abr_task(): Start");
1801 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
) {
1802 if (IS_DEBUG_OSPF_EVENT
)
1804 "ospf_abr_task(): Routing tables are not yet ready");
1808 if (IS_DEBUG_OSPF_EVENT
)
1809 zlog_debug("ospf_abr_task(): unapprove summaries");
1810 ospf_abr_unapprove_summaries(ospf
);
1812 if (IS_DEBUG_OSPF_EVENT
)
1813 zlog_debug("ospf_abr_task(): prepare aggregates");
1814 ospf_abr_prepare_aggregates(ospf
);
1816 if (IS_OSPF_ABR(ospf
)) {
1817 if (IS_DEBUG_OSPF_EVENT
)
1818 zlog_debug("ospf_abr_task(): process network RT");
1819 ospf_abr_process_network_rt(ospf
, ospf
->new_table
);
1821 if (IS_DEBUG_OSPF_EVENT
)
1822 zlog_debug("ospf_abr_task(): process router RT");
1823 ospf_abr_process_router_rt(ospf
, ospf
->new_rtrs
);
1825 if (IS_DEBUG_OSPF_EVENT
)
1826 zlog_debug("ospf_abr_task(): announce aggregates");
1827 ospf_abr_announce_aggregates(ospf
);
1829 if (IS_DEBUG_OSPF_EVENT
)
1830 zlog_debug("ospf_abr_task(): announce stub defaults");
1831 ospf_abr_announce_stub_defaults(ospf
);
1834 if (IS_DEBUG_OSPF_EVENT
)
1835 zlog_debug("ospf_abr_task(): remove unapproved summaries");
1836 ospf_abr_remove_unapproved_summaries(ospf
);
1838 ospf_abr_manage_discard_routes(ospf
);
1840 if (IS_DEBUG_OSPF_EVENT
)
1841 zlog_debug("ospf_abr_task(): Stop");
1844 static int ospf_abr_task_timer(struct thread
*thread
)
1846 struct ospf
*ospf
= THREAD_ARG(thread
);
1848 ospf
->t_abr_task
= 0;
1850 if (IS_DEBUG_OSPF_EVENT
)
1851 zlog_debug("Running ABR task on timer");
1853 ospf_check_abr_status(ospf
);
1854 ospf_abr_nssa_check_status(ospf
);
1856 ospf_abr_task(ospf
);
1857 ospf_abr_nssa_task(ospf
); /* if nssa-abr, then scan Type-7 LSDB */
1862 void ospf_schedule_abr_task(struct ospf
*ospf
)
1864 if (IS_DEBUG_OSPF_EVENT
)
1865 zlog_debug("Scheduling ABR task");
1867 thread_add_timer(master
, ospf_abr_task_timer
, ospf
, OSPF_ABR_TASK_DELAY
,