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
))
416 if (area
->external_routing
!= OSPF_AREA_NSSA
)
419 if (IS_DEBUG_OSPF (nssa
, NSSA
))
420 zlog_debug ("ospf_abr_nssa_check_status: "
422 inet_ntoa (area
->area_id
));
424 if (!IS_OSPF_ABR (area
->ospf
))
426 if (IS_DEBUG_OSPF (nssa
, NSSA
))
427 zlog_debug ("ospf_abr_nssa_check_status: "
429 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
433 switch (area
->NSSATranslatorRole
)
435 case OSPF_NSSA_ROLE_NEVER
:
436 /* We never Translate Type-7 LSA. */
437 /* TODO: check previous state and flush? */
438 if (IS_DEBUG_OSPF (nssa
, NSSA
))
439 zlog_debug ("ospf_abr_nssa_check_status: "
441 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
444 case OSPF_NSSA_ROLE_ALWAYS
:
445 /* We always translate if we are an ABR
446 * TODO: originate new LSAs if state change?
447 * or let the nssa abr task take care of it?
449 if (IS_DEBUG_OSPF (nssa
, NSSA
))
450 zlog_debug ("ospf_abr_nssa_check_status: "
452 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_ENABLED
;
455 case OSPF_NSSA_ROLE_CANDIDATE
:
456 /* We are a candidate for Translation */
457 if (ospf_abr_nssa_am_elected (area
) > 0 )
459 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_ENABLED
;
460 if (IS_DEBUG_OSPF (nssa
, NSSA
))
461 zlog_debug ("ospf_abr_nssa_check_status: "
462 "elected translator");
466 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
467 if (IS_DEBUG_OSPF (nssa
, NSSA
))
468 zlog_debug ("ospf_abr_nssa_check_status: "
476 /* Check area border router status. */
478 ospf_check_abr_status (struct ospf
*ospf
)
480 struct ospf_area
*area
;
481 struct listnode
*node
, *nnode
;
482 int bb_configured
= 0;
483 int bb_act_attached
= 0;
484 int areas_configured
= 0;
485 int areas_act_attached
= 0;
486 u_char new_flags
= ospf
->flags
;
488 if (IS_DEBUG_OSPF_EVENT
)
489 zlog_debug ("ospf_check_abr_status(): Start");
491 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
493 if (listcount (area
->oiflist
))
497 if (OSPF_IS_AREA_BACKBONE (area
))
501 if (ospf_area_actively_attached (area
))
503 areas_act_attached
++;
505 if (OSPF_IS_AREA_BACKBONE (area
))
510 if (IS_DEBUG_OSPF_EVENT
)
512 zlog_debug ("ospf_check_abr_status(): looked through areas");
513 zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured
);
514 zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
516 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
518 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
522 switch (ospf
->abr_type
)
524 case OSPF_ABR_SHORTCUT
:
526 if (areas_act_attached
> 1)
527 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
529 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
533 if ((areas_act_attached
> 1) && bb_configured
)
534 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
536 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
540 if ((areas_configured
> 1) && bb_act_attached
)
541 SET_FLAG (new_flags
, OSPF_FLAG_ABR
);
543 UNSET_FLAG (new_flags
, OSPF_FLAG_ABR
);
549 if (new_flags
!= ospf
->flags
)
551 ospf_spf_calculate_schedule (ospf
);
552 if (IS_DEBUG_OSPF_EVENT
)
553 zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags
);
554 ospf
->flags
= new_flags
;
555 OSPF_TIMER_ON (ospf
->t_router_lsa_update
,
556 ospf_router_lsa_update_timer
, OSPF_LSA_UPDATE_DELAY
);
561 ospf_abr_update_aggregate (struct ospf_area_range
*range
,
562 struct ospf_route
*or)
564 if (IS_DEBUG_OSPF_EVENT
)
565 zlog_debug ("ospf_abr_update_aggregate(): Start");
567 if (range
->cost_config
!= OSPF_AREA_RANGE_COST_UNSPEC
)
569 if (IS_DEBUG_OSPF_EVENT
)
570 zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
573 range
->cost
= range
->cost_config
;
577 if (range
->specifics
== 0)
578 range
->cost
= or->cost
; /* 1st time get 1st cost */
580 if (or->cost
> range
->cost
)
582 if (IS_DEBUG_OSPF_EVENT
)
583 zlog_debug ("ospf_abr_update_aggregate(): largest cost, update");
585 range
->cost
= or->cost
;
593 set_metric (struct ospf_lsa
*lsa
, u_int32_t metric
)
595 struct summary_lsa
*header
;
597 metric
= htonl (metric
);
598 mp
= (u_char
*) &metric
;
600 header
= (struct summary_lsa
*) lsa
->data
;
601 memcpy(header
->metric
, mp
, 3);
605 ospf_abr_check_nssa_range (struct prefix_ipv4
*p
, u_int32_t cost
,
606 struct ospf_area
*area
)
608 /* The Type-7 is tested against the aggregated prefix and forwarded
609 for lsa installation and flooding */
613 /* ospf_abr_translate_nssa */
615 ospf_abr_translate_nssa (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
617 /* Incoming Type-7 or later aggregated Type-7
619 * LSA is skipped if P-bit is off.
620 * LSA is aggregated if within range.
622 * The Type-7 is translated, Installed/Approved as a Type-5 into
623 * global LSDB, then Flooded through AS
625 * Later, any Unapproved Translated Type-5's are flushed/discarded
628 struct ospf_lsa
*old
= NULL
,
630 struct as_external_lsa
*ext7
;
631 struct prefix_ipv4 p
;
633 if (! CHECK_FLAG (lsa
->data
->options
, OSPF_OPTION_NP
))
635 if (IS_DEBUG_OSPF_NSSA
)
636 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
637 inet_ntoa (lsa
->data
->id
));
641 if (IS_DEBUG_OSPF_NSSA
)
642 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
643 inet_ntoa (lsa
->data
->id
));
645 ext7
= (struct as_external_lsa
*)(lsa
->data
);
646 p
.prefix
= lsa
->data
->id
;
647 p
.prefixlen
= ip_masklen (ext7
->mask
);
649 if (ext7
->e
[0].fwd_addr
.s_addr
== OSPF_DEFAULT_DESTINATION
)
651 if (IS_DEBUG_OSPF_NSSA
)
652 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, "
653 "Forward address is 0, NO Translation",
654 inet_ntoa (lsa
->data
->id
));
658 /* try find existing AS-External LSA for this prefix */
660 old
= ospf_external_info_find_lsa (area
->ospf
, &p
);
664 if (IS_DEBUG_OSPF_NSSA
)
665 zlog_debug ("ospf_abr_translate_nssa(): "
666 "found old translated LSA Id %s, refreshing",
667 inet_ntoa (old
->data
->id
));
670 new = ospf_translated_nssa_refresh (area
->ospf
, lsa
, old
);
673 if (IS_DEBUG_OSPF_NSSA
)
674 zlog_debug ("ospf_abr_translate_nssa(): "
675 "could not refresh translated LSA Id %s",
676 inet_ntoa (old
->data
->id
));
681 /* no existing external route for this LSA Id
682 * originate translated LSA
685 if ((new = ospf_translated_nssa_originate (area
->ospf
, lsa
))
688 if (IS_DEBUG_OSPF_NSSA
)
689 zlog_debug ("ospf_abr_translate_nssa(): Could not translate "
690 "Type-7 for %s to Type-5",
691 inet_ntoa (lsa
->data
->id
));
696 /* Area where Aggregate testing will be inserted, just like summary
698 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
704 ospf_abr_translate_nssa_range (struct prefix_ipv4
*p
, u_int32_t cost
)
706 /* The Type-7 is created from the aggregated prefix and forwarded
707 for lsa installation and flooding... to be added... */
711 ospf_abr_announce_network_to_area (struct prefix_ipv4
*p
, u_int32_t cost
,
712 struct ospf_area
*area
)
714 struct ospf_lsa
*lsa
, *old
= NULL
;
715 struct summary_lsa
*sl
= NULL
;
717 if (IS_DEBUG_OSPF_EVENT
)
718 zlog_debug ("ospf_abr_announce_network_to_area(): Start");
720 old
= ospf_lsa_lookup_by_prefix (area
->lsdb
, OSPF_SUMMARY_LSA
,
721 (struct prefix_ipv4
*) p
,
722 area
->ospf
->router_id
);
725 if (IS_DEBUG_OSPF_EVENT
)
726 zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
728 sl
= (struct summary_lsa
*) old
->data
;
730 if (IS_DEBUG_OSPF_EVENT
)
731 zlog_debug ("ospf_abr_announce_network_to_area(): "
732 "old metric: %d, new metric: %d",
733 GET_METRIC (sl
->metric
), cost
);
735 if (GET_METRIC (sl
->metric
) == cost
)
737 /* unchanged. simply reapprove it */
738 if (IS_DEBUG_OSPF_EVENT
)
739 zlog_debug ("ospf_abr_announce_network_to_area(): "
740 "old summary approved");
741 SET_FLAG (old
->flags
, OSPF_LSA_APPROVED
);
745 /* LSA is changed, refresh it */
746 if (IS_DEBUG_OSPF_EVENT
)
747 zlog_debug ("ospf_abr_announce_network_to_area(): "
748 "refreshing summary");
749 set_metric (old
, cost
);
750 lsa
= ospf_summary_lsa_refresh (area
->ospf
, old
);
754 char buf
[INET_ADDRSTRLEN
+ 3]; /* ipv4 and /XX */
756 prefix2str ((struct prefix
*) p
, buf
, sizeof(buf
));
757 zlog_warn ("%s: Could not refresh %s to %s",
760 inet_ntoa (area
->area_id
));
764 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
765 /* This will flood through area. */
770 if (IS_DEBUG_OSPF_EVENT
)
771 zlog_debug ("ospf_abr_announce_network_to_area(): "
772 "creating new summary");
773 lsa
= ospf_summary_lsa_originate ( (struct prefix_ipv4
*)p
, cost
, area
);
774 /* This will flood through area. */
778 char buf
[INET_ADDRSTRLEN
+ 3]; /* ipv4 and /XX */
780 prefix2str ((struct prefix
*)p
, buf
, sizeof(buf
));
781 zlog_warn ("%s: Could not originate %s to %s",
784 inet_ntoa (area
->area_id
));
788 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
789 if (IS_DEBUG_OSPF_EVENT
)
790 zlog_debug ("ospf_abr_announce_network_to_area(): "
791 "flooding new version of summary");
794 if (IS_DEBUG_OSPF_EVENT
)
795 zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
799 ospf_abr_nexthops_belong_to_area (struct ospf_route
*or,
800 struct ospf_area
*area
)
802 struct listnode
*node
, *nnode
;
803 struct ospf_path
*path
;
805 for (ALL_LIST_ELEMENTS (or->paths
, node
, nnode
, path
))
807 struct ospf_interface
*oi
= path
->oi
;
810 if (oi
->area
== area
)
818 ospf_abr_should_accept (struct prefix_ipv4
*p
, struct ospf_area
*area
)
820 if (IMPORT_NAME (area
))
822 if (IMPORT_LIST (area
) == NULL
)
823 IMPORT_LIST (area
) = access_list_lookup (AFI_IP
, IMPORT_NAME (area
));
825 if (IMPORT_LIST (area
))
826 if (access_list_apply (IMPORT_LIST (area
), p
) == FILTER_DENY
)
834 ospf_abr_plist_in_check (struct ospf_area
*area
, struct ospf_route
*or,
835 struct prefix_ipv4
*p
)
837 if (PREFIX_NAME_IN (area
))
839 if (PREFIX_LIST_IN (area
) == NULL
)
840 PREFIX_LIST_IN (area
) = prefix_list_lookup (AFI_IP
,
841 PREFIX_NAME_IN (area
));
842 if (PREFIX_LIST_IN (area
))
843 if (prefix_list_apply (PREFIX_LIST_IN (area
), p
) != PREFIX_PERMIT
)
850 ospf_abr_plist_out_check (struct ospf_area
*area
, struct ospf_route
*or,
851 struct prefix_ipv4
*p
)
853 if (PREFIX_NAME_OUT (area
))
855 if (PREFIX_LIST_OUT (area
) == NULL
)
856 PREFIX_LIST_OUT (area
) = prefix_list_lookup (AFI_IP
,
857 PREFIX_NAME_OUT (area
));
858 if (PREFIX_LIST_OUT (area
))
859 if (prefix_list_apply (PREFIX_LIST_OUT (area
), p
) != PREFIX_PERMIT
)
866 ospf_abr_announce_network (struct ospf
*ospf
,
867 struct prefix_ipv4
*p
, struct ospf_route
*or)
869 struct ospf_area_range
*range
;
870 struct ospf_area
*area
, *or_area
;
871 struct listnode
*node
;
873 if (IS_DEBUG_OSPF_EVENT
)
874 zlog_debug ("ospf_abr_announce_network(): Start");
876 or_area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
);
879 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
881 if (IS_DEBUG_OSPF_EVENT
)
882 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
883 inet_ntoa (area
->area_id
));
885 if (IPV4_ADDR_SAME (&or->u
.std
.area_id
, &area
->area_id
))
888 if (ospf_abr_nexthops_belong_to_area (or, area
))
891 if (!ospf_abr_should_accept (p
, area
))
893 if (IS_DEBUG_OSPF_EVENT
)
894 zlog_debug ("ospf_abr_announce_network(): "
895 "prefix %s/%d was denied by import-list",
896 inet_ntoa (p
->prefix
), p
->prefixlen
);
900 if (!ospf_abr_plist_in_check (area
, or, p
))
902 if (IS_DEBUG_OSPF_EVENT
)
903 zlog_debug ("ospf_abr_announce_network(): "
904 "prefix %s/%d was denied by prefix-list",
905 inet_ntoa (p
->prefix
), p
->prefixlen
);
909 if (area
->external_routing
!= OSPF_AREA_DEFAULT
&& area
->no_summary
)
911 if (IS_DEBUG_OSPF_EVENT
)
912 zlog_debug ("ospf_abr_announce_network(): "
913 "area %s is stub and no_summary",
914 inet_ntoa (area
->area_id
));
918 if (or->path_type
== OSPF_PATH_INTER_AREA
)
920 if (IS_DEBUG_OSPF_EVENT
)
921 zlog_debug ("ospf_abr_announce_network(): this is "
922 "inter-area route to %s/%d",
923 inet_ntoa (p
->prefix
), p
->prefixlen
);
925 if (!OSPF_IS_AREA_BACKBONE (area
))
926 ospf_abr_announce_network_to_area (p
, or->cost
, area
);
929 if (or->path_type
== OSPF_PATH_INTRA_AREA
)
931 if (IS_DEBUG_OSPF_EVENT
)
932 zlog_debug ("ospf_abr_announce_network(): "
933 "this is intra-area route to %s/%d",
934 inet_ntoa (p
->prefix
), p
->prefixlen
);
935 if ((range
= ospf_area_range_match (or_area
, p
))
936 && !ospf_area_is_transit (area
))
937 ospf_abr_update_aggregate (range
, or);
939 ospf_abr_announce_network_to_area (p
, or->cost
, area
);
945 ospf_abr_should_announce (struct ospf
*ospf
,
946 struct prefix_ipv4
*p
, struct ospf_route
*or)
948 struct ospf_area
*area
;
950 area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
);
954 if (EXPORT_NAME (area
))
956 if (EXPORT_LIST (area
) == NULL
)
957 EXPORT_LIST (area
) = access_list_lookup (AFI_IP
, EXPORT_NAME (area
));
959 if (EXPORT_LIST (area
))
960 if (access_list_apply (EXPORT_LIST (area
), p
) == FILTER_DENY
)
968 ospf_abr_process_nssa_translates (struct ospf
*ospf
)
970 /* Scan through all NSSA_LSDB records for all areas;
972 If P-bit is on, translate all Type-7's to 5's and aggregate or
973 flood install as approved in Type-5 LSDB with XLATE Flag on
974 later, do same for all aggregates... At end, DISCARD all
975 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
976 struct listnode
*node
;
977 struct ospf_area
*area
;
978 struct route_node
*rn
;
979 struct ospf_lsa
*lsa
;
981 if (IS_DEBUG_OSPF_NSSA
)
982 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
984 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
986 if (! area
->NSSATranslatorState
)
987 continue; /* skip if not translator */
989 if (area
->external_routing
!= OSPF_AREA_NSSA
)
990 continue; /* skip if not Nssa Area */
992 if (IS_DEBUG_OSPF_NSSA
)
993 zlog_debug ("ospf_abr_process_nssa_translates(): "
994 "looking at area %s", inet_ntoa (area
->area_id
));
996 LSDB_LOOP (NSSA_LSDB (area
), rn
, lsa
)
997 ospf_abr_translate_nssa (area
, lsa
);
1000 if (IS_DEBUG_OSPF_NSSA
)
1001 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
1006 ospf_abr_process_network_rt (struct ospf
*ospf
,
1007 struct route_table
*rt
)
1009 struct ospf_area
*area
;
1010 struct ospf_route
*or;
1011 struct route_node
*rn
;
1013 if (IS_DEBUG_OSPF_EVENT
)
1014 zlog_debug ("ospf_abr_process_network_rt(): Start");
1016 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1018 if ((or = rn
->info
) == NULL
)
1021 if (!(area
= ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
)))
1023 if (IS_DEBUG_OSPF_EVENT
)
1024 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
1025 inet_ntoa (or->u
.std
.area_id
));
1029 if (IS_DEBUG_OSPF_EVENT
)
1030 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
1031 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
1032 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
)
1034 if (IS_DEBUG_OSPF_EVENT
)
1035 zlog_debug ("ospf_abr_process_network_rt(): "
1036 "this is an External router, skipping");
1040 if (or->cost
>= OSPF_LS_INFINITY
)
1042 if (IS_DEBUG_OSPF_EVENT
)
1043 zlog_debug ("ospf_abr_process_network_rt():"
1044 " this route's cost is infinity, skipping");
1048 if (or->type
== OSPF_DESTINATION_DISCARD
)
1050 if (IS_DEBUG_OSPF_EVENT
)
1051 zlog_debug ("ospf_abr_process_network_rt():"
1052 " this is a discard entry, skipping");
1056 if (or->path_type
== OSPF_PATH_INTRA_AREA
&&
1057 !ospf_abr_should_announce (ospf
, (struct prefix_ipv4
*) &rn
->p
, or))
1059 if (IS_DEBUG_OSPF_EVENT
)
1060 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
1064 if (or->path_type
== OSPF_PATH_INTRA_AREA
&&
1065 !ospf_abr_plist_out_check (area
, or, (struct prefix_ipv4
*) &rn
->p
))
1067 if (IS_DEBUG_OSPF_EVENT
)
1068 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
1072 if ((or->path_type
== OSPF_PATH_INTER_AREA
) &&
1073 !OSPF_IS_AREA_ID_BACKBONE (or->u
.std
.area_id
))
1075 if (IS_DEBUG_OSPF_EVENT
)
1076 zlog_debug ("ospf_abr_process_network_rt():"
1077 " this is route is not backbone one, skipping");
1082 if ((ospf
->abr_type
== OSPF_ABR_CISCO
) ||
1083 (ospf
->abr_type
== OSPF_ABR_IBM
))
1085 if (!ospf_act_bb_connection (ospf
) &&
1086 or->path_type
!= OSPF_PATH_INTRA_AREA
)
1088 if (IS_DEBUG_OSPF_EVENT
)
1089 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
1090 "No BB connection, skip not intra-area routes");
1094 if (IS_DEBUG_OSPF_EVENT
)
1095 zlog_debug ("ospf_abr_process_network_rt(): announcing");
1096 ospf_abr_announce_network (ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
1099 if (IS_DEBUG_OSPF_EVENT
)
1100 zlog_debug ("ospf_abr_process_network_rt(): Stop");
1104 ospf_abr_announce_rtr_to_area (struct prefix_ipv4
*p
, u_int32_t cost
,
1105 struct ospf_area
*area
)
1107 struct ospf_lsa
*lsa
, *old
= NULL
;
1108 struct summary_lsa
*slsa
= NULL
;
1110 if (IS_DEBUG_OSPF_EVENT
)
1111 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
1113 old
= ospf_lsa_lookup_by_prefix (area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
,
1114 p
, area
->ospf
->router_id
);
1117 if (IS_DEBUG_OSPF_EVENT
)
1118 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
1119 slsa
= (struct summary_lsa
*) old
->data
;
1121 if (IS_DEBUG_OSPF_EVENT
)
1122 zlog_debug ("ospf_abr_announce_network_to_area(): "
1123 "old metric: %d, new metric: %d",
1124 GET_METRIC (slsa
->metric
), cost
);
1127 if (old
&& (GET_METRIC (slsa
->metric
) == cost
))
1129 if (IS_DEBUG_OSPF_EVENT
)
1130 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
1131 SET_FLAG (old
->flags
, OSPF_LSA_APPROVED
);
1135 if (IS_DEBUG_OSPF_EVENT
)
1136 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
1140 set_metric (old
, cost
);
1141 lsa
= ospf_summary_asbr_lsa_refresh (area
->ospf
, old
);
1144 lsa
= ospf_summary_asbr_lsa_originate (p
, cost
, area
);
1147 char buf
[INET_ADDRSTRLEN
+ 3]; /* ipv4 and /XX */
1149 prefix2str ((struct prefix
*)p
, buf
, sizeof(buf
));
1150 zlog_warn ("%s: Could not refresh/originate %s to %s",
1153 inet_ntoa (area
->area_id
));
1157 if (IS_DEBUG_OSPF_EVENT
)
1158 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
1159 "flooding new version of summary");
1162 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1163 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1165 SET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1166 /* ospf_flood_through_area (area, NULL, lsa);*/
1169 if (IS_DEBUG_OSPF_EVENT
)
1170 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
1175 ospf_abr_announce_rtr (struct ospf
*ospf
,
1176 struct prefix_ipv4
*p
, struct ospf_route
*or)
1178 struct listnode
*node
;
1179 struct ospf_area
*area
;
1181 if (IS_DEBUG_OSPF_EVENT
)
1182 zlog_debug ("ospf_abr_announce_rtr(): Start");
1184 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1186 if (IS_DEBUG_OSPF_EVENT
)
1187 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
1188 inet_ntoa (area
->area_id
));
1190 if (IPV4_ADDR_SAME (&or->u
.std
.area_id
, &area
->area_id
))
1193 if (ospf_abr_nexthops_belong_to_area (or, area
))
1196 if (area
->external_routing
!= OSPF_AREA_DEFAULT
)
1198 if (IS_DEBUG_OSPF_EVENT
)
1199 zlog_debug ("ospf_abr_announce_rtr(): "
1200 "area %s doesn't support external routing",
1201 inet_ntoa(area
->area_id
));
1205 if (or->path_type
== OSPF_PATH_INTER_AREA
)
1207 if (IS_DEBUG_OSPF_EVENT
)
1208 zlog_debug ("ospf_abr_announce_rtr(): "
1209 "this is inter-area route to %s", inet_ntoa (p
->prefix
));
1210 if (!OSPF_IS_AREA_BACKBONE (area
))
1211 ospf_abr_announce_rtr_to_area (p
, or->cost
, area
);
1214 if (or->path_type
== OSPF_PATH_INTRA_AREA
)
1216 if (IS_DEBUG_OSPF_EVENT
)
1217 zlog_debug ("ospf_abr_announce_rtr(): "
1218 "this is intra-area route to %s", inet_ntoa (p
->prefix
));
1219 ospf_abr_announce_rtr_to_area (p
, or->cost
, area
);
1223 if (IS_DEBUG_OSPF_EVENT
)
1224 zlog_debug ("ospf_abr_announce_rtr(): Stop");
1228 ospf_abr_process_router_rt (struct ospf
*ospf
, struct route_table
*rt
)
1230 struct ospf_route
*or;
1231 struct route_node
*rn
;
1234 if (IS_DEBUG_OSPF_EVENT
)
1235 zlog_debug ("ospf_abr_process_router_rt(): Start");
1237 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1239 struct listnode
*node
, *nnode
;
1241 struct ospf_route
*best
= NULL
;
1243 if (rn
->info
== NULL
)
1248 if (IS_DEBUG_OSPF_EVENT
)
1249 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
1250 inet_ntoa (rn
->p
.u
.prefix4
));
1252 for (ALL_LIST_ELEMENTS (l
, node
, nnode
, or))
1254 if (!ospf_area_lookup_by_area_id (ospf
, or->u
.std
.area_id
))
1256 if (IS_DEBUG_OSPF_EVENT
)
1257 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
1258 inet_ntoa (or->u
.std
.area_id
));
1263 if (!CHECK_FLAG (or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
))
1265 if (IS_DEBUG_OSPF_EVENT
)
1266 zlog_debug ("ospf_abr_process_router_rt(): "
1267 "This is not an ASBR, skipping");
1273 best
= ospf_find_asbr_route (ospf
, rt
,
1274 (struct prefix_ipv4
*) &rn
->p
);
1283 if (IS_DEBUG_OSPF_EVENT
)
1284 zlog_debug ("ospf_abr_process_router_rt(): "
1285 "This route is not the best among possible, skipping");
1289 if (or->path_type
== OSPF_PATH_INTER_AREA
&&
1290 !OSPF_IS_AREA_ID_BACKBONE (or->u
.std
.area_id
))
1292 if (IS_DEBUG_OSPF_EVENT
)
1293 zlog_debug ("ospf_abr_process_router_rt(): "
1294 "This route is not a backbone one, skipping");
1298 if (or->cost
>= OSPF_LS_INFINITY
)
1300 if (IS_DEBUG_OSPF_EVENT
)
1301 zlog_debug ("ospf_abr_process_router_rt(): "
1302 "This route has LS_INFINITY metric, skipping");
1306 if (ospf
->abr_type
== OSPF_ABR_CISCO
1307 || ospf
->abr_type
== OSPF_ABR_IBM
)
1308 if (!ospf_act_bb_connection (ospf
)
1309 && or->path_type
!= OSPF_PATH_INTRA_AREA
)
1311 if (IS_DEBUG_OSPF_EVENT
)
1312 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
1313 "No BB connection, skip not intra-area routes");
1317 ospf_abr_announce_rtr (ospf
, (struct prefix_ipv4
*) &rn
->p
, or);
1323 if (IS_DEBUG_OSPF_EVENT
)
1324 zlog_debug ("ospf_abr_process_router_rt(): Stop");
1328 ospf_abr_unapprove_translates (struct ospf
*ospf
) /* For NSSA Translations */
1330 struct ospf_lsa
*lsa
;
1331 struct route_node
*rn
;
1333 if (IS_DEBUG_OSPF_NSSA
)
1334 zlog_debug ("ospf_abr_unapprove_translates(): Start");
1336 /* NSSA Translator is not checked, because it may have gone away,
1337 and we would want to flush any residuals anyway */
1339 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
1340 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
1342 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1343 if (IS_DEBUG_OSPF_NSSA
)
1344 zlog_debug ("ospf_abr_unapprove_translates(): "
1345 "approved unset on link id %s",
1346 inet_ntoa (lsa
->data
->id
));
1349 if (IS_DEBUG_OSPF_NSSA
)
1350 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
1354 ospf_abr_unapprove_summaries (struct ospf
*ospf
)
1356 struct listnode
*node
;
1357 struct ospf_area
*area
;
1358 struct route_node
*rn
;
1359 struct ospf_lsa
*lsa
;
1361 if (IS_DEBUG_OSPF_EVENT
)
1362 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
1364 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1366 if (IS_DEBUG_OSPF_EVENT
)
1367 zlog_debug ("ospf_abr_unapprove_summaries(): "
1368 "considering area %s",
1369 inet_ntoa (area
->area_id
));
1370 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
1371 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1373 if (IS_DEBUG_OSPF_EVENT
)
1374 zlog_debug ("ospf_abr_unapprove_summaries(): "
1375 "approved unset on summary link id %s",
1376 inet_ntoa (lsa
->data
->id
));
1377 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1380 LSDB_LOOP (ASBR_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 asbr-summary link id %s",
1386 inet_ntoa (lsa
->data
->id
));
1387 UNSET_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
);
1391 if (IS_DEBUG_OSPF_EVENT
)
1392 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
1396 ospf_abr_prepare_aggregates (struct ospf
*ospf
)
1398 struct listnode
*node
;
1399 struct route_node
*rn
;
1400 struct ospf_area_range
*range
;
1401 struct ospf_area
*area
;
1403 if (IS_DEBUG_OSPF_EVENT
)
1404 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
1406 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1408 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1409 if ((range
= rn
->info
) != NULL
)
1412 range
->specifics
= 0;
1416 if (IS_DEBUG_OSPF_EVENT
)
1417 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
1421 ospf_abr_announce_aggregates (struct ospf
*ospf
)
1423 struct ospf_area
*area
, *ar
;
1424 struct ospf_area_range
*range
;
1425 struct route_node
*rn
;
1427 struct listnode
*node
, *n
;
1429 if (IS_DEBUG_OSPF_EVENT
)
1430 zlog_debug ("ospf_abr_announce_aggregates(): Start");
1432 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1434 if (IS_DEBUG_OSPF_EVENT
)
1435 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
1436 inet_ntoa (area
->area_id
));
1438 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1439 if ((range
= rn
->info
))
1441 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1443 if (IS_DEBUG_OSPF_EVENT
)
1444 zlog_debug ("ospf_abr_announce_aggregates():"
1445 " discarding suppress-ranges");
1450 p
.u
.prefix4
= range
->addr
;
1451 p
.prefixlen
= range
->masklen
;
1453 if (IS_DEBUG_OSPF_EVENT
)
1454 zlog_debug ("ospf_abr_announce_aggregates():"
1455 " this is range: %s/%d",
1456 inet_ntoa (p
.u
.prefix4
), p
.prefixlen
);
1458 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
1461 p
.u
.prefix4
= range
->subst_addr
;
1462 p
.prefixlen
= range
->subst_masklen
;
1465 if (range
->specifics
)
1467 if (IS_DEBUG_OSPF_EVENT
)
1468 zlog_debug ("ospf_abr_announce_aggregates(): active range");
1470 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, n
, ar
))
1475 /* We do not check nexthops here, because
1476 intra-area routes can be associated with
1479 /* backbone routes are not summarized
1480 when announced into transit areas */
1482 if (ospf_area_is_transit (ar
) &&
1483 OSPF_IS_AREA_BACKBONE (area
))
1485 if (IS_DEBUG_OSPF_EVENT
)
1486 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
1487 "announcement of BB aggregate into"
1491 ospf_abr_announce_network_to_area ((struct prefix_ipv4
*)&p
, range
->cost
, ar
);
1497 if (IS_DEBUG_OSPF_EVENT
)
1498 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
1502 ospf_abr_send_nssa_aggregates (struct ospf
*ospf
) /* temporarily turned off */
1504 struct listnode
*node
; /*, n; */
1505 struct ospf_area
*area
; /*, *ar; */
1506 struct route_node
*rn
;
1507 struct ospf_area_range
*range
;
1508 struct prefix_ipv4 p
;
1510 if (IS_DEBUG_OSPF_NSSA
)
1511 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
1513 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1515 if (! area
->NSSATranslatorState
)
1518 if (IS_DEBUG_OSPF_NSSA
)
1519 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
1520 inet_ntoa (area
->area_id
));
1522 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1524 if (rn
->info
== NULL
)
1529 if (!CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1531 if (IS_DEBUG_OSPF_NSSA
)
1532 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1533 " discarding suppress-ranges");
1538 p
.prefix
= range
->addr
;
1539 p
.prefixlen
= range
->masklen
;
1541 if (IS_DEBUG_OSPF_NSSA
)
1542 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1543 " this is range: %s/%d",
1544 inet_ntoa (p
.prefix
), p
.prefixlen
);
1546 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
1549 p
.prefix
= range
->subst_addr
;
1550 p
.prefixlen
= range
->subst_masklen
;
1553 if (range
->specifics
)
1555 if (IS_DEBUG_OSPF_NSSA
)
1556 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
1558 /* Fetch LSA-Type-7 from aggregate prefix, and then
1559 * translate, Install (as Type-5), Approve, and Flood
1561 ospf_abr_translate_nssa_range (&p
, range
->cost
);
1563 } /* all area ranges*/
1566 if (IS_DEBUG_OSPF_NSSA
)
1567 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
1571 ospf_abr_announce_nssa_defaults (struct ospf
*ospf
) /* By ABR-Translator */
1573 struct listnode
*node
;
1574 struct ospf_area
*area
;
1576 if (! IS_OSPF_ABR (ospf
))
1579 if (IS_DEBUG_OSPF_NSSA
)
1580 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
1582 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1584 if (IS_DEBUG_OSPF_NSSA
)
1585 zlog_debug ("ospf_abr_announce_nssa_defaults(): looking at area %s",
1586 inet_ntoa (area
->area_id
));
1588 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1591 if (OSPF_IS_AREA_BACKBONE (area
))
1592 continue; /* Sanity Check */
1594 /* if (!TranslatorRole continue V 1.0 look for "always" conf */
1595 if (area
->NSSATranslatorState
)
1597 if (IS_DEBUG_OSPF_NSSA
)
1598 zlog_debug ("ospf_abr_announce_nssa_defaults(): "
1599 "announcing 0.0.0.0/0 to this nssa");
1600 /* ospf_abr_announce_nssa_asbr_to_as (&p, area->default_cost, area); */
1601 /*ospf_abr_announce_network_to_area (&p, area->default_cost, area);*/
1607 ospf_abr_announce_stub_defaults (struct ospf
*ospf
)
1609 struct listnode
*node
;
1610 struct ospf_area
*area
;
1611 struct prefix_ipv4 p
;
1613 if (! IS_OSPF_ABR (ospf
))
1616 if (IS_DEBUG_OSPF_EVENT
)
1617 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
1620 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1623 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1625 if (IS_DEBUG_OSPF_EVENT
)
1626 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1627 inet_ntoa (area
->area_id
));
1629 if ( (area
->external_routing
!= OSPF_AREA_STUB
)
1630 && (area
->external_routing
!= OSPF_AREA_NSSA
)
1634 if (OSPF_IS_AREA_BACKBONE (area
))
1635 continue; /* Sanity Check */
1637 if (IS_DEBUG_OSPF_EVENT
)
1638 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1639 "announcing 0.0.0.0/0 to area %s",
1640 inet_ntoa (area
->area_id
));
1641 ospf_abr_announce_network_to_area (&p
, area
->default_cost
, area
);
1644 if (IS_DEBUG_OSPF_EVENT
)
1645 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
1649 ospf_abr_remove_unapproved_translates_apply (struct ospf
*ospf
,
1650 struct ospf_lsa
*lsa
)
1652 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1653 && ! CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1655 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1656 "removing unapproved translates, ID: %s",
1657 inet_ntoa (lsa
->data
->id
));
1659 /* FLUSH THROUGHOUT AS */
1660 ospf_lsa_flush_as (ospf
, lsa
);
1662 /* DISCARD from LSDB */
1668 ospf_abr_remove_unapproved_translates (struct ospf
*ospf
)
1670 struct route_node
*rn
;
1671 struct ospf_lsa
*lsa
;
1673 /* All AREA PROCESS should have APPROVED necessary LSAs */
1674 /* Remove any left over and not APPROVED */
1675 if (IS_DEBUG_OSPF_NSSA
)
1676 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
1678 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
1679 ospf_abr_remove_unapproved_translates_apply (ospf
, lsa
);
1681 if (IS_DEBUG_OSPF_NSSA
)
1682 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
1686 ospf_abr_remove_unapproved_summaries (struct ospf
*ospf
)
1688 struct listnode
*node
;
1689 struct ospf_area
*area
;
1690 struct route_node
*rn
;
1691 struct ospf_lsa
*lsa
;
1693 if (IS_DEBUG_OSPF_EVENT
)
1694 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
1696 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
1698 if (IS_DEBUG_OSPF_EVENT
)
1699 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
1700 "looking at area %s", inet_ntoa (area
->area_id
));
1702 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
1703 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1704 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1705 ospf_lsa_flush_area (lsa
, area
);
1707 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
1708 if (ospf_lsa_is_self_originated (ospf
, lsa
))
1709 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_APPROVED
))
1710 ospf_lsa_flush_area (lsa
, area
);
1713 if (IS_DEBUG_OSPF_EVENT
)
1714 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
1718 ospf_abr_manage_discard_routes (struct ospf
*ospf
)
1720 struct listnode
*node
, *nnode
;
1721 struct route_node
*rn
;
1722 struct ospf_area
*area
;
1723 struct ospf_area_range
*range
;
1725 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
1726 for (rn
= route_top (area
->ranges
); rn
; rn
= route_next (rn
))
1727 if ((range
= rn
->info
) != NULL
)
1728 if (CHECK_FLAG (range
->flags
, OSPF_AREA_RANGE_ADVERTISE
))
1730 if (range
->specifics
)
1731 ospf_add_discard_route (ospf
->new_table
, area
,
1732 (struct prefix_ipv4
*) &rn
->p
);
1734 ospf_delete_discard_route ((struct prefix_ipv4
*) &rn
->p
);
1738 /* This is the function taking care about ABR NSSA, i.e. NSSA
1739 Translator, -LSA aggregation and flooding. For all NSSAs
1741 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1742 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1745 Any received Type-5s are legal for an ABR, else illegal for IR.
1746 Received Type-7s are installed, by area, with incoming P-bit. They
1747 are flooded; if the Elected NSSA Translator, then P-bit off.
1749 Additionally, this ABR will place "translated type-7's" into the
1750 Type-5 LSDB in order to keep track of APPROVAL or not.
1752 It will scan through every area, looking for Type-7 LSAs with P-Bit
1753 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1754 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1757 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1758 left over are FLUSHED and DISCARDED.
1760 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1761 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1764 ospf_abr_nssa_task (struct ospf
*ospf
) /* called only if any_nssa */
1766 if (IS_DEBUG_OSPF_NSSA
)
1767 zlog_debug ("Check for NSSA-ABR Tasks():");
1769 if (! IS_OSPF_ABR (ospf
))
1772 if (! ospf
->anyNSSA
)
1775 /* Each area must confirm TranslatorRole */
1776 if (IS_DEBUG_OSPF_NSSA
)
1777 zlog_debug ("ospf_abr_nssa_task(): Start");
1779 /* For all Global Entries flagged "local-translate", unset APPROVED */
1780 if (IS_DEBUG_OSPF_NSSA
)
1781 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
1783 ospf_abr_unapprove_translates (ospf
);
1785 /* RESET all Ranges in every Area, same as summaries */
1786 if (IS_DEBUG_OSPF_NSSA
)
1787 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
1788 ospf_abr_prepare_aggregates (ospf
); /*TURNED OFF just for now */
1790 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1791 * Aggregate as Type-7
1792 * Install or Approve in Type-5 Global LSDB
1794 if (IS_DEBUG_OSPF_NSSA
)
1795 zlog_debug ("ospf_abr_nssa_task(): process translates");
1796 ospf_abr_process_nssa_translates (ospf
);
1798 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1800 * Scan Type-7's for aggregates, translate to Type-5's,
1801 * Install/Flood/Approve
1803 if (IS_DEBUG_OSPF_NSSA
)
1804 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1805 ospf_abr_send_nssa_aggregates (ospf
); /*TURNED OFF FOR NOW */
1807 /* Send any NSSA defaults as Type-5
1808 *if (IS_DEBUG_OSPF_NSSA)
1809 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1810 *ospf_abr_announce_nssa_defaults (ospf);
1811 * havnt a clue what above is supposed to do.
1814 /* Flush any unapproved previous translates from Global Data Base */
1815 if (IS_DEBUG_OSPF_NSSA
)
1816 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
1817 ospf_abr_remove_unapproved_translates (ospf
);
1819 ospf_abr_manage_discard_routes (ospf
); /* same as normal...discard */
1821 if (IS_DEBUG_OSPF_NSSA
)
1822 zlog_debug ("ospf_abr_nssa_task(): Stop");
1825 /* This is the function taking care about ABR stuff, i.e.
1826 summary-LSA origination and flooding. */
1828 ospf_abr_task (struct ospf
*ospf
)
1830 if (IS_DEBUG_OSPF_EVENT
)
1831 zlog_debug ("ospf_abr_task(): Start");
1833 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
)
1835 if (IS_DEBUG_OSPF_EVENT
)
1836 zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
1840 if (IS_DEBUG_OSPF_EVENT
)
1841 zlog_debug ("ospf_abr_task(): unapprove summaries");
1842 ospf_abr_unapprove_summaries (ospf
);
1844 if (IS_DEBUG_OSPF_EVENT
)
1845 zlog_debug ("ospf_abr_task(): prepare aggregates");
1846 ospf_abr_prepare_aggregates (ospf
);
1848 if (IS_OSPF_ABR (ospf
))
1850 if (IS_DEBUG_OSPF_EVENT
)
1851 zlog_debug ("ospf_abr_task(): process network RT");
1852 ospf_abr_process_network_rt (ospf
, ospf
->new_table
);
1854 if (IS_DEBUG_OSPF_EVENT
)
1855 zlog_debug ("ospf_abr_task(): process router RT");
1856 ospf_abr_process_router_rt (ospf
, ospf
->new_rtrs
);
1858 if (IS_DEBUG_OSPF_EVENT
)
1859 zlog_debug ("ospf_abr_task(): announce aggregates");
1860 ospf_abr_announce_aggregates (ospf
);
1862 if (IS_DEBUG_OSPF_EVENT
)
1863 zlog_debug ("ospf_abr_task(): announce stub defaults");
1864 ospf_abr_announce_stub_defaults (ospf
);
1867 if (IS_DEBUG_OSPF_EVENT
)
1868 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
1869 ospf_abr_remove_unapproved_summaries (ospf
);
1871 ospf_abr_manage_discard_routes (ospf
);
1873 if (IS_DEBUG_OSPF_EVENT
)
1874 zlog_debug ("ospf_abr_task(): Stop");
1878 ospf_abr_task_timer (struct thread
*thread
)
1880 struct ospf
*ospf
= THREAD_ARG (thread
);
1882 ospf
->t_abr_task
= 0;
1884 if (IS_DEBUG_OSPF_EVENT
)
1885 zlog_debug ("Running ABR task on timer");
1887 ospf_check_abr_status (ospf
);
1888 ospf_abr_nssa_check_status (ospf
);
1890 ospf_abr_task (ospf
);
1891 ospf_abr_nssa_task (ospf
); /* if nssa-abr, then scan Type-7 LSDB */
1897 ospf_schedule_abr_task (struct ospf
*ospf
)
1899 if (IS_DEBUG_OSPF_EVENT
)
1900 zlog_debug ("Scheduling ABR task");
1902 if (ospf
->t_abr_task
== NULL
)
1903 ospf
->t_abr_task
= thread_add_timer (master
, ospf_abr_task_timer
,
1904 ospf
, OSPF_ABR_TASK_DELAY
);