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