📄 ospf6_zebra.c
字号:
if (IS_OSPF6_DEBUG_ZEBRA (SEND)) { prefix2str (&request->prefix, buf, sizeof (buf)); zlog_info ("Send %s route: %s", (type == REM ? "remove" : "add"), buf); } if (zclient->sock < 0) { if (IS_OSPF6_DEBUG_ZEBRA (SEND)) zlog_info (" Not connected to Zebra"); return; } if (request->path.origin.adv_router == ospf6->router_id && (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 || request->path.type == OSPF6_PATH_TYPE_EXTERNAL2)) { if (IS_OSPF6_DEBUG_ZEBRA (SEND)) zlog_info (" Ignore self-originated external route"); return; } /* 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)) { if (IS_OSPF6_DEBUG_ZEBRA (SEND)) zlog_info (" Best-path removal resulted Sencondary addition"); type = ADD; request = request->next; } /* Only the best path will be sent to zebra. */ if (! ospf6_route_is_best (request)) { /* this is not preferred best route, ignore */ if (IS_OSPF6_DEBUG_ZEBRA (SEND)) zlog_info (" Ignore non-best route"); return; } nhcount = 0; for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++) if (ospf6_nexthop_is_set (&request->nexthop[i])) nhcount++; if (nhcount == 0) { if (IS_OSPF6_DEBUG_ZEBRA (SEND)) zlog_info (" No nexthop, ignore"); return; } /* allocate memory for nexthop_list */ nexthops = XCALLOC (MTYPE_OSPF6_OTHER, nhcount * sizeof (struct in6_addr *)); if (nexthops == NULL) { zlog_warn ("Can't send route to zebra: malloc failed"); return; } /* allocate memory for ifindex_list */ ifindexes = XCALLOC (MTYPE_OSPF6_OTHER, nhcount * sizeof (unsigned int)); if (ifindexes == NULL) { zlog_warn ("Can't send route to zebra: malloc failed"); XFREE (MTYPE_OSPF6_OTHER, nexthops); return; } for (i = 0; i < nhcount; i++) { if (IS_OSPF6_DEBUG_ZEBRA (SEND)) { 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] = &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); api.nexthop_num = nhcount; api.nexthop = nexthops; 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); dest = (struct prefix_ipv6 *) &request->prefix; if (type == REM) ret = zapi_ipv6_delete (zclient, dest, &api); else ret = zapi_ipv6_add (zclient, dest, &api); if (ret < 0) zlog_err ("zapi_ipv6_%s () failed: %s", (type == REM ? "delete" : "add"), strerror (errno)); XFREE (MTYPE_OSPF6_OTHER, nexthops); XFREE (MTYPE_OSPF6_OTHER, ifindexes); return;}voidospf6_zebra_route_update_add (struct ospf6_route *request){ if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) { ospf6->route_table->hook_add = NULL; ospf6->route_table->hook_remove = NULL; return; } ospf6_zebra_route_update (ADD, request);}voidospf6_zebra_route_update_remove (struct ospf6_route *request){ if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) { 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"){ struct ospf6_route *route; if (zclient->redist[ZEBRA_ROUTE_OSPF6]) return CMD_SUCCESS; zclient->redist[ZEBRA_ROUTE_OSPF6] = 1; 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;}DEFUN (no_redistribute_ospf6, no_redistribute_ospf6_cmd, "no redistribute ospf6", NO_STR "Redistribute control\n" "OSPF6 route\n"){ struct ospf6_route *route; if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) return CMD_SUCCESS; zclient->redist[ZEBRA_ROUTE_OSPF6] = 0; if (ospf6 == NULL) return CMD_SUCCESS; ospf6->route_table->hook_add = NULL; ospf6->route_table->hook_remove = NULL; /* 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;}voidospf6_zebra_init (){ /* Allocate zebra structure. */ zclient = zclient_new (); zclient_init (zclient, ZEBRA_ROUTE_OSPF6); zclient->interface_add = ospf6_zebra_if_add; zclient->interface_delete = ospf6_zebra_if_del; zclient->interface_up = ospf6_zebra_if_state_update; zclient->interface_down = ospf6_zebra_if_state_update; zclient->interface_address_add = ospf6_zebra_if_address_update_add; zclient->interface_address_delete = ospf6_zebra_if_address_update_delete; zclient->ipv4_route_add = NULL; zclient->ipv4_route_delete = NULL; zclient->ipv6_route_add = ospf6_zebra_read_ipv6; zclient->ipv6_route_delete = ospf6_zebra_read_ipv6; /* redistribute connected route by default */ /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */ /* Install zebra node. */ 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); 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" );intconfig_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", VNL); else { if (IS_OSPF6_DEBUG_ZEBRA (SEND)) vty_out (vty, "debug ospf6 zebra send%s", VNL); if (IS_OSPF6_DEBUG_ZEBRA (RECV)) vty_out (vty, "debug ospf6 zebra recv%s", VNL); } return 0;}voidinstall_element_ospf6_debug_zebra (){ 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);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -