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