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