]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_zebra.c
Merge pull request #12851 from sri-mohan1/sri-mohan-ldp
[mirror_frr.git] / ospf6d / ospf6_zebra.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2003 Yasuhiro Ohara
4 */
5
6 #include <zebra.h>
7
8 #include "log.h"
9 #include "vty.h"
10 #include "command.h"
11 #include "prefix.h"
12 #include "stream.h"
13 #include "zclient.h"
14 #include "memory.h"
15 #include "route_opaque.h"
16 #include "lib/bfd.h"
17 #include "lib_errors.h"
18
19 #include "ospf6_proto.h"
20 #include "ospf6_top.h"
21 #include "ospf6_interface.h"
22 #include "ospf6_route.h"
23 #include "ospf6_lsa.h"
24 #include "ospf6_lsdb.h"
25 #include "ospf6_asbr.h"
26 #include "ospf6_nssa.h"
27 #include "ospf6_zebra.h"
28 #include "ospf6d.h"
29 #include "ospf6_area.h"
30 #include "ospf6_gr.h"
31 #include "lib/json.h"
32
33 DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_DISTANCE, "OSPF6 distance");
34
35 unsigned char conf_debug_ospf6_zebra = 0;
36
37 /* information about zebra. */
38 struct zclient *zclient = NULL;
39
40 void ospf6_zebra_vrf_register(struct ospf6 *ospf6)
41 {
42 if (!zclient || zclient->sock < 0 || !ospf6)
43 return;
44
45 if (ospf6->vrf_id != VRF_UNKNOWN) {
46 if (IS_OSPF6_DEBUG_ZEBRA(RECV)) {
47 zlog_debug("%s: Register VRF %s id %u", __func__,
48 ospf6_vrf_id_to_name(ospf6->vrf_id),
49 ospf6->vrf_id);
50 }
51 zclient_send_reg_requests(zclient, ospf6->vrf_id);
52 }
53 }
54
55 void ospf6_zebra_vrf_deregister(struct ospf6 *ospf6)
56 {
57 if (!zclient || zclient->sock < 0 || !ospf6)
58 return;
59
60 if (ospf6->vrf_id != VRF_DEFAULT && ospf6->vrf_id != VRF_UNKNOWN) {
61 if (IS_OSPF6_DEBUG_ZEBRA(RECV)) {
62 zlog_debug("%s: De-Register VRF %s id %u to Zebra.",
63 __func__,
64 ospf6_vrf_id_to_name(ospf6->vrf_id),
65 ospf6->vrf_id);
66 }
67 /* Deregister for router-id, interfaces,
68 * redistributed routes. */
69 zclient_send_dereg_requests(zclient, ospf6->vrf_id);
70 }
71 }
72
73 /* Router-id update message from zebra. */
74 static int ospf6_router_id_update_zebra(ZAPI_CALLBACK_ARGS)
75 {
76 struct prefix router_id;
77 struct ospf6 *o;
78
79 zebra_router_id_update_read(zclient->ibuf, &router_id);
80
81 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
82 zlog_debug("Zebra router-id update %pI4 vrf %s id %u",
83 &router_id.u.prefix4, ospf6_vrf_id_to_name(vrf_id),
84 vrf_id);
85
86 o = ospf6_lookup_by_vrf_id(vrf_id);
87 if (o == NULL)
88 return 0;
89
90 o->router_id_zebra = router_id.u.prefix4.s_addr;
91
92 ospf6_router_id_update(o, false);
93
94 return 0;
95 }
96
97 /* redistribute function */
98 void ospf6_zebra_redistribute(int type, vrf_id_t vrf_id)
99 {
100 if (vrf_bitmap_check(zclient->redist[AFI_IP6][type], vrf_id))
101 return;
102 vrf_bitmap_set(zclient->redist[AFI_IP6][type], vrf_id);
103
104 if (zclient->sock > 0)
105 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient,
106 AFI_IP6, type, 0, vrf_id);
107 }
108
109 void ospf6_zebra_no_redistribute(int type, vrf_id_t vrf_id)
110 {
111 if (!vrf_bitmap_check(zclient->redist[AFI_IP6][type], vrf_id))
112 return;
113 vrf_bitmap_unset(zclient->redist[AFI_IP6][type], vrf_id);
114 if (zclient->sock > 0)
115 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient,
116 AFI_IP6, type, 0, vrf_id);
117 }
118
119 void ospf6_zebra_import_default_route(struct ospf6 *ospf6, bool unreg)
120 {
121 struct prefix prefix = {};
122 int command;
123
124 if (zclient->sock < 0) {
125 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
126 zlog_debug(" Not connected to Zebra");
127 return;
128 }
129
130 prefix.family = AF_INET6;
131 prefix.prefixlen = 0;
132
133 if (unreg)
134 command = ZEBRA_NEXTHOP_UNREGISTER;
135 else
136 command = ZEBRA_NEXTHOP_REGISTER;
137
138 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
139 zlog_debug("%s: sending cmd %s for %pFX (vrf %u)", __func__,
140 zserv_command_string(command), &prefix,
141 ospf6->vrf_id);
142
143 if (zclient_send_rnh(zclient, command, &prefix, SAFI_UNICAST, false,
144 true, ospf6->vrf_id)
145 == ZCLIENT_SEND_FAILURE)
146 flog_err(EC_LIB_ZAPI_SOCKET, "%s: zclient_send_rnh() failed",
147 __func__);
148 }
149
150 static int ospf6_zebra_import_check_update(ZAPI_CALLBACK_ARGS)
151 {
152 struct ospf6 *ospf6;
153 struct zapi_route nhr;
154 struct prefix matched;
155
156 ospf6 = ospf6_lookup_by_vrf_id(vrf_id);
157 if (ospf6 == NULL || !IS_OSPF6_ASBR(ospf6))
158 return 0;
159
160 if (!zapi_nexthop_update_decode(zclient->ibuf, &matched, &nhr)) {
161 zlog_err("%s[%u]: Failure to decode route", __func__,
162 ospf6->vrf_id);
163 return -1;
164 }
165
166 if (matched.family != AF_INET6 || matched.prefixlen != 0 ||
167 nhr.type == ZEBRA_ROUTE_OSPF6)
168 return 0;
169
170 ospf6->nssa_default_import_check.status = !!nhr.nexthop_num;
171 ospf6_abr_nssa_type_7_defaults(ospf6);
172
173 return 0;
174 }
175
176 static int ospf6_zebra_if_address_update_add(ZAPI_CALLBACK_ARGS)
177 {
178 struct connected *c;
179
180 c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD,
181 zclient->ibuf, vrf_id);
182 if (c == NULL)
183 return 0;
184
185 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
186 zlog_debug("Zebra Interface address add: %s %5s %pFX",
187 c->ifp->name, prefix_family_str(c->address),
188 c->address);
189
190 if (c->address->family == AF_INET6) {
191 ospf6_interface_state_update(c->ifp);
192 ospf6_interface_connected_route_update(c->ifp);
193 }
194 return 0;
195 }
196
197 static int ospf6_zebra_if_address_update_delete(ZAPI_CALLBACK_ARGS)
198 {
199 struct connected *c;
200
201 c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE,
202 zclient->ibuf, vrf_id);
203 if (c == NULL)
204 return 0;
205
206 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
207 zlog_debug("Zebra Interface address delete: %s %5s %pFX",
208 c->ifp->name, prefix_family_str(c->address),
209 c->address);
210
211 if (c->address->family == AF_INET6) {
212 ospf6_interface_connected_route_update(c->ifp);
213 ospf6_interface_state_update(c->ifp);
214 }
215
216 connected_free(&c);
217
218 return 0;
219 }
220
221 static int ospf6_zebra_gr_update(struct ospf6 *ospf6, int command,
222 uint32_t stale_time)
223 {
224 struct zapi_cap api;
225
226 if (!zclient || zclient->sock < 0 || !ospf6)
227 return 1;
228
229 memset(&api, 0, sizeof(api));
230 api.cap = command;
231 api.stale_removal_time = stale_time;
232 api.vrf_id = ospf6->vrf_id;
233
234 (void)zclient_capabilities_send(ZEBRA_CLIENT_CAPABILITIES, zclient,
235 &api);
236
237 return 0;
238 }
239
240 int ospf6_zebra_gr_enable(struct ospf6 *ospf6, uint32_t stale_time)
241 {
242 return ospf6_zebra_gr_update(ospf6, ZEBRA_CLIENT_GR_CAPABILITIES,
243 stale_time);
244 }
245
246 int ospf6_zebra_gr_disable(struct ospf6 *ospf6)
247 {
248 return ospf6_zebra_gr_update(ospf6, ZEBRA_CLIENT_GR_DISABLE, 0);
249 }
250
251 static int ospf6_zebra_read_route(ZAPI_CALLBACK_ARGS)
252 {
253 struct zapi_route api;
254 unsigned long ifindex;
255 struct in6_addr *nexthop;
256 struct ospf6 *ospf6;
257 struct prefix_ipv6 p;
258
259 ospf6 = ospf6_lookup_by_vrf_id(vrf_id);
260
261 if (ospf6 == NULL)
262 return 0;
263
264 if (zapi_route_decode(zclient->ibuf, &api) < 0)
265 return -1;
266
267 /* we completely ignore srcdest routes for now. */
268 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX))
269 return 0;
270
271 if (IN6_IS_ADDR_LINKLOCAL(&api.prefix.u.prefix6))
272 return 0;
273
274 ifindex = api.nexthops[0].ifindex;
275 nexthop = &api.nexthops[0].gate.ipv6;
276
277 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
278 zlog_debug(
279 "Zebra Receive route %s: %s %pFX nexthop %pI6 ifindex %ld tag %" ROUTE_TAG_PRI,
280 (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD ? "add"
281 : "delete"),
282 zebra_route_string(api.type), &api.prefix, nexthop,
283 ifindex, api.tag);
284
285 memcpy(&p, &api.prefix, sizeof(p));
286 if (is_default_prefix6(&p))
287 api.type = DEFAULT_ROUTE;
288
289 if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD)
290 ospf6_asbr_redistribute_add(api.type, ifindex, &api.prefix,
291 api.nexthop_num, nexthop, api.tag,
292 ospf6);
293 else
294 ospf6_asbr_redistribute_remove(api.type, ifindex, &api.prefix,
295 ospf6);
296
297 return 0;
298 }
299
300 DEFUN(show_zebra,
301 show_ospf6_zebra_cmd,
302 "show ipv6 ospf6 zebra [json]",
303 SHOW_STR
304 IPV6_STR
305 OSPF6_STR
306 ZEBRA_STR
307 JSON_STR)
308 {
309 int i;
310 bool uj = use_json(argc, argv);
311 json_object *json;
312 json_object *json_zebra;
313 json_object *json_array;
314
315 if (zclient == NULL) {
316 vty_out(vty, "Not connected to zebra\n");
317 return CMD_SUCCESS;
318 }
319
320 if (uj) {
321 json = json_object_new_object();
322 json_zebra = json_object_new_object();
323 json_array = json_object_new_array();
324
325 json_object_int_add(json_zebra, "fail", zclient->fail);
326 json_object_int_add(
327 json_zebra, "redistributeDefault",
328 vrf_bitmap_check(zclient->default_information[AFI_IP6],
329 VRF_DEFAULT));
330 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
331 if (vrf_bitmap_check(zclient->redist[AFI_IP6][i],
332 VRF_DEFAULT))
333 json_object_array_add(
334 json_array,
335 json_object_new_string(
336 zebra_route_string(i)));
337 }
338 json_object_object_add(json_zebra, "redistribute", json_array);
339 json_object_object_add(json, "zebraInformation", json_zebra);
340
341 vty_json(vty, json);
342 } else {
343 vty_out(vty, "Zebra Information\n");
344 vty_out(vty, " fail: %d\n", zclient->fail);
345 vty_out(vty, " redistribute default: %d\n",
346 vrf_bitmap_check(zclient->default_information[AFI_IP6],
347 VRF_DEFAULT));
348 vty_out(vty, " redistribute:");
349 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
350 if (vrf_bitmap_check(zclient->redist[AFI_IP6][i],
351 VRF_DEFAULT))
352 vty_out(vty, " %s", zebra_route_string(i));
353 }
354 vty_out(vty, "\n");
355 }
356 return CMD_SUCCESS;
357 }
358
359 static void ospf6_zebra_append_opaque_attr(struct ospf6_route *request,
360 struct zapi_route *api)
361 {
362 struct ospf_zebra_opaque ospf_opaque = {};
363
364 /* OSPF path type */
365 snprintf(ospf_opaque.path_type, sizeof(ospf_opaque.path_type), "%s",
366 OSPF6_PATH_TYPE_NAME(request->path.type));
367
368 switch (request->path.type) {
369 case OSPF6_PATH_TYPE_INTRA:
370 case OSPF6_PATH_TYPE_INTER:
371 /* OSPF area ID */
372 (void)inet_ntop(AF_INET, &request->path.area_id,
373 ospf_opaque.area_id,
374 sizeof(ospf_opaque.area_id));
375 break;
376 case OSPF6_PATH_TYPE_EXTERNAL1:
377 case OSPF6_PATH_TYPE_EXTERNAL2:
378 /* OSPF route tag */
379 snprintf(ospf_opaque.tag, sizeof(ospf_opaque.tag), "%u",
380 request->path.tag);
381 break;
382 default:
383 break;
384 }
385
386 SET_FLAG(api->message, ZAPI_MESSAGE_OPAQUE);
387 api->opaque.length = sizeof(struct ospf_zebra_opaque);
388 memcpy(api->opaque.data, &ospf_opaque, api->opaque.length);
389 }
390
391 #define ADD 0
392 #define REM 1
393 static void ospf6_zebra_route_update(int type, struct ospf6_route *request,
394 struct ospf6 *ospf6)
395 {
396 struct zapi_route api;
397 int nhcount;
398 int ret = 0;
399 struct prefix *dest;
400
401 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
402 zlog_debug("Zebra Send %s route: %pFX",
403 (type == REM ? "remove" : "add"), &request->prefix);
404
405 if (zclient->sock < 0) {
406 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
407 zlog_debug(" Not connected to Zebra");
408 return;
409 }
410
411 if (request->path.origin.adv_router == ospf6->router_id
412 && (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1
413 || request->path.type == OSPF6_PATH_TYPE_EXTERNAL2)) {
414 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
415 zlog_debug(" Ignore self-originated external route");
416 return;
417 }
418
419 /* If removing is the best path and if there's another path,
420 * treat this request as add the secondary path - if there are
421 * nexthops.
422 */
423 if (type == REM && ospf6_route_is_best(request) && request->next &&
424 ospf6_route_is_same(request, request->next) &&
425 ospf6_route_num_nexthops(request->next) > 0) {
426 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
427 zlog_debug(
428 " Best-path removal resulted Secondary addition");
429 type = ADD;
430 request = request->next;
431 }
432
433 /* Only the best path will be sent to zebra. */
434 if (!ospf6_route_is_best(request)) {
435 /* this is not preferred best route, ignore */
436 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
437 zlog_debug(" Ignore non-best route");
438 return;
439 }
440
441 nhcount = ospf6_route_num_nexthops(request);
442 if (nhcount == 0) {
443 if (type == ADD) {
444 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
445 zlog_debug(" No nexthop, ignore");
446 return;
447 } else if (IS_OSPF6_DEBUG_ZEBRA(SEND))
448 zlog_debug(" No nexthop, rem ok");
449 }
450
451 dest = &request->prefix;
452
453 memset(&api, 0, sizeof(api));
454 api.vrf_id = ospf6->vrf_id;
455 api.type = ZEBRA_ROUTE_OSPF6;
456 api.safi = SAFI_UNICAST;
457 api.prefix = *dest;
458
459 if (nhcount > ospf6->max_multipath) {
460 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
461 zlog_debug(
462 " Nexthop count is greater than configured maximum-path, hence ignore the extra nexthops");
463 }
464
465 api.nexthop_num = MIN(nhcount, ospf6->max_multipath);
466 if (api.nexthop_num > 0) {
467 SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
468 ospf6_route_zebra_copy_nexthops(request, api.nexthops,
469 api.nexthop_num, api.vrf_id);
470 }
471
472 SET_FLAG(api.message, ZAPI_MESSAGE_METRIC);
473 api.metric = (request->path.metric_type == 2 ? request->path.u.cost_e2
474 : request->path.cost);
475 if (request->path.tag) {
476 SET_FLAG(api.message, ZAPI_MESSAGE_TAG);
477 api.tag = request->path.tag;
478 }
479
480 SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
481 api.distance = ospf6_distance_apply((struct prefix_ipv6 *)dest, request,
482 ospf6);
483
484 if (type == ADD
485 && CHECK_FLAG(ospf6->config_flags, OSPF6_SEND_EXTRA_DATA_TO_ZEBRA))
486 ospf6_zebra_append_opaque_attr(request, &api);
487
488 if (type == REM)
489 ret = zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
490 else
491 ret = zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
492
493 if (ret == ZCLIENT_SEND_FAILURE)
494 flog_err(EC_LIB_ZAPI_SOCKET,
495 "zclient_route_send() %s failed: %s",
496 (type == REM ? "delete" : "add"),
497 safe_strerror(errno));
498
499 return;
500 }
501
502 void ospf6_zebra_route_update_add(struct ospf6_route *request,
503 struct ospf6 *ospf6)
504 {
505 if (ospf6->gr_info.restart_in_progress
506 || ospf6->gr_info.prepare_in_progress) {
507 if (IS_DEBUG_OSPF6_GR)
508 zlog_debug(
509 "Zebra: Graceful Restart in progress -- not installing %pFX",
510 &request->prefix);
511 return;
512 }
513
514 ospf6_zebra_route_update(ADD, request, ospf6);
515 }
516
517 void ospf6_zebra_route_update_remove(struct ospf6_route *request,
518 struct ospf6 *ospf6)
519 {
520 if (ospf6->gr_info.restart_in_progress
521 || ospf6->gr_info.prepare_in_progress) {
522 if (IS_DEBUG_OSPF6_GR)
523 zlog_debug(
524 "Zebra: Graceful Restart in progress -- not uninstalling %pFX",
525 &request->prefix);
526 return;
527 }
528
529 ospf6_zebra_route_update(REM, request, ospf6);
530 }
531
532 void ospf6_zebra_add_discard(struct ospf6_route *request, struct ospf6 *ospf6)
533 {
534 struct zapi_route api;
535 struct prefix *dest = &request->prefix;
536
537 if (ospf6->gr_info.restart_in_progress
538 || ospf6->gr_info.prepare_in_progress) {
539 if (IS_DEBUG_OSPF6_GR)
540 zlog_debug(
541 "Zebra: Graceful Restart in progress -- not installing %pFX",
542 &request->prefix);
543 return;
544 }
545
546 if (!CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) {
547 memset(&api, 0, sizeof(api));
548 api.vrf_id = ospf6->vrf_id;
549 api.type = ZEBRA_ROUTE_OSPF6;
550 api.safi = SAFI_UNICAST;
551 api.prefix = *dest;
552 zapi_route_set_blackhole(&api, BLACKHOLE_NULL);
553
554 zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
555
556 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
557 zlog_debug("Zebra: Route add discard %pFX", dest);
558
559 SET_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
560 } else {
561 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
562 zlog_debug(
563 "Zebra: Blackhole route present already %pFX",
564 dest);
565 }
566 }
567
568 void ospf6_zebra_delete_discard(struct ospf6_route *request,
569 struct ospf6 *ospf6)
570 {
571 struct zapi_route api;
572 struct prefix *dest = &request->prefix;
573
574 if (ospf6->gr_info.restart_in_progress
575 || ospf6->gr_info.prepare_in_progress) {
576 if (IS_DEBUG_OSPF6_GR)
577 zlog_debug(
578 "Zebra: Graceful Restart in progress -- not uninstalling %pFX",
579 &request->prefix);
580 return;
581 }
582
583 if (CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) {
584 memset(&api, 0, sizeof(api));
585 api.vrf_id = ospf6->vrf_id;
586 api.type = ZEBRA_ROUTE_OSPF6;
587 api.safi = SAFI_UNICAST;
588 api.prefix = *dest;
589 zapi_route_set_blackhole(&api, BLACKHOLE_NULL);
590
591 zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
592
593 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
594 zlog_debug("Zebra: Route delete discard %pFX", dest);
595
596 UNSET_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
597 } else {
598 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
599 zlog_debug(
600 "Zebra: Blackhole route already deleted %pFX",
601 dest);
602 }
603 }
604
605 static struct ospf6_distance *ospf6_distance_new(void)
606 {
607 return XCALLOC(MTYPE_OSPF6_DISTANCE, sizeof(struct ospf6_distance));
608 }
609
610 static void ospf6_distance_free(struct ospf6_distance *odistance)
611 {
612 XFREE(MTYPE_OSPF6_DISTANCE, odistance);
613 }
614
615 int ospf6_distance_set(struct vty *vty, struct ospf6 *o,
616 const char *distance_str, const char *ip_str,
617 const char *access_list_str)
618 {
619 int ret;
620 struct prefix_ipv6 p;
621 uint8_t distance;
622 struct route_node *rn;
623 struct ospf6_distance *odistance;
624
625 ret = str2prefix_ipv6(ip_str, &p);
626 if (ret == 0) {
627 vty_out(vty, "Malformed prefix\n");
628 return CMD_WARNING_CONFIG_FAILED;
629 }
630
631 distance = atoi(distance_str);
632
633 /* Get OSPF6 distance node. */
634 rn = route_node_get(o->distance_table, (struct prefix *)&p);
635 if (rn->info) {
636 odistance = rn->info;
637 route_unlock_node(rn);
638 } else {
639 odistance = ospf6_distance_new();
640 rn->info = odistance;
641 }
642
643 /* Set distance value. */
644 odistance->distance = distance;
645
646 /* Reset access-list configuration. */
647 if (odistance->access_list) {
648 free(odistance->access_list);
649 odistance->access_list = NULL;
650 }
651 if (access_list_str)
652 odistance->access_list = strdup(access_list_str);
653
654 return CMD_SUCCESS;
655 }
656
657 int ospf6_distance_unset(struct vty *vty, struct ospf6 *o,
658 const char *distance_str, const char *ip_str,
659 const char *access_list_str)
660 {
661 int ret;
662 struct prefix_ipv6 p;
663 struct route_node *rn;
664 struct ospf6_distance *odistance;
665
666 ret = str2prefix_ipv6(ip_str, &p);
667 if (ret == 0) {
668 vty_out(vty, "Malformed prefix\n");
669 return CMD_WARNING_CONFIG_FAILED;
670 }
671
672 rn = route_node_lookup(o->distance_table, (struct prefix *)&p);
673 if (!rn) {
674 vty_out(vty, "Cant't find specified prefix\n");
675 return CMD_WARNING_CONFIG_FAILED;
676 }
677
678 odistance = rn->info;
679
680 if (odistance->access_list)
681 free(odistance->access_list);
682 ospf6_distance_free(odistance);
683
684 rn->info = NULL;
685 route_unlock_node(rn);
686 route_unlock_node(rn);
687
688 return CMD_SUCCESS;
689 }
690
691 void ospf6_distance_reset(struct ospf6 *o)
692 {
693 struct route_node *rn;
694 struct ospf6_distance *odistance;
695
696 for (rn = route_top(o->distance_table); rn; rn = route_next(rn))
697 if ((odistance = rn->info) != NULL) {
698 if (odistance->access_list)
699 free(odistance->access_list);
700 ospf6_distance_free(odistance);
701 rn->info = NULL;
702 route_unlock_node(rn);
703 }
704 }
705
706 uint8_t ospf6_distance_apply(struct prefix_ipv6 *p, struct ospf6_route * or,
707 struct ospf6 *ospf6)
708 {
709 struct ospf6 *o;
710
711 o = ospf6;
712 if (o == NULL)
713 return 0;
714
715 if (o->distance_intra)
716 if (or->path.type == OSPF6_PATH_TYPE_INTRA)
717 return o->distance_intra;
718
719 if (o->distance_inter)
720 if (or->path.type == OSPF6_PATH_TYPE_INTER)
721 return o->distance_inter;
722
723 if (o->distance_external)
724 if (or->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
725 or->path.type == OSPF6_PATH_TYPE_EXTERNAL2)
726 return o->distance_external;
727
728 if (o->distance_all)
729 return o->distance_all;
730
731 return 0;
732 }
733
734 static void ospf6_zebra_connected(struct zclient *zclient)
735 {
736 /* Send the client registration */
737 bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER, VRF_DEFAULT);
738
739 zclient_send_reg_requests(zclient, VRF_DEFAULT);
740 }
741
742 static zclient_handler *const ospf6_handlers[] = {
743 [ZEBRA_ROUTER_ID_UPDATE] = ospf6_router_id_update_zebra,
744 [ZEBRA_INTERFACE_ADDRESS_ADD] = ospf6_zebra_if_address_update_add,
745 [ZEBRA_INTERFACE_ADDRESS_DELETE] = ospf6_zebra_if_address_update_delete,
746 [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = ospf6_zebra_read_route,
747 [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = ospf6_zebra_read_route,
748 [ZEBRA_NEXTHOP_UPDATE] = ospf6_zebra_import_check_update,
749 };
750
751 void ospf6_zebra_init(struct thread_master *master)
752 {
753 /* Allocate zebra structure. */
754 zclient = zclient_new(master, &zclient_options_default, ospf6_handlers,
755 array_size(ospf6_handlers));
756 zclient_init(zclient, ZEBRA_ROUTE_OSPF6, 0, &ospf6d_privs);
757 zclient->zebra_connected = ospf6_zebra_connected;
758
759 /* Install command element for zebra node. */
760 install_element(VIEW_NODE, &show_ospf6_zebra_cmd);
761 }
762
763 /* Debug */
764
765 DEFUN (debug_ospf6_zebra_sendrecv,
766 debug_ospf6_zebra_sendrecv_cmd,
767 "debug ospf6 zebra [<send|recv>]",
768 DEBUG_STR
769 OSPF6_STR
770 "Debug connection between zebra\n"
771 "Debug Sending zebra\n"
772 "Debug Receiving zebra\n"
773 )
774 {
775 int idx_send_recv = 3;
776 unsigned char level = 0;
777
778 if (argc == 4) {
779 if (strmatch(argv[idx_send_recv]->text, "send"))
780 level = OSPF6_DEBUG_ZEBRA_SEND;
781 else if (strmatch(argv[idx_send_recv]->text, "recv"))
782 level = OSPF6_DEBUG_ZEBRA_RECV;
783 } else
784 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
785
786 OSPF6_DEBUG_ZEBRA_ON(level);
787 return CMD_SUCCESS;
788 }
789
790 DEFUN (no_debug_ospf6_zebra_sendrecv,
791 no_debug_ospf6_zebra_sendrecv_cmd,
792 "no debug ospf6 zebra [<send|recv>]",
793 NO_STR
794 DEBUG_STR
795 OSPF6_STR
796 "Debug connection between zebra\n"
797 "Debug Sending zebra\n"
798 "Debug Receiving zebra\n"
799 )
800 {
801 int idx_send_recv = 4;
802 unsigned char level = 0;
803
804 if (argc == 5) {
805 if (strmatch(argv[idx_send_recv]->text, "send"))
806 level = OSPF6_DEBUG_ZEBRA_SEND;
807 else if (strmatch(argv[idx_send_recv]->text, "recv"))
808 level = OSPF6_DEBUG_ZEBRA_RECV;
809 } else
810 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
811
812 OSPF6_DEBUG_ZEBRA_OFF(level);
813 return CMD_SUCCESS;
814 }
815
816
817 int config_write_ospf6_debug_zebra(struct vty *vty)
818 {
819 if (IS_OSPF6_DEBUG_ZEBRA(SEND) && IS_OSPF6_DEBUG_ZEBRA(RECV))
820 vty_out(vty, "debug ospf6 zebra\n");
821 else {
822 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
823 vty_out(vty, "debug ospf6 zebra send\n");
824 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
825 vty_out(vty, "debug ospf6 zebra recv\n");
826 }
827 return 0;
828 }
829
830 void install_element_ospf6_debug_zebra(void)
831 {
832 install_element(ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
833 install_element(ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
834 install_element(CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
835 install_element(CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
836 }