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