blob: 225cf6edbb38a6d517cb7799adbd9a1c889377e1 [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
paul718e3742002-12-13 20:15:29 +000091ospf_area_range_delete (struct ospf_area *area, struct ospf_area_range *range)
92{
93 struct route_node *rn;
94 struct prefix_ipv4 p;
95
96 p.family = AF_INET;
97 p.prefixlen = range->masklen;
98 p.prefix = range->addr;
99
100 rn = route_node_lookup (area->ranges, (struct prefix *)&p);
101 if (rn)
102 {
103 ospf_area_range_free (rn->info);
104 rn->info = NULL;
105 route_unlock_node (rn);
106 route_unlock_node (rn);
107 }
108}
109
110struct ospf_area_range *
111ospf_area_range_lookup (struct ospf_area *area, struct prefix_ipv4 *p)
112{
113 struct route_node *rn;
114
115 rn = route_node_lookup (area->ranges, (struct prefix *)p);
116 if (rn)
117 {
118 route_unlock_node (rn);
119 return rn->info;
120 }
121 return NULL;
122}
123
124struct ospf_area_range *
pauld4a53d52003-07-12 21:30:57 +0000125ospf_area_range_lookup_next (struct ospf_area *area,
126 struct in_addr *range_net,
127 int first)
paul718e3742002-12-13 20:15:29 +0000128{
129 struct route_node *rn;
130 struct prefix_ipv4 p;
131 struct ospf_area_range *find;
132
133 p.family = AF_INET;
134 p.prefixlen = IPV4_MAX_BITLEN;
135 p.prefix = *range_net;
136
137 if (first)
138 rn = route_top (area->ranges);
139 else
140 {
141 rn = route_node_get (area->ranges, (struct prefix *) &p);
142 rn = route_next (rn);
143 }
144
145 for (; rn; rn = route_next (rn))
146 if (rn->info)
147 break;
148
149 if (rn && rn->info)
150 {
151 find = rn->info;
152 *range_net = rn->p.u.prefix4;
153 route_unlock_node (rn);
154 return find;
155 }
156 return NULL;
157}
158
paul4dadc292005-05-06 21:37:42 +0000159static struct ospf_area_range *
paul718e3742002-12-13 20:15:29 +0000160ospf_area_range_match (struct ospf_area *area, struct prefix_ipv4 *p)
161{
162 struct route_node *node;
163
164 node = route_node_match (area->ranges, (struct prefix *) p);
165 if (node)
166 {
167 route_unlock_node (node);
168 return node->info;
169 }
170 return NULL;
171}
172
173struct ospf_area_range *
174ospf_area_range_match_any (struct ospf *ospf, struct prefix_ipv4 *p)
175{
176 struct ospf_area_range *range;
paul1eb8ef22005-04-07 07:30:20 +0000177 struct ospf_area *area;
hasso52dc7ee2004-09-23 19:18:23 +0000178 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000179
paul1eb8ef22005-04-07 07:30:20 +0000180 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
181 if ((range = ospf_area_range_match (area, p)))
paul718e3742002-12-13 20:15:29 +0000182 return range;
183
184 return NULL;
185}
186
187int
188ospf_area_range_active (struct ospf_area_range *range)
189{
190 return range->specifics;
191}
192
paul4dadc292005-05-06 21:37:42 +0000193static int
paul718e3742002-12-13 20:15:29 +0000194ospf_area_actively_attached (struct ospf_area *area)
195{
196 return area->act_ints;
197}
198
199int
200ospf_area_range_set (struct ospf *ospf, struct in_addr area_id,
201 struct prefix_ipv4 *p, int advertise)
202{
203 struct ospf_area *area;
204 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000205 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000206
paul147193a2003-04-19 00:31:59 +0000207 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000208 if (area == NULL)
209 return 0;
210
211 range = ospf_area_range_lookup (area, p);
212 if (range != NULL)
213 {
214 if ((CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
215 && !CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
216 || (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
217 && CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE)))
paul147193a2003-04-19 00:31:59 +0000218 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000219 }
220 else
221 {
222 range = ospf_area_range_new (p);
223 ospf_area_range_add (area, range);
paul147193a2003-04-19 00:31:59 +0000224 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000225 }
226
227 if (CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
228 SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
229 else
230 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
231
232 return 1;
233}
234
235int
236ospf_area_range_cost_set (struct ospf *ospf, struct in_addr area_id,
237 struct prefix_ipv4 *p, u_int32_t cost)
238{
239 struct ospf_area *area;
240 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000241 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000242
paul147193a2003-04-19 00:31:59 +0000243 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000244 if (area == NULL)
245 return 0;
246
Paul Jakma214a4452006-05-12 22:51:49 +0000247 range = ospf_area_range_lookup (area, p);
paul718e3742002-12-13 20:15:29 +0000248 if (range == NULL)
249 return 0;
250
251 if (range->cost_config != cost)
252 {
253 range->cost_config = cost;
254 if (ospf_area_range_active (range))
paul147193a2003-04-19 00:31:59 +0000255 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000256 }
257
258 return 1;
259}
260
261int
262ospf_area_range_unset (struct ospf *ospf, struct in_addr area_id,
263 struct prefix_ipv4 *p)
264{
265 struct ospf_area *area;
266 struct ospf_area_range *range;
267
paul147193a2003-04-19 00:31:59 +0000268 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000269 if (area == NULL)
270 return 0;
271
272 range = ospf_area_range_lookup (area, p);
273 if (range == NULL)
274 return 0;
275
276 if (ospf_area_range_active (range))
paul147193a2003-04-19 00:31:59 +0000277 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000278
279 ospf_area_range_delete (area, range);
280
281 return 1;
282}
283
284int
285ospf_area_range_substitute_set (struct ospf *ospf, struct in_addr area_id,
286 struct prefix_ipv4 *p, struct prefix_ipv4 *s)
287{
288 struct ospf_area *area;
289 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000290 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000291
paul147193a2003-04-19 00:31:59 +0000292 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000293 range = ospf_area_range_lookup (area, p);
294
295 if (range != NULL)
296 {
297 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE) ||
298 !CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
paul147193a2003-04-19 00:31:59 +0000299 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000300 }
301 else
302 {
303 range = ospf_area_range_new (p);
304 ospf_area_range_add (area, range);
paul147193a2003-04-19 00:31:59 +0000305 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000306 }
307
308 SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
309 SET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
310 range->subst_addr = s->prefix;
311 range->subst_masklen = s->prefixlen;
312
313 return 1;
314}
315
316int
317ospf_area_range_substitute_unset (struct ospf *ospf, struct in_addr area_id,
318 struct prefix_ipv4 *p)
319{
320 struct ospf_area *area;
321 struct ospf_area_range *range;
322
paul147193a2003-04-19 00:31:59 +0000323 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000324 if (area == NULL)
325 return 0;
326
327 range = ospf_area_range_lookup (area, p);
328 if (range == NULL)
329 return 0;
330
331 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
332 if (ospf_area_range_active (range))
paul147193a2003-04-19 00:31:59 +0000333 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000334
335 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
336 range->subst_addr.s_addr = 0;
337 range->subst_masklen = 0;
338
339 return 1;
340}
341
342int
paul147193a2003-04-19 00:31:59 +0000343ospf_act_bb_connection (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000344{
paul147193a2003-04-19 00:31:59 +0000345 if (ospf->backbone == NULL)
paul718e3742002-12-13 20:15:29 +0000346 return 0;
347
paul147193a2003-04-19 00:31:59 +0000348 return ospf->backbone->full_nbrs;
paul718e3742002-12-13 20:15:29 +0000349}
350
paule2c6c152003-06-22 08:49:25 +0000351/* Determine whether this router is elected translator or not for area */
paul4dadc292005-05-06 21:37:42 +0000352static int
paule2c6c152003-06-22 08:49:25 +0000353ospf_abr_nssa_am_elected (struct ospf_area *area)
354{
355 struct route_node *rn;
356 struct ospf_lsa *lsa;
357 struct router_lsa *rlsa;
358 struct in_addr *best = NULL;
359
360 LSDB_LOOP ( ROUTER_LSDB (area), rn, lsa)
361 {
362 /* sanity checks */
363 if (!lsa
364 || (lsa->data->type != OSPF_ROUTER_LSA)
365 || IS_LSA_SELF (lsa))
366 continue;
367
368 rlsa = (struct router_lsa *) lsa->data;
369
370 /* ignore non-ABR routers */
371 if (!IS_ROUTER_LSA_BORDER (rlsa))
372 continue;
373
374 /* Router has Nt flag - always translate */
375 if (IS_ROUTER_LSA_NT (rlsa))
376 {
377 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000378 zlog_debug ("ospf_abr_nssa_am_elected: "
paule2c6c152003-06-22 08:49:25 +0000379 "router %s asserts Nt",
380 inet_ntoa (lsa->data->id) );
381 return 0;
382 }
383
384 if (best == NULL)
385 best = &lsa->data->id;
386 else
387 if ( IPV4_ADDR_CMP (&best, &lsa->data->id) < 0)
388 best = &lsa->data->id;
389 }
390
391 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000392 zlog_debug ("ospf_abr_nssa_am_elected: best electable ABR is: %s",
paule2c6c152003-06-22 08:49:25 +0000393 (best) ? inet_ntoa (*best) : "<none>" );
394
395 if (best == NULL)
396 return 1;
397
398 if ( IPV4_ADDR_CMP (&best, &area->ospf->router_id) < 0)
399 return 1;
400 else
401 return 0;
402}
403
404/* Check NSSA ABR status
405 * assumes there are nssa areas
406 */
paul4dadc292005-05-06 21:37:42 +0000407static void
paule2c6c152003-06-22 08:49:25 +0000408ospf_abr_nssa_check_status (struct ospf *ospf)
409{
410 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000411 struct listnode *lnode, *nnode;
paule2c6c152003-06-22 08:49:25 +0000412
paul1eb8ef22005-04-07 07:30:20 +0000413 for (ALL_LIST_ELEMENTS (ospf->areas, lnode, nnode, area))
paule2c6c152003-06-22 08:49:25 +0000414 {
415
416 if (area->external_routing != OSPF_AREA_NSSA)
417 continue;
418
419 if (IS_DEBUG_OSPF (nssa, NSSA))
ajse84cc642004-12-08 17:28:56 +0000420 zlog_debug ("ospf_abr_nssa_check_status: "
paule2c6c152003-06-22 08:49:25 +0000421 "checking area %s",
422 inet_ntoa (area->area_id));
423
424 if (!IS_OSPF_ABR (area->ospf))
425 {
426 if (IS_DEBUG_OSPF (nssa, NSSA))
ajse84cc642004-12-08 17:28:56 +0000427 zlog_debug ("ospf_abr_nssa_check_status: "
428 "not ABR");
pauld4a53d52003-07-12 21:30:57 +0000429 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
paule2c6c152003-06-22 08:49:25 +0000430 continue;
431 }
432
433 switch (area->NSSATranslatorRole)
434 {
435 case OSPF_NSSA_ROLE_NEVER:
436 /* We never Translate Type-7 LSA. */
437 /* TODO: check previous state and flush? */
438 if (IS_DEBUG_OSPF (nssa, NSSA))
ajse84cc642004-12-08 17:28:56 +0000439 zlog_debug ("ospf_abr_nssa_check_status: "
440 "never translate");
pauld4a53d52003-07-12 21:30:57 +0000441 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
paule2c6c152003-06-22 08:49:25 +0000442 continue;
443
444 case OSPF_NSSA_ROLE_ALWAYS:
445 /* We always translate if we are an ABR
446 * TODO: originate new LSAs if state change?
447 * or let the nssa abr task take care of it?
448 */
449 if (IS_DEBUG_OSPF (nssa, NSSA))
ajse84cc642004-12-08 17:28:56 +0000450 zlog_debug ("ospf_abr_nssa_check_status: "
451 "translate always");
pauld4a53d52003-07-12 21:30:57 +0000452 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
paule2c6c152003-06-22 08:49:25 +0000453 continue;
454
455 case OSPF_NSSA_ROLE_CANDIDATE:
456 /* We are a candidate for Translation */
457 if (ospf_abr_nssa_am_elected (area) > 0 )
458 {
pauld4a53d52003-07-12 21:30:57 +0000459 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
paule2c6c152003-06-22 08:49:25 +0000460 if (IS_DEBUG_OSPF (nssa, NSSA))
ajse84cc642004-12-08 17:28:56 +0000461 zlog_debug ("ospf_abr_nssa_check_status: "
462 "elected translator");
paule2c6c152003-06-22 08:49:25 +0000463 }
464 else
465 {
pauld4a53d52003-07-12 21:30:57 +0000466 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
paule2c6c152003-06-22 08:49:25 +0000467 if (IS_DEBUG_OSPF (nssa, NSSA))
ajse84cc642004-12-08 17:28:56 +0000468 zlog_debug ("ospf_abr_nssa_check_status: "
469 "not elected");
paule2c6c152003-06-22 08:49:25 +0000470 }
471 continue;
472 }
473 }
474}
paule2c6c152003-06-22 08:49:25 +0000475
paul718e3742002-12-13 20:15:29 +0000476/* Check area border router status. */
477void
paul147193a2003-04-19 00:31:59 +0000478ospf_check_abr_status (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000479{
480 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000481 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000482 int bb_configured = 0;
483 int bb_act_attached = 0;
484 int areas_configured = 0;
485 int areas_act_attached = 0;
paul147193a2003-04-19 00:31:59 +0000486 u_char new_flags = ospf->flags;
paul718e3742002-12-13 20:15:29 +0000487
488 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000489 zlog_debug ("ospf_check_abr_status(): Start");
paul718e3742002-12-13 20:15:29 +0000490
paul1eb8ef22005-04-07 07:30:20 +0000491 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
paul718e3742002-12-13 20:15:29 +0000492 {
paul718e3742002-12-13 20:15:29 +0000493 if (listcount (area->oiflist))
494 {
495 areas_configured++;
496
497 if (OSPF_IS_AREA_BACKBONE (area))
498 bb_configured = 1;
499 }
500
501 if (ospf_area_actively_attached (area))
502 {
503 areas_act_attached++;
504
505 if (OSPF_IS_AREA_BACKBONE (area))
506 bb_act_attached = 1;
507 }
508 }
509
510 if (IS_DEBUG_OSPF_EVENT)
511 {
ajse84cc642004-12-08 17:28:56 +0000512 zlog_debug ("ospf_check_abr_status(): looked through areas");
513 zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured);
514 zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
paul718e3742002-12-13 20:15:29 +0000515 bb_act_attached);
ajse84cc642004-12-08 17:28:56 +0000516 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
paul718e3742002-12-13 20:15:29 +0000517 areas_configured);
ajse84cc642004-12-08 17:28:56 +0000518 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
paul718e3742002-12-13 20:15:29 +0000519 areas_act_attached);
520 }
521
paul147193a2003-04-19 00:31:59 +0000522 switch (ospf->abr_type)
paul718e3742002-12-13 20:15:29 +0000523 {
524 case OSPF_ABR_SHORTCUT:
525 case OSPF_ABR_STAND:
526 if (areas_act_attached > 1)
527 SET_FLAG (new_flags, OSPF_FLAG_ABR);
528 else
529 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
530 break;
531
532 case OSPF_ABR_IBM:
533 if ((areas_act_attached > 1) && bb_configured)
534 SET_FLAG (new_flags, OSPF_FLAG_ABR);
535 else
536 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
537 break;
538
539 case OSPF_ABR_CISCO:
540 if ((areas_configured > 1) && bb_act_attached)
541 SET_FLAG (new_flags, OSPF_FLAG_ABR);
542 else
543 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
544 break;
545 default:
546 break;
547 }
548
paul147193a2003-04-19 00:31:59 +0000549 if (new_flags != ospf->flags)
paul718e3742002-12-13 20:15:29 +0000550 {
paul147193a2003-04-19 00:31:59 +0000551 ospf_spf_calculate_schedule (ospf);
paul718e3742002-12-13 20:15:29 +0000552 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000553 zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags);
paul147193a2003-04-19 00:31:59 +0000554 ospf->flags = new_flags;
555 OSPF_TIMER_ON (ospf->t_router_lsa_update,
paul718e3742002-12-13 20:15:29 +0000556 ospf_router_lsa_update_timer, OSPF_LSA_UPDATE_DELAY);
557 }
558}
559
paul4dadc292005-05-06 21:37:42 +0000560static void
paul718e3742002-12-13 20:15:29 +0000561ospf_abr_update_aggregate (struct ospf_area_range *range,
paul7f352b82004-02-19 19:37:47 +0000562 struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000563{
564 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000565 zlog_debug ("ospf_abr_update_aggregate(): Start");
paul718e3742002-12-13 20:15:29 +0000566
paul6c835672004-10-11 11:00:30 +0000567 if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
paul718e3742002-12-13 20:15:29 +0000568 {
569 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000570 zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
paul7f352b82004-02-19 19:37:47 +0000571 range->cost_config);
paul718e3742002-12-13 20:15:29 +0000572
573 range->cost = range->cost_config;
574 }
575 else
576 {
577 if (range->specifics == 0)
paul7f352b82004-02-19 19:37:47 +0000578 range->cost = or->cost; /* 1st time get 1st cost */
paul718e3742002-12-13 20:15:29 +0000579
paul7f352b82004-02-19 19:37:47 +0000580 if (or->cost > range->cost)
581 {
582 if (IS_DEBUG_OSPF_EVENT)
paul500e4182005-05-26 17:11:13 +0000583 zlog_debug ("ospf_abr_update_aggregate(): largest cost, update");
paul718e3742002-12-13 20:15:29 +0000584
paul7f352b82004-02-19 19:37:47 +0000585 range->cost = or->cost;
586 }
paul718e3742002-12-13 20:15:29 +0000587 }
588
589 range->specifics++;
590}
591
592static void
593set_metric (struct ospf_lsa *lsa, u_int32_t metric)
594{
595 struct summary_lsa *header;
596 u_char *mp;
597 metric = htonl (metric);
hassoc9e52be2004-09-26 16:09:34 +0000598 mp = (u_char *) &metric;
paul718e3742002-12-13 20:15:29 +0000599 mp++;
600 header = (struct summary_lsa *) lsa->data;
601 memcpy(header->metric, mp, 3);
602}
603
paul4dadc292005-05-06 21:37:42 +0000604static int
paul718e3742002-12-13 20:15:29 +0000605ospf_abr_check_nssa_range (struct prefix_ipv4 *p, u_int32_t cost,
606 struct ospf_area *area)
607{
608 /* The Type-7 is tested against the aggregated prefix and forwarded
609 for lsa installation and flooding */
610 return 0;
611}
612
613/* ospf_abr_translate_nssa */
paul4dadc292005-05-06 21:37:42 +0000614static int
paul147193a2003-04-19 00:31:59 +0000615ospf_abr_translate_nssa (struct ospf_area *area, struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000616{
617 /* Incoming Type-7 or later aggregated Type-7
pauld4a53d52003-07-12 21:30:57 +0000618 *
619 * LSA is skipped if P-bit is off.
620 * LSA is aggregated if within range.
621 *
622 * The Type-7 is translated, Installed/Approved as a Type-5 into
623 * global LSDB, then Flooded through AS
624 *
625 * Later, any Unapproved Translated Type-5's are flushed/discarded
626 */
paul718e3742002-12-13 20:15:29 +0000627
pauld4a53d52003-07-12 21:30:57 +0000628 struct ospf_lsa *old = NULL,
629 *new = NULL;
630 struct as_external_lsa *ext7;
631 struct prefix_ipv4 p;
paul718e3742002-12-13 20:15:29 +0000632
633 if (! CHECK_FLAG (lsa->data->options, OSPF_OPTION_NP))
634 {
635 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000636 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
pauld4a53d52003-07-12 21:30:57 +0000637 inet_ntoa (lsa->data->id));
638 return 1;
paul718e3742002-12-13 20:15:29 +0000639 }
pauld4a53d52003-07-12 21:30:57 +0000640
paul718e3742002-12-13 20:15:29 +0000641 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000642 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
pauld4a53d52003-07-12 21:30:57 +0000643 inet_ntoa (lsa->data->id));
paul718e3742002-12-13 20:15:29 +0000644
pauld4a53d52003-07-12 21:30:57 +0000645 ext7 = (struct as_external_lsa *)(lsa->data);
646 p.prefix = lsa->data->id;
647 p.prefixlen = ip_masklen (ext7->mask);
648
649 if (ext7->e[0].fwd_addr.s_addr == OSPF_DEFAULT_DESTINATION)
650 {
651 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000652 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, "
pauld4a53d52003-07-12 21:30:57 +0000653 "Forward address is 0, NO Translation",
654 inet_ntoa (lsa->data->id));
655 return 1;
656 }
657
658 /* try find existing AS-External LSA for this prefix */
659
660 old = ospf_external_info_find_lsa (area->ospf, &p);
661
662 if (old)
663 {
664 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000665 zlog_debug ("ospf_abr_translate_nssa(): "
pauld4a53d52003-07-12 21:30:57 +0000666 "found old translated LSA Id %s, refreshing",
667 inet_ntoa (old->data->id));
668
669 /* refresh */
670 new = ospf_translated_nssa_refresh (area->ospf, lsa, old);
671 if (!new)
672 {
673 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000674 zlog_debug ("ospf_abr_translate_nssa(): "
pauld4a53d52003-07-12 21:30:57 +0000675 "could not refresh translated LSA Id %s",
676 inet_ntoa (old->data->id));
677 }
678 }
679 else
680 {
681 /* no existing external route for this LSA Id
682 * originate translated LSA
683 */
684
685 if ((new = ospf_translated_nssa_originate (area->ospf, lsa))
686 == NULL)
687 {
688 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000689 zlog_debug ("ospf_abr_translate_nssa(): Could not translate "
pauld4a53d52003-07-12 21:30:57 +0000690 "Type-7 for %s to Type-5",
691 inet_ntoa (lsa->data->id));
692 return 1;
693 }
694 }
paul718e3742002-12-13 20:15:29 +0000695
696 /* Area where Aggregate testing will be inserted, just like summary
697 advertisements */
698 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
699
paul718e3742002-12-13 20:15:29 +0000700 return 0;
701}
702
paul4dadc292005-05-06 21:37:42 +0000703static void
paul718e3742002-12-13 20:15:29 +0000704ospf_abr_translate_nssa_range (struct prefix_ipv4 *p, u_int32_t cost)
705{
706 /* The Type-7 is created from the aggregated prefix and forwarded
707 for lsa installation and flooding... to be added... */
708}
paul718e3742002-12-13 20:15:29 +0000709
vincentba682532005-09-29 13:52:57 +0000710void
paul718e3742002-12-13 20:15:29 +0000711ospf_abr_announce_network_to_area (struct prefix_ipv4 *p, u_int32_t cost,
712 struct ospf_area *area)
713{
714 struct ospf_lsa *lsa, *old = NULL;
715 struct summary_lsa *sl = NULL;
716
717 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000718 zlog_debug ("ospf_abr_announce_network_to_area(): Start");
paul718e3742002-12-13 20:15:29 +0000719
pauld4a53d52003-07-12 21:30:57 +0000720 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_SUMMARY_LSA,
721 (struct prefix_ipv4 *) p,
722 area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +0000723 if (old)
724 {
725 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000726 zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
pauld4a53d52003-07-12 21:30:57 +0000727
paul718e3742002-12-13 20:15:29 +0000728 sl = (struct summary_lsa *) old->data;
729
730 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000731 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000732 "old metric: %d, new metric: %d",
733 GET_METRIC (sl->metric), cost);
734
735 if (GET_METRIC (sl->metric) == cost)
736 {
737 /* unchanged. simply reapprove it */
738 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000739 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000740 "old summary approved");
741 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
742 }
743 else
744 {
745 /* LSA is changed, refresh it */
746 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000747 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000748 "refreshing summary");
749 set_metric (old, cost);
750 lsa = ospf_summary_lsa_refresh (area->ospf, old);
paulc24d6022005-11-20 14:54:12 +0000751
752 if (!lsa)
753 {
754 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
755
756 prefix2str ((struct prefix *) p, buf, sizeof(buf));
757 zlog_warn ("%s: Could not refresh %s to %s",
758 __func__,
759 buf,
760 inet_ntoa (area->area_id));
761 return;
762 }
763
paulc8987752005-07-26 06:07:22 +0000764 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
pauld4a53d52003-07-12 21:30:57 +0000765 /* This will flood through area. */
766 }
paul718e3742002-12-13 20:15:29 +0000767 }
768 else
769 {
770 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000771 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000772 "creating new summary");
773 lsa = ospf_summary_lsa_originate ( (struct prefix_ipv4 *)p, cost, area);
774 /* This will flood through area. */
paul718e3742002-12-13 20:15:29 +0000775
paulc24d6022005-11-20 14:54:12 +0000776 if (!lsa)
777 {
778 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
779
780 prefix2str ((struct prefix *)p, buf, sizeof(buf));
781 zlog_warn ("%s: Could not originate %s to %s",
782 __func__,
783 buf,
784 inet_ntoa (area->area_id));
785 return;
786 }
787
paul718e3742002-12-13 20:15:29 +0000788 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
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 "flooding new version of summary");
paul718e3742002-12-13 20:15:29 +0000792 }
793
794 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000795 zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
paul718e3742002-12-13 20:15:29 +0000796}
797
paul4dadc292005-05-06 21:37:42 +0000798static int
paul718e3742002-12-13 20:15:29 +0000799ospf_abr_nexthops_belong_to_area (struct ospf_route *or,
800 struct ospf_area *area)
801{
paul1eb8ef22005-04-07 07:30:20 +0000802 struct listnode *node, *nnode;
paul96735ee2003-08-10 02:51:22 +0000803 struct ospf_path *path;
paul718e3742002-12-13 20:15:29 +0000804
paul1eb8ef22005-04-07 07:30:20 +0000805 for (ALL_LIST_ELEMENTS (or->paths, node, nnode, path))
paul718e3742002-12-13 20:15:29 +0000806 {
paul718e3742002-12-13 20:15:29 +0000807 struct ospf_interface *oi = path->oi;
808
809 if (oi != NULL)
paul96735ee2003-08-10 02:51:22 +0000810 if (oi->area == area)
811 return 1;
paul718e3742002-12-13 20:15:29 +0000812 }
813
814 return 0;
815}
816
paul4dadc292005-05-06 21:37:42 +0000817static int
pauld4a53d52003-07-12 21:30:57 +0000818ospf_abr_should_accept (struct prefix_ipv4 *p, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +0000819{
820 if (IMPORT_NAME (area))
821 {
822 if (IMPORT_LIST (area) == NULL)
823 IMPORT_LIST (area) = access_list_lookup (AFI_IP, IMPORT_NAME (area));
824
825 if (IMPORT_LIST (area))
826 if (access_list_apply (IMPORT_LIST (area), p) == FILTER_DENY)
827 return 0;
828 }
829
830 return 1;
831}
832
paul4dadc292005-05-06 21:37:42 +0000833static int
paul718e3742002-12-13 20:15:29 +0000834ospf_abr_plist_in_check (struct ospf_area *area, struct ospf_route *or,
pauld4a53d52003-07-12 21:30:57 +0000835 struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000836{
837 if (PREFIX_NAME_IN (area))
838 {
839 if (PREFIX_LIST_IN (area) == NULL)
840 PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP,
841 PREFIX_NAME_IN (area));
842 if (PREFIX_LIST_IN (area))
843 if (prefix_list_apply (PREFIX_LIST_IN (area), p) != PREFIX_PERMIT)
844 return 0;
845 }
846 return 1;
847}
848
paul4dadc292005-05-06 21:37:42 +0000849static int
paul718e3742002-12-13 20:15:29 +0000850ospf_abr_plist_out_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_OUT (area))
854 {
855 if (PREFIX_LIST_OUT (area) == NULL)
856 PREFIX_LIST_OUT (area) = prefix_list_lookup (AFI_IP,
857 PREFIX_NAME_OUT (area));
858 if (PREFIX_LIST_OUT (area))
859 if (prefix_list_apply (PREFIX_LIST_OUT (area), p) != PREFIX_PERMIT)
860 return 0;
861 }
862 return 1;
863}
864
paul4dadc292005-05-06 21:37:42 +0000865static void
paul147193a2003-04-19 00:31:59 +0000866ospf_abr_announce_network (struct ospf *ospf,
pauld4a53d52003-07-12 21:30:57 +0000867 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000868{
paul718e3742002-12-13 20:15:29 +0000869 struct ospf_area_range *range;
paul718e3742002-12-13 20:15:29 +0000870 struct ospf_area *area, *or_area;
hasso52dc7ee2004-09-23 19:18:23 +0000871 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000872
873 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000874 zlog_debug ("ospf_abr_announce_network(): Start");
paul718e3742002-12-13 20:15:29 +0000875
paul147193a2003-04-19 00:31:59 +0000876 or_area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
paul718e3742002-12-13 20:15:29 +0000877 assert (or_area);
878
paul1eb8ef22005-04-07 07:30:20 +0000879 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000880 {
paul718e3742002-12-13 20:15:29 +0000881 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000882 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
paul718e3742002-12-13 20:15:29 +0000883 inet_ntoa (area->area_id));
884
885 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
886 continue;
887
888 if (ospf_abr_nexthops_belong_to_area (or, area))
889 continue;
890
pauld4a53d52003-07-12 21:30:57 +0000891 if (!ospf_abr_should_accept (p, area))
paul718e3742002-12-13 20:15:29 +0000892 {
893 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000894 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000895 "prefix %s/%d was denied by import-list",
896 inet_ntoa (p->prefix), p->prefixlen);
897 continue;
898 }
899
pauld4a53d52003-07-12 21:30:57 +0000900 if (!ospf_abr_plist_in_check (area, or, p))
paul718e3742002-12-13 20:15:29 +0000901 {
902 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000903 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000904 "prefix %s/%d was denied by prefix-list",
905 inet_ntoa (p->prefix), p->prefixlen);
906 continue;
907 }
908
909 if (area->external_routing != OSPF_AREA_DEFAULT && area->no_summary)
910 {
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 "area %s is stub and no_summary",
914 inet_ntoa (area->area_id));
915 continue;
916 }
917
918 if (or->path_type == OSPF_PATH_INTER_AREA)
919 {
920 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000921 zlog_debug ("ospf_abr_announce_network(): this is "
paul718e3742002-12-13 20:15:29 +0000922 "inter-area route to %s/%d",
923 inet_ntoa (p->prefix), p->prefixlen);
924
925 if (!OSPF_IS_AREA_BACKBONE (area))
926 ospf_abr_announce_network_to_area (p, or->cost, area);
927 }
928
929 if (or->path_type == OSPF_PATH_INTRA_AREA)
pauld4a53d52003-07-12 21:30:57 +0000930 {
931 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000932 zlog_debug ("ospf_abr_announce_network(): "
pauld4a53d52003-07-12 21:30:57 +0000933 "this is intra-area route to %s/%d",
934 inet_ntoa (p->prefix), p->prefixlen);
935 if ((range = ospf_area_range_match (or_area, p))
936 && !ospf_area_is_transit (area))
937 ospf_abr_update_aggregate (range, or);
938 else
939 ospf_abr_announce_network_to_area (p, or->cost, area);
940 }
paul718e3742002-12-13 20:15:29 +0000941 }
942}
943
paul4dadc292005-05-06 21:37:42 +0000944static int
paul147193a2003-04-19 00:31:59 +0000945ospf_abr_should_announce (struct ospf *ospf,
pauld4a53d52003-07-12 21:30:57 +0000946 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000947{
paul147193a2003-04-19 00:31:59 +0000948 struct ospf_area *area;
949
950 area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
paul718e3742002-12-13 20:15:29 +0000951
952 assert (area);
953
954 if (EXPORT_NAME (area))
955 {
956 if (EXPORT_LIST (area) == NULL)
957 EXPORT_LIST (area) = access_list_lookup (AFI_IP, EXPORT_NAME (area));
958
959 if (EXPORT_LIST (area))
960 if (access_list_apply (EXPORT_LIST (area), p) == FILTER_DENY)
961 return 0;
962 }
963
964 return 1;
965}
966
paul4dadc292005-05-06 21:37:42 +0000967static void
paul147193a2003-04-19 00:31:59 +0000968ospf_abr_process_nssa_translates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000969{
970 /* Scan through all NSSA_LSDB records for all areas;
971
972 If P-bit is on, translate all Type-7's to 5's and aggregate or
973 flood install as approved in Type-5 LSDB with XLATE Flag on
974 later, do same for all aggregates... At end, DISCARD all
975 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
hasso52dc7ee2004-09-23 19:18:23 +0000976 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000977 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +0000978 struct route_node *rn;
979 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000980
981 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000982 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
paul718e3742002-12-13 20:15:29 +0000983
paul1eb8ef22005-04-07 07:30:20 +0000984 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000985 {
paule2c6c152003-06-22 08:49:25 +0000986 if (! area->NSSATranslatorState)
pauld4a53d52003-07-12 21:30:57 +0000987 continue; /* skip if not translator */
paul718e3742002-12-13 20:15:29 +0000988
989 if (area->external_routing != OSPF_AREA_NSSA)
pauld4a53d52003-07-12 21:30:57 +0000990 continue; /* skip if not Nssa Area */
paul718e3742002-12-13 20:15:29 +0000991
992 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000993 zlog_debug ("ospf_abr_process_nssa_translates(): "
pauld4a53d52003-07-12 21:30:57 +0000994 "looking at area %s", inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +0000995
paul147193a2003-04-19 00:31:59 +0000996 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +0000997 ospf_abr_translate_nssa (area, lsa);
paul718e3742002-12-13 20:15:29 +0000998 }
999
1000 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001001 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001002
1003}
paul718e3742002-12-13 20:15:29 +00001004
paul4dadc292005-05-06 21:37:42 +00001005static void
paul147193a2003-04-19 00:31:59 +00001006ospf_abr_process_network_rt (struct ospf *ospf,
1007 struct route_table *rt)
paul718e3742002-12-13 20:15:29 +00001008{
paul718e3742002-12-13 20:15:29 +00001009 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001010 struct ospf_route *or;
1011 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +00001012
1013 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001014 zlog_debug ("ospf_abr_process_network_rt(): Start");
paul718e3742002-12-13 20:15:29 +00001015
1016 for (rn = route_top (rt); rn; rn = route_next (rn))
1017 {
1018 if ((or = rn->info) == NULL)
1019 continue;
1020
paul147193a2003-04-19 00:31:59 +00001021 if (!(area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id)))
paul718e3742002-12-13 20:15:29 +00001022 {
1023 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001024 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
paul718e3742002-12-13 20:15:29 +00001025 inet_ntoa (or->u.std.area_id));
1026 continue;
1027 }
1028
1029 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001030 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
paul718e3742002-12-13 20:15:29 +00001031 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
1032 if (or->path_type >= OSPF_PATH_TYPE1_EXTERNAL)
1033 {
1034 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001035 zlog_debug ("ospf_abr_process_network_rt(): "
paul718e3742002-12-13 20:15:29 +00001036 "this is an External router, skipping");
1037 continue;
1038 }
1039
1040 if (or->cost >= OSPF_LS_INFINITY)
1041 {
1042 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001043 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001044 " this route's cost is infinity, skipping");
1045 continue;
1046 }
1047
1048 if (or->type == OSPF_DESTINATION_DISCARD)
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 a discard entry, skipping");
1053 continue;
1054 }
1055
1056 if (or->path_type == OSPF_PATH_INTRA_AREA &&
pauld4a53d52003-07-12 21:30:57 +00001057 !ospf_abr_should_announce (ospf, (struct prefix_ipv4 *) &rn->p, or))
paul718e3742002-12-13 20:15:29 +00001058 {
1059 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001060 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
paul718e3742002-12-13 20:15:29 +00001061 continue;
1062 }
1063
1064 if (or->path_type == OSPF_PATH_INTRA_AREA &&
pauld4a53d52003-07-12 21:30:57 +00001065 !ospf_abr_plist_out_check (area, or, (struct prefix_ipv4 *) &rn->p))
paul718e3742002-12-13 20:15:29 +00001066 {
1067 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001068 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
paul718e3742002-12-13 20:15:29 +00001069 continue;
1070 }
1071
1072 if ((or->path_type == OSPF_PATH_INTER_AREA) &&
1073 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1074 {
1075 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001076 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001077 " this is route is not backbone one, skipping");
1078 continue;
1079 }
1080
1081
paul147193a2003-04-19 00:31:59 +00001082 if ((ospf->abr_type == OSPF_ABR_CISCO) ||
1083 (ospf->abr_type == OSPF_ABR_IBM))
paul718e3742002-12-13 20:15:29 +00001084
paul147193a2003-04-19 00:31:59 +00001085 if (!ospf_act_bb_connection (ospf) &&
paul718e3742002-12-13 20:15:29 +00001086 or->path_type != OSPF_PATH_INTRA_AREA)
1087 {
1088 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001089 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
paul718e3742002-12-13 20:15:29 +00001090 "No BB connection, skip not intra-area routes");
1091 continue;
1092 }
1093
1094 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001095 zlog_debug ("ospf_abr_process_network_rt(): announcing");
hassofa2b17e2004-03-04 17:45:00 +00001096 ospf_abr_announce_network (ospf, (struct prefix_ipv4 *)&rn->p, or);
paul718e3742002-12-13 20:15:29 +00001097 }
1098
1099 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001100 zlog_debug ("ospf_abr_process_network_rt(): Stop");
paul718e3742002-12-13 20:15:29 +00001101}
1102
paul4dadc292005-05-06 21:37:42 +00001103static void
paul718e3742002-12-13 20:15:29 +00001104ospf_abr_announce_rtr_to_area (struct prefix_ipv4 *p, u_int32_t cost,
1105 struct ospf_area *area)
1106{
1107 struct ospf_lsa *lsa, *old = NULL;
1108 struct summary_lsa *slsa = NULL;
1109
1110 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001111 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
paul718e3742002-12-13 20:15:29 +00001112
paul147193a2003-04-19 00:31:59 +00001113 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_ASBR_SUMMARY_LSA,
1114 p, area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +00001115 if (old)
1116 {
1117 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001118 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
paul718e3742002-12-13 20:15:29 +00001119 slsa = (struct summary_lsa *) old->data;
1120
1121 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001122 zlog_debug ("ospf_abr_announce_network_to_area(): "
paul718e3742002-12-13 20:15:29 +00001123 "old metric: %d, new metric: %d",
1124 GET_METRIC (slsa->metric), cost);
1125 }
1126
1127 if (old && (GET_METRIC (slsa->metric) == cost))
1128 {
1129 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001130 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
paul718e3742002-12-13 20:15:29 +00001131 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
1132 }
1133 else
1134 {
1135 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001136 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
paul718e3742002-12-13 20:15:29 +00001137
1138 if (old)
1139 {
1140 set_metric (old, cost);
paul147193a2003-04-19 00:31:59 +00001141 lsa = ospf_summary_asbr_lsa_refresh (area->ospf, old);
paul718e3742002-12-13 20:15:29 +00001142 }
1143 else
1144 lsa = ospf_summary_asbr_lsa_originate (p, cost, area);
paulc24d6022005-11-20 14:54:12 +00001145 if (!lsa)
1146 {
1147 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
1148
1149 prefix2str ((struct prefix *)p, buf, sizeof(buf));
1150 zlog_warn ("%s: Could not refresh/originate %s to %s",
1151 __func__,
1152 buf,
1153 inet_ntoa (area->area_id));
1154 return;
1155 }
1156
paul718e3742002-12-13 20:15:29 +00001157 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001158 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
paul718e3742002-12-13 20:15:29 +00001159 "flooding new version of summary");
paulc24d6022005-11-20 14:54:12 +00001160
paul718e3742002-12-13 20:15:29 +00001161 /*
1162 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1163 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1164
1165 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1166 /* ospf_flood_through_area (area, NULL, lsa);*/
1167 }
1168
1169 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001170 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
paul718e3742002-12-13 20:15:29 +00001171}
1172
1173
paul4dadc292005-05-06 21:37:42 +00001174static void
paul147193a2003-04-19 00:31:59 +00001175ospf_abr_announce_rtr (struct ospf *ospf,
1176 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +00001177{
hasso52dc7ee2004-09-23 19:18:23 +00001178 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001179 struct ospf_area *area;
1180
1181 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001182 zlog_debug ("ospf_abr_announce_rtr(): Start");
paul718e3742002-12-13 20:15:29 +00001183
paul1eb8ef22005-04-07 07:30:20 +00001184 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001185 {
paul718e3742002-12-13 20:15:29 +00001186 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001187 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001188 inet_ntoa (area->area_id));
1189
1190 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
1191 continue;
1192
1193 if (ospf_abr_nexthops_belong_to_area (or, area))
1194 continue;
1195
1196 if (area->external_routing != OSPF_AREA_DEFAULT)
1197 {
1198 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001199 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001200 "area %s doesn't support external routing",
1201 inet_ntoa(area->area_id));
1202 continue;
1203 }
1204
1205 if (or->path_type == OSPF_PATH_INTER_AREA)
1206 {
1207 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001208 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001209 "this is inter-area route to %s", inet_ntoa (p->prefix));
1210 if (!OSPF_IS_AREA_BACKBONE (area))
1211 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1212 }
1213
1214 if (or->path_type == OSPF_PATH_INTRA_AREA)
1215 {
1216 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001217 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001218 "this is intra-area route to %s", inet_ntoa (p->prefix));
1219 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1220 }
1221 }
1222
1223 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001224 zlog_debug ("ospf_abr_announce_rtr(): Stop");
paul718e3742002-12-13 20:15:29 +00001225}
1226
paul4dadc292005-05-06 21:37:42 +00001227static void
paul147193a2003-04-19 00:31:59 +00001228ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt)
paul718e3742002-12-13 20:15:29 +00001229{
paul718e3742002-12-13 20:15:29 +00001230 struct ospf_route *or;
paul147193a2003-04-19 00:31:59 +00001231 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +00001232 struct list *l;
1233
1234 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001235 zlog_debug ("ospf_abr_process_router_rt(): Start");
paul718e3742002-12-13 20:15:29 +00001236
1237 for (rn = route_top (rt); rn; rn = route_next (rn))
1238 {
paul1eb8ef22005-04-07 07:30:20 +00001239 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001240 char flag = 0;
1241 struct ospf_route *best = NULL;
1242
1243 if (rn->info == NULL)
1244 continue;
1245
1246 l = rn->info;
1247
1248 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001249 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
paul718e3742002-12-13 20:15:29 +00001250 inet_ntoa (rn->p.u.prefix4));
1251
paul1eb8ef22005-04-07 07:30:20 +00001252 for (ALL_LIST_ELEMENTS (l, node, nnode, or))
paul718e3742002-12-13 20:15:29 +00001253 {
paul147193a2003-04-19 00:31:59 +00001254 if (!ospf_area_lookup_by_area_id (ospf, or->u.std.area_id))
paul718e3742002-12-13 20:15:29 +00001255 {
1256 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001257 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
paul718e3742002-12-13 20:15:29 +00001258 inet_ntoa (or->u.std.area_id));
1259 continue;
1260 }
1261
1262
1263 if (!CHECK_FLAG (or->u.std.flags, ROUTER_LSA_EXTERNAL))
1264 {
1265 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001266 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001267 "This is not an ASBR, skipping");
1268 continue;
1269 }
1270
1271 if (!flag)
1272 {
paul147193a2003-04-19 00:31:59 +00001273 best = ospf_find_asbr_route (ospf, rt,
1274 (struct prefix_ipv4 *) &rn->p);
paul718e3742002-12-13 20:15:29 +00001275 flag = 1;
1276 }
1277
1278 if (best == NULL)
1279 continue;
1280
1281 if (or != best)
1282 {
1283 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001284 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001285 "This route is not the best among possible, skipping");
1286 continue;
1287 }
1288
1289 if (or->path_type == OSPF_PATH_INTER_AREA &&
1290 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1291 {
1292 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001293 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001294 "This route is not a backbone one, skipping");
1295 continue;
1296 }
1297
1298 if (or->cost >= OSPF_LS_INFINITY)
1299 {
1300 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001301 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001302 "This route has LS_INFINITY metric, skipping");
1303 continue;
1304 }
1305
paul147193a2003-04-19 00:31:59 +00001306 if (ospf->abr_type == OSPF_ABR_CISCO
1307 || ospf->abr_type == OSPF_ABR_IBM)
1308 if (!ospf_act_bb_connection (ospf)
1309 && or->path_type != OSPF_PATH_INTRA_AREA)
paul718e3742002-12-13 20:15:29 +00001310 {
1311 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001312 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
paul718e3742002-12-13 20:15:29 +00001313 "No BB connection, skip not intra-area routes");
1314 continue;
1315 }
1316
paul147193a2003-04-19 00:31:59 +00001317 ospf_abr_announce_rtr (ospf, (struct prefix_ipv4 *) &rn->p, or);
paul718e3742002-12-13 20:15:29 +00001318
1319 }
1320
1321 }
1322
1323 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001324 zlog_debug ("ospf_abr_process_router_rt(): Stop");
paul718e3742002-12-13 20:15:29 +00001325}
1326
paul4dadc292005-05-06 21:37:42 +00001327static void
paul147193a2003-04-19 00:31:59 +00001328ospf_abr_unapprove_translates (struct ospf *ospf) /* For NSSA Translations */
paul718e3742002-12-13 20:15:29 +00001329{
paul147193a2003-04-19 00:31:59 +00001330 struct ospf_lsa *lsa;
1331 struct route_node *rn;
1332
paul718e3742002-12-13 20:15:29 +00001333 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001334 zlog_debug ("ospf_abr_unapprove_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001335
1336 /* NSSA Translator is not checked, because it may have gone away,
1337 and we would want to flush any residuals anyway */
1338
paul147193a2003-04-19 00:31:59 +00001339 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1340 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
pauld4a53d52003-07-12 21:30:57 +00001341 {
1342 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1343 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001344 zlog_debug ("ospf_abr_unapprove_translates(): "
pauld4a53d52003-07-12 21:30:57 +00001345 "approved unset on link id %s",
1346 inet_ntoa (lsa->data->id));
1347 }
paul718e3742002-12-13 20:15:29 +00001348
1349 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001350 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001351}
paul718e3742002-12-13 20:15:29 +00001352
paul4dadc292005-05-06 21:37:42 +00001353static void
paul147193a2003-04-19 00:31:59 +00001354ospf_abr_unapprove_summaries (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001355{
hasso52dc7ee2004-09-23 19:18:23 +00001356 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001357 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001358 struct route_node *rn;
1359 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +00001360
1361 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001362 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
paul718e3742002-12-13 20:15:29 +00001363
paul1eb8ef22005-04-07 07:30:20 +00001364 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001365 {
pauld4a53d52003-07-12 21:30:57 +00001366 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001367 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001368 "considering area %s",
1369 inet_ntoa (area->area_id));
paul147193a2003-04-19 00:31:59 +00001370 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001371 if (ospf_lsa_is_self_originated (ospf, lsa))
1372 {
1373 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001374 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001375 "approved unset on summary link id %s",
1376 inet_ntoa (lsa->data->id));
1377 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1378 }
paul147193a2003-04-19 00:31:59 +00001379
1380 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001381 if (ospf_lsa_is_self_originated (ospf, lsa))
1382 {
1383 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001384 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001385 "approved unset on asbr-summary link id %s",
1386 inet_ntoa (lsa->data->id));
1387 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1388 }
paul718e3742002-12-13 20:15:29 +00001389 }
1390
1391 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001392 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
paul718e3742002-12-13 20:15:29 +00001393}
1394
paul4dadc292005-05-06 21:37:42 +00001395static void
paul147193a2003-04-19 00:31:59 +00001396ospf_abr_prepare_aggregates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001397{
hasso52dc7ee2004-09-23 19:18:23 +00001398 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001399 struct route_node *rn;
1400 struct ospf_area_range *range;
paul1eb8ef22005-04-07 07:30:20 +00001401 struct ospf_area *area;
paul718e3742002-12-13 20:15:29 +00001402
1403 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001404 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001405
paul1eb8ef22005-04-07 07:30:20 +00001406 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001407 {
paul718e3742002-12-13 20:15:29 +00001408 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1409 if ((range = rn->info) != NULL)
1410 {
1411 range->cost = 0;
1412 range->specifics = 0;
1413 }
1414 }
1415
1416 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001417 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001418}
1419
paul4dadc292005-05-06 21:37:42 +00001420static void
paul147193a2003-04-19 00:31:59 +00001421ospf_abr_announce_aggregates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001422{
1423 struct ospf_area *area, *ar;
1424 struct ospf_area_range *range;
1425 struct route_node *rn;
pauld4a53d52003-07-12 21:30:57 +00001426 struct prefix p;
hasso52dc7ee2004-09-23 19:18:23 +00001427 struct listnode *node, *n;
paul718e3742002-12-13 20:15:29 +00001428
1429 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001430 zlog_debug ("ospf_abr_announce_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001431
paul1eb8ef22005-04-07 07:30:20 +00001432 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001433 {
paul718e3742002-12-13 20:15:29 +00001434 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001435 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001436 inet_ntoa (area->area_id));
1437
1438 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1439 if ((range = rn->info))
1440 {
1441 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1442 {
1443 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001444 zlog_debug ("ospf_abr_announce_aggregates():"
paul718e3742002-12-13 20:15:29 +00001445 " discarding suppress-ranges");
1446 continue;
1447 }
1448
1449 p.family = AF_INET;
pauld4a53d52003-07-12 21:30:57 +00001450 p.u.prefix4 = range->addr;
paul718e3742002-12-13 20:15:29 +00001451 p.prefixlen = range->masklen;
1452
1453 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001454 zlog_debug ("ospf_abr_announce_aggregates():"
paul718e3742002-12-13 20:15:29 +00001455 " this is range: %s/%d",
pauld4a53d52003-07-12 21:30:57 +00001456 inet_ntoa (p.u.prefix4), p.prefixlen);
paul718e3742002-12-13 20:15:29 +00001457
1458 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1459 {
1460 p.family = AF_INET;
pauld4a53d52003-07-12 21:30:57 +00001461 p.u.prefix4 = range->subst_addr;
paul718e3742002-12-13 20:15:29 +00001462 p.prefixlen = range->subst_masklen;
1463 }
1464
1465 if (range->specifics)
1466 {
1467 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001468 zlog_debug ("ospf_abr_announce_aggregates(): active range");
paul718e3742002-12-13 20:15:29 +00001469
paul1eb8ef22005-04-07 07:30:20 +00001470 for (ALL_LIST_ELEMENTS_RO (ospf->areas, n, ar))
paul718e3742002-12-13 20:15:29 +00001471 {
paul718e3742002-12-13 20:15:29 +00001472 if (ar == area)
1473 continue;
1474
1475 /* We do not check nexthops here, because
1476 intra-area routes can be associated with
1477 one area only */
1478
1479 /* backbone routes are not summarized
1480 when announced into transit areas */
1481
1482 if (ospf_area_is_transit (ar) &&
1483 OSPF_IS_AREA_BACKBONE (area))
1484 {
1485 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001486 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
paul718e3742002-12-13 20:15:29 +00001487 "announcement of BB aggregate into"
1488 " a transit area");
1489 continue;
1490 }
hassofa2b17e2004-03-04 17:45:00 +00001491 ospf_abr_announce_network_to_area ((struct prefix_ipv4 *)&p, range->cost, ar);
paul718e3742002-12-13 20:15:29 +00001492 }
1493 }
1494 }
1495 }
1496
1497 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001498 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001499}
1500
paul4dadc292005-05-06 21:37:42 +00001501static void
paul147193a2003-04-19 00:31:59 +00001502ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */
paul718e3742002-12-13 20:15:29 +00001503{
hasso52dc7ee2004-09-23 19:18:23 +00001504 struct listnode *node; /*, n; */
paul718e3742002-12-13 20:15:29 +00001505 struct ospf_area *area; /*, *ar; */
1506 struct route_node *rn;
1507 struct ospf_area_range *range;
1508 struct prefix_ipv4 p;
1509
1510 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001511 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001512
paul1eb8ef22005-04-07 07:30:20 +00001513 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001514 {
paule2c6c152003-06-22 08:49:25 +00001515 if (! area->NSSATranslatorState)
paul718e3742002-12-13 20:15:29 +00001516 continue;
1517
1518 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001519 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001520 inet_ntoa (area->area_id));
1521
1522 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1523 {
1524 if (rn->info == NULL)
1525 continue;
1526
1527 range = rn->info;
1528
1529 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1530 {
1531 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001532 zlog_debug ("ospf_abr_send_nssa_aggregates():"
paul718e3742002-12-13 20:15:29 +00001533 " discarding suppress-ranges");
1534 continue;
1535 }
1536
1537 p.family = AF_INET;
1538 p.prefix = range->addr;
1539 p.prefixlen = range->masklen;
1540
1541 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001542 zlog_debug ("ospf_abr_send_nssa_aggregates():"
paul718e3742002-12-13 20:15:29 +00001543 " this is range: %s/%d",
1544 inet_ntoa (p.prefix), p.prefixlen);
1545
1546 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1547 {
1548 p.family = AF_INET;
1549 p.prefix = range->subst_addr;
1550 p.prefixlen = range->subst_masklen;
1551 }
1552
1553 if (range->specifics)
paule2c6c152003-06-22 08:49:25 +00001554 {
1555 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001556 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
paul718e3742002-12-13 20:15:29 +00001557
paule2c6c152003-06-22 08:49:25 +00001558 /* Fetch LSA-Type-7 from aggregate prefix, and then
1559 * translate, Install (as Type-5), Approve, and Flood
1560 */
1561 ospf_abr_translate_nssa_range (&p, range->cost);
1562 }
1563 } /* all area ranges*/
paul718e3742002-12-13 20:15:29 +00001564 } /* all areas */
1565
1566 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001567 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001568}
1569
paul4dadc292005-05-06 21:37:42 +00001570static void
paul147193a2003-04-19 00:31:59 +00001571ospf_abr_announce_nssa_defaults (struct ospf *ospf) /* By ABR-Translator */
paul718e3742002-12-13 20:15:29 +00001572{
hasso52dc7ee2004-09-23 19:18:23 +00001573 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001574 struct ospf_area *area;
paul718e3742002-12-13 20:15:29 +00001575
paul147193a2003-04-19 00:31:59 +00001576 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001577 return;
1578
1579 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001580 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
paul718e3742002-12-13 20:15:29 +00001581
paul1eb8ef22005-04-07 07:30:20 +00001582 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001583 {
paul718e3742002-12-13 20:15:29 +00001584 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001585 zlog_debug ("ospf_abr_announce_nssa_defaults(): looking at area %s",
paule2c6c152003-06-22 08:49:25 +00001586 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001587
1588 if (area->external_routing != OSPF_AREA_NSSA)
paule2c6c152003-06-22 08:49:25 +00001589 continue;
paul718e3742002-12-13 20:15:29 +00001590
1591 if (OSPF_IS_AREA_BACKBONE (area))
paule2c6c152003-06-22 08:49:25 +00001592 continue; /* Sanity Check */
paul718e3742002-12-13 20:15:29 +00001593
1594 /* if (!TranslatorRole continue V 1.0 look for "always" conf */
paule2c6c152003-06-22 08:49:25 +00001595 if (area->NSSATranslatorState)
1596 {
1597 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001598 zlog_debug ("ospf_abr_announce_nssa_defaults(): "
paule2c6c152003-06-22 08:49:25 +00001599 "announcing 0.0.0.0/0 to this nssa");
1600 /* ospf_abr_announce_nssa_asbr_to_as (&p, area->default_cost, area); */
pauld4a53d52003-07-12 21:30:57 +00001601 /*ospf_abr_announce_network_to_area (&p, area->default_cost, area);*/
paule2c6c152003-06-22 08:49:25 +00001602 }
paul718e3742002-12-13 20:15:29 +00001603 }
1604}
paul718e3742002-12-13 20:15:29 +00001605
paul4dadc292005-05-06 21:37:42 +00001606static void
paul147193a2003-04-19 00:31:59 +00001607ospf_abr_announce_stub_defaults (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001608{
hasso52dc7ee2004-09-23 19:18:23 +00001609 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001610 struct ospf_area *area;
1611 struct prefix_ipv4 p;
1612
paul147193a2003-04-19 00:31:59 +00001613 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001614 return;
1615
1616 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001617 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
paul718e3742002-12-13 20:15:29 +00001618
1619 p.family = AF_INET;
1620 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1621 p.prefixlen = 0;
1622
paul1eb8ef22005-04-07 07:30:20 +00001623 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001624 {
paul718e3742002-12-13 20:15:29 +00001625 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001626 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1627 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001628
pauld4a53d52003-07-12 21:30:57 +00001629 if ( (area->external_routing != OSPF_AREA_STUB)
pauld4a53d52003-07-12 21:30:57 +00001630 && (area->external_routing != OSPF_AREA_NSSA)
pauld4a53d52003-07-12 21:30:57 +00001631 )
1632 continue;
paul718e3742002-12-13 20:15:29 +00001633
1634 if (OSPF_IS_AREA_BACKBONE (area))
pauld4a53d52003-07-12 21:30:57 +00001635 continue; /* Sanity Check */
1636
paul718e3742002-12-13 20:15:29 +00001637 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001638 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1639 "announcing 0.0.0.0/0 to area %s",
pauld4a53d52003-07-12 21:30:57 +00001640 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001641 ospf_abr_announce_network_to_area (&p, area->default_cost, area);
1642 }
1643
1644 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001645 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
paul718e3742002-12-13 20:15:29 +00001646}
1647
paul4dadc292005-05-06 21:37:42 +00001648static int
paul147193a2003-04-19 00:31:59 +00001649ospf_abr_remove_unapproved_translates_apply (struct ospf *ospf,
1650 struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001651{
1652 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)
1653 && ! CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1654 {
1655 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1656 "removing unapproved translates, ID: %s",
1657 inet_ntoa (lsa->data->id));
1658
1659 /* FLUSH THROUGHOUT AS */
paul147193a2003-04-19 00:31:59 +00001660 ospf_lsa_flush_as (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001661
1662 /* DISCARD from LSDB */
1663 }
1664 return 0;
1665}
1666
paul4dadc292005-05-06 21:37:42 +00001667static void
paul147193a2003-04-19 00:31:59 +00001668ospf_abr_remove_unapproved_translates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001669{
paul147193a2003-04-19 00:31:59 +00001670 struct route_node *rn;
1671 struct ospf_lsa *lsa;
1672
paul718e3742002-12-13 20:15:29 +00001673 /* All AREA PROCESS should have APPROVED necessary LSAs */
1674 /* Remove any left over and not APPROVED */
1675 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001676 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001677
paul147193a2003-04-19 00:31:59 +00001678 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1679 ospf_abr_remove_unapproved_translates_apply (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001680
1681 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001682 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001683}
paul718e3742002-12-13 20:15:29 +00001684
paul4dadc292005-05-06 21:37:42 +00001685static void
paul147193a2003-04-19 00:31:59 +00001686ospf_abr_remove_unapproved_summaries (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001687{
hasso52dc7ee2004-09-23 19:18:23 +00001688 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001689 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001690 struct route_node *rn;
1691 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +00001692
1693 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001694 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
paul718e3742002-12-13 20:15:29 +00001695
paul1eb8ef22005-04-07 07:30:20 +00001696 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001697 {
paul718e3742002-12-13 20:15:29 +00001698 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001699 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
paul718e3742002-12-13 20:15:29 +00001700 "looking at area %s", inet_ntoa (area->area_id));
1701
paul147193a2003-04-19 00:31:59 +00001702 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
1703 if (ospf_lsa_is_self_originated (ospf, lsa))
1704 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1705 ospf_lsa_flush_area (lsa, area);
1706
1707 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
1708 if (ospf_lsa_is_self_originated (ospf, lsa))
1709 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1710 ospf_lsa_flush_area (lsa, area);
paul718e3742002-12-13 20:15:29 +00001711 }
1712
1713 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001714 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
paul718e3742002-12-13 20:15:29 +00001715}
1716
paul4dadc292005-05-06 21:37:42 +00001717static void
paul147193a2003-04-19 00:31:59 +00001718ospf_abr_manage_discard_routes (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001719{
paul1eb8ef22005-04-07 07:30:20 +00001720 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001721 struct route_node *rn;
1722 struct ospf_area *area;
1723 struct ospf_area_range *range;
1724
paul1eb8ef22005-04-07 07:30:20 +00001725 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
1726 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1727 if ((range = rn->info) != NULL)
1728 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1729 {
1730 if (range->specifics)
1731 ospf_add_discard_route (ospf->new_table, area,
1732 (struct prefix_ipv4 *) &rn->p);
1733 else
1734 ospf_delete_discard_route ((struct prefix_ipv4 *) &rn->p);
1735 }
paul718e3742002-12-13 20:15:29 +00001736}
1737
paul718e3742002-12-13 20:15:29 +00001738/* This is the function taking care about ABR NSSA, i.e. NSSA
1739 Translator, -LSA aggregation and flooding. For all NSSAs
1740
1741 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1742 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1743 with the P-bit set.
1744
1745 Any received Type-5s are legal for an ABR, else illegal for IR.
1746 Received Type-7s are installed, by area, with incoming P-bit. They
1747 are flooded; if the Elected NSSA Translator, then P-bit off.
1748
1749 Additionally, this ABR will place "translated type-7's" into the
1750 Type-5 LSDB in order to keep track of APPROVAL or not.
1751
1752 It will scan through every area, looking for Type-7 LSAs with P-Bit
1753 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1754 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1755 5-INSTALLED.
1756
1757 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1758 left over are FLUSHED and DISCARDED.
1759
1760 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1761 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1762
paul4dadc292005-05-06 21:37:42 +00001763static void
paul147193a2003-04-19 00:31:59 +00001764ospf_abr_nssa_task (struct ospf *ospf) /* called only if any_nssa */
paul718e3742002-12-13 20:15:29 +00001765{
1766 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001767 zlog_debug ("Check for NSSA-ABR Tasks():");
paul718e3742002-12-13 20:15:29 +00001768
paul147193a2003-04-19 00:31:59 +00001769 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001770 return;
1771
paul147193a2003-04-19 00:31:59 +00001772 if (! ospf->anyNSSA)
paul718e3742002-12-13 20:15:29 +00001773 return;
1774
1775 /* Each area must confirm TranslatorRole */
1776 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001777 zlog_debug ("ospf_abr_nssa_task(): Start");
paul718e3742002-12-13 20:15:29 +00001778
1779 /* For all Global Entries flagged "local-translate", unset APPROVED */
1780 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001781 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
paul718e3742002-12-13 20:15:29 +00001782
paul147193a2003-04-19 00:31:59 +00001783 ospf_abr_unapprove_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001784
1785 /* RESET all Ranges in every Area, same as summaries */
1786 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001787 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
paule2c6c152003-06-22 08:49:25 +00001788 ospf_abr_prepare_aggregates (ospf); /*TURNED OFF just for now */
paul718e3742002-12-13 20:15:29 +00001789
1790 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
paule2c6c152003-06-22 08:49:25 +00001791 * Aggregate as Type-7
1792 * Install or Approve in Type-5 Global LSDB
1793 */
paul718e3742002-12-13 20:15:29 +00001794 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001795 zlog_debug ("ospf_abr_nssa_task(): process translates");
paul147193a2003-04-19 00:31:59 +00001796 ospf_abr_process_nssa_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001797
1798 /* Translate/Send any "ranged" aggregates, and also 5-Install and
paule2c6c152003-06-22 08:49:25 +00001799 * Approve
1800 * Scan Type-7's for aggregates, translate to Type-5's,
1801 * Install/Flood/Approve
1802 */
paul718e3742002-12-13 20:15:29 +00001803 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001804 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
paule2c6c152003-06-22 08:49:25 +00001805 ospf_abr_send_nssa_aggregates (ospf); /*TURNED OFF FOR NOW */
paul718e3742002-12-13 20:15:29 +00001806
pauld4a53d52003-07-12 21:30:57 +00001807 /* Send any NSSA defaults as Type-5
1808 *if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001809 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
pauld4a53d52003-07-12 21:30:57 +00001810 *ospf_abr_announce_nssa_defaults (ospf);
1811 * havnt a clue what above is supposed to do.
1812 */
paul718e3742002-12-13 20:15:29 +00001813
1814 /* Flush any unapproved previous translates from Global Data Base */
1815 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001816 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
paul147193a2003-04-19 00:31:59 +00001817 ospf_abr_remove_unapproved_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001818
paul147193a2003-04-19 00:31:59 +00001819 ospf_abr_manage_discard_routes (ospf); /* same as normal...discard */
paul718e3742002-12-13 20:15:29 +00001820
1821 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001822 zlog_debug ("ospf_abr_nssa_task(): Stop");
paul718e3742002-12-13 20:15:29 +00001823}
paul718e3742002-12-13 20:15:29 +00001824
1825/* This is the function taking care about ABR stuff, i.e.
1826 summary-LSA origination and flooding. */
1827void
paul147193a2003-04-19 00:31:59 +00001828ospf_abr_task (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001829{
1830 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001831 zlog_debug ("ospf_abr_task(): Start");
paul718e3742002-12-13 20:15:29 +00001832
paul147193a2003-04-19 00:31:59 +00001833 if (ospf->new_table == NULL || ospf->new_rtrs == NULL)
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(): Routing tables are not yet ready");
paul718e3742002-12-13 20:15:29 +00001837 return;
1838 }
1839
1840 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001841 zlog_debug ("ospf_abr_task(): unapprove summaries");
paul147193a2003-04-19 00:31:59 +00001842 ospf_abr_unapprove_summaries (ospf);
paul718e3742002-12-13 20:15:29 +00001843
1844 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001845 zlog_debug ("ospf_abr_task(): prepare aggregates");
paul147193a2003-04-19 00:31:59 +00001846 ospf_abr_prepare_aggregates (ospf);
paul718e3742002-12-13 20:15:29 +00001847
paul147193a2003-04-19 00:31:59 +00001848 if (IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001849 {
1850 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001851 zlog_debug ("ospf_abr_task(): process network RT");
paul147193a2003-04-19 00:31:59 +00001852 ospf_abr_process_network_rt (ospf, ospf->new_table);
paul718e3742002-12-13 20:15:29 +00001853
1854 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001855 zlog_debug ("ospf_abr_task(): process router RT");
paul147193a2003-04-19 00:31:59 +00001856 ospf_abr_process_router_rt (ospf, ospf->new_rtrs);
paul718e3742002-12-13 20:15:29 +00001857
1858 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001859 zlog_debug ("ospf_abr_task(): announce aggregates");
paul147193a2003-04-19 00:31:59 +00001860 ospf_abr_announce_aggregates (ospf);
paul718e3742002-12-13 20:15:29 +00001861
1862 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001863 zlog_debug ("ospf_abr_task(): announce stub defaults");
paul147193a2003-04-19 00:31:59 +00001864 ospf_abr_announce_stub_defaults (ospf);
paul718e3742002-12-13 20:15:29 +00001865 }
1866
1867 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001868 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
paul147193a2003-04-19 00:31:59 +00001869 ospf_abr_remove_unapproved_summaries (ospf);
paul718e3742002-12-13 20:15:29 +00001870
paul147193a2003-04-19 00:31:59 +00001871 ospf_abr_manage_discard_routes (ospf);
paul718e3742002-12-13 20:15:29 +00001872
paul718e3742002-12-13 20:15:29 +00001873 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001874 zlog_debug ("ospf_abr_task(): Stop");
paul718e3742002-12-13 20:15:29 +00001875}
1876
paul4dadc292005-05-06 21:37:42 +00001877static int
paul147193a2003-04-19 00:31:59 +00001878ospf_abr_task_timer (struct thread *thread)
paul718e3742002-12-13 20:15:29 +00001879{
paul147193a2003-04-19 00:31:59 +00001880 struct ospf *ospf = THREAD_ARG (thread);
1881
1882 ospf->t_abr_task = 0;
paul718e3742002-12-13 20:15:29 +00001883
1884 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001885 zlog_debug ("Running ABR task on timer");
paul718e3742002-12-13 20:15:29 +00001886
paul147193a2003-04-19 00:31:59 +00001887 ospf_check_abr_status (ospf);
pauld4a53d52003-07-12 21:30:57 +00001888 ospf_abr_nssa_check_status (ospf);
paul718e3742002-12-13 20:15:29 +00001889
paul147193a2003-04-19 00:31:59 +00001890 ospf_abr_task (ospf);
paule2c6c152003-06-22 08:49:25 +00001891 ospf_abr_nssa_task (ospf); /* if nssa-abr, then scan Type-7 LSDB */
paul718e3742002-12-13 20:15:29 +00001892
paul147193a2003-04-19 00:31:59 +00001893 return 0;
paul718e3742002-12-13 20:15:29 +00001894}
1895
1896void
paul147193a2003-04-19 00:31:59 +00001897ospf_schedule_abr_task (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001898{
1899 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001900 zlog_debug ("Scheduling ABR task");
paul147193a2003-04-19 00:31:59 +00001901
1902 if (ospf->t_abr_task == NULL)
1903 ospf->t_abr_task = thread_add_timer (master, ospf_abr_task_timer,
1904 ospf, OSPF_ABR_TASK_DELAY);
paul718e3742002-12-13 20:15:29 +00001905}