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

📄 ospf_external_routes.c

📁 vxworks下ospf协议栈
💻 C
字号:
/* ospf_external_routes.c - used for processing external routes *//* Copyright 1998 - 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02l,12may03,asr	   Changes to make OSPF virtual stack compatible02k,27may03,agi    Changed rw_container to ospf_container02j,26may03,htm    Modified ospf_process_external_route_to_ospf() to avoid using                   an iterator since the LL may change while the semaphore is                    given so the iterator might access an invalid LL. 02i,22may03,agi    Changes RWOS semaphores to vxWorks semaphores02h,22apr03,ram	   SPR#76812 Modifications for OSPF performance enhancements02g,06mar03,agi    Fixed compiler warning02f,29jan03,mwv    SPR 85893 Remove the call to ospf_find_external_route02e,28jan03,ram	   SPR 85050 Added support for external route redistribution                    based on OSPF external metric values02e,16jan03,smr    Modified ospf_queue_export_route_to_ospf to print metric correctly.02d,06jan03,ram	   SPR 85432 Changes to allow more OSPF external route processing02c,09dec02,ram	   SPR 83418 Added support for OSPF external metric types and values01b,19nov02,mwv    Merge TMS code SPR 8428402b,17oct02,mwv    Add a default metric value to type 2 external routes02a,08oct02,agi    Fixed compiler warnings01y,09jan02,jkw    Created another function for processing external routes.01x,11oct01,jkw    Set pointer to NULL after table_free.01w,13aug01,kc     removed forward declaration for ospf_find_originated_external_route()                   prototype.01v,19jun01,aos    Header file clean up01u,02may01,aos    Added ospf_find_external_route () search function to ospf_queue_export_route_to_ospf ()01t,26sep00,reshma Added WindRiver CopyRight01s,25sep00,reshma RFC-1587 implementation for OSPF NSSA Option, also tested against ANVL.01r,07jul00,reshma Unix compatibility related changes.01q,04apr00,reshma Added some MIB support (Read only).Passed all important ANVL OSPF tests.01p,23dec99,reshma Compatibility with VxWorks-IP and VxWorks RTM-interface01o,28dec98,jack   Compiled and added some comments01n,13nov98,jack   Changes related to introducing queuing in OSPF to RTM interface and                   bug fix on the external route additions path (to RTM)01m,11nov98,jack   Config changes, linted and big endian changes01l,30oct98,jack   Incorporate changes for compilation on Vxworks01k,23aug98,jack   ANVL tested OSPF with PATRICIA tree route table and no recursion01j,13aug98,jack   Added print in function: ospf_queue_export_route_to_ospf01i,10aug98,jack   PATRICIA Route Table Based OSPF Code Base01h,16jun98,jack   Syntax error correction01g,16jun98,jack   Changes related to external_routes queuing and the queue processing01f,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*//*DESCRIPTIONospf_external_routes.c is used for exporting external routes to other protocols throughthe Routing Table Manager.This file is used when adding or deleting external routes in OSPF.*/#include "ospf.h"#if defined (__OSPF_VIRTUAL_STACK__)#include "ospf_vs_lib.h"#endif /* __OSPF_VIRTUAL_STACK__ */#include <time.h>/*************************************************************************** ospf_process_external_route_to_ospf - process external route** This routine will walk through external route queue and* process each external route.  This routine will originate an* external lsa for each externa route.** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/void ospf_process_external_route_to_ospf (){	OSPF_EXTERNAL_ROUTE *sptr_external_route =NULL;	OSPF_EXTERNAL_ROUTE *sptr_external_route_from_global_list =NULL;	ULONG routes_processed = 0;	OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_process_external_route_to_ospf\r\n");	/* SPR#76812 */	if (ospf.sptr_external_route_queue == NULL)         return;    semTake (ospf_external_route_mutex, WAIT_FOREVER);    sptr_external_route = ospf_container_front (ospf.sptr_external_route_queue);    if (sptr_external_route != NULL)         ospf_container_remove_front (ospf.sptr_external_route_queue);    semGive (ospf_external_route_mutex);	while (sptr_external_route != NULL)		{		/* SPR#76812 */		if ( (sptr_external_route->metric & 0x00ffffff) == OSPF_LSInfinity )			{			sptr_external_route_from_global_list = ospf_find_originated_external_route (ospf.sptr_originated_external_routes,				sptr_external_route);			if (sptr_external_route_from_global_list != NULL)				{				sptr_external_route->tag = sptr_external_route_from_global_list->tag;				}#if !defined (__NSSA__)			ospf_originate_external_links_advertisement (sptr_external_route);#else /* __NSSA__ */			sptr_external_route->advertising_router =  ospf.router_id;			ospf_originate_external_links_advertisement (sptr_external_route);			if (ospf.nssa_enabled == TRUE)				{				ospf_originate_type_7_links_advertisement (sptr_external_route);				}#endif /*__NSSA__*/			if (sptr_external_route_from_global_list == NULL)				{				table_free (sptr_external_route);				sptr_external_route = NULL;				}			else				{				table_free (sptr_external_route);				sptr_external_route = NULL;				table_free (sptr_external_route_from_global_list);				sptr_external_route_from_global_list = NULL;				}			}		else			{#if !defined (__NSSA__)			ospf_originate_external_links_advertisement (sptr_external_route);#else /* __NSSA__ */			sptr_external_route->advertising_router =  ospf.router_id;			ospf_originate_external_links_advertisement (sptr_external_route);			if (ospf.nssa_enabled == TRUE)				{				ospf_originate_type_7_links_advertisement (sptr_external_route);				}#endif /*__NSSA__*/			table_free (sptr_external_route);			sptr_external_route = NULL;			}			/* SPR 85432 -- Begin */			routes_processed++;			if(routes_processed >= MAX_EXTERNAL_ROUTES_PROCESSED)			{				break;			}			/* SPR 85432 -- End */            semTake (ospf_external_route_mutex, WAIT_FOREVER);            sptr_external_route = ospf_container_front (ospf.sptr_external_route_queue);            if (sptr_external_route != NULL)                 ospf_container_remove_front (ospf.sptr_external_route_queue);            semGive (ospf_external_route_mutex);		}    return;}/*************************************************************************** ospf_find_originated_external_route - find external route** This routine will walk through external route queue and* try to find the associated external route.** <sptr_originated_external_routes> Originated external routes** <sptr_external_route> External route** RETURNS: OSPF_EXTERNAL_ROUTE * or NULL** ERRNO: N/A** NOMANUAL*/OSPF_EXTERNAL_ROUTE* ospf_find_originated_external_route (OSPF_EXTERNAL_ROUTE *sptr_originated_external_routes,	OSPF_EXTERNAL_ROUTE *sptr_external_route){	OSPF_EXTERNAL_ROUTE *sptr_external_route_from_global_list;	OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_find_originated_external_route\r\n");	for (sptr_external_route_from_global_list = sptr_originated_external_routes; sptr_external_route_from_global_list != NULL;		sptr_external_route_from_global_list = sptr_external_route_from_global_list->sptr_forward_link)		{		if (sptr_external_route->destination_network == sptr_external_route_from_global_list->destination_network &&			 sptr_external_route->destination_mask == sptr_external_route_from_global_list->destination_mask &&			 sptr_external_route->metric == sptr_external_route_from_global_list->metric &&			 sptr_external_route->forwarding_address == sptr_external_route_from_global_list->forwarding_address)			{			ospf_remove_node_from_list ( (OSPF_GENERIC_NODE **) &sptr_originated_external_routes,				(OSPF_GENERIC_NODE *) sptr_external_route_from_global_list);			return (sptr_external_route_from_global_list);			}		}	return (NULL);}/*************************************************************************** delete_exported_route_from_ospf - delete the external route** This routine will delete the external route from OSPF by* calling the originate external link state advertisement with* a max age.** <destination_network> Destination network for external route** <network_mask> Network mask for external route** <metric> Metric for external route** <forwarding_address> Forwarding address for external route** <tag> Tag for external route** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/void delete_exported_route_from_ospf (ULONG destination_network,ULONG network_mask,ULONG metric,ULONG forwarding_address,ULONG tag,ULONG proto){	OSPF_EXTERNAL_ROUTE *sptr_external_route =NULL;	BOOLEAN rc = false;	PARAMETER_NOT_USED(metric);	OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering delete_exported_route_from_ospf\r\n");	sptr_external_route = (OSPF_EXTERNAL_ROUTE *) table_malloc (1, sizeof (OSPF_EXTERNAL_ROUTE));	if (sptr_external_route == NULL)		{		ospf_print_memory_error_message_and_free_buffer_if_necessary ((void *) NULL, "OSPF_EXTERNAL_ROUTE");		return;		}	memset (sptr_external_route, 0x00, sizeof (OSPF_EXTERNAL_ROUTE));	sptr_external_route->sptr_forward_link = NULL;	sptr_external_route->sptr_backward_link = NULL;	sptr_external_route->destination_network = destination_network;	sptr_external_route->destination_mask = network_mask;	/* SPR 83418 -- Begin */	sptr_external_route->metric = 0x00FFFFFF;	if((metric & OSPF_ASE_bit_E) == OSPF_ASE_bit_E)	{		sptr_external_route->metric = sptr_external_route->metric | OSPF_ASE_bit_E;	}	/* SPR 83418 -- End */	sptr_external_route->forwarding_address = forwarding_address;	sptr_external_route->tag = tag;	sptr_external_route->time_stamp = time(NULL) * 60;	/* SPR 85050 -- Begin */	sptr_external_route->route_protocol = proto;	/* SPR 85050 -- End */	/* SPR#76812 -- Begin */	semTake (ospf_external_route_mutex, WAIT_FOREVER);	rc = ospf_container_add_back (ospf.sptr_external_route_queue, sptr_external_route);	semGive (ospf_external_route_mutex);	if(rc == false)	{		table_free ((void *)sptr_external_route);		sptr_external_route = NULL;	}	/* SPR#76812 -- End */	return;}/*************************************************************************** ospf_queue_export_route_to_ospf - queue the external route** This routine will add the external route to the external route* queue.** <destination_network> Destination network for external route** <network_mask> Network mask for external route** <metric> Metric for external route** <forwarding_address> Forwarding address for external route** <tag> Tag for external route** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/void ospf_queue_export_route_to_ospf (ULONG destination_network,ULONG network_mask,ULONG metric,ULONG forwarding_address,ULONG tag, ULONG proto){	OSPF_EXTERNAL_ROUTE *sptr_external_route;	BOOLEAN rc = false;	OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_queue_export_route_to_ospf\r\n");	sptr_external_route = NULL;	sptr_external_route = (OSPF_EXTERNAL_ROUTE *) table_malloc (1, sizeof (OSPF_EXTERNAL_ROUTE));	if (sptr_external_route == NULL)		{		ospf_print_memory_error_message_and_free_buffer_if_necessary ((void *) NULL, "OSPF_EXTERNAL_ROUTE");		return;		}	memset (sptr_external_route, 0x00, sizeof (OSPF_EXTERNAL_ROUTE));	sptr_external_route->sptr_forward_link = NULL;	sptr_external_route->sptr_backward_link = NULL;	sptr_external_route->destination_network = destination_network;	sptr_external_route->destination_mask = network_mask;	/* SPR 83418 -- Begin */	sptr_external_route->metric = metric;	/* SPR 83418 -- End */	sptr_external_route->forwarding_address = forwarding_address;	sptr_external_route->tag = tag;	sptr_external_route->time_stamp = time (NULL);	/* SPR 85050 -- Begin */	sptr_external_route->route_protocol = proto;	/* SPR 85050 -- End */	/* SPR#76812 -- Begin */	semTake (ospf_external_route_mutex, (UINT)WAIT_FOREVER);	rc = ospf_container_add_back (ospf.sptr_external_route_queue, sptr_external_route);	semGive (ospf_external_route_mutex);	if(rc == false)	    {		table_free ((void *)sptr_external_route);		sptr_external_route = NULL;	    }	/* SPR#76812 -- End */	OSPF_PRINTF_ROUTING_TABLE (OSPF_ROUTING_TABLE_PRINTF, "----->>>>> External Route from RTM: Destination:%lx net mask:%lx metric:%d forwarding address:%lx tag:%lx\r\n",		sptr_external_route->destination_network, sptr_external_route->destination_mask, (metric & OSPF_LSInfinity),		sptr_external_route->forwarding_address, sptr_external_route->tag);    }

⌨️ 快捷键说明

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