]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_abr.c
Merge pull request #5924 from donaldsharp/more_func
[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,
712 (struct prefix_ipv4 *)p,
713 area->ospf->router_id);
714 if (old) {
715 if (IS_DEBUG_OSPF_EVENT)
716 zlog_debug(
717 "ospf_abr_announce_network_to_area(): old summary found");
718
719 sl = (struct summary_lsa *)old->data;
720
721 if (IS_DEBUG_OSPF_EVENT)
722 zlog_debug(
723 "ospf_abr_announce_network_to_area(): "
724 "old metric: %d, new metric: %d",
725 GET_METRIC(sl->metric), cost);
726
727 if ((GET_METRIC(sl->metric) == full_cost)
728 && ((old->flags & OSPF_LSA_IN_MAXAGE) == 0)) {
729 /* unchanged. simply reapprove it */
730 if (IS_DEBUG_OSPF_EVENT)
731 zlog_debug(
732 "ospf_abr_announce_network_to_area(): "
733 "old summary approved");
734 SET_FLAG(old->flags, OSPF_LSA_APPROVED);
735 } else {
736 /* LSA is changed, refresh it */
737 if (IS_DEBUG_OSPF_EVENT)
738 zlog_debug(
739 "ospf_abr_announce_network_to_area(): "
740 "refreshing summary");
741 set_metric(old, full_cost);
742 lsa = ospf_lsa_refresh(area->ospf, old);
743
744 if (!lsa) {
745 char buf[PREFIX2STR_BUFFER];
746
747 prefix2str((struct prefix *)p, buf,
748 sizeof(buf));
749 flog_warn(EC_OSPF_LSA_MISSING,
750 "%s: Could not refresh %s to %s",
751 __func__, buf,
752 inet_ntoa(area->area_id));
753 return;
754 }
755
756 SET_FLAG(lsa->flags, OSPF_LSA_APPROVED);
757 /* This will flood through area. */
758 }
759 } else {
760 if (IS_DEBUG_OSPF_EVENT)
761 zlog_debug(
762 "ospf_abr_announce_network_to_area(): "
763 "creating new summary");
764 lsa = ospf_summary_lsa_originate((struct prefix_ipv4 *)p,
765 full_cost, area);
766 /* This will flood through area. */
767
768 if (!lsa) {
769 char buf[PREFIX2STR_BUFFER];
770
771 prefix2str((struct prefix *)p, buf, sizeof(buf));
772 flog_warn(EC_OSPF_LSA_MISSING,
773 "%s: Could not originate %s to %s", __func__,
774 buf, inet_ntoa(area->area_id));
775 return;
776 }
777
778 SET_FLAG(lsa->flags, OSPF_LSA_APPROVED);
779 if (IS_DEBUG_OSPF_EVENT)
780 zlog_debug(
781 "ospf_abr_announce_network_to_area(): "
782 "flooding new version of summary");
783 }
784
785 if (IS_DEBUG_OSPF_EVENT)
786 zlog_debug("ospf_abr_announce_network_to_area(): Stop");
787 }
788
789 static int ospf_abr_nexthops_belong_to_area(struct ospf_route * or,
790 struct ospf_area *area)
791 {
792 struct listnode *node, *nnode;
793 struct ospf_path *path;
794 struct ospf_interface *oi;
795
796 for (ALL_LIST_ELEMENTS_RO(or->paths, node, path))
797 for (ALL_LIST_ELEMENTS_RO(area->oiflist, nnode, oi))
798 if (oi->ifp && oi->ifp->ifindex == path->ifindex)
799 return 1;
800
801 return 0;
802 }
803
804 static int ospf_abr_should_accept(struct prefix_ipv4 *p, struct ospf_area *area)
805 {
806 if (IMPORT_NAME(area)) {
807 if (IMPORT_LIST(area) == NULL)
808 IMPORT_LIST(area) =
809 access_list_lookup(AFI_IP, IMPORT_NAME(area));
810
811 if (IMPORT_LIST(area))
812 if (access_list_apply(IMPORT_LIST(area), p)
813 == FILTER_DENY)
814 return 0;
815 }
816
817 return 1;
818 }
819
820 static int ospf_abr_plist_in_check(struct ospf_area *area,
821 struct ospf_route * or,
822 struct prefix_ipv4 *p)
823 {
824 if (PREFIX_NAME_IN(area)) {
825 if (PREFIX_LIST_IN(area) == NULL)
826 PREFIX_LIST_IN(area) = prefix_list_lookup(
827 AFI_IP, PREFIX_NAME_IN(area));
828 if (PREFIX_LIST_IN(area))
829 if (prefix_list_apply(PREFIX_LIST_IN(area), p)
830 != PREFIX_PERMIT)
831 return 0;
832 }
833 return 1;
834 }
835
836 static int ospf_abr_plist_out_check(struct ospf_area *area,
837 struct ospf_route * or,
838 struct prefix_ipv4 *p)
839 {
840 if (PREFIX_NAME_OUT(area)) {
841 if (PREFIX_LIST_OUT(area) == NULL)
842 PREFIX_LIST_OUT(area) = prefix_list_lookup(
843 AFI_IP, PREFIX_NAME_OUT(area));
844 if (PREFIX_LIST_OUT(area))
845 if (prefix_list_apply(PREFIX_LIST_OUT(area), p)
846 != PREFIX_PERMIT)
847 return 0;
848 }
849 return 1;
850 }
851
852 static void ospf_abr_announce_network(struct ospf *ospf, struct prefix_ipv4 *p,
853 struct ospf_route * or)
854 {
855 struct ospf_area_range *range;
856 struct ospf_area *area, *or_area;
857 struct listnode *node;
858
859 if (IS_DEBUG_OSPF_EVENT)
860 zlog_debug("ospf_abr_announce_network(): Start");
861
862 or_area = ospf_area_lookup_by_area_id(ospf, or->u.std.area_id);
863 assert(or_area);
864
865 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
866 if (IS_DEBUG_OSPF_EVENT)
867 zlog_debug(
868 "ospf_abr_announce_network(): looking at area %s",
869 inet_ntoa(area->area_id));
870
871 if (IPV4_ADDR_SAME(& or->u.std.area_id, &area->area_id))
872 continue;
873
874 if (ospf_abr_nexthops_belong_to_area(or, area))
875 continue;
876
877 if (!ospf_abr_should_accept(p, area)) {
878 if (IS_DEBUG_OSPF_EVENT)
879 zlog_debug(
880 "ospf_abr_announce_network(): "
881 "prefix %s/%d was denied by import-list",
882 inet_ntoa(p->prefix), p->prefixlen);
883 continue;
884 }
885
886 if (!ospf_abr_plist_in_check(area, or, p)) {
887 if (IS_DEBUG_OSPF_EVENT)
888 zlog_debug(
889 "ospf_abr_announce_network(): "
890 "prefix %s/%d was denied by prefix-list",
891 inet_ntoa(p->prefix), p->prefixlen);
892 continue;
893 }
894
895 if (area->external_routing != OSPF_AREA_DEFAULT
896 && area->no_summary) {
897 if (IS_DEBUG_OSPF_EVENT)
898 zlog_debug(
899 "ospf_abr_announce_network(): "
900 "area %s is stub and no_summary",
901 inet_ntoa(area->area_id));
902 continue;
903 }
904
905 if (or->path_type == OSPF_PATH_INTER_AREA) {
906 if (IS_DEBUG_OSPF_EVENT)
907 zlog_debug(
908 "ospf_abr_announce_network(): this is "
909 "inter-area route to %s/%d",
910 inet_ntoa(p->prefix), p->prefixlen);
911
912 if (!OSPF_IS_AREA_BACKBONE(area))
913 ospf_abr_announce_network_to_area(p, or->cost,
914 area);
915 }
916
917 if (or->path_type == OSPF_PATH_INTRA_AREA) {
918 if (IS_DEBUG_OSPF_EVENT)
919 zlog_debug(
920 "ospf_abr_announce_network(): "
921 "this is intra-area route to %s/%d",
922 inet_ntoa(p->prefix), p->prefixlen);
923 if ((range = ospf_area_range_match(or_area, p))
924 && !ospf_area_is_transit(area))
925 ospf_abr_update_aggregate(range, or, area);
926 else
927 ospf_abr_announce_network_to_area(p, or->cost,
928 area);
929 }
930 }
931 }
932
933 static int ospf_abr_should_announce(struct ospf *ospf, struct prefix_ipv4 *p,
934 struct ospf_route * or)
935 {
936 struct ospf_area *area;
937
938 area = ospf_area_lookup_by_area_id(ospf, or->u.std.area_id);
939
940 assert(area);
941
942 if (EXPORT_NAME(area)) {
943 if (EXPORT_LIST(area) == NULL)
944 EXPORT_LIST(area) =
945 access_list_lookup(AFI_IP, EXPORT_NAME(area));
946
947 if (EXPORT_LIST(area))
948 if (access_list_apply(EXPORT_LIST(area), p)
949 == FILTER_DENY)
950 return 0;
951 }
952
953 return 1;
954 }
955
956 static void ospf_abr_process_nssa_translates(struct ospf *ospf)
957 {
958 /* Scan through all NSSA_LSDB records for all areas;
959
960 If P-bit is on, translate all Type-7's to 5's and aggregate or
961 flood install as approved in Type-5 LSDB with XLATE Flag on
962 later, do same for all aggregates... At end, DISCARD all
963 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
964 struct listnode *node;
965 struct ospf_area *area;
966 struct route_node *rn;
967 struct ospf_lsa *lsa;
968
969 if (IS_DEBUG_OSPF_NSSA)
970 zlog_debug("ospf_abr_process_nssa_translates(): Start");
971
972 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
973 if (!area->NSSATranslatorState)
974 continue; /* skip if not translator */
975
976 if (area->external_routing != OSPF_AREA_NSSA)
977 continue; /* skip if not Nssa Area */
978
979 if (IS_DEBUG_OSPF_NSSA)
980 zlog_debug(
981 "ospf_abr_process_nssa_translates(): "
982 "looking at area %s",
983 inet_ntoa(area->area_id));
984
985 LSDB_LOOP (NSSA_LSDB(area), rn, lsa)
986 ospf_abr_translate_nssa(area, lsa);
987 }
988
989 if (IS_DEBUG_OSPF_NSSA)
990 zlog_debug("ospf_abr_process_nssa_translates(): Stop");
991 }
992
993 static void ospf_abr_process_network_rt(struct ospf *ospf,
994 struct route_table *rt)
995 {
996 struct ospf_area *area;
997 struct ospf_route * or ;
998 struct route_node *rn;
999
1000 if (IS_DEBUG_OSPF_EVENT)
1001 zlog_debug("ospf_abr_process_network_rt(): Start");
1002
1003 for (rn = route_top(rt); rn; rn = route_next(rn)) {
1004 if ((or = rn->info) == NULL)
1005 continue;
1006
1007 if (!(area = ospf_area_lookup_by_area_id(ospf,
1008 or->u.std.area_id))) {
1009 if (IS_DEBUG_OSPF_EVENT)
1010 zlog_debug(
1011 "ospf_abr_process_network_rt(): area %s no longer exists",
1012 inet_ntoa(or->u.std.area_id));
1013 continue;
1014 }
1015
1016 if (IS_DEBUG_OSPF_EVENT)
1017 zlog_debug(
1018 "ospf_abr_process_network_rt(): this is a route to %s/%d",
1019 inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen);
1020 if (or->path_type >= OSPF_PATH_TYPE1_EXTERNAL) {
1021 if (IS_DEBUG_OSPF_EVENT)
1022 zlog_debug(
1023 "ospf_abr_process_network_rt(): "
1024 "this is an External router, skipping");
1025 continue;
1026 }
1027
1028 if (or->cost >= OSPF_LS_INFINITY) {
1029 if (IS_DEBUG_OSPF_EVENT)
1030 zlog_debug(
1031 "ospf_abr_process_network_rt():"
1032 " this route's cost is infinity, skipping");
1033 continue;
1034 }
1035
1036 if (or->type == OSPF_DESTINATION_DISCARD) {
1037 if (IS_DEBUG_OSPF_EVENT)
1038 zlog_debug(
1039 "ospf_abr_process_network_rt():"
1040 " this is a discard entry, skipping");
1041 continue;
1042 }
1043
1044 if (
1045 or->path_type == OSPF_PATH_INTRA_AREA
1046 && !ospf_abr_should_announce(
1047 ospf, (struct prefix_ipv4 *)&rn->p,
1048 or)) {
1049 if (IS_DEBUG_OSPF_EVENT)
1050 zlog_debug(
1051 "ospf_abr_process_network_rt(): denied by export-list");
1052 continue;
1053 }
1054
1055 if (
1056 or->path_type == OSPF_PATH_INTRA_AREA
1057 && !ospf_abr_plist_out_check(
1058 area, or,
1059 (struct prefix_ipv4 *)&rn->p)) {
1060 if (IS_DEBUG_OSPF_EVENT)
1061 zlog_debug(
1062 "ospf_abr_process_network_rt(): denied by prefix-list");
1063 continue;
1064 }
1065
1066 if ((or->path_type == OSPF_PATH_INTER_AREA)
1067 && !OSPF_IS_AREA_ID_BACKBONE(or->u.std.area_id)) {
1068 if (IS_DEBUG_OSPF_EVENT)
1069 zlog_debug(
1070 "ospf_abr_process_network_rt():"
1071 " this is route is not backbone one, skipping");
1072 continue;
1073 }
1074
1075
1076 if ((ospf->abr_type == OSPF_ABR_CISCO)
1077 || (ospf->abr_type == OSPF_ABR_IBM))
1078
1079 if (!ospf_act_bb_connection(ospf) &&
1080 or->path_type != OSPF_PATH_INTRA_AREA) {
1081 if (IS_DEBUG_OSPF_EVENT)
1082 zlog_debug(
1083 "ospf_abr_process_network_rt(): ALT ABR: "
1084 "No BB connection, skip not intra-area routes");
1085 continue;
1086 }
1087
1088 if (IS_DEBUG_OSPF_EVENT)
1089 zlog_debug("ospf_abr_process_network_rt(): announcing");
1090 ospf_abr_announce_network(ospf, (struct prefix_ipv4 *)&rn->p,
1091 or);
1092 }
1093
1094 if (IS_DEBUG_OSPF_EVENT)
1095 zlog_debug("ospf_abr_process_network_rt(): Stop");
1096 }
1097
1098 static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4 *p, uint32_t cost,
1099 struct ospf_area *area)
1100 {
1101 struct ospf_lsa *lsa, *old = NULL;
1102 struct summary_lsa *slsa = NULL;
1103
1104 if (IS_DEBUG_OSPF_EVENT)
1105 zlog_debug("ospf_abr_announce_rtr_to_area(): Start");
1106
1107 old = ospf_lsa_lookup_by_prefix(area->lsdb, OSPF_ASBR_SUMMARY_LSA, p,
1108 area->ospf->router_id);
1109 if (old) {
1110 if (IS_DEBUG_OSPF_EVENT)
1111 zlog_debug(
1112 "ospf_abr_announce_rtr_to_area(): old summary found");
1113 slsa = (struct summary_lsa *)old->data;
1114
1115 if (IS_DEBUG_OSPF_EVENT)
1116 zlog_debug(
1117 "ospf_abr_announce_network_to_area(): "
1118 "old metric: %d, new metric: %d",
1119 GET_METRIC(slsa->metric), cost);
1120 }
1121
1122 if (old && (GET_METRIC(slsa->metric) == cost)
1123 && ((old->flags & OSPF_LSA_IN_MAXAGE) == 0)) {
1124 if (IS_DEBUG_OSPF_EVENT)
1125 zlog_debug(
1126 "ospf_abr_announce_rtr_to_area(): old summary approved");
1127 SET_FLAG(old->flags, OSPF_LSA_APPROVED);
1128 } else {
1129 if (IS_DEBUG_OSPF_EVENT)
1130 zlog_debug("ospf_abr_announce_rtr_to_area(): 2.2");
1131
1132 if (old) {
1133 set_metric(old, cost);
1134 lsa = ospf_lsa_refresh(area->ospf, old);
1135 } else
1136 lsa = ospf_summary_asbr_lsa_originate(p, cost, area);
1137 if (!lsa) {
1138 char buf[PREFIX2STR_BUFFER];
1139
1140 prefix2str((struct prefix *)p, buf, sizeof(buf));
1141 flog_warn(EC_OSPF_LSA_MISSING,
1142 "%s: Could not refresh/originate %s to %s",
1143 __func__, buf, inet_ntoa(area->area_id));
1144 return;
1145 }
1146
1147 if (IS_DEBUG_OSPF_EVENT)
1148 zlog_debug(
1149 "ospf_abr_announce_rtr_to_area(): "
1150 "flooding new version of summary");
1151
1152 /*
1153 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new
1154 summary");
1155 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1156
1157 SET_FLAG(lsa->flags, OSPF_LSA_APPROVED);
1158 /* ospf_flood_through_area (area, NULL, lsa);*/
1159 }
1160
1161 if (IS_DEBUG_OSPF_EVENT)
1162 zlog_debug("ospf_abr_announce_rtr_to_area(): Stop");
1163 }
1164
1165
1166 static void ospf_abr_announce_rtr(struct ospf *ospf, struct prefix_ipv4 *p,
1167 struct ospf_route * or)
1168 {
1169 struct listnode *node;
1170 struct ospf_area *area;
1171
1172 if (IS_DEBUG_OSPF_EVENT)
1173 zlog_debug("ospf_abr_announce_rtr(): Start");
1174
1175 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
1176 if (IS_DEBUG_OSPF_EVENT)
1177 zlog_debug(
1178 "ospf_abr_announce_rtr(): looking at area %s",
1179 inet_ntoa(area->area_id));
1180
1181 if (IPV4_ADDR_SAME(& or->u.std.area_id, &area->area_id))
1182 continue;
1183
1184 if (ospf_abr_nexthops_belong_to_area(or, area))
1185 continue;
1186
1187 if (area->external_routing != OSPF_AREA_DEFAULT) {
1188 if (IS_DEBUG_OSPF_EVENT)
1189 zlog_debug(
1190 "ospf_abr_announce_rtr(): "
1191 "area %s doesn't support external routing",
1192 inet_ntoa(area->area_id));
1193 continue;
1194 }
1195
1196 if (or->path_type == OSPF_PATH_INTER_AREA) {
1197 if (IS_DEBUG_OSPF_EVENT)
1198 zlog_debug(
1199 "ospf_abr_announce_rtr(): "
1200 "this is inter-area route to %s",
1201 inet_ntoa(p->prefix));
1202 if (!OSPF_IS_AREA_BACKBONE(area))
1203 ospf_abr_announce_rtr_to_area(p, or->cost,
1204 area);
1205 }
1206
1207 if (or->path_type == OSPF_PATH_INTRA_AREA) {
1208 if (IS_DEBUG_OSPF_EVENT)
1209 zlog_debug(
1210 "ospf_abr_announce_rtr(): "
1211 "this is intra-area route to %s",
1212 inet_ntoa(p->prefix));
1213 ospf_abr_announce_rtr_to_area(p, or->cost, area);
1214 }
1215 }
1216
1217 if (IS_DEBUG_OSPF_EVENT)
1218 zlog_debug("ospf_abr_announce_rtr(): Stop");
1219 }
1220
1221 static void ospf_abr_process_router_rt(struct ospf *ospf,
1222 struct route_table *rt)
1223 {
1224 struct ospf_route * or ;
1225 struct route_node *rn;
1226 struct list *l;
1227
1228 if (IS_DEBUG_OSPF_EVENT)
1229 zlog_debug("ospf_abr_process_router_rt(): Start");
1230
1231 for (rn = route_top(rt); rn; rn = route_next(rn)) {
1232 struct listnode *node, *nnode;
1233 char flag = 0;
1234 struct ospf_route *best = NULL;
1235
1236 if (rn->info == NULL)
1237 continue;
1238
1239 l = rn->info;
1240
1241 if (IS_DEBUG_OSPF_EVENT)
1242 zlog_debug(
1243 "ospf_abr_process_router_rt(): this is a route to %s",
1244 inet_ntoa(rn->p.u.prefix4));
1245
1246 for (ALL_LIST_ELEMENTS(l, node, nnode, or)) {
1247 if (!ospf_area_lookup_by_area_id(ospf,
1248 or->u.std.area_id)) {
1249 if (IS_DEBUG_OSPF_EVENT)
1250 zlog_debug(
1251 "ospf_abr_process_router_rt(): area %s no longer exists",
1252 inet_ntoa(or->u.std.area_id));
1253 continue;
1254 }
1255
1256
1257 if (!CHECK_FLAG(or->u.std.flags, ROUTER_LSA_EXTERNAL)) {
1258 if (IS_DEBUG_OSPF_EVENT)
1259 zlog_debug(
1260 "ospf_abr_process_router_rt(): "
1261 "This is not an ASBR, skipping");
1262 continue;
1263 }
1264
1265 if (!flag) {
1266 best = ospf_find_asbr_route(
1267 ospf, rt, (struct prefix_ipv4 *)&rn->p);
1268 flag = 1;
1269 }
1270
1271 if (best == NULL)
1272 continue;
1273
1274 if (or != best) {
1275 if (IS_DEBUG_OSPF_EVENT)
1276 zlog_debug(
1277 "ospf_abr_process_router_rt(): "
1278 "This route is not the best among possible, skipping");
1279 continue;
1280 }
1281
1282 if (
1283 or->path_type == OSPF_PATH_INTER_AREA
1284 && !OSPF_IS_AREA_ID_BACKBONE(
1285 or->u.std.area_id)) {
1286 if (IS_DEBUG_OSPF_EVENT)
1287 zlog_debug(
1288 "ospf_abr_process_router_rt(): "
1289 "This route is not a backbone one, skipping");
1290 continue;
1291 }
1292
1293 if (or->cost >= OSPF_LS_INFINITY) {
1294 if (IS_DEBUG_OSPF_EVENT)
1295 zlog_debug(
1296 "ospf_abr_process_router_rt(): "
1297 "This route has LS_INFINITY metric, skipping");
1298 continue;
1299 }
1300
1301 if (ospf->abr_type == OSPF_ABR_CISCO
1302 || ospf->abr_type == OSPF_ABR_IBM)
1303 if (!ospf_act_bb_connection(ospf) &&
1304 or->path_type != OSPF_PATH_INTRA_AREA) {
1305 if (IS_DEBUG_OSPF_EVENT)
1306 zlog_debug(
1307 "ospf_abr_process_network_rt(): ALT ABR: "
1308 "No BB connection, skip not intra-area routes");
1309 continue;
1310 }
1311
1312 ospf_abr_announce_rtr(ospf,
1313 (struct prefix_ipv4 *)&rn->p, or);
1314 }
1315 }
1316
1317 if (IS_DEBUG_OSPF_EVENT)
1318 zlog_debug("ospf_abr_process_router_rt(): Stop");
1319 }
1320
1321 static void
1322 ospf_abr_unapprove_translates(struct ospf *ospf) /* For NSSA Translations */
1323 {
1324 struct ospf_lsa *lsa;
1325 struct route_node *rn;
1326
1327 if (IS_DEBUG_OSPF_NSSA)
1328 zlog_debug("ospf_abr_unapprove_translates(): Start");
1329
1330 /* NSSA Translator is not checked, because it may have gone away,
1331 and we would want to flush any residuals anyway */
1332
1333 LSDB_LOOP (EXTERNAL_LSDB(ospf), rn, lsa)
1334 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) {
1335 UNSET_FLAG(lsa->flags, OSPF_LSA_APPROVED);
1336 if (IS_DEBUG_OSPF_NSSA)
1337 zlog_debug(
1338 "ospf_abr_unapprove_translates(): "
1339 "approved unset on link id %s",
1340 inet_ntoa(lsa->data->id));
1341 }
1342
1343 if (IS_DEBUG_OSPF_NSSA)
1344 zlog_debug("ospf_abr_unapprove_translates(): Stop");
1345 }
1346
1347 static void ospf_abr_unapprove_summaries(struct ospf *ospf)
1348 {
1349 struct listnode *node;
1350 struct ospf_area *area;
1351 struct route_node *rn;
1352 struct ospf_lsa *lsa;
1353
1354 if (IS_DEBUG_OSPF_EVENT)
1355 zlog_debug("ospf_abr_unapprove_summaries(): Start");
1356
1357 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
1358 if (IS_DEBUG_OSPF_EVENT)
1359 zlog_debug(
1360 "ospf_abr_unapprove_summaries(): "
1361 "considering area %s",
1362 inet_ntoa(area->area_id));
1363 LSDB_LOOP (SUMMARY_LSDB(area), rn, lsa)
1364 if (ospf_lsa_is_self_originated(ospf, lsa)) {
1365 if (IS_DEBUG_OSPF_EVENT)
1366 zlog_debug(
1367 "ospf_abr_unapprove_summaries(): "
1368 "approved unset on summary link id %s",
1369 inet_ntoa(lsa->data->id));
1370 UNSET_FLAG(lsa->flags, OSPF_LSA_APPROVED);
1371 }
1372
1373 LSDB_LOOP (ASBR_SUMMARY_LSDB(area), rn, lsa)
1374 if (ospf_lsa_is_self_originated(ospf, lsa)) {
1375 if (IS_DEBUG_OSPF_EVENT)
1376 zlog_debug(
1377 "ospf_abr_unapprove_summaries(): "
1378 "approved unset on asbr-summary link id %s",
1379 inet_ntoa(lsa->data->id));
1380 UNSET_FLAG(lsa->flags, OSPF_LSA_APPROVED);
1381 }
1382 }
1383
1384 if (IS_DEBUG_OSPF_EVENT)
1385 zlog_debug("ospf_abr_unapprove_summaries(): Stop");
1386 }
1387
1388 static void ospf_abr_prepare_aggregates(struct ospf *ospf)
1389 {
1390 struct listnode *node;
1391 struct route_node *rn;
1392 struct ospf_area_range *range;
1393 struct ospf_area *area;
1394
1395 if (IS_DEBUG_OSPF_EVENT)
1396 zlog_debug("ospf_abr_prepare_aggregates(): Start");
1397
1398 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
1399 for (rn = route_top(area->ranges); rn; rn = route_next(rn))
1400 if ((range = rn->info) != NULL) {
1401 range->cost = 0;
1402 range->specifics = 0;
1403 }
1404 }
1405
1406 if (IS_DEBUG_OSPF_EVENT)
1407 zlog_debug("ospf_abr_prepare_aggregates(): Stop");
1408 }
1409
1410 static void ospf_abr_announce_aggregates(struct ospf *ospf)
1411 {
1412 struct ospf_area *area, *ar;
1413 struct ospf_area_range *range;
1414 struct route_node *rn;
1415 struct prefix p;
1416 struct listnode *node, *n;
1417
1418 if (IS_DEBUG_OSPF_EVENT)
1419 zlog_debug("ospf_abr_announce_aggregates(): Start");
1420
1421 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
1422 if (IS_DEBUG_OSPF_EVENT)
1423 zlog_debug(
1424 "ospf_abr_announce_aggregates(): looking at area %s",
1425 inet_ntoa(area->area_id));
1426
1427 for (rn = route_top(area->ranges); rn; rn = route_next(rn))
1428 if ((range = rn->info)) {
1429 if (!CHECK_FLAG(range->flags,
1430 OSPF_AREA_RANGE_ADVERTISE)) {
1431 if (IS_DEBUG_OSPF_EVENT)
1432 zlog_debug(
1433 "ospf_abr_announce_aggregates():"
1434 " discarding suppress-ranges");
1435 continue;
1436 }
1437
1438 p.family = AF_INET;
1439 p.u.prefix4 = range->addr;
1440 p.prefixlen = range->masklen;
1441
1442 if (IS_DEBUG_OSPF_EVENT)
1443 zlog_debug(
1444 "ospf_abr_announce_aggregates():"
1445 " this is range: %s/%d",
1446 inet_ntoa(p.u.prefix4),
1447 p.prefixlen);
1448
1449 if (CHECK_FLAG(range->flags,
1450 OSPF_AREA_RANGE_SUBSTITUTE)) {
1451 p.family = AF_INET;
1452 p.u.prefix4 = range->subst_addr;
1453 p.prefixlen = range->subst_masklen;
1454 }
1455
1456 if (range->specifics) {
1457 if (IS_DEBUG_OSPF_EVENT)
1458 zlog_debug(
1459 "ospf_abr_announce_aggregates(): active range");
1460
1461 for (ALL_LIST_ELEMENTS_RO(ospf->areas,
1462 n, ar)) {
1463 if (ar == area)
1464 continue;
1465
1466 /* We do not check nexthops
1467 here, because
1468 intra-area routes can be
1469 associated with
1470 one area only */
1471
1472 /* backbone routes are not
1473 summarized
1474 when announced into transit
1475 areas */
1476
1477 if (ospf_area_is_transit(ar)
1478 && OSPF_IS_AREA_BACKBONE(
1479 area)) {
1480 if (IS_DEBUG_OSPF_EVENT)
1481 zlog_debug(
1482 "ospf_abr_announce_aggregates(): Skipping "
1483 "announcement of BB aggregate into"
1484 " a transit area");
1485 continue;
1486 }
1487 ospf_abr_announce_network_to_area(
1488 (struct prefix_ipv4
1489 *)&p,
1490 range->cost, ar);
1491 }
1492 }
1493 }
1494 }
1495
1496 if (IS_DEBUG_OSPF_EVENT)
1497 zlog_debug("ospf_abr_announce_aggregates(): Stop");
1498 }
1499
1500 static void
1501 ospf_abr_send_nssa_aggregates(struct ospf *ospf) /* temporarily turned off */
1502 {
1503 struct listnode *node; /*, n; */
1504 struct ospf_area *area; /*, *ar; */
1505 struct route_node *rn;
1506 struct ospf_area_range *range;
1507 struct prefix_ipv4 p;
1508
1509 if (IS_DEBUG_OSPF_NSSA)
1510 zlog_debug("ospf_abr_send_nssa_aggregates(): Start");
1511
1512 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
1513 if (!area->NSSATranslatorState)
1514 continue;
1515
1516 if (IS_DEBUG_OSPF_NSSA)
1517 zlog_debug(
1518 "ospf_abr_send_nssa_aggregates(): looking at area %s",
1519 inet_ntoa(area->area_id));
1520
1521 for (rn = route_top(area->ranges); rn; rn = route_next(rn)) {
1522 if (rn->info == NULL)
1523 continue;
1524
1525 range = rn->info;
1526
1527 if (!CHECK_FLAG(range->flags,
1528 OSPF_AREA_RANGE_ADVERTISE)) {
1529 if (IS_DEBUG_OSPF_NSSA)
1530 zlog_debug(
1531 "ospf_abr_send_nssa_aggregates():"
1532 " discarding suppress-ranges");
1533 continue;
1534 }
1535
1536 p.family = AF_INET;
1537 p.prefix = range->addr;
1538 p.prefixlen = range->masklen;
1539
1540 if (IS_DEBUG_OSPF_NSSA)
1541 zlog_debug(
1542 "ospf_abr_send_nssa_aggregates():"
1543 " this is range: %s/%d",
1544 inet_ntoa(p.prefix), p.prefixlen);
1545
1546 if (CHECK_FLAG(range->flags,
1547 OSPF_AREA_RANGE_SUBSTITUTE)) {
1548 p.family = AF_INET;
1549 p.prefix = range->subst_addr;
1550 p.prefixlen = range->subst_masklen;
1551 }
1552
1553 if (range->specifics) {
1554 if (IS_DEBUG_OSPF_NSSA)
1555 zlog_debug(
1556 "ospf_abr_send_nssa_aggregates(): active range");
1557
1558 /* Fetch LSA-Type-7 from aggregate prefix, and
1559 * then
1560 * translate, Install (as Type-5), Approve, and
1561 * Flood
1562 */
1563 ospf_abr_translate_nssa_range(&p, range->cost);
1564 }
1565 } /* all area ranges*/
1566 } /* all areas */
1567
1568 if (IS_DEBUG_OSPF_NSSA)
1569 zlog_debug("ospf_abr_send_nssa_aggregates(): Stop");
1570 }
1571
1572 static void ospf_abr_announce_stub_defaults(struct ospf *ospf)
1573 {
1574 struct listnode *node;
1575 struct ospf_area *area;
1576 struct prefix_ipv4 p;
1577
1578 if (!IS_OSPF_ABR(ospf))
1579 return;
1580
1581 if (IS_DEBUG_OSPF_EVENT)
1582 zlog_debug("ospf_abr_announce_stub_defaults(): Start");
1583
1584 p.family = AF_INET;
1585 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1586 p.prefixlen = 0;
1587
1588 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
1589 if (IS_DEBUG_OSPF_EVENT)
1590 zlog_debug(
1591 "ospf_abr_announce_stub_defaults(): looking at area %s",
1592 inet_ntoa(area->area_id));
1593
1594 if ((area->external_routing != OSPF_AREA_STUB)
1595 && (area->external_routing != OSPF_AREA_NSSA))
1596 continue;
1597
1598 if (OSPF_IS_AREA_BACKBONE(area))
1599 continue; /* Sanity Check */
1600
1601 if (IS_DEBUG_OSPF_EVENT)
1602 zlog_debug(
1603 "ospf_abr_announce_stub_defaults(): "
1604 "announcing 0.0.0.0/0 to area %s",
1605 inet_ntoa(area->area_id));
1606 ospf_abr_announce_network_to_area(&p, area->default_cost, area);
1607 }
1608
1609 if (IS_DEBUG_OSPF_EVENT)
1610 zlog_debug("ospf_abr_announce_stub_defaults(): Stop");
1611 }
1612
1613 static int ospf_abr_remove_unapproved_translates_apply(struct ospf *ospf,
1614 struct ospf_lsa *lsa)
1615 {
1616 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)
1617 && !CHECK_FLAG(lsa->flags, OSPF_LSA_APPROVED)) {
1618 zlog_info(
1619 "ospf_abr_remove_unapproved_translates(): "
1620 "removing unapproved translates, ID: %s",
1621 inet_ntoa(lsa->data->id));
1622
1623 /* FLUSH THROUGHOUT AS */
1624 ospf_lsa_flush_as(ospf, lsa);
1625
1626 /* DISCARD from LSDB */
1627 }
1628 return 0;
1629 }
1630
1631 static void ospf_abr_remove_unapproved_translates(struct ospf *ospf)
1632 {
1633 struct route_node *rn;
1634 struct ospf_lsa *lsa;
1635
1636 /* All AREA PROCESS should have APPROVED necessary LSAs */
1637 /* Remove any left over and not APPROVED */
1638 if (IS_DEBUG_OSPF_NSSA)
1639 zlog_debug("ospf_abr_remove_unapproved_translates(): Start");
1640
1641 LSDB_LOOP (EXTERNAL_LSDB(ospf), rn, lsa)
1642 ospf_abr_remove_unapproved_translates_apply(ospf, lsa);
1643
1644 if (IS_DEBUG_OSPF_NSSA)
1645 zlog_debug("ospf_abr_remove_unapproved_translates(): Stop");
1646 }
1647
1648 static void ospf_abr_remove_unapproved_summaries(struct ospf *ospf)
1649 {
1650 struct listnode *node;
1651 struct ospf_area *area;
1652 struct route_node *rn;
1653 struct ospf_lsa *lsa;
1654
1655 if (IS_DEBUG_OSPF_EVENT)
1656 zlog_debug("ospf_abr_remove_unapproved_summaries(): Start");
1657
1658 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
1659 if (IS_DEBUG_OSPF_EVENT)
1660 zlog_debug(
1661 "ospf_abr_remove_unapproved_summaries(): "
1662 "looking at area %s",
1663 inet_ntoa(area->area_id));
1664
1665 LSDB_LOOP (SUMMARY_LSDB(area), rn, lsa)
1666 if (ospf_lsa_is_self_originated(ospf, lsa))
1667 if (!CHECK_FLAG(lsa->flags, OSPF_LSA_APPROVED))
1668 ospf_lsa_flush_area(lsa, area);
1669
1670 LSDB_LOOP (ASBR_SUMMARY_LSDB(area), rn, lsa)
1671 if (ospf_lsa_is_self_originated(ospf, lsa))
1672 if (!CHECK_FLAG(lsa->flags, OSPF_LSA_APPROVED))
1673 ospf_lsa_flush_area(lsa, area);
1674 }
1675
1676 if (IS_DEBUG_OSPF_EVENT)
1677 zlog_debug("ospf_abr_remove_unapproved_summaries(): Stop");
1678 }
1679
1680 static void ospf_abr_manage_discard_routes(struct ospf *ospf)
1681 {
1682 struct listnode *node, *nnode;
1683 struct route_node *rn;
1684 struct ospf_area *area;
1685 struct ospf_area_range *range;
1686
1687 for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area))
1688 for (rn = route_top(area->ranges); rn; rn = route_next(rn))
1689 if ((range = rn->info) != NULL)
1690 if (CHECK_FLAG(range->flags,
1691 OSPF_AREA_RANGE_ADVERTISE)) {
1692 if (range->specifics)
1693 ospf_add_discard_route(
1694 ospf, ospf->new_table,
1695 area,
1696 (struct prefix_ipv4
1697 *)&rn->p);
1698 else
1699 ospf_delete_discard_route(
1700 ospf, ospf->new_table,
1701 (struct prefix_ipv4
1702 *)&rn->p);
1703 }
1704 }
1705
1706 /* This is the function taking care about ABR NSSA, i.e. NSSA
1707 Translator, -LSA aggregation and flooding. For all NSSAs
1708
1709 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1710 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1711 with the P-bit set.
1712
1713 Any received Type-5s are legal for an ABR, else illegal for IR.
1714 Received Type-7s are installed, by area, with incoming P-bit. They
1715 are flooded; if the Elected NSSA Translator, then P-bit off.
1716
1717 Additionally, this ABR will place "translated type-7's" into the
1718 Type-5 LSDB in order to keep track of APPROVAL or not.
1719
1720 It will scan through every area, looking for Type-7 LSAs with P-Bit
1721 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1722 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1723 5-INSTALLED.
1724
1725 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1726 left over are FLUSHED and DISCARDED.
1727
1728 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1729 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1730
1731 static void ospf_abr_nssa_task(struct ospf *ospf) /* called only if any_nssa */
1732 {
1733 if (IS_DEBUG_OSPF_NSSA)
1734 zlog_debug("Check for NSSA-ABR Tasks():");
1735
1736 if (!IS_OSPF_ABR(ospf))
1737 return;
1738
1739 if (!ospf->anyNSSA)
1740 return;
1741
1742 /* Each area must confirm TranslatorRole */
1743 if (IS_DEBUG_OSPF_NSSA)
1744 zlog_debug("ospf_abr_nssa_task(): Start");
1745
1746 /* For all Global Entries flagged "local-translate", unset APPROVED */
1747 if (IS_DEBUG_OSPF_NSSA)
1748 zlog_debug("ospf_abr_nssa_task(): unapprove translates");
1749
1750 ospf_abr_unapprove_translates(ospf);
1751
1752 /* RESET all Ranges in every Area, same as summaries */
1753 if (IS_DEBUG_OSPF_NSSA)
1754 zlog_debug("ospf_abr_nssa_task(): NSSA initialize aggregates");
1755 ospf_abr_prepare_aggregates(ospf); /*TURNED OFF just for now */
1756
1757 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
1758 * Aggregate as Type-7
1759 * Install or Approve in Type-5 Global LSDB
1760 */
1761 if (IS_DEBUG_OSPF_NSSA)
1762 zlog_debug("ospf_abr_nssa_task(): process translates");
1763 ospf_abr_process_nssa_translates(ospf);
1764
1765 /* Translate/Send any "ranged" aggregates, and also 5-Install and
1766 * Approve
1767 * Scan Type-7's for aggregates, translate to Type-5's,
1768 * Install/Flood/Approve
1769 */
1770 if (IS_DEBUG_OSPF_NSSA)
1771 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
1772 ospf_abr_send_nssa_aggregates(ospf); /*TURNED OFF FOR NOW */
1773
1774 /* Send any NSSA defaults as Type-5
1775 *if (IS_DEBUG_OSPF_NSSA)
1776 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
1777 *ospf_abr_announce_nssa_defaults (ospf);
1778 * havnt a clue what above is supposed to do.
1779 */
1780
1781 /* Flush any unapproved previous translates from Global Data Base */
1782 if (IS_DEBUG_OSPF_NSSA)
1783 zlog_debug(
1784 "ospf_abr_nssa_task(): remove unapproved translates");
1785 ospf_abr_remove_unapproved_translates(ospf);
1786
1787 ospf_abr_manage_discard_routes(ospf); /* same as normal...discard */
1788
1789 if (IS_DEBUG_OSPF_NSSA)
1790 zlog_debug("ospf_abr_nssa_task(): Stop");
1791 }
1792
1793 /* This is the function taking care about ABR stuff, i.e.
1794 summary-LSA origination and flooding. */
1795 void ospf_abr_task(struct ospf *ospf)
1796 {
1797 if (IS_DEBUG_OSPF_EVENT)
1798 zlog_debug("ospf_abr_task(): Start");
1799
1800 if (ospf->new_table == NULL || ospf->new_rtrs == NULL) {
1801 if (IS_DEBUG_OSPF_EVENT)
1802 zlog_debug(
1803 "ospf_abr_task(): Routing tables are not yet ready");
1804 return;
1805 }
1806
1807 if (IS_DEBUG_OSPF_EVENT)
1808 zlog_debug("ospf_abr_task(): unapprove summaries");
1809 ospf_abr_unapprove_summaries(ospf);
1810
1811 if (IS_DEBUG_OSPF_EVENT)
1812 zlog_debug("ospf_abr_task(): prepare aggregates");
1813 ospf_abr_prepare_aggregates(ospf);
1814
1815 if (IS_OSPF_ABR(ospf)) {
1816 if (IS_DEBUG_OSPF_EVENT)
1817 zlog_debug("ospf_abr_task(): process network RT");
1818 ospf_abr_process_network_rt(ospf, ospf->new_table);
1819
1820 if (IS_DEBUG_OSPF_EVENT)
1821 zlog_debug("ospf_abr_task(): process router RT");
1822 ospf_abr_process_router_rt(ospf, ospf->new_rtrs);
1823
1824 if (IS_DEBUG_OSPF_EVENT)
1825 zlog_debug("ospf_abr_task(): announce aggregates");
1826 ospf_abr_announce_aggregates(ospf);
1827
1828 if (IS_DEBUG_OSPF_EVENT)
1829 zlog_debug("ospf_abr_task(): announce stub defaults");
1830 ospf_abr_announce_stub_defaults(ospf);
1831 }
1832
1833 if (IS_DEBUG_OSPF_EVENT)
1834 zlog_debug("ospf_abr_task(): remove unapproved summaries");
1835 ospf_abr_remove_unapproved_summaries(ospf);
1836
1837 ospf_abr_manage_discard_routes(ospf);
1838
1839 if (IS_DEBUG_OSPF_EVENT)
1840 zlog_debug("ospf_abr_task(): Stop");
1841 }
1842
1843 static int ospf_abr_task_timer(struct thread *thread)
1844 {
1845 struct ospf *ospf = THREAD_ARG(thread);
1846
1847 ospf->t_abr_task = 0;
1848
1849 if (IS_DEBUG_OSPF_EVENT)
1850 zlog_debug("Running ABR task on timer");
1851
1852 ospf_check_abr_status(ospf);
1853 ospf_abr_nssa_check_status(ospf);
1854
1855 ospf_abr_task(ospf);
1856 ospf_abr_nssa_task(ospf); /* if nssa-abr, then scan Type-7 LSDB */
1857
1858 return 0;
1859 }
1860
1861 void ospf_schedule_abr_task(struct ospf *ospf)
1862 {
1863 if (IS_DEBUG_OSPF_EVENT)
1864 zlog_debug("Scheduling ABR task");
1865
1866 thread_add_timer(master, ospf_abr_task_timer, ospf, OSPF_ABR_TASK_DELAY,
1867 &ospf->t_abr_task);
1868 }