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