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