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