]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_zebra.c
debian: add pkg-config to build-depends
[mirror_frr.git] / isisd / isis_zebra.c
CommitLineData
eb5d44eb 1/*
ac4d0be5 2 * IS-IS Rout(e)ing protocol - isis_zebra.c
eb5d44eb 3 *
4 * Copyright (C) 2001,2002 Sampo Saaristo
ac4d0be5 5 * Tampere University of Technology
eb5d44eb 6 * Institute of Communications Engineering
f3ccedaa 7 * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org>
eb5d44eb 8 *
ac4d0be5 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)
eb5d44eb 12 * any later version.
13 *
ac4d0be5 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
eb5d44eb 17 * more details.
18
ac4d0be5 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.,
eb5d44eb 21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24#include <zebra.h>
eb5d44eb 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"
f3ccedaa 36#include "nexthop.h"
7076bb2f 37#include "vrf.h"
eb5d44eb 38
c89c05dd 39#include "isisd/dict.h"
eb5d44eb 40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
3f045a08
JB
42#include "isisd/isis_flags.h"
43#include "isisd/isis_misc.h"
44#include "isisd/isis_circuit.h"
45#include "isisd/isis_tlv.h"
c89c05dd 46#include "isisd/isisd.h"
eb5d44eb 47#include "isisd/isis_circuit.h"
48#include "isisd/isis_csm.h"
3f045a08 49#include "isisd/isis_lsp.h"
eb5d44eb 50#include "isisd/isis_route.h"
51#include "isisd/isis_zebra.h"
f8c06e2c 52#include "isisd/isis_te.h"
eb5d44eb 53
54struct zclient *zclient = NULL;
55
18a6dce6 56/* Router-id update message from zebra. */
ac4d0be5 57static int isis_router_id_update_zebra(int command, struct zclient *zclient,
58 zebra_size_t length, vrf_id_t vrf_id)
18a6dce6 59{
ac4d0be5 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;
18a6dce6 81}
eb5d44eb 82
ac4d0be5 83static int isis_zebra_if_add(int command, struct zclient *zclient,
84 zebra_size_t length, vrf_id_t vrf_id)
eb5d44eb 85{
ac4d0be5 86 struct interface *ifp;
eb5d44eb 87
ac4d0be5 88 ifp = zebra_interface_add_read(zclient->ibuf, vrf_id);
f390d2c7 89
ac4d0be5 90 if (isis->debugs & DEBUG_ZEBRA)
91 zlog_debug(
92 "Zebra I/F add: %s index %d flags %ld metric %d mtu %d",
93 ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric,
94 ifp->mtu);
f390d2c7 95
ac4d0be5 96 if (if_is_operative(ifp))
97 isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp),
98 ifp);
f390d2c7 99
ac4d0be5 100 return 0;
eb5d44eb 101}
102
ac4d0be5 103static int isis_zebra_if_del(int command, struct zclient *zclient,
104 zebra_size_t length, vrf_id_t vrf_id)
eb5d44eb 105{
ac4d0be5 106 struct interface *ifp;
107 struct stream *s;
eb5d44eb 108
ac4d0be5 109 s = zclient->ibuf;
110 ifp = zebra_interface_state_read(s, vrf_id);
f390d2c7 111
ac4d0be5 112 if (!ifp)
113 return 0;
eb5d44eb 114
ac4d0be5 115 if (if_is_operative(ifp))
116 zlog_warn("Zebra: got delete of %s, but interface is still up",
117 ifp->name);
eb5d44eb 118
ac4d0be5 119 if (isis->debugs & DEBUG_ZEBRA)
120 zlog_debug(
121 "Zebra I/F delete: %s index %d flags %ld metric %d mtu %d",
122 ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric,
123 ifp->mtu);
eb5d44eb 124
ac4d0be5 125 isis_csm_state_change(IF_DOWN_FROM_Z, circuit_scan_by_ifp(ifp), ifp);
d2fc8896 126
ac4d0be5 127 /* Cannot call if_delete because we should retain the pseudo interface
128 in case there is configuration info attached to it. */
129 if_delete_retain(ifp);
f390d2c7 130
ac4d0be5 131 ifp->ifindex = IFINDEX_DELETED;
d2fc8896 132
ac4d0be5 133 return 0;
eb5d44eb 134}
135
ac4d0be5 136static int isis_zebra_if_state_up(int command, struct zclient *zclient,
137 zebra_size_t length, vrf_id_t vrf_id)
eb5d44eb 138{
ac4d0be5 139 struct interface *ifp;
f390d2c7 140
ac4d0be5 141 ifp = zebra_interface_state_read(zclient->ibuf, vrf_id);
f390d2c7 142
ac4d0be5 143 if (ifp == NULL)
144 return 0;
f390d2c7 145
ac4d0be5 146 isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp), ifp);
f390d2c7 147
ac4d0be5 148 return 0;
eb5d44eb 149}
150
ac4d0be5 151static int isis_zebra_if_state_down(int command, struct zclient *zclient,
152 zebra_size_t length, vrf_id_t vrf_id)
eb5d44eb 153{
ac4d0be5 154 struct interface *ifp;
155 struct isis_circuit *circuit;
f390d2c7 156
ac4d0be5 157 ifp = zebra_interface_state_read(zclient->ibuf, vrf_id);
f390d2c7 158
ac4d0be5 159 if (ifp == NULL)
160 return 0;
f390d2c7 161
ac4d0be5 162 circuit = isis_csm_state_change(IF_DOWN_FROM_Z,
163 circuit_scan_by_ifp(ifp), ifp);
164 if (circuit)
165 SET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF);
f390d2c7 166
ac4d0be5 167 return 0;
eb5d44eb 168}
169
ac4d0be5 170static int isis_zebra_if_address_add(int command, struct zclient *zclient,
171 zebra_size_t length, vrf_id_t vrf_id)
eb5d44eb 172{
ac4d0be5 173 struct connected *c;
174 struct prefix *p;
175 char buf[PREFIX2STR_BUFFER];
eb5d44eb 176
ac4d0be5 177 c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD,
178 zclient->ibuf, vrf_id);
f390d2c7 179
ac4d0be5 180 if (c == NULL)
181 return 0;
f390d2c7 182
ac4d0be5 183 p = c->address;
f390d2c7 184
ac4d0be5 185 prefix2str(p, buf, sizeof(buf));
eb5d44eb 186#ifdef EXTREME_DEBUG
ac4d0be5 187 if (p->family == AF_INET)
188 zlog_debug("connected IP address %s", buf);
189 if (p->family == AF_INET6)
190 zlog_debug("connected IPv6 address %s", buf);
eb5d44eb 191#endif /* EXTREME_DEBUG */
ac4d0be5 192 if (if_is_operative(c->ifp))
193 isis_circuit_add_addr(circuit_scan_by_ifp(c->ifp), c);
eb5d44eb 194
ac4d0be5 195 return 0;
eb5d44eb 196}
197
ac4d0be5 198static int isis_zebra_if_address_del(int command, struct zclient *client,
199 zebra_size_t length, vrf_id_t vrf_id)
eb5d44eb 200{
ac4d0be5 201 struct connected *c;
202 struct interface *ifp;
1cd80845 203#ifdef EXTREME_DEBUG
ac4d0be5 204 struct prefix *p;
205 char buf[PREFIX2STR_BUFFER];
1cd80845 206#endif /* EXTREME_DEBUG */
eb5d44eb 207
ac4d0be5 208 c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE,
209 zclient->ibuf, vrf_id);
f390d2c7 210
ac4d0be5 211 if (c == NULL)
212 return 0;
f390d2c7 213
ac4d0be5 214 ifp = c->ifp;
f390d2c7 215
f891f443 216#ifdef EXTREME_DEBUG
ac4d0be5 217 p = c->address;
218 prefix2str(p, buf, sizeof(buf));
f891f443 219
ac4d0be5 220 if (p->family == AF_INET)
221 zlog_debug("disconnected IP address %s", buf);
222 if (p->family == AF_INET6)
223 zlog_debug("disconnected IPv6 address %s", buf);
f891f443 224#endif /* EXTREME_DEBUG */
f390d2c7 225
ac4d0be5 226 if (if_is_operative(ifp))
227 isis_circuit_del_addr(circuit_scan_by_ifp(ifp), c);
228 connected_free(c);
f390d2c7 229
ac4d0be5 230 return 0;
eb5d44eb 231}
232
ac4d0be5 233static int isis_zebra_link_params(int command, struct zclient *zclient,
234 zebra_size_t length)
f8c06e2c 235{
ac4d0be5 236 struct interface *ifp;
f8c06e2c 237
ac4d0be5 238 ifp = zebra_interface_link_params_read(zclient->ibuf);
f8c06e2c 239
ac4d0be5 240 if (ifp == NULL)
241 return 0;
f8c06e2c 242
ac4d0be5 243 /* Update TE TLV */
244 isis_mpls_te_update(ifp);
f8c06e2c 245
ac4d0be5 246 return 0;
f8c06e2c
OD
247}
248
ac4d0be5 249static void isis_zebra_route_add_ipv4(struct prefix *prefix,
250 struct isis_route_info *route_info)
eb5d44eb 251{
ac4d0be5 252 u_char message;
253 u_int32_t flags;
254 int psize;
255 struct stream *stream;
256 struct isis_nexthop *nexthop;
257 struct listnode *node;
258
259 if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED))
260 return;
261
262 if (vrf_bitmap_check(zclient->redist[AFI_IP][ZEBRA_ROUTE_ISIS],
263 VRF_DEFAULT)) {
264 message = 0;
265 flags = 0;
266
267 SET_FLAG(message, ZAPI_MESSAGE_NEXTHOP);
268 SET_FLAG(message, ZAPI_MESSAGE_METRIC);
2097cd8a 269#if 0
f390d2c7 270 SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
2097cd8a 271#endif
f390d2c7 272
ac4d0be5 273 stream = zclient->obuf;
274 stream_reset(stream);
275 zclient_create_header(stream, ZEBRA_IPV4_ROUTE_ADD,
276 VRF_DEFAULT);
277 /* type */
278 stream_putc(stream, ZEBRA_ROUTE_ISIS);
279 /* instance */
280 stream_putw(stream, 0);
281 /* flags */
282 stream_putl(stream, flags);
283 /* message */
284 stream_putc(stream, message);
285 /* SAFI */
286 stream_putw(stream, SAFI_UNICAST);
287 /* prefix information */
288 psize = PSIZE(prefix->prefixlen);
289 stream_putc(stream, prefix->prefixlen);
290 stream_write(stream, (u_char *)&prefix->u.prefix4, psize);
291
292 stream_putc(stream, listcount(route_info->nexthops));
293
294 /* Nexthop, ifindex, distance and metric information */
295 for (ALL_LIST_ELEMENTS_RO(route_info->nexthops, node,
296 nexthop)) {
297 /* FIXME: can it be ? */
298 if (nexthop->ip.s_addr != INADDR_ANY) {
299 stream_putc(stream, NEXTHOP_TYPE_IPV4);
300 stream_put_in_addr(stream, &nexthop->ip);
301 } else {
302 stream_putc(stream, NEXTHOP_TYPE_IFINDEX);
303 stream_putl(stream, nexthop->ifindex);
304 }
305 }
2097cd8a 306#if 0
f390d2c7 307 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
308 stream_putc (stream, route_info->depth);
2097cd8a 309#endif
ac4d0be5 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 }
eb5d44eb 318}
319
ac4d0be5 320static void isis_zebra_route_del_ipv4(struct prefix *prefix,
321 struct isis_route_info *route_info)
eb5d44eb 322{
ac4d0be5 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;
eb5d44eb 343}
344
ac4d0be5 345static void isis_zebra_route_add_ipv6(struct prefix *prefix,
346 struct isis_route_info *route_info)
eb5d44eb 347{
ac4d0be5 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;
eb5d44eb 369#if 0
370 SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
371 api.distance = route_info->depth;
372#endif
ac4d0be5 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;
f390d2c7 383 }
384
ac4d0be5 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 }
f390d2c7 393
ac4d0be5 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 }
f390d2c7 408
ac4d0be5 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 }
f390d2c7 422
ac4d0be5 423 XFREE(MTYPE_ISIS_TMP, nexthop_list);
424 XFREE(MTYPE_ISIS_TMP, ifindex_list);
f390d2c7 425
ac4d0be5 426 return;
eb5d44eb 427}
428
ac4d0be5 429static void isis_zebra_route_del_ipv6(struct prefix *prefix,
430 struct isis_route_info *route_info)
eb5d44eb 431{
ac4d0be5 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;
f390d2c7 470 }
471
ac4d0be5 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);
eb5d44eb 502}
503
ac4d0be5 504void isis_zebra_route_update(struct prefix *prefix,
505 struct isis_route_info *route_info)
eb5d44eb 506{
ac4d0be5 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;
eb5d44eb 530}
531
ac4d0be5 532static int isis_zebra_read_ipv4(int command, struct zclient *zclient,
533 zebra_size_t length, vrf_id_t vrf_id)
eb5d44eb 534{
ac4d0be5 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;
eb5d44eb 581}
582
ac4d0be5 583static int isis_zebra_read_ipv6(int command, struct zclient *zclient,
584 zebra_size_t length, vrf_id_t vrf_id)
eb5d44eb 585{
ac4d0be5 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;
eb5d44eb 650}
eb5d44eb 651
ac4d0be5 652int isis_distribute_list_update(int routetype)
eb5d44eb 653{
ac4d0be5 654 return 0;
eb5d44eb 655}
656
ac4d0be5 657void isis_zebra_redistribute_set(afi_t afi, int type)
eb5d44eb 658{
ac4d0be5 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);
f3ccedaa
CF
665}
666
ac4d0be5 667void isis_zebra_redistribute_unset(afi_t afi, int type)
f3ccedaa 668{
ac4d0be5 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);
eb5d44eb 675}
676
ac4d0be5 677static void isis_zebra_connected(struct zclient *zclient)
7076bb2f 678{
ac4d0be5 679 zclient_send_reg_requests(zclient, VRF_DEFAULT);
7076bb2f
FL
680}
681
ac4d0be5 682void isis_zebra_init(struct thread_master *master)
eb5d44eb 683{
ac4d0be5 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;
eb5d44eb 701}