blob: 5c308092da26597f09193aad1b9e22589535addc [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23
24#include <zebra.h>
25
26#include "thread.h"
27#include "memory.h"
28#include "linklist.h"
29#include "prefix.h"
30#include "if.h"
31#include "table.h"
32#include "vty.h"
33#include "filter.h"
34#include "plist.h"
35#include "log.h"
36
37#include "ospfd/ospfd.h"
38#include "ospfd/ospf_interface.h"
39#include "ospfd/ospf_ism.h"
40#include "ospfd/ospf_asbr.h"
41#include "ospfd/ospf_lsa.h"
42#include "ospfd/ospf_lsdb.h"
43#include "ospfd/ospf_neighbor.h"
44#include "ospfd/ospf_nsm.h"
45#include "ospfd/ospf_spf.h"
46#include "ospfd/ospf_route.h"
47#include "ospfd/ospf_ia.h"
48#include "ospfd/ospf_flood.h"
49#include "ospfd/ospf_abr.h"
50#include "ospfd/ospf_ase.h"
51#include "ospfd/ospf_zebra.h"
52#include "ospfd/ospf_dump.h"
David Lamparter6b0655a2014-06-04 06:53:35 +020053
paul4dadc292005-05-06 21:37:42 +000054static struct ospf_area_range *
paul718e3742002-12-13 20:15:29 +000055ospf_area_range_new (struct prefix_ipv4 *p)
56{
57 struct ospf_area_range *range;
58
59 range = XCALLOC (MTYPE_OSPF_AREA_RANGE, sizeof (struct ospf_area_range));
60 range->addr = p->prefix;
61 range->masklen = p->prefixlen;
62 range->cost_config = OSPF_AREA_RANGE_COST_UNSPEC;
63
64 return range;
65}
66
paul4dadc292005-05-06 21:37:42 +000067static void
paul718e3742002-12-13 20:15:29 +000068ospf_area_range_free (struct ospf_area_range *range)
69{
70 XFREE (MTYPE_OSPF_AREA_RANGE, range);
71}
72
paul4dadc292005-05-06 21:37:42 +000073static void
paul718e3742002-12-13 20:15:29 +000074ospf_area_range_add (struct ospf_area *area, struct ospf_area_range *range)
75{
76 struct route_node *rn;
77 struct prefix_ipv4 p;
78
79 p.family = AF_INET;
80 p.prefixlen = range->masklen;
81 p.prefix = range->addr;
82
83 rn = route_node_get (area->ranges, (struct prefix *)&p);
84 if (rn->info)
85 route_unlock_node (rn);
86 else
87 rn->info = range;
88}
89
paul4dadc292005-05-06 21:37:42 +000090static void
JR Rivers8fc9e002012-09-24 17:26:46 +000091ospf_area_range_delete (struct ospf_area *area, struct route_node *rn)
paul718e3742002-12-13 20:15:29 +000092{
JR Rivers8fc9e002012-09-24 17:26:46 +000093 struct ospf_area_range *range = rn->info;
paul718e3742002-12-13 20:15:29 +000094
JR Rivers8fc9e002012-09-24 17:26:46 +000095 if (range->specifics != 0)
96 ospf_delete_discard_route (area->ospf->new_table,
97 (struct prefix_ipv4 *) &rn->p);
paul718e3742002-12-13 20:15:29 +000098
JR Rivers8fc9e002012-09-24 17:26:46 +000099 ospf_area_range_free (range);
100 rn->info = NULL;
101 route_unlock_node (rn);
102 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000103}
104
105struct ospf_area_range *
106ospf_area_range_lookup (struct ospf_area *area, struct prefix_ipv4 *p)
107{
108 struct route_node *rn;
109
110 rn = route_node_lookup (area->ranges, (struct prefix *)p);
111 if (rn)
112 {
113 route_unlock_node (rn);
114 return rn->info;
115 }
116 return NULL;
117}
118
119struct ospf_area_range *
pauld4a53d52003-07-12 21:30:57 +0000120ospf_area_range_lookup_next (struct ospf_area *area,
121 struct in_addr *range_net,
122 int first)
paul718e3742002-12-13 20:15:29 +0000123{
124 struct route_node *rn;
125 struct prefix_ipv4 p;
126 struct ospf_area_range *find;
127
128 p.family = AF_INET;
129 p.prefixlen = IPV4_MAX_BITLEN;
130 p.prefix = *range_net;
131
132 if (first)
133 rn = route_top (area->ranges);
134 else
135 {
Joakim Tjernlundc9b07582010-03-08 13:58:11 +0100136 rn = route_node_lookup (area->ranges, (struct prefix *) &p);
137 if (!rn)
138 return NULL;
paul718e3742002-12-13 20:15:29 +0000139 rn = route_next (rn);
140 }
141
142 for (; rn; rn = route_next (rn))
143 if (rn->info)
144 break;
145
146 if (rn && rn->info)
147 {
148 find = rn->info;
149 *range_net = rn->p.u.prefix4;
150 route_unlock_node (rn);
151 return find;
152 }
153 return NULL;
154}
155
paul4dadc292005-05-06 21:37:42 +0000156static struct ospf_area_range *
paul718e3742002-12-13 20:15:29 +0000157ospf_area_range_match (struct ospf_area *area, struct prefix_ipv4 *p)
158{
159 struct route_node *node;
160
161 node = route_node_match (area->ranges, (struct prefix *) p);
162 if (node)
163 {
164 route_unlock_node (node);
165 return node->info;
166 }
167 return NULL;
168}
169
170struct ospf_area_range *
171ospf_area_range_match_any (struct ospf *ospf, struct prefix_ipv4 *p)
172{
173 struct ospf_area_range *range;
paul1eb8ef22005-04-07 07:30:20 +0000174 struct ospf_area *area;
hasso52dc7ee2004-09-23 19:18:23 +0000175 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000176
paul1eb8ef22005-04-07 07:30:20 +0000177 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
178 if ((range = ospf_area_range_match (area, p)))
paul718e3742002-12-13 20:15:29 +0000179 return range;
180
181 return NULL;
182}
183
184int
185ospf_area_range_active (struct ospf_area_range *range)
186{
187 return range->specifics;
188}
189
paul4dadc292005-05-06 21:37:42 +0000190static int
paul718e3742002-12-13 20:15:29 +0000191ospf_area_actively_attached (struct ospf_area *area)
192{
193 return area->act_ints;
194}
195
196int
197ospf_area_range_set (struct ospf *ospf, struct in_addr area_id,
198 struct prefix_ipv4 *p, int advertise)
199{
200 struct ospf_area *area;
201 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000202 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000203
paul147193a2003-04-19 00:31:59 +0000204 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000205 if (area == NULL)
206 return 0;
207
208 range = ospf_area_range_lookup (area, p);
209 if (range != NULL)
210 {
211 if ((CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
212 && !CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
213 || (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
214 && CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE)))
paul147193a2003-04-19 00:31:59 +0000215 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000216 }
217 else
218 {
219 range = ospf_area_range_new (p);
220 ospf_area_range_add (area, range);
paul147193a2003-04-19 00:31:59 +0000221 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000222 }
223
224 if (CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
225 SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
226 else
227 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
228
229 return 1;
230}
231
232int
233ospf_area_range_cost_set (struct ospf *ospf, struct in_addr area_id,
234 struct prefix_ipv4 *p, u_int32_t cost)
235{
236 struct ospf_area *area;
237 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000238 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000239
paul147193a2003-04-19 00:31:59 +0000240 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000241 if (area == NULL)
242 return 0;
243
Paul Jakma214a4452006-05-12 22:51:49 +0000244 range = ospf_area_range_lookup (area, p);
paul718e3742002-12-13 20:15:29 +0000245 if (range == NULL)
246 return 0;
247
248 if (range->cost_config != cost)
249 {
250 range->cost_config = cost;
251 if (ospf_area_range_active (range))
paul147193a2003-04-19 00:31:59 +0000252 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000253 }
254
255 return 1;
256}
257
258int
259ospf_area_range_unset (struct ospf *ospf, struct in_addr area_id,
260 struct prefix_ipv4 *p)
261{
262 struct ospf_area *area;
JR Rivers8fc9e002012-09-24 17:26:46 +0000263 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +0000264
paul147193a2003-04-19 00:31:59 +0000265 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000266 if (area == NULL)
267 return 0;
268
JR Rivers8fc9e002012-09-24 17:26:46 +0000269 rn = route_node_lookup (area->ranges, (struct prefix*)p);
270 if (rn == NULL)
paul718e3742002-12-13 20:15:29 +0000271 return 0;
272
JR Rivers8fc9e002012-09-24 17:26:46 +0000273 if (ospf_area_range_active (rn->info))
paul147193a2003-04-19 00:31:59 +0000274 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000275
JR Rivers8fc9e002012-09-24 17:26:46 +0000276 ospf_area_range_delete (area, rn);
paul718e3742002-12-13 20:15:29 +0000277
278 return 1;
279}
280
281int
282ospf_area_range_substitute_set (struct ospf *ospf, struct in_addr area_id,
283 struct prefix_ipv4 *p, struct prefix_ipv4 *s)
284{
285 struct ospf_area *area;
286 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000287 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000288
paul147193a2003-04-19 00:31:59 +0000289 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000290 range = ospf_area_range_lookup (area, p);
291
292 if (range != NULL)
293 {
294 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE) ||
295 !CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
paul147193a2003-04-19 00:31:59 +0000296 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000297 }
298 else
299 {
300 range = ospf_area_range_new (p);
301 ospf_area_range_add (area, range);
paul147193a2003-04-19 00:31:59 +0000302 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000303 }
304
305 SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
306 SET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
307 range->subst_addr = s->prefix;
308 range->subst_masklen = s->prefixlen;
309
310 return 1;
311}
312
313int
314ospf_area_range_substitute_unset (struct ospf *ospf, struct in_addr area_id,
315 struct prefix_ipv4 *p)
316{
317 struct ospf_area *area;
318 struct ospf_area_range *range;
319
paul147193a2003-04-19 00:31:59 +0000320 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000321 if (area == NULL)
322 return 0;
323
324 range = ospf_area_range_lookup (area, p);
325 if (range == NULL)
326 return 0;
327
328 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
329 if (ospf_area_range_active (range))
paul147193a2003-04-19 00:31:59 +0000330 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000331
332 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
333 range->subst_addr.s_addr = 0;
334 range->subst_masklen = 0;
335
336 return 1;
337}
338
339int
paul147193a2003-04-19 00:31:59 +0000340ospf_act_bb_connection (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000341{
paul147193a2003-04-19 00:31:59 +0000342 if (ospf->backbone == NULL)
paul718e3742002-12-13 20:15:29 +0000343 return 0;
344
paul147193a2003-04-19 00:31:59 +0000345 return ospf->backbone->full_nbrs;
paul718e3742002-12-13 20:15:29 +0000346}
347
paule2c6c152003-06-22 08:49:25 +0000348/* Determine whether this router is elected translator or not for area */
paul4dadc292005-05-06 21:37:42 +0000349static int
paule2c6c152003-06-22 08:49:25 +0000350ospf_abr_nssa_am_elected (struct ospf_area *area)
351{
352 struct route_node *rn;
353 struct ospf_lsa *lsa;
354 struct router_lsa *rlsa;
355 struct in_addr *best = NULL;
356
357 LSDB_LOOP ( ROUTER_LSDB (area), rn, lsa)
358 {
359 /* sanity checks */
360 if (!lsa
361 || (lsa->data->type != OSPF_ROUTER_LSA)
362 || IS_LSA_SELF (lsa))
363 continue;
364
365 rlsa = (struct router_lsa *) lsa->data;
366
367 /* ignore non-ABR routers */
368 if (!IS_ROUTER_LSA_BORDER (rlsa))
369 continue;
370
371 /* Router has Nt flag - always translate */
372 if (IS_ROUTER_LSA_NT (rlsa))
373 {
374 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000375 zlog_debug ("ospf_abr_nssa_am_elected: "
paule2c6c152003-06-22 08:49:25 +0000376 "router %s asserts Nt",
377 inet_ntoa (lsa->data->id) );
378 return 0;
379 }
380
381 if (best == NULL)
382 best = &lsa->data->id;
383 else
Denis Ovsienko4e677f52011-12-18 16:27:02 +0400384 if (IPV4_ADDR_CMP (&best->s_addr, &lsa->data->id.s_addr) < 0)
paule2c6c152003-06-22 08:49:25 +0000385 best = &lsa->data->id;
386 }
387
388 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000389 zlog_debug ("ospf_abr_nssa_am_elected: best electable ABR is: %s",
paule2c6c152003-06-22 08:49:25 +0000390 (best) ? inet_ntoa (*best) : "<none>" );
391
392 if (best == NULL)
393 return 1;
394
Denis Ovsienko4e677f52011-12-18 16:27:02 +0400395 if (IPV4_ADDR_CMP (&best->s_addr, &area->ospf->router_id.s_addr) < 0)
paule2c6c152003-06-22 08:49:25 +0000396 return 1;
397 else
398 return 0;
399}
400
401/* Check NSSA ABR status
402 * assumes there are nssa areas
403 */
paul4dadc292005-05-06 21:37:42 +0000404static void
paule2c6c152003-06-22 08:49:25 +0000405ospf_abr_nssa_check_status (struct ospf *ospf)
406{
407 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000408 struct listnode *lnode, *nnode;
Paul Jakma9560fa82006-06-26 12:50:06 +0000409
paul1eb8ef22005-04-07 07:30:20 +0000410 for (ALL_LIST_ELEMENTS (ospf->areas, lnode, nnode, area))
paule2c6c152003-06-22 08:49:25 +0000411 {
Paul Jakma9560fa82006-06-26 12:50:06 +0000412 u_char old_state = area->NSSATranslatorState;
413
paule2c6c152003-06-22 08:49:25 +0000414 if (area->external_routing != OSPF_AREA_NSSA)
415 continue;
Paul Jakma9560fa82006-06-26 12:50:06 +0000416
paule2c6c152003-06-22 08:49:25 +0000417 if (IS_DEBUG_OSPF (nssa, NSSA))
ajse84cc642004-12-08 17:28:56 +0000418 zlog_debug ("ospf_abr_nssa_check_status: "
paule2c6c152003-06-22 08:49:25 +0000419 "checking area %s",
420 inet_ntoa (area->area_id));
Paul Jakma9560fa82006-06-26 12:50:06 +0000421
paule2c6c152003-06-22 08:49:25 +0000422 if (!IS_OSPF_ABR (area->ospf))
423 {
424 if (IS_DEBUG_OSPF (nssa, NSSA))
Paul Jakma9560fa82006-06-26 12:50:06 +0000425 zlog_debug ("ospf_abr_nssa_check_status: "
426 "not ABR");
pauld4a53d52003-07-12 21:30:57 +0000427 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
paule2c6c152003-06-22 08:49:25 +0000428 }
Paul Jakma9560fa82006-06-26 12:50:06 +0000429 else
430 {
431 switch (area->NSSATranslatorRole)
432 {
433 case OSPF_NSSA_ROLE_NEVER:
434 /* We never Translate Type-7 LSA. */
435 /* TODO: check previous state and flush? */
436 if (IS_DEBUG_OSPF (nssa, NSSA))
437 zlog_debug ("ospf_abr_nssa_check_status: "
438 "never translate");
439 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
440 break;
441
442 case OSPF_NSSA_ROLE_ALWAYS:
443 /* We always translate if we are an ABR
444 * TODO: originate new LSAs if state change?
445 * or let the nssa abr task take care of it?
446 */
447 if (IS_DEBUG_OSPF (nssa, NSSA))
448 zlog_debug ("ospf_abr_nssa_check_status: "
449 "translate always");
450 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
451 break;
452
453 case OSPF_NSSA_ROLE_CANDIDATE:
454 /* We are a candidate for Translation */
455 if (ospf_abr_nssa_am_elected (area) > 0)
456 {
457 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
458 if (IS_DEBUG_OSPF (nssa, NSSA))
459 zlog_debug ("ospf_abr_nssa_check_status: "
460 "elected translator");
461 }
462 else
463 {
464 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
465 if (IS_DEBUG_OSPF (nssa, NSSA))
466 zlog_debug ("ospf_abr_nssa_check_status: " "not elected");
467 }
468 break;
469 }
470 }
471 /* RFC3101, 3.1:
472 * All NSSA border routers must set the E-bit in the Type-1 router-LSAs
473 * of their directly attached non-stub areas, even when they are not
474 * translating.
475 */
476 if (old_state != area->NSSATranslatorState)
477 {
478 if (old_state == OSPF_NSSA_TRANSLATE_DISABLED)
479 ospf_asbr_status_update (ospf, ++ospf->redistribute);
480 else if (area->NSSATranslatorState == OSPF_NSSA_TRANSLATE_DISABLED)
481 ospf_asbr_status_update (ospf, --ospf->redistribute);
482 }
paule2c6c152003-06-22 08:49:25 +0000483 }
484}
paule2c6c152003-06-22 08:49:25 +0000485
paul718e3742002-12-13 20:15:29 +0000486/* Check area border router status. */
487void
paul147193a2003-04-19 00:31:59 +0000488ospf_check_abr_status (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000489{
490 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000491 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000492 int bb_configured = 0;
493 int bb_act_attached = 0;
494 int areas_configured = 0;
495 int areas_act_attached = 0;
paul147193a2003-04-19 00:31:59 +0000496 u_char new_flags = ospf->flags;
paul718e3742002-12-13 20:15:29 +0000497
498 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000499 zlog_debug ("ospf_check_abr_status(): Start");
paul718e3742002-12-13 20:15:29 +0000500
paul1eb8ef22005-04-07 07:30:20 +0000501 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
paul718e3742002-12-13 20:15:29 +0000502 {
paul718e3742002-12-13 20:15:29 +0000503 if (listcount (area->oiflist))
504 {
505 areas_configured++;
506
507 if (OSPF_IS_AREA_BACKBONE (area))
508 bb_configured = 1;
509 }
510
511 if (ospf_area_actively_attached (area))
512 {
513 areas_act_attached++;
514
515 if (OSPF_IS_AREA_BACKBONE (area))
516 bb_act_attached = 1;
517 }
518 }
519
520 if (IS_DEBUG_OSPF_EVENT)
521 {
ajse84cc642004-12-08 17:28:56 +0000522 zlog_debug ("ospf_check_abr_status(): looked through areas");
523 zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured);
524 zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
paul718e3742002-12-13 20:15:29 +0000525 bb_act_attached);
ajse84cc642004-12-08 17:28:56 +0000526 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
paul718e3742002-12-13 20:15:29 +0000527 areas_configured);
ajse84cc642004-12-08 17:28:56 +0000528 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
paul718e3742002-12-13 20:15:29 +0000529 areas_act_attached);
530 }
531
paul147193a2003-04-19 00:31:59 +0000532 switch (ospf->abr_type)
paul718e3742002-12-13 20:15:29 +0000533 {
534 case OSPF_ABR_SHORTCUT:
535 case OSPF_ABR_STAND:
536 if (areas_act_attached > 1)
537 SET_FLAG (new_flags, OSPF_FLAG_ABR);
538 else
539 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
540 break;
541
542 case OSPF_ABR_IBM:
543 if ((areas_act_attached > 1) && bb_configured)
544 SET_FLAG (new_flags, OSPF_FLAG_ABR);
545 else
546 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
547 break;
548
549 case OSPF_ABR_CISCO:
550 if ((areas_configured > 1) && bb_act_attached)
551 SET_FLAG (new_flags, OSPF_FLAG_ABR);
552 else
553 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
554 break;
555 default:
556 break;
557 }
558
paul147193a2003-04-19 00:31:59 +0000559 if (new_flags != ospf->flags)
paul718e3742002-12-13 20:15:29 +0000560 {
Paul Jakmab6eef002014-10-09 14:19:51 +0100561 ospf_spf_calculate_schedule (ospf, SPF_FLAG_ABR_STATUS_CHANGE);
paul718e3742002-12-13 20:15:29 +0000562 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000563 zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags);
paul147193a2003-04-19 00:31:59 +0000564 ospf->flags = new_flags;
Paul Jakmac363d382010-01-24 22:42:13 +0000565 ospf_router_lsa_update (ospf);
paul718e3742002-12-13 20:15:29 +0000566 }
567}
568
paul4dadc292005-05-06 21:37:42 +0000569static void
paul718e3742002-12-13 20:15:29 +0000570ospf_abr_update_aggregate (struct ospf_area_range *range,
JR Riversb4154c12012-09-24 17:26:53 +0000571 struct ospf_route *or, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +0000572{
573 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000574 zlog_debug ("ospf_abr_update_aggregate(): Start");
paul718e3742002-12-13 20:15:29 +0000575
JR Riversb4154c12012-09-24 17:26:53 +0000576 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED) &&
577 (range->cost != OSPF_STUB_MAX_METRIC_SUMMARY_COST))
578 {
579 range->cost = OSPF_STUB_MAX_METRIC_SUMMARY_COST;
580 if (IS_DEBUG_OSPF_EVENT)
581 zlog_debug ("ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
582 range->cost);
583 }
584 else if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
paul718e3742002-12-13 20:15:29 +0000585 {
586 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000587 zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
paul7f352b82004-02-19 19:37:47 +0000588 range->cost_config);
paul718e3742002-12-13 20:15:29 +0000589
590 range->cost = range->cost_config;
591 }
592 else
593 {
594 if (range->specifics == 0)
JR Riversb4154c12012-09-24 17:26:53 +0000595 {
596 if (IS_DEBUG_OSPF_EVENT)
597 zlog_debug ("ospf_abr_update_aggregate(): use or->cost %d",
598 or->cost);
599
600 range->cost = or->cost; /* 1st time get 1st cost */
601 }
paul718e3742002-12-13 20:15:29 +0000602
paul7f352b82004-02-19 19:37:47 +0000603 if (or->cost > range->cost)
604 {
605 if (IS_DEBUG_OSPF_EVENT)
JR Riversb4154c12012-09-24 17:26:53 +0000606 zlog_debug ("ospf_abr_update_aggregate(): update to %d", or->cost);
paul718e3742002-12-13 20:15:29 +0000607
paul7f352b82004-02-19 19:37:47 +0000608 range->cost = or->cost;
609 }
paul718e3742002-12-13 20:15:29 +0000610 }
611
612 range->specifics++;
613}
614
615static void
616set_metric (struct ospf_lsa *lsa, u_int32_t metric)
617{
618 struct summary_lsa *header;
619 u_char *mp;
620 metric = htonl (metric);
hassoc9e52be2004-09-26 16:09:34 +0000621 mp = (u_char *) &metric;
paul718e3742002-12-13 20:15:29 +0000622 mp++;
623 header = (struct summary_lsa *) lsa->data;
624 memcpy(header->metric, mp, 3);
625}
626
paul718e3742002-12-13 20:15:29 +0000627/* ospf_abr_translate_nssa */
paul4dadc292005-05-06 21:37:42 +0000628static int
paul147193a2003-04-19 00:31:59 +0000629ospf_abr_translate_nssa (struct ospf_area *area, struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000630{
631 /* Incoming Type-7 or later aggregated Type-7
pauld4a53d52003-07-12 21:30:57 +0000632 *
633 * LSA is skipped if P-bit is off.
634 * LSA is aggregated if within range.
635 *
636 * The Type-7 is translated, Installed/Approved as a Type-5 into
637 * global LSDB, then Flooded through AS
638 *
639 * Later, any Unapproved Translated Type-5's are flushed/discarded
640 */
paul718e3742002-12-13 20:15:29 +0000641
pauld4a53d52003-07-12 21:30:57 +0000642 struct ospf_lsa *old = NULL,
643 *new = NULL;
644 struct as_external_lsa *ext7;
645 struct prefix_ipv4 p;
paul718e3742002-12-13 20:15:29 +0000646
647 if (! CHECK_FLAG (lsa->data->options, OSPF_OPTION_NP))
648 {
649 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000650 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
pauld4a53d52003-07-12 21:30:57 +0000651 inet_ntoa (lsa->data->id));
652 return 1;
paul718e3742002-12-13 20:15:29 +0000653 }
pauld4a53d52003-07-12 21:30:57 +0000654
paul718e3742002-12-13 20:15:29 +0000655 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000656 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
pauld4a53d52003-07-12 21:30:57 +0000657 inet_ntoa (lsa->data->id));
paul718e3742002-12-13 20:15:29 +0000658
pauld4a53d52003-07-12 21:30:57 +0000659 ext7 = (struct as_external_lsa *)(lsa->data);
660 p.prefix = lsa->data->id;
661 p.prefixlen = ip_masklen (ext7->mask);
662
663 if (ext7->e[0].fwd_addr.s_addr == OSPF_DEFAULT_DESTINATION)
664 {
665 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000666 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, "
pauld4a53d52003-07-12 21:30:57 +0000667 "Forward address is 0, NO Translation",
668 inet_ntoa (lsa->data->id));
669 return 1;
670 }
671
672 /* try find existing AS-External LSA for this prefix */
673
674 old = ospf_external_info_find_lsa (area->ospf, &p);
675
676 if (old)
677 {
678 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000679 zlog_debug ("ospf_abr_translate_nssa(): "
pauld4a53d52003-07-12 21:30:57 +0000680 "found old translated LSA Id %s, refreshing",
681 inet_ntoa (old->data->id));
682
683 /* refresh */
684 new = ospf_translated_nssa_refresh (area->ospf, lsa, old);
685 if (!new)
686 {
687 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000688 zlog_debug ("ospf_abr_translate_nssa(): "
pauld4a53d52003-07-12 21:30:57 +0000689 "could not refresh translated LSA Id %s",
690 inet_ntoa (old->data->id));
691 }
692 }
693 else
694 {
695 /* no existing external route for this LSA Id
696 * originate translated LSA
697 */
698
699 if ((new = ospf_translated_nssa_originate (area->ospf, lsa))
700 == NULL)
701 {
702 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000703 zlog_debug ("ospf_abr_translate_nssa(): Could not translate "
pauld4a53d52003-07-12 21:30:57 +0000704 "Type-7 for %s to Type-5",
705 inet_ntoa (lsa->data->id));
706 return 1;
707 }
708 }
paul718e3742002-12-13 20:15:29 +0000709
710 /* Area where Aggregate testing will be inserted, just like summary
711 advertisements */
712 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
713
paul718e3742002-12-13 20:15:29 +0000714 return 0;
715}
716
paul4dadc292005-05-06 21:37:42 +0000717static void
paul718e3742002-12-13 20:15:29 +0000718ospf_abr_translate_nssa_range (struct prefix_ipv4 *p, u_int32_t cost)
719{
720 /* The Type-7 is created from the aggregated prefix and forwarded
721 for lsa installation and flooding... to be added... */
722}
paul718e3742002-12-13 20:15:29 +0000723
vincentba682532005-09-29 13:52:57 +0000724void
paul718e3742002-12-13 20:15:29 +0000725ospf_abr_announce_network_to_area (struct prefix_ipv4 *p, u_int32_t cost,
726 struct ospf_area *area)
727{
728 struct ospf_lsa *lsa, *old = NULL;
729 struct summary_lsa *sl = NULL;
JR Riversb4154c12012-09-24 17:26:53 +0000730 u_int32_t full_cost;
paul718e3742002-12-13 20:15:29 +0000731
732 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000733 zlog_debug ("ospf_abr_announce_network_to_area(): Start");
paul718e3742002-12-13 20:15:29 +0000734
JR Riversb4154c12012-09-24 17:26:53 +0000735 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
736 full_cost = OSPF_STUB_MAX_METRIC_SUMMARY_COST;
737 else
738 full_cost = cost;
739
pauld4a53d52003-07-12 21:30:57 +0000740 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_SUMMARY_LSA,
741 (struct prefix_ipv4 *) p,
742 area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +0000743 if (old)
744 {
745 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000746 zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
pauld4a53d52003-07-12 21:30:57 +0000747
paul718e3742002-12-13 20:15:29 +0000748 sl = (struct summary_lsa *) old->data;
749
750 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000751 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000752 "old metric: %d, new metric: %d",
753 GET_METRIC (sl->metric), cost);
JR Rivers82175552012-09-24 17:26:50 +0000754
JR Riversb4154c12012-09-24 17:26:53 +0000755 if ((GET_METRIC (sl->metric) == full_cost) &&
JR Rivers82175552012-09-24 17:26:50 +0000756 ((old->flags & OSPF_LSA_IN_MAXAGE) == 0))
pauld4a53d52003-07-12 21:30:57 +0000757 {
758 /* unchanged. simply reapprove it */
759 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000760 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000761 "old summary approved");
762 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
763 }
764 else
765 {
766 /* LSA is changed, refresh it */
767 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000768 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000769 "refreshing summary");
JR Riversb4154c12012-09-24 17:26:53 +0000770 set_metric (old, full_cost);
Paul Jakmac363d382010-01-24 22:42:13 +0000771 lsa = ospf_lsa_refresh (area->ospf, old);
paulc24d6022005-11-20 14:54:12 +0000772
773 if (!lsa)
774 {
775 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
776
777 prefix2str ((struct prefix *) p, buf, sizeof(buf));
778 zlog_warn ("%s: Could not refresh %s to %s",
779 __func__,
780 buf,
781 inet_ntoa (area->area_id));
782 return;
783 }
784
paulc8987752005-07-26 06:07:22 +0000785 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
pauld4a53d52003-07-12 21:30:57 +0000786 /* This will flood through area. */
787 }
paul718e3742002-12-13 20:15:29 +0000788 }
789 else
790 {
791 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000792 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000793 "creating new summary");
JR Riversb4154c12012-09-24 17:26:53 +0000794 lsa = ospf_summary_lsa_originate ( (struct prefix_ipv4 *)p, full_cost, area);
pauld4a53d52003-07-12 21:30:57 +0000795 /* This will flood through area. */
paul718e3742002-12-13 20:15:29 +0000796
paulc24d6022005-11-20 14:54:12 +0000797 if (!lsa)
798 {
799 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
800
801 prefix2str ((struct prefix *)p, buf, sizeof(buf));
802 zlog_warn ("%s: Could not originate %s to %s",
803 __func__,
804 buf,
805 inet_ntoa (area->area_id));
806 return;
807 }
808
paul718e3742002-12-13 20:15:29 +0000809 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
810 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000811 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000812 "flooding new version of summary");
paul718e3742002-12-13 20:15:29 +0000813 }
814
815 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000816 zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
paul718e3742002-12-13 20:15:29 +0000817}
818
paul4dadc292005-05-06 21:37:42 +0000819static int
paul718e3742002-12-13 20:15:29 +0000820ospf_abr_nexthops_belong_to_area (struct ospf_route *or,
821 struct ospf_area *area)
822{
paul1eb8ef22005-04-07 07:30:20 +0000823 struct listnode *node, *nnode;
paul96735ee2003-08-10 02:51:22 +0000824 struct ospf_path *path;
Joakim Tjernlunda8ba8472009-07-27 12:42:34 +0200825 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000826
Joakim Tjernlunda8ba8472009-07-27 12:42:34 +0200827 for (ALL_LIST_ELEMENTS_RO (or->paths, node, path))
828 for (ALL_LIST_ELEMENTS_RO (area->oiflist, nnode, oi))
829 if (oi->ifp && oi->ifp->ifindex == path->ifindex)
830 return 1;
paul718e3742002-12-13 20:15:29 +0000831
832 return 0;
833}
834
paul4dadc292005-05-06 21:37:42 +0000835static int
pauld4a53d52003-07-12 21:30:57 +0000836ospf_abr_should_accept (struct prefix_ipv4 *p, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +0000837{
838 if (IMPORT_NAME (area))
839 {
840 if (IMPORT_LIST (area) == NULL)
841 IMPORT_LIST (area) = access_list_lookup (AFI_IP, IMPORT_NAME (area));
842
843 if (IMPORT_LIST (area))
844 if (access_list_apply (IMPORT_LIST (area), p) == FILTER_DENY)
845 return 0;
846 }
847
848 return 1;
849}
850
paul4dadc292005-05-06 21:37:42 +0000851static int
paul718e3742002-12-13 20:15:29 +0000852ospf_abr_plist_in_check (struct ospf_area *area, struct ospf_route *or,
pauld4a53d52003-07-12 21:30:57 +0000853 struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000854{
855 if (PREFIX_NAME_IN (area))
856 {
857 if (PREFIX_LIST_IN (area) == NULL)
858 PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP,
859 PREFIX_NAME_IN (area));
860 if (PREFIX_LIST_IN (area))
861 if (prefix_list_apply (PREFIX_LIST_IN (area), p) != PREFIX_PERMIT)
862 return 0;
863 }
864 return 1;
865}
866
paul4dadc292005-05-06 21:37:42 +0000867static int
paul718e3742002-12-13 20:15:29 +0000868ospf_abr_plist_out_check (struct ospf_area *area, struct ospf_route *or,
pauld4a53d52003-07-12 21:30:57 +0000869 struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000870{
871 if (PREFIX_NAME_OUT (area))
872 {
873 if (PREFIX_LIST_OUT (area) == NULL)
874 PREFIX_LIST_OUT (area) = prefix_list_lookup (AFI_IP,
875 PREFIX_NAME_OUT (area));
876 if (PREFIX_LIST_OUT (area))
877 if (prefix_list_apply (PREFIX_LIST_OUT (area), p) != PREFIX_PERMIT)
878 return 0;
879 }
880 return 1;
881}
882
paul4dadc292005-05-06 21:37:42 +0000883static void
paul147193a2003-04-19 00:31:59 +0000884ospf_abr_announce_network (struct ospf *ospf,
pauld4a53d52003-07-12 21:30:57 +0000885 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000886{
paul718e3742002-12-13 20:15:29 +0000887 struct ospf_area_range *range;
paul718e3742002-12-13 20:15:29 +0000888 struct ospf_area *area, *or_area;
hasso52dc7ee2004-09-23 19:18:23 +0000889 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000890
891 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000892 zlog_debug ("ospf_abr_announce_network(): Start");
paul718e3742002-12-13 20:15:29 +0000893
paul147193a2003-04-19 00:31:59 +0000894 or_area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
paul718e3742002-12-13 20:15:29 +0000895 assert (or_area);
896
paul1eb8ef22005-04-07 07:30:20 +0000897 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000898 {
paul718e3742002-12-13 20:15:29 +0000899 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000900 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
paul718e3742002-12-13 20:15:29 +0000901 inet_ntoa (area->area_id));
902
903 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
904 continue;
905
906 if (ospf_abr_nexthops_belong_to_area (or, area))
907 continue;
908
pauld4a53d52003-07-12 21:30:57 +0000909 if (!ospf_abr_should_accept (p, area))
paul718e3742002-12-13 20:15:29 +0000910 {
911 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000912 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000913 "prefix %s/%d was denied by import-list",
914 inet_ntoa (p->prefix), p->prefixlen);
915 continue;
916 }
917
pauld4a53d52003-07-12 21:30:57 +0000918 if (!ospf_abr_plist_in_check (area, or, p))
paul718e3742002-12-13 20:15:29 +0000919 {
920 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000921 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000922 "prefix %s/%d was denied by prefix-list",
923 inet_ntoa (p->prefix), p->prefixlen);
924 continue;
925 }
926
927 if (area->external_routing != OSPF_AREA_DEFAULT && area->no_summary)
928 {
929 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000930 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000931 "area %s is stub and no_summary",
932 inet_ntoa (area->area_id));
933 continue;
934 }
935
936 if (or->path_type == OSPF_PATH_INTER_AREA)
937 {
938 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000939 zlog_debug ("ospf_abr_announce_network(): this is "
paul718e3742002-12-13 20:15:29 +0000940 "inter-area route to %s/%d",
941 inet_ntoa (p->prefix), p->prefixlen);
942
943 if (!OSPF_IS_AREA_BACKBONE (area))
944 ospf_abr_announce_network_to_area (p, or->cost, area);
945 }
946
947 if (or->path_type == OSPF_PATH_INTRA_AREA)
pauld4a53d52003-07-12 21:30:57 +0000948 {
949 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000950 zlog_debug ("ospf_abr_announce_network(): "
pauld4a53d52003-07-12 21:30:57 +0000951 "this is intra-area route to %s/%d",
952 inet_ntoa (p->prefix), p->prefixlen);
953 if ((range = ospf_area_range_match (or_area, p))
954 && !ospf_area_is_transit (area))
JR Riversb4154c12012-09-24 17:26:53 +0000955 ospf_abr_update_aggregate (range, or, area);
pauld4a53d52003-07-12 21:30:57 +0000956 else
957 ospf_abr_announce_network_to_area (p, or->cost, area);
958 }
paul718e3742002-12-13 20:15:29 +0000959 }
960}
961
paul4dadc292005-05-06 21:37:42 +0000962static int
paul147193a2003-04-19 00:31:59 +0000963ospf_abr_should_announce (struct ospf *ospf,
pauld4a53d52003-07-12 21:30:57 +0000964 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000965{
paul147193a2003-04-19 00:31:59 +0000966 struct ospf_area *area;
967
968 area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
paul718e3742002-12-13 20:15:29 +0000969
970 assert (area);
971
972 if (EXPORT_NAME (area))
973 {
974 if (EXPORT_LIST (area) == NULL)
975 EXPORT_LIST (area) = access_list_lookup (AFI_IP, EXPORT_NAME (area));
976
977 if (EXPORT_LIST (area))
978 if (access_list_apply (EXPORT_LIST (area), p) == FILTER_DENY)
979 return 0;
980 }
981
982 return 1;
983}
984
paul4dadc292005-05-06 21:37:42 +0000985static void
paul147193a2003-04-19 00:31:59 +0000986ospf_abr_process_nssa_translates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000987{
988 /* Scan through all NSSA_LSDB records for all areas;
989
990 If P-bit is on, translate all Type-7's to 5's and aggregate or
991 flood install as approved in Type-5 LSDB with XLATE Flag on
992 later, do same for all aggregates... At end, DISCARD all
993 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
hasso52dc7ee2004-09-23 19:18:23 +0000994 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000995 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +0000996 struct route_node *rn;
997 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000998
999 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001000 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001001
paul1eb8ef22005-04-07 07:30:20 +00001002 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001003 {
paule2c6c152003-06-22 08:49:25 +00001004 if (! area->NSSATranslatorState)
pauld4a53d52003-07-12 21:30:57 +00001005 continue; /* skip if not translator */
paul718e3742002-12-13 20:15:29 +00001006
1007 if (area->external_routing != OSPF_AREA_NSSA)
pauld4a53d52003-07-12 21:30:57 +00001008 continue; /* skip if not Nssa Area */
paul718e3742002-12-13 20:15:29 +00001009
1010 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001011 zlog_debug ("ospf_abr_process_nssa_translates(): "
pauld4a53d52003-07-12 21:30:57 +00001012 "looking at area %s", inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001013
paul147193a2003-04-19 00:31:59 +00001014 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001015 ospf_abr_translate_nssa (area, lsa);
paul718e3742002-12-13 20:15:29 +00001016 }
1017
1018 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001019 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001020
1021}
paul718e3742002-12-13 20:15:29 +00001022
paul4dadc292005-05-06 21:37:42 +00001023static void
paul147193a2003-04-19 00:31:59 +00001024ospf_abr_process_network_rt (struct ospf *ospf,
1025 struct route_table *rt)
paul718e3742002-12-13 20:15:29 +00001026{
paul718e3742002-12-13 20:15:29 +00001027 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001028 struct ospf_route *or;
1029 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +00001030
1031 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001032 zlog_debug ("ospf_abr_process_network_rt(): Start");
paul718e3742002-12-13 20:15:29 +00001033
1034 for (rn = route_top (rt); rn; rn = route_next (rn))
1035 {
1036 if ((or = rn->info) == NULL)
1037 continue;
1038
paul147193a2003-04-19 00:31:59 +00001039 if (!(area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id)))
paul718e3742002-12-13 20:15:29 +00001040 {
1041 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001042 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
paul718e3742002-12-13 20:15:29 +00001043 inet_ntoa (or->u.std.area_id));
1044 continue;
1045 }
1046
1047 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001048 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
paul718e3742002-12-13 20:15:29 +00001049 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
1050 if (or->path_type >= OSPF_PATH_TYPE1_EXTERNAL)
1051 {
1052 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001053 zlog_debug ("ospf_abr_process_network_rt(): "
paul718e3742002-12-13 20:15:29 +00001054 "this is an External router, skipping");
1055 continue;
1056 }
1057
1058 if (or->cost >= OSPF_LS_INFINITY)
1059 {
1060 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001061 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001062 " this route's cost is infinity, skipping");
1063 continue;
1064 }
1065
1066 if (or->type == OSPF_DESTINATION_DISCARD)
1067 {
1068 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001069 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001070 " this is a discard entry, skipping");
1071 continue;
1072 }
1073
1074 if (or->path_type == OSPF_PATH_INTRA_AREA &&
pauld4a53d52003-07-12 21:30:57 +00001075 !ospf_abr_should_announce (ospf, (struct prefix_ipv4 *) &rn->p, or))
paul718e3742002-12-13 20:15:29 +00001076 {
1077 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001078 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
paul718e3742002-12-13 20:15:29 +00001079 continue;
1080 }
1081
1082 if (or->path_type == OSPF_PATH_INTRA_AREA &&
pauld4a53d52003-07-12 21:30:57 +00001083 !ospf_abr_plist_out_check (area, or, (struct prefix_ipv4 *) &rn->p))
paul718e3742002-12-13 20:15:29 +00001084 {
1085 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001086 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
paul718e3742002-12-13 20:15:29 +00001087 continue;
1088 }
1089
1090 if ((or->path_type == OSPF_PATH_INTER_AREA) &&
1091 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1092 {
1093 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001094 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001095 " this is route is not backbone one, skipping");
1096 continue;
1097 }
1098
1099
paul147193a2003-04-19 00:31:59 +00001100 if ((ospf->abr_type == OSPF_ABR_CISCO) ||
1101 (ospf->abr_type == OSPF_ABR_IBM))
paul718e3742002-12-13 20:15:29 +00001102
paul147193a2003-04-19 00:31:59 +00001103 if (!ospf_act_bb_connection (ospf) &&
paul718e3742002-12-13 20:15:29 +00001104 or->path_type != OSPF_PATH_INTRA_AREA)
1105 {
1106 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001107 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
paul718e3742002-12-13 20:15:29 +00001108 "No BB connection, skip not intra-area routes");
1109 continue;
1110 }
1111
1112 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001113 zlog_debug ("ospf_abr_process_network_rt(): announcing");
hassofa2b17e2004-03-04 17:45:00 +00001114 ospf_abr_announce_network (ospf, (struct prefix_ipv4 *)&rn->p, or);
paul718e3742002-12-13 20:15:29 +00001115 }
1116
1117 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001118 zlog_debug ("ospf_abr_process_network_rt(): Stop");
paul718e3742002-12-13 20:15:29 +00001119}
1120
paul4dadc292005-05-06 21:37:42 +00001121static void
paul718e3742002-12-13 20:15:29 +00001122ospf_abr_announce_rtr_to_area (struct prefix_ipv4 *p, u_int32_t cost,
1123 struct ospf_area *area)
1124{
1125 struct ospf_lsa *lsa, *old = NULL;
1126 struct summary_lsa *slsa = NULL;
1127
1128 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001129 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
paul718e3742002-12-13 20:15:29 +00001130
paul147193a2003-04-19 00:31:59 +00001131 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_ASBR_SUMMARY_LSA,
1132 p, area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +00001133 if (old)
1134 {
1135 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001136 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
paul718e3742002-12-13 20:15:29 +00001137 slsa = (struct summary_lsa *) old->data;
1138
1139 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001140 zlog_debug ("ospf_abr_announce_network_to_area(): "
paul718e3742002-12-13 20:15:29 +00001141 "old metric: %d, new metric: %d",
1142 GET_METRIC (slsa->metric), cost);
1143 }
1144
Vishal Kumard2655482012-12-07 14:47:58 -08001145 if (old && (GET_METRIC (slsa->metric) == cost) &&
1146 ((old->flags & OSPF_LSA_IN_MAXAGE) == 0))
paul718e3742002-12-13 20:15:29 +00001147 {
1148 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001149 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
paul718e3742002-12-13 20:15:29 +00001150 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
1151 }
1152 else
1153 {
1154 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001155 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
paul718e3742002-12-13 20:15:29 +00001156
1157 if (old)
1158 {
1159 set_metric (old, cost);
Paul Jakmac363d382010-01-24 22:42:13 +00001160 lsa = ospf_lsa_refresh (area->ospf, old);
paul718e3742002-12-13 20:15:29 +00001161 }
1162 else
1163 lsa = ospf_summary_asbr_lsa_originate (p, cost, area);
paulc24d6022005-11-20 14:54:12 +00001164 if (!lsa)
1165 {
1166 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
1167
1168 prefix2str ((struct prefix *)p, buf, sizeof(buf));
1169 zlog_warn ("%s: Could not refresh/originate %s to %s",
1170 __func__,
1171 buf,
1172 inet_ntoa (area->area_id));
1173 return;
1174 }
1175
paul718e3742002-12-13 20:15:29 +00001176 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001177 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
paul718e3742002-12-13 20:15:29 +00001178 "flooding new version of summary");
paulc24d6022005-11-20 14:54:12 +00001179
paul718e3742002-12-13 20:15:29 +00001180 /*
1181 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1182 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1183
1184 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1185 /* ospf_flood_through_area (area, NULL, lsa);*/
1186 }
1187
1188 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001189 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
paul718e3742002-12-13 20:15:29 +00001190}
1191
1192
paul4dadc292005-05-06 21:37:42 +00001193static void
paul147193a2003-04-19 00:31:59 +00001194ospf_abr_announce_rtr (struct ospf *ospf,
1195 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +00001196{
hasso52dc7ee2004-09-23 19:18:23 +00001197 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001198 struct ospf_area *area;
1199
1200 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001201 zlog_debug ("ospf_abr_announce_rtr(): Start");
paul718e3742002-12-13 20:15:29 +00001202
paul1eb8ef22005-04-07 07:30:20 +00001203 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001204 {
paul718e3742002-12-13 20:15:29 +00001205 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001206 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001207 inet_ntoa (area->area_id));
1208
1209 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
1210 continue;
1211
1212 if (ospf_abr_nexthops_belong_to_area (or, area))
1213 continue;
1214
1215 if (area->external_routing != OSPF_AREA_DEFAULT)
1216 {
1217 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001218 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001219 "area %s doesn't support external routing",
1220 inet_ntoa(area->area_id));
1221 continue;
1222 }
1223
1224 if (or->path_type == OSPF_PATH_INTER_AREA)
1225 {
1226 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001227 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001228 "this is inter-area route to %s", inet_ntoa (p->prefix));
1229 if (!OSPF_IS_AREA_BACKBONE (area))
1230 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1231 }
1232
1233 if (or->path_type == OSPF_PATH_INTRA_AREA)
1234 {
1235 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001236 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001237 "this is intra-area route to %s", inet_ntoa (p->prefix));
1238 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1239 }
1240 }
1241
1242 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001243 zlog_debug ("ospf_abr_announce_rtr(): Stop");
paul718e3742002-12-13 20:15:29 +00001244}
1245
paul4dadc292005-05-06 21:37:42 +00001246static void
paul147193a2003-04-19 00:31:59 +00001247ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt)
paul718e3742002-12-13 20:15:29 +00001248{
paul718e3742002-12-13 20:15:29 +00001249 struct ospf_route *or;
paul147193a2003-04-19 00:31:59 +00001250 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +00001251 struct list *l;
1252
1253 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001254 zlog_debug ("ospf_abr_process_router_rt(): Start");
paul718e3742002-12-13 20:15:29 +00001255
1256 for (rn = route_top (rt); rn; rn = route_next (rn))
1257 {
paul1eb8ef22005-04-07 07:30:20 +00001258 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001259 char flag = 0;
1260 struct ospf_route *best = NULL;
1261
1262 if (rn->info == NULL)
1263 continue;
1264
1265 l = rn->info;
1266
1267 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001268 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
paul718e3742002-12-13 20:15:29 +00001269 inet_ntoa (rn->p.u.prefix4));
1270
paul1eb8ef22005-04-07 07:30:20 +00001271 for (ALL_LIST_ELEMENTS (l, node, nnode, or))
paul718e3742002-12-13 20:15:29 +00001272 {
paul147193a2003-04-19 00:31:59 +00001273 if (!ospf_area_lookup_by_area_id (ospf, or->u.std.area_id))
paul718e3742002-12-13 20:15:29 +00001274 {
1275 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001276 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
paul718e3742002-12-13 20:15:29 +00001277 inet_ntoa (or->u.std.area_id));
1278 continue;
1279 }
1280
1281
1282 if (!CHECK_FLAG (or->u.std.flags, ROUTER_LSA_EXTERNAL))
1283 {
1284 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001285 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001286 "This is not an ASBR, skipping");
1287 continue;
1288 }
1289
1290 if (!flag)
1291 {
paul147193a2003-04-19 00:31:59 +00001292 best = ospf_find_asbr_route (ospf, rt,
1293 (struct prefix_ipv4 *) &rn->p);
paul718e3742002-12-13 20:15:29 +00001294 flag = 1;
1295 }
1296
1297 if (best == NULL)
1298 continue;
1299
1300 if (or != best)
1301 {
1302 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001303 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001304 "This route is not the best among possible, skipping");
1305 continue;
1306 }
1307
1308 if (or->path_type == OSPF_PATH_INTER_AREA &&
1309 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1310 {
1311 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001312 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001313 "This route is not a backbone one, skipping");
1314 continue;
1315 }
1316
1317 if (or->cost >= OSPF_LS_INFINITY)
1318 {
1319 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001320 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001321 "This route has LS_INFINITY metric, skipping");
1322 continue;
1323 }
1324
paul147193a2003-04-19 00:31:59 +00001325 if (ospf->abr_type == OSPF_ABR_CISCO
1326 || ospf->abr_type == OSPF_ABR_IBM)
1327 if (!ospf_act_bb_connection (ospf)
1328 && or->path_type != OSPF_PATH_INTRA_AREA)
paul718e3742002-12-13 20:15:29 +00001329 {
1330 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001331 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
paul718e3742002-12-13 20:15:29 +00001332 "No BB connection, skip not intra-area routes");
1333 continue;
1334 }
1335
paul147193a2003-04-19 00:31:59 +00001336 ospf_abr_announce_rtr (ospf, (struct prefix_ipv4 *) &rn->p, or);
paul718e3742002-12-13 20:15:29 +00001337
1338 }
1339
1340 }
1341
1342 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001343 zlog_debug ("ospf_abr_process_router_rt(): Stop");
paul718e3742002-12-13 20:15:29 +00001344}
1345
paul4dadc292005-05-06 21:37:42 +00001346static void
paul147193a2003-04-19 00:31:59 +00001347ospf_abr_unapprove_translates (struct ospf *ospf) /* For NSSA Translations */
paul718e3742002-12-13 20:15:29 +00001348{
paul147193a2003-04-19 00:31:59 +00001349 struct ospf_lsa *lsa;
1350 struct route_node *rn;
1351
paul718e3742002-12-13 20:15:29 +00001352 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001353 zlog_debug ("ospf_abr_unapprove_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001354
1355 /* NSSA Translator is not checked, because it may have gone away,
1356 and we would want to flush any residuals anyway */
1357
paul147193a2003-04-19 00:31:59 +00001358 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1359 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
pauld4a53d52003-07-12 21:30:57 +00001360 {
1361 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1362 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001363 zlog_debug ("ospf_abr_unapprove_translates(): "
pauld4a53d52003-07-12 21:30:57 +00001364 "approved unset on link id %s",
1365 inet_ntoa (lsa->data->id));
1366 }
paul718e3742002-12-13 20:15:29 +00001367
1368 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001369 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001370}
paul718e3742002-12-13 20:15:29 +00001371
paul4dadc292005-05-06 21:37:42 +00001372static void
paul147193a2003-04-19 00:31:59 +00001373ospf_abr_unapprove_summaries (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001374{
hasso52dc7ee2004-09-23 19:18:23 +00001375 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001376 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001377 struct route_node *rn;
1378 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +00001379
1380 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001381 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
paul718e3742002-12-13 20:15:29 +00001382
paul1eb8ef22005-04-07 07:30:20 +00001383 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001384 {
pauld4a53d52003-07-12 21:30:57 +00001385 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001386 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001387 "considering area %s",
1388 inet_ntoa (area->area_id));
paul147193a2003-04-19 00:31:59 +00001389 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001390 if (ospf_lsa_is_self_originated (ospf, lsa))
1391 {
1392 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001393 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001394 "approved unset on summary link id %s",
1395 inet_ntoa (lsa->data->id));
1396 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1397 }
paul147193a2003-04-19 00:31:59 +00001398
1399 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001400 if (ospf_lsa_is_self_originated (ospf, lsa))
1401 {
1402 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001403 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001404 "approved unset on asbr-summary link id %s",
1405 inet_ntoa (lsa->data->id));
1406 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1407 }
paul718e3742002-12-13 20:15:29 +00001408 }
1409
1410 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001411 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
paul718e3742002-12-13 20:15:29 +00001412}
1413
paul4dadc292005-05-06 21:37:42 +00001414static void
paul147193a2003-04-19 00:31:59 +00001415ospf_abr_prepare_aggregates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001416{
hasso52dc7ee2004-09-23 19:18:23 +00001417 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001418 struct route_node *rn;
1419 struct ospf_area_range *range;
paul1eb8ef22005-04-07 07:30:20 +00001420 struct ospf_area *area;
paul718e3742002-12-13 20:15:29 +00001421
1422 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001423 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001424
paul1eb8ef22005-04-07 07:30:20 +00001425 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001426 {
paul718e3742002-12-13 20:15:29 +00001427 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1428 if ((range = rn->info) != NULL)
1429 {
1430 range->cost = 0;
1431 range->specifics = 0;
1432 }
1433 }
1434
1435 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001436 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001437}
1438
paul4dadc292005-05-06 21:37:42 +00001439static void
paul147193a2003-04-19 00:31:59 +00001440ospf_abr_announce_aggregates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001441{
1442 struct ospf_area *area, *ar;
1443 struct ospf_area_range *range;
1444 struct route_node *rn;
pauld4a53d52003-07-12 21:30:57 +00001445 struct prefix p;
hasso52dc7ee2004-09-23 19:18:23 +00001446 struct listnode *node, *n;
paul718e3742002-12-13 20:15:29 +00001447
1448 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001449 zlog_debug ("ospf_abr_announce_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001450
paul1eb8ef22005-04-07 07:30:20 +00001451 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001452 {
paul718e3742002-12-13 20:15:29 +00001453 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001454 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001455 inet_ntoa (area->area_id));
1456
1457 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1458 if ((range = rn->info))
1459 {
1460 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1461 {
1462 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001463 zlog_debug ("ospf_abr_announce_aggregates():"
paul718e3742002-12-13 20:15:29 +00001464 " discarding suppress-ranges");
1465 continue;
1466 }
1467
1468 p.family = AF_INET;
pauld4a53d52003-07-12 21:30:57 +00001469 p.u.prefix4 = range->addr;
paul718e3742002-12-13 20:15:29 +00001470 p.prefixlen = range->masklen;
1471
1472 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001473 zlog_debug ("ospf_abr_announce_aggregates():"
paul718e3742002-12-13 20:15:29 +00001474 " this is range: %s/%d",
pauld4a53d52003-07-12 21:30:57 +00001475 inet_ntoa (p.u.prefix4), p.prefixlen);
paul718e3742002-12-13 20:15:29 +00001476
1477 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1478 {
1479 p.family = AF_INET;
pauld4a53d52003-07-12 21:30:57 +00001480 p.u.prefix4 = range->subst_addr;
paul718e3742002-12-13 20:15:29 +00001481 p.prefixlen = range->subst_masklen;
1482 }
1483
1484 if (range->specifics)
1485 {
1486 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001487 zlog_debug ("ospf_abr_announce_aggregates(): active range");
paul718e3742002-12-13 20:15:29 +00001488
paul1eb8ef22005-04-07 07:30:20 +00001489 for (ALL_LIST_ELEMENTS_RO (ospf->areas, n, ar))
paul718e3742002-12-13 20:15:29 +00001490 {
paul718e3742002-12-13 20:15:29 +00001491 if (ar == area)
1492 continue;
1493
1494 /* We do not check nexthops here, because
1495 intra-area routes can be associated with
1496 one area only */
1497
1498 /* backbone routes are not summarized
1499 when announced into transit areas */
1500
1501 if (ospf_area_is_transit (ar) &&
1502 OSPF_IS_AREA_BACKBONE (area))
1503 {
1504 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001505 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
paul718e3742002-12-13 20:15:29 +00001506 "announcement of BB aggregate into"
1507 " a transit area");
1508 continue;
1509 }
hassofa2b17e2004-03-04 17:45:00 +00001510 ospf_abr_announce_network_to_area ((struct prefix_ipv4 *)&p, range->cost, ar);
paul718e3742002-12-13 20:15:29 +00001511 }
1512 }
1513 }
1514 }
1515
1516 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001517 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001518}
1519
paul4dadc292005-05-06 21:37:42 +00001520static void
paul147193a2003-04-19 00:31:59 +00001521ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */
paul718e3742002-12-13 20:15:29 +00001522{
hasso52dc7ee2004-09-23 19:18:23 +00001523 struct listnode *node; /*, n; */
paul718e3742002-12-13 20:15:29 +00001524 struct ospf_area *area; /*, *ar; */
1525 struct route_node *rn;
1526 struct ospf_area_range *range;
1527 struct prefix_ipv4 p;
1528
1529 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001530 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001531
paul1eb8ef22005-04-07 07:30:20 +00001532 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001533 {
paule2c6c152003-06-22 08:49:25 +00001534 if (! area->NSSATranslatorState)
paul718e3742002-12-13 20:15:29 +00001535 continue;
1536
1537 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001538 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001539 inet_ntoa (area->area_id));
1540
1541 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1542 {
1543 if (rn->info == NULL)
1544 continue;
1545
1546 range = rn->info;
1547
1548 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1549 {
1550 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001551 zlog_debug ("ospf_abr_send_nssa_aggregates():"
paul718e3742002-12-13 20:15:29 +00001552 " discarding suppress-ranges");
1553 continue;
1554 }
1555
1556 p.family = AF_INET;
1557 p.prefix = range->addr;
1558 p.prefixlen = range->masklen;
1559
1560 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001561 zlog_debug ("ospf_abr_send_nssa_aggregates():"
paul718e3742002-12-13 20:15:29 +00001562 " this is range: %s/%d",
1563 inet_ntoa (p.prefix), p.prefixlen);
1564
1565 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1566 {
1567 p.family = AF_INET;
1568 p.prefix = range->subst_addr;
1569 p.prefixlen = range->subst_masklen;
1570 }
1571
1572 if (range->specifics)
paule2c6c152003-06-22 08:49:25 +00001573 {
1574 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001575 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
paul718e3742002-12-13 20:15:29 +00001576
paule2c6c152003-06-22 08:49:25 +00001577 /* Fetch LSA-Type-7 from aggregate prefix, and then
1578 * translate, Install (as Type-5), Approve, and Flood
1579 */
1580 ospf_abr_translate_nssa_range (&p, range->cost);
1581 }
1582 } /* all area ranges*/
paul718e3742002-12-13 20:15:29 +00001583 } /* all areas */
1584
1585 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001586 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001587}
1588
paul4dadc292005-05-06 21:37:42 +00001589static void
paul147193a2003-04-19 00:31:59 +00001590ospf_abr_announce_stub_defaults (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001591{
hasso52dc7ee2004-09-23 19:18:23 +00001592 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001593 struct ospf_area *area;
1594 struct prefix_ipv4 p;
1595
paul147193a2003-04-19 00:31:59 +00001596 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001597 return;
1598
1599 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001600 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
paul718e3742002-12-13 20:15:29 +00001601
1602 p.family = AF_INET;
1603 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1604 p.prefixlen = 0;
1605
paul1eb8ef22005-04-07 07:30:20 +00001606 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001607 {
paul718e3742002-12-13 20:15:29 +00001608 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001609 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1610 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001611
pauld4a53d52003-07-12 21:30:57 +00001612 if ( (area->external_routing != OSPF_AREA_STUB)
pauld4a53d52003-07-12 21:30:57 +00001613 && (area->external_routing != OSPF_AREA_NSSA)
pauld4a53d52003-07-12 21:30:57 +00001614 )
1615 continue;
paul718e3742002-12-13 20:15:29 +00001616
1617 if (OSPF_IS_AREA_BACKBONE (area))
pauld4a53d52003-07-12 21:30:57 +00001618 continue; /* Sanity Check */
1619
paul718e3742002-12-13 20:15:29 +00001620 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001621 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1622 "announcing 0.0.0.0/0 to area %s",
pauld4a53d52003-07-12 21:30:57 +00001623 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001624 ospf_abr_announce_network_to_area (&p, area->default_cost, area);
1625 }
1626
1627 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001628 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
paul718e3742002-12-13 20:15:29 +00001629}
1630
paul4dadc292005-05-06 21:37:42 +00001631static int
paul147193a2003-04-19 00:31:59 +00001632ospf_abr_remove_unapproved_translates_apply (struct ospf *ospf,
1633 struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001634{
1635 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)
1636 && ! CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1637 {
1638 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1639 "removing unapproved translates, ID: %s",
1640 inet_ntoa (lsa->data->id));
1641
1642 /* FLUSH THROUGHOUT AS */
paul147193a2003-04-19 00:31:59 +00001643 ospf_lsa_flush_as (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001644
1645 /* DISCARD from LSDB */
1646 }
1647 return 0;
1648}
1649
paul4dadc292005-05-06 21:37:42 +00001650static void
paul147193a2003-04-19 00:31:59 +00001651ospf_abr_remove_unapproved_translates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001652{
paul147193a2003-04-19 00:31:59 +00001653 struct route_node *rn;
1654 struct ospf_lsa *lsa;
1655
paul718e3742002-12-13 20:15:29 +00001656 /* All AREA PROCESS should have APPROVED necessary LSAs */
1657 /* Remove any left over and not APPROVED */
1658 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001659 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001660
paul147193a2003-04-19 00:31:59 +00001661 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1662 ospf_abr_remove_unapproved_translates_apply (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001663
1664 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001665 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001666}
paul718e3742002-12-13 20:15:29 +00001667
paul4dadc292005-05-06 21:37:42 +00001668static void
paul147193a2003-04-19 00:31:59 +00001669ospf_abr_remove_unapproved_summaries (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001670{
hasso52dc7ee2004-09-23 19:18:23 +00001671 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001672 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001673 struct route_node *rn;
1674 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +00001675
1676 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001677 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
paul718e3742002-12-13 20:15:29 +00001678
paul1eb8ef22005-04-07 07:30:20 +00001679 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001680 {
paul718e3742002-12-13 20:15:29 +00001681 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001682 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
paul718e3742002-12-13 20:15:29 +00001683 "looking at area %s", inet_ntoa (area->area_id));
1684
paul147193a2003-04-19 00:31:59 +00001685 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
1686 if (ospf_lsa_is_self_originated (ospf, lsa))
1687 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1688 ospf_lsa_flush_area (lsa, area);
1689
1690 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
1691 if (ospf_lsa_is_self_originated (ospf, lsa))
1692 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1693 ospf_lsa_flush_area (lsa, area);
paul718e3742002-12-13 20:15:29 +00001694 }
1695
1696 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001697 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
paul718e3742002-12-13 20:15:29 +00001698}
1699
paul4dadc292005-05-06 21:37:42 +00001700static void
paul147193a2003-04-19 00:31:59 +00001701ospf_abr_manage_discard_routes (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001702{
paul1eb8ef22005-04-07 07:30:20 +00001703 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001704 struct route_node *rn;
1705 struct ospf_area *area;
1706 struct ospf_area_range *range;
1707
paul1eb8ef22005-04-07 07:30:20 +00001708 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
1709 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1710 if ((range = rn->info) != NULL)
1711 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1712 {
1713 if (range->specifics)
1714 ospf_add_discard_route (ospf->new_table, area,
1715 (struct prefix_ipv4 *) &rn->p);
1716 else
JR Rivers8fc9e002012-09-24 17:26:46 +00001717 ospf_delete_discard_route (ospf->new_table,
1718 (struct prefix_ipv4 *) &rn->p);
paul1eb8ef22005-04-07 07:30:20 +00001719 }
paul718e3742002-12-13 20:15:29 +00001720}
1721
paul718e3742002-12-13 20:15:29 +00001722/* This is the function taking care about ABR NSSA, i.e. NSSA
1723 Translator, -LSA aggregation and flooding. For all NSSAs
1724
1725 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1726 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1727 with the P-bit set.
1728
1729 Any received Type-5s are legal for an ABR, else illegal for IR.
1730 Received Type-7s are installed, by area, with incoming P-bit. They
1731 are flooded; if the Elected NSSA Translator, then P-bit off.
1732
1733 Additionally, this ABR will place "translated type-7's" into the
1734 Type-5 LSDB in order to keep track of APPROVAL or not.
1735
1736 It will scan through every area, looking for Type-7 LSAs with P-Bit
1737 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1738 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1739 5-INSTALLED.
1740
1741 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1742 left over are FLUSHED and DISCARDED.
1743
1744 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1745 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1746
paul4dadc292005-05-06 21:37:42 +00001747static void
paul147193a2003-04-19 00:31:59 +00001748ospf_abr_nssa_task (struct ospf *ospf) /* called only if any_nssa */
paul718e3742002-12-13 20:15:29 +00001749{
1750 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001751 zlog_debug ("Check for NSSA-ABR Tasks():");
paul718e3742002-12-13 20:15:29 +00001752
paul147193a2003-04-19 00:31:59 +00001753 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001754 return;
1755
paul147193a2003-04-19 00:31:59 +00001756 if (! ospf->anyNSSA)
paul718e3742002-12-13 20:15:29 +00001757 return;
1758
1759 /* Each area must confirm TranslatorRole */
1760 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001761 zlog_debug ("ospf_abr_nssa_task(): Start");
paul718e3742002-12-13 20:15:29 +00001762
1763 /* For all Global Entries flagged "local-translate", unset APPROVED */
1764 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001765 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
paul718e3742002-12-13 20:15:29 +00001766
paul147193a2003-04-19 00:31:59 +00001767 ospf_abr_unapprove_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001768
1769 /* RESET all Ranges in every Area, same as summaries */
1770 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001771 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
paule2c6c152003-06-22 08:49:25 +00001772 ospf_abr_prepare_aggregates (ospf); /*TURNED OFF just for now */
paul718e3742002-12-13 20:15:29 +00001773
1774 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
paule2c6c152003-06-22 08:49:25 +00001775 * Aggregate as Type-7
1776 * Install or Approve in Type-5 Global LSDB
1777 */
paul718e3742002-12-13 20:15:29 +00001778 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001779 zlog_debug ("ospf_abr_nssa_task(): process translates");
paul147193a2003-04-19 00:31:59 +00001780 ospf_abr_process_nssa_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001781
1782 /* Translate/Send any "ranged" aggregates, and also 5-Install and
paule2c6c152003-06-22 08:49:25 +00001783 * Approve
1784 * Scan Type-7's for aggregates, translate to Type-5's,
1785 * Install/Flood/Approve
1786 */
paul718e3742002-12-13 20:15:29 +00001787 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001788 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
paule2c6c152003-06-22 08:49:25 +00001789 ospf_abr_send_nssa_aggregates (ospf); /*TURNED OFF FOR NOW */
paul718e3742002-12-13 20:15:29 +00001790
pauld4a53d52003-07-12 21:30:57 +00001791 /* Send any NSSA defaults as Type-5
1792 *if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001793 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
pauld4a53d52003-07-12 21:30:57 +00001794 *ospf_abr_announce_nssa_defaults (ospf);
1795 * havnt a clue what above is supposed to do.
1796 */
paul718e3742002-12-13 20:15:29 +00001797
1798 /* Flush any unapproved previous translates from Global Data Base */
1799 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001800 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
paul147193a2003-04-19 00:31:59 +00001801 ospf_abr_remove_unapproved_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001802
paul147193a2003-04-19 00:31:59 +00001803 ospf_abr_manage_discard_routes (ospf); /* same as normal...discard */
paul718e3742002-12-13 20:15:29 +00001804
1805 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001806 zlog_debug ("ospf_abr_nssa_task(): Stop");
paul718e3742002-12-13 20:15:29 +00001807}
paul718e3742002-12-13 20:15:29 +00001808
1809/* This is the function taking care about ABR stuff, i.e.
1810 summary-LSA origination and flooding. */
1811void
paul147193a2003-04-19 00:31:59 +00001812ospf_abr_task (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001813{
1814 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001815 zlog_debug ("ospf_abr_task(): Start");
paul718e3742002-12-13 20:15:29 +00001816
paul147193a2003-04-19 00:31:59 +00001817 if (ospf->new_table == NULL || ospf->new_rtrs == NULL)
paul718e3742002-12-13 20:15:29 +00001818 {
1819 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001820 zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
paul718e3742002-12-13 20:15:29 +00001821 return;
1822 }
1823
1824 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001825 zlog_debug ("ospf_abr_task(): unapprove summaries");
paul147193a2003-04-19 00:31:59 +00001826 ospf_abr_unapprove_summaries (ospf);
paul718e3742002-12-13 20:15:29 +00001827
1828 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001829 zlog_debug ("ospf_abr_task(): prepare aggregates");
paul147193a2003-04-19 00:31:59 +00001830 ospf_abr_prepare_aggregates (ospf);
paul718e3742002-12-13 20:15:29 +00001831
paul147193a2003-04-19 00:31:59 +00001832 if (IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001833 {
1834 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001835 zlog_debug ("ospf_abr_task(): process network RT");
paul147193a2003-04-19 00:31:59 +00001836 ospf_abr_process_network_rt (ospf, ospf->new_table);
paul718e3742002-12-13 20:15:29 +00001837
1838 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001839 zlog_debug ("ospf_abr_task(): process router RT");
paul147193a2003-04-19 00:31:59 +00001840 ospf_abr_process_router_rt (ospf, ospf->new_rtrs);
paul718e3742002-12-13 20:15:29 +00001841
1842 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001843 zlog_debug ("ospf_abr_task(): announce aggregates");
paul147193a2003-04-19 00:31:59 +00001844 ospf_abr_announce_aggregates (ospf);
paul718e3742002-12-13 20:15:29 +00001845
1846 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001847 zlog_debug ("ospf_abr_task(): announce stub defaults");
paul147193a2003-04-19 00:31:59 +00001848 ospf_abr_announce_stub_defaults (ospf);
paul718e3742002-12-13 20:15:29 +00001849 }
1850
1851 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001852 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
paul147193a2003-04-19 00:31:59 +00001853 ospf_abr_remove_unapproved_summaries (ospf);
paul718e3742002-12-13 20:15:29 +00001854
paul147193a2003-04-19 00:31:59 +00001855 ospf_abr_manage_discard_routes (ospf);
paul718e3742002-12-13 20:15:29 +00001856
paul718e3742002-12-13 20:15:29 +00001857 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001858 zlog_debug ("ospf_abr_task(): Stop");
paul718e3742002-12-13 20:15:29 +00001859}
1860
paul4dadc292005-05-06 21:37:42 +00001861static int
paul147193a2003-04-19 00:31:59 +00001862ospf_abr_task_timer (struct thread *thread)
paul718e3742002-12-13 20:15:29 +00001863{
paul147193a2003-04-19 00:31:59 +00001864 struct ospf *ospf = THREAD_ARG (thread);
1865
1866 ospf->t_abr_task = 0;
paul718e3742002-12-13 20:15:29 +00001867
1868 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001869 zlog_debug ("Running ABR task on timer");
paul718e3742002-12-13 20:15:29 +00001870
paul147193a2003-04-19 00:31:59 +00001871 ospf_check_abr_status (ospf);
pauld4a53d52003-07-12 21:30:57 +00001872 ospf_abr_nssa_check_status (ospf);
paul718e3742002-12-13 20:15:29 +00001873
paul147193a2003-04-19 00:31:59 +00001874 ospf_abr_task (ospf);
paule2c6c152003-06-22 08:49:25 +00001875 ospf_abr_nssa_task (ospf); /* if nssa-abr, then scan Type-7 LSDB */
paul718e3742002-12-13 20:15:29 +00001876
paul147193a2003-04-19 00:31:59 +00001877 return 0;
paul718e3742002-12-13 20:15:29 +00001878}
1879
1880void
paul147193a2003-04-19 00:31:59 +00001881ospf_schedule_abr_task (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001882{
1883 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001884 zlog_debug ("Scheduling ABR task");
paul147193a2003-04-19 00:31:59 +00001885
1886 if (ospf->t_abr_task == NULL)
1887 ospf->t_abr_task = thread_add_timer (master, ospf_abr_task_timer,
1888 ospf, OSPF_ABR_TASK_DELAY);
paul718e3742002-12-13 20:15:29 +00001889}