blob: 96d8df8fa19863237bf769d06d6a299e21fa7727 [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
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
jardineb5d44e2003-12-23 08:09:43 +000025#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000026
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 Bailey3f045a02012-03-24 08:35:20 -070039#include "isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000040#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
hasso92365882005-01-18 13:53:33 +000052static struct isis_nexthop *
jardineb5d44e2003-12-23 08:09:43 +000053isis_nexthop_create (struct in_addr *ip, unsigned int ifindex)
jardineb5d44e2003-12-23 08:09:43 +000054{
55 struct listnode *node;
56 struct isis_nexthop *nexthop;
jardineb5d44e2003-12-23 08:09:43 +000057
paul1eb8ef22005-04-07 07:30:20 +000058 for (ALL_LIST_ELEMENTS_RO (isis->nexthops, node, nexthop))
hassof390d2c2004-09-10 20:48:21 +000059 {
hassof390d2c2004-09-10 20:48:21 +000060 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
hasso3fdb2dd2005-09-28 18:45:54 +000069 nexthop = XCALLOC (MTYPE_ISIS_NEXTHOP, sizeof (struct isis_nexthop));
hassof390d2c2004-09-10 20:48:21 +000070 if (!nexthop)
71 {
72 zlog_err ("ISIS-Rte: isis_nexthop_create: out of memory!");
73 }
74
jardineb5d44e2003-12-23 08:09:43 +000075 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
hasso92365882005-01-18 13:53:33 +000083static void
jardineb5d44e2003-12-23 08:09:43 +000084isis_nexthop_delete (struct isis_nexthop *nexthop)
85{
86 nexthop->lock--;
hassof390d2c2004-09-10 20:48:21 +000087 if (nexthop->lock == 0)
88 {
89 listnode_delete (isis->nexthops, nexthop);
90 XFREE (MTYPE_ISIS_NEXTHOP, nexthop);
91 }
92
jardineb5d44e2003-12-23 08:09:43 +000093 return;
94}
95
hasso92365882005-01-18 13:53:33 +000096static int
hassof390d2c2004-09-10 20:48:21 +000097nexthoplookup (struct list *nexthops, struct in_addr *ip,
98 unsigned int ifindex)
jardineb5d44e2003-12-23 08:09:43 +000099{
100 struct listnode *node;
101 struct isis_nexthop *nh;
102
paul1eb8ef22005-04-07 07:30:20 +0000103 for (ALL_LIST_ELEMENTS_RO (nexthops, node, nh))
hassof390d2c2004-09-10 20:48:21 +0000104 {
hassof390d2c2004-09-10 20:48:21 +0000105 if (!(memcmp (ip, &nh->ip, sizeof (struct in_addr))) &&
106 ifindex == nh->ifindex)
107 return 1;
108 }
jardineb5d44e2003-12-23 08:09:43 +0000109
110 return 0;
111}
112
hasso3d549272005-09-21 18:52:14 +0000113#ifdef EXTREME_DEBUG
hasso92365882005-01-18 13:53:33 +0000114static void
jardineb5d44e2003-12-23 08:09:43 +0000115nexthop_print (struct isis_nexthop *nh)
116{
117 u_char buf[BUFSIZ];
hassof390d2c2004-09-10 20:48:21 +0000118
hassof7c43dc2004-09-26 16:24:14 +0000119 inet_ntop (AF_INET, &nh->ip, (char *) buf, BUFSIZ);
hassof390d2c2004-09-10 20:48:21 +0000120
hasso529d65b2004-12-24 00:14:50 +0000121 zlog_debug (" %s %u", buf, nh->ifindex);
jardineb5d44e2003-12-23 08:09:43 +0000122}
123
hasso92365882005-01-18 13:53:33 +0000124static void
jardineb5d44e2003-12-23 08:09:43 +0000125nexthops_print (struct list *nhs)
126{
127 struct listnode *node;
hasso13fb40a2005-10-01 06:03:04 +0000128 struct isis_nexthop *nh;
hassof390d2c2004-09-10 20:48:21 +0000129
paul1eb8ef22005-04-07 07:30:20 +0000130 for (ALL_LIST_ELEMENTS_RO (nhs, node, nh))
131 nexthop_print (nh);
jardineb5d44e2003-12-23 08:09:43 +0000132}
hasso3d549272005-09-21 18:52:14 +0000133#endif /* EXTREME_DEBUG */
jardineb5d44e2003-12-23 08:09:43 +0000134
135#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000136static struct isis_nexthop6 *
hassof390d2c2004-09-10 20:48:21 +0000137isis_nexthop6_new (struct in6_addr *ip6, unsigned int ifindex)
jardineb5d44e2003-12-23 08:09:43 +0000138{
jardineb5d44e2003-12-23 08:09:43 +0000139 struct isis_nexthop6 *nexthop6;
hassof390d2c2004-09-10 20:48:21 +0000140
hasso3fdb2dd2005-09-28 18:45:54 +0000141 nexthop6 = XCALLOC (MTYPE_ISIS_NEXTHOP6, sizeof (struct isis_nexthop6));
hassof390d2c2004-09-10 20:48:21 +0000142 if (!nexthop6)
143 {
144 zlog_err ("ISIS-Rte: isis_nexthop_create6: out of memory!");
145 }
146
jardineb5d44e2003-12-23 08:09:43 +0000147 nexthop6->ifindex = ifindex;
148 memcpy (&nexthop6->ip6, ip6, sizeof (struct in6_addr));
149 nexthop6->lock++;
150
151 return nexthop6;
152}
153
hasso92365882005-01-18 13:53:33 +0000154static struct isis_nexthop6 *
jardineb5d44e2003-12-23 08:09:43 +0000155isis_nexthop6_create (struct in6_addr *ip6, unsigned int ifindex)
jardineb5d44e2003-12-23 08:09:43 +0000156{
157 struct listnode *node;
158 struct isis_nexthop6 *nexthop6;
jardineb5d44e2003-12-23 08:09:43 +0000159
paul1eb8ef22005-04-07 07:30:20 +0000160 for (ALL_LIST_ELEMENTS_RO (isis->nexthops6, node, nexthop6))
hassof390d2c2004-09-10 20:48:21 +0000161 {
hassof390d2c2004-09-10 20:48:21 +0000162 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
jardineb5d44e2003-12-23 08:09:43 +0000171 nexthop6 = isis_nexthop6_new (ip6, ifindex);
172
173 return nexthop6;
174}
175
hasso92365882005-01-18 13:53:33 +0000176static void
jardineb5d44e2003-12-23 08:09:43 +0000177isis_nexthop6_delete (struct isis_nexthop6 *nexthop6)
178{
179
180 nexthop6->lock--;
hassof390d2c2004-09-10 20:48:21 +0000181 if (nexthop6->lock == 0)
182 {
183 listnode_delete (isis->nexthops6, nexthop6);
184 XFREE (MTYPE_ISIS_NEXTHOP6, nexthop6);
185 }
186
jardineb5d44e2003-12-23 08:09:43 +0000187 return;
188}
189
hasso92365882005-01-18 13:53:33 +0000190static int
hassof390d2c2004-09-10 20:48:21 +0000191nexthop6lookup (struct list *nexthops6, struct in6_addr *ip6,
192 unsigned int ifindex)
jardineb5d44e2003-12-23 08:09:43 +0000193{
194 struct listnode *node;
195 struct isis_nexthop6 *nh6;
196
paul1eb8ef22005-04-07 07:30:20 +0000197 for (ALL_LIST_ELEMENTS_RO (nexthops6, node, nh6))
hassof390d2c2004-09-10 20:48:21 +0000198 {
hassof390d2c2004-09-10 20:48:21 +0000199 if (!(memcmp (ip6, &nh6->ip6, sizeof (struct in6_addr))) &&
200 ifindex == nh6->ifindex)
201 return 1;
202 }
jardineb5d44e2003-12-23 08:09:43 +0000203
204 return 0;
205}
206
hasso92365882005-01-18 13:53:33 +0000207#ifdef EXTREME_DEBUG
208static void
jardineb5d44e2003-12-23 08:09:43 +0000209nexthop6_print (struct isis_nexthop6 *nh6)
210{
211 u_char buf[BUFSIZ];
hassof390d2c2004-09-10 20:48:21 +0000212
hassof7c43dc2004-09-26 16:24:14 +0000213 inet_ntop (AF_INET6, &nh6->ip6, (char *) buf, BUFSIZ);
hassof390d2c2004-09-10 20:48:21 +0000214
hasso529d65b2004-12-24 00:14:50 +0000215 zlog_debug (" %s %u", buf, nh6->ifindex);
jardineb5d44e2003-12-23 08:09:43 +0000216}
217
hasso92365882005-01-18 13:53:33 +0000218static void
jardineb5d44e2003-12-23 08:09:43 +0000219nexthops6_print (struct list *nhs6)
220{
221 struct listnode *node;
jardin10fc9182005-10-01 00:09:39 +0000222 struct isis_nexthop6 *nh6;
hassof390d2c2004-09-10 20:48:21 +0000223
paul1eb8ef22005-04-07 07:30:20 +0000224 for (ALL_LIST_ELEMENTS_RO (nhs6, node, nh6))
225 nexthop6_print (nh6);
jardineb5d44e2003-12-23 08:09:43 +0000226}
hasso92365882005-01-18 13:53:33 +0000227#endif /* EXTREME_DEBUG */
jardineb5d44e2003-12-23 08:09:43 +0000228#endif /* HAVE_IPV6 */
229
hasso92365882005-01-18 13:53:33 +0000230static void
jardineb5d44e2003-12-23 08:09:43 +0000231adjinfo2nexthop (struct list *nexthops, struct isis_adjacency *adj)
232{
233 struct isis_nexthop *nh;
hasso3fdb2dd2005-09-28 18:45:54 +0000234 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000235 struct in_addr *ipv4_addr;
236
237 if (adj->ipv4_addrs == NULL)
238 return;
paul1eb8ef22005-04-07 07:30:20 +0000239
hasso3fdb2dd2005-09-28 18:45:54 +0000240 for (ALL_LIST_ELEMENTS_RO (adj->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000241 {
hassof390d2c2004-09-10 20:48:21 +0000242 if (!nexthoplookup (nexthops, ipv4_addr,
243 adj->circuit->interface->ifindex))
244 {
245 nh = isis_nexthop_create (ipv4_addr,
246 adj->circuit->interface->ifindex);
247 listnode_add (nexthops, nh);
248 }
jardineb5d44e2003-12-23 08:09:43 +0000249 }
jardineb5d44e2003-12-23 08:09:43 +0000250}
251
252#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000253static void
jardineb5d44e2003-12-23 08:09:43 +0000254adjinfo2nexthop6 (struct list *nexthops6, struct isis_adjacency *adj)
255{
hasso3fdb2dd2005-09-28 18:45:54 +0000256 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000257 struct in6_addr *ipv6_addr;
258 struct isis_nexthop6 *nh6;
hassof390d2c2004-09-10 20:48:21 +0000259
jardineb5d44e2003-12-23 08:09:43 +0000260 if (!adj->ipv6_addrs)
261 return;
262
hasso3fdb2dd2005-09-28 18:45:54 +0000263 for (ALL_LIST_ELEMENTS_RO (adj->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000264 {
hassof390d2c2004-09-10 20:48:21 +0000265 if (!nexthop6lookup (nexthops6, ipv6_addr,
266 adj->circuit->interface->ifindex))
267 {
268 nh6 = isis_nexthop6_create (ipv6_addr,
269 adj->circuit->interface->ifindex);
270 listnode_add (nexthops6, nh6);
271 }
jardineb5d44e2003-12-23 08:09:43 +0000272 }
jardineb5d44e2003-12-23 08:09:43 +0000273}
274#endif /* HAVE_IPV6 */
275
hasso92365882005-01-18 13:53:33 +0000276static struct isis_route_info *
hassof390d2c2004-09-10 20:48:21 +0000277isis_route_info_new (uint32_t cost, uint32_t depth, u_char family,
278 struct list *adjacencies)
jardineb5d44e2003-12-23 08:09:43 +0000279{
280 struct isis_route_info *rinfo;
281 struct isis_adjacency *adj;
hasso3fdb2dd2005-09-28 18:45:54 +0000282 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000283
hasso3fdb2dd2005-09-28 18:45:54 +0000284 rinfo = XCALLOC (MTYPE_ISIS_ROUTE_INFO, sizeof (struct isis_route_info));
hassof390d2c2004-09-10 20:48:21 +0000285 if (!rinfo)
286 {
287 zlog_err ("ISIS-Rte: isis_route_info_new: out of memory!");
288 return NULL;
289 }
jardineb5d44e2003-12-23 08:09:43 +0000290
hassof390d2c2004-09-10 20:48:21 +0000291 if (family == AF_INET)
292 {
293 rinfo->nexthops = list_new ();
hasso3fdb2dd2005-09-28 18:45:54 +0000294 for (ALL_LIST_ELEMENTS_RO (adjacencies, node, adj))
Josh Bailey3f045a02012-03-24 08:35:20 -0700295 {
296 /* check for force resync this route */
297 if (CHECK_FLAG (adj->circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF))
298 SET_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC);
299 adjinfo2nexthop (rinfo->nexthops, adj);
300 }
jardineb5d44e2003-12-23 08:09:43 +0000301 }
jardineb5d44e2003-12-23 08:09:43 +0000302#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000303 if (family == AF_INET6)
304 {
305 rinfo->nexthops6 = list_new ();
hasso3fdb2dd2005-09-28 18:45:54 +0000306 for (ALL_LIST_ELEMENTS_RO (adjacencies, node, adj))
Josh Bailey3f045a02012-03-24 08:35:20 -0700307 {
308 /* check for force resync this route */
309 if (CHECK_FLAG (adj->circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF))
310 SET_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC);
311 adjinfo2nexthop6 (rinfo->nexthops6, adj);
312 }
jardineb5d44e2003-12-23 08:09:43 +0000313 }
hassof390d2c2004-09-10 20:48:21 +0000314
jardineb5d44e2003-12-23 08:09:43 +0000315#endif /* HAVE_IPV6 */
316
317 rinfo->cost = cost;
318 rinfo->depth = depth;
hassof390d2c2004-09-10 20:48:21 +0000319
jardineb5d44e2003-12-23 08:09:43 +0000320 return rinfo;
321}
322
hasso92365882005-01-18 13:53:33 +0000323static void
jardineb5d44e2003-12-23 08:09:43 +0000324isis_route_info_delete (struct isis_route_info *route_info)
325{
hassof390d2c2004-09-10 20:48:21 +0000326 if (route_info->nexthops)
327 {
hassof7c43dc2004-09-26 16:24:14 +0000328 route_info->nexthops->del = (void (*)(void *)) isis_nexthop_delete;
hassof390d2c2004-09-10 20:48:21 +0000329 list_delete (route_info->nexthops);
330 }
331
jardineb5d44e2003-12-23 08:09:43 +0000332#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000333 if (route_info->nexthops6)
334 {
hassof7c43dc2004-09-26 16:24:14 +0000335 route_info->nexthops6->del = (void (*)(void *)) isis_nexthop6_delete;
jardineb5d44e2003-12-23 08:09:43 +0000336 list_delete (route_info->nexthops6);
hassof390d2c2004-09-10 20:48:21 +0000337 }
jardineb5d44e2003-12-23 08:09:43 +0000338#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000339
jardineb5d44e2003-12-23 08:09:43 +0000340 XFREE (MTYPE_ISIS_ROUTE_INFO, route_info);
341}
342
hasso92365882005-01-18 13:53:33 +0000343static int
hassof390d2c2004-09-10 20:48:21 +0000344isis_route_info_same_attrib (struct isis_route_info *new,
345 struct isis_route_info *old)
jardineb5d44e2003-12-23 08:09:43 +0000346{
347 if (new->cost != old->cost)
348 return 0;
349 if (new->depth != old->depth)
350 return 0;
hassof390d2c2004-09-10 20:48:21 +0000351
jardineb5d44e2003-12-23 08:09:43 +0000352 return 1;
353}
354
hasso92365882005-01-18 13:53:33 +0000355static int
hassof390d2c2004-09-10 20:48:21 +0000356isis_route_info_same (struct isis_route_info *new,
357 struct isis_route_info *old, u_char family)
jardineb5d44e2003-12-23 08:09:43 +0000358{
hasso3fdb2dd2005-09-28 18:45:54 +0000359 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000360 struct isis_nexthop *nexthop;
361#ifdef HAVE_IPV6
362 struct isis_nexthop6 *nexthop6;
363#endif /* HAVE_IPV6 */
Josh Bailey3f045a02012-03-24 08:35:20 -0700364
365 if (!CHECK_FLAG (old->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED))
366 return 0;
367
368 if (CHECK_FLAG (new->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC))
369 return 0;
370
jardineb5d44e2003-12-23 08:09:43 +0000371 if (!isis_route_info_same_attrib (new, old))
372 return 0;
hassof390d2c2004-09-10 20:48:21 +0000373
374 if (family == AF_INET)
375 {
hasso3fdb2dd2005-09-28 18:45:54 +0000376 for (ALL_LIST_ELEMENTS_RO (new->nexthops, node, nexthop))
Josh Bailey3f045a02012-03-24 08:35:20 -0700377 if (nexthoplookup (old->nexthops, &nexthop->ip, nexthop->ifindex)
paul1eb8ef22005-04-07 07:30:20 +0000378 == 0)
379 return 0;
hassof390d2c2004-09-10 20:48:21 +0000380
hasso3fdb2dd2005-09-28 18:45:54 +0000381 for (ALL_LIST_ELEMENTS_RO (old->nexthops, node, nexthop))
Josh Bailey3f045a02012-03-24 08:35:20 -0700382 if (nexthoplookup (new->nexthops, &nexthop->ip, nexthop->ifindex)
paul1eb8ef22005-04-07 07:30:20 +0000383 == 0)
384 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000385 }
jardineb5d44e2003-12-23 08:09:43 +0000386#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000387 else if (family == AF_INET6)
388 {
hasso3fdb2dd2005-09-28 18:45:54 +0000389 for (ALL_LIST_ELEMENTS_RO (new->nexthops6, node, nexthop6))
paul1eb8ef22005-04-07 07:30:20 +0000390 if (nexthop6lookup (old->nexthops6, &nexthop6->ip6,
391 nexthop6->ifindex) == 0)
392 return 0;
hassof390d2c2004-09-10 20:48:21 +0000393
hasso3fdb2dd2005-09-28 18:45:54 +0000394 for (ALL_LIST_ELEMENTS_RO (old->nexthops6, node, nexthop6))
paul1eb8ef22005-04-07 07:30:20 +0000395 if (nexthop6lookup (new->nexthops6, &nexthop6->ip6,
396 nexthop6->ifindex) == 0)
397 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000398 }
jardineb5d44e2003-12-23 08:09:43 +0000399#endif /* HAVE_IPV6 */
400
401 return 1;
402}
403
jardineb5d44e2003-12-23 08:09:43 +0000404struct isis_route_info *
405isis_route_create (struct prefix *prefix, u_int32_t cost, u_int32_t depth,
hassofac1f7c2005-09-26 18:26:26 +0000406 struct list *adjacencies, struct isis_area *area,
407 int level)
jardineb5d44e2003-12-23 08:09:43 +0000408{
409 struct route_node *route_node;
410 struct isis_route_info *rinfo_new, *rinfo_old, *route_info = NULL;
411 u_char buff[BUFSIZ];
412 u_char family;
hassof390d2c2004-09-10 20:48:21 +0000413
jardineb5d44e2003-12-23 08:09:43 +0000414 family = prefix->family;
415 /* for debugs */
hassof7c43dc2004-09-26 16:24:14 +0000416 prefix2str (prefix, (char *) buff, BUFSIZ);
hassof390d2c2004-09-10 20:48:21 +0000417
jardineb5d44e2003-12-23 08:09:43 +0000418 rinfo_new = isis_route_info_new (cost, depth, family, adjacencies);
hassof390d2c2004-09-10 20:48:21 +0000419 if (!rinfo_new)
420 {
421 zlog_err ("ISIS-Rte (%s): isis_route_create: out of memory!",
422 area->area_tag);
423 return NULL;
424 }
425
jardineb5d44e2003-12-23 08:09:43 +0000426 if (family == AF_INET)
hassofac1f7c2005-09-26 18:26:26 +0000427 route_node = route_node_get (area->route_table[level - 1], prefix);
jardineb5d44e2003-12-23 08:09:43 +0000428#ifdef HAVE_IPV6
429 else if (family == AF_INET6)
hassofac1f7c2005-09-26 18:26:26 +0000430 route_node = route_node_get (area->route_table6[level - 1], prefix);
jardineb5d44e2003-12-23 08:09:43 +0000431#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000432 else
jardineb5d44e2003-12-23 08:09:43 +0000433 return NULL;
hassof390d2c2004-09-10 20:48:21 +0000434 rinfo_old = route_node->info;
435 if (!rinfo_old)
436 {
437 if (isis->debugs & DEBUG_RTE_EVENTS)
Josh Bailey3f045a02012-03-24 08:35:20 -0700438 zlog_debug ("ISIS-Rte (%s) route created: %s", area->area_tag, buff);
439 route_info = rinfo_new;
440 UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
hassof390d2c2004-09-10 20:48:21 +0000441 }
442 else
443 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700444 if (isis->debugs & DEBUG_RTE_EVENTS)
445 zlog_debug ("ISIS-Rte (%s) route already exists: %s", area->area_tag,
446 buff);
447 if (isis_route_info_same (rinfo_new, rinfo_old, family))
448 {
449 if (isis->debugs & DEBUG_RTE_EVENTS)
450 zlog_debug ("ISIS-Rte (%s) route unchanged: %s", area->area_tag,
451 buff);
452 isis_route_info_delete (rinfo_new);
453 route_info = rinfo_old;
454 }
hassof390d2c2004-09-10 20:48:21 +0000455 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700456 {
457 if (isis->debugs & DEBUG_RTE_EVENTS)
458 zlog_debug ("ISIS-Rte (%s) route changed: %s", area->area_tag,
459 buff);
460 isis_route_info_delete (rinfo_old);
461 route_info = rinfo_new;
462 UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
463 }
hassof390d2c2004-09-10 20:48:21 +0000464 }
465
jardineb5d44e2003-12-23 08:09:43 +0000466 SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE);
467 route_node->info = route_info;
hassof390d2c2004-09-10 20:48:21 +0000468
jardineb5d44e2003-12-23 08:09:43 +0000469 return route_info;
470}
471
hasso92365882005-01-18 13:53:33 +0000472static void
jardineb5d44e2003-12-23 08:09:43 +0000473isis_route_delete (struct prefix *prefix, struct route_table *table)
474{
475 struct route_node *rode;
476 struct isis_route_info *rinfo;
477 char buff[BUFSIZ];
478
479 /* for log */
480 prefix2str (prefix, buff, BUFSIZ);
481
482
483 rode = route_node_get (table, prefix);
484 rinfo = rode->info;
485
hassof390d2c2004-09-10 20:48:21 +0000486 if (rinfo == NULL)
487 {
488 if (isis->debugs & DEBUG_RTE_EVENTS)
hasso529d65b2004-12-24 00:14:50 +0000489 zlog_debug ("ISIS-Rte: tried to delete non-existant route %s", buff);
hassof390d2c2004-09-10 20:48:21 +0000490 return;
491 }
jardineb5d44e2003-12-23 08:09:43 +0000492
Josh Bailey3f045a02012-03-24 08:35:20 -0700493 if (CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED))
hassof390d2c2004-09-10 20:48:21 +0000494 {
495 UNSET_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE);
496 if (isis->debugs & DEBUG_RTE_EVENTS)
hasso529d65b2004-12-24 00:14:50 +0000497 zlog_debug ("ISIS-Rte: route delete %s", buff);
hassof390d2c2004-09-10 20:48:21 +0000498 isis_zebra_route_update (prefix, rinfo);
499 }
jardineb5d44e2003-12-23 08:09:43 +0000500 isis_route_info_delete (rinfo);
501 rode->info = NULL;
hassof390d2c2004-09-10 20:48:21 +0000502
jardineb5d44e2003-12-23 08:09:43 +0000503 return;
504}
505
hassofac1f7c2005-09-26 18:26:26 +0000506/* Validating routes in particular table. */
507static void
508isis_route_validate_table (struct isis_area *area, struct route_table *table)
jardineb5d44e2003-12-23 08:09:43 +0000509{
hassofac1f7c2005-09-26 18:26:26 +0000510 struct route_node *rnode, *drnode;
jardineb5d44e2003-12-23 08:09:43 +0000511 struct isis_route_info *rinfo;
512 u_char buff[BUFSIZ];
hassofac1f7c2005-09-26 18:26:26 +0000513
514 for (rnode = route_top (table); rnode; rnode = route_next (rnode))
hassof390d2c2004-09-10 20:48:21 +0000515 {
hassofac1f7c2005-09-26 18:26:26 +0000516 if (rnode->info == NULL)
hassof390d2c2004-09-10 20:48:21 +0000517 continue;
hassofac1f7c2005-09-26 18:26:26 +0000518 rinfo = rnode->info;
hassof390d2c2004-09-10 20:48:21 +0000519
520 if (isis->debugs & DEBUG_RTE_EVENTS)
521 {
hassofac1f7c2005-09-26 18:26:26 +0000522 prefix2str (&rnode->p, (char *) buff, BUFSIZ);
Josh Bailey3f045a02012-03-24 08:35:20 -0700523 zlog_debug ("ISIS-Rte (%s): route validate: %s %s %s %s",
hasso529d65b2004-12-24 00:14:50 +0000524 area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -0700525 (CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED) ?
526 "synced" : "not-synced"),
527 (CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC) ?
528 "resync" : "not-resync"),
hasso529d65b2004-12-24 00:14:50 +0000529 (CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE) ?
hassof390d2c2004-09-10 20:48:21 +0000530 "active" : "inactive"), buff);
531 }
532
hassofac1f7c2005-09-26 18:26:26 +0000533 isis_zebra_route_update (&rnode->p, rinfo);
hassof390d2c2004-09-10 20:48:21 +0000534 if (!CHECK_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE))
hassofac1f7c2005-09-26 18:26:26 +0000535 {
536 /* Area is either L1 or L2 => we use level route tables directly for
537 * validating => no problems with deleting routes. */
538 if (area->is_type != IS_LEVEL_1_AND_2)
539 {
540 isis_route_delete (&rnode->p, table);
541 continue;
542 }
543 /* If area is L1L2, we work with merge table and therefore must
544 * delete node from level tables as well before deleting route info.
545 * FIXME: Is it performance problem? There has to be the better way.
546 * Like not to deal with it here at all (see the next comment)? */
547 if (rnode->p.family == AF_INET)
548 {
549 drnode = route_node_get (area->route_table[0], &rnode->p);
550 if (drnode->info == rnode->info)
551 drnode->info = NULL;
552 drnode = route_node_get (area->route_table[1], &rnode->p);
553 if (drnode->info == rnode->info)
554 drnode->info = NULL;
555 }
Paul Jakma41b36e92006-12-08 01:09:50 +0000556
557#ifdef HAVE_IPV6
hassofac1f7c2005-09-26 18:26:26 +0000558 if (rnode->p.family == AF_INET6)
559 {
560 drnode = route_node_get (area->route_table6[0], &rnode->p);
561 if (drnode->info == rnode->info)
562 drnode->info = NULL;
563 drnode = route_node_get (area->route_table6[1], &rnode->p);
564 if (drnode->info == rnode->info)
565 drnode->info = NULL;
566 }
Paul Jakma41b36e92006-12-08 01:09:50 +0000567#endif
hassofac1f7c2005-09-26 18:26:26 +0000568
569 isis_route_delete (&rnode->p, table);
570 }
jardineb5d44e2003-12-23 08:09:43 +0000571 }
hassofac1f7c2005-09-26 18:26:26 +0000572}
573
574/* Function to validate route tables for L1L2 areas. In this case we can't use
575 * level route tables directly, we have to merge them at first. L1 routes are
576 * preferred over the L2 ones.
577 *
578 * Merge algorithm is trivial (at least for now). All L1 paths are copied into
579 * merge table at first, then L2 paths are added if L1 path for same prefix
580 * doesn't already exists there.
581 *
582 * FIXME: Is it right place to do it at all? Maybe we should push both levels
583 * to the RIB with different zebra route types and let RIB handle this? */
584static void
585isis_route_validate_merge (struct isis_area *area, int family)
586{
587 struct route_table *table = NULL;
588 struct route_table *merge;
589 struct route_node *rnode, *mrnode;
590
591 merge = route_table_init ();
592
593 if (family == AF_INET)
594 table = area->route_table[0];
Paul Jakma41b36e92006-12-08 01:09:50 +0000595#ifdef HAVE_IPV6
hassofac1f7c2005-09-26 18:26:26 +0000596 else if (family == AF_INET6)
597 table = area->route_table6[0];
Paul Jakma41b36e92006-12-08 01:09:50 +0000598#endif
hassofac1f7c2005-09-26 18:26:26 +0000599
600 for (rnode = route_top (table); rnode; rnode = route_next (rnode))
601 {
602 if (rnode->info == NULL)
603 continue;
604 mrnode = route_node_get (merge, &rnode->p);
605 mrnode->info = rnode->info;
606 }
607
608 if (family == AF_INET)
609 table = area->route_table[1];
Paul Jakma41b36e92006-12-08 01:09:50 +0000610#ifdef HAVE_IPV6
hassofac1f7c2005-09-26 18:26:26 +0000611 else if (family == AF_INET6)
612 table = area->route_table6[1];
Paul Jakma41b36e92006-12-08 01:09:50 +0000613#endif
hassofac1f7c2005-09-26 18:26:26 +0000614
615 for (rnode = route_top (table); rnode; rnode = route_next (rnode))
616 {
617 if (rnode->info == NULL)
618 continue;
619 mrnode = route_node_get (merge, &rnode->p);
620 if (mrnode->info != NULL)
621 continue;
622 mrnode->info = rnode->info;
623 }
624
625 isis_route_validate_table (area, merge);
626 route_table_finish (merge);
627}
628
629/* Walk through route tables and propagate necessary changes into RIB. In case
630 * of L1L2 area, level tables have to be merged at first. */
Josh Bailey3f045a02012-03-24 08:35:20 -0700631void
632isis_route_validate (struct isis_area *area)
hassofac1f7c2005-09-26 18:26:26 +0000633{
Josh Bailey3f045a02012-03-24 08:35:20 -0700634 struct listnode *node;
635 struct isis_circuit *circuit;
hassofac1f7c2005-09-26 18:26:26 +0000636
637 if (area->is_type == IS_LEVEL_1)
Josh Bailey3f045a02012-03-24 08:35:20 -0700638 isis_route_validate_table (area, area->route_table[0]);
639 else if (area->is_type == IS_LEVEL_2)
640 isis_route_validate_table (area, area->route_table[1]);
641 else
642 isis_route_validate_merge (area, AF_INET);
hassofac1f7c2005-09-26 18:26:26 +0000643
Paul Jakma41b36e92006-12-08 01:09:50 +0000644#ifdef HAVE_IPV6
hassofac1f7c2005-09-26 18:26:26 +0000645 if (area->is_type == IS_LEVEL_1)
Josh Bailey3f045a02012-03-24 08:35:20 -0700646 isis_route_validate_table (area, area->route_table6[0]);
647 else if (area->is_type == IS_LEVEL_2)
648 isis_route_validate_table (area, area->route_table6[1]);
649 else
650 isis_route_validate_merge (area, AF_INET6);
jardineb5d44e2003-12-23 08:09:43 +0000651#endif
652
Josh Bailey3f045a02012-03-24 08:35:20 -0700653 /* walk all circuits and reset any spf specific flags */
654 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
655 UNSET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF);
656
657 return;
658}
659
660void
661isis_route_invalidate_table (struct isis_area *area, struct route_table *table)
662{
663 struct route_node *rode;
664 struct isis_route_info *rinfo;
665 for (rode = route_top (table); rode; rode = route_next (rode))
666 {
667 if (rode->info == NULL)
668 continue;
669 rinfo = rode->info;
670
671 UNSET_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE);
672 }
673}
674
675void
676isis_route_invalidate (struct isis_area *area)
677{
678 if (area->is_type & IS_LEVEL_1)
679 isis_route_invalidate_table (area, area->route_table[0]);
680 if (area->is_type & IS_LEVEL_2)
681 isis_route_invalidate_table (area, area->route_table[1]);
jardineb5d44e2003-12-23 08:09:43 +0000682}