]>
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" | |
321c1bbb | 36 | #include "srcdest_table.h" |
eb5d44eb | 37 | |
38 | #include "isis_constants.h" | |
39 | #include "isis_common.h" | |
3f045a08 | 40 | #include "isis_flags.h" |
eb5d44eb | 41 | #include "dict.h" |
42 | #include "isisd.h" | |
43 | #include "isis_misc.h" | |
44 | #include "isis_adjacency.h" | |
45 | #include "isis_circuit.h" | |
eb5d44eb | 46 | #include "isis_pdu.h" |
47 | #include "isis_lsp.h" | |
48 | #include "isis_spf.h" | |
49 | #include "isis_route.h" | |
50 | #include "isis_zebra.h" | |
51 | ||
d62a17ae | 52 | static struct isis_nexthop *isis_nexthop_create(struct in_addr *ip, |
53 | ifindex_t ifindex) | |
eb5d44eb | 54 | { |
d62a17ae | 55 | struct listnode *node; |
56 | struct isis_nexthop *nexthop; | |
f390d2c7 | 57 | |
d62a17ae | 58 | for (ALL_LIST_ELEMENTS_RO(isis->nexthops, node, nexthop)) { |
59 | if (nexthop->ifindex != ifindex) | |
60 | continue; | |
61 | if (ip && memcmp(&nexthop->ip, ip, sizeof(struct in_addr)) != 0) | |
62 | continue; | |
f390d2c7 | 63 | |
d62a17ae | 64 | nexthop->lock++; |
65 | return nexthop; | |
66 | } | |
f390d2c7 | 67 | |
d62a17ae | 68 | nexthop = XCALLOC(MTYPE_ISIS_NEXTHOP, sizeof(struct isis_nexthop)); |
f390d2c7 | 69 | |
d62a17ae | 70 | nexthop->ifindex = ifindex; |
71 | memcpy(&nexthop->ip, ip, sizeof(struct in_addr)); | |
72 | listnode_add(isis->nexthops, nexthop); | |
73 | nexthop->lock++; | |
eb5d44eb | 74 | |
d62a17ae | 75 | return nexthop; |
eb5d44eb | 76 | } |
77 | ||
d62a17ae | 78 | static void isis_nexthop_delete(struct isis_nexthop *nexthop) |
eb5d44eb | 79 | { |
d62a17ae | 80 | nexthop->lock--; |
81 | if (nexthop->lock == 0) { | |
82 | listnode_delete(isis->nexthops, nexthop); | |
83 | XFREE(MTYPE_ISIS_NEXTHOP, nexthop); | |
84 | } | |
85 | ||
86 | return; | |
eb5d44eb | 87 | } |
88 | ||
d62a17ae | 89 | static int nexthoplookup(struct list *nexthops, struct in_addr *ip, |
90 | ifindex_t ifindex) | |
eb5d44eb | 91 | { |
d62a17ae | 92 | struct listnode *node; |
93 | struct isis_nexthop *nh; | |
eb5d44eb | 94 | |
d62a17ae | 95 | for (ALL_LIST_ELEMENTS_RO(nexthops, node, nh)) { |
96 | if (!(memcmp(ip, &nh->ip, sizeof(struct in_addr))) | |
97 | && ifindex == nh->ifindex) | |
98 | return 1; | |
99 | } | |
eb5d44eb | 100 | |
d62a17ae | 101 | return 0; |
eb5d44eb | 102 | } |
103 | ||
d62a17ae | 104 | static struct isis_nexthop6 *isis_nexthop6_new(struct in6_addr *ip6, |
105 | ifindex_t ifindex) | |
eb5d44eb | 106 | { |
d62a17ae | 107 | struct isis_nexthop6 *nexthop6; |
f390d2c7 | 108 | |
d62a17ae | 109 | nexthop6 = XCALLOC(MTYPE_ISIS_NEXTHOP6, sizeof(struct isis_nexthop6)); |
f390d2c7 | 110 | |
d62a17ae | 111 | nexthop6->ifindex = ifindex; |
112 | memcpy(&nexthop6->ip6, ip6, sizeof(struct in6_addr)); | |
113 | nexthop6->lock++; | |
eb5d44eb | 114 | |
d62a17ae | 115 | return nexthop6; |
eb5d44eb | 116 | } |
117 | ||
d62a17ae | 118 | static struct isis_nexthop6 *isis_nexthop6_create(struct in6_addr *ip6, |
119 | ifindex_t ifindex) | |
eb5d44eb | 120 | { |
d62a17ae | 121 | struct listnode *node; |
122 | struct isis_nexthop6 *nexthop6; | |
123 | ||
124 | for (ALL_LIST_ELEMENTS_RO(isis->nexthops6, node, nexthop6)) { | |
125 | if (nexthop6->ifindex != ifindex) | |
126 | continue; | |
127 | if (ip6 | |
128 | && memcmp(&nexthop6->ip6, ip6, sizeof(struct in6_addr)) | |
129 | != 0) | |
130 | continue; | |
131 | ||
132 | nexthop6->lock++; | |
133 | return nexthop6; | |
134 | } | |
f390d2c7 | 135 | |
d62a17ae | 136 | nexthop6 = isis_nexthop6_new(ip6, ifindex); |
eb5d44eb | 137 | |
d62a17ae | 138 | return nexthop6; |
eb5d44eb | 139 | } |
140 | ||
d62a17ae | 141 | static void isis_nexthop6_delete(struct isis_nexthop6 *nexthop6) |
eb5d44eb | 142 | { |
143 | ||
d62a17ae | 144 | nexthop6->lock--; |
145 | if (nexthop6->lock == 0) { | |
146 | listnode_delete(isis->nexthops6, nexthop6); | |
147 | XFREE(MTYPE_ISIS_NEXTHOP6, nexthop6); | |
148 | } | |
f390d2c7 | 149 | |
d62a17ae | 150 | return; |
eb5d44eb | 151 | } |
152 | ||
d62a17ae | 153 | static int nexthop6lookup(struct list *nexthops6, struct in6_addr *ip6, |
154 | ifindex_t ifindex) | |
eb5d44eb | 155 | { |
d62a17ae | 156 | struct listnode *node; |
157 | struct isis_nexthop6 *nh6; | |
eb5d44eb | 158 | |
d62a17ae | 159 | for (ALL_LIST_ELEMENTS_RO(nexthops6, node, nh6)) { |
160 | if (!(memcmp(ip6, &nh6->ip6, sizeof(struct in6_addr))) | |
161 | && ifindex == nh6->ifindex) | |
162 | return 1; | |
163 | } | |
eb5d44eb | 164 | |
d62a17ae | 165 | return 0; |
eb5d44eb | 166 | } |
167 | ||
d62a17ae | 168 | static void adjinfo2nexthop(struct list *nexthops, struct isis_adjacency *adj) |
eb5d44eb | 169 | { |
d62a17ae | 170 | struct isis_nexthop *nh; |
d62a17ae | 171 | |
0c1bd758 CF |
172 | for (unsigned int i = 0; i < adj->ipv4_address_count; i++) { |
173 | struct in_addr *ipv4_addr = &adj->ipv4_addresses[i]; | |
d62a17ae | 174 | if (!nexthoplookup(nexthops, ipv4_addr, |
175 | adj->circuit->interface->ifindex)) { | |
176 | nh = isis_nexthop_create( | |
177 | ipv4_addr, adj->circuit->interface->ifindex); | |
178 | nh->router_address = adj->router_address; | |
179 | listnode_add(nexthops, nh); | |
74361f41 | 180 | return; |
d62a17ae | 181 | } |
f390d2c7 | 182 | } |
eb5d44eb | 183 | } |
184 | ||
d62a17ae | 185 | static void adjinfo2nexthop6(struct list *nexthops6, struct isis_adjacency *adj) |
eb5d44eb | 186 | { |
d62a17ae | 187 | struct isis_nexthop6 *nh6; |
188 | ||
0c1bd758 CF |
189 | for (unsigned int i = 0; i < adj->ipv6_address_count; i++) { |
190 | struct in6_addr *ipv6_addr = &adj->ipv6_addresses[i]; | |
d62a17ae | 191 | if (!nexthop6lookup(nexthops6, ipv6_addr, |
192 | adj->circuit->interface->ifindex)) { | |
193 | nh6 = isis_nexthop6_create( | |
194 | ipv6_addr, adj->circuit->interface->ifindex); | |
195 | nh6->router_address6 = adj->router_address6; | |
196 | listnode_add(nexthops6, nh6); | |
74361f41 | 197 | return; |
d62a17ae | 198 | } |
f390d2c7 | 199 | } |
eb5d44eb | 200 | } |
eb5d44eb | 201 | |
d62a17ae | 202 | static struct isis_route_info *isis_route_info_new(struct prefix *prefix, |
321c1bbb | 203 | struct prefix_ipv6 *src_p, |
d62a17ae | 204 | uint32_t cost, |
205 | uint32_t depth, | |
206 | struct list *adjacencies) | |
eb5d44eb | 207 | { |
d62a17ae | 208 | struct isis_route_info *rinfo; |
209 | struct isis_adjacency *adj; | |
210 | struct listnode *node; | |
211 | ||
212 | rinfo = XCALLOC(MTYPE_ISIS_ROUTE_INFO, sizeof(struct isis_route_info)); | |
213 | ||
214 | if (prefix->family == AF_INET) { | |
215 | rinfo->nexthops = list_new(); | |
216 | for (ALL_LIST_ELEMENTS_RO(adjacencies, node, adj)) { | |
217 | /* check for force resync this route */ | |
218 | if (CHECK_FLAG(adj->circuit->flags, | |
219 | ISIS_CIRCUIT_FLAPPED_AFTER_SPF)) | |
220 | SET_FLAG(rinfo->flag, | |
221 | ISIS_ROUTE_FLAG_ZEBRA_RESYNC); | |
222 | /* update neighbor router address */ | |
223 | if (depth == 2 && prefix->prefixlen == 32) | |
224 | adj->router_address = prefix->u.prefix4; | |
225 | adjinfo2nexthop(rinfo->nexthops, adj); | |
226 | } | |
227 | } | |
228 | if (prefix->family == AF_INET6) { | |
229 | rinfo->nexthops6 = list_new(); | |
230 | for (ALL_LIST_ELEMENTS_RO(adjacencies, node, adj)) { | |
231 | /* check for force resync this route */ | |
232 | if (CHECK_FLAG(adj->circuit->flags, | |
233 | ISIS_CIRCUIT_FLAPPED_AFTER_SPF)) | |
234 | SET_FLAG(rinfo->flag, | |
235 | ISIS_ROUTE_FLAG_ZEBRA_RESYNC); | |
236 | /* update neighbor router address */ | |
321c1bbb CF |
237 | if (depth == 2 && prefix->prefixlen == 128 |
238 | && (!src_p || !src_p->prefixlen)) { | |
d62a17ae | 239 | adj->router_address6 = prefix->u.prefix6; |
321c1bbb | 240 | } |
d62a17ae | 241 | adjinfo2nexthop6(rinfo->nexthops6, adj); |
242 | } | |
243 | } | |
244 | ||
245 | rinfo->cost = cost; | |
246 | rinfo->depth = depth; | |
247 | ||
248 | return rinfo; | |
eb5d44eb | 249 | } |
250 | ||
d62a17ae | 251 | static void isis_route_info_delete(struct isis_route_info *route_info) |
eb5d44eb | 252 | { |
d62a17ae | 253 | if (route_info->nexthops) { |
254 | route_info->nexthops->del = | |
255 | (void (*)(void *))isis_nexthop_delete; | |
6a154c88 | 256 | list_delete(&route_info->nexthops); |
d62a17ae | 257 | } |
258 | ||
259 | if (route_info->nexthops6) { | |
260 | route_info->nexthops6->del = | |
261 | (void (*)(void *))isis_nexthop6_delete; | |
6a154c88 | 262 | list_delete(&route_info->nexthops6); |
d62a17ae | 263 | } |
264 | ||
265 | XFREE(MTYPE_ISIS_ROUTE_INFO, route_info); | |
eb5d44eb | 266 | } |
267 | ||
d62a17ae | 268 | static int isis_route_info_same_attrib(struct isis_route_info *new, |
269 | struct isis_route_info *old) | |
eb5d44eb | 270 | { |
d62a17ae | 271 | if (new->cost != old->cost) |
272 | return 0; | |
273 | if (new->depth != old->depth) | |
274 | return 0; | |
f390d2c7 | 275 | |
d62a17ae | 276 | return 1; |
eb5d44eb | 277 | } |
278 | ||
d62a17ae | 279 | static int isis_route_info_same(struct isis_route_info *new, |
d7c0a89a | 280 | struct isis_route_info *old, uint8_t family) |
eb5d44eb | 281 | { |
d62a17ae | 282 | struct listnode *node; |
283 | struct isis_nexthop *nexthop; | |
284 | struct isis_nexthop6 *nexthop6; | |
285 | ||
286 | if (!CHECK_FLAG(old->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) | |
287 | return 0; | |
288 | ||
289 | if (CHECK_FLAG(new->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC)) | |
290 | return 0; | |
291 | ||
292 | if (!isis_route_info_same_attrib(new, old)) | |
293 | return 0; | |
294 | ||
295 | if (family == AF_INET) { | |
296 | for (ALL_LIST_ELEMENTS_RO(new->nexthops, node, nexthop)) | |
297 | if (nexthoplookup(old->nexthops, &nexthop->ip, | |
298 | nexthop->ifindex) | |
299 | == 0) | |
300 | return 0; | |
301 | ||
302 | for (ALL_LIST_ELEMENTS_RO(old->nexthops, node, nexthop)) | |
303 | if (nexthoplookup(new->nexthops, &nexthop->ip, | |
304 | nexthop->ifindex) | |
305 | == 0) | |
306 | return 0; | |
307 | } else if (family == AF_INET6) { | |
308 | for (ALL_LIST_ELEMENTS_RO(new->nexthops6, node, nexthop6)) | |
309 | if (nexthop6lookup(old->nexthops6, &nexthop6->ip6, | |
310 | nexthop6->ifindex) | |
311 | == 0) | |
312 | return 0; | |
313 | ||
314 | for (ALL_LIST_ELEMENTS_RO(old->nexthops6, node, nexthop6)) | |
315 | if (nexthop6lookup(new->nexthops6, &nexthop6->ip6, | |
316 | nexthop6->ifindex) | |
317 | == 0) | |
318 | return 0; | |
319 | } | |
320 | ||
321 | return 1; | |
eb5d44eb | 322 | } |
323 | ||
321c1bbb CF |
324 | struct isis_route_info *isis_route_create(struct prefix *prefix, |
325 | struct prefix_ipv6 *src_p, | |
326 | uint32_t cost, | |
d7c0a89a | 327 | uint32_t depth, |
d62a17ae | 328 | struct list *adjacencies, |
3dace42d CF |
329 | struct isis_area *area, |
330 | struct route_table *table) | |
eb5d44eb | 331 | { |
d62a17ae | 332 | struct route_node *route_node; |
333 | struct isis_route_info *rinfo_new, *rinfo_old, *route_info = NULL; | |
334 | char buff[PREFIX2STR_BUFFER]; | |
d7c0a89a | 335 | uint8_t family; |
d62a17ae | 336 | |
337 | family = prefix->family; | |
338 | /* for debugs */ | |
339 | prefix2str(prefix, buff, sizeof(buff)); | |
340 | ||
3dace42d | 341 | if (!table) |
d62a17ae | 342 | return NULL; |
3dace42d | 343 | |
321c1bbb CF |
344 | rinfo_new = isis_route_info_new(prefix, src_p, cost, |
345 | depth, adjacencies); | |
346 | route_node = srcdest_rnode_get(table, prefix, src_p); | |
d62a17ae | 347 | |
348 | rinfo_old = route_node->info; | |
349 | if (!rinfo_old) { | |
350 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
351 | zlog_debug("ISIS-Rte (%s) route created: %s", | |
352 | area->area_tag, buff); | |
353 | route_info = rinfo_new; | |
354 | UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); | |
355 | } else { | |
bcd9fd50 | 356 | route_unlock_node(route_node); |
d62a17ae | 357 | if (isis->debugs & DEBUG_RTE_EVENTS) |
358 | zlog_debug("ISIS-Rte (%s) route already exists: %s", | |
359 | area->area_tag, buff); | |
360 | if (isis_route_info_same(rinfo_new, rinfo_old, family)) { | |
361 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
362 | zlog_debug("ISIS-Rte (%s) route unchanged: %s", | |
363 | area->area_tag, buff); | |
364 | isis_route_info_delete(rinfo_new); | |
365 | route_info = rinfo_old; | |
366 | } else { | |
367 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
368 | zlog_debug("ISIS-Rte (%s) route changed: %s", | |
369 | area->area_tag, buff); | |
370 | isis_route_info_delete(rinfo_old); | |
371 | route_info = rinfo_new; | |
372 | UNSET_FLAG(route_info->flag, | |
373 | ISIS_ROUTE_FLAG_ZEBRA_SYNCED); | |
374 | } | |
375 | } | |
376 | ||
377 | SET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ACTIVE); | |
378 | route_node->info = route_info; | |
379 | ||
380 | return route_info; | |
eb5d44eb | 381 | } |
382 | ||
bcd9fd50 | 383 | static void isis_route_delete(struct route_node *rode, |
321c1bbb | 384 | struct route_table *table) |
eb5d44eb | 385 | { |
d62a17ae | 386 | struct isis_route_info *rinfo; |
321c1bbb | 387 | char buff[SRCDEST2STR_BUFFER]; |
bcd9fd50 CF |
388 | struct prefix *prefix; |
389 | struct prefix_ipv6 *src_p; | |
d62a17ae | 390 | |
391 | /* for log */ | |
bcd9fd50 | 392 | srcdest_rnode2str(rode, buff, sizeof(buff)); |
d62a17ae | 393 | |
bcd9fd50 CF |
394 | srcdest_rnode_prefixes(rode, (const struct prefix **)&prefix, |
395 | (const struct prefix **)&src_p); | |
d62a17ae | 396 | |
bcd9fd50 | 397 | rinfo = rode->info; |
d62a17ae | 398 | if (rinfo == NULL) { |
399 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
400 | zlog_debug( | |
401 | "ISIS-Rte: tried to delete non-existant route %s", | |
402 | buff); | |
403 | return; | |
404 | } | |
405 | ||
406 | if (CHECK_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) { | |
407 | UNSET_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE); | |
408 | if (isis->debugs & DEBUG_RTE_EVENTS) | |
409 | zlog_debug("ISIS-Rte: route delete %s", buff); | |
321c1bbb | 410 | isis_zebra_route_update(prefix, src_p, rinfo); |
d62a17ae | 411 | } |
412 | isis_route_info_delete(rinfo); | |
413 | rode->info = NULL; | |
bcd9fd50 | 414 | route_unlock_node(rode); |
eb5d44eb | 415 | } |
416 | ||
3dace42d CF |
417 | static void _isis_route_verify_table(struct isis_area *area, |
418 | struct route_table *table, | |
419 | struct route_table **tables) | |
eb5d44eb | 420 | { |
d62a17ae | 421 | struct route_node *rnode, *drnode; |
422 | struct isis_route_info *rinfo; | |
321c1bbb | 423 | char buff[SRCDEST2STR_BUFFER]; |
d62a17ae | 424 | |
321c1bbb CF |
425 | for (rnode = route_top(table); rnode; |
426 | rnode = srcdest_route_next(rnode)) { | |
d62a17ae | 427 | if (rnode->info == NULL) |
428 | continue; | |
429 | rinfo = rnode->info; | |
430 | ||
321c1bbb CF |
431 | struct prefix *dst_p; |
432 | struct prefix_ipv6 *src_p; | |
433 | ||
434 | srcdest_rnode_prefixes(rnode, | |
435 | (const struct prefix **)&dst_p, | |
436 | (const struct prefix **)&src_p); | |
437 | ||
d62a17ae | 438 | if (isis->debugs & DEBUG_RTE_EVENTS) { |
321c1bbb | 439 | srcdest2str(dst_p, src_p, buff, sizeof(buff)); |
d62a17ae | 440 | zlog_debug( |
441 | "ISIS-Rte (%s): route validate: %s %s %s %s", | |
442 | area->area_tag, | |
443 | (CHECK_FLAG(rinfo->flag, | |
444 | ISIS_ROUTE_FLAG_ZEBRA_SYNCED) | |
445 | ? "synced" | |
446 | : "not-synced"), | |
447 | (CHECK_FLAG(rinfo->flag, | |
448 | ISIS_ROUTE_FLAG_ZEBRA_RESYNC) | |
449 | ? "resync" | |
450 | : "not-resync"), | |
451 | (CHECK_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE) | |
452 | ? "active" | |
453 | : "inactive"), | |
454 | buff); | |
455 | } | |
456 | ||
321c1bbb | 457 | isis_zebra_route_update(dst_p, src_p, rinfo); |
bcd9fd50 CF |
458 | |
459 | if (CHECK_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE)) | |
460 | continue; | |
461 | ||
462 | /* Area is either L1 or L2 => we use level route tables | |
463 | * directly for | |
464 | * validating => no problems with deleting routes. */ | |
465 | if (!tables) { | |
466 | isis_route_delete(rnode, table); | |
467 | continue; | |
468 | } | |
469 | ||
470 | /* If area is L1L2, we work with merge table and | |
471 | * therefore must | |
472 | * delete node from level tables as well before deleting | |
473 | * route info. */ | |
474 | for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) { | |
475 | drnode = srcdest_rnode_lookup(tables[level - 1], | |
476 | dst_p, src_p); | |
477 | if (!drnode) | |
d62a17ae | 478 | continue; |
3dace42d | 479 | |
bcd9fd50 | 480 | route_unlock_node(drnode); |
d62a17ae | 481 | |
bcd9fd50 CF |
482 | if (drnode->info != rnode->info) |
483 | continue; | |
484 | ||
485 | drnode->info = NULL; | |
486 | route_unlock_node(drnode); | |
d62a17ae | 487 | } |
bcd9fd50 CF |
488 | |
489 | isis_route_delete(rnode, table); | |
f390d2c7 | 490 | } |
fac1f7cc | 491 | } |
492 | ||
3dace42d CF |
493 | void isis_route_verify_table(struct isis_area *area, struct route_table *table) |
494 | { | |
d90b788e | 495 | _isis_route_verify_table(area, table, NULL); |
3dace42d CF |
496 | } |
497 | ||
fac1f7cc | 498 | /* Function to validate route tables for L1L2 areas. In this case we can't use |
499 | * level route tables directly, we have to merge them at first. L1 routes are | |
500 | * preferred over the L2 ones. | |
501 | * | |
502 | * Merge algorithm is trivial (at least for now). All L1 paths are copied into | |
503 | * merge table at first, then L2 paths are added if L1 path for same prefix | |
504 | * doesn't already exists there. | |
505 | * | |
506 | * FIXME: Is it right place to do it at all? Maybe we should push both levels | |
507 | * to the RIB with different zebra route types and let RIB handle this? */ | |
3dace42d CF |
508 | void isis_route_verify_merge(struct isis_area *area, |
509 | struct route_table *level1_table, | |
510 | struct route_table *level2_table) | |
fac1f7cc | 511 | { |
3dace42d | 512 | struct route_table *tables[] = { level1_table, level2_table }; |
d62a17ae | 513 | struct route_table *merge; |
514 | struct route_node *rnode, *mrnode; | |
515 | ||
321c1bbb | 516 | merge = srcdest_table_init(); |
d62a17ae | 517 | |
3dace42d CF |
518 | for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) { |
519 | for (rnode = route_top(tables[level - 1]); rnode; | |
321c1bbb | 520 | rnode = srcdest_route_next(rnode)) { |
26b0598f CF |
521 | struct isis_route_info *rinfo = rnode->info; |
522 | if (!rinfo) | |
3dace42d | 523 | continue; |
26b0598f | 524 | |
321c1bbb CF |
525 | struct prefix *prefix; |
526 | struct prefix_ipv6 *src_p; | |
527 | ||
528 | srcdest_rnode_prefixes(rnode, | |
529 | (const struct prefix **)&prefix, | |
530 | (const struct prefix **)&src_p); | |
531 | mrnode = srcdest_rnode_get(merge, prefix, src_p); | |
26b0598f CF |
532 | struct isis_route_info *mrinfo = mrnode->info; |
533 | if (mrinfo) { | |
3dace42d | 534 | route_unlock_node(mrnode); |
26b0598f CF |
535 | if (CHECK_FLAG(mrinfo->flag, |
536 | ISIS_ROUTE_FLAG_ACTIVE)) { | |
537 | /* Clear the ZEBRA_SYNCED flag on the | |
538 | * L2 route when L1 wins, otherwise L2 | |
539 | * won't get reinstalled when L1 | |
540 | * disappears. | |
541 | */ | |
542 | UNSET_FLAG( | |
543 | rinfo->flag, | |
544 | ISIS_ROUTE_FLAG_ZEBRA_SYNCED | |
545 | ); | |
546 | continue; | |
547 | } else { | |
548 | /* Clear the ZEBRA_SYNCED flag on the L1 | |
549 | * route when L2 wins, otherwise L1 | |
550 | * won't get reinstalled when it | |
551 | * reappears. | |
552 | */ | |
553 | UNSET_FLAG( | |
554 | mrinfo->flag, | |
555 | ISIS_ROUTE_FLAG_ZEBRA_SYNCED | |
556 | ); | |
557 | } | |
3dace42d CF |
558 | } |
559 | mrnode->info = rnode->info; | |
560 | } | |
d62a17ae | 561 | } |
562 | ||
3dace42d | 563 | _isis_route_verify_table(area, merge, tables); |
d62a17ae | 564 | route_table_finish(merge); |
fac1f7cc | 565 | } |
566 | ||
d62a17ae | 567 | void isis_route_invalidate_table(struct isis_area *area, |
568 | struct route_table *table) | |
3f045a08 | 569 | { |
d62a17ae | 570 | struct route_node *rode; |
571 | struct isis_route_info *rinfo; | |
321c1bbb | 572 | for (rode = route_top(table); rode; rode = srcdest_route_next(rode)) { |
d62a17ae | 573 | if (rode->info == NULL) |
574 | continue; | |
575 | rinfo = rode->info; | |
576 | ||
577 | UNSET_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE); | |
578 | } | |
3f045a08 | 579 | } |