blob: 8e122082a5351c8c70277eedc9399205589e3d8c [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;
46
hassof390d2c2004-09-10 20:48:21 +000047int
jardineb5d44e2003-12-23 08:09:43 +000048isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length)
49{
50 struct interface *ifp;
51
52 ifp = zebra_interface_add_read (zclient->ibuf);
hassof390d2c2004-09-10 20:48:21 +000053
jardineb5d44e2003-12-23 08:09:43 +000054
55 zlog_info ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d",
56 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
hassof390d2c2004-09-10 20:48:21 +000057
jardineb5d44e2003-12-23 08:09:43 +000058 if (if_is_up (ifp))
59 isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
hassof390d2c2004-09-10 20:48:21 +000060
jardineb5d44e2003-12-23 08:09:43 +000061 return 0;
62}
63
64int
65isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length)
66{
67 struct interface *ifp;
68 struct stream *s;
69
70 s = zclient->ibuf;
71 ifp = zebra_interface_state_read (s);
hassof390d2c2004-09-10 20:48:21 +000072
jardineb5d44e2003-12-23 08:09:43 +000073 if (!ifp)
74 return 0;
75
76 if (if_is_up (ifp))
77 zlog_warn ("Zebra: got delete of %s, but interface is still up",
hassof390d2c2004-09-10 20:48:21 +000078 ifp->name);
jardineb5d44e2003-12-23 08:09:43 +000079
80 zlog_info ("Zebra I/F delete: %s index %d flags %ld metric %d mtu %d",
81 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
82
83 if_delete (ifp);
hassof390d2c2004-09-10 20:48:21 +000084
jardineb5d44e2003-12-23 08:09:43 +000085 isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
86
87 return 0;
88}
89
90struct interface *
91zebra_interface_if_lookup (struct stream *s)
92{
93 struct interface *ifp;
94 u_char ifname_tmp[INTERFACE_NAMSIZ];
95
96 /* Read interface name. */
97 stream_get (ifname_tmp, s, INTERFACE_NAMSIZ);
98
99 /* Lookup this by interface index. */
hassof7c43dc2004-09-26 16:24:14 +0000100 ifp = if_lookup_by_name ((char *) ifname_tmp);
jardineb5d44e2003-12-23 08:09:43 +0000101
102 /* If such interface does not exist, indicate an error */
103 if (!ifp)
104 return NULL;
105
106 return ifp;
107}
108
109void
110zebra_interface_if_set_value (struct stream *s, struct interface *ifp)
111{
112 /* Read interface's index. */
113 ifp->ifindex = stream_getl (s);
114
115 /* Read interface's value. */
116 ifp->flags = stream_getl (s);
117 ifp->metric = stream_getl (s);
118 ifp->mtu = stream_getl (s);
119 ifp->bandwidth = stream_getl (s);
120}
121
122int
hassof390d2c2004-09-10 20:48:21 +0000123isis_zebra_if_state_up (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000124 zebra_size_t length)
125{
126 struct interface *ifp;
hassof390d2c2004-09-10 20:48:21 +0000127
jardineb5d44e2003-12-23 08:09:43 +0000128 ifp = zebra_interface_if_lookup (zclient->ibuf);
hassof390d2c2004-09-10 20:48:21 +0000129
jardineb5d44e2003-12-23 08:09:43 +0000130 if (!ifp)
131 return 0;
hassof390d2c2004-09-10 20:48:21 +0000132
133 if (if_is_up (ifp))
134 {
135 zebra_interface_if_set_value (zclient->ibuf, ifp);
136 isis_circuit_update_params (circuit_scan_by_ifp (ifp), ifp);
137 return 0;
138 }
139
jardineb5d44e2003-12-23 08:09:43 +0000140 zebra_interface_if_set_value (zclient->ibuf, ifp);
141 isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
hassof390d2c2004-09-10 20:48:21 +0000142
jardineb5d44e2003-12-23 08:09:43 +0000143 return 0;
144}
145
jardineb5d44e2003-12-23 08:09:43 +0000146int
hassof390d2c2004-09-10 20:48:21 +0000147isis_zebra_if_state_down (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000148 zebra_size_t length)
149{
150 struct interface *ifp;
hassof390d2c2004-09-10 20:48:21 +0000151
jardineb5d44e2003-12-23 08:09:43 +0000152 ifp = zebra_interface_if_lookup (zclient->ibuf);
hassof390d2c2004-09-10 20:48:21 +0000153
jardineb5d44e2003-12-23 08:09:43 +0000154 if (ifp == NULL)
155 return 0;
hassof390d2c2004-09-10 20:48:21 +0000156
157 if (if_is_up (ifp))
158 {
159 zebra_interface_if_set_value (zclient->ibuf, ifp);
160 isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
161 }
162
jardineb5d44e2003-12-23 08:09:43 +0000163 return 0;
164}
165
166int
hassof390d2c2004-09-10 20:48:21 +0000167isis_zebra_if_address_add (int command, struct zclient *zclient,
168 zebra_size_t length)
jardineb5d44e2003-12-23 08:09:43 +0000169{
170 struct connected *c;
171 struct prefix *p;
hassof7c43dc2004-09-26 16:24:14 +0000172 char buf[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000173
hassof390d2c2004-09-10 20:48:21 +0000174 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD,
175 zclient->ibuf);
176
jardineb5d44e2003-12-23 08:09:43 +0000177 if (c == NULL)
178 return 0;
hassof390d2c2004-09-10 20:48:21 +0000179
jardineb5d44e2003-12-23 08:09:43 +0000180 p = c->address;
hassof390d2c2004-09-10 20:48:21 +0000181
jardineb5d44e2003-12-23 08:09:43 +0000182 prefix2str (p, buf, BUFSIZ);
183#ifdef EXTREME_DEBUG
hassof390d2c2004-09-10 20:48:21 +0000184 if (p->family == AF_INET)
jardineb5d44e2003-12-23 08:09:43 +0000185 zlog_info ("connected IP address %s", buf);
186#ifdef HAVE_IPV6
187 if (p->family == AF_INET6)
188 zlog_info ("connected IPv6 address %s", buf);
189#endif /* HAVE_IPV6 */
190#endif /* EXTREME_DEBUG */
hassof390d2c2004-09-10 20:48:21 +0000191 isis_circuit_add_addr (circuit_scan_by_ifp (c->ifp), c);
jardineb5d44e2003-12-23 08:09:43 +0000192
193 return 0;
194}
195
196int
hassof390d2c2004-09-10 20:48:21 +0000197isis_zebra_if_address_del (int command, struct zclient *client,
198 zebra_size_t length)
jardineb5d44e2003-12-23 08:09:43 +0000199{
200 struct connected *c;
201 struct interface *ifp;
hassof891f442004-09-14 13:54:30 +0000202 struct prefix *p;
203 u_char buf[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000204
hassof390d2c2004-09-10 20:48:21 +0000205 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE,
206 zclient->ibuf);
207
jardineb5d44e2003-12-23 08:09:43 +0000208 if (c == NULL)
209 return 0;
hassof390d2c2004-09-10 20:48:21 +0000210
jardineb5d44e2003-12-23 08:09:43 +0000211 ifp = c->ifp;
hassof390d2c2004-09-10 20:48:21 +0000212
hassof891f442004-09-14 13:54:30 +0000213#ifdef EXTREME_DEBUG
214 p = c->address;
215 prefix2str (p, buf, BUFSIZ);
216
217 if (p->family == AF_INET)
218 zlog_info ("disconnected IP address %s", buf);
219#ifdef HAVE_IPV6
220 if (p->family == AF_INET6)
221 zlog_info ("disconnected IPv6 address %s", buf);
222#endif /* HAVE_IPV6 */
223#endif /* EXTREME_DEBUG */
hassof390d2c2004-09-10 20:48:21 +0000224
jardineb5d44e2003-12-23 08:09:43 +0000225 isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c);
hassof891f442004-09-14 13:54:30 +0000226 connected_free (c);
hassof390d2c2004-09-10 20:48:21 +0000227
jardineb5d44e2003-12-23 08:09:43 +0000228 return 0;
229}
230
231void
hassof390d2c2004-09-10 20:48:21 +0000232isis_zebra_route_add_ipv4 (struct prefix *prefix,
233 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000234{
235 u_char message, flags;
236 int psize;
237 struct stream *stream;
238 struct isis_nexthop *nexthop;
239 struct listnode *node;
240
241 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
242 return;
243
hassof390d2c2004-09-10 20:48:21 +0000244 if (zclient->redist[ZEBRA_ROUTE_ISIS])
245 {
246 message = 0;
247 flags = 0;
jardineb5d44e2003-12-23 08:09:43 +0000248
hassof390d2c2004-09-10 20:48:21 +0000249 SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP);
250 SET_FLAG (message, ZAPI_MESSAGE_METRIC);
hasso2097cd82003-12-23 11:51:08 +0000251#if 0
hassof390d2c2004-09-10 20:48:21 +0000252 SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
hasso2097cd82003-12-23 11:51:08 +0000253#endif
hassof390d2c2004-09-10 20:48:21 +0000254
255 stream = zclient->obuf;
256 stream_reset (stream);
257 /* Length place holder. */
258 stream_putw (stream, 0);
259 /* command */
260 stream_putc (stream, ZEBRA_IPV4_ROUTE_ADD);
261 /* type */
262 stream_putc (stream, ZEBRA_ROUTE_ISIS);
263 /* flags */
264 stream_putc (stream, flags);
265 /* message */
266 stream_putc (stream, message);
267 /* prefix information */
268 psize = PSIZE (prefix->prefixlen);
269 stream_putc (stream, prefix->prefixlen);
270 stream_write (stream, (u_char *) & prefix->u.prefix4, psize);
271
272 stream_putc (stream, listcount (route_info->nexthops));
273
274 /* Nexthop, ifindex, distance and metric information */
275 for (node = listhead (route_info->nexthops); node; nextnode (node))
276 {
277 nexthop = getdata (node);
278 /* FIXME: can it be ? */
279 if (nexthop->ip.s_addr != INADDR_ANY)
280 {
281 stream_putc (stream, ZEBRA_NEXTHOP_IPV4);
282 stream_put_in_addr (stream, &nexthop->ip);
283 }
284 else
285 {
286 stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX);
287 stream_putl (stream, nexthop->ifindex);
288 }
289 }
290#if 0
291 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
292 stream_putc (stream, route_info->depth);
293#endif
294 if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
295 stream_putl (stream, route_info->cost);
296
297 stream_putw_at (stream, 0, stream_get_endp (stream));
298 writen (zclient->sock, stream->data, stream_get_endp (stream));
299 }
jardineb5d44e2003-12-23 08:09:43 +0000300}
301
302void
hassof390d2c2004-09-10 20:48:21 +0000303isis_zebra_route_del_ipv4 (struct prefix *prefix,
304 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000305{
306 struct zapi_ipv4 api;
307 struct prefix_ipv4 prefix4;
hassof390d2c2004-09-10 20:48:21 +0000308
309 if (zclient->redist[ZEBRA_ROUTE_ISIS])
310 {
311 api.type = ZEBRA_ROUTE_ISIS;
312 api.flags = 0;
313 api.message = 0;
314 prefix4.family = AF_INET;
315 prefix4.prefixlen = prefix->prefixlen;
316 prefix4.prefix = prefix->u.prefix4;
317 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, &prefix4, &api);
318 }
319
jardineb5d44e2003-12-23 08:09:43 +0000320 return;
321}
322
323#ifdef HAVE_IPV6
324void
325isis_zebra_route_add_ipv6 (struct prefix *prefix,
hassof390d2c2004-09-10 20:48:21 +0000326 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000327{
328 struct zapi_ipv6 api;
329 struct in6_addr **nexthop_list;
330 unsigned int *ifindex_list;
331 struct isis_nexthop6 *nexthop6;
332 int i, size;
333 struct listnode *node;
334 struct prefix_ipv6 prefix6;
335
336 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
337 return;
hassof390d2c2004-09-10 20:48:21 +0000338
jardineb5d44e2003-12-23 08:09:43 +0000339 api.type = ZEBRA_ROUTE_ISIS;
340 api.flags = 0;
341 api.message = 0;
342 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
343 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
344 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
345 api.metric = route_info->cost;
346#if 0
347 SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
348 api.distance = route_info->depth;
349#endif
350 api.nexthop_num = listcount (route_info->nexthops6);
351 api.ifindex_num = listcount (route_info->nexthops6);
hassof390d2c2004-09-10 20:48:21 +0000352
jardineb5d44e2003-12-23 08:09:43 +0000353 /* allocate memory for nexthop_list */
354 size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
355 nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000356 if (!nexthop_list)
357 {
358 zlog_err ("isis_zebra_add_route_ipv6: out of memory!");
359 return;
360 }
361
jardineb5d44e2003-12-23 08:09:43 +0000362 /* allocate memory for ifindex_list */
363 size = sizeof (unsigned int) * listcount (route_info->nexthops6);
364 ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000365 if (!ifindex_list)
366 {
367 zlog_err ("isis_zebra_add_route_ipv6: out of memory!");
368 XFREE (MTYPE_ISIS_TMP, nexthop_list);
369 return;
370 }
371
jardineb5d44e2003-12-23 08:09:43 +0000372 /* for each nexthop */
373 i = 0;
hassof390d2c2004-09-10 20:48:21 +0000374 for (node = listhead (route_info->nexthops6); node; nextnode (node))
375 {
376 nexthop6 = getdata (node);
377
378 if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
379 !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6))
380 {
381 api.nexthop_num--;
382 api.ifindex_num--;
383 continue;
384 }
385
386 nexthop_list[i] = &nexthop6->ip6;
387 ifindex_list[i] = nexthop6->ifindex;
388 i++;
jardineb5d44e2003-12-23 08:09:43 +0000389 }
hassof390d2c2004-09-10 20:48:21 +0000390
jardineb5d44e2003-12-23 08:09:43 +0000391 api.nexthop = nexthop_list;
392 api.ifindex = ifindex_list;
hassof390d2c2004-09-10 20:48:21 +0000393
394 if (api.nexthop_num && api.ifindex_num)
395 {
396 prefix6.family = AF_INET6;
397 prefix6.prefixlen = prefix->prefixlen;
398 memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
399 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, &prefix6, &api);
400 SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC);
401 }
402
jardineb5d44e2003-12-23 08:09:43 +0000403 XFREE (MTYPE_ISIS_TMP, nexthop_list);
404 XFREE (MTYPE_ISIS_TMP, ifindex_list);
hassof390d2c2004-09-10 20:48:21 +0000405
jardineb5d44e2003-12-23 08:09:43 +0000406 return;
407}
408
409void
hassof390d2c2004-09-10 20:48:21 +0000410isis_zebra_route_del_ipv6 (struct prefix *prefix,
411 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000412{
413 struct zapi_ipv6 api;
414 struct in6_addr **nexthop_list;
415 unsigned int *ifindex_list;
416 struct isis_nexthop6 *nexthop6;
417 int i, size;
418 struct listnode *node;
419 struct prefix_ipv6 prefix6;
420
421 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC))
422 return;
hassof390d2c2004-09-10 20:48:21 +0000423
jardineb5d44e2003-12-23 08:09:43 +0000424 api.type = ZEBRA_ROUTE_ISIS;
425 api.flags = 0;
426 api.message = 0;
427 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
428 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
429 api.nexthop_num = listcount (route_info->nexthops6);
430 api.ifindex_num = listcount (route_info->nexthops6);
hassof390d2c2004-09-10 20:48:21 +0000431
jardineb5d44e2003-12-23 08:09:43 +0000432 /* allocate memory for nexthop_list */
433 size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
434 nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000435 if (!nexthop_list)
436 {
437 zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
438 return;
439 }
440
jardineb5d44e2003-12-23 08:09:43 +0000441 /* allocate memory for ifindex_list */
442 size = sizeof (unsigned int) * listcount (route_info->nexthops6);
443 ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size);
hassof390d2c2004-09-10 20:48:21 +0000444 if (!ifindex_list)
445 {
446 zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
447 XFREE (MTYPE_ISIS_TMP, nexthop_list);
448 return;
449 }
450
jardineb5d44e2003-12-23 08:09:43 +0000451 /* for each nexthop */
452 i = 0;
hassof390d2c2004-09-10 20:48:21 +0000453 for (node = listhead (route_info->nexthops6); node; nextnode (node))
454 {
455 nexthop6 = getdata (node);
456
457 if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
458 !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6))
459 {
460 api.nexthop_num--;
461 api.ifindex_num--;
462 continue;
463 }
464
465 nexthop_list[i] = &nexthop6->ip6;
466 ifindex_list[i] = nexthop6->ifindex;
467 i++;
jardineb5d44e2003-12-23 08:09:43 +0000468 }
hassof390d2c2004-09-10 20:48:21 +0000469
jardineb5d44e2003-12-23 08:09:43 +0000470 api.nexthop = nexthop_list;
471 api.ifindex = ifindex_list;
jardineb5d44e2003-12-23 08:09:43 +0000472
hassof390d2c2004-09-10 20:48:21 +0000473 if (api.nexthop_num && api.ifindex_num)
474 {
475 prefix6.family = AF_INET6;
476 prefix6.prefixlen = prefix->prefixlen;
477 memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
478 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, &prefix6, &api);
479 UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC);
480 }
481
482 XFREE (MTYPE_ISIS_TMP, nexthop_list);
483 XFREE (MTYPE_ISIS_TMP, ifindex_list);
484}
jardineb5d44e2003-12-23 08:09:43 +0000485
486#endif /* HAVE_IPV6 */
487
jardineb5d44e2003-12-23 08:09:43 +0000488void
489isis_zebra_route_update (struct prefix *prefix,
hassof390d2c2004-09-10 20:48:21 +0000490 struct isis_route_info *route_info)
jardineb5d44e2003-12-23 08:09:43 +0000491{
492 if (zclient->sock < 0)
493 return;
494
495 if (!zclient->redist[ZEBRA_ROUTE_ISIS])
496 return;
497
hassof390d2c2004-09-10 20:48:21 +0000498 if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE))
499 {
500 if (prefix->family == AF_INET)
501 isis_zebra_route_add_ipv4 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000502#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000503 else if (prefix->family == AF_INET6)
504 isis_zebra_route_add_ipv6 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000505#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000506 }
507 else
508 {
509 if (prefix->family == AF_INET)
510 isis_zebra_route_del_ipv4 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000511#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000512 else if (prefix->family == AF_INET6)
513 isis_zebra_route_del_ipv6 (prefix, route_info);
jardineb5d44e2003-12-23 08:09:43 +0000514#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000515 }
jardineb5d44e2003-12-23 08:09:43 +0000516 return;
517}
518
jardineb5d44e2003-12-23 08:09:43 +0000519int
hassof390d2c2004-09-10 20:48:21 +0000520isis_zebra_read_ipv4 (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000521 zebra_size_t length)
522{
523 struct stream *stream;
524 struct zapi_ipv4 api;
525 struct prefix_ipv4 p;
526 unsigned long ifindex;
527 struct in_addr nexthop;
528
529 stream = zclient->ibuf;
530 memset (&p, 0, sizeof (struct prefix_ipv4));
531 ifindex = 0;
532
hassof390d2c2004-09-10 20:48:21 +0000533 api.type = stream_getc (stream);
534 api.flags = stream_getc (stream);
jardineb5d44e2003-12-23 08:09:43 +0000535 api.message = stream_getc (stream);
536
537 p.family = AF_INET;
538 p.prefixlen = stream_getc (stream);
539 stream_get (&p.prefix, stream, PSIZE (p.prefixlen));
hassof390d2c2004-09-10 20:48:21 +0000540
541 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
542 {
jardineb5d44e2003-12-23 08:09:43 +0000543 api.nexthop_num = stream_getc (stream);
544 nexthop.s_addr = stream_get_ipv4 (stream);
hassof390d2c2004-09-10 20:48:21 +0000545 }
546 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
547 {
548 api.ifindex_num = stream_getc (stream);
549 ifindex = stream_getl (stream);
550 }
jardineb5d44e2003-12-23 08:09:43 +0000551 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
552 api.distance = stream_getc (stream);
553 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
554 api.metric = stream_getl (stream);
555 else
556 api.metric = 0;
hassof390d2c2004-09-10 20:48:21 +0000557
558 if (command == ZEBRA_IPV4_ROUTE_ADD)
559 {
560 zlog_info ("IPv4 Route add from Z");
561 }
jardineb5d44e2003-12-23 08:09:43 +0000562
563 return 0;
564}
565
hassof390d2c2004-09-10 20:48:21 +0000566int
567isis_zebra_read_ipv6 (int command, struct zclient *zclient,
jardineb5d44e2003-12-23 08:09:43 +0000568 zebra_size_t length)
569{
jardineb5d44e2003-12-23 08:09:43 +0000570 return 0;
571}
572
573#define ISIS_TYPE_IS_REDISTRIBUTED(T) \
574T == ZEBRA_ROUTE_MAX ? zclient->default_information : zclient->redist[type]
575
576int
577isis_distribute_list_update (int routetype)
578{
579 return 0;
580}
581
582int
hassof390d2c2004-09-10 20:48:21 +0000583isis_redistribute_default_set (int routetype, int metric_type,
584 int metric_value)
jardineb5d44e2003-12-23 08:09:43 +0000585{
586 return 0;
587}
588
jardineb5d44e2003-12-23 08:09:43 +0000589void
590isis_zebra_init ()
591{
jardineb5d44e2003-12-23 08:09:43 +0000592 zclient = zclient_new ();
593 zclient_init (zclient, ZEBRA_ROUTE_ISIS);
594 zclient->interface_add = isis_zebra_if_add;
595 zclient->interface_delete = isis_zebra_if_del;
596 zclient->interface_up = isis_zebra_if_state_up;
597 zclient->interface_down = isis_zebra_if_state_down;
598 zclient->interface_address_add = isis_zebra_if_address_add;
599 zclient->interface_address_delete = isis_zebra_if_address_del;
600 zclient->ipv4_route_add = isis_zebra_read_ipv4;
601 zclient->ipv4_route_delete = isis_zebra_read_ipv4;
602#ifdef HAVE_IPV6
603 zclient->ipv6_route_add = isis_zebra_read_ipv6;
604 zclient->ipv6_route_delete = isis_zebra_read_ipv6;
605#endif /* HAVE_IPV6 */
606
607 return;
608}
609
610void
611isis_zebra_finish ()
612{
jardineb5d44e2003-12-23 08:09:43 +0000613 zclient_stop (zclient);
614 zclient_free (zclient);
615 zclient = (struct zclient *) NULL;
616
617 return;
618}