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 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 62 | for (ALL_LIST_ELEMENTS_RO (isis->nexthops, node, nexthop)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 63 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 64 | if (nexthop->ifindex != ifindex) |
| 65 | continue; |
| 66 | if (ip && memcmp (&nexthop->ip, ip, sizeof (struct in_addr)) != 0) |
| 67 | continue; |
| 68 | |
| 69 | nexthop->lock++; |
| 70 | return nexthop; |
| 71 | } |
| 72 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 73 | nexthop = XCALLOC (MTYPE_ISIS_NEXTHOP, sizeof (struct isis_nexthop)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 74 | if (!nexthop) |
| 75 | { |
| 76 | zlog_err ("ISIS-Rte: isis_nexthop_create: out of memory!"); |
| 77 | } |
| 78 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 79 | nexthop->ifindex = ifindex; |
| 80 | memcpy (&nexthop->ip, ip, sizeof (struct in_addr)); |
| 81 | listnode_add (isis->nexthops, nexthop); |
| 82 | nexthop->lock++; |
| 83 | |
| 84 | return nexthop; |
| 85 | } |
| 86 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 87 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 88 | isis_nexthop_delete (struct isis_nexthop *nexthop) |
| 89 | { |
| 90 | nexthop->lock--; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 91 | if (nexthop->lock == 0) |
| 92 | { |
| 93 | listnode_delete (isis->nexthops, nexthop); |
| 94 | XFREE (MTYPE_ISIS_NEXTHOP, nexthop); |
| 95 | } |
| 96 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 97 | return; |
| 98 | } |
| 99 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 100 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 101 | nexthoplookup (struct list *nexthops, struct in_addr *ip, |
| 102 | unsigned int ifindex) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 103 | { |
| 104 | struct listnode *node; |
| 105 | struct isis_nexthop *nh; |
| 106 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 107 | for (ALL_LIST_ELEMENTS_RO (nexthops, node, nh)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 108 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 109 | if (!(memcmp (ip, &nh->ip, sizeof (struct in_addr))) && |
| 110 | ifindex == nh->ifindex) |
| 111 | return 1; |
| 112 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
hasso | 3d54927 | 2005-09-21 18:52:14 +0000 | [diff] [blame] | 117 | #ifdef EXTREME_DEBUG |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 118 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 119 | nexthop_print (struct isis_nexthop *nh) |
| 120 | { |
| 121 | u_char buf[BUFSIZ]; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 122 | |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 123 | inet_ntop (AF_INET, &nh->ip, (char *) buf, BUFSIZ); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 124 | |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 125 | zlog_debug (" %s %u", buf, nh->ifindex); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 126 | } |
| 127 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 128 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 129 | nexthops_print (struct list *nhs) |
| 130 | { |
| 131 | struct listnode *node; |
hasso | 13fb40a | 2005-10-01 06:03:04 +0000 | [diff] [blame] | 132 | struct isis_nexthop *nh; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 133 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 134 | for (ALL_LIST_ELEMENTS_RO (nhs, node, nh)) |
| 135 | nexthop_print (nh); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 136 | } |
hasso | 3d54927 | 2005-09-21 18:52:14 +0000 | [diff] [blame] | 137 | #endif /* EXTREME_DEBUG */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 138 | |
| 139 | #ifdef HAVE_IPV6 |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 140 | static struct isis_nexthop6 * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 141 | isis_nexthop6_new (struct in6_addr *ip6, unsigned int ifindex) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 142 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 143 | struct isis_nexthop6 *nexthop6; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 144 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 145 | nexthop6 = XCALLOC (MTYPE_ISIS_NEXTHOP6, sizeof (struct isis_nexthop6)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 146 | if (!nexthop6) |
| 147 | { |
| 148 | zlog_err ("ISIS-Rte: isis_nexthop_create6: out of memory!"); |
| 149 | } |
| 150 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 151 | nexthop6->ifindex = ifindex; |
| 152 | memcpy (&nexthop6->ip6, ip6, sizeof (struct in6_addr)); |
| 153 | nexthop6->lock++; |
| 154 | |
| 155 | return nexthop6; |
| 156 | } |
| 157 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 158 | static struct isis_nexthop6 * |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 159 | isis_nexthop6_create (struct in6_addr *ip6, unsigned int ifindex) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 160 | { |
| 161 | struct listnode *node; |
| 162 | struct isis_nexthop6 *nexthop6; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 163 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 164 | for (ALL_LIST_ELEMENTS_RO (isis->nexthops6, node, nexthop6)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 165 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 166 | if (nexthop6->ifindex != ifindex) |
| 167 | continue; |
| 168 | if (ip6 && memcmp (&nexthop6->ip6, ip6, sizeof (struct in6_addr)) != 0) |
| 169 | continue; |
| 170 | |
| 171 | nexthop6->lock++; |
| 172 | return nexthop6; |
| 173 | } |
| 174 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 175 | nexthop6 = isis_nexthop6_new (ip6, ifindex); |
| 176 | |
| 177 | return nexthop6; |
| 178 | } |
| 179 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 180 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 181 | isis_nexthop6_delete (struct isis_nexthop6 *nexthop6) |
| 182 | { |
| 183 | |
| 184 | nexthop6->lock--; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 185 | if (nexthop6->lock == 0) |
| 186 | { |
| 187 | listnode_delete (isis->nexthops6, nexthop6); |
| 188 | XFREE (MTYPE_ISIS_NEXTHOP6, nexthop6); |
| 189 | } |
| 190 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 191 | return; |
| 192 | } |
| 193 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 194 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 195 | nexthop6lookup (struct list *nexthops6, struct in6_addr *ip6, |
| 196 | unsigned int ifindex) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 197 | { |
| 198 | struct listnode *node; |
| 199 | struct isis_nexthop6 *nh6; |
| 200 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 201 | for (ALL_LIST_ELEMENTS_RO (nexthops6, node, nh6)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 202 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 203 | if (!(memcmp (ip6, &nh6->ip6, sizeof (struct in6_addr))) && |
| 204 | ifindex == nh6->ifindex) |
| 205 | return 1; |
| 206 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 211 | #ifdef EXTREME_DEBUG |
| 212 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 213 | nexthop6_print (struct isis_nexthop6 *nh6) |
| 214 | { |
| 215 | u_char buf[BUFSIZ]; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 216 | |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 217 | inet_ntop (AF_INET6, &nh6->ip6, (char *) buf, BUFSIZ); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 218 | |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 219 | zlog_debug (" %s %u", buf, nh6->ifindex); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 220 | } |
| 221 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 222 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 223 | nexthops6_print (struct list *nhs6) |
| 224 | { |
| 225 | struct listnode *node; |
jardin | 10fc918 | 2005-10-01 00:09:39 +0000 | [diff] [blame] | 226 | struct isis_nexthop6 *nh6; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 227 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 228 | for (ALL_LIST_ELEMENTS_RO (nhs6, node, nh6)) |
| 229 | nexthop6_print (nh6); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 230 | } |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 231 | #endif /* EXTREME_DEBUG */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 232 | #endif /* HAVE_IPV6 */ |
| 233 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 234 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 235 | adjinfo2nexthop (struct list *nexthops, struct isis_adjacency *adj) |
| 236 | { |
| 237 | struct isis_nexthop *nh; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 238 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 239 | struct in_addr *ipv4_addr; |
| 240 | |
| 241 | if (adj->ipv4_addrs == NULL) |
| 242 | return; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 243 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 244 | for (ALL_LIST_ELEMENTS_RO (adj->ipv4_addrs, node, ipv4_addr)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 245 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 246 | if (!nexthoplookup (nexthops, ipv4_addr, |
| 247 | adj->circuit->interface->ifindex)) |
| 248 | { |
| 249 | nh = isis_nexthop_create (ipv4_addr, |
| 250 | adj->circuit->interface->ifindex); |
| 251 | listnode_add (nexthops, nh); |
| 252 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 253 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | #ifdef HAVE_IPV6 |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 257 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 258 | adjinfo2nexthop6 (struct list *nexthops6, struct isis_adjacency *adj) |
| 259 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 260 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 261 | struct in6_addr *ipv6_addr; |
| 262 | struct isis_nexthop6 *nh6; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 263 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 264 | if (!adj->ipv6_addrs) |
| 265 | return; |
| 266 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 267 | for (ALL_LIST_ELEMENTS_RO (adj->ipv6_addrs, node, ipv6_addr)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 268 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 269 | if (!nexthop6lookup (nexthops6, ipv6_addr, |
| 270 | adj->circuit->interface->ifindex)) |
| 271 | { |
| 272 | nh6 = isis_nexthop6_create (ipv6_addr, |
| 273 | adj->circuit->interface->ifindex); |
| 274 | listnode_add (nexthops6, nh6); |
| 275 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 276 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 277 | } |
| 278 | #endif /* HAVE_IPV6 */ |
| 279 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 280 | static struct isis_route_info * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 281 | isis_route_info_new (uint32_t cost, uint32_t depth, u_char family, |
| 282 | struct list *adjacencies) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 283 | { |
| 284 | struct isis_route_info *rinfo; |
| 285 | struct isis_adjacency *adj; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 286 | struct listnode *node; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 287 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 288 | rinfo = XCALLOC (MTYPE_ISIS_ROUTE_INFO, sizeof (struct isis_route_info)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 289 | if (!rinfo) |
| 290 | { |
| 291 | zlog_err ("ISIS-Rte: isis_route_info_new: out of memory!"); |
| 292 | return NULL; |
| 293 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 294 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 295 | if (family == AF_INET) |
| 296 | { |
| 297 | rinfo->nexthops = list_new (); |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 298 | for (ALL_LIST_ELEMENTS_RO (adjacencies, node, adj)) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 299 | adjinfo2nexthop (rinfo->nexthops, adj); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 300 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 301 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 302 | if (family == AF_INET6) |
| 303 | { |
| 304 | rinfo->nexthops6 = list_new (); |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 305 | for (ALL_LIST_ELEMENTS_RO (adjacencies, node, adj)) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 306 | adjinfo2nexthop6 (rinfo->nexthops6, adj); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 307 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 308 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 309 | #endif /* HAVE_IPV6 */ |
| 310 | |
| 311 | rinfo->cost = cost; |
| 312 | rinfo->depth = depth; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 313 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 314 | return rinfo; |
| 315 | } |
| 316 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 317 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 318 | isis_route_info_delete (struct isis_route_info *route_info) |
| 319 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 320 | if (route_info->nexthops) |
| 321 | { |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 322 | route_info->nexthops->del = (void (*)(void *)) isis_nexthop_delete; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 323 | list_delete (route_info->nexthops); |
| 324 | } |
| 325 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 326 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 327 | if (route_info->nexthops6) |
| 328 | { |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 329 | route_info->nexthops6->del = (void (*)(void *)) isis_nexthop6_delete; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 330 | list_delete (route_info->nexthops6); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 331 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 332 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 333 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 334 | XFREE (MTYPE_ISIS_ROUTE_INFO, route_info); |
| 335 | } |
| 336 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 337 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 338 | isis_route_info_same_attrib (struct isis_route_info *new, |
| 339 | struct isis_route_info *old) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 340 | { |
| 341 | if (new->cost != old->cost) |
| 342 | return 0; |
| 343 | if (new->depth != old->depth) |
| 344 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 345 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 346 | return 1; |
| 347 | } |
| 348 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 349 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 350 | isis_route_info_same (struct isis_route_info *new, |
| 351 | struct isis_route_info *old, u_char family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 352 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 353 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 354 | struct isis_nexthop *nexthop; |
| 355 | #ifdef HAVE_IPV6 |
| 356 | struct isis_nexthop6 *nexthop6; |
| 357 | #endif /* HAVE_IPV6 */ |
| 358 | if (!isis_route_info_same_attrib (new, old)) |
| 359 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 360 | |
| 361 | if (family == AF_INET) |
| 362 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 363 | for (ALL_LIST_ELEMENTS_RO (new->nexthops, node, nexthop)) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 364 | if (nexthoplookup (old->nexthops, &nexthop->ip, nexthop->ifindex) |
| 365 | == 0) |
| 366 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 367 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 368 | for (ALL_LIST_ELEMENTS_RO (old->nexthops, node, nexthop)) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 369 | if (nexthoplookup (new->nexthops, &nexthop->ip, nexthop->ifindex) |
| 370 | == 0) |
| 371 | return 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 372 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 373 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 374 | else if (family == AF_INET6) |
| 375 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 376 | for (ALL_LIST_ELEMENTS_RO (new->nexthops6, node, nexthop6)) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 377 | if (nexthop6lookup (old->nexthops6, &nexthop6->ip6, |
| 378 | nexthop6->ifindex) == 0) |
| 379 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 380 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 381 | for (ALL_LIST_ELEMENTS_RO (old->nexthops6, node, nexthop6)) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 382 | if (nexthop6lookup (new->nexthops6, &nexthop6->ip6, |
| 383 | nexthop6->ifindex) == 0) |
| 384 | return 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 385 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 386 | #endif /* HAVE_IPV6 */ |
| 387 | |
| 388 | return 1; |
| 389 | } |
| 390 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 391 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 392 | isis_nexthops_merge (struct list *new, struct list *old) |
| 393 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 394 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 395 | struct isis_nexthop *nexthop; |
| 396 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 397 | for (ALL_LIST_ELEMENTS_RO (new, node, nexthop)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 398 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 399 | if (nexthoplookup (old, &nexthop->ip, nexthop->ifindex)) |
| 400 | continue; |
| 401 | listnode_add (old, nexthop); |
| 402 | nexthop->lock++; |
| 403 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 404 | } |
| 405 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 406 | #ifdef HAVE_IPV6 |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 407 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 408 | isis_nexthops6_merge (struct list *new, struct list *old) |
| 409 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 410 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 411 | struct isis_nexthop6 *nexthop6; |
| 412 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 413 | for (ALL_LIST_ELEMENTS_RO (new, node, nexthop6)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 414 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 415 | if (nexthop6lookup (old, &nexthop6->ip6, nexthop6->ifindex)) |
| 416 | continue; |
| 417 | listnode_add (old, nexthop6); |
| 418 | nexthop6->lock++; |
| 419 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 420 | } |
| 421 | #endif /* HAVE_IPV6 */ |
| 422 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 423 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 424 | isis_route_info_merge (struct isis_route_info *new, |
| 425 | struct isis_route_info *old, u_char family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 426 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 427 | if (family == AF_INET) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 428 | isis_nexthops_merge (new->nexthops, old->nexthops); |
| 429 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 430 | else if (family == AF_INET6) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 431 | isis_nexthops6_merge (new->nexthops6, old->nexthops6); |
| 432 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 433 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 434 | return; |
| 435 | } |
| 436 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 437 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 438 | isis_route_info_prefer_new (struct isis_route_info *new, |
| 439 | struct isis_route_info *old) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 440 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 441 | if (!CHECK_FLAG (old->flag, ISIS_ROUTE_FLAG_ACTIVE)) |
| 442 | return 1; |
| 443 | |
| 444 | if (new->cost < old->cost) |
| 445 | return 1; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 446 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 450 | struct isis_route_info * |
| 451 | isis_route_create (struct prefix *prefix, u_int32_t cost, u_int32_t depth, |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 452 | struct list *adjacencies, struct isis_area *area, |
| 453 | int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 454 | { |
| 455 | struct route_node *route_node; |
| 456 | struct isis_route_info *rinfo_new, *rinfo_old, *route_info = NULL; |
| 457 | u_char buff[BUFSIZ]; |
| 458 | u_char family; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 459 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 460 | family = prefix->family; |
| 461 | /* for debugs */ |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 462 | prefix2str (prefix, (char *) buff, BUFSIZ); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 463 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 464 | rinfo_new = isis_route_info_new (cost, depth, family, adjacencies); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 465 | if (!rinfo_new) |
| 466 | { |
| 467 | zlog_err ("ISIS-Rte (%s): isis_route_create: out of memory!", |
| 468 | area->area_tag); |
| 469 | return NULL; |
| 470 | } |
| 471 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 472 | if (family == AF_INET) |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 473 | route_node = route_node_get (area->route_table[level - 1], prefix); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 474 | #ifdef HAVE_IPV6 |
| 475 | else if (family == AF_INET6) |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 476 | route_node = route_node_get (area->route_table6[level - 1], prefix); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 477 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 478 | else |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 479 | return NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 480 | rinfo_old = route_node->info; |
| 481 | if (!rinfo_old) |
| 482 | { |
| 483 | if (isis->debugs & DEBUG_RTE_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 484 | zlog_debug ("ISIS-Rte (%s) route created: %s", area->area_tag, buff); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 485 | SET_FLAG (rinfo_new->flag, ISIS_ROUTE_FLAG_ACTIVE); |
| 486 | route_node->info = rinfo_new; |
| 487 | return rinfo_new; |
| 488 | } |
| 489 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 490 | if (isis->debugs & DEBUG_RTE_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 491 | zlog_debug ("ISIS-Rte (%s) route already exists: %s", area->area_tag, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 492 | buff); |
| 493 | |
| 494 | if (isis_route_info_same (rinfo_new, rinfo_old, family)) |
| 495 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 496 | if (isis->debugs & DEBUG_RTE_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 497 | zlog_debug ("ISIS-Rte (%s) route unchanged: %s", area->area_tag, buff); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 498 | isis_route_info_delete (rinfo_new); |
| 499 | route_info = rinfo_old; |
| 500 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 501 | else if (isis_route_info_same_attrib (rinfo_new, rinfo_old)) |
| 502 | { |
| 503 | /* merge the nexthop lists */ |
| 504 | if (isis->debugs & DEBUG_RTE_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 505 | zlog_debug ("ISIS-Rte (%s) route changed (same attribs): %s", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 506 | area->area_tag, buff); |
| 507 | #ifdef EXTREME_DEBUG |
hasso | 3d54927 | 2005-09-21 18:52:14 +0000 | [diff] [blame] | 508 | if (family == AF_INET) |
| 509 | { |
| 510 | zlog_debug ("Old nexthops"); |
| 511 | nexthops_print (rinfo_old->nexthops); |
| 512 | zlog_debug ("New nexthops"); |
| 513 | nexthops_print (rinfo_new->nexthops); |
| 514 | } |
| 515 | else if (family == AF_INET6) |
| 516 | { |
| 517 | zlog_debug ("Old nexthops"); |
| 518 | nexthops6_print (rinfo_old->nexthops6); |
| 519 | zlog_debug ("New nexthops"); |
| 520 | nexthops6_print (rinfo_new->nexthops6); |
| 521 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 522 | #endif /* EXTREME_DEBUG */ |
| 523 | isis_route_info_merge (rinfo_new, rinfo_old, family); |
| 524 | isis_route_info_delete (rinfo_new); |
| 525 | route_info = rinfo_old; |
hasso | 13fb40a | 2005-10-01 06:03:04 +0000 | [diff] [blame] | 526 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 527 | } |
| 528 | else |
| 529 | { |
| 530 | if (isis_route_info_prefer_new (rinfo_new, rinfo_old)) |
| 531 | { |
| 532 | if (isis->debugs & DEBUG_RTE_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 533 | zlog_debug ("ISIS-Rte (%s) route changed: %s", area->area_tag, |
| 534 | buff); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 535 | isis_route_info_delete (rinfo_old); |
| 536 | route_info = rinfo_new; |
| 537 | } |
| 538 | else |
| 539 | { |
| 540 | if (isis->debugs & DEBUG_RTE_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 541 | zlog_debug ("ISIS-Rte (%s) route rejected: %s", area->area_tag, |
| 542 | buff); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 543 | isis_route_info_delete (rinfo_new); |
| 544 | route_info = rinfo_old; |
| 545 | } |
| 546 | } |
| 547 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 548 | SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE); |
| 549 | route_node->info = route_info; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 550 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 551 | return route_info; |
| 552 | } |
| 553 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 554 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 555 | isis_route_delete (struct prefix *prefix, struct route_table *table) |
| 556 | { |
| 557 | struct route_node *rode; |
| 558 | struct isis_route_info *rinfo; |
| 559 | char buff[BUFSIZ]; |
| 560 | |
| 561 | /* for log */ |
| 562 | prefix2str (prefix, buff, BUFSIZ); |
| 563 | |
| 564 | |
| 565 | rode = route_node_get (table, prefix); |
| 566 | rinfo = rode->info; |
| 567 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 568 | if (rinfo == NULL) |
| 569 | { |
| 570 | if (isis->debugs & DEBUG_RTE_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 571 | zlog_debug ("ISIS-Rte: tried to delete non-existant route %s", buff); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 572 | return; |
| 573 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 574 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 575 | if (CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) |
| 576 | { |
| 577 | UNSET_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE); |
| 578 | if (isis->debugs & DEBUG_RTE_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 579 | zlog_debug ("ISIS-Rte: route delete %s", buff); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 580 | isis_zebra_route_update (prefix, rinfo); |
| 581 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 582 | isis_route_info_delete (rinfo); |
| 583 | rode->info = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 584 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 585 | return; |
| 586 | } |
| 587 | |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 588 | /* Validating routes in particular table. */ |
| 589 | static void |
| 590 | isis_route_validate_table (struct isis_area *area, struct route_table *table) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 591 | { |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 592 | struct route_node *rnode, *drnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 593 | struct isis_route_info *rinfo; |
| 594 | u_char buff[BUFSIZ]; |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 595 | |
| 596 | for (rnode = route_top (table); rnode; rnode = route_next (rnode)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 597 | { |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 598 | if (rnode->info == NULL) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 599 | continue; |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 600 | rinfo = rnode->info; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 601 | |
| 602 | if (isis->debugs & DEBUG_RTE_EVENTS) |
| 603 | { |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 604 | prefix2str (&rnode->p, (char *) buff, BUFSIZ); |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 605 | zlog_debug ("ISIS-Rte (%s): route validate: %s %s %s", |
| 606 | area->area_tag, |
| 607 | (CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC) ? |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 608 | "sync'ed" : "nosync"), |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 609 | (CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE) ? |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 610 | "active" : "inactive"), buff); |
| 611 | } |
| 612 | |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 613 | isis_zebra_route_update (&rnode->p, rinfo); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 614 | if (!CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE)) |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 615 | { |
| 616 | /* Area is either L1 or L2 => we use level route tables directly for |
| 617 | * validating => no problems with deleting routes. */ |
| 618 | if (area->is_type != IS_LEVEL_1_AND_2) |
| 619 | { |
| 620 | isis_route_delete (&rnode->p, table); |
| 621 | continue; |
| 622 | } |
| 623 | /* If area is L1L2, we work with merge table and therefore must |
| 624 | * delete node from level tables as well before deleting route info. |
| 625 | * FIXME: Is it performance problem? There has to be the better way. |
| 626 | * Like not to deal with it here at all (see the next comment)? */ |
| 627 | if (rnode->p.family == AF_INET) |
| 628 | { |
| 629 | drnode = route_node_get (area->route_table[0], &rnode->p); |
| 630 | if (drnode->info == rnode->info) |
| 631 | drnode->info = NULL; |
| 632 | drnode = route_node_get (area->route_table[1], &rnode->p); |
| 633 | if (drnode->info == rnode->info) |
| 634 | drnode->info = NULL; |
| 635 | } |
| 636 | if (rnode->p.family == AF_INET6) |
| 637 | { |
| 638 | drnode = route_node_get (area->route_table6[0], &rnode->p); |
| 639 | if (drnode->info == rnode->info) |
| 640 | drnode->info = NULL; |
| 641 | drnode = route_node_get (area->route_table6[1], &rnode->p); |
| 642 | if (drnode->info == rnode->info) |
| 643 | drnode->info = NULL; |
| 644 | } |
| 645 | |
| 646 | isis_route_delete (&rnode->p, table); |
| 647 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 648 | } |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | /* Function to validate route tables for L1L2 areas. In this case we can't use |
| 652 | * level route tables directly, we have to merge them at first. L1 routes are |
| 653 | * preferred over the L2 ones. |
| 654 | * |
| 655 | * Merge algorithm is trivial (at least for now). All L1 paths are copied into |
| 656 | * merge table at first, then L2 paths are added if L1 path for same prefix |
| 657 | * doesn't already exists there. |
| 658 | * |
| 659 | * FIXME: Is it right place to do it at all? Maybe we should push both levels |
| 660 | * to the RIB with different zebra route types and let RIB handle this? */ |
| 661 | static void |
| 662 | isis_route_validate_merge (struct isis_area *area, int family) |
| 663 | { |
| 664 | struct route_table *table = NULL; |
| 665 | struct route_table *merge; |
| 666 | struct route_node *rnode, *mrnode; |
| 667 | |
| 668 | merge = route_table_init (); |
| 669 | |
| 670 | if (family == AF_INET) |
| 671 | table = area->route_table[0]; |
| 672 | else if (family == AF_INET6) |
| 673 | table = area->route_table6[0]; |
| 674 | |
| 675 | for (rnode = route_top (table); rnode; rnode = route_next (rnode)) |
| 676 | { |
| 677 | if (rnode->info == NULL) |
| 678 | continue; |
| 679 | mrnode = route_node_get (merge, &rnode->p); |
| 680 | mrnode->info = rnode->info; |
| 681 | } |
| 682 | |
| 683 | if (family == AF_INET) |
| 684 | table = area->route_table[1]; |
| 685 | else if (family == AF_INET6) |
| 686 | table = area->route_table6[1]; |
| 687 | |
| 688 | for (rnode = route_top (table); rnode; rnode = route_next (rnode)) |
| 689 | { |
| 690 | if (rnode->info == NULL) |
| 691 | continue; |
| 692 | mrnode = route_node_get (merge, &rnode->p); |
| 693 | if (mrnode->info != NULL) |
| 694 | continue; |
| 695 | mrnode->info = rnode->info; |
| 696 | } |
| 697 | |
| 698 | isis_route_validate_table (area, merge); |
| 699 | route_table_finish (merge); |
| 700 | } |
| 701 | |
| 702 | /* Walk through route tables and propagate necessary changes into RIB. In case |
| 703 | * of L1L2 area, level tables have to be merged at first. */ |
| 704 | int |
| 705 | isis_route_validate (struct thread *thread) |
| 706 | { |
| 707 | struct isis_area *area; |
| 708 | |
| 709 | area = THREAD_ARG (thread); |
| 710 | |
| 711 | if (area->is_type == IS_LEVEL_1) |
| 712 | { |
| 713 | isis_route_validate_table (area, area->route_table[0]); |
| 714 | goto validate_ipv6; |
| 715 | } |
| 716 | if (area->is_type == IS_LEVEL_2) |
| 717 | { |
| 718 | isis_route_validate_table (area, area->route_table[1]); |
| 719 | goto validate_ipv6; |
| 720 | } |
| 721 | |
| 722 | isis_route_validate_merge (area, AF_INET); |
| 723 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 724 | #ifdef HAVE_IPV6 |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 725 | validate_ipv6: |
| 726 | if (area->is_type == IS_LEVEL_1) |
| 727 | { |
| 728 | isis_route_validate_table (area, area->route_table6[0]); |
| 729 | return ISIS_OK; |
| 730 | } |
| 731 | if (area->is_type == IS_LEVEL_2) |
| 732 | { |
| 733 | isis_route_validate_table (area, area->route_table6[1]); |
| 734 | return ISIS_OK; |
| 735 | } |
| 736 | |
| 737 | isis_route_validate_merge (area, AF_INET6); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 738 | #endif |
| 739 | |
| 740 | return ISIS_OK; |
| 741 | } |