+ initial edition of meta-queue for RIB updates processing (bug #431)
[jleu-quagga.git] / ospfd / ospf_abr.c
blob88636f1a41d1d5dc4cefec4f428edc379e6cf7e4
1 /*
2 * OSPF ABR functions.
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
10 * later version.
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
20 * 02111-1307, USA.
24 #include <zebra.h>
26 #include "thread.h"
27 #include "memory.h"
28 #include "linklist.h"
29 #include "prefix.h"
30 #include "if.h"
31 #include "table.h"
32 #include "vty.h"
33 #include "filter.h"
34 #include "plist.h"
35 #include "log.h"
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;
64 return range;
67 static void
68 ospf_area_range_free (struct ospf_area_range *range)
70 XFREE (MTYPE_OSPF_AREA_RANGE, range);
73 static void
74 ospf_area_range_add (struct ospf_area *area, struct ospf_area_range *range)
76 struct route_node *rn;
77 struct prefix_ipv4 p;
79 p.family = AF_INET;
80 p.prefixlen = range->masklen;
81 p.prefix = range->addr;
83 rn = route_node_get (area->ranges, (struct prefix *)&p);
84 if (rn->info)
85 route_unlock_node (rn);
86 else
87 rn->info = range;
90 static void
91 ospf_area_range_delete (struct ospf_area *area, struct ospf_area_range *range)
93 struct route_node *rn;
94 struct prefix_ipv4 p;
96 p.family = AF_INET;
97 p.prefixlen = range->masklen;
98 p.prefix = range->addr;
100 rn = route_node_lookup (area->ranges, (struct prefix *)&p);
101 if (rn)
103 ospf_area_range_free (rn->info);
104 rn->info = NULL;
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);
116 if (rn)
118 route_unlock_node (rn);
119 return rn->info;
121 return NULL;
124 struct ospf_area_range *
125 ospf_area_range_lookup_next (struct ospf_area *area,
126 struct in_addr *range_net,
127 int first)
129 struct route_node *rn;
130 struct prefix_ipv4 p;
131 struct ospf_area_range *find;
133 p.family = AF_INET;
134 p.prefixlen = IPV4_MAX_BITLEN;
135 p.prefix = *range_net;
137 if (first)
138 rn = route_top (area->ranges);
139 else
141 rn = route_node_get (area->ranges, (struct prefix *) &p);
142 rn = route_next (rn);
145 for (; rn; rn = route_next (rn))
146 if (rn->info)
147 break;
149 if (rn && rn->info)
151 find = rn->info;
152 *range_net = rn->p.u.prefix4;
153 route_unlock_node (rn);
154 return find;
156 return NULL;
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);
165 if (node)
167 route_unlock_node (node);
168 return node->info;
170 return NULL;
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)))
182 return range;
184 return NULL;
188 ospf_area_range_active (struct ospf_area_range *range)
190 return range->specifics;
193 static int
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);
208 if (area == NULL)
209 return 0;
211 range = ospf_area_range_lookup (area, p);
212 if (range != NULL)
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);
220 else
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);
229 else
230 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
232 return 1;
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);
244 if (area == NULL)
245 return 0;
247 range = ospf_area_range_lookup (area, p);
248 if (range == NULL)
249 return 0;
251 if (range->cost_config != cost)
253 range->cost_config = cost;
254 if (ospf_area_range_active (range))
255 ospf_schedule_abr_task (ospf);
258 return 1;
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);
269 if (area == NULL)
270 return 0;
272 range = ospf_area_range_lookup (area, p);
273 if (range == NULL)
274 return 0;
276 if (ospf_area_range_active (range))
277 ospf_schedule_abr_task (ospf);
279 ospf_area_range_delete (area, range);
281 return 1;
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);
295 if (range != NULL)
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);
301 else
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;
313 return 1;
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);
324 if (area == NULL)
325 return 0;
327 range = ospf_area_range_lookup (area, p);
328 if (range == NULL)
329 return 0;
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;
339 return 1;
343 ospf_act_bb_connection (struct ospf *ospf)
345 if (ospf->backbone == NULL)
346 return 0;
348 return ospf->backbone->full_nbrs;
351 /* Determine whether this router is elected translator or not for area */
352 static int
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)
362 /* sanity checks */
363 if (!lsa
364 || (lsa->data->type != OSPF_ROUTER_LSA)
365 || IS_LSA_SELF (lsa))
366 continue;
368 rlsa = (struct router_lsa *) lsa->data;
370 /* ignore non-ABR routers */
371 if (!IS_ROUTER_LSA_BORDER (rlsa))
372 continue;
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) );
381 return 0;
384 if (best == NULL)
385 best = &lsa->data->id;
386 else
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>" );
395 if (best == NULL)
396 return 1;
398 if ( IPV4_ADDR_CMP (&best, &area->ospf->router_id) < 0)
399 return 1;
400 else
401 return 0;
404 /* Check NSSA ABR status
405 * assumes there are nssa areas
407 static void
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)
418 continue;
420 if (IS_DEBUG_OSPF (nssa, NSSA))
421 zlog_debug ("ospf_abr_nssa_check_status: "
422 "checking area %s",
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: "
429 "not ABR");
430 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
432 else
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: "
441 "never translate");
442 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
443 break;
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: "
452 "translate always");
453 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
454 break;
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");
465 else
467 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
468 if (IS_DEBUG_OSPF (nssa, NSSA))
469 zlog_debug ("ospf_abr_nssa_check_status: " "not elected");
471 break;
474 /* RFC3101, 3.1:
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
477 * translating.
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. */
490 void
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))
508 areas_configured++;
510 if (OSPF_IS_AREA_BACKBONE (area))
511 bb_configured = 1;
514 if (ospf_area_actively_attached (area))
516 areas_act_attached++;
518 if (OSPF_IS_AREA_BACKBONE (area))
519 bb_act_attached = 1;
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",
528 bb_act_attached);
529 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
530 areas_configured);
531 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
532 areas_act_attached);
535 switch (ospf->abr_type)
537 case OSPF_ABR_SHORTCUT:
538 case OSPF_ABR_STAND:
539 if (areas_act_attached > 1)
540 SET_FLAG (new_flags, OSPF_FLAG_ABR);
541 else
542 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
543 break;
545 case OSPF_ABR_IBM:
546 if ((areas_act_attached > 1) && bb_configured)
547 SET_FLAG (new_flags, OSPF_FLAG_ABR);
548 else
549 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
550 break;
552 case OSPF_ABR_CISCO:
553 if ((areas_configured > 1) && bb_act_attached)
554 SET_FLAG (new_flags, OSPF_FLAG_ABR);
555 else
556 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
557 break;
558 default:
559 break;
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);
573 static void
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",
584 range->cost_config);
586 range->cost = range->cost_config;
588 else
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;
602 range->specifics++;
605 static void
606 set_metric (struct ospf_lsa *lsa, u_int32_t metric)
608 struct summary_lsa *header;
609 u_char *mp;
610 metric = htonl (metric);
611 mp = (u_char *) &metric;
612 mp++;
613 header = (struct summary_lsa *) lsa->data;
614 memcpy(header->metric, mp, 3);
617 static int
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 */
623 return 0;
626 /* ospf_abr_translate_nssa */
627 static int
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,
642 *new = 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));
651 return 1;
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));
668 return 1;
671 /* try find existing AS-External LSA for this prefix */
673 old = ospf_external_info_find_lsa (area->ospf, &p);
675 if (old)
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));
682 /* refresh */
683 new = ospf_translated_nssa_refresh (area->ospf, lsa, old);
684 if (!new)
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));
692 else
694 /* no existing external route for this LSA Id
695 * originate translated LSA
698 if ((new = ospf_translated_nssa_originate (area->ospf, lsa))
699 == NULL)
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));
705 return 1;
709 /* Area where Aggregate testing will be inserted, just like summary
710 advertisements */
711 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
713 return 0;
716 static void
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... */
723 void
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);
736 if (old)
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);
756 else
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);
765 if (!lsa)
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",
771 __func__,
772 buf,
773 inet_ntoa (area->area_id));
774 return;
777 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
778 /* This will flood through area. */
781 else
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. */
789 if (!lsa)
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",
795 __func__,
796 buf,
797 inet_ntoa (area->area_id));
798 return;
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");
811 static int
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;
818 for (ALL_LIST_ELEMENTS (or->paths, node, nnode, path))
820 struct ospf_interface *oi = path->oi;
822 if (oi != NULL)
823 if (oi->area == area)
824 return 1;
827 return 0;
830 static int
831 ospf_abr_should_accept (struct prefix_ipv4 *p, struct ospf_area *area)
833 if (IMPORT_NAME (area))
835 if (IMPORT_LIST (area) == NULL)
836 IMPORT_LIST (area) = access_list_lookup (AFI_IP, IMPORT_NAME (area));
838 if (IMPORT_LIST (area))
839 if (access_list_apply (IMPORT_LIST (area), p) == FILTER_DENY)
840 return 0;
843 return 1;
846 static int
847 ospf_abr_plist_in_check (struct ospf_area *area, struct ospf_route *or,
848 struct prefix_ipv4 *p)
850 if (PREFIX_NAME_IN (area))
852 if (PREFIX_LIST_IN (area) == NULL)
853 PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP,
854 PREFIX_NAME_IN (area));
855 if (PREFIX_LIST_IN (area))
856 if (prefix_list_apply (PREFIX_LIST_IN (area), p) != PREFIX_PERMIT)
857 return 0;
859 return 1;
862 static int
863 ospf_abr_plist_out_check (struct ospf_area *area, struct ospf_route *or,
864 struct prefix_ipv4 *p)
866 if (PREFIX_NAME_OUT (area))
868 if (PREFIX_LIST_OUT (area) == NULL)
869 PREFIX_LIST_OUT (area) = prefix_list_lookup (AFI_IP,
870 PREFIX_NAME_OUT (area));
871 if (PREFIX_LIST_OUT (area))
872 if (prefix_list_apply (PREFIX_LIST_OUT (area), p) != PREFIX_PERMIT)
873 return 0;
875 return 1;
878 static void
879 ospf_abr_announce_network (struct ospf *ospf,
880 struct prefix_ipv4 *p, struct ospf_route *or)
882 struct ospf_area_range *range;
883 struct ospf_area *area, *or_area;
884 struct listnode *node;
886 if (IS_DEBUG_OSPF_EVENT)
887 zlog_debug ("ospf_abr_announce_network(): Start");
889 or_area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
890 assert (or_area);
892 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
894 if (IS_DEBUG_OSPF_EVENT)
895 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
896 inet_ntoa (area->area_id));
898 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
899 continue;
901 if (ospf_abr_nexthops_belong_to_area (or, area))
902 continue;
904 if (!ospf_abr_should_accept (p, area))
906 if (IS_DEBUG_OSPF_EVENT)
907 zlog_debug ("ospf_abr_announce_network(): "
908 "prefix %s/%d was denied by import-list",
909 inet_ntoa (p->prefix), p->prefixlen);
910 continue;
913 if (!ospf_abr_plist_in_check (area, or, p))
915 if (IS_DEBUG_OSPF_EVENT)
916 zlog_debug ("ospf_abr_announce_network(): "
917 "prefix %s/%d was denied by prefix-list",
918 inet_ntoa (p->prefix), p->prefixlen);
919 continue;
922 if (area->external_routing != OSPF_AREA_DEFAULT && area->no_summary)
924 if (IS_DEBUG_OSPF_EVENT)
925 zlog_debug ("ospf_abr_announce_network(): "
926 "area %s is stub and no_summary",
927 inet_ntoa (area->area_id));
928 continue;
931 if (or->path_type == OSPF_PATH_INTER_AREA)
933 if (IS_DEBUG_OSPF_EVENT)
934 zlog_debug ("ospf_abr_announce_network(): this is "
935 "inter-area route to %s/%d",
936 inet_ntoa (p->prefix), p->prefixlen);
938 if (!OSPF_IS_AREA_BACKBONE (area))
939 ospf_abr_announce_network_to_area (p, or->cost, area);
942 if (or->path_type == OSPF_PATH_INTRA_AREA)
944 if (IS_DEBUG_OSPF_EVENT)
945 zlog_debug ("ospf_abr_announce_network(): "
946 "this is intra-area route to %s/%d",
947 inet_ntoa (p->prefix), p->prefixlen);
948 if ((range = ospf_area_range_match (or_area, p))
949 && !ospf_area_is_transit (area))
950 ospf_abr_update_aggregate (range, or);
951 else
952 ospf_abr_announce_network_to_area (p, or->cost, area);
957 static int
958 ospf_abr_should_announce (struct ospf *ospf,
959 struct prefix_ipv4 *p, struct ospf_route *or)
961 struct ospf_area *area;
963 area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
965 assert (area);
967 if (EXPORT_NAME (area))
969 if (EXPORT_LIST (area) == NULL)
970 EXPORT_LIST (area) = access_list_lookup (AFI_IP, EXPORT_NAME (area));
972 if (EXPORT_LIST (area))
973 if (access_list_apply (EXPORT_LIST (area), p) == FILTER_DENY)
974 return 0;
977 return 1;
980 static void
981 ospf_abr_process_nssa_translates (struct ospf *ospf)
983 /* Scan through all NSSA_LSDB records for all areas;
985 If P-bit is on, translate all Type-7's to 5's and aggregate or
986 flood install as approved in Type-5 LSDB with XLATE Flag on
987 later, do same for all aggregates... At end, DISCARD all
988 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
989 struct listnode *node;
990 struct ospf_area *area;
991 struct route_node *rn;
992 struct ospf_lsa *lsa;
994 if (IS_DEBUG_OSPF_NSSA)
995 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
997 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
999 if (! area->NSSATranslatorState)
1000 continue; /* skip if not translator */
1002 if (area->external_routing != OSPF_AREA_NSSA)
1003 continue; /* skip if not Nssa Area */
1005 if (IS_DEBUG_OSPF_NSSA)
1006 zlog_debug ("ospf_abr_process_nssa_translates(): "
1007 "looking at area %s", inet_ntoa (area->area_id));
1009 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
1010 ospf_abr_translate_nssa (area, lsa);
1013 if (IS_DEBUG_OSPF_NSSA)
1014 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
1018 static void
1019 ospf_abr_process_network_rt (struct ospf *ospf,
1020 struct route_table *rt)
1022 struct ospf_area *area;
1023 struct ospf_route *or;
1024 struct route_node *rn;
1026 if (IS_DEBUG_OSPF_EVENT)
1027 zlog_debug ("ospf_abr_process_network_rt(): Start");
1029 for (rn = route_top (rt); rn; rn = route_next (rn))
1031 if ((or = rn->info) == NULL)
1032 continue;
1034 if (!(area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id)))
1036 if (IS_DEBUG_OSPF_EVENT)
1037 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
1038 inet_ntoa (or->u.std.area_id));
1039 continue;
1042 if (IS_DEBUG_OSPF_EVENT)
1043 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
1044 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
1045 if (or->path_type >= OSPF_PATH_TYPE1_EXTERNAL)
1047 if (IS_DEBUG_OSPF_EVENT)
1048 zlog_debug ("ospf_abr_process_network_rt(): "
1049 "this is an External router, skipping");
1050 continue;
1053 if (or->cost >= OSPF_LS_INFINITY)
1055 if (IS_DEBUG_OSPF_EVENT)
1056 zlog_debug ("ospf_abr_process_network_rt():"
1057 " this route's cost is infinity, skipping");
1058 continue;
1061 if (or->type == OSPF_DESTINATION_DISCARD)
1063 if (IS_DEBUG_OSPF_EVENT)
1064 zlog_debug ("ospf_abr_process_network_rt():"
1065 " this is a discard entry, skipping");
1066 continue;
1069 if (or->path_type == OSPF_PATH_INTRA_AREA &&
1070 !ospf_abr_should_announce (ospf, (struct prefix_ipv4 *) &rn->p, or))
1072 if (IS_DEBUG_OSPF_EVENT)
1073 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
1074 continue;
1077 if (or->path_type == OSPF_PATH_INTRA_AREA &&
1078 !ospf_abr_plist_out_check (area, or, (struct prefix_ipv4 *) &rn->p))
1080 if (IS_DEBUG_OSPF_EVENT)
1081 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
1082 continue;
1085 if ((or->path_type == OSPF_PATH_INTER_AREA) &&
1086 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1088 if (IS_DEBUG_OSPF_EVENT)
1089 zlog_debug ("ospf_abr_process_network_rt():"
1090 " this is route is not backbone one, skipping");
1091 continue;
1095 if ((ospf->abr_type == OSPF_ABR_CISCO) ||
1096 (ospf->abr_type == OSPF_ABR_IBM))
1098 if (!ospf_act_bb_connection (ospf) &&
1099 or->path_type != OSPF_PATH_INTRA_AREA)
1101 if (IS_DEBUG_OSPF_EVENT)
1102 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
1103 "No BB connection, skip not intra-area routes");
1104 continue;
1107 if (IS_DEBUG_OSPF_EVENT)
1108 zlog_debug ("ospf_abr_process_network_rt(): announcing");
1109 ospf_abr_announce_network (ospf, (struct prefix_ipv4 *)&rn->p, or);
1112 if (IS_DEBUG_OSPF_EVENT)
1113 zlog_debug ("ospf_abr_process_network_rt(): Stop");
1116 static void
1117 ospf_abr_announce_rtr_to_area (struct prefix_ipv4 *p, u_int32_t cost,
1118 struct ospf_area *area)
1120 struct ospf_lsa *lsa, *old = NULL;
1121 struct summary_lsa *slsa = NULL;
1123 if (IS_DEBUG_OSPF_EVENT)
1124 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
1126 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_ASBR_SUMMARY_LSA,
1127 p, area->ospf->router_id);
1128 if (old)
1130 if (IS_DEBUG_OSPF_EVENT)
1131 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
1132 slsa = (struct summary_lsa *) old->data;
1134 if (IS_DEBUG_OSPF_EVENT)
1135 zlog_debug ("ospf_abr_announce_network_to_area(): "
1136 "old metric: %d, new metric: %d",
1137 GET_METRIC (slsa->metric), cost);
1140 if (old && (GET_METRIC (slsa->metric) == cost))
1142 if (IS_DEBUG_OSPF_EVENT)
1143 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
1144 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
1146 else
1148 if (IS_DEBUG_OSPF_EVENT)
1149 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
1151 if (old)
1153 set_metric (old, cost);
1154 lsa = ospf_summary_asbr_lsa_refresh (area->ospf, old);
1156 else
1157 lsa = ospf_summary_asbr_lsa_originate (p, cost, area);
1158 if (!lsa)
1160 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
1162 prefix2str ((struct prefix *)p, buf, sizeof(buf));
1163 zlog_warn ("%s: Could not refresh/originate %s to %s",
1164 __func__,
1165 buf,
1166 inet_ntoa (area->area_id));
1167 return;
1170 if (IS_DEBUG_OSPF_EVENT)
1171 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
1172 "flooding new version of summary");
1175 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1176 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1178 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1179 /* ospf_flood_through_area (area, NULL, lsa);*/
1182 if (IS_DEBUG_OSPF_EVENT)
1183 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
1187 static void
1188 ospf_abr_announce_rtr (struct ospf *ospf,
1189 struct prefix_ipv4 *p, struct ospf_route *or)
1191 struct listnode *node;
1192 struct ospf_area *area;
1194 if (IS_DEBUG_OSPF_EVENT)
1195 zlog_debug ("ospf_abr_announce_rtr(): Start");
1197 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1199 if (IS_DEBUG_OSPF_EVENT)
1200 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
1201 inet_ntoa (area->area_id));
1203 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
1204 continue;
1206 if (ospf_abr_nexthops_belong_to_area (or, area))
1207 continue;
1209 if (area->external_routing != OSPF_AREA_DEFAULT)
1211 if (IS_DEBUG_OSPF_EVENT)
1212 zlog_debug ("ospf_abr_announce_rtr(): "
1213 "area %s doesn't support external routing",
1214 inet_ntoa(area->area_id));
1215 continue;
1218 if (or->path_type == OSPF_PATH_INTER_AREA)
1220 if (IS_DEBUG_OSPF_EVENT)
1221 zlog_debug ("ospf_abr_announce_rtr(): "
1222 "this is inter-area route to %s", inet_ntoa (p->prefix));
1223 if (!OSPF_IS_AREA_BACKBONE (area))
1224 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1227 if (or->path_type == OSPF_PATH_INTRA_AREA)
1229 if (IS_DEBUG_OSPF_EVENT)
1230 zlog_debug ("ospf_abr_announce_rtr(): "
1231 "this is intra-area route to %s", inet_ntoa (p->prefix));
1232 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1236 if (IS_DEBUG_OSPF_EVENT)
1237 zlog_debug ("ospf_abr_announce_rtr(): Stop");
1240 static void
1241 ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt)
1243 struct ospf_route *or;
1244 struct route_node *rn;
1245 struct list *l;
1247 if (IS_DEBUG_OSPF_EVENT)
1248 zlog_debug ("ospf_abr_process_router_rt(): Start");
1250 for (rn = route_top (rt); rn; rn = route_next (rn))
1252 struct listnode *node, *nnode;
1253 char flag = 0;
1254 struct ospf_route *best = NULL;
1256 if (rn->info == NULL)
1257 continue;
1259 l = rn->info;
1261 if (IS_DEBUG_OSPF_EVENT)
1262 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
1263 inet_ntoa (rn->p.u.prefix4));
1265 for (ALL_LIST_ELEMENTS (l, node, nnode, or))
1267 if (!ospf_area_lookup_by_area_id (ospf, or->u.std.area_id))
1269 if (IS_DEBUG_OSPF_EVENT)
1270 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
1271 inet_ntoa (or->u.std.area_id));
1272 continue;
1276 if (!CHECK_FLAG (or->u.std.flags, ROUTER_LSA_EXTERNAL))
1278 if (IS_DEBUG_OSPF_EVENT)
1279 zlog_debug ("ospf_abr_process_router_rt(): "
1280 "This is not an ASBR, skipping");
1281 continue;
1284 if (!flag)
1286 best = ospf_find_asbr_route (ospf, rt,
1287 (struct prefix_ipv4 *) &rn->p);
1288 flag = 1;
1291 if (best == NULL)
1292 continue;
1294 if (or != best)
1296 if (IS_DEBUG_OSPF_EVENT)
1297 zlog_debug ("ospf_abr_process_router_rt(): "
1298 "This route is not the best among possible, skipping");
1299 continue;
1302 if (or->path_type == OSPF_PATH_INTER_AREA &&
1303 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1305 if (IS_DEBUG_OSPF_EVENT)
1306 zlog_debug ("ospf_abr_process_router_rt(): "
1307 "This route is not a backbone one, skipping");
1308 continue;
1311 if (or->cost >= OSPF_LS_INFINITY)
1313 if (IS_DEBUG_OSPF_EVENT)
1314 zlog_debug ("ospf_abr_process_router_rt(): "
1315 "This route has LS_INFINITY metric, skipping");
1316 continue;
1319 if (ospf->abr_type == OSPF_ABR_CISCO
1320 || ospf->abr_type == OSPF_ABR_IBM)
1321 if (!ospf_act_bb_connection (ospf)
1322 && or->path_type != OSPF_PATH_INTRA_AREA)
1324 if (IS_DEBUG_OSPF_EVENT)
1325 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
1326 "No BB connection, skip not intra-area routes");
1327 continue;
1330 ospf_abr_announce_rtr (ospf, (struct prefix_ipv4 *) &rn->p, or);
1336 if (IS_DEBUG_OSPF_EVENT)
1337 zlog_debug ("ospf_abr_process_router_rt(): Stop");
1340 static void
1341 ospf_abr_unapprove_translates (struct ospf *ospf) /* For NSSA Translations */
1343 struct ospf_lsa *lsa;
1344 struct route_node *rn;
1346 if (IS_DEBUG_OSPF_NSSA)
1347 zlog_debug ("ospf_abr_unapprove_translates(): Start");
1349 /* NSSA Translator is not checked, because it may have gone away,
1350 and we would want to flush any residuals anyway */
1352 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1353 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
1355 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1356 if (IS_DEBUG_OSPF_NSSA)
1357 zlog_debug ("ospf_abr_unapprove_translates(): "
1358 "approved unset on link id %s",
1359 inet_ntoa (lsa->data->id));
1362 if (IS_DEBUG_OSPF_NSSA)
1363 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
1366 static void
1367 ospf_abr_unapprove_summaries (struct ospf *ospf)
1369 struct listnode *node;
1370 struct ospf_area *area;
1371 struct route_node *rn;
1372 struct ospf_lsa *lsa;
1374 if (IS_DEBUG_OSPF_EVENT)
1375 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
1377 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1379 if (IS_DEBUG_OSPF_EVENT)
1380 zlog_debug ("ospf_abr_unapprove_summaries(): "
1381 "considering area %s",
1382 inet_ntoa (area->area_id));
1383 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
1384 if (ospf_lsa_is_self_originated (ospf, lsa))
1386 if (IS_DEBUG_OSPF_EVENT)
1387 zlog_debug ("ospf_abr_unapprove_summaries(): "
1388 "approved unset on summary link id %s",
1389 inet_ntoa (lsa->data->id));
1390 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1393 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
1394 if (ospf_lsa_is_self_originated (ospf, lsa))
1396 if (IS_DEBUG_OSPF_EVENT)
1397 zlog_debug ("ospf_abr_unapprove_summaries(): "
1398 "approved unset on asbr-summary link id %s",
1399 inet_ntoa (lsa->data->id));
1400 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1404 if (IS_DEBUG_OSPF_EVENT)
1405 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
1408 static void
1409 ospf_abr_prepare_aggregates (struct ospf *ospf)
1411 struct listnode *node;
1412 struct route_node *rn;
1413 struct ospf_area_range *range;
1414 struct ospf_area *area;
1416 if (IS_DEBUG_OSPF_EVENT)
1417 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
1419 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1421 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1422 if ((range = rn->info) != NULL)
1424 range->cost = 0;
1425 range->specifics = 0;
1429 if (IS_DEBUG_OSPF_EVENT)
1430 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
1433 static void
1434 ospf_abr_announce_aggregates (struct ospf *ospf)
1436 struct ospf_area *area, *ar;
1437 struct ospf_area_range *range;
1438 struct route_node *rn;
1439 struct prefix p;
1440 struct listnode *node, *n;
1442 if (IS_DEBUG_OSPF_EVENT)
1443 zlog_debug ("ospf_abr_announce_aggregates(): Start");
1445 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1447 if (IS_DEBUG_OSPF_EVENT)
1448 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
1449 inet_ntoa (area->area_id));
1451 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1452 if ((range = rn->info))
1454 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1456 if (IS_DEBUG_OSPF_EVENT)
1457 zlog_debug ("ospf_abr_announce_aggregates():"
1458 " discarding suppress-ranges");
1459 continue;
1462 p.family = AF_INET;
1463 p.u.prefix4 = range->addr;
1464 p.prefixlen = range->masklen;
1466 if (IS_DEBUG_OSPF_EVENT)
1467 zlog_debug ("ospf_abr_announce_aggregates():"
1468 " this is range: %s/%d",
1469 inet_ntoa (p.u.prefix4), p.prefixlen);
1471 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1473 p.family = AF_INET;
1474 p.u.prefix4 = range->subst_addr;
1475 p.prefixlen = range->subst_masklen;
1478 if (range->specifics)
1480 if (IS_DEBUG_OSPF_EVENT)
1481 zlog_debug ("ospf_abr_announce_aggregates(): active range");
1483 for (ALL_LIST_ELEMENTS_RO (ospf->areas, n, ar))
1485 if (ar == area)
1486 continue;
1488 /* We do not check nexthops here, because
1489 intra-area routes can be associated with
1490 one area only */
1492 /* backbone routes are not summarized
1493 when announced into transit areas */
1495 if (ospf_area_is_transit (ar) &&
1496 OSPF_IS_AREA_BACKBONE (area))
1498 if (IS_DEBUG_OSPF_EVENT)
1499 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
1500 "announcement of BB aggregate into"
1501 " a transit area");
1502 continue;
1504 ospf_abr_announce_network_to_area ((struct prefix_ipv4 *)&p, range->cost, ar);
1510 if (IS_DEBUG_OSPF_EVENT)
1511 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
1514 static void
1515 ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */
1517 struct listnode *node; /*, n; */
1518 struct ospf_area *area; /*, *ar; */
1519 struct route_node *rn;
1520 struct ospf_area_range *range;
1521 struct prefix_ipv4 p;
1523 if (IS_DEBUG_OSPF_NSSA)
1524 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
1526 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1528 if (! area->NSSATranslatorState)
1529 continue;
1531 if (IS_DEBUG_OSPF_NSSA)
1532 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
1533 inet_ntoa (area->area_id));
1535 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1537 if (rn->info == NULL)
1538 continue;
1540 range = rn->info;
1542 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1544 if (IS_DEBUG_OSPF_NSSA)
1545 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1546 " discarding suppress-ranges");
1547 continue;
1550 p.family = AF_INET;
1551 p.prefix = range->addr;
1552 p.prefixlen = range->masklen;
1554 if (IS_DEBUG_OSPF_NSSA)
1555 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1556 " this is range: %s/%d",
1557 inet_ntoa (p.prefix), p.prefixlen);
1559 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1561 p.family = AF_INET;
1562 p.prefix = range->subst_addr;
1563 p.prefixlen = range->subst_masklen;
1566 if (range->specifics)
1568 if (IS_DEBUG_OSPF_NSSA)
1569 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
1571 /* Fetch LSA-Type-7 from aggregate prefix, and then
1572 * translate, Install (as Type-5), Approve, and Flood
1574 ospf_abr_translate_nssa_range (&p, range->cost);
1576 } /* all area ranges*/
1577 } /* all areas */
1579 if (IS_DEBUG_OSPF_NSSA)
1580 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
1583 static void
1584 ospf_abr_announce_nssa_defaults (struct ospf *ospf) /* By ABR-Translator */
1586 struct listnode *node;
1587 struct ospf_area *area;
1589 if (! IS_OSPF_ABR (ospf))
1590 return;
1592 if (IS_DEBUG_OSPF_NSSA)
1593 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
1595 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1597 if (IS_DEBUG_OSPF_NSSA)
1598 zlog_debug ("ospf_abr_announce_nssa_defaults(): looking at area %s",
1599 inet_ntoa (area->area_id));
1601 if (area->external_routing != OSPF_AREA_NSSA)
1602 continue;
1604 if (OSPF_IS_AREA_BACKBONE (area))
1605 continue; /* Sanity Check */
1607 /* if (!TranslatorRole continue V 1.0 look for "always" conf */
1608 if (area->NSSATranslatorState)
1610 if (IS_DEBUG_OSPF_NSSA)
1611 zlog_debug ("ospf_abr_announce_nssa_defaults(): "
1612 "announcing 0.0.0.0/0 to this nssa");
1613 /* ospf_abr_announce_nssa_asbr_to_as (&p, area->default_cost, area); */
1614 /*ospf_abr_announce_network_to_area (&p, area->default_cost, area);*/
1619 static void
1620 ospf_abr_announce_stub_defaults (struct ospf *ospf)
1622 struct listnode *node;
1623 struct ospf_area *area;
1624 struct prefix_ipv4 p;
1626 if (! IS_OSPF_ABR (ospf))
1627 return;
1629 if (IS_DEBUG_OSPF_EVENT)
1630 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
1632 p.family = AF_INET;
1633 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1634 p.prefixlen = 0;
1636 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1638 if (IS_DEBUG_OSPF_EVENT)
1639 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1640 inet_ntoa (area->area_id));
1642 if ( (area->external_routing != OSPF_AREA_STUB)
1643 && (area->external_routing != OSPF_AREA_NSSA)
1645 continue;
1647 if (OSPF_IS_AREA_BACKBONE (area))
1648 continue; /* Sanity Check */
1650 if (IS_DEBUG_OSPF_EVENT)
1651 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1652 "announcing 0.0.0.0/0 to area %s",
1653 inet_ntoa (area->area_id));
1654 ospf_abr_announce_network_to_area (&p, area->default_cost, area);
1657 if (IS_DEBUG_OSPF_EVENT)
1658 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
1661 static int
1662 ospf_abr_remove_unapproved_translates_apply (struct ospf *ospf,
1663 struct ospf_lsa *lsa)
1665 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)
1666 && ! CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1668 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1669 "removing unapproved translates, ID: %s",
1670 inet_ntoa (lsa->data->id));
1672 /* FLUSH THROUGHOUT AS */
1673 ospf_lsa_flush_as (ospf, lsa);
1675 /* DISCARD from LSDB */
1677 return 0;
1680 static void
1681 ospf_abr_remove_unapproved_translates (struct ospf *ospf)
1683 struct route_node *rn;
1684 struct ospf_lsa *lsa;
1686 /* All AREA PROCESS should have APPROVED necessary LSAs */
1687 /* Remove any left over and not APPROVED */
1688 if (IS_DEBUG_OSPF_NSSA)
1689 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
1691 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1692 ospf_abr_remove_unapproved_translates_apply (ospf, lsa);
1694 if (IS_DEBUG_OSPF_NSSA)
1695 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
1698 static void
1699 ospf_abr_remove_unapproved_summaries (struct ospf *ospf)
1701 struct listnode *node;
1702 struct ospf_area *area;
1703 struct route_node *rn;
1704 struct ospf_lsa *lsa;
1706 if (IS_DEBUG_OSPF_EVENT)
1707 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
1709 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1711 if (IS_DEBUG_OSPF_EVENT)
1712 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
1713 "looking at area %s", inet_ntoa (area->area_id));
1715 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
1716 if (ospf_lsa_is_self_originated (ospf, lsa))
1717 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1718 ospf_lsa_flush_area (lsa, area);
1720 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
1721 if (ospf_lsa_is_self_originated (ospf, lsa))
1722 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1723 ospf_lsa_flush_area (lsa, area);
1726 if (IS_DEBUG_OSPF_EVENT)
1727 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
1730 static void
1731 ospf_abr_manage_discard_routes (struct ospf *ospf)
1733 struct listnode *node, *nnode;
1734 struct route_node *rn;
1735 struct ospf_area *area;
1736 struct ospf_area_range *range;
1738 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
1739 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1740 if ((range = rn->info) != NULL)
1741 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1743 if (range->specifics)
1744 ospf_add_discard_route (ospf->new_table, area,
1745 (struct prefix_ipv4 *) &rn->p);
1746 else
1747 ospf_delete_discard_route ((struct prefix_ipv4 *) &rn->p);
1751 /* This is the function taking care about ABR NSSA, i.e. NSSA
1752 Translator, -LSA aggregation and flooding. For all NSSAs
1754 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1755 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1756 with the P-bit set.
1758 Any received Type-5s are legal for an ABR, else illegal for IR.
1759 Received Type-7s are installed, by area, with incoming P-bit. They
1760 are flooded; if the Elected NSSA Translator, then P-bit off.
1762 Additionally, this ABR will place "translated type-7's" into the
1763 Type-5 LSDB in order to keep track of APPROVAL or not.
1765 It will scan through every area, looking for Type-7 LSAs with P-Bit
1766 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1767 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1768 5-INSTALLED.
1770 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1771 left over are FLUSHED and DISCARDED.
1773 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1774 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1776 static void
1777 ospf_abr_nssa_task (struct ospf *ospf) /* called only if any_nssa */
1779 if (IS_DEBUG_OSPF_NSSA)
1780 zlog_debug ("Check for NSSA-ABR Tasks():");
1782 if (! IS_OSPF_ABR (ospf))
1783 return;
1785 if (! ospf->anyNSSA)
1786 return;
1788 /* Each area must confirm TranslatorRole */
1789 if (IS_DEBUG_OSPF_NSSA)
1790 zlog_debug ("ospf_abr_nssa_task(): Start");
1792 /* For all Global Entries flagged "local-translate", unset APPROVED */
1793 if (IS_DEBUG_OSPF_NSSA)
1794 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
1796 ospf_abr_unapprove_translates (ospf);
1798 /* RESET all Ranges in every Area, same as summaries */
1799 if (IS_DEBUG_OSPF_NSSA)
1800 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
1801 ospf_abr_prepare_aggregates (ospf); /*TURNED OFF just for now */
1803 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1804 * Aggregate as Type-7
1805 * Install or Approve in Type-5 Global LSDB
1807 if (IS_DEBUG_OSPF_NSSA)
1808 zlog_debug ("ospf_abr_nssa_task(): process translates");
1809 ospf_abr_process_nssa_translates (ospf);
1811 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1812 * Approve
1813 * Scan Type-7's for aggregates, translate to Type-5's,
1814 * Install/Flood/Approve
1816 if (IS_DEBUG_OSPF_NSSA)
1817 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1818 ospf_abr_send_nssa_aggregates (ospf); /*TURNED OFF FOR NOW */
1820 /* Send any NSSA defaults as Type-5
1821 *if (IS_DEBUG_OSPF_NSSA)
1822 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1823 *ospf_abr_announce_nssa_defaults (ospf);
1824 * havnt a clue what above is supposed to do.
1827 /* Flush any unapproved previous translates from Global Data Base */
1828 if (IS_DEBUG_OSPF_NSSA)
1829 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
1830 ospf_abr_remove_unapproved_translates (ospf);
1832 ospf_abr_manage_discard_routes (ospf); /* same as normal...discard */
1834 if (IS_DEBUG_OSPF_NSSA)
1835 zlog_debug ("ospf_abr_nssa_task(): Stop");
1838 /* This is the function taking care about ABR stuff, i.e.
1839 summary-LSA origination and flooding. */
1840 void
1841 ospf_abr_task (struct ospf *ospf)
1843 if (IS_DEBUG_OSPF_EVENT)
1844 zlog_debug ("ospf_abr_task(): Start");
1846 if (ospf->new_table == NULL || ospf->new_rtrs == NULL)
1848 if (IS_DEBUG_OSPF_EVENT)
1849 zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
1850 return;
1853 if (IS_DEBUG_OSPF_EVENT)
1854 zlog_debug ("ospf_abr_task(): unapprove summaries");
1855 ospf_abr_unapprove_summaries (ospf);
1857 if (IS_DEBUG_OSPF_EVENT)
1858 zlog_debug ("ospf_abr_task(): prepare aggregates");
1859 ospf_abr_prepare_aggregates (ospf);
1861 if (IS_OSPF_ABR (ospf))
1863 if (IS_DEBUG_OSPF_EVENT)
1864 zlog_debug ("ospf_abr_task(): process network RT");
1865 ospf_abr_process_network_rt (ospf, ospf->new_table);
1867 if (IS_DEBUG_OSPF_EVENT)
1868 zlog_debug ("ospf_abr_task(): process router RT");
1869 ospf_abr_process_router_rt (ospf, ospf->new_rtrs);
1871 if (IS_DEBUG_OSPF_EVENT)
1872 zlog_debug ("ospf_abr_task(): announce aggregates");
1873 ospf_abr_announce_aggregates (ospf);
1875 if (IS_DEBUG_OSPF_EVENT)
1876 zlog_debug ("ospf_abr_task(): announce stub defaults");
1877 ospf_abr_announce_stub_defaults (ospf);
1880 if (IS_DEBUG_OSPF_EVENT)
1881 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
1882 ospf_abr_remove_unapproved_summaries (ospf);
1884 ospf_abr_manage_discard_routes (ospf);
1886 if (IS_DEBUG_OSPF_EVENT)
1887 zlog_debug ("ospf_abr_task(): Stop");
1890 static int
1891 ospf_abr_task_timer (struct thread *thread)
1893 struct ospf *ospf = THREAD_ARG (thread);
1895 ospf->t_abr_task = 0;
1897 if (IS_DEBUG_OSPF_EVENT)
1898 zlog_debug ("Running ABR task on timer");
1900 ospf_check_abr_status (ospf);
1901 ospf_abr_nssa_check_status (ospf);
1903 ospf_abr_task (ospf);
1904 ospf_abr_nssa_task (ospf); /* if nssa-abr, then scan Type-7 LSDB */
1906 return 0;
1909 void
1910 ospf_schedule_abr_task (struct ospf *ospf)
1912 if (IS_DEBUG_OSPF_EVENT)
1913 zlog_debug ("Scheduling ABR task");
1915 if (ospf->t_abr_task == NULL)
1916 ospf->t_abr_task = thread_add_timer (master, ospf_abr_task_timer,
1917 ospf, OSPF_ABR_TASK_DELAY);