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

📄 ospf_transmit.c

📁 vxworks下ospf协议栈
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ospf_transmit.c - OSPF transmit *//* Copyright 2000-2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02f,18aug03,agi Changed call to ospf_MD_string() to common code mdString()02e,30jul03,agi Changed call to MD_string() to ospf_MD_string()02d,26may03,agi Changed rwos_get_system_elapsed_time_second() to                ospf_get_system_elapsed_time_second()02c,22apr03,ram SPR#76812 Modifications for OSPF performance enhancements02b,03dec02,ram	SPR 84312 - Change elapsed time to return seconds02a,08oct02,agi Fixed compiler warnings 25,12november,jkw			Virtual link hello fix. 24,13october01,kc			Dynamic configuration changes. 23,13october01,br			Virtual link updates 22,22september01,kc		Removed references to port number in ospf_send_packet() 21,23august01,jkw			Fixed compiler warnings. 20,20june01,jkw			Added unnumbered link support 19,11may01,aos				Added null pointer checks 18,1may01,aos				In ospf_get_an_ip_send_packet() removed fixed size cluster size to packet_size 17,26september00,reshma	Added WindRiver CopyRight 16 25september00,reshma	RFC-1587 implementation for OSPF NSSA Option, also tested against ANVL. 15,07july00,reshma			Unix compatibility related changes. 14,04april00,reshma		Added some MIB support (Read only).Passed all important ANVL OSPF tests. 13,23december99,reshma		Compatibility with VxWorks-IP and VxWorks RTM-interface 12,13august99,jack			ifdefed lsl control calls 11,28december98,jack		Compiled and added some comments 10,11november98,jack		Config changes, linted and big endian changes 09,30october98,jack		Incorporate changes for compilation on Vxworks 08,23august98,jack			ANVL tested OSPF with PATRICIA tree route table and no recursion 07,10august98,jack			PATRICIA Route Table Based OSPF Code Base 06,04june98,jack			Integration with RTM and BGP 05,24april98,jack			RTM changes 04,10july97,cindy			Pre-release v1.52b 03,02october97,cindy		Release Version 1.52 02,22october96,cindy		Release Version 1.50 01,05june96,cindy			First Beta Release*//*DESCRIPTIONospf_transmit.c is used for transmiting OSPF packets to the appropriate destinations.  This filefinds the destinations for the packets and calls the appropriate functions to transmit the OSPFpacket.This file is used every time an OSPF packet needs to be transmitted.*/#include "ospf.h"#if defined (__OSPF_VIRTUAL_STACK__)#include "ospf_vs_lib.h"#endif /* __OSPF_VIRTUAL_STACK__ */#include <net/mbuf.h>#include <netBufLib.h>#include <net/mbuf.h>#include <tickLib.h>/**************************************************************************************************************************************/static STATUS ospf_initialize_ospf_packet_header (OSPF_HEADER *sptr_packet,enum OSPF_UNION_PACKET_TYPES type, ULONG *ulptr_length /* in host order */,	OSPF_INTERFACE *sptr_interface);static STATUS ospf_initialize_checksum_and_authentication (OSPF_HEADER *sptr_packet,ULONG *ulptr_length /* in host order */,	OSPF_INTERFACE *sptr_interface);static OSPF_AUTHENTICATION_KEY *ospf_get_best_key_to_use_for_md5_authentication (OSPF_INTERFACE *sptr_interface);static void ospf_send_packet_to_all_neighbors_in_up_state (OSPF_HEADER *sptr_packet,ULONG length /* in host order */,	OSPF_INTERFACE *sptr_interface,enum BOOLEAN free_packet);static void ospf_send_packet_to_all_eligible_neighbors (OSPF_HEADER *sptr_packet,ULONG length /* in host order */,	OSPF_INTERFACE *sptr_interface,enum BOOLEAN free_packet);static void ospf_send_packet_to_all_neighbors_in_exchange_state (OSPF_HEADER *sptr_packet,ULONG length /* in host order */,	OSPF_INTERFACE *sptr_interface,enum BOOLEAN free_packet);static void ospf_send_packet_to_designated_router_and_backup_designated_router (OSPF_HEADER *sptr_packet,ULONG length /* in host order */,	OSPF_INTERFACE *sptr_interface,enum BOOLEAN free_packet);static void ospf_send_packet (OSPF_HEADER *sptr_packet,ULONG length /* in host order */,ULONG destination_address,	OSPF_INTERFACE *sptr_interface,enum BOOLEAN free_packet);static ULONG ospf_virtual_link_convert_rid_to_interface_addresss( ULONG destination_address, OSPF_AREA_ENTRY *sptr_transit_area );/**********************************************************************************//* section 8.1 of OSPF specification (page 54-56) */void ospf_tx_packet (OSPF_HEADER *sptr_packet,OSPF_INTERFACE *sptr_interface,enum OSPF_UNION_PACKET_TYPES type,	ULONG length /* in host_order */,ULONG destination,enum BOOLEAN free_packet){	OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_tx_packet\r\n");	ospf_initialize_ospf_packet_header (sptr_packet, type, &length /* in host order */, sptr_interface);	switch (destination)									/* Handle OSPF_NBMA send cases */		{		case OSPF_ALL_UP_NEIGHBORS:			{			ospf_send_packet_to_all_neighbors_in_up_state (sptr_packet, length /* in host order */, sptr_interface, free_packet);			break;			}		case OSPF_ALL_ELIGIBLE_NEIGHBORS:			{			ospf_send_packet_to_all_eligible_neighbors (sptr_packet, length /* in host order */, sptr_interface, free_packet);			break;			}		case OSPF_ALL_EXCHANGE_NEIGHBORS:			{			ospf_send_packet_to_all_neighbors_in_exchange_state (sptr_packet, length /* in host order */, sptr_interface, free_packet);			break;			}		case OSPF_DESIGNATED_ROUTER_AND_BACKUP_DESIGNATED_ROUTER:			{			ospf_send_packet_to_designated_router_and_backup_designated_router (sptr_packet, length /* in host order */, sptr_interface,				free_packet);			break;			}		default:			{			ospf_send_packet (sptr_packet, length /* in host order */, destination, sptr_interface, free_packet);			break;			}		}	return;}/**************************************************************************************************************************************/static STATUS ospf_initialize_ospf_packet_header (OSPF_HEADER *sptr_packet,enum OSPF_UNION_PACKET_TYPES type, ULONG *ulptr_length /* in host order */,	OSPF_INTERFACE *sptr_interface){	OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_initialize_ospf_packet_header\r\n");	sptr_packet->version = OSPF_VERSION;	sptr_packet->type = (BYTE_ENUM (OSPF_UNION_PACKET_TYPES)) type;	sptr_packet->router_id = ospf.router_id;	sptr_packet->router_id = host_to_net_long (sptr_packet->router_id);	sptr_packet->length = (USHORT) *ulptr_length;	sptr_packet->length = host_to_net_short (sptr_packet->length);	if (sptr_interface->type == OSPF_VIRTUAL_LINK)		{		sptr_packet->area_id = OSPF_BACKBONE;		}	else		{		sptr_packet->area_id = host_to_net_long (sptr_interface->sptr_area->area_id);		}	ospf_initialize_checksum_and_authentication (sptr_packet, ulptr_length /* in host order */, sptr_interface);	return OK;}/**************************************************************************************************************************************/static STATUS ospf_initialize_checksum_and_authentication (OSPF_HEADER *sptr_packet,ULONG *ulptr_length /* in host order */,	OSPF_INTERFACE *sptr_interface){	OSPF_AUTHENTICATION_KEY *sptr_authentication_key;	BYTE bptr_digest[OSPF_AUTHENTICATION_SIZE];	BYTE *bptr_end_of_packet;	USHORT index;	ULONG length_of_OSPF_packet;	OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_initialize_checksum_and_authentication\r\n");	switch (sptr_interface->authentication.type)		{		case OSPF_AUTHENTICATION_NONE:			{			sptr_packet->authentication_type = OSPF_AUTHENTICATION_NONE;			sptr_packet->authentication_type = host_to_net_short (sptr_packet->authentication_type);			memset (sptr_packet->authentication_field.key_or_plain_text_passwd, 0x0, OSPF_AUTHENTICATION_SIMPLE_SIZE);			sptr_packet->checksum = 0x0000;			sptr_packet->checksum = calculate_ip_checksum (NULL, (BYTE *) sptr_packet, (USHORT) *ulptr_length /* in host order */);			break;			}		case OSPF_AUTHENTICATION_SIMPLE:			{			sptr_packet->authentication_type = OSPF_AUTHENTICATION_SIMPLE;			sptr_packet->authentication_type = host_to_net_short (sptr_packet->authentication_type);			memset (sptr_packet->authentication_field.key_or_plain_text_passwd, 0x0, OSPF_AUTHENTICATION_SIMPLE_SIZE);			sptr_packet->checksum = 0x0000;			sptr_packet->checksum = calculate_ip_checksum (NULL, (BYTE *) sptr_packet, (USHORT) *ulptr_length /* in host order */);			memcpy ((void*) &(sptr_packet->authentication_field.key_or_plain_text_passwd), (void*) &(sptr_interface->authentication.key_or_plain_text_passwd), OSPF_AUTHENTICATION_SIMPLE_SIZE);			break;			}		case OSPF_AUTHENTICATION_MD5:			{			length_of_OSPF_packet = *ulptr_length;			sptr_packet->authentication_type = OSPF_AUTHENTICATION_MD5;			sptr_packet->authentication_type = host_to_net_short (sptr_packet->authentication_type);			sptr_packet->checksum = 0x0000;			/* Initialize MD5 fields */			sptr_packet->authentication_field.md5.offset = 0x0000;			sptr_authentication_key = ospf_get_best_key_to_use_for_md5_authentication (sptr_interface);			sptr_packet->authentication_field.md5.key_ID = sptr_authentication_key->key_ID;			sptr_packet->authentication_field.md5.authentication_data_length = OSPF_AUTHENTICATION_MD5_SIZE;			/* SPR 84312 -- Begin */			sptr_packet->authentication_field.md5.cryptographic_sequence_number = ospf_get_system_elapsed_time_second ();			/* Sequence is current time */			/* SPR 84312 -- End */			sptr_packet->authentication_field.md5.cryptographic_sequence_number =				host_to_net_long (sptr_packet->authentication_field.md5.cryptographic_sequence_number);			/* append secret key to the end of the OSPF packet */			bptr_end_of_packet = (BYTE *) sptr_packet;			for (index = 0x0000; index < length_of_OSPF_packet; ++index)				{				++bptr_end_of_packet;				/* go to end of packet */				}			memcpy ((void *) bptr_end_of_packet, (const void *) (sptr_authentication_key->md5_16byte_password), (size_t) OSPF_AUTHENTICATION_MD5_SIZE);

⌨️ 快捷键说明

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