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
;
199 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
201 area
= ospf_area_get (ospf
, area_id
, ret
);
205 range
= ospf_area_range_lookup (area
, p
);
208 if ((CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
209 && !CHECK_FLAG (advertise
, OSPF_AREA_RANGE_ADVERTISE
))
210 || (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
211 && CHECK_FLAG (advertise
, OSPF_AREA_RANGE_ADVERTISE
)))
212 ospf_schedule_abr_task (ospf
);
216 range
= ospf_area_range_new (p
);
217 ospf_area_range_add (area
, range
);
218 ospf_schedule_abr_task (ospf
);
221 if (CHECK_FLAG (advertise
, OSPF_AREA_RANGE_ADVERTISE
))
222 SET_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
224 UNSET_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
230 ospf_area_range_cost_set (struct ospf
*ospf
, struct in_addr area_id
,
231 struct prefix_ipv4
*p
, u_int32_t cost
)
233 struct ospf_area
*area
;
234 struct ospf_area_range
*range
;
235 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
237 area
= ospf_area_get (ospf
, area_id
, ret
);
241 range
= ospf_area_range_lookup (area
, p
);
245 if (range
->cost_config
!= cost
)
247 range
->cost_config
= cost
;
248 if (ospf_area_range_active (range
))
249 ospf_schedule_abr_task (ospf
);
256 ospf_area_range_unset (struct ospf
*ospf
, struct in_addr area_id
,
257 struct prefix_ipv4
*p
)
259 struct ospf_area
*area
;
260 struct route_node
*rn
;
262 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
266 rn
= route_node_lookup (area
->ranges
, (struct prefix
*)p
);
270 if (ospf_area_range_active (rn
->info
))
271 ospf_schedule_abr_task (ospf
);
273 ospf_area_range_delete (area
, rn
);
279 ospf_area_range_substitute_set (struct ospf
*ospf
, struct in_addr area_id
,
280 struct prefix_ipv4
*p
, struct prefix_ipv4
*s
)
282 struct ospf_area
*area
;
283 struct ospf_area_range
*range
;
284 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
286 area
= ospf_area_get (ospf
, area_id
, ret
);
287 range
= ospf_area_range_lookup (area
, p
);
291 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
) ||
292 !CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
293 ospf_schedule_abr_task (ospf
);
297 range
= ospf_area_range_new (p
);
298 ospf_area_range_add (area
, range
);
299 ospf_schedule_abr_task (ospf
);
302 SET_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
303 SET_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
304 range
->subst_addr
= s
->prefix
;
305 range
->subst_masklen
= s
->prefixlen
;
311 ospf_area_range_substitute_unset (struct ospf
*ospf
, struct in_addr area_id
,
312 struct prefix_ipv4
*p
)
314 struct ospf_area
*area
;
315 struct ospf_area_range
*range
;
317 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
321 range
= ospf_area_range_lookup (area
, p
);
325 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
326 if (ospf_area_range_active (range
))
327 ospf_schedule_abr_task (ospf
);
329 UNSET_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
330 range
->subst_addr
.s_addr
= 0;
331 range
->subst_masklen
= 0;
337 ospf_act_bb_connection (struct ospf
*ospf
)
339 if (ospf
->backbone
== NULL
)
342 return ospf
->backbone
->full_nbrs
;
345 /* Determine whether this router is elected translator or not for area */
347 ospf_abr_nssa_am_elected (struct ospf_area
*area
)
349 struct route_node
*rn
;
350 struct ospf_lsa
*lsa
;
351 struct router_lsa
*rlsa
;
352 struct in_addr
*best
= NULL
;
354 LSDB_LOOP ( ROUTER_LSDB (area
), rn
, lsa
)
358 || (lsa
->data
->type
!= OSPF_ROUTER_LSA
)
359 || IS_LSA_SELF (lsa
))
362 rlsa
= (struct router_lsa
*) lsa
->data
;
364 /* ignore non-ABR routers */
365 if (!IS_ROUTER_LSA_BORDER (rlsa
))
368 /* Router has Nt flag - always translate */
369 if (IS_ROUTER_LSA_NT (rlsa
))
371 if (IS_DEBUG_OSPF_NSSA
)
372 zlog_debug ("ospf_abr_nssa_am_elected: "
373 "router %s asserts Nt",
374 inet_ntoa (lsa
->data
->id
) );
379 best
= &lsa
->data
->id
;
381 if (IPV4_ADDR_CMP (&best
->s_addr
, &lsa
->data
->id
.s_addr
) < 0)
382 best
= &lsa
->data
->id
;
385 if (IS_DEBUG_OSPF_NSSA
)
386 zlog_debug ("ospf_abr_nssa_am_elected: best electable ABR is: %s",
387 (best
) ? inet_ntoa (*best
) : "<none>" );
392 if (IPV4_ADDR_CMP (&best
->s_addr
, &area
->ospf
->router_id
.s_addr
) < 0)
398 /* Check NSSA ABR status
399 * assumes there are nssa areas
402 ospf_abr_nssa_check_status (struct ospf
*ospf
)
404 struct ospf_area
*area
;
405 struct listnode
*lnode
, *nnode
;
407 for (ALL_LIST_ELEMENTS (ospf
->areas
, lnode
, nnode
, area
))
409 u_char old_state
= area
->NSSATranslatorState
;
411 if (area
->external_routing
!= OSPF_AREA_NSSA
)
414 if (IS_DEBUG_OSPF (nssa
, NSSA
))
415 zlog_debug ("ospf_abr_nssa_check_status: "
417 inet_ntoa (area
->area_id
));
419 if (!IS_OSPF_ABR (area
->ospf
))
421 if (IS_DEBUG_OSPF (nssa
, NSSA
))
422 zlog_debug ("ospf_abr_nssa_check_status: "
424 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
428 switch (area
->NSSATranslatorRole
)
430 case OSPF_NSSA_ROLE_NEVER
:
431 /* We never Translate Type-7 LSA. */
432 /* TODO: check previous state and flush? */
433 if (IS_DEBUG_OSPF (nssa
, NSSA
))
434 zlog_debug ("ospf_abr_nssa_check_status: "
436 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
439 case OSPF_NSSA_ROLE_ALWAYS
:
440 /* We always translate if we are an ABR
441 * TODO: originate new LSAs if state change?
442 * or let the nssa abr task take care of it?
444 if (IS_DEBUG_OSPF (nssa
, NSSA
))
445 zlog_debug ("ospf_abr_nssa_check_status: "
447 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_ENABLED
;
450 case OSPF_NSSA_ROLE_CANDIDATE
:
451 /* We are a candidate for Translation */
452 if (ospf_abr_nssa_am_elected (area
) > 0)
454 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_ENABLED
;
455 if (IS_DEBUG_OSPF (nssa
, NSSA
))
456 zlog_debug ("ospf_abr_nssa_check_status: "
457 "elected translator");
461 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
462 if (IS_DEBUG_OSPF (nssa
, NSSA
))
463 zlog_debug ("ospf_abr_nssa_check_status: " "not elected");
469 * All NSSA border routers must set the E-bit in the Type-1 router-LSAs
470 * of their directly attached non-stub areas, even when they are not
473 if (old_state
!= area
->NSSATranslatorState
)
475 if (old_state
== OSPF_NSSA_TRANSLATE_DISABLED
)
476 ospf_asbr_status_update (ospf
, ++ospf
->redistribute
);
477 else if (area
->NSSATranslatorState
== OSPF_NSSA_TRANSLATE_DISABLED
)
478 ospf_asbr_status_update (ospf
, --ospf
->redistribute
);
483 /* Check area border router status. */
485 ospf_check_abr_status (struct ospf
*ospf
)
487 struct ospf_area
*area
;
488 struct listnode
*node
, *nnode
;
489 int bb_configured
= 0;
490 int bb_act_attached
= 0;
491 int areas_configured
= 0;
492 int areas_act_attached
= 0;
493 u_char new_flags
= ospf
->flags
;
495 if (IS_DEBUG_OSPF_EVENT
)
496 zlog_debug ("ospf_check_abr_status(): Start");
498 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
500 if (listcount (area
->oiflist
))
504 if (OSPF_IS_AREA_BACKBONE (area
))
508 if (ospf_area_actively_attached (area
))
510 areas_act_attached
++;
512 if (OSPF_IS_AREA_BACKBONE (area
))
517 if (IS_DEBUG_OSPF_EVENT
)
519 zlog_debug ("ospf_check_abr_status(): looked through areas");
520 zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured
);
521 zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
523 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
525 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
529 switch (ospf
->abr_type
)
531 case OSPF_ABR_SHORTCUT
:
533 if (areas_act_attached
> 1)
534 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
536 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
540 if ((areas_act_attached
> 1) && bb_configured
)
541 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
543 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
547 if ((areas_configured
> 1) && bb_act_attached
)
548 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
550 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
556 if (new_flags
!= ospf
->flags
)
558 ospf_spf_calculate_schedule (ospf
, SPF_FLAG_ABR_STATUS_CHANGE
);
559 if (IS_DEBUG_OSPF_EVENT
)
560 zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags
);
561 ospf
->flags
= new_flags
;
562 ospf_router_lsa_update (ospf
);
567 ospf_abr_update_aggregate (struct ospf_area_range
*range
,
568 struct ospf_route
*or, struct ospf_area
*area
)
570 if (IS_DEBUG_OSPF_EVENT
)
571 zlog_debug ("ospf_abr_update_aggregate(): Start");
573 if (CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
) &&
574 (range
->cost
!= OSPF_STUB_MAX_METRIC_SUMMARY_COST
))
576 range
->cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
577 if (IS_DEBUG_OSPF_EVENT
)
578 zlog_debug ("ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
581 else if (range
->cost_config
!= OSPF_AREA_RANGE_COST_UNSPEC
)
583 if (IS_DEBUG_OSPF_EVENT
)
584 zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
587 range
->cost
= range
->cost_config
;
591 if (range
->specifics
== 0)
593 if (IS_DEBUG_OSPF_EVENT
)
594 zlog_debug ("ospf_abr_update_aggregate(): use or->cost %d",
597 range
->cost
= or->cost
; /* 1st time get 1st cost */
600 if (or->cost
> range
->cost
)
602 if (IS_DEBUG_OSPF_EVENT
)
603 zlog_debug ("ospf_abr_update_aggregate(): update to %d", or->cost
);
605 range
->cost
= or->cost
;
613 set_metric (struct ospf_lsa
*lsa
, u_int32_t metric
)
615 struct summary_lsa
*header
;
617 metric
= htonl (metric
);
618 mp
= (u_char
*) &metric
;
620 header
= (struct summary_lsa
*) lsa
->data
;
621 memcpy(header
->metric
, mp
, 3);
624 /* ospf_abr_translate_nssa */
626 ospf_abr_translate_nssa (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
628 /* Incoming Type-7 or later aggregated Type-7
630 * LSA is skipped if P-bit is off.
631 * LSA is aggregated if within range.
633 * The Type-7 is translated, Installed/Approved as a Type-5 into
634 * global LSDB, then Flooded through AS
636 * Later, any Unapproved Translated Type-5's are flushed/discarded
639 struct ospf_lsa
*old
= NULL
,
641 struct as_external_lsa
*ext7
;
642 struct prefix_ipv4 p
;
644 if (! CHECK_FLAG (lsa
->data
->options
, OSPF_OPTION_NP
))
646 if (IS_DEBUG_OSPF_NSSA
)
647 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
648 inet_ntoa (lsa
->data
->id
));
652 if (IS_DEBUG_OSPF_NSSA
)
653 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
654 inet_ntoa (lsa
->data
->id
));
656 ext7
= (struct as_external_lsa
*)(lsa
->data
);
657 p
.prefix
= lsa
->data
->id
;
658 p
.prefixlen
= ip_masklen (ext7
->mask
);
660 if (ext7
->e
[0].fwd_addr
.s_addr
== OSPF_DEFAULT_DESTINATION
)
662 if (IS_DEBUG_OSPF_NSSA
)
663 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, "
664 "Forward address is 0, NO Translation",
665 inet_ntoa (lsa
->data
->id
));
669 /* try find existing AS-External LSA for this prefix */
671 old
= ospf_external_info_find_lsa (area
->ospf
, &p
);
675 if (IS_DEBUG_OSPF_NSSA
)
676 zlog_debug ("ospf_abr_translate_nssa(): "
677 "found old translated LSA Id %s, refreshing",
678 inet_ntoa (old
->data
->id
));
681 new = ospf_translated_nssa_refresh (area
->ospf
, lsa
, old
);
684 if (IS_DEBUG_OSPF_NSSA
)
685 zlog_debug ("ospf_abr_translate_nssa(): "
686 "could not refresh translated LSA Id %s",
687 inet_ntoa (old
->data
->id
));
692 /* no existing external route for this LSA Id
693 * originate translated LSA
696 if ((new = ospf_translated_nssa_originate (area
->ospf
, lsa
))
699 if (IS_DEBUG_OSPF_NSSA
)
700 zlog_debug ("ospf_abr_translate_nssa(): Could not translate "
701 "Type-7 for %s to Type-5",
702 inet_ntoa (lsa
->data
->id
));
707 /* Area where Aggregate testing will be inserted, just like summary
709 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
715 ospf_abr_translate_nssa_range (struct prefix_ipv4
*p
, u_int32_t cost
)
717 /* The Type-7 is created from the aggregated prefix and forwarded
718 for lsa installation and flooding... to be added... */
722 ospf_abr_announce_network_to_area (struct prefix_ipv4
*p
, u_int32_t cost
,
723 struct ospf_area
*area
)
725 struct ospf_lsa
*lsa
, *old
= NULL
;
726 struct summary_lsa
*sl
= NULL
;
729 if (IS_DEBUG_OSPF_EVENT
)
730 zlog_debug ("ospf_abr_announce_network_to_area(): Start");
732 if (CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
733 full_cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
737 old
= ospf_lsa_lookup_by_prefix (area
->lsdb
, OSPF_SUMMARY_LSA
,
738 (struct prefix_ipv4
*) p
,
739 area
->ospf
->router_id
);
742 if (IS_DEBUG_OSPF_EVENT
)
743 zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
745 sl
= (struct summary_lsa
*) old
->data
;
747 if (IS_DEBUG_OSPF_EVENT
)
748 zlog_debug ("ospf_abr_announce_network_to_area(): "
749 "old metric: %d, new metric: %d",
750 GET_METRIC (sl
->metric
), cost
);
752 if ((GET_METRIC (sl
->metric
) == full_cost
) &&
753 ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0))
755 /* unchanged. simply reapprove it */
756 if (IS_DEBUG_OSPF_EVENT
)
757 zlog_debug ("ospf_abr_announce_network_to_area(): "
758 "old summary approved");
759 SET_FLAG (old
->flags
, OSPF_LSA_APPROVED
);
763 /* LSA is changed, refresh it */
764 if (IS_DEBUG_OSPF_EVENT
)
765 zlog_debug ("ospf_abr_announce_network_to_area(): "
766 "refreshing summary");
767 set_metric (old
, full_cost
);
768 lsa
= ospf_lsa_refresh (area
->ospf
, old
);
772 char buf
[PREFIX2STR_BUFFER
];
774 prefix2str ((struct prefix
*) p
, buf
, sizeof(buf
));
775 zlog_warn ("%s: Could not refresh %s to %s",
778 inet_ntoa (area
->area_id
));
782 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
783 /* This will flood through area. */
788 if (IS_DEBUG_OSPF_EVENT
)
789 zlog_debug ("ospf_abr_announce_network_to_area(): "
790 "creating new summary");
791 lsa
= ospf_summary_lsa_originate ( (struct prefix_ipv4
*)p
, full_cost
, area
);
792 /* This will flood through area. */
796 char buf
[PREFIX2STR_BUFFER
];
798 prefix2str ((struct prefix
*)p
, buf
, sizeof(buf
));
799 zlog_warn ("%s: Could not originate %s to %s",
802 inet_ntoa (area
->area_id
));
806 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
807 if (IS_DEBUG_OSPF_EVENT
)
808 zlog_debug ("ospf_abr_announce_network_to_area(): "
809 "flooding new version of summary");
812 if (IS_DEBUG_OSPF_EVENT
)
813 zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
817 ospf_abr_nexthops_belong_to_area (struct ospf_route
*or,
818 struct ospf_area
*area
)
820 struct listnode
*node
, *nnode
;
821 struct ospf_path
*path
;
822 struct ospf_interface
*oi
;
824 for (ALL_LIST_ELEMENTS_RO (or->paths
, node
, path
))
825 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, nnode
, oi
))
826 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
833 ospf_abr_should_accept (struct prefix_ipv4
*p
, struct ospf_area
*area
)
835 if (IMPORT_NAME (area
))
837 if (IMPORT_LIST (area
) == NULL
)
838 IMPORT_LIST (area
) = access_list_lookup (AFI_IP
, IMPORT_NAME (area
));
840 if (IMPORT_LIST (area
))
841 if (access_list_apply (IMPORT_LIST (area
), p
) == FILTER_DENY
)
849 ospf_abr_plist_in_check (struct ospf_area
*area
, struct ospf_route
*or,
850 struct prefix_ipv4
*p
)
852 if (PREFIX_NAME_IN (area
))
854 if (PREFIX_LIST_IN (area
) == NULL
)
855 PREFIX_LIST_IN (area
) = prefix_list_lookup (AFI_IP
,
856 PREFIX_NAME_IN (area
));
857 if (PREFIX_LIST_IN (area
))
858 if (prefix_list_apply (PREFIX_LIST_IN (area
), p
) != PREFIX_PERMIT
)
865 ospf_abr_plist_out_check (struct ospf_area
*area
, struct ospf_route
*or,
866 struct prefix_ipv4
*p
)
868 if (PREFIX_NAME_OUT (area
))
870 if (PREFIX_LIST_OUT (area
) == NULL
)
871 PREFIX_LIST_OUT (area
) = prefix_list_lookup (AFI_IP
,
872 PREFIX_NAME_OUT (area
));
873 if (PREFIX_LIST_OUT (area
))
874 if (prefix_list_apply (PREFIX_LIST_OUT (area
), p
) != PREFIX_PERMIT
)
881 ospf_abr_announce_network (struct ospf
*ospf
,
882 struct prefix_ipv4
*p
, struct ospf_route
*or)
884 struct ospf_area_range
*range
;
885 struct ospf_area
*area
, *or_area
;
886 struct listnode
*node
;
888 if (IS_DEBUG_OSPF_EVENT
)
889 zlog_debug ("ospf_abr_announce_network(): Start");
891 or_area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
);
894 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
896 if (IS_DEBUG_OSPF_EVENT
)
897 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
898 inet_ntoa (area
->area_id
));
900 if (IPV4_ADDR_SAME (&or->u
.std
.area_id
, &area
->area_id
))
903 if (ospf_abr_nexthops_belong_to_area (or, area
))
906 if (!ospf_abr_should_accept (p
, area
))
908 if (IS_DEBUG_OSPF_EVENT
)
909 zlog_debug ("ospf_abr_announce_network(): "
910 "prefix %s/%d was denied by import-list",
911 inet_ntoa (p
->prefix
), p
->prefixlen
);
915 if (!ospf_abr_plist_in_check (area
, or, p
))
917 if (IS_DEBUG_OSPF_EVENT
)
918 zlog_debug ("ospf_abr_announce_network(): "
919 "prefix %s/%d was denied by prefix-list",
920 inet_ntoa (p
->prefix
), p
->prefixlen
);
924 if (area
->external_routing
!= OSPF_AREA_DEFAULT
&& area
->no_summary
)
926 if (IS_DEBUG_OSPF_EVENT
)
927 zlog_debug ("ospf_abr_announce_network(): "
928 "area %s is stub and no_summary",
929 inet_ntoa (area
->area_id
));
933 if (or->path_type
== OSPF_PATH_INTER_AREA
)
935 if (IS_DEBUG_OSPF_EVENT
)
936 zlog_debug ("ospf_abr_announce_network(): this is "
937 "inter-area route to %s/%d",
938 inet_ntoa (p
->prefix
), p
->prefixlen
);
940 if (!OSPF_IS_AREA_BACKBONE (area
))
941 ospf_abr_announce_network_to_area (p
, or->cost
, area
);
944 if (or->path_type
== OSPF_PATH_INTRA_AREA
)
946 if (IS_DEBUG_OSPF_EVENT
)
947 zlog_debug ("ospf_abr_announce_network(): "
948 "this is intra-area route to %s/%d",
949 inet_ntoa (p
->prefix
), p
->prefixlen
);
950 if ((range
= ospf_area_range_match (or_area
, p
))
951 && !ospf_area_is_transit (area
))
952 ospf_abr_update_aggregate (range
, or, area
);
954 ospf_abr_announce_network_to_area (p
, or->cost
, area
);
960 ospf_abr_should_announce (struct ospf
*ospf
,
961 struct prefix_ipv4
*p
, struct ospf_route
*or)
963 struct ospf_area
*area
;
965 area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
);
969 if (EXPORT_NAME (area
))
971 if (EXPORT_LIST (area
) == NULL
)
972 EXPORT_LIST (area
) = access_list_lookup (AFI_IP
, EXPORT_NAME (area
));
974 if (EXPORT_LIST (area
))
975 if (access_list_apply (EXPORT_LIST (area
), p
) == FILTER_DENY
)
983 ospf_abr_process_nssa_translates (struct ospf
*ospf
)
985 /* Scan through all NSSA_LSDB records for all areas;
987 If P-bit is on, translate all Type-7's to 5's and aggregate or
988 flood install as approved in Type-5 LSDB with XLATE Flag on
989 later, do same for all aggregates... At end, DISCARD all
990 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
991 struct listnode
*node
;
992 struct ospf_area
*area
;
993 struct route_node
*rn
;
994 struct ospf_lsa
*lsa
;
996 if (IS_DEBUG_OSPF_NSSA
)
997 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
999 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1001 if (! area
->NSSATranslatorState
)
1002 continue; /* skip if not translator */
1004 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1005 continue; /* skip if not Nssa Area */
1007 if (IS_DEBUG_OSPF_NSSA
)
1008 zlog_debug ("ospf_abr_process_nssa_translates(): "
1009 "looking at area %s", inet_ntoa (area
->area_id
));
1011 LSDB_LOOP (NSSA_LSDB (area
), rn
, lsa
)
1012 ospf_abr_translate_nssa (area
, lsa
);
1015 if (IS_DEBUG_OSPF_NSSA
)
1016 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
1021 ospf_abr_process_network_rt (struct ospf
*ospf
,
1022 struct route_table
*rt
)
1024 struct ospf_area
*area
;
1025 struct ospf_route
*or;
1026 struct route_node
*rn
;
1028 if (IS_DEBUG_OSPF_EVENT
)
1029 zlog_debug ("ospf_abr_process_network_rt(): Start");
1031 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1033 if ((or = rn
->info
) == NULL
)
1036 if (!(area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
)))
1038 if (IS_DEBUG_OSPF_EVENT
)
1039 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
1040 inet_ntoa (or->u
.std
.area_id
));
1044 if (IS_DEBUG_OSPF_EVENT
)
1045 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
1046 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
1047 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
)
1049 if (IS_DEBUG_OSPF_EVENT
)
1050 zlog_debug ("ospf_abr_process_network_rt(): "
1051 "this is an External router, skipping");
1055 if (or->cost
>= OSPF_LS_INFINITY
)
1057 if (IS_DEBUG_OSPF_EVENT
)
1058 zlog_debug ("ospf_abr_process_network_rt():"
1059 " this route's cost is infinity, skipping");
1063 if (or->type
== OSPF_DESTINATION_DISCARD
)
1065 if (IS_DEBUG_OSPF_EVENT
)
1066 zlog_debug ("ospf_abr_process_network_rt():"
1067 " this is a discard entry, skipping");
1071 if (or->path_type
== OSPF_PATH_INTRA_AREA
&&
1072 !ospf_abr_should_announce (ospf
, (struct prefix_ipv4
*) &rn
->p
, or))
1074 if (IS_DEBUG_OSPF_EVENT
)
1075 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
1079 if (or->path_type
== OSPF_PATH_INTRA_AREA
&&
1080 !ospf_abr_plist_out_check (area
, or, (struct prefix_ipv4
*) &rn
->p
))
1082 if (IS_DEBUG_OSPF_EVENT
)
1083 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
1087 if ((or->path_type
== OSPF_PATH_INTER_AREA
) &&
1088 !OSPF_IS_AREA_ID_BACKBONE (or->u
.std
.area_id
))
1090 if (IS_DEBUG_OSPF_EVENT
)
1091 zlog_debug ("ospf_abr_process_network_rt():"
1092 " this is route is not backbone one, skipping");
1097 if ((ospf
->abr_type
== OSPF_ABR_CISCO
) ||
1098 (ospf
->abr_type
== OSPF_ABR_IBM
))
1100 if (!ospf_act_bb_connection (ospf
) &&
1101 or->path_type
!= OSPF_PATH_INTRA_AREA
)
1103 if (IS_DEBUG_OSPF_EVENT
)
1104 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
1105 "No BB connection, skip not intra-area routes");
1109 if (IS_DEBUG_OSPF_EVENT
)
1110 zlog_debug ("ospf_abr_process_network_rt(): announcing");
1111 ospf_abr_announce_network (ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
1114 if (IS_DEBUG_OSPF_EVENT
)
1115 zlog_debug ("ospf_abr_process_network_rt(): Stop");
1119 ospf_abr_announce_rtr_to_area (struct prefix_ipv4
*p
, u_int32_t cost
,
1120 struct ospf_area
*area
)
1122 struct ospf_lsa
*lsa
, *old
= NULL
;
1123 struct summary_lsa
*slsa
= NULL
;
1125 if (IS_DEBUG_OSPF_EVENT
)
1126 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
1128 old
= ospf_lsa_lookup_by_prefix (area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
,
1129 p
, area
->ospf
->router_id
);
1132 if (IS_DEBUG_OSPF_EVENT
)
1133 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
1134 slsa
= (struct summary_lsa
*) old
->data
;
1136 if (IS_DEBUG_OSPF_EVENT
)
1137 zlog_debug ("ospf_abr_announce_network_to_area(): "
1138 "old metric: %d, new metric: %d",
1139 GET_METRIC (slsa
->metric
), cost
);
1142 if (old
&& (GET_METRIC (slsa
->metric
) == cost
) &&
1143 ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0))
1145 if (IS_DEBUG_OSPF_EVENT
)
1146 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
1147 SET_FLAG (old
->flags
, OSPF_LSA_APPROVED
);
1151 if (IS_DEBUG_OSPF_EVENT
)
1152 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
1156 set_metric (old
, cost
);
1157 lsa
= ospf_lsa_refresh (area
->ospf
, old
);
1160 lsa
= ospf_summary_asbr_lsa_originate (p
, cost
, area
);
1163 char buf
[PREFIX2STR_BUFFER
];
1165 prefix2str ((struct prefix
*)p
, buf
, sizeof(buf
));
1166 zlog_warn ("%s: Could not refresh/originate %s to %s",
1169 inet_ntoa (area
->area_id
));
1173 if (IS_DEBUG_OSPF_EVENT
)
1174 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
1175 "flooding new version of summary");
1178 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1179 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1181 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1182 /* ospf_flood_through_area (area, NULL, lsa);*/
1185 if (IS_DEBUG_OSPF_EVENT
)
1186 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
1191 ospf_abr_announce_rtr (struct ospf
*ospf
,
1192 struct prefix_ipv4
*p
, struct ospf_route
*or)
1194 struct listnode
*node
;
1195 struct ospf_area
*area
;
1197 if (IS_DEBUG_OSPF_EVENT
)
1198 zlog_debug ("ospf_abr_announce_rtr(): Start");
1200 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1202 if (IS_DEBUG_OSPF_EVENT
)
1203 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
1204 inet_ntoa (area
->area_id
));
1206 if (IPV4_ADDR_SAME (&or->u
.std
.area_id
, &area
->area_id
))
1209 if (ospf_abr_nexthops_belong_to_area (or, area
))
1212 if (area
->external_routing
!= OSPF_AREA_DEFAULT
)
1214 if (IS_DEBUG_OSPF_EVENT
)
1215 zlog_debug ("ospf_abr_announce_rtr(): "
1216 "area %s doesn't support external routing",
1217 inet_ntoa(area
->area_id
));
1221 if (or->path_type
== OSPF_PATH_INTER_AREA
)
1223 if (IS_DEBUG_OSPF_EVENT
)
1224 zlog_debug ("ospf_abr_announce_rtr(): "
1225 "this is inter-area route to %s", inet_ntoa (p
->prefix
));
1226 if (!OSPF_IS_AREA_BACKBONE (area
))
1227 ospf_abr_announce_rtr_to_area (p
, or->cost
, area
);
1230 if (or->path_type
== OSPF_PATH_INTRA_AREA
)
1232 if (IS_DEBUG_OSPF_EVENT
)
1233 zlog_debug ("ospf_abr_announce_rtr(): "
1234 "this is intra-area route to %s", inet_ntoa (p
->prefix
));
1235 ospf_abr_announce_rtr_to_area (p
, or->cost
, area
);
1239 if (IS_DEBUG_OSPF_EVENT
)
1240 zlog_debug ("ospf_abr_announce_rtr(): Stop");
1244 ospf_abr_process_router_rt (struct ospf
*ospf
, struct route_table
*rt
)
1246 struct ospf_route
*or;
1247 struct route_node
*rn
;
1250 if (IS_DEBUG_OSPF_EVENT
)
1251 zlog_debug ("ospf_abr_process_router_rt(): Start");
1253 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1255 struct listnode
*node
, *nnode
;
1257 struct ospf_route
*best
= NULL
;
1259 if (rn
->info
== NULL
)
1264 if (IS_DEBUG_OSPF_EVENT
)
1265 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
1266 inet_ntoa (rn
->p
.u
.prefix4
));
1268 for (ALL_LIST_ELEMENTS (l
, node
, nnode
, or))
1270 if (!ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
))
1272 if (IS_DEBUG_OSPF_EVENT
)
1273 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
1274 inet_ntoa (or->u
.std
.area_id
));
1279 if (!CHECK_FLAG (or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
))
1281 if (IS_DEBUG_OSPF_EVENT
)
1282 zlog_debug ("ospf_abr_process_router_rt(): "
1283 "This is not an ASBR, skipping");
1289 best
= ospf_find_asbr_route (ospf
, rt
,
1290 (struct prefix_ipv4
*) &rn
->p
);
1299 if (IS_DEBUG_OSPF_EVENT
)
1300 zlog_debug ("ospf_abr_process_router_rt(): "
1301 "This route is not the best among possible, skipping");
1305 if (or->path_type
== OSPF_PATH_INTER_AREA
&&
1306 !OSPF_IS_AREA_ID_BACKBONE (or->u
.std
.area_id
))
1308 if (IS_DEBUG_OSPF_EVENT
)
1309 zlog_debug ("ospf_abr_process_router_rt(): "
1310 "This route is not a backbone one, skipping");
1314 if (or->cost
>= OSPF_LS_INFINITY
)
1316 if (IS_DEBUG_OSPF_EVENT
)
1317 zlog_debug ("ospf_abr_process_router_rt(): "
1318 "This route has LS_INFINITY metric, skipping");
1322 if (ospf
->abr_type
== OSPF_ABR_CISCO
1323 || ospf
->abr_type
== OSPF_ABR_IBM
)
1324 if (!ospf_act_bb_connection (ospf
)
1325 && or->path_type
!= OSPF_PATH_INTRA_AREA
)
1327 if (IS_DEBUG_OSPF_EVENT
)
1328 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
1329 "No BB connection, skip not intra-area routes");
1333 ospf_abr_announce_rtr (ospf
, (struct prefix_ipv4
*) &rn
->p
, or);
1339 if (IS_DEBUG_OSPF_EVENT
)
1340 zlog_debug ("ospf_abr_process_router_rt(): Stop");
1344 ospf_abr_unapprove_translates (struct ospf
*ospf
) /* For NSSA Translations */
1346 struct ospf_lsa
*lsa
;
1347 struct route_node
*rn
;
1349 if (IS_DEBUG_OSPF_NSSA
)
1350 zlog_debug ("ospf_abr_unapprove_translates(): Start");
1352 /* NSSA Translator is not checked, because it may have gone away,
1353 and we would want to flush any residuals anyway */
1355 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
1356 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
1358 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1359 if (IS_DEBUG_OSPF_NSSA
)
1360 zlog_debug ("ospf_abr_unapprove_translates(): "
1361 "approved unset on link id %s",
1362 inet_ntoa (lsa
->data
->id
));
1365 if (IS_DEBUG_OSPF_NSSA
)
1366 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
1370 ospf_abr_unapprove_summaries (struct ospf
*ospf
)
1372 struct listnode
*node
;
1373 struct ospf_area
*area
;
1374 struct route_node
*rn
;
1375 struct ospf_lsa
*lsa
;
1377 if (IS_DEBUG_OSPF_EVENT
)
1378 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
1380 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1382 if (IS_DEBUG_OSPF_EVENT
)
1383 zlog_debug ("ospf_abr_unapprove_summaries(): "
1384 "considering area %s",
1385 inet_ntoa (area
->area_id
));
1386 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
1387 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1389 if (IS_DEBUG_OSPF_EVENT
)
1390 zlog_debug ("ospf_abr_unapprove_summaries(): "
1391 "approved unset on summary link id %s",
1392 inet_ntoa (lsa
->data
->id
));
1393 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1396 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
1397 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1399 if (IS_DEBUG_OSPF_EVENT
)
1400 zlog_debug ("ospf_abr_unapprove_summaries(): "
1401 "approved unset on asbr-summary link id %s",
1402 inet_ntoa (lsa
->data
->id
));
1403 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1407 if (IS_DEBUG_OSPF_EVENT
)
1408 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
1412 ospf_abr_prepare_aggregates (struct ospf
*ospf
)
1414 struct listnode
*node
;
1415 struct route_node
*rn
;
1416 struct ospf_area_range
*range
;
1417 struct ospf_area
*area
;
1419 if (IS_DEBUG_OSPF_EVENT
)
1420 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
1422 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1424 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1425 if ((range
= rn
->info
) != NULL
)
1428 range
->specifics
= 0;
1432 if (IS_DEBUG_OSPF_EVENT
)
1433 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
1437 ospf_abr_announce_aggregates (struct ospf
*ospf
)
1439 struct ospf_area
*area
, *ar
;
1440 struct ospf_area_range
*range
;
1441 struct route_node
*rn
;
1443 struct listnode
*node
, *n
;
1445 if (IS_DEBUG_OSPF_EVENT
)
1446 zlog_debug ("ospf_abr_announce_aggregates(): Start");
1448 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1450 if (IS_DEBUG_OSPF_EVENT
)
1451 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
1452 inet_ntoa (area
->area_id
));
1454 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1455 if ((range
= rn
->info
))
1457 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1459 if (IS_DEBUG_OSPF_EVENT
)
1460 zlog_debug ("ospf_abr_announce_aggregates():"
1461 " discarding suppress-ranges");
1466 p
.u
.prefix4
= range
->addr
;
1467 p
.prefixlen
= range
->masklen
;
1469 if (IS_DEBUG_OSPF_EVENT
)
1470 zlog_debug ("ospf_abr_announce_aggregates():"
1471 " this is range: %s/%d",
1472 inet_ntoa (p
.u
.prefix4
), p
.prefixlen
);
1474 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
1477 p
.u
.prefix4
= range
->subst_addr
;
1478 p
.prefixlen
= range
->subst_masklen
;
1481 if (range
->specifics
)
1483 if (IS_DEBUG_OSPF_EVENT
)
1484 zlog_debug ("ospf_abr_announce_aggregates(): active range");
1486 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, n
, ar
))
1491 /* We do not check nexthops here, because
1492 intra-area routes can be associated with
1495 /* backbone routes are not summarized
1496 when announced into transit areas */
1498 if (ospf_area_is_transit (ar
) &&
1499 OSPF_IS_AREA_BACKBONE (area
))
1501 if (IS_DEBUG_OSPF_EVENT
)
1502 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
1503 "announcement of BB aggregate into"
1507 ospf_abr_announce_network_to_area ((struct prefix_ipv4
*)&p
, range
->cost
, ar
);
1513 if (IS_DEBUG_OSPF_EVENT
)
1514 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
1518 ospf_abr_send_nssa_aggregates (struct ospf
*ospf
) /* temporarily turned off */
1520 struct listnode
*node
; /*, n; */
1521 struct ospf_area
*area
; /*, *ar; */
1522 struct route_node
*rn
;
1523 struct ospf_area_range
*range
;
1524 struct prefix_ipv4 p
;
1526 if (IS_DEBUG_OSPF_NSSA
)
1527 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
1529 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1531 if (! area
->NSSATranslatorState
)
1534 if (IS_DEBUG_OSPF_NSSA
)
1535 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
1536 inet_ntoa (area
->area_id
));
1538 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1540 if (rn
->info
== NULL
)
1545 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1547 if (IS_DEBUG_OSPF_NSSA
)
1548 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1549 " discarding suppress-ranges");
1554 p
.prefix
= range
->addr
;
1555 p
.prefixlen
= range
->masklen
;
1557 if (IS_DEBUG_OSPF_NSSA
)
1558 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1559 " this is range: %s/%d",
1560 inet_ntoa (p
.prefix
), p
.prefixlen
);
1562 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
1565 p
.prefix
= range
->subst_addr
;
1566 p
.prefixlen
= range
->subst_masklen
;
1569 if (range
->specifics
)
1571 if (IS_DEBUG_OSPF_NSSA
)
1572 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
1574 /* Fetch LSA-Type-7 from aggregate prefix, and then
1575 * translate, Install (as Type-5), Approve, and Flood
1577 ospf_abr_translate_nssa_range (&p
, range
->cost
);
1579 } /* all area ranges*/
1582 if (IS_DEBUG_OSPF_NSSA
)
1583 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
1587 ospf_abr_announce_stub_defaults (struct ospf
*ospf
)
1589 struct listnode
*node
;
1590 struct ospf_area
*area
;
1591 struct prefix_ipv4 p
;
1593 if (! IS_OSPF_ABR (ospf
))
1596 if (IS_DEBUG_OSPF_EVENT
)
1597 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
1600 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1603 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1605 if (IS_DEBUG_OSPF_EVENT
)
1606 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1607 inet_ntoa (area
->area_id
));
1609 if ( (area
->external_routing
!= OSPF_AREA_STUB
)
1610 && (area
->external_routing
!= OSPF_AREA_NSSA
)
1614 if (OSPF_IS_AREA_BACKBONE (area
))
1615 continue; /* Sanity Check */
1617 if (IS_DEBUG_OSPF_EVENT
)
1618 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1619 "announcing 0.0.0.0/0 to area %s",
1620 inet_ntoa (area
->area_id
));
1621 ospf_abr_announce_network_to_area (&p
, area
->default_cost
, area
);
1624 if (IS_DEBUG_OSPF_EVENT
)
1625 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
1629 ospf_abr_remove_unapproved_translates_apply (struct ospf
*ospf
,
1630 struct ospf_lsa
*lsa
)
1632 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1633 && ! CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1635 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1636 "removing unapproved translates, ID: %s",
1637 inet_ntoa (lsa
->data
->id
));
1639 /* FLUSH THROUGHOUT AS */
1640 ospf_lsa_flush_as (ospf
, lsa
);
1642 /* DISCARD from LSDB */
1648 ospf_abr_remove_unapproved_translates (struct ospf
*ospf
)
1650 struct route_node
*rn
;
1651 struct ospf_lsa
*lsa
;
1653 /* All AREA PROCESS should have APPROVED necessary LSAs */
1654 /* Remove any left over and not APPROVED */
1655 if (IS_DEBUG_OSPF_NSSA
)
1656 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
1658 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
1659 ospf_abr_remove_unapproved_translates_apply (ospf
, lsa
);
1661 if (IS_DEBUG_OSPF_NSSA
)
1662 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
1666 ospf_abr_remove_unapproved_summaries (struct ospf
*ospf
)
1668 struct listnode
*node
;
1669 struct ospf_area
*area
;
1670 struct route_node
*rn
;
1671 struct ospf_lsa
*lsa
;
1673 if (IS_DEBUG_OSPF_EVENT
)
1674 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
1676 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1678 if (IS_DEBUG_OSPF_EVENT
)
1679 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
1680 "looking at area %s", inet_ntoa (area
->area_id
));
1682 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
1683 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1684 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1685 ospf_lsa_flush_area (lsa
, area
);
1687 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
1688 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1689 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1690 ospf_lsa_flush_area (lsa
, area
);
1693 if (IS_DEBUG_OSPF_EVENT
)
1694 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
1698 ospf_abr_manage_discard_routes (struct ospf
*ospf
)
1700 struct listnode
*node
, *nnode
;
1701 struct route_node
*rn
;
1702 struct ospf_area
*area
;
1703 struct ospf_area_range
*range
;
1705 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
1706 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1707 if ((range
= rn
->info
) != NULL
)
1708 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1710 if (range
->specifics
)
1711 ospf_add_discard_route (ospf
->new_table
, area
,
1712 (struct prefix_ipv4
*) &rn
->p
);
1714 ospf_delete_discard_route (ospf
->new_table
,
1715 (struct prefix_ipv4
*) &rn
->p
);
1719 /* This is the function taking care about ABR NSSA, i.e. NSSA
1720 Translator, -LSA aggregation and flooding. For all NSSAs
1722 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1723 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1726 Any received Type-5s are legal for an ABR, else illegal for IR.
1727 Received Type-7s are installed, by area, with incoming P-bit. They
1728 are flooded; if the Elected NSSA Translator, then P-bit off.
1730 Additionally, this ABR will place "translated type-7's" into the
1731 Type-5 LSDB in order to keep track of APPROVAL or not.
1733 It will scan through every area, looking for Type-7 LSAs with P-Bit
1734 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1735 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1738 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1739 left over are FLUSHED and DISCARDED.
1741 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1742 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1745 ospf_abr_nssa_task (struct ospf
*ospf
) /* called only if any_nssa */
1747 if (IS_DEBUG_OSPF_NSSA
)
1748 zlog_debug ("Check for NSSA-ABR Tasks():");
1750 if (! IS_OSPF_ABR (ospf
))
1753 if (! ospf
->anyNSSA
)
1756 /* Each area must confirm TranslatorRole */
1757 if (IS_DEBUG_OSPF_NSSA
)
1758 zlog_debug ("ospf_abr_nssa_task(): Start");
1760 /* For all Global Entries flagged "local-translate", unset APPROVED */
1761 if (IS_DEBUG_OSPF_NSSA
)
1762 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
1764 ospf_abr_unapprove_translates (ospf
);
1766 /* RESET all Ranges in every Area, same as summaries */
1767 if (IS_DEBUG_OSPF_NSSA
)
1768 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
1769 ospf_abr_prepare_aggregates (ospf
); /*TURNED OFF just for now */
1771 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1772 * Aggregate as Type-7
1773 * Install or Approve in Type-5 Global LSDB
1775 if (IS_DEBUG_OSPF_NSSA
)
1776 zlog_debug ("ospf_abr_nssa_task(): process translates");
1777 ospf_abr_process_nssa_translates (ospf
);
1779 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1781 * Scan Type-7's for aggregates, translate to Type-5's,
1782 * Install/Flood/Approve
1784 if (IS_DEBUG_OSPF_NSSA
)
1785 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1786 ospf_abr_send_nssa_aggregates (ospf
); /*TURNED OFF FOR NOW */
1788 /* Send any NSSA defaults as Type-5
1789 *if (IS_DEBUG_OSPF_NSSA)
1790 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1791 *ospf_abr_announce_nssa_defaults (ospf);
1792 * havnt a clue what above is supposed to do.
1795 /* Flush any unapproved previous translates from Global Data Base */
1796 if (IS_DEBUG_OSPF_NSSA
)
1797 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
1798 ospf_abr_remove_unapproved_translates (ospf
);
1800 ospf_abr_manage_discard_routes (ospf
); /* same as normal...discard */
1802 if (IS_DEBUG_OSPF_NSSA
)
1803 zlog_debug ("ospf_abr_nssa_task(): Stop");
1806 /* This is the function taking care about ABR stuff, i.e.
1807 summary-LSA origination and flooding. */
1809 ospf_abr_task (struct ospf
*ospf
)
1811 if (IS_DEBUG_OSPF_EVENT
)
1812 zlog_debug ("ospf_abr_task(): Start");
1814 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
)
1816 if (IS_DEBUG_OSPF_EVENT
)
1817 zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
1821 if (IS_DEBUG_OSPF_EVENT
)
1822 zlog_debug ("ospf_abr_task(): unapprove summaries");
1823 ospf_abr_unapprove_summaries (ospf
);
1825 if (IS_DEBUG_OSPF_EVENT
)
1826 zlog_debug ("ospf_abr_task(): prepare aggregates");
1827 ospf_abr_prepare_aggregates (ospf
);
1829 if (IS_OSPF_ABR (ospf
))
1831 if (IS_DEBUG_OSPF_EVENT
)
1832 zlog_debug ("ospf_abr_task(): process network RT");
1833 ospf_abr_process_network_rt (ospf
, ospf
->new_table
);
1835 if (IS_DEBUG_OSPF_EVENT
)
1836 zlog_debug ("ospf_abr_task(): process router RT");
1837 ospf_abr_process_router_rt (ospf
, ospf
->new_rtrs
);
1839 if (IS_DEBUG_OSPF_EVENT
)
1840 zlog_debug ("ospf_abr_task(): announce aggregates");
1841 ospf_abr_announce_aggregates (ospf
);
1843 if (IS_DEBUG_OSPF_EVENT
)
1844 zlog_debug ("ospf_abr_task(): announce stub defaults");
1845 ospf_abr_announce_stub_defaults (ospf
);
1848 if (IS_DEBUG_OSPF_EVENT
)
1849 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
1850 ospf_abr_remove_unapproved_summaries (ospf
);
1852 ospf_abr_manage_discard_routes (ospf
);
1854 if (IS_DEBUG_OSPF_EVENT
)
1855 zlog_debug ("ospf_abr_task(): Stop");
1859 ospf_abr_task_timer (struct thread
*thread
)
1861 struct ospf
*ospf
= THREAD_ARG (thread
);
1863 ospf
->t_abr_task
= 0;
1865 if (IS_DEBUG_OSPF_EVENT
)
1866 zlog_debug ("Running ABR task on timer");
1868 ospf_check_abr_status (ospf
);
1869 ospf_abr_nssa_check_status (ospf
);
1871 ospf_abr_task (ospf
);
1872 ospf_abr_nssa_task (ospf
); /* if nssa-abr, then scan Type-7 LSDB */
1878 ospf_schedule_abr_task (struct ospf
*ospf
)
1880 if (IS_DEBUG_OSPF_EVENT
)
1881 zlog_debug ("Scheduling ABR task");
1883 thread_add_timer(master
, ospf_abr_task_timer
, ospf
, OSPF_ABR_TASK_DELAY
,