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. */
53 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 */
73 ospf6_zebra_redistribute (int type
)
75 if (vrf_bitmap_check (zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
))
77 vrf_bitmap_set (zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
);
79 if (zclient
->sock
> 0)
80 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD
, zclient
, AFI_IP6
, type
, 0,
85 ospf6_zebra_no_redistribute (int type
)
87 if (!vrf_bitmap_check (zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
))
89 vrf_bitmap_unset (zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
);
90 if (zclient
->sock
> 0)
91 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE
, zclient
, AFI_IP6
, type
,
95 /* Inteface addition message from zebra. */
97 ospf6_zebra_if_add (int command
, struct zclient
*zclient
, zebra_size_t length
,
100 struct interface
*ifp
;
102 ifp
= zebra_interface_add_read (zclient
->ibuf
, vrf_id
);
103 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
104 zlog_debug ("Zebra Interface add: %s index %d mtu %d",
105 ifp
->name
, ifp
->ifindex
, ifp
->mtu6
);
106 ospf6_interface_if_add (ifp
);
111 ospf6_zebra_if_del (int command
, struct zclient
*zclient
, zebra_size_t length
,
114 struct interface
*ifp
;
116 if (!(ifp
= zebra_interface_state_read (zclient
->ibuf
, vrf_id
)))
120 zlog_warn ("Zebra: got delete of %s, but interface is still up", ifp
->name
);
122 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
123 zlog_debug ("Zebra Interface delete: %s index %d mtu %d",
124 ifp
->name
, ifp
->ifindex
, ifp
->mtu6
);
127 /* XXX: ospf6_interface_if_del is not the right way to handle this,
128 * because among other thinkable issues, it will also clear all
129 * settings as they are contained in the struct ospf6_interface. */
130 ospf6_interface_if_del (ifp
);
133 ifp
->ifindex
= IFINDEX_DELETED
;
138 ospf6_zebra_if_state_update (int command
, struct zclient
*zclient
,
139 zebra_size_t length
, vrf_id_t vrf_id
)
141 struct interface
*ifp
;
143 ifp
= zebra_interface_state_read (zclient
->ibuf
, vrf_id
);
147 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
148 zlog_debug ("Zebra Interface state change: "
149 "%s index %d flags %llx metric %d mtu %d bandwidth %d",
150 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
151 ifp
->metric
, ifp
->mtu6
, ifp
->bandwidth
);
153 ospf6_interface_state_update (ifp
);
158 ospf6_zebra_if_address_update_add (int command
, struct zclient
*zclient
,
159 zebra_size_t length
, vrf_id_t vrf_id
)
164 c
= zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD
, zclient
->ibuf
,
169 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
170 zlog_debug ("Zebra Interface address add: %s %5s %s/%d",
171 c
->ifp
->name
, prefix_family_str (c
->address
),
172 inet_ntop (c
->address
->family
, &c
->address
->u
.prefix
,
173 buf
, sizeof (buf
)), c
->address
->prefixlen
);
175 if (c
->address
->family
== AF_INET6
)
177 ospf6_interface_state_update (c
->ifp
);
178 ospf6_interface_connected_route_update (c
->ifp
);
184 ospf6_zebra_if_address_update_delete (int command
, struct zclient
*zclient
,
185 zebra_size_t length
, vrf_id_t vrf_id
)
190 c
= zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE
, zclient
->ibuf
,
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
)), c
->address
->prefixlen
);
201 if (c
->address
->family
== AF_INET6
)
203 ospf6_interface_connected_route_update (c
->ifp
);
204 ospf6_interface_state_update (c
->ifp
);
213 ospf6_zebra_read_ipv6 (int command
, struct zclient
*zclient
,
214 zebra_size_t length
, vrf_id_t vrf_id
)
217 struct zapi_ipv6 api
;
218 unsigned long ifindex
;
219 struct prefix p
, src_p
;
220 struct in6_addr
*nexthop
;
228 memset (&api
, 0, sizeof (api
));
230 /* Type, flags, message. */
231 api
.type
= stream_getc (s
);
232 api
.instance
= stream_getw (s
);
233 api
.flags
= stream_getl (s
);
234 api
.message
= stream_getc (s
);
237 memset (&p
, 0, sizeof (struct prefix
));
239 p
.prefixlen
= MIN(IPV6_MAX_PREFIXLEN
, stream_getc (s
));
240 stream_get (&p
.u
.prefix6
, s
, PSIZE (p
.prefixlen
));
242 memset (&src_p
, 0, sizeof (struct prefix
));
243 src_p
.family
= AF_INET6
;
244 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_SRCPFX
))
246 src_p
.prefixlen
= stream_getc (s
);
247 stream_get (&src_p
.u
.prefix6
, s
, PSIZE (src_p
.prefixlen
));
251 /* we completely ignore srcdest routes for now. */
254 /* Nexthop, ifindex, distance, metric. */
255 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
257 api
.nexthop_num
= stream_getc (s
);
258 nexthop
= (struct in6_addr
*)
259 malloc (api
.nexthop_num
* sizeof (struct in6_addr
));
260 stream_get (nexthop
, s
, api
.nexthop_num
* sizeof (struct in6_addr
));
262 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_IFINDEX
))
264 api
.ifindex_num
= stream_getc (s
);
265 ifindex
= stream_getl (s
);
267 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
))
268 api
.distance
= stream_getc (s
);
271 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
))
272 api
.metric
= stream_getl (s
);
276 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_TAG
))
277 api
.tag
= stream_getl (s
);
281 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
283 char prefixstr
[PREFIX2STR_BUFFER
], nexthopstr
[128];
284 prefix2str ((struct prefix
*)&p
, prefixstr
, sizeof (prefixstr
));
286 inet_ntop (AF_INET6
, nexthop
, nexthopstr
, sizeof (nexthopstr
));
288 snprintf (nexthopstr
, sizeof (nexthopstr
), "::");
290 zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld tag %"ROUTE_TAG_PRI
,
291 (command
== ZEBRA_REDISTRIBUTE_IPV6_ADD
? "add" : "delete"),
292 zebra_route_string(api
.type
), prefixstr
, nexthopstr
, ifindex
, api
.tag
);
295 if (command
== ZEBRA_REDISTRIBUTE_IPV6_ADD
)
296 ospf6_asbr_redistribute_add (api
.type
, ifindex
, &p
,
297 api
.nexthop_num
, nexthop
, api
.tag
);
299 ospf6_asbr_redistribute_remove (api
.type
, ifindex
, &p
);
301 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
314 "Zebra information\n")
319 vty_out (vty
, "Not connected to zebra%s", VNL
);
323 vty_out (vty
, "Zebra Infomation%s", VNL
);
324 vty_out (vty
, " enable: %d fail: %d%s",
325 zclient
->enable
, zclient
->fail
, VNL
);
326 vty_out (vty
, " redistribute default: %d%s",
327 vrf_bitmap_check (zclient
->default_information
, VRF_DEFAULT
),
329 vty_out (vty
, " redistribute:");
330 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
332 if (vrf_bitmap_check (zclient
->redist
[AFI_IP6
][i
], VRF_DEFAULT
))
333 vty_out (vty
, " %s", zebra_route_string(i
));
335 vty_out (vty
, "%s", VNL
);
339 /* Zebra configuration write function. */
341 config_write_ospf6_zebra (struct vty
*vty
)
343 if (! zclient
->enable
)
345 vty_out (vty
, "no router zebra%s", VNL
);
346 vty_out (vty
, "!%s", VNL
);
348 else if (! vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
351 vty_out (vty
, "router zebra%s", VNL
);
352 vty_out (vty
, " no redistribute ospf6%s", VNL
);
353 vty_out (vty
, "!%s", VNL
);
358 /* Zebra node structure. */
359 static struct cmd_node zebra_node
=
362 "%s(config-zebra)# ",
368 ospf6_zebra_route_update (int type
, struct ospf6_route
*request
)
370 struct zapi_ipv6 api
;
371 char buf
[PREFIX2STR_BUFFER
];
373 struct in6_addr
**nexthops
;
374 ifindex_t
*ifindexes
;
376 struct prefix_ipv6
*dest
;
378 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
380 prefix2str (&request
->prefix
, buf
, sizeof (buf
));
381 zlog_debug ("Send %s route: %s",
382 (type
== REM
? "remove" : "add"), buf
);
385 if (zclient
->sock
< 0)
387 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
388 zlog_debug (" Not connected to Zebra");
392 if (request
->path
.origin
.adv_router
== ospf6
->router_id
&&
393 (request
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
||
394 request
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
))
396 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
397 zlog_debug (" Ignore self-originated external route");
401 /* If removing is the best path and if there's another path,
402 treat this request as add the secondary path */
403 if (type
== REM
&& ospf6_route_is_best (request
) &&
404 request
->next
&& ospf6_route_is_same (request
, request
->next
))
406 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
407 zlog_debug (" Best-path removal resulted Sencondary addition");
409 request
= request
->next
;
412 /* Only the best path will be sent to zebra. */
413 if (! ospf6_route_is_best (request
))
415 /* this is not preferred best route, ignore */
416 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
417 zlog_debug (" Ignore non-best route");
421 nhcount
= ospf6_route_num_nexthops (request
);
424 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
425 zlog_debug (" No nexthop, ignore");
429 /* allocate memory for nexthop_list */
430 nexthops
= XCALLOC (MTYPE_OSPF6_OTHER
,
431 nhcount
* sizeof (struct in6_addr
*));
432 if (nexthops
== NULL
)
434 zlog_warn ("Can't send route to zebra: malloc failed");
438 /* allocate memory for ifindex_list */
439 ifindexes
= XCALLOC (MTYPE_OSPF6_OTHER
,
440 nhcount
* sizeof (ifindex_t
));
441 if (ifindexes
== NULL
)
443 zlog_warn ("Can't send route to zebra: malloc failed");
444 XFREE (MTYPE_OSPF6_OTHER
, nexthops
);
448 ospf6_route_zebra_copy_nexthops (request
, ifindexes
, nexthops
, nhcount
);
450 api
.vrf_id
= VRF_DEFAULT
;
451 api
.type
= ZEBRA_ROUTE_OSPF6
;
455 api
.safi
= SAFI_UNICAST
;
456 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
457 api
.nexthop_num
= nhcount
;
458 api
.nexthop
= nexthops
;
459 SET_FLAG (api
.message
, ZAPI_MESSAGE_IFINDEX
);
460 api
.ifindex_num
= nhcount
;
461 api
.ifindex
= ifindexes
;
462 SET_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
);
463 api
.metric
= (request
->path
.metric_type
== 2 ?
464 request
->path
.u
.cost_e2
: request
->path
.cost
);
465 if (request
->path
.tag
)
467 SET_FLAG (api
.message
, ZAPI_MESSAGE_TAG
);
468 api
.tag
= request
->path
.tag
;
471 dest
= (struct prefix_ipv6
*) &request
->prefix
;
473 SET_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
);
474 api
.distance
= ospf6_distance_apply (dest
, request
);
477 ret
= zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE
, zclient
, dest
, NULL
, &api
);
479 ret
= zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD
, zclient
, dest
, NULL
, &api
);
482 zlog_err ("zapi_ipv6_route() %s failed: %s",
483 (type
== REM
? "delete" : "add"), safe_strerror (errno
));
485 XFREE (MTYPE_OSPF6_OTHER
, nexthops
);
486 XFREE (MTYPE_OSPF6_OTHER
, ifindexes
);
492 ospf6_zebra_route_update_add (struct ospf6_route
*request
)
494 if (! vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
497 ospf6
->route_table
->hook_add
= NULL
;
498 ospf6
->route_table
->hook_remove
= NULL
;
501 ospf6_zebra_route_update (ADD
, request
);
505 ospf6_zebra_route_update_remove (struct ospf6_route
*request
)
507 if (! vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
510 ospf6
->route_table
->hook_add
= NULL
;
511 ospf6
->route_table
->hook_remove
= NULL
;
514 ospf6_zebra_route_update (REM
, request
);
518 ospf6_zebra_add_discard (struct ospf6_route
*request
)
520 struct zapi_ipv6 api
;
521 char buf
[INET6_ADDRSTRLEN
];
522 struct prefix_ipv6
*dest
;
524 if (vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
527 if (!CHECK_FLAG (request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
))
529 api
.vrf_id
= VRF_DEFAULT
;
530 api
.type
= ZEBRA_ROUTE_OSPF6
;
531 api
.flags
= ZEBRA_FLAG_BLACKHOLE
;
534 api
.safi
= SAFI_UNICAST
;
535 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
539 dest
= (struct prefix_ipv6
*) &request
->prefix
;
541 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD
, zclient
, dest
, NULL
, &api
);
543 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
544 zlog_debug ("Zebra: Route add discard %s/%d",
545 inet_ntop (AF_INET6
, &dest
->prefix
,
546 buf
, INET6_ADDRSTRLEN
),
548 SET_FLAG (request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
);
552 dest
= (struct prefix_ipv6
*) &request
->prefix
;
554 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
555 zlog_debug ("Zebra: Blackhole route present already %s/%d",
556 inet_ntop (AF_INET6
, &dest
->prefix
,
557 buf
, INET6_ADDRSTRLEN
),
564 ospf6_zebra_delete_discard (struct ospf6_route
*request
)
566 struct zapi_ipv6 api
;
567 char buf
[INET6_ADDRSTRLEN
];
568 struct prefix_ipv6
*dest
;
570 if (vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
], VRF_DEFAULT
))
572 if (CHECK_FLAG (request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
))
574 api
.vrf_id
= VRF_DEFAULT
;
575 api
.type
= ZEBRA_ROUTE_OSPF6
;
576 api
.flags
= ZEBRA_FLAG_BLACKHOLE
;
579 api
.safi
= SAFI_UNICAST
;
580 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
584 dest
= (struct prefix_ipv6
*) &request
->prefix
;
586 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE
, zclient
, dest
, NULL
, &api
);
588 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
589 zlog_debug ("Zebra: Route delete discard %s/%d",
590 inet_ntop (AF_INET6
, &dest
->prefix
, buf
,
591 INET6_ADDRSTRLEN
), dest
->prefixlen
);
592 UNSET_FLAG (request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
);
596 dest
= (struct prefix_ipv6
*) &request
->prefix
;
597 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
598 zlog_debug ("Zebra: Blackhole route already deleted %s/%d",
599 inet_ntop (AF_INET6
, &dest
->prefix
, buf
,
600 INET6_ADDRSTRLEN
), dest
->prefixlen
);
605 DEFUN (redistribute_ospf6
,
606 redistribute_ospf6_cmd
,
607 "redistribute ospf6",
608 "Redistribute control\n"
611 struct ospf6_route
*route
;
613 if (vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
], VRF_DEFAULT
))
616 vrf_bitmap_set (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
], VRF_DEFAULT
);
621 /* send ospf6 route to zebra route table */
622 for (route
= ospf6_route_head (ospf6
->route_table
); route
;
623 route
= ospf6_route_next (route
))
624 ospf6_zebra_route_update_add (route
);
626 ospf6
->route_table
->hook_add
= ospf6_zebra_route_update_add
;
627 ospf6
->route_table
->hook_remove
= ospf6_zebra_route_update_remove
;
632 DEFUN (no_redistribute_ospf6
,
633 no_redistribute_ospf6_cmd
,
634 "no redistribute ospf6",
636 "Redistribute control\n"
639 struct ospf6_route
*route
;
641 if (! vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
], VRF_DEFAULT
))
644 vrf_bitmap_unset (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
], VRF_DEFAULT
);
649 ospf6
->route_table
->hook_add
= NULL
;
650 ospf6
->route_table
->hook_remove
= NULL
;
652 /* withdraw ospf6 route from zebra route table */
653 for (route
= ospf6_route_head (ospf6
->route_table
); route
;
654 route
= ospf6_route_next (route
))
655 ospf6_zebra_route_update_remove (route
);
660 static struct ospf6_distance
*
661 ospf6_distance_new (void)
663 return XCALLOC (MTYPE_OSPF6_DISTANCE
, sizeof (struct ospf6_distance
));
667 ospf6_distance_free (struct ospf6_distance
*odistance
)
669 XFREE (MTYPE_OSPF6_DISTANCE
, odistance
);
673 ospf6_distance_set (struct vty
*vty
, struct ospf6
*o
,
674 const char *distance_str
,
676 const char *access_list_str
)
679 struct prefix_ipv6 p
;
681 struct route_node
*rn
;
682 struct ospf6_distance
*odistance
;
684 ret
= str2prefix_ipv6 (ip_str
, &p
);
687 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
691 distance
= atoi (distance_str
);
693 /* Get OSPF6 distance node. */
694 rn
= route_node_get (o
->distance_table
, (struct prefix
*) &p
);
697 odistance
= rn
->info
;
698 route_unlock_node (rn
);
702 odistance
= ospf6_distance_new ();
703 rn
->info
= odistance
;
706 /* Set distance value. */
707 odistance
->distance
= distance
;
709 /* Reset access-list configuration. */
710 if (odistance
->access_list
)
712 free (odistance
->access_list
);
713 odistance
->access_list
= NULL
;
716 odistance
->access_list
= strdup (access_list_str
);
722 ospf6_distance_unset (struct vty
*vty
, struct ospf6
*o
,
723 const char *distance_str
,
725 const char *access_list_str
)
728 struct prefix_ipv6 p
;
729 struct route_node
*rn
;
730 struct ospf6_distance
*odistance
;
732 ret
= str2prefix_ipv6 (ip_str
, &p
);
735 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
739 rn
= route_node_lookup (o
->distance_table
, (struct prefix
*) &p
);
742 vty_out (vty
, "Cant't find specified prefix%s", VTY_NEWLINE
);
746 odistance
= rn
->info
;
748 if (odistance
->access_list
)
749 free (odistance
->access_list
);
750 ospf6_distance_free (odistance
);
753 route_unlock_node (rn
);
754 route_unlock_node (rn
);
760 ospf6_distance_reset (struct ospf6
*o
)
762 struct route_node
*rn
;
763 struct ospf6_distance
*odistance
;
765 for (rn
= route_top (o
->distance_table
); rn
; rn
= route_next (rn
))
766 if ((odistance
= rn
->info
) != NULL
)
768 if (odistance
->access_list
)
769 free (odistance
->access_list
);
770 ospf6_distance_free (odistance
);
772 route_unlock_node (rn
);
777 ospf6_distance_apply (struct prefix_ipv6
*p
, struct ospf6_route
*or)
785 if (o
->distance_intra
)
786 if (or->path
.type
== OSPF6_PATH_TYPE_INTRA
)
787 return o
->distance_intra
;
789 if (o
->distance_inter
)
790 if (or->path
.type
== OSPF6_PATH_TYPE_INTER
)
791 return o
->distance_inter
;
793 if (o
->distance_external
)
794 if(or->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
795 || or->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
)
796 return o
->distance_external
;
799 return o
->distance_all
;
805 ospf6_zebra_connected (struct zclient
*zclient
)
807 /* Send the client registration */
808 bfd_client_sendmsg(zclient
, ZEBRA_BFD_CLIENT_REGISTER
);
810 zclient_send_reg_requests (zclient
, VRF_DEFAULT
);
814 ospf6_zebra_init (struct thread_master
*master
)
816 /* Allocate zebra structure. */
817 zclient
= zclient_new(master
);
818 zclient_init (zclient
, ZEBRA_ROUTE_OSPF6
, 0);
819 zclient
->zebra_connected
= ospf6_zebra_connected
;
820 zclient
->router_id_update
= ospf6_router_id_update_zebra
;
821 zclient
->interface_add
= ospf6_zebra_if_add
;
822 zclient
->interface_delete
= ospf6_zebra_if_del
;
823 zclient
->interface_up
= ospf6_zebra_if_state_update
;
824 zclient
->interface_down
= ospf6_zebra_if_state_update
;
825 zclient
->interface_address_add
= ospf6_zebra_if_address_update_add
;
826 zclient
->interface_address_delete
= ospf6_zebra_if_address_update_delete
;
827 zclient
->redistribute_route_ipv4_add
= NULL
;
828 zclient
->redistribute_route_ipv4_del
= NULL
;
829 zclient
->redistribute_route_ipv6_add
= ospf6_zebra_read_ipv6
;
830 zclient
->redistribute_route_ipv6_del
= ospf6_zebra_read_ipv6
;
832 /* redistribute connected route by default */
833 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
835 /* Install zebra node. */
836 install_node (&zebra_node
, config_write_ospf6_zebra
);
838 /* Install command element for zebra node. */
839 install_element (VIEW_NODE
, &show_zebra_cmd
);
840 install_default (ZEBRA_NODE
);
841 install_element (ZEBRA_NODE
, &redistribute_ospf6_cmd
);
842 install_element (ZEBRA_NODE
, &no_redistribute_ospf6_cmd
);
849 DEFUN (debug_ospf6_zebra_sendrecv
,
850 debug_ospf6_zebra_sendrecv_cmd
,
851 "debug ospf6 zebra [<send|recv>]",
854 "Debug connection between zebra\n"
855 "Debug Sending zebra\n"
856 "Debug Receiving zebra\n"
859 int idx_send_recv
= 3;
860 unsigned char level
= 0;
864 if (strmatch(argv
[idx_send_recv
]->text
, "send"))
865 level
= OSPF6_DEBUG_ZEBRA_SEND
;
866 else if (strmatch(argv
[idx_send_recv
]->text
, "recv"))
867 level
= OSPF6_DEBUG_ZEBRA_RECV
;
870 level
= OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
;
872 OSPF6_DEBUG_ZEBRA_ON (level
);
876 DEFUN (no_debug_ospf6_zebra_sendrecv
,
877 no_debug_ospf6_zebra_sendrecv_cmd
,
878 "no debug ospf6 zebra [<send|recv>]",
882 "Debug connection between zebra\n"
883 "Debug Sending zebra\n"
884 "Debug Receiving zebra\n"
887 int idx_send_recv
= 4;
888 unsigned char level
= 0;
892 if (strmatch(argv
[idx_send_recv
]->text
, "send"))
893 level
= OSPF6_DEBUG_ZEBRA_SEND
;
894 else if (strmatch(argv
[idx_send_recv
]->text
, "recv"))
895 level
= OSPF6_DEBUG_ZEBRA_RECV
;
898 level
= OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
;
900 OSPF6_DEBUG_ZEBRA_OFF (level
);
906 config_write_ospf6_debug_zebra (struct vty
*vty
)
908 if (IS_OSPF6_DEBUG_ZEBRA (SEND
) && IS_OSPF6_DEBUG_ZEBRA (RECV
))
909 vty_out (vty
, "debug ospf6 zebra%s", VNL
);
912 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
913 vty_out (vty
, "debug ospf6 zebra send%s", VNL
);
914 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
915 vty_out (vty
, "debug ospf6 zebra recv%s", VNL
);
921 install_element_ospf6_debug_zebra (void)
923 install_element (ENABLE_NODE
, &debug_ospf6_zebra_sendrecv_cmd
);
924 install_element (ENABLE_NODE
, &no_debug_ospf6_zebra_sendrecv_cmd
);
925 install_element (CONFIG_NODE
, &debug_ospf6_zebra_sendrecv_cmd
);
926 install_element (CONFIG_NODE
, &no_debug_ospf6_zebra_sendrecv_cmd
);