diff options
Diffstat (limited to 'ospf6d/ospf6_zebra.c')
-rw-r--r-- | ospf6d/ospf6_zebra.c | 590 |
1 files changed, 265 insertions, 325 deletions
diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 4e8815f31..b62208665 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1999 Yasuhiro Ohara + * Copyright (C) 2003 Yasuhiro Ohara * * This file is part of GNU Zebra. * @@ -19,12 +19,26 @@ * Boston, MA 02111-1307, USA. */ -#include "ospf6d.h" +#include <zebra.h> + +#include "log.h" +#include "vty.h" +#include "command.h" +#include "prefix.h" +#include "stream.h" +#include "zclient.h" +#include "memory.h" +#include "ospf6d.h" +#include "ospf6_proto.h" +#include "ospf6_top.h" #include "ospf6_interface.h" +#include "ospf6_route.h" +#include "ospf6_lsa.h" #include "ospf6_asbr.h" +#include "ospf6_zebra.h" -#include "ospf6_linklist.h" +unsigned char conf_debug_ospf6_zebra = 0; /* information about zebra. */ struct zclient *zclient = NULL; @@ -33,50 +47,23 @@ struct zclient *zclient = NULL; void ospf6_zebra_redistribute (int type) { - int top_change = 0; - if (zclient->redist[type]) return; - - if (! ospf6_is_asbr (ospf6)) - top_change = 1; - zclient->redist[type] = 1; - if (zclient->sock > 0) zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient->sock, type); - - if (top_change) - CALL_CHANGE_HOOK (&top_hook, ospf6); } void ospf6_zebra_no_redistribute (int type) { - int top_change = 0; - - if (!zclient->redist[type]) + if (! zclient->redist[type]) return; - - if (ospf6_is_asbr (ospf6)) - top_change = 1; - zclient->redist[type] = 0; - if (zclient->sock > 0) zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient->sock, type); - - if (top_change) - CALL_CHANGE_HOOK (&top_hook, ospf6); -} - -int -ospf6_zebra_is_redistribute (int type) -{ - return zclient->redist[type]; } - /* Inteface addition message from zebra. */ int ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length) @@ -84,14 +71,10 @@ ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length) struct interface *ifp; ifp = zebra_interface_add_read (zclient->ibuf); - - /* log */ - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: I/F add: %s index %d mtu %d", + if (IS_OSPF6_DEBUG_ZEBRA (RECV)) + zlog_info ("Zebra Interface add: %s index %d mtu %d", ifp->name, ifp->ifindex, ifp->mtu); - ospf6_interface_if_add (ifp); - return 0; } @@ -99,18 +82,15 @@ int ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length) { #if 0 - struct interface *ifp = NULL; + struct interface *ifp; ifp = zebra_interface_delete_read (zclient->ibuf); - - /* log */ - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: I/F delete: %s index %d mtu %d", + if (IS_OSPF6_DEBUG_ZEBRA (RECV)) + zlog_info ("Zebra Interface delete: %s index %d mtu %d", ifp->name, ifp->ifindex, ifp->mtu); ospf6_interface_if_del (ifp); -#endif - +#endif /*0*/ return 0; } @@ -121,10 +101,9 @@ ospf6_zebra_if_state_update (int command, struct zclient *zclient, struct interface *ifp; ifp = zebra_interface_state_read (zclient->ibuf); - - /* log */ - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: I/F %s state change: index %d flags %ld metric %d mtu %d", + if (IS_OSPF6_DEBUG_ZEBRA (RECV)) + zlog_info ("Zebra Interface state change: " + "%s index %d flags %ld metric %d mtu %d", ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); ospf6_interface_state_update (ifp); @@ -133,7 +112,7 @@ ospf6_zebra_if_state_update (int command, struct zclient *zclient, int ospf6_zebra_if_address_update_add (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length) { struct connected *c; char buf[128]; @@ -142,14 +121,14 @@ ospf6_zebra_if_address_update_add (int command, struct zclient *zclient, if (c == NULL) return 0; - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: I/F %s address add: %5s %s/%d", + if (IS_OSPF6_DEBUG_ZEBRA (RECV)) + zlog_info ("Zebra Interface address add: %s %5s %s/%d", c->ifp->name, prefix_family_str (c->address), inet_ntop (c->address->family, &c->address->u.prefix, buf, sizeof (buf)), c->address->prefixlen); if (c->address->family == AF_INET6) - ospf6_interface_address_update (c->ifp); + ospf6_interface_connected_route_update (c->ifp); return 0; } @@ -165,14 +144,14 @@ ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient, if (c == NULL) return 0; - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: I/F %s address del: %5s %s/%d", + if (IS_OSPF6_DEBUG_ZEBRA (RECV)) + zlog_info ("Zebra Interface address delete: %s %5s %s/%d", c->ifp->name, prefix_family_str (c->address), inet_ntop (c->address->family, &c->address->u.prefix, buf, sizeof (buf)), c->address->prefixlen); if (c->address->family == AF_INET6) - ospf6_interface_address_update (c->ifp); + ospf6_interface_connected_route_update (c->ifp); return 0; } @@ -180,17 +159,8 @@ ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient, const char *zebra_route_name[ZEBRA_ROUTE_MAX] = -{ - "System", - "Kernel", - "Connect", - "Static", - "RIP", - "RIPng", - "OSPF", - "OSPF6", - "BGP", -}; + { "System", "Kernel", "Connect", "Static", "RIP", "RIPng", "OSPF", + "OSPF6", "BGP" }; const char *zebra_route_abname[ZEBRA_ROUTE_MAX] = { "X", "K", "C", "S", "r", "R", "o", "O", "B" }; @@ -204,7 +174,6 @@ ospf6_zebra_read_ipv6 (int command, struct zclient *zclient, unsigned long ifindex; struct prefix_ipv6 p; struct in6_addr *nexthop; - char prefixstr[128], nexthopstr[128]; s = zclient->ibuf; ifindex = 0; @@ -244,27 +213,25 @@ ospf6_zebra_read_ipv6 (int command, struct zclient *zclient, else api.metric = 0; - /* log */ - if (IS_OSPF6_DUMP_ZEBRA) + if (IS_OSPF6_DEBUG_ZEBRA (RECV)) { + char prefixstr[128], nexthopstr[128]; prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr)); - inet_ntop (AF_INET6, &nexthop, nexthopstr, sizeof (nexthopstr)); - - if (command == ZEBRA_IPV6_ROUTE_ADD) - zlog_info ("ZEBRA: Receive add %s route: %s nexthop:%s ifindex:%ld", - zebra_route_name [api.type], prefixstr, - nexthopstr, ifindex); + if (nexthop) + inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr)); else - zlog_info ("ZEBRA: Receive remove %s route: %s nexthop:%s ifindex:%ld", - zebra_route_name [api.type], prefixstr, - nexthopstr, ifindex); + snprintf (nexthopstr, sizeof (nexthopstr), "::"); + + zlog_info ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld", + (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"), + zebra_route_name[api.type], prefixstr, nexthopstr, ifindex); } if (command == ZEBRA_IPV6_ROUTE_ADD) - ospf6_asbr_route_add (api.type, ifindex, (struct prefix *) &p, - api.nexthop_num, nexthop); + ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p, + api.nexthop_num, nexthop); else - ospf6_asbr_route_remove (api.type, ifindex, (struct prefix *) &p); + ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p); if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) free (nexthop); @@ -272,6 +239,8 @@ ospf6_zebra_read_ipv6 (int command, struct zclient *zclient, return 0; } + + DEFUN (show_zebra, show_zebra_cmd, @@ -280,18 +249,24 @@ DEFUN (show_zebra, "Zebra information\n") { int i; - if (!zclient) - vty_out (vty, "Not connected to zebra%s", VTY_NEWLINE); + if (zclient == NULL) + { + vty_out (vty, "Not connected to zebra%s", VTY_NEWLINE); + return CMD_SUCCESS; + } vty_out (vty, "Zebra Infomation%s", VTY_NEWLINE); - vty_out (vty, " enable: %d%s", zclient->enable, VTY_NEWLINE); - vty_out (vty, " fail: %d%s", zclient->fail, VTY_NEWLINE); + vty_out (vty, " enable: %d fail: %d%s", + zclient->enable, zclient->fail, VTY_NEWLINE); vty_out (vty, " redistribute default: %d%s", zclient->redist_default, VTY_NEWLINE); + vty_out (vty, " redistribute:"); for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - vty_out (vty, " RouteType: %s - %s%s", zebra_route_name[i], - zclient->redist[i] ? "redistributed" : "not redistributed", - VTY_NEWLINE); + { + if (zclient->redist[i]) + vty_out (vty, " %s", zebra_route_name[i]); + } + vty_out (vty, "%s", VTY_NEWLINE); return CMD_SUCCESS; } @@ -301,9 +276,6 @@ DEFUN (router_zebra, "Enable a routing process\n" "Make connection to zebra daemon\n") { - if (IS_OSPF6_DUMP_CONFIG) - zlog_info ("Config: router zebra"); - vty->node = ZEBRA_NODE; zclient->enable = 1; zclient_start (zclient); @@ -317,9 +289,6 @@ DEFUN (no_router_zebra, "Configure routing process\n" "Disable connection to zebra daemon\n") { - if (IS_OSPF6_DUMP_CONFIG) - zlog_info ("no router zebra"); - zclient->enable = 0; zclient_stop (zclient); return CMD_SUCCESS; @@ -327,18 +296,18 @@ DEFUN (no_router_zebra, /* Zebra configuration write function. */ int -ospf6_zebra_config_write (struct vty *vty) +config_write_ospf6_zebra (struct vty *vty) { if (! zclient->enable) { vty_out (vty, "no router zebra%s", VTY_NEWLINE); - return 1; + vty_out (vty, "!%s", VTY_NEWLINE); } else if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) { vty_out (vty, "router zebra%s", VTY_NEWLINE); vty_out (vty, " no redistribute ospf6%s", VTY_NEWLINE); - return 1; + vty_out (vty, "!%s", VTY_NEWLINE); } return 0; } @@ -348,41 +317,32 @@ struct cmd_node zebra_node = { ZEBRA_NODE, "%s(config-zebra)# ", - vtysh: 0 }; #define ADD 0 -#define CHANGE 1 -#define REMOVE 2 - +#define REM 1 static void -ospf6_zebra_route_update (int type, struct ospf6_route_req *request) +ospf6_zebra_route_update (int type, struct ospf6_route *request) { - char buf[96], ifname[IFNAMSIZ]; - struct zapi_ipv6 api; - struct ospf6_route_req route; - struct linklist *nexthop_list; - struct linklist_node node; - struct ospf6_nexthop *nexthop = NULL; + char buf[64], ifname[IFNAMSIZ]; + int nhcount; struct in6_addr **nexthops; unsigned int *ifindexes; - struct prefix_ipv6 *p; int i, ret = 0; + struct prefix_ipv6 *dest; - if (IS_OSPF6_DUMP_ZEBRA) + if (IS_OSPF6_DEBUG_ZEBRA (SEND)) { - prefix2str (&request->route.prefix, buf, sizeof (buf)); - if (type == REMOVE) - zlog_info ("ZEBRA: Send remove route: %s", buf); - else - zlog_info ("ZEBRA: Send add route: %s", buf); + prefix2str (&request->prefix, buf, sizeof (buf)); + zlog_info ("Send %s route: %s", + (type == REM ? "remove" : "add"), buf); } if (zclient->sock < 0) { - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: failed: not connected to zebra"); + if (IS_OSPF6_DEBUG_ZEBRA (SEND)) + zlog_info (" Not connected to Zebra"); return; } @@ -390,195 +350,99 @@ ospf6_zebra_route_update (int type, struct ospf6_route_req *request) (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 || request->path.type == OSPF6_PATH_TYPE_EXTERNAL2)) { - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: self originated external route, ignore"); + if (IS_OSPF6_DEBUG_ZEBRA (SEND)) + zlog_info (" Ignore self-originated external route"); return; } - /* Only the best path (i.e. the first path of the path-list - in 'struct ospf6_route') will be sent to zebra. */ - ospf6_route_lookup (&route, &request->route.prefix, request->table); - if (memcmp (&route.path, &request->path, sizeof (route.path))) + /* If removing is the best path and if there's another path, + treat this request as add the secondary path */ + if (type == REM && ospf6_route_is_best (request) && + request->next && ospf6_route_is_same (request, request->next)) { - /* this is not preferred best route, ignore */ - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: not best path, ignore"); - return; + if (IS_OSPF6_DEBUG_ZEBRA (SEND)) + zlog_info (" Best-path removal resulted Sencondary addition"); + type = ADD; + request = request->next; } - nexthop_list = linklist_create (); - - /* for each nexthop */ - for (ospf6_route_lookup (&route, &request->route.prefix, request->table); - ! ospf6_route_end (&route); ospf6_route_next (&route)) + /* Only the best path will be sent to zebra. */ + if (! ospf6_route_is_best (request)) { - if (memcmp (&route.path, &request->path, sizeof (route.path))) - break; - - #define IN6_IS_ILLEGAL_NEXTHOP(a)\ - ((*(u_int32_t *)(void *)(&(a)->s6_addr[0]) == 0xffffffff) &&\ - (*(u_int32_t *)(void *)(&(a)->s6_addr[4]) == 0xffffffff) &&\ - (*(u_int32_t *)(void *)(&(a)->s6_addr[8]) == 0xffffffff) &&\ - (*(u_int32_t *)(void *)(&(a)->s6_addr[12]) == 0xffffffff)) - if (IN6_IS_ILLEGAL_NEXTHOP (&route.nexthop.address)) - { - zlog_warn ("ZEBRA: Illegal nexthop"); - continue; - } - - if (type == REMOVE && ! memcmp (&route.nexthop, &request->nexthop, - sizeof (struct ospf6_nexthop))) - continue; - - nexthop = XCALLOC (MTYPE_OSPF6_OTHER, sizeof (struct ospf6_nexthop)); - if (! nexthop) - { - zlog_warn ("ZEBRA: Can't update nexthop: malloc failed"); - continue; - } - - memcpy (nexthop, &route.nexthop, sizeof (struct ospf6_nexthop)); - linklist_add (nexthop, nexthop_list); + /* this is not preferred best route, ignore */ + if (IS_OSPF6_DEBUG_ZEBRA (SEND)) + zlog_info (" Ignore non-best route"); + return; } - if (type == REMOVE && nexthop_list->count != 0) - type = ADD; - else if (type == REMOVE && nexthop_list->count == 0) - { - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: all nexthop with the selected path has gone"); - - if (! memcmp (&request->route, &route.route, - sizeof (struct ospf6_route))) - { - /* send 'add' of alternative route */ - struct ospf6_path seconde_path; - - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: found alternative path to add"); - - memcpy (&seconde_path, &route.path, sizeof (struct ospf6_path)); - type = ADD; - - while (! memcmp (&seconde_path, &route.path, - sizeof (struct ospf6_path))) - { - nexthop = XCALLOC (MTYPE_OSPF6_OTHER, - sizeof (struct ospf6_nexthop)); - if (! nexthop) - zlog_warn ("ZEBRA: Can't update nexthop: malloc failed"); - else - { - memcpy (nexthop, &route.nexthop, - sizeof (struct ospf6_nexthop)); - linklist_add (nexthop, nexthop_list); - } - - ospf6_route_next (&route); - } - } - else - { - /* there is no alternative route. send 'remove' to zebra for - requested route */ - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: can't find alternative path, remove"); - - if (IS_OSPF6_DUMP_ZEBRA) - { - zlog_info ("ZEBRA: Debug: walk over the route ?"); - ospf6_route_log_request ("Debug route", "***", &route); - ospf6_route_log_request ("Debug request", "***", request); - } - - nexthop = XCALLOC (MTYPE_OSPF6_OTHER, - sizeof (struct ospf6_nexthop)); - if (! nexthop) - zlog_warn ("ZEBRA: Can't update nexthop: malloc failed"); - else - { - memcpy (nexthop, &request->nexthop, - sizeof (struct ospf6_nexthop)); - linklist_add (nexthop, nexthop_list); - } - } - } + nhcount = 0; + for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++) + if (ospf6_nexthop_is_set (&request->nexthop[i])) + nhcount++; - if (nexthop_list->count == 0) + if (nhcount == 0) { - if (IS_OSPF6_DUMP_ZEBRA) - zlog_info ("ZEBRA: no nexthop, ignore"); - linklist_delete (nexthop_list); + if (IS_OSPF6_DEBUG_ZEBRA (SEND)) + zlog_info (" No nexthop, ignore"); return; } /* allocate memory for nexthop_list */ nexthops = XCALLOC (MTYPE_OSPF6_OTHER, - nexthop_list->count * sizeof (struct in6_addr *)); - if (! nexthops) + nhcount * sizeof (struct in6_addr *)); + if (nexthops == NULL) { - zlog_warn ("ZEBRA: Can't update zebra route: malloc failed"); - for (linklist_head (nexthop_list, &node); !linklist_end (&node); - linklist_next (&node)) - XFREE (MTYPE_OSPF6_OTHER, node.data); - linklist_delete (nexthop_list); + zlog_warn ("Can't send route to zebra: malloc failed"); return; } /* allocate memory for ifindex_list */ ifindexes = XCALLOC (MTYPE_OSPF6_OTHER, - nexthop_list->count * sizeof (unsigned int)); - if (! ifindexes) + nhcount * sizeof (unsigned int)); + if (ifindexes == NULL) { - zlog_warn ("ZEBRA: Can't update zebra route: malloc failed"); - for (linklist_head (nexthop_list, &node); !linklist_end (&node); - linklist_next (&node)) - XFREE (MTYPE_OSPF6_OTHER, node.data); - linklist_delete (nexthop_list); + zlog_warn ("Can't send route to zebra: malloc failed"); XFREE (MTYPE_OSPF6_OTHER, nexthops); return; } - i = 0; - for (linklist_head (nexthop_list, &node); ! linklist_end (&node); - linklist_next (&node)) + for (i = 0; i < nhcount; i++) { - nexthop = node.data; - if (IS_OSPF6_DUMP_ZEBRA) + if (IS_OSPF6_DEBUG_ZEBRA (SEND)) { - inet_ntop (AF_INET6, &nexthop->address, buf, sizeof (buf)); - if_indextoname (nexthop->ifindex, ifname); - zlog_info ("ZEBRA: nexthop: %s%%%s(%d)", - buf, ifname, nexthop->ifindex); + inet_ntop (AF_INET6, &request->nexthop[i].address, + buf, sizeof (buf)); + if_indextoname (request->nexthop[i].ifindex, ifname); + zlog_info (" nexthop: %s%%%s(%d)", buf, ifname, + request->nexthop[i].ifindex); } - nexthops[i] = &nexthop->address; - ifindexes[i] = nexthop->ifindex; - i++; + nexthops[i] = &request->nexthop[i].address; + ifindexes[i] = request->nexthop[i].ifindex; } api.type = ZEBRA_ROUTE_OSPF6; api.flags = 0; api.message = 0; SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); - SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); - api.nexthop_num = nexthop_list->count; + api.nexthop_num = nhcount; api.nexthop = nexthops; - api.ifindex_num = nexthop_list->count; + SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); + api.ifindex_num = nhcount; api.ifindex = ifindexes; + SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); + api.metric = (request->path.metric_type == 2 ? + request->path.cost_e2 : request->path.cost); - p = (struct prefix_ipv6 *) &request->route.prefix; - if (type == REMOVE && nexthop_list->count == 1) - ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, p, &api); + dest = (struct prefix_ipv6 *) &request->prefix; + if (type == REM) + ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api); else - ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, p, &api); + ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api); if (ret < 0) - zlog_err ("ZEBRA: zapi_ipv6_route () failed: %s", strerror (errno)); + zlog_err ("zapi_ipv6_route() %s failed: %s", + (type == REM ? "delete" : "add"), strerror (errno)); - for (linklist_head (nexthop_list, &node); !linklist_end (&node); - linklist_next (&node)) - XFREE (MTYPE_OSPF6_OTHER, node.data); - linklist_delete (nexthop_list); XFREE (MTYPE_OSPF6_OTHER, nexthops); XFREE (MTYPE_OSPF6_OTHER, ifindexes); @@ -586,64 +450,52 @@ ospf6_zebra_route_update (int type, struct ospf6_route_req *request) } void -ospf6_zebra_route_update_add (struct ospf6_route_req *request) +ospf6_zebra_route_update_add (struct ospf6_route *request) { - ospf6_zebra_route_update (ADD, request); -} - -void -ospf6_zebra_route_update_remove (struct ospf6_route_req *request) -{ - ospf6_zebra_route_update (REMOVE, request); -} - -static void -ospf6_zebra_redistribute_ospf6 () -{ - struct route_node *node; - - for (node = route_top (ospf6->route_table->table); node; - node = route_next (node)) + if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) { - if (! node || ! node->info) - continue; - ospf6_zebra_route_update_add (node->info); + ospf6->route_table->hook_add = NULL; + ospf6->route_table->hook_remove = NULL; + return; } + ospf6_zebra_route_update (ADD, request); } -static void -ospf6_zebra_no_redistribute_ospf6 () +void +ospf6_zebra_route_update_remove (struct ospf6_route *request) { - struct route_node *node; - - if (! ospf6) - return; - - for (node = route_top (ospf6->route_table->table); node; - node = route_next (node)) + if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) { - if (! node || ! node->info) - continue; - - ospf6_zebra_route_update_remove (node->info); + ospf6->route_table->hook_add = NULL; + ospf6->route_table->hook_remove = NULL; + return; } + ospf6_zebra_route_update (REM, request); } - DEFUN (redistribute_ospf6, redistribute_ospf6_cmd, "redistribute ospf6", "Redistribute control\n" "OSPF6 route\n") { - /* log */ - if (IS_OSPF6_DUMP_CONFIG) - zlog_info ("Config: redistribute ospf6"); + struct ospf6_route *route; + + if (zclient->redist[ZEBRA_ROUTE_OSPF6]) + return CMD_SUCCESS; zclient->redist[ZEBRA_ROUTE_OSPF6] = 1; - /* set zebra route table */ - ospf6_zebra_redistribute_ospf6 (); + if (ospf6 == NULL) + return CMD_SUCCESS; + + /* send ospf6 route to zebra route table */ + for (route = ospf6_route_head (ospf6->route_table); route; + route = ospf6_route_next (route)) + ospf6_zebra_route_update_add (route); + + ospf6->route_table->hook_add = ospf6_zebra_route_update_add; + ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove; return CMD_SUCCESS; } @@ -655,22 +507,23 @@ DEFUN (no_redistribute_ospf6, "Redistribute control\n" "OSPF6 route\n") { - /* log */ - if (IS_OSPF6_DUMP_CONFIG) - zlog_info ("Config: no redistribute ospf6"); + struct ospf6_route *route; + + if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) + return CMD_SUCCESS; zclient->redist[ZEBRA_ROUTE_OSPF6] = 0; - if (! ospf6) + if (ospf6 == NULL) return CMD_SUCCESS; - /* clean up zebra route table */ - ospf6_zebra_no_redistribute_ospf6 (); + ospf6->route_table->hook_add = NULL; + ospf6->route_table->hook_remove = NULL; - ospf6_route_hook_unregister (ospf6_zebra_route_update_add, - ospf6_zebra_route_update_add, - ospf6_zebra_route_update_remove, - ospf6->route_table); + /* withdraw ospf6 route from zebra route table */ + for (route = ospf6_route_head (ospf6->route_table); route; + route = ospf6_route_next (route)) + ospf6_zebra_route_update_remove (route); return CMD_SUCCESS; } @@ -696,33 +549,120 @@ ospf6_zebra_init () /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */ /* Install zebra node. */ - install_node (&zebra_node, ospf6_zebra_config_write); + install_node (&zebra_node, config_write_ospf6_zebra); /* Install command element for zebra node. */ install_element (VIEW_NODE, &show_zebra_cmd); install_element (ENABLE_NODE, &show_zebra_cmd); install_element (CONFIG_NODE, &router_zebra_cmd); install_element (CONFIG_NODE, &no_router_zebra_cmd); + install_default (ZEBRA_NODE); install_element (ZEBRA_NODE, &redistribute_ospf6_cmd); install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd); -#if 0 - hook.name = "ZebraRouteUpdate"; - hook.hook_add = ospf6_zebra_route_update_add; - hook.hook_change = ospf6_zebra_route_update_add; - hook.hook_remove = ospf6_zebra_route_update_remove; - ospf6_hook_register (&hook, &route_hook); -#endif - return; } +/* Debug */ + +DEFUN (debug_ospf6_zebra_sendrecv, + debug_ospf6_zebra_sendrecv_cmd, + "debug ospf6 zebra (send|recv)", + DEBUG_STR + OSPF6_STR + "Debug connection between zebra\n" + "Debug Sending zebra\n" + "Debug Receiving zebra\n" + ) +{ + unsigned char level = 0; + + if (argc) + { + if (! strncmp (argv[0], "s", 1)) + level = OSPF6_DEBUG_ZEBRA_SEND; + else if (! strncmp (argv[0], "r", 1)) + level = OSPF6_DEBUG_ZEBRA_RECV; + } + else + level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; + + OSPF6_DEBUG_ZEBRA_ON (level); + return CMD_SUCCESS; +} + +ALIAS (debug_ospf6_zebra_sendrecv, + debug_ospf6_zebra_cmd, + "debug ospf6 zebra", + DEBUG_STR + OSPF6_STR + "Debug connection between zebra\n" + ); + + +DEFUN (no_debug_ospf6_zebra_sendrecv, + no_debug_ospf6_zebra_sendrecv_cmd, + "no debug ospf6 zebra (send|recv)", + NO_STR + DEBUG_STR + OSPF6_STR + "Debug connection between zebra\n" + "Debug Sending zebra\n" + "Debug Receiving zebra\n" + ) +{ + unsigned char level = 0; + + if (argc) + { + if (! strncmp (argv[0], "s", 1)) + level = OSPF6_DEBUG_ZEBRA_SEND; + else if (! strncmp (argv[0], "r", 1)) + level = OSPF6_DEBUG_ZEBRA_RECV; + } + else + level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; + + OSPF6_DEBUG_ZEBRA_OFF (level); + return CMD_SUCCESS; +} + +ALIAS (no_debug_ospf6_zebra_sendrecv, + no_debug_ospf6_zebra_cmd, + "no debug ospf6 zebra", + NO_STR + DEBUG_STR + OSPF6_STR + "Debug connection between zebra\n" + ); + +int +config_write_ospf6_debug_zebra (struct vty *vty) +{ + if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV)) + vty_out (vty, "debug ospf6 zebra%s", VTY_NEWLINE); + else + { + if (IS_OSPF6_DEBUG_ZEBRA (SEND)) + vty_out (vty, "debug ospf6 zebra send%s", VTY_NEWLINE); + if (IS_OSPF6_DEBUG_ZEBRA (RECV)) + vty_out (vty, "debug ospf6 zebra recv%s", VTY_NEWLINE); + } + return 0; +} + void -ospf6_zebra_finish () +install_element_ospf6_debug_zebra () { - zclient_stop (zclient); - zclient_free (zclient); - zclient = (struct zclient *) NULL; + install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd); + install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd); + install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd); + install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); + install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd); + install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd); + install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd); + install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); } + |