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