3 * Copyright (C) 1999, 2000 Alex Zinin, Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 #include "ospfd/ospfd.h"
37 #include "ospfd/ospf_interface.h"
38 #include "ospfd/ospf_ism.h"
39 #include "ospfd/ospf_asbr.h"
40 #include "ospfd/ospf_lsa.h"
41 #include "ospfd/ospf_lsdb.h"
42 #include "ospfd/ospf_neighbor.h"
43 #include "ospfd/ospf_nsm.h"
44 #include "ospfd/ospf_spf.h"
45 #include "ospfd/ospf_route.h"
46 #include "ospfd/ospf_ia.h"
47 #include "ospfd/ospf_flood.h"
48 #include "ospfd/ospf_abr.h"
49 #include "ospfd/ospf_ase.h"
50 #include "ospfd/ospf_zebra.h"
51 #include "ospfd/ospf_dump.h"
52 #include "ospfd/ospf_errors.h"
54 static struct ospf_area_range
*ospf_area_range_new(struct prefix_ipv4
*p
)
56 struct ospf_area_range
*range
;
58 range
= XCALLOC(MTYPE_OSPF_AREA_RANGE
, sizeof(struct ospf_area_range
));
59 range
->addr
= p
->prefix
;
60 range
->masklen
= p
->prefixlen
;
61 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
66 static void ospf_area_range_free(struct ospf_area_range
*range
)
68 XFREE(MTYPE_OSPF_AREA_RANGE
, range
);
71 static void ospf_area_range_add(struct ospf_area
*area
,
72 struct ospf_area_range
*range
)
74 struct route_node
*rn
;
78 p
.prefixlen
= range
->masklen
;
79 p
.prefix
= range
->addr
;
82 rn
= route_node_get(area
->ranges
, (struct prefix
*)&p
);
84 route_unlock_node(rn
);
89 static void ospf_area_range_delete(struct ospf_area
*area
,
90 struct route_node
*rn
)
92 struct ospf_area_range
*range
= rn
->info
;
94 if (range
->specifics
!= 0)
95 ospf_delete_discard_route(area
->ospf
, area
->ospf
->new_table
,
96 (struct prefix_ipv4
*)&rn
->p
);
98 ospf_area_range_free(range
);
100 route_unlock_node(rn
);
101 route_unlock_node(rn
);
104 struct ospf_area_range
*ospf_area_range_lookup(struct ospf_area
*area
,
105 struct prefix_ipv4
*p
)
107 struct route_node
*rn
;
109 rn
= route_node_lookup(area
->ranges
, (struct prefix
*)p
);
111 route_unlock_node(rn
);
117 struct ospf_area_range
*ospf_area_range_lookup_next(struct ospf_area
*area
,
118 struct in_addr
*range_net
,
121 struct route_node
*rn
;
122 struct prefix_ipv4 p
;
123 struct ospf_area_range
*find
;
126 p
.prefixlen
= IPV4_MAX_BITLEN
;
127 p
.prefix
= *range_net
;
131 rn
= route_top(area
->ranges
);
133 rn
= route_node_get(area
->ranges
, (struct prefix
*)&p
);
137 for (; rn
; rn
= route_next(rn
))
141 if (rn
&& rn
->info
) {
143 *range_net
= rn
->p
.u
.prefix4
;
144 route_unlock_node(rn
);
150 static struct ospf_area_range
*ospf_area_range_match(struct ospf_area
*area
,
151 struct prefix_ipv4
*p
)
153 struct route_node
*node
;
155 node
= route_node_match(area
->ranges
, (struct prefix
*)p
);
157 route_unlock_node(node
);
163 struct ospf_area_range
*ospf_area_range_match_any(struct ospf
*ospf
,
164 struct prefix_ipv4
*p
)
166 struct ospf_area_range
*range
;
167 struct ospf_area
*area
;
168 struct listnode
*node
;
170 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
171 if ((range
= ospf_area_range_match(area
, p
)))
177 int ospf_area_range_active(struct ospf_area_range
*range
)
179 return range
->specifics
;
182 static int ospf_area_actively_attached(struct ospf_area
*area
)
184 return area
->act_ints
;
187 int ospf_area_range_set(struct ospf
*ospf
, struct in_addr area_id
,
188 struct prefix_ipv4
*p
, int advertise
)
190 struct ospf_area
*area
;
191 struct ospf_area_range
*range
;
193 area
= ospf_area_get(ospf
, area_id
);
197 range
= ospf_area_range_lookup(area
, p
);
199 if (!CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
200 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
201 if ((CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
202 && !CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
203 || (!CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
204 && CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
)))
205 ospf_schedule_abr_task(ospf
);
207 range
= ospf_area_range_new(p
);
208 ospf_area_range_add(area
, range
);
209 ospf_schedule_abr_task(ospf
);
212 if (CHECK_FLAG(advertise
, OSPF_AREA_RANGE_ADVERTISE
))
213 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
215 UNSET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
216 range
->cost_config
= OSPF_AREA_RANGE_COST_UNSPEC
;
222 int ospf_area_range_cost_set(struct ospf
*ospf
, struct in_addr area_id
,
223 struct prefix_ipv4
*p
, uint32_t cost
)
225 struct ospf_area
*area
;
226 struct ospf_area_range
*range
;
228 area
= ospf_area_get(ospf
, area_id
);
232 range
= ospf_area_range_lookup(area
, p
);
236 if (range
->cost_config
!= cost
) {
237 range
->cost_config
= cost
;
238 if (ospf_area_range_active(range
))
239 ospf_schedule_abr_task(ospf
);
245 int ospf_area_range_unset(struct ospf
*ospf
, struct in_addr area_id
,
246 struct prefix_ipv4
*p
)
248 struct ospf_area
*area
;
249 struct route_node
*rn
;
251 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
255 rn
= route_node_lookup(area
->ranges
, (struct prefix
*)p
);
259 if (ospf_area_range_active(rn
->info
))
260 ospf_schedule_abr_task(ospf
);
262 ospf_area_range_delete(area
, rn
);
267 int ospf_area_range_substitute_set(struct ospf
*ospf
, struct in_addr area_id
,
268 struct prefix_ipv4
*p
, struct prefix_ipv4
*s
)
270 struct ospf_area
*area
;
271 struct ospf_area_range
*range
;
273 area
= ospf_area_get(ospf
, area_id
);
274 range
= ospf_area_range_lookup(area
, p
);
277 if (!CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
)
278 || !CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
279 ospf_schedule_abr_task(ospf
);
281 range
= ospf_area_range_new(p
);
282 ospf_area_range_add(area
, range
);
283 ospf_schedule_abr_task(ospf
);
286 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_ADVERTISE
);
287 SET_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
288 range
->subst_addr
= s
->prefix
;
289 range
->subst_masklen
= s
->prefixlen
;
294 int ospf_area_range_substitute_unset(struct ospf
*ospf
, struct in_addr area_id
,
295 struct prefix_ipv4
*p
)
297 struct ospf_area
*area
;
298 struct ospf_area_range
*range
;
300 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
304 range
= ospf_area_range_lookup(area
, p
);
308 if (CHECK_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
))
309 if (ospf_area_range_active(range
))
310 ospf_schedule_abr_task(ospf
);
312 UNSET_FLAG(range
->flags
, OSPF_AREA_RANGE_SUBSTITUTE
);
313 range
->subst_addr
.s_addr
= INADDR_ANY
;
314 range
->subst_masklen
= 0;
319 int ospf_act_bb_connection(struct ospf
*ospf
)
321 if (ospf
->backbone
== NULL
)
324 return ospf
->backbone
->full_nbrs
;
327 /* Determine whether this router is elected translator or not for area */
328 static int ospf_abr_nssa_am_elected(struct ospf_area
*area
)
330 struct route_node
*rn
;
331 struct ospf_lsa
*lsa
;
332 struct router_lsa
*rlsa
;
333 struct in_addr
*best
= NULL
;
335 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
) {
337 if (!lsa
|| (lsa
->data
->type
!= OSPF_ROUTER_LSA
)
341 rlsa
= (struct router_lsa
*)lsa
->data
;
343 /* ignore non-ABR routers */
344 if (!IS_ROUTER_LSA_BORDER(rlsa
))
347 /* Router has Nt flag - always translate */
348 if (IS_ROUTER_LSA_NT(rlsa
)) {
349 if (IS_DEBUG_OSPF_NSSA
)
351 "ospf_abr_nssa_am_elected: "
352 "router %s asserts Nt",
353 inet_ntoa(lsa
->data
->id
));
358 best
= &lsa
->data
->id
;
359 else if (IPV4_ADDR_CMP(&best
->s_addr
, &lsa
->data
->id
.s_addr
)
361 best
= &lsa
->data
->id
;
364 if (IS_DEBUG_OSPF_NSSA
)
366 "ospf_abr_nssa_am_elected: best electable ABR is: %s",
367 (best
) ? inet_ntoa(*best
) : "<none>");
372 if (IPV4_ADDR_CMP(&best
->s_addr
, &area
->ospf
->router_id
.s_addr
) < 0)
378 /* Check NSSA ABR status
379 * assumes there are nssa areas
381 static void ospf_abr_nssa_check_status(struct ospf
*ospf
)
383 struct ospf_area
*area
;
384 struct listnode
*lnode
, *nnode
;
386 for (ALL_LIST_ELEMENTS(ospf
->areas
, lnode
, nnode
, area
)) {
387 uint8_t old_state
= area
->NSSATranslatorState
;
389 if (area
->external_routing
!= OSPF_AREA_NSSA
)
392 if (IS_DEBUG_OSPF(nssa
, NSSA
))
394 "ospf_abr_nssa_check_status: "
396 inet_ntoa(area
->area_id
));
398 if (!IS_OSPF_ABR(area
->ospf
)) {
399 if (IS_DEBUG_OSPF(nssa
, NSSA
))
401 "ospf_abr_nssa_check_status: "
403 area
->NSSATranslatorState
=
404 OSPF_NSSA_TRANSLATE_DISABLED
;
406 switch (area
->NSSATranslatorRole
) {
407 case OSPF_NSSA_ROLE_NEVER
:
408 /* We never Translate Type-7 LSA. */
409 /* TODO: check previous state and flush? */
410 if (IS_DEBUG_OSPF(nssa
, NSSA
))
412 "ospf_abr_nssa_check_status: "
414 area
->NSSATranslatorState
=
415 OSPF_NSSA_TRANSLATE_DISABLED
;
418 case OSPF_NSSA_ROLE_ALWAYS
:
419 /* We always translate if we are an ABR
420 * TODO: originate new LSAs if state change?
421 * or let the nssa abr task take care of it?
423 if (IS_DEBUG_OSPF(nssa
, NSSA
))
425 "ospf_abr_nssa_check_status: "
427 area
->NSSATranslatorState
=
428 OSPF_NSSA_TRANSLATE_ENABLED
;
431 case OSPF_NSSA_ROLE_CANDIDATE
:
432 /* We are a candidate for Translation */
433 if (ospf_abr_nssa_am_elected(area
) > 0) {
434 area
->NSSATranslatorState
=
435 OSPF_NSSA_TRANSLATE_ENABLED
;
436 if (IS_DEBUG_OSPF(nssa
, NSSA
))
438 "ospf_abr_nssa_check_status: "
439 "elected translator");
441 area
->NSSATranslatorState
=
442 OSPF_NSSA_TRANSLATE_DISABLED
;
443 if (IS_DEBUG_OSPF(nssa
, NSSA
))
445 "ospf_abr_nssa_check_status: "
452 * All NSSA border routers must set the E-bit in the Type-1
454 * of their directly attached non-stub areas, even when they are
458 if (old_state
!= area
->NSSATranslatorState
) {
459 if (old_state
== OSPF_NSSA_TRANSLATE_DISABLED
)
460 ospf_asbr_status_update(ospf
,
461 ++ospf
->redistribute
);
462 else if (area
->NSSATranslatorState
463 == OSPF_NSSA_TRANSLATE_DISABLED
)
464 ospf_asbr_status_update(ospf
,
465 --ospf
->redistribute
);
470 /* Check area border router status. */
471 void ospf_check_abr_status(struct ospf
*ospf
)
473 struct ospf_area
*area
;
474 struct listnode
*node
, *nnode
;
475 int bb_configured
= 0;
476 int bb_act_attached
= 0;
477 int areas_configured
= 0;
478 int areas_act_attached
= 0;
479 uint8_t new_flags
= ospf
->flags
;
481 if (IS_DEBUG_OSPF_EVENT
)
482 zlog_debug("ospf_check_abr_status(): Start");
484 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
485 if (listcount(area
->oiflist
)) {
488 if (OSPF_IS_AREA_BACKBONE(area
))
492 if (ospf_area_actively_attached(area
)) {
493 areas_act_attached
++;
495 if (OSPF_IS_AREA_BACKBONE(area
))
500 if (IS_DEBUG_OSPF_EVENT
) {
501 zlog_debug("ospf_check_abr_status(): looked through areas");
502 zlog_debug("ospf_check_abr_status(): bb_configured: %d",
504 zlog_debug("ospf_check_abr_status(): bb_act_attached: %d",
506 zlog_debug("ospf_check_abr_status(): areas_configured: %d",
508 zlog_debug("ospf_check_abr_status(): areas_act_attached: %d",
512 switch (ospf
->abr_type
) {
513 case OSPF_ABR_SHORTCUT
:
515 if (areas_act_attached
> 1)
516 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
518 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
522 if ((areas_act_attached
> 1) && bb_configured
)
523 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
525 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
529 if ((areas_configured
> 1) && bb_act_attached
)
530 SET_FLAG(new_flags
, OSPF_FLAG_ABR
);
532 UNSET_FLAG(new_flags
, OSPF_FLAG_ABR
);
538 if (new_flags
!= ospf
->flags
) {
539 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_ABR_STATUS_CHANGE
);
540 if (IS_DEBUG_OSPF_EVENT
)
542 "ospf_check_abr_status(): new router flags: %x",
544 ospf
->flags
= new_flags
;
545 ospf_router_lsa_update(ospf
);
549 static void ospf_abr_update_aggregate(struct ospf_area_range
*range
,
550 struct ospf_route
* or,
551 struct ospf_area
*area
)
553 if (IS_DEBUG_OSPF_EVENT
)
554 zlog_debug("ospf_abr_update_aggregate(): Start");
556 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)
557 && (range
->cost
!= OSPF_STUB_MAX_METRIC_SUMMARY_COST
)) {
558 range
->cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
559 if (IS_DEBUG_OSPF_EVENT
)
561 "ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
563 } else if (range
->cost_config
!= OSPF_AREA_RANGE_COST_UNSPEC
) {
564 if (IS_DEBUG_OSPF_EVENT
)
566 "ospf_abr_update_aggregate(): use configured cost %d",
569 range
->cost
= range
->cost_config
;
571 if (range
->specifics
== 0) {
572 if (IS_DEBUG_OSPF_EVENT
)
574 "ospf_abr_update_aggregate(): use or->cost %d",
577 range
->cost
= or->cost
; /* 1st time get 1st cost */
580 if (or->cost
> range
->cost
) {
581 if (IS_DEBUG_OSPF_EVENT
)
583 "ospf_abr_update_aggregate(): update to %d",
586 range
->cost
= or->cost
;
593 static void set_metric(struct ospf_lsa
*lsa
, uint32_t metric
)
595 struct summary_lsa
*header
;
597 metric
= htonl(metric
);
598 mp
= (uint8_t *)&metric
;
600 header
= (struct summary_lsa
*)lsa
->data
;
601 memcpy(header
->metric
, mp
, 3);
604 /* ospf_abr_translate_nssa */
605 static int ospf_abr_translate_nssa(struct ospf_area
*area
, struct ospf_lsa
*lsa
)
607 /* Incoming Type-7 or later aggregated Type-7
609 * LSA is skipped if P-bit is off.
610 * LSA is aggregated if within range.
612 * The Type-7 is translated, Installed/Approved as a Type-5 into
613 * global LSDB, then Flooded through AS
615 * Later, any Unapproved Translated Type-5's are flushed/discarded
618 struct ospf_lsa
*old
= NULL
, *new = NULL
;
619 struct as_external_lsa
*ext7
;
620 struct prefix_ipv4 p
;
622 if (!CHECK_FLAG(lsa
->data
->options
, OSPF_OPTION_NP
)) {
623 if (IS_DEBUG_OSPF_NSSA
)
625 "ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
626 inet_ntoa(lsa
->data
->id
));
630 if (IS_DEBUG_OSPF_NSSA
)
632 "ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
633 inet_ntoa(lsa
->data
->id
));
635 ext7
= (struct as_external_lsa
*)(lsa
->data
);
636 p
.prefix
= lsa
->data
->id
;
637 p
.prefixlen
= ip_masklen(ext7
->mask
);
639 if (ext7
->e
[0].fwd_addr
.s_addr
== OSPF_DEFAULT_DESTINATION
) {
640 if (IS_DEBUG_OSPF_NSSA
)
642 "ospf_abr_translate_nssa(): LSA Id %s, "
643 "Forward address is 0, NO Translation",
644 inet_ntoa(lsa
->data
->id
));
648 /* try find existing AS-External LSA for this prefix */
650 old
= ospf_external_info_find_lsa(area
->ospf
, &p
);
653 if (IS_DEBUG_OSPF_NSSA
)
655 "ospf_abr_translate_nssa(): "
656 "found old translated LSA Id %s, refreshing",
657 inet_ntoa(old
->data
->id
));
660 new = ospf_translated_nssa_refresh(area
->ospf
, lsa
, old
);
662 if (IS_DEBUG_OSPF_NSSA
)
664 "ospf_abr_translate_nssa(): "
665 "could not refresh translated LSA Id %s",
666 inet_ntoa(old
->data
->id
));
669 /* no existing external route for this LSA Id
670 * originate translated LSA
673 if (ospf_translated_nssa_originate(area
->ospf
, lsa
) == NULL
) {
674 if (IS_DEBUG_OSPF_NSSA
)
676 "ospf_abr_translate_nssa(): Could not translate "
677 "Type-7 for %s to Type-5",
678 inet_ntoa(lsa
->data
->id
));
683 /* Area where Aggregate testing will be inserted, just like summary
685 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
690 static void ospf_abr_translate_nssa_range(struct prefix_ipv4
*p
, uint32_t cost
)
692 /* The Type-7 is created from the aggregated prefix and forwarded
693 for lsa installation and flooding... to be added... */
696 void ospf_abr_announce_network_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
697 struct ospf_area
*area
)
699 struct ospf_lsa
*lsa
, *old
= NULL
;
700 struct summary_lsa
*sl
= NULL
;
703 if (IS_DEBUG_OSPF_EVENT
)
704 zlog_debug("ospf_abr_announce_network_to_area(): Start");
706 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
707 full_cost
= OSPF_STUB_MAX_METRIC_SUMMARY_COST
;
711 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_SUMMARY_LSA
, p
,
712 area
->ospf
->router_id
);
714 if (IS_DEBUG_OSPF_EVENT
)
716 "ospf_abr_announce_network_to_area(): old summary found");
718 sl
= (struct summary_lsa
*)old
->data
;
720 if (IS_DEBUG_OSPF_EVENT
)
722 "ospf_abr_announce_network_to_area(): "
723 "old metric: %d, new metric: %d",
724 GET_METRIC(sl
->metric
), cost
);
726 if ((GET_METRIC(sl
->metric
) == full_cost
)
727 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
728 /* unchanged. simply reapprove it */
729 if (IS_DEBUG_OSPF_EVENT
)
731 "ospf_abr_announce_network_to_area(): "
732 "old summary approved");
733 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
735 /* LSA is changed, refresh it */
736 if (IS_DEBUG_OSPF_EVENT
)
738 "ospf_abr_announce_network_to_area(): "
739 "refreshing summary");
740 set_metric(old
, full_cost
);
741 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
744 char buf
[PREFIX2STR_BUFFER
];
746 prefix2str((struct prefix
*)p
, buf
,
748 flog_warn(EC_OSPF_LSA_MISSING
,
749 "%s: Could not refresh %s to %s",
751 inet_ntoa(area
->area_id
));
755 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
756 /* This will flood through area. */
759 if (IS_DEBUG_OSPF_EVENT
)
761 "ospf_abr_announce_network_to_area(): "
762 "creating new summary");
763 lsa
= ospf_summary_lsa_originate(p
, full_cost
, area
);
764 /* This will flood through area. */
767 char buf
[PREFIX2STR_BUFFER
];
769 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
770 flog_warn(EC_OSPF_LSA_MISSING
,
771 "%s: Could not originate %s to %s", __func__
,
772 buf
, inet_ntoa(area
->area_id
));
776 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
777 if (IS_DEBUG_OSPF_EVENT
)
779 "ospf_abr_announce_network_to_area(): "
780 "flooding new version of summary");
783 if (IS_DEBUG_OSPF_EVENT
)
784 zlog_debug("ospf_abr_announce_network_to_area(): Stop");
787 static int ospf_abr_nexthops_belong_to_area(struct ospf_route
* or,
788 struct ospf_area
*area
)
790 struct listnode
*node
, *nnode
;
791 struct ospf_path
*path
;
792 struct ospf_interface
*oi
;
794 for (ALL_LIST_ELEMENTS_RO(or->paths
, node
, path
))
795 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, nnode
, oi
))
796 if (oi
->ifp
&& oi
->ifp
->ifindex
== path
->ifindex
)
802 static int ospf_abr_should_accept(struct prefix_ipv4
*p
, struct ospf_area
*area
)
804 if (IMPORT_NAME(area
)) {
805 if (IMPORT_LIST(area
) == NULL
)
807 access_list_lookup(AFI_IP
, IMPORT_NAME(area
));
809 if (IMPORT_LIST(area
))
810 if (access_list_apply(IMPORT_LIST(area
), p
)
818 static int ospf_abr_plist_in_check(struct ospf_area
*area
,
819 struct ospf_route
* or,
820 struct prefix_ipv4
*p
)
822 if (PREFIX_NAME_IN(area
)) {
823 if (PREFIX_LIST_IN(area
) == NULL
)
824 PREFIX_LIST_IN(area
) = prefix_list_lookup(
825 AFI_IP
, PREFIX_NAME_IN(area
));
826 if (PREFIX_LIST_IN(area
))
827 if (prefix_list_apply(PREFIX_LIST_IN(area
), p
)
834 static int ospf_abr_plist_out_check(struct ospf_area
*area
,
835 struct ospf_route
* or,
836 struct prefix_ipv4
*p
)
838 if (PREFIX_NAME_OUT(area
)) {
839 if (PREFIX_LIST_OUT(area
) == NULL
)
840 PREFIX_LIST_OUT(area
) = prefix_list_lookup(
841 AFI_IP
, PREFIX_NAME_OUT(area
));
842 if (PREFIX_LIST_OUT(area
))
843 if (prefix_list_apply(PREFIX_LIST_OUT(area
), p
)
850 static void ospf_abr_announce_network(struct ospf
*ospf
, struct prefix_ipv4
*p
,
851 struct ospf_route
* or)
853 struct ospf_area_range
*range
;
854 struct ospf_area
*area
, *or_area
;
855 struct listnode
*node
;
857 if (IS_DEBUG_OSPF_EVENT
)
858 zlog_debug("ospf_abr_announce_network(): Start");
860 or_area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
863 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
864 if (IS_DEBUG_OSPF_EVENT
)
866 "ospf_abr_announce_network(): looking at area %s",
867 inet_ntoa(area
->area_id
));
869 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
872 if (ospf_abr_nexthops_belong_to_area(or, area
))
875 if (!ospf_abr_should_accept(p
, area
)) {
876 if (IS_DEBUG_OSPF_EVENT
)
878 "ospf_abr_announce_network(): "
879 "prefix %s/%d was denied by import-list",
880 inet_ntoa(p
->prefix
), p
->prefixlen
);
884 if (!ospf_abr_plist_in_check(area
, or, p
)) {
885 if (IS_DEBUG_OSPF_EVENT
)
887 "ospf_abr_announce_network(): "
888 "prefix %s/%d was denied by prefix-list",
889 inet_ntoa(p
->prefix
), p
->prefixlen
);
893 if (area
->external_routing
!= OSPF_AREA_DEFAULT
894 && area
->no_summary
) {
895 if (IS_DEBUG_OSPF_EVENT
)
897 "ospf_abr_announce_network(): "
898 "area %s is stub and no_summary",
899 inet_ntoa(area
->area_id
));
903 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
904 if (IS_DEBUG_OSPF_EVENT
)
906 "ospf_abr_announce_network(): this is "
907 "inter-area route to %s/%d",
908 inet_ntoa(p
->prefix
), p
->prefixlen
);
910 if (!OSPF_IS_AREA_BACKBONE(area
))
911 ospf_abr_announce_network_to_area(p
, or->cost
,
915 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
916 if (IS_DEBUG_OSPF_EVENT
)
918 "ospf_abr_announce_network(): "
919 "this is intra-area route to %s/%d",
920 inet_ntoa(p
->prefix
), p
->prefixlen
);
921 if ((range
= ospf_area_range_match(or_area
, p
))
922 && !ospf_area_is_transit(area
))
923 ospf_abr_update_aggregate(range
, or, area
);
925 ospf_abr_announce_network_to_area(p
, or->cost
,
931 static int ospf_abr_should_announce(struct ospf
*ospf
, struct prefix_ipv4
*p
,
932 struct ospf_route
* or)
934 struct ospf_area
*area
;
936 area
= ospf_area_lookup_by_area_id(ospf
, or->u
.std
.area_id
);
940 if (EXPORT_NAME(area
)) {
941 if (EXPORT_LIST(area
) == NULL
)
943 access_list_lookup(AFI_IP
, EXPORT_NAME(area
));
945 if (EXPORT_LIST(area
))
946 if (access_list_apply(EXPORT_LIST(area
), p
)
954 static void ospf_abr_process_nssa_translates(struct ospf
*ospf
)
956 /* Scan through all NSSA_LSDB records for all areas;
958 If P-bit is on, translate all Type-7's to 5's and aggregate or
959 flood install as approved in Type-5 LSDB with XLATE Flag on
960 later, do same for all aggregates... At end, DISCARD all
961 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
962 struct listnode
*node
;
963 struct ospf_area
*area
;
964 struct route_node
*rn
;
965 struct ospf_lsa
*lsa
;
967 if (IS_DEBUG_OSPF_NSSA
)
968 zlog_debug("ospf_abr_process_nssa_translates(): Start");
970 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
971 if (!area
->NSSATranslatorState
)
972 continue; /* skip if not translator */
974 if (area
->external_routing
!= OSPF_AREA_NSSA
)
975 continue; /* skip if not Nssa Area */
977 if (IS_DEBUG_OSPF_NSSA
)
979 "ospf_abr_process_nssa_translates(): "
980 "looking at area %s",
981 inet_ntoa(area
->area_id
));
983 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
984 ospf_abr_translate_nssa(area
, lsa
);
987 if (IS_DEBUG_OSPF_NSSA
)
988 zlog_debug("ospf_abr_process_nssa_translates(): Stop");
991 static void ospf_abr_process_network_rt(struct ospf
*ospf
,
992 struct route_table
*rt
)
994 struct ospf_area
*area
;
995 struct ospf_route
* or ;
996 struct route_node
*rn
;
998 if (IS_DEBUG_OSPF_EVENT
)
999 zlog_debug("ospf_abr_process_network_rt(): Start");
1001 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1002 if ((or = rn
->info
) == NULL
)
1005 if (!(area
= ospf_area_lookup_by_area_id(ospf
,
1006 or->u
.std
.area_id
))) {
1007 if (IS_DEBUG_OSPF_EVENT
)
1009 "ospf_abr_process_network_rt(): area %s no longer exists",
1010 inet_ntoa(or->u
.std
.area_id
));
1014 if (IS_DEBUG_OSPF_EVENT
)
1016 "ospf_abr_process_network_rt(): this is a route to %s/%d",
1017 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
1018 if (or->path_type
>= OSPF_PATH_TYPE1_EXTERNAL
) {
1019 if (IS_DEBUG_OSPF_EVENT
)
1021 "ospf_abr_process_network_rt(): "
1022 "this is an External router, skipping");
1026 if (or->cost
>= OSPF_LS_INFINITY
) {
1027 if (IS_DEBUG_OSPF_EVENT
)
1029 "ospf_abr_process_network_rt():"
1030 " this route's cost is infinity, skipping");
1034 if (or->type
== OSPF_DESTINATION_DISCARD
) {
1035 if (IS_DEBUG_OSPF_EVENT
)
1037 "ospf_abr_process_network_rt():"
1038 " this is a discard entry, skipping");
1043 or->path_type
== OSPF_PATH_INTRA_AREA
1044 && !ospf_abr_should_announce(
1045 ospf
, (struct prefix_ipv4
*)&rn
->p
,
1047 if (IS_DEBUG_OSPF_EVENT
)
1049 "ospf_abr_process_network_rt(): denied by export-list");
1054 or->path_type
== OSPF_PATH_INTRA_AREA
1055 && !ospf_abr_plist_out_check(
1057 (struct prefix_ipv4
*)&rn
->p
)) {
1058 if (IS_DEBUG_OSPF_EVENT
)
1060 "ospf_abr_process_network_rt(): denied by prefix-list");
1064 if ((or->path_type
== OSPF_PATH_INTER_AREA
)
1065 && !OSPF_IS_AREA_ID_BACKBONE(or->u
.std
.area_id
)) {
1066 if (IS_DEBUG_OSPF_EVENT
)
1068 "ospf_abr_process_network_rt():"
1069 " this is route is not backbone one, skipping");
1074 if ((ospf
->abr_type
== OSPF_ABR_CISCO
)
1075 || (ospf
->abr_type
== OSPF_ABR_IBM
))
1077 if (!ospf_act_bb_connection(ospf
) &&
1078 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1079 if (IS_DEBUG_OSPF_EVENT
)
1081 "ospf_abr_process_network_rt(): ALT ABR: "
1082 "No BB connection, skip not intra-area routes");
1086 if (IS_DEBUG_OSPF_EVENT
)
1087 zlog_debug("ospf_abr_process_network_rt(): announcing");
1088 ospf_abr_announce_network(ospf
, (struct prefix_ipv4
*)&rn
->p
,
1092 if (IS_DEBUG_OSPF_EVENT
)
1093 zlog_debug("ospf_abr_process_network_rt(): Stop");
1096 static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4
*p
, uint32_t cost
,
1097 struct ospf_area
*area
)
1099 struct ospf_lsa
*lsa
, *old
= NULL
;
1100 struct summary_lsa
*slsa
= NULL
;
1102 if (IS_DEBUG_OSPF_EVENT
)
1103 zlog_debug("ospf_abr_announce_rtr_to_area(): Start");
1105 old
= ospf_lsa_lookup_by_prefix(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
,
1106 area
->ospf
->router_id
);
1108 if (IS_DEBUG_OSPF_EVENT
)
1110 "ospf_abr_announce_rtr_to_area(): old summary found");
1111 slsa
= (struct summary_lsa
*)old
->data
;
1113 if (IS_DEBUG_OSPF_EVENT
)
1115 "ospf_abr_announce_network_to_area(): "
1116 "old metric: %d, new metric: %d",
1117 GET_METRIC(slsa
->metric
), cost
);
1120 if (old
&& (GET_METRIC(slsa
->metric
) == cost
)
1121 && ((old
->flags
& OSPF_LSA_IN_MAXAGE
) == 0)) {
1122 if (IS_DEBUG_OSPF_EVENT
)
1124 "ospf_abr_announce_rtr_to_area(): old summary approved");
1125 SET_FLAG(old
->flags
, OSPF_LSA_APPROVED
);
1127 if (IS_DEBUG_OSPF_EVENT
)
1128 zlog_debug("ospf_abr_announce_rtr_to_area(): 2.2");
1131 set_metric(old
, cost
);
1132 lsa
= ospf_lsa_refresh(area
->ospf
, old
);
1134 lsa
= ospf_summary_asbr_lsa_originate(p
, cost
, area
);
1136 char buf
[PREFIX2STR_BUFFER
];
1138 prefix2str((struct prefix
*)p
, buf
, sizeof(buf
));
1139 flog_warn(EC_OSPF_LSA_MISSING
,
1140 "%s: Could not refresh/originate %s to %s",
1141 __func__
, buf
, inet_ntoa(area
->area_id
));
1145 if (IS_DEBUG_OSPF_EVENT
)
1147 "ospf_abr_announce_rtr_to_area(): "
1148 "flooding new version of summary");
1151 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new
1153 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1155 SET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1156 /* ospf_flood_through_area (area, NULL, lsa);*/
1159 if (IS_DEBUG_OSPF_EVENT
)
1160 zlog_debug("ospf_abr_announce_rtr_to_area(): Stop");
1164 static void ospf_abr_announce_rtr(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1165 struct ospf_route
* or)
1167 struct listnode
*node
;
1168 struct ospf_area
*area
;
1170 if (IS_DEBUG_OSPF_EVENT
)
1171 zlog_debug("ospf_abr_announce_rtr(): Start");
1173 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1174 if (IS_DEBUG_OSPF_EVENT
)
1176 "ospf_abr_announce_rtr(): looking at area %s",
1177 inet_ntoa(area
->area_id
));
1179 if (IPV4_ADDR_SAME(& or->u
.std
.area_id
, &area
->area_id
))
1182 if (ospf_abr_nexthops_belong_to_area(or, area
))
1185 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
1186 if (IS_DEBUG_OSPF_EVENT
)
1188 "ospf_abr_announce_rtr(): "
1189 "area %s doesn't support external routing",
1190 inet_ntoa(area
->area_id
));
1194 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
1195 if (IS_DEBUG_OSPF_EVENT
)
1197 "ospf_abr_announce_rtr(): "
1198 "this is inter-area route to %s",
1199 inet_ntoa(p
->prefix
));
1200 if (!OSPF_IS_AREA_BACKBONE(area
))
1201 ospf_abr_announce_rtr_to_area(p
, or->cost
,
1205 if (or->path_type
== OSPF_PATH_INTRA_AREA
) {
1206 if (IS_DEBUG_OSPF_EVENT
)
1208 "ospf_abr_announce_rtr(): "
1209 "this is intra-area route to %s",
1210 inet_ntoa(p
->prefix
));
1211 ospf_abr_announce_rtr_to_area(p
, or->cost
, area
);
1215 if (IS_DEBUG_OSPF_EVENT
)
1216 zlog_debug("ospf_abr_announce_rtr(): Stop");
1219 static void ospf_abr_process_router_rt(struct ospf
*ospf
,
1220 struct route_table
*rt
)
1222 struct ospf_route
* or ;
1223 struct route_node
*rn
;
1226 if (IS_DEBUG_OSPF_EVENT
)
1227 zlog_debug("ospf_abr_process_router_rt(): Start");
1229 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
1230 struct listnode
*node
, *nnode
;
1232 struct ospf_route
*best
= NULL
;
1234 if (rn
->info
== NULL
)
1239 if (IS_DEBUG_OSPF_EVENT
)
1241 "ospf_abr_process_router_rt(): this is a route to %s",
1242 inet_ntoa(rn
->p
.u
.prefix4
));
1244 for (ALL_LIST_ELEMENTS(l
, node
, nnode
, or)) {
1245 if (!ospf_area_lookup_by_area_id(ospf
,
1246 or->u
.std
.area_id
)) {
1247 if (IS_DEBUG_OSPF_EVENT
)
1249 "ospf_abr_process_router_rt(): area %s no longer exists",
1250 inet_ntoa(or->u
.std
.area_id
));
1255 if (!CHECK_FLAG(or->u
.std
.flags
, ROUTER_LSA_EXTERNAL
)) {
1256 if (IS_DEBUG_OSPF_EVENT
)
1258 "ospf_abr_process_router_rt(): "
1259 "This is not an ASBR, skipping");
1264 best
= ospf_find_asbr_route(
1265 ospf
, rt
, (struct prefix_ipv4
*)&rn
->p
);
1273 if (IS_DEBUG_OSPF_EVENT
)
1275 "ospf_abr_process_router_rt(): "
1276 "This route is not the best among possible, skipping");
1281 or->path_type
== OSPF_PATH_INTER_AREA
1282 && !OSPF_IS_AREA_ID_BACKBONE(
1283 or->u
.std
.area_id
)) {
1284 if (IS_DEBUG_OSPF_EVENT
)
1286 "ospf_abr_process_router_rt(): "
1287 "This route is not a backbone one, skipping");
1291 if (or->cost
>= OSPF_LS_INFINITY
) {
1292 if (IS_DEBUG_OSPF_EVENT
)
1294 "ospf_abr_process_router_rt(): "
1295 "This route has LS_INFINITY metric, skipping");
1299 if (ospf
->abr_type
== OSPF_ABR_CISCO
1300 || ospf
->abr_type
== OSPF_ABR_IBM
)
1301 if (!ospf_act_bb_connection(ospf
) &&
1302 or->path_type
!= OSPF_PATH_INTRA_AREA
) {
1303 if (IS_DEBUG_OSPF_EVENT
)
1305 "ospf_abr_process_network_rt(): ALT ABR: "
1306 "No BB connection, skip not intra-area routes");
1310 ospf_abr_announce_rtr(ospf
,
1311 (struct prefix_ipv4
*)&rn
->p
, or);
1315 if (IS_DEBUG_OSPF_EVENT
)
1316 zlog_debug("ospf_abr_process_router_rt(): Stop");
1320 ospf_abr_unapprove_translates(struct ospf
*ospf
) /* For NSSA Translations */
1322 struct ospf_lsa
*lsa
;
1323 struct route_node
*rn
;
1325 if (IS_DEBUG_OSPF_NSSA
)
1326 zlog_debug("ospf_abr_unapprove_translates(): Start");
1328 /* NSSA Translator is not checked, because it may have gone away,
1329 and we would want to flush any residuals anyway */
1331 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1332 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) {
1333 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1334 if (IS_DEBUG_OSPF_NSSA
)
1336 "ospf_abr_unapprove_translates(): "
1337 "approved unset on link id %s",
1338 inet_ntoa(lsa
->data
->id
));
1341 if (IS_DEBUG_OSPF_NSSA
)
1342 zlog_debug("ospf_abr_unapprove_translates(): Stop");
1345 static void ospf_abr_unapprove_summaries(struct ospf
*ospf
)
1347 struct listnode
*node
;
1348 struct ospf_area
*area
;
1349 struct route_node
*rn
;
1350 struct ospf_lsa
*lsa
;
1352 if (IS_DEBUG_OSPF_EVENT
)
1353 zlog_debug("ospf_abr_unapprove_summaries(): Start");
1355 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1356 if (IS_DEBUG_OSPF_EVENT
)
1358 "ospf_abr_unapprove_summaries(): "
1359 "considering area %s",
1360 inet_ntoa(area
->area_id
));
1361 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1362 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1363 if (IS_DEBUG_OSPF_EVENT
)
1365 "ospf_abr_unapprove_summaries(): "
1366 "approved unset on summary link id %s",
1367 inet_ntoa(lsa
->data
->id
));
1368 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1371 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1372 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
1373 if (IS_DEBUG_OSPF_EVENT
)
1375 "ospf_abr_unapprove_summaries(): "
1376 "approved unset on asbr-summary link id %s",
1377 inet_ntoa(lsa
->data
->id
));
1378 UNSET_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
);
1382 if (IS_DEBUG_OSPF_EVENT
)
1383 zlog_debug("ospf_abr_unapprove_summaries(): Stop");
1386 static void ospf_abr_prepare_aggregates(struct ospf
*ospf
)
1388 struct listnode
*node
;
1389 struct route_node
*rn
;
1390 struct ospf_area_range
*range
;
1391 struct ospf_area
*area
;
1393 if (IS_DEBUG_OSPF_EVENT
)
1394 zlog_debug("ospf_abr_prepare_aggregates(): Start");
1396 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1397 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1398 if ((range
= rn
->info
) != NULL
) {
1400 range
->specifics
= 0;
1404 if (IS_DEBUG_OSPF_EVENT
)
1405 zlog_debug("ospf_abr_prepare_aggregates(): Stop");
1408 static void ospf_abr_announce_aggregates(struct ospf
*ospf
)
1410 struct ospf_area
*area
, *ar
;
1411 struct ospf_area_range
*range
;
1412 struct route_node
*rn
;
1414 struct listnode
*node
, *n
;
1416 if (IS_DEBUG_OSPF_EVENT
)
1417 zlog_debug("ospf_abr_announce_aggregates(): Start");
1419 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1420 if (IS_DEBUG_OSPF_EVENT
)
1422 "ospf_abr_announce_aggregates(): looking at area %s",
1423 inet_ntoa(area
->area_id
));
1425 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1426 if ((range
= rn
->info
)) {
1427 if (!CHECK_FLAG(range
->flags
,
1428 OSPF_AREA_RANGE_ADVERTISE
)) {
1429 if (IS_DEBUG_OSPF_EVENT
)
1431 "ospf_abr_announce_aggregates():"
1432 " discarding suppress-ranges");
1437 p
.u
.prefix4
= range
->addr
;
1438 p
.prefixlen
= range
->masklen
;
1440 if (IS_DEBUG_OSPF_EVENT
)
1442 "ospf_abr_announce_aggregates():"
1443 " this is range: %s/%d",
1444 inet_ntoa(p
.u
.prefix4
),
1447 if (CHECK_FLAG(range
->flags
,
1448 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1450 p
.u
.prefix4
= range
->subst_addr
;
1451 p
.prefixlen
= range
->subst_masklen
;
1454 if (range
->specifics
) {
1455 if (IS_DEBUG_OSPF_EVENT
)
1457 "ospf_abr_announce_aggregates(): active range");
1459 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
,
1464 /* We do not check nexthops
1466 intra-area routes can be
1470 /* backbone routes are not
1472 when announced into transit
1475 if (ospf_area_is_transit(ar
)
1476 && OSPF_IS_AREA_BACKBONE(
1478 if (IS_DEBUG_OSPF_EVENT
)
1480 "ospf_abr_announce_aggregates(): Skipping "
1481 "announcement of BB aggregate into"
1485 ospf_abr_announce_network_to_area(
1494 if (IS_DEBUG_OSPF_EVENT
)
1495 zlog_debug("ospf_abr_announce_aggregates(): Stop");
1499 ospf_abr_send_nssa_aggregates(struct ospf
*ospf
) /* temporarily turned off */
1501 struct listnode
*node
; /*, n; */
1502 struct ospf_area
*area
; /*, *ar; */
1503 struct route_node
*rn
;
1504 struct ospf_area_range
*range
;
1505 struct prefix_ipv4 p
;
1507 if (IS_DEBUG_OSPF_NSSA
)
1508 zlog_debug("ospf_abr_send_nssa_aggregates(): Start");
1510 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1511 if (!area
->NSSATranslatorState
)
1514 if (IS_DEBUG_OSPF_NSSA
)
1516 "ospf_abr_send_nssa_aggregates(): looking at area %s",
1517 inet_ntoa(area
->area_id
));
1519 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
)) {
1520 if (rn
->info
== NULL
)
1525 if (!CHECK_FLAG(range
->flags
,
1526 OSPF_AREA_RANGE_ADVERTISE
)) {
1527 if (IS_DEBUG_OSPF_NSSA
)
1529 "ospf_abr_send_nssa_aggregates():"
1530 " discarding suppress-ranges");
1535 p
.prefix
= range
->addr
;
1536 p
.prefixlen
= range
->masklen
;
1538 if (IS_DEBUG_OSPF_NSSA
)
1540 "ospf_abr_send_nssa_aggregates():"
1541 " this is range: %s/%d",
1542 inet_ntoa(p
.prefix
), p
.prefixlen
);
1544 if (CHECK_FLAG(range
->flags
,
1545 OSPF_AREA_RANGE_SUBSTITUTE
)) {
1547 p
.prefix
= range
->subst_addr
;
1548 p
.prefixlen
= range
->subst_masklen
;
1551 if (range
->specifics
) {
1552 if (IS_DEBUG_OSPF_NSSA
)
1554 "ospf_abr_send_nssa_aggregates(): active range");
1556 /* Fetch LSA-Type-7 from aggregate prefix, and
1558 * translate, Install (as Type-5), Approve, and
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");
1570 static void ospf_abr_announce_stub_defaults(struct ospf
*ospf
)
1572 struct listnode
*node
;
1573 struct ospf_area
*area
;
1574 struct prefix_ipv4 p
;
1576 if (!IS_OSPF_ABR(ospf
))
1579 if (IS_DEBUG_OSPF_EVENT
)
1580 zlog_debug("ospf_abr_announce_stub_defaults(): Start");
1583 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1586 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1587 if (IS_DEBUG_OSPF_EVENT
)
1589 "ospf_abr_announce_stub_defaults(): looking at area %s",
1590 inet_ntoa(area
->area_id
));
1592 if ((area
->external_routing
!= OSPF_AREA_STUB
)
1593 && (area
->external_routing
!= OSPF_AREA_NSSA
))
1596 if (OSPF_IS_AREA_BACKBONE(area
))
1597 continue; /* Sanity Check */
1599 if (IS_DEBUG_OSPF_EVENT
)
1601 "ospf_abr_announce_stub_defaults(): "
1602 "announcing 0.0.0.0/0 to area %s",
1603 inet_ntoa(area
->area_id
));
1604 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1607 if (IS_DEBUG_OSPF_EVENT
)
1608 zlog_debug("ospf_abr_announce_stub_defaults(): Stop");
1611 static int ospf_abr_remove_unapproved_translates_apply(struct ospf
*ospf
,
1612 struct ospf_lsa
*lsa
)
1614 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)
1615 && !CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
)) {
1617 "ospf_abr_remove_unapproved_translates(): "
1618 "removing unapproved translates, ID: %s",
1619 inet_ntoa(lsa
->data
->id
));
1621 /* FLUSH THROUGHOUT AS */
1622 ospf_lsa_flush_as(ospf
, lsa
);
1624 /* DISCARD from LSDB */
1629 static void ospf_abr_remove_unapproved_translates(struct ospf
*ospf
)
1631 struct route_node
*rn
;
1632 struct ospf_lsa
*lsa
;
1634 /* All AREA PROCESS should have APPROVED necessary LSAs */
1635 /* Remove any left over and not APPROVED */
1636 if (IS_DEBUG_OSPF_NSSA
)
1637 zlog_debug("ospf_abr_remove_unapproved_translates(): Start");
1639 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1640 ospf_abr_remove_unapproved_translates_apply(ospf
, lsa
);
1642 if (IS_DEBUG_OSPF_NSSA
)
1643 zlog_debug("ospf_abr_remove_unapproved_translates(): Stop");
1646 static void ospf_abr_remove_unapproved_summaries(struct ospf
*ospf
)
1648 struct listnode
*node
;
1649 struct ospf_area
*area
;
1650 struct route_node
*rn
;
1651 struct ospf_lsa
*lsa
;
1653 if (IS_DEBUG_OSPF_EVENT
)
1654 zlog_debug("ospf_abr_remove_unapproved_summaries(): Start");
1656 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1657 if (IS_DEBUG_OSPF_EVENT
)
1659 "ospf_abr_remove_unapproved_summaries(): "
1660 "looking at area %s",
1661 inet_ntoa(area
->area_id
));
1663 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1664 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1665 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1666 ospf_lsa_flush_area(lsa
, area
);
1668 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1669 if (ospf_lsa_is_self_originated(ospf
, lsa
))
1670 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_APPROVED
))
1671 ospf_lsa_flush_area(lsa
, area
);
1674 if (IS_DEBUG_OSPF_EVENT
)
1675 zlog_debug("ospf_abr_remove_unapproved_summaries(): Stop");
1678 static void ospf_abr_manage_discard_routes(struct ospf
*ospf
)
1680 struct listnode
*node
, *nnode
;
1681 struct route_node
*rn
;
1682 struct ospf_area
*area
;
1683 struct ospf_area_range
*range
;
1685 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
1686 for (rn
= route_top(area
->ranges
); rn
; rn
= route_next(rn
))
1687 if ((range
= rn
->info
) != NULL
)
1688 if (CHECK_FLAG(range
->flags
,
1689 OSPF_AREA_RANGE_ADVERTISE
)) {
1690 if (range
->specifics
)
1691 ospf_add_discard_route(
1692 ospf
, ospf
->new_table
,
1697 ospf_delete_discard_route(
1698 ospf
, ospf
->new_table
,
1704 /* This is the function taking care about ABR NSSA, i.e. NSSA
1705 Translator, -LSA aggregation and flooding. For all NSSAs
1707 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1708 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1711 Any received Type-5s are legal for an ABR, else illegal for IR.
1712 Received Type-7s are installed, by area, with incoming P-bit. They
1713 are flooded; if the Elected NSSA Translator, then P-bit off.
1715 Additionally, this ABR will place "translated type-7's" into the
1716 Type-5 LSDB in order to keep track of APPROVAL or not.
1718 It will scan through every area, looking for Type-7 LSAs with P-Bit
1719 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1720 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1723 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1724 left over are FLUSHED and DISCARDED.
1726 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1727 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1729 static void ospf_abr_nssa_task(struct ospf
*ospf
) /* called only if any_nssa */
1731 if (IS_DEBUG_OSPF_NSSA
)
1732 zlog_debug("Check for NSSA-ABR Tasks():");
1734 if (!IS_OSPF_ABR(ospf
))
1740 /* Each area must confirm TranslatorRole */
1741 if (IS_DEBUG_OSPF_NSSA
)
1742 zlog_debug("ospf_abr_nssa_task(): Start");
1744 /* For all Global Entries flagged "local-translate", unset APPROVED */
1745 if (IS_DEBUG_OSPF_NSSA
)
1746 zlog_debug("ospf_abr_nssa_task(): unapprove translates");
1748 ospf_abr_unapprove_translates(ospf
);
1750 /* RESET all Ranges in every Area, same as summaries */
1751 if (IS_DEBUG_OSPF_NSSA
)
1752 zlog_debug("ospf_abr_nssa_task(): NSSA initialize aggregates");
1753 ospf_abr_prepare_aggregates(ospf
); /*TURNED OFF just for now */
1755 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1756 * Aggregate as Type-7
1757 * Install or Approve in Type-5 Global LSDB
1759 if (IS_DEBUG_OSPF_NSSA
)
1760 zlog_debug("ospf_abr_nssa_task(): process translates");
1761 ospf_abr_process_nssa_translates(ospf
);
1763 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1765 * Scan Type-7's for aggregates, translate to Type-5's,
1766 * Install/Flood/Approve
1768 if (IS_DEBUG_OSPF_NSSA
)
1769 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1770 ospf_abr_send_nssa_aggregates(ospf
); /*TURNED OFF FOR NOW */
1772 /* Send any NSSA defaults as Type-5
1773 *if (IS_DEBUG_OSPF_NSSA)
1774 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1775 *ospf_abr_announce_nssa_defaults (ospf);
1776 * havnt a clue what above is supposed to do.
1779 /* Flush any unapproved previous translates from Global Data Base */
1780 if (IS_DEBUG_OSPF_NSSA
)
1782 "ospf_abr_nssa_task(): remove unapproved translates");
1783 ospf_abr_remove_unapproved_translates(ospf
);
1785 ospf_abr_manage_discard_routes(ospf
); /* same as normal...discard */
1787 if (IS_DEBUG_OSPF_NSSA
)
1788 zlog_debug("ospf_abr_nssa_task(): Stop");
1791 /* This is the function taking care about ABR stuff, i.e.
1792 summary-LSA origination and flooding. */
1793 void ospf_abr_task(struct ospf
*ospf
)
1795 if (IS_DEBUG_OSPF_EVENT
)
1796 zlog_debug("ospf_abr_task(): Start");
1798 if (ospf
->new_table
== NULL
|| ospf
->new_rtrs
== NULL
) {
1799 if (IS_DEBUG_OSPF_EVENT
)
1801 "ospf_abr_task(): Routing tables are not yet ready");
1805 if (IS_DEBUG_OSPF_EVENT
)
1806 zlog_debug("ospf_abr_task(): unapprove summaries");
1807 ospf_abr_unapprove_summaries(ospf
);
1809 if (IS_DEBUG_OSPF_EVENT
)
1810 zlog_debug("ospf_abr_task(): prepare aggregates");
1811 ospf_abr_prepare_aggregates(ospf
);
1813 if (IS_OSPF_ABR(ospf
)) {
1814 if (IS_DEBUG_OSPF_EVENT
)
1815 zlog_debug("ospf_abr_task(): process network RT");
1816 ospf_abr_process_network_rt(ospf
, ospf
->new_table
);
1818 if (IS_DEBUG_OSPF_EVENT
)
1819 zlog_debug("ospf_abr_task(): process router RT");
1820 ospf_abr_process_router_rt(ospf
, ospf
->new_rtrs
);
1822 if (IS_DEBUG_OSPF_EVENT
)
1823 zlog_debug("ospf_abr_task(): announce aggregates");
1824 ospf_abr_announce_aggregates(ospf
);
1826 if (IS_DEBUG_OSPF_EVENT
)
1827 zlog_debug("ospf_abr_task(): announce stub defaults");
1828 ospf_abr_announce_stub_defaults(ospf
);
1831 if (IS_DEBUG_OSPF_EVENT
)
1832 zlog_debug("ospf_abr_task(): remove unapproved summaries");
1833 ospf_abr_remove_unapproved_summaries(ospf
);
1835 ospf_abr_manage_discard_routes(ospf
);
1837 if (IS_DEBUG_OSPF_EVENT
)
1838 zlog_debug("ospf_abr_task(): Stop");
1841 static int ospf_abr_task_timer(struct thread
*thread
)
1843 struct ospf
*ospf
= THREAD_ARG(thread
);
1845 ospf
->t_abr_task
= 0;
1847 if (IS_DEBUG_OSPF_EVENT
)
1848 zlog_debug("Running ABR task on timer");
1850 ospf_check_abr_status(ospf
);
1851 ospf_abr_nssa_check_status(ospf
);
1853 ospf_abr_task(ospf
);
1854 ospf_abr_nssa_task(ospf
); /* if nssa-abr, then scan Type-7 LSDB */
1859 void ospf_schedule_abr_task(struct ospf
*ospf
)
1861 if (IS_DEBUG_OSPF_EVENT
)
1862 zlog_debug("Scheduling ABR task");
1864 thread_add_timer(master
, ospf_abr_task_timer
, ospf
, OSPF_ABR_TASK_DELAY
,