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