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