blob: 84f79fa24777220fa7194fbd982050bf34ddbbbf [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
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public Licenseas published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000024
25#include "thread.h"
26#include "command.h"
27#include "memory.h"
28#include "log.h"
29#include "if.h"
30#include "network.h"
31#include "prefix.h"
32#include "zclient.h"
33#include "stream.h"
34#include "linklist.h"
35
36#include "isisd/isis_constants.h"
37#include "isisd/isis_common.h"
38#include "isisd/isis_circuit.h"
39#include "isisd/isis_csm.h"
40#include "isisd/isis_route.h"
41#include "isisd/isis_zebra.h"
42
43struct zclient *zclient = NULL;
44
45extern struct thread_master *master;
hasso18a6dce2004-10-03 18:18:34 +000046struct in_addr router_id_zebra;
47
48/* Router-id update message from zebra. */
49int
50isis_router_id_update_zebra (int command, struct zclient *zclient,
51 zebra_size_t length)
52{
53 struct prefix router_id;
hasso18a6dce2004-10-03 18:18:34 +000054
55 zebra_router_id_update_read (zclient->ibuf,&router_id);
56 router_id_zebra = router_id.u.prefix4;
57
58 /* FIXME: Do we react somehow? */
59 return 0;
60}
jardineb5d44e2003-12-23 08:09:43 +000061
hassof390d2c2004-09-10 20:48:21 +000062int
jardineb5d44e2003-12-23 08:09:43 +000063isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length)
64{
65 struct interface *ifp;
66
67 ifp = zebra_interface_add_read (zclient->ibuf);
hassof390d2c2004-09-10 20:48:21 +000068
jardineb5d44e2003-12-23 08:09:43 +000069
70 zlog_info ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d",
71 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
hassof390d2c2004-09-10 20:48:21 +000072
jardineb5d44e2003-12-23 08:09:43 +000073 if (if_is_up (ifp))
74 isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
hassof390d2c2004-09-10 20:48:21 +000075
jardineb5d44e2003-12-23 08:09:43 +000076 return 0;
77}
78
79int
80isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length)
81{
82 struct interface *ifp;
83 struct stream *s;
84
85 s = zclient->ibuf;
86 ifp = zebra_interface_state_read (s);
hassof390d2c2004-09-10 20:48:21 +000087
jardineb5d44e2003-12-23 08:09:43 +000088 if (!ifp)
89 return 0;
90
91 if (if_is_up (ifp))
92 zlog_warn ("Zebra: got delete of %s, but interface is still up",
hassof390d2c2004-09-10 20:48:21 +000093 ifp->name);
jardineb5d44e2003-12-23 08:09:43 +000094
95 zlog_info ("Zebra I/F delete: %s index %d flags %ld metric %d mtu %d",
96 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
97
98 if_delete (ifp);
hassof390d2c2004-09-10 20:48:21 +000099
jardineb5d44e2003-12-23 08:09:43 +0000100 isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
101
102 return 0;
103}
104
105struct interface *
106zebra_interface_if_lookup (struct stream *s)
107{
108 struct interface *ifp;
109 u_char ifname_tmp[INTERFACE_NAMSIZ];
110
111 /* Read interface name. */
112 stream_get (ifname_tmp, s, INTERFACE_NAMSIZ);
113
114 /* Lookup this by interface index. */
hassof7c43dc2004-09-26 16:24:14 +0000115 ifp = if_lookup_by_name ((char *) ifname_tmp);
jardineb5d44e2003-12-23 08:09:43 +0000116
117 /* If such interface does not exist, indicate an error */
118 if (!ifp)
119 return NULL;
120
121 return ifp;
122}
123
jardineb5d44e2003-12-23 08:09:43 +0000124int
hassof390d2c2004-09-10 20:48:21 +0000125isis_zebra_if_state_up (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000126 zebra_size_t length)
127{
128 struct interface *ifp;
hassof390d2c2004-09-10 20:48:21 +0000129
jardineb5d44e2003-12-23 08:09:43 +0000130 ifp = zebra_interface_if_lookup (zclient->ibuf);
hassof390d2c2004-09-10 20:48:21 +0000131
jardineb5d44e2003-12-23 08:09:43 +0000132 if (!ifp)
133 return 0;
hassof390d2c2004-09-10 20:48:21 +0000134
135 if (if_is_up (ifp))
136 {
137 zebra_interface_if_set_value (zclient->ibuf, ifp);
138 isis_circuit_update_params (circuit_scan_by_ifp (ifp), ifp);
139 return 0;
140 }
141
jardineb5d44e2003-12-23 08:09:43 +0000142 zebra_interface_if_set_value (zclient->ibuf, ifp);
143 isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
hassof390d2c2004-09-10 20:48:21 +0000144
jardineb5d44e2003-12-23 08:09:43 +0000145 return 0;
146}
147
jardineb5d44e2003-12-23 08:09:43 +0000148int
hassof390d2c2004-09-10 20:48:21 +0000149isis_zebra_if_state_down (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000150 zebra_size_t length)
151{
152 struct interface *ifp;
hassof390d2c2004-09-10 20:48:21 +0000153
jardineb5d44e2003-12-23 08:09:43 +0000154 ifp = zebra_interface_if_lookup (zclient->ibuf);
hassof390d2c2004-09-10 20:48:21 +0000155
jardineb5d44e2003-12-23 08:09:43 +0000156 if (ifp == NULL)
157 return 0;
hassof390d2c2004-09-10 20:48:21 +0000158
159 if (if_is_up (ifp))
160 {
161 zebra_interface_if_set_value (zclient->ibuf, ifp);
162 isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
163 }
164
jardineb5d44e2003-12-23 08:09:43 +0000165 return 0;
166}
167
168int
hassof390d2c2004-09-10 20:48:21 +0000169isis_zebra_if_address_add (int command, struct zclient *zclient,
170 zebra_size_t length)
jardineb5d44e2003-12-23 08:09:43 +0000171{
172 struct connected *c;
173 struct prefix *p;
hassof7c43dc2004-09-26 16:24:14 +0000174 char buf[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000175
hassof390d2c2004-09-10 20:48:21 +0000176 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD,
177 zclient->ibuf);
178
jardineb5d44e2003-12-23 08:09:43 +0000179 if (c == NULL)
180 return 0;
hassof390d2c2004-09-10 20:48:21 +0000181
jardineb5d44e2003-12-23 08:09:43 +0000182 p = c->address;
hassof390d2c2004-09-10 20:48:21 +0000183
jardineb5d44e2003-12-23 08:09:43 +0000184 prefix2str (p, buf, BUFSIZ);
185#ifdef EXTREME_DEBUG
hassof390d2c2004-09-10 20:48:21 +0000186 if (p->family == AF_INET)
jardineb5d44e2003-12-23 08:09:43 +0000187 zlog_info ("connected IP address %s", buf);
188#ifdef HAVE_IPV6
189 if (p->family == AF_INET6)
190 zlog_info ("connected IPv6 address %s", buf);
191#endif /* HAVE_IPV6 */
192#endif /* EXTREME_DEBUG */
hassof390d2c2004-09-10 20:48:21 +0000193 isis_circuit_add_addr (circuit_scan_by_ifp (c->ifp), c);
jardineb5d44e2003-12-23 08:09:43 +0000194
195 return 0;
196}
197
198int
hassof390d2c2004-09-10 20:48:21 +0000199isis_zebra_if_address_del (int command, struct zclient *client,
200 zebra_size_t length)
jardineb5d44e2003-12-23 08:09:43 +0000201{
202 struct connected *c;
203 struct interface *ifp;
hasso1cd80842004-10-07 20:07:40 +0000204#ifdef EXTREME_DEBUG
hassof891f442004-09-14 13:54:30 +0000205 struct prefix *p;
206 u_char buf[BUFSIZ];
hasso1cd80842004-10-07 20:07:40 +0000207#endif /* EXTREME_DEBUG */
jardineb5d44e2003-12-23 08:09:43 +0000208
hassof390d2c2004-09-10 20:48:21 +0000209 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE,
210 zclient->ibuf);
211
jardineb5d44e2003-12-23 08:09:43 +0000212 if (c == NULL)
213 return 0;
hassof390d2c2004-09-10 20:48:21 +0000214
jardineb5d44e2003-12-23 08:09:43 +0000215 ifp = c->ifp;
hassof390d2c2004-09-10 20:48:21 +0000216
hassof891f442004-09-14 13:54:30 +0000217#ifdef EXTREME_DEBUG
218 p = c->address;
219 prefix2str (p, buf, BUFSIZ);
220
221 if (p->family == AF_INET)
222 zlog_info ("disconnected IP address %s", buf);
223#ifdef HAVE_IPV6
224 if (p->family == AF_INET6)
225 zlog_info ("disconnected IPv6 address %s", buf);
226#endif /* HAVE_IPV6 */
227#endif /* EXTREME_DEBUG */
hassof390d2c2004-09-10 20:48:21 +0000228
jardineb5d44e2003-12-23 08:09:43 +0000229 isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c);
hassof891f442004-09-14 13:54:30 +0000230 connected_free (c);
hassof390d2c2004-09-10 20:48:21 +0000231
jardineb5d44e2003-12-23 08:09:43 +0000232 return 0;
233}
234
235void
hassof390d2c2004-09-10 20:48:21 +0000236isis_zebra_route_add_ipv4 (struct prefix *prefix,
237 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000238{
239 u_char message, flags;
240 int psize;
241 struct stream *stream;
242 struct isis_nexthop *nexthop;
243 struct listnode *node;
244
245 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
246 return;
247
hassof390d2c2004-09-10 20:48:21 +0000248 if (zclient->redist[ZEBRA_ROUTE_ISIS])
249 {
250 message = 0;
251 flags = 0;
jardineb5d44e2003-12-23 08:09:43 +0000252
hassof390d2c2004-09-10 20:48:21 +0000253 SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP);
254 SET_FLAG (message, ZAPI_MESSAGE_METRIC);
hasso2097cd82003-12-23 11:51:08 +0000255#if 0
hassof390d2c2004-09-10 20:48:21 +0000256 SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
hasso2097cd82003-12-23 11:51:08 +0000257#endif
hassof390d2c2004-09-10 20:48:21 +0000258
259 stream = zclient->obuf;
260 stream_reset (stream);
261 /* Length place holder. */
262 stream_putw (stream, 0);
263 /* command */
264 stream_putc (stream, ZEBRA_IPV4_ROUTE_ADD);
265 /* type */
266 stream_putc (stream, ZEBRA_ROUTE_ISIS);
267 /* flags */
268 stream_putc (stream, flags);
269 /* message */
270 stream_putc (stream, message);
271 /* prefix information */
272 psize = PSIZE (prefix->prefixlen);
273 stream_putc (stream, prefix->prefixlen);
274 stream_write (stream, (u_char *) & prefix->u.prefix4, psize);
275
276 stream_putc (stream, listcount (route_info->nexthops));
277
278 /* Nexthop, ifindex, distance and metric information */
279 for (node = listhead (route_info->nexthops); node; nextnode (node))
280 {
281 nexthop = getdata (node);
282 /* FIXME: can it be ? */
283 if (nexthop->ip.s_addr != INADDR_ANY)
284 {
285 stream_putc (stream, ZEBRA_NEXTHOP_IPV4);
286 stream_put_in_addr (stream, &nexthop->ip);
287 }
288 else
289 {
290 stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX);
291 stream_putl (stream, nexthop->ifindex);
292 }
293 }
294#if 0
295 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
296 stream_putc (stream, route_info->depth);
297#endif
298 if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
299 stream_putl (stream, route_info->cost);
300
301 stream_putw_at (stream, 0, stream_get_endp (stream));
302 writen (zclient->sock, stream->data, stream_get_endp (stream));
303 }
jardineb5d44e2003-12-23 08:09:43 +0000304}
305
306void
hassof390d2c2004-09-10 20:48:21 +0000307isis_zebra_route_del_ipv4 (struct prefix *prefix,
308 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000309{
310 struct zapi_ipv4 api;
311 struct prefix_ipv4 prefix4;
hassof390d2c2004-09-10 20:48:21 +0000312
313 if (zclient->redist[ZEBRA_ROUTE_ISIS])
314 {
315 api.type = ZEBRA_ROUTE_ISIS;
316 api.flags = 0;
317 api.message = 0;
318 prefix4.family = AF_INET;
319 prefix4.prefixlen = prefix->prefixlen;
320 prefix4.prefix = prefix->u.prefix4;
321 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, &prefix4, &api);
322 }
323
jardineb5d44e2003-12-23 08:09:43 +0000324 return;
325}
326
327#ifdef HAVE_IPV6
328void
329isis_zebra_route_add_ipv6 (struct prefix *prefix,
hassof390d2c2004-09-10 20:48:21 +0000330 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000331{
332 struct zapi_ipv6 api;
333 struct in6_addr **nexthop_list;
334 unsigned int *ifindex_list;
335 struct isis_nexthop6 *nexthop6;
336 int i, size;
337 struct listnode *node;
338 struct prefix_ipv6 prefix6;
339
340 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
341 return;
hassof390d2c2004-09-10 20:48:21 +0000342
jardineb5d44e2003-12-23 08:09:43 +0000343 api.type = ZEBRA_ROUTE_ISIS;
344 api.flags = 0;
345 api.message = 0;
346 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);
368 ifindex_list = (unsigned int *) 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;
hassof390d2c2004-09-10 20:48:21 +0000378 for (node = listhead (route_info->nexthops6); node; nextnode (node))
379 {
380 nexthop6 = getdata (node);
381
382 if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
383 !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6))
384 {
385 api.nexthop_num--;
386 api.ifindex_num--;
387 continue;
388 }
389
390 nexthop_list[i] = &nexthop6->ip6;
391 ifindex_list[i] = nexthop6->ifindex;
392 i++;
jardineb5d44e2003-12-23 08:09:43 +0000393 }
hassof390d2c2004-09-10 20:48:21 +0000394
jardineb5d44e2003-12-23 08:09:43 +0000395 api.nexthop = nexthop_list;
396 api.ifindex = ifindex_list;
hassof390d2c2004-09-10 20:48:21 +0000397
398 if (api.nexthop_num && api.ifindex_num)
399 {
400 prefix6.family = AF_INET6;
401 prefix6.prefixlen = prefix->prefixlen;
402 memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
403 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, &prefix6, &api);
404 SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC);
405 }
406
jardineb5d44e2003-12-23 08:09:43 +0000407 XFREE (MTYPE_ISIS_TMP, nexthop_list);
408 XFREE (MTYPE_ISIS_TMP, ifindex_list);
hassof390d2c2004-09-10 20:48:21 +0000409
jardineb5d44e2003-12-23 08:09:43 +0000410 return;
411}
412
413void
hassof390d2c2004-09-10 20:48:21 +0000414isis_zebra_route_del_ipv6 (struct prefix *prefix,
415 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000416{
417 struct zapi_ipv6 api;
418 struct in6_addr **nexthop_list;
419 unsigned int *ifindex_list;
420 struct isis_nexthop6 *nexthop6;
421 int i, size;
422 struct listnode *node;
423 struct prefix_ipv6 prefix6;
424
425 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
426 return;
hassof390d2c2004-09-10 20:48:21 +0000427
jardineb5d44e2003-12-23 08:09:43 +0000428 api.type = ZEBRA_ROUTE_ISIS;
429 api.flags = 0;
430 api.message = 0;
431 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
432 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
433 api.nexthop_num = listcount (route_info->nexthops6);
434 api.ifindex_num = listcount (route_info->nexthops6);
hassof390d2c2004-09-10 20:48:21 +0000435
jardineb5d44e2003-12-23 08:09:43 +0000436 /* allocate memory for nexthop_list */
437 size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
438 nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000439 if (!nexthop_list)
440 {
441 zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
442 return;
443 }
444
jardineb5d44e2003-12-23 08:09:43 +0000445 /* allocate memory for ifindex_list */
446 size = sizeof (unsigned int) * listcount (route_info->nexthops6);
447 ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000448 if (!ifindex_list)
449 {
450 zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
451 XFREE (MTYPE_ISIS_TMP, nexthop_list);
452 return;
453 }
454
jardineb5d44e2003-12-23 08:09:43 +0000455 /* for each nexthop */
456 i = 0;
hassof390d2c2004-09-10 20:48:21 +0000457 for (node = listhead (route_info->nexthops6); node; nextnode (node))
458 {
459 nexthop6 = getdata (node);
460
461 if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
462 !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6))
463 {
464 api.nexthop_num--;
465 api.ifindex_num--;
466 continue;
467 }
468
469 nexthop_list[i] = &nexthop6->ip6;
470 ifindex_list[i] = nexthop6->ifindex;
471 i++;
jardineb5d44e2003-12-23 08:09:43 +0000472 }
hassof390d2c2004-09-10 20:48:21 +0000473
jardineb5d44e2003-12-23 08:09:43 +0000474 api.nexthop = nexthop_list;
475 api.ifindex = ifindex_list;
jardineb5d44e2003-12-23 08:09:43 +0000476
hassof390d2c2004-09-10 20:48:21 +0000477 if (api.nexthop_num && api.ifindex_num)
478 {
479 prefix6.family = AF_INET6;
480 prefix6.prefixlen = prefix->prefixlen;
481 memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
482 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, &prefix6, &api);
483 UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC);
484 }
485
486 XFREE (MTYPE_ISIS_TMP, nexthop_list);
487 XFREE (MTYPE_ISIS_TMP, ifindex_list);
488}
jardineb5d44e2003-12-23 08:09:43 +0000489
490#endif /* HAVE_IPV6 */
491
jardineb5d44e2003-12-23 08:09:43 +0000492void
493isis_zebra_route_update (struct prefix *prefix,
hassof390d2c2004-09-10 20:48:21 +0000494 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000495{
496 if (zclient->sock < 0)
497 return;
498
499 if (!zclient->redist[ZEBRA_ROUTE_ISIS])
500 return;
501
hassof390d2c2004-09-10 20:48:21 +0000502 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE))
503 {
504 if (prefix->family == AF_INET)
505 isis_zebra_route_add_ipv4 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000506#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000507 else if (prefix->family == AF_INET6)
508 isis_zebra_route_add_ipv6 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000509#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000510 }
511 else
512 {
513 if (prefix->family == AF_INET)
514 isis_zebra_route_del_ipv4 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000515#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000516 else if (prefix->family == AF_INET6)
517 isis_zebra_route_del_ipv6 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000518#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000519 }
jardineb5d44e2003-12-23 08:09:43 +0000520 return;
521}
522
jardineb5d44e2003-12-23 08:09:43 +0000523int
hassof390d2c2004-09-10 20:48:21 +0000524isis_zebra_read_ipv4 (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000525 zebra_size_t length)
526{
527 struct stream *stream;
528 struct zapi_ipv4 api;
529 struct prefix_ipv4 p;
530 unsigned long ifindex;
531 struct in_addr nexthop;
532
533 stream = zclient->ibuf;
534 memset (&p, 0, sizeof (struct prefix_ipv4));
535 ifindex = 0;
536
hassof390d2c2004-09-10 20:48:21 +0000537 api.type = stream_getc (stream);
538 api.flags = stream_getc (stream);
jardineb5d44e2003-12-23 08:09:43 +0000539 api.message = stream_getc (stream);
540
541 p.family = AF_INET;
542 p.prefixlen = stream_getc (stream);
543 stream_get (&p.prefix, stream, PSIZE (p.prefixlen));
hassof390d2c2004-09-10 20:48:21 +0000544
545 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
546 {
jardineb5d44e2003-12-23 08:09:43 +0000547 api.nexthop_num = stream_getc (stream);
548 nexthop.s_addr = stream_get_ipv4 (stream);
hassof390d2c2004-09-10 20:48:21 +0000549 }
550 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
551 {
552 api.ifindex_num = stream_getc (stream);
553 ifindex = stream_getl (stream);
554 }
jardineb5d44e2003-12-23 08:09:43 +0000555 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
556 api.distance = stream_getc (stream);
557 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
558 api.metric = stream_getl (stream);
559 else
560 api.metric = 0;
hassof390d2c2004-09-10 20:48:21 +0000561
562 if (command == ZEBRA_IPV4_ROUTE_ADD)
563 {
564 zlog_info ("IPv4 Route add from Z");
565 }
jardineb5d44e2003-12-23 08:09:43 +0000566
567 return 0;
568}
569
hassof390d2c2004-09-10 20:48:21 +0000570int
571isis_zebra_read_ipv6 (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000572 zebra_size_t length)
573{
jardineb5d44e2003-12-23 08:09:43 +0000574 return 0;
575}
576
577#define ISIS_TYPE_IS_REDISTRIBUTED(T) \
578T == ZEBRA_ROUTE_MAX ? zclient->default_information : zclient->redist[type]
579
580int
581isis_distribute_list_update (int routetype)
582{
583 return 0;
584}
585
586int
hassof390d2c2004-09-10 20:48:21 +0000587isis_redistribute_default_set (int routetype, int metric_type,
588 int metric_value)
jardineb5d44e2003-12-23 08:09:43 +0000589{
590 return 0;
591}
592
jardineb5d44e2003-12-23 08:09:43 +0000593void
594isis_zebra_init ()
595{
jardineb5d44e2003-12-23 08:09:43 +0000596 zclient = zclient_new ();
597 zclient_init (zclient, ZEBRA_ROUTE_ISIS);
hasso18a6dce2004-10-03 18:18:34 +0000598 zclient->router_id_update = isis_router_id_update_zebra;
jardineb5d44e2003-12-23 08:09:43 +0000599 zclient->interface_add = isis_zebra_if_add;
600 zclient->interface_delete = isis_zebra_if_del;
601 zclient->interface_up = isis_zebra_if_state_up;
602 zclient->interface_down = isis_zebra_if_state_down;
603 zclient->interface_address_add = isis_zebra_if_address_add;
604 zclient->interface_address_delete = isis_zebra_if_address_del;
605 zclient->ipv4_route_add = isis_zebra_read_ipv4;
606 zclient->ipv4_route_delete = isis_zebra_read_ipv4;
607#ifdef HAVE_IPV6
608 zclient->ipv6_route_add = isis_zebra_read_ipv6;
609 zclient->ipv6_route_delete = isis_zebra_read_ipv6;
610#endif /* HAVE_IPV6 */
611
612 return;
613}
614
615void
616isis_zebra_finish ()
617{
jardineb5d44e2003-12-23 08:09:43 +0000618 zclient_stop (zclient);
619 zclient_free (zclient);
620 zclient = (struct zclient *) NULL;
621
622 return;
623}