Import Debian changes 1.2.2-1
[quagga-debian.git] / isisd / isis_zebra.c
1 /*
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  * Copyright (C) 2013-2015   Christian Franke <chris@opensourcerouting.org>
8  *
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>
25
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"
36 #include "vrf.h"
37
38 #include "isisd/dict.h"
39 #include "isisd/isis_constants.h"
40 #include "isisd/isis_common.h"
41 #include "isisd/isis_flags.h"
42 #include "isisd/isis_misc.h"
43 #include "isisd/isis_circuit.h"
44 #include "isisd/isis_tlv.h"
45 #include "isisd/isisd.h"
46 #include "isisd/isis_circuit.h"
47 #include "isisd/isis_csm.h"
48 #include "isisd/isis_lsp.h"
49 #include "isisd/isis_route.h"
50 #include "isisd/isis_zebra.h"
51 #include "isisd/isis_te.h"
52
53 struct zclient *zclient = NULL;
54
55 /* Router-id update message from zebra. */
56 static int
57 isis_router_id_update_zebra (int command, struct zclient *zclient,
58                              zebra_size_t length, vrf_id_t vrf_id)
59 {
60   struct isis_area *area;
61   struct listnode *node;
62   struct prefix router_id;
63
64   /*
65    * If ISIS TE is enable, TE Router ID is set through specific command.
66    * See mpls_te_router_addr() command in isis_te.c
67    */
68   if (IS_MPLS_TE(isisMplsTE))
69     return 0;
70
71   zebra_router_id_update_read (zclient->ibuf, &router_id);
72   if (isis->router_id == router_id.u.prefix4.s_addr)
73     return 0;
74
75   isis->router_id = router_id.u.prefix4.s_addr;
76   for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area))
77     if (listcount (area->area_addrs) > 0)
78       lsp_regenerate_schedule (area, area->is_type, 0);
79
80   return 0;
81 }
82
83 static int
84 isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length,
85     vrf_id_t vrf_id)
86 {
87   struct interface *ifp;
88
89   ifp = zebra_interface_add_read (zclient->ibuf, vrf_id);
90
91   if (isis->debugs & DEBUG_ZEBRA)
92     zlog_debug ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d",
93                 ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, ifp->mtu);
94
95   if (if_is_operative (ifp))
96     isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
97
98   return 0;
99 }
100
101 static int
102 isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length,
103     vrf_id_t vrf_id)
104 {
105   struct interface *ifp;
106   struct stream *s;
107
108   s = zclient->ibuf;
109   ifp = zebra_interface_state_read (s, vrf_id);
110
111   if (!ifp)
112     return 0;
113
114   if (if_is_operative (ifp))
115     zlog_warn ("Zebra: got delete of %s, but interface is still up",
116                ifp->name);
117
118   if (isis->debugs & DEBUG_ZEBRA)
119     zlog_debug ("Zebra I/F delete: %s index %d flags %ld metric %d mtu %d",
120                 ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, ifp->mtu);
121
122   isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
123
124   /* Cannot call if_delete because we should retain the pseudo interface
125      in case there is configuration info attached to it. */
126   if_delete_retain(ifp);
127
128   ifp->ifindex = IFINDEX_INTERNAL;
129
130   return 0;
131 }
132
133 static int
134 isis_zebra_if_state_up (int command, struct zclient *zclient,
135                         zebra_size_t length, vrf_id_t vrf_id)
136 {
137   struct interface *ifp;
138
139   ifp = zebra_interface_state_read (zclient->ibuf, vrf_id);
140
141   if (ifp == NULL)
142     return 0;
143
144   isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp);
145
146   return 0;
147 }
148
149 static int
150 isis_zebra_if_state_down (int command, struct zclient *zclient,
151                           zebra_size_t length, vrf_id_t vrf_id)
152 {
153   struct interface *ifp;
154   struct isis_circuit *circuit;
155
156   ifp = zebra_interface_state_read (zclient->ibuf, vrf_id);
157
158   if (ifp == NULL)
159     return 0;
160
161   circuit = isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp),
162                                    ifp);
163   if (circuit)
164     SET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF);
165
166   return 0;
167 }
168
169 static int
170 isis_zebra_if_address_add (int command, struct zclient *zclient,
171                            zebra_size_t length, vrf_id_t vrf_id)
172 {
173   struct connected *c;
174   struct prefix *p;
175   char buf[BUFSIZ];
176
177   c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD,
178                                     zclient->ibuf, vrf_id);
179
180   if (c == NULL)
181     return 0;
182
183   p = c->address;
184
185   prefix2str (p, buf, BUFSIZ);
186 #ifdef EXTREME_DEBUG
187   if (p->family == AF_INET)
188     zlog_debug ("connected IP address %s", buf);
189 #ifdef HAVE_IPV6
190   if (p->family == AF_INET6)
191     zlog_debug ("connected IPv6 address %s", buf);
192 #endif /* HAVE_IPV6 */
193 #endif /* EXTREME_DEBUG */
194   if (if_is_operative (c->ifp))
195     isis_circuit_add_addr (circuit_scan_by_ifp (c->ifp), c);
196
197   return 0;
198 }
199
200 static int
201 isis_zebra_if_address_del (int command, struct zclient *client,
202                            zebra_size_t length, vrf_id_t vrf_id)
203 {
204   struct connected *c;
205   struct interface *ifp;
206 #ifdef EXTREME_DEBUG
207   struct prefix *p;
208   u_char buf[BUFSIZ];
209 #endif /* EXTREME_DEBUG */
210
211   c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE,
212                                     zclient->ibuf, vrf_id);
213
214   if (c == NULL)
215     return 0;
216
217   ifp = c->ifp;
218
219 #ifdef EXTREME_DEBUG
220   p = c->address;
221   prefix2str (p, buf, BUFSIZ);
222
223   if (p->family == AF_INET)
224     zlog_debug ("disconnected IP address %s", buf);
225 #ifdef HAVE_IPV6
226   if (p->family == AF_INET6)
227     zlog_debug ("disconnected IPv6 address %s", buf);
228 #endif /* HAVE_IPV6 */
229 #endif /* EXTREME_DEBUG */
230
231   if (if_is_operative (ifp))
232     isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c);
233   connected_free (c);
234
235   return 0;
236 }
237
238 static int
239 isis_zebra_link_params (int command, struct zclient *zclient,
240                         zebra_size_t length)
241 {
242   struct interface *ifp;
243
244   ifp = zebra_interface_link_params_read (zclient->ibuf);
245
246   if (ifp == NULL)
247     return 0;
248
249   /* Update TE TLV */
250   isis_mpls_te_update(ifp);
251
252   return 0;
253 }
254
255 static void
256 isis_zebra_route_add_ipv4 (struct prefix *prefix,
257                            struct isis_route_info *route_info)
258 {
259   u_char message, flags;
260   int psize;
261   struct stream *stream;
262   struct isis_nexthop *nexthop;
263   struct listnode *node;
264
265   if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED))
266     return;
267
268   if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_ISIS], VRF_DEFAULT))
269     {
270       message = 0;
271       flags = 0;
272
273       SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP);
274       SET_FLAG (message, ZAPI_MESSAGE_METRIC);
275 #if 0
276       SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
277 #endif
278
279       stream = zclient->obuf;
280       stream_reset (stream);
281       zclient_create_header (stream, ZEBRA_IPV4_ROUTE_ADD, VRF_DEFAULT);
282       /* type */
283       stream_putc (stream, ZEBRA_ROUTE_ISIS);
284       /* flags */
285       stream_putc (stream, flags);
286       /* message */
287       stream_putc (stream, message);
288       /* SAFI */
289       stream_putw (stream, SAFI_UNICAST);
290       /* prefix information */
291       psize = PSIZE (prefix->prefixlen);
292       stream_putc (stream, prefix->prefixlen);
293       stream_write (stream, (u_char *) & prefix->u.prefix4, psize);
294
295       stream_putc (stream, listcount (route_info->nexthops));
296
297       /* Nexthop, ifindex, distance and metric information */
298       for (ALL_LIST_ELEMENTS_RO (route_info->nexthops, node, nexthop))
299         {
300           /* FIXME: can it be ? */
301           if (nexthop->ip.s_addr != INADDR_ANY)
302             {
303               stream_putc (stream, ZEBRA_NEXTHOP_IPV4);
304               stream_put_in_addr (stream, &nexthop->ip);
305             }
306           else
307             {
308               stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX);
309               stream_putl (stream, nexthop->ifindex);
310             }
311         }
312 #if 0
313       if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
314         stream_putc (stream, route_info->depth);
315 #endif
316       if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
317         stream_putl (stream, route_info->cost);
318
319       stream_putw_at (stream, 0, stream_get_endp (stream));
320       zclient_send_message(zclient);
321       SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
322       UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC);
323     }
324 }
325
326 static void
327 isis_zebra_route_del_ipv4 (struct prefix *prefix,
328                            struct isis_route_info *route_info)
329 {
330   struct zapi_ipv4 api;
331   struct prefix_ipv4 prefix4;
332
333   if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_ISIS], VRF_DEFAULT))
334     {
335       api.vrf_id = VRF_DEFAULT;
336       api.type = ZEBRA_ROUTE_ISIS;
337       api.flags = 0;
338       api.message = 0;
339       api.safi = SAFI_UNICAST;
340       prefix4.family = AF_INET;
341       prefix4.prefixlen = prefix->prefixlen;
342       prefix4.prefix = prefix->u.prefix4;
343       zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, &prefix4, &api);
344     }
345   UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
346
347   return;
348 }
349
350 #ifdef HAVE_IPV6
351 static void
352 isis_zebra_route_add_ipv6 (struct prefix *prefix,
353                            struct isis_route_info *route_info)
354 {
355   struct zapi_ipv6 api;
356   struct in6_addr **nexthop_list;
357   ifindex_t *ifindex_list;
358   struct isis_nexthop6 *nexthop6;
359   int i, size;
360   struct listnode *node;
361   struct prefix_ipv6 prefix6;
362
363   if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED))
364     return;
365
366   api.vrf_id = VRF_DEFAULT;
367   api.type = ZEBRA_ROUTE_ISIS;
368   api.flags = 0;
369   api.message = 0;
370   api.safi = SAFI_UNICAST;
371   SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
372   SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
373   SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
374   api.metric = route_info->cost;
375 #if 0
376   SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
377   api.distance = route_info->depth;
378 #endif
379   api.nexthop_num = listcount (route_info->nexthops6);
380   api.ifindex_num = listcount (route_info->nexthops6);
381
382   /* allocate memory for nexthop_list */
383   size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
384   nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
385   if (!nexthop_list)
386     {
387       zlog_err ("isis_zebra_add_route_ipv6: out of memory!");
388       return;
389     }
390
391   /* allocate memory for ifindex_list */
392   size = sizeof (unsigned int) * listcount (route_info->nexthops6);
393   ifindex_list = (ifindex_t *) XMALLOC (MTYPE_ISIS_TMP, size);
394   if (!ifindex_list)
395     {
396       zlog_err ("isis_zebra_add_route_ipv6: out of memory!");
397       XFREE (MTYPE_ISIS_TMP, nexthop_list);
398       return;
399     }
400
401   /* for each nexthop */
402   i = 0;
403   for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6))
404     {
405       if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
406           !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6))
407         {
408           api.nexthop_num--;
409           api.ifindex_num--;
410           continue;
411         }
412
413       nexthop_list[i] = &nexthop6->ip6;
414       ifindex_list[i] = nexthop6->ifindex;
415       i++;
416     }
417
418   api.nexthop = nexthop_list;
419   api.ifindex = ifindex_list;
420
421   if (api.nexthop_num && api.ifindex_num)
422     {
423       prefix6.family = AF_INET6;
424       prefix6.prefixlen = prefix->prefixlen;
425       memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
426       zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, &prefix6, &api);
427       SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
428       UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC);
429     }
430
431   XFREE (MTYPE_ISIS_TMP, nexthop_list);
432   XFREE (MTYPE_ISIS_TMP, ifindex_list);
433
434   return;
435 }
436
437 static void
438 isis_zebra_route_del_ipv6 (struct prefix *prefix,
439                            struct isis_route_info *route_info)
440 {
441   struct zapi_ipv6 api;
442   struct in6_addr **nexthop_list;
443   ifindex_t *ifindex_list;
444   struct isis_nexthop6 *nexthop6;
445   int i, size;
446   struct listnode *node;
447   struct prefix_ipv6 prefix6;
448
449   if (!CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED))
450     return;
451
452   api.vrf_id = VRF_DEFAULT;
453   api.type = ZEBRA_ROUTE_ISIS;
454   api.flags = 0;
455   api.message = 0;
456   api.safi = SAFI_UNICAST;
457   SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
458   SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
459   api.nexthop_num = listcount (route_info->nexthops6);
460   api.ifindex_num = listcount (route_info->nexthops6);
461
462   /* allocate memory for nexthop_list */
463   size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6);
464   nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size);
465   if (!nexthop_list)
466     {
467       zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
468       return;
469     }
470
471   /* allocate memory for ifindex_list */
472   size = sizeof (unsigned int) * listcount (route_info->nexthops6);
473   ifindex_list = (ifindex_t *) XMALLOC (MTYPE_ISIS_TMP, size);
474   if (!ifindex_list)
475     {
476       zlog_err ("isis_zebra_route_del_ipv6: out of memory!");
477       XFREE (MTYPE_ISIS_TMP, nexthop_list);
478       return;
479     }
480
481   /* for each nexthop */
482   i = 0;
483   for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6))
484     {
485       if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) &&
486           !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6))
487         {
488           api.nexthop_num--;
489           api.ifindex_num--;
490           continue;
491         }
492
493       nexthop_list[i] = &nexthop6->ip6;
494       ifindex_list[i] = nexthop6->ifindex;
495       i++;
496     }
497
498   api.nexthop = nexthop_list;
499   api.ifindex = ifindex_list;
500
501   if (api.nexthop_num && api.ifindex_num)
502     {
503       prefix6.family = AF_INET6;
504       prefix6.prefixlen = prefix->prefixlen;
505       memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr));
506       zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, &prefix6, &api);
507       UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
508     }
509
510   XFREE (MTYPE_ISIS_TMP, nexthop_list);
511   XFREE (MTYPE_ISIS_TMP, ifindex_list);
512 }
513
514 #endif /* HAVE_IPV6 */
515
516 void
517 isis_zebra_route_update (struct prefix *prefix,
518                          struct isis_route_info *route_info)
519 {
520   if (zclient->sock < 0)
521     return;
522
523   if (!vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_ISIS], VRF_DEFAULT))
524     return;
525
526   if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE))
527     {
528       if (prefix->family == AF_INET)
529         isis_zebra_route_add_ipv4 (prefix, route_info);
530 #ifdef HAVE_IPV6
531       else if (prefix->family == AF_INET6)
532         isis_zebra_route_add_ipv6 (prefix, route_info);
533 #endif /* HAVE_IPV6 */
534     }
535   else
536     {
537       if (prefix->family == AF_INET)
538         isis_zebra_route_del_ipv4 (prefix, route_info);
539 #ifdef HAVE_IPV6
540       else if (prefix->family == AF_INET6)
541         isis_zebra_route_del_ipv6 (prefix, route_info);
542 #endif /* HAVE_IPV6 */
543     }
544   return;
545 }
546
547 static int
548 isis_zebra_read_ipv4 (int command, struct zclient *zclient,
549                       zebra_size_t length, vrf_id_t vrf_id)
550 {
551   struct stream *stream;
552   struct zapi_ipv4 api;
553   struct prefix_ipv4 p;
554   struct prefix *p_generic = (struct prefix*)&p;
555   unsigned long ifindex __attribute__ ((unused));
556   struct in_addr nexthop __attribute__ ((unused));
557   unsigned char plength = 0;
558
559   stream = zclient->ibuf;
560   memset(&api, 0, sizeof(api));
561   memset (&p, 0, sizeof (struct prefix_ipv4));
562   memset(&nexthop, 0, sizeof(nexthop));
563   ifindex = 0;
564
565   api.type = stream_getc (stream);
566   api.flags = stream_getc (stream);
567   api.message = stream_getc (stream);
568
569   p.family = AF_INET;
570   plength = stream_getc (stream);
571   p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, plength);
572   stream_get (&p.prefix, stream, PSIZE (p.prefixlen));
573
574   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
575     {
576       api.nexthop_num = stream_getc (stream);
577       nexthop.s_addr = stream_get_ipv4 (stream);
578     }
579   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
580     {
581       api.ifindex_num = stream_getc (stream);
582       ifindex = stream_getl (stream);
583     }
584   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
585     api.distance = stream_getc (stream);
586   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
587     api.metric = stream_getl (stream);
588
589   /*
590    * Avoid advertising a false default reachability. (A default
591    * route installed by IS-IS gets redistributed from zebra back
592    * into IS-IS causing us to start advertising default reachabity
593    * without this check)
594    */
595   if (p.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS)
596     command = ZEBRA_IPV4_ROUTE_DELETE;
597
598   if (command == ZEBRA_IPV4_ROUTE_ADD)
599     isis_redist_add(api.type, p_generic, api.distance, api.metric);
600   else
601     isis_redist_delete(api.type, p_generic);
602
603   return 0;
604 }
605
606 static int
607 isis_zebra_read_ipv6 (int command, struct zclient *zclient,
608                       zebra_size_t length, vrf_id_t vrf_id)
609 {
610   struct stream *stream;
611   struct zapi_ipv6 api;
612   struct prefix_ipv6 p;
613   struct prefix *p_generic = (struct prefix*)&p;
614   struct in6_addr nexthop;
615   unsigned long ifindex __attribute__((unused));
616
617   stream = zclient->ibuf;
618   memset(&api, 0, sizeof(api));
619   memset(&p, 0, sizeof(struct prefix_ipv6));
620   memset(&nexthop, 0, sizeof(nexthop));
621   ifindex = 0;
622
623   api.type = stream_getc(stream);
624   api.flags = stream_getc(stream);
625   api.message = stream_getc(stream);
626
627   p.family = AF_INET6;
628   p.prefixlen = stream_getc(stream);
629   stream_get(&p.prefix, stream, PSIZE(p.prefixlen));
630
631   if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP))
632     {
633       api.nexthop_num = stream_getc(stream); /* this is always 1 */
634       stream_get(&nexthop, stream, sizeof(nexthop));
635     }
636   if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX))
637     {
638       api.ifindex_num = stream_getc(stream);
639       ifindex = stream_getl(stream);
640     }
641   if (CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE))
642     api.distance = stream_getc(stream);
643   if (CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC))
644     api.metric = stream_getl(stream);
645
646   /*
647    * Avoid advertising a false default reachability. (A default
648    * route installed by IS-IS gets redistributed from zebra back
649    * into IS-IS causing us to start advertising default reachabity
650    * without this check)
651    */
652   if (p.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS)
653     command = ZEBRA_IPV6_ROUTE_DELETE;
654
655   if (command == ZEBRA_IPV6_ROUTE_ADD)
656     isis_redist_add(api.type, p_generic, api.distance, api.metric);
657   else
658     isis_redist_delete(api.type, p_generic);
659
660   return 0;
661 }
662
663 int
664 isis_distribute_list_update (int routetype)
665 {
666   return 0;
667 }
668
669 void
670 isis_zebra_redistribute_set(int type)
671 {
672   if (type == DEFAULT_ROUTE)
673     zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, VRF_DEFAULT);
674   else
675     zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
676 }
677
678 void
679 isis_zebra_redistribute_unset(int type)
680 {
681   if (type == DEFAULT_ROUTE)
682     zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, VRF_DEFAULT);
683   else
684     zclient_redistribute(ZEBRA_REDISTRIBUTE_DELETE, zclient, type, VRF_DEFAULT);
685 }
686
687 static void
688 isis_zebra_connected (struct zclient *zclient)
689 {
690   zclient_send_requests (zclient, VRF_DEFAULT);
691 }
692
693 void
694 isis_zebra_init (struct thread_master *master)
695 {
696   zclient = zclient_new (master);
697   zclient_init (zclient, ZEBRA_ROUTE_ISIS);
698   zclient->zebra_connected = isis_zebra_connected;
699   zclient->router_id_update = isis_router_id_update_zebra;
700   zclient->interface_add = isis_zebra_if_add;
701   zclient->interface_delete = isis_zebra_if_del;
702   zclient->interface_up = isis_zebra_if_state_up;
703   zclient->interface_down = isis_zebra_if_state_down;
704   zclient->interface_address_add = isis_zebra_if_address_add;
705   zclient->interface_address_delete = isis_zebra_if_address_del;
706   zclient->interface_link_params = isis_zebra_link_params;
707   zclient->ipv4_route_add = isis_zebra_read_ipv4;
708   zclient->ipv4_route_delete = isis_zebra_read_ipv4;
709 #ifdef HAVE_IPV6
710   zclient->ipv6_route_add = isis_zebra_read_ipv6;
711   zclient->ipv6_route_delete = isis_zebra_read_ipv6;
712 #endif /* HAVE_IPV6 */
713
714   return;
715 }