]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_zebra.c
Merge branch 'cmaster' of ssh://stash.cumulusnetworks.com:7999/quag/quagga into cmaster
[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 {
508e53e2 259 char prefixstr[128], 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;
d2fc8896 371 char buf[64];
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 {
520 api.type = ZEBRA_ROUTE_OSPF6;
521 api.flags = ZEBRA_FLAG_BLACKHOLE;
7c8ff89e 522 api.instance = 0;
c3c0ac83
DS
523 api.message = 0;
524 api.safi = SAFI_UNICAST;
525 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
526 api.nexthop_num = 0;
527 api.ifindex_num = 0;
528
529 dest = (struct prefix_ipv6 *) &request->prefix;
530
531 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
532
533 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
534 zlog_debug ("Zebra: Route add discard %s/%d",
535 inet_ntop (AF_INET6, &dest->prefix,
536 buf, INET6_ADDRSTRLEN),
537 dest->prefixlen);
538 SET_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
539 }
540 else
541 {
542 dest = (struct prefix_ipv6 *) &request->prefix;
543
544 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
545 zlog_debug ("Zebra: Blackhole route present already %s/%d",
546 inet_ntop (AF_INET6, &dest->prefix,
547 buf, INET6_ADDRSTRLEN),
548 dest->prefixlen);
549 }
550 }
551}
552
553void
554ospf6_zebra_delete_discard (struct ospf6_route *request)
555{
556 struct zapi_ipv6 api;
557 char buf[INET6_ADDRSTRLEN];
558 struct prefix_ipv6 *dest;
559
7076bb2f 560 if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
c3c0ac83
DS
561 {
562 if (CHECK_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED))
563 {
564
565 api.type = ZEBRA_ROUTE_OSPF6;
566 api.flags = ZEBRA_FLAG_BLACKHOLE;
7c8ff89e 567 api.instance = 0;
c3c0ac83
DS
568 api.message = 0;
569 api.safi = SAFI_UNICAST;
570 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
571 api.nexthop_num = 0;
572 api.ifindex_num = 0;
573
574 dest = (struct prefix_ipv6 *) &request->prefix;
575
576 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
577
578 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
579 zlog_debug ("Zebra: Route delete discard %s/%d",
580 inet_ntop (AF_INET6, &dest->prefix, buf,
581 INET6_ADDRSTRLEN), dest->prefixlen);
582 UNSET_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
583 }
584 else
585 {
586 dest = (struct prefix_ipv6 *) &request->prefix;
587 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
588 zlog_debug ("Zebra: Blackhole route already deleted %s/%d",
589 inet_ntop (AF_INET6, &dest->prefix, buf,
590 INET6_ADDRSTRLEN), dest->prefixlen);
591 }
592 }
593}
594
718e3744 595DEFUN (redistribute_ospf6,
596 redistribute_ospf6_cmd,
597 "redistribute ospf6",
598 "Redistribute control\n"
599 "OSPF6 route\n")
600{
508e53e2 601 struct ospf6_route *route;
602
7076bb2f 603 if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
508e53e2 604 return CMD_SUCCESS;
718e3744 605
7076bb2f 606 vrf_bitmap_set (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT);
718e3744 607
508e53e2 608 if (ospf6 == NULL)
609 return CMD_SUCCESS;
610
611 /* send ospf6 route to zebra route table */
612 for (route = ospf6_route_head (ospf6->route_table); route;
613 route = ospf6_route_next (route))
614 ospf6_zebra_route_update_add (route);
615
616 ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
617 ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
718e3744 618
619 return CMD_SUCCESS;
620}
621
622DEFUN (no_redistribute_ospf6,
623 no_redistribute_ospf6_cmd,
624 "no redistribute ospf6",
625 NO_STR
626 "Redistribute control\n"
627 "OSPF6 route\n")
628{
508e53e2 629 struct ospf6_route *route;
630
7076bb2f 631 if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
508e53e2 632 return CMD_SUCCESS;
718e3744 633
7076bb2f 634 vrf_bitmap_unset (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT);
718e3744 635
508e53e2 636 if (ospf6 == NULL)
718e3744 637 return CMD_SUCCESS;
638
508e53e2 639 ospf6->route_table->hook_add = NULL;
640 ospf6->route_table->hook_remove = NULL;
718e3744 641
508e53e2 642 /* withdraw ospf6 route from zebra route table */
643 for (route = ospf6_route_head (ospf6->route_table); route;
644 route = ospf6_route_next (route))
645 ospf6_zebra_route_update_remove (route);
718e3744 646
647 return CMD_SUCCESS;
648}
649
7076bb2f
FL
650static void
651ospf6_zebra_connected (struct zclient *zclient)
652{
653 zclient_send_requests (zclient, VRF_DEFAULT);
654}
655
718e3744 656void
4140ca4d 657ospf6_zebra_init (struct thread_master *master)
718e3744 658{
659 /* Allocate zebra structure. */
4140ca4d 660 zclient = zclient_new(master);
7c8ff89e 661 zclient_init (zclient, ZEBRA_ROUTE_OSPF6, 0);
7076bb2f 662 zclient->zebra_connected = ospf6_zebra_connected;
18a6dce6 663 zclient->router_id_update = ospf6_router_id_update_zebra;
718e3744 664 zclient->interface_add = ospf6_zebra_if_add;
665 zclient->interface_delete = ospf6_zebra_if_del;
666 zclient->interface_up = ospf6_zebra_if_state_update;
667 zclient->interface_down = ospf6_zebra_if_state_update;
668 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
669 zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
670 zclient->ipv4_route_add = NULL;
671 zclient->ipv4_route_delete = NULL;
5048fe14 672 zclient->redistribute_route_ipv4_add = NULL;
673 zclient->redistribute_route_ipv4_del = NULL;
718e3744 674 zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
675 zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
5048fe14 676 zclient->redistribute_route_ipv6_add = ospf6_zebra_read_ipv6;
677 zclient->redistribute_route_ipv6_del = ospf6_zebra_read_ipv6;
718e3744 678
679 /* redistribute connected route by default */
680 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
681
682 /* Install zebra node. */
508e53e2 683 install_node (&zebra_node, config_write_ospf6_zebra);
718e3744 684
685 /* Install command element for zebra node. */
686 install_element (VIEW_NODE, &show_zebra_cmd);
687 install_element (ENABLE_NODE, &show_zebra_cmd);
688 install_element (CONFIG_NODE, &router_zebra_cmd);
689 install_element (CONFIG_NODE, &no_router_zebra_cmd);
508e53e2 690
718e3744 691 install_default (ZEBRA_NODE);
692 install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
693 install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
694
718e3744 695 return;
696}
697
508e53e2 698/* Debug */
6b0655a2 699
508e53e2 700DEFUN (debug_ospf6_zebra_sendrecv,
701 debug_ospf6_zebra_sendrecv_cmd,
702 "debug ospf6 zebra (send|recv)",
703 DEBUG_STR
704 OSPF6_STR
705 "Debug connection between zebra\n"
706 "Debug Sending zebra\n"
707 "Debug Receiving zebra\n"
708 )
709{
710 unsigned char level = 0;
711
712 if (argc)
713 {
714 if (! strncmp (argv[0], "s", 1))
715 level = OSPF6_DEBUG_ZEBRA_SEND;
716 else if (! strncmp (argv[0], "r", 1))
717 level = OSPF6_DEBUG_ZEBRA_RECV;
718 }
719 else
720 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
721
722 OSPF6_DEBUG_ZEBRA_ON (level);
723 return CMD_SUCCESS;
724}
725
726ALIAS (debug_ospf6_zebra_sendrecv,
727 debug_ospf6_zebra_cmd,
728 "debug ospf6 zebra",
729 DEBUG_STR
730 OSPF6_STR
731 "Debug connection between zebra\n"
6ac29a51 732 )
508e53e2 733
734
735DEFUN (no_debug_ospf6_zebra_sendrecv,
736 no_debug_ospf6_zebra_sendrecv_cmd,
737 "no debug ospf6 zebra (send|recv)",
738 NO_STR
739 DEBUG_STR
740 OSPF6_STR
741 "Debug connection between zebra\n"
742 "Debug Sending zebra\n"
743 "Debug Receiving zebra\n"
744 )
745{
746 unsigned char level = 0;
747
748 if (argc)
749 {
750 if (! strncmp (argv[0], "s", 1))
751 level = OSPF6_DEBUG_ZEBRA_SEND;
752 else if (! strncmp (argv[0], "r", 1))
753 level = OSPF6_DEBUG_ZEBRA_RECV;
754 }
755 else
756 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
757
758 OSPF6_DEBUG_ZEBRA_OFF (level);
759 return CMD_SUCCESS;
760}
761
762ALIAS (no_debug_ospf6_zebra_sendrecv,
763 no_debug_ospf6_zebra_cmd,
764 "no debug ospf6 zebra",
765 NO_STR
766 DEBUG_STR
767 OSPF6_STR
768 "Debug connection between zebra\n"
6ac29a51 769 )
508e53e2 770
771int
772config_write_ospf6_debug_zebra (struct vty *vty)
773{
774 if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
049207c3 775 vty_out (vty, "debug ospf6 zebra%s", VNL);
508e53e2 776 else
777 {
778 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
049207c3 779 vty_out (vty, "debug ospf6 zebra send%s", VNL);
508e53e2 780 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
049207c3 781 vty_out (vty, "debug ospf6 zebra recv%s", VNL);
508e53e2 782 }
783 return 0;
784}
785
718e3744 786void
6ac29a51 787install_element_ospf6_debug_zebra (void)
718e3744 788{
508e53e2 789 install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd);
790 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd);
791 install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
792 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
793 install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd);
794 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd);
795 install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
796 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
718e3744 797}
798
508e53e2 799