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
*
54 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
;
67 ospf_area_range_free (struct ospf_area_range
*range
)
69 XFREE (MTYPE_OSPF_AREA_RANGE
, range
);
73 ospf_area_range_add (struct ospf_area
*area
, struct ospf_area_range
*range
)
75 struct route_node
*rn
;
79 p
.prefixlen
= range
->masklen
;
80 p
.prefix
= range
->addr
;
82 rn
= route_node_get (area
->ranges
, (struct prefix
*)&p
);
84 route_unlock_node (rn
);
90 ospf_area_range_delete (struct ospf_area
*area
, struct route_node
*rn
)
92 struct ospf_area_range
*range
= rn
->info
;
94 if (range
->specifics
!= 0)
95 ospf_delete_discard_route (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
*
105 ospf_area_range_lookup (struct ospf_area
*area
, struct prefix_ipv4
*p
)
107 struct route_node
*rn
;
109 rn
= route_node_lookup (area
->ranges
, (struct prefix
*)p
);
112 route_unlock_node (rn
);
118 struct ospf_area_range
*
119 ospf_area_range_lookup_next (struct ospf_area
*area
,
120 struct in_addr
*range_net
,
123 struct route_node
*rn
;
124 struct prefix_ipv4 p
;
125 struct ospf_area_range
*find
;
128 p
.prefixlen
= IPV4_MAX_BITLEN
;
129 p
.prefix
= *range_net
;
132 rn
= route_top (area
->ranges
);
135 rn
= route_node_get (area
->ranges
, (struct prefix
*) &p
);
136 rn
= route_next (rn
);
139 for (; rn
; rn
= route_next (rn
))
146 *range_net
= rn
->p
.u
.prefix4
;
147 route_unlock_node (rn
);
153 static struct ospf_area_range
*
154 ospf_area_range_match (struct ospf_area
*area
, struct prefix_ipv4
*p
)
156 struct route_node
*node
;
158 node
= route_node_match (area
->ranges
, (struct prefix
*) p
);
161 route_unlock_node (node
);
167 struct ospf_area_range
*
168 ospf_area_range_match_any (struct ospf
*ospf
, struct prefix_ipv4
*p
)
170 struct ospf_area_range
*range
;
171 struct ospf_area
*area
;
172 struct listnode
*node
;
174 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
175 if ((range
= ospf_area_range_match (area
, p
)))
182 ospf_area_range_active (struct ospf_area_range
*range
)
184 return range
->specifics
;
188 ospf_area_actively_attached (struct ospf_area
*area
)
190 return area
->act_ints
;
194 ospf_area_range_set (struct ospf
*ospf
, struct in_addr area_id
,
195 struct prefix_ipv4
*p
, int advertise
)
197 struct ospf_area
*area
;
198 struct ospf_area_range
*range
;
200 area
= ospf_area_get (ospf
, area_id
);
204 range
= ospf_area_range_lookup (area
, p
);
207 if ((CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
208 && !CHECK_FLAG (advertise
, OSPF_AREA_RANGE_ADVERTISE
))
209 || (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
210 && CHECK_FLAG (advertise
, OSPF_AREA_RANGE_ADVERTISE
)))
211 ospf_schedule_abr_task (ospf
);
215 range
= ospf_area_range_new (p
);
216 ospf_area_range_add (area
, range
);
217 ospf_schedule_abr_task (ospf
);
220 if (CHECK_FLAG (advertise
, OSPF_AREA_RANGE_ADVERTISE
))
221 SET_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
223 UNSET_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
229 ospf_area_range_cost_set (struct ospf
*ospf
, struct in_addr area_id
,
230 struct prefix_ipv4
*p
, u_int32_t cost
)
232 struct ospf_area
*area
;
233 struct ospf_area_range
*range
;
235 area
= ospf_area_get (ospf
, area_id
);
239 range
= ospf_area_range_lookup (area
, p
);
243 if (range
->cost_config
!= cost
)
245 range
->cost_config
= cost
;
246 if (ospf_area_range_active (range
))
247 ospf_schedule_abr_task (ospf
);
254 ospf_area_range_unset (struct ospf
*ospf
, struct in_addr area_id
,
255 struct prefix_ipv4
*p
)
257 struct ospf_area
*area
;
258 struct route_node
*rn
;
260 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
264 rn
= route_node_lookup (area
->ranges
, (struct prefix
*)p
);
268 if (ospf_area_range_active (rn
->info
))
269 ospf_schedule_abr_task (ospf
);
271 ospf_area_range_delete (area
, rn
);
277 ospf_area_range_substitute_set (struct ospf
*ospf
, struct in_addr area_id
,
278 struct prefix_ipv4
*p
, struct prefix_ipv4
*s
)
280 struct ospf_area
*area
;
281 struct ospf_area_range
*range
;
283 area
= ospf_area_get (ospf
, area_id
);
284 range
= ospf_area_range_lookup (area
, p
);
288 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
) ||
289 !CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
290 ospf_schedule_abr_task (ospf
);
294 range
= ospf_area_range_new (p
);
295 ospf_area_range_add (area
, range
);
296 ospf_schedule_abr_task (ospf
);
299 SET_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
300 SET_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
301 range
->subst_addr
= s
->prefix
;
302 range
->subst_masklen
= s
->prefixlen
;
308 ospf_area_range_substitute_unset (struct ospf
*ospf
, struct in_addr area_id
,
309 struct prefix_ipv4
*p
)
311 struct ospf_area
*area
;
312 struct ospf_area_range
*range
;
314 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
318 range
= ospf_area_range_lookup (area
, p
);
322 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
323 if (ospf_area_range_active (range
))
324 ospf_schedule_abr_task (ospf
);
326 UNSET_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
327 range
->subst_addr
.s_addr
= 0;
328 range
->subst_masklen
= 0;
334 ospf_act_bb_connection (struct ospf
*ospf
)
336 if (ospf
->backbone
== NULL
)
339 return ospf
->backbone
->full_nbrs
;
342 /* Determine whether this router is elected translator or not for area */
344 ospf_abr_nssa_am_elected (struct ospf_area
*area
)
346 struct route_node
*rn
;
347 struct ospf_lsa
*lsa
;
348 struct router_lsa
*rlsa
;
349 struct in_addr
*best
= NULL
;
351 LSDB_LOOP ( ROUTER_LSDB (area
), rn
, lsa
)
355 || (lsa
->data
->type
!= OSPF_ROUTER_LSA
)
356 || IS_LSA_SELF (lsa
))
359 rlsa
= (struct router_lsa
*) lsa
->data
;
361 /* ignore non-ABR routers */
362 if (!IS_ROUTER_LSA_BORDER (rlsa
))
365 /* Router has Nt flag - always translate */
366 if (IS_ROUTER_LSA_NT (rlsa
))
368 if (IS_DEBUG_OSPF_NSSA
)
369 zlog_debug ("ospf_abr_nssa_am_elected: "
370 "router %s asserts Nt",
371 inet_ntoa (lsa
->data
->id
) );
376 best
= &lsa
->data
->id
;
378 if (IPV4_ADDR_CMP (&best
->s_addr
, &lsa
->data
->id
.s_addr
) < 0)
379 best
= &lsa
->data
->id
;
382 if (IS_DEBUG_OSPF_NSSA
)
383 zlog_debug ("ospf_abr_nssa_am_elected: best electable ABR is: %s",
384 (best
) ? inet_ntoa (*best
) : "<none>" );
389 if (IPV4_ADDR_CMP (&best
->s_addr
, &area
->ospf
->router_id
.s_addr
) < 0)
395 /* Check NSSA ABR status
396 * assumes there are nssa areas
399 ospf_abr_nssa_check_status (struct ospf
*ospf
)
401 struct ospf_area
*area
;
402 struct listnode
*lnode
, *nnode
;
404 for (ALL_LIST_ELEMENTS (ospf
->areas
, lnode
, nnode
, area
))
406 u_char old_state
= area
->NSSATranslatorState
;
408 if (area
->external_routing
!= OSPF_AREA_NSSA
)
411 if (IS_DEBUG_OSPF (nssa
, NSSA
))
412 zlog_debug ("ospf_abr_nssa_check_status: "
414 inet_ntoa (area
->area_id
));
416 if (!IS_OSPF_ABR (area
->ospf
))
418 if (IS_DEBUG_OSPF (nssa
, NSSA
))
419 zlog_debug ("ospf_abr_nssa_check_status: "
421 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
425 switch (area
->NSSATranslatorRole
)
427 case OSPF_NSSA_ROLE_NEVER
:
428 /* We never Translate Type-7 LSA. */
429 /* TODO: check previous state and flush? */
430 if (IS_DEBUG_OSPF (nssa
, NSSA
))
431 zlog_debug ("ospf_abr_nssa_check_status: "
433 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
436 case OSPF_NSSA_ROLE_ALWAYS
:
437 /* We always translate if we are an ABR
438 * TODO: originate new LSAs if state change?
439 * or let the nssa abr task take care of it?
441 if (IS_DEBUG_OSPF (nssa
, NSSA
))
442 zlog_debug ("ospf_abr_nssa_check_status: "
444 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_ENABLED
;
447 case OSPF_NSSA_ROLE_CANDIDATE
:
448 /* We are a candidate for Translation */
449 if (ospf_abr_nssa_am_elected (area
) > 0)
451 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_ENABLED
;
452 if (IS_DEBUG_OSPF (nssa
, NSSA
))
453 zlog_debug ("ospf_abr_nssa_check_status: "
454 "elected translator");
458 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
459 if (IS_DEBUG_OSPF (nssa
, NSSA
))
460 zlog_debug ("ospf_abr_nssa_check_status: " "not elected");
466 * All NSSA border routers must set the E-bit in the Type-1 router-LSAs
467 * of their directly attached non-stub areas, even when they are not
470 if (old_state
!= area
->NSSATranslatorState
)
472 if (old_state
== OSPF_NSSA_TRANSLATE_DISABLED
)
473 ospf_asbr_status_update (ospf
, ++ospf
->redistribute
);
474 else if (area
->NSSATranslatorState
== OSPF_NSSA_TRANSLATE_DISABLED
)
475 ospf_asbr_status_update (ospf
, --ospf
->redistribute
);
480 /* Check area border router status. */
482 ospf_check_abr_status (struct ospf
*ospf
)
484 struct ospf_area
*area
;
485 struct listnode
*node
, *nnode
;
486 int bb_configured
= 0;
487 int bb_act_attached
= 0;
488 int areas_configured
= 0;
489 int areas_act_attached
= 0;
490 u_char new_flags
= ospf
->flags
;
492 if (IS_DEBUG_OSPF_EVENT
)
493 zlog_debug ("ospf_check_abr_status(): Start");
495 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
497 if (listcount (area
->oiflist
))
501 if (OSPF_IS_AREA_BACKBONE (area
))
505 if (ospf_area_actively_attached (area
))
507 areas_act_attached
++;
509 if (OSPF_IS_AREA_BACKBONE (area
))
514 if (IS_DEBUG_OSPF_EVENT
)
516 zlog_debug ("ospf_check_abr_status(): looked through areas");
517 zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured
);
518 zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
520 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
522 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
526 switch (ospf
->abr_type
)
528 case OSPF_ABR_SHORTCUT
:
530 if (areas_act_attached
> 1)
531 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
533 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
537 if ((areas_act_attached
> 1) && bb_configured
)
538 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
540 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
544 if ((areas_configured
> 1) && bb_act_attached
)
545 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
547 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
553 if (new_flags
!= ospf
->flags
)
555 ospf_spf_calculate_schedule (ospf
, SPF_FLAG_ABR_STATUS_CHANGE
);
556 if (IS_DEBUG_OSPF_EVENT
)
557 zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags
);
558 ospf
->flags
= new_flags
;
559 ospf_router_lsa_update (ospf
);
564 ospf_abr_update_aggregate (struct ospf_area_range
*range
,
565 struct ospf_route
*or, struct ospf_area
*area
)
567 if (IS_DEBUG_OSPF_EVENT
)
568 zlog_debug ("ospf_abr_update_aggregate(): Start");
570 if (CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
) &&
571 (range
->cost
!= OSPF_STUB_MAX_METRIC_SUMMARY_COST
))
573 range
->cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
574 if (IS_DEBUG_OSPF_EVENT
)
575 zlog_debug ("ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
578 else if (range
->cost_config
!= OSPF_AREA_RANGE_COST_UNSPEC
)
580 if (IS_DEBUG_OSPF_EVENT
)
581 zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
584 range
->cost
= range
->cost_config
;
588 if (range
->specifics
== 0)
590 if (IS_DEBUG_OSPF_EVENT
)
591 zlog_debug ("ospf_abr_update_aggregate(): use or->cost %d",
594 range
->cost
= or->cost
; /* 1st time get 1st cost */
597 if (or->cost
> range
->cost
)
599 if (IS_DEBUG_OSPF_EVENT
)
600 zlog_debug ("ospf_abr_update_aggregate(): update to %d", or->cost
);
602 range
->cost
= or->cost
;
610 set_metric (struct ospf_lsa
*lsa
, u_int32_t metric
)
612 struct summary_lsa
*header
;
614 metric
= htonl (metric
);
615 mp
= (u_char
*) &metric
;
617 header
= (struct summary_lsa
*) lsa
->data
;
618 memcpy(header
->metric
, mp
, 3);
621 /* ospf_abr_translate_nssa */
623 ospf_abr_translate_nssa (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
625 /* Incoming Type-7 or later aggregated Type-7
627 * LSA is skipped if P-bit is off.
628 * LSA is aggregated if within range.
630 * The Type-7 is translated, Installed/Approved as a Type-5 into
631 * global LSDB, then Flooded through AS
633 * Later, any Unapproved Translated Type-5's are flushed/discarded
636 struct ospf_lsa
*old
= NULL
,
638 struct as_external_lsa
*ext7
;
639 struct prefix_ipv4 p
;
641 if (! CHECK_FLAG (lsa
->data
->options
, OSPF_OPTION_NP
))
643 if (IS_DEBUG_OSPF_NSSA
)
644 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
645 inet_ntoa (lsa
->data
->id
));
649 if (IS_DEBUG_OSPF_NSSA
)
650 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
651 inet_ntoa (lsa
->data
->id
));
653 ext7
= (struct as_external_lsa
*)(lsa
->data
);
654 p
.prefix
= lsa
->data
->id
;
655 p
.prefixlen
= ip_masklen (ext7
->mask
);
657 if (ext7
->e
[0].fwd_addr
.s_addr
== OSPF_DEFAULT_DESTINATION
)
659 if (IS_DEBUG_OSPF_NSSA
)
660 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, "
661 "Forward address is 0, NO Translation",
662 inet_ntoa (lsa
->data
->id
));
666 /* try find existing AS-External LSA for this prefix */
668 old
= ospf_external_info_find_lsa (area
->ospf
, &p
);
672 if (IS_DEBUG_OSPF_NSSA
)
673 zlog_debug ("ospf_abr_translate_nssa(): "
674 "found old translated LSA Id %s, refreshing",
675 inet_ntoa (old
->data
->id
));
678 new = ospf_translated_nssa_refresh (area
->ospf
, lsa
, old
);
681 if (IS_DEBUG_OSPF_NSSA
)
682 zlog_debug ("ospf_abr_translate_nssa(): "
683 "could not refresh translated LSA Id %s",
684 inet_ntoa (old
->data
->id
));
689 /* no existing external route for this LSA Id
690 * originate translated LSA
693 if ((new = ospf_translated_nssa_originate (area
->ospf
, lsa
))
696 if (IS_DEBUG_OSPF_NSSA
)
697 zlog_debug ("ospf_abr_translate_nssa(): Could not translate "
698 "Type-7 for %s to Type-5",
699 inet_ntoa (lsa
->data
->id
));
704 /* Area where Aggregate testing will be inserted, just like summary
706 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
712 ospf_abr_translate_nssa_range (struct prefix_ipv4
*p
, u_int32_t cost
)
714 /* The Type-7 is created from the aggregated prefix and forwarded
715 for lsa installation and flooding... to be added... */
719 ospf_abr_announce_network_to_area (struct prefix_ipv4
*p
, u_int32_t cost
,
720 struct ospf_area
*area
)
722 struct ospf_lsa
*lsa
, *old
= NULL
;
723 struct summary_lsa
*sl
= NULL
;
726 if (IS_DEBUG_OSPF_EVENT
)
727 zlog_debug ("ospf_abr_announce_network_to_area(): Start");
729 if (CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
730 full_cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
734 old
= ospf_lsa_lookup_by_prefix (area
->lsdb
, OSPF_SUMMARY_LSA
,
735 (struct prefix_ipv4
*) p
,
736 area
->ospf
->router_id
);
739 if (IS_DEBUG_OSPF_EVENT
)
740 zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
742 sl
= (struct summary_lsa
*) old
->data
;
744 if (IS_DEBUG_OSPF_EVENT
)
745 zlog_debug ("ospf_abr_announce_network_to_area(): "
746 "old metric: %d, new metric: %d",
747 GET_METRIC (sl
->metric
), cost
);
749 if ((GET_METRIC (sl
->metric
) == full_cost
) &&
750 ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0))
752 /* unchanged. simply reapprove it */
753 if (IS_DEBUG_OSPF_EVENT
)
754 zlog_debug ("ospf_abr_announce_network_to_area(): "
755 "old summary approved");
756 SET_FLAG (old
->flags
, OSPF_LSA_APPROVED
);
760 /* LSA is changed, refresh it */
761 if (IS_DEBUG_OSPF_EVENT
)
762 zlog_debug ("ospf_abr_announce_network_to_area(): "
763 "refreshing summary");
764 set_metric (old
, full_cost
);
765 lsa
= ospf_lsa_refresh (area
->ospf
, old
);
769 char buf
[PREFIX2STR_BUFFER
];
771 prefix2str ((struct prefix
*) p
, buf
, sizeof(buf
));
772 zlog_warn ("%s: Could not refresh %s to %s",
775 inet_ntoa (area
->area_id
));
779 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
780 /* This will flood through area. */
785 if (IS_DEBUG_OSPF_EVENT
)
786 zlog_debug ("ospf_abr_announce_network_to_area(): "
787 "creating new summary");
788 lsa
= ospf_summary_lsa_originate ( (struct prefix_ipv4
*)p
, full_cost
, area
);
789 /* This will flood through area. */
793 char buf
[PREFIX2STR_BUFFER
];
795 prefix2str ((struct prefix
*)p
, buf
, sizeof(buf
));
796 zlog_warn ("%s: Could not originate %s to %s",
799 inet_ntoa (area
->area_id
));
803 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
804 if (IS_DEBUG_OSPF_EVENT
)
805 zlog_debug ("ospf_abr_announce_network_to_area(): "
806 "flooding new version of summary");
809 if (IS_DEBUG_OSPF_EVENT
)
810 zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
814 ospf_abr_nexthops_belong_to_area (struct ospf_route
*or,
815 struct ospf_area
*area
)
817 struct listnode
*node
, *nnode
;
818 struct ospf_path
*path
;
819 struct ospf_interface
*oi
;
821 for (ALL_LIST_ELEMENTS_RO (or->paths
, node
, path
))
822 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, nnode
, oi
))
823 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
830 ospf_abr_should_accept (struct prefix_ipv4
*p
, struct ospf_area
*area
)
832 if (IMPORT_NAME (area
))
834 if (IMPORT_LIST (area
) == NULL
)
835 IMPORT_LIST (area
) = access_list_lookup (AFI_IP
, IMPORT_NAME (area
));
837 if (IMPORT_LIST (area
))
838 if (access_list_apply (IMPORT_LIST (area
), p
) == FILTER_DENY
)
846 ospf_abr_plist_in_check (struct ospf_area
*area
, struct ospf_route
*or,
847 struct prefix_ipv4
*p
)
849 if (PREFIX_NAME_IN (area
))
851 if (PREFIX_LIST_IN (area
) == NULL
)
852 PREFIX_LIST_IN (area
) = prefix_list_lookup (AFI_IP
,
853 PREFIX_NAME_IN (area
));
854 if (PREFIX_LIST_IN (area
))
855 if (prefix_list_apply (PREFIX_LIST_IN (area
), p
) != PREFIX_PERMIT
)
862 ospf_abr_plist_out_check (struct ospf_area
*area
, struct ospf_route
*or,
863 struct prefix_ipv4
*p
)
865 if (PREFIX_NAME_OUT (area
))
867 if (PREFIX_LIST_OUT (area
) == NULL
)
868 PREFIX_LIST_OUT (area
) = prefix_list_lookup (AFI_IP
,
869 PREFIX_NAME_OUT (area
));
870 if (PREFIX_LIST_OUT (area
))
871 if (prefix_list_apply (PREFIX_LIST_OUT (area
), p
) != PREFIX_PERMIT
)
878 ospf_abr_announce_network (struct ospf
*ospf
,
879 struct prefix_ipv4
*p
, struct ospf_route
*or)
881 struct ospf_area_range
*range
;
882 struct ospf_area
*area
, *or_area
;
883 struct listnode
*node
;
885 if (IS_DEBUG_OSPF_EVENT
)
886 zlog_debug ("ospf_abr_announce_network(): Start");
888 or_area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
);
891 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
893 if (IS_DEBUG_OSPF_EVENT
)
894 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
895 inet_ntoa (area
->area_id
));
897 if (IPV4_ADDR_SAME (&or->u
.std
.area_id
, &area
->area_id
))
900 if (ospf_abr_nexthops_belong_to_area (or, area
))
903 if (!ospf_abr_should_accept (p
, area
))
905 if (IS_DEBUG_OSPF_EVENT
)
906 zlog_debug ("ospf_abr_announce_network(): "
907 "prefix %s/%d was denied by import-list",
908 inet_ntoa (p
->prefix
), p
->prefixlen
);
912 if (!ospf_abr_plist_in_check (area
, or, p
))
914 if (IS_DEBUG_OSPF_EVENT
)
915 zlog_debug ("ospf_abr_announce_network(): "
916 "prefix %s/%d was denied by prefix-list",
917 inet_ntoa (p
->prefix
), p
->prefixlen
);
921 if (area
->external_routing
!= OSPF_AREA_DEFAULT
&& area
->no_summary
)
923 if (IS_DEBUG_OSPF_EVENT
)
924 zlog_debug ("ospf_abr_announce_network(): "
925 "area %s is stub and no_summary",
926 inet_ntoa (area
->area_id
));
930 if (or->path_type
== OSPF_PATH_INTER_AREA
)
932 if (IS_DEBUG_OSPF_EVENT
)
933 zlog_debug ("ospf_abr_announce_network(): this is "
934 "inter-area route to %s/%d",
935 inet_ntoa (p
->prefix
), p
->prefixlen
);
937 if (!OSPF_IS_AREA_BACKBONE (area
))
938 ospf_abr_announce_network_to_area (p
, or->cost
, area
);
941 if (or->path_type
== OSPF_PATH_INTRA_AREA
)
943 if (IS_DEBUG_OSPF_EVENT
)
944 zlog_debug ("ospf_abr_announce_network(): "
945 "this is intra-area route to %s/%d",
946 inet_ntoa (p
->prefix
), p
->prefixlen
);
947 if ((range
= ospf_area_range_match (or_area
, p
))
948 && !ospf_area_is_transit (area
))
949 ospf_abr_update_aggregate (range
, or, area
);
951 ospf_abr_announce_network_to_area (p
, or->cost
, area
);
957 ospf_abr_should_announce (struct ospf
*ospf
,
958 struct prefix_ipv4
*p
, struct ospf_route
*or)
960 struct ospf_area
*area
;
962 area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
);
966 if (EXPORT_NAME (area
))
968 if (EXPORT_LIST (area
) == NULL
)
969 EXPORT_LIST (area
) = access_list_lookup (AFI_IP
, EXPORT_NAME (area
));
971 if (EXPORT_LIST (area
))
972 if (access_list_apply (EXPORT_LIST (area
), p
) == FILTER_DENY
)
980 ospf_abr_process_nssa_translates (struct ospf
*ospf
)
982 /* Scan through all NSSA_LSDB records for all areas;
984 If P-bit is on, translate all Type-7's to 5's and aggregate or
985 flood install as approved in Type-5 LSDB with XLATE Flag on
986 later, do same for all aggregates... At end, DISCARD all
987 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
988 struct listnode
*node
;
989 struct ospf_area
*area
;
990 struct route_node
*rn
;
991 struct ospf_lsa
*lsa
;
993 if (IS_DEBUG_OSPF_NSSA
)
994 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
996 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
998 if (! area
->NSSATranslatorState
)
999 continue; /* skip if not translator */
1001 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1002 continue; /* skip if not Nssa Area */
1004 if (IS_DEBUG_OSPF_NSSA
)
1005 zlog_debug ("ospf_abr_process_nssa_translates(): "
1006 "looking at area %s", inet_ntoa (area
->area_id
));
1008 LSDB_LOOP (NSSA_LSDB (area
), rn
, lsa
)
1009 ospf_abr_translate_nssa (area
, lsa
);
1012 if (IS_DEBUG_OSPF_NSSA
)
1013 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
1018 ospf_abr_process_network_rt (struct ospf
*ospf
,
1019 struct route_table
*rt
)
1021 struct ospf_area
*area
;
1022 struct ospf_route
*or;
1023 struct route_node
*rn
;
1025 if (IS_DEBUG_OSPF_EVENT
)
1026 zlog_debug ("ospf_abr_process_network_rt(): Start");
1028 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1030 if ((or = rn
->info
) == NULL
)
1033 if (!(area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
)))
1035 if (IS_DEBUG_OSPF_EVENT
)
1036 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
1037 inet_ntoa (or->u
.std
.area_id
));
1041 if (IS_DEBUG_OSPF_EVENT
)
1042 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
1043 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
1044 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
)
1046 if (IS_DEBUG_OSPF_EVENT
)
1047 zlog_debug ("ospf_abr_process_network_rt(): "
1048 "this is an External router, skipping");
1052 if (or->cost
>= OSPF_LS_INFINITY
)
1054 if (IS_DEBUG_OSPF_EVENT
)
1055 zlog_debug ("ospf_abr_process_network_rt():"
1056 " this route's cost is infinity, skipping");
1060 if (or->type
== OSPF_DESTINATION_DISCARD
)
1062 if (IS_DEBUG_OSPF_EVENT
)
1063 zlog_debug ("ospf_abr_process_network_rt():"
1064 " this is a discard entry, skipping");
1068 if (or->path_type
== OSPF_PATH_INTRA_AREA
&&
1069 !ospf_abr_should_announce (ospf
, (struct prefix_ipv4
*) &rn
->p
, or))
1071 if (IS_DEBUG_OSPF_EVENT
)
1072 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
1076 if (or->path_type
== OSPF_PATH_INTRA_AREA
&&
1077 !ospf_abr_plist_out_check (area
, or, (struct prefix_ipv4
*) &rn
->p
))
1079 if (IS_DEBUG_OSPF_EVENT
)
1080 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
1084 if ((or->path_type
== OSPF_PATH_INTER_AREA
) &&
1085 !OSPF_IS_AREA_ID_BACKBONE (or->u
.std
.area_id
))
1087 if (IS_DEBUG_OSPF_EVENT
)
1088 zlog_debug ("ospf_abr_process_network_rt():"
1089 " this is route is not backbone one, skipping");
1094 if ((ospf
->abr_type
== OSPF_ABR_CISCO
) ||
1095 (ospf
->abr_type
== OSPF_ABR_IBM
))
1097 if (!ospf_act_bb_connection (ospf
) &&
1098 or->path_type
!= OSPF_PATH_INTRA_AREA
)
1100 if (IS_DEBUG_OSPF_EVENT
)
1101 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
1102 "No BB connection, skip not intra-area routes");
1106 if (IS_DEBUG_OSPF_EVENT
)
1107 zlog_debug ("ospf_abr_process_network_rt(): announcing");
1108 ospf_abr_announce_network (ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
1111 if (IS_DEBUG_OSPF_EVENT
)
1112 zlog_debug ("ospf_abr_process_network_rt(): Stop");
1116 ospf_abr_announce_rtr_to_area (struct prefix_ipv4
*p
, u_int32_t cost
,
1117 struct ospf_area
*area
)
1119 struct ospf_lsa
*lsa
, *old
= NULL
;
1120 struct summary_lsa
*slsa
= NULL
;
1122 if (IS_DEBUG_OSPF_EVENT
)
1123 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
1125 old
= ospf_lsa_lookup_by_prefix (area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
,
1126 p
, area
->ospf
->router_id
);
1129 if (IS_DEBUG_OSPF_EVENT
)
1130 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
1131 slsa
= (struct summary_lsa
*) old
->data
;
1133 if (IS_DEBUG_OSPF_EVENT
)
1134 zlog_debug ("ospf_abr_announce_network_to_area(): "
1135 "old metric: %d, new metric: %d",
1136 GET_METRIC (slsa
->metric
), cost
);
1139 if (old
&& (GET_METRIC (slsa
->metric
) == cost
) &&
1140 ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0))
1142 if (IS_DEBUG_OSPF_EVENT
)
1143 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
1144 SET_FLAG (old
->flags
, OSPF_LSA_APPROVED
);
1148 if (IS_DEBUG_OSPF_EVENT
)
1149 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
1153 set_metric (old
, cost
);
1154 lsa
= ospf_lsa_refresh (area
->ospf
, old
);
1157 lsa
= ospf_summary_asbr_lsa_originate (p
, cost
, area
);
1160 char buf
[PREFIX2STR_BUFFER
];
1162 prefix2str ((struct prefix
*)p
, buf
, sizeof(buf
));
1163 zlog_warn ("%s: Could not refresh/originate %s to %s",
1166 inet_ntoa (area
->area_id
));
1170 if (IS_DEBUG_OSPF_EVENT
)
1171 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
1172 "flooding new version of summary");
1175 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1176 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1178 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1179 /* ospf_flood_through_area (area, NULL, lsa);*/
1182 if (IS_DEBUG_OSPF_EVENT
)
1183 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
1188 ospf_abr_announce_rtr (struct ospf
*ospf
,
1189 struct prefix_ipv4
*p
, struct ospf_route
*or)
1191 struct listnode
*node
;
1192 struct ospf_area
*area
;
1194 if (IS_DEBUG_OSPF_EVENT
)
1195 zlog_debug ("ospf_abr_announce_rtr(): Start");
1197 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1199 if (IS_DEBUG_OSPF_EVENT
)
1200 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
1201 inet_ntoa (area
->area_id
));
1203 if (IPV4_ADDR_SAME (&or->u
.std
.area_id
, &area
->area_id
))
1206 if (ospf_abr_nexthops_belong_to_area (or, area
))
1209 if (area
->external_routing
!= OSPF_AREA_DEFAULT
)
1211 if (IS_DEBUG_OSPF_EVENT
)
1212 zlog_debug ("ospf_abr_announce_rtr(): "
1213 "area %s doesn't support external routing",
1214 inet_ntoa(area
->area_id
));
1218 if (or->path_type
== OSPF_PATH_INTER_AREA
)
1220 if (IS_DEBUG_OSPF_EVENT
)
1221 zlog_debug ("ospf_abr_announce_rtr(): "
1222 "this is inter-area route to %s", inet_ntoa (p
->prefix
));
1223 if (!OSPF_IS_AREA_BACKBONE (area
))
1224 ospf_abr_announce_rtr_to_area (p
, or->cost
, area
);
1227 if (or->path_type
== OSPF_PATH_INTRA_AREA
)
1229 if (IS_DEBUG_OSPF_EVENT
)
1230 zlog_debug ("ospf_abr_announce_rtr(): "
1231 "this is intra-area route to %s", inet_ntoa (p
->prefix
));
1232 ospf_abr_announce_rtr_to_area (p
, or->cost
, area
);
1236 if (IS_DEBUG_OSPF_EVENT
)
1237 zlog_debug ("ospf_abr_announce_rtr(): Stop");
1241 ospf_abr_process_router_rt (struct ospf
*ospf
, struct route_table
*rt
)
1243 struct ospf_route
*or;
1244 struct route_node
*rn
;
1247 if (IS_DEBUG_OSPF_EVENT
)
1248 zlog_debug ("ospf_abr_process_router_rt(): Start");
1250 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1252 struct listnode
*node
, *nnode
;
1254 struct ospf_route
*best
= NULL
;
1256 if (rn
->info
== NULL
)
1261 if (IS_DEBUG_OSPF_EVENT
)
1262 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
1263 inet_ntoa (rn
->p
.u
.prefix4
));
1265 for (ALL_LIST_ELEMENTS (l
, node
, nnode
, or))
1267 if (!ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
))
1269 if (IS_DEBUG_OSPF_EVENT
)
1270 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
1271 inet_ntoa (or->u
.std
.area_id
));
1276 if (!CHECK_FLAG (or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
))
1278 if (IS_DEBUG_OSPF_EVENT
)
1279 zlog_debug ("ospf_abr_process_router_rt(): "
1280 "This is not an ASBR, skipping");
1286 best
= ospf_find_asbr_route (ospf
, rt
,
1287 (struct prefix_ipv4
*) &rn
->p
);
1296 if (IS_DEBUG_OSPF_EVENT
)
1297 zlog_debug ("ospf_abr_process_router_rt(): "
1298 "This route is not the best among possible, skipping");
1302 if (or->path_type
== OSPF_PATH_INTER_AREA
&&
1303 !OSPF_IS_AREA_ID_BACKBONE (or->u
.std
.area_id
))
1305 if (IS_DEBUG_OSPF_EVENT
)
1306 zlog_debug ("ospf_abr_process_router_rt(): "
1307 "This route is not a backbone one, skipping");
1311 if (or->cost
>= OSPF_LS_INFINITY
)
1313 if (IS_DEBUG_OSPF_EVENT
)
1314 zlog_debug ("ospf_abr_process_router_rt(): "
1315 "This route has LS_INFINITY metric, skipping");
1319 if (ospf
->abr_type
== OSPF_ABR_CISCO
1320 || ospf
->abr_type
== OSPF_ABR_IBM
)
1321 if (!ospf_act_bb_connection (ospf
)
1322 && or->path_type
!= OSPF_PATH_INTRA_AREA
)
1324 if (IS_DEBUG_OSPF_EVENT
)
1325 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
1326 "No BB connection, skip not intra-area routes");
1330 ospf_abr_announce_rtr (ospf
, (struct prefix_ipv4
*) &rn
->p
, or);
1336 if (IS_DEBUG_OSPF_EVENT
)
1337 zlog_debug ("ospf_abr_process_router_rt(): Stop");
1341 ospf_abr_unapprove_translates (struct ospf
*ospf
) /* For NSSA Translations */
1343 struct ospf_lsa
*lsa
;
1344 struct route_node
*rn
;
1346 if (IS_DEBUG_OSPF_NSSA
)
1347 zlog_debug ("ospf_abr_unapprove_translates(): Start");
1349 /* NSSA Translator is not checked, because it may have gone away,
1350 and we would want to flush any residuals anyway */
1352 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
1353 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
1355 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1356 if (IS_DEBUG_OSPF_NSSA
)
1357 zlog_debug ("ospf_abr_unapprove_translates(): "
1358 "approved unset on link id %s",
1359 inet_ntoa (lsa
->data
->id
));
1362 if (IS_DEBUG_OSPF_NSSA
)
1363 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
1367 ospf_abr_unapprove_summaries (struct ospf
*ospf
)
1369 struct listnode
*node
;
1370 struct ospf_area
*area
;
1371 struct route_node
*rn
;
1372 struct ospf_lsa
*lsa
;
1374 if (IS_DEBUG_OSPF_EVENT
)
1375 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
1377 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1379 if (IS_DEBUG_OSPF_EVENT
)
1380 zlog_debug ("ospf_abr_unapprove_summaries(): "
1381 "considering area %s",
1382 inet_ntoa (area
->area_id
));
1383 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
1384 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1386 if (IS_DEBUG_OSPF_EVENT
)
1387 zlog_debug ("ospf_abr_unapprove_summaries(): "
1388 "approved unset on summary link id %s",
1389 inet_ntoa (lsa
->data
->id
));
1390 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1393 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
1394 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1396 if (IS_DEBUG_OSPF_EVENT
)
1397 zlog_debug ("ospf_abr_unapprove_summaries(): "
1398 "approved unset on asbr-summary link id %s",
1399 inet_ntoa (lsa
->data
->id
));
1400 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1404 if (IS_DEBUG_OSPF_EVENT
)
1405 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
1409 ospf_abr_prepare_aggregates (struct ospf
*ospf
)
1411 struct listnode
*node
;
1412 struct route_node
*rn
;
1413 struct ospf_area_range
*range
;
1414 struct ospf_area
*area
;
1416 if (IS_DEBUG_OSPF_EVENT
)
1417 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
1419 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1421 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1422 if ((range
= rn
->info
) != NULL
)
1425 range
->specifics
= 0;
1429 if (IS_DEBUG_OSPF_EVENT
)
1430 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
1434 ospf_abr_announce_aggregates (struct ospf
*ospf
)
1436 struct ospf_area
*area
, *ar
;
1437 struct ospf_area_range
*range
;
1438 struct route_node
*rn
;
1440 struct listnode
*node
, *n
;
1442 if (IS_DEBUG_OSPF_EVENT
)
1443 zlog_debug ("ospf_abr_announce_aggregates(): Start");
1445 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1447 if (IS_DEBUG_OSPF_EVENT
)
1448 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
1449 inet_ntoa (area
->area_id
));
1451 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1452 if ((range
= rn
->info
))
1454 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1456 if (IS_DEBUG_OSPF_EVENT
)
1457 zlog_debug ("ospf_abr_announce_aggregates():"
1458 " discarding suppress-ranges");
1463 p
.u
.prefix4
= range
->addr
;
1464 p
.prefixlen
= range
->masklen
;
1466 if (IS_DEBUG_OSPF_EVENT
)
1467 zlog_debug ("ospf_abr_announce_aggregates():"
1468 " this is range: %s/%d",
1469 inet_ntoa (p
.u
.prefix4
), p
.prefixlen
);
1471 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
1474 p
.u
.prefix4
= range
->subst_addr
;
1475 p
.prefixlen
= range
->subst_masklen
;
1478 if (range
->specifics
)
1480 if (IS_DEBUG_OSPF_EVENT
)
1481 zlog_debug ("ospf_abr_announce_aggregates(): active range");
1483 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, n
, ar
))
1488 /* We do not check nexthops here, because
1489 intra-area routes can be associated with
1492 /* backbone routes are not summarized
1493 when announced into transit areas */
1495 if (ospf_area_is_transit (ar
) &&
1496 OSPF_IS_AREA_BACKBONE (area
))
1498 if (IS_DEBUG_OSPF_EVENT
)
1499 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
1500 "announcement of BB aggregate into"
1504 ospf_abr_announce_network_to_area ((struct prefix_ipv4
*)&p
, range
->cost
, ar
);
1510 if (IS_DEBUG_OSPF_EVENT
)
1511 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
1515 ospf_abr_send_nssa_aggregates (struct ospf
*ospf
) /* temporarily turned off */
1517 struct listnode
*node
; /*, n; */
1518 struct ospf_area
*area
; /*, *ar; */
1519 struct route_node
*rn
;
1520 struct ospf_area_range
*range
;
1521 struct prefix_ipv4 p
;
1523 if (IS_DEBUG_OSPF_NSSA
)
1524 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
1526 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1528 if (! area
->NSSATranslatorState
)
1531 if (IS_DEBUG_OSPF_NSSA
)
1532 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
1533 inet_ntoa (area
->area_id
));
1535 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1537 if (rn
->info
== NULL
)
1542 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1544 if (IS_DEBUG_OSPF_NSSA
)
1545 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1546 " discarding suppress-ranges");
1551 p
.prefix
= range
->addr
;
1552 p
.prefixlen
= range
->masklen
;
1554 if (IS_DEBUG_OSPF_NSSA
)
1555 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1556 " this is range: %s/%d",
1557 inet_ntoa (p
.prefix
), p
.prefixlen
);
1559 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
1562 p
.prefix
= range
->subst_addr
;
1563 p
.prefixlen
= range
->subst_masklen
;
1566 if (range
->specifics
)
1568 if (IS_DEBUG_OSPF_NSSA
)
1569 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
1571 /* Fetch LSA-Type-7 from aggregate prefix, and then
1572 * translate, Install (as Type-5), Approve, and Flood
1574 ospf_abr_translate_nssa_range (&p
, range
->cost
);
1576 } /* all area ranges*/
1579 if (IS_DEBUG_OSPF_NSSA
)
1580 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
1584 ospf_abr_announce_stub_defaults (struct ospf
*ospf
)
1586 struct listnode
*node
;
1587 struct ospf_area
*area
;
1588 struct prefix_ipv4 p
;
1590 if (! IS_OSPF_ABR (ospf
))
1593 if (IS_DEBUG_OSPF_EVENT
)
1594 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
1597 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1600 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1602 if (IS_DEBUG_OSPF_EVENT
)
1603 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1604 inet_ntoa (area
->area_id
));
1606 if ( (area
->external_routing
!= OSPF_AREA_STUB
)
1607 && (area
->external_routing
!= OSPF_AREA_NSSA
)
1611 if (OSPF_IS_AREA_BACKBONE (area
))
1612 continue; /* Sanity Check */
1614 if (IS_DEBUG_OSPF_EVENT
)
1615 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1616 "announcing 0.0.0.0/0 to area %s",
1617 inet_ntoa (area
->area_id
));
1618 ospf_abr_announce_network_to_area (&p
, area
->default_cost
, area
);
1621 if (IS_DEBUG_OSPF_EVENT
)
1622 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
1626 ospf_abr_remove_unapproved_translates_apply (struct ospf
*ospf
,
1627 struct ospf_lsa
*lsa
)
1629 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1630 && ! CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1632 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1633 "removing unapproved translates, ID: %s",
1634 inet_ntoa (lsa
->data
->id
));
1636 /* FLUSH THROUGHOUT AS */
1637 ospf_lsa_flush_as (ospf
, lsa
);
1639 /* DISCARD from LSDB */
1645 ospf_abr_remove_unapproved_translates (struct ospf
*ospf
)
1647 struct route_node
*rn
;
1648 struct ospf_lsa
*lsa
;
1650 /* All AREA PROCESS should have APPROVED necessary LSAs */
1651 /* Remove any left over and not APPROVED */
1652 if (IS_DEBUG_OSPF_NSSA
)
1653 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
1655 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
1656 ospf_abr_remove_unapproved_translates_apply (ospf
, lsa
);
1658 if (IS_DEBUG_OSPF_NSSA
)
1659 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
1663 ospf_abr_remove_unapproved_summaries (struct ospf
*ospf
)
1665 struct listnode
*node
;
1666 struct ospf_area
*area
;
1667 struct route_node
*rn
;
1668 struct ospf_lsa
*lsa
;
1670 if (IS_DEBUG_OSPF_EVENT
)
1671 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
1673 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1675 if (IS_DEBUG_OSPF_EVENT
)
1676 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
1677 "looking at area %s", inet_ntoa (area
->area_id
));
1679 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
1680 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1681 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1682 ospf_lsa_flush_area (lsa
, area
);
1684 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
1685 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1686 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1687 ospf_lsa_flush_area (lsa
, area
);
1690 if (IS_DEBUG_OSPF_EVENT
)
1691 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
1695 ospf_abr_manage_discard_routes (struct ospf
*ospf
)
1697 struct listnode
*node
, *nnode
;
1698 struct route_node
*rn
;
1699 struct ospf_area
*area
;
1700 struct ospf_area_range
*range
;
1702 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
1703 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1704 if ((range
= rn
->info
) != NULL
)
1705 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1707 if (range
->specifics
)
1708 ospf_add_discard_route (ospf
->new_table
, area
,
1709 (struct prefix_ipv4
*) &rn
->p
);
1711 ospf_delete_discard_route (ospf
->new_table
,
1712 (struct prefix_ipv4
*) &rn
->p
);
1716 /* This is the function taking care about ABR NSSA, i.e. NSSA
1717 Translator, -LSA aggregation and flooding. For all NSSAs
1719 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1720 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1723 Any received Type-5s are legal for an ABR, else illegal for IR.
1724 Received Type-7s are installed, by area, with incoming P-bit. They
1725 are flooded; if the Elected NSSA Translator, then P-bit off.
1727 Additionally, this ABR will place "translated type-7's" into the
1728 Type-5 LSDB in order to keep track of APPROVAL or not.
1730 It will scan through every area, looking for Type-7 LSAs with P-Bit
1731 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1732 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1735 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1736 left over are FLUSHED and DISCARDED.
1738 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1739 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1742 ospf_abr_nssa_task (struct ospf
*ospf
) /* called only if any_nssa */
1744 if (IS_DEBUG_OSPF_NSSA
)
1745 zlog_debug ("Check for NSSA-ABR Tasks():");
1747 if (! IS_OSPF_ABR (ospf
))
1750 if (! ospf
->anyNSSA
)
1753 /* Each area must confirm TranslatorRole */
1754 if (IS_DEBUG_OSPF_NSSA
)
1755 zlog_debug ("ospf_abr_nssa_task(): Start");
1757 /* For all Global Entries flagged "local-translate", unset APPROVED */
1758 if (IS_DEBUG_OSPF_NSSA
)
1759 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
1761 ospf_abr_unapprove_translates (ospf
);
1763 /* RESET all Ranges in every Area, same as summaries */
1764 if (IS_DEBUG_OSPF_NSSA
)
1765 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
1766 ospf_abr_prepare_aggregates (ospf
); /*TURNED OFF just for now */
1768 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1769 * Aggregate as Type-7
1770 * Install or Approve in Type-5 Global LSDB
1772 if (IS_DEBUG_OSPF_NSSA
)
1773 zlog_debug ("ospf_abr_nssa_task(): process translates");
1774 ospf_abr_process_nssa_translates (ospf
);
1776 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1778 * Scan Type-7's for aggregates, translate to Type-5's,
1779 * Install/Flood/Approve
1781 if (IS_DEBUG_OSPF_NSSA
)
1782 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1783 ospf_abr_send_nssa_aggregates (ospf
); /*TURNED OFF FOR NOW */
1785 /* Send any NSSA defaults as Type-5
1786 *if (IS_DEBUG_OSPF_NSSA)
1787 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1788 *ospf_abr_announce_nssa_defaults (ospf);
1789 * havnt a clue what above is supposed to do.
1792 /* Flush any unapproved previous translates from Global Data Base */
1793 if (IS_DEBUG_OSPF_NSSA
)
1794 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
1795 ospf_abr_remove_unapproved_translates (ospf
);
1797 ospf_abr_manage_discard_routes (ospf
); /* same as normal...discard */
1799 if (IS_DEBUG_OSPF_NSSA
)
1800 zlog_debug ("ospf_abr_nssa_task(): Stop");
1803 /* This is the function taking care about ABR stuff, i.e.
1804 summary-LSA origination and flooding. */
1806 ospf_abr_task (struct ospf
*ospf
)
1808 if (IS_DEBUG_OSPF_EVENT
)
1809 zlog_debug ("ospf_abr_task(): Start");
1811 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
)
1813 if (IS_DEBUG_OSPF_EVENT
)
1814 zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
1818 if (IS_DEBUG_OSPF_EVENT
)
1819 zlog_debug ("ospf_abr_task(): unapprove summaries");
1820 ospf_abr_unapprove_summaries (ospf
);
1822 if (IS_DEBUG_OSPF_EVENT
)
1823 zlog_debug ("ospf_abr_task(): prepare aggregates");
1824 ospf_abr_prepare_aggregates (ospf
);
1826 if (IS_OSPF_ABR (ospf
))
1828 if (IS_DEBUG_OSPF_EVENT
)
1829 zlog_debug ("ospf_abr_task(): process network RT");
1830 ospf_abr_process_network_rt (ospf
, ospf
->new_table
);
1832 if (IS_DEBUG_OSPF_EVENT
)
1833 zlog_debug ("ospf_abr_task(): process router RT");
1834 ospf_abr_process_router_rt (ospf
, ospf
->new_rtrs
);
1836 if (IS_DEBUG_OSPF_EVENT
)
1837 zlog_debug ("ospf_abr_task(): announce aggregates");
1838 ospf_abr_announce_aggregates (ospf
);
1840 if (IS_DEBUG_OSPF_EVENT
)
1841 zlog_debug ("ospf_abr_task(): announce stub defaults");
1842 ospf_abr_announce_stub_defaults (ospf
);
1845 if (IS_DEBUG_OSPF_EVENT
)
1846 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
1847 ospf_abr_remove_unapproved_summaries (ospf
);
1849 ospf_abr_manage_discard_routes (ospf
);
1851 if (IS_DEBUG_OSPF_EVENT
)
1852 zlog_debug ("ospf_abr_task(): Stop");
1856 ospf_abr_task_timer (struct thread
*thread
)
1858 struct ospf
*ospf
= THREAD_ARG (thread
);
1860 ospf
->t_abr_task
= 0;
1862 if (IS_DEBUG_OSPF_EVENT
)
1863 zlog_debug ("Running ABR task on timer");
1865 ospf_check_abr_status (ospf
);
1866 ospf_abr_nssa_check_status (ospf
);
1868 ospf_abr_task (ospf
);
1869 ospf_abr_nssa_task (ospf
); /* if nssa-abr, then scan Type-7 LSDB */
1875 ospf_schedule_abr_task (struct ospf
*ospf
)
1877 if (IS_DEBUG_OSPF_EVENT
)
1878 zlog_debug ("Scheduling ABR task");
1880 thread_add_timer(master
, ospf_abr_task_timer
, ospf
, OSPF_ABR_TASK_DELAY
,