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