jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 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 | |
| 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> |
| 27 | #include <zebra.h> |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 28 | |
| 29 | #include "thread.h" |
| 30 | #include "linklist.h" |
| 31 | #include "vty.h" |
| 32 | #include "log.h" |
| 33 | #include "memory.h" |
| 34 | #include "prefix.h" |
| 35 | #include "hash.h" |
| 36 | #include "if.h" |
| 37 | #include "table.h" |
| 38 | |
| 39 | #include "isis_constants.h" |
| 40 | #include "isis_common.h" |
| 41 | #include "dict.h" |
| 42 | #include "isisd.h" |
| 43 | #include "isis_misc.h" |
| 44 | #include "isis_adjacency.h" |
| 45 | #include "isis_circuit.h" |
| 46 | #include "isis_tlv.h" |
| 47 | #include "isis_pdu.h" |
| 48 | #include "isis_lsp.h" |
| 49 | #include "isis_spf.h" |
| 50 | #include "isis_route.h" |
| 51 | #include "isis_zebra.h" |
| 52 | |
| 53 | extern struct isis *isis; |
| 54 | extern struct thread_master *master; |
| 55 | |
| 56 | struct isis_nexthop * |
| 57 | isis_nexthop_create (struct in_addr *ip, unsigned int ifindex) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 58 | { |
| 59 | struct listnode *node; |
| 60 | struct isis_nexthop *nexthop; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 61 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 62 | for (node = listhead (isis->nexthops); node; nextnode (node)) |
| 63 | { |
| 64 | nexthop = getdata (node); |
| 65 | if (nexthop->ifindex != ifindex) |
| 66 | continue; |
| 67 | if (ip && memcmp (&nexthop->ip, ip, sizeof (struct in_addr)) != 0) |
| 68 | continue; |
| 69 | |
| 70 | nexthop->lock++; |
| 71 | return nexthop; |
| 72 | } |
| 73 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 74 | nexthop = XMALLOC (MTYPE_ISIS_NEXTHOP, sizeof (struct isis_nexthop)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 75 | if (!nexthop) |
| 76 | { |
| 77 | zlog_err ("ISIS-Rte: isis_nexthop_create: out of memory!"); |
| 78 | } |
| 79 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 80 | memset (nexthop, 0, sizeof (struct isis_nexthop)); |
| 81 | nexthop->ifindex = ifindex; |
| 82 | memcpy (&nexthop->ip, ip, sizeof (struct in_addr)); |
| 83 | listnode_add (isis->nexthops, nexthop); |
| 84 | nexthop->lock++; |
| 85 | |
| 86 | return nexthop; |
| 87 | } |
| 88 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 89 | void |
| 90 | isis_nexthop_delete (struct isis_nexthop *nexthop) |
| 91 | { |
| 92 | nexthop->lock--; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 93 | if (nexthop->lock == 0) |
| 94 | { |
| 95 | listnode_delete (isis->nexthops, nexthop); |
| 96 | XFREE (MTYPE_ISIS_NEXTHOP, nexthop); |
| 97 | } |
| 98 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 99 | return; |
| 100 | } |
| 101 | |
| 102 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 103 | nexthoplookup (struct list *nexthops, struct in_addr *ip, |
| 104 | unsigned int ifindex) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 105 | { |
| 106 | struct listnode *node; |
| 107 | struct isis_nexthop *nh; |
| 108 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 109 | for (node = listhead (nexthops); node; nextnode (node)) |
| 110 | { |
| 111 | nh = getdata (node); |
| 112 | if (!(memcmp (ip, &nh->ip, sizeof (struct in_addr))) && |
| 113 | ifindex == nh->ifindex) |
| 114 | return 1; |
| 115 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | nexthop_print (struct isis_nexthop *nh) |
| 122 | { |
| 123 | u_char buf[BUFSIZ]; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 124 | |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 125 | inet_ntop (AF_INET, &nh->ip, (char *) buf, BUFSIZ); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 126 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 127 | zlog_info (" %s %u", buf, nh->ifindex); |
| 128 | } |
| 129 | |
| 130 | void |
| 131 | nexthops_print (struct list *nhs) |
| 132 | { |
| 133 | struct listnode *node; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 134 | |
| 135 | for (node = listhead (nhs); node; nextnode (node)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 136 | nexthop_print (getdata (node)); |
| 137 | } |
| 138 | |
| 139 | #ifdef HAVE_IPV6 |
| 140 | |
| 141 | struct isis_nexthop6 * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 142 | isis_nexthop6_new (struct in6_addr *ip6, unsigned int ifindex) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 143 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 144 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 145 | struct isis_nexthop6 *nexthop6; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 146 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 147 | nexthop6 = XMALLOC (MTYPE_ISIS_NEXTHOP6, sizeof (struct isis_nexthop6)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 148 | if (!nexthop6) |
| 149 | { |
| 150 | zlog_err ("ISIS-Rte: isis_nexthop_create6: out of memory!"); |
| 151 | } |
| 152 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 153 | memset (nexthop6, 0, sizeof (struct isis_nexthop6)); |
| 154 | nexthop6->ifindex = ifindex; |
| 155 | memcpy (&nexthop6->ip6, ip6, sizeof (struct in6_addr)); |
| 156 | nexthop6->lock++; |
| 157 | |
| 158 | return nexthop6; |
| 159 | } |
| 160 | |
| 161 | struct isis_nexthop6 * |
| 162 | isis_nexthop6_create (struct in6_addr *ip6, unsigned int ifindex) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 163 | { |
| 164 | struct listnode *node; |
| 165 | struct isis_nexthop6 *nexthop6; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 166 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 167 | for (node = listhead (isis->nexthops6); node; nextnode (node)) |
| 168 | { |
| 169 | nexthop6 = getdata (node); |
| 170 | if (nexthop6->ifindex != ifindex) |
| 171 | continue; |
| 172 | if (ip6 && memcmp (&nexthop6->ip6, ip6, sizeof (struct in6_addr)) != 0) |
| 173 | continue; |
| 174 | |
| 175 | nexthop6->lock++; |
| 176 | return nexthop6; |
| 177 | } |
| 178 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 179 | nexthop6 = isis_nexthop6_new (ip6, ifindex); |
| 180 | |
| 181 | return nexthop6; |
| 182 | } |
| 183 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 184 | void |
| 185 | isis_nexthop6_delete (struct isis_nexthop6 *nexthop6) |
| 186 | { |
| 187 | |
| 188 | nexthop6->lock--; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 189 | if (nexthop6->lock == 0) |
| 190 | { |
| 191 | listnode_delete (isis->nexthops6, nexthop6); |
| 192 | XFREE (MTYPE_ISIS_NEXTHOP6, nexthop6); |
| 193 | } |
| 194 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | |
| 198 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 199 | nexthop6lookup (struct list *nexthops6, struct in6_addr *ip6, |
| 200 | unsigned int ifindex) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 201 | { |
| 202 | struct listnode *node; |
| 203 | struct isis_nexthop6 *nh6; |
| 204 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 205 | for (node = listhead (nexthops6); node; nextnode (node)) |
| 206 | { |
| 207 | nh6 = getdata (node); |
| 208 | if (!(memcmp (ip6, &nh6->ip6, sizeof (struct in6_addr))) && |
| 209 | ifindex == nh6->ifindex) |
| 210 | return 1; |
| 211 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | void |
| 217 | nexthop6_print (struct isis_nexthop6 *nh6) |
| 218 | { |
| 219 | u_char buf[BUFSIZ]; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 220 | |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 221 | inet_ntop (AF_INET6, &nh6->ip6, (char *) buf, BUFSIZ); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 222 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 223 | zlog_info (" %s %u", buf, nh6->ifindex); |
| 224 | } |
| 225 | |
| 226 | void |
| 227 | nexthops6_print (struct list *nhs6) |
| 228 | { |
| 229 | struct listnode *node; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 230 | |
| 231 | for (node = listhead (nhs6); node; nextnode (node)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 232 | nexthop6_print (getdata (node)); |
| 233 | } |
| 234 | |
| 235 | |
| 236 | #endif /* HAVE_IPV6 */ |
| 237 | |
| 238 | void |
| 239 | adjinfo2nexthop (struct list *nexthops, struct isis_adjacency *adj) |
| 240 | { |
| 241 | struct isis_nexthop *nh; |
| 242 | struct listnode *node; |
| 243 | struct in_addr *ipv4_addr; |
| 244 | |
| 245 | if (adj->ipv4_addrs == NULL) |
| 246 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 247 | for (node = listhead (adj->ipv4_addrs); node; nextnode (node)) |
| 248 | { |
| 249 | ipv4_addr = getdata (node); |
| 250 | if (!nexthoplookup (nexthops, ipv4_addr, |
| 251 | adj->circuit->interface->ifindex)) |
| 252 | { |
| 253 | nh = isis_nexthop_create (ipv4_addr, |
| 254 | adj->circuit->interface->ifindex); |
| 255 | listnode_add (nexthops, nh); |
| 256 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 257 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | #ifdef HAVE_IPV6 |
| 261 | void |
| 262 | adjinfo2nexthop6 (struct list *nexthops6, struct isis_adjacency *adj) |
| 263 | { |
| 264 | struct listnode *node; |
| 265 | struct in6_addr *ipv6_addr; |
| 266 | struct isis_nexthop6 *nh6; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 267 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 268 | if (!adj->ipv6_addrs) |
| 269 | return; |
| 270 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 271 | for (node = listhead (adj->ipv6_addrs); node; nextnode (node)) |
| 272 | { |
| 273 | ipv6_addr = getdata (node); |
| 274 | if (!nexthop6lookup (nexthops6, ipv6_addr, |
| 275 | adj->circuit->interface->ifindex)) |
| 276 | { |
| 277 | nh6 = isis_nexthop6_create (ipv6_addr, |
| 278 | adj->circuit->interface->ifindex); |
| 279 | listnode_add (nexthops6, nh6); |
| 280 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 281 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 282 | } |
| 283 | #endif /* HAVE_IPV6 */ |
| 284 | |
| 285 | struct isis_route_info * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 286 | isis_route_info_new (uint32_t cost, uint32_t depth, u_char family, |
| 287 | struct list *adjacencies) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 288 | { |
| 289 | struct isis_route_info *rinfo; |
| 290 | struct isis_adjacency *adj; |
| 291 | struct listnode *node; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 292 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 293 | rinfo = XMALLOC (MTYPE_ISIS_ROUTE_INFO, sizeof (struct isis_route_info)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 294 | if (!rinfo) |
| 295 | { |
| 296 | zlog_err ("ISIS-Rte: isis_route_info_new: out of memory!"); |
| 297 | return NULL; |
| 298 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 299 | memset (rinfo, 0, sizeof (struct isis_route_info)); |
| 300 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 301 | if (family == AF_INET) |
| 302 | { |
| 303 | rinfo->nexthops = list_new (); |
| 304 | for (node = listhead (adjacencies); node; nextnode (node)) |
| 305 | { |
| 306 | adj = getdata (node); |
| 307 | adjinfo2nexthop (rinfo->nexthops, adj); |
| 308 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 309 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 310 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 311 | if (family == AF_INET6) |
| 312 | { |
| 313 | rinfo->nexthops6 = list_new (); |
| 314 | for (node = listhead (adjacencies); node; nextnode (node)) |
| 315 | { |
| 316 | adj = getdata (node); |
| 317 | adjinfo2nexthop6 (rinfo->nexthops6, adj); |
| 318 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 319 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 320 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 321 | #endif /* HAVE_IPV6 */ |
| 322 | |
| 323 | rinfo->cost = cost; |
| 324 | rinfo->depth = depth; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 325 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 326 | return rinfo; |
| 327 | } |
| 328 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 329 | void |
| 330 | isis_route_info_delete (struct isis_route_info *route_info) |
| 331 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 332 | if (route_info->nexthops) |
| 333 | { |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 334 | route_info->nexthops->del = (void (*)(void *)) isis_nexthop_delete; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 335 | list_delete (route_info->nexthops); |
| 336 | } |
| 337 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 338 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 339 | if (route_info->nexthops6) |
| 340 | { |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 341 | route_info->nexthops6->del = (void (*)(void *)) isis_nexthop6_delete; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 342 | list_delete (route_info->nexthops6); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 343 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 344 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 345 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 346 | XFREE (MTYPE_ISIS_ROUTE_INFO, route_info); |
| 347 | } |
| 348 | |
| 349 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 350 | isis_route_info_same_attrib (struct isis_route_info *new, |
| 351 | struct isis_route_info *old) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 352 | { |
| 353 | if (new->cost != old->cost) |
| 354 | return 0; |
| 355 | if (new->depth != old->depth) |
| 356 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 357 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 358 | return 1; |
| 359 | } |
| 360 | |
| 361 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 362 | isis_route_info_same (struct isis_route_info *new, |
| 363 | struct isis_route_info *old, u_char family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 364 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 365 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 366 | struct isis_nexthop *nexthop; |
| 367 | #ifdef HAVE_IPV6 |
| 368 | struct isis_nexthop6 *nexthop6; |
| 369 | #endif /* HAVE_IPV6 */ |
| 370 | if (!isis_route_info_same_attrib (new, old)) |
| 371 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 372 | |
| 373 | if (family == AF_INET) |
| 374 | { |
| 375 | for (node = listhead (new->nexthops); node; nextnode (node)) |
| 376 | { |
| 377 | nexthop = (struct isis_nexthop *) getdata (node); |
| 378 | if (nexthoplookup (old->nexthops, &nexthop->ip, nexthop->ifindex) == |
| 379 | 0) |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | for (node = listhead (old->nexthops); node; nextnode (node)) |
| 384 | { |
| 385 | nexthop = (struct isis_nexthop *) getdata (node); |
| 386 | if (nexthoplookup (new->nexthops, &nexthop->ip, nexthop->ifindex) == |
| 387 | 0) |
| 388 | return 0; |
| 389 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 390 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 391 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 392 | else if (family == AF_INET6) |
| 393 | { |
| 394 | for (node = listhead (new->nexthops6); node; nextnode (node)) |
| 395 | { |
| 396 | nexthop6 = (struct isis_nexthop6 *) getdata (node); |
| 397 | if (nexthop6lookup (old->nexthops6, &nexthop6->ip6, |
| 398 | nexthop6->ifindex) == 0) |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | for (node = listhead (old->nexthops6); node; nextnode (node)) |
| 403 | { |
| 404 | nexthop6 = (struct isis_nexthop6 *) getdata (node); |
| 405 | if (nexthop6lookup (new->nexthops6, &nexthop6->ip6, |
| 406 | nexthop6->ifindex) == 0) |
| 407 | return 0; |
| 408 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 409 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 410 | #endif /* HAVE_IPV6 */ |
| 411 | |
| 412 | return 1; |
| 413 | } |
| 414 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 415 | void |
| 416 | isis_nexthops_merge (struct list *new, struct list *old) |
| 417 | { |
| 418 | struct listnode *node; |
| 419 | struct isis_nexthop *nexthop; |
| 420 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 421 | for (node = listhead (new); node; nextnode (node)) |
| 422 | { |
| 423 | nexthop = (struct isis_nexthop *) getdata (node); |
| 424 | if (nexthoplookup (old, &nexthop->ip, nexthop->ifindex)) |
| 425 | continue; |
| 426 | listnode_add (old, nexthop); |
| 427 | nexthop->lock++; |
| 428 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 429 | } |
| 430 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 431 | #ifdef HAVE_IPV6 |
| 432 | void |
| 433 | isis_nexthops6_merge (struct list *new, struct list *old) |
| 434 | { |
| 435 | struct listnode *node; |
| 436 | struct isis_nexthop6 *nexthop6; |
| 437 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 438 | for (node = listhead (new); node; nextnode (node)) |
| 439 | { |
| 440 | nexthop6 = (struct isis_nexthop6 *) getdata (node); |
| 441 | if (nexthop6lookup (old, &nexthop6->ip6, nexthop6->ifindex)) |
| 442 | continue; |
| 443 | listnode_add (old, nexthop6); |
| 444 | nexthop6->lock++; |
| 445 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 446 | } |
| 447 | #endif /* HAVE_IPV6 */ |
| 448 | |
| 449 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 450 | isis_route_info_merge (struct isis_route_info *new, |
| 451 | struct isis_route_info *old, u_char family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 452 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 453 | if (family == AF_INET) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 454 | isis_nexthops_merge (new->nexthops, old->nexthops); |
| 455 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 456 | else if (family == AF_INET6) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 457 | isis_nexthops6_merge (new->nexthops6, old->nexthops6); |
| 458 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 459 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 460 | return; |
| 461 | } |
| 462 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 463 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 464 | isis_route_info_prefer_new (struct isis_route_info *new, |
| 465 | struct isis_route_info *old) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 466 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 467 | if (!CHECK_FLAG (old->flag, ISIS_ROUTE_FLAG_ACTIVE)) |
| 468 | return 1; |
| 469 | |
| 470 | if (new->cost < old->cost) |
| 471 | return 1; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 472 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 473 | return 0; |
| 474 | } |
| 475 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 476 | struct isis_route_info * |
| 477 | isis_route_create (struct prefix *prefix, u_int32_t cost, u_int32_t depth, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 478 | struct list *adjacencies, struct isis_area *area) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 479 | { |
| 480 | struct route_node *route_node; |
| 481 | struct isis_route_info *rinfo_new, *rinfo_old, *route_info = NULL; |
| 482 | u_char buff[BUFSIZ]; |
| 483 | u_char family; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 484 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 485 | family = prefix->family; |
| 486 | /* for debugs */ |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 487 | prefix2str (prefix, (char *) buff, BUFSIZ); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 488 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 489 | rinfo_new = isis_route_info_new (cost, depth, family, adjacencies); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 490 | if (!rinfo_new) |
| 491 | { |
| 492 | zlog_err ("ISIS-Rte (%s): isis_route_create: out of memory!", |
| 493 | area->area_tag); |
| 494 | return NULL; |
| 495 | } |
| 496 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 497 | if (family == AF_INET) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 498 | route_node = route_node_get (area->route_table, prefix); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 499 | #ifdef HAVE_IPV6 |
| 500 | else if (family == AF_INET6) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 501 | route_node = route_node_get (area->route_table6, prefix); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 502 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 503 | else |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 504 | return NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 505 | rinfo_old = route_node->info; |
| 506 | if (!rinfo_old) |
| 507 | { |
| 508 | if (isis->debugs & DEBUG_RTE_EVENTS) |
| 509 | zlog_info ("ISIS-Rte (%s) route created: %s", area->area_tag, buff); |
| 510 | SET_FLAG (rinfo_new->flag, ISIS_ROUTE_FLAG_ACTIVE); |
| 511 | route_node->info = rinfo_new; |
| 512 | return rinfo_new; |
| 513 | } |
| 514 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 515 | if (isis->debugs & DEBUG_RTE_EVENTS) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 516 | zlog_info ("ISIS-Rte (%s) route already exists: %s", area->area_tag, |
| 517 | buff); |
| 518 | |
| 519 | if (isis_route_info_same (rinfo_new, rinfo_old, family)) |
| 520 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 521 | if (isis->debugs & DEBUG_RTE_EVENTS) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 522 | zlog_info ("ISIS-Rte (%s) route unchanged: %s", area->area_tag, buff); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 523 | isis_route_info_delete (rinfo_new); |
| 524 | route_info = rinfo_old; |
| 525 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 526 | else if (isis_route_info_same_attrib (rinfo_new, rinfo_old)) |
| 527 | { |
| 528 | /* merge the nexthop lists */ |
| 529 | if (isis->debugs & DEBUG_RTE_EVENTS) |
| 530 | zlog_info ("ISIS-Rte (%s) route changed (same attribs): %s", |
| 531 | area->area_tag, buff); |
| 532 | #ifdef EXTREME_DEBUG |
| 533 | zlog_info ("Old nexthops"); |
| 534 | nexthops6_print (rinfo_old->nexthops6); |
| 535 | zlog_info ("New nexthops"); |
| 536 | nexthops6_print (rinfo_new->nexthops6); |
| 537 | #endif /* EXTREME_DEBUG */ |
| 538 | isis_route_info_merge (rinfo_new, rinfo_old, family); |
| 539 | isis_route_info_delete (rinfo_new); |
| 540 | route_info = rinfo_old; |
| 541 | } |
| 542 | else |
| 543 | { |
| 544 | if (isis_route_info_prefer_new (rinfo_new, rinfo_old)) |
| 545 | { |
| 546 | if (isis->debugs & DEBUG_RTE_EVENTS) |
| 547 | zlog_info ("ISIS-Rte (%s) route changed: %s", area->area_tag, |
| 548 | buff); |
| 549 | isis_route_info_delete (rinfo_old); |
| 550 | route_info = rinfo_new; |
| 551 | } |
| 552 | else |
| 553 | { |
| 554 | if (isis->debugs & DEBUG_RTE_EVENTS) |
| 555 | zlog_info ("ISIS-Rte (%s) route rejected: %s", area->area_tag, |
| 556 | buff); |
| 557 | isis_route_info_delete (rinfo_new); |
| 558 | route_info = rinfo_old; |
| 559 | } |
| 560 | } |
| 561 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 562 | SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE); |
| 563 | route_node->info = route_info; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 564 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 565 | return route_info; |
| 566 | } |
| 567 | |
| 568 | void |
| 569 | isis_route_delete (struct prefix *prefix, struct route_table *table) |
| 570 | { |
| 571 | struct route_node *rode; |
| 572 | struct isis_route_info *rinfo; |
| 573 | char buff[BUFSIZ]; |
| 574 | |
| 575 | /* for log */ |
| 576 | prefix2str (prefix, buff, BUFSIZ); |
| 577 | |
| 578 | |
| 579 | rode = route_node_get (table, prefix); |
| 580 | rinfo = rode->info; |
| 581 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 582 | if (rinfo == NULL) |
| 583 | { |
| 584 | if (isis->debugs & DEBUG_RTE_EVENTS) |
| 585 | zlog_info ("ISIS-Rte: tried to delete non-existant route %s", buff); |
| 586 | return; |
| 587 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 588 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 589 | if (CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) |
| 590 | { |
| 591 | UNSET_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE); |
| 592 | if (isis->debugs & DEBUG_RTE_EVENTS) |
| 593 | zlog_info ("ISIS-Rte: route delete %s", buff); |
| 594 | isis_zebra_route_update (prefix, rinfo); |
| 595 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 596 | isis_route_info_delete (rinfo); |
| 597 | rode->info = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 598 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 599 | return; |
| 600 | } |
| 601 | |
| 602 | int |
| 603 | isis_route_validate (struct thread *thread) |
| 604 | { |
| 605 | struct isis_area *area; |
| 606 | struct route_table *table; |
| 607 | struct route_node *rode; |
| 608 | struct isis_route_info *rinfo; |
| 609 | u_char buff[BUFSIZ]; |
| 610 | #ifdef HAVE_IPV6 |
| 611 | int v6done = 0; |
| 612 | #endif |
| 613 | area = THREAD_ARG (thread); |
| 614 | table = area->route_table; |
| 615 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 616 | again: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 617 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 618 | for (rode = route_top (table); rode; rode = route_next (rode)) |
| 619 | { |
| 620 | if (rode->info == NULL) |
| 621 | continue; |
| 622 | rinfo = rode->info; |
| 623 | |
| 624 | if (isis->debugs & DEBUG_RTE_EVENTS) |
| 625 | { |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 626 | prefix2str (&rode->p, (char *) buff, BUFSIZ); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 627 | zlog_info ("ISIS-Rte (%s): route validate: %s %s %s", |
| 628 | area->area_tag, |
| 629 | (CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC) ? |
| 630 | "sync'ed" : "nosync"), |
| 631 | (CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE) ? |
| 632 | "active" : "inactive"), buff); |
| 633 | } |
| 634 | |
| 635 | isis_zebra_route_update (&rode->p, rinfo); |
| 636 | if (!CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE)) |
| 637 | isis_route_delete (&rode->p, area->route_table); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 638 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 639 | #ifdef HAVE_IPV6 |
| 640 | if (v6done) |
| 641 | return ISIS_OK; |
| 642 | table = area->route_table6; |
| 643 | v6done = 1; |
| 644 | goto again; |
| 645 | #endif |
| 646 | |
| 647 | return ISIS_OK; |
| 648 | } |