]>
Commit | Line | Data |
---|---|---|
eb5d44eb | 1 | /* |
2 | * IS-IS Rout(e)ing protocol - isis_route.c | |
3 | * Copyright (C) 2001,2002 Sampo Saaristo | |
d62a17ae | 4 | * Tampere University of Technology |
eb5d44eb | 5 | * Institute of Communications Engineering |
6 | * | |
7 | * based on ../ospf6d/ospf6_route.[ch] | |
8 | * by Yasuhiro Ohara | |
9 | * | |
d62a17ae | 10 | * This program is free software; you can redistribute it and/or modify it |
11 | * under the terms of the GNU General Public Licenseas published by the Free | |
12 | * Software Foundation; either version 2 of the License, or (at your option) | |
eb5d44eb | 13 | * any later version. |
14 | * | |
d62a17ae | 15 | * This program is distributed in the hope that it will be useful,but WITHOUT |
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
eb5d44eb | 18 | * more details. |
896014f4 DL |
19 | * |
20 | * You should have received a copy of the GNU General Public License along | |
21 | * with this program; see the file COPYING; if not, write to the Free Software | |
22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
eb5d44eb | 23 | */ |
24 | ||
eb5d44eb | 25 | #include <zebra.h> |
eb5d44eb | 26 | |
27 | #include "thread.h" | |
28 | #include "linklist.h" | |
29 | #include "vty.h" | |
30 | #include "log.h" | |
31 | #include "memory.h" | |
32 | #include "prefix.h" | |
33 | #include "hash.h" | |
34 | #include "if.h" | |
35 | #include "table.h" | |
36 | ||
37 | #include "isis_constants.h" | |
38 | #include "isis_common.h" | |
3f045a08 | 39 | #include "isis_flags.h" |
eb5d44eb | 40 | #include "dict.h" |
41 | #include "isisd.h" | |
42 | #include "isis_misc.h" | |
43 | #include "isis_adjacency.h" | |
44 | #include "isis_circuit.h" | |
eb5d44eb | 45 | #include "isis_pdu.h" |
46 | #include "isis_lsp.h" | |
47 | #include "isis_spf.h" | |
48 | #include "isis_route.h" | |
49 | #include "isis_zebra.h" | |
50 | ||
d62a17ae | 51 | static struct isis_nexthop *isis_nexthop_create(struct in_addr *ip, |
52 | ifindex_t ifindex) | |
eb5d44eb | 53 | { |
d62a17ae | 54 | struct listnode *node; |
55 | struct isis_nexthop *nexthop; | |
f390d2c7 | 56 | |
d62a17ae | 57 | for (ALL_LIST_ELEMENTS_RO(isis->nexthops, node, nexthop)) { |
58 | if (nexthop->ifindex != ifindex) | |
59 | continue; | |
60 | if (ip && memcmp(&nexthop->ip, ip, sizeof(struct in_addr)) != 0) | |
61 | continue; | |
f390d2c7 | 62 | |
d62a17ae | 63 | nexthop->lock++; |
64 | return nexthop; | |
65 | } | |
f390d2c7 | 66 | |
d62a17ae | 67 | nexthop = XCALLOC(MTYPE_ISIS_NEXTHOP, sizeof(struct isis_nexthop)); |
f390d2c7 | 68 | |
d62a17ae | 69 | nexthop->ifindex = ifindex; |
70 | memcpy(&nexthop->ip, ip, sizeof(struct in_addr)); | |
71 | listnode_add(isis->nexthops, nexthop); | |
72 | nexthop->lock++; | |
eb5d44eb | 73 | |
d62a17ae | 74 | return nexthop; |
eb5d44eb | 75 | } |
76 | ||
d62a17ae | 77 | static void isis_nexthop_delete(struct isis_nexthop *nexthop) |
eb5d44eb | 78 | { |
d62a17ae | 79 | nexthop->lock--; |
80 | if (nexthop->lock == 0) { | |
81 | listnode_delete(isis->nexthops, nexthop); | |
82 | XFREE(MTYPE_ISIS_NEXTHOP, nexthop); | |
83 | } | |
84 | ||
85 | return; | |
eb5d44eb | 86 | } |
87 | ||
d62a17ae | 88 | static int nexthoplookup(struct list *nexthops, struct in_addr *ip, |
89 | ifindex_t ifindex) | |
eb5d44eb | 90 | { |
d62a17ae | 91 | struct listnode *node; |
92 | struct isis_nexthop *nh; | |
eb5d44eb | 93 | |
d62a17ae | 94 | for (ALL_LIST_ELEMENTS_RO(nexthops, node, nh)) { |
95 | if (!(memcmp(ip, &nh->ip, sizeof(struct in_addr))) | |
96 | && ifindex == nh->ifindex) | |
97 | return 1; | |
98 | } | |
eb5d44eb | 99 | |
d62a17ae | 100 | return 0; |
eb5d44eb | 101 | } |
102 | ||
3d549276 | 103 | #ifdef EXTREME_DEBUG |
d62a17ae | 104 | static void nexthop_print(struct isis_nexthop *nh) |
eb5d44eb | 105 | { |
d62a17ae | 106 | u_char buf[BUFSIZ]; |
f390d2c7 | 107 | |
d62a17ae | 108 | inet_ntop(AF_INET, &nh->ip, (char *)buf, BUFSIZ); |
f390d2c7 | 109 | |
d62a17ae | 110 | zlog_debug(" %s %u", buf, nh->ifindex); |
eb5d44eb | 111 | } |
112 | ||
d62a17ae | 113 | static void nexthops_print(struct list *nhs) |
eb5d44eb | 114 | { |
d62a17ae | 115 | struct listnode *node; |
116 | struct isis_nexthop *nh; | |
f390d2c7 | 117 | |
d62a17ae | 118 | for (ALL_LIST_ELEMENTS_RO(nhs, node, nh)) |
119 | nexthop_print(nh); | |
eb5d44eb | 120 | } |
3d549276 | 121 | #endif /* EXTREME_DEBUG */ |
eb5d44eb | 122 | |
d62a17ae | 123 | static struct isis_nexthop6 *isis_nexthop6_new(struct in6_addr *ip6, |
124 | ifindex_t ifindex) | |
eb5d44eb | 125 | { |
d62a17ae | 126 | struct isis_nexthop6 *nexthop6; |
f390d2c7 | 127 | |
d62a17ae | 128 | nexthop6 = XCALLOC(MTYPE_ISIS_NEXTHOP6, sizeof(struct isis_nexthop6)); |
f390d2c7 | 129 | |
d62a17ae | 130 | nexthop6->ifindex = ifindex; |
131 | memcpy(&nexthop6->ip6, ip6, sizeof(struct in6_addr)); | |
132 | nexthop6->lock++; | |
eb5d44eb | 133 | |
d62a17ae | 134 | return nexthop6; |
eb5d44eb | 135 | } |
136 | ||
d62a17ae | 137 | static struct isis_nexthop6 *isis_nexthop6_create(struct in6_addr *ip6, |
138 | ifindex_t ifindex) | |
eb5d44eb | 139 | { |
d62a17ae | 140 | struct listnode *node; |
141 | struct isis_nexthop6 *nexthop6; | |
142 | ||
143 | for (ALL_LIST_ELEMENTS_RO(isis->nexthops6, node, nexthop6)) { | |
144 | if (nexthop6->ifindex != ifindex) | |
145 | continue; | |
146 | if (ip6 | |
147 | && memcmp(&nexthop6->ip6, ip6, sizeof(struct in6_addr)) | |
148 | != 0) | |
149 | continue; | |
150 | ||
151 | nexthop6->lock++; | |
152 | return nexthop6; | |
153 | } | |
f390d2c7 | 154 | |
d62a17ae | 155 | nexthop6 = isis_nexthop6_new(ip6, ifindex); |
eb5d44eb | 156 | |
d62a17ae | 157 | return nexthop6; |
eb5d44eb | 158 | } |
159 | ||
d62a17ae | 160 | static void isis_nexthop6_delete(struct isis_nexthop6 *nexthop6) |
eb5d44eb | 161 | { |
162 | ||
d62a17ae | 163 | nexthop6->lock--; |
164 | if (nexthop6->lock == 0) { | |
165 | listnode_delete(isis->nexthops6, nexthop6); | |
166 | XFREE(MTYPE_ISIS_NEXTHOP6, nexthop6); | |
167 | } | |
f390d2c7 | 168 | |
d62a17ae | 169 | return; |
eb5d44eb | 170 | } |
171 | ||
d62a17ae | 172 | static int nexthop6lookup(struct list *nexthops6, struct in6_addr *ip6, |
173 | ifindex_t ifindex) | |
eb5d44eb | 174 | { |
d62a17ae | 175 | struct listnode *node; |
176 | struct isis_nexthop6 *nh6; | |
eb5d44eb | 177 | |
d62a17ae | 178 | for (ALL_LIST_ELEMENTS_RO(nexthops6, node, nh6)) { |
179 | if (!(memcmp(ip6, &nh6->ip6, sizeof(struct in6_addr))) | |
180 | && ifindex == nh6->ifindex) | |
181 | return 1; | |
182 | } | |
eb5d44eb | 183 | |
d62a17ae | 184 | return 0; |
eb5d44eb | 185 | } |
186 | ||
92365889 | 187 | #ifdef EXTREME_DEBUG |
d62a17ae | 188 | static void nexthop6_print(struct isis_nexthop6 *nh6) |
eb5d44eb | 189 | { |
d62a17ae | 190 | u_char buf[BUFSIZ]; |
f390d2c7 | 191 | |
d62a17ae | 192 | inet_ntop(AF_INET6, &nh6->ip6, (char *)buf, BUFSIZ); |
f390d2c7 | 193 | |
d62a17ae | 194 | zlog_debug(" %s %u", buf, nh6->ifindex); |
eb5d44eb | 195 | } |
196 | ||
d62a17ae | 197 | static void nexthops6_print(struct list *nhs6) |
eb5d44eb | 198 | { |
d62a17ae | 199 | struct listnode *node; |
200 | struct isis_nexthop6 *nh6; | |
f390d2c7 | 201 | |
d62a17ae | 202 | for (ALL_LIST_ELEMENTS_RO(nhs6, node, nh6)) |
203 | nexthop6_print(nh6); | |
eb5d44eb | 204 | } |
92365889 | 205 | #endif /* EXTREME_DEBUG */ |
eb5d44eb | 206 | |
d62a17ae | 207 | static void adjinfo2nexthop(struct list *nexthops, struct isis_adjacency *adj) |
eb5d44eb | 208 | { |
d62a17ae | 209 | struct isis_nexthop *nh; |
d62a17ae | 210 | |
0c1bd758 | 211 | if (!adj->ipv4_address_count) |
d62a17ae | 212 | return; |
213 | ||
0c1bd758 CF |
214 | for (unsigned int i = 0; i < adj->ipv4_address_count; i++) { |
215 | struct in_addr *ipv4_addr = &adj->ipv4_addresses[i]; | |
d62a17ae | 216 | if (!nexthoplookup(nexthops, ipv4_addr, |
217 | adj->circuit->interface->ifindex)) { | |
218 | nh = isis_nexthop_create( | |
219 | ipv4_addr, adj->circuit->interface->ifindex); | |
220 | nh->router_address = adj->router_address; | |
221 | listnode_add(nexthops, nh); | |
222 | } | |
f390d2c7 | 223 | } |
eb5d44eb | 224 | } |
225 | ||
d62a17ae | 226 | static void adjinfo2nexthop6(struct list *nexthops6, struct isis_adjacency *adj) |
eb5d44eb | 227 | { |
d62a17ae | 228 | struct isis_nexthop6 *nh6; |
229 | ||
0c1bd758 | 230 | if (!adj->ipv6_address_count) |
d62a17ae | 231 | return; |
232 | ||
0c1bd758 CF |
233 | for (unsigned int i = 0; i < adj->ipv6_address_count; i++) { |
234 | struct in6_addr *ipv6_addr = &adj->ipv6_addresses[i]; | |
d62a17ae | 235 | if (!nexthop6lookup(nexthops6, ipv6_addr, |
236 | adj->circuit->interface->ifindex)) { | |
237 | nh6 = isis_nexthop6_create( | |
238 | ipv6_addr, adj->circuit->interface->ifindex); | |
239 | nh6->router_address6 = adj->router_address6; | |
240 | listnode_add(nexthops6, nh6); | |
241 | } | |
f390d2c7 | 242 | } |
eb5d44eb | 243 | } |
eb5d44eb | 244 | |
d62a17ae | 245 | static struct isis_route_info *isis_route_info_new(struct prefix *prefix, |
246 | uint32_t cost, | |
247 | uint32_t depth, | |
248 | struct list *adjacencies) | |
eb5d44eb | 249 | { |
d62a17ae | 250 | struct isis_route_info *rinfo; |
251 | struct isis_adjacency *adj; | |
252 | struct listnode *node; | |
253 | ||
254 | rinfo = XCALLOC(MTYPE_ISIS_ROUTE_INFO, sizeof(struct isis_route_info)); | |
255 | ||
256 | if (prefix->family == AF_INET) { | |
257 | rinfo->nexthops = list_new(); | |
258 | for (ALL_LIST_ELEMENTS_RO(adjacencies, node, adj)) { | |
259 | /* check for force resync this route */ | |
260 | if (CHECK_FLAG(adj->circuit->flags, | |
261 | ISIS_CIRCUIT_FLAPPED_AFTER_SPF)) | |
262 | SET_FLAG(rinfo->flag, | |
263 | ISIS_ROUTE_FLAG_ZEBRA_RESYNC); | |
264 | /* update neighbor router address */ | |
265 | if (depth == 2 && prefix->prefixlen == 32) | |
266 | adj->router_address = prefix->u.prefix4; | |
267 | adjinfo2nexthop(rinfo->nexthops, adj); | |
268 | } | |
269 | } | |
270 | if (prefix->family == AF_INET6) { | |
271 | rinfo->nexthops6 = list_new(); | |
272 | for (ALL_LIST_ELEMENTS_RO(adjacencies, node, adj)) { | |
273 | /* check for force resync this route */ | |
274 | if (CHECK_FLAG(adj->circuit->flags, | |
275 | ISIS_CIRCUIT_FLAPPED_AFTER_SPF)) | |
276 | SET_FLAG(rinfo->flag, | |
277 | ISIS_ROUTE_FLAG_ZEBRA_RESYNC); | |
278 | /* update neighbor router address */ | |
279 | if (depth == 2 && prefix->prefixlen == 128) | |
280 | adj->router_address6 = prefix->u.prefix6; | |
281 | adjinfo2nexthop6(rinfo->nexthops6, adj); | |
282 | } | |
283 | } | |
284 | ||
285 | rinfo->cost = cost; | |
286 | rinfo->depth = depth; | |
287 | ||
288 | return rinfo; | |
eb5d44eb | 289 | } |
290 | ||
d62a17ae | 291 | static void isis_route_info_delete(struct isis_route_info *route_info) |
eb5d44eb | 292 | { |
d62a17ae | 293 | if (route_info->nexthops) { |
294 | route_info->nexthops->del = | |
295 | (void (*)(void *))isis_nexthop_delete; | |
296 | list_delete(route_info->nexthops); | |
297 | } | |
298 | ||
299 | if (route_info->nexthops6) { | |
300 | route_info->nexthops6->del = | |
301 | (void (*)(void *))isis_nexthop6_delete; | |
302 | list_delete(route_info->nexthops6); | |
303 | } | |
304 | ||
305 | XFREE(MTYPE_ISIS_ROUTE_INFO, route_info); | |
eb5d44eb | 306 | } |
307 | ||
d62a17ae | 308 | static int isis_route_info_same_attrib(struct isis_route_info *new, |
309 | struct isis_route_info *old) | |
eb5d44eb | 310 | { |
d62a17ae | 311 | if (new->cost != old->cost) |
312 | return 0; | |
313 | if (new->depth != old->depth) | |
314 | return 0; | |
f390d2c7 | 315 | |
d62a17ae | 316 | return 1; |
eb5d44eb | 317 | } |
318 | ||
d62a17ae | 319 | static int isis_route_info_same(struct isis_route_info *new, |
320 | struct isis_route_info *old, u_char family) | |
eb5d44eb | 321 | { |
d62a17ae | 322 | struct listnode *node; |
323 | struct isis_nexthop *nexthop; | |
324 | struct isis_nexthop6 *nexthop6; | |
325 | ||
326 | if (!CHECK_FLAG(old->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) | |
327 | return 0; | |
328 | ||
329 | if (CHECK_FLAG(new->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC)) | |
330 | return 0; | |
331 | ||
332 | if (!isis_route_info_same_attrib(new, old)) | |
333 | return 0; | |
334 | ||
335 | if (family == AF_INET) { | |
336 | for (ALL_LIST_ELEMENTS_RO(new->nexthops, node, nexthop)) | |
337 | if (nexthoplookup(old->nexthops, &nexthop->ip, | |
338 | nexthop->ifindex) | |
339 | == 0) | |
340 | return 0; | |
341 | ||
342 | for (ALL_LIST_ELEMENTS_RO(old->nexthops, node, nexthop)) | |
343 | if (nexthoplookup(new->nexthops, &nexthop->ip, | |
344 | nexthop->ifindex) | |
345 | == 0) | |
346 | return 0; | |
347 | } else if (family == AF_INET6) { | |
348 | for (ALL_LIST_ELEMENTS_RO(new->nexthops6, node, nexthop6)) | |
349 | if (nexthop6lookup(old->nexthops6, &nexthop6->ip6, | |
350 | nexthop6->ifindex) | |
351 | == 0) | |
352 | return 0; | |
353 | ||
354 | for (ALL_LIST_ELEMENTS_RO(old->nexthops6, node, nexthop6)) | |
355 | if (nexthop6lookup(new->nexthops6, &nexthop6->ip6, | |
356 | nexthop6->ifindex) | |
357 | == 0) | |
358 | return 0; | |
359 | } | |
360 | ||
361 | return 1; | |
eb5d44eb | 362 | } |
363 | ||
d62a17ae | 364 | struct isis_route_info *isis_route_create(struct prefix *prefix, u_int32_t cost, |
365 | u_int32_t depth, | |
366 | struct list *adjacencies, | |
367 | struct isis_area *area, int level) | |
eb5d44eb | 368 | { |
d62a17ae | 369 | struct route_node *route_node; |
370 | struct isis_route_info *rinfo_new, *rinfo_old, *route_info = NULL; | |
371 | char buff[PREFIX2STR_BUFFER]; | |
372 | u_char family; | |
373 | ||
374 | family = prefix->family; | |
375 | /* for debugs */ | |
376 | prefix2str(prefix, buff, sizeof(buff)); | |
377 | ||
378 | rinfo_new = isis_route_info_new(prefix, cost, depth, adjacencies); | |
379 | ||
380 | if (family == AF_INET) | |
381 | route_node = | |
382 | route_node_get(area->route_table[level - 1], prefix); | |
383 | else if (family == AF_INET6) | |
384 | route_node = | |
385 | route_node_get(area->route_table6[level - 1], prefix); | |
386 | else { | |
387 | isis_route_info_delete(rinfo_new); | |
388 | return NULL; | |
389 | } | |
390 | ||
391 | rinfo_old = route_node->info; | |
392 | if (!rinfo_old) { | |
393 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
394 | zlog_debug("ISIS-Rte (%s) route created: %s", | |
395 | area->area_tag, buff); | |
396 | route_info = rinfo_new; | |
397 | UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); | |
398 | } else { | |
399 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
400 | zlog_debug("ISIS-Rte (%s) route already exists: %s", | |
401 | area->area_tag, buff); | |
402 | if (isis_route_info_same(rinfo_new, rinfo_old, family)) { | |
403 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
404 | zlog_debug("ISIS-Rte (%s) route unchanged: %s", | |
405 | area->area_tag, buff); | |
406 | isis_route_info_delete(rinfo_new); | |
407 | route_info = rinfo_old; | |
408 | } else { | |
409 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
410 | zlog_debug("ISIS-Rte (%s) route changed: %s", | |
411 | area->area_tag, buff); | |
412 | isis_route_info_delete(rinfo_old); | |
413 | route_info = rinfo_new; | |
414 | UNSET_FLAG(route_info->flag, | |
415 | ISIS_ROUTE_FLAG_ZEBRA_SYNCED); | |
416 | } | |
417 | } | |
418 | ||
419 | SET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ACTIVE); | |
420 | route_node->info = route_info; | |
421 | ||
422 | return route_info; | |
eb5d44eb | 423 | } |
424 | ||
d62a17ae | 425 | static void isis_route_delete(struct prefix *prefix, struct route_table *table) |
eb5d44eb | 426 | { |
d62a17ae | 427 | struct route_node *rode; |
428 | struct isis_route_info *rinfo; | |
429 | char buff[PREFIX2STR_BUFFER]; | |
430 | ||
431 | /* for log */ | |
432 | prefix2str(prefix, buff, sizeof(buff)); | |
433 | ||
434 | ||
435 | rode = route_node_get(table, prefix); | |
436 | rinfo = rode->info; | |
437 | ||
438 | if (rinfo == NULL) { | |
439 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
440 | zlog_debug( | |
441 | "ISIS-Rte: tried to delete non-existant route %s", | |
442 | buff); | |
443 | return; | |
444 | } | |
445 | ||
446 | if (CHECK_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) { | |
447 | UNSET_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE); | |
448 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
449 | zlog_debug("ISIS-Rte: route delete %s", buff); | |
450 | isis_zebra_route_update(prefix, rinfo); | |
451 | } | |
452 | isis_route_info_delete(rinfo); | |
453 | rode->info = NULL; | |
454 | ||
455 | return; | |
eb5d44eb | 456 | } |
457 | ||
fac1f7cc | 458 | /* Validating routes in particular table. */ |
d62a17ae | 459 | static void isis_route_validate_table(struct isis_area *area, |
460 | struct route_table *table) | |
eb5d44eb | 461 | { |
d62a17ae | 462 | struct route_node *rnode, *drnode; |
463 | struct isis_route_info *rinfo; | |
464 | char buff[PREFIX2STR_BUFFER]; | |
465 | ||
466 | for (rnode = route_top(table); rnode; rnode = route_next(rnode)) { | |
467 | if (rnode->info == NULL) | |
468 | continue; | |
469 | rinfo = rnode->info; | |
470 | ||
471 | if (isis->debugs & DEBUG_RTE_EVENTS) { | |
472 | prefix2str(&rnode->p, buff, sizeof(buff)); | |
473 | zlog_debug( | |
474 | "ISIS-Rte (%s): route validate: %s %s %s %s", | |
475 | area->area_tag, | |
476 | (CHECK_FLAG(rinfo->flag, | |
477 | ISIS_ROUTE_FLAG_ZEBRA_SYNCED) | |
478 | ? "synced" | |
479 | : "not-synced"), | |
480 | (CHECK_FLAG(rinfo->flag, | |
481 | ISIS_ROUTE_FLAG_ZEBRA_RESYNC) | |
482 | ? "resync" | |
483 | : "not-resync"), | |
484 | (CHECK_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE) | |
485 | ? "active" | |
486 | : "inactive"), | |
487 | buff); | |
488 | } | |
489 | ||
490 | isis_zebra_route_update(&rnode->p, rinfo); | |
491 | if (!CHECK_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE)) { | |
492 | /* Area is either L1 or L2 => we use level route tables | |
493 | * directly for | |
494 | * validating => no problems with deleting routes. */ | |
495 | if (area->is_type != IS_LEVEL_1_AND_2) { | |
496 | isis_route_delete(&rnode->p, table); | |
497 | continue; | |
498 | } | |
499 | /* If area is L1L2, we work with merge table and | |
500 | * therefore must | |
501 | * delete node from level tables as well before deleting | |
502 | * route info. | |
503 | * FIXME: Is it performance problem? There has to be the | |
504 | * better way. | |
505 | * Like not to deal with it here at all (see the next | |
506 | * comment)? */ | |
507 | if (rnode->p.family == AF_INET) { | |
508 | drnode = route_node_get(area->route_table[0], | |
509 | &rnode->p); | |
510 | if (drnode->info == rnode->info) | |
511 | drnode->info = NULL; | |
512 | drnode = route_node_get(area->route_table[1], | |
513 | &rnode->p); | |
514 | if (drnode->info == rnode->info) | |
515 | drnode->info = NULL; | |
516 | } | |
517 | ||
518 | if (rnode->p.family == AF_INET6) { | |
519 | drnode = route_node_get(area->route_table6[0], | |
520 | &rnode->p); | |
521 | if (drnode->info == rnode->info) | |
522 | drnode->info = NULL; | |
523 | drnode = route_node_get(area->route_table6[1], | |
524 | &rnode->p); | |
525 | if (drnode->info == rnode->info) | |
526 | drnode->info = NULL; | |
527 | } | |
528 | ||
529 | isis_route_delete(&rnode->p, table); | |
530 | } | |
f390d2c7 | 531 | } |
fac1f7cc | 532 | } |
533 | ||
534 | /* Function to validate route tables for L1L2 areas. In this case we can't use | |
535 | * level route tables directly, we have to merge them at first. L1 routes are | |
536 | * preferred over the L2 ones. | |
537 | * | |
538 | * Merge algorithm is trivial (at least for now). All L1 paths are copied into | |
539 | * merge table at first, then L2 paths are added if L1 path for same prefix | |
540 | * doesn't already exists there. | |
541 | * | |
542 | * FIXME: Is it right place to do it at all? Maybe we should push both levels | |
543 | * to the RIB with different zebra route types and let RIB handle this? */ | |
d62a17ae | 544 | static void isis_route_validate_merge(struct isis_area *area, int family) |
fac1f7cc | 545 | { |
d62a17ae | 546 | struct route_table *table = NULL; |
547 | struct route_table *merge; | |
548 | struct route_node *rnode, *mrnode; | |
549 | ||
550 | merge = route_table_init(); | |
551 | ||
552 | if (family == AF_INET) | |
553 | table = area->route_table[0]; | |
554 | else if (family == AF_INET6) | |
555 | table = area->route_table6[0]; | |
556 | else { | |
557 | zlog_warn("ISIS-Rte (%s) %s called for unknown family %d", | |
558 | area->area_tag, __func__, family); | |
559 | route_table_finish(merge); | |
560 | return; | |
561 | } | |
562 | ||
563 | for (rnode = route_top(table); rnode; rnode = route_next(rnode)) { | |
564 | if (rnode->info == NULL) | |
565 | continue; | |
566 | mrnode = route_node_get(merge, &rnode->p); | |
567 | mrnode->info = rnode->info; | |
568 | } | |
569 | ||
570 | if (family == AF_INET) | |
571 | table = area->route_table[1]; | |
572 | else if (family == AF_INET6) | |
573 | table = area->route_table6[1]; | |
574 | ||
575 | for (rnode = route_top(table); rnode; rnode = route_next(rnode)) { | |
576 | if (rnode->info == NULL) | |
577 | continue; | |
578 | mrnode = route_node_get(merge, &rnode->p); | |
579 | if (mrnode->info != NULL) | |
580 | continue; | |
581 | mrnode->info = rnode->info; | |
582 | } | |
583 | ||
584 | isis_route_validate_table(area, merge); | |
585 | route_table_finish(merge); | |
fac1f7cc | 586 | } |
587 | ||
588 | /* Walk through route tables and propagate necessary changes into RIB. In case | |
589 | * of L1L2 area, level tables have to be merged at first. */ | |
d62a17ae | 590 | void isis_route_validate(struct isis_area *area) |
fac1f7cc | 591 | { |
d62a17ae | 592 | struct listnode *node; |
593 | struct isis_circuit *circuit; | |
594 | ||
595 | if (area->is_type == IS_LEVEL_1) | |
596 | isis_route_validate_table(area, area->route_table[0]); | |
597 | else if (area->is_type == IS_LEVEL_2) | |
598 | isis_route_validate_table(area, area->route_table[1]); | |
599 | else | |
600 | isis_route_validate_merge(area, AF_INET); | |
601 | ||
602 | if (area->is_type == IS_LEVEL_1) | |
603 | isis_route_validate_table(area, area->route_table6[0]); | |
604 | else if (area->is_type == IS_LEVEL_2) | |
605 | isis_route_validate_table(area, area->route_table6[1]); | |
606 | else | |
607 | isis_route_validate_merge(area, AF_INET6); | |
608 | ||
609 | if (!area->circuit_list) { | |
610 | return; | |
611 | } | |
612 | /* walk all circuits and reset any spf specific flags */ | |
613 | for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit)) | |
614 | UNSET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF); | |
615 | ||
616 | return; | |
3f045a08 JB |
617 | } |
618 | ||
d62a17ae | 619 | void isis_route_invalidate_table(struct isis_area *area, |
620 | struct route_table *table) | |
3f045a08 | 621 | { |
d62a17ae | 622 | struct route_node *rode; |
623 | struct isis_route_info *rinfo; | |
624 | for (rode = route_top(table); rode; rode = route_next(rode)) { | |
625 | if (rode->info == NULL) | |
626 | continue; | |
627 | rinfo = rode->info; | |
628 | ||
629 | UNSET_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE); | |
630 | } | |
3f045a08 | 631 | } |
eb5d44eb | 632 | |
d62a17ae | 633 | void isis_route_invalidate(struct isis_area *area) |
3f045a08 | 634 | { |
d62a17ae | 635 | if (area->is_type & IS_LEVEL_1) |
636 | isis_route_invalidate_table(area, area->route_table[0]); | |
637 | if (area->is_type & IS_LEVEL_2) | |
638 | isis_route_invalidate_table(area, area->route_table[1]); | |
eb5d44eb | 639 | } |