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