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