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