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