blob: 7e32195b38513bf422f809ec6f86feaafbcc3001 [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;
Paul Jakma9560fa82006-06-26 12:50:06 +0000412
paul1eb8ef22005-04-07 07:30:20 +0000413 for (ALL_LIST_ELEMENTS (ospf->areas, lnode, nnode, area))
paule2c6c152003-06-22 08:49:25 +0000414 {
Paul Jakma9560fa82006-06-26 12:50:06 +0000415 u_char old_state = area->NSSATranslatorState;
416
paule2c6c152003-06-22 08:49:25 +0000417 if (area->external_routing != OSPF_AREA_NSSA)
418 continue;
Paul Jakma9560fa82006-06-26 12:50:06 +0000419
paule2c6c152003-06-22 08:49:25 +0000420 if (IS_DEBUG_OSPF (nssa, NSSA))
ajse84cc642004-12-08 17:28:56 +0000421 zlog_debug ("ospf_abr_nssa_check_status: "
paule2c6c152003-06-22 08:49:25 +0000422 "checking area %s",
423 inet_ntoa (area->area_id));
Paul Jakma9560fa82006-06-26 12:50:06 +0000424
paule2c6c152003-06-22 08:49:25 +0000425 if (!IS_OSPF_ABR (area->ospf))
426 {
427 if (IS_DEBUG_OSPF (nssa, NSSA))
Paul Jakma9560fa82006-06-26 12:50:06 +0000428 zlog_debug ("ospf_abr_nssa_check_status: "
429 "not ABR");
pauld4a53d52003-07-12 21:30:57 +0000430 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
paule2c6c152003-06-22 08:49:25 +0000431 }
Paul Jakma9560fa82006-06-26 12:50:06 +0000432 else
433 {
434 switch (area->NSSATranslatorRole)
435 {
436 case OSPF_NSSA_ROLE_NEVER:
437 /* We never Translate Type-7 LSA. */
438 /* TODO: check previous state and flush? */
439 if (IS_DEBUG_OSPF (nssa, NSSA))
440 zlog_debug ("ospf_abr_nssa_check_status: "
441 "never translate");
442 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
443 break;
444
445 case OSPF_NSSA_ROLE_ALWAYS:
446 /* We always translate if we are an ABR
447 * TODO: originate new LSAs if state change?
448 * or let the nssa abr task take care of it?
449 */
450 if (IS_DEBUG_OSPF (nssa, NSSA))
451 zlog_debug ("ospf_abr_nssa_check_status: "
452 "translate always");
453 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
454 break;
455
456 case OSPF_NSSA_ROLE_CANDIDATE:
457 /* We are a candidate for Translation */
458 if (ospf_abr_nssa_am_elected (area) > 0)
459 {
460 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
461 if (IS_DEBUG_OSPF (nssa, NSSA))
462 zlog_debug ("ospf_abr_nssa_check_status: "
463 "elected translator");
464 }
465 else
466 {
467 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
468 if (IS_DEBUG_OSPF (nssa, NSSA))
469 zlog_debug ("ospf_abr_nssa_check_status: " "not elected");
470 }
471 break;
472 }
473 }
474 /* RFC3101, 3.1:
475 * All NSSA border routers must set the E-bit in the Type-1 router-LSAs
476 * of their directly attached non-stub areas, even when they are not
477 * translating.
478 */
479 if (old_state != area->NSSATranslatorState)
480 {
481 if (old_state == OSPF_NSSA_TRANSLATE_DISABLED)
482 ospf_asbr_status_update (ospf, ++ospf->redistribute);
483 else if (area->NSSATranslatorState == OSPF_NSSA_TRANSLATE_DISABLED)
484 ospf_asbr_status_update (ospf, --ospf->redistribute);
485 }
paule2c6c152003-06-22 08:49:25 +0000486 }
487}
paule2c6c152003-06-22 08:49:25 +0000488
paul718e3742002-12-13 20:15:29 +0000489/* Check area border router status. */
490void
paul147193a2003-04-19 00:31:59 +0000491ospf_check_abr_status (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000492{
493 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000494 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000495 int bb_configured = 0;
496 int bb_act_attached = 0;
497 int areas_configured = 0;
498 int areas_act_attached = 0;
paul147193a2003-04-19 00:31:59 +0000499 u_char new_flags = ospf->flags;
paul718e3742002-12-13 20:15:29 +0000500
501 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000502 zlog_debug ("ospf_check_abr_status(): Start");
paul718e3742002-12-13 20:15:29 +0000503
paul1eb8ef22005-04-07 07:30:20 +0000504 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
paul718e3742002-12-13 20:15:29 +0000505 {
paul718e3742002-12-13 20:15:29 +0000506 if (listcount (area->oiflist))
507 {
508 areas_configured++;
509
510 if (OSPF_IS_AREA_BACKBONE (area))
511 bb_configured = 1;
512 }
513
514 if (ospf_area_actively_attached (area))
515 {
516 areas_act_attached++;
517
518 if (OSPF_IS_AREA_BACKBONE (area))
519 bb_act_attached = 1;
520 }
521 }
522
523 if (IS_DEBUG_OSPF_EVENT)
524 {
ajse84cc642004-12-08 17:28:56 +0000525 zlog_debug ("ospf_check_abr_status(): looked through areas");
526 zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured);
527 zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
paul718e3742002-12-13 20:15:29 +0000528 bb_act_attached);
ajse84cc642004-12-08 17:28:56 +0000529 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
paul718e3742002-12-13 20:15:29 +0000530 areas_configured);
ajse84cc642004-12-08 17:28:56 +0000531 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
paul718e3742002-12-13 20:15:29 +0000532 areas_act_attached);
533 }
534
paul147193a2003-04-19 00:31:59 +0000535 switch (ospf->abr_type)
paul718e3742002-12-13 20:15:29 +0000536 {
537 case OSPF_ABR_SHORTCUT:
538 case OSPF_ABR_STAND:
539 if (areas_act_attached > 1)
540 SET_FLAG (new_flags, OSPF_FLAG_ABR);
541 else
542 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
543 break;
544
545 case OSPF_ABR_IBM:
546 if ((areas_act_attached > 1) && bb_configured)
547 SET_FLAG (new_flags, OSPF_FLAG_ABR);
548 else
549 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
550 break;
551
552 case OSPF_ABR_CISCO:
553 if ((areas_configured > 1) && bb_act_attached)
554 SET_FLAG (new_flags, OSPF_FLAG_ABR);
555 else
556 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
557 break;
558 default:
559 break;
560 }
561
paul147193a2003-04-19 00:31:59 +0000562 if (new_flags != ospf->flags)
paul718e3742002-12-13 20:15:29 +0000563 {
paul147193a2003-04-19 00:31:59 +0000564 ospf_spf_calculate_schedule (ospf);
paul718e3742002-12-13 20:15:29 +0000565 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000566 zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags);
paul147193a2003-04-19 00:31:59 +0000567 ospf->flags = new_flags;
568 OSPF_TIMER_ON (ospf->t_router_lsa_update,
paul718e3742002-12-13 20:15:29 +0000569 ospf_router_lsa_update_timer, OSPF_LSA_UPDATE_DELAY);
570 }
571}
572
paul4dadc292005-05-06 21:37:42 +0000573static void
paul718e3742002-12-13 20:15:29 +0000574ospf_abr_update_aggregate (struct ospf_area_range *range,
paul7f352b82004-02-19 19:37:47 +0000575 struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000576{
577 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000578 zlog_debug ("ospf_abr_update_aggregate(): Start");
paul718e3742002-12-13 20:15:29 +0000579
paul6c835672004-10-11 11:00:30 +0000580 if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
paul718e3742002-12-13 20:15:29 +0000581 {
582 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000583 zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
paul7f352b82004-02-19 19:37:47 +0000584 range->cost_config);
paul718e3742002-12-13 20:15:29 +0000585
586 range->cost = range->cost_config;
587 }
588 else
589 {
590 if (range->specifics == 0)
paul7f352b82004-02-19 19:37:47 +0000591 range->cost = or->cost; /* 1st time get 1st cost */
paul718e3742002-12-13 20:15:29 +0000592
paul7f352b82004-02-19 19:37:47 +0000593 if (or->cost > range->cost)
594 {
595 if (IS_DEBUG_OSPF_EVENT)
paul500e4182005-05-26 17:11:13 +0000596 zlog_debug ("ospf_abr_update_aggregate(): largest cost, update");
paul718e3742002-12-13 20:15:29 +0000597
paul7f352b82004-02-19 19:37:47 +0000598 range->cost = or->cost;
599 }
paul718e3742002-12-13 20:15:29 +0000600 }
601
602 range->specifics++;
603}
604
605static void
606set_metric (struct ospf_lsa *lsa, u_int32_t metric)
607{
608 struct summary_lsa *header;
609 u_char *mp;
610 metric = htonl (metric);
hassoc9e52be2004-09-26 16:09:34 +0000611 mp = (u_char *) &metric;
paul718e3742002-12-13 20:15:29 +0000612 mp++;
613 header = (struct summary_lsa *) lsa->data;
614 memcpy(header->metric, mp, 3);
615}
616
paul4dadc292005-05-06 21:37:42 +0000617static int
paul718e3742002-12-13 20:15:29 +0000618ospf_abr_check_nssa_range (struct prefix_ipv4 *p, u_int32_t cost,
619 struct ospf_area *area)
620{
621 /* The Type-7 is tested against the aggregated prefix and forwarded
622 for lsa installation and flooding */
623 return 0;
624}
625
626/* ospf_abr_translate_nssa */
paul4dadc292005-05-06 21:37:42 +0000627static int
paul147193a2003-04-19 00:31:59 +0000628ospf_abr_translate_nssa (struct ospf_area *area, struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000629{
630 /* Incoming Type-7 or later aggregated Type-7
pauld4a53d52003-07-12 21:30:57 +0000631 *
632 * LSA is skipped if P-bit is off.
633 * LSA is aggregated if within range.
634 *
635 * The Type-7 is translated, Installed/Approved as a Type-5 into
636 * global LSDB, then Flooded through AS
637 *
638 * Later, any Unapproved Translated Type-5's are flushed/discarded
639 */
paul718e3742002-12-13 20:15:29 +0000640
pauld4a53d52003-07-12 21:30:57 +0000641 struct ospf_lsa *old = NULL,
642 *new = NULL;
643 struct as_external_lsa *ext7;
644 struct prefix_ipv4 p;
paul718e3742002-12-13 20:15:29 +0000645
646 if (! CHECK_FLAG (lsa->data->options, OSPF_OPTION_NP))
647 {
648 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000649 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
pauld4a53d52003-07-12 21:30:57 +0000650 inet_ntoa (lsa->data->id));
651 return 1;
paul718e3742002-12-13 20:15:29 +0000652 }
pauld4a53d52003-07-12 21:30:57 +0000653
paul718e3742002-12-13 20:15:29 +0000654 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000655 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
pauld4a53d52003-07-12 21:30:57 +0000656 inet_ntoa (lsa->data->id));
paul718e3742002-12-13 20:15:29 +0000657
pauld4a53d52003-07-12 21:30:57 +0000658 ext7 = (struct as_external_lsa *)(lsa->data);
659 p.prefix = lsa->data->id;
660 p.prefixlen = ip_masklen (ext7->mask);
661
662 if (ext7->e[0].fwd_addr.s_addr == OSPF_DEFAULT_DESTINATION)
663 {
664 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000665 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, "
pauld4a53d52003-07-12 21:30:57 +0000666 "Forward address is 0, NO Translation",
667 inet_ntoa (lsa->data->id));
668 return 1;
669 }
670
671 /* try find existing AS-External LSA for this prefix */
672
673 old = ospf_external_info_find_lsa (area->ospf, &p);
674
675 if (old)
676 {
677 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000678 zlog_debug ("ospf_abr_translate_nssa(): "
pauld4a53d52003-07-12 21:30:57 +0000679 "found old translated LSA Id %s, refreshing",
680 inet_ntoa (old->data->id));
681
682 /* refresh */
683 new = ospf_translated_nssa_refresh (area->ospf, lsa, old);
684 if (!new)
685 {
686 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000687 zlog_debug ("ospf_abr_translate_nssa(): "
pauld4a53d52003-07-12 21:30:57 +0000688 "could not refresh translated LSA Id %s",
689 inet_ntoa (old->data->id));
690 }
691 }
692 else
693 {
694 /* no existing external route for this LSA Id
695 * originate translated LSA
696 */
697
698 if ((new = ospf_translated_nssa_originate (area->ospf, lsa))
699 == NULL)
700 {
701 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000702 zlog_debug ("ospf_abr_translate_nssa(): Could not translate "
pauld4a53d52003-07-12 21:30:57 +0000703 "Type-7 for %s to Type-5",
704 inet_ntoa (lsa->data->id));
705 return 1;
706 }
707 }
paul718e3742002-12-13 20:15:29 +0000708
709 /* Area where Aggregate testing will be inserted, just like summary
710 advertisements */
711 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
712
paul718e3742002-12-13 20:15:29 +0000713 return 0;
714}
715
paul4dadc292005-05-06 21:37:42 +0000716static void
paul718e3742002-12-13 20:15:29 +0000717ospf_abr_translate_nssa_range (struct prefix_ipv4 *p, u_int32_t cost)
718{
719 /* The Type-7 is created from the aggregated prefix and forwarded
720 for lsa installation and flooding... to be added... */
721}
paul718e3742002-12-13 20:15:29 +0000722
vincentba682532005-09-29 13:52:57 +0000723void
paul718e3742002-12-13 20:15:29 +0000724ospf_abr_announce_network_to_area (struct prefix_ipv4 *p, u_int32_t cost,
725 struct ospf_area *area)
726{
727 struct ospf_lsa *lsa, *old = NULL;
728 struct summary_lsa *sl = NULL;
729
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
pauld4a53d52003-07-12 21:30:57 +0000733 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_SUMMARY_LSA,
734 (struct prefix_ipv4 *) p,
735 area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +0000736 if (old)
737 {
738 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000739 zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
pauld4a53d52003-07-12 21:30:57 +0000740
paul718e3742002-12-13 20:15:29 +0000741 sl = (struct summary_lsa *) old->data;
742
743 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000744 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000745 "old metric: %d, new metric: %d",
746 GET_METRIC (sl->metric), cost);
747
748 if (GET_METRIC (sl->metric) == cost)
749 {
750 /* unchanged. simply reapprove it */
751 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000752 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000753 "old summary approved");
754 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
755 }
756 else
757 {
758 /* LSA is changed, refresh it */
759 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000760 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000761 "refreshing summary");
762 set_metric (old, cost);
763 lsa = ospf_summary_lsa_refresh (area->ospf, old);
paulc24d6022005-11-20 14:54:12 +0000764
765 if (!lsa)
766 {
767 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
768
769 prefix2str ((struct prefix *) p, buf, sizeof(buf));
770 zlog_warn ("%s: Could not refresh %s to %s",
771 __func__,
772 buf,
773 inet_ntoa (area->area_id));
774 return;
775 }
776
paulc8987752005-07-26 06:07:22 +0000777 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
pauld4a53d52003-07-12 21:30:57 +0000778 /* This will flood through area. */
779 }
paul718e3742002-12-13 20:15:29 +0000780 }
781 else
782 {
783 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000784 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000785 "creating new summary");
786 lsa = ospf_summary_lsa_originate ( (struct prefix_ipv4 *)p, cost, area);
787 /* This will flood through area. */
paul718e3742002-12-13 20:15:29 +0000788
paulc24d6022005-11-20 14:54:12 +0000789 if (!lsa)
790 {
791 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
792
793 prefix2str ((struct prefix *)p, buf, sizeof(buf));
794 zlog_warn ("%s: Could not originate %s to %s",
795 __func__,
796 buf,
797 inet_ntoa (area->area_id));
798 return;
799 }
800
paul718e3742002-12-13 20:15:29 +0000801 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
802 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000803 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000804 "flooding new version of summary");
paul718e3742002-12-13 20:15:29 +0000805 }
806
807 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000808 zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
paul718e3742002-12-13 20:15:29 +0000809}
810
paul4dadc292005-05-06 21:37:42 +0000811static int
paul718e3742002-12-13 20:15:29 +0000812ospf_abr_nexthops_belong_to_area (struct ospf_route *or,
813 struct ospf_area *area)
814{
paul1eb8ef22005-04-07 07:30:20 +0000815 struct listnode *node, *nnode;
paul96735ee2003-08-10 02:51:22 +0000816 struct ospf_path *path;
Joakim Tjernlunda8ba8472009-07-27 12:42:34 +0200817 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000818
Joakim Tjernlunda8ba8472009-07-27 12:42:34 +0200819 for (ALL_LIST_ELEMENTS_RO (or->paths, node, path))
820 for (ALL_LIST_ELEMENTS_RO (area->oiflist, nnode, oi))
821 if (oi->ifp && oi->ifp->ifindex == path->ifindex)
822 return 1;
paul718e3742002-12-13 20:15:29 +0000823
824 return 0;
825}
826
paul4dadc292005-05-06 21:37:42 +0000827static int
pauld4a53d52003-07-12 21:30:57 +0000828ospf_abr_should_accept (struct prefix_ipv4 *p, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +0000829{
830 if (IMPORT_NAME (area))
831 {
832 if (IMPORT_LIST (area) == NULL)
833 IMPORT_LIST (area) = access_list_lookup (AFI_IP, IMPORT_NAME (area));
834
835 if (IMPORT_LIST (area))
836 if (access_list_apply (IMPORT_LIST (area), p) == FILTER_DENY)
837 return 0;
838 }
839
840 return 1;
841}
842
paul4dadc292005-05-06 21:37:42 +0000843static int
paul718e3742002-12-13 20:15:29 +0000844ospf_abr_plist_in_check (struct ospf_area *area, struct ospf_route *or,
pauld4a53d52003-07-12 21:30:57 +0000845 struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000846{
847 if (PREFIX_NAME_IN (area))
848 {
849 if (PREFIX_LIST_IN (area) == NULL)
850 PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP,
851 PREFIX_NAME_IN (area));
852 if (PREFIX_LIST_IN (area))
853 if (prefix_list_apply (PREFIX_LIST_IN (area), p) != PREFIX_PERMIT)
854 return 0;
855 }
856 return 1;
857}
858
paul4dadc292005-05-06 21:37:42 +0000859static int
paul718e3742002-12-13 20:15:29 +0000860ospf_abr_plist_out_check (struct ospf_area *area, struct ospf_route *or,
pauld4a53d52003-07-12 21:30:57 +0000861 struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000862{
863 if (PREFIX_NAME_OUT (area))
864 {
865 if (PREFIX_LIST_OUT (area) == NULL)
866 PREFIX_LIST_OUT (area) = prefix_list_lookup (AFI_IP,
867 PREFIX_NAME_OUT (area));
868 if (PREFIX_LIST_OUT (area))
869 if (prefix_list_apply (PREFIX_LIST_OUT (area), p) != PREFIX_PERMIT)
870 return 0;
871 }
872 return 1;
873}
874
paul4dadc292005-05-06 21:37:42 +0000875static void
paul147193a2003-04-19 00:31:59 +0000876ospf_abr_announce_network (struct ospf *ospf,
pauld4a53d52003-07-12 21:30:57 +0000877 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000878{
paul718e3742002-12-13 20:15:29 +0000879 struct ospf_area_range *range;
paul718e3742002-12-13 20:15:29 +0000880 struct ospf_area *area, *or_area;
hasso52dc7ee2004-09-23 19:18:23 +0000881 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000882
883 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000884 zlog_debug ("ospf_abr_announce_network(): Start");
paul718e3742002-12-13 20:15:29 +0000885
paul147193a2003-04-19 00:31:59 +0000886 or_area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
paul718e3742002-12-13 20:15:29 +0000887 assert (or_area);
888
paul1eb8ef22005-04-07 07:30:20 +0000889 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000890 {
paul718e3742002-12-13 20:15:29 +0000891 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000892 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
paul718e3742002-12-13 20:15:29 +0000893 inet_ntoa (area->area_id));
894
895 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
896 continue;
897
898 if (ospf_abr_nexthops_belong_to_area (or, area))
899 continue;
900
pauld4a53d52003-07-12 21:30:57 +0000901 if (!ospf_abr_should_accept (p, area))
paul718e3742002-12-13 20:15:29 +0000902 {
903 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000904 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000905 "prefix %s/%d was denied by import-list",
906 inet_ntoa (p->prefix), p->prefixlen);
907 continue;
908 }
909
pauld4a53d52003-07-12 21:30:57 +0000910 if (!ospf_abr_plist_in_check (area, or, p))
paul718e3742002-12-13 20:15:29 +0000911 {
912 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000913 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000914 "prefix %s/%d was denied by prefix-list",
915 inet_ntoa (p->prefix), p->prefixlen);
916 continue;
917 }
918
919 if (area->external_routing != OSPF_AREA_DEFAULT && area->no_summary)
920 {
921 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000922 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000923 "area %s is stub and no_summary",
924 inet_ntoa (area->area_id));
925 continue;
926 }
927
928 if (or->path_type == OSPF_PATH_INTER_AREA)
929 {
930 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000931 zlog_debug ("ospf_abr_announce_network(): this is "
paul718e3742002-12-13 20:15:29 +0000932 "inter-area route to %s/%d",
933 inet_ntoa (p->prefix), p->prefixlen);
934
935 if (!OSPF_IS_AREA_BACKBONE (area))
936 ospf_abr_announce_network_to_area (p, or->cost, area);
937 }
938
939 if (or->path_type == OSPF_PATH_INTRA_AREA)
pauld4a53d52003-07-12 21:30:57 +0000940 {
941 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000942 zlog_debug ("ospf_abr_announce_network(): "
pauld4a53d52003-07-12 21:30:57 +0000943 "this is intra-area route to %s/%d",
944 inet_ntoa (p->prefix), p->prefixlen);
945 if ((range = ospf_area_range_match (or_area, p))
946 && !ospf_area_is_transit (area))
947 ospf_abr_update_aggregate (range, or);
948 else
949 ospf_abr_announce_network_to_area (p, or->cost, area);
950 }
paul718e3742002-12-13 20:15:29 +0000951 }
952}
953
paul4dadc292005-05-06 21:37:42 +0000954static int
paul147193a2003-04-19 00:31:59 +0000955ospf_abr_should_announce (struct ospf *ospf,
pauld4a53d52003-07-12 21:30:57 +0000956 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000957{
paul147193a2003-04-19 00:31:59 +0000958 struct ospf_area *area;
959
960 area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
paul718e3742002-12-13 20:15:29 +0000961
962 assert (area);
963
964 if (EXPORT_NAME (area))
965 {
966 if (EXPORT_LIST (area) == NULL)
967 EXPORT_LIST (area) = access_list_lookup (AFI_IP, EXPORT_NAME (area));
968
969 if (EXPORT_LIST (area))
970 if (access_list_apply (EXPORT_LIST (area), p) == FILTER_DENY)
971 return 0;
972 }
973
974 return 1;
975}
976
paul4dadc292005-05-06 21:37:42 +0000977static void
paul147193a2003-04-19 00:31:59 +0000978ospf_abr_process_nssa_translates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000979{
980 /* Scan through all NSSA_LSDB records for all areas;
981
982 If P-bit is on, translate all Type-7's to 5's and aggregate or
983 flood install as approved in Type-5 LSDB with XLATE Flag on
984 later, do same for all aggregates... At end, DISCARD all
985 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
hasso52dc7ee2004-09-23 19:18:23 +0000986 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000987 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +0000988 struct route_node *rn;
989 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000990
991 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000992 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
paul718e3742002-12-13 20:15:29 +0000993
paul1eb8ef22005-04-07 07:30:20 +0000994 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000995 {
paule2c6c152003-06-22 08:49:25 +0000996 if (! area->NSSATranslatorState)
pauld4a53d52003-07-12 21:30:57 +0000997 continue; /* skip if not translator */
paul718e3742002-12-13 20:15:29 +0000998
999 if (area->external_routing != OSPF_AREA_NSSA)
pauld4a53d52003-07-12 21:30:57 +00001000 continue; /* skip if not Nssa Area */
paul718e3742002-12-13 20:15:29 +00001001
1002 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001003 zlog_debug ("ospf_abr_process_nssa_translates(): "
pauld4a53d52003-07-12 21:30:57 +00001004 "looking at area %s", inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001005
paul147193a2003-04-19 00:31:59 +00001006 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001007 ospf_abr_translate_nssa (area, lsa);
paul718e3742002-12-13 20:15:29 +00001008 }
1009
1010 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001011 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001012
1013}
paul718e3742002-12-13 20:15:29 +00001014
paul4dadc292005-05-06 21:37:42 +00001015static void
paul147193a2003-04-19 00:31:59 +00001016ospf_abr_process_network_rt (struct ospf *ospf,
1017 struct route_table *rt)
paul718e3742002-12-13 20:15:29 +00001018{
paul718e3742002-12-13 20:15:29 +00001019 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001020 struct ospf_route *or;
1021 struct route_node *rn;
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(): Start");
paul718e3742002-12-13 20:15:29 +00001025
1026 for (rn = route_top (rt); rn; rn = route_next (rn))
1027 {
1028 if ((or = rn->info) == NULL)
1029 continue;
1030
paul147193a2003-04-19 00:31:59 +00001031 if (!(area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id)))
paul718e3742002-12-13 20:15:29 +00001032 {
1033 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001034 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
paul718e3742002-12-13 20:15:29 +00001035 inet_ntoa (or->u.std.area_id));
1036 continue;
1037 }
1038
1039 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001040 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
paul718e3742002-12-13 20:15:29 +00001041 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
1042 if (or->path_type >= OSPF_PATH_TYPE1_EXTERNAL)
1043 {
1044 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001045 zlog_debug ("ospf_abr_process_network_rt(): "
paul718e3742002-12-13 20:15:29 +00001046 "this is an External router, skipping");
1047 continue;
1048 }
1049
1050 if (or->cost >= OSPF_LS_INFINITY)
1051 {
1052 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001053 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001054 " this route's cost is infinity, skipping");
1055 continue;
1056 }
1057
1058 if (or->type == OSPF_DESTINATION_DISCARD)
1059 {
1060 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001061 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001062 " this is a discard entry, skipping");
1063 continue;
1064 }
1065
1066 if (or->path_type == OSPF_PATH_INTRA_AREA &&
pauld4a53d52003-07-12 21:30:57 +00001067 !ospf_abr_should_announce (ospf, (struct prefix_ipv4 *) &rn->p, or))
paul718e3742002-12-13 20:15:29 +00001068 {
1069 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001070 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
paul718e3742002-12-13 20:15:29 +00001071 continue;
1072 }
1073
1074 if (or->path_type == OSPF_PATH_INTRA_AREA &&
pauld4a53d52003-07-12 21:30:57 +00001075 !ospf_abr_plist_out_check (area, or, (struct prefix_ipv4 *) &rn->p))
paul718e3742002-12-13 20:15:29 +00001076 {
1077 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001078 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
paul718e3742002-12-13 20:15:29 +00001079 continue;
1080 }
1081
1082 if ((or->path_type == OSPF_PATH_INTER_AREA) &&
1083 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1084 {
1085 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001086 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001087 " this is route is not backbone one, skipping");
1088 continue;
1089 }
1090
1091
paul147193a2003-04-19 00:31:59 +00001092 if ((ospf->abr_type == OSPF_ABR_CISCO) ||
1093 (ospf->abr_type == OSPF_ABR_IBM))
paul718e3742002-12-13 20:15:29 +00001094
paul147193a2003-04-19 00:31:59 +00001095 if (!ospf_act_bb_connection (ospf) &&
paul718e3742002-12-13 20:15:29 +00001096 or->path_type != OSPF_PATH_INTRA_AREA)
1097 {
1098 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001099 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
paul718e3742002-12-13 20:15:29 +00001100 "No BB connection, skip not intra-area routes");
1101 continue;
1102 }
1103
1104 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001105 zlog_debug ("ospf_abr_process_network_rt(): announcing");
hassofa2b17e2004-03-04 17:45:00 +00001106 ospf_abr_announce_network (ospf, (struct prefix_ipv4 *)&rn->p, or);
paul718e3742002-12-13 20:15:29 +00001107 }
1108
1109 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001110 zlog_debug ("ospf_abr_process_network_rt(): Stop");
paul718e3742002-12-13 20:15:29 +00001111}
1112
paul4dadc292005-05-06 21:37:42 +00001113static void
paul718e3742002-12-13 20:15:29 +00001114ospf_abr_announce_rtr_to_area (struct prefix_ipv4 *p, u_int32_t cost,
1115 struct ospf_area *area)
1116{
1117 struct ospf_lsa *lsa, *old = NULL;
1118 struct summary_lsa *slsa = NULL;
1119
1120 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001121 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
paul718e3742002-12-13 20:15:29 +00001122
paul147193a2003-04-19 00:31:59 +00001123 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_ASBR_SUMMARY_LSA,
1124 p, area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +00001125 if (old)
1126 {
1127 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001128 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
paul718e3742002-12-13 20:15:29 +00001129 slsa = (struct summary_lsa *) old->data;
1130
1131 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001132 zlog_debug ("ospf_abr_announce_network_to_area(): "
paul718e3742002-12-13 20:15:29 +00001133 "old metric: %d, new metric: %d",
1134 GET_METRIC (slsa->metric), cost);
1135 }
1136
1137 if (old && (GET_METRIC (slsa->metric) == cost))
1138 {
1139 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001140 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
paul718e3742002-12-13 20:15:29 +00001141 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
1142 }
1143 else
1144 {
1145 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001146 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
paul718e3742002-12-13 20:15:29 +00001147
1148 if (old)
1149 {
1150 set_metric (old, cost);
paul147193a2003-04-19 00:31:59 +00001151 lsa = ospf_summary_asbr_lsa_refresh (area->ospf, old);
paul718e3742002-12-13 20:15:29 +00001152 }
1153 else
1154 lsa = ospf_summary_asbr_lsa_originate (p, cost, area);
paulc24d6022005-11-20 14:54:12 +00001155 if (!lsa)
1156 {
1157 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
1158
1159 prefix2str ((struct prefix *)p, buf, sizeof(buf));
1160 zlog_warn ("%s: Could not refresh/originate %s to %s",
1161 __func__,
1162 buf,
1163 inet_ntoa (area->area_id));
1164 return;
1165 }
1166
paul718e3742002-12-13 20:15:29 +00001167 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001168 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
paul718e3742002-12-13 20:15:29 +00001169 "flooding new version of summary");
paulc24d6022005-11-20 14:54:12 +00001170
paul718e3742002-12-13 20:15:29 +00001171 /*
1172 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1173 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1174
1175 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1176 /* ospf_flood_through_area (area, NULL, lsa);*/
1177 }
1178
1179 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001180 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
paul718e3742002-12-13 20:15:29 +00001181}
1182
1183
paul4dadc292005-05-06 21:37:42 +00001184static void
paul147193a2003-04-19 00:31:59 +00001185ospf_abr_announce_rtr (struct ospf *ospf,
1186 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +00001187{
hasso52dc7ee2004-09-23 19:18:23 +00001188 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001189 struct ospf_area *area;
1190
1191 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001192 zlog_debug ("ospf_abr_announce_rtr(): Start");
paul718e3742002-12-13 20:15:29 +00001193
paul1eb8ef22005-04-07 07:30:20 +00001194 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001195 {
paul718e3742002-12-13 20:15:29 +00001196 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001197 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001198 inet_ntoa (area->area_id));
1199
1200 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
1201 continue;
1202
1203 if (ospf_abr_nexthops_belong_to_area (or, area))
1204 continue;
1205
1206 if (area->external_routing != OSPF_AREA_DEFAULT)
1207 {
1208 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001209 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001210 "area %s doesn't support external routing",
1211 inet_ntoa(area->area_id));
1212 continue;
1213 }
1214
1215 if (or->path_type == OSPF_PATH_INTER_AREA)
1216 {
1217 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001218 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001219 "this is inter-area route to %s", inet_ntoa (p->prefix));
1220 if (!OSPF_IS_AREA_BACKBONE (area))
1221 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1222 }
1223
1224 if (or->path_type == OSPF_PATH_INTRA_AREA)
1225 {
1226 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001227 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001228 "this is intra-area route to %s", inet_ntoa (p->prefix));
1229 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1230 }
1231 }
1232
1233 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001234 zlog_debug ("ospf_abr_announce_rtr(): Stop");
paul718e3742002-12-13 20:15:29 +00001235}
1236
paul4dadc292005-05-06 21:37:42 +00001237static void
paul147193a2003-04-19 00:31:59 +00001238ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt)
paul718e3742002-12-13 20:15:29 +00001239{
paul718e3742002-12-13 20:15:29 +00001240 struct ospf_route *or;
paul147193a2003-04-19 00:31:59 +00001241 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +00001242 struct list *l;
1243
1244 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001245 zlog_debug ("ospf_abr_process_router_rt(): Start");
paul718e3742002-12-13 20:15:29 +00001246
1247 for (rn = route_top (rt); rn; rn = route_next (rn))
1248 {
paul1eb8ef22005-04-07 07:30:20 +00001249 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001250 char flag = 0;
1251 struct ospf_route *best = NULL;
1252
1253 if (rn->info == NULL)
1254 continue;
1255
1256 l = rn->info;
1257
1258 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001259 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
paul718e3742002-12-13 20:15:29 +00001260 inet_ntoa (rn->p.u.prefix4));
1261
paul1eb8ef22005-04-07 07:30:20 +00001262 for (ALL_LIST_ELEMENTS (l, node, nnode, or))
paul718e3742002-12-13 20:15:29 +00001263 {
paul147193a2003-04-19 00:31:59 +00001264 if (!ospf_area_lookup_by_area_id (ospf, or->u.std.area_id))
paul718e3742002-12-13 20:15:29 +00001265 {
1266 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001267 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
paul718e3742002-12-13 20:15:29 +00001268 inet_ntoa (or->u.std.area_id));
1269 continue;
1270 }
1271
1272
1273 if (!CHECK_FLAG (or->u.std.flags, ROUTER_LSA_EXTERNAL))
1274 {
1275 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001276 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001277 "This is not an ASBR, skipping");
1278 continue;
1279 }
1280
1281 if (!flag)
1282 {
paul147193a2003-04-19 00:31:59 +00001283 best = ospf_find_asbr_route (ospf, rt,
1284 (struct prefix_ipv4 *) &rn->p);
paul718e3742002-12-13 20:15:29 +00001285 flag = 1;
1286 }
1287
1288 if (best == NULL)
1289 continue;
1290
1291 if (or != best)
1292 {
1293 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001294 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001295 "This route is not the best among possible, skipping");
1296 continue;
1297 }
1298
1299 if (or->path_type == OSPF_PATH_INTER_AREA &&
1300 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1301 {
1302 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001303 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001304 "This route is not a backbone one, skipping");
1305 continue;
1306 }
1307
1308 if (or->cost >= OSPF_LS_INFINITY)
1309 {
1310 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001311 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001312 "This route has LS_INFINITY metric, skipping");
1313 continue;
1314 }
1315
paul147193a2003-04-19 00:31:59 +00001316 if (ospf->abr_type == OSPF_ABR_CISCO
1317 || ospf->abr_type == OSPF_ABR_IBM)
1318 if (!ospf_act_bb_connection (ospf)
1319 && or->path_type != OSPF_PATH_INTRA_AREA)
paul718e3742002-12-13 20:15:29 +00001320 {
1321 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001322 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
paul718e3742002-12-13 20:15:29 +00001323 "No BB connection, skip not intra-area routes");
1324 continue;
1325 }
1326
paul147193a2003-04-19 00:31:59 +00001327 ospf_abr_announce_rtr (ospf, (struct prefix_ipv4 *) &rn->p, or);
paul718e3742002-12-13 20:15:29 +00001328
1329 }
1330
1331 }
1332
1333 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001334 zlog_debug ("ospf_abr_process_router_rt(): Stop");
paul718e3742002-12-13 20:15:29 +00001335}
1336
paul4dadc292005-05-06 21:37:42 +00001337static void
paul147193a2003-04-19 00:31:59 +00001338ospf_abr_unapprove_translates (struct ospf *ospf) /* For NSSA Translations */
paul718e3742002-12-13 20:15:29 +00001339{
paul147193a2003-04-19 00:31:59 +00001340 struct ospf_lsa *lsa;
1341 struct route_node *rn;
1342
paul718e3742002-12-13 20:15:29 +00001343 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001344 zlog_debug ("ospf_abr_unapprove_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001345
1346 /* NSSA Translator is not checked, because it may have gone away,
1347 and we would want to flush any residuals anyway */
1348
paul147193a2003-04-19 00:31:59 +00001349 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1350 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
pauld4a53d52003-07-12 21:30:57 +00001351 {
1352 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1353 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001354 zlog_debug ("ospf_abr_unapprove_translates(): "
pauld4a53d52003-07-12 21:30:57 +00001355 "approved unset on link id %s",
1356 inet_ntoa (lsa->data->id));
1357 }
paul718e3742002-12-13 20:15:29 +00001358
1359 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001360 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001361}
paul718e3742002-12-13 20:15:29 +00001362
paul4dadc292005-05-06 21:37:42 +00001363static void
paul147193a2003-04-19 00:31:59 +00001364ospf_abr_unapprove_summaries (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001365{
hasso52dc7ee2004-09-23 19:18:23 +00001366 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001367 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001368 struct route_node *rn;
1369 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +00001370
1371 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001372 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
paul718e3742002-12-13 20:15:29 +00001373
paul1eb8ef22005-04-07 07:30:20 +00001374 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001375 {
pauld4a53d52003-07-12 21:30:57 +00001376 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001377 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001378 "considering area %s",
1379 inet_ntoa (area->area_id));
paul147193a2003-04-19 00:31:59 +00001380 LSDB_LOOP (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 summary link id %s",
1386 inet_ntoa (lsa->data->id));
1387 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1388 }
paul147193a2003-04-19 00:31:59 +00001389
1390 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001391 if (ospf_lsa_is_self_originated (ospf, lsa))
1392 {
1393 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001394 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001395 "approved unset on asbr-summary link id %s",
1396 inet_ntoa (lsa->data->id));
1397 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1398 }
paul718e3742002-12-13 20:15:29 +00001399 }
1400
1401 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001402 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
paul718e3742002-12-13 20:15:29 +00001403}
1404
paul4dadc292005-05-06 21:37:42 +00001405static void
paul147193a2003-04-19 00:31:59 +00001406ospf_abr_prepare_aggregates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001407{
hasso52dc7ee2004-09-23 19:18:23 +00001408 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001409 struct route_node *rn;
1410 struct ospf_area_range *range;
paul1eb8ef22005-04-07 07:30:20 +00001411 struct ospf_area *area;
paul718e3742002-12-13 20:15:29 +00001412
1413 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001414 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001415
paul1eb8ef22005-04-07 07:30:20 +00001416 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001417 {
paul718e3742002-12-13 20:15:29 +00001418 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1419 if ((range = rn->info) != NULL)
1420 {
1421 range->cost = 0;
1422 range->specifics = 0;
1423 }
1424 }
1425
1426 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001427 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001428}
1429
paul4dadc292005-05-06 21:37:42 +00001430static void
paul147193a2003-04-19 00:31:59 +00001431ospf_abr_announce_aggregates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001432{
1433 struct ospf_area *area, *ar;
1434 struct ospf_area_range *range;
1435 struct route_node *rn;
pauld4a53d52003-07-12 21:30:57 +00001436 struct prefix p;
hasso52dc7ee2004-09-23 19:18:23 +00001437 struct listnode *node, *n;
paul718e3742002-12-13 20:15:29 +00001438
1439 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001440 zlog_debug ("ospf_abr_announce_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001441
paul1eb8ef22005-04-07 07:30:20 +00001442 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001443 {
paul718e3742002-12-13 20:15:29 +00001444 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001445 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001446 inet_ntoa (area->area_id));
1447
1448 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1449 if ((range = rn->info))
1450 {
1451 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
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 " discarding suppress-ranges");
1456 continue;
1457 }
1458
1459 p.family = AF_INET;
pauld4a53d52003-07-12 21:30:57 +00001460 p.u.prefix4 = range->addr;
paul718e3742002-12-13 20:15:29 +00001461 p.prefixlen = range->masklen;
1462
1463 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001464 zlog_debug ("ospf_abr_announce_aggregates():"
paul718e3742002-12-13 20:15:29 +00001465 " this is range: %s/%d",
pauld4a53d52003-07-12 21:30:57 +00001466 inet_ntoa (p.u.prefix4), p.prefixlen);
paul718e3742002-12-13 20:15:29 +00001467
1468 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1469 {
1470 p.family = AF_INET;
pauld4a53d52003-07-12 21:30:57 +00001471 p.u.prefix4 = range->subst_addr;
paul718e3742002-12-13 20:15:29 +00001472 p.prefixlen = range->subst_masklen;
1473 }
1474
1475 if (range->specifics)
1476 {
1477 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001478 zlog_debug ("ospf_abr_announce_aggregates(): active range");
paul718e3742002-12-13 20:15:29 +00001479
paul1eb8ef22005-04-07 07:30:20 +00001480 for (ALL_LIST_ELEMENTS_RO (ospf->areas, n, ar))
paul718e3742002-12-13 20:15:29 +00001481 {
paul718e3742002-12-13 20:15:29 +00001482 if (ar == area)
1483 continue;
1484
1485 /* We do not check nexthops here, because
1486 intra-area routes can be associated with
1487 one area only */
1488
1489 /* backbone routes are not summarized
1490 when announced into transit areas */
1491
1492 if (ospf_area_is_transit (ar) &&
1493 OSPF_IS_AREA_BACKBONE (area))
1494 {
1495 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001496 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
paul718e3742002-12-13 20:15:29 +00001497 "announcement of BB aggregate into"
1498 " a transit area");
1499 continue;
1500 }
hassofa2b17e2004-03-04 17:45:00 +00001501 ospf_abr_announce_network_to_area ((struct prefix_ipv4 *)&p, range->cost, ar);
paul718e3742002-12-13 20:15:29 +00001502 }
1503 }
1504 }
1505 }
1506
1507 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001508 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001509}
1510
paul4dadc292005-05-06 21:37:42 +00001511static void
paul147193a2003-04-19 00:31:59 +00001512ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */
paul718e3742002-12-13 20:15:29 +00001513{
hasso52dc7ee2004-09-23 19:18:23 +00001514 struct listnode *node; /*, n; */
paul718e3742002-12-13 20:15:29 +00001515 struct ospf_area *area; /*, *ar; */
1516 struct route_node *rn;
1517 struct ospf_area_range *range;
1518 struct prefix_ipv4 p;
1519
1520 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001521 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001522
paul1eb8ef22005-04-07 07:30:20 +00001523 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001524 {
paule2c6c152003-06-22 08:49:25 +00001525 if (! area->NSSATranslatorState)
paul718e3742002-12-13 20:15:29 +00001526 continue;
1527
1528 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001529 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001530 inet_ntoa (area->area_id));
1531
1532 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1533 {
1534 if (rn->info == NULL)
1535 continue;
1536
1537 range = rn->info;
1538
1539 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
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 " discarding suppress-ranges");
1544 continue;
1545 }
1546
1547 p.family = AF_INET;
1548 p.prefix = range->addr;
1549 p.prefixlen = range->masklen;
1550
1551 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001552 zlog_debug ("ospf_abr_send_nssa_aggregates():"
paul718e3742002-12-13 20:15:29 +00001553 " this is range: %s/%d",
1554 inet_ntoa (p.prefix), p.prefixlen);
1555
1556 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1557 {
1558 p.family = AF_INET;
1559 p.prefix = range->subst_addr;
1560 p.prefixlen = range->subst_masklen;
1561 }
1562
1563 if (range->specifics)
paule2c6c152003-06-22 08:49:25 +00001564 {
1565 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001566 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
paul718e3742002-12-13 20:15:29 +00001567
paule2c6c152003-06-22 08:49:25 +00001568 /* Fetch LSA-Type-7 from aggregate prefix, and then
1569 * translate, Install (as Type-5), Approve, and Flood
1570 */
1571 ospf_abr_translate_nssa_range (&p, range->cost);
1572 }
1573 } /* all area ranges*/
paul718e3742002-12-13 20:15:29 +00001574 } /* all areas */
1575
1576 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001577 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001578}
1579
paul4dadc292005-05-06 21:37:42 +00001580static void
paul147193a2003-04-19 00:31:59 +00001581ospf_abr_announce_nssa_defaults (struct ospf *ospf) /* By ABR-Translator */
paul718e3742002-12-13 20:15:29 +00001582{
hasso52dc7ee2004-09-23 19:18:23 +00001583 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001584 struct ospf_area *area;
paul718e3742002-12-13 20:15:29 +00001585
paul147193a2003-04-19 00:31:59 +00001586 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001587 return;
1588
1589 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001590 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
paul718e3742002-12-13 20:15:29 +00001591
paul1eb8ef22005-04-07 07:30:20 +00001592 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001593 {
paul718e3742002-12-13 20:15:29 +00001594 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001595 zlog_debug ("ospf_abr_announce_nssa_defaults(): looking at area %s",
paule2c6c152003-06-22 08:49:25 +00001596 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001597
1598 if (area->external_routing != OSPF_AREA_NSSA)
paule2c6c152003-06-22 08:49:25 +00001599 continue;
paul718e3742002-12-13 20:15:29 +00001600
1601 if (OSPF_IS_AREA_BACKBONE (area))
paule2c6c152003-06-22 08:49:25 +00001602 continue; /* Sanity Check */
paul718e3742002-12-13 20:15:29 +00001603
1604 /* if (!TranslatorRole continue V 1.0 look for "always" conf */
paule2c6c152003-06-22 08:49:25 +00001605 if (area->NSSATranslatorState)
1606 {
1607 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001608 zlog_debug ("ospf_abr_announce_nssa_defaults(): "
paule2c6c152003-06-22 08:49:25 +00001609 "announcing 0.0.0.0/0 to this nssa");
1610 /* ospf_abr_announce_nssa_asbr_to_as (&p, area->default_cost, area); */
pauld4a53d52003-07-12 21:30:57 +00001611 /*ospf_abr_announce_network_to_area (&p, area->default_cost, area);*/
paule2c6c152003-06-22 08:49:25 +00001612 }
paul718e3742002-12-13 20:15:29 +00001613 }
1614}
paul718e3742002-12-13 20:15:29 +00001615
paul4dadc292005-05-06 21:37:42 +00001616static void
paul147193a2003-04-19 00:31:59 +00001617ospf_abr_announce_stub_defaults (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001618{
hasso52dc7ee2004-09-23 19:18:23 +00001619 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001620 struct ospf_area *area;
1621 struct prefix_ipv4 p;
1622
paul147193a2003-04-19 00:31:59 +00001623 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001624 return;
1625
1626 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001627 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
paul718e3742002-12-13 20:15:29 +00001628
1629 p.family = AF_INET;
1630 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1631 p.prefixlen = 0;
1632
paul1eb8ef22005-04-07 07:30:20 +00001633 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001634 {
paul718e3742002-12-13 20:15:29 +00001635 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001636 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1637 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001638
pauld4a53d52003-07-12 21:30:57 +00001639 if ( (area->external_routing != OSPF_AREA_STUB)
pauld4a53d52003-07-12 21:30:57 +00001640 && (area->external_routing != OSPF_AREA_NSSA)
pauld4a53d52003-07-12 21:30:57 +00001641 )
1642 continue;
paul718e3742002-12-13 20:15:29 +00001643
1644 if (OSPF_IS_AREA_BACKBONE (area))
pauld4a53d52003-07-12 21:30:57 +00001645 continue; /* Sanity Check */
1646
paul718e3742002-12-13 20:15:29 +00001647 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001648 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1649 "announcing 0.0.0.0/0 to area %s",
pauld4a53d52003-07-12 21:30:57 +00001650 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001651 ospf_abr_announce_network_to_area (&p, area->default_cost, area);
1652 }
1653
1654 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001655 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
paul718e3742002-12-13 20:15:29 +00001656}
1657
paul4dadc292005-05-06 21:37:42 +00001658static int
paul147193a2003-04-19 00:31:59 +00001659ospf_abr_remove_unapproved_translates_apply (struct ospf *ospf,
1660 struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001661{
1662 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)
1663 && ! CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1664 {
1665 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1666 "removing unapproved translates, ID: %s",
1667 inet_ntoa (lsa->data->id));
1668
1669 /* FLUSH THROUGHOUT AS */
paul147193a2003-04-19 00:31:59 +00001670 ospf_lsa_flush_as (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001671
1672 /* DISCARD from LSDB */
1673 }
1674 return 0;
1675}
1676
paul4dadc292005-05-06 21:37:42 +00001677static void
paul147193a2003-04-19 00:31:59 +00001678ospf_abr_remove_unapproved_translates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001679{
paul147193a2003-04-19 00:31:59 +00001680 struct route_node *rn;
1681 struct ospf_lsa *lsa;
1682
paul718e3742002-12-13 20:15:29 +00001683 /* All AREA PROCESS should have APPROVED necessary LSAs */
1684 /* Remove any left over and not APPROVED */
1685 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001686 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001687
paul147193a2003-04-19 00:31:59 +00001688 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1689 ospf_abr_remove_unapproved_translates_apply (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001690
1691 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001692 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001693}
paul718e3742002-12-13 20:15:29 +00001694
paul4dadc292005-05-06 21:37:42 +00001695static void
paul147193a2003-04-19 00:31:59 +00001696ospf_abr_remove_unapproved_summaries (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001697{
hasso52dc7ee2004-09-23 19:18:23 +00001698 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001699 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001700 struct route_node *rn;
1701 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +00001702
1703 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001704 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
paul718e3742002-12-13 20:15:29 +00001705
paul1eb8ef22005-04-07 07:30:20 +00001706 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001707 {
paul718e3742002-12-13 20:15:29 +00001708 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001709 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
paul718e3742002-12-13 20:15:29 +00001710 "looking at area %s", inet_ntoa (area->area_id));
1711
paul147193a2003-04-19 00:31:59 +00001712 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
1713 if (ospf_lsa_is_self_originated (ospf, lsa))
1714 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1715 ospf_lsa_flush_area (lsa, area);
1716
1717 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
1718 if (ospf_lsa_is_self_originated (ospf, lsa))
1719 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1720 ospf_lsa_flush_area (lsa, area);
paul718e3742002-12-13 20:15:29 +00001721 }
1722
1723 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001724 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
paul718e3742002-12-13 20:15:29 +00001725}
1726
paul4dadc292005-05-06 21:37:42 +00001727static void
paul147193a2003-04-19 00:31:59 +00001728ospf_abr_manage_discard_routes (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001729{
paul1eb8ef22005-04-07 07:30:20 +00001730 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001731 struct route_node *rn;
1732 struct ospf_area *area;
1733 struct ospf_area_range *range;
1734
paul1eb8ef22005-04-07 07:30:20 +00001735 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
1736 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1737 if ((range = rn->info) != NULL)
1738 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1739 {
1740 if (range->specifics)
1741 ospf_add_discard_route (ospf->new_table, area,
1742 (struct prefix_ipv4 *) &rn->p);
1743 else
1744 ospf_delete_discard_route ((struct prefix_ipv4 *) &rn->p);
1745 }
paul718e3742002-12-13 20:15:29 +00001746}
1747
paul718e3742002-12-13 20:15:29 +00001748/* This is the function taking care about ABR NSSA, i.e. NSSA
1749 Translator, -LSA aggregation and flooding. For all NSSAs
1750
1751 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1752 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1753 with the P-bit set.
1754
1755 Any received Type-5s are legal for an ABR, else illegal for IR.
1756 Received Type-7s are installed, by area, with incoming P-bit. They
1757 are flooded; if the Elected NSSA Translator, then P-bit off.
1758
1759 Additionally, this ABR will place "translated type-7's" into the
1760 Type-5 LSDB in order to keep track of APPROVAL or not.
1761
1762 It will scan through every area, looking for Type-7 LSAs with P-Bit
1763 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1764 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1765 5-INSTALLED.
1766
1767 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1768 left over are FLUSHED and DISCARDED.
1769
1770 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1771 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1772
paul4dadc292005-05-06 21:37:42 +00001773static void
paul147193a2003-04-19 00:31:59 +00001774ospf_abr_nssa_task (struct ospf *ospf) /* called only if any_nssa */
paul718e3742002-12-13 20:15:29 +00001775{
1776 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001777 zlog_debug ("Check for NSSA-ABR Tasks():");
paul718e3742002-12-13 20:15:29 +00001778
paul147193a2003-04-19 00:31:59 +00001779 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001780 return;
1781
paul147193a2003-04-19 00:31:59 +00001782 if (! ospf->anyNSSA)
paul718e3742002-12-13 20:15:29 +00001783 return;
1784
1785 /* Each area must confirm TranslatorRole */
1786 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001787 zlog_debug ("ospf_abr_nssa_task(): Start");
paul718e3742002-12-13 20:15:29 +00001788
1789 /* For all Global Entries flagged "local-translate", unset APPROVED */
1790 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001791 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
paul718e3742002-12-13 20:15:29 +00001792
paul147193a2003-04-19 00:31:59 +00001793 ospf_abr_unapprove_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001794
1795 /* RESET all Ranges in every Area, same as summaries */
1796 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001797 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
paule2c6c152003-06-22 08:49:25 +00001798 ospf_abr_prepare_aggregates (ospf); /*TURNED OFF just for now */
paul718e3742002-12-13 20:15:29 +00001799
1800 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
paule2c6c152003-06-22 08:49:25 +00001801 * Aggregate as Type-7
1802 * Install or Approve in Type-5 Global LSDB
1803 */
paul718e3742002-12-13 20:15:29 +00001804 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001805 zlog_debug ("ospf_abr_nssa_task(): process translates");
paul147193a2003-04-19 00:31:59 +00001806 ospf_abr_process_nssa_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001807
1808 /* Translate/Send any "ranged" aggregates, and also 5-Install and
paule2c6c152003-06-22 08:49:25 +00001809 * Approve
1810 * Scan Type-7's for aggregates, translate to Type-5's,
1811 * Install/Flood/Approve
1812 */
paul718e3742002-12-13 20:15:29 +00001813 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001814 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
paule2c6c152003-06-22 08:49:25 +00001815 ospf_abr_send_nssa_aggregates (ospf); /*TURNED OFF FOR NOW */
paul718e3742002-12-13 20:15:29 +00001816
pauld4a53d52003-07-12 21:30:57 +00001817 /* Send any NSSA defaults as Type-5
1818 *if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001819 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
pauld4a53d52003-07-12 21:30:57 +00001820 *ospf_abr_announce_nssa_defaults (ospf);
1821 * havnt a clue what above is supposed to do.
1822 */
paul718e3742002-12-13 20:15:29 +00001823
1824 /* Flush any unapproved previous translates from Global Data Base */
1825 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001826 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
paul147193a2003-04-19 00:31:59 +00001827 ospf_abr_remove_unapproved_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001828
paul147193a2003-04-19 00:31:59 +00001829 ospf_abr_manage_discard_routes (ospf); /* same as normal...discard */
paul718e3742002-12-13 20:15:29 +00001830
1831 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001832 zlog_debug ("ospf_abr_nssa_task(): Stop");
paul718e3742002-12-13 20:15:29 +00001833}
paul718e3742002-12-13 20:15:29 +00001834
1835/* This is the function taking care about ABR stuff, i.e.
1836 summary-LSA origination and flooding. */
1837void
paul147193a2003-04-19 00:31:59 +00001838ospf_abr_task (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001839{
1840 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001841 zlog_debug ("ospf_abr_task(): Start");
paul718e3742002-12-13 20:15:29 +00001842
paul147193a2003-04-19 00:31:59 +00001843 if (ospf->new_table == NULL || ospf->new_rtrs == NULL)
paul718e3742002-12-13 20:15:29 +00001844 {
1845 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001846 zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
paul718e3742002-12-13 20:15:29 +00001847 return;
1848 }
1849
1850 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001851 zlog_debug ("ospf_abr_task(): unapprove summaries");
paul147193a2003-04-19 00:31:59 +00001852 ospf_abr_unapprove_summaries (ospf);
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(): prepare aggregates");
paul147193a2003-04-19 00:31:59 +00001856 ospf_abr_prepare_aggregates (ospf);
paul718e3742002-12-13 20:15:29 +00001857
paul147193a2003-04-19 00:31:59 +00001858 if (IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001859 {
1860 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001861 zlog_debug ("ospf_abr_task(): process network RT");
paul147193a2003-04-19 00:31:59 +00001862 ospf_abr_process_network_rt (ospf, ospf->new_table);
paul718e3742002-12-13 20:15:29 +00001863
1864 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001865 zlog_debug ("ospf_abr_task(): process router RT");
paul147193a2003-04-19 00:31:59 +00001866 ospf_abr_process_router_rt (ospf, ospf->new_rtrs);
paul718e3742002-12-13 20:15:29 +00001867
1868 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001869 zlog_debug ("ospf_abr_task(): announce aggregates");
paul147193a2003-04-19 00:31:59 +00001870 ospf_abr_announce_aggregates (ospf);
paul718e3742002-12-13 20:15:29 +00001871
1872 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001873 zlog_debug ("ospf_abr_task(): announce stub defaults");
paul147193a2003-04-19 00:31:59 +00001874 ospf_abr_announce_stub_defaults (ospf);
paul718e3742002-12-13 20:15:29 +00001875 }
1876
1877 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001878 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
paul147193a2003-04-19 00:31:59 +00001879 ospf_abr_remove_unapproved_summaries (ospf);
paul718e3742002-12-13 20:15:29 +00001880
paul147193a2003-04-19 00:31:59 +00001881 ospf_abr_manage_discard_routes (ospf);
paul718e3742002-12-13 20:15:29 +00001882
paul718e3742002-12-13 20:15:29 +00001883 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001884 zlog_debug ("ospf_abr_task(): Stop");
paul718e3742002-12-13 20:15:29 +00001885}
1886
paul4dadc292005-05-06 21:37:42 +00001887static int
paul147193a2003-04-19 00:31:59 +00001888ospf_abr_task_timer (struct thread *thread)
paul718e3742002-12-13 20:15:29 +00001889{
paul147193a2003-04-19 00:31:59 +00001890 struct ospf *ospf = THREAD_ARG (thread);
1891
1892 ospf->t_abr_task = 0;
paul718e3742002-12-13 20:15:29 +00001893
1894 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001895 zlog_debug ("Running ABR task on timer");
paul718e3742002-12-13 20:15:29 +00001896
paul147193a2003-04-19 00:31:59 +00001897 ospf_check_abr_status (ospf);
pauld4a53d52003-07-12 21:30:57 +00001898 ospf_abr_nssa_check_status (ospf);
paul718e3742002-12-13 20:15:29 +00001899
paul147193a2003-04-19 00:31:59 +00001900 ospf_abr_task (ospf);
paule2c6c152003-06-22 08:49:25 +00001901 ospf_abr_nssa_task (ospf); /* if nssa-abr, then scan Type-7 LSDB */
paul718e3742002-12-13 20:15:29 +00001902
paul147193a2003-04-19 00:31:59 +00001903 return 0;
paul718e3742002-12-13 20:15:29 +00001904}
1905
1906void
paul147193a2003-04-19 00:31:59 +00001907ospf_schedule_abr_task (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001908{
1909 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001910 zlog_debug ("Scheduling ABR task");
paul147193a2003-04-19 00:31:59 +00001911
1912 if (ospf->t_abr_task == NULL)
1913 ospf->t_abr_task = thread_add_timer (master, ospf_abr_task_timer,
1914 ospf, OSPF_ABR_TASK_DELAY);
paul718e3742002-12-13 20:15:29 +00001915}