]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
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" | |
718e3744 | 53 | \f |
4dadc291 | 54 | static struct ospf_area_range * |
718e3744 | 55 | ospf_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 | ||
4dadc291 | 67 | static void |
718e3744 | 68 | ospf_area_range_free (struct ospf_area_range *range) |
69 | { | |
70 | XFREE (MTYPE_OSPF_AREA_RANGE, range); | |
71 | } | |
72 | ||
4dadc291 | 73 | static void |
718e3744 | 74 | ospf_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 | ||
4dadc291 | 90 | static void |
718e3744 | 91 | ospf_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 | ||
110 | struct ospf_area_range * | |
111 | ospf_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 | ||
124 | struct ospf_area_range * | |
d4a53d58 | 125 | ospf_area_range_lookup_next (struct ospf_area *area, |
126 | struct in_addr *range_net, | |
127 | int first) | |
718e3744 | 128 | { |
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 | ||
4dadc291 | 159 | static struct ospf_area_range * |
718e3744 | 160 | ospf_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 | ||
173 | struct ospf_area_range * | |
174 | ospf_area_range_match_any (struct ospf *ospf, struct prefix_ipv4 *p) | |
175 | { | |
176 | struct ospf_area_range *range; | |
1eb8ef25 | 177 | struct ospf_area *area; |
52dc7ee6 | 178 | struct listnode *node; |
718e3744 | 179 | |
1eb8ef25 | 180 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
181 | if ((range = ospf_area_range_match (area, p))) | |
718e3744 | 182 | return range; |
183 | ||
184 | return NULL; | |
185 | } | |
186 | ||
187 | int | |
188 | ospf_area_range_active (struct ospf_area_range *range) | |
189 | { | |
190 | return range->specifics; | |
191 | } | |
192 | ||
4dadc291 | 193 | static int |
718e3744 | 194 | ospf_area_actively_attached (struct ospf_area *area) |
195 | { | |
196 | return area->act_ints; | |
197 | } | |
198 | ||
199 | int | |
200 | ospf_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; | |
147193a2 | 205 | int ret = OSPF_AREA_ID_FORMAT_ADDRESS; |
718e3744 | 206 | |
147193a2 | 207 | area = ospf_area_get (ospf, area_id, ret); |
718e3744 | 208 | 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))) | |
147193a2 | 218 | ospf_schedule_abr_task (ospf); |
718e3744 | 219 | } |
220 | else | |
221 | { | |
222 | range = ospf_area_range_new (p); | |
223 | ospf_area_range_add (area, range); | |
147193a2 | 224 | ospf_schedule_abr_task (ospf); |
718e3744 | 225 | } |
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 | ||
235 | int | |
236 | ospf_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; | |
147193a2 | 241 | int ret = OSPF_AREA_ID_FORMAT_ADDRESS; |
718e3744 | 242 | |
147193a2 | 243 | area = ospf_area_get (ospf, area_id, ret); |
718e3744 | 244 | if (area == NULL) |
245 | return 0; | |
246 | ||
247 | range = ospf_area_range_new (p); | |
248 | 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)) | |
147193a2 | 255 | ospf_schedule_abr_task (ospf); |
718e3744 | 256 | } |
257 | ||
258 | return 1; | |
259 | } | |
260 | ||
261 | int | |
262 | ospf_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 | ||
147193a2 | 268 | area = ospf_area_lookup_by_area_id (ospf, area_id); |
718e3744 | 269 | 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)) | |
147193a2 | 277 | ospf_schedule_abr_task (ospf); |
718e3744 | 278 | |
279 | ospf_area_range_delete (area, range); | |
280 | ||
281 | return 1; | |
282 | } | |
283 | ||
284 | int | |
285 | ospf_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; | |
147193a2 | 290 | int ret = OSPF_AREA_ID_FORMAT_ADDRESS; |
718e3744 | 291 | |
147193a2 | 292 | area = ospf_area_get (ospf, area_id, ret); |
718e3744 | 293 | 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)) | |
147193a2 | 299 | ospf_schedule_abr_task (ospf); |
718e3744 | 300 | } |
301 | else | |
302 | { | |
303 | range = ospf_area_range_new (p); | |
304 | ospf_area_range_add (area, range); | |
147193a2 | 305 | ospf_schedule_abr_task (ospf); |
718e3744 | 306 | } |
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 | ||
316 | int | |
317 | ospf_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 | ||
147193a2 | 323 | area = ospf_area_lookup_by_area_id (ospf, area_id); |
718e3744 | 324 | 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)) | |
147193a2 | 333 | ospf_schedule_abr_task (ospf); |
718e3744 | 334 | |
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 | ||
342 | int | |
147193a2 | 343 | ospf_act_bb_connection (struct ospf *ospf) |
718e3744 | 344 | { |
147193a2 | 345 | if (ospf->backbone == NULL) |
718e3744 | 346 | return 0; |
347 | ||
147193a2 | 348 | return ospf->backbone->full_nbrs; |
718e3744 | 349 | } |
350 | ||
e2c6c153 | 351 | /* Determine whether this router is elected translator or not for area */ |
4dadc291 | 352 | static int |
e2c6c153 | 353 | ospf_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) | |
e84cc647 | 378 | zlog_debug ("ospf_abr_nssa_am_elected: " |
e2c6c153 | 379 | "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) | |
e84cc647 | 392 | zlog_debug ("ospf_abr_nssa_am_elected: best electable ABR is: %s", |
e2c6c153 | 393 | (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 | */ | |
4dadc291 | 407 | static void |
e2c6c153 | 408 | ospf_abr_nssa_check_status (struct ospf *ospf) |
409 | { | |
410 | struct ospf_area *area; | |
1eb8ef25 | 411 | struct listnode *lnode, *nnode; |
e2c6c153 | 412 | |
1eb8ef25 | 413 | for (ALL_LIST_ELEMENTS (ospf->areas, lnode, nnode, area)) |
e2c6c153 | 414 | { |
415 | ||
416 | if (area->external_routing != OSPF_AREA_NSSA) | |
417 | continue; | |
418 | ||
419 | if (IS_DEBUG_OSPF (nssa, NSSA)) | |
e84cc647 | 420 | zlog_debug ("ospf_abr_nssa_check_status: " |
e2c6c153 | 421 | "checking area %s", |
422 | inet_ntoa (area->area_id)); | |
423 | ||
424 | if (!IS_OSPF_ABR (area->ospf)) | |
425 | { | |
426 | if (IS_DEBUG_OSPF (nssa, NSSA)) | |
e84cc647 | 427 | zlog_debug ("ospf_abr_nssa_check_status: " |
428 | "not ABR"); | |
d4a53d58 | 429 | area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED; |
e2c6c153 | 430 | continue; |
431 | } | |
432 | ||
433 | switch (area->NSSATranslatorRole) | |
434 | { | |
435 | case OSPF_NSSA_ROLE_NEVER: | |
436 | /* We never Translate Type-7 LSA. */ | |
437 | /* TODO: check previous state and flush? */ | |
438 | if (IS_DEBUG_OSPF (nssa, NSSA)) | |
e84cc647 | 439 | zlog_debug ("ospf_abr_nssa_check_status: " |
440 | "never translate"); | |
d4a53d58 | 441 | area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED; |
e2c6c153 | 442 | continue; |
443 | ||
444 | case OSPF_NSSA_ROLE_ALWAYS: | |
445 | /* We always translate if we are an ABR | |
446 | * TODO: originate new LSAs if state change? | |
447 | * or let the nssa abr task take care of it? | |
448 | */ | |
449 | if (IS_DEBUG_OSPF (nssa, NSSA)) | |
e84cc647 | 450 | zlog_debug ("ospf_abr_nssa_check_status: " |
451 | "translate always"); | |
d4a53d58 | 452 | area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED; |
e2c6c153 | 453 | continue; |
454 | ||
455 | case OSPF_NSSA_ROLE_CANDIDATE: | |
456 | /* We are a candidate for Translation */ | |
457 | if (ospf_abr_nssa_am_elected (area) > 0 ) | |
458 | { | |
d4a53d58 | 459 | area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED; |
e2c6c153 | 460 | if (IS_DEBUG_OSPF (nssa, NSSA)) |
e84cc647 | 461 | zlog_debug ("ospf_abr_nssa_check_status: " |
462 | "elected translator"); | |
e2c6c153 | 463 | } |
464 | else | |
465 | { | |
d4a53d58 | 466 | area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED; |
e2c6c153 | 467 | if (IS_DEBUG_OSPF (nssa, NSSA)) |
e84cc647 | 468 | zlog_debug ("ospf_abr_nssa_check_status: " |
469 | "not elected"); | |
e2c6c153 | 470 | } |
471 | continue; | |
472 | } | |
473 | } | |
474 | } | |
e2c6c153 | 475 | |
718e3744 | 476 | /* Check area border router status. */ |
477 | void | |
147193a2 | 478 | ospf_check_abr_status (struct ospf *ospf) |
718e3744 | 479 | { |
480 | struct ospf_area *area; | |
1eb8ef25 | 481 | struct listnode *node, *nnode; |
718e3744 | 482 | int bb_configured = 0; |
483 | int bb_act_attached = 0; | |
484 | int areas_configured = 0; | |
485 | int areas_act_attached = 0; | |
147193a2 | 486 | u_char new_flags = ospf->flags; |
718e3744 | 487 | |
488 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 489 | zlog_debug ("ospf_check_abr_status(): Start"); |
718e3744 | 490 | |
1eb8ef25 | 491 | for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area)) |
718e3744 | 492 | { |
718e3744 | 493 | if (listcount (area->oiflist)) |
494 | { | |
495 | areas_configured++; | |
496 | ||
497 | if (OSPF_IS_AREA_BACKBONE (area)) | |
498 | bb_configured = 1; | |
499 | } | |
500 | ||
501 | if (ospf_area_actively_attached (area)) | |
502 | { | |
503 | areas_act_attached++; | |
504 | ||
505 | if (OSPF_IS_AREA_BACKBONE (area)) | |
506 | bb_act_attached = 1; | |
507 | } | |
508 | } | |
509 | ||
510 | if (IS_DEBUG_OSPF_EVENT) | |
511 | { | |
e84cc647 | 512 | zlog_debug ("ospf_check_abr_status(): looked through areas"); |
513 | zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured); | |
514 | zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d", | |
718e3744 | 515 | bb_act_attached); |
e84cc647 | 516 | zlog_debug ("ospf_check_abr_status(): areas_configured: %d", |
718e3744 | 517 | areas_configured); |
e84cc647 | 518 | zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d", |
718e3744 | 519 | areas_act_attached); |
520 | } | |
521 | ||
147193a2 | 522 | switch (ospf->abr_type) |
718e3744 | 523 | { |
524 | case OSPF_ABR_SHORTCUT: | |
525 | case OSPF_ABR_STAND: | |
526 | if (areas_act_attached > 1) | |
527 | SET_FLAG (new_flags, OSPF_FLAG_ABR); | |
528 | else | |
529 | UNSET_FLAG (new_flags, OSPF_FLAG_ABR); | |
530 | break; | |
531 | ||
532 | case OSPF_ABR_IBM: | |
533 | if ((areas_act_attached > 1) && bb_configured) | |
534 | SET_FLAG (new_flags, OSPF_FLAG_ABR); | |
535 | else | |
536 | UNSET_FLAG (new_flags, OSPF_FLAG_ABR); | |
537 | break; | |
538 | ||
539 | case OSPF_ABR_CISCO: | |
540 | if ((areas_configured > 1) && bb_act_attached) | |
541 | SET_FLAG (new_flags, OSPF_FLAG_ABR); | |
542 | else | |
543 | UNSET_FLAG (new_flags, OSPF_FLAG_ABR); | |
544 | break; | |
545 | default: | |
546 | break; | |
547 | } | |
548 | ||
147193a2 | 549 | if (new_flags != ospf->flags) |
718e3744 | 550 | { |
147193a2 | 551 | ospf_spf_calculate_schedule (ospf); |
718e3744 | 552 | if (IS_DEBUG_OSPF_EVENT) |
e84cc647 | 553 | zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags); |
147193a2 | 554 | ospf->flags = new_flags; |
555 | OSPF_TIMER_ON (ospf->t_router_lsa_update, | |
718e3744 | 556 | ospf_router_lsa_update_timer, OSPF_LSA_UPDATE_DELAY); |
557 | } | |
558 | } | |
559 | ||
4dadc291 | 560 | static void |
718e3744 | 561 | ospf_abr_update_aggregate (struct ospf_area_range *range, |
7f352b86 | 562 | struct ospf_route *or) |
718e3744 | 563 | { |
564 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 565 | zlog_debug ("ospf_abr_update_aggregate(): Start"); |
718e3744 | 566 | |
6c835671 | 567 | if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC) |
718e3744 | 568 | { |
569 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 570 | zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d", |
7f352b86 | 571 | range->cost_config); |
718e3744 | 572 | |
573 | range->cost = range->cost_config; | |
574 | } | |
575 | else | |
576 | { | |
577 | if (range->specifics == 0) | |
7f352b86 | 578 | range->cost = or->cost; /* 1st time get 1st cost */ |
718e3744 | 579 | |
7f352b86 | 580 | if (or->cost > range->cost) |
581 | { | |
582 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 583 | zlog_debug ("ospf_abr_update_aggregate(): lowest cost, update"); |
718e3744 | 584 | |
7f352b86 | 585 | range->cost = or->cost; |
586 | } | |
718e3744 | 587 | } |
588 | ||
589 | range->specifics++; | |
590 | } | |
591 | ||
592 | static void | |
593 | set_metric (struct ospf_lsa *lsa, u_int32_t metric) | |
594 | { | |
595 | struct summary_lsa *header; | |
596 | u_char *mp; | |
597 | metric = htonl (metric); | |
c9e52be3 | 598 | mp = (u_char *) &metric; |
718e3744 | 599 | mp++; |
600 | header = (struct summary_lsa *) lsa->data; | |
601 | memcpy(header->metric, mp, 3); | |
602 | } | |
603 | ||
4dadc291 | 604 | static int |
718e3744 | 605 | ospf_abr_check_nssa_range (struct prefix_ipv4 *p, u_int32_t cost, |
606 | struct ospf_area *area) | |
607 | { | |
608 | /* The Type-7 is tested against the aggregated prefix and forwarded | |
609 | for lsa installation and flooding */ | |
610 | return 0; | |
611 | } | |
612 | ||
613 | /* ospf_abr_translate_nssa */ | |
4dadc291 | 614 | static int |
147193a2 | 615 | ospf_abr_translate_nssa (struct ospf_area *area, struct ospf_lsa *lsa) |
718e3744 | 616 | { |
617 | /* Incoming Type-7 or later aggregated Type-7 | |
d4a53d58 | 618 | * |
619 | * LSA is skipped if P-bit is off. | |
620 | * LSA is aggregated if within range. | |
621 | * | |
622 | * The Type-7 is translated, Installed/Approved as a Type-5 into | |
623 | * global LSDB, then Flooded through AS | |
624 | * | |
625 | * Later, any Unapproved Translated Type-5's are flushed/discarded | |
626 | */ | |
718e3744 | 627 | |
d4a53d58 | 628 | struct ospf_lsa *old = NULL, |
629 | *new = NULL; | |
630 | struct as_external_lsa *ext7; | |
631 | struct prefix_ipv4 p; | |
718e3744 | 632 | |
633 | if (! CHECK_FLAG (lsa->data->options, OSPF_OPTION_NP)) | |
634 | { | |
635 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 636 | zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation", |
d4a53d58 | 637 | inet_ntoa (lsa->data->id)); |
638 | return 1; | |
718e3744 | 639 | } |
d4a53d58 | 640 | |
718e3744 | 641 | if (IS_DEBUG_OSPF_NSSA) |
e84cc647 | 642 | zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5", |
d4a53d58 | 643 | inet_ntoa (lsa->data->id)); |
718e3744 | 644 | |
d4a53d58 | 645 | ext7 = (struct as_external_lsa *)(lsa->data); |
646 | p.prefix = lsa->data->id; | |
647 | p.prefixlen = ip_masklen (ext7->mask); | |
648 | ||
649 | if (ext7->e[0].fwd_addr.s_addr == OSPF_DEFAULT_DESTINATION) | |
650 | { | |
651 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 652 | zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, " |
d4a53d58 | 653 | "Forward address is 0, NO Translation", |
654 | inet_ntoa (lsa->data->id)); | |
655 | return 1; | |
656 | } | |
657 | ||
658 | /* try find existing AS-External LSA for this prefix */ | |
659 | ||
660 | old = ospf_external_info_find_lsa (area->ospf, &p); | |
661 | ||
662 | if (old) | |
663 | { | |
664 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 665 | zlog_debug ("ospf_abr_translate_nssa(): " |
d4a53d58 | 666 | "found old translated LSA Id %s, refreshing", |
667 | inet_ntoa (old->data->id)); | |
668 | ||
669 | /* refresh */ | |
670 | new = ospf_translated_nssa_refresh (area->ospf, lsa, old); | |
671 | if (!new) | |
672 | { | |
673 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 674 | zlog_debug ("ospf_abr_translate_nssa(): " |
d4a53d58 | 675 | "could not refresh translated LSA Id %s", |
676 | inet_ntoa (old->data->id)); | |
677 | } | |
678 | } | |
679 | else | |
680 | { | |
681 | /* no existing external route for this LSA Id | |
682 | * originate translated LSA | |
683 | */ | |
684 | ||
685 | if ((new = ospf_translated_nssa_originate (area->ospf, lsa)) | |
686 | == NULL) | |
687 | { | |
688 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 689 | zlog_debug ("ospf_abr_translate_nssa(): Could not translate " |
d4a53d58 | 690 | "Type-7 for %s to Type-5", |
691 | inet_ntoa (lsa->data->id)); | |
692 | return 1; | |
693 | } | |
694 | } | |
718e3744 | 695 | |
696 | /* Area where Aggregate testing will be inserted, just like summary | |
697 | advertisements */ | |
698 | /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */ | |
699 | ||
718e3744 | 700 | return 0; |
701 | } | |
702 | ||
4dadc291 | 703 | static void |
718e3744 | 704 | ospf_abr_translate_nssa_range (struct prefix_ipv4 *p, u_int32_t cost) |
705 | { | |
706 | /* The Type-7 is created from the aggregated prefix and forwarded | |
707 | for lsa installation and flooding... to be added... */ | |
708 | } | |
718e3744 | 709 | |
4dadc291 | 710 | static void |
718e3744 | 711 | ospf_abr_announce_network_to_area (struct prefix_ipv4 *p, u_int32_t cost, |
712 | struct ospf_area *area) | |
713 | { | |
714 | struct ospf_lsa *lsa, *old = NULL; | |
715 | struct summary_lsa *sl = NULL; | |
716 | ||
717 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 718 | zlog_debug ("ospf_abr_announce_network_to_area(): Start"); |
718e3744 | 719 | |
d4a53d58 | 720 | old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_SUMMARY_LSA, |
721 | (struct prefix_ipv4 *) p, | |
722 | area->ospf->router_id); | |
718e3744 | 723 | if (old) |
724 | { | |
725 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 726 | zlog_debug ("ospf_abr_announce_network_to_area(): old summary found"); |
718e3744 | 727 | |
d4a53d58 | 728 | sl = (struct summary_lsa *) old->data; |
718e3744 | 729 | |
718e3744 | 730 | if (IS_DEBUG_OSPF_EVENT) |
e84cc647 | 731 | zlog_debug ("ospf_abr_announce_network_to_area(): " |
d4a53d58 | 732 | "old metric: %d, new metric: %d", |
733 | GET_METRIC (sl->metric), cost); | |
734 | ||
735 | if (GET_METRIC (sl->metric) == cost) | |
736 | { | |
737 | /* unchanged. simply reapprove it */ | |
738 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 739 | zlog_debug ("ospf_abr_announce_network_to_area(): " |
d4a53d58 | 740 | "old summary approved"); |
741 | SET_FLAG (old->flags, OSPF_LSA_APPROVED); | |
742 | } | |
743 | else | |
744 | { | |
745 | /* LSA is changed, refresh it */ | |
746 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 747 | zlog_debug ("ospf_abr_announce_network_to_area(): " |
d4a53d58 | 748 | "refreshing summary"); |
749 | set_metric (old, cost); | |
750 | lsa = ospf_summary_lsa_refresh (area->ospf, old); | |
9e67dc27 | 751 | SET_FLAG (old->flags, OSPF_LSA_APPROVED); |
d4a53d58 | 752 | /* This will flood through area. */ |
753 | } | |
718e3744 | 754 | } |
755 | else | |
756 | { | |
757 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 758 | zlog_debug ("ospf_abr_announce_network_to_area(): " |
d4a53d58 | 759 | "creating new summary"); |
760 | lsa = ospf_summary_lsa_originate ( (struct prefix_ipv4 *)p, cost, area); | |
761 | /* This will flood through area. */ | |
718e3744 | 762 | |
718e3744 | 763 | SET_FLAG (lsa->flags, OSPF_LSA_APPROVED); |
764 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 765 | zlog_debug ("ospf_abr_announce_network_to_area(): " |
d4a53d58 | 766 | "flooding new version of summary"); |
718e3744 | 767 | } |
768 | ||
769 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 770 | zlog_debug ("ospf_abr_announce_network_to_area(): Stop"); |
718e3744 | 771 | } |
772 | ||
4dadc291 | 773 | static int |
718e3744 | 774 | ospf_abr_nexthops_belong_to_area (struct ospf_route *or, |
775 | struct ospf_area *area) | |
776 | { | |
1eb8ef25 | 777 | struct listnode *node, *nnode; |
96735eea | 778 | struct ospf_path *path; |
718e3744 | 779 | |
1eb8ef25 | 780 | for (ALL_LIST_ELEMENTS (or->paths, node, nnode, path)) |
718e3744 | 781 | { |
718e3744 | 782 | struct ospf_interface *oi = path->oi; |
783 | ||
784 | if (oi != NULL) | |
96735eea | 785 | if (oi->area == area) |
786 | return 1; | |
718e3744 | 787 | } |
788 | ||
789 | return 0; | |
790 | } | |
791 | ||
4dadc291 | 792 | static int |
d4a53d58 | 793 | ospf_abr_should_accept (struct prefix_ipv4 *p, struct ospf_area *area) |
718e3744 | 794 | { |
795 | if (IMPORT_NAME (area)) | |
796 | { | |
797 | if (IMPORT_LIST (area) == NULL) | |
798 | IMPORT_LIST (area) = access_list_lookup (AFI_IP, IMPORT_NAME (area)); | |
799 | ||
800 | if (IMPORT_LIST (area)) | |
801 | if (access_list_apply (IMPORT_LIST (area), p) == FILTER_DENY) | |
802 | return 0; | |
803 | } | |
804 | ||
805 | return 1; | |
806 | } | |
807 | ||
4dadc291 | 808 | static int |
718e3744 | 809 | ospf_abr_plist_in_check (struct ospf_area *area, struct ospf_route *or, |
d4a53d58 | 810 | struct prefix_ipv4 *p) |
718e3744 | 811 | { |
812 | if (PREFIX_NAME_IN (area)) | |
813 | { | |
814 | if (PREFIX_LIST_IN (area) == NULL) | |
815 | PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP, | |
816 | PREFIX_NAME_IN (area)); | |
817 | if (PREFIX_LIST_IN (area)) | |
818 | if (prefix_list_apply (PREFIX_LIST_IN (area), p) != PREFIX_PERMIT) | |
819 | return 0; | |
820 | } | |
821 | return 1; | |
822 | } | |
823 | ||
4dadc291 | 824 | static int |
718e3744 | 825 | ospf_abr_plist_out_check (struct ospf_area *area, struct ospf_route *or, |
d4a53d58 | 826 | struct prefix_ipv4 *p) |
718e3744 | 827 | { |
828 | if (PREFIX_NAME_OUT (area)) | |
829 | { | |
830 | if (PREFIX_LIST_OUT (area) == NULL) | |
831 | PREFIX_LIST_OUT (area) = prefix_list_lookup (AFI_IP, | |
832 | PREFIX_NAME_OUT (area)); | |
833 | if (PREFIX_LIST_OUT (area)) | |
834 | if (prefix_list_apply (PREFIX_LIST_OUT (area), p) != PREFIX_PERMIT) | |
835 | return 0; | |
836 | } | |
837 | return 1; | |
838 | } | |
839 | ||
4dadc291 | 840 | static void |
147193a2 | 841 | ospf_abr_announce_network (struct ospf *ospf, |
d4a53d58 | 842 | struct prefix_ipv4 *p, struct ospf_route *or) |
718e3744 | 843 | { |
718e3744 | 844 | struct ospf_area_range *range; |
718e3744 | 845 | struct ospf_area *area, *or_area; |
52dc7ee6 | 846 | struct listnode *node; |
718e3744 | 847 | |
848 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 849 | zlog_debug ("ospf_abr_announce_network(): Start"); |
718e3744 | 850 | |
147193a2 | 851 | or_area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id); |
718e3744 | 852 | assert (or_area); |
853 | ||
1eb8ef25 | 854 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
718e3744 | 855 | { |
718e3744 | 856 | if (IS_DEBUG_OSPF_EVENT) |
e84cc647 | 857 | zlog_debug ("ospf_abr_announce_network(): looking at area %s", |
718e3744 | 858 | inet_ntoa (area->area_id)); |
859 | ||
860 | if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id)) | |
861 | continue; | |
862 | ||
863 | if (ospf_abr_nexthops_belong_to_area (or, area)) | |
864 | continue; | |
865 | ||
d4a53d58 | 866 | if (!ospf_abr_should_accept (p, area)) |
718e3744 | 867 | { |
868 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 869 | zlog_debug ("ospf_abr_announce_network(): " |
718e3744 | 870 | "prefix %s/%d was denied by import-list", |
871 | inet_ntoa (p->prefix), p->prefixlen); | |
872 | continue; | |
873 | } | |
874 | ||
d4a53d58 | 875 | if (!ospf_abr_plist_in_check (area, or, p)) |
718e3744 | 876 | { |
877 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 878 | zlog_debug ("ospf_abr_announce_network(): " |
718e3744 | 879 | "prefix %s/%d was denied by prefix-list", |
880 | inet_ntoa (p->prefix), p->prefixlen); | |
881 | continue; | |
882 | } | |
883 | ||
884 | if (area->external_routing != OSPF_AREA_DEFAULT && area->no_summary) | |
885 | { | |
886 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 887 | zlog_debug ("ospf_abr_announce_network(): " |
718e3744 | 888 | "area %s is stub and no_summary", |
889 | inet_ntoa (area->area_id)); | |
890 | continue; | |
891 | } | |
892 | ||
893 | if (or->path_type == OSPF_PATH_INTER_AREA) | |
894 | { | |
895 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 896 | zlog_debug ("ospf_abr_announce_network(): this is " |
718e3744 | 897 | "inter-area route to %s/%d", |
898 | inet_ntoa (p->prefix), p->prefixlen); | |
899 | ||
900 | if (!OSPF_IS_AREA_BACKBONE (area)) | |
901 | ospf_abr_announce_network_to_area (p, or->cost, area); | |
902 | } | |
903 | ||
904 | if (or->path_type == OSPF_PATH_INTRA_AREA) | |
d4a53d58 | 905 | { |
906 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 907 | zlog_debug ("ospf_abr_announce_network(): " |
d4a53d58 | 908 | "this is intra-area route to %s/%d", |
909 | inet_ntoa (p->prefix), p->prefixlen); | |
910 | if ((range = ospf_area_range_match (or_area, p)) | |
911 | && !ospf_area_is_transit (area)) | |
912 | ospf_abr_update_aggregate (range, or); | |
913 | else | |
914 | ospf_abr_announce_network_to_area (p, or->cost, area); | |
915 | } | |
718e3744 | 916 | } |
917 | } | |
918 | ||
4dadc291 | 919 | static int |
147193a2 | 920 | ospf_abr_should_announce (struct ospf *ospf, |
d4a53d58 | 921 | struct prefix_ipv4 *p, struct ospf_route *or) |
718e3744 | 922 | { |
147193a2 | 923 | struct ospf_area *area; |
924 | ||
925 | area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id); | |
718e3744 | 926 | |
927 | assert (area); | |
928 | ||
929 | if (EXPORT_NAME (area)) | |
930 | { | |
931 | if (EXPORT_LIST (area) == NULL) | |
932 | EXPORT_LIST (area) = access_list_lookup (AFI_IP, EXPORT_NAME (area)); | |
933 | ||
934 | if (EXPORT_LIST (area)) | |
935 | if (access_list_apply (EXPORT_LIST (area), p) == FILTER_DENY) | |
936 | return 0; | |
937 | } | |
938 | ||
939 | return 1; | |
940 | } | |
941 | ||
4dadc291 | 942 | static void |
147193a2 | 943 | ospf_abr_process_nssa_translates (struct ospf *ospf) |
718e3744 | 944 | { |
945 | /* Scan through all NSSA_LSDB records for all areas; | |
946 | ||
947 | If P-bit is on, translate all Type-7's to 5's and aggregate or | |
948 | flood install as approved in Type-5 LSDB with XLATE Flag on | |
949 | later, do same for all aggregates... At end, DISCARD all | |
950 | remaining UNAPPROVED Type-5's (Aggregate is for future ) */ | |
52dc7ee6 | 951 | struct listnode *node; |
718e3744 | 952 | struct ospf_area *area; |
147193a2 | 953 | struct route_node *rn; |
954 | struct ospf_lsa *lsa; | |
718e3744 | 955 | |
956 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 957 | zlog_debug ("ospf_abr_process_nssa_translates(): Start"); |
718e3744 | 958 | |
1eb8ef25 | 959 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
718e3744 | 960 | { |
e2c6c153 | 961 | if (! area->NSSATranslatorState) |
d4a53d58 | 962 | continue; /* skip if not translator */ |
718e3744 | 963 | |
964 | if (area->external_routing != OSPF_AREA_NSSA) | |
d4a53d58 | 965 | continue; /* skip if not Nssa Area */ |
718e3744 | 966 | |
967 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 968 | zlog_debug ("ospf_abr_process_nssa_translates(): " |
d4a53d58 | 969 | "looking at area %s", inet_ntoa (area->area_id)); |
718e3744 | 970 | |
147193a2 | 971 | LSDB_LOOP (NSSA_LSDB (area), rn, lsa) |
d4a53d58 | 972 | ospf_abr_translate_nssa (area, lsa); |
718e3744 | 973 | } |
974 | ||
975 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 976 | zlog_debug ("ospf_abr_process_nssa_translates(): Stop"); |
718e3744 | 977 | |
978 | } | |
718e3744 | 979 | |
4dadc291 | 980 | static void |
147193a2 | 981 | ospf_abr_process_network_rt (struct ospf *ospf, |
982 | struct route_table *rt) | |
718e3744 | 983 | { |
718e3744 | 984 | struct ospf_area *area; |
147193a2 | 985 | struct ospf_route *or; |
986 | struct route_node *rn; | |
718e3744 | 987 | |
988 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 989 | zlog_debug ("ospf_abr_process_network_rt(): Start"); |
718e3744 | 990 | |
991 | for (rn = route_top (rt); rn; rn = route_next (rn)) | |
992 | { | |
993 | if ((or = rn->info) == NULL) | |
994 | continue; | |
995 | ||
147193a2 | 996 | if (!(area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id))) |
718e3744 | 997 | { |
998 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 999 | zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists", |
718e3744 | 1000 | inet_ntoa (or->u.std.area_id)); |
1001 | continue; | |
1002 | } | |
1003 | ||
1004 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1005 | zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d", |
718e3744 | 1006 | inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen); |
1007 | if (or->path_type >= OSPF_PATH_TYPE1_EXTERNAL) | |
1008 | { | |
1009 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1010 | zlog_debug ("ospf_abr_process_network_rt(): " |
718e3744 | 1011 | "this is an External router, skipping"); |
1012 | continue; | |
1013 | } | |
1014 | ||
1015 | if (or->cost >= OSPF_LS_INFINITY) | |
1016 | { | |
1017 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1018 | zlog_debug ("ospf_abr_process_network_rt():" |
718e3744 | 1019 | " this route's cost is infinity, skipping"); |
1020 | continue; | |
1021 | } | |
1022 | ||
1023 | if (or->type == OSPF_DESTINATION_DISCARD) | |
1024 | { | |
1025 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1026 | zlog_debug ("ospf_abr_process_network_rt():" |
718e3744 | 1027 | " this is a discard entry, skipping"); |
1028 | continue; | |
1029 | } | |
1030 | ||
1031 | if (or->path_type == OSPF_PATH_INTRA_AREA && | |
d4a53d58 | 1032 | !ospf_abr_should_announce (ospf, (struct prefix_ipv4 *) &rn->p, or)) |
718e3744 | 1033 | { |
1034 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1035 | zlog_debug("ospf_abr_process_network_rt(): denied by export-list"); |
718e3744 | 1036 | continue; |
1037 | } | |
1038 | ||
1039 | if (or->path_type == OSPF_PATH_INTRA_AREA && | |
d4a53d58 | 1040 | !ospf_abr_plist_out_check (area, or, (struct prefix_ipv4 *) &rn->p)) |
718e3744 | 1041 | { |
1042 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1043 | zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list"); |
718e3744 | 1044 | continue; |
1045 | } | |
1046 | ||
1047 | if ((or->path_type == OSPF_PATH_INTER_AREA) && | |
1048 | !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id)) | |
1049 | { | |
1050 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1051 | zlog_debug ("ospf_abr_process_network_rt():" |
718e3744 | 1052 | " this is route is not backbone one, skipping"); |
1053 | continue; | |
1054 | } | |
1055 | ||
1056 | ||
147193a2 | 1057 | if ((ospf->abr_type == OSPF_ABR_CISCO) || |
1058 | (ospf->abr_type == OSPF_ABR_IBM)) | |
718e3744 | 1059 | |
147193a2 | 1060 | if (!ospf_act_bb_connection (ospf) && |
718e3744 | 1061 | or->path_type != OSPF_PATH_INTRA_AREA) |
1062 | { | |
1063 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1064 | zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: " |
718e3744 | 1065 | "No BB connection, skip not intra-area routes"); |
1066 | continue; | |
1067 | } | |
1068 | ||
1069 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1070 | zlog_debug ("ospf_abr_process_network_rt(): announcing"); |
fa2b17e3 | 1071 | ospf_abr_announce_network (ospf, (struct prefix_ipv4 *)&rn->p, or); |
718e3744 | 1072 | } |
1073 | ||
1074 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1075 | zlog_debug ("ospf_abr_process_network_rt(): Stop"); |
718e3744 | 1076 | } |
1077 | ||
4dadc291 | 1078 | static void |
718e3744 | 1079 | ospf_abr_announce_rtr_to_area (struct prefix_ipv4 *p, u_int32_t cost, |
1080 | struct ospf_area *area) | |
1081 | { | |
1082 | struct ospf_lsa *lsa, *old = NULL; | |
1083 | struct summary_lsa *slsa = NULL; | |
1084 | ||
1085 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1086 | zlog_debug ("ospf_abr_announce_rtr_to_area(): Start"); |
718e3744 | 1087 | |
147193a2 | 1088 | old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_ASBR_SUMMARY_LSA, |
1089 | p, area->ospf->router_id); | |
718e3744 | 1090 | if (old) |
1091 | { | |
1092 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1093 | zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found"); |
718e3744 | 1094 | slsa = (struct summary_lsa *) old->data; |
1095 | ||
1096 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1097 | zlog_debug ("ospf_abr_announce_network_to_area(): " |
718e3744 | 1098 | "old metric: %d, new metric: %d", |
1099 | GET_METRIC (slsa->metric), cost); | |
1100 | } | |
1101 | ||
1102 | if (old && (GET_METRIC (slsa->metric) == cost)) | |
1103 | { | |
1104 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1105 | zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved"); |
718e3744 | 1106 | SET_FLAG (old->flags, OSPF_LSA_APPROVED); |
1107 | } | |
1108 | else | |
1109 | { | |
1110 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1111 | zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2"); |
718e3744 | 1112 | |
1113 | if (old) | |
1114 | { | |
1115 | set_metric (old, cost); | |
147193a2 | 1116 | lsa = ospf_summary_asbr_lsa_refresh (area->ospf, old); |
718e3744 | 1117 | } |
1118 | else | |
1119 | lsa = ospf_summary_asbr_lsa_originate (p, cost, area); | |
1120 | ||
1121 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1122 | zlog_debug ("ospf_abr_announce_rtr_to_area(): " |
718e3744 | 1123 | "flooding new version of summary"); |
1124 | /* | |
1125 | zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary"); | |
1126 | lsa = ospf_summary_asbr_lsa (p, cost, area, old); */ | |
1127 | ||
1128 | SET_FLAG (lsa->flags, OSPF_LSA_APPROVED); | |
1129 | /* ospf_flood_through_area (area, NULL, lsa);*/ | |
1130 | } | |
1131 | ||
1132 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1133 | zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop"); |
718e3744 | 1134 | } |
1135 | ||
1136 | ||
4dadc291 | 1137 | static void |
147193a2 | 1138 | ospf_abr_announce_rtr (struct ospf *ospf, |
1139 | struct prefix_ipv4 *p, struct ospf_route *or) | |
718e3744 | 1140 | { |
52dc7ee6 | 1141 | struct listnode *node; |
718e3744 | 1142 | struct ospf_area *area; |
1143 | ||
1144 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1145 | zlog_debug ("ospf_abr_announce_rtr(): Start"); |
718e3744 | 1146 | |
1eb8ef25 | 1147 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
718e3744 | 1148 | { |
718e3744 | 1149 | if (IS_DEBUG_OSPF_EVENT) |
e84cc647 | 1150 | zlog_debug ("ospf_abr_announce_rtr(): looking at area %s", |
718e3744 | 1151 | inet_ntoa (area->area_id)); |
1152 | ||
1153 | if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id)) | |
1154 | continue; | |
1155 | ||
1156 | if (ospf_abr_nexthops_belong_to_area (or, area)) | |
1157 | continue; | |
1158 | ||
1159 | if (area->external_routing != OSPF_AREA_DEFAULT) | |
1160 | { | |
1161 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1162 | zlog_debug ("ospf_abr_announce_rtr(): " |
718e3744 | 1163 | "area %s doesn't support external routing", |
1164 | inet_ntoa(area->area_id)); | |
1165 | continue; | |
1166 | } | |
1167 | ||
1168 | if (or->path_type == OSPF_PATH_INTER_AREA) | |
1169 | { | |
1170 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1171 | zlog_debug ("ospf_abr_announce_rtr(): " |
718e3744 | 1172 | "this is inter-area route to %s", inet_ntoa (p->prefix)); |
1173 | if (!OSPF_IS_AREA_BACKBONE (area)) | |
1174 | ospf_abr_announce_rtr_to_area (p, or->cost, area); | |
1175 | } | |
1176 | ||
1177 | if (or->path_type == OSPF_PATH_INTRA_AREA) | |
1178 | { | |
1179 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1180 | zlog_debug ("ospf_abr_announce_rtr(): " |
718e3744 | 1181 | "this is intra-area route to %s", inet_ntoa (p->prefix)); |
1182 | ospf_abr_announce_rtr_to_area (p, or->cost, area); | |
1183 | } | |
1184 | } | |
1185 | ||
1186 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1187 | zlog_debug ("ospf_abr_announce_rtr(): Stop"); |
718e3744 | 1188 | } |
1189 | ||
4dadc291 | 1190 | static void |
147193a2 | 1191 | ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt) |
718e3744 | 1192 | { |
718e3744 | 1193 | struct ospf_route *or; |
147193a2 | 1194 | struct route_node *rn; |
718e3744 | 1195 | struct list *l; |
1196 | ||
1197 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1198 | zlog_debug ("ospf_abr_process_router_rt(): Start"); |
718e3744 | 1199 | |
1200 | for (rn = route_top (rt); rn; rn = route_next (rn)) | |
1201 | { | |
1eb8ef25 | 1202 | struct listnode *node, *nnode; |
718e3744 | 1203 | char flag = 0; |
1204 | struct ospf_route *best = NULL; | |
1205 | ||
1206 | if (rn->info == NULL) | |
1207 | continue; | |
1208 | ||
1209 | l = rn->info; | |
1210 | ||
1211 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1212 | zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s", |
718e3744 | 1213 | inet_ntoa (rn->p.u.prefix4)); |
1214 | ||
1eb8ef25 | 1215 | for (ALL_LIST_ELEMENTS (l, node, nnode, or)) |
718e3744 | 1216 | { |
147193a2 | 1217 | if (!ospf_area_lookup_by_area_id (ospf, or->u.std.area_id)) |
718e3744 | 1218 | { |
1219 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1220 | zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists", |
718e3744 | 1221 | inet_ntoa (or->u.std.area_id)); |
1222 | continue; | |
1223 | } | |
1224 | ||
1225 | ||
1226 | if (!CHECK_FLAG (or->u.std.flags, ROUTER_LSA_EXTERNAL)) | |
1227 | { | |
1228 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1229 | zlog_debug ("ospf_abr_process_router_rt(): " |
718e3744 | 1230 | "This is not an ASBR, skipping"); |
1231 | continue; | |
1232 | } | |
1233 | ||
1234 | if (!flag) | |
1235 | { | |
147193a2 | 1236 | best = ospf_find_asbr_route (ospf, rt, |
1237 | (struct prefix_ipv4 *) &rn->p); | |
718e3744 | 1238 | flag = 1; |
1239 | } | |
1240 | ||
1241 | if (best == NULL) | |
1242 | continue; | |
1243 | ||
1244 | if (or != best) | |
1245 | { | |
1246 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1247 | zlog_debug ("ospf_abr_process_router_rt(): " |
718e3744 | 1248 | "This route is not the best among possible, skipping"); |
1249 | continue; | |
1250 | } | |
1251 | ||
1252 | if (or->path_type == OSPF_PATH_INTER_AREA && | |
1253 | !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id)) | |
1254 | { | |
1255 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1256 | zlog_debug ("ospf_abr_process_router_rt(): " |
718e3744 | 1257 | "This route is not a backbone one, skipping"); |
1258 | continue; | |
1259 | } | |
1260 | ||
1261 | if (or->cost >= OSPF_LS_INFINITY) | |
1262 | { | |
1263 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1264 | zlog_debug ("ospf_abr_process_router_rt(): " |
718e3744 | 1265 | "This route has LS_INFINITY metric, skipping"); |
1266 | continue; | |
1267 | } | |
1268 | ||
147193a2 | 1269 | if (ospf->abr_type == OSPF_ABR_CISCO |
1270 | || ospf->abr_type == OSPF_ABR_IBM) | |
1271 | if (!ospf_act_bb_connection (ospf) | |
1272 | && or->path_type != OSPF_PATH_INTRA_AREA) | |
718e3744 | 1273 | { |
1274 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1275 | zlog_debug("ospf_abr_process_network_rt(): ALT ABR: " |
718e3744 | 1276 | "No BB connection, skip not intra-area routes"); |
1277 | continue; | |
1278 | } | |
1279 | ||
147193a2 | 1280 | ospf_abr_announce_rtr (ospf, (struct prefix_ipv4 *) &rn->p, or); |
718e3744 | 1281 | |
1282 | } | |
1283 | ||
1284 | } | |
1285 | ||
1286 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1287 | zlog_debug ("ospf_abr_process_router_rt(): Stop"); |
718e3744 | 1288 | } |
1289 | ||
4dadc291 | 1290 | static void |
147193a2 | 1291 | ospf_abr_unapprove_translates (struct ospf *ospf) /* For NSSA Translations */ |
718e3744 | 1292 | { |
147193a2 | 1293 | struct ospf_lsa *lsa; |
1294 | struct route_node *rn; | |
1295 | ||
718e3744 | 1296 | if (IS_DEBUG_OSPF_NSSA) |
e84cc647 | 1297 | zlog_debug ("ospf_abr_unapprove_translates(): Start"); |
718e3744 | 1298 | |
1299 | /* NSSA Translator is not checked, because it may have gone away, | |
1300 | and we would want to flush any residuals anyway */ | |
1301 | ||
147193a2 | 1302 | LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa) |
1303 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
d4a53d58 | 1304 | { |
1305 | UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED); | |
1306 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1307 | zlog_debug ("ospf_abr_unapprove_translates(): " |
d4a53d58 | 1308 | "approved unset on link id %s", |
1309 | inet_ntoa (lsa->data->id)); | |
1310 | } | |
718e3744 | 1311 | |
1312 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1313 | zlog_debug ("ospf_abr_unapprove_translates(): Stop"); |
718e3744 | 1314 | } |
718e3744 | 1315 | |
4dadc291 | 1316 | static void |
147193a2 | 1317 | ospf_abr_unapprove_summaries (struct ospf *ospf) |
718e3744 | 1318 | { |
52dc7ee6 | 1319 | struct listnode *node; |
718e3744 | 1320 | struct ospf_area *area; |
147193a2 | 1321 | struct route_node *rn; |
1322 | struct ospf_lsa *lsa; | |
718e3744 | 1323 | |
1324 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1325 | zlog_debug ("ospf_abr_unapprove_summaries(): Start"); |
718e3744 | 1326 | |
1eb8ef25 | 1327 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
718e3744 | 1328 | { |
d4a53d58 | 1329 | if (IS_DEBUG_OSPF_EVENT) |
e84cc647 | 1330 | zlog_debug ("ospf_abr_unapprove_summaries(): " |
d4a53d58 | 1331 | "considering area %s", |
1332 | inet_ntoa (area->area_id)); | |
147193a2 | 1333 | LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa) |
d4a53d58 | 1334 | if (ospf_lsa_is_self_originated (ospf, lsa)) |
1335 | { | |
1336 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1337 | zlog_debug ("ospf_abr_unapprove_summaries(): " |
d4a53d58 | 1338 | "approved unset on summary link id %s", |
1339 | inet_ntoa (lsa->data->id)); | |
1340 | UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED); | |
1341 | } | |
147193a2 | 1342 | |
1343 | LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa) | |
d4a53d58 | 1344 | if (ospf_lsa_is_self_originated (ospf, lsa)) |
1345 | { | |
1346 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1347 | zlog_debug ("ospf_abr_unapprove_summaries(): " |
d4a53d58 | 1348 | "approved unset on asbr-summary link id %s", |
1349 | inet_ntoa (lsa->data->id)); | |
1350 | UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED); | |
1351 | } | |
718e3744 | 1352 | } |
1353 | ||
1354 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1355 | zlog_debug ("ospf_abr_unapprove_summaries(): Stop"); |
718e3744 | 1356 | } |
1357 | ||
4dadc291 | 1358 | static void |
147193a2 | 1359 | ospf_abr_prepare_aggregates (struct ospf *ospf) |
718e3744 | 1360 | { |
52dc7ee6 | 1361 | struct listnode *node; |
718e3744 | 1362 | struct route_node *rn; |
1363 | struct ospf_area_range *range; | |
1eb8ef25 | 1364 | struct ospf_area *area; |
718e3744 | 1365 | |
1366 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1367 | zlog_debug ("ospf_abr_prepare_aggregates(): Start"); |
718e3744 | 1368 | |
1eb8ef25 | 1369 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
718e3744 | 1370 | { |
718e3744 | 1371 | for (rn = route_top (area->ranges); rn; rn = route_next (rn)) |
1372 | if ((range = rn->info) != NULL) | |
1373 | { | |
1374 | range->cost = 0; | |
1375 | range->specifics = 0; | |
1376 | } | |
1377 | } | |
1378 | ||
1379 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1380 | zlog_debug ("ospf_abr_prepare_aggregates(): Stop"); |
718e3744 | 1381 | } |
1382 | ||
4dadc291 | 1383 | static void |
147193a2 | 1384 | ospf_abr_announce_aggregates (struct ospf *ospf) |
718e3744 | 1385 | { |
1386 | struct ospf_area *area, *ar; | |
1387 | struct ospf_area_range *range; | |
1388 | struct route_node *rn; | |
d4a53d58 | 1389 | struct prefix p; |
52dc7ee6 | 1390 | struct listnode *node, *n; |
718e3744 | 1391 | |
1392 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1393 | zlog_debug ("ospf_abr_announce_aggregates(): Start"); |
718e3744 | 1394 | |
1eb8ef25 | 1395 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
718e3744 | 1396 | { |
718e3744 | 1397 | if (IS_DEBUG_OSPF_EVENT) |
e84cc647 | 1398 | zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s", |
718e3744 | 1399 | inet_ntoa (area->area_id)); |
1400 | ||
1401 | for (rn = route_top (area->ranges); rn; rn = route_next (rn)) | |
1402 | if ((range = rn->info)) | |
1403 | { | |
1404 | if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)) | |
1405 | { | |
1406 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1407 | zlog_debug ("ospf_abr_announce_aggregates():" |
718e3744 | 1408 | " discarding suppress-ranges"); |
1409 | continue; | |
1410 | } | |
1411 | ||
1412 | p.family = AF_INET; | |
d4a53d58 | 1413 | p.u.prefix4 = range->addr; |
718e3744 | 1414 | p.prefixlen = range->masklen; |
1415 | ||
1416 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1417 | zlog_debug ("ospf_abr_announce_aggregates():" |
718e3744 | 1418 | " this is range: %s/%d", |
d4a53d58 | 1419 | inet_ntoa (p.u.prefix4), p.prefixlen); |
718e3744 | 1420 | |
1421 | if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE)) | |
1422 | { | |
1423 | p.family = AF_INET; | |
d4a53d58 | 1424 | p.u.prefix4 = range->subst_addr; |
718e3744 | 1425 | p.prefixlen = range->subst_masklen; |
1426 | } | |
1427 | ||
1428 | if (range->specifics) | |
1429 | { | |
1430 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1431 | zlog_debug ("ospf_abr_announce_aggregates(): active range"); |
718e3744 | 1432 | |
1eb8ef25 | 1433 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, n, ar)) |
718e3744 | 1434 | { |
718e3744 | 1435 | if (ar == area) |
1436 | continue; | |
1437 | ||
1438 | /* We do not check nexthops here, because | |
1439 | intra-area routes can be associated with | |
1440 | one area only */ | |
1441 | ||
1442 | /* backbone routes are not summarized | |
1443 | when announced into transit areas */ | |
1444 | ||
1445 | if (ospf_area_is_transit (ar) && | |
1446 | OSPF_IS_AREA_BACKBONE (area)) | |
1447 | { | |
1448 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1449 | zlog_debug ("ospf_abr_announce_aggregates(): Skipping " |
718e3744 | 1450 | "announcement of BB aggregate into" |
1451 | " a transit area"); | |
1452 | continue; | |
1453 | } | |
fa2b17e3 | 1454 | ospf_abr_announce_network_to_area ((struct prefix_ipv4 *)&p, range->cost, ar); |
718e3744 | 1455 | } |
1456 | } | |
1457 | } | |
1458 | } | |
1459 | ||
1460 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1461 | zlog_debug ("ospf_abr_announce_aggregates(): Stop"); |
718e3744 | 1462 | } |
1463 | ||
4dadc291 | 1464 | static void |
147193a2 | 1465 | ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */ |
718e3744 | 1466 | { |
52dc7ee6 | 1467 | struct listnode *node; /*, n; */ |
718e3744 | 1468 | struct ospf_area *area; /*, *ar; */ |
1469 | struct route_node *rn; | |
1470 | struct ospf_area_range *range; | |
1471 | struct prefix_ipv4 p; | |
1472 | ||
1473 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1474 | zlog_debug ("ospf_abr_send_nssa_aggregates(): Start"); |
718e3744 | 1475 | |
1eb8ef25 | 1476 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
718e3744 | 1477 | { |
e2c6c153 | 1478 | if (! area->NSSATranslatorState) |
718e3744 | 1479 | continue; |
1480 | ||
1481 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1482 | zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s", |
718e3744 | 1483 | inet_ntoa (area->area_id)); |
1484 | ||
1485 | for (rn = route_top (area->ranges); rn; rn = route_next (rn)) | |
1486 | { | |
1487 | if (rn->info == NULL) | |
1488 | continue; | |
1489 | ||
1490 | range = rn->info; | |
1491 | ||
1492 | if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)) | |
1493 | { | |
1494 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1495 | zlog_debug ("ospf_abr_send_nssa_aggregates():" |
718e3744 | 1496 | " discarding suppress-ranges"); |
1497 | continue; | |
1498 | } | |
1499 | ||
1500 | p.family = AF_INET; | |
1501 | p.prefix = range->addr; | |
1502 | p.prefixlen = range->masklen; | |
1503 | ||
1504 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1505 | zlog_debug ("ospf_abr_send_nssa_aggregates():" |
718e3744 | 1506 | " this is range: %s/%d", |
1507 | inet_ntoa (p.prefix), p.prefixlen); | |
1508 | ||
1509 | if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE)) | |
1510 | { | |
1511 | p.family = AF_INET; | |
1512 | p.prefix = range->subst_addr; | |
1513 | p.prefixlen = range->subst_masklen; | |
1514 | } | |
1515 | ||
1516 | if (range->specifics) | |
e2c6c153 | 1517 | { |
1518 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1519 | zlog_debug ("ospf_abr_send_nssa_aggregates(): active range"); |
e2c6c153 | 1520 | |
1521 | /* Fetch LSA-Type-7 from aggregate prefix, and then | |
1522 | * translate, Install (as Type-5), Approve, and Flood | |
1523 | */ | |
1524 | ospf_abr_translate_nssa_range (&p, range->cost); | |
1525 | } | |
1526 | } /* all area ranges*/ | |
718e3744 | 1527 | } /* all areas */ |
1528 | ||
1529 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1530 | zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop"); |
718e3744 | 1531 | } |
1532 | ||
4dadc291 | 1533 | static void |
147193a2 | 1534 | ospf_abr_announce_nssa_defaults (struct ospf *ospf) /* By ABR-Translator */ |
718e3744 | 1535 | { |
52dc7ee6 | 1536 | struct listnode *node; |
718e3744 | 1537 | struct ospf_area *area; |
718e3744 | 1538 | |
147193a2 | 1539 | if (! IS_OSPF_ABR (ospf)) |
718e3744 | 1540 | return; |
1541 | ||
1542 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1543 | zlog_debug ("ospf_abr_announce_stub_defaults(): Start"); |
718e3744 | 1544 | |
1eb8ef25 | 1545 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
718e3744 | 1546 | { |
718e3744 | 1547 | if (IS_DEBUG_OSPF_NSSA) |
e84cc647 | 1548 | zlog_debug ("ospf_abr_announce_nssa_defaults(): looking at area %s", |
e2c6c153 | 1549 | inet_ntoa (area->area_id)); |
718e3744 | 1550 | |
1551 | if (area->external_routing != OSPF_AREA_NSSA) | |
e2c6c153 | 1552 | continue; |
718e3744 | 1553 | |
1554 | if (OSPF_IS_AREA_BACKBONE (area)) | |
e2c6c153 | 1555 | continue; /* Sanity Check */ |
718e3744 | 1556 | |
1557 | /* if (!TranslatorRole continue V 1.0 look for "always" conf */ | |
e2c6c153 | 1558 | if (area->NSSATranslatorState) |
1559 | { | |
1560 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1561 | zlog_debug ("ospf_abr_announce_nssa_defaults(): " |
e2c6c153 | 1562 | "announcing 0.0.0.0/0 to this nssa"); |
1563 | /* ospf_abr_announce_nssa_asbr_to_as (&p, area->default_cost, area); */ | |
d4a53d58 | 1564 | /*ospf_abr_announce_network_to_area (&p, area->default_cost, area);*/ |
e2c6c153 | 1565 | } |
718e3744 | 1566 | } |
1567 | } | |
718e3744 | 1568 | |
4dadc291 | 1569 | static void |
147193a2 | 1570 | ospf_abr_announce_stub_defaults (struct ospf *ospf) |
718e3744 | 1571 | { |
52dc7ee6 | 1572 | struct listnode *node; |
718e3744 | 1573 | struct ospf_area *area; |
1574 | struct prefix_ipv4 p; | |
1575 | ||
147193a2 | 1576 | if (! IS_OSPF_ABR (ospf)) |
718e3744 | 1577 | return; |
1578 | ||
1579 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1580 | zlog_debug ("ospf_abr_announce_stub_defaults(): Start"); |
718e3744 | 1581 | |
1582 | p.family = AF_INET; | |
1583 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1584 | p.prefixlen = 0; | |
1585 | ||
1eb8ef25 | 1586 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
718e3744 | 1587 | { |
718e3744 | 1588 | if (IS_DEBUG_OSPF_EVENT) |
e84cc647 | 1589 | zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s", |
1590 | inet_ntoa (area->area_id)); | |
718e3744 | 1591 | |
d4a53d58 | 1592 | if ( (area->external_routing != OSPF_AREA_STUB) |
d4a53d58 | 1593 | && (area->external_routing != OSPF_AREA_NSSA) |
d4a53d58 | 1594 | ) |
1595 | continue; | |
718e3744 | 1596 | |
1597 | if (OSPF_IS_AREA_BACKBONE (area)) | |
d4a53d58 | 1598 | continue; /* Sanity Check */ |
1599 | ||
718e3744 | 1600 | if (IS_DEBUG_OSPF_EVENT) |
e84cc647 | 1601 | zlog_debug ("ospf_abr_announce_stub_defaults(): " |
1602 | "announcing 0.0.0.0/0 to area %s", | |
d4a53d58 | 1603 | inet_ntoa (area->area_id)); |
718e3744 | 1604 | ospf_abr_announce_network_to_area (&p, area->default_cost, area); |
1605 | } | |
1606 | ||
1607 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1608 | zlog_debug ("ospf_abr_announce_stub_defaults(): Stop"); |
718e3744 | 1609 | } |
1610 | ||
4dadc291 | 1611 | static int |
147193a2 | 1612 | ospf_abr_remove_unapproved_translates_apply (struct ospf *ospf, |
1613 | struct ospf_lsa *lsa) | |
718e3744 | 1614 | { |
1615 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT) | |
1616 | && ! CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED)) | |
1617 | { | |
1618 | zlog_info ("ospf_abr_remove_unapproved_translates(): " | |
1619 | "removing unapproved translates, ID: %s", | |
1620 | inet_ntoa (lsa->data->id)); | |
1621 | ||
1622 | /* FLUSH THROUGHOUT AS */ | |
147193a2 | 1623 | ospf_lsa_flush_as (ospf, lsa); |
718e3744 | 1624 | |
1625 | /* DISCARD from LSDB */ | |
1626 | } | |
1627 | return 0; | |
1628 | } | |
1629 | ||
4dadc291 | 1630 | static void |
147193a2 | 1631 | ospf_abr_remove_unapproved_translates (struct ospf *ospf) |
718e3744 | 1632 | { |
147193a2 | 1633 | struct route_node *rn; |
1634 | struct ospf_lsa *lsa; | |
1635 | ||
718e3744 | 1636 | /* All AREA PROCESS should have APPROVED necessary LSAs */ |
1637 | /* Remove any left over and not APPROVED */ | |
1638 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1639 | zlog_debug ("ospf_abr_remove_unapproved_translates(): Start"); |
718e3744 | 1640 | |
147193a2 | 1641 | LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa) |
1642 | ospf_abr_remove_unapproved_translates_apply (ospf, lsa); | |
718e3744 | 1643 | |
1644 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1645 | zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop"); |
718e3744 | 1646 | } |
718e3744 | 1647 | |
4dadc291 | 1648 | static void |
147193a2 | 1649 | ospf_abr_remove_unapproved_summaries (struct ospf *ospf) |
718e3744 | 1650 | { |
52dc7ee6 | 1651 | struct listnode *node; |
718e3744 | 1652 | struct ospf_area *area; |
147193a2 | 1653 | struct route_node *rn; |
1654 | struct ospf_lsa *lsa; | |
718e3744 | 1655 | |
1656 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1657 | zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start"); |
718e3744 | 1658 | |
1eb8ef25 | 1659 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
718e3744 | 1660 | { |
718e3744 | 1661 | if (IS_DEBUG_OSPF_EVENT) |
e84cc647 | 1662 | zlog_debug ("ospf_abr_remove_unapproved_summaries(): " |
718e3744 | 1663 | "looking at area %s", inet_ntoa (area->area_id)); |
1664 | ||
147193a2 | 1665 | LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa) |
1666 | if (ospf_lsa_is_self_originated (ospf, lsa)) | |
1667 | if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED)) | |
1668 | ospf_lsa_flush_area (lsa, area); | |
1669 | ||
1670 | LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa) | |
1671 | if (ospf_lsa_is_self_originated (ospf, lsa)) | |
1672 | if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED)) | |
1673 | ospf_lsa_flush_area (lsa, area); | |
718e3744 | 1674 | } |
1675 | ||
1676 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1677 | zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop"); |
718e3744 | 1678 | } |
1679 | ||
4dadc291 | 1680 | static void |
147193a2 | 1681 | ospf_abr_manage_discard_routes (struct ospf *ospf) |
718e3744 | 1682 | { |
1eb8ef25 | 1683 | struct listnode *node, *nnode; |
718e3744 | 1684 | struct route_node *rn; |
1685 | struct ospf_area *area; | |
1686 | struct ospf_area_range *range; | |
1687 | ||
1eb8ef25 | 1688 | for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area)) |
1689 | for (rn = route_top (area->ranges); rn; rn = route_next (rn)) | |
1690 | if ((range = rn->info) != NULL) | |
1691 | if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)) | |
1692 | { | |
1693 | if (range->specifics) | |
1694 | ospf_add_discard_route (ospf->new_table, area, | |
1695 | (struct prefix_ipv4 *) &rn->p); | |
1696 | else | |
1697 | ospf_delete_discard_route ((struct prefix_ipv4 *) &rn->p); | |
1698 | } | |
718e3744 | 1699 | } |
1700 | ||
718e3744 | 1701 | /* This is the function taking care about ABR NSSA, i.e. NSSA |
1702 | Translator, -LSA aggregation and flooding. For all NSSAs | |
1703 | ||
1704 | Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's | |
1705 | are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB | |
1706 | with the P-bit set. | |
1707 | ||
1708 | Any received Type-5s are legal for an ABR, else illegal for IR. | |
1709 | Received Type-7s are installed, by area, with incoming P-bit. They | |
1710 | are flooded; if the Elected NSSA Translator, then P-bit off. | |
1711 | ||
1712 | Additionally, this ABR will place "translated type-7's" into the | |
1713 | Type-5 LSDB in order to keep track of APPROVAL or not. | |
1714 | ||
1715 | It will scan through every area, looking for Type-7 LSAs with P-Bit | |
1716 | SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or | |
1717 | AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED & | |
1718 | 5-INSTALLED. | |
1719 | ||
1720 | 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs | |
1721 | left over are FLUSHED and DISCARDED. | |
1722 | ||
1723 | For External Calculations, any NSSA areas use the Type-7 AREA-LSDB, | |
1724 | any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */ | |
1725 | ||
4dadc291 | 1726 | static void |
147193a2 | 1727 | ospf_abr_nssa_task (struct ospf *ospf) /* called only if any_nssa */ |
718e3744 | 1728 | { |
1729 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1730 | zlog_debug ("Check for NSSA-ABR Tasks():"); |
718e3744 | 1731 | |
147193a2 | 1732 | if (! IS_OSPF_ABR (ospf)) |
718e3744 | 1733 | return; |
1734 | ||
147193a2 | 1735 | if (! ospf->anyNSSA) |
718e3744 | 1736 | return; |
1737 | ||
1738 | /* Each area must confirm TranslatorRole */ | |
1739 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1740 | zlog_debug ("ospf_abr_nssa_task(): Start"); |
718e3744 | 1741 | |
1742 | /* For all Global Entries flagged "local-translate", unset APPROVED */ | |
1743 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1744 | zlog_debug ("ospf_abr_nssa_task(): unapprove translates"); |
718e3744 | 1745 | |
147193a2 | 1746 | ospf_abr_unapprove_translates (ospf); |
718e3744 | 1747 | |
1748 | /* RESET all Ranges in every Area, same as summaries */ | |
1749 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1750 | zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates"); |
e2c6c153 | 1751 | ospf_abr_prepare_aggregates (ospf); /*TURNED OFF just for now */ |
718e3744 | 1752 | |
1753 | /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or | |
e2c6c153 | 1754 | * Aggregate as Type-7 |
1755 | * Install or Approve in Type-5 Global LSDB | |
1756 | */ | |
718e3744 | 1757 | if (IS_DEBUG_OSPF_NSSA) |
e84cc647 | 1758 | zlog_debug ("ospf_abr_nssa_task(): process translates"); |
147193a2 | 1759 | ospf_abr_process_nssa_translates (ospf); |
718e3744 | 1760 | |
1761 | /* Translate/Send any "ranged" aggregates, and also 5-Install and | |
e2c6c153 | 1762 | * Approve |
1763 | * Scan Type-7's for aggregates, translate to Type-5's, | |
1764 | * Install/Flood/Approve | |
1765 | */ | |
718e3744 | 1766 | if (IS_DEBUG_OSPF_NSSA) |
e84cc647 | 1767 | zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates"); |
e2c6c153 | 1768 | ospf_abr_send_nssa_aggregates (ospf); /*TURNED OFF FOR NOW */ |
718e3744 | 1769 | |
d4a53d58 | 1770 | /* Send any NSSA defaults as Type-5 |
1771 | *if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1772 | * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults"); |
d4a53d58 | 1773 | *ospf_abr_announce_nssa_defaults (ospf); |
1774 | * havnt a clue what above is supposed to do. | |
1775 | */ | |
718e3744 | 1776 | |
1777 | /* Flush any unapproved previous translates from Global Data Base */ | |
1778 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1779 | zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates"); |
147193a2 | 1780 | ospf_abr_remove_unapproved_translates (ospf); |
718e3744 | 1781 | |
147193a2 | 1782 | ospf_abr_manage_discard_routes (ospf); /* same as normal...discard */ |
718e3744 | 1783 | |
1784 | if (IS_DEBUG_OSPF_NSSA) | |
e84cc647 | 1785 | zlog_debug ("ospf_abr_nssa_task(): Stop"); |
718e3744 | 1786 | } |
718e3744 | 1787 | |
1788 | /* This is the function taking care about ABR stuff, i.e. | |
1789 | summary-LSA origination and flooding. */ | |
1790 | void | |
147193a2 | 1791 | ospf_abr_task (struct ospf *ospf) |
718e3744 | 1792 | { |
1793 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1794 | zlog_debug ("ospf_abr_task(): Start"); |
718e3744 | 1795 | |
147193a2 | 1796 | if (ospf->new_table == NULL || ospf->new_rtrs == NULL) |
718e3744 | 1797 | { |
1798 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1799 | zlog_debug ("ospf_abr_task(): Routing tables are not yet ready"); |
718e3744 | 1800 | return; |
1801 | } | |
1802 | ||
1803 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1804 | zlog_debug ("ospf_abr_task(): unapprove summaries"); |
147193a2 | 1805 | ospf_abr_unapprove_summaries (ospf); |
718e3744 | 1806 | |
1807 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1808 | zlog_debug ("ospf_abr_task(): prepare aggregates"); |
147193a2 | 1809 | ospf_abr_prepare_aggregates (ospf); |
718e3744 | 1810 | |
147193a2 | 1811 | if (IS_OSPF_ABR (ospf)) |
718e3744 | 1812 | { |
1813 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1814 | zlog_debug ("ospf_abr_task(): process network RT"); |
147193a2 | 1815 | ospf_abr_process_network_rt (ospf, ospf->new_table); |
718e3744 | 1816 | |
1817 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1818 | zlog_debug ("ospf_abr_task(): process router RT"); |
147193a2 | 1819 | ospf_abr_process_router_rt (ospf, ospf->new_rtrs); |
718e3744 | 1820 | |
1821 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1822 | zlog_debug ("ospf_abr_task(): announce aggregates"); |
147193a2 | 1823 | ospf_abr_announce_aggregates (ospf); |
718e3744 | 1824 | |
1825 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1826 | zlog_debug ("ospf_abr_task(): announce stub defaults"); |
147193a2 | 1827 | ospf_abr_announce_stub_defaults (ospf); |
718e3744 | 1828 | } |
1829 | ||
1830 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1831 | zlog_debug ("ospf_abr_task(): remove unapproved summaries"); |
147193a2 | 1832 | ospf_abr_remove_unapproved_summaries (ospf); |
718e3744 | 1833 | |
147193a2 | 1834 | ospf_abr_manage_discard_routes (ospf); |
718e3744 | 1835 | |
718e3744 | 1836 | if (IS_DEBUG_OSPF_EVENT) |
e84cc647 | 1837 | zlog_debug ("ospf_abr_task(): Stop"); |
718e3744 | 1838 | } |
1839 | ||
4dadc291 | 1840 | static int |
147193a2 | 1841 | ospf_abr_task_timer (struct thread *thread) |
718e3744 | 1842 | { |
147193a2 | 1843 | struct ospf *ospf = THREAD_ARG (thread); |
1844 | ||
1845 | ospf->t_abr_task = 0; | |
718e3744 | 1846 | |
1847 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1848 | zlog_debug ("Running ABR task on timer"); |
718e3744 | 1849 | |
147193a2 | 1850 | ospf_check_abr_status (ospf); |
d4a53d58 | 1851 | ospf_abr_nssa_check_status (ospf); |
718e3744 | 1852 | |
147193a2 | 1853 | ospf_abr_task (ospf); |
e2c6c153 | 1854 | ospf_abr_nssa_task (ospf); /* if nssa-abr, then scan Type-7 LSDB */ |
718e3744 | 1855 | |
147193a2 | 1856 | return 0; |
718e3744 | 1857 | } |
1858 | ||
1859 | void | |
147193a2 | 1860 | ospf_schedule_abr_task (struct ospf *ospf) |
718e3744 | 1861 | { |
1862 | if (IS_DEBUG_OSPF_EVENT) | |
e84cc647 | 1863 | zlog_debug ("Scheduling ABR task"); |
147193a2 | 1864 | |
1865 | if (ospf->t_abr_task == NULL) | |
1866 | ospf->t_abr_task = thread_add_timer (master, ospf_abr_task_timer, | |
1867 | ospf, OSPF_ABR_TASK_DELAY); | |
718e3744 | 1868 | } |