2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
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
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.
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
32 #include "ospf6_proto.h"
33 #include "ospf6_top.h"
34 #include "ospf6_interface.h"
35 #include "ospf6_route.h"
36 #include "ospf6_lsa.h"
37 #include "ospf6_lsdb.h"
38 #include "ospf6_asbr.h"
39 #include "ospf6_zebra.h"
42 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_DISTANCE
, "OSPF6 distance")
44 unsigned char conf_debug_ospf6_zebra
= 0;
46 /* information about zebra. */
47 struct zclient
*zclient
= NULL
;
49 struct in_addr router_id_zebra
;
51 /* Router-id update message from zebra. */
52 static int ospf6_router_id_update_zebra(int command
, struct zclient
*zclient
,
53 zebra_size_t length
, vrf_id_t vrf_id
)
55 struct prefix router_id
;
56 struct ospf6
*o
= ospf6
;
58 zebra_router_id_update_read(zclient
->ibuf
, &router_id
);
59 router_id_zebra
= router_id
.u
.prefix4
;
64 if (o
->router_id
== 0)
65 o
->router_id
= (u_int32_t
)router_id_zebra
.s_addr
;
70 /* redistribute function */
71 void ospf6_zebra_redistribute(int type
)
73 if (vrf_bitmap_check(zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
))
75 vrf_bitmap_set(zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
);
77 if (zclient
->sock
> 0)
78 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD
, zclient
,
79 AFI_IP6
, type
, 0, VRF_DEFAULT
);
82 void ospf6_zebra_no_redistribute(int type
)
84 if (!vrf_bitmap_check(zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
))
86 vrf_bitmap_unset(zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
);
87 if (zclient
->sock
> 0)
88 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE
, zclient
,
89 AFI_IP6
, type
, 0, VRF_DEFAULT
);
92 /* Inteface addition message from zebra. */
93 static int ospf6_zebra_if_add(int command
, struct zclient
*zclient
,
94 zebra_size_t length
, vrf_id_t vrf_id
)
96 struct interface
*ifp
;
98 ifp
= zebra_interface_add_read(zclient
->ibuf
, vrf_id
);
99 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
100 zlog_debug("Zebra Interface add: %s index %d mtu %d", ifp
->name
,
101 ifp
->ifindex
, ifp
->mtu6
);
102 ospf6_interface_if_add(ifp
);
106 static int ospf6_zebra_if_del(int command
, struct zclient
*zclient
,
107 zebra_size_t length
, vrf_id_t vrf_id
)
109 struct interface
*ifp
;
111 if (!(ifp
= zebra_interface_state_read(zclient
->ibuf
, vrf_id
)))
115 zlog_warn("Zebra: got delete of %s, but interface is still up",
118 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
119 zlog_debug("Zebra Interface delete: %s index %d mtu %d",
120 ifp
->name
, ifp
->ifindex
, ifp
->mtu6
);
123 /* XXX: ospf6_interface_if_del is not the right way to handle this,
124 * because among other thinkable issues, it will also clear all
125 * settings as they are contained in the struct ospf6_interface. */
126 ospf6_interface_if_del (ifp
);
129 ifp
->ifindex
= IFINDEX_DELETED
;
133 static int ospf6_zebra_if_state_update(int command
, struct zclient
*zclient
,
134 zebra_size_t length
, vrf_id_t vrf_id
)
136 struct interface
*ifp
;
138 ifp
= zebra_interface_state_read(zclient
->ibuf
, vrf_id
);
142 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
144 "Zebra Interface state change: "
145 "%s index %d flags %llx metric %d mtu %d bandwidth %d",
146 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
147 ifp
->metric
, ifp
->mtu6
, ifp
->bandwidth
);
149 ospf6_interface_state_update(ifp
);
153 static int ospf6_zebra_if_address_update_add(int command
,
154 struct zclient
*zclient
,
161 c
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD
,
162 zclient
->ibuf
, vrf_id
);
166 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
167 zlog_debug("Zebra Interface address add: %s %5s %s/%d",
168 c
->ifp
->name
, prefix_family_str(c
->address
),
169 inet_ntop(c
->address
->family
, &c
->address
->u
.prefix
,
171 c
->address
->prefixlen
);
173 if (c
->address
->family
== AF_INET6
) {
174 ospf6_interface_state_update(c
->ifp
);
175 ospf6_interface_connected_route_update(c
->ifp
);
180 static int ospf6_zebra_if_address_update_delete(int command
,
181 struct zclient
*zclient
,
188 c
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE
,
189 zclient
->ibuf
, vrf_id
);
193 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
194 zlog_debug("Zebra Interface address delete: %s %5s %s/%d",
195 c
->ifp
->name
, prefix_family_str(c
->address
),
196 inet_ntop(c
->address
->family
, &c
->address
->u
.prefix
,
198 c
->address
->prefixlen
);
200 if (c
->address
->family
== AF_INET6
) {
201 ospf6_interface_connected_route_update(c
->ifp
);
202 ospf6_interface_state_update(c
->ifp
);
210 static int ospf6_zebra_read_ipv6(int command
, struct zclient
*zclient
,
211 zebra_size_t length
, vrf_id_t vrf_id
)
214 struct zapi_ipv6 api
;
215 unsigned long ifindex
;
216 struct prefix p
, src_p
;
217 struct in6_addr
*nexthop
;
225 memset(&api
, 0, sizeof(api
));
227 /* Type, flags, message. */
228 api
.type
= stream_getc(s
);
229 api
.instance
= stream_getw(s
);
230 api
.flags
= stream_getl(s
);
231 api
.message
= stream_getc(s
);
234 memset(&p
, 0, sizeof(struct prefix
));
236 p
.prefixlen
= MIN(IPV6_MAX_PREFIXLEN
, stream_getc(s
));
237 stream_get(&p
.u
.prefix6
, s
, PSIZE(p
.prefixlen
));
239 memset(&src_p
, 0, sizeof(struct prefix
));
240 src_p
.family
= AF_INET6
;
241 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_SRCPFX
)) {
242 src_p
.prefixlen
= stream_getc(s
);
243 stream_get(&src_p
.u
.prefix6
, s
, PSIZE(src_p
.prefixlen
));
247 /* we completely ignore srcdest routes for now. */
250 /* Nexthop, ifindex, distance, metric. */
251 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
)) {
252 api
.nexthop_num
= stream_getc(s
);
253 nexthop
= (struct in6_addr
*)malloc(api
.nexthop_num
254 * sizeof(struct in6_addr
));
255 stream_get(nexthop
, s
,
256 api
.nexthop_num
* sizeof(struct in6_addr
));
258 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_IFINDEX
)) {
259 api
.ifindex_num
= stream_getc(s
);
260 ifindex
= stream_getl(s
);
262 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
))
263 api
.distance
= stream_getc(s
);
266 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
))
267 api
.metric
= stream_getl(s
);
271 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_TAG
))
272 api
.tag
= stream_getl(s
);
276 if (IS_OSPF6_DEBUG_ZEBRA(RECV
)) {
277 char prefixstr
[PREFIX2STR_BUFFER
], nexthopstr
[128];
278 prefix2str((struct prefix
*)&p
, prefixstr
, sizeof(prefixstr
));
280 inet_ntop(AF_INET6
, nexthop
, nexthopstr
,
283 snprintf(nexthopstr
, sizeof(nexthopstr
), "::");
286 "Zebra Receive route %s: %s %s nexthop %s ifindex %ld tag %" ROUTE_TAG_PRI
,
287 (command
== ZEBRA_REDISTRIBUTE_IPV6_ADD
? "add"
289 zebra_route_string(api
.type
), prefixstr
, nexthopstr
,
293 if (command
== ZEBRA_REDISTRIBUTE_IPV6_ADD
)
294 ospf6_asbr_redistribute_add(api
.type
, ifindex
, &p
,
295 api
.nexthop_num
, nexthop
, api
.tag
);
297 ospf6_asbr_redistribute_remove(api
.type
, ifindex
, &p
);
299 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
))
306 show_ospf6_zebra_cmd
,
307 "show ipv6 ospf6 zebra",
311 "Zebra information\n")
314 if (zclient
== NULL
) {
315 vty_out(vty
, "Not connected to zebra\n");
319 vty_out(vty
, "Zebra Infomation\n");
320 vty_out(vty
, " enable: %d fail: %d\n", zclient
->enable
, zclient
->fail
);
321 vty_out(vty
, " redistribute default: %d\n",
322 vrf_bitmap_check(zclient
->default_information
, VRF_DEFAULT
));
323 vty_out(vty
, " redistribute:");
324 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
325 if (vrf_bitmap_check(zclient
->redist
[AFI_IP6
][i
], VRF_DEFAULT
))
326 vty_out(vty
, " %s", zebra_route_string(i
));
332 /* Zebra configuration write function. */
333 static int config_write_ospf6_zebra(struct vty
*vty
)
335 if (!zclient
->enable
) {
336 vty_out(vty
, "no router zebra\n");
338 } else if (!vrf_bitmap_check(
339 zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
341 vty_out(vty
, "router zebra\n");
342 vty_out(vty
, " no redistribute ospf6\n");
348 /* Zebra node structure. */
349 static struct cmd_node zebra_node
= {
350 ZEBRA_NODE
, "%s(config-zebra)# ",
355 static void ospf6_zebra_route_update(int type
, struct ospf6_route
*request
)
357 struct zapi_ipv6 api
;
358 char buf
[PREFIX2STR_BUFFER
];
360 struct in6_addr
**nexthops
;
361 ifindex_t
*ifindexes
;
363 struct prefix_ipv6
*dest
;
365 if (IS_OSPF6_DEBUG_ZEBRA(SEND
)) {
366 prefix2str(&request
->prefix
, buf
, sizeof(buf
));
367 zlog_debug("Send %s route: %s",
368 (type
== REM
? "remove" : "add"), buf
);
371 if (zclient
->sock
< 0) {
372 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
373 zlog_debug(" Not connected to Zebra");
377 if (request
->path
.origin
.adv_router
== ospf6
->router_id
378 && (request
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
379 || request
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
)) {
380 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
381 zlog_debug(" Ignore self-originated external route");
385 /* If removing is the best path and if there's another path,
386 treat this request as add the secondary path */
387 if (type
== REM
&& ospf6_route_is_best(request
) && request
->next
388 && ospf6_route_is_same(request
, request
->next
)) {
389 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
391 " Best-path removal resulted Sencondary addition");
393 request
= request
->next
;
396 /* Only the best path will be sent to zebra. */
397 if (!ospf6_route_is_best(request
)) {
398 /* this is not preferred best route, ignore */
399 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
400 zlog_debug(" Ignore non-best route");
404 nhcount
= ospf6_route_num_nexthops(request
);
406 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
407 zlog_debug(" No nexthop, ignore");
411 /* allocate memory for nexthop_list */
413 XCALLOC(MTYPE_OSPF6_OTHER
, nhcount
* sizeof(struct in6_addr
*));
414 if (nexthops
== NULL
) {
415 zlog_warn("Can't send route to zebra: malloc failed");
419 /* allocate memory for ifindex_list */
420 ifindexes
= XCALLOC(MTYPE_OSPF6_OTHER
, nhcount
* sizeof(ifindex_t
));
421 if (ifindexes
== NULL
) {
422 zlog_warn("Can't send route to zebra: malloc failed");
423 XFREE(MTYPE_OSPF6_OTHER
, nexthops
);
427 ospf6_route_zebra_copy_nexthops(request
, ifindexes
, nexthops
, nhcount
);
429 api
.vrf_id
= VRF_DEFAULT
;
430 api
.type
= ZEBRA_ROUTE_OSPF6
;
434 api
.safi
= SAFI_UNICAST
;
435 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
436 api
.nexthop_num
= nhcount
;
437 api
.nexthop
= nexthops
;
438 SET_FLAG(api
.message
, ZAPI_MESSAGE_IFINDEX
);
439 api
.ifindex_num
= nhcount
;
440 api
.ifindex
= ifindexes
;
441 SET_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
);
442 api
.metric
= (request
->path
.metric_type
== 2 ? request
->path
.u
.cost_e2
443 : request
->path
.cost
);
444 if (request
->path
.tag
) {
445 SET_FLAG(api
.message
, ZAPI_MESSAGE_TAG
);
446 api
.tag
= request
->path
.tag
;
449 dest
= (struct prefix_ipv6
*)&request
->prefix
;
451 SET_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
);
452 api
.distance
= ospf6_distance_apply(dest
, request
);
455 ret
= zapi_ipv6_route(ZEBRA_IPV6_ROUTE_DELETE
, zclient
, dest
,
458 ret
= zapi_ipv6_route(ZEBRA_IPV6_ROUTE_ADD
, zclient
, dest
, NULL
,
462 zlog_err("zapi_ipv6_route() %s failed: %s",
463 (type
== REM
? "delete" : "add"),
464 safe_strerror(errno
));
466 XFREE(MTYPE_OSPF6_OTHER
, nexthops
);
467 XFREE(MTYPE_OSPF6_OTHER
, ifindexes
);
472 void ospf6_zebra_route_update_add(struct ospf6_route
*request
)
474 if (!vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
476 ospf6
->route_table
->hook_add
= NULL
;
477 ospf6
->route_table
->hook_remove
= NULL
;
480 ospf6_zebra_route_update(ADD
, request
);
483 void ospf6_zebra_route_update_remove(struct ospf6_route
*request
)
485 if (!vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
487 ospf6
->route_table
->hook_add
= NULL
;
488 ospf6
->route_table
->hook_remove
= NULL
;
491 ospf6_zebra_route_update(REM
, request
);
494 void ospf6_zebra_add_discard(struct ospf6_route
*request
)
496 struct zapi_ipv6 api
;
497 char buf
[INET6_ADDRSTRLEN
];
498 struct prefix_ipv6
*dest
;
500 if (vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
502 if (!CHECK_FLAG(request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
)) {
503 api
.vrf_id
= VRF_DEFAULT
;
504 api
.type
= ZEBRA_ROUTE_OSPF6
;
505 api
.flags
= ZEBRA_FLAG_BLACKHOLE
;
508 api
.safi
= SAFI_UNICAST
;
509 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
513 dest
= (struct prefix_ipv6
*)&request
->prefix
;
515 zapi_ipv6_route(ZEBRA_IPV6_ROUTE_ADD
, zclient
, dest
,
518 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
519 zlog_debug("Zebra: Route add discard %s/%d",
520 inet_ntop(AF_INET6
, &dest
->prefix
,
521 buf
, INET6_ADDRSTRLEN
),
523 SET_FLAG(request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
);
525 dest
= (struct prefix_ipv6
*)&request
->prefix
;
527 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
529 "Zebra: Blackhole route present already %s/%d",
530 inet_ntop(AF_INET6
, &dest
->prefix
, buf
,
537 void ospf6_zebra_delete_discard(struct ospf6_route
*request
)
539 struct zapi_ipv6 api
;
540 char buf
[INET6_ADDRSTRLEN
];
541 struct prefix_ipv6
*dest
;
543 if (vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
545 if (CHECK_FLAG(request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
)) {
546 api
.vrf_id
= VRF_DEFAULT
;
547 api
.type
= ZEBRA_ROUTE_OSPF6
;
548 api
.flags
= ZEBRA_FLAG_BLACKHOLE
;
551 api
.safi
= SAFI_UNICAST
;
552 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
556 dest
= (struct prefix_ipv6
*)&request
->prefix
;
558 zapi_ipv6_route(ZEBRA_IPV6_ROUTE_DELETE
, zclient
, dest
,
561 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
562 zlog_debug("Zebra: Route delete discard %s/%d",
563 inet_ntop(AF_INET6
, &dest
->prefix
,
564 buf
, INET6_ADDRSTRLEN
),
566 UNSET_FLAG(request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
);
568 dest
= (struct prefix_ipv6
*)&request
->prefix
;
569 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
571 "Zebra: Blackhole route already deleted %s/%d",
572 inet_ntop(AF_INET6
, &dest
->prefix
, buf
,
579 DEFUN (redistribute_ospf6
,
580 redistribute_ospf6_cmd
,
581 "redistribute ospf6",
582 "Redistribute control\n"
585 struct ospf6_route
*route
;
587 if (vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
591 vrf_bitmap_set(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
597 /* send ospf6 route to zebra route table */
598 for (route
= ospf6_route_head(ospf6
->route_table
); route
;
599 route
= ospf6_route_next(route
))
600 ospf6_zebra_route_update_add(route
);
602 ospf6
->route_table
->hook_add
= ospf6_zebra_route_update_add
;
603 ospf6
->route_table
->hook_remove
= ospf6_zebra_route_update_remove
;
608 DEFUN (no_redistribute_ospf6
,
609 no_redistribute_ospf6_cmd
,
610 "no redistribute ospf6",
612 "Redistribute control\n"
615 struct ospf6_route
*route
;
617 if (!vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
621 vrf_bitmap_unset(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
627 ospf6
->route_table
->hook_add
= NULL
;
628 ospf6
->route_table
->hook_remove
= NULL
;
630 /* withdraw ospf6 route from zebra route table */
631 for (route
= ospf6_route_head(ospf6
->route_table
); route
;
632 route
= ospf6_route_next(route
))
633 ospf6_zebra_route_update_remove(route
);
638 static struct ospf6_distance
*ospf6_distance_new(void)
640 return XCALLOC(MTYPE_OSPF6_DISTANCE
, sizeof(struct ospf6_distance
));
643 static void ospf6_distance_free(struct ospf6_distance
*odistance
)
645 XFREE(MTYPE_OSPF6_DISTANCE
, odistance
);
648 int ospf6_distance_set(struct vty
*vty
, struct ospf6
*o
,
649 const char *distance_str
, const char *ip_str
,
650 const char *access_list_str
)
653 struct prefix_ipv6 p
;
655 struct route_node
*rn
;
656 struct ospf6_distance
*odistance
;
658 ret
= str2prefix_ipv6(ip_str
, &p
);
660 vty_out(vty
, "Malformed prefix\n");
661 return CMD_WARNING_CONFIG_FAILED
;
664 distance
= atoi(distance_str
);
666 /* Get OSPF6 distance node. */
667 rn
= route_node_get(o
->distance_table
, (struct prefix
*)&p
);
669 odistance
= rn
->info
;
670 route_unlock_node(rn
);
672 odistance
= ospf6_distance_new();
673 rn
->info
= odistance
;
676 /* Set distance value. */
677 odistance
->distance
= distance
;
679 /* Reset access-list configuration. */
680 if (odistance
->access_list
) {
681 free(odistance
->access_list
);
682 odistance
->access_list
= NULL
;
685 odistance
->access_list
= strdup(access_list_str
);
690 int ospf6_distance_unset(struct vty
*vty
, struct ospf6
*o
,
691 const char *distance_str
, const char *ip_str
,
692 const char *access_list_str
)
695 struct prefix_ipv6 p
;
696 struct route_node
*rn
;
697 struct ospf6_distance
*odistance
;
699 ret
= str2prefix_ipv6(ip_str
, &p
);
701 vty_out(vty
, "Malformed prefix\n");
702 return CMD_WARNING_CONFIG_FAILED
;
705 rn
= route_node_lookup(o
->distance_table
, (struct prefix
*)&p
);
707 vty_out(vty
, "Cant't find specified prefix\n");
708 return CMD_WARNING_CONFIG_FAILED
;
711 odistance
= rn
->info
;
713 if (odistance
->access_list
)
714 free(odistance
->access_list
);
715 ospf6_distance_free(odistance
);
718 route_unlock_node(rn
);
719 route_unlock_node(rn
);
724 void ospf6_distance_reset(struct ospf6
*o
)
726 struct route_node
*rn
;
727 struct ospf6_distance
*odistance
;
729 for (rn
= route_top(o
->distance_table
); rn
; rn
= route_next(rn
))
730 if ((odistance
= rn
->info
) != NULL
) {
731 if (odistance
->access_list
)
732 free(odistance
->access_list
);
733 ospf6_distance_free(odistance
);
735 route_unlock_node(rn
);
739 u_char
ospf6_distance_apply(struct prefix_ipv6
*p
, struct ospf6_route
* or)
747 if (o
->distance_intra
)
748 if (or->path
.type
== OSPF6_PATH_TYPE_INTRA
)
749 return o
->distance_intra
;
751 if (o
->distance_inter
)
752 if (or->path
.type
== OSPF6_PATH_TYPE_INTER
)
753 return o
->distance_inter
;
755 if (o
->distance_external
)
756 if (or->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
||
757 or->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
)
758 return o
->distance_external
;
761 return o
->distance_all
;
766 static void ospf6_zebra_connected(struct zclient
*zclient
)
768 /* Send the client registration */
769 bfd_client_sendmsg(zclient
, ZEBRA_BFD_CLIENT_REGISTER
);
771 zclient_send_reg_requests(zclient
, VRF_DEFAULT
);
774 void ospf6_zebra_init(struct thread_master
*master
)
776 /* Allocate zebra structure. */
777 zclient
= zclient_new(master
);
778 zclient_init(zclient
, ZEBRA_ROUTE_OSPF6
, 0);
779 zclient
->zebra_connected
= ospf6_zebra_connected
;
780 zclient
->router_id_update
= ospf6_router_id_update_zebra
;
781 zclient
->interface_add
= ospf6_zebra_if_add
;
782 zclient
->interface_delete
= ospf6_zebra_if_del
;
783 zclient
->interface_up
= ospf6_zebra_if_state_update
;
784 zclient
->interface_down
= ospf6_zebra_if_state_update
;
785 zclient
->interface_address_add
= ospf6_zebra_if_address_update_add
;
786 zclient
->interface_address_delete
=
787 ospf6_zebra_if_address_update_delete
;
788 zclient
->redistribute_route_ipv4_add
= NULL
;
789 zclient
->redistribute_route_ipv4_del
= NULL
;
790 zclient
->redistribute_route_ipv6_add
= ospf6_zebra_read_ipv6
;
791 zclient
->redistribute_route_ipv6_del
= ospf6_zebra_read_ipv6
;
793 /* redistribute connected route by default */
794 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
796 /* Install zebra node. */
797 install_node(&zebra_node
, config_write_ospf6_zebra
);
799 /* Install command element for zebra node. */
800 install_element(VIEW_NODE
, &show_ospf6_zebra_cmd
);
801 install_default(ZEBRA_NODE
);
802 install_element(ZEBRA_NODE
, &redistribute_ospf6_cmd
);
803 install_element(ZEBRA_NODE
, &no_redistribute_ospf6_cmd
);
810 DEFUN (debug_ospf6_zebra_sendrecv
,
811 debug_ospf6_zebra_sendrecv_cmd
,
812 "debug ospf6 zebra [<send|recv>]",
815 "Debug connection between zebra\n"
816 "Debug Sending zebra\n"
817 "Debug Receiving zebra\n"
820 int idx_send_recv
= 3;
821 unsigned char level
= 0;
824 if (strmatch(argv
[idx_send_recv
]->text
, "send"))
825 level
= OSPF6_DEBUG_ZEBRA_SEND
;
826 else if (strmatch(argv
[idx_send_recv
]->text
, "recv"))
827 level
= OSPF6_DEBUG_ZEBRA_RECV
;
829 level
= OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
;
831 OSPF6_DEBUG_ZEBRA_ON(level
);
835 DEFUN (no_debug_ospf6_zebra_sendrecv
,
836 no_debug_ospf6_zebra_sendrecv_cmd
,
837 "no debug ospf6 zebra [<send|recv>]",
841 "Debug connection between zebra\n"
842 "Debug Sending zebra\n"
843 "Debug Receiving zebra\n"
846 int idx_send_recv
= 4;
847 unsigned char level
= 0;
850 if (strmatch(argv
[idx_send_recv
]->text
, "send"))
851 level
= OSPF6_DEBUG_ZEBRA_SEND
;
852 else if (strmatch(argv
[idx_send_recv
]->text
, "recv"))
853 level
= OSPF6_DEBUG_ZEBRA_RECV
;
855 level
= OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
;
857 OSPF6_DEBUG_ZEBRA_OFF(level
);
862 int config_write_ospf6_debug_zebra(struct vty
*vty
)
864 if (IS_OSPF6_DEBUG_ZEBRA(SEND
) && IS_OSPF6_DEBUG_ZEBRA(RECV
))
865 vty_out(vty
, "debug ospf6 zebra\n");
867 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
868 vty_out(vty
, "debug ospf6 zebra send\n");
869 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
870 vty_out(vty
, "debug ospf6 zebra recv\n");
875 void install_element_ospf6_debug_zebra(void)
877 install_element(ENABLE_NODE
, &debug_ospf6_zebra_sendrecv_cmd
);
878 install_element(ENABLE_NODE
, &no_debug_ospf6_zebra_sendrecv_cmd
);
879 install_element(CONFIG_NODE
, &debug_ospf6_zebra_sendrecv_cmd
);
880 install_element(CONFIG_NODE
, &no_debug_ospf6_zebra_sendrecv_cmd
);