📄 ospf_utilities.c
字号:
if (sptr_ip_route_entry->gateway == 0L) { for (sptr_area = ospf.sptr_area_list; sptr_area != NULL; sptr_area = sptr_area->sptr_forward_link) { for (sptr_interface = sptr_area->sptr_interfaces; sptr_interface != NULL; sptr_interface = sptr_interface->sptr_forward_link) { if(sptr_interface->address == sptr_next_hop_block->outgoing_router_interface) { if(sptr_interface->type == OSPF_POINT_TO_POINT) sptr_ip_route_entry->gateway = ospf_get_destination_address_of_PPP_link (sptr_next_hop_block->outgoing_router_interface); else sptr_ip_route_entry->gateway = sptr_next_hop_block->outgoing_router_interface; } } } } /* SPR 74616 */ /* SPR 81145 */ /* SPR 84714 -- Begin */ /* install the appropriate metric depending if this is external type 2 or not*/ if (sptr_ospf_route_entry_to_export->type2_cost == 0x00) { sptr_ip_route_entry->metric = sptr_ospf_route_entry_to_export->path_cost; } else { sptr_ip_route_entry->metric = sptr_ospf_route_entry_to_export->type2_cost; } /* SPR 84714 -- End */ sptr_ip_route_entry->ipRouteProto = OSPF_PROTOCOL_TYPE; /* defined in kroute.h */ sptr_ip_route_entry->sender_ip_address = sptr_ospf_route_entry_to_export->advertising_router; sptr_ip_route_entry->ipRouteType = INDIRECT_ROUTE_TYPE; /* #### Reshma: RTM does not add this Gateway to Routing table unless this routetype is INDIRECT_ROUTE_TYPE */ /* SPR 84711 -- Begin */ /* Set the OSPF weight in the kernel table */ sptr_ip_route_entry->weight = RTM_OSPF_ROUTE_WEIGHT; /* SPR 84711 -- End */ ospf_set_ip_route_tagfiled (sptr_ip_route_entry, sptr_ospf_route_entry_to_export); ospf_set_ip_metrics (sptr_ip_route_entry, sptr_ospf_route_entry_to_export); return (PASS);}/******************************************************************************/static void ospf_set_ip_route_tagfiled (IP_ROUTE_ENTRY *sptr_ip_route, OSPF_ROUTING_TABLE_ENTRY *sptr_ospf_route_entry_to_export){ OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_set_ip_route_tagfiled\r\n"); if (sptr_ospf_route_entry_to_export->path_type == OSPF_ROUTE_PATH_TYPE_INTRA || sptr_ospf_route_entry_to_export->path_type == OSPF_ROUTE_PATH_TYPE_INTER) { sptr_ip_route->route_tag = OSPF_INTERNAL; } else if (sptr_ospf_route_entry_to_export->path_type == OSPF_ROUTE_PATH_TYPE_1_EXTERNAL || sptr_ospf_route_entry_to_export->path_type == OSPF_ROUTE_PATH_TYPE_2_EXTERNAL ) { if ((sptr_ospf_route_entry_to_export->sptr_link_state_origin != NULL) && (sptr_ospf_route_entry_to_export->sptr_link_state_origin->sptr_external != NULL)) { if ((sptr_ospf_route_entry_to_export->sptr_link_state_origin->sptr_external->tos0_external_route_tag & 0x0000ffff) != 0x00) { if ((sptr_ospf_route_entry_to_export->sptr_link_state_origin->sptr_external->tos0_external_route_tag & 0xffff0000) != 0x00) { sptr_ip_route->route_tag = (USHORT) (sptr_ospf_route_entry_to_export->sptr_link_state_origin->sptr_external->tos0_external_route_tag & 0xffff0000); } else { sptr_ip_route->route_tag = (USHORT) RFC1745_EGP_ORIGEGP_ROUTE_TAG; /* RFC 1745 - neighbor AS is there in tag */ } } else { sptr_ip_route->route_tag = (USHORT) RFC1745_IGP_TO_OSPF_ROUTE_TAG; /* AS field in tag is NULL means loacl AS static export or RIP */ } } else { /* sptr_link_state_origin pointer is NULL - somethings wrong */ sptr_ip_route->route_tag = (USHORT) RFC1745_BGP_TO_OSPF_ROUTE_TAG; } } return;}/******************************************************************************/static void ospf_set_ip_metrics (IP_ROUTE_ENTRY *sptr_ip_route, OSPF_ROUTING_TABLE_ENTRY *sptr_ospf_route_entry_to_export){ OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_set_ip_metrics\r\n"); sptr_ip_route->metric_2 = 0x00000000L; sptr_ip_route->metric_3 = 0x00000000L; sptr_ip_route->metric_4 = 0x00000000L; switch (sptr_ospf_route_entry_to_export->path_type) { case OSPF_ROUTE_PATH_TYPE_INTRA: sptr_ip_route->metric_2 = 0x00000000L; break; case OSPF_ROUTE_PATH_TYPE_INTER: sptr_ip_route->metric_2 = TRUE; break; case OSPF_ROUTE_PATH_TYPE_1_EXTERNAL: sptr_ip_route->metric_3 = TRUE; break; case OSPF_ROUTE_PATH_TYPE_2_EXTERNAL: sptr_ip_route->metric_4 = sptr_ospf_route_entry_to_export->type2_cost; break; default: break; } return;}/******************************************************************************/void* ospf_buffer_free(void* p_data){ OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_buffer_free\r\n"); /* SPR 81808 */ table_free(p_data); p_data = NULL; return p_data;}/******************************************************************************//* SPR 74616 */ULONG ospf_get_destination_address_of_PPP_link ( ULONG src_ppp_addr) { struct ifnet *ifp; struct ifaddr *ifa; ULONG src_ip_address; ULONG dest_ip_address; bool mutex_released = FALSE; int s; mutex_released = semGive (ospf_global_mutex);#if defined (VIRTUAL_STACK) virtualStackNumTaskIdSet (ospf.ospf_vsid);#endif /* VIRTUAL_STACK */ s = splimp();#if defined (VIRTUAL_STACK) for (ifp = _ifnet; ifp!= NULL; ifp = ifp->if_next)#else for (ifp = ifnet; ifp!= NULL; ifp = ifp->if_next)#endif { for (ifa = ifp->if_addrlist; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr->sa_family == AF_INET) { src_ip_address = htonl(((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr); if ((ifp->if_flags & IFF_POINTOPOINT) && (src_ip_address == src_ppp_addr)) { dest_ip_address = ntohl(((struct sockaddr_in *)ifa->ifa_dstaddr)->sin_addr.s_addr); splx(s); if (mutex_released) semTake (ospf_global_mutex, WAIT_FOREVER); return (dest_ip_address); } } } } splx(s); if (mutex_released) semTake (ospf_global_mutex, WAIT_FOREVER); return (0L); }/* SPR 74616 *//******************************************************************************/void ospfShowVersion(void){ printf ("\t\t\tWindNet OSPFv%d\r\n", OSPF_VERSION); printf ("\n"); printf ("\tVersion number\t:\t%s.%s\r\n", OSPF_REV, OSPF_REV_TYPE); printf ("\tCreation date\t:\t%s\r\n", OSPF_BUILD); printf ("\n"); return;} /* * dstaddr_to_ifp () * with a dest address returns the ifnet* structure * * RETURNS : ifnet* pointer if the address was found * : NULL if the address was not found * */struct ifnet* dstaddr_to_ifp ( struct in_addr addr ) { register struct in_ifaddr *ia; struct ifnet* ifp; int s;#if defined (VIRTUAL_STACK) virtualStackNumTaskIdSet (ospf.ospf_vsid);#endif /* VIRTUAL_STACK */ s = splimp();#if defined (VIRTUAL_STACK) for (ia = _in_ifaddr; ia != NULL && (ia->ia_dstaddr.sin_addr.s_addr != (addr).s_addr); ia = ia->ia_next)#else for (ia = in_ifaddr; ia != NULL && (ia->ia_dstaddr.sin_addr.s_addr != (addr).s_addr); ia = ia->ia_next)#endif /* VIRTUAL_STACK */ continue; ifp = (ia == NULL) ? NULL : ia->ia_ifp; splx(s); return ifp; }UINT ospf_get_system_elapsed_time_second () { ULONG absolute_tick_count; UINT seconds; UINT ticks_per_second = 0; ticks_per_second = (UINT)sysClkRateGet (); absolute_tick_count = tickGet (); seconds = absolute_tick_count/ticks_per_second; return (seconds); }#if (_BYTE_ORDER == _LITTLE_ENDIAN)/*************************************************************/USHORT ospf_host_to_net_short (USHORT host_order_short_value){ BYTE *bptr_return_value; USHORT net_order_value; bptr_return_value = (BYTE *) &net_order_value; *bptr_return_value = (BYTE) (host_order_short_value >> NUMBER_OF_BITS_IN_BYTE); ++bptr_return_value; *bptr_return_value = (BYTE) host_order_short_value; return (net_order_value);}/*****************************************************************************/USHORT ospf_net_to_host_short (USHORT net_order_short_value){ USHORT host_order_value; BYTE *bptr_net_order_value; bptr_net_order_value = (BYTE *) &net_order_short_value; host_order_value = *bptr_net_order_value; ++bptr_net_order_value; host_order_value <<= NUMBER_OF_BITS_IN_BYTE; host_order_value = (USHORT) (host_order_value | *bptr_net_order_value); return (host_order_value);} /*****************************************************************************/ULONG ospf_host_to_net_long (ULONG host_order_long_value){ BYTE *bptr_net_order_value; BYTE *bptr_host_order_long_value; ULONG net_order_value; bptr_net_order_value = (BYTE *) &net_order_value + (sizeof (ULONG) - 0x0001); bptr_host_order_long_value = (BYTE *) &host_order_long_value; *bptr_net_order_value = *bptr_host_order_long_value; --bptr_net_order_value; ++bptr_host_order_long_value; *bptr_net_order_value = *bptr_host_order_long_value; --bptr_net_order_value; ++bptr_host_order_long_value; *bptr_net_order_value = *bptr_host_order_long_value; --bptr_net_order_value; ++bptr_host_order_long_value; *bptr_net_order_value = *bptr_host_order_long_value; return (net_order_value);}/*****************************************************************************/ULONG ospf_net_to_host_long (ULONG net_order_long_value){ ULONG host_order_value; BYTE *bptr_net_order_long_value; bptr_net_order_long_value = (BYTE *) &net_order_long_value; host_order_value = *bptr_net_order_long_value; ++bptr_net_order_long_value; host_order_value <<= NUMBER_OF_BITS_IN_BYTE; host_order_value = host_order_value | *bptr_net_order_long_value; ++bptr_net_order_long_value; host_order_value <<= NUMBER_OF_BITS_IN_BYTE; host_order_value = host_order_value | *bptr_net_order_long_value; ++bptr_net_order_long_value; host_order_value <<= NUMBER_OF_BITS_IN_BYTE; host_order_value = host_order_value | *bptr_net_order_long_value; return (host_order_value);}#endif/*************************************************************************//* * Convert an internet address (in network byte order) to a dotted decimal ascii string. */char * ospf_convert_ip_address_to_dot_format (char *cptr_array_to_store_dot_format_address, ULONG ip_address){ sprintf ((char *) cptr_array_to_store_dot_format_address, "%lu.%lu.%lu.%lu", high_byte_of_dword (ip_address), high_low_byte_of_dword (ip_address), low_high_of_dword (ip_address), low_byte_of_dword (ip_address)); return (cptr_array_to_store_dot_format_address);}/*************************************************************************/char * ospf_strlwr (char *cptr_string_to_lower_case){ char *cptr_original_string_to_lower_case; cptr_original_string_to_lower_case = cptr_string_to_lower_case; while (*cptr_string_to_lower_case != (char) (ULONG) NULL) { if (*cptr_string_to_lower_case >= 'A' && *cptr_string_to_lower_case <= 'Z') { *cptr_string_to_lower_case += (char) 0x20; } ++cptr_string_to_lower_case; } return (cptr_original_string_to_lower_case);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -