blob: f5edc99e5ac07053a1fb6494d0328a974bd31f73 [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"
paul718e3742002-12-13 20:15:29 +000053
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 {
136 rn = route_node_get (area->ranges, (struct prefix *) &p);
137 rn = route_next (rn);
138 }
139
140 for (; rn; rn = route_next (rn))
141 if (rn->info)
142 break;
143
144 if (rn && rn->info)
145 {
146 find = rn->info;
147 *range_net = rn->p.u.prefix4;
148 route_unlock_node (rn);
149 return find;
150 }
151 return NULL;
152}
153
paul4dadc292005-05-06 21:37:42 +0000154static struct ospf_area_range *
paul718e3742002-12-13 20:15:29 +0000155ospf_area_range_match (struct ospf_area *area, struct prefix_ipv4 *p)
156{
157 struct route_node *node;
158
159 node = route_node_match (area->ranges, (struct prefix *) p);
160 if (node)
161 {
162 route_unlock_node (node);
163 return node->info;
164 }
165 return NULL;
166}
167
168struct ospf_area_range *
169ospf_area_range_match_any (struct ospf *ospf, struct prefix_ipv4 *p)
170{
171 struct ospf_area_range *range;
paul1eb8ef22005-04-07 07:30:20 +0000172 struct ospf_area *area;
hasso52dc7ee2004-09-23 19:18:23 +0000173 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000174
paul1eb8ef22005-04-07 07:30:20 +0000175 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
176 if ((range = ospf_area_range_match (area, p)))
paul718e3742002-12-13 20:15:29 +0000177 return range;
178
179 return NULL;
180}
181
182int
183ospf_area_range_active (struct ospf_area_range *range)
184{
185 return range->specifics;
186}
187
paul4dadc292005-05-06 21:37:42 +0000188static int
paul718e3742002-12-13 20:15:29 +0000189ospf_area_actively_attached (struct ospf_area *area)
190{
191 return area->act_ints;
192}
193
194int
195ospf_area_range_set (struct ospf *ospf, struct in_addr area_id,
196 struct prefix_ipv4 *p, int advertise)
197{
198 struct ospf_area *area;
199 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000200 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000201
paul147193a2003-04-19 00:31:59 +0000202 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000203 if (area == NULL)
204 return 0;
205
206 range = ospf_area_range_lookup (area, p);
207 if (range != NULL)
208 {
209 if ((CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
210 && !CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
211 || (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
212 && CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE)))
paul147193a2003-04-19 00:31:59 +0000213 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000214 }
215 else
216 {
217 range = ospf_area_range_new (p);
218 ospf_area_range_add (area, range);
paul147193a2003-04-19 00:31:59 +0000219 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000220 }
221
222 if (CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
223 SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
224 else
225 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
226
227 return 1;
228}
229
230int
231ospf_area_range_cost_set (struct ospf *ospf, struct in_addr area_id,
232 struct prefix_ipv4 *p, u_int32_t cost)
233{
234 struct ospf_area *area;
235 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000236 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000237
paul147193a2003-04-19 00:31:59 +0000238 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000239 if (area == NULL)
240 return 0;
241
Paul Jakma214a4452006-05-12 22:51:49 +0000242 range = ospf_area_range_lookup (area, p);
paul718e3742002-12-13 20:15:29 +0000243 if (range == NULL)
244 return 0;
245
246 if (range->cost_config != cost)
247 {
248 range->cost_config = cost;
249 if (ospf_area_range_active (range))
paul147193a2003-04-19 00:31:59 +0000250 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000251 }
252
253 return 1;
254}
255
256int
257ospf_area_range_unset (struct ospf *ospf, struct in_addr area_id,
258 struct prefix_ipv4 *p)
259{
260 struct ospf_area *area;
JR Rivers8fc9e002012-09-24 17:26:46 +0000261 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +0000262
paul147193a2003-04-19 00:31:59 +0000263 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000264 if (area == NULL)
265 return 0;
266
JR Rivers8fc9e002012-09-24 17:26:46 +0000267 rn = route_node_lookup (area->ranges, (struct prefix*)p);
268 if (rn == NULL)
paul718e3742002-12-13 20:15:29 +0000269 return 0;
270
JR Rivers8fc9e002012-09-24 17:26:46 +0000271 if (ospf_area_range_active (rn->info))
paul147193a2003-04-19 00:31:59 +0000272 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000273
JR Rivers8fc9e002012-09-24 17:26:46 +0000274 ospf_area_range_delete (area, rn);
paul718e3742002-12-13 20:15:29 +0000275
276 return 1;
277}
278
279int
280ospf_area_range_substitute_set (struct ospf *ospf, struct in_addr area_id,
281 struct prefix_ipv4 *p, struct prefix_ipv4 *s)
282{
283 struct ospf_area *area;
284 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000285 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000286
paul147193a2003-04-19 00:31:59 +0000287 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000288 range = ospf_area_range_lookup (area, p);
289
290 if (range != NULL)
291 {
292 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE) ||
293 !CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
paul147193a2003-04-19 00:31:59 +0000294 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000295 }
296 else
297 {
298 range = ospf_area_range_new (p);
299 ospf_area_range_add (area, range);
paul147193a2003-04-19 00:31:59 +0000300 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000301 }
302
303 SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
304 SET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
305 range->subst_addr = s->prefix;
306 range->subst_masklen = s->prefixlen;
307
308 return 1;
309}
310
311int
312ospf_area_range_substitute_unset (struct ospf *ospf, struct in_addr area_id,
313 struct prefix_ipv4 *p)
314{
315 struct ospf_area *area;
316 struct ospf_area_range *range;
317
paul147193a2003-04-19 00:31:59 +0000318 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000319 if (area == NULL)
320 return 0;
321
322 range = ospf_area_range_lookup (area, p);
323 if (range == NULL)
324 return 0;
325
326 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
327 if (ospf_area_range_active (range))
paul147193a2003-04-19 00:31:59 +0000328 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000329
330 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
331 range->subst_addr.s_addr = 0;
332 range->subst_masklen = 0;
333
334 return 1;
335}
336
337int
paul147193a2003-04-19 00:31:59 +0000338ospf_act_bb_connection (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000339{
paul147193a2003-04-19 00:31:59 +0000340 if (ospf->backbone == NULL)
paul718e3742002-12-13 20:15:29 +0000341 return 0;
342
paul147193a2003-04-19 00:31:59 +0000343 return ospf->backbone->full_nbrs;
paul718e3742002-12-13 20:15:29 +0000344}
345
paule2c6c152003-06-22 08:49:25 +0000346/* Determine whether this router is elected translator or not for area */
paul4dadc292005-05-06 21:37:42 +0000347static int
paule2c6c152003-06-22 08:49:25 +0000348ospf_abr_nssa_am_elected (struct ospf_area *area)
349{
350 struct route_node *rn;
351 struct ospf_lsa *lsa;
352 struct router_lsa *rlsa;
353 struct in_addr *best = NULL;
354
355 LSDB_LOOP ( ROUTER_LSDB (area), rn, lsa)
356 {
357 /* sanity checks */
358 if (!lsa
359 || (lsa->data->type != OSPF_ROUTER_LSA)
360 || IS_LSA_SELF (lsa))
361 continue;
362
363 rlsa = (struct router_lsa *) lsa->data;
364
365 /* ignore non-ABR routers */
366 if (!IS_ROUTER_LSA_BORDER (rlsa))
367 continue;
368
369 /* Router has Nt flag - always translate */
370 if (IS_ROUTER_LSA_NT (rlsa))
371 {
372 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000373 zlog_debug ("ospf_abr_nssa_am_elected: "
paule2c6c152003-06-22 08:49:25 +0000374 "router %s asserts Nt",
375 inet_ntoa (lsa->data->id) );
376 return 0;
377 }
378
379 if (best == NULL)
380 best = &lsa->data->id;
381 else
Denis Ovsienko4e677f52011-12-18 16:27:02 +0400382 if (IPV4_ADDR_CMP (&best->s_addr, &lsa->data->id.s_addr) < 0)
paule2c6c152003-06-22 08:49:25 +0000383 best = &lsa->data->id;
384 }
385
386 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000387 zlog_debug ("ospf_abr_nssa_am_elected: best electable ABR is: %s",
paule2c6c152003-06-22 08:49:25 +0000388 (best) ? inet_ntoa (*best) : "<none>" );
389
390 if (best == NULL)
391 return 1;
392
Denis Ovsienko4e677f52011-12-18 16:27:02 +0400393 if (IPV4_ADDR_CMP (&best->s_addr, &area->ospf->router_id.s_addr) < 0)
paule2c6c152003-06-22 08:49:25 +0000394 return 1;
395 else
396 return 0;
397}
398
399/* Check NSSA ABR status
400 * assumes there are nssa areas
401 */
paul4dadc292005-05-06 21:37:42 +0000402static void
paule2c6c152003-06-22 08:49:25 +0000403ospf_abr_nssa_check_status (struct ospf *ospf)
404{
405 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000406 struct listnode *lnode, *nnode;
Paul Jakma9560fa82006-06-26 12:50:06 +0000407
paul1eb8ef22005-04-07 07:30:20 +0000408 for (ALL_LIST_ELEMENTS (ospf->areas, lnode, nnode, area))
paule2c6c152003-06-22 08:49:25 +0000409 {
Paul Jakma9560fa82006-06-26 12:50:06 +0000410 u_char old_state = area->NSSATranslatorState;
411
paule2c6c152003-06-22 08:49:25 +0000412 if (area->external_routing != OSPF_AREA_NSSA)
413 continue;
Paul Jakma9560fa82006-06-26 12:50:06 +0000414
paule2c6c152003-06-22 08:49:25 +0000415 if (IS_DEBUG_OSPF (nssa, NSSA))
ajse84cc642004-12-08 17:28:56 +0000416 zlog_debug ("ospf_abr_nssa_check_status: "
paule2c6c152003-06-22 08:49:25 +0000417 "checking area %s",
418 inet_ntoa (area->area_id));
Paul Jakma9560fa82006-06-26 12:50:06 +0000419
paule2c6c152003-06-22 08:49:25 +0000420 if (!IS_OSPF_ABR (area->ospf))
421 {
422 if (IS_DEBUG_OSPF (nssa, NSSA))
Paul Jakma9560fa82006-06-26 12:50:06 +0000423 zlog_debug ("ospf_abr_nssa_check_status: "
424 "not ABR");
pauld4a53d52003-07-12 21:30:57 +0000425 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
paule2c6c152003-06-22 08:49:25 +0000426 }
Paul Jakma9560fa82006-06-26 12:50:06 +0000427 else
428 {
429 switch (area->NSSATranslatorRole)
430 {
431 case OSPF_NSSA_ROLE_NEVER:
432 /* We never Translate Type-7 LSA. */
433 /* TODO: check previous state and flush? */
434 if (IS_DEBUG_OSPF (nssa, NSSA))
435 zlog_debug ("ospf_abr_nssa_check_status: "
436 "never translate");
437 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
438 break;
439
440 case OSPF_NSSA_ROLE_ALWAYS:
441 /* We always translate if we are an ABR
442 * TODO: originate new LSAs if state change?
443 * or let the nssa abr task take care of it?
444 */
445 if (IS_DEBUG_OSPF (nssa, NSSA))
446 zlog_debug ("ospf_abr_nssa_check_status: "
447 "translate always");
448 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
449 break;
450
451 case OSPF_NSSA_ROLE_CANDIDATE:
452 /* We are a candidate for Translation */
453 if (ospf_abr_nssa_am_elected (area) > 0)
454 {
455 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
456 if (IS_DEBUG_OSPF (nssa, NSSA))
457 zlog_debug ("ospf_abr_nssa_check_status: "
458 "elected translator");
459 }
460 else
461 {
462 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
463 if (IS_DEBUG_OSPF (nssa, NSSA))
464 zlog_debug ("ospf_abr_nssa_check_status: " "not elected");
465 }
466 break;
467 }
468 }
469 /* RFC3101, 3.1:
470 * All NSSA border routers must set the E-bit in the Type-1 router-LSAs
471 * of their directly attached non-stub areas, even when they are not
472 * translating.
473 */
474 if (old_state != area->NSSATranslatorState)
475 {
476 if (old_state == OSPF_NSSA_TRANSLATE_DISABLED)
477 ospf_asbr_status_update (ospf, ++ospf->redistribute);
478 else if (area->NSSATranslatorState == OSPF_NSSA_TRANSLATE_DISABLED)
479 ospf_asbr_status_update (ospf, --ospf->redistribute);
480 }
paule2c6c152003-06-22 08:49:25 +0000481 }
482}
paule2c6c152003-06-22 08:49:25 +0000483
paul718e3742002-12-13 20:15:29 +0000484/* Check area border router status. */
485void
paul147193a2003-04-19 00:31:59 +0000486ospf_check_abr_status (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000487{
488 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000489 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000490 int bb_configured = 0;
491 int bb_act_attached = 0;
492 int areas_configured = 0;
493 int areas_act_attached = 0;
paul147193a2003-04-19 00:31:59 +0000494 u_char new_flags = ospf->flags;
paul718e3742002-12-13 20:15:29 +0000495
496 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000497 zlog_debug ("ospf_check_abr_status(): Start");
paul718e3742002-12-13 20:15:29 +0000498
paul1eb8ef22005-04-07 07:30:20 +0000499 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
paul718e3742002-12-13 20:15:29 +0000500 {
paul718e3742002-12-13 20:15:29 +0000501 if (listcount (area->oiflist))
502 {
503 areas_configured++;
504
505 if (OSPF_IS_AREA_BACKBONE (area))
506 bb_configured = 1;
507 }
508
509 if (ospf_area_actively_attached (area))
510 {
511 areas_act_attached++;
512
513 if (OSPF_IS_AREA_BACKBONE (area))
514 bb_act_attached = 1;
515 }
516 }
517
518 if (IS_DEBUG_OSPF_EVENT)
519 {
ajse84cc642004-12-08 17:28:56 +0000520 zlog_debug ("ospf_check_abr_status(): looked through areas");
521 zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured);
522 zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
paul718e3742002-12-13 20:15:29 +0000523 bb_act_attached);
ajse84cc642004-12-08 17:28:56 +0000524 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
paul718e3742002-12-13 20:15:29 +0000525 areas_configured);
ajse84cc642004-12-08 17:28:56 +0000526 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
paul718e3742002-12-13 20:15:29 +0000527 areas_act_attached);
528 }
529
paul147193a2003-04-19 00:31:59 +0000530 switch (ospf->abr_type)
paul718e3742002-12-13 20:15:29 +0000531 {
532 case OSPF_ABR_SHORTCUT:
533 case OSPF_ABR_STAND:
534 if (areas_act_attached > 1)
535 SET_FLAG (new_flags, OSPF_FLAG_ABR);
536 else
537 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
538 break;
539
540 case OSPF_ABR_IBM:
541 if ((areas_act_attached > 1) && bb_configured)
542 SET_FLAG (new_flags, OSPF_FLAG_ABR);
543 else
544 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
545 break;
546
547 case OSPF_ABR_CISCO:
548 if ((areas_configured > 1) && bb_act_attached)
549 SET_FLAG (new_flags, OSPF_FLAG_ABR);
550 else
551 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
552 break;
553 default:
554 break;
555 }
556
paul147193a2003-04-19 00:31:59 +0000557 if (new_flags != ospf->flags)
paul718e3742002-12-13 20:15:29 +0000558 {
paul147193a2003-04-19 00:31:59 +0000559 ospf_spf_calculate_schedule (ospf);
paul718e3742002-12-13 20:15:29 +0000560 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000561 zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags);
paul147193a2003-04-19 00:31:59 +0000562 ospf->flags = new_flags;
Paul Jakmac363d382010-01-24 22:42:13 +0000563 ospf_router_lsa_update (ospf);
paul718e3742002-12-13 20:15:29 +0000564 }
565}
566
paul4dadc292005-05-06 21:37:42 +0000567static void
paul718e3742002-12-13 20:15:29 +0000568ospf_abr_update_aggregate (struct ospf_area_range *range,
JR Riversb4154c12012-09-24 17:26:53 +0000569 struct ospf_route *or, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +0000570{
571 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000572 zlog_debug ("ospf_abr_update_aggregate(): Start");
paul718e3742002-12-13 20:15:29 +0000573
JR Riversb4154c12012-09-24 17:26:53 +0000574 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED) &&
575 (range->cost != OSPF_STUB_MAX_METRIC_SUMMARY_COST))
576 {
577 range->cost = OSPF_STUB_MAX_METRIC_SUMMARY_COST;
578 if (IS_DEBUG_OSPF_EVENT)
579 zlog_debug ("ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
580 range->cost);
581 }
582 else if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
paul718e3742002-12-13 20:15:29 +0000583 {
584 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000585 zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
paul7f352b82004-02-19 19:37:47 +0000586 range->cost_config);
paul718e3742002-12-13 20:15:29 +0000587
588 range->cost = range->cost_config;
589 }
590 else
591 {
592 if (range->specifics == 0)
JR Riversb4154c12012-09-24 17:26:53 +0000593 {
594 if (IS_DEBUG_OSPF_EVENT)
595 zlog_debug ("ospf_abr_update_aggregate(): use or->cost %d",
596 or->cost);
597
598 range->cost = or->cost; /* 1st time get 1st cost */
599 }
paul718e3742002-12-13 20:15:29 +0000600
paul7f352b82004-02-19 19:37:47 +0000601 if (or->cost > range->cost)
602 {
603 if (IS_DEBUG_OSPF_EVENT)
JR Riversb4154c12012-09-24 17:26:53 +0000604 zlog_debug ("ospf_abr_update_aggregate(): update to %d", or->cost);
paul718e3742002-12-13 20:15:29 +0000605
paul7f352b82004-02-19 19:37:47 +0000606 range->cost = or->cost;
607 }
paul718e3742002-12-13 20:15:29 +0000608 }
609
610 range->specifics++;
611}
612
613static void
614set_metric (struct ospf_lsa *lsa, u_int32_t metric)
615{
616 struct summary_lsa *header;
617 u_char *mp;
618 metric = htonl (metric);
hassoc9e52be2004-09-26 16:09:34 +0000619 mp = (u_char *) &metric;
paul718e3742002-12-13 20:15:29 +0000620 mp++;
621 header = (struct summary_lsa *) lsa->data;
622 memcpy(header->metric, mp, 3);
623}
624
paul718e3742002-12-13 20:15:29 +0000625/* ospf_abr_translate_nssa */
paul4dadc292005-05-06 21:37:42 +0000626static int
paul147193a2003-04-19 00:31:59 +0000627ospf_abr_translate_nssa (struct ospf_area *area, struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000628{
629 /* Incoming Type-7 or later aggregated Type-7
pauld4a53d52003-07-12 21:30:57 +0000630 *
631 * LSA is skipped if P-bit is off.
632 * LSA is aggregated if within range.
633 *
634 * The Type-7 is translated, Installed/Approved as a Type-5 into
635 * global LSDB, then Flooded through AS
636 *
637 * Later, any Unapproved Translated Type-5's are flushed/discarded
638 */
paul718e3742002-12-13 20:15:29 +0000639
pauld4a53d52003-07-12 21:30:57 +0000640 struct ospf_lsa *old = NULL,
641 *new = NULL;
642 struct as_external_lsa *ext7;
643 struct prefix_ipv4 p;
paul718e3742002-12-13 20:15:29 +0000644
645 if (! CHECK_FLAG (lsa->data->options, OSPF_OPTION_NP))
646 {
647 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000648 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
pauld4a53d52003-07-12 21:30:57 +0000649 inet_ntoa (lsa->data->id));
650 return 1;
paul718e3742002-12-13 20:15:29 +0000651 }
pauld4a53d52003-07-12 21:30:57 +0000652
paul718e3742002-12-13 20:15:29 +0000653 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000654 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
pauld4a53d52003-07-12 21:30:57 +0000655 inet_ntoa (lsa->data->id));
paul718e3742002-12-13 20:15:29 +0000656
pauld4a53d52003-07-12 21:30:57 +0000657 ext7 = (struct as_external_lsa *)(lsa->data);
658 p.prefix = lsa->data->id;
659 p.prefixlen = ip_masklen (ext7->mask);
660
661 if (ext7->e[0].fwd_addr.s_addr == OSPF_DEFAULT_DESTINATION)
662 {
663 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000664 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, "
pauld4a53d52003-07-12 21:30:57 +0000665 "Forward address is 0, NO Translation",
666 inet_ntoa (lsa->data->id));
667 return 1;
668 }
669
670 /* try find existing AS-External LSA for this prefix */
671
672 old = ospf_external_info_find_lsa (area->ospf, &p);
673
674 if (old)
675 {
676 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000677 zlog_debug ("ospf_abr_translate_nssa(): "
pauld4a53d52003-07-12 21:30:57 +0000678 "found old translated LSA Id %s, refreshing",
679 inet_ntoa (old->data->id));
680
681 /* refresh */
682 new = ospf_translated_nssa_refresh (area->ospf, lsa, old);
683 if (!new)
684 {
685 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000686 zlog_debug ("ospf_abr_translate_nssa(): "
pauld4a53d52003-07-12 21:30:57 +0000687 "could not refresh translated LSA Id %s",
688 inet_ntoa (old->data->id));
689 }
690 }
691 else
692 {
693 /* no existing external route for this LSA Id
694 * originate translated LSA
695 */
696
697 if ((new = ospf_translated_nssa_originate (area->ospf, lsa))
698 == NULL)
699 {
700 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000701 zlog_debug ("ospf_abr_translate_nssa(): Could not translate "
pauld4a53d52003-07-12 21:30:57 +0000702 "Type-7 for %s to Type-5",
703 inet_ntoa (lsa->data->id));
704 return 1;
705 }
706 }
paul718e3742002-12-13 20:15:29 +0000707
708 /* Area where Aggregate testing will be inserted, just like summary
709 advertisements */
710 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
711
paul718e3742002-12-13 20:15:29 +0000712 return 0;
713}
714
paul4dadc292005-05-06 21:37:42 +0000715static void
paul718e3742002-12-13 20:15:29 +0000716ospf_abr_translate_nssa_range (struct prefix_ipv4 *p, u_int32_t cost)
717{
718 /* The Type-7 is created from the aggregated prefix and forwarded
719 for lsa installation and flooding... to be added... */
720}
paul718e3742002-12-13 20:15:29 +0000721
vincentba682532005-09-29 13:52:57 +0000722void
paul718e3742002-12-13 20:15:29 +0000723ospf_abr_announce_network_to_area (struct prefix_ipv4 *p, u_int32_t cost,
724 struct ospf_area *area)
725{
726 struct ospf_lsa *lsa, *old = NULL;
727 struct summary_lsa *sl = NULL;
JR Riversb4154c12012-09-24 17:26:53 +0000728 u_int32_t full_cost;
paul718e3742002-12-13 20:15:29 +0000729
730 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000731 zlog_debug ("ospf_abr_announce_network_to_area(): Start");
paul718e3742002-12-13 20:15:29 +0000732
JR Riversb4154c12012-09-24 17:26:53 +0000733 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
734 full_cost = OSPF_STUB_MAX_METRIC_SUMMARY_COST;
735 else
736 full_cost = cost;
737
pauld4a53d52003-07-12 21:30:57 +0000738 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_SUMMARY_LSA,
739 (struct prefix_ipv4 *) p,
740 area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +0000741 if (old)
742 {
743 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000744 zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
pauld4a53d52003-07-12 21:30:57 +0000745
paul718e3742002-12-13 20:15:29 +0000746 sl = (struct summary_lsa *) old->data;
747
748 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000749 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000750 "old metric: %d, new metric: %d",
751 GET_METRIC (sl->metric), cost);
JR Rivers82175552012-09-24 17:26:50 +0000752
JR Riversb4154c12012-09-24 17:26:53 +0000753 if ((GET_METRIC (sl->metric) == full_cost) &&
JR Rivers82175552012-09-24 17:26:50 +0000754 ((old->flags & OSPF_LSA_IN_MAXAGE) == 0))
pauld4a53d52003-07-12 21:30:57 +0000755 {
756 /* unchanged. simply reapprove it */
757 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000758 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000759 "old summary approved");
760 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
761 }
762 else
763 {
764 /* LSA is changed, refresh it */
765 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000766 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000767 "refreshing summary");
JR Riversb4154c12012-09-24 17:26:53 +0000768 set_metric (old, full_cost);
Paul Jakmac363d382010-01-24 22:42:13 +0000769 lsa = ospf_lsa_refresh (area->ospf, old);
paulc24d6022005-11-20 14:54:12 +0000770
771 if (!lsa)
772 {
773 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
774
775 prefix2str ((struct prefix *) p, buf, sizeof(buf));
776 zlog_warn ("%s: Could not refresh %s to %s",
777 __func__,
778 buf,
779 inet_ntoa (area->area_id));
780 return;
781 }
782
paulc8987752005-07-26 06:07:22 +0000783 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
pauld4a53d52003-07-12 21:30:57 +0000784 /* This will flood through area. */
785 }
paul718e3742002-12-13 20:15:29 +0000786 }
787 else
788 {
789 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000790 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000791 "creating new summary");
JR Riversb4154c12012-09-24 17:26:53 +0000792 lsa = ospf_summary_lsa_originate ( (struct prefix_ipv4 *)p, full_cost, area);
pauld4a53d52003-07-12 21:30:57 +0000793 /* This will flood through area. */
paul718e3742002-12-13 20:15:29 +0000794
paulc24d6022005-11-20 14:54:12 +0000795 if (!lsa)
796 {
797 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
798
799 prefix2str ((struct prefix *)p, buf, sizeof(buf));
800 zlog_warn ("%s: Could not originate %s to %s",
801 __func__,
802 buf,
803 inet_ntoa (area->area_id));
804 return;
805 }
806
paul718e3742002-12-13 20:15:29 +0000807 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
808 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000809 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000810 "flooding new version of summary");
paul718e3742002-12-13 20:15:29 +0000811 }
812
813 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000814 zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
paul718e3742002-12-13 20:15:29 +0000815}
816
paul4dadc292005-05-06 21:37:42 +0000817static int
paul718e3742002-12-13 20:15:29 +0000818ospf_abr_nexthops_belong_to_area (struct ospf_route *or,
819 struct ospf_area *area)
820{
paul1eb8ef22005-04-07 07:30:20 +0000821 struct listnode *node, *nnode;
paul96735ee2003-08-10 02:51:22 +0000822 struct ospf_path *path;
Joakim Tjernlunda8ba8472009-07-27 12:42:34 +0200823 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000824
Joakim Tjernlunda8ba8472009-07-27 12:42:34 +0200825 for (ALL_LIST_ELEMENTS_RO (or->paths, node, path))
826 for (ALL_LIST_ELEMENTS_RO (area->oiflist, nnode, oi))
827 if (oi->ifp && oi->ifp->ifindex == path->ifindex)
828 return 1;
paul718e3742002-12-13 20:15:29 +0000829
830 return 0;
831}
832
paul4dadc292005-05-06 21:37:42 +0000833static int
pauld4a53d52003-07-12 21:30:57 +0000834ospf_abr_should_accept (struct prefix_ipv4 *p, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +0000835{
836 if (IMPORT_NAME (area))
837 {
838 if (IMPORT_LIST (area) == NULL)
839 IMPORT_LIST (area) = access_list_lookup (AFI_IP, IMPORT_NAME (area));
840
841 if (IMPORT_LIST (area))
842 if (access_list_apply (IMPORT_LIST (area), p) == FILTER_DENY)
843 return 0;
844 }
845
846 return 1;
847}
848
paul4dadc292005-05-06 21:37:42 +0000849static int
paul718e3742002-12-13 20:15:29 +0000850ospf_abr_plist_in_check (struct ospf_area *area, struct ospf_route *or,
pauld4a53d52003-07-12 21:30:57 +0000851 struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000852{
853 if (PREFIX_NAME_IN (area))
854 {
855 if (PREFIX_LIST_IN (area) == NULL)
856 PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP,
857 PREFIX_NAME_IN (area));
858 if (PREFIX_LIST_IN (area))
859 if (prefix_list_apply (PREFIX_LIST_IN (area), p) != PREFIX_PERMIT)
860 return 0;
861 }
862 return 1;
863}
864
paul4dadc292005-05-06 21:37:42 +0000865static int
paul718e3742002-12-13 20:15:29 +0000866ospf_abr_plist_out_check (struct ospf_area *area, struct ospf_route *or,
pauld4a53d52003-07-12 21:30:57 +0000867 struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000868{
869 if (PREFIX_NAME_OUT (area))
870 {
871 if (PREFIX_LIST_OUT (area) == NULL)
872 PREFIX_LIST_OUT (area) = prefix_list_lookup (AFI_IP,
873 PREFIX_NAME_OUT (area));
874 if (PREFIX_LIST_OUT (area))
875 if (prefix_list_apply (PREFIX_LIST_OUT (area), p) != PREFIX_PERMIT)
876 return 0;
877 }
878 return 1;
879}
880
paul4dadc292005-05-06 21:37:42 +0000881static void
paul147193a2003-04-19 00:31:59 +0000882ospf_abr_announce_network (struct ospf *ospf,
pauld4a53d52003-07-12 21:30:57 +0000883 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000884{
paul718e3742002-12-13 20:15:29 +0000885 struct ospf_area_range *range;
paul718e3742002-12-13 20:15:29 +0000886 struct ospf_area *area, *or_area;
hasso52dc7ee2004-09-23 19:18:23 +0000887 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000888
889 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000890 zlog_debug ("ospf_abr_announce_network(): Start");
paul718e3742002-12-13 20:15:29 +0000891
paul147193a2003-04-19 00:31:59 +0000892 or_area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
paul718e3742002-12-13 20:15:29 +0000893 assert (or_area);
894
paul1eb8ef22005-04-07 07:30:20 +0000895 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000896 {
paul718e3742002-12-13 20:15:29 +0000897 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000898 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
paul718e3742002-12-13 20:15:29 +0000899 inet_ntoa (area->area_id));
900
901 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
902 continue;
903
904 if (ospf_abr_nexthops_belong_to_area (or, area))
905 continue;
906
pauld4a53d52003-07-12 21:30:57 +0000907 if (!ospf_abr_should_accept (p, area))
paul718e3742002-12-13 20:15:29 +0000908 {
909 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000910 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000911 "prefix %s/%d was denied by import-list",
912 inet_ntoa (p->prefix), p->prefixlen);
913 continue;
914 }
915
pauld4a53d52003-07-12 21:30:57 +0000916 if (!ospf_abr_plist_in_check (area, or, p))
paul718e3742002-12-13 20:15:29 +0000917 {
918 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000919 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000920 "prefix %s/%d was denied by prefix-list",
921 inet_ntoa (p->prefix), p->prefixlen);
922 continue;
923 }
924
925 if (area->external_routing != OSPF_AREA_DEFAULT && area->no_summary)
926 {
927 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000928 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000929 "area %s is stub and no_summary",
930 inet_ntoa (area->area_id));
931 continue;
932 }
933
934 if (or->path_type == OSPF_PATH_INTER_AREA)
935 {
936 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000937 zlog_debug ("ospf_abr_announce_network(): this is "
paul718e3742002-12-13 20:15:29 +0000938 "inter-area route to %s/%d",
939 inet_ntoa (p->prefix), p->prefixlen);
940
941 if (!OSPF_IS_AREA_BACKBONE (area))
942 ospf_abr_announce_network_to_area (p, or->cost, area);
943 }
944
945 if (or->path_type == OSPF_PATH_INTRA_AREA)
pauld4a53d52003-07-12 21:30:57 +0000946 {
947 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000948 zlog_debug ("ospf_abr_announce_network(): "
pauld4a53d52003-07-12 21:30:57 +0000949 "this is intra-area route to %s/%d",
950 inet_ntoa (p->prefix), p->prefixlen);
951 if ((range = ospf_area_range_match (or_area, p))
952 && !ospf_area_is_transit (area))
JR Riversb4154c12012-09-24 17:26:53 +0000953 ospf_abr_update_aggregate (range, or, area);
pauld4a53d52003-07-12 21:30:57 +0000954 else
955 ospf_abr_announce_network_to_area (p, or->cost, area);
956 }
paul718e3742002-12-13 20:15:29 +0000957 }
958}
959
paul4dadc292005-05-06 21:37:42 +0000960static int
paul147193a2003-04-19 00:31:59 +0000961ospf_abr_should_announce (struct ospf *ospf,
pauld4a53d52003-07-12 21:30:57 +0000962 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000963{
paul147193a2003-04-19 00:31:59 +0000964 struct ospf_area *area;
965
966 area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
paul718e3742002-12-13 20:15:29 +0000967
968 assert (area);
969
970 if (EXPORT_NAME (area))
971 {
972 if (EXPORT_LIST (area) == NULL)
973 EXPORT_LIST (area) = access_list_lookup (AFI_IP, EXPORT_NAME (area));
974
975 if (EXPORT_LIST (area))
976 if (access_list_apply (EXPORT_LIST (area), p) == FILTER_DENY)
977 return 0;
978 }
979
980 return 1;
981}
982
paul4dadc292005-05-06 21:37:42 +0000983static void
paul147193a2003-04-19 00:31:59 +0000984ospf_abr_process_nssa_translates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000985{
986 /* Scan through all NSSA_LSDB records for all areas;
987
988 If P-bit is on, translate all Type-7's to 5's and aggregate or
989 flood install as approved in Type-5 LSDB with XLATE Flag on
990 later, do same for all aggregates... At end, DISCARD all
991 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
hasso52dc7ee2004-09-23 19:18:23 +0000992 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000993 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +0000994 struct route_node *rn;
995 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000996
997 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000998 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
paul718e3742002-12-13 20:15:29 +0000999
paul1eb8ef22005-04-07 07:30:20 +00001000 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001001 {
paule2c6c152003-06-22 08:49:25 +00001002 if (! area->NSSATranslatorState)
pauld4a53d52003-07-12 21:30:57 +00001003 continue; /* skip if not translator */
paul718e3742002-12-13 20:15:29 +00001004
1005 if (area->external_routing != OSPF_AREA_NSSA)
pauld4a53d52003-07-12 21:30:57 +00001006 continue; /* skip if not Nssa Area */
paul718e3742002-12-13 20:15:29 +00001007
1008 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001009 zlog_debug ("ospf_abr_process_nssa_translates(): "
pauld4a53d52003-07-12 21:30:57 +00001010 "looking at area %s", inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001011
paul147193a2003-04-19 00:31:59 +00001012 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001013 ospf_abr_translate_nssa (area, lsa);
paul718e3742002-12-13 20:15:29 +00001014 }
1015
1016 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001017 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001018
1019}
paul718e3742002-12-13 20:15:29 +00001020
paul4dadc292005-05-06 21:37:42 +00001021static void
paul147193a2003-04-19 00:31:59 +00001022ospf_abr_process_network_rt (struct ospf *ospf,
1023 struct route_table *rt)
paul718e3742002-12-13 20:15:29 +00001024{
paul718e3742002-12-13 20:15:29 +00001025 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001026 struct ospf_route *or;
1027 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +00001028
1029 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001030 zlog_debug ("ospf_abr_process_network_rt(): Start");
paul718e3742002-12-13 20:15:29 +00001031
1032 for (rn = route_top (rt); rn; rn = route_next (rn))
1033 {
1034 if ((or = rn->info) == NULL)
1035 continue;
1036
paul147193a2003-04-19 00:31:59 +00001037 if (!(area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id)))
paul718e3742002-12-13 20:15:29 +00001038 {
1039 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001040 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
paul718e3742002-12-13 20:15:29 +00001041 inet_ntoa (or->u.std.area_id));
1042 continue;
1043 }
1044
1045 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001046 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
paul718e3742002-12-13 20:15:29 +00001047 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
1048 if (or->path_type >= OSPF_PATH_TYPE1_EXTERNAL)
1049 {
1050 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001051 zlog_debug ("ospf_abr_process_network_rt(): "
paul718e3742002-12-13 20:15:29 +00001052 "this is an External router, skipping");
1053 continue;
1054 }
1055
1056 if (or->cost >= OSPF_LS_INFINITY)
1057 {
1058 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001059 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001060 " this route's cost is infinity, skipping");
1061 continue;
1062 }
1063
1064 if (or->type == OSPF_DESTINATION_DISCARD)
1065 {
1066 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001067 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001068 " this is a discard entry, skipping");
1069 continue;
1070 }
1071
1072 if (or->path_type == OSPF_PATH_INTRA_AREA &&
pauld4a53d52003-07-12 21:30:57 +00001073 !ospf_abr_should_announce (ospf, (struct prefix_ipv4 *) &rn->p, or))
paul718e3742002-12-13 20:15:29 +00001074 {
1075 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001076 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
paul718e3742002-12-13 20:15:29 +00001077 continue;
1078 }
1079
1080 if (or->path_type == OSPF_PATH_INTRA_AREA &&
pauld4a53d52003-07-12 21:30:57 +00001081 !ospf_abr_plist_out_check (area, or, (struct prefix_ipv4 *) &rn->p))
paul718e3742002-12-13 20:15:29 +00001082 {
1083 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001084 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
paul718e3742002-12-13 20:15:29 +00001085 continue;
1086 }
1087
1088 if ((or->path_type == OSPF_PATH_INTER_AREA) &&
1089 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1090 {
1091 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001092 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001093 " this is route is not backbone one, skipping");
1094 continue;
1095 }
1096
1097
paul147193a2003-04-19 00:31:59 +00001098 if ((ospf->abr_type == OSPF_ABR_CISCO) ||
1099 (ospf->abr_type == OSPF_ABR_IBM))
paul718e3742002-12-13 20:15:29 +00001100
paul147193a2003-04-19 00:31:59 +00001101 if (!ospf_act_bb_connection (ospf) &&
paul718e3742002-12-13 20:15:29 +00001102 or->path_type != OSPF_PATH_INTRA_AREA)
1103 {
1104 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001105 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
paul718e3742002-12-13 20:15:29 +00001106 "No BB connection, skip not intra-area routes");
1107 continue;
1108 }
1109
1110 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001111 zlog_debug ("ospf_abr_process_network_rt(): announcing");
hassofa2b17e2004-03-04 17:45:00 +00001112 ospf_abr_announce_network (ospf, (struct prefix_ipv4 *)&rn->p, or);
paul718e3742002-12-13 20:15:29 +00001113 }
1114
1115 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001116 zlog_debug ("ospf_abr_process_network_rt(): Stop");
paul718e3742002-12-13 20:15:29 +00001117}
1118
paul4dadc292005-05-06 21:37:42 +00001119static void
paul718e3742002-12-13 20:15:29 +00001120ospf_abr_announce_rtr_to_area (struct prefix_ipv4 *p, u_int32_t cost,
1121 struct ospf_area *area)
1122{
1123 struct ospf_lsa *lsa, *old = NULL;
1124 struct summary_lsa *slsa = NULL;
1125
1126 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001127 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
paul718e3742002-12-13 20:15:29 +00001128
paul147193a2003-04-19 00:31:59 +00001129 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_ASBR_SUMMARY_LSA,
1130 p, area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +00001131 if (old)
1132 {
1133 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001134 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
paul718e3742002-12-13 20:15:29 +00001135 slsa = (struct summary_lsa *) old->data;
1136
1137 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001138 zlog_debug ("ospf_abr_announce_network_to_area(): "
paul718e3742002-12-13 20:15:29 +00001139 "old metric: %d, new metric: %d",
1140 GET_METRIC (slsa->metric), cost);
1141 }
1142
1143 if (old && (GET_METRIC (slsa->metric) == cost))
1144 {
1145 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001146 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
paul718e3742002-12-13 20:15:29 +00001147 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
1148 }
1149 else
1150 {
1151 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001152 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
paul718e3742002-12-13 20:15:29 +00001153
1154 if (old)
1155 {
1156 set_metric (old, cost);
Paul Jakmac363d382010-01-24 22:42:13 +00001157 lsa = ospf_lsa_refresh (area->ospf, old);
paul718e3742002-12-13 20:15:29 +00001158 }
1159 else
1160 lsa = ospf_summary_asbr_lsa_originate (p, cost, area);
paulc24d6022005-11-20 14:54:12 +00001161 if (!lsa)
1162 {
1163 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
1164
1165 prefix2str ((struct prefix *)p, buf, sizeof(buf));
1166 zlog_warn ("%s: Could not refresh/originate %s to %s",
1167 __func__,
1168 buf,
1169 inet_ntoa (area->area_id));
1170 return;
1171 }
1172
paul718e3742002-12-13 20:15:29 +00001173 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001174 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
paul718e3742002-12-13 20:15:29 +00001175 "flooding new version of summary");
paulc24d6022005-11-20 14:54:12 +00001176
paul718e3742002-12-13 20:15:29 +00001177 /*
1178 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1179 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1180
1181 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1182 /* ospf_flood_through_area (area, NULL, lsa);*/
1183 }
1184
1185 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001186 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
paul718e3742002-12-13 20:15:29 +00001187}
1188
1189
paul4dadc292005-05-06 21:37:42 +00001190static void
paul147193a2003-04-19 00:31:59 +00001191ospf_abr_announce_rtr (struct ospf *ospf,
1192 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +00001193{
hasso52dc7ee2004-09-23 19:18:23 +00001194 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001195 struct ospf_area *area;
1196
1197 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001198 zlog_debug ("ospf_abr_announce_rtr(): Start");
paul718e3742002-12-13 20:15:29 +00001199
paul1eb8ef22005-04-07 07:30:20 +00001200 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001201 {
paul718e3742002-12-13 20:15:29 +00001202 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001203 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001204 inet_ntoa (area->area_id));
1205
1206 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
1207 continue;
1208
1209 if (ospf_abr_nexthops_belong_to_area (or, area))
1210 continue;
1211
1212 if (area->external_routing != OSPF_AREA_DEFAULT)
1213 {
1214 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001215 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001216 "area %s doesn't support external routing",
1217 inet_ntoa(area->area_id));
1218 continue;
1219 }
1220
1221 if (or->path_type == OSPF_PATH_INTER_AREA)
1222 {
1223 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001224 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001225 "this is inter-area route to %s", inet_ntoa (p->prefix));
1226 if (!OSPF_IS_AREA_BACKBONE (area))
1227 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1228 }
1229
1230 if (or->path_type == OSPF_PATH_INTRA_AREA)
1231 {
1232 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001233 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001234 "this is intra-area route to %s", inet_ntoa (p->prefix));
1235 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1236 }
1237 }
1238
1239 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001240 zlog_debug ("ospf_abr_announce_rtr(): Stop");
paul718e3742002-12-13 20:15:29 +00001241}
1242
paul4dadc292005-05-06 21:37:42 +00001243static void
paul147193a2003-04-19 00:31:59 +00001244ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt)
paul718e3742002-12-13 20:15:29 +00001245{
paul718e3742002-12-13 20:15:29 +00001246 struct ospf_route *or;
paul147193a2003-04-19 00:31:59 +00001247 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +00001248 struct list *l;
1249
1250 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001251 zlog_debug ("ospf_abr_process_router_rt(): Start");
paul718e3742002-12-13 20:15:29 +00001252
1253 for (rn = route_top (rt); rn; rn = route_next (rn))
1254 {
paul1eb8ef22005-04-07 07:30:20 +00001255 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001256 char flag = 0;
1257 struct ospf_route *best = NULL;
1258
1259 if (rn->info == NULL)
1260 continue;
1261
1262 l = rn->info;
1263
1264 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001265 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
paul718e3742002-12-13 20:15:29 +00001266 inet_ntoa (rn->p.u.prefix4));
1267
paul1eb8ef22005-04-07 07:30:20 +00001268 for (ALL_LIST_ELEMENTS (l, node, nnode, or))
paul718e3742002-12-13 20:15:29 +00001269 {
paul147193a2003-04-19 00:31:59 +00001270 if (!ospf_area_lookup_by_area_id (ospf, or->u.std.area_id))
paul718e3742002-12-13 20:15:29 +00001271 {
1272 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001273 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
paul718e3742002-12-13 20:15:29 +00001274 inet_ntoa (or->u.std.area_id));
1275 continue;
1276 }
1277
1278
1279 if (!CHECK_FLAG (or->u.std.flags, ROUTER_LSA_EXTERNAL))
1280 {
1281 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001282 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001283 "This is not an ASBR, skipping");
1284 continue;
1285 }
1286
1287 if (!flag)
1288 {
paul147193a2003-04-19 00:31:59 +00001289 best = ospf_find_asbr_route (ospf, rt,
1290 (struct prefix_ipv4 *) &rn->p);
paul718e3742002-12-13 20:15:29 +00001291 flag = 1;
1292 }
1293
1294 if (best == NULL)
1295 continue;
1296
1297 if (or != best)
1298 {
1299 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001300 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001301 "This route is not the best among possible, skipping");
1302 continue;
1303 }
1304
1305 if (or->path_type == OSPF_PATH_INTER_AREA &&
1306 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1307 {
1308 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001309 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001310 "This route is not a backbone one, skipping");
1311 continue;
1312 }
1313
1314 if (or->cost >= OSPF_LS_INFINITY)
1315 {
1316 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001317 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001318 "This route has LS_INFINITY metric, skipping");
1319 continue;
1320 }
1321
paul147193a2003-04-19 00:31:59 +00001322 if (ospf->abr_type == OSPF_ABR_CISCO
1323 || ospf->abr_type == OSPF_ABR_IBM)
1324 if (!ospf_act_bb_connection (ospf)
1325 && or->path_type != OSPF_PATH_INTRA_AREA)
paul718e3742002-12-13 20:15:29 +00001326 {
1327 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001328 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
paul718e3742002-12-13 20:15:29 +00001329 "No BB connection, skip not intra-area routes");
1330 continue;
1331 }
1332
paul147193a2003-04-19 00:31:59 +00001333 ospf_abr_announce_rtr (ospf, (struct prefix_ipv4 *) &rn->p, or);
paul718e3742002-12-13 20:15:29 +00001334
1335 }
1336
1337 }
1338
1339 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001340 zlog_debug ("ospf_abr_process_router_rt(): Stop");
paul718e3742002-12-13 20:15:29 +00001341}
1342
paul4dadc292005-05-06 21:37:42 +00001343static void
paul147193a2003-04-19 00:31:59 +00001344ospf_abr_unapprove_translates (struct ospf *ospf) /* For NSSA Translations */
paul718e3742002-12-13 20:15:29 +00001345{
paul147193a2003-04-19 00:31:59 +00001346 struct ospf_lsa *lsa;
1347 struct route_node *rn;
1348
paul718e3742002-12-13 20:15:29 +00001349 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001350 zlog_debug ("ospf_abr_unapprove_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001351
1352 /* NSSA Translator is not checked, because it may have gone away,
1353 and we would want to flush any residuals anyway */
1354
paul147193a2003-04-19 00:31:59 +00001355 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1356 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
pauld4a53d52003-07-12 21:30:57 +00001357 {
1358 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1359 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001360 zlog_debug ("ospf_abr_unapprove_translates(): "
pauld4a53d52003-07-12 21:30:57 +00001361 "approved unset on link id %s",
1362 inet_ntoa (lsa->data->id));
1363 }
paul718e3742002-12-13 20:15:29 +00001364
1365 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001366 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001367}
paul718e3742002-12-13 20:15:29 +00001368
paul4dadc292005-05-06 21:37:42 +00001369static void
paul147193a2003-04-19 00:31:59 +00001370ospf_abr_unapprove_summaries (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001371{
hasso52dc7ee2004-09-23 19:18:23 +00001372 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001373 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001374 struct route_node *rn;
1375 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +00001376
1377 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001378 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
paul718e3742002-12-13 20:15:29 +00001379
paul1eb8ef22005-04-07 07:30:20 +00001380 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001381 {
pauld4a53d52003-07-12 21:30:57 +00001382 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001383 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001384 "considering area %s",
1385 inet_ntoa (area->area_id));
paul147193a2003-04-19 00:31:59 +00001386 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001387 if (ospf_lsa_is_self_originated (ospf, lsa))
1388 {
1389 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001390 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001391 "approved unset on summary link id %s",
1392 inet_ntoa (lsa->data->id));
1393 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1394 }
paul147193a2003-04-19 00:31:59 +00001395
1396 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001397 if (ospf_lsa_is_self_originated (ospf, lsa))
1398 {
1399 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001400 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001401 "approved unset on asbr-summary link id %s",
1402 inet_ntoa (lsa->data->id));
1403 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1404 }
paul718e3742002-12-13 20:15:29 +00001405 }
1406
1407 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001408 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
paul718e3742002-12-13 20:15:29 +00001409}
1410
paul4dadc292005-05-06 21:37:42 +00001411static void
paul147193a2003-04-19 00:31:59 +00001412ospf_abr_prepare_aggregates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001413{
hasso52dc7ee2004-09-23 19:18:23 +00001414 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001415 struct route_node *rn;
1416 struct ospf_area_range *range;
paul1eb8ef22005-04-07 07:30:20 +00001417 struct ospf_area *area;
paul718e3742002-12-13 20:15:29 +00001418
1419 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001420 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001421
paul1eb8ef22005-04-07 07:30:20 +00001422 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001423 {
paul718e3742002-12-13 20:15:29 +00001424 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1425 if ((range = rn->info) != NULL)
1426 {
1427 range->cost = 0;
1428 range->specifics = 0;
1429 }
1430 }
1431
1432 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001433 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001434}
1435
paul4dadc292005-05-06 21:37:42 +00001436static void
paul147193a2003-04-19 00:31:59 +00001437ospf_abr_announce_aggregates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001438{
1439 struct ospf_area *area, *ar;
1440 struct ospf_area_range *range;
1441 struct route_node *rn;
pauld4a53d52003-07-12 21:30:57 +00001442 struct prefix p;
hasso52dc7ee2004-09-23 19:18:23 +00001443 struct listnode *node, *n;
paul718e3742002-12-13 20:15:29 +00001444
1445 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001446 zlog_debug ("ospf_abr_announce_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001447
paul1eb8ef22005-04-07 07:30:20 +00001448 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001449 {
paul718e3742002-12-13 20:15:29 +00001450 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001451 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001452 inet_ntoa (area->area_id));
1453
1454 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1455 if ((range = rn->info))
1456 {
1457 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1458 {
1459 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001460 zlog_debug ("ospf_abr_announce_aggregates():"
paul718e3742002-12-13 20:15:29 +00001461 " discarding suppress-ranges");
1462 continue;
1463 }
1464
1465 p.family = AF_INET;
pauld4a53d52003-07-12 21:30:57 +00001466 p.u.prefix4 = range->addr;
paul718e3742002-12-13 20:15:29 +00001467 p.prefixlen = range->masklen;
1468
1469 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001470 zlog_debug ("ospf_abr_announce_aggregates():"
paul718e3742002-12-13 20:15:29 +00001471 " this is range: %s/%d",
pauld4a53d52003-07-12 21:30:57 +00001472 inet_ntoa (p.u.prefix4), p.prefixlen);
paul718e3742002-12-13 20:15:29 +00001473
1474 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1475 {
1476 p.family = AF_INET;
pauld4a53d52003-07-12 21:30:57 +00001477 p.u.prefix4 = range->subst_addr;
paul718e3742002-12-13 20:15:29 +00001478 p.prefixlen = range->subst_masklen;
1479 }
1480
1481 if (range->specifics)
1482 {
1483 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001484 zlog_debug ("ospf_abr_announce_aggregates(): active range");
paul718e3742002-12-13 20:15:29 +00001485
paul1eb8ef22005-04-07 07:30:20 +00001486 for (ALL_LIST_ELEMENTS_RO (ospf->areas, n, ar))
paul718e3742002-12-13 20:15:29 +00001487 {
paul718e3742002-12-13 20:15:29 +00001488 if (ar == area)
1489 continue;
1490
1491 /* We do not check nexthops here, because
1492 intra-area routes can be associated with
1493 one area only */
1494
1495 /* backbone routes are not summarized
1496 when announced into transit areas */
1497
1498 if (ospf_area_is_transit (ar) &&
1499 OSPF_IS_AREA_BACKBONE (area))
1500 {
1501 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001502 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
paul718e3742002-12-13 20:15:29 +00001503 "announcement of BB aggregate into"
1504 " a transit area");
1505 continue;
1506 }
hassofa2b17e2004-03-04 17:45:00 +00001507 ospf_abr_announce_network_to_area ((struct prefix_ipv4 *)&p, range->cost, ar);
paul718e3742002-12-13 20:15:29 +00001508 }
1509 }
1510 }
1511 }
1512
1513 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001514 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001515}
1516
paul4dadc292005-05-06 21:37:42 +00001517static void
paul147193a2003-04-19 00:31:59 +00001518ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */
paul718e3742002-12-13 20:15:29 +00001519{
hasso52dc7ee2004-09-23 19:18:23 +00001520 struct listnode *node; /*, n; */
paul718e3742002-12-13 20:15:29 +00001521 struct ospf_area *area; /*, *ar; */
1522 struct route_node *rn;
1523 struct ospf_area_range *range;
1524 struct prefix_ipv4 p;
1525
1526 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001527 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001528
paul1eb8ef22005-04-07 07:30:20 +00001529 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001530 {
paule2c6c152003-06-22 08:49:25 +00001531 if (! area->NSSATranslatorState)
paul718e3742002-12-13 20:15:29 +00001532 continue;
1533
1534 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001535 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001536 inet_ntoa (area->area_id));
1537
1538 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1539 {
1540 if (rn->info == NULL)
1541 continue;
1542
1543 range = rn->info;
1544
1545 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1546 {
1547 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001548 zlog_debug ("ospf_abr_send_nssa_aggregates():"
paul718e3742002-12-13 20:15:29 +00001549 " discarding suppress-ranges");
1550 continue;
1551 }
1552
1553 p.family = AF_INET;
1554 p.prefix = range->addr;
1555 p.prefixlen = range->masklen;
1556
1557 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001558 zlog_debug ("ospf_abr_send_nssa_aggregates():"
paul718e3742002-12-13 20:15:29 +00001559 " this is range: %s/%d",
1560 inet_ntoa (p.prefix), p.prefixlen);
1561
1562 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1563 {
1564 p.family = AF_INET;
1565 p.prefix = range->subst_addr;
1566 p.prefixlen = range->subst_masklen;
1567 }
1568
1569 if (range->specifics)
paule2c6c152003-06-22 08:49:25 +00001570 {
1571 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001572 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
paul718e3742002-12-13 20:15:29 +00001573
paule2c6c152003-06-22 08:49:25 +00001574 /* Fetch LSA-Type-7 from aggregate prefix, and then
1575 * translate, Install (as Type-5), Approve, and Flood
1576 */
1577 ospf_abr_translate_nssa_range (&p, range->cost);
1578 }
1579 } /* all area ranges*/
paul718e3742002-12-13 20:15:29 +00001580 } /* all areas */
1581
1582 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001583 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001584}
1585
paul4dadc292005-05-06 21:37:42 +00001586static void
paul147193a2003-04-19 00:31:59 +00001587ospf_abr_announce_stub_defaults (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001588{
hasso52dc7ee2004-09-23 19:18:23 +00001589 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001590 struct ospf_area *area;
1591 struct prefix_ipv4 p;
1592
paul147193a2003-04-19 00:31:59 +00001593 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001594 return;
1595
1596 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001597 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
paul718e3742002-12-13 20:15:29 +00001598
1599 p.family = AF_INET;
1600 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1601 p.prefixlen = 0;
1602
paul1eb8ef22005-04-07 07:30:20 +00001603 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001604 {
paul718e3742002-12-13 20:15:29 +00001605 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001606 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1607 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001608
pauld4a53d52003-07-12 21:30:57 +00001609 if ( (area->external_routing != OSPF_AREA_STUB)
pauld4a53d52003-07-12 21:30:57 +00001610 && (area->external_routing != OSPF_AREA_NSSA)
pauld4a53d52003-07-12 21:30:57 +00001611 )
1612 continue;
paul718e3742002-12-13 20:15:29 +00001613
1614 if (OSPF_IS_AREA_BACKBONE (area))
pauld4a53d52003-07-12 21:30:57 +00001615 continue; /* Sanity Check */
1616
paul718e3742002-12-13 20:15:29 +00001617 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001618 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1619 "announcing 0.0.0.0/0 to area %s",
pauld4a53d52003-07-12 21:30:57 +00001620 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001621 ospf_abr_announce_network_to_area (&p, area->default_cost, area);
1622 }
1623
1624 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001625 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
paul718e3742002-12-13 20:15:29 +00001626}
1627
paul4dadc292005-05-06 21:37:42 +00001628static int
paul147193a2003-04-19 00:31:59 +00001629ospf_abr_remove_unapproved_translates_apply (struct ospf *ospf,
1630 struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001631{
1632 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)
1633 && ! CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1634 {
1635 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1636 "removing unapproved translates, ID: %s",
1637 inet_ntoa (lsa->data->id));
1638
1639 /* FLUSH THROUGHOUT AS */
paul147193a2003-04-19 00:31:59 +00001640 ospf_lsa_flush_as (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001641
1642 /* DISCARD from LSDB */
1643 }
1644 return 0;
1645}
1646
paul4dadc292005-05-06 21:37:42 +00001647static void
paul147193a2003-04-19 00:31:59 +00001648ospf_abr_remove_unapproved_translates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001649{
paul147193a2003-04-19 00:31:59 +00001650 struct route_node *rn;
1651 struct ospf_lsa *lsa;
1652
paul718e3742002-12-13 20:15:29 +00001653 /* All AREA PROCESS should have APPROVED necessary LSAs */
1654 /* Remove any left over and not APPROVED */
1655 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001656 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001657
paul147193a2003-04-19 00:31:59 +00001658 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1659 ospf_abr_remove_unapproved_translates_apply (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001660
1661 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001662 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001663}
paul718e3742002-12-13 20:15:29 +00001664
paul4dadc292005-05-06 21:37:42 +00001665static void
paul147193a2003-04-19 00:31:59 +00001666ospf_abr_remove_unapproved_summaries (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001667{
hasso52dc7ee2004-09-23 19:18:23 +00001668 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001669 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001670 struct route_node *rn;
1671 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +00001672
1673 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001674 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
paul718e3742002-12-13 20:15:29 +00001675
paul1eb8ef22005-04-07 07:30:20 +00001676 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001677 {
paul718e3742002-12-13 20:15:29 +00001678 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001679 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
paul718e3742002-12-13 20:15:29 +00001680 "looking at area %s", inet_ntoa (area->area_id));
1681
paul147193a2003-04-19 00:31:59 +00001682 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
1683 if (ospf_lsa_is_self_originated (ospf, lsa))
1684 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1685 ospf_lsa_flush_area (lsa, area);
1686
1687 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
1688 if (ospf_lsa_is_self_originated (ospf, lsa))
1689 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1690 ospf_lsa_flush_area (lsa, area);
paul718e3742002-12-13 20:15:29 +00001691 }
1692
1693 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001694 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
paul718e3742002-12-13 20:15:29 +00001695}
1696
paul4dadc292005-05-06 21:37:42 +00001697static void
paul147193a2003-04-19 00:31:59 +00001698ospf_abr_manage_discard_routes (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001699{
paul1eb8ef22005-04-07 07:30:20 +00001700 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001701 struct route_node *rn;
1702 struct ospf_area *area;
1703 struct ospf_area_range *range;
1704
paul1eb8ef22005-04-07 07:30:20 +00001705 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
1706 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1707 if ((range = rn->info) != NULL)
1708 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1709 {
1710 if (range->specifics)
1711 ospf_add_discard_route (ospf->new_table, area,
1712 (struct prefix_ipv4 *) &rn->p);
1713 else
JR Rivers8fc9e002012-09-24 17:26:46 +00001714 ospf_delete_discard_route (ospf->new_table,
1715 (struct prefix_ipv4 *) &rn->p);
paul1eb8ef22005-04-07 07:30:20 +00001716 }
paul718e3742002-12-13 20:15:29 +00001717}
1718
paul718e3742002-12-13 20:15:29 +00001719/* This is the function taking care about ABR NSSA, i.e. NSSA
1720 Translator, -LSA aggregation and flooding. For all NSSAs
1721
1722 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1723 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1724 with the P-bit set.
1725
1726 Any received Type-5s are legal for an ABR, else illegal for IR.
1727 Received Type-7s are installed, by area, with incoming P-bit. They
1728 are flooded; if the Elected NSSA Translator, then P-bit off.
1729
1730 Additionally, this ABR will place "translated type-7's" into the
1731 Type-5 LSDB in order to keep track of APPROVAL or not.
1732
1733 It will scan through every area, looking for Type-7 LSAs with P-Bit
1734 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1735 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1736 5-INSTALLED.
1737
1738 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1739 left over are FLUSHED and DISCARDED.
1740
1741 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1742 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1743
paul4dadc292005-05-06 21:37:42 +00001744static void
paul147193a2003-04-19 00:31:59 +00001745ospf_abr_nssa_task (struct ospf *ospf) /* called only if any_nssa */
paul718e3742002-12-13 20:15:29 +00001746{
1747 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001748 zlog_debug ("Check for NSSA-ABR Tasks():");
paul718e3742002-12-13 20:15:29 +00001749
paul147193a2003-04-19 00:31:59 +00001750 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001751 return;
1752
paul147193a2003-04-19 00:31:59 +00001753 if (! ospf->anyNSSA)
paul718e3742002-12-13 20:15:29 +00001754 return;
1755
1756 /* Each area must confirm TranslatorRole */
1757 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001758 zlog_debug ("ospf_abr_nssa_task(): Start");
paul718e3742002-12-13 20:15:29 +00001759
1760 /* For all Global Entries flagged "local-translate", unset APPROVED */
1761 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001762 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
paul718e3742002-12-13 20:15:29 +00001763
paul147193a2003-04-19 00:31:59 +00001764 ospf_abr_unapprove_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001765
1766 /* RESET all Ranges in every Area, same as summaries */
1767 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001768 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
paule2c6c152003-06-22 08:49:25 +00001769 ospf_abr_prepare_aggregates (ospf); /*TURNED OFF just for now */
paul718e3742002-12-13 20:15:29 +00001770
1771 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
paule2c6c152003-06-22 08:49:25 +00001772 * Aggregate as Type-7
1773 * Install or Approve in Type-5 Global LSDB
1774 */
paul718e3742002-12-13 20:15:29 +00001775 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001776 zlog_debug ("ospf_abr_nssa_task(): process translates");
paul147193a2003-04-19 00:31:59 +00001777 ospf_abr_process_nssa_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001778
1779 /* Translate/Send any "ranged" aggregates, and also 5-Install and
paule2c6c152003-06-22 08:49:25 +00001780 * Approve
1781 * Scan Type-7's for aggregates, translate to Type-5's,
1782 * Install/Flood/Approve
1783 */
paul718e3742002-12-13 20:15:29 +00001784 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001785 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
paule2c6c152003-06-22 08:49:25 +00001786 ospf_abr_send_nssa_aggregates (ospf); /*TURNED OFF FOR NOW */
paul718e3742002-12-13 20:15:29 +00001787
pauld4a53d52003-07-12 21:30:57 +00001788 /* Send any NSSA defaults as Type-5
1789 *if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001790 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
pauld4a53d52003-07-12 21:30:57 +00001791 *ospf_abr_announce_nssa_defaults (ospf);
1792 * havnt a clue what above is supposed to do.
1793 */
paul718e3742002-12-13 20:15:29 +00001794
1795 /* Flush any unapproved previous translates from Global Data Base */
1796 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001797 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
paul147193a2003-04-19 00:31:59 +00001798 ospf_abr_remove_unapproved_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001799
paul147193a2003-04-19 00:31:59 +00001800 ospf_abr_manage_discard_routes (ospf); /* same as normal...discard */
paul718e3742002-12-13 20:15:29 +00001801
1802 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001803 zlog_debug ("ospf_abr_nssa_task(): Stop");
paul718e3742002-12-13 20:15:29 +00001804}
paul718e3742002-12-13 20:15:29 +00001805
1806/* This is the function taking care about ABR stuff, i.e.
1807 summary-LSA origination and flooding. */
1808void
paul147193a2003-04-19 00:31:59 +00001809ospf_abr_task (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001810{
1811 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001812 zlog_debug ("ospf_abr_task(): Start");
paul718e3742002-12-13 20:15:29 +00001813
paul147193a2003-04-19 00:31:59 +00001814 if (ospf->new_table == NULL || ospf->new_rtrs == NULL)
paul718e3742002-12-13 20:15:29 +00001815 {
1816 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001817 zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
paul718e3742002-12-13 20:15:29 +00001818 return;
1819 }
1820
1821 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001822 zlog_debug ("ospf_abr_task(): unapprove summaries");
paul147193a2003-04-19 00:31:59 +00001823 ospf_abr_unapprove_summaries (ospf);
paul718e3742002-12-13 20:15:29 +00001824
1825 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001826 zlog_debug ("ospf_abr_task(): prepare aggregates");
paul147193a2003-04-19 00:31:59 +00001827 ospf_abr_prepare_aggregates (ospf);
paul718e3742002-12-13 20:15:29 +00001828
paul147193a2003-04-19 00:31:59 +00001829 if (IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001830 {
1831 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001832 zlog_debug ("ospf_abr_task(): process network RT");
paul147193a2003-04-19 00:31:59 +00001833 ospf_abr_process_network_rt (ospf, ospf->new_table);
paul718e3742002-12-13 20:15:29 +00001834
1835 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001836 zlog_debug ("ospf_abr_task(): process router RT");
paul147193a2003-04-19 00:31:59 +00001837 ospf_abr_process_router_rt (ospf, ospf->new_rtrs);
paul718e3742002-12-13 20:15:29 +00001838
1839 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001840 zlog_debug ("ospf_abr_task(): announce aggregates");
paul147193a2003-04-19 00:31:59 +00001841 ospf_abr_announce_aggregates (ospf);
paul718e3742002-12-13 20:15:29 +00001842
1843 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001844 zlog_debug ("ospf_abr_task(): announce stub defaults");
paul147193a2003-04-19 00:31:59 +00001845 ospf_abr_announce_stub_defaults (ospf);
paul718e3742002-12-13 20:15:29 +00001846 }
1847
1848 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001849 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
paul147193a2003-04-19 00:31:59 +00001850 ospf_abr_remove_unapproved_summaries (ospf);
paul718e3742002-12-13 20:15:29 +00001851
paul147193a2003-04-19 00:31:59 +00001852 ospf_abr_manage_discard_routes (ospf);
paul718e3742002-12-13 20:15:29 +00001853
paul718e3742002-12-13 20:15:29 +00001854 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001855 zlog_debug ("ospf_abr_task(): Stop");
paul718e3742002-12-13 20:15:29 +00001856}
1857
paul4dadc292005-05-06 21:37:42 +00001858static int
paul147193a2003-04-19 00:31:59 +00001859ospf_abr_task_timer (struct thread *thread)
paul718e3742002-12-13 20:15:29 +00001860{
paul147193a2003-04-19 00:31:59 +00001861 struct ospf *ospf = THREAD_ARG (thread);
1862
1863 ospf->t_abr_task = 0;
paul718e3742002-12-13 20:15:29 +00001864
1865 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001866 zlog_debug ("Running ABR task on timer");
paul718e3742002-12-13 20:15:29 +00001867
paul147193a2003-04-19 00:31:59 +00001868 ospf_check_abr_status (ospf);
pauld4a53d52003-07-12 21:30:57 +00001869 ospf_abr_nssa_check_status (ospf);
paul718e3742002-12-13 20:15:29 +00001870
paul147193a2003-04-19 00:31:59 +00001871 ospf_abr_task (ospf);
paule2c6c152003-06-22 08:49:25 +00001872 ospf_abr_nssa_task (ospf); /* if nssa-abr, then scan Type-7 LSDB */
paul718e3742002-12-13 20:15:29 +00001873
paul147193a2003-04-19 00:31:59 +00001874 return 0;
paul718e3742002-12-13 20:15:29 +00001875}
1876
1877void
paul147193a2003-04-19 00:31:59 +00001878ospf_schedule_abr_task (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001879{
1880 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001881 zlog_debug ("Scheduling ABR task");
paul147193a2003-04-19 00:31:59 +00001882
1883 if (ospf->t_abr_task == NULL)
1884 ospf->t_abr_task = thread_add_timer (master, ospf_abr_task_timer,
1885 ospf, OSPF_ABR_TASK_DELAY);
paul718e3742002-12-13 20:15:29 +00001886}