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