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(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
200 && !CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
201 || (!CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
202 && CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
)))
203 ospf_schedule_abr_task(ospf
);
205 range
= ospf_area_range_new(p
);
206 ospf_area_range_add(area
, range
);
207 ospf_schedule_abr_task(ospf
);
210 if (CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
211 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
213 UNSET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
218 int ospf_area_range_cost_set(struct ospf
*ospf
, struct in_addr area_id
,
219 struct prefix_ipv4
*p
, uint32_t cost
)
221 struct ospf_area
*area
;
222 struct ospf_area_range
*range
;
224 area
= ospf_area_get(ospf
, area_id
);
228 range
= ospf_area_range_lookup(area
, p
);
232 if (range
->cost_config
!= cost
) {
233 range
->cost_config
= cost
;
234 if (ospf_area_range_active(range
))
235 ospf_schedule_abr_task(ospf
);
241 int ospf_area_range_unset(struct ospf
*ospf
, struct in_addr area_id
,
242 struct prefix_ipv4
*p
)
244 struct ospf_area
*area
;
245 struct route_node
*rn
;
247 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
251 rn
= route_node_lookup(area
->ranges
, (struct prefix
*)p
);
255 if (ospf_area_range_active(rn
->info
))
256 ospf_schedule_abr_task(ospf
);
258 ospf_area_range_delete(area
, rn
);
263 int ospf_area_range_substitute_set(struct ospf
*ospf
, struct in_addr area_id
,
264 struct prefix_ipv4
*p
, struct prefix_ipv4
*s
)
266 struct ospf_area
*area
;
267 struct ospf_area_range
*range
;
269 area
= ospf_area_get(ospf
, area_id
);
270 range
= ospf_area_range_lookup(area
, p
);
273 if (!CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
274 || !CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
275 ospf_schedule_abr_task(ospf
);
277 range
= ospf_area_range_new(p
);
278 ospf_area_range_add(area
, range
);
279 ospf_schedule_abr_task(ospf
);
282 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
283 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
284 range
->subst_addr
= s
->prefix
;
285 range
->subst_masklen
= s
->prefixlen
;
290 int ospf_area_range_substitute_unset(struct ospf
*ospf
, struct in_addr area_id
,
291 struct prefix_ipv4
*p
)
293 struct ospf_area
*area
;
294 struct ospf_area_range
*range
;
296 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
300 range
= ospf_area_range_lookup(area
, p
);
304 if (CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
305 if (ospf_area_range_active(range
))
306 ospf_schedule_abr_task(ospf
);
308 UNSET_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
309 range
->subst_addr
.s_addr
= 0;
310 range
->subst_masklen
= 0;
315 int ospf_act_bb_connection(struct ospf
*ospf
)
317 if (ospf
->backbone
== NULL
)
320 return ospf
->backbone
->full_nbrs
;
323 /* Determine whether this router is elected translator or not for area */
324 static int ospf_abr_nssa_am_elected(struct ospf_area
*area
)
326 struct route_node
*rn
;
327 struct ospf_lsa
*lsa
;
328 struct router_lsa
*rlsa
;
329 struct in_addr
*best
= NULL
;
331 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
) {
333 if (!lsa
|| (lsa
->data
->type
!= OSPF_ROUTER_LSA
)
337 rlsa
= (struct router_lsa
*)lsa
->data
;
339 /* ignore non-ABR routers */
340 if (!IS_ROUTER_LSA_BORDER(rlsa
))
343 /* Router has Nt flag - always translate */
344 if (IS_ROUTER_LSA_NT(rlsa
)) {
345 if (IS_DEBUG_OSPF_NSSA
)
347 "ospf_abr_nssa_am_elected: "
348 "router %s asserts Nt",
349 inet_ntoa(lsa
->data
->id
));
354 best
= &lsa
->data
->id
;
355 else if (IPV4_ADDR_CMP(&best
->s_addr
, &lsa
->data
->id
.s_addr
)
357 best
= &lsa
->data
->id
;
360 if (IS_DEBUG_OSPF_NSSA
)
362 "ospf_abr_nssa_am_elected: best electable ABR is: %s",
363 (best
) ? inet_ntoa(*best
) : "<none>");
368 if (IPV4_ADDR_CMP(&best
->s_addr
, &area
->ospf
->router_id
.s_addr
) < 0)
374 /* Check NSSA ABR status
375 * assumes there are nssa areas
377 static void ospf_abr_nssa_check_status(struct ospf
*ospf
)
379 struct ospf_area
*area
;
380 struct listnode
*lnode
, *nnode
;
382 for (ALL_LIST_ELEMENTS(ospf
->areas
, lnode
, nnode
, area
)) {
383 uint8_t old_state
= area
->NSSATranslatorState
;
385 if (area
->external_routing
!= OSPF_AREA_NSSA
)
388 if (IS_DEBUG_OSPF(nssa
, NSSA
))
390 "ospf_abr_nssa_check_status: "
392 inet_ntoa(area
->area_id
));
394 if (!IS_OSPF_ABR(area
->ospf
)) {
395 if (IS_DEBUG_OSPF(nssa
, NSSA
))
397 "ospf_abr_nssa_check_status: "
399 area
->NSSATranslatorState
=
400 OSPF_NSSA_TRANSLATE_DISABLED
;
402 switch (area
->NSSATranslatorRole
) {
403 case OSPF_NSSA_ROLE_NEVER
:
404 /* We never Translate Type-7 LSA. */
405 /* TODO: check previous state and flush? */
406 if (IS_DEBUG_OSPF(nssa
, NSSA
))
408 "ospf_abr_nssa_check_status: "
410 area
->NSSATranslatorState
=
411 OSPF_NSSA_TRANSLATE_DISABLED
;
414 case OSPF_NSSA_ROLE_ALWAYS
:
415 /* We always translate if we are an ABR
416 * TODO: originate new LSAs if state change?
417 * or let the nssa abr task take care of it?
419 if (IS_DEBUG_OSPF(nssa
, NSSA
))
421 "ospf_abr_nssa_check_status: "
423 area
->NSSATranslatorState
=
424 OSPF_NSSA_TRANSLATE_ENABLED
;
427 case OSPF_NSSA_ROLE_CANDIDATE
:
428 /* We are a candidate for Translation */
429 if (ospf_abr_nssa_am_elected(area
) > 0) {
430 area
->NSSATranslatorState
=
431 OSPF_NSSA_TRANSLATE_ENABLED
;
432 if (IS_DEBUG_OSPF(nssa
, NSSA
))
434 "ospf_abr_nssa_check_status: "
435 "elected translator");
437 area
->NSSATranslatorState
=
438 OSPF_NSSA_TRANSLATE_DISABLED
;
439 if (IS_DEBUG_OSPF(nssa
, NSSA
))
441 "ospf_abr_nssa_check_status: "
448 * All NSSA border routers must set the E-bit in the Type-1
450 * of their directly attached non-stub areas, even when they are
454 if (old_state
!= area
->NSSATranslatorState
) {
455 if (old_state
== OSPF_NSSA_TRANSLATE_DISABLED
)
456 ospf_asbr_status_update(ospf
,
457 ++ospf
->redistribute
);
458 else if (area
->NSSATranslatorState
459 == OSPF_NSSA_TRANSLATE_DISABLED
)
460 ospf_asbr_status_update(ospf
,
461 --ospf
->redistribute
);
466 /* Check area border router status. */
467 void ospf_check_abr_status(struct ospf
*ospf
)
469 struct ospf_area
*area
;
470 struct listnode
*node
, *nnode
;
471 int bb_configured
= 0;
472 int bb_act_attached
= 0;
473 int areas_configured
= 0;
474 int areas_act_attached
= 0;
475 uint8_t new_flags
= ospf
->flags
;
477 if (IS_DEBUG_OSPF_EVENT
)
478 zlog_debug("ospf_check_abr_status(): Start");
480 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
481 if (listcount(area
->oiflist
)) {
484 if (OSPF_IS_AREA_BACKBONE(area
))
488 if (ospf_area_actively_attached(area
)) {
489 areas_act_attached
++;
491 if (OSPF_IS_AREA_BACKBONE(area
))
496 if (IS_DEBUG_OSPF_EVENT
) {
497 zlog_debug("ospf_check_abr_status(): looked through areas");
498 zlog_debug("ospf_check_abr_status(): bb_configured: %d",
500 zlog_debug("ospf_check_abr_status(): bb_act_attached: %d",
502 zlog_debug("ospf_check_abr_status(): areas_configured: %d",
504 zlog_debug("ospf_check_abr_status(): areas_act_attached: %d",
508 switch (ospf
->abr_type
) {
509 case OSPF_ABR_SHORTCUT
:
511 if (areas_act_attached
> 1)
512 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
514 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
518 if ((areas_act_attached
> 1) && bb_configured
)
519 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
521 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
525 if ((areas_configured
> 1) && bb_act_attached
)
526 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
528 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
534 if (new_flags
!= ospf
->flags
) {
535 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_ABR_STATUS_CHANGE
);
536 if (IS_DEBUG_OSPF_EVENT
)
538 "ospf_check_abr_status(): new router flags: %x",
540 ospf
->flags
= new_flags
;
541 ospf_router_lsa_update(ospf
);
545 static void ospf_abr_update_aggregate(struct ospf_area_range
*range
,
546 struct ospf_route
* or,
547 struct ospf_area
*area
)
549 if (IS_DEBUG_OSPF_EVENT
)
550 zlog_debug("ospf_abr_update_aggregate(): Start");
552 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)
553 && (range
->cost
!= OSPF_STUB_MAX_METRIC_SUMMARY_COST
)) {
554 range
->cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
555 if (IS_DEBUG_OSPF_EVENT
)
557 "ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
559 } else if (range
->cost_config
!= OSPF_AREA_RANGE_COST_UNSPEC
) {
560 if (IS_DEBUG_OSPF_EVENT
)
562 "ospf_abr_update_aggregate(): use configured cost %d",
565 range
->cost
= range
->cost_config
;
567 if (range
->specifics
== 0) {
568 if (IS_DEBUG_OSPF_EVENT
)
570 "ospf_abr_update_aggregate(): use or->cost %d",
573 range
->cost
= or->cost
; /* 1st time get 1st cost */
576 if (or->cost
> range
->cost
) {
577 if (IS_DEBUG_OSPF_EVENT
)
579 "ospf_abr_update_aggregate(): update to %d",
582 range
->cost
= or->cost
;
589 static void set_metric(struct ospf_lsa
*lsa
, uint32_t metric
)
591 struct summary_lsa
*header
;
593 metric
= htonl(metric
);
594 mp
= (uint8_t *)&metric
;
596 header
= (struct summary_lsa
*)lsa
->data
;
597 memcpy(header
->metric
, mp
, 3);
600 /* ospf_abr_translate_nssa */
601 static int ospf_abr_translate_nssa(struct ospf_area
*area
, struct ospf_lsa
*lsa
)
603 /* Incoming Type-7 or later aggregated Type-7
605 * LSA is skipped if P-bit is off.
606 * LSA is aggregated if within range.
608 * The Type-7 is translated, Installed/Approved as a Type-5 into
609 * global LSDB, then Flooded through AS
611 * Later, any Unapproved Translated Type-5's are flushed/discarded
614 struct ospf_lsa
*old
= NULL
, *new = NULL
;
615 struct as_external_lsa
*ext7
;
616 struct prefix_ipv4 p
;
618 if (!CHECK_FLAG(lsa
->data
->options
, OSPF_OPTION_NP
)) {
619 if (IS_DEBUG_OSPF_NSSA
)
621 "ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
622 inet_ntoa(lsa
->data
->id
));
626 if (IS_DEBUG_OSPF_NSSA
)
628 "ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
629 inet_ntoa(lsa
->data
->id
));
631 ext7
= (struct as_external_lsa
*)(lsa
->data
);
632 p
.prefix
= lsa
->data
->id
;
633 p
.prefixlen
= ip_masklen(ext7
->mask
);
635 if (ext7
->e
[0].fwd_addr
.s_addr
== OSPF_DEFAULT_DESTINATION
) {
636 if (IS_DEBUG_OSPF_NSSA
)
638 "ospf_abr_translate_nssa(): LSA Id %s, "
639 "Forward address is 0, NO Translation",
640 inet_ntoa(lsa
->data
->id
));
644 /* try find existing AS-External LSA for this prefix */
646 old
= ospf_external_info_find_lsa(area
->ospf
, &p
);
649 if (IS_DEBUG_OSPF_NSSA
)
651 "ospf_abr_translate_nssa(): "
652 "found old translated LSA Id %s, refreshing",
653 inet_ntoa(old
->data
->id
));
656 new = ospf_translated_nssa_refresh(area
->ospf
, lsa
, old
);
658 if (IS_DEBUG_OSPF_NSSA
)
660 "ospf_abr_translate_nssa(): "
661 "could not refresh translated LSA Id %s",
662 inet_ntoa(old
->data
->id
));
665 /* no existing external route for this LSA Id
666 * originate translated LSA
669 if ((new = ospf_translated_nssa_originate(area
->ospf
, lsa
))
671 if (IS_DEBUG_OSPF_NSSA
)
673 "ospf_abr_translate_nssa(): Could not translate "
674 "Type-7 for %s to Type-5",
675 inet_ntoa(lsa
->data
->id
));
680 /* Area where Aggregate testing will be inserted, just like summary
682 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
687 static void ospf_abr_translate_nssa_range(struct prefix_ipv4
*p
, uint32_t cost
)
689 /* The Type-7 is created from the aggregated prefix and forwarded
690 for lsa installation and flooding... to be added... */
693 void ospf_abr_announce_network_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
694 struct ospf_area
*area
)
696 struct ospf_lsa
*lsa
, *old
= NULL
;
697 struct summary_lsa
*sl
= NULL
;
700 if (IS_DEBUG_OSPF_EVENT
)
701 zlog_debug("ospf_abr_announce_network_to_area(): Start");
703 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
704 full_cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
708 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_SUMMARY_LSA
,
709 (struct prefix_ipv4
*)p
,
710 area
->ospf
->router_id
);
712 if (IS_DEBUG_OSPF_EVENT
)
714 "ospf_abr_announce_network_to_area(): old summary found");
716 sl
= (struct summary_lsa
*)old
->data
;
718 if (IS_DEBUG_OSPF_EVENT
)
720 "ospf_abr_announce_network_to_area(): "
721 "old metric: %d, new metric: %d",
722 GET_METRIC(sl
->metric
), cost
);
724 if ((GET_METRIC(sl
->metric
) == full_cost
)
725 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
726 /* unchanged. simply reapprove it */
727 if (IS_DEBUG_OSPF_EVENT
)
729 "ospf_abr_announce_network_to_area(): "
730 "old summary approved");
731 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
733 /* LSA is changed, refresh it */
734 if (IS_DEBUG_OSPF_EVENT
)
736 "ospf_abr_announce_network_to_area(): "
737 "refreshing summary");
738 set_metric(old
, full_cost
);
739 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
742 char buf
[PREFIX2STR_BUFFER
];
744 prefix2str((struct prefix
*)p
, buf
,
746 flog_warn(OSPF_WARN_LSA_MISSING
,
747 "%s: Could not refresh %s to %s",
749 inet_ntoa(area
->area_id
));
753 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
754 /* This will flood through area. */
757 if (IS_DEBUG_OSPF_EVENT
)
759 "ospf_abr_announce_network_to_area(): "
760 "creating new summary");
761 lsa
= ospf_summary_lsa_originate((struct prefix_ipv4
*)p
,
763 /* This will flood through area. */
766 char buf
[PREFIX2STR_BUFFER
];
768 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
769 flog_warn(OSPF_WARN_LSA_MISSING
,
770 "%s: Could not originate %s to %s", __func__
,
771 buf
, inet_ntoa(area
->area_id
));
775 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
776 if (IS_DEBUG_OSPF_EVENT
)
778 "ospf_abr_announce_network_to_area(): "
779 "flooding new version of summary");
782 if (IS_DEBUG_OSPF_EVENT
)
783 zlog_debug("ospf_abr_announce_network_to_area(): Stop");
786 static int ospf_abr_nexthops_belong_to_area(struct ospf_route
* or,
787 struct ospf_area
*area
)
789 struct listnode
*node
, *nnode
;
790 struct ospf_path
*path
;
791 struct ospf_interface
*oi
;
793 for (ALL_LIST_ELEMENTS_RO(or->paths
, node
, path
))
794 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, nnode
, oi
))
795 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
801 static int ospf_abr_should_accept(struct prefix_ipv4
*p
, struct ospf_area
*area
)
803 if (IMPORT_NAME(area
)) {
804 if (IMPORT_LIST(area
) == NULL
)
806 access_list_lookup(AFI_IP
, IMPORT_NAME(area
));
808 if (IMPORT_LIST(area
))
809 if (access_list_apply(IMPORT_LIST(area
), p
)
817 static int ospf_abr_plist_in_check(struct ospf_area
*area
,
818 struct ospf_route
* or,
819 struct prefix_ipv4
*p
)
821 if (PREFIX_NAME_IN(area
)) {
822 if (PREFIX_LIST_IN(area
) == NULL
)
823 PREFIX_LIST_IN(area
) = prefix_list_lookup(
824 AFI_IP
, PREFIX_NAME_IN(area
));
825 if (PREFIX_LIST_IN(area
))
826 if (prefix_list_apply(PREFIX_LIST_IN(area
), p
)
833 static int ospf_abr_plist_out_check(struct ospf_area
*area
,
834 struct ospf_route
* or,
835 struct prefix_ipv4
*p
)
837 if (PREFIX_NAME_OUT(area
)) {
838 if (PREFIX_LIST_OUT(area
) == NULL
)
839 PREFIX_LIST_OUT(area
) = prefix_list_lookup(
840 AFI_IP
, PREFIX_NAME_OUT(area
));
841 if (PREFIX_LIST_OUT(area
))
842 if (prefix_list_apply(PREFIX_LIST_OUT(area
), p
)
849 static void ospf_abr_announce_network(struct ospf
*ospf
, struct prefix_ipv4
*p
,
850 struct ospf_route
* or)
852 struct ospf_area_range
*range
;
853 struct ospf_area
*area
, *or_area
;
854 struct listnode
*node
;
856 if (IS_DEBUG_OSPF_EVENT
)
857 zlog_debug("ospf_abr_announce_network(): Start");
859 or_area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
862 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
863 if (IS_DEBUG_OSPF_EVENT
)
865 "ospf_abr_announce_network(): looking at area %s",
866 inet_ntoa(area
->area_id
));
868 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
871 if (ospf_abr_nexthops_belong_to_area(or, area
))
874 if (!ospf_abr_should_accept(p
, area
)) {
875 if (IS_DEBUG_OSPF_EVENT
)
877 "ospf_abr_announce_network(): "
878 "prefix %s/%d was denied by import-list",
879 inet_ntoa(p
->prefix
), p
->prefixlen
);
883 if (!ospf_abr_plist_in_check(area
, or, p
)) {
884 if (IS_DEBUG_OSPF_EVENT
)
886 "ospf_abr_announce_network(): "
887 "prefix %s/%d was denied by prefix-list",
888 inet_ntoa(p
->prefix
), p
->prefixlen
);
892 if (area
->external_routing
!= OSPF_AREA_DEFAULT
893 && area
->no_summary
) {
894 if (IS_DEBUG_OSPF_EVENT
)
896 "ospf_abr_announce_network(): "
897 "area %s is stub and no_summary",
898 inet_ntoa(area
->area_id
));
902 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
903 if (IS_DEBUG_OSPF_EVENT
)
905 "ospf_abr_announce_network(): this is "
906 "inter-area route to %s/%d",
907 inet_ntoa(p
->prefix
), p
->prefixlen
);
909 if (!OSPF_IS_AREA_BACKBONE(area
))
910 ospf_abr_announce_network_to_area(p
, or->cost
,
914 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
915 if (IS_DEBUG_OSPF_EVENT
)
917 "ospf_abr_announce_network(): "
918 "this is intra-area route to %s/%d",
919 inet_ntoa(p
->prefix
), p
->prefixlen
);
920 if ((range
= ospf_area_range_match(or_area
, p
))
921 && !ospf_area_is_transit(area
))
922 ospf_abr_update_aggregate(range
, or, area
);
924 ospf_abr_announce_network_to_area(p
, or->cost
,
930 static int ospf_abr_should_announce(struct ospf
*ospf
, struct prefix_ipv4
*p
,
931 struct ospf_route
* or)
933 struct ospf_area
*area
;
935 area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
939 if (EXPORT_NAME(area
)) {
940 if (EXPORT_LIST(area
) == NULL
)
942 access_list_lookup(AFI_IP
, EXPORT_NAME(area
));
944 if (EXPORT_LIST(area
))
945 if (access_list_apply(EXPORT_LIST(area
), p
)
953 static void ospf_abr_process_nssa_translates(struct ospf
*ospf
)
955 /* Scan through all NSSA_LSDB records for all areas;
957 If P-bit is on, translate all Type-7's to 5's and aggregate or
958 flood install as approved in Type-5 LSDB with XLATE Flag on
959 later, do same for all aggregates... At end, DISCARD all
960 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
961 struct listnode
*node
;
962 struct ospf_area
*area
;
963 struct route_node
*rn
;
964 struct ospf_lsa
*lsa
;
966 if (IS_DEBUG_OSPF_NSSA
)
967 zlog_debug("ospf_abr_process_nssa_translates(): Start");
969 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
970 if (!area
->NSSATranslatorState
)
971 continue; /* skip if not translator */
973 if (area
->external_routing
!= OSPF_AREA_NSSA
)
974 continue; /* skip if not Nssa Area */
976 if (IS_DEBUG_OSPF_NSSA
)
978 "ospf_abr_process_nssa_translates(): "
979 "looking at area %s",
980 inet_ntoa(area
->area_id
));
982 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
983 ospf_abr_translate_nssa(area
, lsa
);
986 if (IS_DEBUG_OSPF_NSSA
)
987 zlog_debug("ospf_abr_process_nssa_translates(): Stop");
990 static void ospf_abr_process_network_rt(struct ospf
*ospf
,
991 struct route_table
*rt
)
993 struct ospf_area
*area
;
994 struct ospf_route
* or ;
995 struct route_node
*rn
;
997 if (IS_DEBUG_OSPF_EVENT
)
998 zlog_debug("ospf_abr_process_network_rt(): Start");
1000 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1001 if ((or = rn
->info
) == NULL
)
1004 if (!(area
= ospf_area_lookup_by_area_id(ospf
,
1005 or->u
.std
.area_id
))) {
1006 if (IS_DEBUG_OSPF_EVENT
)
1008 "ospf_abr_process_network_rt(): area %s no longer exists",
1009 inet_ntoa(or->u
.std
.area_id
));
1013 if (IS_DEBUG_OSPF_EVENT
)
1015 "ospf_abr_process_network_rt(): this is a route to %s/%d",
1016 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
1017 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
) {
1018 if (IS_DEBUG_OSPF_EVENT
)
1020 "ospf_abr_process_network_rt(): "
1021 "this is an External router, skipping");
1025 if (or->cost
>= OSPF_LS_INFINITY
) {
1026 if (IS_DEBUG_OSPF_EVENT
)
1028 "ospf_abr_process_network_rt():"
1029 " this route's cost is infinity, skipping");
1033 if (or->type
== OSPF_DESTINATION_DISCARD
) {
1034 if (IS_DEBUG_OSPF_EVENT
)
1036 "ospf_abr_process_network_rt():"
1037 " this is a discard entry, skipping");
1042 or->path_type
== OSPF_PATH_INTRA_AREA
1043 && !ospf_abr_should_announce(
1044 ospf
, (struct prefix_ipv4
*)&rn
->p
,
1046 if (IS_DEBUG_OSPF_EVENT
)
1048 "ospf_abr_process_network_rt(): denied by export-list");
1053 or->path_type
== OSPF_PATH_INTRA_AREA
1054 && !ospf_abr_plist_out_check(
1056 (struct prefix_ipv4
*)&rn
->p
)) {
1057 if (IS_DEBUG_OSPF_EVENT
)
1059 "ospf_abr_process_network_rt(): denied by prefix-list");
1063 if ((or->path_type
== OSPF_PATH_INTER_AREA
)
1064 && !OSPF_IS_AREA_ID_BACKBONE(or->u
.std
.area_id
)) {
1065 if (IS_DEBUG_OSPF_EVENT
)
1067 "ospf_abr_process_network_rt():"
1068 " this is route is not backbone one, skipping");
1073 if ((ospf
->abr_type
== OSPF_ABR_CISCO
)
1074 || (ospf
->abr_type
== OSPF_ABR_IBM
))
1076 if (!ospf_act_bb_connection(ospf
) &&
1077 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1078 if (IS_DEBUG_OSPF_EVENT
)
1080 "ospf_abr_process_network_rt(): ALT ABR: "
1081 "No BB connection, skip not intra-area routes");
1085 if (IS_DEBUG_OSPF_EVENT
)
1086 zlog_debug("ospf_abr_process_network_rt(): announcing");
1087 ospf_abr_announce_network(ospf
, (struct prefix_ipv4
*)&rn
->p
,
1091 if (IS_DEBUG_OSPF_EVENT
)
1092 zlog_debug("ospf_abr_process_network_rt(): Stop");
1095 static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
1096 struct ospf_area
*area
)
1098 struct ospf_lsa
*lsa
, *old
= NULL
;
1099 struct summary_lsa
*slsa
= NULL
;
1101 if (IS_DEBUG_OSPF_EVENT
)
1102 zlog_debug("ospf_abr_announce_rtr_to_area(): Start");
1104 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
,
1105 area
->ospf
->router_id
);
1107 if (IS_DEBUG_OSPF_EVENT
)
1109 "ospf_abr_announce_rtr_to_area(): old summary found");
1110 slsa
= (struct summary_lsa
*)old
->data
;
1112 if (IS_DEBUG_OSPF_EVENT
)
1114 "ospf_abr_announce_network_to_area(): "
1115 "old metric: %d, new metric: %d",
1116 GET_METRIC(slsa
->metric
), cost
);
1119 if (old
&& (GET_METRIC(slsa
->metric
) == cost
)
1120 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
1121 if (IS_DEBUG_OSPF_EVENT
)
1123 "ospf_abr_announce_rtr_to_area(): old summary approved");
1124 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
1126 if (IS_DEBUG_OSPF_EVENT
)
1127 zlog_debug("ospf_abr_announce_rtr_to_area(): 2.2");
1130 set_metric(old
, cost
);
1131 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
1133 lsa
= ospf_summary_asbr_lsa_originate(p
, cost
, area
);
1135 char buf
[PREFIX2STR_BUFFER
];
1137 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
1138 flog_warn(OSPF_WARN_LSA_MISSING
,
1139 "%s: Could not refresh/originate %s to %s",
1140 __func__
, buf
, inet_ntoa(area
->area_id
));
1144 if (IS_DEBUG_OSPF_EVENT
)
1146 "ospf_abr_announce_rtr_to_area(): "
1147 "flooding new version of summary");
1150 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new
1152 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1154 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1155 /* ospf_flood_through_area (area, NULL, lsa);*/
1158 if (IS_DEBUG_OSPF_EVENT
)
1159 zlog_debug("ospf_abr_announce_rtr_to_area(): Stop");
1163 static void ospf_abr_announce_rtr(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1164 struct ospf_route
* or)
1166 struct listnode
*node
;
1167 struct ospf_area
*area
;
1169 if (IS_DEBUG_OSPF_EVENT
)
1170 zlog_debug("ospf_abr_announce_rtr(): Start");
1172 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1173 if (IS_DEBUG_OSPF_EVENT
)
1175 "ospf_abr_announce_rtr(): looking at area %s",
1176 inet_ntoa(area
->area_id
));
1178 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
1181 if (ospf_abr_nexthops_belong_to_area(or, area
))
1184 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
1185 if (IS_DEBUG_OSPF_EVENT
)
1187 "ospf_abr_announce_rtr(): "
1188 "area %s doesn't support external routing",
1189 inet_ntoa(area
->area_id
));
1193 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
1194 if (IS_DEBUG_OSPF_EVENT
)
1196 "ospf_abr_announce_rtr(): "
1197 "this is inter-area route to %s",
1198 inet_ntoa(p
->prefix
));
1199 if (!OSPF_IS_AREA_BACKBONE(area
))
1200 ospf_abr_announce_rtr_to_area(p
, or->cost
,
1204 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
1205 if (IS_DEBUG_OSPF_EVENT
)
1207 "ospf_abr_announce_rtr(): "
1208 "this is intra-area route to %s",
1209 inet_ntoa(p
->prefix
));
1210 ospf_abr_announce_rtr_to_area(p
, or->cost
, area
);
1214 if (IS_DEBUG_OSPF_EVENT
)
1215 zlog_debug("ospf_abr_announce_rtr(): Stop");
1218 static void ospf_abr_process_router_rt(struct ospf
*ospf
,
1219 struct route_table
*rt
)
1221 struct ospf_route
* or ;
1222 struct route_node
*rn
;
1225 if (IS_DEBUG_OSPF_EVENT
)
1226 zlog_debug("ospf_abr_process_router_rt(): Start");
1228 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1229 struct listnode
*node
, *nnode
;
1231 struct ospf_route
*best
= NULL
;
1233 if (rn
->info
== NULL
)
1238 if (IS_DEBUG_OSPF_EVENT
)
1240 "ospf_abr_process_router_rt(): this is a route to %s",
1241 inet_ntoa(rn
->p
.u
.prefix4
));
1243 for (ALL_LIST_ELEMENTS(l
, node
, nnode
, or)) {
1244 if (!ospf_area_lookup_by_area_id(ospf
,
1245 or->u
.std
.area_id
)) {
1246 if (IS_DEBUG_OSPF_EVENT
)
1248 "ospf_abr_process_router_rt(): area %s no longer exists",
1249 inet_ntoa(or->u
.std
.area_id
));
1254 if (!CHECK_FLAG(or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
)) {
1255 if (IS_DEBUG_OSPF_EVENT
)
1257 "ospf_abr_process_router_rt(): "
1258 "This is not an ASBR, skipping");
1263 best
= ospf_find_asbr_route(
1264 ospf
, rt
, (struct prefix_ipv4
*)&rn
->p
);
1272 if (IS_DEBUG_OSPF_EVENT
)
1274 "ospf_abr_process_router_rt(): "
1275 "This route is not the best among possible, skipping");
1280 or->path_type
== OSPF_PATH_INTER_AREA
1281 && !OSPF_IS_AREA_ID_BACKBONE(
1282 or->u
.std
.area_id
)) {
1283 if (IS_DEBUG_OSPF_EVENT
)
1285 "ospf_abr_process_router_rt(): "
1286 "This route is not a backbone one, skipping");
1290 if (or->cost
>= OSPF_LS_INFINITY
) {
1291 if (IS_DEBUG_OSPF_EVENT
)
1293 "ospf_abr_process_router_rt(): "
1294 "This route has LS_INFINITY metric, skipping");
1298 if (ospf
->abr_type
== OSPF_ABR_CISCO
1299 || ospf
->abr_type
== OSPF_ABR_IBM
)
1300 if (!ospf_act_bb_connection(ospf
) &&
1301 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1302 if (IS_DEBUG_OSPF_EVENT
)
1304 "ospf_abr_process_network_rt(): ALT ABR: "
1305 "No BB connection, skip not intra-area routes");
1309 ospf_abr_announce_rtr(ospf
,
1310 (struct prefix_ipv4
*)&rn
->p
, or);
1314 if (IS_DEBUG_OSPF_EVENT
)
1315 zlog_debug("ospf_abr_process_router_rt(): Stop");
1319 ospf_abr_unapprove_translates(struct ospf
*ospf
) /* For NSSA Translations */
1321 struct ospf_lsa
*lsa
;
1322 struct route_node
*rn
;
1324 if (IS_DEBUG_OSPF_NSSA
)
1325 zlog_debug("ospf_abr_unapprove_translates(): Start");
1327 /* NSSA Translator is not checked, because it may have gone away,
1328 and we would want to flush any residuals anyway */
1330 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1331 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) {
1332 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1333 if (IS_DEBUG_OSPF_NSSA
)
1335 "ospf_abr_unapprove_translates(): "
1336 "approved unset on link id %s",
1337 inet_ntoa(lsa
->data
->id
));
1340 if (IS_DEBUG_OSPF_NSSA
)
1341 zlog_debug("ospf_abr_unapprove_translates(): Stop");
1344 static void ospf_abr_unapprove_summaries(struct ospf
*ospf
)
1346 struct listnode
*node
;
1347 struct ospf_area
*area
;
1348 struct route_node
*rn
;
1349 struct ospf_lsa
*lsa
;
1351 if (IS_DEBUG_OSPF_EVENT
)
1352 zlog_debug("ospf_abr_unapprove_summaries(): Start");
1354 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1355 if (IS_DEBUG_OSPF_EVENT
)
1357 "ospf_abr_unapprove_summaries(): "
1358 "considering area %s",
1359 inet_ntoa(area
->area_id
));
1360 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1361 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1362 if (IS_DEBUG_OSPF_EVENT
)
1364 "ospf_abr_unapprove_summaries(): "
1365 "approved unset on summary link id %s",
1366 inet_ntoa(lsa
->data
->id
));
1367 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1370 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1371 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1372 if (IS_DEBUG_OSPF_EVENT
)
1374 "ospf_abr_unapprove_summaries(): "
1375 "approved unset on asbr-summary link id %s",
1376 inet_ntoa(lsa
->data
->id
));
1377 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1381 if (IS_DEBUG_OSPF_EVENT
)
1382 zlog_debug("ospf_abr_unapprove_summaries(): Stop");
1385 static void ospf_abr_prepare_aggregates(struct ospf
*ospf
)
1387 struct listnode
*node
;
1388 struct route_node
*rn
;
1389 struct ospf_area_range
*range
;
1390 struct ospf_area
*area
;
1392 if (IS_DEBUG_OSPF_EVENT
)
1393 zlog_debug("ospf_abr_prepare_aggregates(): Start");
1395 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1396 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1397 if ((range
= rn
->info
) != NULL
) {
1399 range
->specifics
= 0;
1403 if (IS_DEBUG_OSPF_EVENT
)
1404 zlog_debug("ospf_abr_prepare_aggregates(): Stop");
1407 static void ospf_abr_announce_aggregates(struct ospf
*ospf
)
1409 struct ospf_area
*area
, *ar
;
1410 struct ospf_area_range
*range
;
1411 struct route_node
*rn
;
1413 struct listnode
*node
, *n
;
1415 if (IS_DEBUG_OSPF_EVENT
)
1416 zlog_debug("ospf_abr_announce_aggregates(): Start");
1418 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1419 if (IS_DEBUG_OSPF_EVENT
)
1421 "ospf_abr_announce_aggregates(): looking at area %s",
1422 inet_ntoa(area
->area_id
));
1424 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1425 if ((range
= rn
->info
)) {
1426 if (!CHECK_FLAG(range
->flags
,
1427 OSPF_AREA_RANGE_ADVERTISE
)) {
1428 if (IS_DEBUG_OSPF_EVENT
)
1430 "ospf_abr_announce_aggregates():"
1431 " discarding suppress-ranges");
1436 p
.u
.prefix4
= range
->addr
;
1437 p
.prefixlen
= range
->masklen
;
1439 if (IS_DEBUG_OSPF_EVENT
)
1441 "ospf_abr_announce_aggregates():"
1442 " this is range: %s/%d",
1443 inet_ntoa(p
.u
.prefix4
),
1446 if (CHECK_FLAG(range
->flags
,
1447 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1449 p
.u
.prefix4
= range
->subst_addr
;
1450 p
.prefixlen
= range
->subst_masklen
;
1453 if (range
->specifics
) {
1454 if (IS_DEBUG_OSPF_EVENT
)
1456 "ospf_abr_announce_aggregates(): active range");
1458 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
,
1463 /* We do not check nexthops
1465 intra-area routes can be
1469 /* backbone routes are not
1471 when announced into transit
1474 if (ospf_area_is_transit(ar
)
1475 && OSPF_IS_AREA_BACKBONE(
1477 if (IS_DEBUG_OSPF_EVENT
)
1479 "ospf_abr_announce_aggregates(): Skipping "
1480 "announcement of BB aggregate into"
1484 ospf_abr_announce_network_to_area(
1493 if (IS_DEBUG_OSPF_EVENT
)
1494 zlog_debug("ospf_abr_announce_aggregates(): Stop");
1498 ospf_abr_send_nssa_aggregates(struct ospf
*ospf
) /* temporarily turned off */
1500 struct listnode
*node
; /*, n; */
1501 struct ospf_area
*area
; /*, *ar; */
1502 struct route_node
*rn
;
1503 struct ospf_area_range
*range
;
1504 struct prefix_ipv4 p
;
1506 if (IS_DEBUG_OSPF_NSSA
)
1507 zlog_debug("ospf_abr_send_nssa_aggregates(): Start");
1509 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1510 if (!area
->NSSATranslatorState
)
1513 if (IS_DEBUG_OSPF_NSSA
)
1515 "ospf_abr_send_nssa_aggregates(): looking at area %s",
1516 inet_ntoa(area
->area_id
));
1518 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
)) {
1519 if (rn
->info
== NULL
)
1524 if (!CHECK_FLAG(range
->flags
,
1525 OSPF_AREA_RANGE_ADVERTISE
)) {
1526 if (IS_DEBUG_OSPF_NSSA
)
1528 "ospf_abr_send_nssa_aggregates():"
1529 " discarding suppress-ranges");
1534 p
.prefix
= range
->addr
;
1535 p
.prefixlen
= range
->masklen
;
1537 if (IS_DEBUG_OSPF_NSSA
)
1539 "ospf_abr_send_nssa_aggregates():"
1540 " this is range: %s/%d",
1541 inet_ntoa(p
.prefix
), p
.prefixlen
);
1543 if (CHECK_FLAG(range
->flags
,
1544 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1546 p
.prefix
= range
->subst_addr
;
1547 p
.prefixlen
= range
->subst_masklen
;
1550 if (range
->specifics
) {
1551 if (IS_DEBUG_OSPF_NSSA
)
1553 "ospf_abr_send_nssa_aggregates(): active range");
1555 /* Fetch LSA-Type-7 from aggregate prefix, and
1557 * translate, Install (as Type-5), Approve, and
1560 ospf_abr_translate_nssa_range(&p
, range
->cost
);
1562 } /* all area ranges*/
1565 if (IS_DEBUG_OSPF_NSSA
)
1566 zlog_debug("ospf_abr_send_nssa_aggregates(): Stop");
1569 static void ospf_abr_announce_stub_defaults(struct ospf
*ospf
)
1571 struct listnode
*node
;
1572 struct ospf_area
*area
;
1573 struct prefix_ipv4 p
;
1575 if (!IS_OSPF_ABR(ospf
))
1578 if (IS_DEBUG_OSPF_EVENT
)
1579 zlog_debug("ospf_abr_announce_stub_defaults(): Start");
1582 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1585 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1586 if (IS_DEBUG_OSPF_EVENT
)
1588 "ospf_abr_announce_stub_defaults(): looking at area %s",
1589 inet_ntoa(area
->area_id
));
1591 if ((area
->external_routing
!= OSPF_AREA_STUB
)
1592 && (area
->external_routing
!= OSPF_AREA_NSSA
))
1595 if (OSPF_IS_AREA_BACKBONE(area
))
1596 continue; /* Sanity Check */
1598 if (IS_DEBUG_OSPF_EVENT
)
1600 "ospf_abr_announce_stub_defaults(): "
1601 "announcing 0.0.0.0/0 to area %s",
1602 inet_ntoa(area
->area_id
));
1603 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1606 if (IS_DEBUG_OSPF_EVENT
)
1607 zlog_debug("ospf_abr_announce_stub_defaults(): Stop");
1610 static int ospf_abr_remove_unapproved_translates_apply(struct ospf
*ospf
,
1611 struct ospf_lsa
*lsa
)
1613 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1614 && !CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
)) {
1616 "ospf_abr_remove_unapproved_translates(): "
1617 "removing unapproved translates, ID: %s",
1618 inet_ntoa(lsa
->data
->id
));
1620 /* FLUSH THROUGHOUT AS */
1621 ospf_lsa_flush_as(ospf
, lsa
);
1623 /* DISCARD from LSDB */
1628 static void ospf_abr_remove_unapproved_translates(struct ospf
*ospf
)
1630 struct route_node
*rn
;
1631 struct ospf_lsa
*lsa
;
1633 /* All AREA PROCESS should have APPROVED necessary LSAs */
1634 /* Remove any left over and not APPROVED */
1635 if (IS_DEBUG_OSPF_NSSA
)
1636 zlog_debug("ospf_abr_remove_unapproved_translates(): Start");
1638 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1639 ospf_abr_remove_unapproved_translates_apply(ospf
, lsa
);
1641 if (IS_DEBUG_OSPF_NSSA
)
1642 zlog_debug("ospf_abr_remove_unapproved_translates(): Stop");
1645 static void ospf_abr_remove_unapproved_summaries(struct ospf
*ospf
)
1647 struct listnode
*node
;
1648 struct ospf_area
*area
;
1649 struct route_node
*rn
;
1650 struct ospf_lsa
*lsa
;
1652 if (IS_DEBUG_OSPF_EVENT
)
1653 zlog_debug("ospf_abr_remove_unapproved_summaries(): Start");
1655 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1656 if (IS_DEBUG_OSPF_EVENT
)
1658 "ospf_abr_remove_unapproved_summaries(): "
1659 "looking at area %s",
1660 inet_ntoa(area
->area_id
));
1662 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1663 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1664 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1665 ospf_lsa_flush_area(lsa
, area
);
1667 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1668 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1669 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1670 ospf_lsa_flush_area(lsa
, area
);
1673 if (IS_DEBUG_OSPF_EVENT
)
1674 zlog_debug("ospf_abr_remove_unapproved_summaries(): Stop");
1677 static void ospf_abr_manage_discard_routes(struct ospf
*ospf
)
1679 struct listnode
*node
, *nnode
;
1680 struct route_node
*rn
;
1681 struct ospf_area
*area
;
1682 struct ospf_area_range
*range
;
1684 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
1685 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1686 if ((range
= rn
->info
) != NULL
)
1687 if (CHECK_FLAG(range
->flags
,
1688 OSPF_AREA_RANGE_ADVERTISE
)) {
1689 if (range
->specifics
)
1690 ospf_add_discard_route(
1691 ospf
, ospf
->new_table
,
1696 ospf_delete_discard_route(
1697 ospf
, ospf
->new_table
,
1703 /* This is the function taking care about ABR NSSA, i.e. NSSA
1704 Translator, -LSA aggregation and flooding. For all NSSAs
1706 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1707 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1710 Any received Type-5s are legal for an ABR, else illegal for IR.
1711 Received Type-7s are installed, by area, with incoming P-bit. They
1712 are flooded; if the Elected NSSA Translator, then P-bit off.
1714 Additionally, this ABR will place "translated type-7's" into the
1715 Type-5 LSDB in order to keep track of APPROVAL or not.
1717 It will scan through every area, looking for Type-7 LSAs with P-Bit
1718 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1719 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1722 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1723 left over are FLUSHED and DISCARDED.
1725 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1726 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1728 static void ospf_abr_nssa_task(struct ospf
*ospf
) /* called only if any_nssa */
1730 if (IS_DEBUG_OSPF_NSSA
)
1731 zlog_debug("Check for NSSA-ABR Tasks():");
1733 if (!IS_OSPF_ABR(ospf
))
1739 /* Each area must confirm TranslatorRole */
1740 if (IS_DEBUG_OSPF_NSSA
)
1741 zlog_debug("ospf_abr_nssa_task(): Start");
1743 /* For all Global Entries flagged "local-translate", unset APPROVED */
1744 if (IS_DEBUG_OSPF_NSSA
)
1745 zlog_debug("ospf_abr_nssa_task(): unapprove translates");
1747 ospf_abr_unapprove_translates(ospf
);
1749 /* RESET all Ranges in every Area, same as summaries */
1750 if (IS_DEBUG_OSPF_NSSA
)
1751 zlog_debug("ospf_abr_nssa_task(): NSSA initialize aggregates");
1752 ospf_abr_prepare_aggregates(ospf
); /*TURNED OFF just for now */
1754 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1755 * Aggregate as Type-7
1756 * Install or Approve in Type-5 Global LSDB
1758 if (IS_DEBUG_OSPF_NSSA
)
1759 zlog_debug("ospf_abr_nssa_task(): process translates");
1760 ospf_abr_process_nssa_translates(ospf
);
1762 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1764 * Scan Type-7's for aggregates, translate to Type-5's,
1765 * Install/Flood/Approve
1767 if (IS_DEBUG_OSPF_NSSA
)
1768 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1769 ospf_abr_send_nssa_aggregates(ospf
); /*TURNED OFF FOR NOW */
1771 /* Send any NSSA defaults as Type-5
1772 *if (IS_DEBUG_OSPF_NSSA)
1773 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1774 *ospf_abr_announce_nssa_defaults (ospf);
1775 * havnt a clue what above is supposed to do.
1778 /* Flush any unapproved previous translates from Global Data Base */
1779 if (IS_DEBUG_OSPF_NSSA
)
1781 "ospf_abr_nssa_task(): remove unapproved translates");
1782 ospf_abr_remove_unapproved_translates(ospf
);
1784 ospf_abr_manage_discard_routes(ospf
); /* same as normal...discard */
1786 if (IS_DEBUG_OSPF_NSSA
)
1787 zlog_debug("ospf_abr_nssa_task(): Stop");
1790 /* This is the function taking care about ABR stuff, i.e.
1791 summary-LSA origination and flooding. */
1792 void ospf_abr_task(struct ospf
*ospf
)
1794 if (IS_DEBUG_OSPF_EVENT
)
1795 zlog_debug("ospf_abr_task(): Start");
1797 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
) {
1798 if (IS_DEBUG_OSPF_EVENT
)
1800 "ospf_abr_task(): Routing tables are not yet ready");
1804 if (IS_DEBUG_OSPF_EVENT
)
1805 zlog_debug("ospf_abr_task(): unapprove summaries");
1806 ospf_abr_unapprove_summaries(ospf
);
1808 if (IS_DEBUG_OSPF_EVENT
)
1809 zlog_debug("ospf_abr_task(): prepare aggregates");
1810 ospf_abr_prepare_aggregates(ospf
);
1812 if (IS_OSPF_ABR(ospf
)) {
1813 if (IS_DEBUG_OSPF_EVENT
)
1814 zlog_debug("ospf_abr_task(): process network RT");
1815 ospf_abr_process_network_rt(ospf
, ospf
->new_table
);
1817 if (IS_DEBUG_OSPF_EVENT
)
1818 zlog_debug("ospf_abr_task(): process router RT");
1819 ospf_abr_process_router_rt(ospf
, ospf
->new_rtrs
);
1821 if (IS_DEBUG_OSPF_EVENT
)
1822 zlog_debug("ospf_abr_task(): announce aggregates");
1823 ospf_abr_announce_aggregates(ospf
);
1825 if (IS_DEBUG_OSPF_EVENT
)
1826 zlog_debug("ospf_abr_task(): announce stub defaults");
1827 ospf_abr_announce_stub_defaults(ospf
);
1830 if (IS_DEBUG_OSPF_EVENT
)
1831 zlog_debug("ospf_abr_task(): remove unapproved summaries");
1832 ospf_abr_remove_unapproved_summaries(ospf
);
1834 ospf_abr_manage_discard_routes(ospf
);
1836 if (IS_DEBUG_OSPF_EVENT
)
1837 zlog_debug("ospf_abr_task(): Stop");
1840 static int ospf_abr_task_timer(struct thread
*thread
)
1842 struct ospf
*ospf
= THREAD_ARG(thread
);
1844 ospf
->t_abr_task
= 0;
1846 if (IS_DEBUG_OSPF_EVENT
)
1847 zlog_debug("Running ABR task on timer");
1849 ospf_check_abr_status(ospf
);
1850 ospf_abr_nssa_check_status(ospf
);
1852 ospf_abr_task(ospf
);
1853 ospf_abr_nssa_task(ospf
); /* if nssa-abr, then scan Type-7 LSDB */
1858 void ospf_schedule_abr_task(struct ospf
*ospf
)
1860 if (IS_DEBUG_OSPF_EVENT
)
1861 zlog_debug("Scheduling ABR task");
1863 thread_add_timer(master
, ospf_abr_task_timer
, ospf
, OSPF_ABR_TASK_DELAY
,