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