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