]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_abr.c
ospfd-spf-stats.patch
[mirror_frr.git] / ospfd / ospf_abr.c
1 /*
2 * OSPF ABR functions.
3 * Copyright (C) 1999, 2000 Alex Zinin, Toshiaki Takada
4 *
5 * This file is part of GNU Zebra.
6 *
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.
11 *
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.
16 *
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.
21 */
22
23
24 #include <zebra.h>
25
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"
36
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"
53
54 static struct ospf_area_range *
55 ospf_area_range_new (struct prefix_ipv4 *p)
56 {
57 struct ospf_area_range *range;
58
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;
63
64 return range;
65 }
66
67 static void
68 ospf_area_range_free (struct ospf_area_range *range)
69 {
70 XFREE (MTYPE_OSPF_AREA_RANGE, range);
71 }
72
73 static void
74 ospf_area_range_add (struct ospf_area *area, struct ospf_area_range *range)
75 {
76 struct route_node *rn;
77 struct prefix_ipv4 p;
78
79 p.family = AF_INET;
80 p.prefixlen = range->masklen;
81 p.prefix = range->addr;
82
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;
88 }
89
90 static void
91 ospf_area_range_delete (struct ospf_area *area, struct route_node *rn)
92 {
93 struct ospf_area_range *range = rn->info;
94
95 if (range->specifics != 0)
96 ospf_delete_discard_route (area->ospf->new_table,
97 (struct prefix_ipv4 *) &rn->p);
98
99 ospf_area_range_free (range);
100 rn->info = NULL;
101 route_unlock_node (rn);
102 route_unlock_node (rn);
103 }
104
105 struct ospf_area_range *
106 ospf_area_range_lookup (struct ospf_area *area, struct prefix_ipv4 *p)
107 {
108 struct route_node *rn;
109
110 rn = route_node_lookup (area->ranges, (struct prefix *)p);
111 if (rn)
112 {
113 route_unlock_node (rn);
114 return rn->info;
115 }
116 return NULL;
117 }
118
119 struct ospf_area_range *
120 ospf_area_range_lookup_next (struct ospf_area *area,
121 struct in_addr *range_net,
122 int first)
123 {
124 struct route_node *rn;
125 struct prefix_ipv4 p;
126 struct ospf_area_range *find;
127
128 p.family = AF_INET;
129 p.prefixlen = IPV4_MAX_BITLEN;
130 p.prefix = *range_net;
131
132 if (first)
133 rn = route_top (area->ranges);
134 else
135 {
136 rn = route_node_get (area->ranges, (struct prefix *) &p);
137 rn = route_next (rn);
138 }
139
140 for (; rn; rn = route_next (rn))
141 if (rn->info)
142 break;
143
144 if (rn && rn->info)
145 {
146 find = rn->info;
147 *range_net = rn->p.u.prefix4;
148 route_unlock_node (rn);
149 return find;
150 }
151 return NULL;
152 }
153
154 static struct ospf_area_range *
155 ospf_area_range_match (struct ospf_area *area, struct prefix_ipv4 *p)
156 {
157 struct route_node *node;
158
159 node = route_node_match (area->ranges, (struct prefix *) p);
160 if (node)
161 {
162 route_unlock_node (node);
163 return node->info;
164 }
165 return NULL;
166 }
167
168 struct ospf_area_range *
169 ospf_area_range_match_any (struct ospf *ospf, struct prefix_ipv4 *p)
170 {
171 struct ospf_area_range *range;
172 struct ospf_area *area;
173 struct listnode *node;
174
175 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
176 if ((range = ospf_area_range_match (area, p)))
177 return range;
178
179 return NULL;
180 }
181
182 int
183 ospf_area_range_active (struct ospf_area_range *range)
184 {
185 return range->specifics;
186 }
187
188 static int
189 ospf_area_actively_attached (struct ospf_area *area)
190 {
191 return area->act_ints;
192 }
193
194 int
195 ospf_area_range_set (struct ospf *ospf, struct in_addr area_id,
196 struct prefix_ipv4 *p, int advertise)
197 {
198 struct ospf_area *area;
199 struct ospf_area_range *range;
200 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
201
202 area = ospf_area_get (ospf, area_id, ret);
203 if (area == NULL)
204 return 0;
205
206 range = ospf_area_range_lookup (area, p);
207 if (range != NULL)
208 {
209 if ((CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
210 && !CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
211 || (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
212 && CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE)))
213 ospf_schedule_abr_task (ospf);
214 }
215 else
216 {
217 range = ospf_area_range_new (p);
218 ospf_area_range_add (area, range);
219 ospf_schedule_abr_task (ospf);
220 }
221
222 if (CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
223 SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
224 else
225 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
226
227 return 1;
228 }
229
230 int
231 ospf_area_range_cost_set (struct ospf *ospf, struct in_addr area_id,
232 struct prefix_ipv4 *p, u_int32_t cost)
233 {
234 struct ospf_area *area;
235 struct ospf_area_range *range;
236 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
237
238 area = ospf_area_get (ospf, area_id, ret);
239 if (area == NULL)
240 return 0;
241
242 range = ospf_area_range_lookup (area, p);
243 if (range == NULL)
244 return 0;
245
246 if (range->cost_config != cost)
247 {
248 range->cost_config = cost;
249 if (ospf_area_range_active (range))
250 ospf_schedule_abr_task (ospf);
251 }
252
253 return 1;
254 }
255
256 int
257 ospf_area_range_unset (struct ospf *ospf, struct in_addr area_id,
258 struct prefix_ipv4 *p)
259 {
260 struct ospf_area *area;
261 struct route_node *rn;
262
263 area = ospf_area_lookup_by_area_id (ospf, area_id);
264 if (area == NULL)
265 return 0;
266
267 rn = route_node_lookup (area->ranges, (struct prefix*)p);
268 if (rn == NULL)
269 return 0;
270
271 if (ospf_area_range_active (rn->info))
272 ospf_schedule_abr_task (ospf);
273
274 ospf_area_range_delete (area, rn);
275
276 return 1;
277 }
278
279 int
280 ospf_area_range_substitute_set (struct ospf *ospf, struct in_addr area_id,
281 struct prefix_ipv4 *p, struct prefix_ipv4 *s)
282 {
283 struct ospf_area *area;
284 struct ospf_area_range *range;
285 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
286
287 area = ospf_area_get (ospf, area_id, ret);
288 range = ospf_area_range_lookup (area, p);
289
290 if (range != NULL)
291 {
292 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE) ||
293 !CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
294 ospf_schedule_abr_task (ospf);
295 }
296 else
297 {
298 range = ospf_area_range_new (p);
299 ospf_area_range_add (area, range);
300 ospf_schedule_abr_task (ospf);
301 }
302
303 SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
304 SET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
305 range->subst_addr = s->prefix;
306 range->subst_masklen = s->prefixlen;
307
308 return 1;
309 }
310
311 int
312 ospf_area_range_substitute_unset (struct ospf *ospf, struct in_addr area_id,
313 struct prefix_ipv4 *p)
314 {
315 struct ospf_area *area;
316 struct ospf_area_range *range;
317
318 area = ospf_area_lookup_by_area_id (ospf, area_id);
319 if (area == NULL)
320 return 0;
321
322 range = ospf_area_range_lookup (area, p);
323 if (range == NULL)
324 return 0;
325
326 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
327 if (ospf_area_range_active (range))
328 ospf_schedule_abr_task (ospf);
329
330 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
331 range->subst_addr.s_addr = 0;
332 range->subst_masklen = 0;
333
334 return 1;
335 }
336
337 int
338 ospf_act_bb_connection (struct ospf *ospf)
339 {
340 if (ospf->backbone == NULL)
341 return 0;
342
343 return ospf->backbone->full_nbrs;
344 }
345
346 /* Determine whether this router is elected translator or not for area */
347 static int
348 ospf_abr_nssa_am_elected (struct ospf_area *area)
349 {
350 struct route_node *rn;
351 struct ospf_lsa *lsa;
352 struct router_lsa *rlsa;
353 struct in_addr *best = NULL;
354
355 LSDB_LOOP ( ROUTER_LSDB (area), rn, lsa)
356 {
357 /* sanity checks */
358 if (!lsa
359 || (lsa->data->type != OSPF_ROUTER_LSA)
360 || IS_LSA_SELF (lsa))
361 continue;
362
363 rlsa = (struct router_lsa *) lsa->data;
364
365 /* ignore non-ABR routers */
366 if (!IS_ROUTER_LSA_BORDER (rlsa))
367 continue;
368
369 /* Router has Nt flag - always translate */
370 if (IS_ROUTER_LSA_NT (rlsa))
371 {
372 if (IS_DEBUG_OSPF_NSSA)
373 zlog_debug ("ospf_abr_nssa_am_elected: "
374 "router %s asserts Nt",
375 inet_ntoa (lsa->data->id) );
376 return 0;
377 }
378
379 if (best == NULL)
380 best = &lsa->data->id;
381 else
382 if (IPV4_ADDR_CMP (&best->s_addr, &lsa->data->id.s_addr) < 0)
383 best = &lsa->data->id;
384 }
385
386 if (IS_DEBUG_OSPF_NSSA)
387 zlog_debug ("ospf_abr_nssa_am_elected: best electable ABR is: %s",
388 (best) ? inet_ntoa (*best) : "<none>" );
389
390 if (best == NULL)
391 return 1;
392
393 if (IPV4_ADDR_CMP (&best->s_addr, &area->ospf->router_id.s_addr) < 0)
394 return 1;
395 else
396 return 0;
397 }
398
399 /* Check NSSA ABR status
400 * assumes there are nssa areas
401 */
402 static void
403 ospf_abr_nssa_check_status (struct ospf *ospf)
404 {
405 struct ospf_area *area;
406 struct listnode *lnode, *nnode;
407
408 for (ALL_LIST_ELEMENTS (ospf->areas, lnode, nnode, area))
409 {
410 u_char old_state = area->NSSATranslatorState;
411
412 if (area->external_routing != OSPF_AREA_NSSA)
413 continue;
414
415 if (IS_DEBUG_OSPF (nssa, NSSA))
416 zlog_debug ("ospf_abr_nssa_check_status: "
417 "checking area %s",
418 inet_ntoa (area->area_id));
419
420 if (!IS_OSPF_ABR (area->ospf))
421 {
422 if (IS_DEBUG_OSPF (nssa, NSSA))
423 zlog_debug ("ospf_abr_nssa_check_status: "
424 "not ABR");
425 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
426 }
427 else
428 {
429 switch (area->NSSATranslatorRole)
430 {
431 case OSPF_NSSA_ROLE_NEVER:
432 /* We never Translate Type-7 LSA. */
433 /* TODO: check previous state and flush? */
434 if (IS_DEBUG_OSPF (nssa, NSSA))
435 zlog_debug ("ospf_abr_nssa_check_status: "
436 "never translate");
437 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
438 break;
439
440 case OSPF_NSSA_ROLE_ALWAYS:
441 /* We always translate if we are an ABR
442 * TODO: originate new LSAs if state change?
443 * or let the nssa abr task take care of it?
444 */
445 if (IS_DEBUG_OSPF (nssa, NSSA))
446 zlog_debug ("ospf_abr_nssa_check_status: "
447 "translate always");
448 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
449 break;
450
451 case OSPF_NSSA_ROLE_CANDIDATE:
452 /* We are a candidate for Translation */
453 if (ospf_abr_nssa_am_elected (area) > 0)
454 {
455 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
456 if (IS_DEBUG_OSPF (nssa, NSSA))
457 zlog_debug ("ospf_abr_nssa_check_status: "
458 "elected translator");
459 }
460 else
461 {
462 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
463 if (IS_DEBUG_OSPF (nssa, NSSA))
464 zlog_debug ("ospf_abr_nssa_check_status: " "not elected");
465 }
466 break;
467 }
468 }
469 /* RFC3101, 3.1:
470 * All NSSA border routers must set the E-bit in the Type-1 router-LSAs
471 * of their directly attached non-stub areas, even when they are not
472 * translating.
473 */
474 if (old_state != area->NSSATranslatorState)
475 {
476 if (old_state == OSPF_NSSA_TRANSLATE_DISABLED)
477 ospf_asbr_status_update (ospf, ++ospf->redistribute);
478 else if (area->NSSATranslatorState == OSPF_NSSA_TRANSLATE_DISABLED)
479 ospf_asbr_status_update (ospf, --ospf->redistribute);
480 }
481 }
482 }
483
484 /* Check area border router status. */
485 void
486 ospf_check_abr_status (struct ospf *ospf)
487 {
488 struct ospf_area *area;
489 struct listnode *node, *nnode;
490 int bb_configured = 0;
491 int bb_act_attached = 0;
492 int areas_configured = 0;
493 int areas_act_attached = 0;
494 u_char new_flags = ospf->flags;
495
496 if (IS_DEBUG_OSPF_EVENT)
497 zlog_debug ("ospf_check_abr_status(): Start");
498
499 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
500 {
501 if (listcount (area->oiflist))
502 {
503 areas_configured++;
504
505 if (OSPF_IS_AREA_BACKBONE (area))
506 bb_configured = 1;
507 }
508
509 if (ospf_area_actively_attached (area))
510 {
511 areas_act_attached++;
512
513 if (OSPF_IS_AREA_BACKBONE (area))
514 bb_act_attached = 1;
515 }
516 }
517
518 if (IS_DEBUG_OSPF_EVENT)
519 {
520 zlog_debug ("ospf_check_abr_status(): looked through areas");
521 zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured);
522 zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
523 bb_act_attached);
524 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
525 areas_configured);
526 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
527 areas_act_attached);
528 }
529
530 switch (ospf->abr_type)
531 {
532 case OSPF_ABR_SHORTCUT:
533 case OSPF_ABR_STAND:
534 if (areas_act_attached > 1)
535 SET_FLAG (new_flags, OSPF_FLAG_ABR);
536 else
537 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
538 break;
539
540 case OSPF_ABR_IBM:
541 if ((areas_act_attached > 1) && bb_configured)
542 SET_FLAG (new_flags, OSPF_FLAG_ABR);
543 else
544 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
545 break;
546
547 case OSPF_ABR_CISCO:
548 if ((areas_configured > 1) && bb_act_attached)
549 SET_FLAG (new_flags, OSPF_FLAG_ABR);
550 else
551 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
552 break;
553 default:
554 break;
555 }
556
557 if (new_flags != ospf->flags)
558 {
559 ospf_flag_spf_reason (SPF_FLAG_ABR_STATUS_CHANGE);
560 ospf_spf_calculate_schedule (ospf);
561 if (IS_DEBUG_OSPF_EVENT)
562 zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags);
563 ospf->flags = new_flags;
564 ospf_router_lsa_update (ospf);
565 }
566 }
567
568 static void
569 ospf_abr_update_aggregate (struct ospf_area_range *range,
570 struct ospf_route *or, struct ospf_area *area)
571 {
572 if (IS_DEBUG_OSPF_EVENT)
573 zlog_debug ("ospf_abr_update_aggregate(): Start");
574
575 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED) &&
576 (range->cost != OSPF_STUB_MAX_METRIC_SUMMARY_COST))
577 {
578 range->cost = OSPF_STUB_MAX_METRIC_SUMMARY_COST;
579 if (IS_DEBUG_OSPF_EVENT)
580 zlog_debug ("ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
581 range->cost);
582 }
583 else if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
584 {
585 if (IS_DEBUG_OSPF_EVENT)
586 zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
587 range->cost_config);
588
589 range->cost = range->cost_config;
590 }
591 else
592 {
593 if (range->specifics == 0)
594 {
595 if (IS_DEBUG_OSPF_EVENT)
596 zlog_debug ("ospf_abr_update_aggregate(): use or->cost %d",
597 or->cost);
598
599 range->cost = or->cost; /* 1st time get 1st cost */
600 }
601
602 if (or->cost > range->cost)
603 {
604 if (IS_DEBUG_OSPF_EVENT)
605 zlog_debug ("ospf_abr_update_aggregate(): update to %d", or->cost);
606
607 range->cost = or->cost;
608 }
609 }
610
611 range->specifics++;
612 }
613
614 static void
615 set_metric (struct ospf_lsa *lsa, u_int32_t metric)
616 {
617 struct summary_lsa *header;
618 u_char *mp;
619 metric = htonl (metric);
620 mp = (u_char *) &metric;
621 mp++;
622 header = (struct summary_lsa *) lsa->data;
623 memcpy(header->metric, mp, 3);
624 }
625
626 /* ospf_abr_translate_nssa */
627 static int
628 ospf_abr_translate_nssa (struct ospf_area *area, struct ospf_lsa *lsa)
629 {
630 /* Incoming Type-7 or later aggregated Type-7
631 *
632 * LSA is skipped if P-bit is off.
633 * LSA is aggregated if within range.
634 *
635 * The Type-7 is translated, Installed/Approved as a Type-5 into
636 * global LSDB, then Flooded through AS
637 *
638 * Later, any Unapproved Translated Type-5's are flushed/discarded
639 */
640
641 struct ospf_lsa *old = NULL,
642 *new = NULL;
643 struct as_external_lsa *ext7;
644 struct prefix_ipv4 p;
645
646 if (! CHECK_FLAG (lsa->data->options, OSPF_OPTION_NP))
647 {
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;
652 }
653
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));
657
658 ext7 = (struct as_external_lsa *)(lsa->data);
659 p.prefix = lsa->data->id;
660 p.prefixlen = ip_masklen (ext7->mask);
661
662 if (ext7->e[0].fwd_addr.s_addr == OSPF_DEFAULT_DESTINATION)
663 {
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;
669 }
670
671 /* try find existing AS-External LSA for this prefix */
672
673 old = ospf_external_info_find_lsa (area->ospf, &p);
674
675 if (old)
676 {
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));
681
682 /* refresh */
683 new = ospf_translated_nssa_refresh (area->ospf, lsa, old);
684 if (!new)
685 {
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));
690 }
691 }
692 else
693 {
694 /* no existing external route for this LSA Id
695 * originate translated LSA
696 */
697
698 if ((new = ospf_translated_nssa_originate (area->ospf, lsa))
699 == NULL)
700 {
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;
706 }
707 }
708
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); */
712
713 return 0;
714 }
715
716 static void
717 ospf_abr_translate_nssa_range (struct prefix_ipv4 *p, u_int32_t cost)
718 {
719 /* The Type-7 is created from the aggregated prefix and forwarded
720 for lsa installation and flooding... to be added... */
721 }
722
723 void
724 ospf_abr_announce_network_to_area (struct prefix_ipv4 *p, u_int32_t cost,
725 struct ospf_area *area)
726 {
727 struct ospf_lsa *lsa, *old = NULL;
728 struct summary_lsa *sl = NULL;
729 u_int32_t full_cost;
730
731 if (IS_DEBUG_OSPF_EVENT)
732 zlog_debug ("ospf_abr_announce_network_to_area(): Start");
733
734 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
735 full_cost = OSPF_STUB_MAX_METRIC_SUMMARY_COST;
736 else
737 full_cost = cost;
738
739 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_SUMMARY_LSA,
740 (struct prefix_ipv4 *) p,
741 area->ospf->router_id);
742 if (old)
743 {
744 if (IS_DEBUG_OSPF_EVENT)
745 zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
746
747 sl = (struct summary_lsa *) old->data;
748
749 if (IS_DEBUG_OSPF_EVENT)
750 zlog_debug ("ospf_abr_announce_network_to_area(): "
751 "old metric: %d, new metric: %d",
752 GET_METRIC (sl->metric), cost);
753
754 if ((GET_METRIC (sl->metric) == full_cost) &&
755 ((old->flags & OSPF_LSA_IN_MAXAGE) == 0))
756 {
757 /* unchanged. simply reapprove it */
758 if (IS_DEBUG_OSPF_EVENT)
759 zlog_debug ("ospf_abr_announce_network_to_area(): "
760 "old summary approved");
761 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
762 }
763 else
764 {
765 /* LSA is changed, refresh it */
766 if (IS_DEBUG_OSPF_EVENT)
767 zlog_debug ("ospf_abr_announce_network_to_area(): "
768 "refreshing summary");
769 set_metric (old, full_cost);
770 lsa = ospf_lsa_refresh (area->ospf, old);
771
772 if (!lsa)
773 {
774 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
775
776 prefix2str ((struct prefix *) p, buf, sizeof(buf));
777 zlog_warn ("%s: Could not refresh %s to %s",
778 __func__,
779 buf,
780 inet_ntoa (area->area_id));
781 return;
782 }
783
784 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
785 /* This will flood through area. */
786 }
787 }
788 else
789 {
790 if (IS_DEBUG_OSPF_EVENT)
791 zlog_debug ("ospf_abr_announce_network_to_area(): "
792 "creating new summary");
793 lsa = ospf_summary_lsa_originate ( (struct prefix_ipv4 *)p, full_cost, area);
794 /* This will flood through area. */
795
796 if (!lsa)
797 {
798 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
799
800 prefix2str ((struct prefix *)p, buf, sizeof(buf));
801 zlog_warn ("%s: Could not originate %s to %s",
802 __func__,
803 buf,
804 inet_ntoa (area->area_id));
805 return;
806 }
807
808 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
809 if (IS_DEBUG_OSPF_EVENT)
810 zlog_debug ("ospf_abr_announce_network_to_area(): "
811 "flooding new version of summary");
812 }
813
814 if (IS_DEBUG_OSPF_EVENT)
815 zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
816 }
817
818 static int
819 ospf_abr_nexthops_belong_to_area (struct ospf_route *or,
820 struct ospf_area *area)
821 {
822 struct listnode *node, *nnode;
823 struct ospf_path *path;
824 struct ospf_interface *oi;
825
826 for (ALL_LIST_ELEMENTS_RO (or->paths, node, path))
827 for (ALL_LIST_ELEMENTS_RO (area->oiflist, nnode, oi))
828 if (oi->ifp && oi->ifp->ifindex == path->ifindex)
829 return 1;
830
831 return 0;
832 }
833
834 static int
835 ospf_abr_should_accept (struct prefix_ipv4 *p, struct ospf_area *area)
836 {
837 if (IMPORT_NAME (area))
838 {
839 if (IMPORT_LIST (area) == NULL)
840 IMPORT_LIST (area) = access_list_lookup (AFI_IP, IMPORT_NAME (area));
841
842 if (IMPORT_LIST (area))
843 if (access_list_apply (IMPORT_LIST (area), p) == FILTER_DENY)
844 return 0;
845 }
846
847 return 1;
848 }
849
850 static int
851 ospf_abr_plist_in_check (struct ospf_area *area, struct ospf_route *or,
852 struct prefix_ipv4 *p)
853 {
854 if (PREFIX_NAME_IN (area))
855 {
856 if (PREFIX_LIST_IN (area) == NULL)
857 PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP,
858 PREFIX_NAME_IN (area));
859 if (PREFIX_LIST_IN (area))
860 if (prefix_list_apply (PREFIX_LIST_IN (area), p) != PREFIX_PERMIT)
861 return 0;
862 }
863 return 1;
864 }
865
866 static int
867 ospf_abr_plist_out_check (struct ospf_area *area, struct ospf_route *or,
868 struct prefix_ipv4 *p)
869 {
870 if (PREFIX_NAME_OUT (area))
871 {
872 if (PREFIX_LIST_OUT (area) == NULL)
873 PREFIX_LIST_OUT (area) = prefix_list_lookup (AFI_IP,
874 PREFIX_NAME_OUT (area));
875 if (PREFIX_LIST_OUT (area))
876 if (prefix_list_apply (PREFIX_LIST_OUT (area), p) != PREFIX_PERMIT)
877 return 0;
878 }
879 return 1;
880 }
881
882 static void
883 ospf_abr_announce_network (struct ospf *ospf,
884 struct prefix_ipv4 *p, struct ospf_route *or)
885 {
886 struct ospf_area_range *range;
887 struct ospf_area *area, *or_area;
888 struct listnode *node;
889
890 if (IS_DEBUG_OSPF_EVENT)
891 zlog_debug ("ospf_abr_announce_network(): Start");
892
893 or_area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
894 assert (or_area);
895
896 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
897 {
898 if (IS_DEBUG_OSPF_EVENT)
899 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
900 inet_ntoa (area->area_id));
901
902 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
903 continue;
904
905 if (ospf_abr_nexthops_belong_to_area (or, area))
906 continue;
907
908 if (!ospf_abr_should_accept (p, area))
909 {
910 if (IS_DEBUG_OSPF_EVENT)
911 zlog_debug ("ospf_abr_announce_network(): "
912 "prefix %s/%d was denied by import-list",
913 inet_ntoa (p->prefix), p->prefixlen);
914 continue;
915 }
916
917 if (!ospf_abr_plist_in_check (area, or, p))
918 {
919 if (IS_DEBUG_OSPF_EVENT)
920 zlog_debug ("ospf_abr_announce_network(): "
921 "prefix %s/%d was denied by prefix-list",
922 inet_ntoa (p->prefix), p->prefixlen);
923 continue;
924 }
925
926 if (area->external_routing != OSPF_AREA_DEFAULT && area->no_summary)
927 {
928 if (IS_DEBUG_OSPF_EVENT)
929 zlog_debug ("ospf_abr_announce_network(): "
930 "area %s is stub and no_summary",
931 inet_ntoa (area->area_id));
932 continue;
933 }
934
935 if (or->path_type == OSPF_PATH_INTER_AREA)
936 {
937 if (IS_DEBUG_OSPF_EVENT)
938 zlog_debug ("ospf_abr_announce_network(): this is "
939 "inter-area route to %s/%d",
940 inet_ntoa (p->prefix), p->prefixlen);
941
942 if (!OSPF_IS_AREA_BACKBONE (area))
943 ospf_abr_announce_network_to_area (p, or->cost, area);
944 }
945
946 if (or->path_type == OSPF_PATH_INTRA_AREA)
947 {
948 if (IS_DEBUG_OSPF_EVENT)
949 zlog_debug ("ospf_abr_announce_network(): "
950 "this is intra-area route to %s/%d",
951 inet_ntoa (p->prefix), p->prefixlen);
952 if ((range = ospf_area_range_match (or_area, p))
953 && !ospf_area_is_transit (area))
954 ospf_abr_update_aggregate (range, or, area);
955 else
956 ospf_abr_announce_network_to_area (p, or->cost, area);
957 }
958 }
959 }
960
961 static int
962 ospf_abr_should_announce (struct ospf *ospf,
963 struct prefix_ipv4 *p, struct ospf_route *or)
964 {
965 struct ospf_area *area;
966
967 area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
968
969 assert (area);
970
971 if (EXPORT_NAME (area))
972 {
973 if (EXPORT_LIST (area) == NULL)
974 EXPORT_LIST (area) = access_list_lookup (AFI_IP, EXPORT_NAME (area));
975
976 if (EXPORT_LIST (area))
977 if (access_list_apply (EXPORT_LIST (area), p) == FILTER_DENY)
978 return 0;
979 }
980
981 return 1;
982 }
983
984 static void
985 ospf_abr_process_nssa_translates (struct ospf *ospf)
986 {
987 /* Scan through all NSSA_LSDB records for all areas;
988
989 If P-bit is on, translate all Type-7's to 5's and aggregate or
990 flood install as approved in Type-5 LSDB with XLATE Flag on
991 later, do same for all aggregates... At end, DISCARD all
992 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
993 struct listnode *node;
994 struct ospf_area *area;
995 struct route_node *rn;
996 struct ospf_lsa *lsa;
997
998 if (IS_DEBUG_OSPF_NSSA)
999 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
1000
1001 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1002 {
1003 if (! area->NSSATranslatorState)
1004 continue; /* skip if not translator */
1005
1006 if (area->external_routing != OSPF_AREA_NSSA)
1007 continue; /* skip if not Nssa Area */
1008
1009 if (IS_DEBUG_OSPF_NSSA)
1010 zlog_debug ("ospf_abr_process_nssa_translates(): "
1011 "looking at area %s", inet_ntoa (area->area_id));
1012
1013 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
1014 ospf_abr_translate_nssa (area, lsa);
1015 }
1016
1017 if (IS_DEBUG_OSPF_NSSA)
1018 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
1019
1020 }
1021
1022 static void
1023 ospf_abr_process_network_rt (struct ospf *ospf,
1024 struct route_table *rt)
1025 {
1026 struct ospf_area *area;
1027 struct ospf_route *or;
1028 struct route_node *rn;
1029
1030 if (IS_DEBUG_OSPF_EVENT)
1031 zlog_debug ("ospf_abr_process_network_rt(): Start");
1032
1033 for (rn = route_top (rt); rn; rn = route_next (rn))
1034 {
1035 if ((or = rn->info) == NULL)
1036 continue;
1037
1038 if (!(area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id)))
1039 {
1040 if (IS_DEBUG_OSPF_EVENT)
1041 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
1042 inet_ntoa (or->u.std.area_id));
1043 continue;
1044 }
1045
1046 if (IS_DEBUG_OSPF_EVENT)
1047 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
1048 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
1049 if (or->path_type >= OSPF_PATH_TYPE1_EXTERNAL)
1050 {
1051 if (IS_DEBUG_OSPF_EVENT)
1052 zlog_debug ("ospf_abr_process_network_rt(): "
1053 "this is an External router, skipping");
1054 continue;
1055 }
1056
1057 if (or->cost >= OSPF_LS_INFINITY)
1058 {
1059 if (IS_DEBUG_OSPF_EVENT)
1060 zlog_debug ("ospf_abr_process_network_rt():"
1061 " this route's cost is infinity, skipping");
1062 continue;
1063 }
1064
1065 if (or->type == OSPF_DESTINATION_DISCARD)
1066 {
1067 if (IS_DEBUG_OSPF_EVENT)
1068 zlog_debug ("ospf_abr_process_network_rt():"
1069 " this is a discard entry, skipping");
1070 continue;
1071 }
1072
1073 if (or->path_type == OSPF_PATH_INTRA_AREA &&
1074 !ospf_abr_should_announce (ospf, (struct prefix_ipv4 *) &rn->p, or))
1075 {
1076 if (IS_DEBUG_OSPF_EVENT)
1077 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
1078 continue;
1079 }
1080
1081 if (or->path_type == OSPF_PATH_INTRA_AREA &&
1082 !ospf_abr_plist_out_check (area, or, (struct prefix_ipv4 *) &rn->p))
1083 {
1084 if (IS_DEBUG_OSPF_EVENT)
1085 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
1086 continue;
1087 }
1088
1089 if ((or->path_type == OSPF_PATH_INTER_AREA) &&
1090 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1091 {
1092 if (IS_DEBUG_OSPF_EVENT)
1093 zlog_debug ("ospf_abr_process_network_rt():"
1094 " this is route is not backbone one, skipping");
1095 continue;
1096 }
1097
1098
1099 if ((ospf->abr_type == OSPF_ABR_CISCO) ||
1100 (ospf->abr_type == OSPF_ABR_IBM))
1101
1102 if (!ospf_act_bb_connection (ospf) &&
1103 or->path_type != OSPF_PATH_INTRA_AREA)
1104 {
1105 if (IS_DEBUG_OSPF_EVENT)
1106 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
1107 "No BB connection, skip not intra-area routes");
1108 continue;
1109 }
1110
1111 if (IS_DEBUG_OSPF_EVENT)
1112 zlog_debug ("ospf_abr_process_network_rt(): announcing");
1113 ospf_abr_announce_network (ospf, (struct prefix_ipv4 *)&rn->p, or);
1114 }
1115
1116 if (IS_DEBUG_OSPF_EVENT)
1117 zlog_debug ("ospf_abr_process_network_rt(): Stop");
1118 }
1119
1120 static void
1121 ospf_abr_announce_rtr_to_area (struct prefix_ipv4 *p, u_int32_t cost,
1122 struct ospf_area *area)
1123 {
1124 struct ospf_lsa *lsa, *old = NULL;
1125 struct summary_lsa *slsa = NULL;
1126
1127 if (IS_DEBUG_OSPF_EVENT)
1128 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
1129
1130 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_ASBR_SUMMARY_LSA,
1131 p, area->ospf->router_id);
1132 if (old)
1133 {
1134 if (IS_DEBUG_OSPF_EVENT)
1135 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
1136 slsa = (struct summary_lsa *) old->data;
1137
1138 if (IS_DEBUG_OSPF_EVENT)
1139 zlog_debug ("ospf_abr_announce_network_to_area(): "
1140 "old metric: %d, new metric: %d",
1141 GET_METRIC (slsa->metric), cost);
1142 }
1143
1144 if (old && (GET_METRIC (slsa->metric) == cost) &&
1145 ((old->flags & OSPF_LSA_IN_MAXAGE) == 0))
1146 {
1147 if (IS_DEBUG_OSPF_EVENT)
1148 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
1149 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
1150 }
1151 else
1152 {
1153 if (IS_DEBUG_OSPF_EVENT)
1154 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
1155
1156 if (old)
1157 {
1158 set_metric (old, cost);
1159 lsa = ospf_lsa_refresh (area->ospf, old);
1160 }
1161 else
1162 lsa = ospf_summary_asbr_lsa_originate (p, cost, area);
1163 if (!lsa)
1164 {
1165 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
1166
1167 prefix2str ((struct prefix *)p, buf, sizeof(buf));
1168 zlog_warn ("%s: Could not refresh/originate %s to %s",
1169 __func__,
1170 buf,
1171 inet_ntoa (area->area_id));
1172 return;
1173 }
1174
1175 if (IS_DEBUG_OSPF_EVENT)
1176 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
1177 "flooding new version of summary");
1178
1179 /*
1180 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1181 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1182
1183 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1184 /* ospf_flood_through_area (area, NULL, lsa);*/
1185 }
1186
1187 if (IS_DEBUG_OSPF_EVENT)
1188 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
1189 }
1190
1191
1192 static void
1193 ospf_abr_announce_rtr (struct ospf *ospf,
1194 struct prefix_ipv4 *p, struct ospf_route *or)
1195 {
1196 struct listnode *node;
1197 struct ospf_area *area;
1198
1199 if (IS_DEBUG_OSPF_EVENT)
1200 zlog_debug ("ospf_abr_announce_rtr(): Start");
1201
1202 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1203 {
1204 if (IS_DEBUG_OSPF_EVENT)
1205 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
1206 inet_ntoa (area->area_id));
1207
1208 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
1209 continue;
1210
1211 if (ospf_abr_nexthops_belong_to_area (or, area))
1212 continue;
1213
1214 if (area->external_routing != OSPF_AREA_DEFAULT)
1215 {
1216 if (IS_DEBUG_OSPF_EVENT)
1217 zlog_debug ("ospf_abr_announce_rtr(): "
1218 "area %s doesn't support external routing",
1219 inet_ntoa(area->area_id));
1220 continue;
1221 }
1222
1223 if (or->path_type == OSPF_PATH_INTER_AREA)
1224 {
1225 if (IS_DEBUG_OSPF_EVENT)
1226 zlog_debug ("ospf_abr_announce_rtr(): "
1227 "this is inter-area route to %s", inet_ntoa (p->prefix));
1228 if (!OSPF_IS_AREA_BACKBONE (area))
1229 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1230 }
1231
1232 if (or->path_type == OSPF_PATH_INTRA_AREA)
1233 {
1234 if (IS_DEBUG_OSPF_EVENT)
1235 zlog_debug ("ospf_abr_announce_rtr(): "
1236 "this is intra-area route to %s", inet_ntoa (p->prefix));
1237 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1238 }
1239 }
1240
1241 if (IS_DEBUG_OSPF_EVENT)
1242 zlog_debug ("ospf_abr_announce_rtr(): Stop");
1243 }
1244
1245 static void
1246 ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt)
1247 {
1248 struct ospf_route *or;
1249 struct route_node *rn;
1250 struct list *l;
1251
1252 if (IS_DEBUG_OSPF_EVENT)
1253 zlog_debug ("ospf_abr_process_router_rt(): Start");
1254
1255 for (rn = route_top (rt); rn; rn = route_next (rn))
1256 {
1257 struct listnode *node, *nnode;
1258 char flag = 0;
1259 struct ospf_route *best = NULL;
1260
1261 if (rn->info == NULL)
1262 continue;
1263
1264 l = rn->info;
1265
1266 if (IS_DEBUG_OSPF_EVENT)
1267 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
1268 inet_ntoa (rn->p.u.prefix4));
1269
1270 for (ALL_LIST_ELEMENTS (l, node, nnode, or))
1271 {
1272 if (!ospf_area_lookup_by_area_id (ospf, or->u.std.area_id))
1273 {
1274 if (IS_DEBUG_OSPF_EVENT)
1275 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
1276 inet_ntoa (or->u.std.area_id));
1277 continue;
1278 }
1279
1280
1281 if (!CHECK_FLAG (or->u.std.flags, ROUTER_LSA_EXTERNAL))
1282 {
1283 if (IS_DEBUG_OSPF_EVENT)
1284 zlog_debug ("ospf_abr_process_router_rt(): "
1285 "This is not an ASBR, skipping");
1286 continue;
1287 }
1288
1289 if (!flag)
1290 {
1291 best = ospf_find_asbr_route (ospf, rt,
1292 (struct prefix_ipv4 *) &rn->p);
1293 flag = 1;
1294 }
1295
1296 if (best == NULL)
1297 continue;
1298
1299 if (or != best)
1300 {
1301 if (IS_DEBUG_OSPF_EVENT)
1302 zlog_debug ("ospf_abr_process_router_rt(): "
1303 "This route is not the best among possible, skipping");
1304 continue;
1305 }
1306
1307 if (or->path_type == OSPF_PATH_INTER_AREA &&
1308 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1309 {
1310 if (IS_DEBUG_OSPF_EVENT)
1311 zlog_debug ("ospf_abr_process_router_rt(): "
1312 "This route is not a backbone one, skipping");
1313 continue;
1314 }
1315
1316 if (or->cost >= OSPF_LS_INFINITY)
1317 {
1318 if (IS_DEBUG_OSPF_EVENT)
1319 zlog_debug ("ospf_abr_process_router_rt(): "
1320 "This route has LS_INFINITY metric, skipping");
1321 continue;
1322 }
1323
1324 if (ospf->abr_type == OSPF_ABR_CISCO
1325 || ospf->abr_type == OSPF_ABR_IBM)
1326 if (!ospf_act_bb_connection (ospf)
1327 && or->path_type != OSPF_PATH_INTRA_AREA)
1328 {
1329 if (IS_DEBUG_OSPF_EVENT)
1330 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
1331 "No BB connection, skip not intra-area routes");
1332 continue;
1333 }
1334
1335 ospf_abr_announce_rtr (ospf, (struct prefix_ipv4 *) &rn->p, or);
1336
1337 }
1338
1339 }
1340
1341 if (IS_DEBUG_OSPF_EVENT)
1342 zlog_debug ("ospf_abr_process_router_rt(): Stop");
1343 }
1344
1345 static void
1346 ospf_abr_unapprove_translates (struct ospf *ospf) /* For NSSA Translations */
1347 {
1348 struct ospf_lsa *lsa;
1349 struct route_node *rn;
1350
1351 if (IS_DEBUG_OSPF_NSSA)
1352 zlog_debug ("ospf_abr_unapprove_translates(): Start");
1353
1354 /* NSSA Translator is not checked, because it may have gone away,
1355 and we would want to flush any residuals anyway */
1356
1357 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1358 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
1359 {
1360 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1361 if (IS_DEBUG_OSPF_NSSA)
1362 zlog_debug ("ospf_abr_unapprove_translates(): "
1363 "approved unset on link id %s",
1364 inet_ntoa (lsa->data->id));
1365 }
1366
1367 if (IS_DEBUG_OSPF_NSSA)
1368 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
1369 }
1370
1371 static void
1372 ospf_abr_unapprove_summaries (struct ospf *ospf)
1373 {
1374 struct listnode *node;
1375 struct ospf_area *area;
1376 struct route_node *rn;
1377 struct ospf_lsa *lsa;
1378
1379 if (IS_DEBUG_OSPF_EVENT)
1380 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
1381
1382 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1383 {
1384 if (IS_DEBUG_OSPF_EVENT)
1385 zlog_debug ("ospf_abr_unapprove_summaries(): "
1386 "considering area %s",
1387 inet_ntoa (area->area_id));
1388 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
1389 if (ospf_lsa_is_self_originated (ospf, lsa))
1390 {
1391 if (IS_DEBUG_OSPF_EVENT)
1392 zlog_debug ("ospf_abr_unapprove_summaries(): "
1393 "approved unset on summary link id %s",
1394 inet_ntoa (lsa->data->id));
1395 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1396 }
1397
1398 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
1399 if (ospf_lsa_is_self_originated (ospf, lsa))
1400 {
1401 if (IS_DEBUG_OSPF_EVENT)
1402 zlog_debug ("ospf_abr_unapprove_summaries(): "
1403 "approved unset on asbr-summary link id %s",
1404 inet_ntoa (lsa->data->id));
1405 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1406 }
1407 }
1408
1409 if (IS_DEBUG_OSPF_EVENT)
1410 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
1411 }
1412
1413 static void
1414 ospf_abr_prepare_aggregates (struct ospf *ospf)
1415 {
1416 struct listnode *node;
1417 struct route_node *rn;
1418 struct ospf_area_range *range;
1419 struct ospf_area *area;
1420
1421 if (IS_DEBUG_OSPF_EVENT)
1422 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
1423
1424 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1425 {
1426 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1427 if ((range = rn->info) != NULL)
1428 {
1429 range->cost = 0;
1430 range->specifics = 0;
1431 }
1432 }
1433
1434 if (IS_DEBUG_OSPF_EVENT)
1435 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
1436 }
1437
1438 static void
1439 ospf_abr_announce_aggregates (struct ospf *ospf)
1440 {
1441 struct ospf_area *area, *ar;
1442 struct ospf_area_range *range;
1443 struct route_node *rn;
1444 struct prefix p;
1445 struct listnode *node, *n;
1446
1447 if (IS_DEBUG_OSPF_EVENT)
1448 zlog_debug ("ospf_abr_announce_aggregates(): Start");
1449
1450 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1451 {
1452 if (IS_DEBUG_OSPF_EVENT)
1453 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
1454 inet_ntoa (area->area_id));
1455
1456 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1457 if ((range = rn->info))
1458 {
1459 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1460 {
1461 if (IS_DEBUG_OSPF_EVENT)
1462 zlog_debug ("ospf_abr_announce_aggregates():"
1463 " discarding suppress-ranges");
1464 continue;
1465 }
1466
1467 p.family = AF_INET;
1468 p.u.prefix4 = range->addr;
1469 p.prefixlen = range->masklen;
1470
1471 if (IS_DEBUG_OSPF_EVENT)
1472 zlog_debug ("ospf_abr_announce_aggregates():"
1473 " this is range: %s/%d",
1474 inet_ntoa (p.u.prefix4), p.prefixlen);
1475
1476 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1477 {
1478 p.family = AF_INET;
1479 p.u.prefix4 = range->subst_addr;
1480 p.prefixlen = range->subst_masklen;
1481 }
1482
1483 if (range->specifics)
1484 {
1485 if (IS_DEBUG_OSPF_EVENT)
1486 zlog_debug ("ospf_abr_announce_aggregates(): active range");
1487
1488 for (ALL_LIST_ELEMENTS_RO (ospf->areas, n, ar))
1489 {
1490 if (ar == area)
1491 continue;
1492
1493 /* We do not check nexthops here, because
1494 intra-area routes can be associated with
1495 one area only */
1496
1497 /* backbone routes are not summarized
1498 when announced into transit areas */
1499
1500 if (ospf_area_is_transit (ar) &&
1501 OSPF_IS_AREA_BACKBONE (area))
1502 {
1503 if (IS_DEBUG_OSPF_EVENT)
1504 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
1505 "announcement of BB aggregate into"
1506 " a transit area");
1507 continue;
1508 }
1509 ospf_abr_announce_network_to_area ((struct prefix_ipv4 *)&p, range->cost, ar);
1510 }
1511 }
1512 }
1513 }
1514
1515 if (IS_DEBUG_OSPF_EVENT)
1516 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
1517 }
1518
1519 static void
1520 ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */
1521 {
1522 struct listnode *node; /*, n; */
1523 struct ospf_area *area; /*, *ar; */
1524 struct route_node *rn;
1525 struct ospf_area_range *range;
1526 struct prefix_ipv4 p;
1527
1528 if (IS_DEBUG_OSPF_NSSA)
1529 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
1530
1531 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1532 {
1533 if (! area->NSSATranslatorState)
1534 continue;
1535
1536 if (IS_DEBUG_OSPF_NSSA)
1537 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
1538 inet_ntoa (area->area_id));
1539
1540 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1541 {
1542 if (rn->info == NULL)
1543 continue;
1544
1545 range = rn->info;
1546
1547 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1548 {
1549 if (IS_DEBUG_OSPF_NSSA)
1550 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1551 " discarding suppress-ranges");
1552 continue;
1553 }
1554
1555 p.family = AF_INET;
1556 p.prefix = range->addr;
1557 p.prefixlen = range->masklen;
1558
1559 if (IS_DEBUG_OSPF_NSSA)
1560 zlog_debug ("ospf_abr_send_nssa_aggregates():"
1561 " this is range: %s/%d",
1562 inet_ntoa (p.prefix), p.prefixlen);
1563
1564 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1565 {
1566 p.family = AF_INET;
1567 p.prefix = range->subst_addr;
1568 p.prefixlen = range->subst_masklen;
1569 }
1570
1571 if (range->specifics)
1572 {
1573 if (IS_DEBUG_OSPF_NSSA)
1574 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
1575
1576 /* Fetch LSA-Type-7 from aggregate prefix, and then
1577 * translate, Install (as Type-5), Approve, and Flood
1578 */
1579 ospf_abr_translate_nssa_range (&p, range->cost);
1580 }
1581 } /* all area ranges*/
1582 } /* all areas */
1583
1584 if (IS_DEBUG_OSPF_NSSA)
1585 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
1586 }
1587
1588 static void
1589 ospf_abr_announce_stub_defaults (struct ospf *ospf)
1590 {
1591 struct listnode *node;
1592 struct ospf_area *area;
1593 struct prefix_ipv4 p;
1594
1595 if (! IS_OSPF_ABR (ospf))
1596 return;
1597
1598 if (IS_DEBUG_OSPF_EVENT)
1599 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
1600
1601 p.family = AF_INET;
1602 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1603 p.prefixlen = 0;
1604
1605 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1606 {
1607 if (IS_DEBUG_OSPF_EVENT)
1608 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1609 inet_ntoa (area->area_id));
1610
1611 if ( (area->external_routing != OSPF_AREA_STUB)
1612 && (area->external_routing != OSPF_AREA_NSSA)
1613 )
1614 continue;
1615
1616 if (OSPF_IS_AREA_BACKBONE (area))
1617 continue; /* Sanity Check */
1618
1619 if (IS_DEBUG_OSPF_EVENT)
1620 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1621 "announcing 0.0.0.0/0 to area %s",
1622 inet_ntoa (area->area_id));
1623 ospf_abr_announce_network_to_area (&p, area->default_cost, area);
1624 }
1625
1626 if (IS_DEBUG_OSPF_EVENT)
1627 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
1628 }
1629
1630 static int
1631 ospf_abr_remove_unapproved_translates_apply (struct ospf *ospf,
1632 struct ospf_lsa *lsa)
1633 {
1634 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)
1635 && ! CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1636 {
1637 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1638 "removing unapproved translates, ID: %s",
1639 inet_ntoa (lsa->data->id));
1640
1641 /* FLUSH THROUGHOUT AS */
1642 ospf_lsa_flush_as (ospf, lsa);
1643
1644 /* DISCARD from LSDB */
1645 }
1646 return 0;
1647 }
1648
1649 static void
1650 ospf_abr_remove_unapproved_translates (struct ospf *ospf)
1651 {
1652 struct route_node *rn;
1653 struct ospf_lsa *lsa;
1654
1655 /* All AREA PROCESS should have APPROVED necessary LSAs */
1656 /* Remove any left over and not APPROVED */
1657 if (IS_DEBUG_OSPF_NSSA)
1658 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
1659
1660 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1661 ospf_abr_remove_unapproved_translates_apply (ospf, lsa);
1662
1663 if (IS_DEBUG_OSPF_NSSA)
1664 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
1665 }
1666
1667 static void
1668 ospf_abr_remove_unapproved_summaries (struct ospf *ospf)
1669 {
1670 struct listnode *node;
1671 struct ospf_area *area;
1672 struct route_node *rn;
1673 struct ospf_lsa *lsa;
1674
1675 if (IS_DEBUG_OSPF_EVENT)
1676 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
1677
1678 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1679 {
1680 if (IS_DEBUG_OSPF_EVENT)
1681 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
1682 "looking at area %s", inet_ntoa (area->area_id));
1683
1684 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
1685 if (ospf_lsa_is_self_originated (ospf, lsa))
1686 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1687 ospf_lsa_flush_area (lsa, area);
1688
1689 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
1690 if (ospf_lsa_is_self_originated (ospf, lsa))
1691 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1692 ospf_lsa_flush_area (lsa, area);
1693 }
1694
1695 if (IS_DEBUG_OSPF_EVENT)
1696 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
1697 }
1698
1699 static void
1700 ospf_abr_manage_discard_routes (struct ospf *ospf)
1701 {
1702 struct listnode *node, *nnode;
1703 struct route_node *rn;
1704 struct ospf_area *area;
1705 struct ospf_area_range *range;
1706
1707 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
1708 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1709 if ((range = rn->info) != NULL)
1710 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1711 {
1712 if (range->specifics)
1713 ospf_add_discard_route (ospf->new_table, area,
1714 (struct prefix_ipv4 *) &rn->p);
1715 else
1716 ospf_delete_discard_route (ospf->new_table,
1717 (struct prefix_ipv4 *) &rn->p);
1718 }
1719 }
1720
1721 /* This is the function taking care about ABR NSSA, i.e. NSSA
1722 Translator, -LSA aggregation and flooding. For all NSSAs
1723
1724 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1725 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1726 with the P-bit set.
1727
1728 Any received Type-5s are legal for an ABR, else illegal for IR.
1729 Received Type-7s are installed, by area, with incoming P-bit. They
1730 are flooded; if the Elected NSSA Translator, then P-bit off.
1731
1732 Additionally, this ABR will place "translated type-7's" into the
1733 Type-5 LSDB in order to keep track of APPROVAL or not.
1734
1735 It will scan through every area, looking for Type-7 LSAs with P-Bit
1736 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1737 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1738 5-INSTALLED.
1739
1740 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1741 left over are FLUSHED and DISCARDED.
1742
1743 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1744 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1745
1746 static void
1747 ospf_abr_nssa_task (struct ospf *ospf) /* called only if any_nssa */
1748 {
1749 if (IS_DEBUG_OSPF_NSSA)
1750 zlog_debug ("Check for NSSA-ABR Tasks():");
1751
1752 if (! IS_OSPF_ABR (ospf))
1753 return;
1754
1755 if (! ospf->anyNSSA)
1756 return;
1757
1758 /* Each area must confirm TranslatorRole */
1759 if (IS_DEBUG_OSPF_NSSA)
1760 zlog_debug ("ospf_abr_nssa_task(): Start");
1761
1762 /* For all Global Entries flagged "local-translate", unset APPROVED */
1763 if (IS_DEBUG_OSPF_NSSA)
1764 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
1765
1766 ospf_abr_unapprove_translates (ospf);
1767
1768 /* RESET all Ranges in every Area, same as summaries */
1769 if (IS_DEBUG_OSPF_NSSA)
1770 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
1771 ospf_abr_prepare_aggregates (ospf); /*TURNED OFF just for now */
1772
1773 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1774 * Aggregate as Type-7
1775 * Install or Approve in Type-5 Global LSDB
1776 */
1777 if (IS_DEBUG_OSPF_NSSA)
1778 zlog_debug ("ospf_abr_nssa_task(): process translates");
1779 ospf_abr_process_nssa_translates (ospf);
1780
1781 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1782 * Approve
1783 * Scan Type-7's for aggregates, translate to Type-5's,
1784 * Install/Flood/Approve
1785 */
1786 if (IS_DEBUG_OSPF_NSSA)
1787 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1788 ospf_abr_send_nssa_aggregates (ospf); /*TURNED OFF FOR NOW */
1789
1790 /* Send any NSSA defaults as Type-5
1791 *if (IS_DEBUG_OSPF_NSSA)
1792 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1793 *ospf_abr_announce_nssa_defaults (ospf);
1794 * havnt a clue what above is supposed to do.
1795 */
1796
1797 /* Flush any unapproved previous translates from Global Data Base */
1798 if (IS_DEBUG_OSPF_NSSA)
1799 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
1800 ospf_abr_remove_unapproved_translates (ospf);
1801
1802 ospf_abr_manage_discard_routes (ospf); /* same as normal...discard */
1803
1804 if (IS_DEBUG_OSPF_NSSA)
1805 zlog_debug ("ospf_abr_nssa_task(): Stop");
1806 }
1807
1808 /* This is the function taking care about ABR stuff, i.e.
1809 summary-LSA origination and flooding. */
1810 void
1811 ospf_abr_task (struct ospf *ospf)
1812 {
1813 if (IS_DEBUG_OSPF_EVENT)
1814 zlog_debug ("ospf_abr_task(): Start");
1815
1816 if (ospf->new_table == NULL || ospf->new_rtrs == NULL)
1817 {
1818 if (IS_DEBUG_OSPF_EVENT)
1819 zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
1820 return;
1821 }
1822
1823 if (IS_DEBUG_OSPF_EVENT)
1824 zlog_debug ("ospf_abr_task(): unapprove summaries");
1825 ospf_abr_unapprove_summaries (ospf);
1826
1827 if (IS_DEBUG_OSPF_EVENT)
1828 zlog_debug ("ospf_abr_task(): prepare aggregates");
1829 ospf_abr_prepare_aggregates (ospf);
1830
1831 if (IS_OSPF_ABR (ospf))
1832 {
1833 if (IS_DEBUG_OSPF_EVENT)
1834 zlog_debug ("ospf_abr_task(): process network RT");
1835 ospf_abr_process_network_rt (ospf, ospf->new_table);
1836
1837 if (IS_DEBUG_OSPF_EVENT)
1838 zlog_debug ("ospf_abr_task(): process router RT");
1839 ospf_abr_process_router_rt (ospf, ospf->new_rtrs);
1840
1841 if (IS_DEBUG_OSPF_EVENT)
1842 zlog_debug ("ospf_abr_task(): announce aggregates");
1843 ospf_abr_announce_aggregates (ospf);
1844
1845 if (IS_DEBUG_OSPF_EVENT)
1846 zlog_debug ("ospf_abr_task(): announce stub defaults");
1847 ospf_abr_announce_stub_defaults (ospf);
1848 }
1849
1850 if (IS_DEBUG_OSPF_EVENT)
1851 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
1852 ospf_abr_remove_unapproved_summaries (ospf);
1853
1854 ospf_abr_manage_discard_routes (ospf);
1855
1856 if (IS_DEBUG_OSPF_EVENT)
1857 zlog_debug ("ospf_abr_task(): Stop");
1858 }
1859
1860 static int
1861 ospf_abr_task_timer (struct thread *thread)
1862 {
1863 struct ospf *ospf = THREAD_ARG (thread);
1864
1865 ospf->t_abr_task = 0;
1866
1867 if (IS_DEBUG_OSPF_EVENT)
1868 zlog_debug ("Running ABR task on timer");
1869
1870 ospf_check_abr_status (ospf);
1871 ospf_abr_nssa_check_status (ospf);
1872
1873 ospf_abr_task (ospf);
1874 ospf_abr_nssa_task (ospf); /* if nssa-abr, then scan Type-7 LSDB */
1875
1876 return 0;
1877 }
1878
1879 void
1880 ospf_schedule_abr_task (struct ospf *ospf)
1881 {
1882 if (IS_DEBUG_OSPF_EVENT)
1883 zlog_debug ("Scheduling ABR task");
1884
1885 if (ospf->t_abr_task == NULL)
1886 ospf->t_abr_task = thread_add_timer (master, ospf_abr_task_timer,
1887 ospf, OSPF_ABR_TASK_DELAY);
1888 }