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
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
33 #include "ospf6_proto.h"
34 #include "ospf6_top.h"
35 #include "ospf6_interface.h"
36 #include "ospf6_route.h"
37 #include "ospf6_lsa.h"
38 #include "ospf6_lsdb.h"
39 #include "ospf6_asbr.h"
40 #include "ospf6_zebra.h"
43 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_DISTANCE
, "OSPF6 distance")
45 unsigned char conf_debug_ospf6_zebra
= 0;
47 /* information about zebra. */
48 struct zclient
*zclient
= NULL
;
50 struct in_addr router_id_zebra
;
52 /* Router-id update message from zebra. */
53 static int ospf6_router_id_update_zebra(int command
, struct zclient
*zclient
,
54 zebra_size_t length
, vrf_id_t vrf_id
)
56 struct prefix router_id
;
57 struct ospf6
*o
= ospf6
;
59 zebra_router_id_update_read(zclient
->ibuf
, &router_id
);
60 router_id_zebra
= router_id
.u
.prefix4
;
65 if (o
->router_id
== 0)
66 o
->router_id
= (u_int32_t
)router_id_zebra
.s_addr
;
71 /* redistribute function */
72 void ospf6_zebra_redistribute(int type
)
74 if (vrf_bitmap_check(zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
))
76 vrf_bitmap_set(zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
);
78 if (zclient
->sock
> 0)
79 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD
, zclient
,
80 AFI_IP6
, type
, 0, VRF_DEFAULT
);
83 void ospf6_zebra_no_redistribute(int type
)
85 if (!vrf_bitmap_check(zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
))
87 vrf_bitmap_unset(zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
);
88 if (zclient
->sock
> 0)
89 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE
, zclient
,
90 AFI_IP6
, type
, 0, VRF_DEFAULT
);
93 /* Inteface addition message from zebra. */
94 static int ospf6_zebra_if_add(int command
, struct zclient
*zclient
,
95 zebra_size_t length
, vrf_id_t vrf_id
)
97 struct interface
*ifp
;
99 ifp
= zebra_interface_add_read(zclient
->ibuf
, vrf_id
);
100 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
101 zlog_debug("Zebra Interface add: %s index %d mtu %d", ifp
->name
,
102 ifp
->ifindex
, ifp
->mtu6
);
103 ospf6_interface_if_add(ifp
);
107 static int ospf6_zebra_if_del(int command
, struct zclient
*zclient
,
108 zebra_size_t length
, vrf_id_t vrf_id
)
110 struct interface
*ifp
;
112 if (!(ifp
= zebra_interface_state_read(zclient
->ibuf
, vrf_id
)))
116 zlog_warn("Zebra: got delete of %s, but interface is still up",
119 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
120 zlog_debug("Zebra Interface delete: %s index %d mtu %d",
121 ifp
->name
, ifp
->ifindex
, ifp
->mtu6
);
124 /* XXX: ospf6_interface_if_del is not the right way to handle this,
125 * because among other thinkable issues, it will also clear all
126 * settings as they are contained in the struct ospf6_interface. */
127 ospf6_interface_if_del (ifp
);
130 ifp
->ifindex
= IFINDEX_DELETED
;
134 static int ospf6_zebra_if_state_update(int command
, struct zclient
*zclient
,
135 zebra_size_t length
, vrf_id_t vrf_id
)
137 struct interface
*ifp
;
139 ifp
= zebra_interface_state_read(zclient
->ibuf
, vrf_id
);
143 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
145 "Zebra Interface state change: "
146 "%s index %d flags %llx metric %d mtu %d bandwidth %d",
147 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
148 ifp
->metric
, ifp
->mtu6
, ifp
->bandwidth
);
150 ospf6_interface_state_update(ifp
);
154 static int ospf6_zebra_if_address_update_add(int command
,
155 struct zclient
*zclient
,
162 c
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD
,
163 zclient
->ibuf
, vrf_id
);
167 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
168 zlog_debug("Zebra Interface address add: %s %5s %s/%d",
169 c
->ifp
->name
, prefix_family_str(c
->address
),
170 inet_ntop(c
->address
->family
, &c
->address
->u
.prefix
,
172 c
->address
->prefixlen
);
174 if (c
->address
->family
== AF_INET6
) {
175 ospf6_interface_state_update(c
->ifp
);
176 ospf6_interface_connected_route_update(c
->ifp
);
181 static int ospf6_zebra_if_address_update_delete(int command
,
182 struct zclient
*zclient
,
189 c
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE
,
190 zclient
->ibuf
, vrf_id
);
194 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
195 zlog_debug("Zebra Interface address delete: %s %5s %s/%d",
196 c
->ifp
->name
, prefix_family_str(c
->address
),
197 inet_ntop(c
->address
->family
, &c
->address
->u
.prefix
,
199 c
->address
->prefixlen
);
201 if (c
->address
->family
== AF_INET6
) {
202 ospf6_interface_connected_route_update(c
->ifp
);
203 ospf6_interface_state_update(c
->ifp
);
211 static int ospf6_zebra_read_ipv6(int command
, struct zclient
*zclient
,
212 zebra_size_t length
, vrf_id_t vrf_id
)
215 struct zapi_ipv6 api
;
216 unsigned long ifindex
;
217 struct prefix p
, src_p
;
218 struct in6_addr
*nexthop
;
226 memset(&api
, 0, sizeof(api
));
228 /* Type, flags, message. */
229 api
.type
= stream_getc(s
);
230 api
.instance
= stream_getw(s
);
231 api
.flags
= stream_getl(s
);
232 api
.message
= stream_getc(s
);
235 memset(&p
, 0, sizeof(struct prefix
));
237 p
.prefixlen
= MIN(IPV6_MAX_PREFIXLEN
, stream_getc(s
));
238 stream_get(&p
.u
.prefix6
, s
, PSIZE(p
.prefixlen
));
240 memset(&src_p
, 0, sizeof(struct prefix
));
241 src_p
.family
= AF_INET6
;
242 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_SRCPFX
)) {
243 src_p
.prefixlen
= stream_getc(s
);
244 stream_get(&src_p
.u
.prefix6
, s
, PSIZE(src_p
.prefixlen
));
248 /* we completely ignore srcdest routes for now. */
251 /* Nexthop, ifindex, distance, metric. */
252 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
)) {
253 api
.nexthop_num
= stream_getc(s
);
254 nexthop
= (struct in6_addr
*)malloc(api
.nexthop_num
255 * sizeof(struct in6_addr
));
256 stream_get(nexthop
, s
,
257 api
.nexthop_num
* sizeof(struct in6_addr
));
259 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_IFINDEX
)) {
260 api
.ifindex_num
= stream_getc(s
);
261 ifindex
= stream_getl(s
);
263 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
))
264 api
.distance
= stream_getc(s
);
267 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
))
268 api
.metric
= stream_getl(s
);
272 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_TAG
))
273 api
.tag
= stream_getl(s
);
277 if (IS_OSPF6_DEBUG_ZEBRA(RECV
)) {
278 char prefixstr
[PREFIX2STR_BUFFER
], nexthopstr
[128];
279 prefix2str((struct prefix
*)&p
, prefixstr
, sizeof(prefixstr
));
281 inet_ntop(AF_INET6
, nexthop
, nexthopstr
,
284 snprintf(nexthopstr
, sizeof(nexthopstr
), "::");
287 "Zebra Receive route %s: %s %s nexthop %s ifindex %ld tag %" ROUTE_TAG_PRI
,
288 (command
== ZEBRA_REDISTRIBUTE_IPV6_ADD
? "add"
290 zebra_route_string(api
.type
), prefixstr
, nexthopstr
,
294 if (command
== ZEBRA_REDISTRIBUTE_IPV6_ADD
)
295 ospf6_asbr_redistribute_add(api
.type
, ifindex
, &p
,
296 api
.nexthop_num
, nexthop
, api
.tag
);
298 ospf6_asbr_redistribute_remove(api
.type
, ifindex
, &p
);
300 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
))
311 "Zebra information\n")
314 if (zclient
== NULL
) {
315 vty_out(vty
, "Not connected to zebra%s", VNL
);
319 vty_out(vty
, "Zebra Infomation%s", VNL
);
320 vty_out(vty
, " enable: %d fail: %d%s", zclient
->enable
, zclient
->fail
,
322 vty_out(vty
, " redistribute default: %d%s",
323 vrf_bitmap_check(zclient
->default_information
, VRF_DEFAULT
),
325 vty_out(vty
, " redistribute:");
326 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
327 if (vrf_bitmap_check(zclient
->redist
[AFI_IP6
][i
], VRF_DEFAULT
))
328 vty_out(vty
, " %s", zebra_route_string(i
));
330 vty_out(vty
, "%s", VNL
);
334 /* Zebra configuration write function. */
335 static int config_write_ospf6_zebra(struct vty
*vty
)
337 if (!zclient
->enable
) {
338 vty_out(vty
, "no router zebra%s", VNL
);
339 vty_out(vty
, "!%s", VNL
);
340 } else if (!vrf_bitmap_check(
341 zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
343 vty_out(vty
, "router zebra%s", VNL
);
344 vty_out(vty
, " no redistribute ospf6%s", VNL
);
345 vty_out(vty
, "!%s", VNL
);
350 /* Zebra node structure. */
351 static struct cmd_node zebra_node
= {
352 ZEBRA_NODE
, "%s(config-zebra)# ",
357 static void ospf6_zebra_route_update(int type
, struct ospf6_route
*request
)
359 struct zapi_ipv6 api
;
360 char buf
[PREFIX2STR_BUFFER
];
362 struct in6_addr
**nexthops
;
363 ifindex_t
*ifindexes
;
365 struct prefix_ipv6
*dest
;
367 if (IS_OSPF6_DEBUG_ZEBRA(SEND
)) {
368 prefix2str(&request
->prefix
, buf
, sizeof(buf
));
369 zlog_debug("Send %s route: %s",
370 (type
== REM
? "remove" : "add"), buf
);
373 if (zclient
->sock
< 0) {
374 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
375 zlog_debug(" Not connected to Zebra");
379 if (request
->path
.origin
.adv_router
== ospf6
->router_id
380 && (request
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
381 || request
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
)) {
382 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
383 zlog_debug(" Ignore self-originated external route");
387 /* If removing is the best path and if there's another path,
388 treat this request as add the secondary path */
389 if (type
== REM
&& ospf6_route_is_best(request
) && request
->next
390 && ospf6_route_is_same(request
, request
->next
)) {
391 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
393 " Best-path removal resulted Sencondary addition");
395 request
= request
->next
;
398 /* Only the best path will be sent to zebra. */
399 if (!ospf6_route_is_best(request
)) {
400 /* this is not preferred best route, ignore */
401 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
402 zlog_debug(" Ignore non-best route");
406 nhcount
= ospf6_route_num_nexthops(request
);
408 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
409 zlog_debug(" No nexthop, ignore");
413 /* allocate memory for nexthop_list */
415 XCALLOC(MTYPE_OSPF6_OTHER
, nhcount
* sizeof(struct in6_addr
*));
416 if (nexthops
== NULL
) {
417 zlog_warn("Can't send route to zebra: malloc failed");
421 /* allocate memory for ifindex_list */
422 ifindexes
= XCALLOC(MTYPE_OSPF6_OTHER
, nhcount
* sizeof(ifindex_t
));
423 if (ifindexes
== NULL
) {
424 zlog_warn("Can't send route to zebra: malloc failed");
425 XFREE(MTYPE_OSPF6_OTHER
, nexthops
);
429 ospf6_route_zebra_copy_nexthops(request
, ifindexes
, nexthops
, nhcount
);
431 api
.vrf_id
= VRF_DEFAULT
;
432 api
.type
= ZEBRA_ROUTE_OSPF6
;
436 api
.safi
= SAFI_UNICAST
;
437 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
438 api
.nexthop_num
= nhcount
;
439 api
.nexthop
= nexthops
;
440 SET_FLAG(api
.message
, ZAPI_MESSAGE_IFINDEX
);
441 api
.ifindex_num
= nhcount
;
442 api
.ifindex
= ifindexes
;
443 SET_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
);
444 api
.metric
= (request
->path
.metric_type
== 2 ? request
->path
.u
.cost_e2
445 : request
->path
.cost
);
446 if (request
->path
.tag
) {
447 SET_FLAG(api
.message
, ZAPI_MESSAGE_TAG
);
448 api
.tag
= request
->path
.tag
;
451 dest
= (struct prefix_ipv6
*)&request
->prefix
;
453 SET_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
);
454 api
.distance
= ospf6_distance_apply(dest
, request
);
457 ret
= zapi_ipv6_route(ZEBRA_IPV6_ROUTE_DELETE
, zclient
, dest
,
460 ret
= zapi_ipv6_route(ZEBRA_IPV6_ROUTE_ADD
, zclient
, dest
, NULL
,
464 zlog_err("zapi_ipv6_route() %s failed: %s",
465 (type
== REM
? "delete" : "add"),
466 safe_strerror(errno
));
468 XFREE(MTYPE_OSPF6_OTHER
, nexthops
);
469 XFREE(MTYPE_OSPF6_OTHER
, ifindexes
);
474 void ospf6_zebra_route_update_add(struct ospf6_route
*request
)
476 if (!vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
478 ospf6
->route_table
->hook_add
= NULL
;
479 ospf6
->route_table
->hook_remove
= NULL
;
482 ospf6_zebra_route_update(ADD
, request
);
485 void ospf6_zebra_route_update_remove(struct ospf6_route
*request
)
487 if (!vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
489 ospf6
->route_table
->hook_add
= NULL
;
490 ospf6
->route_table
->hook_remove
= NULL
;
493 ospf6_zebra_route_update(REM
, request
);
496 void ospf6_zebra_add_discard(struct ospf6_route
*request
)
498 struct zapi_ipv6 api
;
499 char buf
[INET6_ADDRSTRLEN
];
500 struct prefix_ipv6
*dest
;
502 if (vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
504 if (!CHECK_FLAG(request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
)) {
505 api
.vrf_id
= VRF_DEFAULT
;
506 api
.type
= ZEBRA_ROUTE_OSPF6
;
507 api
.flags
= ZEBRA_FLAG_BLACKHOLE
;
510 api
.safi
= SAFI_UNICAST
;
511 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
515 dest
= (struct prefix_ipv6
*)&request
->prefix
;
517 zapi_ipv6_route(ZEBRA_IPV6_ROUTE_ADD
, zclient
, dest
,
520 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
521 zlog_debug("Zebra: Route add discard %s/%d",
522 inet_ntop(AF_INET6
, &dest
->prefix
,
523 buf
, INET6_ADDRSTRLEN
),
525 SET_FLAG(request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
);
527 dest
= (struct prefix_ipv6
*)&request
->prefix
;
529 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
531 "Zebra: Blackhole route present already %s/%d",
532 inet_ntop(AF_INET6
, &dest
->prefix
, buf
,
539 void ospf6_zebra_delete_discard(struct ospf6_route
*request
)
541 struct zapi_ipv6 api
;
542 char buf
[INET6_ADDRSTRLEN
];
543 struct prefix_ipv6
*dest
;
545 if (vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
547 if (CHECK_FLAG(request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
)) {
548 api
.vrf_id
= VRF_DEFAULT
;
549 api
.type
= ZEBRA_ROUTE_OSPF6
;
550 api
.flags
= ZEBRA_FLAG_BLACKHOLE
;
553 api
.safi
= SAFI_UNICAST
;
554 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
558 dest
= (struct prefix_ipv6
*)&request
->prefix
;
560 zapi_ipv6_route(ZEBRA_IPV6_ROUTE_DELETE
, zclient
, dest
,
563 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
564 zlog_debug("Zebra: Route delete discard %s/%d",
565 inet_ntop(AF_INET6
, &dest
->prefix
,
566 buf
, INET6_ADDRSTRLEN
),
568 UNSET_FLAG(request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
);
570 dest
= (struct prefix_ipv6
*)&request
->prefix
;
571 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
573 "Zebra: Blackhole route already deleted %s/%d",
574 inet_ntop(AF_INET6
, &dest
->prefix
, buf
,
581 DEFUN (redistribute_ospf6
,
582 redistribute_ospf6_cmd
,
583 "redistribute ospf6",
584 "Redistribute control\n"
587 struct ospf6_route
*route
;
589 if (vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
593 vrf_bitmap_set(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
599 /* send ospf6 route to zebra route table */
600 for (route
= ospf6_route_head(ospf6
->route_table
); route
;
601 route
= ospf6_route_next(route
))
602 ospf6_zebra_route_update_add(route
);
604 ospf6
->route_table
->hook_add
= ospf6_zebra_route_update_add
;
605 ospf6
->route_table
->hook_remove
= ospf6_zebra_route_update_remove
;
610 DEFUN (no_redistribute_ospf6
,
611 no_redistribute_ospf6_cmd
,
612 "no redistribute ospf6",
614 "Redistribute control\n"
617 struct ospf6_route
*route
;
619 if (!vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
623 vrf_bitmap_unset(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
629 ospf6
->route_table
->hook_add
= NULL
;
630 ospf6
->route_table
->hook_remove
= NULL
;
632 /* withdraw ospf6 route from zebra route table */
633 for (route
= ospf6_route_head(ospf6
->route_table
); route
;
634 route
= ospf6_route_next(route
))
635 ospf6_zebra_route_update_remove(route
);
640 static struct ospf6_distance
*ospf6_distance_new(void)
642 return XCALLOC(MTYPE_OSPF6_DISTANCE
, sizeof(struct ospf6_distance
));
645 static void ospf6_distance_free(struct ospf6_distance
*odistance
)
647 XFREE(MTYPE_OSPF6_DISTANCE
, odistance
);
650 int ospf6_distance_set(struct vty
*vty
, struct ospf6
*o
,
651 const char *distance_str
, const char *ip_str
,
652 const char *access_list_str
)
655 struct prefix_ipv6 p
;
657 struct route_node
*rn
;
658 struct ospf6_distance
*odistance
;
660 ret
= str2prefix_ipv6(ip_str
, &p
);
662 vty_out(vty
, "Malformed prefix%s", VTY_NEWLINE
);
666 distance
= atoi(distance_str
);
668 /* Get OSPF6 distance node. */
669 rn
= route_node_get(o
->distance_table
, (struct prefix
*)&p
);
671 odistance
= rn
->info
;
672 route_unlock_node(rn
);
674 odistance
= ospf6_distance_new();
675 rn
->info
= odistance
;
678 /* Set distance value. */
679 odistance
->distance
= distance
;
681 /* Reset access-list configuration. */
682 if (odistance
->access_list
) {
683 free(odistance
->access_list
);
684 odistance
->access_list
= NULL
;
687 odistance
->access_list
= strdup(access_list_str
);
692 int ospf6_distance_unset(struct vty
*vty
, struct ospf6
*o
,
693 const char *distance_str
, const char *ip_str
,
694 const char *access_list_str
)
697 struct prefix_ipv6 p
;
698 struct route_node
*rn
;
699 struct ospf6_distance
*odistance
;
701 ret
= str2prefix_ipv6(ip_str
, &p
);
703 vty_out(vty
, "Malformed prefix%s", VTY_NEWLINE
);
707 rn
= route_node_lookup(o
->distance_table
, (struct prefix
*)&p
);
709 vty_out(vty
, "Cant't find specified prefix%s", VTY_NEWLINE
);
713 odistance
= rn
->info
;
715 if (odistance
->access_list
)
716 free(odistance
->access_list
);
717 ospf6_distance_free(odistance
);
720 route_unlock_node(rn
);
721 route_unlock_node(rn
);
726 void ospf6_distance_reset(struct ospf6
*o
)
728 struct route_node
*rn
;
729 struct ospf6_distance
*odistance
;
731 for (rn
= route_top(o
->distance_table
); rn
; rn
= route_next(rn
))
732 if ((odistance
= rn
->info
) != NULL
) {
733 if (odistance
->access_list
)
734 free(odistance
->access_list
);
735 ospf6_distance_free(odistance
);
737 route_unlock_node(rn
);
741 u_char
ospf6_distance_apply(struct prefix_ipv6
*p
, struct ospf6_route
* or)
749 if (o
->distance_intra
)
750 if (or->path
.type
== OSPF6_PATH_TYPE_INTRA
)
751 return o
->distance_intra
;
753 if (o
->distance_inter
)
754 if (or->path
.type
== OSPF6_PATH_TYPE_INTER
)
755 return o
->distance_inter
;
757 if (o
->distance_external
)
758 if (or->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
||
759 or->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
)
760 return o
->distance_external
;
763 return o
->distance_all
;
768 static void ospf6_zebra_connected(struct zclient
*zclient
)
770 /* Send the client registration */
771 bfd_client_sendmsg(zclient
, ZEBRA_BFD_CLIENT_REGISTER
);
773 zclient_send_reg_requests(zclient
, VRF_DEFAULT
);
776 void ospf6_zebra_init(struct thread_master
*master
)
778 /* Allocate zebra structure. */
779 zclient
= zclient_new(master
);
780 zclient_init(zclient
, ZEBRA_ROUTE_OSPF6
, 0);
781 zclient
->zebra_connected
= ospf6_zebra_connected
;
782 zclient
->router_id_update
= ospf6_router_id_update_zebra
;
783 zclient
->interface_add
= ospf6_zebra_if_add
;
784 zclient
->interface_delete
= ospf6_zebra_if_del
;
785 zclient
->interface_up
= ospf6_zebra_if_state_update
;
786 zclient
->interface_down
= ospf6_zebra_if_state_update
;
787 zclient
->interface_address_add
= ospf6_zebra_if_address_update_add
;
788 zclient
->interface_address_delete
=
789 ospf6_zebra_if_address_update_delete
;
790 zclient
->redistribute_route_ipv4_add
= NULL
;
791 zclient
->redistribute_route_ipv4_del
= NULL
;
792 zclient
->redistribute_route_ipv6_add
= ospf6_zebra_read_ipv6
;
793 zclient
->redistribute_route_ipv6_del
= ospf6_zebra_read_ipv6
;
795 /* redistribute connected route by default */
796 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
798 /* Install zebra node. */
799 install_node(&zebra_node
, config_write_ospf6_zebra
);
801 /* Install command element for zebra node. */
802 install_element(VIEW_NODE
, &show_zebra_cmd
);
803 install_default(ZEBRA_NODE
);
804 install_element(ZEBRA_NODE
, &redistribute_ospf6_cmd
);
805 install_element(ZEBRA_NODE
, &no_redistribute_ospf6_cmd
);
812 DEFUN (debug_ospf6_zebra_sendrecv
,
813 debug_ospf6_zebra_sendrecv_cmd
,
814 "debug ospf6 zebra [<send|recv>]",
817 "Debug connection between zebra\n"
818 "Debug Sending zebra\n"
819 "Debug Receiving zebra\n"
822 int idx_send_recv
= 3;
823 unsigned char level
= 0;
826 if (strmatch(argv
[idx_send_recv
]->text
, "send"))
827 level
= OSPF6_DEBUG_ZEBRA_SEND
;
828 else if (strmatch(argv
[idx_send_recv
]->text
, "recv"))
829 level
= OSPF6_DEBUG_ZEBRA_RECV
;
831 level
= OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
;
833 OSPF6_DEBUG_ZEBRA_ON(level
);
837 DEFUN (no_debug_ospf6_zebra_sendrecv
,
838 no_debug_ospf6_zebra_sendrecv_cmd
,
839 "no debug ospf6 zebra [<send|recv>]",
843 "Debug connection between zebra\n"
844 "Debug Sending zebra\n"
845 "Debug Receiving zebra\n"
848 int idx_send_recv
= 4;
849 unsigned char level
= 0;
852 if (strmatch(argv
[idx_send_recv
]->text
, "send"))
853 level
= OSPF6_DEBUG_ZEBRA_SEND
;
854 else if (strmatch(argv
[idx_send_recv
]->text
, "recv"))
855 level
= OSPF6_DEBUG_ZEBRA_RECV
;
857 level
= OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
;
859 OSPF6_DEBUG_ZEBRA_OFF(level
);
864 int config_write_ospf6_debug_zebra(struct vty
*vty
)
866 if (IS_OSPF6_DEBUG_ZEBRA(SEND
) && IS_OSPF6_DEBUG_ZEBRA(RECV
))
867 vty_out(vty
, "debug ospf6 zebra%s", VNL
);
869 if (IS_OSPF6_DEBUG_ZEBRA(SEND
))
870 vty_out(vty
, "debug ospf6 zebra send%s", VNL
);
871 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
872 vty_out(vty
, "debug ospf6 zebra recv%s", VNL
);
877 void install_element_ospf6_debug_zebra(void)
879 install_element(ENABLE_NODE
, &debug_ospf6_zebra_sendrecv_cmd
);
880 install_element(ENABLE_NODE
, &no_debug_ospf6_zebra_sendrecv_cmd
);
881 install_element(CONFIG_NODE
, &debug_ospf6_zebra_sendrecv_cmd
);
882 install_element(CONFIG_NODE
, &no_debug_ospf6_zebra_sendrecv_cmd
);