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