blob: ef1048b23b61513c02d528c2e2bb1e195a062bd7 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * OSPF ABR functions.
3 * Copyright (C) 1999, 2000 Alex Zinin, Toshiaki Takada
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23
24#include <zebra.h>
25
26#include "thread.h"
27#include "memory.h"
28#include "linklist.h"
29#include "prefix.h"
30#include "if.h"
31#include "table.h"
32#include "vty.h"
33#include "filter.h"
34#include "plist.h"
35#include "log.h"
36
37#include "ospfd/ospfd.h"
38#include "ospfd/ospf_interface.h"
39#include "ospfd/ospf_ism.h"
40#include "ospfd/ospf_asbr.h"
41#include "ospfd/ospf_lsa.h"
42#include "ospfd/ospf_lsdb.h"
43#include "ospfd/ospf_neighbor.h"
44#include "ospfd/ospf_nsm.h"
45#include "ospfd/ospf_spf.h"
46#include "ospfd/ospf_route.h"
47#include "ospfd/ospf_ia.h"
48#include "ospfd/ospf_flood.h"
49#include "ospfd/ospf_abr.h"
50#include "ospfd/ospf_ase.h"
51#include "ospfd/ospf_zebra.h"
52#include "ospfd/ospf_dump.h"
paul718e3742002-12-13 20:15:29 +000053
paul4dadc292005-05-06 21:37:42 +000054static struct ospf_area_range *
paul718e3742002-12-13 20:15:29 +000055ospf_area_range_new (struct prefix_ipv4 *p)
56{
57 struct ospf_area_range *range;
58
59 range = XCALLOC (MTYPE_OSPF_AREA_RANGE, sizeof (struct ospf_area_range));
60 range->addr = p->prefix;
61 range->masklen = p->prefixlen;
62 range->cost_config = OSPF_AREA_RANGE_COST_UNSPEC;
63
64 return range;
65}
66
paul4dadc292005-05-06 21:37:42 +000067static void
paul718e3742002-12-13 20:15:29 +000068ospf_area_range_free (struct ospf_area_range *range)
69{
70 XFREE (MTYPE_OSPF_AREA_RANGE, range);
71}
72
paul4dadc292005-05-06 21:37:42 +000073static void
paul718e3742002-12-13 20:15:29 +000074ospf_area_range_add (struct ospf_area *area, struct ospf_area_range *range)
75{
76 struct route_node *rn;
77 struct prefix_ipv4 p;
78
79 p.family = AF_INET;
80 p.prefixlen = range->masklen;
81 p.prefix = range->addr;
82
83 rn = route_node_get (area->ranges, (struct prefix *)&p);
84 if (rn->info)
85 route_unlock_node (rn);
86 else
87 rn->info = range;
88}
89
paul4dadc292005-05-06 21:37:42 +000090static void
JR Rivers8fc9e002012-09-24 17:26:46 +000091ospf_area_range_delete (struct ospf_area *area, struct route_node *rn)
paul718e3742002-12-13 20:15:29 +000092{
JR Rivers8fc9e002012-09-24 17:26:46 +000093 struct ospf_area_range *range = rn->info;
paul718e3742002-12-13 20:15:29 +000094
JR Rivers8fc9e002012-09-24 17:26:46 +000095 if (range->specifics != 0)
96 ospf_delete_discard_route (area->ospf->new_table,
97 (struct prefix_ipv4 *) &rn->p);
paul718e3742002-12-13 20:15:29 +000098
JR Rivers8fc9e002012-09-24 17:26:46 +000099 ospf_area_range_free (range);
100 rn->info = NULL;
101 route_unlock_node (rn);
102 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000103}
104
105struct ospf_area_range *
106ospf_area_range_lookup (struct ospf_area *area, struct prefix_ipv4 *p)
107{
108 struct route_node *rn;
109
110 rn = route_node_lookup (area->ranges, (struct prefix *)p);
111 if (rn)
112 {
113 route_unlock_node (rn);
114 return rn->info;
115 }
116 return NULL;
117}
118
119struct ospf_area_range *
pauld4a53d52003-07-12 21:30:57 +0000120ospf_area_range_lookup_next (struct ospf_area *area,
121 struct in_addr *range_net,
122 int first)
paul718e3742002-12-13 20:15:29 +0000123{
124 struct route_node *rn;
125 struct prefix_ipv4 p;
126 struct ospf_area_range *find;
127
128 p.family = AF_INET;
129 p.prefixlen = IPV4_MAX_BITLEN;
130 p.prefix = *range_net;
131
132 if (first)
133 rn = route_top (area->ranges);
134 else
135 {
136 rn = route_node_get (area->ranges, (struct prefix *) &p);
137 rn = route_next (rn);
138 }
139
140 for (; rn; rn = route_next (rn))
141 if (rn->info)
142 break;
143
144 if (rn && rn->info)
145 {
146 find = rn->info;
147 *range_net = rn->p.u.prefix4;
148 route_unlock_node (rn);
149 return find;
150 }
151 return NULL;
152}
153
paul4dadc292005-05-06 21:37:42 +0000154static struct ospf_area_range *
paul718e3742002-12-13 20:15:29 +0000155ospf_area_range_match (struct ospf_area *area, struct prefix_ipv4 *p)
156{
157 struct route_node *node;
158
159 node = route_node_match (area->ranges, (struct prefix *) p);
160 if (node)
161 {
162 route_unlock_node (node);
163 return node->info;
164 }
165 return NULL;
166}
167
168struct ospf_area_range *
169ospf_area_range_match_any (struct ospf *ospf, struct prefix_ipv4 *p)
170{
171 struct ospf_area_range *range;
paul1eb8ef22005-04-07 07:30:20 +0000172 struct ospf_area *area;
hasso52dc7ee2004-09-23 19:18:23 +0000173 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000174
paul1eb8ef22005-04-07 07:30:20 +0000175 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
176 if ((range = ospf_area_range_match (area, p)))
paul718e3742002-12-13 20:15:29 +0000177 return range;
178
179 return NULL;
180}
181
182int
183ospf_area_range_active (struct ospf_area_range *range)
184{
185 return range->specifics;
186}
187
paul4dadc292005-05-06 21:37:42 +0000188static int
paul718e3742002-12-13 20:15:29 +0000189ospf_area_actively_attached (struct ospf_area *area)
190{
191 return area->act_ints;
192}
193
194int
195ospf_area_range_set (struct ospf *ospf, struct in_addr area_id,
196 struct prefix_ipv4 *p, int advertise)
197{
198 struct ospf_area *area;
199 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000200 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000201
paul147193a2003-04-19 00:31:59 +0000202 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000203 if (area == NULL)
204 return 0;
205
206 range = ospf_area_range_lookup (area, p);
207 if (range != NULL)
208 {
209 if ((CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
210 && !CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
211 || (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
212 && CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE)))
paul147193a2003-04-19 00:31:59 +0000213 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000214 }
215 else
216 {
217 range = ospf_area_range_new (p);
218 ospf_area_range_add (area, range);
paul147193a2003-04-19 00:31:59 +0000219 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000220 }
221
222 if (CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
223 SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
224 else
225 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
226
227 return 1;
228}
229
230int
231ospf_area_range_cost_set (struct ospf *ospf, struct in_addr area_id,
232 struct prefix_ipv4 *p, u_int32_t cost)
233{
234 struct ospf_area *area;
235 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000236 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000237
paul147193a2003-04-19 00:31:59 +0000238 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000239 if (area == NULL)
240 return 0;
241
Paul Jakma214a4452006-05-12 22:51:49 +0000242 range = ospf_area_range_lookup (area, p);
paul718e3742002-12-13 20:15:29 +0000243 if (range == NULL)
244 return 0;
245
246 if (range->cost_config != cost)
247 {
248 range->cost_config = cost;
249 if (ospf_area_range_active (range))
paul147193a2003-04-19 00:31:59 +0000250 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000251 }
252
253 return 1;
254}
255
256int
257ospf_area_range_unset (struct ospf *ospf, struct in_addr area_id,
258 struct prefix_ipv4 *p)
259{
260 struct ospf_area *area;
JR Rivers8fc9e002012-09-24 17:26:46 +0000261 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +0000262
paul147193a2003-04-19 00:31:59 +0000263 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000264 if (area == NULL)
265 return 0;
266
JR Rivers8fc9e002012-09-24 17:26:46 +0000267 rn = route_node_lookup (area->ranges, (struct prefix*)p);
268 if (rn == NULL)
paul718e3742002-12-13 20:15:29 +0000269 return 0;
270
JR Rivers8fc9e002012-09-24 17:26:46 +0000271 if (ospf_area_range_active (rn->info))
paul147193a2003-04-19 00:31:59 +0000272 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000273
JR Rivers8fc9e002012-09-24 17:26:46 +0000274 ospf_area_range_delete (area, rn);
paul718e3742002-12-13 20:15:29 +0000275
276 return 1;
277}
278
279int
280ospf_area_range_substitute_set (struct ospf *ospf, struct in_addr area_id,
281 struct prefix_ipv4 *p, struct prefix_ipv4 *s)
282{
283 struct ospf_area *area;
284 struct ospf_area_range *range;
paul147193a2003-04-19 00:31:59 +0000285 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000286
paul147193a2003-04-19 00:31:59 +0000287 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000288 range = ospf_area_range_lookup (area, p);
289
290 if (range != NULL)
291 {
292 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE) ||
293 !CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
paul147193a2003-04-19 00:31:59 +0000294 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000295 }
296 else
297 {
298 range = ospf_area_range_new (p);
299 ospf_area_range_add (area, range);
paul147193a2003-04-19 00:31:59 +0000300 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000301 }
302
303 SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
304 SET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
305 range->subst_addr = s->prefix;
306 range->subst_masklen = s->prefixlen;
307
308 return 1;
309}
310
311int
312ospf_area_range_substitute_unset (struct ospf *ospf, struct in_addr area_id,
313 struct prefix_ipv4 *p)
314{
315 struct ospf_area *area;
316 struct ospf_area_range *range;
317
paul147193a2003-04-19 00:31:59 +0000318 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000319 if (area == NULL)
320 return 0;
321
322 range = ospf_area_range_lookup (area, p);
323 if (range == NULL)
324 return 0;
325
326 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
327 if (ospf_area_range_active (range))
paul147193a2003-04-19 00:31:59 +0000328 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000329
330 UNSET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
331 range->subst_addr.s_addr = 0;
332 range->subst_masklen = 0;
333
334 return 1;
335}
336
337int
paul147193a2003-04-19 00:31:59 +0000338ospf_act_bb_connection (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000339{
paul147193a2003-04-19 00:31:59 +0000340 if (ospf->backbone == NULL)
paul718e3742002-12-13 20:15:29 +0000341 return 0;
342
paul147193a2003-04-19 00:31:59 +0000343 return ospf->backbone->full_nbrs;
paul718e3742002-12-13 20:15:29 +0000344}
345
paule2c6c152003-06-22 08:49:25 +0000346/* Determine whether this router is elected translator or not for area */
paul4dadc292005-05-06 21:37:42 +0000347static int
paule2c6c152003-06-22 08:49:25 +0000348ospf_abr_nssa_am_elected (struct ospf_area *area)
349{
350 struct route_node *rn;
351 struct ospf_lsa *lsa;
352 struct router_lsa *rlsa;
353 struct in_addr *best = NULL;
354
355 LSDB_LOOP ( ROUTER_LSDB (area), rn, lsa)
356 {
357 /* sanity checks */
358 if (!lsa
359 || (lsa->data->type != OSPF_ROUTER_LSA)
360 || IS_LSA_SELF (lsa))
361 continue;
362
363 rlsa = (struct router_lsa *) lsa->data;
364
365 /* ignore non-ABR routers */
366 if (!IS_ROUTER_LSA_BORDER (rlsa))
367 continue;
368
369 /* Router has Nt flag - always translate */
370 if (IS_ROUTER_LSA_NT (rlsa))
371 {
372 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000373 zlog_debug ("ospf_abr_nssa_am_elected: "
paule2c6c152003-06-22 08:49:25 +0000374 "router %s asserts Nt",
375 inet_ntoa (lsa->data->id) );
376 return 0;
377 }
378
379 if (best == NULL)
380 best = &lsa->data->id;
381 else
Denis Ovsienko4e677f52011-12-18 16:27:02 +0400382 if (IPV4_ADDR_CMP (&best->s_addr, &lsa->data->id.s_addr) < 0)
paule2c6c152003-06-22 08:49:25 +0000383 best = &lsa->data->id;
384 }
385
386 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000387 zlog_debug ("ospf_abr_nssa_am_elected: best electable ABR is: %s",
paule2c6c152003-06-22 08:49:25 +0000388 (best) ? inet_ntoa (*best) : "<none>" );
389
390 if (best == NULL)
391 return 1;
392
Denis Ovsienko4e677f52011-12-18 16:27:02 +0400393 if (IPV4_ADDR_CMP (&best->s_addr, &area->ospf->router_id.s_addr) < 0)
paule2c6c152003-06-22 08:49:25 +0000394 return 1;
395 else
396 return 0;
397}
398
399/* Check NSSA ABR status
400 * assumes there are nssa areas
401 */
paul4dadc292005-05-06 21:37:42 +0000402static void
paule2c6c152003-06-22 08:49:25 +0000403ospf_abr_nssa_check_status (struct ospf *ospf)
404{
405 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000406 struct listnode *lnode, *nnode;
Paul Jakma9560fa82006-06-26 12:50:06 +0000407
paul1eb8ef22005-04-07 07:30:20 +0000408 for (ALL_LIST_ELEMENTS (ospf->areas, lnode, nnode, area))
paule2c6c152003-06-22 08:49:25 +0000409 {
Paul Jakma9560fa82006-06-26 12:50:06 +0000410 u_char old_state = area->NSSATranslatorState;
411
paule2c6c152003-06-22 08:49:25 +0000412 if (area->external_routing != OSPF_AREA_NSSA)
413 continue;
Paul Jakma9560fa82006-06-26 12:50:06 +0000414
paule2c6c152003-06-22 08:49:25 +0000415 if (IS_DEBUG_OSPF (nssa, NSSA))
ajse84cc642004-12-08 17:28:56 +0000416 zlog_debug ("ospf_abr_nssa_check_status: "
paule2c6c152003-06-22 08:49:25 +0000417 "checking area %s",
418 inet_ntoa (area->area_id));
Paul Jakma9560fa82006-06-26 12:50:06 +0000419
paule2c6c152003-06-22 08:49:25 +0000420 if (!IS_OSPF_ABR (area->ospf))
421 {
422 if (IS_DEBUG_OSPF (nssa, NSSA))
Paul Jakma9560fa82006-06-26 12:50:06 +0000423 zlog_debug ("ospf_abr_nssa_check_status: "
424 "not ABR");
pauld4a53d52003-07-12 21:30:57 +0000425 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
paule2c6c152003-06-22 08:49:25 +0000426 }
Paul Jakma9560fa82006-06-26 12:50:06 +0000427 else
428 {
429 switch (area->NSSATranslatorRole)
430 {
431 case OSPF_NSSA_ROLE_NEVER:
432 /* We never Translate Type-7 LSA. */
433 /* TODO: check previous state and flush? */
434 if (IS_DEBUG_OSPF (nssa, NSSA))
435 zlog_debug ("ospf_abr_nssa_check_status: "
436 "never translate");
437 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
438 break;
439
440 case OSPF_NSSA_ROLE_ALWAYS:
441 /* We always translate if we are an ABR
442 * TODO: originate new LSAs if state change?
443 * or let the nssa abr task take care of it?
444 */
445 if (IS_DEBUG_OSPF (nssa, NSSA))
446 zlog_debug ("ospf_abr_nssa_check_status: "
447 "translate always");
448 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
449 break;
450
451 case OSPF_NSSA_ROLE_CANDIDATE:
452 /* We are a candidate for Translation */
453 if (ospf_abr_nssa_am_elected (area) > 0)
454 {
455 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
456 if (IS_DEBUG_OSPF (nssa, NSSA))
457 zlog_debug ("ospf_abr_nssa_check_status: "
458 "elected translator");
459 }
460 else
461 {
462 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
463 if (IS_DEBUG_OSPF (nssa, NSSA))
464 zlog_debug ("ospf_abr_nssa_check_status: " "not elected");
465 }
466 break;
467 }
468 }
469 /* RFC3101, 3.1:
470 * All NSSA border routers must set the E-bit in the Type-1 router-LSAs
471 * of their directly attached non-stub areas, even when they are not
472 * translating.
473 */
474 if (old_state != area->NSSATranslatorState)
475 {
476 if (old_state == OSPF_NSSA_TRANSLATE_DISABLED)
477 ospf_asbr_status_update (ospf, ++ospf->redistribute);
478 else if (area->NSSATranslatorState == OSPF_NSSA_TRANSLATE_DISABLED)
479 ospf_asbr_status_update (ospf, --ospf->redistribute);
480 }
paule2c6c152003-06-22 08:49:25 +0000481 }
482}
paule2c6c152003-06-22 08:49:25 +0000483
paul718e3742002-12-13 20:15:29 +0000484/* Check area border router status. */
485void
paul147193a2003-04-19 00:31:59 +0000486ospf_check_abr_status (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000487{
488 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000489 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000490 int bb_configured = 0;
491 int bb_act_attached = 0;
492 int areas_configured = 0;
493 int areas_act_attached = 0;
paul147193a2003-04-19 00:31:59 +0000494 u_char new_flags = ospf->flags;
paul718e3742002-12-13 20:15:29 +0000495
496 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000497 zlog_debug ("ospf_check_abr_status(): Start");
paul718e3742002-12-13 20:15:29 +0000498
paul1eb8ef22005-04-07 07:30:20 +0000499 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
paul718e3742002-12-13 20:15:29 +0000500 {
paul718e3742002-12-13 20:15:29 +0000501 if (listcount (area->oiflist))
502 {
503 areas_configured++;
504
505 if (OSPF_IS_AREA_BACKBONE (area))
506 bb_configured = 1;
507 }
508
509 if (ospf_area_actively_attached (area))
510 {
511 areas_act_attached++;
512
513 if (OSPF_IS_AREA_BACKBONE (area))
514 bb_act_attached = 1;
515 }
516 }
517
518 if (IS_DEBUG_OSPF_EVENT)
519 {
ajse84cc642004-12-08 17:28:56 +0000520 zlog_debug ("ospf_check_abr_status(): looked through areas");
521 zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured);
522 zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
paul718e3742002-12-13 20:15:29 +0000523 bb_act_attached);
ajse84cc642004-12-08 17:28:56 +0000524 zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
paul718e3742002-12-13 20:15:29 +0000525 areas_configured);
ajse84cc642004-12-08 17:28:56 +0000526 zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
paul718e3742002-12-13 20:15:29 +0000527 areas_act_attached);
528 }
529
paul147193a2003-04-19 00:31:59 +0000530 switch (ospf->abr_type)
paul718e3742002-12-13 20:15:29 +0000531 {
532 case OSPF_ABR_SHORTCUT:
533 case OSPF_ABR_STAND:
534 if (areas_act_attached > 1)
535 SET_FLAG (new_flags, OSPF_FLAG_ABR);
536 else
537 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
538 break;
539
540 case OSPF_ABR_IBM:
541 if ((areas_act_attached > 1) && bb_configured)
542 SET_FLAG (new_flags, OSPF_FLAG_ABR);
543 else
544 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
545 break;
546
547 case OSPF_ABR_CISCO:
548 if ((areas_configured > 1) && bb_act_attached)
549 SET_FLAG (new_flags, OSPF_FLAG_ABR);
550 else
551 UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
552 break;
553 default:
554 break;
555 }
556
paul147193a2003-04-19 00:31:59 +0000557 if (new_flags != ospf->flags)
paul718e3742002-12-13 20:15:29 +0000558 {
paul147193a2003-04-19 00:31:59 +0000559 ospf_spf_calculate_schedule (ospf);
paul718e3742002-12-13 20:15:29 +0000560 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000561 zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags);
paul147193a2003-04-19 00:31:59 +0000562 ospf->flags = new_flags;
Paul Jakmac363d382010-01-24 22:42:13 +0000563 ospf_router_lsa_update (ospf);
paul718e3742002-12-13 20:15:29 +0000564 }
565}
566
paul4dadc292005-05-06 21:37:42 +0000567static void
paul718e3742002-12-13 20:15:29 +0000568ospf_abr_update_aggregate (struct ospf_area_range *range,
paul7f352b82004-02-19 19:37:47 +0000569 struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000570{
571 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000572 zlog_debug ("ospf_abr_update_aggregate(): Start");
paul718e3742002-12-13 20:15:29 +0000573
paul6c835672004-10-11 11:00:30 +0000574 if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
paul718e3742002-12-13 20:15:29 +0000575 {
576 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000577 zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
paul7f352b82004-02-19 19:37:47 +0000578 range->cost_config);
paul718e3742002-12-13 20:15:29 +0000579
580 range->cost = range->cost_config;
581 }
582 else
583 {
584 if (range->specifics == 0)
paul7f352b82004-02-19 19:37:47 +0000585 range->cost = or->cost; /* 1st time get 1st cost */
paul718e3742002-12-13 20:15:29 +0000586
paul7f352b82004-02-19 19:37:47 +0000587 if (or->cost > range->cost)
588 {
589 if (IS_DEBUG_OSPF_EVENT)
paul500e4182005-05-26 17:11:13 +0000590 zlog_debug ("ospf_abr_update_aggregate(): largest cost, update");
paul718e3742002-12-13 20:15:29 +0000591
paul7f352b82004-02-19 19:37:47 +0000592 range->cost = or->cost;
593 }
paul718e3742002-12-13 20:15:29 +0000594 }
595
596 range->specifics++;
597}
598
599static void
600set_metric (struct ospf_lsa *lsa, u_int32_t metric)
601{
602 struct summary_lsa *header;
603 u_char *mp;
604 metric = htonl (metric);
hassoc9e52be2004-09-26 16:09:34 +0000605 mp = (u_char *) &metric;
paul718e3742002-12-13 20:15:29 +0000606 mp++;
607 header = (struct summary_lsa *) lsa->data;
608 memcpy(header->metric, mp, 3);
609}
610
paul718e3742002-12-13 20:15:29 +0000611/* ospf_abr_translate_nssa */
paul4dadc292005-05-06 21:37:42 +0000612static int
paul147193a2003-04-19 00:31:59 +0000613ospf_abr_translate_nssa (struct ospf_area *area, struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000614{
615 /* Incoming Type-7 or later aggregated Type-7
pauld4a53d52003-07-12 21:30:57 +0000616 *
617 * LSA is skipped if P-bit is off.
618 * LSA is aggregated if within range.
619 *
620 * The Type-7 is translated, Installed/Approved as a Type-5 into
621 * global LSDB, then Flooded through AS
622 *
623 * Later, any Unapproved Translated Type-5's are flushed/discarded
624 */
paul718e3742002-12-13 20:15:29 +0000625
pauld4a53d52003-07-12 21:30:57 +0000626 struct ospf_lsa *old = NULL,
627 *new = NULL;
628 struct as_external_lsa *ext7;
629 struct prefix_ipv4 p;
paul718e3742002-12-13 20:15:29 +0000630
631 if (! CHECK_FLAG (lsa->data->options, OSPF_OPTION_NP))
632 {
633 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000634 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
pauld4a53d52003-07-12 21:30:57 +0000635 inet_ntoa (lsa->data->id));
636 return 1;
paul718e3742002-12-13 20:15:29 +0000637 }
pauld4a53d52003-07-12 21:30:57 +0000638
paul718e3742002-12-13 20:15:29 +0000639 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000640 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
pauld4a53d52003-07-12 21:30:57 +0000641 inet_ntoa (lsa->data->id));
paul718e3742002-12-13 20:15:29 +0000642
pauld4a53d52003-07-12 21:30:57 +0000643 ext7 = (struct as_external_lsa *)(lsa->data);
644 p.prefix = lsa->data->id;
645 p.prefixlen = ip_masklen (ext7->mask);
646
647 if (ext7->e[0].fwd_addr.s_addr == OSPF_DEFAULT_DESTINATION)
648 {
649 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000650 zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, "
pauld4a53d52003-07-12 21:30:57 +0000651 "Forward address is 0, NO Translation",
652 inet_ntoa (lsa->data->id));
653 return 1;
654 }
655
656 /* try find existing AS-External LSA for this prefix */
657
658 old = ospf_external_info_find_lsa (area->ospf, &p);
659
660 if (old)
661 {
662 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000663 zlog_debug ("ospf_abr_translate_nssa(): "
pauld4a53d52003-07-12 21:30:57 +0000664 "found old translated LSA Id %s, refreshing",
665 inet_ntoa (old->data->id));
666
667 /* refresh */
668 new = ospf_translated_nssa_refresh (area->ospf, lsa, old);
669 if (!new)
670 {
671 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000672 zlog_debug ("ospf_abr_translate_nssa(): "
pauld4a53d52003-07-12 21:30:57 +0000673 "could not refresh translated LSA Id %s",
674 inet_ntoa (old->data->id));
675 }
676 }
677 else
678 {
679 /* no existing external route for this LSA Id
680 * originate translated LSA
681 */
682
683 if ((new = ospf_translated_nssa_originate (area->ospf, lsa))
684 == NULL)
685 {
686 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000687 zlog_debug ("ospf_abr_translate_nssa(): Could not translate "
pauld4a53d52003-07-12 21:30:57 +0000688 "Type-7 for %s to Type-5",
689 inet_ntoa (lsa->data->id));
690 return 1;
691 }
692 }
paul718e3742002-12-13 20:15:29 +0000693
694 /* Area where Aggregate testing will be inserted, just like summary
695 advertisements */
696 /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
697
paul718e3742002-12-13 20:15:29 +0000698 return 0;
699}
700
paul4dadc292005-05-06 21:37:42 +0000701static void
paul718e3742002-12-13 20:15:29 +0000702ospf_abr_translate_nssa_range (struct prefix_ipv4 *p, u_int32_t cost)
703{
704 /* The Type-7 is created from the aggregated prefix and forwarded
705 for lsa installation and flooding... to be added... */
706}
paul718e3742002-12-13 20:15:29 +0000707
vincentba682532005-09-29 13:52:57 +0000708void
paul718e3742002-12-13 20:15:29 +0000709ospf_abr_announce_network_to_area (struct prefix_ipv4 *p, u_int32_t cost,
710 struct ospf_area *area)
711{
712 struct ospf_lsa *lsa, *old = NULL;
713 struct summary_lsa *sl = NULL;
714
715 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000716 zlog_debug ("ospf_abr_announce_network_to_area(): Start");
paul718e3742002-12-13 20:15:29 +0000717
pauld4a53d52003-07-12 21:30:57 +0000718 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_SUMMARY_LSA,
719 (struct prefix_ipv4 *) p,
720 area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +0000721 if (old)
722 {
723 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000724 zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
pauld4a53d52003-07-12 21:30:57 +0000725
paul718e3742002-12-13 20:15:29 +0000726 sl = (struct summary_lsa *) old->data;
727
728 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000729 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000730 "old metric: %d, new metric: %d",
731 GET_METRIC (sl->metric), cost);
732
733 if (GET_METRIC (sl->metric) == cost)
734 {
735 /* unchanged. simply reapprove it */
736 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000737 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000738 "old summary approved");
739 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
740 }
741 else
742 {
743 /* LSA is changed, refresh it */
744 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000745 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000746 "refreshing summary");
747 set_metric (old, cost);
Paul Jakmac363d382010-01-24 22:42:13 +0000748 lsa = ospf_lsa_refresh (area->ospf, old);
paulc24d6022005-11-20 14:54:12 +0000749
750 if (!lsa)
751 {
752 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
753
754 prefix2str ((struct prefix *) p, buf, sizeof(buf));
755 zlog_warn ("%s: Could not refresh %s to %s",
756 __func__,
757 buf,
758 inet_ntoa (area->area_id));
759 return;
760 }
761
paulc8987752005-07-26 06:07:22 +0000762 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
pauld4a53d52003-07-12 21:30:57 +0000763 /* This will flood through area. */
764 }
paul718e3742002-12-13 20:15:29 +0000765 }
766 else
767 {
768 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000769 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000770 "creating new summary");
771 lsa = ospf_summary_lsa_originate ( (struct prefix_ipv4 *)p, cost, area);
772 /* This will flood through area. */
paul718e3742002-12-13 20:15:29 +0000773
paulc24d6022005-11-20 14:54:12 +0000774 if (!lsa)
775 {
776 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
777
778 prefix2str ((struct prefix *)p, buf, sizeof(buf));
779 zlog_warn ("%s: Could not originate %s to %s",
780 __func__,
781 buf,
782 inet_ntoa (area->area_id));
783 return;
784 }
785
paul718e3742002-12-13 20:15:29 +0000786 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
787 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000788 zlog_debug ("ospf_abr_announce_network_to_area(): "
pauld4a53d52003-07-12 21:30:57 +0000789 "flooding new version of summary");
paul718e3742002-12-13 20:15:29 +0000790 }
791
792 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000793 zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
paul718e3742002-12-13 20:15:29 +0000794}
795
paul4dadc292005-05-06 21:37:42 +0000796static int
paul718e3742002-12-13 20:15:29 +0000797ospf_abr_nexthops_belong_to_area (struct ospf_route *or,
798 struct ospf_area *area)
799{
paul1eb8ef22005-04-07 07:30:20 +0000800 struct listnode *node, *nnode;
paul96735ee2003-08-10 02:51:22 +0000801 struct ospf_path *path;
Joakim Tjernlunda8ba8472009-07-27 12:42:34 +0200802 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000803
Joakim Tjernlunda8ba8472009-07-27 12:42:34 +0200804 for (ALL_LIST_ELEMENTS_RO (or->paths, node, path))
805 for (ALL_LIST_ELEMENTS_RO (area->oiflist, nnode, oi))
806 if (oi->ifp && oi->ifp->ifindex == path->ifindex)
807 return 1;
paul718e3742002-12-13 20:15:29 +0000808
809 return 0;
810}
811
paul4dadc292005-05-06 21:37:42 +0000812static int
pauld4a53d52003-07-12 21:30:57 +0000813ospf_abr_should_accept (struct prefix_ipv4 *p, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +0000814{
815 if (IMPORT_NAME (area))
816 {
817 if (IMPORT_LIST (area) == NULL)
818 IMPORT_LIST (area) = access_list_lookup (AFI_IP, IMPORT_NAME (area));
819
820 if (IMPORT_LIST (area))
821 if (access_list_apply (IMPORT_LIST (area), p) == FILTER_DENY)
822 return 0;
823 }
824
825 return 1;
826}
827
paul4dadc292005-05-06 21:37:42 +0000828static int
paul718e3742002-12-13 20:15:29 +0000829ospf_abr_plist_in_check (struct ospf_area *area, struct ospf_route *or,
pauld4a53d52003-07-12 21:30:57 +0000830 struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000831{
832 if (PREFIX_NAME_IN (area))
833 {
834 if (PREFIX_LIST_IN (area) == NULL)
835 PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP,
836 PREFIX_NAME_IN (area));
837 if (PREFIX_LIST_IN (area))
838 if (prefix_list_apply (PREFIX_LIST_IN (area), p) != PREFIX_PERMIT)
839 return 0;
840 }
841 return 1;
842}
843
paul4dadc292005-05-06 21:37:42 +0000844static int
paul718e3742002-12-13 20:15:29 +0000845ospf_abr_plist_out_check (struct ospf_area *area, struct ospf_route *or,
pauld4a53d52003-07-12 21:30:57 +0000846 struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000847{
848 if (PREFIX_NAME_OUT (area))
849 {
850 if (PREFIX_LIST_OUT (area) == NULL)
851 PREFIX_LIST_OUT (area) = prefix_list_lookup (AFI_IP,
852 PREFIX_NAME_OUT (area));
853 if (PREFIX_LIST_OUT (area))
854 if (prefix_list_apply (PREFIX_LIST_OUT (area), p) != PREFIX_PERMIT)
855 return 0;
856 }
857 return 1;
858}
859
paul4dadc292005-05-06 21:37:42 +0000860static void
paul147193a2003-04-19 00:31:59 +0000861ospf_abr_announce_network (struct ospf *ospf,
pauld4a53d52003-07-12 21:30:57 +0000862 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000863{
paul718e3742002-12-13 20:15:29 +0000864 struct ospf_area_range *range;
paul718e3742002-12-13 20:15:29 +0000865 struct ospf_area *area, *or_area;
hasso52dc7ee2004-09-23 19:18:23 +0000866 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000867
868 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000869 zlog_debug ("ospf_abr_announce_network(): Start");
paul718e3742002-12-13 20:15:29 +0000870
paul147193a2003-04-19 00:31:59 +0000871 or_area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
paul718e3742002-12-13 20:15:29 +0000872 assert (or_area);
873
paul1eb8ef22005-04-07 07:30:20 +0000874 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000875 {
paul718e3742002-12-13 20:15:29 +0000876 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000877 zlog_debug ("ospf_abr_announce_network(): looking at area %s",
paul718e3742002-12-13 20:15:29 +0000878 inet_ntoa (area->area_id));
879
880 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
881 continue;
882
883 if (ospf_abr_nexthops_belong_to_area (or, area))
884 continue;
885
pauld4a53d52003-07-12 21:30:57 +0000886 if (!ospf_abr_should_accept (p, area))
paul718e3742002-12-13 20:15:29 +0000887 {
888 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000889 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000890 "prefix %s/%d was denied by import-list",
891 inet_ntoa (p->prefix), p->prefixlen);
892 continue;
893 }
894
pauld4a53d52003-07-12 21:30:57 +0000895 if (!ospf_abr_plist_in_check (area, or, p))
paul718e3742002-12-13 20:15:29 +0000896 {
897 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000898 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000899 "prefix %s/%d was denied by prefix-list",
900 inet_ntoa (p->prefix), p->prefixlen);
901 continue;
902 }
903
904 if (area->external_routing != OSPF_AREA_DEFAULT && area->no_summary)
905 {
906 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000907 zlog_debug ("ospf_abr_announce_network(): "
paul718e3742002-12-13 20:15:29 +0000908 "area %s is stub and no_summary",
909 inet_ntoa (area->area_id));
910 continue;
911 }
912
913 if (or->path_type == OSPF_PATH_INTER_AREA)
914 {
915 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000916 zlog_debug ("ospf_abr_announce_network(): this is "
paul718e3742002-12-13 20:15:29 +0000917 "inter-area route to %s/%d",
918 inet_ntoa (p->prefix), p->prefixlen);
919
920 if (!OSPF_IS_AREA_BACKBONE (area))
921 ospf_abr_announce_network_to_area (p, or->cost, area);
922 }
923
924 if (or->path_type == OSPF_PATH_INTRA_AREA)
pauld4a53d52003-07-12 21:30:57 +0000925 {
926 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +0000927 zlog_debug ("ospf_abr_announce_network(): "
pauld4a53d52003-07-12 21:30:57 +0000928 "this is intra-area route to %s/%d",
929 inet_ntoa (p->prefix), p->prefixlen);
930 if ((range = ospf_area_range_match (or_area, p))
931 && !ospf_area_is_transit (area))
932 ospf_abr_update_aggregate (range, or);
933 else
934 ospf_abr_announce_network_to_area (p, or->cost, area);
935 }
paul718e3742002-12-13 20:15:29 +0000936 }
937}
938
paul4dadc292005-05-06 21:37:42 +0000939static int
paul147193a2003-04-19 00:31:59 +0000940ospf_abr_should_announce (struct ospf *ospf,
pauld4a53d52003-07-12 21:30:57 +0000941 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +0000942{
paul147193a2003-04-19 00:31:59 +0000943 struct ospf_area *area;
944
945 area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
paul718e3742002-12-13 20:15:29 +0000946
947 assert (area);
948
949 if (EXPORT_NAME (area))
950 {
951 if (EXPORT_LIST (area) == NULL)
952 EXPORT_LIST (area) = access_list_lookup (AFI_IP, EXPORT_NAME (area));
953
954 if (EXPORT_LIST (area))
955 if (access_list_apply (EXPORT_LIST (area), p) == FILTER_DENY)
956 return 0;
957 }
958
959 return 1;
960}
961
paul4dadc292005-05-06 21:37:42 +0000962static void
paul147193a2003-04-19 00:31:59 +0000963ospf_abr_process_nssa_translates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000964{
965 /* Scan through all NSSA_LSDB records for all areas;
966
967 If P-bit is on, translate all Type-7's to 5's and aggregate or
968 flood install as approved in Type-5 LSDB with XLATE Flag on
969 later, do same for all aggregates... At end, DISCARD all
970 remaining UNAPPROVED Type-5's (Aggregate is for future ) */
hasso52dc7ee2004-09-23 19:18:23 +0000971 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000972 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +0000973 struct route_node *rn;
974 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000975
976 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000977 zlog_debug ("ospf_abr_process_nssa_translates(): Start");
paul718e3742002-12-13 20:15:29 +0000978
paul1eb8ef22005-04-07 07:30:20 +0000979 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000980 {
paule2c6c152003-06-22 08:49:25 +0000981 if (! area->NSSATranslatorState)
pauld4a53d52003-07-12 21:30:57 +0000982 continue; /* skip if not translator */
paul718e3742002-12-13 20:15:29 +0000983
984 if (area->external_routing != OSPF_AREA_NSSA)
pauld4a53d52003-07-12 21:30:57 +0000985 continue; /* skip if not Nssa Area */
paul718e3742002-12-13 20:15:29 +0000986
987 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000988 zlog_debug ("ospf_abr_process_nssa_translates(): "
pauld4a53d52003-07-12 21:30:57 +0000989 "looking at area %s", inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +0000990
paul147193a2003-04-19 00:31:59 +0000991 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +0000992 ospf_abr_translate_nssa (area, lsa);
paul718e3742002-12-13 20:15:29 +0000993 }
994
995 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +0000996 zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
paul718e3742002-12-13 20:15:29 +0000997
998}
paul718e3742002-12-13 20:15:29 +0000999
paul4dadc292005-05-06 21:37:42 +00001000static void
paul147193a2003-04-19 00:31:59 +00001001ospf_abr_process_network_rt (struct ospf *ospf,
1002 struct route_table *rt)
paul718e3742002-12-13 20:15:29 +00001003{
paul718e3742002-12-13 20:15:29 +00001004 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001005 struct ospf_route *or;
1006 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +00001007
1008 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001009 zlog_debug ("ospf_abr_process_network_rt(): Start");
paul718e3742002-12-13 20:15:29 +00001010
1011 for (rn = route_top (rt); rn; rn = route_next (rn))
1012 {
1013 if ((or = rn->info) == NULL)
1014 continue;
1015
paul147193a2003-04-19 00:31:59 +00001016 if (!(area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id)))
paul718e3742002-12-13 20:15:29 +00001017 {
1018 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001019 zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
paul718e3742002-12-13 20:15:29 +00001020 inet_ntoa (or->u.std.area_id));
1021 continue;
1022 }
1023
1024 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001025 zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
paul718e3742002-12-13 20:15:29 +00001026 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
1027 if (or->path_type >= OSPF_PATH_TYPE1_EXTERNAL)
1028 {
1029 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001030 zlog_debug ("ospf_abr_process_network_rt(): "
paul718e3742002-12-13 20:15:29 +00001031 "this is an External router, skipping");
1032 continue;
1033 }
1034
1035 if (or->cost >= OSPF_LS_INFINITY)
1036 {
1037 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001038 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001039 " this route's cost is infinity, skipping");
1040 continue;
1041 }
1042
1043 if (or->type == OSPF_DESTINATION_DISCARD)
1044 {
1045 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001046 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001047 " this is a discard entry, skipping");
1048 continue;
1049 }
1050
1051 if (or->path_type == OSPF_PATH_INTRA_AREA &&
pauld4a53d52003-07-12 21:30:57 +00001052 !ospf_abr_should_announce (ospf, (struct prefix_ipv4 *) &rn->p, or))
paul718e3742002-12-13 20:15:29 +00001053 {
1054 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001055 zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
paul718e3742002-12-13 20:15:29 +00001056 continue;
1057 }
1058
1059 if (or->path_type == OSPF_PATH_INTRA_AREA &&
pauld4a53d52003-07-12 21:30:57 +00001060 !ospf_abr_plist_out_check (area, or, (struct prefix_ipv4 *) &rn->p))
paul718e3742002-12-13 20:15:29 +00001061 {
1062 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001063 zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
paul718e3742002-12-13 20:15:29 +00001064 continue;
1065 }
1066
1067 if ((or->path_type == OSPF_PATH_INTER_AREA) &&
1068 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1069 {
1070 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001071 zlog_debug ("ospf_abr_process_network_rt():"
paul718e3742002-12-13 20:15:29 +00001072 " this is route is not backbone one, skipping");
1073 continue;
1074 }
1075
1076
paul147193a2003-04-19 00:31:59 +00001077 if ((ospf->abr_type == OSPF_ABR_CISCO) ||
1078 (ospf->abr_type == OSPF_ABR_IBM))
paul718e3742002-12-13 20:15:29 +00001079
paul147193a2003-04-19 00:31:59 +00001080 if (!ospf_act_bb_connection (ospf) &&
paul718e3742002-12-13 20:15:29 +00001081 or->path_type != OSPF_PATH_INTRA_AREA)
1082 {
1083 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001084 zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
paul718e3742002-12-13 20:15:29 +00001085 "No BB connection, skip not intra-area routes");
1086 continue;
1087 }
1088
1089 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001090 zlog_debug ("ospf_abr_process_network_rt(): announcing");
hassofa2b17e2004-03-04 17:45:00 +00001091 ospf_abr_announce_network (ospf, (struct prefix_ipv4 *)&rn->p, or);
paul718e3742002-12-13 20:15:29 +00001092 }
1093
1094 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001095 zlog_debug ("ospf_abr_process_network_rt(): Stop");
paul718e3742002-12-13 20:15:29 +00001096}
1097
paul4dadc292005-05-06 21:37:42 +00001098static void
paul718e3742002-12-13 20:15:29 +00001099ospf_abr_announce_rtr_to_area (struct prefix_ipv4 *p, u_int32_t cost,
1100 struct ospf_area *area)
1101{
1102 struct ospf_lsa *lsa, *old = NULL;
1103 struct summary_lsa *slsa = NULL;
1104
1105 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001106 zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
paul718e3742002-12-13 20:15:29 +00001107
paul147193a2003-04-19 00:31:59 +00001108 old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_ASBR_SUMMARY_LSA,
1109 p, area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +00001110 if (old)
1111 {
1112 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001113 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
paul718e3742002-12-13 20:15:29 +00001114 slsa = (struct summary_lsa *) old->data;
1115
1116 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001117 zlog_debug ("ospf_abr_announce_network_to_area(): "
paul718e3742002-12-13 20:15:29 +00001118 "old metric: %d, new metric: %d",
1119 GET_METRIC (slsa->metric), cost);
1120 }
1121
1122 if (old && (GET_METRIC (slsa->metric) == cost))
1123 {
1124 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001125 zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
paul718e3742002-12-13 20:15:29 +00001126 SET_FLAG (old->flags, OSPF_LSA_APPROVED);
1127 }
1128 else
1129 {
1130 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001131 zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
paul718e3742002-12-13 20:15:29 +00001132
1133 if (old)
1134 {
1135 set_metric (old, cost);
Paul Jakmac363d382010-01-24 22:42:13 +00001136 lsa = ospf_lsa_refresh (area->ospf, old);
paul718e3742002-12-13 20:15:29 +00001137 }
1138 else
1139 lsa = ospf_summary_asbr_lsa_originate (p, cost, area);
paulc24d6022005-11-20 14:54:12 +00001140 if (!lsa)
1141 {
1142 char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
1143
1144 prefix2str ((struct prefix *)p, buf, sizeof(buf));
1145 zlog_warn ("%s: Could not refresh/originate %s to %s",
1146 __func__,
1147 buf,
1148 inet_ntoa (area->area_id));
1149 return;
1150 }
1151
paul718e3742002-12-13 20:15:29 +00001152 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001153 zlog_debug ("ospf_abr_announce_rtr_to_area(): "
paul718e3742002-12-13 20:15:29 +00001154 "flooding new version of summary");
paulc24d6022005-11-20 14:54:12 +00001155
paul718e3742002-12-13 20:15:29 +00001156 /*
1157 zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
1158 lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
1159
1160 SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1161 /* ospf_flood_through_area (area, NULL, lsa);*/
1162 }
1163
1164 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001165 zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
paul718e3742002-12-13 20:15:29 +00001166}
1167
1168
paul4dadc292005-05-06 21:37:42 +00001169static void
paul147193a2003-04-19 00:31:59 +00001170ospf_abr_announce_rtr (struct ospf *ospf,
1171 struct prefix_ipv4 *p, struct ospf_route *or)
paul718e3742002-12-13 20:15:29 +00001172{
hasso52dc7ee2004-09-23 19:18:23 +00001173 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001174 struct ospf_area *area;
1175
1176 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001177 zlog_debug ("ospf_abr_announce_rtr(): Start");
paul718e3742002-12-13 20:15:29 +00001178
paul1eb8ef22005-04-07 07:30:20 +00001179 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001180 {
paul718e3742002-12-13 20:15:29 +00001181 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001182 zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001183 inet_ntoa (area->area_id));
1184
1185 if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
1186 continue;
1187
1188 if (ospf_abr_nexthops_belong_to_area (or, area))
1189 continue;
1190
1191 if (area->external_routing != OSPF_AREA_DEFAULT)
1192 {
1193 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001194 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001195 "area %s doesn't support external routing",
1196 inet_ntoa(area->area_id));
1197 continue;
1198 }
1199
1200 if (or->path_type == OSPF_PATH_INTER_AREA)
1201 {
1202 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001203 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001204 "this is inter-area route to %s", inet_ntoa (p->prefix));
1205 if (!OSPF_IS_AREA_BACKBONE (area))
1206 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1207 }
1208
1209 if (or->path_type == OSPF_PATH_INTRA_AREA)
1210 {
1211 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001212 zlog_debug ("ospf_abr_announce_rtr(): "
paul718e3742002-12-13 20:15:29 +00001213 "this is intra-area route to %s", inet_ntoa (p->prefix));
1214 ospf_abr_announce_rtr_to_area (p, or->cost, area);
1215 }
1216 }
1217
1218 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001219 zlog_debug ("ospf_abr_announce_rtr(): Stop");
paul718e3742002-12-13 20:15:29 +00001220}
1221
paul4dadc292005-05-06 21:37:42 +00001222static void
paul147193a2003-04-19 00:31:59 +00001223ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt)
paul718e3742002-12-13 20:15:29 +00001224{
paul718e3742002-12-13 20:15:29 +00001225 struct ospf_route *or;
paul147193a2003-04-19 00:31:59 +00001226 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +00001227 struct list *l;
1228
1229 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001230 zlog_debug ("ospf_abr_process_router_rt(): Start");
paul718e3742002-12-13 20:15:29 +00001231
1232 for (rn = route_top (rt); rn; rn = route_next (rn))
1233 {
paul1eb8ef22005-04-07 07:30:20 +00001234 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001235 char flag = 0;
1236 struct ospf_route *best = NULL;
1237
1238 if (rn->info == NULL)
1239 continue;
1240
1241 l = rn->info;
1242
1243 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001244 zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
paul718e3742002-12-13 20:15:29 +00001245 inet_ntoa (rn->p.u.prefix4));
1246
paul1eb8ef22005-04-07 07:30:20 +00001247 for (ALL_LIST_ELEMENTS (l, node, nnode, or))
paul718e3742002-12-13 20:15:29 +00001248 {
paul147193a2003-04-19 00:31:59 +00001249 if (!ospf_area_lookup_by_area_id (ospf, or->u.std.area_id))
paul718e3742002-12-13 20:15:29 +00001250 {
1251 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001252 zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
paul718e3742002-12-13 20:15:29 +00001253 inet_ntoa (or->u.std.area_id));
1254 continue;
1255 }
1256
1257
1258 if (!CHECK_FLAG (or->u.std.flags, ROUTER_LSA_EXTERNAL))
1259 {
1260 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001261 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001262 "This is not an ASBR, skipping");
1263 continue;
1264 }
1265
1266 if (!flag)
1267 {
paul147193a2003-04-19 00:31:59 +00001268 best = ospf_find_asbr_route (ospf, rt,
1269 (struct prefix_ipv4 *) &rn->p);
paul718e3742002-12-13 20:15:29 +00001270 flag = 1;
1271 }
1272
1273 if (best == NULL)
1274 continue;
1275
1276 if (or != best)
1277 {
1278 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001279 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001280 "This route is not the best among possible, skipping");
1281 continue;
1282 }
1283
1284 if (or->path_type == OSPF_PATH_INTER_AREA &&
1285 !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
1286 {
1287 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001288 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001289 "This route is not a backbone one, skipping");
1290 continue;
1291 }
1292
1293 if (or->cost >= OSPF_LS_INFINITY)
1294 {
1295 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001296 zlog_debug ("ospf_abr_process_router_rt(): "
paul718e3742002-12-13 20:15:29 +00001297 "This route has LS_INFINITY metric, skipping");
1298 continue;
1299 }
1300
paul147193a2003-04-19 00:31:59 +00001301 if (ospf->abr_type == OSPF_ABR_CISCO
1302 || ospf->abr_type == OSPF_ABR_IBM)
1303 if (!ospf_act_bb_connection (ospf)
1304 && or->path_type != OSPF_PATH_INTRA_AREA)
paul718e3742002-12-13 20:15:29 +00001305 {
1306 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001307 zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
paul718e3742002-12-13 20:15:29 +00001308 "No BB connection, skip not intra-area routes");
1309 continue;
1310 }
1311
paul147193a2003-04-19 00:31:59 +00001312 ospf_abr_announce_rtr (ospf, (struct prefix_ipv4 *) &rn->p, or);
paul718e3742002-12-13 20:15:29 +00001313
1314 }
1315
1316 }
1317
1318 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001319 zlog_debug ("ospf_abr_process_router_rt(): Stop");
paul718e3742002-12-13 20:15:29 +00001320}
1321
paul4dadc292005-05-06 21:37:42 +00001322static void
paul147193a2003-04-19 00:31:59 +00001323ospf_abr_unapprove_translates (struct ospf *ospf) /* For NSSA Translations */
paul718e3742002-12-13 20:15:29 +00001324{
paul147193a2003-04-19 00:31:59 +00001325 struct ospf_lsa *lsa;
1326 struct route_node *rn;
1327
paul718e3742002-12-13 20:15:29 +00001328 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001329 zlog_debug ("ospf_abr_unapprove_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001330
1331 /* NSSA Translator is not checked, because it may have gone away,
1332 and we would want to flush any residuals anyway */
1333
paul147193a2003-04-19 00:31:59 +00001334 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1335 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
pauld4a53d52003-07-12 21:30:57 +00001336 {
1337 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1338 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001339 zlog_debug ("ospf_abr_unapprove_translates(): "
pauld4a53d52003-07-12 21:30:57 +00001340 "approved unset on link id %s",
1341 inet_ntoa (lsa->data->id));
1342 }
paul718e3742002-12-13 20:15:29 +00001343
1344 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001345 zlog_debug ("ospf_abr_unapprove_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001346}
paul718e3742002-12-13 20:15:29 +00001347
paul4dadc292005-05-06 21:37:42 +00001348static void
paul147193a2003-04-19 00:31:59 +00001349ospf_abr_unapprove_summaries (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001350{
hasso52dc7ee2004-09-23 19:18:23 +00001351 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001352 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001353 struct route_node *rn;
1354 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +00001355
1356 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001357 zlog_debug ("ospf_abr_unapprove_summaries(): Start");
paul718e3742002-12-13 20:15:29 +00001358
paul1eb8ef22005-04-07 07:30:20 +00001359 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001360 {
pauld4a53d52003-07-12 21:30:57 +00001361 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001362 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001363 "considering area %s",
1364 inet_ntoa (area->area_id));
paul147193a2003-04-19 00:31:59 +00001365 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001366 if (ospf_lsa_is_self_originated (ospf, lsa))
1367 {
1368 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001369 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001370 "approved unset on summary link id %s",
1371 inet_ntoa (lsa->data->id));
1372 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1373 }
paul147193a2003-04-19 00:31:59 +00001374
1375 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
pauld4a53d52003-07-12 21:30:57 +00001376 if (ospf_lsa_is_self_originated (ospf, lsa))
1377 {
1378 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001379 zlog_debug ("ospf_abr_unapprove_summaries(): "
pauld4a53d52003-07-12 21:30:57 +00001380 "approved unset on asbr-summary link id %s",
1381 inet_ntoa (lsa->data->id));
1382 UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
1383 }
paul718e3742002-12-13 20:15:29 +00001384 }
1385
1386 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001387 zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
paul718e3742002-12-13 20:15:29 +00001388}
1389
paul4dadc292005-05-06 21:37:42 +00001390static void
paul147193a2003-04-19 00:31:59 +00001391ospf_abr_prepare_aggregates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001392{
hasso52dc7ee2004-09-23 19:18:23 +00001393 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001394 struct route_node *rn;
1395 struct ospf_area_range *range;
paul1eb8ef22005-04-07 07:30:20 +00001396 struct ospf_area *area;
paul718e3742002-12-13 20:15:29 +00001397
1398 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001399 zlog_debug ("ospf_abr_prepare_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001400
paul1eb8ef22005-04-07 07:30:20 +00001401 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001402 {
paul718e3742002-12-13 20:15:29 +00001403 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1404 if ((range = rn->info) != NULL)
1405 {
1406 range->cost = 0;
1407 range->specifics = 0;
1408 }
1409 }
1410
1411 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001412 zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001413}
1414
paul4dadc292005-05-06 21:37:42 +00001415static void
paul147193a2003-04-19 00:31:59 +00001416ospf_abr_announce_aggregates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001417{
1418 struct ospf_area *area, *ar;
1419 struct ospf_area_range *range;
1420 struct route_node *rn;
pauld4a53d52003-07-12 21:30:57 +00001421 struct prefix p;
hasso52dc7ee2004-09-23 19:18:23 +00001422 struct listnode *node, *n;
paul718e3742002-12-13 20:15:29 +00001423
1424 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001425 zlog_debug ("ospf_abr_announce_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001426
paul1eb8ef22005-04-07 07:30:20 +00001427 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001428 {
paul718e3742002-12-13 20:15:29 +00001429 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001430 zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001431 inet_ntoa (area->area_id));
1432
1433 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1434 if ((range = rn->info))
1435 {
1436 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1437 {
1438 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001439 zlog_debug ("ospf_abr_announce_aggregates():"
paul718e3742002-12-13 20:15:29 +00001440 " discarding suppress-ranges");
1441 continue;
1442 }
1443
1444 p.family = AF_INET;
pauld4a53d52003-07-12 21:30:57 +00001445 p.u.prefix4 = range->addr;
paul718e3742002-12-13 20:15:29 +00001446 p.prefixlen = range->masklen;
1447
1448 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001449 zlog_debug ("ospf_abr_announce_aggregates():"
paul718e3742002-12-13 20:15:29 +00001450 " this is range: %s/%d",
pauld4a53d52003-07-12 21:30:57 +00001451 inet_ntoa (p.u.prefix4), p.prefixlen);
paul718e3742002-12-13 20:15:29 +00001452
1453 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1454 {
1455 p.family = AF_INET;
pauld4a53d52003-07-12 21:30:57 +00001456 p.u.prefix4 = range->subst_addr;
paul718e3742002-12-13 20:15:29 +00001457 p.prefixlen = range->subst_masklen;
1458 }
1459
1460 if (range->specifics)
1461 {
1462 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001463 zlog_debug ("ospf_abr_announce_aggregates(): active range");
paul718e3742002-12-13 20:15:29 +00001464
paul1eb8ef22005-04-07 07:30:20 +00001465 for (ALL_LIST_ELEMENTS_RO (ospf->areas, n, ar))
paul718e3742002-12-13 20:15:29 +00001466 {
paul718e3742002-12-13 20:15:29 +00001467 if (ar == area)
1468 continue;
1469
1470 /* We do not check nexthops here, because
1471 intra-area routes can be associated with
1472 one area only */
1473
1474 /* backbone routes are not summarized
1475 when announced into transit areas */
1476
1477 if (ospf_area_is_transit (ar) &&
1478 OSPF_IS_AREA_BACKBONE (area))
1479 {
1480 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001481 zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
paul718e3742002-12-13 20:15:29 +00001482 "announcement of BB aggregate into"
1483 " a transit area");
1484 continue;
1485 }
hassofa2b17e2004-03-04 17:45:00 +00001486 ospf_abr_announce_network_to_area ((struct prefix_ipv4 *)&p, range->cost, ar);
paul718e3742002-12-13 20:15:29 +00001487 }
1488 }
1489 }
1490 }
1491
1492 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001493 zlog_debug ("ospf_abr_announce_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001494}
1495
paul4dadc292005-05-06 21:37:42 +00001496static void
paul147193a2003-04-19 00:31:59 +00001497ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */
paul718e3742002-12-13 20:15:29 +00001498{
hasso52dc7ee2004-09-23 19:18:23 +00001499 struct listnode *node; /*, n; */
paul718e3742002-12-13 20:15:29 +00001500 struct ospf_area *area; /*, *ar; */
1501 struct route_node *rn;
1502 struct ospf_area_range *range;
1503 struct prefix_ipv4 p;
1504
1505 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001506 zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
paul718e3742002-12-13 20:15:29 +00001507
paul1eb8ef22005-04-07 07:30:20 +00001508 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001509 {
paule2c6c152003-06-22 08:49:25 +00001510 if (! area->NSSATranslatorState)
paul718e3742002-12-13 20:15:29 +00001511 continue;
1512
1513 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001514 zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
paul718e3742002-12-13 20:15:29 +00001515 inet_ntoa (area->area_id));
1516
1517 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1518 {
1519 if (rn->info == NULL)
1520 continue;
1521
1522 range = rn->info;
1523
1524 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1525 {
1526 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001527 zlog_debug ("ospf_abr_send_nssa_aggregates():"
paul718e3742002-12-13 20:15:29 +00001528 " discarding suppress-ranges");
1529 continue;
1530 }
1531
1532 p.family = AF_INET;
1533 p.prefix = range->addr;
1534 p.prefixlen = range->masklen;
1535
1536 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001537 zlog_debug ("ospf_abr_send_nssa_aggregates():"
paul718e3742002-12-13 20:15:29 +00001538 " this is range: %s/%d",
1539 inet_ntoa (p.prefix), p.prefixlen);
1540
1541 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
1542 {
1543 p.family = AF_INET;
1544 p.prefix = range->subst_addr;
1545 p.prefixlen = range->subst_masklen;
1546 }
1547
1548 if (range->specifics)
paule2c6c152003-06-22 08:49:25 +00001549 {
1550 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001551 zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
paul718e3742002-12-13 20:15:29 +00001552
paule2c6c152003-06-22 08:49:25 +00001553 /* Fetch LSA-Type-7 from aggregate prefix, and then
1554 * translate, Install (as Type-5), Approve, and Flood
1555 */
1556 ospf_abr_translate_nssa_range (&p, range->cost);
1557 }
1558 } /* all area ranges*/
paul718e3742002-12-13 20:15:29 +00001559 } /* all areas */
1560
1561 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001562 zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
paul718e3742002-12-13 20:15:29 +00001563}
1564
paul4dadc292005-05-06 21:37:42 +00001565static void
paul147193a2003-04-19 00:31:59 +00001566ospf_abr_announce_stub_defaults (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001567{
hasso52dc7ee2004-09-23 19:18:23 +00001568 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001569 struct ospf_area *area;
1570 struct prefix_ipv4 p;
1571
paul147193a2003-04-19 00:31:59 +00001572 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001573 return;
1574
1575 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001576 zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
paul718e3742002-12-13 20:15:29 +00001577
1578 p.family = AF_INET;
1579 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1580 p.prefixlen = 0;
1581
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_EVENT)
ajse84cc642004-12-08 17:28:56 +00001585 zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
1586 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001587
pauld4a53d52003-07-12 21:30:57 +00001588 if ( (area->external_routing != OSPF_AREA_STUB)
pauld4a53d52003-07-12 21:30:57 +00001589 && (area->external_routing != OSPF_AREA_NSSA)
pauld4a53d52003-07-12 21:30:57 +00001590 )
1591 continue;
paul718e3742002-12-13 20:15:29 +00001592
1593 if (OSPF_IS_AREA_BACKBONE (area))
pauld4a53d52003-07-12 21:30:57 +00001594 continue; /* Sanity Check */
1595
paul718e3742002-12-13 20:15:29 +00001596 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001597 zlog_debug ("ospf_abr_announce_stub_defaults(): "
1598 "announcing 0.0.0.0/0 to area %s",
pauld4a53d52003-07-12 21:30:57 +00001599 inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001600 ospf_abr_announce_network_to_area (&p, area->default_cost, area);
1601 }
1602
1603 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001604 zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
paul718e3742002-12-13 20:15:29 +00001605}
1606
paul4dadc292005-05-06 21:37:42 +00001607static int
paul147193a2003-04-19 00:31:59 +00001608ospf_abr_remove_unapproved_translates_apply (struct ospf *ospf,
1609 struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001610{
1611 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)
1612 && ! CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1613 {
1614 zlog_info ("ospf_abr_remove_unapproved_translates(): "
1615 "removing unapproved translates, ID: %s",
1616 inet_ntoa (lsa->data->id));
1617
1618 /* FLUSH THROUGHOUT AS */
paul147193a2003-04-19 00:31:59 +00001619 ospf_lsa_flush_as (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001620
1621 /* DISCARD from LSDB */
1622 }
1623 return 0;
1624}
1625
paul4dadc292005-05-06 21:37:42 +00001626static void
paul147193a2003-04-19 00:31:59 +00001627ospf_abr_remove_unapproved_translates (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001628{
paul147193a2003-04-19 00:31:59 +00001629 struct route_node *rn;
1630 struct ospf_lsa *lsa;
1631
paul718e3742002-12-13 20:15:29 +00001632 /* All AREA PROCESS should have APPROVED necessary LSAs */
1633 /* Remove any left over and not APPROVED */
1634 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001635 zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
paul718e3742002-12-13 20:15:29 +00001636
paul147193a2003-04-19 00:31:59 +00001637 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
1638 ospf_abr_remove_unapproved_translates_apply (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001639
1640 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001641 zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
paul718e3742002-12-13 20:15:29 +00001642}
paul718e3742002-12-13 20:15:29 +00001643
paul4dadc292005-05-06 21:37:42 +00001644static void
paul147193a2003-04-19 00:31:59 +00001645ospf_abr_remove_unapproved_summaries (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001646{
hasso52dc7ee2004-09-23 19:18:23 +00001647 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001648 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001649 struct route_node *rn;
1650 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +00001651
1652 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001653 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
paul718e3742002-12-13 20:15:29 +00001654
paul1eb8ef22005-04-07 07:30:20 +00001655 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +00001656 {
paul718e3742002-12-13 20:15:29 +00001657 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001658 zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
paul718e3742002-12-13 20:15:29 +00001659 "looking at area %s", inet_ntoa (area->area_id));
1660
paul147193a2003-04-19 00:31:59 +00001661 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
1662 if (ospf_lsa_is_self_originated (ospf, lsa))
1663 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1664 ospf_lsa_flush_area (lsa, area);
1665
1666 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
1667 if (ospf_lsa_is_self_originated (ospf, lsa))
1668 if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
1669 ospf_lsa_flush_area (lsa, area);
paul718e3742002-12-13 20:15:29 +00001670 }
1671
1672 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001673 zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
paul718e3742002-12-13 20:15:29 +00001674}
1675
paul4dadc292005-05-06 21:37:42 +00001676static void
paul147193a2003-04-19 00:31:59 +00001677ospf_abr_manage_discard_routes (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001678{
paul1eb8ef22005-04-07 07:30:20 +00001679 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001680 struct route_node *rn;
1681 struct ospf_area *area;
1682 struct ospf_area_range *range;
1683
paul1eb8ef22005-04-07 07:30:20 +00001684 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
1685 for (rn = route_top (area->ranges); rn; rn = route_next (rn))
1686 if ((range = rn->info) != NULL)
1687 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
1688 {
1689 if (range->specifics)
1690 ospf_add_discard_route (ospf->new_table, area,
1691 (struct prefix_ipv4 *) &rn->p);
1692 else
JR Rivers8fc9e002012-09-24 17:26:46 +00001693 ospf_delete_discard_route (ospf->new_table,
1694 (struct prefix_ipv4 *) &rn->p);
paul1eb8ef22005-04-07 07:30:20 +00001695 }
paul718e3742002-12-13 20:15:29 +00001696}
1697
paul718e3742002-12-13 20:15:29 +00001698/* This is the function taking care about ABR NSSA, i.e. NSSA
1699 Translator, -LSA aggregation and flooding. For all NSSAs
1700
1701 Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
1702 are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
1703 with the P-bit set.
1704
1705 Any received Type-5s are legal for an ABR, else illegal for IR.
1706 Received Type-7s are installed, by area, with incoming P-bit. They
1707 are flooded; if the Elected NSSA Translator, then P-bit off.
1708
1709 Additionally, this ABR will place "translated type-7's" into the
1710 Type-5 LSDB in order to keep track of APPROVAL or not.
1711
1712 It will scan through every area, looking for Type-7 LSAs with P-Bit
1713 SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
1714 AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
1715 5-INSTALLED.
1716
1717 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
1718 left over are FLUSHED and DISCARDED.
1719
1720 For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
1721 any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
1722
paul4dadc292005-05-06 21:37:42 +00001723static void
paul147193a2003-04-19 00:31:59 +00001724ospf_abr_nssa_task (struct ospf *ospf) /* called only if any_nssa */
paul718e3742002-12-13 20:15:29 +00001725{
1726 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001727 zlog_debug ("Check for NSSA-ABR Tasks():");
paul718e3742002-12-13 20:15:29 +00001728
paul147193a2003-04-19 00:31:59 +00001729 if (! IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001730 return;
1731
paul147193a2003-04-19 00:31:59 +00001732 if (! ospf->anyNSSA)
paul718e3742002-12-13 20:15:29 +00001733 return;
1734
1735 /* Each area must confirm TranslatorRole */
1736 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001737 zlog_debug ("ospf_abr_nssa_task(): Start");
paul718e3742002-12-13 20:15:29 +00001738
1739 /* For all Global Entries flagged "local-translate", unset APPROVED */
1740 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001741 zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
paul718e3742002-12-13 20:15:29 +00001742
paul147193a2003-04-19 00:31:59 +00001743 ospf_abr_unapprove_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001744
1745 /* RESET all Ranges in every Area, same as summaries */
1746 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001747 zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
paule2c6c152003-06-22 08:49:25 +00001748 ospf_abr_prepare_aggregates (ospf); /*TURNED OFF just for now */
paul718e3742002-12-13 20:15:29 +00001749
1750 /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
paule2c6c152003-06-22 08:49:25 +00001751 * Aggregate as Type-7
1752 * Install or Approve in Type-5 Global LSDB
1753 */
paul718e3742002-12-13 20:15:29 +00001754 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001755 zlog_debug ("ospf_abr_nssa_task(): process translates");
paul147193a2003-04-19 00:31:59 +00001756 ospf_abr_process_nssa_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001757
1758 /* Translate/Send any "ranged" aggregates, and also 5-Install and
paule2c6c152003-06-22 08:49:25 +00001759 * Approve
1760 * Scan Type-7's for aggregates, translate to Type-5's,
1761 * Install/Flood/Approve
1762 */
paul718e3742002-12-13 20:15:29 +00001763 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001764 zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
paule2c6c152003-06-22 08:49:25 +00001765 ospf_abr_send_nssa_aggregates (ospf); /*TURNED OFF FOR NOW */
paul718e3742002-12-13 20:15:29 +00001766
pauld4a53d52003-07-12 21:30:57 +00001767 /* Send any NSSA defaults as Type-5
1768 *if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001769 * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
pauld4a53d52003-07-12 21:30:57 +00001770 *ospf_abr_announce_nssa_defaults (ospf);
1771 * havnt a clue what above is supposed to do.
1772 */
paul718e3742002-12-13 20:15:29 +00001773
1774 /* Flush any unapproved previous translates from Global Data Base */
1775 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001776 zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
paul147193a2003-04-19 00:31:59 +00001777 ospf_abr_remove_unapproved_translates (ospf);
paul718e3742002-12-13 20:15:29 +00001778
paul147193a2003-04-19 00:31:59 +00001779 ospf_abr_manage_discard_routes (ospf); /* same as normal...discard */
paul718e3742002-12-13 20:15:29 +00001780
1781 if (IS_DEBUG_OSPF_NSSA)
ajse84cc642004-12-08 17:28:56 +00001782 zlog_debug ("ospf_abr_nssa_task(): Stop");
paul718e3742002-12-13 20:15:29 +00001783}
paul718e3742002-12-13 20:15:29 +00001784
1785/* This is the function taking care about ABR stuff, i.e.
1786 summary-LSA origination and flooding. */
1787void
paul147193a2003-04-19 00:31:59 +00001788ospf_abr_task (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001789{
1790 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001791 zlog_debug ("ospf_abr_task(): Start");
paul718e3742002-12-13 20:15:29 +00001792
paul147193a2003-04-19 00:31:59 +00001793 if (ospf->new_table == NULL || ospf->new_rtrs == NULL)
paul718e3742002-12-13 20:15:29 +00001794 {
1795 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001796 zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
paul718e3742002-12-13 20:15:29 +00001797 return;
1798 }
1799
1800 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001801 zlog_debug ("ospf_abr_task(): unapprove summaries");
paul147193a2003-04-19 00:31:59 +00001802 ospf_abr_unapprove_summaries (ospf);
paul718e3742002-12-13 20:15:29 +00001803
1804 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001805 zlog_debug ("ospf_abr_task(): prepare aggregates");
paul147193a2003-04-19 00:31:59 +00001806 ospf_abr_prepare_aggregates (ospf);
paul718e3742002-12-13 20:15:29 +00001807
paul147193a2003-04-19 00:31:59 +00001808 if (IS_OSPF_ABR (ospf))
paul718e3742002-12-13 20:15:29 +00001809 {
1810 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001811 zlog_debug ("ospf_abr_task(): process network RT");
paul147193a2003-04-19 00:31:59 +00001812 ospf_abr_process_network_rt (ospf, ospf->new_table);
paul718e3742002-12-13 20:15:29 +00001813
1814 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001815 zlog_debug ("ospf_abr_task(): process router RT");
paul147193a2003-04-19 00:31:59 +00001816 ospf_abr_process_router_rt (ospf, ospf->new_rtrs);
paul718e3742002-12-13 20:15:29 +00001817
1818 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001819 zlog_debug ("ospf_abr_task(): announce aggregates");
paul147193a2003-04-19 00:31:59 +00001820 ospf_abr_announce_aggregates (ospf);
paul718e3742002-12-13 20:15:29 +00001821
1822 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001823 zlog_debug ("ospf_abr_task(): announce stub defaults");
paul147193a2003-04-19 00:31:59 +00001824 ospf_abr_announce_stub_defaults (ospf);
paul718e3742002-12-13 20:15:29 +00001825 }
1826
1827 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001828 zlog_debug ("ospf_abr_task(): remove unapproved summaries");
paul147193a2003-04-19 00:31:59 +00001829 ospf_abr_remove_unapproved_summaries (ospf);
paul718e3742002-12-13 20:15:29 +00001830
paul147193a2003-04-19 00:31:59 +00001831 ospf_abr_manage_discard_routes (ospf);
paul718e3742002-12-13 20:15:29 +00001832
paul718e3742002-12-13 20:15:29 +00001833 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001834 zlog_debug ("ospf_abr_task(): Stop");
paul718e3742002-12-13 20:15:29 +00001835}
1836
paul4dadc292005-05-06 21:37:42 +00001837static int
paul147193a2003-04-19 00:31:59 +00001838ospf_abr_task_timer (struct thread *thread)
paul718e3742002-12-13 20:15:29 +00001839{
paul147193a2003-04-19 00:31:59 +00001840 struct ospf *ospf = THREAD_ARG (thread);
1841
1842 ospf->t_abr_task = 0;
paul718e3742002-12-13 20:15:29 +00001843
1844 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001845 zlog_debug ("Running ABR task on timer");
paul718e3742002-12-13 20:15:29 +00001846
paul147193a2003-04-19 00:31:59 +00001847 ospf_check_abr_status (ospf);
pauld4a53d52003-07-12 21:30:57 +00001848 ospf_abr_nssa_check_status (ospf);
paul718e3742002-12-13 20:15:29 +00001849
paul147193a2003-04-19 00:31:59 +00001850 ospf_abr_task (ospf);
paule2c6c152003-06-22 08:49:25 +00001851 ospf_abr_nssa_task (ospf); /* if nssa-abr, then scan Type-7 LSDB */
paul718e3742002-12-13 20:15:29 +00001852
paul147193a2003-04-19 00:31:59 +00001853 return 0;
paul718e3742002-12-13 20:15:29 +00001854}
1855
1856void
paul147193a2003-04-19 00:31:59 +00001857ospf_schedule_abr_task (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001858{
1859 if (IS_DEBUG_OSPF_EVENT)
ajse84cc642004-12-08 17:28:56 +00001860 zlog_debug ("Scheduling ABR task");
paul147193a2003-04-19 00:31:59 +00001861
1862 if (ospf->t_abr_task == NULL)
1863 ospf->t_abr_task = thread_add_timer (master, ospf_abr_task_timer,
1864 ospf, OSPF_ABR_TASK_DELAY);
paul718e3742002-12-13 20:15:29 +00001865}