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. */
54 ospf6_router_id_update_zebra (int command
, struct zclient
*zclient
,
55 zebra_size_t length
, vrf_id_t vrf_id
)
57 struct prefix router_id
;
58 struct ospf6
*o
= ospf6
;
60 zebra_router_id_update_read(zclient
->ibuf
,&router_id
);
61 router_id_zebra
= router_id
.u
.prefix4
;
66 if (o
->router_id
== 0)
67 o
->router_id
= (u_int32_t
) router_id_zebra
.s_addr
;
72 /* redistribute function */
74 ospf6_zebra_redistribute (int type
)
76 if (vrf_bitmap_check (zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
))
78 vrf_bitmap_set (zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
);
80 if (zclient
->sock
> 0)
81 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD
, zclient
, AFI_IP6
, type
, 0,
86 ospf6_zebra_no_redistribute (int type
)
88 if (!vrf_bitmap_check (zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
))
90 vrf_bitmap_unset (zclient
->redist
[AFI_IP6
][type
], VRF_DEFAULT
);
91 if (zclient
->sock
> 0)
92 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE
, zclient
, AFI_IP6
, type
,
96 /* Inteface addition message from zebra. */
98 ospf6_zebra_if_add (int command
, struct zclient
*zclient
, zebra_size_t length
,
101 struct interface
*ifp
;
103 ifp
= zebra_interface_add_read (zclient
->ibuf
, vrf_id
);
104 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
105 zlog_debug ("Zebra Interface add: %s index %d mtu %d",
106 ifp
->name
, ifp
->ifindex
, ifp
->mtu6
);
107 ospf6_interface_if_add (ifp
);
112 ospf6_zebra_if_del (int command
, struct zclient
*zclient
, zebra_size_t length
,
115 struct interface
*ifp
;
117 if (!(ifp
= zebra_interface_state_read (zclient
->ibuf
, vrf_id
)))
121 zlog_warn ("Zebra: got delete of %s, but interface is still up", ifp
->name
);
123 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
124 zlog_debug ("Zebra Interface delete: %s index %d mtu %d",
125 ifp
->name
, ifp
->ifindex
, ifp
->mtu6
);
128 /* XXX: ospf6_interface_if_del is not the right way to handle this,
129 * because among other thinkable issues, it will also clear all
130 * settings as they are contained in the struct ospf6_interface. */
131 ospf6_interface_if_del (ifp
);
134 ifp
->ifindex
= IFINDEX_DELETED
;
139 ospf6_zebra_if_state_update (int command
, struct zclient
*zclient
,
140 zebra_size_t length
, vrf_id_t vrf_id
)
142 struct interface
*ifp
;
144 ifp
= zebra_interface_state_read (zclient
->ibuf
, vrf_id
);
148 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
149 zlog_debug ("Zebra Interface state change: "
150 "%s index %d flags %llx metric %d mtu %d bandwidth %d",
151 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
152 ifp
->metric
, ifp
->mtu6
, ifp
->bandwidth
);
154 ospf6_interface_state_update (ifp
);
159 ospf6_zebra_if_address_update_add (int command
, struct zclient
*zclient
,
160 zebra_size_t length
, vrf_id_t vrf_id
)
165 c
= zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD
, zclient
->ibuf
,
170 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
171 zlog_debug ("Zebra Interface address add: %s %5s %s/%d",
172 c
->ifp
->name
, prefix_family_str (c
->address
),
173 inet_ntop (c
->address
->family
, &c
->address
->u
.prefix
,
174 buf
, sizeof (buf
)), c
->address
->prefixlen
);
176 if (c
->address
->family
== AF_INET6
)
178 ospf6_interface_state_update (c
->ifp
);
179 ospf6_interface_connected_route_update (c
->ifp
);
185 ospf6_zebra_if_address_update_delete (int command
, struct zclient
*zclient
,
186 zebra_size_t length
, vrf_id_t vrf_id
)
191 c
= zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE
, zclient
->ibuf
,
196 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
197 zlog_debug ("Zebra Interface address delete: %s %5s %s/%d",
198 c
->ifp
->name
, prefix_family_str (c
->address
),
199 inet_ntop (c
->address
->family
, &c
->address
->u
.prefix
,
200 buf
, sizeof (buf
)), c
->address
->prefixlen
);
202 if (c
->address
->family
== AF_INET6
)
204 ospf6_interface_connected_route_update (c
->ifp
);
205 ospf6_interface_state_update (c
->ifp
);
214 ospf6_zebra_read_ipv6 (int command
, struct zclient
*zclient
,
215 zebra_size_t length
, vrf_id_t vrf_id
)
218 struct zapi_ipv6 api
;
219 unsigned long ifindex
;
220 struct prefix p
, src_p
;
221 struct in6_addr
*nexthop
;
229 memset (&api
, 0, sizeof (api
));
231 /* Type, flags, message. */
232 api
.type
= stream_getc (s
);
233 api
.instance
= stream_getw (s
);
234 api
.flags
= stream_getl (s
);
235 api
.message
= stream_getc (s
);
238 memset (&p
, 0, sizeof (struct prefix
));
240 p
.prefixlen
= MIN(IPV6_MAX_PREFIXLEN
, stream_getc (s
));
241 stream_get (&p
.u
.prefix6
, s
, PSIZE (p
.prefixlen
));
243 memset (&src_p
, 0, sizeof (struct prefix
));
244 src_p
.family
= AF_INET6
;
245 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_SRCPFX
))
247 src_p
.prefixlen
= stream_getc (s
);
248 stream_get (&src_p
.u
.prefix6
, s
, PSIZE (src_p
.prefixlen
));
252 /* we completely ignore srcdest routes for now. */
255 /* Nexthop, ifindex, distance, metric. */
256 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
258 api
.nexthop_num
= stream_getc (s
);
259 nexthop
= (struct in6_addr
*)
260 malloc (api
.nexthop_num
* sizeof (struct in6_addr
));
261 stream_get (nexthop
, s
, api
.nexthop_num
* sizeof (struct in6_addr
));
263 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_IFINDEX
))
265 api
.ifindex_num
= stream_getc (s
);
266 ifindex
= stream_getl (s
);
268 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
))
269 api
.distance
= stream_getc (s
);
272 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
))
273 api
.metric
= stream_getl (s
);
277 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_TAG
))
278 api
.tag
= stream_getl (s
);
282 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
284 char prefixstr
[PREFIX2STR_BUFFER
], nexthopstr
[128];
285 prefix2str ((struct prefix
*)&p
, prefixstr
, sizeof (prefixstr
));
287 inet_ntop (AF_INET6
, nexthop
, nexthopstr
, sizeof (nexthopstr
));
289 snprintf (nexthopstr
, sizeof (nexthopstr
), "::");
291 zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld tag %"ROUTE_TAG_PRI
,
292 (command
== ZEBRA_REDISTRIBUTE_IPV6_ADD
? "add" : "delete"),
293 zebra_route_string(api
.type
), prefixstr
, nexthopstr
, ifindex
, api
.tag
);
296 if (command
== ZEBRA_REDISTRIBUTE_IPV6_ADD
)
297 ospf6_asbr_redistribute_add (api
.type
, ifindex
, &p
,
298 api
.nexthop_num
, nexthop
, api
.tag
);
300 ospf6_asbr_redistribute_remove (api
.type
, ifindex
, &p
);
302 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
315 "Zebra information\n")
320 vty_out (vty
, "Not connected to zebra%s", VNL
);
324 vty_out (vty
, "Zebra Infomation%s", VNL
);
325 vty_out (vty
, " enable: %d fail: %d%s",
326 zclient
->enable
, zclient
->fail
, VNL
);
327 vty_out (vty
, " redistribute default: %d%s",
328 vrf_bitmap_check (zclient
->default_information
, VRF_DEFAULT
),
330 vty_out (vty
, " redistribute:");
331 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
333 if (vrf_bitmap_check (zclient
->redist
[AFI_IP6
][i
], VRF_DEFAULT
))
334 vty_out (vty
, " %s", zebra_route_string(i
));
336 vty_out (vty
, "%s", VNL
);
340 /* Zebra configuration write function. */
342 config_write_ospf6_zebra (struct vty
*vty
)
344 if (! zclient
->enable
)
346 vty_out (vty
, "no router zebra%s", VNL
);
347 vty_out (vty
, "!%s", VNL
);
349 else if (! vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
352 vty_out (vty
, "router zebra%s", VNL
);
353 vty_out (vty
, " no redistribute ospf6%s", VNL
);
354 vty_out (vty
, "!%s", VNL
);
359 /* Zebra node structure. */
360 static struct cmd_node zebra_node
=
363 "%s(config-zebra)# ",
369 ospf6_zebra_route_update (int type
, struct ospf6_route
*request
)
371 struct zapi_ipv6 api
;
372 char buf
[PREFIX2STR_BUFFER
];
374 struct in6_addr
**nexthops
;
375 ifindex_t
*ifindexes
;
377 struct prefix_ipv6
*dest
;
379 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
381 prefix2str (&request
->prefix
, buf
, sizeof (buf
));
382 zlog_debug ("Send %s route: %s",
383 (type
== REM
? "remove" : "add"), buf
);
386 if (zclient
->sock
< 0)
388 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
389 zlog_debug (" Not connected to Zebra");
393 if (request
->path
.origin
.adv_router
== ospf6
->router_id
&&
394 (request
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
||
395 request
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
))
397 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
398 zlog_debug (" Ignore self-originated external route");
402 /* If removing is the best path and if there's another path,
403 treat this request as add the secondary path */
404 if (type
== REM
&& ospf6_route_is_best (request
) &&
405 request
->next
&& ospf6_route_is_same (request
, request
->next
))
407 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
408 zlog_debug (" Best-path removal resulted Sencondary addition");
410 request
= request
->next
;
413 /* Only the best path will be sent to zebra. */
414 if (! ospf6_route_is_best (request
))
416 /* this is not preferred best route, ignore */
417 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
418 zlog_debug (" Ignore non-best route");
422 nhcount
= ospf6_route_num_nexthops (request
);
425 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
426 zlog_debug (" No nexthop, ignore");
430 /* allocate memory for nexthop_list */
431 nexthops
= XCALLOC (MTYPE_OSPF6_OTHER
,
432 nhcount
* sizeof (struct in6_addr
*));
433 if (nexthops
== NULL
)
435 zlog_warn ("Can't send route to zebra: malloc failed");
439 /* allocate memory for ifindex_list */
440 ifindexes
= XCALLOC (MTYPE_OSPF6_OTHER
,
441 nhcount
* sizeof (ifindex_t
));
442 if (ifindexes
== NULL
)
444 zlog_warn ("Can't send route to zebra: malloc failed");
445 XFREE (MTYPE_OSPF6_OTHER
, nexthops
);
449 ospf6_route_zebra_copy_nexthops (request
, ifindexes
, nexthops
, nhcount
);
451 api
.vrf_id
= VRF_DEFAULT
;
452 api
.type
= ZEBRA_ROUTE_OSPF6
;
456 api
.safi
= SAFI_UNICAST
;
457 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
458 api
.nexthop_num
= nhcount
;
459 api
.nexthop
= nexthops
;
460 SET_FLAG (api
.message
, ZAPI_MESSAGE_IFINDEX
);
461 api
.ifindex_num
= nhcount
;
462 api
.ifindex
= ifindexes
;
463 SET_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
);
464 api
.metric
= (request
->path
.metric_type
== 2 ?
465 request
->path
.u
.cost_e2
: request
->path
.cost
);
466 if (request
->path
.tag
)
468 SET_FLAG (api
.message
, ZAPI_MESSAGE_TAG
);
469 api
.tag
= request
->path
.tag
;
472 dest
= (struct prefix_ipv6
*) &request
->prefix
;
474 SET_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
);
475 api
.distance
= ospf6_distance_apply (dest
, request
);
478 ret
= zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE
, zclient
, dest
, NULL
, &api
);
480 ret
= zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD
, zclient
, dest
, NULL
, &api
);
483 zlog_err ("zapi_ipv6_route() %s failed: %s",
484 (type
== REM
? "delete" : "add"), safe_strerror (errno
));
486 XFREE (MTYPE_OSPF6_OTHER
, nexthops
);
487 XFREE (MTYPE_OSPF6_OTHER
, ifindexes
);
493 ospf6_zebra_route_update_add (struct ospf6_route
*request
)
495 if (! vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
498 ospf6
->route_table
->hook_add
= NULL
;
499 ospf6
->route_table
->hook_remove
= NULL
;
502 ospf6_zebra_route_update (ADD
, request
);
506 ospf6_zebra_route_update_remove (struct ospf6_route
*request
)
508 if (! vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
511 ospf6
->route_table
->hook_add
= NULL
;
512 ospf6
->route_table
->hook_remove
= NULL
;
515 ospf6_zebra_route_update (REM
, request
);
519 ospf6_zebra_add_discard (struct ospf6_route
*request
)
521 struct zapi_ipv6 api
;
522 char buf
[INET6_ADDRSTRLEN
];
523 struct prefix_ipv6
*dest
;
525 if (vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
],
528 if (!CHECK_FLAG (request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
))
530 api
.vrf_id
= VRF_DEFAULT
;
531 api
.type
= ZEBRA_ROUTE_OSPF6
;
532 api
.flags
= ZEBRA_FLAG_BLACKHOLE
;
535 api
.safi
= SAFI_UNICAST
;
536 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
540 dest
= (struct prefix_ipv6
*) &request
->prefix
;
542 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD
, zclient
, dest
, NULL
, &api
);
544 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
545 zlog_debug ("Zebra: Route add discard %s/%d",
546 inet_ntop (AF_INET6
, &dest
->prefix
,
547 buf
, INET6_ADDRSTRLEN
),
549 SET_FLAG (request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
);
553 dest
= (struct prefix_ipv6
*) &request
->prefix
;
555 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
556 zlog_debug ("Zebra: Blackhole route present already %s/%d",
557 inet_ntop (AF_INET6
, &dest
->prefix
,
558 buf
, INET6_ADDRSTRLEN
),
565 ospf6_zebra_delete_discard (struct ospf6_route
*request
)
567 struct zapi_ipv6 api
;
568 char buf
[INET6_ADDRSTRLEN
];
569 struct prefix_ipv6
*dest
;
571 if (vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
], VRF_DEFAULT
))
573 if (CHECK_FLAG (request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
))
575 api
.vrf_id
= VRF_DEFAULT
;
576 api
.type
= ZEBRA_ROUTE_OSPF6
;
577 api
.flags
= ZEBRA_FLAG_BLACKHOLE
;
580 api
.safi
= SAFI_UNICAST
;
581 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
585 dest
= (struct prefix_ipv6
*) &request
->prefix
;
587 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE
, zclient
, dest
, NULL
, &api
);
589 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
590 zlog_debug ("Zebra: Route delete discard %s/%d",
591 inet_ntop (AF_INET6
, &dest
->prefix
, buf
,
592 INET6_ADDRSTRLEN
), dest
->prefixlen
);
593 UNSET_FLAG (request
->flag
, OSPF6_ROUTE_BLACKHOLE_ADDED
);
597 dest
= (struct prefix_ipv6
*) &request
->prefix
;
598 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
599 zlog_debug ("Zebra: Blackhole route already deleted %s/%d",
600 inet_ntop (AF_INET6
, &dest
->prefix
, buf
,
601 INET6_ADDRSTRLEN
), dest
->prefixlen
);
606 DEFUN (redistribute_ospf6
,
607 redistribute_ospf6_cmd
,
608 "redistribute ospf6",
609 "Redistribute control\n"
612 struct ospf6_route
*route
;
614 if (vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
], VRF_DEFAULT
))
617 vrf_bitmap_set (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
], VRF_DEFAULT
);
622 /* send ospf6 route to zebra route table */
623 for (route
= ospf6_route_head (ospf6
->route_table
); route
;
624 route
= ospf6_route_next (route
))
625 ospf6_zebra_route_update_add (route
);
627 ospf6
->route_table
->hook_add
= ospf6_zebra_route_update_add
;
628 ospf6
->route_table
->hook_remove
= ospf6_zebra_route_update_remove
;
633 DEFUN (no_redistribute_ospf6
,
634 no_redistribute_ospf6_cmd
,
635 "no redistribute ospf6",
637 "Redistribute control\n"
640 struct ospf6_route
*route
;
642 if (! vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
], VRF_DEFAULT
))
645 vrf_bitmap_unset (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_OSPF6
], VRF_DEFAULT
);
650 ospf6
->route_table
->hook_add
= NULL
;
651 ospf6
->route_table
->hook_remove
= NULL
;
653 /* withdraw ospf6 route from zebra route table */
654 for (route
= ospf6_route_head (ospf6
->route_table
); route
;
655 route
= ospf6_route_next (route
))
656 ospf6_zebra_route_update_remove (route
);
661 static struct ospf6_distance
*
662 ospf6_distance_new (void)
664 return XCALLOC (MTYPE_OSPF6_DISTANCE
, sizeof (struct ospf6_distance
));
668 ospf6_distance_free (struct ospf6_distance
*odistance
)
670 XFREE (MTYPE_OSPF6_DISTANCE
, odistance
);
674 ospf6_distance_set (struct vty
*vty
, struct ospf6
*o
,
675 const char *distance_str
,
677 const char *access_list_str
)
680 struct prefix_ipv6 p
;
682 struct route_node
*rn
;
683 struct ospf6_distance
*odistance
;
685 ret
= str2prefix_ipv6 (ip_str
, &p
);
688 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
692 distance
= atoi (distance_str
);
694 /* Get OSPF6 distance node. */
695 rn
= route_node_get (o
->distance_table
, (struct prefix
*) &p
);
698 odistance
= rn
->info
;
699 route_unlock_node (rn
);
703 odistance
= ospf6_distance_new ();
704 rn
->info
= odistance
;
707 /* Set distance value. */
708 odistance
->distance
= distance
;
710 /* Reset access-list configuration. */
711 if (odistance
->access_list
)
713 free (odistance
->access_list
);
714 odistance
->access_list
= NULL
;
717 odistance
->access_list
= strdup (access_list_str
);
723 ospf6_distance_unset (struct vty
*vty
, struct ospf6
*o
,
724 const char *distance_str
,
726 const char *access_list_str
)
729 struct prefix_ipv6 p
;
730 struct route_node
*rn
;
731 struct ospf6_distance
*odistance
;
733 ret
= str2prefix_ipv6 (ip_str
, &p
);
736 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
740 rn
= route_node_lookup (o
->distance_table
, (struct prefix
*) &p
);
743 vty_out (vty
, "Cant't find specified prefix%s", VTY_NEWLINE
);
747 odistance
= rn
->info
;
749 if (odistance
->access_list
)
750 free (odistance
->access_list
);
751 ospf6_distance_free (odistance
);
754 route_unlock_node (rn
);
755 route_unlock_node (rn
);
761 ospf6_distance_reset (struct ospf6
*o
)
763 struct route_node
*rn
;
764 struct ospf6_distance
*odistance
;
766 for (rn
= route_top (o
->distance_table
); rn
; rn
= route_next (rn
))
767 if ((odistance
= rn
->info
) != NULL
)
769 if (odistance
->access_list
)
770 free (odistance
->access_list
);
771 ospf6_distance_free (odistance
);
773 route_unlock_node (rn
);
778 ospf6_distance_apply (struct prefix_ipv6
*p
, struct ospf6_route
*or)
786 if (o
->distance_intra
)
787 if (or->path
.type
== OSPF6_PATH_TYPE_INTRA
)
788 return o
->distance_intra
;
790 if (o
->distance_inter
)
791 if (or->path
.type
== OSPF6_PATH_TYPE_INTER
)
792 return o
->distance_inter
;
794 if (o
->distance_external
)
795 if(or->path
.type
== OSPF6_PATH_TYPE_EXTERNAL1
796 || or->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
)
797 return o
->distance_external
;
800 return o
->distance_all
;
806 ospf6_zebra_connected (struct zclient
*zclient
)
808 /* Send the client registration */
809 bfd_client_sendmsg(zclient
, ZEBRA_BFD_CLIENT_REGISTER
);
811 zclient_send_reg_requests (zclient
, VRF_DEFAULT
);
815 ospf6_zebra_init (struct thread_master
*master
)
817 /* Allocate zebra structure. */
818 zclient
= zclient_new(master
);
819 zclient_init (zclient
, ZEBRA_ROUTE_OSPF6
, 0);
820 zclient
->zebra_connected
= ospf6_zebra_connected
;
821 zclient
->router_id_update
= ospf6_router_id_update_zebra
;
822 zclient
->interface_add
= ospf6_zebra_if_add
;
823 zclient
->interface_delete
= ospf6_zebra_if_del
;
824 zclient
->interface_up
= ospf6_zebra_if_state_update
;
825 zclient
->interface_down
= ospf6_zebra_if_state_update
;
826 zclient
->interface_address_add
= ospf6_zebra_if_address_update_add
;
827 zclient
->interface_address_delete
= ospf6_zebra_if_address_update_delete
;
828 zclient
->redistribute_route_ipv4_add
= NULL
;
829 zclient
->redistribute_route_ipv4_del
= NULL
;
830 zclient
->redistribute_route_ipv6_add
= ospf6_zebra_read_ipv6
;
831 zclient
->redistribute_route_ipv6_del
= ospf6_zebra_read_ipv6
;
833 /* redistribute connected route by default */
834 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
836 /* Install zebra node. */
837 install_node (&zebra_node
, config_write_ospf6_zebra
);
839 /* Install command element for zebra node. */
840 install_element (VIEW_NODE
, &show_zebra_cmd
);
841 install_default (ZEBRA_NODE
);
842 install_element (ZEBRA_NODE
, &redistribute_ospf6_cmd
);
843 install_element (ZEBRA_NODE
, &no_redistribute_ospf6_cmd
);
850 DEFUN (debug_ospf6_zebra_sendrecv
,
851 debug_ospf6_zebra_sendrecv_cmd
,
852 "debug ospf6 zebra [<send|recv>]",
855 "Debug connection between zebra\n"
856 "Debug Sending zebra\n"
857 "Debug Receiving zebra\n"
860 int idx_send_recv
= 3;
861 unsigned char level
= 0;
865 if (strmatch(argv
[idx_send_recv
]->text
, "send"))
866 level
= OSPF6_DEBUG_ZEBRA_SEND
;
867 else if (strmatch(argv
[idx_send_recv
]->text
, "recv"))
868 level
= OSPF6_DEBUG_ZEBRA_RECV
;
871 level
= OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
;
873 OSPF6_DEBUG_ZEBRA_ON (level
);
877 DEFUN (no_debug_ospf6_zebra_sendrecv
,
878 no_debug_ospf6_zebra_sendrecv_cmd
,
879 "no debug ospf6 zebra [<send|recv>]",
883 "Debug connection between zebra\n"
884 "Debug Sending zebra\n"
885 "Debug Receiving zebra\n"
888 int idx_send_recv
= 4;
889 unsigned char level
= 0;
893 if (strmatch(argv
[idx_send_recv
]->text
, "send"))
894 level
= OSPF6_DEBUG_ZEBRA_SEND
;
895 else if (strmatch(argv
[idx_send_recv
]->text
, "recv"))
896 level
= OSPF6_DEBUG_ZEBRA_RECV
;
899 level
= OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
;
901 OSPF6_DEBUG_ZEBRA_OFF (level
);
907 config_write_ospf6_debug_zebra (struct vty
*vty
)
909 if (IS_OSPF6_DEBUG_ZEBRA (SEND
) && IS_OSPF6_DEBUG_ZEBRA (RECV
))
910 vty_out (vty
, "debug ospf6 zebra%s", VNL
);
913 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
914 vty_out (vty
, "debug ospf6 zebra send%s", VNL
);
915 if (IS_OSPF6_DEBUG_ZEBRA (RECV
))
916 vty_out (vty
, "debug ospf6 zebra recv%s", VNL
);
922 install_element_ospf6_debug_zebra (void)
924 install_element (ENABLE_NODE
, &debug_ospf6_zebra_sendrecv_cmd
);
925 install_element (ENABLE_NODE
, &no_debug_ospf6_zebra_sendrecv_cmd
);
926 install_element (CONFIG_NODE
, &debug_ospf6_zebra_sendrecv_cmd
);
927 install_element (CONFIG_NODE
, &no_debug_ospf6_zebra_sendrecv_cmd
);