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"
53 static struct ospf_area_range
*ospf_area_range_new(struct prefix_ipv4
*p
)
55 struct ospf_area_range
*range
;
57 range
= XCALLOC(MTYPE_OSPF_AREA_RANGE
, sizeof(struct ospf_area_range
));
58 range
->addr
= p
->prefix
;
59 range
->masklen
= p
->prefixlen
;
60 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
65 static void ospf_area_range_free(struct ospf_area_range
*range
)
67 XFREE(MTYPE_OSPF_AREA_RANGE
, range
);
70 static void ospf_area_range_add(struct ospf_area
*area
,
71 struct ospf_area_range
*range
)
73 struct route_node
*rn
;
77 p
.prefixlen
= range
->masklen
;
78 p
.prefix
= range
->addr
;
81 rn
= route_node_get(area
->ranges
, (struct prefix
*)&p
);
83 route_unlock_node(rn
);
88 static void ospf_area_range_delete(struct ospf_area
*area
,
89 struct route_node
*rn
)
91 struct ospf_area_range
*range
= rn
->info
;
93 if (range
->specifics
!= 0)
94 ospf_delete_discard_route(area
->ospf
, area
->ospf
->new_table
,
95 (struct prefix_ipv4
*)&rn
->p
);
97 ospf_area_range_free(range
);
99 route_unlock_node(rn
);
100 route_unlock_node(rn
);
103 struct ospf_area_range
*ospf_area_range_lookup(struct ospf_area
*area
,
104 struct prefix_ipv4
*p
)
106 struct route_node
*rn
;
108 rn
= route_node_lookup(area
->ranges
, (struct prefix
*)p
);
110 route_unlock_node(rn
);
116 struct ospf_area_range
*ospf_area_range_lookup_next(struct ospf_area
*area
,
117 struct in_addr
*range_net
,
120 struct route_node
*rn
;
121 struct prefix_ipv4 p
;
122 struct ospf_area_range
*find
;
125 p
.prefixlen
= IPV4_MAX_BITLEN
;
126 p
.prefix
= *range_net
;
130 rn
= route_top(area
->ranges
);
132 rn
= route_node_get(area
->ranges
, (struct prefix
*)&p
);
136 for (; rn
; rn
= route_next(rn
))
140 if (rn
&& rn
->info
) {
142 *range_net
= rn
->p
.u
.prefix4
;
143 route_unlock_node(rn
);
149 static struct ospf_area_range
*ospf_area_range_match(struct ospf_area
*area
,
150 struct prefix_ipv4
*p
)
152 struct route_node
*node
;
154 node
= route_node_match(area
->ranges
, (struct prefix
*)p
);
156 route_unlock_node(node
);
162 struct ospf_area_range
*ospf_area_range_match_any(struct ospf
*ospf
,
163 struct prefix_ipv4
*p
)
165 struct ospf_area_range
*range
;
166 struct ospf_area
*area
;
167 struct listnode
*node
;
169 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
170 if ((range
= ospf_area_range_match(area
, p
)))
176 int ospf_area_range_active(struct ospf_area_range
*range
)
178 return range
->specifics
;
181 static int ospf_area_actively_attached(struct ospf_area
*area
)
183 return area
->act_ints
;
186 int ospf_area_range_set(struct ospf
*ospf
, struct in_addr area_id
,
187 struct prefix_ipv4
*p
, int advertise
)
189 struct ospf_area
*area
;
190 struct ospf_area_range
*range
;
192 area
= ospf_area_get(ospf
, area_id
);
196 range
= ospf_area_range_lookup(area
, p
);
198 if ((CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
199 && !CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
200 || (!CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
201 && CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
)))
202 ospf_schedule_abr_task(ospf
);
204 range
= ospf_area_range_new(p
);
205 ospf_area_range_add(area
, range
);
206 ospf_schedule_abr_task(ospf
);
209 if (CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
210 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
212 UNSET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
217 int ospf_area_range_cost_set(struct ospf
*ospf
, struct in_addr area_id
,
218 struct prefix_ipv4
*p
, u_int32_t cost
)
220 struct ospf_area
*area
;
221 struct ospf_area_range
*range
;
223 area
= ospf_area_get(ospf
, area_id
);
227 range
= ospf_area_range_lookup(area
, p
);
231 if (range
->cost_config
!= cost
) {
232 range
->cost_config
= cost
;
233 if (ospf_area_range_active(range
))
234 ospf_schedule_abr_task(ospf
);
240 int ospf_area_range_unset(struct ospf
*ospf
, struct in_addr area_id
,
241 struct prefix_ipv4
*p
)
243 struct ospf_area
*area
;
244 struct route_node
*rn
;
246 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
250 rn
= route_node_lookup(area
->ranges
, (struct prefix
*)p
);
254 if (ospf_area_range_active(rn
->info
))
255 ospf_schedule_abr_task(ospf
);
257 ospf_area_range_delete(area
, rn
);
262 int ospf_area_range_substitute_set(struct ospf
*ospf
, struct in_addr area_id
,
263 struct prefix_ipv4
*p
, struct prefix_ipv4
*s
)
265 struct ospf_area
*area
;
266 struct ospf_area_range
*range
;
268 area
= ospf_area_get(ospf
, area_id
);
269 range
= ospf_area_range_lookup(area
, p
);
272 if (!CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
273 || !CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
274 ospf_schedule_abr_task(ospf
);
276 range
= ospf_area_range_new(p
);
277 ospf_area_range_add(area
, range
);
278 ospf_schedule_abr_task(ospf
);
281 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
282 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
283 range
->subst_addr
= s
->prefix
;
284 range
->subst_masklen
= s
->prefixlen
;
289 int ospf_area_range_substitute_unset(struct ospf
*ospf
, struct in_addr area_id
,
290 struct prefix_ipv4
*p
)
292 struct ospf_area
*area
;
293 struct ospf_area_range
*range
;
295 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
299 range
= ospf_area_range_lookup(area
, p
);
303 if (CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
304 if (ospf_area_range_active(range
))
305 ospf_schedule_abr_task(ospf
);
307 UNSET_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
308 range
->subst_addr
.s_addr
= 0;
309 range
->subst_masklen
= 0;
314 int ospf_act_bb_connection(struct ospf
*ospf
)
316 if (ospf
->backbone
== NULL
)
319 return ospf
->backbone
->full_nbrs
;
322 /* Determine whether this router is elected translator or not for area */
323 static int ospf_abr_nssa_am_elected(struct ospf_area
*area
)
325 struct route_node
*rn
;
326 struct ospf_lsa
*lsa
;
327 struct router_lsa
*rlsa
;
328 struct in_addr
*best
= NULL
;
330 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 u_char 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 u_char 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
, u_int32_t metric
)
591 struct summary_lsa
*header
;
593 metric
= htonl(metric
);
594 mp
= (u_char
*)&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
, u_int32_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
, u_int32_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 zlog_warn("%s: Could not refresh %s to %s",
748 inet_ntoa(area
->area_id
));
752 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
753 /* This will flood through area. */
756 if (IS_DEBUG_OSPF_EVENT
)
758 "ospf_abr_announce_network_to_area(): "
759 "creating new summary");
760 lsa
= ospf_summary_lsa_originate((struct prefix_ipv4
*)p
,
762 /* This will flood through area. */
765 char buf
[PREFIX2STR_BUFFER
];
767 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
768 zlog_warn("%s: Could not originate %s to %s", __func__
,
769 buf
, inet_ntoa(area
->area_id
));
773 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
774 if (IS_DEBUG_OSPF_EVENT
)
776 "ospf_abr_announce_network_to_area(): "
777 "flooding new version of summary");
780 if (IS_DEBUG_OSPF_EVENT
)
781 zlog_debug("ospf_abr_announce_network_to_area(): Stop");
784 static int ospf_abr_nexthops_belong_to_area(struct ospf_route
* or,
785 struct ospf_area
*area
)
787 struct listnode
*node
, *nnode
;
788 struct ospf_path
*path
;
789 struct ospf_interface
*oi
;
791 for (ALL_LIST_ELEMENTS_RO(or->paths
, node
, path
))
792 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, nnode
, oi
))
793 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
799 static int ospf_abr_should_accept(struct prefix_ipv4
*p
, struct ospf_area
*area
)
801 if (IMPORT_NAME(area
)) {
802 if (IMPORT_LIST(area
) == NULL
)
804 access_list_lookup(AFI_IP
, IMPORT_NAME(area
));
806 if (IMPORT_LIST(area
))
807 if (access_list_apply(IMPORT_LIST(area
), p
)
815 static int ospf_abr_plist_in_check(struct ospf_area
*area
,
816 struct ospf_route
* or,
817 struct prefix_ipv4
*p
)
819 if (PREFIX_NAME_IN(area
)) {
820 if (PREFIX_LIST_IN(area
) == NULL
)
821 PREFIX_LIST_IN(area
) = prefix_list_lookup(
822 AFI_IP
, PREFIX_NAME_IN(area
));
823 if (PREFIX_LIST_IN(area
))
824 if (prefix_list_apply(PREFIX_LIST_IN(area
), p
)
831 static int ospf_abr_plist_out_check(struct ospf_area
*area
,
832 struct ospf_route
* or,
833 struct prefix_ipv4
*p
)
835 if (PREFIX_NAME_OUT(area
)) {
836 if (PREFIX_LIST_OUT(area
) == NULL
)
837 PREFIX_LIST_OUT(area
) = prefix_list_lookup(
838 AFI_IP
, PREFIX_NAME_OUT(area
));
839 if (PREFIX_LIST_OUT(area
))
840 if (prefix_list_apply(PREFIX_LIST_OUT(area
), p
)
847 static void ospf_abr_announce_network(struct ospf
*ospf
, struct prefix_ipv4
*p
,
848 struct ospf_route
* or)
850 struct ospf_area_range
*range
;
851 struct ospf_area
*area
, *or_area
;
852 struct listnode
*node
;
854 if (IS_DEBUG_OSPF_EVENT
)
855 zlog_debug("ospf_abr_announce_network(): Start");
857 or_area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
860 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
861 if (IS_DEBUG_OSPF_EVENT
)
863 "ospf_abr_announce_network(): looking at area %s",
864 inet_ntoa(area
->area_id
));
866 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
869 if (ospf_abr_nexthops_belong_to_area(or, area
))
872 if (!ospf_abr_should_accept(p
, area
)) {
873 if (IS_DEBUG_OSPF_EVENT
)
875 "ospf_abr_announce_network(): "
876 "prefix %s/%d was denied by import-list",
877 inet_ntoa(p
->prefix
), p
->prefixlen
);
881 if (!ospf_abr_plist_in_check(area
, or, p
)) {
882 if (IS_DEBUG_OSPF_EVENT
)
884 "ospf_abr_announce_network(): "
885 "prefix %s/%d was denied by prefix-list",
886 inet_ntoa(p
->prefix
), p
->prefixlen
);
890 if (area
->external_routing
!= OSPF_AREA_DEFAULT
891 && area
->no_summary
) {
892 if (IS_DEBUG_OSPF_EVENT
)
894 "ospf_abr_announce_network(): "
895 "area %s is stub and no_summary",
896 inet_ntoa(area
->area_id
));
900 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
901 if (IS_DEBUG_OSPF_EVENT
)
903 "ospf_abr_announce_network(): this is "
904 "inter-area route to %s/%d",
905 inet_ntoa(p
->prefix
), p
->prefixlen
);
907 if (!OSPF_IS_AREA_BACKBONE(area
))
908 ospf_abr_announce_network_to_area(p
, or->cost
,
912 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
913 if (IS_DEBUG_OSPF_EVENT
)
915 "ospf_abr_announce_network(): "
916 "this is intra-area route to %s/%d",
917 inet_ntoa(p
->prefix
), p
->prefixlen
);
918 if ((range
= ospf_area_range_match(or_area
, p
))
919 && !ospf_area_is_transit(area
))
920 ospf_abr_update_aggregate(range
, or, area
);
922 ospf_abr_announce_network_to_area(p
, or->cost
,
928 static int ospf_abr_should_announce(struct ospf
*ospf
, struct prefix_ipv4
*p
,
929 struct ospf_route
* or)
931 struct ospf_area
*area
;
933 area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
937 if (EXPORT_NAME(area
)) {
938 if (EXPORT_LIST(area
) == NULL
)
940 access_list_lookup(AFI_IP
, EXPORT_NAME(area
));
942 if (EXPORT_LIST(area
))
943 if (access_list_apply(EXPORT_LIST(area
), p
)
951 static void ospf_abr_process_nssa_translates(struct ospf
*ospf
)
953 /* Scan through all NSSA_LSDB records for all areas;
955 If P-bit is on, translate all Type-7's to 5's and aggregate or
956 flood install as approved in Type-5 LSDB with XLATE Flag on
957 later, do same for all aggregates... At end, DISCARD all
958 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
959 struct listnode
*node
;
960 struct ospf_area
*area
;
961 struct route_node
*rn
;
962 struct ospf_lsa
*lsa
;
964 if (IS_DEBUG_OSPF_NSSA
)
965 zlog_debug("ospf_abr_process_nssa_translates(): Start");
967 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
968 if (!area
->NSSATranslatorState
)
969 continue; /* skip if not translator */
971 if (area
->external_routing
!= OSPF_AREA_NSSA
)
972 continue; /* skip if not Nssa Area */
974 if (IS_DEBUG_OSPF_NSSA
)
976 "ospf_abr_process_nssa_translates(): "
977 "looking at area %s",
978 inet_ntoa(area
->area_id
));
980 LSDB_LOOP(NSSA_LSDB(area
), rn
, lsa
)
981 ospf_abr_translate_nssa(area
, lsa
);
984 if (IS_DEBUG_OSPF_NSSA
)
985 zlog_debug("ospf_abr_process_nssa_translates(): Stop");
988 static void ospf_abr_process_network_rt(struct ospf
*ospf
,
989 struct route_table
*rt
)
991 struct ospf_area
*area
;
992 struct ospf_route
* or ;
993 struct route_node
*rn
;
995 if (IS_DEBUG_OSPF_EVENT
)
996 zlog_debug("ospf_abr_process_network_rt(): Start");
998 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
999 if ((or = rn
->info
) == NULL
)
1002 if (!(area
= ospf_area_lookup_by_area_id(ospf
,
1003 or->u
.std
.area_id
))) {
1004 if (IS_DEBUG_OSPF_EVENT
)
1006 "ospf_abr_process_network_rt(): area %s no longer exists",
1007 inet_ntoa(or->u
.std
.area_id
));
1011 if (IS_DEBUG_OSPF_EVENT
)
1013 "ospf_abr_process_network_rt(): this is a route to %s/%d",
1014 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
1015 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
) {
1016 if (IS_DEBUG_OSPF_EVENT
)
1018 "ospf_abr_process_network_rt(): "
1019 "this is an External router, skipping");
1023 if (or->cost
>= OSPF_LS_INFINITY
) {
1024 if (IS_DEBUG_OSPF_EVENT
)
1026 "ospf_abr_process_network_rt():"
1027 " this route's cost is infinity, skipping");
1031 if (or->type
== OSPF_DESTINATION_DISCARD
) {
1032 if (IS_DEBUG_OSPF_EVENT
)
1034 "ospf_abr_process_network_rt():"
1035 " this is a discard entry, skipping");
1040 or->path_type
== OSPF_PATH_INTRA_AREA
1041 && !ospf_abr_should_announce(
1042 ospf
, (struct prefix_ipv4
*)&rn
->p
,
1044 if (IS_DEBUG_OSPF_EVENT
)
1046 "ospf_abr_process_network_rt(): denied by export-list");
1051 or->path_type
== OSPF_PATH_INTRA_AREA
1052 && !ospf_abr_plist_out_check(
1054 (struct prefix_ipv4
*)&rn
->p
)) {
1055 if (IS_DEBUG_OSPF_EVENT
)
1057 "ospf_abr_process_network_rt(): denied by prefix-list");
1061 if ((or->path_type
== OSPF_PATH_INTER_AREA
)
1062 && !OSPF_IS_AREA_ID_BACKBONE(or->u
.std
.area_id
)) {
1063 if (IS_DEBUG_OSPF_EVENT
)
1065 "ospf_abr_process_network_rt():"
1066 " this is route is not backbone one, skipping");
1071 if ((ospf
->abr_type
== OSPF_ABR_CISCO
)
1072 || (ospf
->abr_type
== OSPF_ABR_IBM
))
1074 if (!ospf_act_bb_connection(ospf
) &&
1075 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1076 if (IS_DEBUG_OSPF_EVENT
)
1078 "ospf_abr_process_network_rt(): ALT ABR: "
1079 "No BB connection, skip not intra-area routes");
1083 if (IS_DEBUG_OSPF_EVENT
)
1084 zlog_debug("ospf_abr_process_network_rt(): announcing");
1085 ospf_abr_announce_network(ospf
, (struct prefix_ipv4
*)&rn
->p
,
1089 if (IS_DEBUG_OSPF_EVENT
)
1090 zlog_debug("ospf_abr_process_network_rt(): Stop");
1093 static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4
*p
, u_int32_t cost
,
1094 struct ospf_area
*area
)
1096 struct ospf_lsa
*lsa
, *old
= NULL
;
1097 struct summary_lsa
*slsa
= NULL
;
1099 if (IS_DEBUG_OSPF_EVENT
)
1100 zlog_debug("ospf_abr_announce_rtr_to_area(): Start");
1102 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
,
1103 area
->ospf
->router_id
);
1105 if (IS_DEBUG_OSPF_EVENT
)
1107 "ospf_abr_announce_rtr_to_area(): old summary found");
1108 slsa
= (struct summary_lsa
*)old
->data
;
1110 if (IS_DEBUG_OSPF_EVENT
)
1112 "ospf_abr_announce_network_to_area(): "
1113 "old metric: %d, new metric: %d",
1114 GET_METRIC(slsa
->metric
), cost
);
1117 if (old
&& (GET_METRIC(slsa
->metric
) == cost
)
1118 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
1119 if (IS_DEBUG_OSPF_EVENT
)
1121 "ospf_abr_announce_rtr_to_area(): old summary approved");
1122 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
1124 if (IS_DEBUG_OSPF_EVENT
)
1125 zlog_debug("ospf_abr_announce_rtr_to_area(): 2.2");
1128 set_metric(old
, cost
);
1129 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
1131 lsa
= ospf_summary_asbr_lsa_originate(p
, cost
, area
);
1133 char buf
[PREFIX2STR_BUFFER
];
1135 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
1136 zlog_warn("%s: Could not refresh/originate %s to %s",
1137 __func__
, buf
, inet_ntoa(area
->area_id
));
1141 if (IS_DEBUG_OSPF_EVENT
)
1143 "ospf_abr_announce_rtr_to_area(): "
1144 "flooding new version of summary");
1147 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new
1149 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1151 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1152 /* ospf_flood_through_area (area, NULL, lsa);*/
1155 if (IS_DEBUG_OSPF_EVENT
)
1156 zlog_debug("ospf_abr_announce_rtr_to_area(): Stop");
1160 static void ospf_abr_announce_rtr(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1161 struct ospf_route
* or)
1163 struct listnode
*node
;
1164 struct ospf_area
*area
;
1166 if (IS_DEBUG_OSPF_EVENT
)
1167 zlog_debug("ospf_abr_announce_rtr(): Start");
1169 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1170 if (IS_DEBUG_OSPF_EVENT
)
1172 "ospf_abr_announce_rtr(): looking at area %s",
1173 inet_ntoa(area
->area_id
));
1175 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
1178 if (ospf_abr_nexthops_belong_to_area(or, area
))
1181 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
1182 if (IS_DEBUG_OSPF_EVENT
)
1184 "ospf_abr_announce_rtr(): "
1185 "area %s doesn't support external routing",
1186 inet_ntoa(area
->area_id
));
1190 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
1191 if (IS_DEBUG_OSPF_EVENT
)
1193 "ospf_abr_announce_rtr(): "
1194 "this is inter-area route to %s",
1195 inet_ntoa(p
->prefix
));
1196 if (!OSPF_IS_AREA_BACKBONE(area
))
1197 ospf_abr_announce_rtr_to_area(p
, or->cost
,
1201 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
1202 if (IS_DEBUG_OSPF_EVENT
)
1204 "ospf_abr_announce_rtr(): "
1205 "this is intra-area route to %s",
1206 inet_ntoa(p
->prefix
));
1207 ospf_abr_announce_rtr_to_area(p
, or->cost
, area
);
1211 if (IS_DEBUG_OSPF_EVENT
)
1212 zlog_debug("ospf_abr_announce_rtr(): Stop");
1215 static void ospf_abr_process_router_rt(struct ospf
*ospf
,
1216 struct route_table
*rt
)
1218 struct ospf_route
* or ;
1219 struct route_node
*rn
;
1222 if (IS_DEBUG_OSPF_EVENT
)
1223 zlog_debug("ospf_abr_process_router_rt(): Start");
1225 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1226 struct listnode
*node
, *nnode
;
1228 struct ospf_route
*best
= NULL
;
1230 if (rn
->info
== NULL
)
1235 if (IS_DEBUG_OSPF_EVENT
)
1237 "ospf_abr_process_router_rt(): this is a route to %s",
1238 inet_ntoa(rn
->p
.u
.prefix4
));
1240 for (ALL_LIST_ELEMENTS(l
, node
, nnode
, or)) {
1241 if (!ospf_area_lookup_by_area_id(ospf
,
1242 or->u
.std
.area_id
)) {
1243 if (IS_DEBUG_OSPF_EVENT
)
1245 "ospf_abr_process_router_rt(): area %s no longer exists",
1246 inet_ntoa(or->u
.std
.area_id
));
1251 if (!CHECK_FLAG(or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
)) {
1252 if (IS_DEBUG_OSPF_EVENT
)
1254 "ospf_abr_process_router_rt(): "
1255 "This is not an ASBR, skipping");
1260 best
= ospf_find_asbr_route(
1261 ospf
, rt
, (struct prefix_ipv4
*)&rn
->p
);
1269 if (IS_DEBUG_OSPF_EVENT
)
1271 "ospf_abr_process_router_rt(): "
1272 "This route is not the best among possible, skipping");
1277 or->path_type
== OSPF_PATH_INTER_AREA
1278 && !OSPF_IS_AREA_ID_BACKBONE(
1279 or->u
.std
.area_id
)) {
1280 if (IS_DEBUG_OSPF_EVENT
)
1282 "ospf_abr_process_router_rt(): "
1283 "This route is not a backbone one, skipping");
1287 if (or->cost
>= OSPF_LS_INFINITY
) {
1288 if (IS_DEBUG_OSPF_EVENT
)
1290 "ospf_abr_process_router_rt(): "
1291 "This route has LS_INFINITY metric, skipping");
1295 if (ospf
->abr_type
== OSPF_ABR_CISCO
1296 || ospf
->abr_type
== OSPF_ABR_IBM
)
1297 if (!ospf_act_bb_connection(ospf
) &&
1298 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1299 if (IS_DEBUG_OSPF_EVENT
)
1301 "ospf_abr_process_network_rt(): ALT ABR: "
1302 "No BB connection, skip not intra-area routes");
1306 ospf_abr_announce_rtr(ospf
,
1307 (struct prefix_ipv4
*)&rn
->p
, or);
1311 if (IS_DEBUG_OSPF_EVENT
)
1312 zlog_debug("ospf_abr_process_router_rt(): Stop");
1316 ospf_abr_unapprove_translates(struct ospf
*ospf
) /* For NSSA Translations */
1318 struct ospf_lsa
*lsa
;
1319 struct route_node
*rn
;
1321 if (IS_DEBUG_OSPF_NSSA
)
1322 zlog_debug("ospf_abr_unapprove_translates(): Start");
1324 /* NSSA Translator is not checked, because it may have gone away,
1325 and we would want to flush any residuals anyway */
1327 LSDB_LOOP(EXTERNAL_LSDB(ospf
), rn
, lsa
)
1328 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) {
1329 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1330 if (IS_DEBUG_OSPF_NSSA
)
1332 "ospf_abr_unapprove_translates(): "
1333 "approved unset on link id %s",
1334 inet_ntoa(lsa
->data
->id
));
1337 if (IS_DEBUG_OSPF_NSSA
)
1338 zlog_debug("ospf_abr_unapprove_translates(): Stop");
1341 static void ospf_abr_unapprove_summaries(struct ospf
*ospf
)
1343 struct listnode
*node
;
1344 struct ospf_area
*area
;
1345 struct route_node
*rn
;
1346 struct ospf_lsa
*lsa
;
1348 if (IS_DEBUG_OSPF_EVENT
)
1349 zlog_debug("ospf_abr_unapprove_summaries(): Start");
1351 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1352 if (IS_DEBUG_OSPF_EVENT
)
1354 "ospf_abr_unapprove_summaries(): "
1355 "considering area %s",
1356 inet_ntoa(area
->area_id
));
1357 LSDB_LOOP(SUMMARY_LSDB(area
), rn
, lsa
)
1358 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1359 if (IS_DEBUG_OSPF_EVENT
)
1361 "ospf_abr_unapprove_summaries(): "
1362 "approved unset on summary link id %s",
1363 inet_ntoa(lsa
->data
->id
));
1364 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1367 LSDB_LOOP(ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1368 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1369 if (IS_DEBUG_OSPF_EVENT
)
1371 "ospf_abr_unapprove_summaries(): "
1372 "approved unset on asbr-summary link id %s",
1373 inet_ntoa(lsa
->data
->id
));
1374 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1378 if (IS_DEBUG_OSPF_EVENT
)
1379 zlog_debug("ospf_abr_unapprove_summaries(): Stop");
1382 static void ospf_abr_prepare_aggregates(struct ospf
*ospf
)
1384 struct listnode
*node
;
1385 struct route_node
*rn
;
1386 struct ospf_area_range
*range
;
1387 struct ospf_area
*area
;
1389 if (IS_DEBUG_OSPF_EVENT
)
1390 zlog_debug("ospf_abr_prepare_aggregates(): Start");
1392 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1393 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1394 if ((range
= rn
->info
) != NULL
) {
1396 range
->specifics
= 0;
1400 if (IS_DEBUG_OSPF_EVENT
)
1401 zlog_debug("ospf_abr_prepare_aggregates(): Stop");
1404 static void ospf_abr_announce_aggregates(struct ospf
*ospf
)
1406 struct ospf_area
*area
, *ar
;
1407 struct ospf_area_range
*range
;
1408 struct route_node
*rn
;
1410 struct listnode
*node
, *n
;
1412 if (IS_DEBUG_OSPF_EVENT
)
1413 zlog_debug("ospf_abr_announce_aggregates(): Start");
1415 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1416 if (IS_DEBUG_OSPF_EVENT
)
1418 "ospf_abr_announce_aggregates(): looking at area %s",
1419 inet_ntoa(area
->area_id
));
1421 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1422 if ((range
= rn
->info
)) {
1423 if (!CHECK_FLAG(range
->flags
,
1424 OSPF_AREA_RANGE_ADVERTISE
)) {
1425 if (IS_DEBUG_OSPF_EVENT
)
1427 "ospf_abr_announce_aggregates():"
1428 " discarding suppress-ranges");
1433 p
.u
.prefix4
= range
->addr
;
1434 p
.prefixlen
= range
->masklen
;
1436 if (IS_DEBUG_OSPF_EVENT
)
1438 "ospf_abr_announce_aggregates():"
1439 " this is range: %s/%d",
1440 inet_ntoa(p
.u
.prefix4
),
1443 if (CHECK_FLAG(range
->flags
,
1444 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1446 p
.u
.prefix4
= range
->subst_addr
;
1447 p
.prefixlen
= range
->subst_masklen
;
1450 if (range
->specifics
) {
1451 if (IS_DEBUG_OSPF_EVENT
)
1453 "ospf_abr_announce_aggregates(): active range");
1455 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
,
1460 /* We do not check nexthops
1462 intra-area routes can be
1466 /* backbone routes are not
1468 when announced into transit
1471 if (ospf_area_is_transit(ar
)
1472 && OSPF_IS_AREA_BACKBONE(
1474 if (IS_DEBUG_OSPF_EVENT
)
1476 "ospf_abr_announce_aggregates(): Skipping "
1477 "announcement of BB aggregate into"
1481 ospf_abr_announce_network_to_area(
1490 if (IS_DEBUG_OSPF_EVENT
)
1491 zlog_debug("ospf_abr_announce_aggregates(): Stop");
1495 ospf_abr_send_nssa_aggregates(struct ospf
*ospf
) /* temporarily turned off */
1497 struct listnode
*node
; /*, n; */
1498 struct ospf_area
*area
; /*, *ar; */
1499 struct route_node
*rn
;
1500 struct ospf_area_range
*range
;
1501 struct prefix_ipv4 p
;
1503 if (IS_DEBUG_OSPF_NSSA
)
1504 zlog_debug("ospf_abr_send_nssa_aggregates(): Start");
1506 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1507 if (!area
->NSSATranslatorState
)
1510 if (IS_DEBUG_OSPF_NSSA
)
1512 "ospf_abr_send_nssa_aggregates(): looking at area %s",
1513 inet_ntoa(area
->area_id
));
1515 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
)) {
1516 if (rn
->info
== NULL
)
1521 if (!CHECK_FLAG(range
->flags
,
1522 OSPF_AREA_RANGE_ADVERTISE
)) {
1523 if (IS_DEBUG_OSPF_NSSA
)
1525 "ospf_abr_send_nssa_aggregates():"
1526 " discarding suppress-ranges");
1531 p
.prefix
= range
->addr
;
1532 p
.prefixlen
= range
->masklen
;
1534 if (IS_DEBUG_OSPF_NSSA
)
1536 "ospf_abr_send_nssa_aggregates():"
1537 " this is range: %s/%d",
1538 inet_ntoa(p
.prefix
), p
.prefixlen
);
1540 if (CHECK_FLAG(range
->flags
,
1541 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1543 p
.prefix
= range
->subst_addr
;
1544 p
.prefixlen
= range
->subst_masklen
;
1547 if (range
->specifics
) {
1548 if (IS_DEBUG_OSPF_NSSA
)
1550 "ospf_abr_send_nssa_aggregates(): active range");
1552 /* Fetch LSA-Type-7 from aggregate prefix, and
1554 * translate, Install (as Type-5), Approve, and
1557 ospf_abr_translate_nssa_range(&p
, range
->cost
);
1559 } /* all area ranges*/
1562 if (IS_DEBUG_OSPF_NSSA
)
1563 zlog_debug("ospf_abr_send_nssa_aggregates(): Stop");
1566 static void ospf_abr_announce_stub_defaults(struct ospf
*ospf
)
1568 struct listnode
*node
;
1569 struct ospf_area
*area
;
1570 struct prefix_ipv4 p
;
1572 if (!IS_OSPF_ABR(ospf
))
1575 if (IS_DEBUG_OSPF_EVENT
)
1576 zlog_debug("ospf_abr_announce_stub_defaults(): Start");
1579 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1582 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1583 if (IS_DEBUG_OSPF_EVENT
)
1585 "ospf_abr_announce_stub_defaults(): looking at area %s",
1586 inet_ntoa(area
->area_id
));
1588 if ((area
->external_routing
!= OSPF_AREA_STUB
)
1589 && (area
->external_routing
!= OSPF_AREA_NSSA
))
1592 if (OSPF_IS_AREA_BACKBONE(area
))
1593 continue; /* Sanity Check */
1595 if (IS_DEBUG_OSPF_EVENT
)
1597 "ospf_abr_announce_stub_defaults(): "
1598 "announcing 0.0.0.0/0 to area %s",
1599 inet_ntoa(area
->area_id
));
1600 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1603 if (IS_DEBUG_OSPF_EVENT
)
1604 zlog_debug("ospf_abr_announce_stub_defaults(): Stop");
1607 static int ospf_abr_remove_unapproved_translates_apply(struct ospf
*ospf
,
1608 struct ospf_lsa
*lsa
)
1610 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1611 && !CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
)) {
1613 "ospf_abr_remove_unapproved_translates(): "
1614 "removing unapproved translates, ID: %s",
1615 inet_ntoa(lsa
->data
->id
));
1617 /* FLUSH THROUGHOUT AS */
1618 ospf_lsa_flush_as(ospf
, lsa
);
1620 /* DISCARD from LSDB */
1625 static void ospf_abr_remove_unapproved_translates(struct ospf
*ospf
)
1627 struct route_node
*rn
;
1628 struct ospf_lsa
*lsa
;
1630 /* All AREA PROCESS should have APPROVED necessary LSAs */
1631 /* Remove any left over and not APPROVED */
1632 if (IS_DEBUG_OSPF_NSSA
)
1633 zlog_debug("ospf_abr_remove_unapproved_translates(): Start");
1635 LSDB_LOOP(EXTERNAL_LSDB(ospf
), rn
, lsa
)
1636 ospf_abr_remove_unapproved_translates_apply(ospf
, lsa
);
1638 if (IS_DEBUG_OSPF_NSSA
)
1639 zlog_debug("ospf_abr_remove_unapproved_translates(): Stop");
1642 static void ospf_abr_remove_unapproved_summaries(struct ospf
*ospf
)
1644 struct listnode
*node
;
1645 struct ospf_area
*area
;
1646 struct route_node
*rn
;
1647 struct ospf_lsa
*lsa
;
1649 if (IS_DEBUG_OSPF_EVENT
)
1650 zlog_debug("ospf_abr_remove_unapproved_summaries(): Start");
1652 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1653 if (IS_DEBUG_OSPF_EVENT
)
1655 "ospf_abr_remove_unapproved_summaries(): "
1656 "looking at area %s",
1657 inet_ntoa(area
->area_id
));
1659 LSDB_LOOP(SUMMARY_LSDB(area
), rn
, lsa
)
1660 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1661 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1662 ospf_lsa_flush_area(lsa
, area
);
1664 LSDB_LOOP(ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1665 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1666 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1667 ospf_lsa_flush_area(lsa
, area
);
1670 if (IS_DEBUG_OSPF_EVENT
)
1671 zlog_debug("ospf_abr_remove_unapproved_summaries(): Stop");
1674 static void ospf_abr_manage_discard_routes(struct ospf
*ospf
)
1676 struct listnode
*node
, *nnode
;
1677 struct route_node
*rn
;
1678 struct ospf_area
*area
;
1679 struct ospf_area_range
*range
;
1681 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
1682 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1683 if ((range
= rn
->info
) != NULL
)
1684 if (CHECK_FLAG(range
->flags
,
1685 OSPF_AREA_RANGE_ADVERTISE
)) {
1686 if (range
->specifics
)
1687 ospf_add_discard_route(ospf
,
1688 ospf
->new_table
, area
,
1692 ospf_delete_discard_route(ospf
,
1699 /* This is the function taking care about ABR NSSA, i.e. NSSA
1700 Translator, -LSA aggregation and flooding. For all NSSAs
1702 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1703 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1706 Any received Type-5s are legal for an ABR, else illegal for IR.
1707 Received Type-7s are installed, by area, with incoming P-bit. They
1708 are flooded; if the Elected NSSA Translator, then P-bit off.
1710 Additionally, this ABR will place "translated type-7's" into the
1711 Type-5 LSDB in order to keep track of APPROVAL or not.
1713 It will scan through every area, looking for Type-7 LSAs with P-Bit
1714 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1715 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1718 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1719 left over are FLUSHED and DISCARDED.
1721 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1722 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1724 static void ospf_abr_nssa_task(struct ospf
*ospf
) /* called only if any_nssa */
1726 if (IS_DEBUG_OSPF_NSSA
)
1727 zlog_debug("Check for NSSA-ABR Tasks():");
1729 if (!IS_OSPF_ABR(ospf
))
1735 /* Each area must confirm TranslatorRole */
1736 if (IS_DEBUG_OSPF_NSSA
)
1737 zlog_debug("ospf_abr_nssa_task(): Start");
1739 /* For all Global Entries flagged "local-translate", unset APPROVED */
1740 if (IS_DEBUG_OSPF_NSSA
)
1741 zlog_debug("ospf_abr_nssa_task(): unapprove translates");
1743 ospf_abr_unapprove_translates(ospf
);
1745 /* RESET all Ranges in every Area, same as summaries */
1746 if (IS_DEBUG_OSPF_NSSA
)
1747 zlog_debug("ospf_abr_nssa_task(): NSSA initialize aggregates");
1748 ospf_abr_prepare_aggregates(ospf
); /*TURNED OFF just for now */
1750 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1751 * Aggregate as Type-7
1752 * Install or Approve in Type-5 Global LSDB
1754 if (IS_DEBUG_OSPF_NSSA
)
1755 zlog_debug("ospf_abr_nssa_task(): process translates");
1756 ospf_abr_process_nssa_translates(ospf
);
1758 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1760 * Scan Type-7's for aggregates, translate to Type-5's,
1761 * Install/Flood/Approve
1763 if (IS_DEBUG_OSPF_NSSA
)
1764 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1765 ospf_abr_send_nssa_aggregates(ospf
); /*TURNED OFF FOR NOW */
1767 /* Send any NSSA defaults as Type-5
1768 *if (IS_DEBUG_OSPF_NSSA)
1769 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1770 *ospf_abr_announce_nssa_defaults (ospf);
1771 * havnt a clue what above is supposed to do.
1774 /* Flush any unapproved previous translates from Global Data Base */
1775 if (IS_DEBUG_OSPF_NSSA
)
1777 "ospf_abr_nssa_task(): remove unapproved translates");
1778 ospf_abr_remove_unapproved_translates(ospf
);
1780 ospf_abr_manage_discard_routes(ospf
); /* same as normal...discard */
1782 if (IS_DEBUG_OSPF_NSSA
)
1783 zlog_debug("ospf_abr_nssa_task(): Stop");
1786 /* This is the function taking care about ABR stuff, i.e.
1787 summary-LSA origination and flooding. */
1788 void ospf_abr_task(struct ospf
*ospf
)
1790 if (IS_DEBUG_OSPF_EVENT
)
1791 zlog_debug("ospf_abr_task(): Start");
1793 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
) {
1794 if (IS_DEBUG_OSPF_EVENT
)
1796 "ospf_abr_task(): Routing tables are not yet ready");
1800 if (IS_DEBUG_OSPF_EVENT
)
1801 zlog_debug("ospf_abr_task(): unapprove summaries");
1802 ospf_abr_unapprove_summaries(ospf
);
1804 if (IS_DEBUG_OSPF_EVENT
)
1805 zlog_debug("ospf_abr_task(): prepare aggregates");
1806 ospf_abr_prepare_aggregates(ospf
);
1808 if (IS_OSPF_ABR(ospf
)) {
1809 if (IS_DEBUG_OSPF_EVENT
)
1810 zlog_debug("ospf_abr_task(): process network RT");
1811 ospf_abr_process_network_rt(ospf
, ospf
->new_table
);
1813 if (IS_DEBUG_OSPF_EVENT
)
1814 zlog_debug("ospf_abr_task(): process router RT");
1815 ospf_abr_process_router_rt(ospf
, ospf
->new_rtrs
);
1817 if (IS_DEBUG_OSPF_EVENT
)
1818 zlog_debug("ospf_abr_task(): announce aggregates");
1819 ospf_abr_announce_aggregates(ospf
);
1821 if (IS_DEBUG_OSPF_EVENT
)
1822 zlog_debug("ospf_abr_task(): announce stub defaults");
1823 ospf_abr_announce_stub_defaults(ospf
);
1826 if (IS_DEBUG_OSPF_EVENT
)
1827 zlog_debug("ospf_abr_task(): remove unapproved summaries");
1828 ospf_abr_remove_unapproved_summaries(ospf
);
1830 ospf_abr_manage_discard_routes(ospf
);
1832 if (IS_DEBUG_OSPF_EVENT
)
1833 zlog_debug("ospf_abr_task(): Stop");
1836 static int ospf_abr_task_timer(struct thread
*thread
)
1838 struct ospf
*ospf
= THREAD_ARG(thread
);
1840 ospf
->t_abr_task
= 0;
1842 if (IS_DEBUG_OSPF_EVENT
)
1843 zlog_debug("Running ABR task on timer");
1845 ospf_check_abr_status(ospf
);
1846 ospf_abr_nssa_check_status(ospf
);
1848 ospf_abr_task(ospf
);
1849 ospf_abr_nssa_task(ospf
); /* if nssa-abr, then scan Type-7 LSDB */
1854 void ospf_schedule_abr_task(struct ospf
*ospf
)
1856 if (IS_DEBUG_OSPF_EVENT
)
1857 zlog_debug("Scheduling ABR task");
1859 thread_add_timer(master
, ospf_abr_task_timer
, ospf
, OSPF_ABR_TASK_DELAY
,