blob: 6c398cf54d7b7ad7df92007271d231469e95cb5e [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_zebra.c
3 *
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
Christian Frankeacf98652015-11-12 14:24:22 +01007 * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org>
jardineb5d44e2003-12-23 08:09:43 +00008 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000025
26#include "thread.h"
27#include "command.h"
28#include "memory.h"
29#include "log.h"
30#include "if.h"
31#include "network.h"
32#include "prefix.h"
33#include "zclient.h"
34#include "stream.h"
35#include "linklist.h"
Feng Luc99f3482014-10-16 09:52:36 +080036#include "vrf.h"
jardineb5d44e2003-12-23 08:09:43 +000037
hassoc89c05d2005-09-04 21:36:36 +000038#include "isisd/dict.h"
jardineb5d44e2003-12-23 08:09:43 +000039#include "isisd/isis_constants.h"
40#include "isisd/isis_common.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070041#include "isisd/isis_flags.h"
42#include "isisd/isis_misc.h"
43#include "isisd/isis_circuit.h"
44#include "isisd/isis_tlv.h"
hassoc89c05d2005-09-04 21:36:36 +000045#include "isisd/isisd.h"
jardineb5d44e2003-12-23 08:09:43 +000046#include "isisd/isis_circuit.h"
47#include "isisd/isis_csm.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070048#include "isisd/isis_lsp.h"
jardineb5d44e2003-12-23 08:09:43 +000049#include "isisd/isis_route.h"
50#include "isisd/isis_zebra.h"
51
52struct zclient *zclient = NULL;
53
hasso18a6dce2004-10-03 18:18:34 +000054/* Router-id update message from zebra. */
hasso92365882005-01-18 13:53:33 +000055static int
hasso18a6dce2004-10-03 18:18:34 +000056isis_router_id_update_zebra (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +080057 zebra_size_t length, vrf_id_t vrf_id)
hasso18a6dce2004-10-03 18:18:34 +000058{
Josh Bailey3f045a02012-03-24 08:35:20 -070059 struct isis_area *area;
60 struct listnode *node;
hasso18a6dce2004-10-03 18:18:34 +000061 struct prefix router_id;
hasso18a6dce2004-10-03 18:18:34 +000062
Josh Bailey3f045a02012-03-24 08:35:20 -070063 zebra_router_id_update_read (zclient->ibuf, &router_id);
64 if (isis->router_id == router_id.u.prefix4.s_addr)
65 return 0;
hasso18a6dce2004-10-03 18:18:34 +000066
Josh Bailey3f045a02012-03-24 08:35:20 -070067 isis->router_id = router_id.u.prefix4.s_addr;
68 for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area))
69 if (listcount (area->area_addrs) > 0)
70 lsp_regenerate_schedule (area, area->is_type, 0);
71
hasso18a6dce2004-10-03 18:18:34 +000072 return 0;
73}
jardineb5d44e2003-12-23 08:09:43 +000074
hasso92365882005-01-18 13:53:33 +000075static int
Feng Luc99f3482014-10-16 09:52:36 +080076isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length,
77 vrf_id_t vrf_id)
jardineb5d44e2003-12-23 08:09:43 +000078{
79 struct interface *ifp;
80
Feng Luc99f3482014-10-16 09:52:36 +080081 ifp = zebra_interface_add_read (zclient->ibuf, vrf_id);
hassof390d2c2004-09-10 20:48:21 +000082
hassoc89c05d2005-09-04 21:36:36 +000083 if (isis->debugs & DEBUG_ZEBRA)
84 zlog_debug ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d",
Paul Jakma41b36e92006-12-08 01:09:50 +000085 ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, ifp->mtu);
hassof390d2c2004-09-10 20:48:21 +000086
hassob30c5e62004-12-29 20:06:41 +000087 if (if_is_operative (ifp))
jardineb5d44e2003-12-23 08:09:43 +000088 isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
hassof390d2c2004-09-10 20:48:21 +000089
jardineb5d44e2003-12-23 08:09:43 +000090 return 0;
91}
92
hasso92365882005-01-18 13:53:33 +000093static int
Feng Luc99f3482014-10-16 09:52:36 +080094isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length,
95 vrf_id_t vrf_id)
jardineb5d44e2003-12-23 08:09:43 +000096{
97 struct interface *ifp;
98 struct stream *s;
99
100 s = zclient->ibuf;
Feng Luc99f3482014-10-16 09:52:36 +0800101 ifp = zebra_interface_state_read (s, vrf_id);
hassof390d2c2004-09-10 20:48:21 +0000102
jardineb5d44e2003-12-23 08:09:43 +0000103 if (!ifp)
104 return 0;
105
hassob30c5e62004-12-29 20:06:41 +0000106 if (if_is_operative (ifp))
jardineb5d44e2003-12-23 08:09:43 +0000107 zlog_warn ("Zebra: got delete of %s, but interface is still up",
hassof390d2c2004-09-10 20:48:21 +0000108 ifp->name);
jardineb5d44e2003-12-23 08:09:43 +0000109
hassoc89c05d2005-09-04 21:36:36 +0000110 if (isis->debugs & DEBUG_ZEBRA)
111 zlog_debug ("Zebra I/F delete: %s index %d flags %ld metric %d mtu %d",
Paul Jakma41b36e92006-12-08 01:09:50 +0000112 ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, ifp->mtu);
jardineb5d44e2003-12-23 08:09:43 +0000113
Josh Bailey3f045a02012-03-24 08:35:20 -0700114 isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
ajsd2fc8892005-04-02 18:38:43 +0000115
116 /* Cannot call if_delete because we should retain the pseudo interface
117 in case there is configuration info attached to it. */
118 if_delete_retain(ifp);
hassof390d2c2004-09-10 20:48:21 +0000119
ajsd2fc8892005-04-02 18:38:43 +0000120 ifp->ifindex = IFINDEX_INTERNAL;
121
jardineb5d44e2003-12-23 08:09:43 +0000122 return 0;
123}
124
hasso92365882005-01-18 13:53:33 +0000125static int
hassof390d2c2004-09-10 20:48:21 +0000126isis_zebra_if_state_up (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800127 zebra_size_t length, vrf_id_t vrf_id)
jardineb5d44e2003-12-23 08:09:43 +0000128{
129 struct interface *ifp;
hassof390d2c2004-09-10 20:48:21 +0000130
Feng Luc99f3482014-10-16 09:52:36 +0800131 ifp = zebra_interface_state_read (zclient->ibuf, vrf_id);
hassof390d2c2004-09-10 20:48:21 +0000132
Josh Bailey3f045a02012-03-24 08:35:20 -0700133 if (ifp == NULL)
jardineb5d44e2003-12-23 08:09:43 +0000134 return 0;
hassof390d2c2004-09-10 20:48:21 +0000135
jardineb5d44e2003-12-23 08:09:43 +0000136 isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
hassof390d2c2004-09-10 20:48:21 +0000137
jardineb5d44e2003-12-23 08:09:43 +0000138 return 0;
139}
140
hasso92365882005-01-18 13:53:33 +0000141static int
hassof390d2c2004-09-10 20:48:21 +0000142isis_zebra_if_state_down (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800143 zebra_size_t length, vrf_id_t vrf_id)
jardineb5d44e2003-12-23 08:09:43 +0000144{
145 struct interface *ifp;
Josh Bailey3f045a02012-03-24 08:35:20 -0700146 struct isis_circuit *circuit;
hassof390d2c2004-09-10 20:48:21 +0000147
Feng Luc99f3482014-10-16 09:52:36 +0800148 ifp = zebra_interface_state_read (zclient->ibuf, vrf_id);
hassof390d2c2004-09-10 20:48:21 +0000149
jardineb5d44e2003-12-23 08:09:43 +0000150 if (ifp == NULL)
151 return 0;
hassof390d2c2004-09-10 20:48:21 +0000152
Josh Bailey3f045a02012-03-24 08:35:20 -0700153 circuit = isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp),
154 ifp);
155 if (circuit)
156 SET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF);
hassof390d2c2004-09-10 20:48:21 +0000157
jardineb5d44e2003-12-23 08:09:43 +0000158 return 0;
159}
160
hasso92365882005-01-18 13:53:33 +0000161static int
hassof390d2c2004-09-10 20:48:21 +0000162isis_zebra_if_address_add (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800163 zebra_size_t length, vrf_id_t vrf_id)
jardineb5d44e2003-12-23 08:09:43 +0000164{
165 struct connected *c;
166 struct prefix *p;
hassof7c43dc2004-09-26 16:24:14 +0000167 char buf[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000168
hassof390d2c2004-09-10 20:48:21 +0000169 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD,
Feng Luc99f3482014-10-16 09:52:36 +0800170 zclient->ibuf, vrf_id);
hassof390d2c2004-09-10 20:48:21 +0000171
jardineb5d44e2003-12-23 08:09:43 +0000172 if (c == NULL)
173 return 0;
hassof390d2c2004-09-10 20:48:21 +0000174
jardineb5d44e2003-12-23 08:09:43 +0000175 p = c->address;
hassof390d2c2004-09-10 20:48:21 +0000176
jardineb5d44e2003-12-23 08:09:43 +0000177 prefix2str (p, buf, BUFSIZ);
178#ifdef EXTREME_DEBUG
hassof390d2c2004-09-10 20:48:21 +0000179 if (p->family == AF_INET)
hasso529d65b2004-12-24 00:14:50 +0000180 zlog_debug ("connected IP address %s", buf);
jardineb5d44e2003-12-23 08:09:43 +0000181#ifdef HAVE_IPV6
182 if (p->family == AF_INET6)
hasso529d65b2004-12-24 00:14:50 +0000183 zlog_debug ("connected IPv6 address %s", buf);
jardineb5d44e2003-12-23 08:09:43 +0000184#endif /* HAVE_IPV6 */
185#endif /* EXTREME_DEBUG */
hassob30c5e62004-12-29 20:06:41 +0000186 if (if_is_operative (c->ifp))
187 isis_circuit_add_addr (circuit_scan_by_ifp (c->ifp), c);
jardineb5d44e2003-12-23 08:09:43 +0000188
189 return 0;
190}
191
hasso92365882005-01-18 13:53:33 +0000192static int
hassof390d2c2004-09-10 20:48:21 +0000193isis_zebra_if_address_del (int command, struct zclient *client,
Feng Luc99f3482014-10-16 09:52:36 +0800194 zebra_size_t length, vrf_id_t vrf_id)
jardineb5d44e2003-12-23 08:09:43 +0000195{
196 struct connected *c;
197 struct interface *ifp;
hasso1cd80842004-10-07 20:07:40 +0000198#ifdef EXTREME_DEBUG
hassof891f442004-09-14 13:54:30 +0000199 struct prefix *p;
200 u_char buf[BUFSIZ];
hasso1cd80842004-10-07 20:07:40 +0000201#endif /* EXTREME_DEBUG */
jardineb5d44e2003-12-23 08:09:43 +0000202
hassof390d2c2004-09-10 20:48:21 +0000203 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE,
Feng Luc99f3482014-10-16 09:52:36 +0800204 zclient->ibuf, vrf_id);
hassof390d2c2004-09-10 20:48:21 +0000205
jardineb5d44e2003-12-23 08:09:43 +0000206 if (c == NULL)
207 return 0;
hassof390d2c2004-09-10 20:48:21 +0000208
jardineb5d44e2003-12-23 08:09:43 +0000209 ifp = c->ifp;
hassof390d2c2004-09-10 20:48:21 +0000210
hassof891f442004-09-14 13:54:30 +0000211#ifdef EXTREME_DEBUG
212 p = c->address;
213 prefix2str (p, buf, BUFSIZ);
214
215 if (p->family == AF_INET)
hasso529d65b2004-12-24 00:14:50 +0000216 zlog_debug ("disconnected IP address %s", buf);
hassof891f442004-09-14 13:54:30 +0000217#ifdef HAVE_IPV6
218 if (p->family == AF_INET6)
hasso529d65b2004-12-24 00:14:50 +0000219 zlog_debug ("disconnected IPv6 address %s", buf);
hassof891f442004-09-14 13:54:30 +0000220#endif /* HAVE_IPV6 */
221#endif /* EXTREME_DEBUG */
hassof390d2c2004-09-10 20:48:21 +0000222
hassob30c5e62004-12-29 20:06:41 +0000223 if (if_is_operative (ifp))
224 isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c);
hassof891f442004-09-14 13:54:30 +0000225 connected_free (c);
hassof390d2c2004-09-10 20:48:21 +0000226
jardineb5d44e2003-12-23 08:09:43 +0000227 return 0;
228}
229
hasso92365882005-01-18 13:53:33 +0000230static void
hassof390d2c2004-09-10 20:48:21 +0000231isis_zebra_route_add_ipv4 (struct prefix *prefix,
232 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000233{
234 u_char message, flags;
235 int psize;
236 struct stream *stream;
237 struct isis_nexthop *nexthop;
238 struct listnode *node;
239
Josh Bailey3f045a02012-03-24 08:35:20 -0700240 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED))
jardineb5d44e2003-12-23 08:09:43 +0000241 return;
242
Feng Luc99f3482014-10-16 09:52:36 +0800243 if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_ISIS], VRF_DEFAULT))
hassof390d2c2004-09-10 20:48:21 +0000244 {
245 message = 0;
246 flags = 0;
jardineb5d44e2003-12-23 08:09:43 +0000247
hassof390d2c2004-09-10 20:48:21 +0000248 SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP);
249 SET_FLAG (message, ZAPI_MESSAGE_METRIC);
hasso2097cd82003-12-23 11:51:08 +0000250#if 0
hassof390d2c2004-09-10 20:48:21 +0000251 SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
hasso2097cd82003-12-23 11:51:08 +0000252#endif
hassof390d2c2004-09-10 20:48:21 +0000253
254 stream = zclient->obuf;
255 stream_reset (stream);
Feng Luc99f3482014-10-16 09:52:36 +0800256 zclient_create_header (stream, ZEBRA_IPV4_ROUTE_ADD, VRF_DEFAULT);
hassof390d2c2004-09-10 20:48:21 +0000257 /* type */
258 stream_putc (stream, ZEBRA_ROUTE_ISIS);
259 /* flags */
260 stream_putc (stream, flags);
261 /* message */
262 stream_putc (stream, message);
Avneesh Sachdevaa3b2642012-04-11 23:56:03 -0700263 /* SAFI */
264 stream_putw (stream, SAFI_UNICAST);
hassof390d2c2004-09-10 20:48:21 +0000265 /* prefix information */
266 psize = PSIZE (prefix->prefixlen);
267 stream_putc (stream, prefix->prefixlen);
268 stream_write (stream, (u_char *) & prefix->u.prefix4, psize);
269
270 stream_putc (stream, listcount (route_info->nexthops));
271
272 /* Nexthop, ifindex, distance and metric information */
paul1eb8ef22005-04-07 07:30:20 +0000273 for (ALL_LIST_ELEMENTS_RO (route_info->nexthops, node, nexthop))
hassof390d2c2004-09-10 20:48:21 +0000274 {
hassof390d2c2004-09-10 20:48:21 +0000275 /* FIXME: can it be ? */
276 if (nexthop->ip.s_addr != INADDR_ANY)
277 {
278 stream_putc (stream, ZEBRA_NEXTHOP_IPV4);
279 stream_put_in_addr (stream, &nexthop->ip);
280 }
281 else
282 {
283 stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX);
284 stream_putl (stream, nexthop->ifindex);
285 }
286 }
287#if 0
288 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
289 stream_putc (stream, route_info->depth);
290#endif
291 if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
292 stream_putl (stream, route_info->cost);
293
294 stream_putw_at (stream, 0, stream_get_endp (stream));
ajs634f9ea2005-04-11 15:51:40 +0000295 zclient_send_message(zclient);
Josh Bailey3f045a02012-03-24 08:35:20 -0700296 SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
297 UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC);
hassof390d2c2004-09-10 20:48:21 +0000298 }
jardineb5d44e2003-12-23 08:09:43 +0000299}
300
hasso92365882005-01-18 13:53:33 +0000301static void
hassof390d2c2004-09-10 20:48:21 +0000302isis_zebra_route_del_ipv4 (struct prefix *prefix,
303 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000304{
305 struct zapi_ipv4 api;
306 struct prefix_ipv4 prefix4;
hassof390d2c2004-09-10 20:48:21 +0000307
Feng Luc99f3482014-10-16 09:52:36 +0800308 if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_ISIS], VRF_DEFAULT))
hassof390d2c2004-09-10 20:48:21 +0000309 {
Feng Luc99f3482014-10-16 09:52:36 +0800310 api.vrf_id = VRF_DEFAULT;
hassof390d2c2004-09-10 20:48:21 +0000311 api.type = ZEBRA_ROUTE_ISIS;
312 api.flags = 0;
313 api.message = 0;
Avneesh Sachdevaa3b2642012-04-11 23:56:03 -0700314 api.safi = SAFI_UNICAST;
hassof390d2c2004-09-10 20:48:21 +0000315 prefix4.family = AF_INET;
316 prefix4.prefixlen = prefix->prefixlen;
317 prefix4.prefix = prefix->u.prefix4;
318 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, &prefix4, &api);
319 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700320 UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
hassof390d2c2004-09-10 20:48:21 +0000321
jardineb5d44e2003-12-23 08:09:43 +0000322 return;
323}
324
325#ifdef HAVE_IPV6
David Lamparterf50ee932015-03-04 07:13:38 +0100326static void
jardineb5d44e2003-12-23 08:09:43 +0000327isis_zebra_route_add_ipv6 (struct prefix *prefix,
hassof390d2c2004-09-10 20:48:21 +0000328 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000329{
330 struct zapi_ipv6 api;
331 struct in6_addr **nexthop_list;
Paul Jakma9099f9b2016-01-18 10:12:10 +0000332 ifindex_t *ifindex_list;
jardineb5d44e2003-12-23 08:09:43 +0000333 struct isis_nexthop6 *nexthop6;
334 int i, size;
335 struct listnode *node;
336 struct prefix_ipv6 prefix6;
337
Josh Bailey3f045a02012-03-24 08:35:20 -0700338 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED))
jardineb5d44e2003-12-23 08:09:43 +0000339 return;
hassof390d2c2004-09-10 20:48:21 +0000340
Feng Luc99f3482014-10-16 09:52:36 +0800341 api.vrf_id = VRF_DEFAULT;
jardineb5d44e2003-12-23 08:09:43 +0000342 api.type = ZEBRA_ROUTE_ISIS;
343 api.flags = 0;
344 api.message = 0;
Avneesh Sachdevaa3b2642012-04-11 23:56:03 -0700345 api.safi = SAFI_UNICAST;
jardineb5d44e2003-12-23 08:09:43 +0000346 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
347 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
348 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
349 api.metric = route_info->cost;
350#if 0
351 SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
352 api.distance = route_info->depth;
353#endif
354 api.nexthop_num = listcount (route_info->nexthops6);
355 api.ifindex_num = listcount (route_info->nexthops6);
hassof390d2c2004-09-10 20:48:21 +0000356
jardineb5d44e2003-12-23 08:09:43 +0000357 /* allocate memory for nexthop_list */
358 size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
359 nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000360 if (!nexthop_list)
361 {
362 zlog_err ("isis_zebra_add_route_ipv6: out of memory!");
363 return;
364 }
365
jardineb5d44e2003-12-23 08:09:43 +0000366 /* allocate memory for ifindex_list */
367 size = sizeof (unsigned int) * listcount (route_info->nexthops6);
Paul Jakma9099f9b2016-01-18 10:12:10 +0000368 ifindex_list = (ifindex_t *) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000369 if (!ifindex_list)
370 {
371 zlog_err ("isis_zebra_add_route_ipv6: out of memory!");
372 XFREE (MTYPE_ISIS_TMP, nexthop_list);
373 return;
374 }
375
jardineb5d44e2003-12-23 08:09:43 +0000376 /* for each nexthop */
377 i = 0;
paul1eb8ef22005-04-07 07:30:20 +0000378 for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6))
hassof390d2c2004-09-10 20:48:21 +0000379 {
hassof390d2c2004-09-10 20:48:21 +0000380 if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
381 !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6))
382 {
383 api.nexthop_num--;
384 api.ifindex_num--;
385 continue;
386 }
387
388 nexthop_list[i] = &nexthop6->ip6;
389 ifindex_list[i] = nexthop6->ifindex;
390 i++;
jardineb5d44e2003-12-23 08:09:43 +0000391 }
hassof390d2c2004-09-10 20:48:21 +0000392
jardineb5d44e2003-12-23 08:09:43 +0000393 api.nexthop = nexthop_list;
394 api.ifindex = ifindex_list;
hassof390d2c2004-09-10 20:48:21 +0000395
396 if (api.nexthop_num && api.ifindex_num)
397 {
398 prefix6.family = AF_INET6;
399 prefix6.prefixlen = prefix->prefixlen;
400 memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
401 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, &prefix6, &api);
Josh Bailey3f045a02012-03-24 08:35:20 -0700402 SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
403 UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC);
hassof390d2c2004-09-10 20:48:21 +0000404 }
405
jardineb5d44e2003-12-23 08:09:43 +0000406 XFREE (MTYPE_ISIS_TMP, nexthop_list);
407 XFREE (MTYPE_ISIS_TMP, ifindex_list);
hassof390d2c2004-09-10 20:48:21 +0000408
jardineb5d44e2003-12-23 08:09:43 +0000409 return;
410}
411
hasso92365882005-01-18 13:53:33 +0000412static void
hassof390d2c2004-09-10 20:48:21 +0000413isis_zebra_route_del_ipv6 (struct prefix *prefix,
414 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000415{
416 struct zapi_ipv6 api;
417 struct in6_addr **nexthop_list;
Paul Jakma9099f9b2016-01-18 10:12:10 +0000418 ifindex_t *ifindex_list;
jardineb5d44e2003-12-23 08:09:43 +0000419 struct isis_nexthop6 *nexthop6;
420 int i, size;
421 struct listnode *node;
422 struct prefix_ipv6 prefix6;
423
Christian Franke912aac42015-11-10 18:04:47 +0100424 if (!CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED))
jardineb5d44e2003-12-23 08:09:43 +0000425 return;
hassof390d2c2004-09-10 20:48:21 +0000426
Feng Luc99f3482014-10-16 09:52:36 +0800427 api.vrf_id = VRF_DEFAULT;
jardineb5d44e2003-12-23 08:09:43 +0000428 api.type = ZEBRA_ROUTE_ISIS;
429 api.flags = 0;
430 api.message = 0;
Avneesh Sachdevaa3b2642012-04-11 23:56:03 -0700431 api.safi = SAFI_UNICAST;
jardineb5d44e2003-12-23 08:09:43 +0000432 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
433 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
434 api.nexthop_num = listcount (route_info->nexthops6);
435 api.ifindex_num = listcount (route_info->nexthops6);
hassof390d2c2004-09-10 20:48:21 +0000436
jardineb5d44e2003-12-23 08:09:43 +0000437 /* allocate memory for nexthop_list */
438 size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
439 nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000440 if (!nexthop_list)
441 {
442 zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
443 return;
444 }
445
jardineb5d44e2003-12-23 08:09:43 +0000446 /* allocate memory for ifindex_list */
447 size = sizeof (unsigned int) * listcount (route_info->nexthops6);
Paul Jakma9099f9b2016-01-18 10:12:10 +0000448 ifindex_list = (ifindex_t *) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000449 if (!ifindex_list)
450 {
451 zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
452 XFREE (MTYPE_ISIS_TMP, nexthop_list);
453 return;
454 }
455
jardineb5d44e2003-12-23 08:09:43 +0000456 /* for each nexthop */
457 i = 0;
paul1eb8ef22005-04-07 07:30:20 +0000458 for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6))
hassof390d2c2004-09-10 20:48:21 +0000459 {
hassof390d2c2004-09-10 20:48:21 +0000460 if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
461 !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6))
462 {
463 api.nexthop_num--;
464 api.ifindex_num--;
465 continue;
466 }
467
468 nexthop_list[i] = &nexthop6->ip6;
469 ifindex_list[i] = nexthop6->ifindex;
470 i++;
jardineb5d44e2003-12-23 08:09:43 +0000471 }
hassof390d2c2004-09-10 20:48:21 +0000472
jardineb5d44e2003-12-23 08:09:43 +0000473 api.nexthop = nexthop_list;
474 api.ifindex = ifindex_list;
jardineb5d44e2003-12-23 08:09:43 +0000475
hassof390d2c2004-09-10 20:48:21 +0000476 if (api.nexthop_num && api.ifindex_num)
477 {
478 prefix6.family = AF_INET6;
479 prefix6.prefixlen = prefix->prefixlen;
480 memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
481 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, &prefix6, &api);
Josh Bailey3f045a02012-03-24 08:35:20 -0700482 UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
hassof390d2c2004-09-10 20:48:21 +0000483 }
484
485 XFREE (MTYPE_ISIS_TMP, nexthop_list);
486 XFREE (MTYPE_ISIS_TMP, ifindex_list);
487}
jardineb5d44e2003-12-23 08:09:43 +0000488
489#endif /* HAVE_IPV6 */
490
jardineb5d44e2003-12-23 08:09:43 +0000491void
492isis_zebra_route_update (struct prefix *prefix,
hassof390d2c2004-09-10 20:48:21 +0000493 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000494{
495 if (zclient->sock < 0)
496 return;
497
Feng Luc99f3482014-10-16 09:52:36 +0800498 if (!vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_ISIS], VRF_DEFAULT))
jardineb5d44e2003-12-23 08:09:43 +0000499 return;
500
hassof390d2c2004-09-10 20:48:21 +0000501 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE))
502 {
503 if (prefix->family == AF_INET)
504 isis_zebra_route_add_ipv4 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000505#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000506 else if (prefix->family == AF_INET6)
507 isis_zebra_route_add_ipv6 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000508#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000509 }
510 else
511 {
512 if (prefix->family == AF_INET)
513 isis_zebra_route_del_ipv4 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000514#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000515 else if (prefix->family == AF_INET6)
516 isis_zebra_route_del_ipv6 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000517#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000518 }
jardineb5d44e2003-12-23 08:09:43 +0000519 return;
520}
521
hasso92365882005-01-18 13:53:33 +0000522static int
hassof390d2c2004-09-10 20:48:21 +0000523isis_zebra_read_ipv4 (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800524 zebra_size_t length, vrf_id_t vrf_id)
jardineb5d44e2003-12-23 08:09:43 +0000525{
526 struct stream *stream;
527 struct zapi_ipv4 api;
528 struct prefix_ipv4 p;
Christian Frankeacf98652015-11-12 14:24:22 +0100529 struct prefix *p_generic = (struct prefix*)&p;
David Lamparterf50ee932015-03-04 07:13:38 +0100530 unsigned long ifindex __attribute__ ((unused));
531 struct in_addr nexthop __attribute__ ((unused));
jardineb5d44e2003-12-23 08:09:43 +0000532
533 stream = zclient->ibuf;
Christian Frankeacf98652015-11-12 14:24:22 +0100534 memset(&api, 0, sizeof(api));
jardineb5d44e2003-12-23 08:09:43 +0000535 memset (&p, 0, sizeof (struct prefix_ipv4));
Christian Frankeacf98652015-11-12 14:24:22 +0100536 memset(&nexthop, 0, sizeof(nexthop));
jardineb5d44e2003-12-23 08:09:43 +0000537 ifindex = 0;
538
hassof390d2c2004-09-10 20:48:21 +0000539 api.type = stream_getc (stream);
540 api.flags = stream_getc (stream);
jardineb5d44e2003-12-23 08:09:43 +0000541 api.message = stream_getc (stream);
542
543 p.family = AF_INET;
544 p.prefixlen = stream_getc (stream);
545 stream_get (&p.prefix, stream, PSIZE (p.prefixlen));
hassof390d2c2004-09-10 20:48:21 +0000546
547 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
548 {
jardineb5d44e2003-12-23 08:09:43 +0000549 api.nexthop_num = stream_getc (stream);
550 nexthop.s_addr = stream_get_ipv4 (stream);
hassof390d2c2004-09-10 20:48:21 +0000551 }
552 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
553 {
554 api.ifindex_num = stream_getc (stream);
555 ifindex = stream_getl (stream);
556 }
jardineb5d44e2003-12-23 08:09:43 +0000557 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
558 api.distance = stream_getc (stream);
559 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
560 api.metric = stream_getl (stream);
Christian Frankeacf98652015-11-12 14:24:22 +0100561
562 /*
563 * Avoid advertising a false default reachability. (A default
564 * route installed by IS-IS gets redistributed from zebra back
565 * into IS-IS causing us to start advertising default reachabity
566 * without this check)
567 */
568 if (p.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS)
569 command = ZEBRA_IPV4_ROUTE_DELETE;
hassof390d2c2004-09-10 20:48:21 +0000570
571 if (command == ZEBRA_IPV4_ROUTE_ADD)
Christian Frankeacf98652015-11-12 14:24:22 +0100572 isis_redist_add(api.type, p_generic, api.distance, api.metric);
573 else
574 isis_redist_delete(api.type, p_generic);
jardineb5d44e2003-12-23 08:09:43 +0000575
576 return 0;
577}
578
hasso92365882005-01-18 13:53:33 +0000579static int
hassof390d2c2004-09-10 20:48:21 +0000580isis_zebra_read_ipv6 (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800581 zebra_size_t length, vrf_id_t vrf_id)
jardineb5d44e2003-12-23 08:09:43 +0000582{
Christian Frankeacf98652015-11-12 14:24:22 +0100583 struct stream *stream;
584 struct zapi_ipv6 api;
585 struct prefix_ipv6 p;
586 struct prefix *p_generic = (struct prefix*)&p;
587 struct in6_addr nexthop;
588 unsigned long ifindex __attribute__((unused));
589
590 stream = zclient->ibuf;
591 memset(&api, 0, sizeof(api));
592 memset(&p, 0, sizeof(struct prefix_ipv6));
593 memset(&nexthop, 0, sizeof(nexthop));
594 ifindex = 0;
595
596 api.type = stream_getc(stream);
597 api.flags = stream_getc(stream);
598 api.message = stream_getc(stream);
599
600 p.family = AF_INET6;
601 p.prefixlen = stream_getc(stream);
602 stream_get(&p.prefix, stream, PSIZE(p.prefixlen));
603
604 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP))
605 {
606 api.nexthop_num = stream_getc(stream); /* this is always 1 */
607 stream_get(&nexthop, stream, sizeof(nexthop));
608 }
609 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX))
610 {
611 api.ifindex_num = stream_getc(stream);
612 ifindex = stream_getl(stream);
613 }
614 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE))
615 api.distance = stream_getc(stream);
616 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC))
617 api.metric = stream_getl(stream);
618
619 /*
620 * Avoid advertising a false default reachability. (A default
621 * route installed by IS-IS gets redistributed from zebra back
622 * into IS-IS causing us to start advertising default reachabity
623 * without this check)
624 */
625 if (p.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS)
626 command = ZEBRA_IPV6_ROUTE_DELETE;
627
628 if (command == ZEBRA_IPV6_ROUTE_ADD)
629 isis_redist_add(api.type, p_generic, api.distance, api.metric);
630 else
631 isis_redist_delete(api.type, p_generic);
632
jardineb5d44e2003-12-23 08:09:43 +0000633 return 0;
634}
jardineb5d44e2003-12-23 08:09:43 +0000635
636int
637isis_distribute_list_update (int routetype)
638{
639 return 0;
640}
641
Christian Frankeacf98652015-11-12 14:24:22 +0100642void
643isis_zebra_redistribute_set(int type)
jardineb5d44e2003-12-23 08:09:43 +0000644{
Christian Frankeacf98652015-11-12 14:24:22 +0100645 if (type == DEFAULT_ROUTE)
646 zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, VRF_DEFAULT);
647 else
648 zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
jardineb5d44e2003-12-23 08:09:43 +0000649}
Christian Frankeacf98652015-11-12 14:24:22 +0100650
651void
652isis_zebra_redistribute_unset(int type)
653{
654 if (type == DEFAULT_ROUTE)
655 zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, VRF_DEFAULT);
656 else
657 zclient_redistribute(ZEBRA_REDISTRIBUTE_DELETE, zclient, type, VRF_DEFAULT);
658}
jardineb5d44e2003-12-23 08:09:43 +0000659
Feng Luc99f3482014-10-16 09:52:36 +0800660static void
661isis_zebra_connected (struct zclient *zclient)
662{
663 zclient_send_requests (zclient, VRF_DEFAULT);
664}
665
jardineb5d44e2003-12-23 08:09:43 +0000666void
Donald Sharp71252932015-09-24 09:25:19 -0400667isis_zebra_init (struct thread_master *master)
jardineb5d44e2003-12-23 08:09:43 +0000668{
Donald Sharp71252932015-09-24 09:25:19 -0400669 zclient = zclient_new (master);
jardineb5d44e2003-12-23 08:09:43 +0000670 zclient_init (zclient, ZEBRA_ROUTE_ISIS);
Feng Luc99f3482014-10-16 09:52:36 +0800671 zclient->zebra_connected = isis_zebra_connected;
hasso18a6dce2004-10-03 18:18:34 +0000672 zclient->router_id_update = isis_router_id_update_zebra;
jardineb5d44e2003-12-23 08:09:43 +0000673 zclient->interface_add = isis_zebra_if_add;
674 zclient->interface_delete = isis_zebra_if_del;
675 zclient->interface_up = isis_zebra_if_state_up;
676 zclient->interface_down = isis_zebra_if_state_down;
677 zclient->interface_address_add = isis_zebra_if_address_add;
678 zclient->interface_address_delete = isis_zebra_if_address_del;
679 zclient->ipv4_route_add = isis_zebra_read_ipv4;
680 zclient->ipv4_route_delete = isis_zebra_read_ipv4;
681#ifdef HAVE_IPV6
682 zclient->ipv6_route_add = isis_zebra_read_ipv6;
683 zclient->ipv6_route_delete = isis_zebra_read_ipv6;
684#endif /* HAVE_IPV6 */
685
686 return;
687}