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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
37 #include "ospfd/ospfd.h"
38 #include "ospfd/ospf_interface.h"
39 #include "ospfd/ospf_ism.h"
40 #include "ospfd/ospf_asbr.h"
41 #include "ospfd/ospf_lsa.h"
42 #include "ospfd/ospf_lsdb.h"
43 #include "ospfd/ospf_neighbor.h"
44 #include "ospfd/ospf_nsm.h"
45 #include "ospfd/ospf_spf.h"
46 #include "ospfd/ospf_route.h"
47 #include "ospfd/ospf_ia.h"
48 #include "ospfd/ospf_flood.h"
49 #include "ospfd/ospf_abr.h"
50 #include "ospfd/ospf_ase.h"
51 #include "ospfd/ospf_zebra.h"
52 #include "ospfd/ospf_dump.h"
54 static struct ospf_area_range
*
55 ospf_area_range_new (struct prefix_ipv4
*p
)
57 struct ospf_area_range
*range
;
59 range
= XCALLOC (MTYPE_OSPF_AREA_RANGE
, sizeof (struct ospf_area_range
));
60 range
->addr
= p
->prefix
;
61 range
->masklen
= p
->prefixlen
;
62 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
68 ospf_area_range_free (struct ospf_area_range
*range
)
70 XFREE (MTYPE_OSPF_AREA_RANGE
, range
);
74 ospf_area_range_add (struct ospf_area
*area
, struct ospf_area_range
*range
)
76 struct route_node
*rn
;
80 p
.prefixlen
= range
->masklen
;
81 p
.prefix
= range
->addr
;
83 rn
= route_node_get (area
->ranges
, (struct prefix
*)&p
);
85 route_unlock_node (rn
);
91 ospf_area_range_delete (struct ospf_area
*area
, struct ospf_area_range
*range
)
93 struct route_node
*rn
;
97 p
.prefixlen
= range
->masklen
;
98 p
.prefix
= range
->addr
;
100 rn
= route_node_lookup (area
->ranges
, (struct prefix
*)&p
);
103 ospf_area_range_free (rn
->info
);
105 route_unlock_node (rn
);
106 route_unlock_node (rn
);
110 struct ospf_area_range
*
111 ospf_area_range_lookup (struct ospf_area
*area
, struct prefix_ipv4
*p
)
113 struct route_node
*rn
;
115 rn
= route_node_lookup (area
->ranges
, (struct prefix
*)p
);
118 route_unlock_node (rn
);
124 struct ospf_area_range
*
125 ospf_area_range_lookup_next (struct ospf_area
*area
,
126 struct in_addr
*range_net
,
129 struct route_node
*rn
;
130 struct prefix_ipv4 p
;
131 struct ospf_area_range
*find
;
134 p
.prefixlen
= IPV4_MAX_BITLEN
;
135 p
.prefix
= *range_net
;
138 rn
= route_top (area
->ranges
);
141 rn
= route_node_get (area
->ranges
, (struct prefix
*) &p
);
142 rn
= route_next (rn
);
145 for (; rn
; rn
= route_next (rn
))
152 *range_net
= rn
->p
.u
.prefix4
;
153 route_unlock_node (rn
);
159 static struct ospf_area_range
*
160 ospf_area_range_match (struct ospf_area
*area
, struct prefix_ipv4
*p
)
162 struct route_node
*node
;
164 node
= route_node_match (area
->ranges
, (struct prefix
*) p
);
167 route_unlock_node (node
);
173 struct ospf_area_range
*
174 ospf_area_range_match_any (struct ospf
*ospf
, struct prefix_ipv4
*p
)
176 struct ospf_area_range
*range
;
177 struct ospf_area
*area
;
178 struct listnode
*node
;
180 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
181 if ((range
= ospf_area_range_match (area
, p
)))
188 ospf_area_range_active (struct ospf_area_range
*range
)
190 return range
->specifics
;
194 ospf_area_actively_attached (struct ospf_area
*area
)
196 return area
->act_ints
;
200 ospf_area_range_set (struct ospf
*ospf
, struct in_addr area_id
,
201 struct prefix_ipv4
*p
, int advertise
)
203 struct ospf_area
*area
;
204 struct ospf_area_range
*range
;
205 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
207 area
= ospf_area_get (ospf
, area_id
, ret
);
211 range
= ospf_area_range_lookup (area
, p
);
214 if ((CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
215 && !CHECK_FLAG (advertise
, OSPF_AREA_RANGE_ADVERTISE
))
216 || (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
217 && CHECK_FLAG (advertise
, OSPF_AREA_RANGE_ADVERTISE
)))
218 ospf_schedule_abr_task (ospf
);
222 range
= ospf_area_range_new (p
);
223 ospf_area_range_add (area
, range
);
224 ospf_schedule_abr_task (ospf
);
227 if (CHECK_FLAG (advertise
, OSPF_AREA_RANGE_ADVERTISE
))
228 SET_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
230 UNSET_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
236 ospf_area_range_cost_set (struct ospf
*ospf
, struct in_addr area_id
,
237 struct prefix_ipv4
*p
, u_int32_t cost
)
239 struct ospf_area
*area
;
240 struct ospf_area_range
*range
;
241 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
243 area
= ospf_area_get (ospf
, area_id
, ret
);
247 range
= ospf_area_range_lookup (area
, p
);
251 if (range
->cost_config
!= cost
)
253 range
->cost_config
= cost
;
254 if (ospf_area_range_active (range
))
255 ospf_schedule_abr_task (ospf
);
262 ospf_area_range_unset (struct ospf
*ospf
, struct in_addr area_id
,
263 struct prefix_ipv4
*p
)
265 struct ospf_area
*area
;
266 struct ospf_area_range
*range
;
268 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
272 range
= ospf_area_range_lookup (area
, p
);
276 if (ospf_area_range_active (range
))
277 ospf_schedule_abr_task (ospf
);
279 ospf_area_range_delete (area
, range
);
285 ospf_area_range_substitute_set (struct ospf
*ospf
, struct in_addr area_id
,
286 struct prefix_ipv4
*p
, struct prefix_ipv4
*s
)
288 struct ospf_area
*area
;
289 struct ospf_area_range
*range
;
290 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
292 area
= ospf_area_get (ospf
, area_id
, ret
);
293 range
= ospf_area_range_lookup (area
, p
);
297 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
) ||
298 !CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
299 ospf_schedule_abr_task (ospf
);
303 range
= ospf_area_range_new (p
);
304 ospf_area_range_add (area
, range
);
305 ospf_schedule_abr_task (ospf
);
308 SET_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
309 SET_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
310 range
->subst_addr
= s
->prefix
;
311 range
->subst_masklen
= s
->prefixlen
;
317 ospf_area_range_substitute_unset (struct ospf
*ospf
, struct in_addr area_id
,
318 struct prefix_ipv4
*p
)
320 struct ospf_area
*area
;
321 struct ospf_area_range
*range
;
323 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
327 range
= ospf_area_range_lookup (area
, p
);
331 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
332 if (ospf_area_range_active (range
))
333 ospf_schedule_abr_task (ospf
);
335 UNSET_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
336 range
->subst_addr
.s_addr
= 0;
337 range
->subst_masklen
= 0;
343 ospf_act_bb_connection (struct ospf
*ospf
)
345 if (ospf
->backbone
== NULL
)
348 return ospf
->backbone
->full_nbrs
;
351 /* Determine whether this router is elected translator or not for area */
353 ospf_abr_nssa_am_elected (struct ospf_area
*area
)
355 struct route_node
*rn
;
356 struct ospf_lsa
*lsa
;
357 struct router_lsa
*rlsa
;
358 struct in_addr
*best
= NULL
;
360 LSDB_LOOP ( ROUTER_LSDB (area
), rn
, lsa
)
364 || (lsa
->data
->type
!= OSPF_ROUTER_LSA
)
365 || IS_LSA_SELF (lsa
))
368 rlsa
= (struct router_lsa
*) lsa
->data
;
370 /* ignore non-ABR routers */
371 if (!IS_ROUTER_LSA_BORDER (rlsa
))
374 /* Router has Nt flag - always translate */
375 if (IS_ROUTER_LSA_NT (rlsa
))
377 if (IS_DEBUG_OSPF_NSSA
)
378 zlog_debug ("ospf_abr_nssa_am_elected: "
379 "router %s asserts Nt",
380 inet_ntoa (lsa
->data
->id
) );
385 best
= &lsa
->data
->id
;
387 if ( IPV4_ADDR_CMP (&best
, &lsa
->data
->id
) < 0)
388 best
= &lsa
->data
->id
;
391 if (IS_DEBUG_OSPF_NSSA
)
392 zlog_debug ("ospf_abr_nssa_am_elected: best electable ABR is: %s",
393 (best
) ? inet_ntoa (*best
) : "<none>" );
398 if ( IPV4_ADDR_CMP (&best
, &area
->ospf
->router_id
) < 0)
404 /* Check NSSA ABR status
405 * assumes there are nssa areas
408 ospf_abr_nssa_check_status (struct ospf
*ospf
)
410 struct ospf_area
*area
;
411 struct listnode
*lnode
, *nnode
;
413 for (ALL_LIST_ELEMENTS (ospf
->areas
, lnode
, nnode
, area
))
415 u_char old_state
= area
->NSSATranslatorState
;
417 if (area
->external_routing
!= OSPF_AREA_NSSA
)
420 if (IS_DEBUG_OSPF (nssa
, NSSA
))
421 zlog_debug ("ospf_abr_nssa_check_status: "
423 inet_ntoa (area
->area_id
));
425 if (!IS_OSPF_ABR (area
->ospf
))
427 if (IS_DEBUG_OSPF (nssa
, NSSA
))
428 zlog_debug ("ospf_abr_nssa_check_status: "
430 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
434 switch (area
->NSSATranslatorRole
)
436 case OSPF_NSSA_ROLE_NEVER
:
437 /* We never Translate Type-7 LSA. */
438 /* TODO: check previous state and flush? */
439 if (IS_DEBUG_OSPF (nssa
, NSSA
))
440 zlog_debug ("ospf_abr_nssa_check_status: "
442 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
445 case OSPF_NSSA_ROLE_ALWAYS
:
446 /* We always translate if we are an ABR
447 * TODO: originate new LSAs if state change?
448 * or let the nssa abr task take care of it?
450 if (IS_DEBUG_OSPF (nssa
, NSSA
))
451 zlog_debug ("ospf_abr_nssa_check_status: "
453 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_ENABLED
;
456 case OSPF_NSSA_ROLE_CANDIDATE
:
457 /* We are a candidate for Translation */
458 if (ospf_abr_nssa_am_elected (area
) > 0)
460 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_ENABLED
;
461 if (IS_DEBUG_OSPF (nssa
, NSSA
))
462 zlog_debug ("ospf_abr_nssa_check_status: "
463 "elected translator");
467 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
468 if (IS_DEBUG_OSPF (nssa
, NSSA
))
469 zlog_debug ("ospf_abr_nssa_check_status: " "not elected");
475 * All NSSA border routers must set the E-bit in the Type-1 router-LSAs
476 * of their directly attached non-stub areas, even when they are not
479 if (old_state
!= area
->NSSATranslatorState
)
481 if (old_state
== OSPF_NSSA_TRANSLATE_DISABLED
)
482 ospf_asbr_status_update (ospf
, ++ospf
->redistribute
);
483 else if (area
->NSSATranslatorState
== OSPF_NSSA_TRANSLATE_DISABLED
)
484 ospf_asbr_status_update (ospf
, --ospf
->redistribute
);
489 /* Check area border router status. */
491 ospf_check_abr_status (struct ospf
*ospf
)
493 struct ospf_area
*area
;
494 struct listnode
*node
, *nnode
;
495 int bb_configured
= 0;
496 int bb_act_attached
= 0;
497 int areas_configured
= 0;
498 int areas_act_attached
= 0;
499 u_char new_flags
= ospf
->flags
;
501 if (IS_DEBUG_OSPF_EVENT
)
502 zlog_debug ("ospf_check_abr_status(): Start");
504 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
506 if (listcount (area
->oiflist
))
510 if (OSPF_IS_AREA_BACKBONE (area
))
514 if (ospf_area_actively_attached (area
))
516 areas_act_attached
++;
518 if (OSPF_IS_AREA_BACKBONE (area
))
523 if (IS_DEBUG_OSPF_EVENT
)
525 zlog_debug ("ospf_check_abr_status(): looked through areas");
526 zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured
);
527 zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
529 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
531 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
535 switch (ospf
->abr_type
)
537 case OSPF_ABR_SHORTCUT
:
539 if (areas_act_attached
> 1)
540 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
542 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
546 if ((areas_act_attached
> 1) && bb_configured
)
547 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
549 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
553 if ((areas_configured
> 1) && bb_act_attached
)
554 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
556 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
562 if (new_flags
!= ospf
->flags
)
564 ospf_spf_calculate_schedule (ospf
);
565 if (IS_DEBUG_OSPF_EVENT
)
566 zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags
);
567 ospf
->flags
= new_flags
;
568 OSPF_TIMER_ON (ospf
->t_router_lsa_update
,
569 ospf_router_lsa_update_timer
, OSPF_LSA_UPDATE_DELAY
);
574 ospf_abr_update_aggregate (struct ospf_area_range
*range
,
575 struct ospf_route
*or)
577 if (IS_DEBUG_OSPF_EVENT
)
578 zlog_debug ("ospf_abr_update_aggregate(): Start");
580 if (range
->cost_config
!= OSPF_AREA_RANGE_COST_UNSPEC
)
582 if (IS_DEBUG_OSPF_EVENT
)
583 zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
586 range
->cost
= range
->cost_config
;
590 if (range
->specifics
== 0)
591 range
->cost
= or->cost
; /* 1st time get 1st cost */
593 if (or->cost
> range
->cost
)
595 if (IS_DEBUG_OSPF_EVENT
)
596 zlog_debug ("ospf_abr_update_aggregate(): largest cost, update");
598 range
->cost
= or->cost
;
606 set_metric (struct ospf_lsa
*lsa
, u_int32_t metric
)
608 struct summary_lsa
*header
;
610 metric
= htonl (metric
);
611 mp
= (u_char
*) &metric
;
613 header
= (struct summary_lsa
*) lsa
->data
;
614 memcpy(header
->metric
, mp
, 3);
618 ospf_abr_check_nssa_range (struct prefix_ipv4
*p
, u_int32_t cost
,
619 struct ospf_area
*area
)
621 /* The Type-7 is tested against the aggregated prefix and forwarded
622 for lsa installation and flooding */
626 /* ospf_abr_translate_nssa */
628 ospf_abr_translate_nssa (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
630 /* Incoming Type-7 or later aggregated Type-7
632 * LSA is skipped if P-bit is off.
633 * LSA is aggregated if within range.
635 * The Type-7 is translated, Installed/Approved as a Type-5 into
636 * global LSDB, then Flooded through AS
638 * Later, any Unapproved Translated Type-5's are flushed/discarded
641 struct ospf_lsa
*old
= NULL
,
643 struct as_external_lsa
*ext7
;
644 struct prefix_ipv4 p
;
646 if (! CHECK_FLAG (lsa
->data
->options
, OSPF_OPTION_NP
))
648 if (IS_DEBUG_OSPF_NSSA
)
649 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
650 inet_ntoa (lsa
->data
->id
));
654 if (IS_DEBUG_OSPF_NSSA
)
655 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
656 inet_ntoa (lsa
->data
->id
));
658 ext7
= (struct as_external_lsa
*)(lsa
->data
);
659 p
.prefix
= lsa
->data
->id
;
660 p
.prefixlen
= ip_masklen (ext7
->mask
);
662 if (ext7
->e
[0].fwd_addr
.s_addr
== OSPF_DEFAULT_DESTINATION
)
664 if (IS_DEBUG_OSPF_NSSA
)
665 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, "
666 "Forward address is 0, NO Translation",
667 inet_ntoa (lsa
->data
->id
));
671 /* try find existing AS-External LSA for this prefix */
673 old
= ospf_external_info_find_lsa (area
->ospf
, &p
);
677 if (IS_DEBUG_OSPF_NSSA
)
678 zlog_debug ("ospf_abr_translate_nssa(): "
679 "found old translated LSA Id %s, refreshing",
680 inet_ntoa (old
->data
->id
));
683 new = ospf_translated_nssa_refresh (area
->ospf
, lsa
, old
);
686 if (IS_DEBUG_OSPF_NSSA
)
687 zlog_debug ("ospf_abr_translate_nssa(): "
688 "could not refresh translated LSA Id %s",
689 inet_ntoa (old
->data
->id
));
694 /* no existing external route for this LSA Id
695 * originate translated LSA
698 if ((new = ospf_translated_nssa_originate (area
->ospf
, lsa
))
701 if (IS_DEBUG_OSPF_NSSA
)
702 zlog_debug ("ospf_abr_translate_nssa(): Could not translate "
703 "Type-7 for %s to Type-5",
704 inet_ntoa (lsa
->data
->id
));
709 /* Area where Aggregate testing will be inserted, just like summary
711 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
717 ospf_abr_translate_nssa_range (struct prefix_ipv4
*p
, u_int32_t cost
)
719 /* The Type-7 is created from the aggregated prefix and forwarded
720 for lsa installation and flooding... to be added... */
724 ospf_abr_announce_network_to_area (struct prefix_ipv4
*p
, u_int32_t cost
,
725 struct ospf_area
*area
)
727 struct ospf_lsa
*lsa
, *old
= NULL
;
728 struct summary_lsa
*sl
= NULL
;
730 if (IS_DEBUG_OSPF_EVENT
)
731 zlog_debug ("ospf_abr_announce_network_to_area(): Start");
733 old
= ospf_lsa_lookup_by_prefix (area
->lsdb
, OSPF_SUMMARY_LSA
,
734 (struct prefix_ipv4
*) p
,
735 area
->ospf
->router_id
);
738 if (IS_DEBUG_OSPF_EVENT
)
739 zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
741 sl
= (struct summary_lsa
*) old
->data
;
743 if (IS_DEBUG_OSPF_EVENT
)
744 zlog_debug ("ospf_abr_announce_network_to_area(): "
745 "old metric: %d, new metric: %d",
746 GET_METRIC (sl
->metric
), cost
);
748 if (GET_METRIC (sl
->metric
) == cost
)
750 /* unchanged. simply reapprove it */
751 if (IS_DEBUG_OSPF_EVENT
)
752 zlog_debug ("ospf_abr_announce_network_to_area(): "
753 "old summary approved");
754 SET_FLAG (old
->flags
, OSPF_LSA_APPROVED
);
758 /* LSA is changed, refresh it */
759 if (IS_DEBUG_OSPF_EVENT
)
760 zlog_debug ("ospf_abr_announce_network_to_area(): "
761 "refreshing summary");
762 set_metric (old
, cost
);
763 lsa
= ospf_summary_lsa_refresh (area
->ospf
, old
);
767 char buf
[INET_ADDRSTRLEN
+ 3]; /* ipv4 and /XX */
769 prefix2str ((struct prefix
*) p
, buf
, sizeof(buf
));
770 zlog_warn ("%s: Could not refresh %s to %s",
773 inet_ntoa (area
->area_id
));
777 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
778 /* This will flood through area. */
783 if (IS_DEBUG_OSPF_EVENT
)
784 zlog_debug ("ospf_abr_announce_network_to_area(): "
785 "creating new summary");
786 lsa
= ospf_summary_lsa_originate ( (struct prefix_ipv4
*)p
, cost
, area
);
787 /* This will flood through area. */
791 char buf
[INET_ADDRSTRLEN
+ 3]; /* ipv4 and /XX */
793 prefix2str ((struct prefix
*)p
, buf
, sizeof(buf
));
794 zlog_warn ("%s: Could not originate %s to %s",
797 inet_ntoa (area
->area_id
));
801 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
802 if (IS_DEBUG_OSPF_EVENT
)
803 zlog_debug ("ospf_abr_announce_network_to_area(): "
804 "flooding new version of summary");
807 if (IS_DEBUG_OSPF_EVENT
)
808 zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
812 ospf_abr_nexthops_belong_to_area (struct ospf_route
*or,
813 struct ospf_area
*area
)
815 struct listnode
*node
, *nnode
;
816 struct ospf_path
*path
;
817 struct ospf_interface
*oi
;
819 for (ALL_LIST_ELEMENTS_RO (or->paths
, node
, path
))
820 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, nnode
, oi
))
821 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
828 ospf_abr_should_accept (struct prefix_ipv4
*p
, struct ospf_area
*area
)
830 if (IMPORT_NAME (area
))
832 if (IMPORT_LIST (area
) == NULL
)
833 IMPORT_LIST (area
) = access_list_lookup (AFI_IP
, IMPORT_NAME (area
));
835 if (IMPORT_LIST (area
))
836 if (access_list_apply (IMPORT_LIST (area
), p
) == FILTER_DENY
)
844 ospf_abr_plist_in_check (struct ospf_area
*area
, struct ospf_route
*or,
845 struct prefix_ipv4
*p
)
847 if (PREFIX_NAME_IN (area
))
849 if (PREFIX_LIST_IN (area
) == NULL
)
850 PREFIX_LIST_IN (area
) = prefix_list_lookup (AFI_IP
,
851 PREFIX_NAME_IN (area
));
852 if (PREFIX_LIST_IN (area
))
853 if (prefix_list_apply (PREFIX_LIST_IN (area
), p
) != PREFIX_PERMIT
)
860 ospf_abr_plist_out_check (struct ospf_area
*area
, struct ospf_route
*or,
861 struct prefix_ipv4
*p
)
863 if (PREFIX_NAME_OUT (area
))
865 if (PREFIX_LIST_OUT (area
) == NULL
)
866 PREFIX_LIST_OUT (area
) = prefix_list_lookup (AFI_IP
,
867 PREFIX_NAME_OUT (area
));
868 if (PREFIX_LIST_OUT (area
))
869 if (prefix_list_apply (PREFIX_LIST_OUT (area
), p
) != PREFIX_PERMIT
)
876 ospf_abr_announce_network (struct ospf
*ospf
,
877 struct prefix_ipv4
*p
, struct ospf_route
*or)
879 struct ospf_area_range
*range
;
880 struct ospf_area
*area
, *or_area
;
881 struct listnode
*node
;
883 if (IS_DEBUG_OSPF_EVENT
)
884 zlog_debug ("ospf_abr_announce_network(): Start");
886 or_area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
);
889 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
891 if (IS_DEBUG_OSPF_EVENT
)
892 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
893 inet_ntoa (area
->area_id
));
895 if (IPV4_ADDR_SAME (&or->u
.std
.area_id
, &area
->area_id
))
898 if (ospf_abr_nexthops_belong_to_area (or, area
))
901 if (!ospf_abr_should_accept (p
, area
))
903 if (IS_DEBUG_OSPF_EVENT
)
904 zlog_debug ("ospf_abr_announce_network(): "
905 "prefix %s/%d was denied by import-list",
906 inet_ntoa (p
->prefix
), p
->prefixlen
);
910 if (!ospf_abr_plist_in_check (area
, or, p
))
912 if (IS_DEBUG_OSPF_EVENT
)
913 zlog_debug ("ospf_abr_announce_network(): "
914 "prefix %s/%d was denied by prefix-list",
915 inet_ntoa (p
->prefix
), p
->prefixlen
);
919 if (area
->external_routing
!= OSPF_AREA_DEFAULT
&& area
->no_summary
)
921 if (IS_DEBUG_OSPF_EVENT
)
922 zlog_debug ("ospf_abr_announce_network(): "
923 "area %s is stub and no_summary",
924 inet_ntoa (area
->area_id
));
928 if (or->path_type
== OSPF_PATH_INTER_AREA
)
930 if (IS_DEBUG_OSPF_EVENT
)
931 zlog_debug ("ospf_abr_announce_network(): this is "
932 "inter-area route to %s/%d",
933 inet_ntoa (p
->prefix
), p
->prefixlen
);
935 if (!OSPF_IS_AREA_BACKBONE (area
))
936 ospf_abr_announce_network_to_area (p
, or->cost
, area
);
939 if (or->path_type
== OSPF_PATH_INTRA_AREA
)
941 if (IS_DEBUG_OSPF_EVENT
)
942 zlog_debug ("ospf_abr_announce_network(): "
943 "this is intra-area route to %s/%d",
944 inet_ntoa (p
->prefix
), p
->prefixlen
);
945 if ((range
= ospf_area_range_match (or_area
, p
))
946 && !ospf_area_is_transit (area
))
947 ospf_abr_update_aggregate (range
, or);
949 ospf_abr_announce_network_to_area (p
, or->cost
, area
);
955 ospf_abr_should_announce (struct ospf
*ospf
,
956 struct prefix_ipv4
*p
, struct ospf_route
*or)
958 struct ospf_area
*area
;
960 area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
);
964 if (EXPORT_NAME (area
))
966 if (EXPORT_LIST (area
) == NULL
)
967 EXPORT_LIST (area
) = access_list_lookup (AFI_IP
, EXPORT_NAME (area
));
969 if (EXPORT_LIST (area
))
970 if (access_list_apply (EXPORT_LIST (area
), p
) == FILTER_DENY
)
978 ospf_abr_process_nssa_translates (struct ospf
*ospf
)
980 /* Scan through all NSSA_LSDB records for all areas;
982 If P-bit is on, translate all Type-7's to 5's and aggregate or
983 flood install as approved in Type-5 LSDB with XLATE Flag on
984 later, do same for all aggregates... At end, DISCARD all
985 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
986 struct listnode
*node
;
987 struct ospf_area
*area
;
988 struct route_node
*rn
;
989 struct ospf_lsa
*lsa
;
991 if (IS_DEBUG_OSPF_NSSA
)
992 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
994 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
996 if (! area
->NSSATranslatorState
)
997 continue; /* skip if not translator */
999 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1000 continue; /* skip if not Nssa Area */
1002 if (IS_DEBUG_OSPF_NSSA
)
1003 zlog_debug ("ospf_abr_process_nssa_translates(): "
1004 "looking at area %s", inet_ntoa (area
->area_id
));
1006 LSDB_LOOP (NSSA_LSDB (area
), rn
, lsa
)
1007 ospf_abr_translate_nssa (area
, lsa
);
1010 if (IS_DEBUG_OSPF_NSSA
)
1011 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
1016 ospf_abr_process_network_rt (struct ospf
*ospf
,
1017 struct route_table
*rt
)
1019 struct ospf_area
*area
;
1020 struct ospf_route
*or;
1021 struct route_node
*rn
;
1023 if (IS_DEBUG_OSPF_EVENT
)
1024 zlog_debug ("ospf_abr_process_network_rt(): Start");
1026 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1028 if ((or = rn
->info
) == NULL
)
1031 if (!(area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
)))
1033 if (IS_DEBUG_OSPF_EVENT
)
1034 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
1035 inet_ntoa (or->u
.std
.area_id
));
1039 if (IS_DEBUG_OSPF_EVENT
)
1040 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
1041 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
1042 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
)
1044 if (IS_DEBUG_OSPF_EVENT
)
1045 zlog_debug ("ospf_abr_process_network_rt(): "
1046 "this is an External router, skipping");
1050 if (or->cost
>= OSPF_LS_INFINITY
)
1052 if (IS_DEBUG_OSPF_EVENT
)
1053 zlog_debug ("ospf_abr_process_network_rt():"
1054 " this route's cost is infinity, skipping");
1058 if (or->type
== OSPF_DESTINATION_DISCARD
)
1060 if (IS_DEBUG_OSPF_EVENT
)
1061 zlog_debug ("ospf_abr_process_network_rt():"
1062 " this is a discard entry, skipping");
1066 if (or->path_type
== OSPF_PATH_INTRA_AREA
&&
1067 !ospf_abr_should_announce (ospf
, (struct prefix_ipv4
*) &rn
->p
, or))
1069 if (IS_DEBUG_OSPF_EVENT
)
1070 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
1074 if (or->path_type
== OSPF_PATH_INTRA_AREA
&&
1075 !ospf_abr_plist_out_check (area
, or, (struct prefix_ipv4
*) &rn
->p
))
1077 if (IS_DEBUG_OSPF_EVENT
)
1078 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
1082 if ((or->path_type
== OSPF_PATH_INTER_AREA
) &&
1083 !OSPF_IS_AREA_ID_BACKBONE (or->u
.std
.area_id
))
1085 if (IS_DEBUG_OSPF_EVENT
)
1086 zlog_debug ("ospf_abr_process_network_rt():"
1087 " this is route is not backbone one, skipping");
1092 if ((ospf
->abr_type
== OSPF_ABR_CISCO
) ||
1093 (ospf
->abr_type
== OSPF_ABR_IBM
))
1095 if (!ospf_act_bb_connection (ospf
) &&
1096 or->path_type
!= OSPF_PATH_INTRA_AREA
)
1098 if (IS_DEBUG_OSPF_EVENT
)
1099 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
1100 "No BB connection, skip not intra-area routes");
1104 if (IS_DEBUG_OSPF_EVENT
)
1105 zlog_debug ("ospf_abr_process_network_rt(): announcing");
1106 ospf_abr_announce_network (ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
1109 if (IS_DEBUG_OSPF_EVENT
)
1110 zlog_debug ("ospf_abr_process_network_rt(): Stop");
1114 ospf_abr_announce_rtr_to_area (struct prefix_ipv4
*p
, u_int32_t cost
,
1115 struct ospf_area
*area
)
1117 struct ospf_lsa
*lsa
, *old
= NULL
;
1118 struct summary_lsa
*slsa
= NULL
;
1120 if (IS_DEBUG_OSPF_EVENT
)
1121 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
1123 old
= ospf_lsa_lookup_by_prefix (area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
,
1124 p
, area
->ospf
->router_id
);
1127 if (IS_DEBUG_OSPF_EVENT
)
1128 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
1129 slsa
= (struct summary_lsa
*) old
->data
;
1131 if (IS_DEBUG_OSPF_EVENT
)
1132 zlog_debug ("ospf_abr_announce_network_to_area(): "
1133 "old metric: %d, new metric: %d",
1134 GET_METRIC (slsa
->metric
), cost
);
1137 if (old
&& (GET_METRIC (slsa
->metric
) == cost
))
1139 if (IS_DEBUG_OSPF_EVENT
)
1140 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
1141 SET_FLAG (old
->flags
, OSPF_LSA_APPROVED
);
1145 if (IS_DEBUG_OSPF_EVENT
)
1146 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
1150 set_metric (old
, cost
);
1151 lsa
= ospf_summary_asbr_lsa_refresh (area
->ospf
, old
);
1154 lsa
= ospf_summary_asbr_lsa_originate (p
, cost
, area
);
1157 char buf
[INET_ADDRSTRLEN
+ 3]; /* ipv4 and /XX */
1159 prefix2str ((struct prefix
*)p
, buf
, sizeof(buf
));
1160 zlog_warn ("%s: Could not refresh/originate %s to %s",
1163 inet_ntoa (area
->area_id
));
1167 if (IS_DEBUG_OSPF_EVENT
)
1168 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
1169 "flooding new version of summary");
1172 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1173 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1175 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1176 /* ospf_flood_through_area (area, NULL, lsa);*/
1179 if (IS_DEBUG_OSPF_EVENT
)
1180 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
1185 ospf_abr_announce_rtr (struct ospf
*ospf
,
1186 struct prefix_ipv4
*p
, struct ospf_route
*or)
1188 struct listnode
*node
;
1189 struct ospf_area
*area
;
1191 if (IS_DEBUG_OSPF_EVENT
)
1192 zlog_debug ("ospf_abr_announce_rtr(): Start");
1194 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1196 if (IS_DEBUG_OSPF_EVENT
)
1197 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
1198 inet_ntoa (area
->area_id
));
1200 if (IPV4_ADDR_SAME (&or->u
.std
.area_id
, &area
->area_id
))
1203 if (ospf_abr_nexthops_belong_to_area (or, area
))
1206 if (area
->external_routing
!= OSPF_AREA_DEFAULT
)
1208 if (IS_DEBUG_OSPF_EVENT
)
1209 zlog_debug ("ospf_abr_announce_rtr(): "
1210 "area %s doesn't support external routing",
1211 inet_ntoa(area
->area_id
));
1215 if (or->path_type
== OSPF_PATH_INTER_AREA
)
1217 if (IS_DEBUG_OSPF_EVENT
)
1218 zlog_debug ("ospf_abr_announce_rtr(): "
1219 "this is inter-area route to %s", inet_ntoa (p
->prefix
));
1220 if (!OSPF_IS_AREA_BACKBONE (area
))
1221 ospf_abr_announce_rtr_to_area (p
, or->cost
, area
);
1224 if (or->path_type
== OSPF_PATH_INTRA_AREA
)
1226 if (IS_DEBUG_OSPF_EVENT
)
1227 zlog_debug ("ospf_abr_announce_rtr(): "
1228 "this is intra-area route to %s", inet_ntoa (p
->prefix
));
1229 ospf_abr_announce_rtr_to_area (p
, or->cost
, area
);
1233 if (IS_DEBUG_OSPF_EVENT
)
1234 zlog_debug ("ospf_abr_announce_rtr(): Stop");
1238 ospf_abr_process_router_rt (struct ospf
*ospf
, struct route_table
*rt
)
1240 struct ospf_route
*or;
1241 struct route_node
*rn
;
1244 if (IS_DEBUG_OSPF_EVENT
)
1245 zlog_debug ("ospf_abr_process_router_rt(): Start");
1247 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1249 struct listnode
*node
, *nnode
;
1251 struct ospf_route
*best
= NULL
;
1253 if (rn
->info
== NULL
)
1258 if (IS_DEBUG_OSPF_EVENT
)
1259 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
1260 inet_ntoa (rn
->p
.u
.prefix4
));
1262 for (ALL_LIST_ELEMENTS (l
, node
, nnode
, or))
1264 if (!ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
))
1266 if (IS_DEBUG_OSPF_EVENT
)
1267 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
1268 inet_ntoa (or->u
.std
.area_id
));
1273 if (!CHECK_FLAG (or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
))
1275 if (IS_DEBUG_OSPF_EVENT
)
1276 zlog_debug ("ospf_abr_process_router_rt(): "
1277 "This is not an ASBR, skipping");
1283 best
= ospf_find_asbr_route (ospf
, rt
,
1284 (struct prefix_ipv4
*) &rn
->p
);
1293 if (IS_DEBUG_OSPF_EVENT
)
1294 zlog_debug ("ospf_abr_process_router_rt(): "
1295 "This route is not the best among possible, skipping");
1299 if (or->path_type
== OSPF_PATH_INTER_AREA
&&
1300 !OSPF_IS_AREA_ID_BACKBONE (or->u
.std
.area_id
))
1302 if (IS_DEBUG_OSPF_EVENT
)
1303 zlog_debug ("ospf_abr_process_router_rt(): "
1304 "This route is not a backbone one, skipping");
1308 if (or->cost
>= OSPF_LS_INFINITY
)
1310 if (IS_DEBUG_OSPF_EVENT
)
1311 zlog_debug ("ospf_abr_process_router_rt(): "
1312 "This route has LS_INFINITY metric, skipping");
1316 if (ospf
->abr_type
== OSPF_ABR_CISCO
1317 || ospf
->abr_type
== OSPF_ABR_IBM
)
1318 if (!ospf_act_bb_connection (ospf
)
1319 && or->path_type
!= OSPF_PATH_INTRA_AREA
)
1321 if (IS_DEBUG_OSPF_EVENT
)
1322 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
1323 "No BB connection, skip not intra-area routes");
1327 ospf_abr_announce_rtr (ospf
, (struct prefix_ipv4
*) &rn
->p
, or);
1333 if (IS_DEBUG_OSPF_EVENT
)
1334 zlog_debug ("ospf_abr_process_router_rt(): Stop");
1338 ospf_abr_unapprove_translates (struct ospf
*ospf
) /* For NSSA Translations */
1340 struct ospf_lsa
*lsa
;
1341 struct route_node
*rn
;
1343 if (IS_DEBUG_OSPF_NSSA
)
1344 zlog_debug ("ospf_abr_unapprove_translates(): Start");
1346 /* NSSA Translator is not checked, because it may have gone away,
1347 and we would want to flush any residuals anyway */
1349 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
1350 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
1352 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1353 if (IS_DEBUG_OSPF_NSSA
)
1354 zlog_debug ("ospf_abr_unapprove_translates(): "
1355 "approved unset on link id %s",
1356 inet_ntoa (lsa
->data
->id
));
1359 if (IS_DEBUG_OSPF_NSSA
)
1360 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
1364 ospf_abr_unapprove_summaries (struct ospf
*ospf
)
1366 struct listnode
*node
;
1367 struct ospf_area
*area
;
1368 struct route_node
*rn
;
1369 struct ospf_lsa
*lsa
;
1371 if (IS_DEBUG_OSPF_EVENT
)
1372 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
1374 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1376 if (IS_DEBUG_OSPF_EVENT
)
1377 zlog_debug ("ospf_abr_unapprove_summaries(): "
1378 "considering area %s",
1379 inet_ntoa (area
->area_id
));
1380 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
1381 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1383 if (IS_DEBUG_OSPF_EVENT
)
1384 zlog_debug ("ospf_abr_unapprove_summaries(): "
1385 "approved unset on summary link id %s",
1386 inet_ntoa (lsa
->data
->id
));
1387 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1390 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
1391 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1393 if (IS_DEBUG_OSPF_EVENT
)
1394 zlog_debug ("ospf_abr_unapprove_summaries(): "
1395 "approved unset on asbr-summary link id %s",
1396 inet_ntoa (lsa
->data
->id
));
1397 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1401 if (IS_DEBUG_OSPF_EVENT
)
1402 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
1406 ospf_abr_prepare_aggregates (struct ospf
*ospf
)
1408 struct listnode
*node
;
1409 struct route_node
*rn
;
1410 struct ospf_area_range
*range
;
1411 struct ospf_area
*area
;
1413 if (IS_DEBUG_OSPF_EVENT
)
1414 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
1416 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1418 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1419 if ((range
= rn
->info
) != NULL
)
1422 range
->specifics
= 0;
1426 if (IS_DEBUG_OSPF_EVENT
)
1427 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
1431 ospf_abr_announce_aggregates (struct ospf
*ospf
)
1433 struct ospf_area
*area
, *ar
;
1434 struct ospf_area_range
*range
;
1435 struct route_node
*rn
;
1437 struct listnode
*node
, *n
;
1439 if (IS_DEBUG_OSPF_EVENT
)
1440 zlog_debug ("ospf_abr_announce_aggregates(): Start");
1442 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1444 if (IS_DEBUG_OSPF_EVENT
)
1445 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
1446 inet_ntoa (area
->area_id
));
1448 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1449 if ((range
= rn
->info
))
1451 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1453 if (IS_DEBUG_OSPF_EVENT
)
1454 zlog_debug ("ospf_abr_announce_aggregates():"
1455 " discarding suppress-ranges");
1460 p
.u
.prefix4
= range
->addr
;
1461 p
.prefixlen
= range
->masklen
;
1463 if (IS_DEBUG_OSPF_EVENT
)
1464 zlog_debug ("ospf_abr_announce_aggregates():"
1465 " this is range: %s/%d",
1466 inet_ntoa (p
.u
.prefix4
), p
.prefixlen
);
1468 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
1471 p
.u
.prefix4
= range
->subst_addr
;
1472 p
.prefixlen
= range
->subst_masklen
;
1475 if (range
->specifics
)
1477 if (IS_DEBUG_OSPF_EVENT
)
1478 zlog_debug ("ospf_abr_announce_aggregates(): active range");
1480 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, n
, ar
))
1485 /* We do not check nexthops here, because
1486 intra-area routes can be associated with
1489 /* backbone routes are not summarized
1490 when announced into transit areas */
1492 if (ospf_area_is_transit (ar
) &&
1493 OSPF_IS_AREA_BACKBONE (area
))
1495 if (IS_DEBUG_OSPF_EVENT
)
1496 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
1497 "announcement of BB aggregate into"
1501 ospf_abr_announce_network_to_area ((struct prefix_ipv4
*)&p
, range
->cost
, ar
);
1507 if (IS_DEBUG_OSPF_EVENT
)
1508 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
1512 ospf_abr_send_nssa_aggregates (struct ospf
*ospf
) /* temporarily turned off */
1514 struct listnode
*node
; /*, n; */
1515 struct ospf_area
*area
; /*, *ar; */
1516 struct route_node
*rn
;
1517 struct ospf_area_range
*range
;
1518 struct prefix_ipv4 p
;
1520 if (IS_DEBUG_OSPF_NSSA
)
1521 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
1523 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1525 if (! area
->NSSATranslatorState
)
1528 if (IS_DEBUG_OSPF_NSSA
)
1529 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
1530 inet_ntoa (area
->area_id
));
1532 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1534 if (rn
->info
== NULL
)
1539 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1541 if (IS_DEBUG_OSPF_NSSA
)
1542 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1543 " discarding suppress-ranges");
1548 p
.prefix
= range
->addr
;
1549 p
.prefixlen
= range
->masklen
;
1551 if (IS_DEBUG_OSPF_NSSA
)
1552 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1553 " this is range: %s/%d",
1554 inet_ntoa (p
.prefix
), p
.prefixlen
);
1556 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
1559 p
.prefix
= range
->subst_addr
;
1560 p
.prefixlen
= range
->subst_masklen
;
1563 if (range
->specifics
)
1565 if (IS_DEBUG_OSPF_NSSA
)
1566 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
1568 /* Fetch LSA-Type-7 from aggregate prefix, and then
1569 * translate, Install (as Type-5), Approve, and Flood
1571 ospf_abr_translate_nssa_range (&p
, range
->cost
);
1573 } /* all area ranges*/
1576 if (IS_DEBUG_OSPF_NSSA
)
1577 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
1581 ospf_abr_announce_nssa_defaults (struct ospf
*ospf
) /* By ABR-Translator */
1583 struct listnode
*node
;
1584 struct ospf_area
*area
;
1586 if (! IS_OSPF_ABR (ospf
))
1589 if (IS_DEBUG_OSPF_NSSA
)
1590 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
1592 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1594 if (IS_DEBUG_OSPF_NSSA
)
1595 zlog_debug ("ospf_abr_announce_nssa_defaults(): looking at area %s",
1596 inet_ntoa (area
->area_id
));
1598 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1601 if (OSPF_IS_AREA_BACKBONE (area
))
1602 continue; /* Sanity Check */
1604 /* if (!TranslatorRole continue V 1.0 look for "always" conf */
1605 if (area
->NSSATranslatorState
)
1607 if (IS_DEBUG_OSPF_NSSA
)
1608 zlog_debug ("ospf_abr_announce_nssa_defaults(): "
1609 "announcing 0.0.0.0/0 to this nssa");
1610 /* ospf_abr_announce_nssa_asbr_to_as (&p, area->default_cost, area); */
1611 /*ospf_abr_announce_network_to_area (&p, area->default_cost, area);*/
1617 ospf_abr_announce_stub_defaults (struct ospf
*ospf
)
1619 struct listnode
*node
;
1620 struct ospf_area
*area
;
1621 struct prefix_ipv4 p
;
1623 if (! IS_OSPF_ABR (ospf
))
1626 if (IS_DEBUG_OSPF_EVENT
)
1627 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
1630 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1633 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1635 if (IS_DEBUG_OSPF_EVENT
)
1636 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1637 inet_ntoa (area
->area_id
));
1639 if ( (area
->external_routing
!= OSPF_AREA_STUB
)
1640 && (area
->external_routing
!= OSPF_AREA_NSSA
)
1644 if (OSPF_IS_AREA_BACKBONE (area
))
1645 continue; /* Sanity Check */
1647 if (IS_DEBUG_OSPF_EVENT
)
1648 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1649 "announcing 0.0.0.0/0 to area %s",
1650 inet_ntoa (area
->area_id
));
1651 ospf_abr_announce_network_to_area (&p
, area
->default_cost
, area
);
1654 if (IS_DEBUG_OSPF_EVENT
)
1655 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
1659 ospf_abr_remove_unapproved_translates_apply (struct ospf
*ospf
,
1660 struct ospf_lsa
*lsa
)
1662 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1663 && ! CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1665 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1666 "removing unapproved translates, ID: %s",
1667 inet_ntoa (lsa
->data
->id
));
1669 /* FLUSH THROUGHOUT AS */
1670 ospf_lsa_flush_as (ospf
, lsa
);
1672 /* DISCARD from LSDB */
1678 ospf_abr_remove_unapproved_translates (struct ospf
*ospf
)
1680 struct route_node
*rn
;
1681 struct ospf_lsa
*lsa
;
1683 /* All AREA PROCESS should have APPROVED necessary LSAs */
1684 /* Remove any left over and not APPROVED */
1685 if (IS_DEBUG_OSPF_NSSA
)
1686 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
1688 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
1689 ospf_abr_remove_unapproved_translates_apply (ospf
, lsa
);
1691 if (IS_DEBUG_OSPF_NSSA
)
1692 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
1696 ospf_abr_remove_unapproved_summaries (struct ospf
*ospf
)
1698 struct listnode
*node
;
1699 struct ospf_area
*area
;
1700 struct route_node
*rn
;
1701 struct ospf_lsa
*lsa
;
1703 if (IS_DEBUG_OSPF_EVENT
)
1704 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
1706 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1708 if (IS_DEBUG_OSPF_EVENT
)
1709 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
1710 "looking at area %s", inet_ntoa (area
->area_id
));
1712 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
1713 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1714 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1715 ospf_lsa_flush_area (lsa
, area
);
1717 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
1718 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1719 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1720 ospf_lsa_flush_area (lsa
, area
);
1723 if (IS_DEBUG_OSPF_EVENT
)
1724 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
1728 ospf_abr_manage_discard_routes (struct ospf
*ospf
)
1730 struct listnode
*node
, *nnode
;
1731 struct route_node
*rn
;
1732 struct ospf_area
*area
;
1733 struct ospf_area_range
*range
;
1735 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
1736 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1737 if ((range
= rn
->info
) != NULL
)
1738 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1740 if (range
->specifics
)
1741 ospf_add_discard_route (ospf
->new_table
, area
,
1742 (struct prefix_ipv4
*) &rn
->p
);
1744 ospf_delete_discard_route ((struct prefix_ipv4
*) &rn
->p
);
1748 /* This is the function taking care about ABR NSSA, i.e. NSSA
1749 Translator, -LSA aggregation and flooding. For all NSSAs
1751 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1752 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1755 Any received Type-5s are legal for an ABR, else illegal for IR.
1756 Received Type-7s are installed, by area, with incoming P-bit. They
1757 are flooded; if the Elected NSSA Translator, then P-bit off.
1759 Additionally, this ABR will place "translated type-7's" into the
1760 Type-5 LSDB in order to keep track of APPROVAL or not.
1762 It will scan through every area, looking for Type-7 LSAs with P-Bit
1763 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1764 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1767 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1768 left over are FLUSHED and DISCARDED.
1770 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1771 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1774 ospf_abr_nssa_task (struct ospf
*ospf
) /* called only if any_nssa */
1776 if (IS_DEBUG_OSPF_NSSA
)
1777 zlog_debug ("Check for NSSA-ABR Tasks():");
1779 if (! IS_OSPF_ABR (ospf
))
1782 if (! ospf
->anyNSSA
)
1785 /* Each area must confirm TranslatorRole */
1786 if (IS_DEBUG_OSPF_NSSA
)
1787 zlog_debug ("ospf_abr_nssa_task(): Start");
1789 /* For all Global Entries flagged "local-translate", unset APPROVED */
1790 if (IS_DEBUG_OSPF_NSSA
)
1791 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
1793 ospf_abr_unapprove_translates (ospf
);
1795 /* RESET all Ranges in every Area, same as summaries */
1796 if (IS_DEBUG_OSPF_NSSA
)
1797 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
1798 ospf_abr_prepare_aggregates (ospf
); /*TURNED OFF just for now */
1800 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1801 * Aggregate as Type-7
1802 * Install or Approve in Type-5 Global LSDB
1804 if (IS_DEBUG_OSPF_NSSA
)
1805 zlog_debug ("ospf_abr_nssa_task(): process translates");
1806 ospf_abr_process_nssa_translates (ospf
);
1808 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1810 * Scan Type-7's for aggregates, translate to Type-5's,
1811 * Install/Flood/Approve
1813 if (IS_DEBUG_OSPF_NSSA
)
1814 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1815 ospf_abr_send_nssa_aggregates (ospf
); /*TURNED OFF FOR NOW */
1817 /* Send any NSSA defaults as Type-5
1818 *if (IS_DEBUG_OSPF_NSSA)
1819 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1820 *ospf_abr_announce_nssa_defaults (ospf);
1821 * havnt a clue what above is supposed to do.
1824 /* Flush any unapproved previous translates from Global Data Base */
1825 if (IS_DEBUG_OSPF_NSSA
)
1826 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
1827 ospf_abr_remove_unapproved_translates (ospf
);
1829 ospf_abr_manage_discard_routes (ospf
); /* same as normal...discard */
1831 if (IS_DEBUG_OSPF_NSSA
)
1832 zlog_debug ("ospf_abr_nssa_task(): Stop");
1835 /* This is the function taking care about ABR stuff, i.e.
1836 summary-LSA origination and flooding. */
1838 ospf_abr_task (struct ospf
*ospf
)
1840 if (IS_DEBUG_OSPF_EVENT
)
1841 zlog_debug ("ospf_abr_task(): Start");
1843 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
)
1845 if (IS_DEBUG_OSPF_EVENT
)
1846 zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
1850 if (IS_DEBUG_OSPF_EVENT
)
1851 zlog_debug ("ospf_abr_task(): unapprove summaries");
1852 ospf_abr_unapprove_summaries (ospf
);
1854 if (IS_DEBUG_OSPF_EVENT
)
1855 zlog_debug ("ospf_abr_task(): prepare aggregates");
1856 ospf_abr_prepare_aggregates (ospf
);
1858 if (IS_OSPF_ABR (ospf
))
1860 if (IS_DEBUG_OSPF_EVENT
)
1861 zlog_debug ("ospf_abr_task(): process network RT");
1862 ospf_abr_process_network_rt (ospf
, ospf
->new_table
);
1864 if (IS_DEBUG_OSPF_EVENT
)
1865 zlog_debug ("ospf_abr_task(): process router RT");
1866 ospf_abr_process_router_rt (ospf
, ospf
->new_rtrs
);
1868 if (IS_DEBUG_OSPF_EVENT
)
1869 zlog_debug ("ospf_abr_task(): announce aggregates");
1870 ospf_abr_announce_aggregates (ospf
);
1872 if (IS_DEBUG_OSPF_EVENT
)
1873 zlog_debug ("ospf_abr_task(): announce stub defaults");
1874 ospf_abr_announce_stub_defaults (ospf
);
1877 if (IS_DEBUG_OSPF_EVENT
)
1878 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
1879 ospf_abr_remove_unapproved_summaries (ospf
);
1881 ospf_abr_manage_discard_routes (ospf
);
1883 if (IS_DEBUG_OSPF_EVENT
)
1884 zlog_debug ("ospf_abr_task(): Stop");
1888 ospf_abr_task_timer (struct thread
*thread
)
1890 struct ospf
*ospf
= THREAD_ARG (thread
);
1892 ospf
->t_abr_task
= 0;
1894 if (IS_DEBUG_OSPF_EVENT
)
1895 zlog_debug ("Running ABR task on timer");
1897 ospf_check_abr_status (ospf
);
1898 ospf_abr_nssa_check_status (ospf
);
1900 ospf_abr_task (ospf
);
1901 ospf_abr_nssa_task (ospf
); /* if nssa-abr, then scan Type-7 LSDB */
1907 ospf_schedule_abr_task (struct ospf
*ospf
)
1909 if (IS_DEBUG_OSPF_EVENT
)
1910 zlog_debug ("Scheduling ABR task");
1912 if (ospf
->t_abr_task
== NULL
)
1913 ospf
->t_abr_task
= thread_add_timer (master
, ospf_abr_task_timer
,
1914 ospf
, OSPF_ABR_TASK_DELAY
);