⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ospf_utilities.c

📁 vxworks下ospf协议栈
💻 C
📖 第 1 页 / 共 4 页
字号:
/* ospf_utilities.c  - OSPF utility functions *//* Copyright 2000-2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02v,12may03,asr	    Changes to make OSPF virtual stack compatible02t,26may03,agi     Added ospf_get_system_elapsed_time_second(),                     ported utility functions from RWOS02u,27may03,kc      MIPS board crash due to reference of a null pointer in                     ospf_set_ip_router_tagfiled ()02t,27may02,mwv     SPR 87784 create the function ospf_process_export_route_queue_all()                    This function will process all messages in the export route queue.					Fixed a compile warning in the function ospf_redistribute_route (),					removed the variable route_already_in_ip_table,02s,15may03,htm     SPR 86907 Vitual link is not included in router-LSA for the backbone02r,14may03,agi     moved from RWOS semaphores to vxWorks semaphores02q,22apr03,ram	    SPR#76812 Modifications for OSPF performance enhancements02p,17feb02,ram		SPR 81808 Added OSPF memory partition support02o,09dec02,ram		SPR 84714 & 84711 Added correct metric for type 2 external					and OSPF route weigth.					02o,04dec02,kkz     Warning cleanup02n,03dec02,mwv     Update ospfShowVersion, spr 8462602m,19nov02,kc      Added new ospf_flush_network_link_advertisement() and                    ospf_notify_areas_for_abr_change() routines.02l,31oct02,htm     Add fix for SPR# 8114502k,18oct02,hme     Revert ospf_redistribute_route() case OSPF_REPLACE_PATH to pre                    TRS 29100102j,18sep02,agi     Fixed ospf_redistribute_route()02i,06jun02,kc      Obsolete the routine ospf_free_rw_container_and_data().02h,22apr02,ark     Added in fixes for Virtual links02g,17apr02,ark     Added in fix for SPR 74616. Added new function                    ospf_get_destination_address_of PPP link.Modified                    ospf_convert_ospf_route_table_entry_into_ip_route.02f,09jan02,jkw     Remove elapsed time from checking same instance.02e,20dec01,jkw     Removed sptr_area->sptr_interfaces structure.02d,13oct01,kc      Dynamic configuration changes.02c,11oct01,jkw     Set pointer to NULL after table_free.02b,22sep01,kc      Obsolete ospf_get_port_number(). Added ospf_validate_interface().02a,14jul01,aos     Add ospfShowVersion() function01z,23jul01,jkw     Added in routine to delete items in a container and the container.01y,20jun01,jkw     Added unnumbered link support01x,11may01,aos     Added null pointer checks01w,03may01,jkw     Added checks for NULL pointers and alarm messages01v,26sep00,reshma  Added WindRiver CopyRight01u,25sep00,reshma  RFC-1587 implementation for OSPF NSSA Option, also tested against                    ANVL.01t,13jul00,reshma  Function ospf_parse_port_plain_text_or_md5_password() modified to                    process  simple/MD5 authentication type correctly.01s,07jul00,reshma  Unix compatibility related changes.01r,04apr00,reshma  Added some MIB support (Read only).Passed all important ANVL OSPF                    tests.01q,23dec99,reshma  Compatibility with VxWorks-IP and VxWorks RTM-interface01p,16aug99,jack    Folded the fix in RTM patricia - always return most specific route -                    Sue case into ospf patricia tree.01o,19jul99,jack    RFC 1745 tag related changes01n,28jul99,jack    change in ospf_convert_ospf_route_table_entry_into_ip_route01m,15jan99,jack    Changed the return value in ospf_get_port_number to NO_SUCH_PORT if                    no port is found01l,28dec98,jack    Compiled and added some comments01k,13nov98,jack    Changes related to introducing queuing in OSPF to RTM interface and                    bug fix on the external route additions path (to RTM)01j,11nov98,jack    Config changes, linted and big endian changes01i,30oct98,jack    Incorporate changes for compilation on Vxworks01h,23aug98,jack    ANVL tested OSPF with PATRICIA tree route table and no recursion01g,10aug98,jack    PATRICIA Route Table Based OSPF Code Base01f,04jun98,jack    Integration with RTM and BGP01e,24apr98,jack    RTM changes01d,10jul97,cindy   Pre-release v1.52b01c,02oct97,cindy   Release Version 1.5201b,22oct96,cindy   Release Version 1.5001a,05jun96,cindy   First Beta Release*//*DESCRIPTIONThis file contains various utility functions such as comparing ipaddresses, incrementing sequence numbers, finding the authentication sizes,checking the type of OSPF router.  This file is used whenever a utilityfunction needs to be called.*/#include "ospf.h"#if defined (__OSPF_VIRTUAL_STACK__)#include "ospf_vs_lib.h"#endif /* __OSPF_VIRTUAL_STACK__ *//* defines */#define NUMBER_OF_BITS_IN_BYTE    8static enum TEST ospf_convert_ospf_route_table_entry_into_ip_route    (IP_ROUTE_ENTRY *	sptr_ip_route_entry,     OSPF_ROUTING_TABLE_ENTRY *	sptr_ospf_route_entry_to_export,     OSPF_NEXT_HOP_BLOCK	*	sptr_next_hop_block);static enum TEST ospf_redistribute_route    (enum OSPF_ROUTING_TABLE_UPDATE_ACTION action,     IP_ROUTE_ENTRY *	sptr_ip_route_entry);static void ospf_set_ip_route_tagfiled    (IP_ROUTE_ENTRY *	sptr_ip_route,     OSPF_ROUTING_TABLE_ENTRY *	sptr_ospf_route_entry_to_export);static void ospf_set_ip_metrics    (IP_ROUTE_ENTRY *	sptr_ip_route,     OSPF_ROUTING_TABLE_ENTRY *	sptr_ospf_route_entry_to_export);/* SPR 74616 */ULONG ospf_get_destination_address_of_PPP_link (ULONG ppp_src_addr);/* SPR 74616 */extern void ospfShowVersion(void);/******************************************************************************/enum BOOLEAN ospf_check_if_addresses_match (ULONG address_1,ULONG address_2){	OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_check_if_addresses_match\r\n");	if (address_1 == address_2)		{		return (TRUE);		}	else		{		return (FALSE);		}}/******************************************************************************/enum BOOLEAN ospf_check_for_transit_areas (void){	enum BOOLEAN transit_areas_exist;	OSPF_AREA_ENTRY *sptr_area = NULL;	OSPF_AREA_ENTRY *sptr_next_area = NULL;	OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_check_for_transit_areas\r\n");	transit_areas_exist = FALSE;	for (sptr_area = ospf.sptr_area_list; sptr_area != NULL; sptr_area = sptr_next_area)		{		sptr_next_area = sptr_area->sptr_forward_link;		if (sptr_area->flags._bit.transit == TRUE)			{			transit_areas_exist = TRUE;			break;			}		}	return (transit_areas_exist);}/******************************************************************************/void ospf_generate_network_and_router_link_state_advertisements (OSPF_INTERFACE *sptr_interface){	OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_generate_network_and_router_link_state_advertisements\r\n");	if (sptr_interface->sptr_area->build_router == TRUE)		{		ospf_originate_router_links_advertisement (sptr_interface->sptr_area);		/* SPR 86907  -- Begin */		if ((sptr_interface->type == OSPF_VIRTUAL_LINK) && (sptr_interface->sptr_transit_area != NULL))             ospf_originate_router_links_advertisement (sptr_interface->sptr_transit_area);		/* SPR 86907  -- End */		sptr_interface->sptr_area->build_router = FALSE;		}	if (sptr_interface->flags._bit.build_network == TRUE)		{		ospf_originate_network_links_advertisement (sptr_interface);		sptr_interface->flags._bit.build_network = FALSE;		}	return;}/******************************************************************************/ULONG ospf_get_authentication_size (OSPF_INTERFACE *sptr_interface){	OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_get_authentication_size\r\n");	if (sptr_interface->authentication.type == OSPF_AUTHENTICATION_MD5)		{		return (OSPF_AUTHENTICATION_MD5_SIZE);		}	else		{		return (0x00000000L);		}}/******************************************************************************/ULONG ospf_get_interface_mtu (OSPF_INTERFACE *sptr_interface){	ULONG mtu;	OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_get_interface_mtu\r\n");#if defined (__OSPF_VIRTUAL_LINK__)	if (sptr_interface->type == OSPF_VIRTUAL_LINK)		{		mtu = 1500;		}	else		{		mtu = sptr_interface->mtu;		}#else /*__OSPF_VIRTUAL_LINK__*/	if (sptr_interface->type == OSPF_VIRTUAL_LINK)		{		mtu = OSPF_MAXIMUM_PACKET_SIZE_FOR_VIRTUAL_LINK;		}	else		{		mtu = sptr_interface->mtu;		}#endif /* __OSPF_VIRTUAL_LINK__ *//* Mistral commented on  May 22nd */	/*mtu = mtu - sizeof (IP_HEADER); */	return (mtu);}/**************************************************************************************** ospf_flush_network_link_advertisement - flush network link advertisement** This routine flush the self-originated network-LSA. It is called when a router* that has formerly been the designated router for a netwok is no longer declared* itself as the designated router. This could happen when the interface is* dynamically brought down due to the configuration changes** RETURNS: N/A*/void ospf_flush_network_link_advertisement( OSPF_INTERFACE *sptr_interface ){    USHORT age = 0x00;	OSPF_LS_DATABASE_ENTRY *    sptr_network_database_entry = NULL;    /* SPR 84478, 84485, 84486 -- Begin */    if (sptr_interface->designated_router.address == sptr_interface->address)        {        /*         * A router that has formerly been the Designated Router for a network,         * but is no longer, should flush the network-LSA that it had previously         * (SPR#75785)         */         /*search for the old network LSA entry in the  database and set the          * age= OSPF_MAX_AGE          */         /* SPR#76812 -- Begin */         sptr_network_database_entry = ospf_find_LSA (             sptr_interface->sptr_area,              sptr_interface->designated_router.address,             ospf.router_id,              OSPF_LS_NETWORK);		 /* SPR#76812 -- End */               if(sptr_network_database_entry != NULL)             {             age = OSPF_MAXIMUM_AGE;             age = host_to_net_short (age);             /* Assign OSPF_MAX_AGE value to network LSA*/             sptr_network_database_entry->advertisement.sptr_network->ls_header.age = age;             }        }    /* SPR 84478, 84485, 84486 -- End */    }/*************************************************************************************** ospf_notify_areas_for_abr_change - send notification for area border router changes** This routine originates the router link state advertisements for areas to which* this router connects for the changes in its area border router status.** RETURNS: N/A*/void ospf_notify_areas_for_abr_change( ulong_t area_id_to_skip ){    /* SPR 84478, 84485, 84486 -- Begin */    OSPF_AREA_ENTRY* sptr_area;    for ( sptr_area = ospf.sptr_area_list; sptr_area != NULL;          sptr_area = sptr_area->sptr_forward_link )    {        /* skip the area that doesn't need the router lsa to send to. The area to         * skip would be the area that has already gone through the link state         * database exchange process due to changes in the area or interface         * configuration         */        if ( sptr_area->area_id == area_id_to_skip )            continue;        /* originate router lsa to notify interface in the area that the router's         * area border router status has changed.         */        ospf_originate_router_links_advertisement( sptr_area );    }    return;    /* SPR 84478, 84485, 84486 -- End */}/********************************************************************************* ospf_check_if_area_border_router - check if router is an area border router** This routine checks if the router is an area border router. If the router is* attached to multiple areas, then it's an area border router (page 149, #3)* provided that there is at least one operational interface in each area. It is* not necessary to check for the number of operational virtual interfaces in an* area because if there is no operational interface in the transit area, the end* point of the virtual interface will not be reachable, thus, virtual interfaces*  will not operate.** RETURNS: TRUE or FALSE*/enum BOOLEAN ospf_check_if_area_border_router (void){	OSPF_AREA_ENTRY *sptr_area = NULL;	OSPF_AREA_ENTRY *sptr_next_area = NULL;	USHORT number_of_areas = 0x0000;	OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_check_if_area_border_router\r\n");	for (sptr_area = ospf.sptr_area_list; sptr_area != NULL; sptr_area = sptr_next_area)		{		sptr_next_area = sptr_area->sptr_forward_link;		if (sptr_area->number_of_interfaces_in_up_state == 0)			{			continue;			}		number_of_areas++;		}	if ((number_of_areas > 0x0001) || (ospf.number_of_virtual_links > 0x00000000L))		{		return (TRUE);		}	else		{		return (FALSE);		}}/********************************************************************************* ospf_validate_interface - validate the existence of an interface** This routine walks the sptr_interface_list and verify if the given interface* IP address matches the IP address of a node on the list.** RETURNS: TRUE or FALSE*/enum BOOLEAN ospf_validate_interface(ULONG interface_address){    OSPF_INTERFACE  *sptr_interface;    for ( sptr_interface = ospf.sptr_interface_list; sptr_interface != NULL;          sptr_interface = sptr_interface->sptr_forward_link )    {        if ((sptr_interface->port_enabled == TRUE) &&            (sptr_interface->address == interface_address))        {            return(TRUE);        }    }    return(FALSE);}/**************************************************************************//* section 13.1 of OSPF specification (page 136) */enum TEST ospf_check_if_more_recent (OSPF_LS_HEADER *sptr_new_ls_header,OSPF_LS_HEADER *sptr_current_ls_header,ULONG elapsed_time){	seq_t new_sequence_number;	seq_t current_sequence_number;	USHORT new_age;	USHORT current_age;	OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_check_if_more_recent\r\n");	new_sequence_number = sptr_new_ls_header->sequence_number;	new_sequence_number = net_to_host_long (new_sequence_number);	current_sequence_number = sptr_current_ls_header->sequence_number;	current_sequence_number = net_to_host_long (current_sequence_number);	if (new_sequence_number > current_sequence_number)		{		return (PASS);		}	else if (sptr_new_ls_header->sequence_number == sptr_current_ls_header->sequence_number)		{		if (sptr_new_ls_header->checksum > sptr_current_ls_header->checksum)			{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -