blob: f56c5d49c923002ef07fd49431516d29b983fe2a [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;
54 char buf[BUFSIZ];
55
56 zebra_router_id_update_read (zclient->ibuf,&router_id);
57 router_id_zebra = router_id.u.prefix4;
58
59 /* FIXME: Do we react somehow? */
60 return 0;
61}
jardineb5d44e2003-12-23 08:09:43 +000062
hassof390d2c2004-09-10 20:48:21 +000063int
jardineb5d44e2003-12-23 08:09:43 +000064isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length)
65{
66 struct interface *ifp;
67
68 ifp = zebra_interface_add_read (zclient->ibuf);
hassof390d2c2004-09-10 20:48:21 +000069
jardineb5d44e2003-12-23 08:09:43 +000070
71 zlog_info ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d",
72 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
hassof390d2c2004-09-10 20:48:21 +000073
jardineb5d44e2003-12-23 08:09:43 +000074 if (if_is_up (ifp))
75 isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
hassof390d2c2004-09-10 20:48:21 +000076
jardineb5d44e2003-12-23 08:09:43 +000077 return 0;
78}
79
80int
81isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length)
82{
83 struct interface *ifp;
84 struct stream *s;
85
86 s = zclient->ibuf;
87 ifp = zebra_interface_state_read (s);
hassof390d2c2004-09-10 20:48:21 +000088
jardineb5d44e2003-12-23 08:09:43 +000089 if (!ifp)
90 return 0;
91
92 if (if_is_up (ifp))
93 zlog_warn ("Zebra: got delete of %s, but interface is still up",
hassof390d2c2004-09-10 20:48:21 +000094 ifp->name);
jardineb5d44e2003-12-23 08:09:43 +000095
96 zlog_info ("Zebra I/F delete: %s index %d flags %ld metric %d mtu %d",
97 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
98
99 if_delete (ifp);
hassof390d2c2004-09-10 20:48:21 +0000100
jardineb5d44e2003-12-23 08:09:43 +0000101 isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
102
103 return 0;
104}
105
106struct interface *
107zebra_interface_if_lookup (struct stream *s)
108{
109 struct interface *ifp;
110 u_char ifname_tmp[INTERFACE_NAMSIZ];
111
112 /* Read interface name. */
113 stream_get (ifname_tmp, s, INTERFACE_NAMSIZ);
114
115 /* Lookup this by interface index. */
hassof7c43dc2004-09-26 16:24:14 +0000116 ifp = if_lookup_by_name ((char *) ifname_tmp);
jardineb5d44e2003-12-23 08:09:43 +0000117
118 /* If such interface does not exist, indicate an error */
119 if (!ifp)
120 return NULL;
121
122 return ifp;
123}
124
jardineb5d44e2003-12-23 08:09:43 +0000125int
hassof390d2c2004-09-10 20:48:21 +0000126isis_zebra_if_state_up (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000127 zebra_size_t length)
128{
129 struct interface *ifp;
hassof390d2c2004-09-10 20:48:21 +0000130
jardineb5d44e2003-12-23 08:09:43 +0000131 ifp = zebra_interface_if_lookup (zclient->ibuf);
hassof390d2c2004-09-10 20:48:21 +0000132
jardineb5d44e2003-12-23 08:09:43 +0000133 if (!ifp)
134 return 0;
hassof390d2c2004-09-10 20:48:21 +0000135
136 if (if_is_up (ifp))
137 {
138 zebra_interface_if_set_value (zclient->ibuf, ifp);
139 isis_circuit_update_params (circuit_scan_by_ifp (ifp), ifp);
140 return 0;
141 }
142
jardineb5d44e2003-12-23 08:09:43 +0000143 zebra_interface_if_set_value (zclient->ibuf, ifp);
144 isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
hassof390d2c2004-09-10 20:48:21 +0000145
jardineb5d44e2003-12-23 08:09:43 +0000146 return 0;
147}
148
jardineb5d44e2003-12-23 08:09:43 +0000149int
hassof390d2c2004-09-10 20:48:21 +0000150isis_zebra_if_state_down (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000151 zebra_size_t length)
152{
153 struct interface *ifp;
hassof390d2c2004-09-10 20:48:21 +0000154
jardineb5d44e2003-12-23 08:09:43 +0000155 ifp = zebra_interface_if_lookup (zclient->ibuf);
hassof390d2c2004-09-10 20:48:21 +0000156
jardineb5d44e2003-12-23 08:09:43 +0000157 if (ifp == NULL)
158 return 0;
hassof390d2c2004-09-10 20:48:21 +0000159
160 if (if_is_up (ifp))
161 {
162 zebra_interface_if_set_value (zclient->ibuf, ifp);
163 isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
164 }
165
jardineb5d44e2003-12-23 08:09:43 +0000166 return 0;
167}
168
169int
hassof390d2c2004-09-10 20:48:21 +0000170isis_zebra_if_address_add (int command, struct zclient *zclient,
171 zebra_size_t length)
jardineb5d44e2003-12-23 08:09:43 +0000172{
173 struct connected *c;
174 struct prefix *p;
hassof7c43dc2004-09-26 16:24:14 +0000175 char buf[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000176
hassof390d2c2004-09-10 20:48:21 +0000177 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD,
178 zclient->ibuf);
179
jardineb5d44e2003-12-23 08:09:43 +0000180 if (c == NULL)
181 return 0;
hassof390d2c2004-09-10 20:48:21 +0000182
jardineb5d44e2003-12-23 08:09:43 +0000183 p = c->address;
hassof390d2c2004-09-10 20:48:21 +0000184
jardineb5d44e2003-12-23 08:09:43 +0000185 prefix2str (p, buf, BUFSIZ);
186#ifdef EXTREME_DEBUG
hassof390d2c2004-09-10 20:48:21 +0000187 if (p->family == AF_INET)
jardineb5d44e2003-12-23 08:09:43 +0000188 zlog_info ("connected IP address %s", buf);
189#ifdef HAVE_IPV6
190 if (p->family == AF_INET6)
191 zlog_info ("connected IPv6 address %s", buf);
192#endif /* HAVE_IPV6 */
193#endif /* EXTREME_DEBUG */
hassof390d2c2004-09-10 20:48:21 +0000194 isis_circuit_add_addr (circuit_scan_by_ifp (c->ifp), c);
jardineb5d44e2003-12-23 08:09:43 +0000195
196 return 0;
197}
198
199int
hassof390d2c2004-09-10 20:48:21 +0000200isis_zebra_if_address_del (int command, struct zclient *client,
201 zebra_size_t length)
jardineb5d44e2003-12-23 08:09:43 +0000202{
203 struct connected *c;
204 struct interface *ifp;
hassof891f442004-09-14 13:54:30 +0000205 struct prefix *p;
206 u_char buf[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000207
hassof390d2c2004-09-10 20:48:21 +0000208 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE,
209 zclient->ibuf);
210
jardineb5d44e2003-12-23 08:09:43 +0000211 if (c == NULL)
212 return 0;
hassof390d2c2004-09-10 20:48:21 +0000213
jardineb5d44e2003-12-23 08:09:43 +0000214 ifp = c->ifp;
hassof390d2c2004-09-10 20:48:21 +0000215
hassof891f442004-09-14 13:54:30 +0000216#ifdef EXTREME_DEBUG
217 p = c->address;
218 prefix2str (p, buf, BUFSIZ);
219
220 if (p->family == AF_INET)
221 zlog_info ("disconnected IP address %s", buf);
222#ifdef HAVE_IPV6
223 if (p->family == AF_INET6)
224 zlog_info ("disconnected IPv6 address %s", buf);
225#endif /* HAVE_IPV6 */
226#endif /* EXTREME_DEBUG */
hassof390d2c2004-09-10 20:48:21 +0000227
jardineb5d44e2003-12-23 08:09:43 +0000228 isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c);
hassof891f442004-09-14 13:54:30 +0000229 connected_free (c);
hassof390d2c2004-09-10 20:48:21 +0000230
jardineb5d44e2003-12-23 08:09:43 +0000231 return 0;
232}
233
234void
hassof390d2c2004-09-10 20:48:21 +0000235isis_zebra_route_add_ipv4 (struct prefix *prefix,
236 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000237{
238 u_char message, flags;
239 int psize;
240 struct stream *stream;
241 struct isis_nexthop *nexthop;
242 struct listnode *node;
243
244 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
245 return;
246
hassof390d2c2004-09-10 20:48:21 +0000247 if (zclient->redist[ZEBRA_ROUTE_ISIS])
248 {
249 message = 0;
250 flags = 0;
jardineb5d44e2003-12-23 08:09:43 +0000251
hassof390d2c2004-09-10 20:48:21 +0000252 SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP);
253 SET_FLAG (message, ZAPI_MESSAGE_METRIC);
hasso2097cd82003-12-23 11:51:08 +0000254#if 0
hassof390d2c2004-09-10 20:48:21 +0000255 SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
hasso2097cd82003-12-23 11:51:08 +0000256#endif
hassof390d2c2004-09-10 20:48:21 +0000257
258 stream = zclient->obuf;
259 stream_reset (stream);
260 /* Length place holder. */
261 stream_putw (stream, 0);
262 /* command */
263 stream_putc (stream, ZEBRA_IPV4_ROUTE_ADD);
264 /* type */
265 stream_putc (stream, ZEBRA_ROUTE_ISIS);
266 /* flags */
267 stream_putc (stream, flags);
268 /* message */
269 stream_putc (stream, message);
270 /* prefix information */
271 psize = PSIZE (prefix->prefixlen);
272 stream_putc (stream, prefix->prefixlen);
273 stream_write (stream, (u_char *) & prefix->u.prefix4, psize);
274
275 stream_putc (stream, listcount (route_info->nexthops));
276
277 /* Nexthop, ifindex, distance and metric information */
278 for (node = listhead (route_info->nexthops); node; nextnode (node))
279 {
280 nexthop = getdata (node);
281 /* FIXME: can it be ? */
282 if (nexthop->ip.s_addr != INADDR_ANY)
283 {
284 stream_putc (stream, ZEBRA_NEXTHOP_IPV4);
285 stream_put_in_addr (stream, &nexthop->ip);
286 }
287 else
288 {
289 stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX);
290 stream_putl (stream, nexthop->ifindex);
291 }
292 }
293#if 0
294 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
295 stream_putc (stream, route_info->depth);
296#endif
297 if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
298 stream_putl (stream, route_info->cost);
299
300 stream_putw_at (stream, 0, stream_get_endp (stream));
301 writen (zclient->sock, stream->data, stream_get_endp (stream));
302 }
jardineb5d44e2003-12-23 08:09:43 +0000303}
304
305void
hassof390d2c2004-09-10 20:48:21 +0000306isis_zebra_route_del_ipv4 (struct prefix *prefix,
307 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000308{
309 struct zapi_ipv4 api;
310 struct prefix_ipv4 prefix4;
hassof390d2c2004-09-10 20:48:21 +0000311
312 if (zclient->redist[ZEBRA_ROUTE_ISIS])
313 {
314 api.type = ZEBRA_ROUTE_ISIS;
315 api.flags = 0;
316 api.message = 0;
317 prefix4.family = AF_INET;
318 prefix4.prefixlen = prefix->prefixlen;
319 prefix4.prefix = prefix->u.prefix4;
320 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, &prefix4, &api);
321 }
322
jardineb5d44e2003-12-23 08:09:43 +0000323 return;
324}
325
326#ifdef HAVE_IPV6
327void
328isis_zebra_route_add_ipv6 (struct prefix *prefix,
hassof390d2c2004-09-10 20:48:21 +0000329 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000330{
331 struct zapi_ipv6 api;
332 struct in6_addr **nexthop_list;
333 unsigned int *ifindex_list;
334 struct isis_nexthop6 *nexthop6;
335 int i, size;
336 struct listnode *node;
337 struct prefix_ipv6 prefix6;
338
339 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
340 return;
hassof390d2c2004-09-10 20:48:21 +0000341
jardineb5d44e2003-12-23 08:09:43 +0000342 api.type = ZEBRA_ROUTE_ISIS;
343 api.flags = 0;
344 api.message = 0;
345 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
346 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
347 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
348 api.metric = route_info->cost;
349#if 0
350 SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
351 api.distance = route_info->depth;
352#endif
353 api.nexthop_num = listcount (route_info->nexthops6);
354 api.ifindex_num = listcount (route_info->nexthops6);
hassof390d2c2004-09-10 20:48:21 +0000355
jardineb5d44e2003-12-23 08:09:43 +0000356 /* allocate memory for nexthop_list */
357 size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
358 nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000359 if (!nexthop_list)
360 {
361 zlog_err ("isis_zebra_add_route_ipv6: out of memory!");
362 return;
363 }
364
jardineb5d44e2003-12-23 08:09:43 +0000365 /* allocate memory for ifindex_list */
366 size = sizeof (unsigned int) * listcount (route_info->nexthops6);
367 ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000368 if (!ifindex_list)
369 {
370 zlog_err ("isis_zebra_add_route_ipv6: out of memory!");
371 XFREE (MTYPE_ISIS_TMP, nexthop_list);
372 return;
373 }
374
jardineb5d44e2003-12-23 08:09:43 +0000375 /* for each nexthop */
376 i = 0;
hassof390d2c2004-09-10 20:48:21 +0000377 for (node = listhead (route_info->nexthops6); node; nextnode (node))
378 {
379 nexthop6 = getdata (node);
380
381 if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
382 !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6))
383 {
384 api.nexthop_num--;
385 api.ifindex_num--;
386 continue;
387 }
388
389 nexthop_list[i] = &nexthop6->ip6;
390 ifindex_list[i] = nexthop6->ifindex;
391 i++;
jardineb5d44e2003-12-23 08:09:43 +0000392 }
hassof390d2c2004-09-10 20:48:21 +0000393
jardineb5d44e2003-12-23 08:09:43 +0000394 api.nexthop = nexthop_list;
395 api.ifindex = ifindex_list;
hassof390d2c2004-09-10 20:48:21 +0000396
397 if (api.nexthop_num && api.ifindex_num)
398 {
399 prefix6.family = AF_INET6;
400 prefix6.prefixlen = prefix->prefixlen;
401 memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
402 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, &prefix6, &api);
403 SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC);
404 }
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
412void
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;
418 unsigned int *ifindex_list;
419 struct isis_nexthop6 *nexthop6;
420 int i, size;
421 struct listnode *node;
422 struct prefix_ipv6 prefix6;
423
424 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
425 return;
hassof390d2c2004-09-10 20:48:21 +0000426
jardineb5d44e2003-12-23 08:09:43 +0000427 api.type = ZEBRA_ROUTE_ISIS;
428 api.flags = 0;
429 api.message = 0;
430 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
431 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
432 api.nexthop_num = listcount (route_info->nexthops6);
433 api.ifindex_num = listcount (route_info->nexthops6);
hassof390d2c2004-09-10 20:48:21 +0000434
jardineb5d44e2003-12-23 08:09:43 +0000435 /* allocate memory for nexthop_list */
436 size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
437 nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000438 if (!nexthop_list)
439 {
440 zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
441 return;
442 }
443
jardineb5d44e2003-12-23 08:09:43 +0000444 /* allocate memory for ifindex_list */
445 size = sizeof (unsigned int) * listcount (route_info->nexthops6);
446 ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000447 if (!ifindex_list)
448 {
449 zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
450 XFREE (MTYPE_ISIS_TMP, nexthop_list);
451 return;
452 }
453
jardineb5d44e2003-12-23 08:09:43 +0000454 /* for each nexthop */
455 i = 0;
hassof390d2c2004-09-10 20:48:21 +0000456 for (node = listhead (route_info->nexthops6); node; nextnode (node))
457 {
458 nexthop6 = getdata (node);
459
460 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);
482 UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC);
483 }
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
498 if (!zclient->redist[ZEBRA_ROUTE_ISIS])
499 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
jardineb5d44e2003-12-23 08:09:43 +0000522int
hassof390d2c2004-09-10 20:48:21 +0000523isis_zebra_read_ipv4 (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000524 zebra_size_t length)
525{
526 struct stream *stream;
527 struct zapi_ipv4 api;
528 struct prefix_ipv4 p;
529 unsigned long ifindex;
530 struct in_addr nexthop;
531
532 stream = zclient->ibuf;
533 memset (&p, 0, sizeof (struct prefix_ipv4));
534 ifindex = 0;
535
hassof390d2c2004-09-10 20:48:21 +0000536 api.type = stream_getc (stream);
537 api.flags = stream_getc (stream);
jardineb5d44e2003-12-23 08:09:43 +0000538 api.message = stream_getc (stream);
539
540 p.family = AF_INET;
541 p.prefixlen = stream_getc (stream);
542 stream_get (&p.prefix, stream, PSIZE (p.prefixlen));
hassof390d2c2004-09-10 20:48:21 +0000543
544 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
545 {
jardineb5d44e2003-12-23 08:09:43 +0000546 api.nexthop_num = stream_getc (stream);
547 nexthop.s_addr = stream_get_ipv4 (stream);
hassof390d2c2004-09-10 20:48:21 +0000548 }
549 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
550 {
551 api.ifindex_num = stream_getc (stream);
552 ifindex = stream_getl (stream);
553 }
jardineb5d44e2003-12-23 08:09:43 +0000554 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
555 api.distance = stream_getc (stream);
556 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
557 api.metric = stream_getl (stream);
558 else
559 api.metric = 0;
hassof390d2c2004-09-10 20:48:21 +0000560
561 if (command == ZEBRA_IPV4_ROUTE_ADD)
562 {
563 zlog_info ("IPv4 Route add from Z");
564 }
jardineb5d44e2003-12-23 08:09:43 +0000565
566 return 0;
567}
568
hassof390d2c2004-09-10 20:48:21 +0000569int
570isis_zebra_read_ipv6 (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000571 zebra_size_t length)
572{
jardineb5d44e2003-12-23 08:09:43 +0000573 return 0;
574}
575
576#define ISIS_TYPE_IS_REDISTRIBUTED(T) \
577T == ZEBRA_ROUTE_MAX ? zclient->default_information : zclient->redist[type]
578
579int
580isis_distribute_list_update (int routetype)
581{
582 return 0;
583}
584
585int
hassof390d2c2004-09-10 20:48:21 +0000586isis_redistribute_default_set (int routetype, int metric_type,
587 int metric_value)
jardineb5d44e2003-12-23 08:09:43 +0000588{
589 return 0;
590}
591
jardineb5d44e2003-12-23 08:09:43 +0000592void
593isis_zebra_init ()
594{
jardineb5d44e2003-12-23 08:09:43 +0000595 zclient = zclient_new ();
596 zclient_init (zclient, ZEBRA_ROUTE_ISIS);
hasso18a6dce2004-10-03 18:18:34 +0000597 zclient->router_id_update = isis_router_id_update_zebra;
jardineb5d44e2003-12-23 08:09:43 +0000598 zclient->interface_add = isis_zebra_if_add;
599 zclient->interface_delete = isis_zebra_if_del;
600 zclient->interface_up = isis_zebra_if_state_up;
601 zclient->interface_down = isis_zebra_if_state_down;
602 zclient->interface_address_add = isis_zebra_if_address_add;
603 zclient->interface_address_delete = isis_zebra_if_address_del;
604 zclient->ipv4_route_add = isis_zebra_read_ipv4;
605 zclient->ipv4_route_delete = isis_zebra_read_ipv4;
606#ifdef HAVE_IPV6
607 zclient->ipv6_route_add = isis_zebra_read_ipv6;
608 zclient->ipv6_route_delete = isis_zebra_read_ipv6;
609#endif /* HAVE_IPV6 */
610
611 return;
612}
613
614void
615isis_zebra_finish ()
616{
jardineb5d44e2003-12-23 08:09:43 +0000617 zclient_stop (zclient);
618 zclient_free (zclient);
619 zclient = (struct zclient *) NULL;
620
621 return;
622}