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
, uint32_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
) {
332 if (!lsa
|| (lsa
->data
->type
!= OSPF_ROUTER_LSA
)
336 rlsa
= (struct router_lsa
*)lsa
->data
;
338 /* ignore non-ABR routers */
339 if (!IS_ROUTER_LSA_BORDER(rlsa
))
342 /* Router has Nt flag - always translate */
343 if (IS_ROUTER_LSA_NT(rlsa
)) {
344 if (IS_DEBUG_OSPF_NSSA
)
346 "ospf_abr_nssa_am_elected: "
347 "router %s asserts Nt",
348 inet_ntoa(lsa
->data
->id
));
353 best
= &lsa
->data
->id
;
354 else if (IPV4_ADDR_CMP(&best
->s_addr
, &lsa
->data
->id
.s_addr
)
356 best
= &lsa
->data
->id
;
359 if (IS_DEBUG_OSPF_NSSA
)
361 "ospf_abr_nssa_am_elected: best electable ABR is: %s",
362 (best
) ? inet_ntoa(*best
) : "<none>");
367 if (IPV4_ADDR_CMP(&best
->s_addr
, &area
->ospf
->router_id
.s_addr
) < 0)
373 /* Check NSSA ABR status
374 * assumes there are nssa areas
376 static void ospf_abr_nssa_check_status(struct ospf
*ospf
)
378 struct ospf_area
*area
;
379 struct listnode
*lnode
, *nnode
;
381 for (ALL_LIST_ELEMENTS(ospf
->areas
, lnode
, nnode
, area
)) {
382 uint8_t old_state
= area
->NSSATranslatorState
;
384 if (area
->external_routing
!= OSPF_AREA_NSSA
)
387 if (IS_DEBUG_OSPF(nssa
, NSSA
))
389 "ospf_abr_nssa_check_status: "
391 inet_ntoa(area
->area_id
));
393 if (!IS_OSPF_ABR(area
->ospf
)) {
394 if (IS_DEBUG_OSPF(nssa
, NSSA
))
396 "ospf_abr_nssa_check_status: "
398 area
->NSSATranslatorState
=
399 OSPF_NSSA_TRANSLATE_DISABLED
;
401 switch (area
->NSSATranslatorRole
) {
402 case OSPF_NSSA_ROLE_NEVER
:
403 /* We never Translate Type-7 LSA. */
404 /* TODO: check previous state and flush? */
405 if (IS_DEBUG_OSPF(nssa
, NSSA
))
407 "ospf_abr_nssa_check_status: "
409 area
->NSSATranslatorState
=
410 OSPF_NSSA_TRANSLATE_DISABLED
;
413 case OSPF_NSSA_ROLE_ALWAYS
:
414 /* We always translate if we are an ABR
415 * TODO: originate new LSAs if state change?
416 * or let the nssa abr task take care of it?
418 if (IS_DEBUG_OSPF(nssa
, NSSA
))
420 "ospf_abr_nssa_check_status: "
422 area
->NSSATranslatorState
=
423 OSPF_NSSA_TRANSLATE_ENABLED
;
426 case OSPF_NSSA_ROLE_CANDIDATE
:
427 /* We are a candidate for Translation */
428 if (ospf_abr_nssa_am_elected(area
) > 0) {
429 area
->NSSATranslatorState
=
430 OSPF_NSSA_TRANSLATE_ENABLED
;
431 if (IS_DEBUG_OSPF(nssa
, NSSA
))
433 "ospf_abr_nssa_check_status: "
434 "elected translator");
436 area
->NSSATranslatorState
=
437 OSPF_NSSA_TRANSLATE_DISABLED
;
438 if (IS_DEBUG_OSPF(nssa
, NSSA
))
440 "ospf_abr_nssa_check_status: "
447 * All NSSA border routers must set the E-bit in the Type-1
449 * of their directly attached non-stub areas, even when they are
453 if (old_state
!= area
->NSSATranslatorState
) {
454 if (old_state
== OSPF_NSSA_TRANSLATE_DISABLED
)
455 ospf_asbr_status_update(ospf
,
456 ++ospf
->redistribute
);
457 else if (area
->NSSATranslatorState
458 == OSPF_NSSA_TRANSLATE_DISABLED
)
459 ospf_asbr_status_update(ospf
,
460 --ospf
->redistribute
);
465 /* Check area border router status. */
466 void ospf_check_abr_status(struct ospf
*ospf
)
468 struct ospf_area
*area
;
469 struct listnode
*node
, *nnode
;
470 int bb_configured
= 0;
471 int bb_act_attached
= 0;
472 int areas_configured
= 0;
473 int areas_act_attached
= 0;
474 uint8_t new_flags
= ospf
->flags
;
476 if (IS_DEBUG_OSPF_EVENT
)
477 zlog_debug("ospf_check_abr_status(): Start");
479 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
480 if (listcount(area
->oiflist
)) {
483 if (OSPF_IS_AREA_BACKBONE(area
))
487 if (ospf_area_actively_attached(area
)) {
488 areas_act_attached
++;
490 if (OSPF_IS_AREA_BACKBONE(area
))
495 if (IS_DEBUG_OSPF_EVENT
) {
496 zlog_debug("ospf_check_abr_status(): looked through areas");
497 zlog_debug("ospf_check_abr_status(): bb_configured: %d",
499 zlog_debug("ospf_check_abr_status(): bb_act_attached: %d",
501 zlog_debug("ospf_check_abr_status(): areas_configured: %d",
503 zlog_debug("ospf_check_abr_status(): areas_act_attached: %d",
507 switch (ospf
->abr_type
) {
508 case OSPF_ABR_SHORTCUT
:
510 if (areas_act_attached
> 1)
511 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
513 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
517 if ((areas_act_attached
> 1) && bb_configured
)
518 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
520 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
524 if ((areas_configured
> 1) && bb_act_attached
)
525 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
527 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
533 if (new_flags
!= ospf
->flags
) {
534 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_ABR_STATUS_CHANGE
);
535 if (IS_DEBUG_OSPF_EVENT
)
537 "ospf_check_abr_status(): new router flags: %x",
539 ospf
->flags
= new_flags
;
540 ospf_router_lsa_update(ospf
);
544 static void ospf_abr_update_aggregate(struct ospf_area_range
*range
,
545 struct ospf_route
* or,
546 struct ospf_area
*area
)
548 if (IS_DEBUG_OSPF_EVENT
)
549 zlog_debug("ospf_abr_update_aggregate(): Start");
551 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)
552 && (range
->cost
!= OSPF_STUB_MAX_METRIC_SUMMARY_COST
)) {
553 range
->cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
554 if (IS_DEBUG_OSPF_EVENT
)
556 "ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
558 } else if (range
->cost_config
!= OSPF_AREA_RANGE_COST_UNSPEC
) {
559 if (IS_DEBUG_OSPF_EVENT
)
561 "ospf_abr_update_aggregate(): use configured cost %d",
564 range
->cost
= range
->cost_config
;
566 if (range
->specifics
== 0) {
567 if (IS_DEBUG_OSPF_EVENT
)
569 "ospf_abr_update_aggregate(): use or->cost %d",
572 range
->cost
= or->cost
; /* 1st time get 1st cost */
575 if (or->cost
> range
->cost
) {
576 if (IS_DEBUG_OSPF_EVENT
)
578 "ospf_abr_update_aggregate(): update to %d",
581 range
->cost
= or->cost
;
588 static void set_metric(struct ospf_lsa
*lsa
, uint32_t metric
)
590 struct summary_lsa
*header
;
592 metric
= htonl(metric
);
593 mp
= (uint8_t *)&metric
;
595 header
= (struct summary_lsa
*)lsa
->data
;
596 memcpy(header
->metric
, mp
, 3);
599 /* ospf_abr_translate_nssa */
600 static int ospf_abr_translate_nssa(struct ospf_area
*area
, struct ospf_lsa
*lsa
)
602 /* Incoming Type-7 or later aggregated Type-7
604 * LSA is skipped if P-bit is off.
605 * LSA is aggregated if within range.
607 * The Type-7 is translated, Installed/Approved as a Type-5 into
608 * global LSDB, then Flooded through AS
610 * Later, any Unapproved Translated Type-5's are flushed/discarded
613 struct ospf_lsa
*old
= NULL
, *new = NULL
;
614 struct as_external_lsa
*ext7
;
615 struct prefix_ipv4 p
;
617 if (!CHECK_FLAG(lsa
->data
->options
, OSPF_OPTION_NP
)) {
618 if (IS_DEBUG_OSPF_NSSA
)
620 "ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
621 inet_ntoa(lsa
->data
->id
));
625 if (IS_DEBUG_OSPF_NSSA
)
627 "ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
628 inet_ntoa(lsa
->data
->id
));
630 ext7
= (struct as_external_lsa
*)(lsa
->data
);
631 p
.prefix
= lsa
->data
->id
;
632 p
.prefixlen
= ip_masklen(ext7
->mask
);
634 if (ext7
->e
[0].fwd_addr
.s_addr
== OSPF_DEFAULT_DESTINATION
) {
635 if (IS_DEBUG_OSPF_NSSA
)
637 "ospf_abr_translate_nssa(): LSA Id %s, "
638 "Forward address is 0, NO Translation",
639 inet_ntoa(lsa
->data
->id
));
643 /* try find existing AS-External LSA for this prefix */
645 old
= ospf_external_info_find_lsa(area
->ospf
, &p
);
648 if (IS_DEBUG_OSPF_NSSA
)
650 "ospf_abr_translate_nssa(): "
651 "found old translated LSA Id %s, refreshing",
652 inet_ntoa(old
->data
->id
));
655 new = ospf_translated_nssa_refresh(area
->ospf
, lsa
, old
);
657 if (IS_DEBUG_OSPF_NSSA
)
659 "ospf_abr_translate_nssa(): "
660 "could not refresh translated LSA Id %s",
661 inet_ntoa(old
->data
->id
));
664 /* no existing external route for this LSA Id
665 * originate translated LSA
668 if ((new = ospf_translated_nssa_originate(area
->ospf
, lsa
))
670 if (IS_DEBUG_OSPF_NSSA
)
672 "ospf_abr_translate_nssa(): Could not translate "
673 "Type-7 for %s to Type-5",
674 inet_ntoa(lsa
->data
->id
));
679 /* Area where Aggregate testing will be inserted, just like summary
681 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
686 static void ospf_abr_translate_nssa_range(struct prefix_ipv4
*p
, uint32_t cost
)
688 /* The Type-7 is created from the aggregated prefix and forwarded
689 for lsa installation and flooding... to be added... */
692 void ospf_abr_announce_network_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
693 struct ospf_area
*area
)
695 struct ospf_lsa
*lsa
, *old
= NULL
;
696 struct summary_lsa
*sl
= NULL
;
699 if (IS_DEBUG_OSPF_EVENT
)
700 zlog_debug("ospf_abr_announce_network_to_area(): Start");
702 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
703 full_cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
707 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_SUMMARY_LSA
,
708 (struct prefix_ipv4
*)p
,
709 area
->ospf
->router_id
);
711 if (IS_DEBUG_OSPF_EVENT
)
713 "ospf_abr_announce_network_to_area(): old summary found");
715 sl
= (struct summary_lsa
*)old
->data
;
717 if (IS_DEBUG_OSPF_EVENT
)
719 "ospf_abr_announce_network_to_area(): "
720 "old metric: %d, new metric: %d",
721 GET_METRIC(sl
->metric
), cost
);
723 if ((GET_METRIC(sl
->metric
) == full_cost
)
724 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
725 /* unchanged. simply reapprove it */
726 if (IS_DEBUG_OSPF_EVENT
)
728 "ospf_abr_announce_network_to_area(): "
729 "old summary approved");
730 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
732 /* LSA is changed, refresh it */
733 if (IS_DEBUG_OSPF_EVENT
)
735 "ospf_abr_announce_network_to_area(): "
736 "refreshing summary");
737 set_metric(old
, full_cost
);
738 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
741 char buf
[PREFIX2STR_BUFFER
];
743 prefix2str((struct prefix
*)p
, buf
,
745 zlog_warn("%s: Could not refresh %s to %s",
747 inet_ntoa(area
->area_id
));
751 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
752 /* This will flood through area. */
755 if (IS_DEBUG_OSPF_EVENT
)
757 "ospf_abr_announce_network_to_area(): "
758 "creating new summary");
759 lsa
= ospf_summary_lsa_originate((struct prefix_ipv4
*)p
,
761 /* This will flood through area. */
764 char buf
[PREFIX2STR_BUFFER
];
766 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
767 zlog_warn("%s: Could not originate %s to %s", __func__
,
768 buf
, inet_ntoa(area
->area_id
));
772 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
773 if (IS_DEBUG_OSPF_EVENT
)
775 "ospf_abr_announce_network_to_area(): "
776 "flooding new version of summary");
779 if (IS_DEBUG_OSPF_EVENT
)
780 zlog_debug("ospf_abr_announce_network_to_area(): Stop");
783 static int ospf_abr_nexthops_belong_to_area(struct ospf_route
* or,
784 struct ospf_area
*area
)
786 struct listnode
*node
, *nnode
;
787 struct ospf_path
*path
;
788 struct ospf_interface
*oi
;
790 for (ALL_LIST_ELEMENTS_RO(or->paths
, node
, path
))
791 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, nnode
, oi
))
792 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
798 static int ospf_abr_should_accept(struct prefix_ipv4
*p
, struct ospf_area
*area
)
800 if (IMPORT_NAME(area
)) {
801 if (IMPORT_LIST(area
) == NULL
)
803 access_list_lookup(AFI_IP
, IMPORT_NAME(area
));
805 if (IMPORT_LIST(area
))
806 if (access_list_apply(IMPORT_LIST(area
), p
)
814 static int ospf_abr_plist_in_check(struct ospf_area
*area
,
815 struct ospf_route
* or,
816 struct prefix_ipv4
*p
)
818 if (PREFIX_NAME_IN(area
)) {
819 if (PREFIX_LIST_IN(area
) == NULL
)
820 PREFIX_LIST_IN(area
) = prefix_list_lookup(
821 AFI_IP
, PREFIX_NAME_IN(area
));
822 if (PREFIX_LIST_IN(area
))
823 if (prefix_list_apply(PREFIX_LIST_IN(area
), p
)
830 static int ospf_abr_plist_out_check(struct ospf_area
*area
,
831 struct ospf_route
* or,
832 struct prefix_ipv4
*p
)
834 if (PREFIX_NAME_OUT(area
)) {
835 if (PREFIX_LIST_OUT(area
) == NULL
)
836 PREFIX_LIST_OUT(area
) = prefix_list_lookup(
837 AFI_IP
, PREFIX_NAME_OUT(area
));
838 if (PREFIX_LIST_OUT(area
))
839 if (prefix_list_apply(PREFIX_LIST_OUT(area
), p
)
846 static void ospf_abr_announce_network(struct ospf
*ospf
, struct prefix_ipv4
*p
,
847 struct ospf_route
* or)
849 struct ospf_area_range
*range
;
850 struct ospf_area
*area
, *or_area
;
851 struct listnode
*node
;
853 if (IS_DEBUG_OSPF_EVENT
)
854 zlog_debug("ospf_abr_announce_network(): Start");
856 or_area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
859 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
860 if (IS_DEBUG_OSPF_EVENT
)
862 "ospf_abr_announce_network(): looking at area %s",
863 inet_ntoa(area
->area_id
));
865 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
868 if (ospf_abr_nexthops_belong_to_area(or, area
))
871 if (!ospf_abr_should_accept(p
, area
)) {
872 if (IS_DEBUG_OSPF_EVENT
)
874 "ospf_abr_announce_network(): "
875 "prefix %s/%d was denied by import-list",
876 inet_ntoa(p
->prefix
), p
->prefixlen
);
880 if (!ospf_abr_plist_in_check(area
, or, p
)) {
881 if (IS_DEBUG_OSPF_EVENT
)
883 "ospf_abr_announce_network(): "
884 "prefix %s/%d was denied by prefix-list",
885 inet_ntoa(p
->prefix
), p
->prefixlen
);
889 if (area
->external_routing
!= OSPF_AREA_DEFAULT
890 && area
->no_summary
) {
891 if (IS_DEBUG_OSPF_EVENT
)
893 "ospf_abr_announce_network(): "
894 "area %s is stub and no_summary",
895 inet_ntoa(area
->area_id
));
899 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
900 if (IS_DEBUG_OSPF_EVENT
)
902 "ospf_abr_announce_network(): this is "
903 "inter-area route to %s/%d",
904 inet_ntoa(p
->prefix
), p
->prefixlen
);
906 if (!OSPF_IS_AREA_BACKBONE(area
))
907 ospf_abr_announce_network_to_area(p
, or->cost
,
911 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
912 if (IS_DEBUG_OSPF_EVENT
)
914 "ospf_abr_announce_network(): "
915 "this is intra-area route to %s/%d",
916 inet_ntoa(p
->prefix
), p
->prefixlen
);
917 if ((range
= ospf_area_range_match(or_area
, p
))
918 && !ospf_area_is_transit(area
))
919 ospf_abr_update_aggregate(range
, or, area
);
921 ospf_abr_announce_network_to_area(p
, or->cost
,
927 static int ospf_abr_should_announce(struct ospf
*ospf
, struct prefix_ipv4
*p
,
928 struct ospf_route
* or)
930 struct ospf_area
*area
;
932 area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
936 if (EXPORT_NAME(area
)) {
937 if (EXPORT_LIST(area
) == NULL
)
939 access_list_lookup(AFI_IP
, EXPORT_NAME(area
));
941 if (EXPORT_LIST(area
))
942 if (access_list_apply(EXPORT_LIST(area
), p
)
950 static void ospf_abr_process_nssa_translates(struct ospf
*ospf
)
952 /* Scan through all NSSA_LSDB records for all areas;
954 If P-bit is on, translate all Type-7's to 5's and aggregate or
955 flood install as approved in Type-5 LSDB with XLATE Flag on
956 later, do same for all aggregates... At end, DISCARD all
957 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
958 struct listnode
*node
;
959 struct ospf_area
*area
;
960 struct route_node
*rn
;
961 struct ospf_lsa
*lsa
;
963 if (IS_DEBUG_OSPF_NSSA
)
964 zlog_debug("ospf_abr_process_nssa_translates(): Start");
966 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
967 if (!area
->NSSATranslatorState
)
968 continue; /* skip if not translator */
970 if (area
->external_routing
!= OSPF_AREA_NSSA
)
971 continue; /* skip if not Nssa Area */
973 if (IS_DEBUG_OSPF_NSSA
)
975 "ospf_abr_process_nssa_translates(): "
976 "looking at area %s",
977 inet_ntoa(area
->area_id
));
979 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
980 ospf_abr_translate_nssa(area
, lsa
);
983 if (IS_DEBUG_OSPF_NSSA
)
984 zlog_debug("ospf_abr_process_nssa_translates(): Stop");
987 static void ospf_abr_process_network_rt(struct ospf
*ospf
,
988 struct route_table
*rt
)
990 struct ospf_area
*area
;
991 struct ospf_route
* or ;
992 struct route_node
*rn
;
994 if (IS_DEBUG_OSPF_EVENT
)
995 zlog_debug("ospf_abr_process_network_rt(): Start");
997 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
998 if ((or = rn
->info
) == NULL
)
1001 if (!(area
= ospf_area_lookup_by_area_id(ospf
,
1002 or->u
.std
.area_id
))) {
1003 if (IS_DEBUG_OSPF_EVENT
)
1005 "ospf_abr_process_network_rt(): area %s no longer exists",
1006 inet_ntoa(or->u
.std
.area_id
));
1010 if (IS_DEBUG_OSPF_EVENT
)
1012 "ospf_abr_process_network_rt(): this is a route to %s/%d",
1013 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
1014 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
) {
1015 if (IS_DEBUG_OSPF_EVENT
)
1017 "ospf_abr_process_network_rt(): "
1018 "this is an External router, skipping");
1022 if (or->cost
>= OSPF_LS_INFINITY
) {
1023 if (IS_DEBUG_OSPF_EVENT
)
1025 "ospf_abr_process_network_rt():"
1026 " this route's cost is infinity, skipping");
1030 if (or->type
== OSPF_DESTINATION_DISCARD
) {
1031 if (IS_DEBUG_OSPF_EVENT
)
1033 "ospf_abr_process_network_rt():"
1034 " this is a discard entry, skipping");
1039 or->path_type
== OSPF_PATH_INTRA_AREA
1040 && !ospf_abr_should_announce(
1041 ospf
, (struct prefix_ipv4
*)&rn
->p
,
1043 if (IS_DEBUG_OSPF_EVENT
)
1045 "ospf_abr_process_network_rt(): denied by export-list");
1050 or->path_type
== OSPF_PATH_INTRA_AREA
1051 && !ospf_abr_plist_out_check(
1053 (struct prefix_ipv4
*)&rn
->p
)) {
1054 if (IS_DEBUG_OSPF_EVENT
)
1056 "ospf_abr_process_network_rt(): denied by prefix-list");
1060 if ((or->path_type
== OSPF_PATH_INTER_AREA
)
1061 && !OSPF_IS_AREA_ID_BACKBONE(or->u
.std
.area_id
)) {
1062 if (IS_DEBUG_OSPF_EVENT
)
1064 "ospf_abr_process_network_rt():"
1065 " this is route is not backbone one, skipping");
1070 if ((ospf
->abr_type
== OSPF_ABR_CISCO
)
1071 || (ospf
->abr_type
== OSPF_ABR_IBM
))
1073 if (!ospf_act_bb_connection(ospf
) &&
1074 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1075 if (IS_DEBUG_OSPF_EVENT
)
1077 "ospf_abr_process_network_rt(): ALT ABR: "
1078 "No BB connection, skip not intra-area routes");
1082 if (IS_DEBUG_OSPF_EVENT
)
1083 zlog_debug("ospf_abr_process_network_rt(): announcing");
1084 ospf_abr_announce_network(ospf
, (struct prefix_ipv4
*)&rn
->p
,
1088 if (IS_DEBUG_OSPF_EVENT
)
1089 zlog_debug("ospf_abr_process_network_rt(): Stop");
1092 static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
1093 struct ospf_area
*area
)
1095 struct ospf_lsa
*lsa
, *old
= NULL
;
1096 struct summary_lsa
*slsa
= NULL
;
1098 if (IS_DEBUG_OSPF_EVENT
)
1099 zlog_debug("ospf_abr_announce_rtr_to_area(): Start");
1101 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
,
1102 area
->ospf
->router_id
);
1104 if (IS_DEBUG_OSPF_EVENT
)
1106 "ospf_abr_announce_rtr_to_area(): old summary found");
1107 slsa
= (struct summary_lsa
*)old
->data
;
1109 if (IS_DEBUG_OSPF_EVENT
)
1111 "ospf_abr_announce_network_to_area(): "
1112 "old metric: %d, new metric: %d",
1113 GET_METRIC(slsa
->metric
), cost
);
1116 if (old
&& (GET_METRIC(slsa
->metric
) == cost
)
1117 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
1118 if (IS_DEBUG_OSPF_EVENT
)
1120 "ospf_abr_announce_rtr_to_area(): old summary approved");
1121 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
1123 if (IS_DEBUG_OSPF_EVENT
)
1124 zlog_debug("ospf_abr_announce_rtr_to_area(): 2.2");
1127 set_metric(old
, cost
);
1128 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
1130 lsa
= ospf_summary_asbr_lsa_originate(p
, cost
, area
);
1132 char buf
[PREFIX2STR_BUFFER
];
1134 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
1135 zlog_warn("%s: Could not refresh/originate %s to %s",
1136 __func__
, buf
, inet_ntoa(area
->area_id
));
1140 if (IS_DEBUG_OSPF_EVENT
)
1142 "ospf_abr_announce_rtr_to_area(): "
1143 "flooding new version of summary");
1146 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new
1148 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1150 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1151 /* ospf_flood_through_area (area, NULL, lsa);*/
1154 if (IS_DEBUG_OSPF_EVENT
)
1155 zlog_debug("ospf_abr_announce_rtr_to_area(): Stop");
1159 static void ospf_abr_announce_rtr(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1160 struct ospf_route
* or)
1162 struct listnode
*node
;
1163 struct ospf_area
*area
;
1165 if (IS_DEBUG_OSPF_EVENT
)
1166 zlog_debug("ospf_abr_announce_rtr(): Start");
1168 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1169 if (IS_DEBUG_OSPF_EVENT
)
1171 "ospf_abr_announce_rtr(): looking at area %s",
1172 inet_ntoa(area
->area_id
));
1174 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
1177 if (ospf_abr_nexthops_belong_to_area(or, area
))
1180 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
1181 if (IS_DEBUG_OSPF_EVENT
)
1183 "ospf_abr_announce_rtr(): "
1184 "area %s doesn't support external routing",
1185 inet_ntoa(area
->area_id
));
1189 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
1190 if (IS_DEBUG_OSPF_EVENT
)
1192 "ospf_abr_announce_rtr(): "
1193 "this is inter-area route to %s",
1194 inet_ntoa(p
->prefix
));
1195 if (!OSPF_IS_AREA_BACKBONE(area
))
1196 ospf_abr_announce_rtr_to_area(p
, or->cost
,
1200 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
1201 if (IS_DEBUG_OSPF_EVENT
)
1203 "ospf_abr_announce_rtr(): "
1204 "this is intra-area route to %s",
1205 inet_ntoa(p
->prefix
));
1206 ospf_abr_announce_rtr_to_area(p
, or->cost
, area
);
1210 if (IS_DEBUG_OSPF_EVENT
)
1211 zlog_debug("ospf_abr_announce_rtr(): Stop");
1214 static void ospf_abr_process_router_rt(struct ospf
*ospf
,
1215 struct route_table
*rt
)
1217 struct ospf_route
* or ;
1218 struct route_node
*rn
;
1221 if (IS_DEBUG_OSPF_EVENT
)
1222 zlog_debug("ospf_abr_process_router_rt(): Start");
1224 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1225 struct listnode
*node
, *nnode
;
1227 struct ospf_route
*best
= NULL
;
1229 if (rn
->info
== NULL
)
1234 if (IS_DEBUG_OSPF_EVENT
)
1236 "ospf_abr_process_router_rt(): this is a route to %s",
1237 inet_ntoa(rn
->p
.u
.prefix4
));
1239 for (ALL_LIST_ELEMENTS(l
, node
, nnode
, or)) {
1240 if (!ospf_area_lookup_by_area_id(ospf
,
1241 or->u
.std
.area_id
)) {
1242 if (IS_DEBUG_OSPF_EVENT
)
1244 "ospf_abr_process_router_rt(): area %s no longer exists",
1245 inet_ntoa(or->u
.std
.area_id
));
1250 if (!CHECK_FLAG(or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
)) {
1251 if (IS_DEBUG_OSPF_EVENT
)
1253 "ospf_abr_process_router_rt(): "
1254 "This is not an ASBR, skipping");
1259 best
= ospf_find_asbr_route(
1260 ospf
, rt
, (struct prefix_ipv4
*)&rn
->p
);
1268 if (IS_DEBUG_OSPF_EVENT
)
1270 "ospf_abr_process_router_rt(): "
1271 "This route is not the best among possible, skipping");
1276 or->path_type
== OSPF_PATH_INTER_AREA
1277 && !OSPF_IS_AREA_ID_BACKBONE(
1278 or->u
.std
.area_id
)) {
1279 if (IS_DEBUG_OSPF_EVENT
)
1281 "ospf_abr_process_router_rt(): "
1282 "This route is not a backbone one, skipping");
1286 if (or->cost
>= OSPF_LS_INFINITY
) {
1287 if (IS_DEBUG_OSPF_EVENT
)
1289 "ospf_abr_process_router_rt(): "
1290 "This route has LS_INFINITY metric, skipping");
1294 if (ospf
->abr_type
== OSPF_ABR_CISCO
1295 || ospf
->abr_type
== OSPF_ABR_IBM
)
1296 if (!ospf_act_bb_connection(ospf
) &&
1297 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1298 if (IS_DEBUG_OSPF_EVENT
)
1300 "ospf_abr_process_network_rt(): ALT ABR: "
1301 "No BB connection, skip not intra-area routes");
1305 ospf_abr_announce_rtr(ospf
,
1306 (struct prefix_ipv4
*)&rn
->p
, or);
1310 if (IS_DEBUG_OSPF_EVENT
)
1311 zlog_debug("ospf_abr_process_router_rt(): Stop");
1315 ospf_abr_unapprove_translates(struct ospf
*ospf
) /* For NSSA Translations */
1317 struct ospf_lsa
*lsa
;
1318 struct route_node
*rn
;
1320 if (IS_DEBUG_OSPF_NSSA
)
1321 zlog_debug("ospf_abr_unapprove_translates(): Start");
1323 /* NSSA Translator is not checked, because it may have gone away,
1324 and we would want to flush any residuals anyway */
1326 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1327 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) {
1328 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1329 if (IS_DEBUG_OSPF_NSSA
)
1331 "ospf_abr_unapprove_translates(): "
1332 "approved unset on link id %s",
1333 inet_ntoa(lsa
->data
->id
));
1336 if (IS_DEBUG_OSPF_NSSA
)
1337 zlog_debug("ospf_abr_unapprove_translates(): Stop");
1340 static void ospf_abr_unapprove_summaries(struct ospf
*ospf
)
1342 struct listnode
*node
;
1343 struct ospf_area
*area
;
1344 struct route_node
*rn
;
1345 struct ospf_lsa
*lsa
;
1347 if (IS_DEBUG_OSPF_EVENT
)
1348 zlog_debug("ospf_abr_unapprove_summaries(): Start");
1350 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1351 if (IS_DEBUG_OSPF_EVENT
)
1353 "ospf_abr_unapprove_summaries(): "
1354 "considering area %s",
1355 inet_ntoa(area
->area_id
));
1356 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1357 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1358 if (IS_DEBUG_OSPF_EVENT
)
1360 "ospf_abr_unapprove_summaries(): "
1361 "approved unset on summary link id %s",
1362 inet_ntoa(lsa
->data
->id
));
1363 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1366 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1367 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1368 if (IS_DEBUG_OSPF_EVENT
)
1370 "ospf_abr_unapprove_summaries(): "
1371 "approved unset on asbr-summary link id %s",
1372 inet_ntoa(lsa
->data
->id
));
1373 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1377 if (IS_DEBUG_OSPF_EVENT
)
1378 zlog_debug("ospf_abr_unapprove_summaries(): Stop");
1381 static void ospf_abr_prepare_aggregates(struct ospf
*ospf
)
1383 struct listnode
*node
;
1384 struct route_node
*rn
;
1385 struct ospf_area_range
*range
;
1386 struct ospf_area
*area
;
1388 if (IS_DEBUG_OSPF_EVENT
)
1389 zlog_debug("ospf_abr_prepare_aggregates(): Start");
1391 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1392 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1393 if ((range
= rn
->info
) != NULL
) {
1395 range
->specifics
= 0;
1399 if (IS_DEBUG_OSPF_EVENT
)
1400 zlog_debug("ospf_abr_prepare_aggregates(): Stop");
1403 static void ospf_abr_announce_aggregates(struct ospf
*ospf
)
1405 struct ospf_area
*area
, *ar
;
1406 struct ospf_area_range
*range
;
1407 struct route_node
*rn
;
1409 struct listnode
*node
, *n
;
1411 if (IS_DEBUG_OSPF_EVENT
)
1412 zlog_debug("ospf_abr_announce_aggregates(): Start");
1414 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1415 if (IS_DEBUG_OSPF_EVENT
)
1417 "ospf_abr_announce_aggregates(): looking at area %s",
1418 inet_ntoa(area
->area_id
));
1420 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1421 if ((range
= rn
->info
)) {
1422 if (!CHECK_FLAG(range
->flags
,
1423 OSPF_AREA_RANGE_ADVERTISE
)) {
1424 if (IS_DEBUG_OSPF_EVENT
)
1426 "ospf_abr_announce_aggregates():"
1427 " discarding suppress-ranges");
1432 p
.u
.prefix4
= range
->addr
;
1433 p
.prefixlen
= range
->masklen
;
1435 if (IS_DEBUG_OSPF_EVENT
)
1437 "ospf_abr_announce_aggregates():"
1438 " this is range: %s/%d",
1439 inet_ntoa(p
.u
.prefix4
),
1442 if (CHECK_FLAG(range
->flags
,
1443 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1445 p
.u
.prefix4
= range
->subst_addr
;
1446 p
.prefixlen
= range
->subst_masklen
;
1449 if (range
->specifics
) {
1450 if (IS_DEBUG_OSPF_EVENT
)
1452 "ospf_abr_announce_aggregates(): active range");
1454 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
,
1459 /* We do not check nexthops
1461 intra-area routes can be
1465 /* backbone routes are not
1467 when announced into transit
1470 if (ospf_area_is_transit(ar
)
1471 && OSPF_IS_AREA_BACKBONE(
1473 if (IS_DEBUG_OSPF_EVENT
)
1475 "ospf_abr_announce_aggregates(): Skipping "
1476 "announcement of BB aggregate into"
1480 ospf_abr_announce_network_to_area(
1489 if (IS_DEBUG_OSPF_EVENT
)
1490 zlog_debug("ospf_abr_announce_aggregates(): Stop");
1494 ospf_abr_send_nssa_aggregates(struct ospf
*ospf
) /* temporarily turned off */
1496 struct listnode
*node
; /*, n; */
1497 struct ospf_area
*area
; /*, *ar; */
1498 struct route_node
*rn
;
1499 struct ospf_area_range
*range
;
1500 struct prefix_ipv4 p
;
1502 if (IS_DEBUG_OSPF_NSSA
)
1503 zlog_debug("ospf_abr_send_nssa_aggregates(): Start");
1505 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1506 if (!area
->NSSATranslatorState
)
1509 if (IS_DEBUG_OSPF_NSSA
)
1511 "ospf_abr_send_nssa_aggregates(): looking at area %s",
1512 inet_ntoa(area
->area_id
));
1514 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
)) {
1515 if (rn
->info
== NULL
)
1520 if (!CHECK_FLAG(range
->flags
,
1521 OSPF_AREA_RANGE_ADVERTISE
)) {
1522 if (IS_DEBUG_OSPF_NSSA
)
1524 "ospf_abr_send_nssa_aggregates():"
1525 " discarding suppress-ranges");
1530 p
.prefix
= range
->addr
;
1531 p
.prefixlen
= range
->masklen
;
1533 if (IS_DEBUG_OSPF_NSSA
)
1535 "ospf_abr_send_nssa_aggregates():"
1536 " this is range: %s/%d",
1537 inet_ntoa(p
.prefix
), p
.prefixlen
);
1539 if (CHECK_FLAG(range
->flags
,
1540 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1542 p
.prefix
= range
->subst_addr
;
1543 p
.prefixlen
= range
->subst_masklen
;
1546 if (range
->specifics
) {
1547 if (IS_DEBUG_OSPF_NSSA
)
1549 "ospf_abr_send_nssa_aggregates(): active range");
1551 /* Fetch LSA-Type-7 from aggregate prefix, and
1553 * translate, Install (as Type-5), Approve, and
1556 ospf_abr_translate_nssa_range(&p
, range
->cost
);
1558 } /* all area ranges*/
1561 if (IS_DEBUG_OSPF_NSSA
)
1562 zlog_debug("ospf_abr_send_nssa_aggregates(): Stop");
1565 static void ospf_abr_announce_stub_defaults(struct ospf
*ospf
)
1567 struct listnode
*node
;
1568 struct ospf_area
*area
;
1569 struct prefix_ipv4 p
;
1571 if (!IS_OSPF_ABR(ospf
))
1574 if (IS_DEBUG_OSPF_EVENT
)
1575 zlog_debug("ospf_abr_announce_stub_defaults(): Start");
1578 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1581 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1582 if (IS_DEBUG_OSPF_EVENT
)
1584 "ospf_abr_announce_stub_defaults(): looking at area %s",
1585 inet_ntoa(area
->area_id
));
1587 if ((area
->external_routing
!= OSPF_AREA_STUB
)
1588 && (area
->external_routing
!= OSPF_AREA_NSSA
))
1591 if (OSPF_IS_AREA_BACKBONE(area
))
1592 continue; /* Sanity Check */
1594 if (IS_DEBUG_OSPF_EVENT
)
1596 "ospf_abr_announce_stub_defaults(): "
1597 "announcing 0.0.0.0/0 to area %s",
1598 inet_ntoa(area
->area_id
));
1599 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1602 if (IS_DEBUG_OSPF_EVENT
)
1603 zlog_debug("ospf_abr_announce_stub_defaults(): Stop");
1606 static int ospf_abr_remove_unapproved_translates_apply(struct ospf
*ospf
,
1607 struct ospf_lsa
*lsa
)
1609 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1610 && !CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
)) {
1612 "ospf_abr_remove_unapproved_translates(): "
1613 "removing unapproved translates, ID: %s",
1614 inet_ntoa(lsa
->data
->id
));
1616 /* FLUSH THROUGHOUT AS */
1617 ospf_lsa_flush_as(ospf
, lsa
);
1619 /* DISCARD from LSDB */
1624 static void ospf_abr_remove_unapproved_translates(struct ospf
*ospf
)
1626 struct route_node
*rn
;
1627 struct ospf_lsa
*lsa
;
1629 /* All AREA PROCESS should have APPROVED necessary LSAs */
1630 /* Remove any left over and not APPROVED */
1631 if (IS_DEBUG_OSPF_NSSA
)
1632 zlog_debug("ospf_abr_remove_unapproved_translates(): Start");
1634 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1635 ospf_abr_remove_unapproved_translates_apply(ospf
, lsa
);
1637 if (IS_DEBUG_OSPF_NSSA
)
1638 zlog_debug("ospf_abr_remove_unapproved_translates(): Stop");
1641 static void ospf_abr_remove_unapproved_summaries(struct ospf
*ospf
)
1643 struct listnode
*node
;
1644 struct ospf_area
*area
;
1645 struct route_node
*rn
;
1646 struct ospf_lsa
*lsa
;
1648 if (IS_DEBUG_OSPF_EVENT
)
1649 zlog_debug("ospf_abr_remove_unapproved_summaries(): Start");
1651 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1652 if (IS_DEBUG_OSPF_EVENT
)
1654 "ospf_abr_remove_unapproved_summaries(): "
1655 "looking at area %s",
1656 inet_ntoa(area
->area_id
));
1658 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1659 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1660 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1661 ospf_lsa_flush_area(lsa
, area
);
1663 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1664 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1665 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1666 ospf_lsa_flush_area(lsa
, area
);
1669 if (IS_DEBUG_OSPF_EVENT
)
1670 zlog_debug("ospf_abr_remove_unapproved_summaries(): Stop");
1673 static void ospf_abr_manage_discard_routes(struct ospf
*ospf
)
1675 struct listnode
*node
, *nnode
;
1676 struct route_node
*rn
;
1677 struct ospf_area
*area
;
1678 struct ospf_area_range
*range
;
1680 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
1681 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1682 if ((range
= rn
->info
) != NULL
)
1683 if (CHECK_FLAG(range
->flags
,
1684 OSPF_AREA_RANGE_ADVERTISE
)) {
1685 if (range
->specifics
)
1686 ospf_add_discard_route(
1687 ospf
, ospf
->new_table
,
1692 ospf_delete_discard_route(
1693 ospf
, ospf
->new_table
,
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
,