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