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