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