]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_zebra.c
all: removed all DEFUN command stomps
[mirror_frr.git] / ospf6d / ospf6_zebra.c
CommitLineData
718e3744 1/*
508e53e2 2 * Copyright (C) 2003 Yasuhiro Ohara
718e3744 3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
508e53e2 22#include <zebra.h>
23
24#include "log.h"
25#include "vty.h"
26#include "command.h"
27#include "prefix.h"
28#include "stream.h"
29#include "zclient.h"
30#include "memory.h"
2376c3f2 31#include "lib/bfd.h"
718e3744 32
508e53e2 33#include "ospf6_proto.h"
34#include "ospf6_top.h"
718e3744 35#include "ospf6_interface.h"
508e53e2 36#include "ospf6_route.h"
37#include "ospf6_lsa.h"
049207c3 38#include "ospf6_lsdb.h"
718e3744 39#include "ospf6_asbr.h"
508e53e2 40#include "ospf6_zebra.h"
049207c3 41#include "ospf6d.h"
718e3744 42
508e53e2 43unsigned char conf_debug_ospf6_zebra = 0;
718e3744 44
45/* information about zebra. */
46struct zclient *zclient = NULL;
47
18a6dce6 48struct in_addr router_id_zebra;
49
50/* Router-id update message from zebra. */
6ac29a51 51static int
18a6dce6 52ospf6_router_id_update_zebra (int command, struct zclient *zclient,
7076bb2f 53 zebra_size_t length, vrf_id_t vrf_id)
18a6dce6 54{
55 struct prefix router_id;
56 struct ospf6 *o = ospf6;
57
58 zebra_router_id_update_read(zclient->ibuf,&router_id);
59 router_id_zebra = router_id.u.prefix4;
60
c1ba9e8a 61 if (o == NULL)
62 return 0;
63
18a6dce6 64 if (o->router_id == 0)
65 o->router_id = (u_int32_t) router_id_zebra.s_addr;
66
67 return 0;
68}
69
718e3744 70/* redistribute function */
71void
72ospf6_zebra_redistribute (int type)
73{
7076bb2f 74 if (vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT))
718e3744 75 return;
7076bb2f
FL
76 vrf_bitmap_set (zclient->redist[AFI_IP6][type], VRF_DEFAULT);
77
718e3744 78 if (zclient->sock > 0)
7076bb2f
FL
79 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0,
80 VRF_DEFAULT);
718e3744 81}
82
83void
84ospf6_zebra_no_redistribute (int type)
85{
7076bb2f 86 if (!vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT))
718e3744 87 return;
7076bb2f 88 vrf_bitmap_unset (zclient->redist[AFI_IP6][type], VRF_DEFAULT);
718e3744 89 if (zclient->sock > 0)
7076bb2f
FL
90 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP6, type,
91 0, VRF_DEFAULT);
718e3744 92}
93
718e3744 94/* Inteface addition message from zebra. */
6ac29a51 95static int
7076bb2f
FL
96ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length,
97 vrf_id_t vrf_id)
718e3744 98{
99 struct interface *ifp;
100
7076bb2f 101 ifp = zebra_interface_add_read (zclient->ibuf, vrf_id);
508e53e2 102 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
c6487d61 103 zlog_debug ("Zebra Interface add: %s index %d mtu %d",
104 ifp->name, ifp->ifindex, ifp->mtu6);
718e3744 105 ospf6_interface_if_add (ifp);
718e3744 106 return 0;
107}
108
6ac29a51 109static int
7076bb2f
FL
110ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length,
111 vrf_id_t vrf_id)
718e3744 112{
508e53e2 113 struct interface *ifp;
718e3744 114
7076bb2f 115 if (!(ifp = zebra_interface_state_read (zclient->ibuf, vrf_id)))
d2fc8896 116 return 0;
117
118 if (if_is_up (ifp))
119 zlog_warn ("Zebra: got delete of %s, but interface is still up", ifp->name);
120
508e53e2 121 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
c6487d61 122 zlog_debug ("Zebra Interface delete: %s index %d mtu %d",
123 ifp->name, ifp->ifindex, ifp->mtu6);
718e3744 124
d2fc8896 125#if 0
d9628728
CF
126 /* XXX: ospf6_interface_if_del is not the right way to handle this,
127 * because among other thinkable issues, it will also clear all
128 * settings as they are contained in the struct ospf6_interface. */
718e3744 129 ospf6_interface_if_del (ifp);
508e53e2 130#endif /*0*/
d2fc8896 131
84361d61 132 ifp->ifindex = IFINDEX_DELETED;
718e3744 133 return 0;
134}
135
6ac29a51 136static int
718e3744 137ospf6_zebra_if_state_update (int command, struct zclient *zclient,
7076bb2f 138 zebra_size_t length, vrf_id_t vrf_id)
718e3744 139{
140 struct interface *ifp;
141
7076bb2f 142 ifp = zebra_interface_state_read (zclient->ibuf, vrf_id);
57c4f4f4
IF
143 if (ifp == NULL)
144 return 0;
145
508e53e2 146 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
c6487d61 147 zlog_debug ("Zebra Interface state change: "
c19543b2 148 "%s index %d flags %llx metric %d mtu %d bandwidth %d",
30d20590 149 ifp->name, ifp->ifindex, (unsigned long long)ifp->flags,
c19543b2 150 ifp->metric, ifp->mtu6, ifp->bandwidth);
718e3744 151
152 ospf6_interface_state_update (ifp);
153 return 0;
154}
155
6ac29a51 156static int
718e3744 157ospf6_zebra_if_address_update_add (int command, struct zclient *zclient,
7076bb2f 158 zebra_size_t length, vrf_id_t vrf_id)
718e3744 159{
160 struct connected *c;
161 char buf[128];
162
7076bb2f
FL
163 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf,
164 vrf_id);
718e3744 165 if (c == NULL)
166 return 0;
167
508e53e2 168 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
c6487d61 169 zlog_debug ("Zebra Interface address add: %s %5s %s/%d",
170 c->ifp->name, prefix_family_str (c->address),
171 inet_ntop (c->address->family, &c->address->u.prefix,
172 buf, sizeof (buf)), c->address->prefixlen);
718e3744 173
174 if (c->address->family == AF_INET6)
b13c1d92
CF
175 {
176 ospf6_interface_state_update (c->ifp);
177 ospf6_interface_connected_route_update (c->ifp);
178 }
718e3744 179 return 0;
180}
181
6ac29a51 182static int
718e3744 183ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient,
7076bb2f 184 zebra_size_t length, vrf_id_t vrf_id)
718e3744 185{
186 struct connected *c;
187 char buf[128];
188
7076bb2f
FL
189 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf,
190 vrf_id);
718e3744 191 if (c == NULL)
192 return 0;
193
508e53e2 194 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
c6487d61 195 zlog_debug ("Zebra Interface address delete: %s %5s %s/%d",
196 c->ifp->name, prefix_family_str (c->address),
197 inet_ntop (c->address->family, &c->address->u.prefix,
198 buf, sizeof (buf)), c->address->prefixlen);
718e3744 199
200 if (c->address->family == AF_INET6)
b13c1d92
CF
201 {
202 ospf6_interface_connected_route_update (c->ifp);
203 ospf6_interface_state_update (c->ifp);
204 }
718e3744 205
3f6d6a5d
DS
206 connected_free (c);
207
718e3744 208 return 0;
209}
210
6ac29a51 211static int
718e3744 212ospf6_zebra_read_ipv6 (int command, struct zclient *zclient,
7076bb2f 213 zebra_size_t length, vrf_id_t vrf_id)
718e3744 214{
215 struct stream *s;
216 struct zapi_ipv6 api;
217 unsigned long ifindex;
218 struct prefix_ipv6 p;
219 struct in6_addr *nexthop;
718e3744 220
87bb7354
DS
221 if (ospf6 == NULL)
222 return 0;
223
718e3744 224 s = zclient->ibuf;
225 ifindex = 0;
226 nexthop = NULL;
227 memset (&api, 0, sizeof (api));
228
229 /* Type, flags, message. */
230 api.type = stream_getc (s);
7c8ff89e 231 api.instance = stream_getw (s);
718e3744 232 api.flags = stream_getc (s);
233 api.message = stream_getc (s);
234
235 /* IPv6 prefix. */
236 memset (&p, 0, sizeof (struct prefix_ipv6));
237 p.family = AF_INET6;
238 p.prefixlen = stream_getc (s);
239 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
240
241 /* Nexthop, ifindex, distance, metric. */
242 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
243 {
244 api.nexthop_num = stream_getc (s);
245 nexthop = (struct in6_addr *)
246 malloc (api.nexthop_num * sizeof (struct in6_addr));
247 stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr));
248 }
249 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
250 {
251 api.ifindex_num = stream_getc (s);
252 ifindex = stream_getl (s);
253 }
254 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
255 api.distance = stream_getc (s);
256 else
257 api.distance = 0;
258 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
259 api.metric = stream_getl (s);
260 else
261 api.metric = 0;
262
508e53e2 263 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
718e3744 264 {
4690c7d7 265 char prefixstr[PREFIX2STR_BUFFER], nexthopstr[128];
718e3744 266 prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr));
508e53e2 267 if (nexthop)
268 inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr));
718e3744 269 else
508e53e2 270 snprintf (nexthopstr, sizeof (nexthopstr), "::");
271
c6487d61 272 zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld",
273 (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"),
f52d13cb 274 zebra_route_string(api.type), prefixstr, nexthopstr, ifindex);
718e3744 275 }
276
5048fe14 277 if (command == ZEBRA_REDISTRIBUTE_IPV6_ADD)
508e53e2 278 ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p,
279 api.nexthop_num, nexthop);
718e3744 280 else
508e53e2 281 ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p);
718e3744 282
283 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
284 free (nexthop);
285
286 return 0;
287}
288
508e53e2 289
290
6b0655a2 291
718e3744 292DEFUN (show_zebra,
293 show_zebra_cmd,
294 "show zebra",
295 SHOW_STR
296 "Zebra information\n")
297{
298 int i;
508e53e2 299 if (zclient == NULL)
300 {
049207c3 301 vty_out (vty, "Not connected to zebra%s", VNL);
508e53e2 302 return CMD_SUCCESS;
303 }
718e3744 304
049207c3 305 vty_out (vty, "Zebra Infomation%s", VNL);
508e53e2 306 vty_out (vty, " enable: %d fail: %d%s",
049207c3 307 zclient->enable, zclient->fail, VNL);
7076bb2f
FL
308 vty_out (vty, " redistribute default: %d%s",
309 vrf_bitmap_check (zclient->default_information, VRF_DEFAULT),
049207c3 310 VNL);
508e53e2 311 vty_out (vty, " redistribute:");
718e3744 312 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
508e53e2 313 {
7076bb2f 314 if (vrf_bitmap_check (zclient->redist[AFI_IP6][i], VRF_DEFAULT))
f52d13cb 315 vty_out (vty, " %s", zebra_route_string(i));
508e53e2 316 }
049207c3 317 vty_out (vty, "%s", VNL);
718e3744 318 return CMD_SUCCESS;
319}
320
718e3744 321/* Zebra configuration write function. */
6ac29a51 322static int
508e53e2 323config_write_ospf6_zebra (struct vty *vty)
718e3744 324{
325 if (! zclient->enable)
326 {
049207c3 327 vty_out (vty, "no router zebra%s", VNL);
328 vty_out (vty, "!%s", VNL);
718e3744 329 }
7076bb2f
FL
330 else if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6],
331 VRF_DEFAULT))
718e3744 332 {
049207c3 333 vty_out (vty, "router zebra%s", VNL);
334 vty_out (vty, " no redistribute ospf6%s", VNL);
335 vty_out (vty, "!%s", VNL);
718e3744 336 }
337 return 0;
338}
339
340/* Zebra node structure. */
7fc626de 341static struct cmd_node zebra_node =
718e3744 342{
343 ZEBRA_NODE,
344 "%s(config-zebra)# ",
345};
346
347#define ADD 0
508e53e2 348#define REM 1
718e3744 349static void
508e53e2 350ospf6_zebra_route_update (int type, struct ospf6_route *request)
718e3744 351{
718e3744 352 struct zapi_ipv6 api;
4690c7d7 353 char buf[PREFIX2STR_BUFFER];
508e53e2 354 int nhcount;
718e3744 355 struct in6_addr **nexthops;
b892f1dd 356 ifindex_t *ifindexes;
c3c0ac83 357 int ret = 0;
508e53e2 358 struct prefix_ipv6 *dest;
718e3744 359
508e53e2 360 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
718e3744 361 {
508e53e2 362 prefix2str (&request->prefix, buf, sizeof (buf));
c6487d61 363 zlog_debug ("Send %s route: %s",
364 (type == REM ? "remove" : "add"), buf);
718e3744 365 }
366
367 if (zclient->sock < 0)
368 {
508e53e2 369 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
c6487d61 370 zlog_debug (" Not connected to Zebra");
718e3744 371 return;
372 }
373
374 if (request->path.origin.adv_router == ospf6->router_id &&
375 (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
376 request->path.type == OSPF6_PATH_TYPE_EXTERNAL2))
377 {
508e53e2 378 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
c6487d61 379 zlog_debug (" Ignore self-originated external route");
718e3744 380 return;
381 }
382
508e53e2 383 /* If removing is the best path and if there's another path,
384 treat this request as add the secondary path */
385 if (type == REM && ospf6_route_is_best (request) &&
386 request->next && ospf6_route_is_same (request, request->next))
718e3744 387 {
508e53e2 388 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
c6487d61 389 zlog_debug (" Best-path removal resulted Sencondary addition");
508e53e2 390 type = ADD;
391 request = request->next;
718e3744 392 }
393
508e53e2 394 /* Only the best path will be sent to zebra. */
395 if (! ospf6_route_is_best (request))
718e3744 396 {
508e53e2 397 /* this is not preferred best route, ignore */
398 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
c6487d61 399 zlog_debug (" Ignore non-best route");
508e53e2 400 return;
718e3744 401 }
402
c3c0ac83 403 nhcount = ospf6_route_num_nexthops (request);
508e53e2 404 if (nhcount == 0)
718e3744 405 {
508e53e2 406 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
c6487d61 407 zlog_debug (" No nexthop, ignore");
718e3744 408 return;
409 }
410
411 /* allocate memory for nexthop_list */
412 nexthops = XCALLOC (MTYPE_OSPF6_OTHER,
508e53e2 413 nhcount * sizeof (struct in6_addr *));
414 if (nexthops == NULL)
718e3744 415 {
508e53e2 416 zlog_warn ("Can't send route to zebra: malloc failed");
718e3744 417 return;
418 }
419
420 /* allocate memory for ifindex_list */
421 ifindexes = XCALLOC (MTYPE_OSPF6_OTHER,
b892f1dd 422 nhcount * sizeof (ifindex_t));
508e53e2 423 if (ifindexes == NULL)
718e3744 424 {
508e53e2 425 zlog_warn ("Can't send route to zebra: malloc failed");
718e3744 426 XFREE (MTYPE_OSPF6_OTHER, nexthops);
427 return;
428 }
429
c3c0ac83 430 ospf6_route_zebra_copy_nexthops (request, ifindexes, nexthops, nhcount);
718e3744 431
7076bb2f 432 api.vrf_id = VRF_DEFAULT;
718e3744 433 api.type = ZEBRA_ROUTE_OSPF6;
7c8ff89e 434 api.instance = 0;
718e3744 435 api.flags = 0;
436 api.message = 0;
b4e45f67 437 api.safi = SAFI_UNICAST;
718e3744 438 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
508e53e2 439 api.nexthop_num = nhcount;
718e3744 440 api.nexthop = nexthops;
508e53e2 441 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
442 api.ifindex_num = nhcount;
718e3744 443 api.ifindex = ifindexes;
508e53e2 444 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
445 api.metric = (request->path.metric_type == 2 ?
c3c0ac83 446 request->path.u.cost_e2 : request->path.cost);
718e3744 447
508e53e2 448 dest = (struct prefix_ipv6 *) &request->prefix;
449 if (type == REM)
450 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
718e3744 451 else
508e53e2 452 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
718e3744 453
454 if (ret < 0)
508e53e2 455 zlog_err ("zapi_ipv6_route() %s failed: %s",
6099b3b5 456 (type == REM ? "delete" : "add"), safe_strerror (errno));
718e3744 457
718e3744 458 XFREE (MTYPE_OSPF6_OTHER, nexthops);
459 XFREE (MTYPE_OSPF6_OTHER, ifindexes);
460
461 return;
462}
463
464void
508e53e2 465ospf6_zebra_route_update_add (struct ospf6_route *request)
718e3744 466{
7076bb2f
FL
467 if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6],
468 VRF_DEFAULT))
718e3744 469 {
508e53e2 470 ospf6->route_table->hook_add = NULL;
471 ospf6->route_table->hook_remove = NULL;
472 return;
718e3744 473 }
508e53e2 474 ospf6_zebra_route_update (ADD, request);
718e3744 475}
476
508e53e2 477void
478ospf6_zebra_route_update_remove (struct ospf6_route *request)
718e3744 479{
7076bb2f
FL
480 if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6],
481 VRF_DEFAULT))
718e3744 482 {
508e53e2 483 ospf6->route_table->hook_add = NULL;
484 ospf6->route_table->hook_remove = NULL;
485 return;
718e3744 486 }
508e53e2 487 ospf6_zebra_route_update (REM, request);
718e3744 488}
489
c3c0ac83
DS
490void
491ospf6_zebra_add_discard (struct ospf6_route *request)
492{
493 struct zapi_ipv6 api;
494 char buf[INET6_ADDRSTRLEN];
495 struct prefix_ipv6 *dest;
496
7076bb2f
FL
497 if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6],
498 VRF_DEFAULT))
c3c0ac83
DS
499 {
500 if (!CHECK_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED))
501 {
1a1f4efa 502 api.vrf_id = VRF_DEFAULT;
c3c0ac83
DS
503 api.type = ZEBRA_ROUTE_OSPF6;
504 api.flags = ZEBRA_FLAG_BLACKHOLE;
7c8ff89e 505 api.instance = 0;
c3c0ac83
DS
506 api.message = 0;
507 api.safi = SAFI_UNICAST;
508 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
509 api.nexthop_num = 0;
510 api.ifindex_num = 0;
511
512 dest = (struct prefix_ipv6 *) &request->prefix;
513
514 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
515
516 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
517 zlog_debug ("Zebra: Route add discard %s/%d",
518 inet_ntop (AF_INET6, &dest->prefix,
519 buf, INET6_ADDRSTRLEN),
520 dest->prefixlen);
521 SET_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
522 }
523 else
524 {
525 dest = (struct prefix_ipv6 *) &request->prefix;
526
527 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
528 zlog_debug ("Zebra: Blackhole route present already %s/%d",
529 inet_ntop (AF_INET6, &dest->prefix,
530 buf, INET6_ADDRSTRLEN),
531 dest->prefixlen);
532 }
533 }
534}
535
536void
537ospf6_zebra_delete_discard (struct ospf6_route *request)
538{
539 struct zapi_ipv6 api;
540 char buf[INET6_ADDRSTRLEN];
541 struct prefix_ipv6 *dest;
542
7076bb2f 543 if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
c3c0ac83
DS
544 {
545 if (CHECK_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED))
546 {
1a1f4efa 547 api.vrf_id = VRF_DEFAULT;
c3c0ac83
DS
548 api.type = ZEBRA_ROUTE_OSPF6;
549 api.flags = ZEBRA_FLAG_BLACKHOLE;
7c8ff89e 550 api.instance = 0;
c3c0ac83
DS
551 api.message = 0;
552 api.safi = SAFI_UNICAST;
553 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
554 api.nexthop_num = 0;
555 api.ifindex_num = 0;
556
557 dest = (struct prefix_ipv6 *) &request->prefix;
558
559 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
560
561 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
562 zlog_debug ("Zebra: Route delete discard %s/%d",
563 inet_ntop (AF_INET6, &dest->prefix, buf,
564 INET6_ADDRSTRLEN), dest->prefixlen);
565 UNSET_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
566 }
567 else
568 {
569 dest = (struct prefix_ipv6 *) &request->prefix;
570 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
571 zlog_debug ("Zebra: Blackhole route already deleted %s/%d",
572 inet_ntop (AF_INET6, &dest->prefix, buf,
573 INET6_ADDRSTRLEN), dest->prefixlen);
574 }
575 }
576}
577
718e3744 578DEFUN (redistribute_ospf6,
579 redistribute_ospf6_cmd,
580 "redistribute ospf6",
581 "Redistribute control\n"
582 "OSPF6 route\n")
583{
508e53e2 584 struct ospf6_route *route;
585
7076bb2f 586 if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
508e53e2 587 return CMD_SUCCESS;
718e3744 588
7076bb2f 589 vrf_bitmap_set (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT);
718e3744 590
508e53e2 591 if (ospf6 == NULL)
592 return CMD_SUCCESS;
593
594 /* send ospf6 route to zebra route table */
595 for (route = ospf6_route_head (ospf6->route_table); route;
596 route = ospf6_route_next (route))
597 ospf6_zebra_route_update_add (route);
598
599 ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
600 ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
718e3744 601
602 return CMD_SUCCESS;
603}
604
605DEFUN (no_redistribute_ospf6,
606 no_redistribute_ospf6_cmd,
607 "no redistribute ospf6",
608 NO_STR
609 "Redistribute control\n"
610 "OSPF6 route\n")
611{
508e53e2 612 struct ospf6_route *route;
613
7076bb2f 614 if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
508e53e2 615 return CMD_SUCCESS;
718e3744 616
7076bb2f 617 vrf_bitmap_unset (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT);
718e3744 618
508e53e2 619 if (ospf6 == NULL)
718e3744 620 return CMD_SUCCESS;
621
508e53e2 622 ospf6->route_table->hook_add = NULL;
623 ospf6->route_table->hook_remove = NULL;
718e3744 624
508e53e2 625 /* withdraw ospf6 route from zebra route table */
626 for (route = ospf6_route_head (ospf6->route_table); route;
627 route = ospf6_route_next (route))
628 ospf6_zebra_route_update_remove (route);
718e3744 629
630 return CMD_SUCCESS;
631}
632
7076bb2f
FL
633static void
634ospf6_zebra_connected (struct zclient *zclient)
635{
2376c3f2 636 /* Send the client registration */
637 bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER);
638
0e5223e7 639 zclient_send_reg_requests (zclient, VRF_DEFAULT);
7076bb2f
FL
640}
641
718e3744 642void
4140ca4d 643ospf6_zebra_init (struct thread_master *master)
718e3744 644{
645 /* Allocate zebra structure. */
4140ca4d 646 zclient = zclient_new(master);
7c8ff89e 647 zclient_init (zclient, ZEBRA_ROUTE_OSPF6, 0);
7076bb2f 648 zclient->zebra_connected = ospf6_zebra_connected;
18a6dce6 649 zclient->router_id_update = ospf6_router_id_update_zebra;
718e3744 650 zclient->interface_add = ospf6_zebra_if_add;
651 zclient->interface_delete = ospf6_zebra_if_del;
652 zclient->interface_up = ospf6_zebra_if_state_update;
653 zclient->interface_down = ospf6_zebra_if_state_update;
654 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
655 zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
656 zclient->ipv4_route_add = NULL;
657 zclient->ipv4_route_delete = NULL;
5048fe14 658 zclient->redistribute_route_ipv4_add = NULL;
659 zclient->redistribute_route_ipv4_del = NULL;
718e3744 660 zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
661 zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
5048fe14 662 zclient->redistribute_route_ipv6_add = ospf6_zebra_read_ipv6;
663 zclient->redistribute_route_ipv6_del = ospf6_zebra_read_ipv6;
718e3744 664
665 /* redistribute connected route by default */
666 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
667
668 /* Install zebra node. */
508e53e2 669 install_node (&zebra_node, config_write_ospf6_zebra);
718e3744 670
671 /* Install command element for zebra node. */
672 install_element (VIEW_NODE, &show_zebra_cmd);
673 install_element (ENABLE_NODE, &show_zebra_cmd);
718e3744 674 install_default (ZEBRA_NODE);
675 install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
676 install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
677
718e3744 678 return;
679}
680
508e53e2 681/* Debug */
6b0655a2 682
508e53e2 683DEFUN (debug_ospf6_zebra_sendrecv,
684 debug_ospf6_zebra_sendrecv_cmd,
1d68dbfe 685 "debug ospf6 zebra [<send|recv>]",
508e53e2 686 DEBUG_STR
687 OSPF6_STR
688 "Debug connection between zebra\n"
689 "Debug Sending zebra\n"
690 "Debug Receiving zebra\n"
691 )
692{
51c26414 693 int idx_send_recv = 3;
508e53e2 694 unsigned char level = 0;
695
1d68dbfe 696 if (argc == 4)
508e53e2 697 {
1d68dbfe 698 if (strmatch(argv[idx_send_recv]->text, "send"))
508e53e2 699 level = OSPF6_DEBUG_ZEBRA_SEND;
1d68dbfe 700 else if (strmatch(argv[idx_send_recv]->text, "recv"))
508e53e2 701 level = OSPF6_DEBUG_ZEBRA_RECV;
702 }
703 else
704 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
705
706 OSPF6_DEBUG_ZEBRA_ON (level);
707 return CMD_SUCCESS;
708}
709
508e53e2 710DEFUN (no_debug_ospf6_zebra_sendrecv,
711 no_debug_ospf6_zebra_sendrecv_cmd,
1d68dbfe 712 "no debug ospf6 zebra [<send|recv>]",
508e53e2 713 NO_STR
714 DEBUG_STR
715 OSPF6_STR
716 "Debug connection between zebra\n"
717 "Debug Sending zebra\n"
718 "Debug Receiving zebra\n"
719 )
720{
51c26414 721 int idx_send_recv = 4;
508e53e2 722 unsigned char level = 0;
723
1d68dbfe 724 if (argc == 5)
508e53e2 725 {
1d68dbfe 726 if (strmatch(argv[idx_send_recv]->text, "send"))
508e53e2 727 level = OSPF6_DEBUG_ZEBRA_SEND;
1d68dbfe 728 else if (strmatch(argv[idx_send_recv]->text, "recv"))
508e53e2 729 level = OSPF6_DEBUG_ZEBRA_RECV;
730 }
731 else
732 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
733
734 OSPF6_DEBUG_ZEBRA_OFF (level);
735 return CMD_SUCCESS;
736}
737
508e53e2 738
739int
740config_write_ospf6_debug_zebra (struct vty *vty)
741{
742 if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
049207c3 743 vty_out (vty, "debug ospf6 zebra%s", VNL);
508e53e2 744 else
745 {
746 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
049207c3 747 vty_out (vty, "debug ospf6 zebra send%s", VNL);
508e53e2 748 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
049207c3 749 vty_out (vty, "debug ospf6 zebra recv%s", VNL);
508e53e2 750 }
751 return 0;
752}
753
718e3744 754void
6ac29a51 755install_element_ospf6_debug_zebra (void)
718e3744 756{
508e53e2 757 install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
758 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
508e53e2 759 install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
760 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
718e3744 761}
762
508e53e2 763