]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_zebra.c
bgpd: Prevent crash in bgp_table_range_lookup
[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
718e3744 100/* Inteface addition message from zebra. */
121f9dee 101static int ospf6_zebra_if_add(ZAPI_CALLBACK_ARGS)
718e3744 102{
d62a17ae 103 struct interface *ifp;
104
105 ifp = zebra_interface_add_read(zclient->ibuf, vrf_id);
106 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
107 zlog_debug("Zebra Interface add: %s index %d mtu %d", ifp->name,
108 ifp->ifindex, ifp->mtu6);
109 ospf6_interface_if_add(ifp);
110 return 0;
718e3744 111}
112
121f9dee 113static int ospf6_zebra_if_del(ZAPI_CALLBACK_ARGS)
718e3744 114{
d62a17ae 115 struct interface *ifp;
718e3744 116
d62a17ae 117 if (!(ifp = zebra_interface_state_read(zclient->ibuf, vrf_id)))
118 return 0;
d2fc8896 119
d62a17ae 120 if (if_is_up(ifp))
121 zlog_warn("Zebra: got delete of %s, but interface is still up",
122 ifp->name);
d2fc8896 123
d62a17ae 124 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
125 zlog_debug("Zebra Interface delete: %s index %d mtu %d",
126 ifp->name, ifp->ifindex, ifp->mtu6);
718e3744 127
ff880b78 128 if_set_index(ifp, IFINDEX_INTERNAL);
d62a17ae 129 return 0;
718e3744 130}
131
121f9dee 132static int ospf6_zebra_if_state_update(ZAPI_CALLBACK_ARGS)
718e3744 133{
d62a17ae 134 struct interface *ifp;
135
136 ifp = zebra_interface_state_read(zclient->ibuf, vrf_id);
137 if (ifp == NULL)
138 return 0;
139
140 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
141 zlog_debug(
142 "Zebra Interface state change: "
143 "%s index %d flags %llx metric %d mtu %d bandwidth %d",
144 ifp->name, ifp->ifindex, (unsigned long long)ifp->flags,
145 ifp->metric, ifp->mtu6, ifp->bandwidth);
146
147 ospf6_interface_state_update(ifp);
148 return 0;
718e3744 149}
150
121f9dee 151static int ospf6_zebra_if_address_update_add(ZAPI_CALLBACK_ARGS)
718e3744 152{
d62a17ae 153 struct connected *c;
154 char buf[128];
155
156 c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD,
157 zclient->ibuf, vrf_id);
158 if (c == NULL)
159 return 0;
160
161 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
162 zlog_debug("Zebra Interface address add: %s %5s %s/%d",
163 c->ifp->name, prefix_family_str(c->address),
164 inet_ntop(c->address->family, &c->address->u.prefix,
165 buf, sizeof(buf)),
166 c->address->prefixlen);
167
168 if (c->address->family == AF_INET6) {
169 ospf6_interface_state_update(c->ifp);
170 ospf6_interface_connected_route_update(c->ifp);
171 }
172 return 0;
718e3744 173}
174
121f9dee 175static int ospf6_zebra_if_address_update_delete(ZAPI_CALLBACK_ARGS)
718e3744 176{
d62a17ae 177 struct connected *c;
178 char buf[128];
179
180 c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE,
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 delete: %s %5s %s/%d",
187 c->ifp->name, prefix_family_str(c->address),
188 inet_ntop(c->address->family, &c->address->u.prefix,
189 buf, sizeof(buf)),
190 c->address->prefixlen);
191
192 if (c->address->family == AF_INET6) {
193 ospf6_interface_connected_route_update(c->ifp);
194 ospf6_interface_state_update(c->ifp);
195 }
718e3744 196
d62a17ae 197 connected_free(c);
718e3744 198
d62a17ae 199 return 0;
200}
718e3744 201
121f9dee 202static int ospf6_zebra_read_route(ZAPI_CALLBACK_ARGS)
d62a17ae 203{
74489921 204 struct zapi_route api;
d62a17ae 205 unsigned long ifindex;
d62a17ae 206 struct in6_addr *nexthop;
207
208 if (ospf6 == NULL)
209 return 0;
210
74489921
RW
211 if (zapi_route_decode(zclient->ibuf, &api) < 0)
212 return -1;
d62a17ae 213
74489921
RW
214 /* we completely ignore srcdest routes for now. */
215 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX))
d62a17ae 216 return 0;
217
9fb2b879
DS
218 if (IN6_IS_ADDR_LINKLOCAL(&api.prefix.u.prefix6))
219 return 0;
220
74489921
RW
221 ifindex = api.nexthops[0].ifindex;
222 nexthop = &api.nexthops[0].gate.ipv6;
d62a17ae 223
224 if (IS_OSPF6_DEBUG_ZEBRA(RECV)) {
225 char prefixstr[PREFIX2STR_BUFFER], nexthopstr[128];
74489921
RW
226 prefix2str((struct prefix *)&api.prefix, prefixstr,
227 sizeof(prefixstr));
0af35d90 228 inet_ntop(AF_INET6, nexthop, nexthopstr, sizeof(nexthopstr));
d62a17ae 229
230 zlog_debug(
231 "Zebra Receive route %s: %s %s nexthop %s ifindex %ld tag %" ROUTE_TAG_PRI,
121f9dee
QY
232 (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD ? "add"
233 : "delete"),
d62a17ae 234 zebra_route_string(api.type), prefixstr, nexthopstr,
235 ifindex, api.tag);
236 }
718e3744 237
121f9dee 238 if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD)
74489921 239 ospf6_asbr_redistribute_add(api.type, ifindex, &api.prefix,
d62a17ae 240 api.nexthop_num, nexthop, api.tag);
241 else
74489921 242 ospf6_asbr_redistribute_remove(api.type, ifindex, &api.prefix);
718e3744 243
d62a17ae 244 return 0;
718e3744 245}
246
718e3744 247DEFUN (show_zebra,
eefe02da
DS
248 show_ospf6_zebra_cmd,
249 "show ipv6 ospf6 zebra",
718e3744 250 SHOW_STR
eefe02da
DS
251 IPV6_STR
252 OSPF6_STR
41e7fb80 253 ZEBRA_STR)
718e3744 254{
d62a17ae 255 int i;
256 if (zclient == NULL) {
257 vty_out(vty, "Not connected to zebra\n");
258 return CMD_SUCCESS;
259 }
260
261 vty_out(vty, "Zebra Infomation\n");
34b054ba 262 vty_out(vty, " fail: %d\n", zclient->fail);
d62a17ae 263 vty_out(vty, " redistribute default: %d\n",
49db7a7b
RW
264 vrf_bitmap_check(zclient->default_information[AFI_IP6],
265 VRF_DEFAULT));
d62a17ae 266 vty_out(vty, " redistribute:");
267 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
268 if (vrf_bitmap_check(zclient->redist[AFI_IP6][i], VRF_DEFAULT))
269 vty_out(vty, " %s", zebra_route_string(i));
270 }
271 vty_out(vty, "\n");
272 return CMD_SUCCESS;
718e3744 273}
274
718e3744 275#define ADD 0
508e53e2 276#define REM 1
d62a17ae 277static void ospf6_zebra_route_update(int type, struct ospf6_route *request)
718e3744 278{
5afa1c6b 279 struct zapi_route api;
d62a17ae 280 char buf[PREFIX2STR_BUFFER];
281 int nhcount;
d62a17ae 282 int ret = 0;
5afa1c6b 283 struct prefix *dest;
d62a17ae 284
285 if (IS_OSPF6_DEBUG_ZEBRA(SEND)) {
286 prefix2str(&request->prefix, buf, sizeof(buf));
287 zlog_debug("Send %s route: %s",
288 (type == REM ? "remove" : "add"), buf);
289 }
290
291 if (zclient->sock < 0) {
292 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
293 zlog_debug(" Not connected to Zebra");
294 return;
295 }
296
297 if (request->path.origin.adv_router == ospf6->router_id
298 && (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1
299 || request->path.type == OSPF6_PATH_TYPE_EXTERNAL2)) {
300 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
301 zlog_debug(" Ignore self-originated external route");
302 return;
303 }
304
305 /* If removing is the best path and if there's another path,
306 treat this request as add the secondary path */
307 if (type == REM && ospf6_route_is_best(request) && request->next
308 && ospf6_route_is_same(request, request->next)) {
309 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
310 zlog_debug(
311 " Best-path removal resulted Sencondary addition");
312 type = ADD;
313 request = request->next;
314 }
315
316 /* Only the best path will be sent to zebra. */
317 if (!ospf6_route_is_best(request)) {
318 /* this is not preferred best route, ignore */
319 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
320 zlog_debug(" Ignore non-best route");
321 return;
322 }
323
324 nhcount = ospf6_route_num_nexthops(request);
325 if (nhcount == 0) {
326 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
327 zlog_debug(" No nexthop, ignore");
328 return;
329 }
330
5afa1c6b 331 dest = &request->prefix;
d62a17ae 332
5afa1c6b 333 memset(&api, 0, sizeof(api));
d62a17ae 334 api.vrf_id = VRF_DEFAULT;
335 api.type = ZEBRA_ROUTE_OSPF6;
d62a17ae 336 api.safi = SAFI_UNICAST;
5afa1c6b 337 api.prefix = *dest;
d62a17ae 338 SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
a74e593b
RW
339 api.nexthop_num = MIN(nhcount, MULTIPATH_NUM);
340 ospf6_route_zebra_copy_nexthops(request, api.nexthops, api.nexthop_num);
d62a17ae 341 SET_FLAG(api.message, ZAPI_MESSAGE_METRIC);
342 api.metric = (request->path.metric_type == 2 ? request->path.u.cost_e2
343 : request->path.cost);
344 if (request->path.tag) {
345 SET_FLAG(api.message, ZAPI_MESSAGE_TAG);
346 api.tag = request->path.tag;
347 }
348
d62a17ae 349 SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
5afa1c6b
RW
350 api.distance =
351 ospf6_distance_apply((struct prefix_ipv6 *)dest, request);
d62a17ae 352
353 if (type == REM)
5afa1c6b 354 ret = zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
d62a17ae 355 else
5afa1c6b 356 ret = zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
d62a17ae 357
358 if (ret < 0)
450971aa 359 flog_err(EC_LIB_ZAPI_SOCKET,
1c50c1c0
QY
360 "zclient_route_send() %s failed: %s",
361 (type == REM ? "delete" : "add"),
362 safe_strerror(errno));
d62a17ae 363
d62a17ae 364 return;
718e3744 365}
366
d62a17ae 367void ospf6_zebra_route_update_add(struct ospf6_route *request)
718e3744 368{
d62a17ae 369 ospf6_zebra_route_update(ADD, request);
718e3744 370}
371
d62a17ae 372void ospf6_zebra_route_update_remove(struct ospf6_route *request)
718e3744 373{
d62a17ae 374 ospf6_zebra_route_update(REM, request);
718e3744 375}
376
d62a17ae 377void ospf6_zebra_add_discard(struct ospf6_route *request)
c3c0ac83 378{
5afa1c6b 379 struct zapi_route api;
d62a17ae 380 char buf[INET6_ADDRSTRLEN];
5afa1c6b 381 struct prefix *dest = &request->prefix;
d62a17ae 382
d00061ea 383 if (!CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) {
5afa1c6b 384 memset(&api, 0, sizeof(api));
d00061ea
RW
385 api.vrf_id = VRF_DEFAULT;
386 api.type = ZEBRA_ROUTE_OSPF6;
d00061ea 387 api.safi = SAFI_UNICAST;
5afa1c6b 388 api.prefix = *dest;
09a484dd 389 zapi_route_set_blackhole(&api, BLACKHOLE_NULL);
d00061ea 390
5afa1c6b 391 zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
d00061ea
RW
392
393 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
394 zlog_debug("Zebra: Route add discard %s/%d",
5afa1c6b 395 inet_ntop(AF_INET6, &dest->u.prefix6, buf,
d00061ea
RW
396 INET6_ADDRSTRLEN),
397 dest->prefixlen);
398
399 SET_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
400 } else {
d00061ea
RW
401 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
402 zlog_debug(
403 "Zebra: Blackhole route present already %s/%d",
5afa1c6b 404 inet_ntop(AF_INET6, &dest->u.prefix6, buf,
d00061ea
RW
405 INET6_ADDRSTRLEN),
406 dest->prefixlen);
c3c0ac83 407 }
c3c0ac83
DS
408}
409
d62a17ae 410void ospf6_zebra_delete_discard(struct ospf6_route *request)
c3c0ac83 411{
5afa1c6b 412 struct zapi_route api;
d62a17ae 413 char buf[INET6_ADDRSTRLEN];
5afa1c6b 414 struct prefix *dest = &request->prefix;
d62a17ae 415
d00061ea 416 if (CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) {
5afa1c6b 417 memset(&api, 0, sizeof(api));
d00061ea
RW
418 api.vrf_id = VRF_DEFAULT;
419 api.type = ZEBRA_ROUTE_OSPF6;
d00061ea 420 api.safi = SAFI_UNICAST;
5afa1c6b 421 api.prefix = *dest;
09a484dd 422 zapi_route_set_blackhole(&api, BLACKHOLE_NULL);
d00061ea 423
5afa1c6b 424 zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
d00061ea
RW
425
426 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
427 zlog_debug("Zebra: Route delete discard %s/%d",
5afa1c6b 428 inet_ntop(AF_INET6, &dest->u.prefix6, buf,
d00061ea
RW
429 INET6_ADDRSTRLEN),
430 dest->prefixlen);
431
432 UNSET_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED);
433 } else {
d00061ea
RW
434 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
435 zlog_debug(
436 "Zebra: Blackhole route already deleted %s/%d",
5afa1c6b 437 inet_ntop(AF_INET6, &dest->u.prefix6, buf,
d00061ea
RW
438 INET6_ADDRSTRLEN),
439 dest->prefixlen);
c3c0ac83 440 }
c3c0ac83
DS
441}
442
d62a17ae 443static struct ospf6_distance *ospf6_distance_new(void)
baff583e 444{
d62a17ae 445 return XCALLOC(MTYPE_OSPF6_DISTANCE, sizeof(struct ospf6_distance));
baff583e
MZ
446}
447
d62a17ae 448static void ospf6_distance_free(struct ospf6_distance *odistance)
baff583e 449{
d62a17ae 450 XFREE(MTYPE_OSPF6_DISTANCE, odistance);
baff583e
MZ
451}
452
d62a17ae 453int ospf6_distance_set(struct vty *vty, struct ospf6 *o,
454 const char *distance_str, const char *ip_str,
455 const char *access_list_str)
baff583e 456{
d62a17ae 457 int ret;
458 struct prefix_ipv6 p;
d7c0a89a 459 uint8_t distance;
d62a17ae 460 struct route_node *rn;
461 struct ospf6_distance *odistance;
462
463 ret = str2prefix_ipv6(ip_str, &p);
464 if (ret == 0) {
465 vty_out(vty, "Malformed prefix\n");
466 return CMD_WARNING_CONFIG_FAILED;
467 }
468
469 distance = atoi(distance_str);
470
471 /* Get OSPF6 distance node. */
472 rn = route_node_get(o->distance_table, (struct prefix *)&p);
473 if (rn->info) {
474 odistance = rn->info;
475 route_unlock_node(rn);
476 } else {
477 odistance = ospf6_distance_new();
478 rn->info = odistance;
479 }
480
481 /* Set distance value. */
482 odistance->distance = distance;
483
484 /* Reset access-list configuration. */
485 if (odistance->access_list) {
486 free(odistance->access_list);
487 odistance->access_list = NULL;
488 }
489 if (access_list_str)
490 odistance->access_list = strdup(access_list_str);
491
492 return CMD_SUCCESS;
baff583e
MZ
493}
494
d62a17ae 495int ospf6_distance_unset(struct vty *vty, struct ospf6 *o,
496 const char *distance_str, const char *ip_str,
497 const char *access_list_str)
baff583e 498{
d62a17ae 499 int ret;
500 struct prefix_ipv6 p;
501 struct route_node *rn;
502 struct ospf6_distance *odistance;
503
504 ret = str2prefix_ipv6(ip_str, &p);
505 if (ret == 0) {
506 vty_out(vty, "Malformed prefix\n");
507 return CMD_WARNING_CONFIG_FAILED;
508 }
509
510 rn = route_node_lookup(o->distance_table, (struct prefix *)&p);
511 if (!rn) {
512 vty_out(vty, "Cant't find specified prefix\n");
513 return CMD_WARNING_CONFIG_FAILED;
514 }
515
516 odistance = rn->info;
517
518 if (odistance->access_list)
519 free(odistance->access_list);
520 ospf6_distance_free(odistance);
521
522 rn->info = NULL;
523 route_unlock_node(rn);
524 route_unlock_node(rn);
525
526 return CMD_SUCCESS;
baff583e
MZ
527}
528
d62a17ae 529void ospf6_distance_reset(struct ospf6 *o)
baff583e 530{
d62a17ae 531 struct route_node *rn;
532 struct ospf6_distance *odistance;
533
534 for (rn = route_top(o->distance_table); rn; rn = route_next(rn))
535 if ((odistance = rn->info) != NULL) {
536 if (odistance->access_list)
537 free(odistance->access_list);
538 ospf6_distance_free(odistance);
539 rn->info = NULL;
540 route_unlock_node(rn);
541 }
baff583e
MZ
542}
543
d7c0a89a 544uint8_t ospf6_distance_apply(struct prefix_ipv6 *p, struct ospf6_route * or)
baff583e 545{
d62a17ae 546 struct ospf6 *o;
baff583e 547
d62a17ae 548 o = ospf6;
549 if (o == NULL)
550 return 0;
baff583e 551
d62a17ae 552 if (o->distance_intra)
553 if (or->path.type == OSPF6_PATH_TYPE_INTRA)
554 return o->distance_intra;
baff583e 555
d62a17ae 556 if (o->distance_inter)
557 if (or->path.type == OSPF6_PATH_TYPE_INTER)
558 return o->distance_inter;
baff583e 559
d62a17ae 560 if (o->distance_external)
561 if (or->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
562 or->path.type == OSPF6_PATH_TYPE_EXTERNAL2)
563 return o->distance_external;
baff583e 564
d62a17ae 565 if (o->distance_all)
566 return o->distance_all;
baff583e 567
d62a17ae 568 return 0;
baff583e
MZ
569}
570
d62a17ae 571static void ospf6_zebra_connected(struct zclient *zclient)
7076bb2f 572{
d62a17ae 573 /* Send the client registration */
574 bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER);
2376c3f2 575
d62a17ae 576 zclient_send_reg_requests(zclient, VRF_DEFAULT);
7076bb2f
FL
577}
578
d62a17ae 579void ospf6_zebra_init(struct thread_master *master)
718e3744 580{
d62a17ae 581 /* Allocate zebra structure. */
26f63a1e 582 zclient = zclient_new(master, &zclient_options_default);
342213ea 583 zclient_init(zclient, ZEBRA_ROUTE_OSPF6, 0, &ospf6d_privs);
d62a17ae 584 zclient->zebra_connected = ospf6_zebra_connected;
585 zclient->router_id_update = ospf6_router_id_update_zebra;
586 zclient->interface_add = ospf6_zebra_if_add;
587 zclient->interface_delete = ospf6_zebra_if_del;
588 zclient->interface_up = ospf6_zebra_if_state_update;
589 zclient->interface_down = ospf6_zebra_if_state_update;
590 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
591 zclient->interface_address_delete =
592 ospf6_zebra_if_address_update_delete;
74489921
RW
593 zclient->redistribute_route_add = ospf6_zebra_read_route;
594 zclient->redistribute_route_del = ospf6_zebra_read_route;
d62a17ae 595
d62a17ae 596 /* Install command element for zebra node. */
597 install_element(VIEW_NODE, &show_ospf6_zebra_cmd);
718e3744 598}
599
508e53e2 600/* Debug */
6b0655a2 601
508e53e2 602DEFUN (debug_ospf6_zebra_sendrecv,
603 debug_ospf6_zebra_sendrecv_cmd,
1d68dbfe 604 "debug ospf6 zebra [<send|recv>]",
508e53e2 605 DEBUG_STR
606 OSPF6_STR
607 "Debug connection between zebra\n"
608 "Debug Sending zebra\n"
609 "Debug Receiving zebra\n"
610 )
611{
d62a17ae 612 int idx_send_recv = 3;
613 unsigned char level = 0;
614
615 if (argc == 4) {
616 if (strmatch(argv[idx_send_recv]->text, "send"))
617 level = OSPF6_DEBUG_ZEBRA_SEND;
618 else if (strmatch(argv[idx_send_recv]->text, "recv"))
619 level = OSPF6_DEBUG_ZEBRA_RECV;
620 } else
621 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
622
623 OSPF6_DEBUG_ZEBRA_ON(level);
624 return CMD_SUCCESS;
508e53e2 625}
626
508e53e2 627DEFUN (no_debug_ospf6_zebra_sendrecv,
628 no_debug_ospf6_zebra_sendrecv_cmd,
1d68dbfe 629 "no debug ospf6 zebra [<send|recv>]",
508e53e2 630 NO_STR
631 DEBUG_STR
632 OSPF6_STR
633 "Debug connection between zebra\n"
634 "Debug Sending zebra\n"
635 "Debug Receiving zebra\n"
636 )
637{
d62a17ae 638 int idx_send_recv = 4;
639 unsigned char level = 0;
640
641 if (argc == 5) {
642 if (strmatch(argv[idx_send_recv]->text, "send"))
643 level = OSPF6_DEBUG_ZEBRA_SEND;
644 else if (strmatch(argv[idx_send_recv]->text, "recv"))
645 level = OSPF6_DEBUG_ZEBRA_RECV;
646 } else
647 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
648
649 OSPF6_DEBUG_ZEBRA_OFF(level);
650 return CMD_SUCCESS;
508e53e2 651}
652
508e53e2 653
d62a17ae 654int config_write_ospf6_debug_zebra(struct vty *vty)
508e53e2 655{
d62a17ae 656 if (IS_OSPF6_DEBUG_ZEBRA(SEND) && IS_OSPF6_DEBUG_ZEBRA(RECV))
657 vty_out(vty, "debug ospf6 zebra\n");
658 else {
659 if (IS_OSPF6_DEBUG_ZEBRA(SEND))
660 vty_out(vty, "debug ospf6 zebra send\n");
661 if (IS_OSPF6_DEBUG_ZEBRA(RECV))
662 vty_out(vty, "debug ospf6 zebra recv\n");
663 }
664 return 0;
508e53e2 665}
666
d62a17ae 667void install_element_ospf6_debug_zebra(void)
718e3744 668{
d62a17ae 669 install_element(ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
670 install_element(ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
671 install_element(CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
672 install_element(CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
718e3744 673}