]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_zebra.c
Merge pull request #5653 from slankdev/slankdev-bgpd-support-prefix-sid-srv6-l3vpn
[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 *
896014f4
DL
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 19 */
20
508e53e2 21#include <zebra.h>
22
23#include "log.h"
24#include "vty.h"
25#include "command.h"
26#include "prefix.h"
27#include "stream.h"
28#include "zclient.h"
29#include "memory.h"
2376c3f2 30#include "lib/bfd.h"
4ba03be5 31#include "lib_errors.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
d62a17ae 43DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_DISTANCE, "OSPF6 distance")
baff583e 44
508e53e2 45unsigned char conf_debug_ospf6_zebra = 0;
718e3744 46
47/* information about zebra. */
48struct zclient *zclient = NULL;
49
18a6dce6 50/* Router-id update message from zebra. */
121f9dee 51static int ospf6_router_id_update_zebra(ZAPI_CALLBACK_ARGS)
18a6dce6 52{
d62a17ae 53 struct prefix router_id;
54 struct ospf6 *o = ospf6;
18a6dce6 55
d62a17ae 56 zebra_router_id_update_read(zclient->ibuf, &router_id);
18a6dce6 57
78c6ba61
CS
58 om6->zebra_router_id = router_id.u.prefix4.s_addr;
59
d62a17ae 60 if (o == NULL)
61 return 0;
c1ba9e8a 62
d6927cf3 63 o->router_id_zebra = router_id.u.prefix4;
78c6ba61
CS
64 if (IS_OSPF6_DEBUG_ZEBRA(RECV)) {
65 char buf[INET_ADDRSTRLEN];
66
67 zlog_debug("%s: zebra router-id %s update",
68 __PRETTY_FUNCTION__,
69 inet_ntop(AF_INET, &router_id.u.prefix4,
70 buf, INET_ADDRSTRLEN));
71 }
d6927cf3 72
78c6ba61 73 ospf6_router_id_update();
18a6dce6 74
d62a17ae 75 return 0;
18a6dce6 76}
77
718e3744 78/* redistribute function */
d62a17ae 79void ospf6_zebra_redistribute(int type)
718e3744 80{
d62a17ae 81 if (vrf_bitmap_check(zclient->redist[AFI_IP6][type], VRF_DEFAULT))
82 return;
83 vrf_bitmap_set(zclient->redist[AFI_IP6][type], VRF_DEFAULT);
7076bb2f 84
d62a17ae 85 if (zclient->sock > 0)
86 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient,
87 AFI_IP6, type, 0, VRF_DEFAULT);
718e3744 88}
89
d62a17ae 90void ospf6_zebra_no_redistribute(int type)
718e3744 91{
d62a17ae 92 if (!vrf_bitmap_check(zclient->redist[AFI_IP6][type], VRF_DEFAULT))
93 return;
94 vrf_bitmap_unset(zclient->redist[AFI_IP6][type], VRF_DEFAULT);
95 if (zclient->sock > 0)
96 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient,
97 AFI_IP6, type, 0, VRF_DEFAULT);
718e3744 98}
99
121f9dee 100static int ospf6_zebra_if_address_update_add(ZAPI_CALLBACK_ARGS)
718e3744 101{
d62a17ae 102 struct connected *c;
103 char buf[128];
104
105 c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD,
106 zclient->ibuf, vrf_id);
107 if (c == NULL)
108 return 0;
109
110 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
111 zlog_debug("Zebra Interface address add: %s %5s %s/%d",
112 c->ifp->name, prefix_family_str(c->address),
113 inet_ntop(c->address->family, &c->address->u.prefix,
114 buf, sizeof(buf)),
115 c->address->prefixlen);
116
117 if (c->address->family == AF_INET6) {
118 ospf6_interface_state_update(c->ifp);
119 ospf6_interface_connected_route_update(c->ifp);
120 }
121 return 0;
718e3744 122}
123
121f9dee 124static int ospf6_zebra_if_address_update_delete(ZAPI_CALLBACK_ARGS)
718e3744 125{
d62a17ae 126 struct connected *c;
127 char buf[128];
128
129 c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE,
130 zclient->ibuf, vrf_id);
131 if (c == NULL)
132 return 0;
133
134 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
135 zlog_debug("Zebra Interface address delete: %s %5s %s/%d",
136 c->ifp->name, prefix_family_str(c->address),
137 inet_ntop(c->address->family, &c->address->u.prefix,
138 buf, sizeof(buf)),
139 c->address->prefixlen);
140
141 if (c->address->family == AF_INET6) {
142 ospf6_interface_connected_route_update(c->ifp);
143 ospf6_interface_state_update(c->ifp);
144 }
718e3744 145
721c0857 146 connected_free(&c);
718e3744 147
d62a17ae 148 return 0;
149}
718e3744 150
121f9dee 151static int ospf6_zebra_read_route(ZAPI_CALLBACK_ARGS)
d62a17ae 152{
74489921 153 struct zapi_route api;
d62a17ae 154 unsigned long ifindex;
d62a17ae 155 struct in6_addr *nexthop;
156
157 if (ospf6 == NULL)
158 return 0;
159
74489921
RW
160 if (zapi_route_decode(zclient->ibuf, &api) < 0)
161 return -1;
d62a17ae 162
74489921
RW
163 /* we completely ignore srcdest routes for now. */
164 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX))
d62a17ae 165 return 0;
166
9fb2b879
DS
167 if (IN6_IS_ADDR_LINKLOCAL(&api.prefix.u.prefix6))
168 return 0;
169
74489921
RW
170 ifindex = api.nexthops[0].ifindex;
171 nexthop = &api.nexthops[0].gate.ipv6;
d62a17ae 172
173 if (IS_OSPF6_DEBUG_ZEBRA(RECV)) {
174 char prefixstr[PREFIX2STR_BUFFER], nexthopstr[128];
74489921
RW
175 prefix2str((struct prefix *)&api.prefix, prefixstr,
176 sizeof(prefixstr));
0af35d90 177 inet_ntop(AF_INET6, nexthop, nexthopstr, sizeof(nexthopstr));
d62a17ae 178
179 zlog_debug(
180 "Zebra Receive route %s: %s %s nexthop %s ifindex %ld tag %" ROUTE_TAG_PRI,
121f9dee
QY
181 (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD ? "add"
182 : "delete"),
d62a17ae 183 zebra_route_string(api.type), prefixstr, nexthopstr,
184 ifindex, api.tag);
185 }
718e3744 186
121f9dee 187 if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD)
74489921 188 ospf6_asbr_redistribute_add(api.type, ifindex, &api.prefix,
d62a17ae 189 api.nexthop_num, nexthop, api.tag);
190 else
74489921 191 ospf6_asbr_redistribute_remove(api.type, ifindex, &api.prefix);
718e3744 192
d62a17ae 193 return 0;
718e3744 194}
195
718e3744 196DEFUN (show_zebra,
eefe02da
DS
197 show_ospf6_zebra_cmd,
198 "show ipv6 ospf6 zebra",
718e3744 199 SHOW_STR
eefe02da
DS
200 IPV6_STR
201 OSPF6_STR
41e7fb80 202 ZEBRA_STR)
718e3744 203{
d62a17ae 204 int i;
205 if (zclient == NULL) {
206 vty_out(vty, "Not connected to zebra\n");
207 return CMD_SUCCESS;
208 }
209
f79f7a7b 210 vty_out(vty, "Zebra Information\n");
34b054ba 211 vty_out(vty, " fail: %d\n", zclient->fail);
d62a17ae 212 vty_out(vty, " redistribute default: %d\n",
49db7a7b
RW
213 vrf_bitmap_check(zclient->default_information[AFI_IP6],
214 VRF_DEFAULT));
d62a17ae 215 vty_out(vty, " redistribute:");
216 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
217 if (vrf_bitmap_check(zclient->redist[AFI_IP6][i], VRF_DEFAULT))
218 vty_out(vty, " %s", zebra_route_string(i));
219 }
220 vty_out(vty, "\n");
221 return CMD_SUCCESS;
718e3744 222}
223
718e3744 224#define ADD 0
508e53e2 225#define REM 1
d62a17ae 226static void ospf6_zebra_route_update(int type, struct ospf6_route *request)
718e3744 227{
5afa1c6b 228 struct zapi_route api;
d62a17ae 229 char buf[PREFIX2STR_BUFFER];
230 int nhcount;
d62a17ae 231 int ret = 0;
5afa1c6b 232 struct prefix *dest;
d62a17ae 233
234 if (IS_OSPF6_DEBUG_ZEBRA(SEND)) {
235 prefix2str(&request->prefix, buf, sizeof(buf));
236 zlog_debug("Send %s route: %s",
237 (type == REM ? "remove" : "add"), buf);
238 }
239
240 if (zclient->sock < 0) {
241 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
242 zlog_debug(" Not connected to Zebra");
243 return;
244 }
245
246 if (request->path.origin.adv_router == ospf6->router_id
247 && (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1
248 || request->path.type == OSPF6_PATH_TYPE_EXTERNAL2)) {
249 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
250 zlog_debug(" Ignore self-originated external route");
251 return;
252 }
253
254 /* If removing is the best path and if there's another path,
255 treat this request as add the secondary path */
256 if (type == REM && ospf6_route_is_best(request) && request->next
257 && ospf6_route_is_same(request, request->next)) {
258 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
259 zlog_debug(
260 " Best-path removal resulted Sencondary addition");
261 type = ADD;
262 request = request->next;
263 }
264
265 /* Only the best path will be sent to zebra. */
266 if (!ospf6_route_is_best(request)) {
267 /* this is not preferred best route, ignore */
268 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
269 zlog_debug(" Ignore non-best route");
270 return;
271 }
272
273 nhcount = ospf6_route_num_nexthops(request);
274 if (nhcount == 0) {
275 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
276 zlog_debug(" No nexthop, ignore");
277 return;
278 }
279
5afa1c6b 280 dest = &request->prefix;
d62a17ae 281
5afa1c6b 282 memset(&api, 0, sizeof(api));
d62a17ae 283 api.vrf_id = VRF_DEFAULT;
284 api.type = ZEBRA_ROUTE_OSPF6;
d62a17ae 285 api.safi = SAFI_UNICAST;
5afa1c6b 286 api.prefix = *dest;
d62a17ae 287 SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
a74e593b
RW
288 api.nexthop_num = MIN(nhcount, MULTIPATH_NUM);
289 ospf6_route_zebra_copy_nexthops(request, api.nexthops, api.nexthop_num);
d62a17ae 290 SET_FLAG(api.message, ZAPI_MESSAGE_METRIC);
291 api.metric = (request->path.metric_type == 2 ? request->path.u.cost_e2
292 : request->path.cost);
293 if (request->path.tag) {
294 SET_FLAG(api.message, ZAPI_MESSAGE_TAG);
295 api.tag = request->path.tag;
296 }
297
d62a17ae 298 SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
5afa1c6b
RW
299 api.distance =
300 ospf6_distance_apply((struct prefix_ipv6 *)dest, request);
d62a17ae 301
302 if (type == REM)
5afa1c6b 303 ret = zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
d62a17ae 304 else
5afa1c6b 305 ret = zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
d62a17ae 306
307 if (ret < 0)
450971aa 308 flog_err(EC_LIB_ZAPI_SOCKET,
1c50c1c0
QY
309 "zclient_route_send() %s failed: %s",
310 (type == REM ? "delete" : "add"),
311 safe_strerror(errno));
d62a17ae 312
d62a17ae 313 return;
718e3744 314}
315
d62a17ae 316void ospf6_zebra_route_update_add(struct ospf6_route *request)
718e3744 317{
d62a17ae 318 ospf6_zebra_route_update(ADD, request);
718e3744 319}
320
d62a17ae 321void ospf6_zebra_route_update_remove(struct ospf6_route *request)
718e3744 322{
d62a17ae 323 ospf6_zebra_route_update(REM, request);
718e3744 324}
325
d62a17ae 326void ospf6_zebra_add_discard(struct ospf6_route *request)
c3c0ac83 327{
5afa1c6b 328 struct zapi_route api;
d62a17ae 329 char buf[INET6_ADDRSTRLEN];
5afa1c6b 330 struct prefix *dest = &request->prefix;
d62a17ae 331
d00061ea 332 if (!CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) {
5afa1c6b 333 memset(&api, 0, sizeof(api));
d00061ea
RW
334 api.vrf_id = VRF_DEFAULT;
335 api.type = ZEBRA_ROUTE_OSPF6;
d00061ea 336 api.safi = SAFI_UNICAST;
5afa1c6b 337 api.prefix = *dest;
09a484dd 338 zapi_route_set_blackhole(&api, BLACKHOLE_NULL);
d00061ea 339
5afa1c6b 340 zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
d00061ea
RW
341
342 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
343 zlog_debug("Zebra: Route add discard %s/%d",
5afa1c6b 344 inet_ntop(AF_INET6, &dest->u.prefix6, buf,
d00061ea
RW
345 INET6_ADDRSTRLEN),
346 dest->prefixlen);
347
348 SET_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
349 } else {
d00061ea
RW
350 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
351 zlog_debug(
352 "Zebra: Blackhole route present already %s/%d",
5afa1c6b 353 inet_ntop(AF_INET6, &dest->u.prefix6, buf,
d00061ea
RW
354 INET6_ADDRSTRLEN),
355 dest->prefixlen);
c3c0ac83 356 }
c3c0ac83
DS
357}
358
d62a17ae 359void ospf6_zebra_delete_discard(struct ospf6_route *request)
c3c0ac83 360{
5afa1c6b 361 struct zapi_route api;
d62a17ae 362 char buf[INET6_ADDRSTRLEN];
5afa1c6b 363 struct prefix *dest = &request->prefix;
d62a17ae 364
d00061ea 365 if (CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) {
5afa1c6b 366 memset(&api, 0, sizeof(api));
d00061ea
RW
367 api.vrf_id = VRF_DEFAULT;
368 api.type = ZEBRA_ROUTE_OSPF6;
d00061ea 369 api.safi = SAFI_UNICAST;
5afa1c6b 370 api.prefix = *dest;
09a484dd 371 zapi_route_set_blackhole(&api, BLACKHOLE_NULL);
d00061ea 372
5afa1c6b 373 zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
d00061ea
RW
374
375 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
376 zlog_debug("Zebra: Route delete discard %s/%d",
5afa1c6b 377 inet_ntop(AF_INET6, &dest->u.prefix6, buf,
d00061ea
RW
378 INET6_ADDRSTRLEN),
379 dest->prefixlen);
380
381 UNSET_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
382 } else {
d00061ea
RW
383 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
384 zlog_debug(
385 "Zebra: Blackhole route already deleted %s/%d",
5afa1c6b 386 inet_ntop(AF_INET6, &dest->u.prefix6, buf,
d00061ea
RW
387 INET6_ADDRSTRLEN),
388 dest->prefixlen);
c3c0ac83 389 }
c3c0ac83
DS
390}
391
d62a17ae 392static struct ospf6_distance *ospf6_distance_new(void)
baff583e 393{
d62a17ae 394 return XCALLOC(MTYPE_OSPF6_DISTANCE, sizeof(struct ospf6_distance));
baff583e
MZ
395}
396
d62a17ae 397static void ospf6_distance_free(struct ospf6_distance *odistance)
baff583e 398{
d62a17ae 399 XFREE(MTYPE_OSPF6_DISTANCE, odistance);
baff583e
MZ
400}
401
d62a17ae 402int ospf6_distance_set(struct vty *vty, struct ospf6 *o,
403 const char *distance_str, const char *ip_str,
404 const char *access_list_str)
baff583e 405{
d62a17ae 406 int ret;
407 struct prefix_ipv6 p;
d7c0a89a 408 uint8_t distance;
d62a17ae 409 struct route_node *rn;
410 struct ospf6_distance *odistance;
411
412 ret = str2prefix_ipv6(ip_str, &p);
413 if (ret == 0) {
414 vty_out(vty, "Malformed prefix\n");
415 return CMD_WARNING_CONFIG_FAILED;
416 }
417
418 distance = atoi(distance_str);
419
420 /* Get OSPF6 distance node. */
421 rn = route_node_get(o->distance_table, (struct prefix *)&p);
422 if (rn->info) {
423 odistance = rn->info;
424 route_unlock_node(rn);
425 } else {
426 odistance = ospf6_distance_new();
427 rn->info = odistance;
428 }
429
430 /* Set distance value. */
431 odistance->distance = distance;
432
433 /* Reset access-list configuration. */
434 if (odistance->access_list) {
435 free(odistance->access_list);
436 odistance->access_list = NULL;
437 }
438 if (access_list_str)
439 odistance->access_list = strdup(access_list_str);
440
441 return CMD_SUCCESS;
baff583e
MZ
442}
443
d62a17ae 444int ospf6_distance_unset(struct vty *vty, struct ospf6 *o,
445 const char *distance_str, const char *ip_str,
446 const char *access_list_str)
baff583e 447{
d62a17ae 448 int ret;
449 struct prefix_ipv6 p;
450 struct route_node *rn;
451 struct ospf6_distance *odistance;
452
453 ret = str2prefix_ipv6(ip_str, &p);
454 if (ret == 0) {
455 vty_out(vty, "Malformed prefix\n");
456 return CMD_WARNING_CONFIG_FAILED;
457 }
458
459 rn = route_node_lookup(o->distance_table, (struct prefix *)&p);
460 if (!rn) {
461 vty_out(vty, "Cant't find specified prefix\n");
462 return CMD_WARNING_CONFIG_FAILED;
463 }
464
465 odistance = rn->info;
466
467 if (odistance->access_list)
468 free(odistance->access_list);
469 ospf6_distance_free(odistance);
470
471 rn->info = NULL;
472 route_unlock_node(rn);
473 route_unlock_node(rn);
474
475 return CMD_SUCCESS;
baff583e
MZ
476}
477
d62a17ae 478void ospf6_distance_reset(struct ospf6 *o)
baff583e 479{
d62a17ae 480 struct route_node *rn;
481 struct ospf6_distance *odistance;
482
483 for (rn = route_top(o->distance_table); rn; rn = route_next(rn))
484 if ((odistance = rn->info) != NULL) {
485 if (odistance->access_list)
486 free(odistance->access_list);
487 ospf6_distance_free(odistance);
488 rn->info = NULL;
489 route_unlock_node(rn);
490 }
baff583e
MZ
491}
492
d7c0a89a 493uint8_t ospf6_distance_apply(struct prefix_ipv6 *p, struct ospf6_route * or)
baff583e 494{
d62a17ae 495 struct ospf6 *o;
baff583e 496
d62a17ae 497 o = ospf6;
498 if (o == NULL)
499 return 0;
baff583e 500
d62a17ae 501 if (o->distance_intra)
502 if (or->path.type == OSPF6_PATH_TYPE_INTRA)
503 return o->distance_intra;
baff583e 504
d62a17ae 505 if (o->distance_inter)
506 if (or->path.type == OSPF6_PATH_TYPE_INTER)
507 return o->distance_inter;
baff583e 508
d62a17ae 509 if (o->distance_external)
510 if (or->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
511 or->path.type == OSPF6_PATH_TYPE_EXTERNAL2)
512 return o->distance_external;
baff583e 513
d62a17ae 514 if (o->distance_all)
515 return o->distance_all;
baff583e 516
d62a17ae 517 return 0;
baff583e
MZ
518}
519
d62a17ae 520static void ospf6_zebra_connected(struct zclient *zclient)
7076bb2f 521{
d62a17ae 522 /* Send the client registration */
0945d5ed 523 bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER, VRF_DEFAULT);
2376c3f2 524
d62a17ae 525 zclient_send_reg_requests(zclient, VRF_DEFAULT);
7076bb2f
FL
526}
527
d62a17ae 528void ospf6_zebra_init(struct thread_master *master)
718e3744 529{
d62a17ae 530 /* Allocate zebra structure. */
26f63a1e 531 zclient = zclient_new(master, &zclient_options_default);
342213ea 532 zclient_init(zclient, ZEBRA_ROUTE_OSPF6, 0, &ospf6d_privs);
d62a17ae 533 zclient->zebra_connected = ospf6_zebra_connected;
534 zclient->router_id_update = ospf6_router_id_update_zebra;
d62a17ae 535 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
536 zclient->interface_address_delete =
537 ospf6_zebra_if_address_update_delete;
74489921
RW
538 zclient->redistribute_route_add = ospf6_zebra_read_route;
539 zclient->redistribute_route_del = ospf6_zebra_read_route;
d62a17ae 540
d62a17ae 541 /* Install command element for zebra node. */
542 install_element(VIEW_NODE, &show_ospf6_zebra_cmd);
718e3744 543}
544
508e53e2 545/* Debug */
6b0655a2 546
508e53e2 547DEFUN (debug_ospf6_zebra_sendrecv,
548 debug_ospf6_zebra_sendrecv_cmd,
1d68dbfe 549 "debug ospf6 zebra [<send|recv>]",
508e53e2 550 DEBUG_STR
551 OSPF6_STR
552 "Debug connection between zebra\n"
553 "Debug Sending zebra\n"
554 "Debug Receiving zebra\n"
555 )
556{
d62a17ae 557 int idx_send_recv = 3;
558 unsigned char level = 0;
559
560 if (argc == 4) {
561 if (strmatch(argv[idx_send_recv]->text, "send"))
562 level = OSPF6_DEBUG_ZEBRA_SEND;
563 else if (strmatch(argv[idx_send_recv]->text, "recv"))
564 level = OSPF6_DEBUG_ZEBRA_RECV;
565 } else
566 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
567
568 OSPF6_DEBUG_ZEBRA_ON(level);
569 return CMD_SUCCESS;
508e53e2 570}
571
508e53e2 572DEFUN (no_debug_ospf6_zebra_sendrecv,
573 no_debug_ospf6_zebra_sendrecv_cmd,
1d68dbfe 574 "no debug ospf6 zebra [<send|recv>]",
508e53e2 575 NO_STR
576 DEBUG_STR
577 OSPF6_STR
578 "Debug connection between zebra\n"
579 "Debug Sending zebra\n"
580 "Debug Receiving zebra\n"
581 )
582{
d62a17ae 583 int idx_send_recv = 4;
584 unsigned char level = 0;
585
586 if (argc == 5) {
587 if (strmatch(argv[idx_send_recv]->text, "send"))
588 level = OSPF6_DEBUG_ZEBRA_SEND;
589 else if (strmatch(argv[idx_send_recv]->text, "recv"))
590 level = OSPF6_DEBUG_ZEBRA_RECV;
591 } else
592 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
593
594 OSPF6_DEBUG_ZEBRA_OFF(level);
595 return CMD_SUCCESS;
508e53e2 596}
597
508e53e2 598
d62a17ae 599int config_write_ospf6_debug_zebra(struct vty *vty)
508e53e2 600{
d62a17ae 601 if (IS_OSPF6_DEBUG_ZEBRA(SEND) && IS_OSPF6_DEBUG_ZEBRA(RECV))
602 vty_out(vty, "debug ospf6 zebra\n");
603 else {
604 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
605 vty_out(vty, "debug ospf6 zebra send\n");
606 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
607 vty_out(vty, "debug ospf6 zebra recv\n");
608 }
609 return 0;
508e53e2 610}
611
d62a17ae 612void install_element_ospf6_debug_zebra(void)
718e3744 613{
d62a17ae 614 install_element(ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
615 install_element(ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
616 install_element(CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
617 install_element(CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
718e3744 618}