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

📄 pppbacprx.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* pppbacprx.c - BACP received packet processing *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02c,06aug02,jr  fixed build warnings 02b,16feb02,jr  Formatted the Debug Messages and initialized the local variables                as part of the memory reduction process01a,03feb01,sd 	created*//*DESCRIPTIONThis module implements the receive functios for the BACP protocol.bacp_packet_received function is called on receiving a BACP protocol packet,which calls the corresponding packet received function to process tha packetfurther.The configure request, reject and nak received functions call the option processing functions to process the received options.*//* includes */#include "ppp/pppBacpComponent.h"#include "private/ppp/pppBacpComponentP.h"#include "ppp/pppControlLayer.h"/* externs */IMPORT OPTION_PARSE_RESULT parse_bacp_options_from_configure_request	(PFW_OBJ *, OPTION_LISTS *,	M_BLK_ID, PFW_PLUGIN_OBJ_STATE *);IMPORT OPTION_PARSE_RESULT parse_bacp_options_from_nak_configure	(PFW_OBJ *, OPTION_LISTS *, M_BLK_ID, PFW_PLUGIN_OBJ_STATE *);IMPORT OPTION_PARSE_RESULT parse_ppp_options_from_reject_configure    (PFW_OBJ *, OPTION_LISTS *, M_BLK_ID);/* locals and forwards */LOCAL void bacp_code_zero_received (PFW_PLUGIN_OBJ_STATE * pluginState,						M_BLK_ID packet);LOCAL void bacp_configure_request_received (PFW_PLUGIN_OBJ_STATE *pluginState,						M_BLK_ID packet);LOCAL void bacp_configure_ack_received (PFW_PLUGIN_OBJ_STATE *pluginState,						M_BLK_ID packet);LOCAL void bacp_configure_nak_received (PFW_PLUGIN_OBJ_STATE *pluginState,						M_BLK_ID packet);LOCAL void bacp_configure_reject_received (PFW_PLUGIN_OBJ_STATE *pluginState,						M_BLK_ID packet);LOCAL void bacp_code_reject_received (PFW_PLUGIN_OBJ_STATE *pluginState,						M_BLK_ID packet);LOCAL void bacp_termination_request_received (PFW_PLUGIN_OBJ_STATE *pluginState,						M_BLK_ID packet);LOCAL void bacp_termination_ack_received (PFW_PLUGIN_OBJ_STATE *pluginState,						M_BLK_ID packet);LOCAL FPTR_BACP_PACKET_RECEIVED bacp_received_packet_processors[] = 			{			bacp_code_zero_received,			bacp_configure_request_received,			bacp_configure_ack_received,			bacp_configure_nak_received,			bacp_configure_reject_received,			bacp_termination_request_received,			bacp_termination_ack_received,			bacp_code_reject_received			};/******************************************************************************** bacpSetReceiveFunctions - set receive function pointers** This function initializes the BACP receive function pointers of the * BACP component structure** RETURNS: N/A*/void bacpSetReceiveFunctions 	(	PPP_BACP_COMPONENT * bacpComponent		/* BACP component */	)	{	bacpComponent->fptr_bacp_packet_received = bacp_received_packet_processors;	}/******************************************************************************** bacp_code_zero_received - */LOCAL void bacp_code_zero_received    (    PFW_PLUGIN_OBJ_STATE * pluginState,    M_BLK_ID packet    )    {    logMsg ("bacp_code_zero_received \n",1,2,3,4,5,6);    if (packet != NULL)		netMblkClChainFree (packet);    }/******************************************************************************** bacp_packet_received - process the received BACP packet** This routine is called by the bacpReceive () to process the BACP packets.* The received BACP packet is verified against various error conditions,* BACP packet header code is identified and corresponding packet processing * function is called. The BACP_STATISTICS_COUNTERS are updated for good packet* and the BACP_QUALITY_COUNTERS are updated for bad packet.** RETURNS: PASS/FAIL*/TEST bacp_packet_received	(	PFW_PLUGIN_OBJ_STATE * pluginState,		/* state for the stack */	M_BLK_ID packet							/* received BACP packet */	)	{	BYTE packetCode;	USHORT number_of_bytes_rxed = 0;	BACP_PACKET * sptr_bacp_rx_packet = NULL;	USHORT pppPacketLength = 0;	BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *)pluginState->stackData;	PPP_BACP_COMPONENT * pBacpComponent = 			(PPP_BACP_COMPONENT * )pluginState->pluginObj;	/* if packet or pluginState is NULL, return FAIL */	if (pluginState == NULL || packet == NULL)		{		return FAIL;		}	/* if state is < PPP_CLOSED_STATE, return FAIL */	if (pStackData->stateData.state < PPP_CLOSED_STATE)		{		netMblkClChainFree (packet);		return FAIL;		}	/* get a pointer to the BACP packet from the received packet */	sptr_bacp_rx_packet = mtod (packet, BACP_PACKET *);	/* get the number of received bytes */	if (packet->mBlkHdr.mFlags & M_PKTHDR  && packet->mBlkHdr.mNext != NULL)		number_of_bytes_rxed = packet->mBlkPktHdr.len;	else		number_of_bytes_rxed = packet->mBlkHdr.mLen;	/* if bytes received < (BACP header + PPP header), return */ 	if (number_of_bytes_rxed < (sizeof (BACP_HEADER) + sizeof (PPP_HEADER)))		{		netMblkClChainFree (packet);		return (PASS);		}	/* get the packet length */	pppPacketLength = ntohs (sptr_bacp_rx_packet->bacp_header.length);	if (pppPacketLength != (number_of_bytes_rxed - sizeof (PPP_HEADER)) || 			pppPacketLength < sizeof (BACP_HEADER))		{		netMblkClChainFree (packet);		return (PASS);		}	if ((pppPacketLength > pStackData->bundleLocalMRRU) && (pppPacketLength 												> DEFAULT_MAXIMUM_MRRU))		{#ifdef PPP_DEBUG	    logMsg ("PPP_BACP Rx Packet dropped: length %d, ID %d\n", pppPacketLength,				sptr_bacp_rx_packet->bacp_header.id,3,4,5,6);#endif /* PPP_DEBUG */		netMblkClChainFree (packet);		return (PASS);		}	/* get the BACP header code and check if it is valid */	packetCode = sptr_bacp_rx_packet->bacp_header.code;	if ((packetCode > CODE_REJECT) ||		(packetCode == (BYTE) 0x00))		{		logMsg ("PPP_BACP Rx Illegal Packet code Received for stack: 0x%x\n",				    (UINT32)pluginState->stackObj, 2, 3, 4, 5, 6);		execute_bacp_state_machine (pluginState, PPP_RECEIVE_UNKNOWN_CODE_EVENT,								packet);		/* update the link quality counters for invalid code */		++pStackData->link_quality_counters.ifInErrors;		if (pStackData->link_quality_counters.InGoodOctets >= number_of_bytes_rxed)			pStackData->link_quality_counters.InGoodOctets -= number_of_bytes_rxed;		else			pStackData->link_quality_counters.InGoodOctets = 0;		return (PASS);		}		/* call the corresponding packet processing function, if valid code */	(*pBacpComponent->fptr_bacp_packet_received [packetCode]) (pluginState ,												packet);	/* update the BACP statistics */	++pStackData->bacp_statistics.number_of_rx_packets;	++pStackData->bacp_statistics.number_of_control_rx_packets [packetCode];	pStackData->bacp_statistics.number_of_rx_bytes += number_of_bytes_rxed;	return (PASS);	}/******************************************************************************** bacp_configure_request_received - process configure request received ** This routine is called by the bacp_packet_received () to process the BACP * configuration request packet. The received BACP configuration request packet * is verified against error conditions. The received options are processed and * the execute_state_machine () is called with the appropriate event.** RETURNS: N/A*/LOCAL void bacp_configure_request_received	(	PFW_PLUGIN_OBJ_STATE * pluginState,		/* state for the stack */	M_BLK_ID packet							/* received BACP packet */	)	{	M_BLK_ID contiguousPacket = packet;	BACP_PACKET *sptr_bacp_rx_packet = NULL;	USHORT number_of_bytes_rxed = 0;	OPTION_PARSE_RESULT parse_result;	PPP_EVENT ppp_event = PPP_RECEIVE_CONFIGURE_REQUEST_GOOD_EVENT;	BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *)pluginState->stackData;	/* get a pointer to the BACP packet from the received packet */    sptr_bacp_rx_packet = mtod (packet, BACP_PACKET *);#ifdef PPP_DEBUG    logMsg ("PPP_BACP Rx ConfigReq : time %ld, ID %d\n",tickGet (),					sptr_bacp_rx_packet->bacp_header.id, 3, 4, 5, 6);#endif /* PPP_DEBUG */    /* option processing expects a contiguous buffer */	if (packet->mBlkHdr.mNext != NULL)		{		number_of_bytes_rxed = packet->mBlkPktHdr.len;		contiguousPacket = m_pullup (packet, 				ntohs (sptr_bacp_rx_packet->bacp_header.length));		if (contiguousPacket == NULL)			return;		}	else		number_of_bytes_rxed = packet->mBlkHdr.mLen;	sptr_bacp_rx_packet = mtod (contiguousPacket, BACP_PACKET *);	if (number_of_bytes_rxed >= BACP_PACKET_HEADER_SIZE)		{		/* strip BACP header */		contiguousPacket->mBlkHdr.mLen -= BACP_PACKET_HEADER_SIZE;		contiguousPacket->mBlkHdr.mData += BACP_PACKET_HEADER_SIZE;		/* parse the options to add to the accepted, nacked and rejected list */		parse_result = parse_bacp_options_from_configure_request (				pluginState->pluginObj->pfwObj, &pStackData->option_lists,				contiguousPacket, pluginState);		/* option parsing error */		if (parse_result == OPTION_PARSING_ERROR)			{			netMblkClChainFree (contiguousPacket);			return;			}				/* some options are rejected */		if (parse_result == SOME_OPTIONS_ARE_REJECTED)			ppp_event = PPP_RECEIVE_CONFIG_REQUEST_BAD_OPTION_EVENT;		else			/* some options are nacked */			if (parse_result == SOME_OPTIONS_ARE_NACKED)				{				ppp_event = PPP_RECEIVE_CONFIGURE_REQUEST_BAD_EVENT;				}			else				{				/* the options are acceptable */				ppp_event = PPP_RECEIVE_CONFIGURE_REQUEST_GOOD_EVENT;				}		/* undo stripping of BACP header */		contiguousPacket->mBlkHdr.mLen += BACP_PACKET_HEADER_SIZE;		contiguousPacket->mBlkHdr.mData -= BACP_PACKET_HEADER_SIZE;#ifdef PPP_DEBUG		logMsg ("PPP_BACP configReq processed: time %ld, ID %d\n", tickGet (),					sptr_bacp_rx_packet->bacp_header.id,3,4,5,6);#endif /* PPP_DEBUG */		pStackData->last_rxed_bacp_configuration_request_packet =					contiguousPacket;		/* take necessary action */		execute_bacp_state_machine (pluginState, ppp_event, NULL);		}	else /* number_of_bytes_rxed <= BACP_PACKET_HEADER_SIZE */		{		/* drop the packet */		netMblkClChainFree (contiguousPacket);		}	}/******************************************************************************** bacp_configure_ack_received - process the configure ack received** This routine is called by the bacp_packet_received () function to process the * BACP configuration ack packet. The received BACP configuration ack packet is * verified against error conditions. The execute_bacp_state_machine () function * is called with the PPP_RECEIVE_CONFIGURE_ACK_EVENT.* * RETURNS:N/A*/LOCAL void bacp_configure_ack_received	(	PFW_PLUGIN_OBJ_STATE * pluginState,		/* state for the stack */	M_BLK_ID packet							/* received BACP packet */	)	{	M_BLK_ID contiguousPacket = packet;	BACP_PACKET *sptr_bacp_rx_packet = NULL;	BACP_PACKET *sptr_bacp_last_tx_packet = NULL;	USHORT number_of_bytes_rxed = 0;	BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *)pluginState->stackData;	if (packet == NULL)		return;	/* get a pointer to the BACP packet */	sptr_bacp_rx_packet = mtod (packet, BACP_PACKET *);#ifdef PPP_DEBUG	logMsg ("PPP_BACP Rx configAck : time %ld, ID %d\n", tickGet (),			sptr_bacp_rx_packet->bacp_header.id,3,4,5,6);#endif /* PPP_DEBUG */	/* option processing expects a contiguous buffer */	if (packet->mBlkHdr.mNext != NULL)		{		number_of_bytes_rxed = packet->mBlkPktHdr.len;		contiguousPacket = m_pullup (packet, 				ntohs (sptr_bacp_rx_packet->bacp_header.length));		if (contiguousPacket == NULL)			return;		}	else		number_of_bytes_rxed = packet->mBlkHdr.mLen;	/* length of ACK packet must be equal to the sent request packet */	if (number_of_bytes_rxed != 		pStackData->length_of_last_txed_bacp_packet)		{		logMsg ("PPP_BACP Rx ConfigAck bad-length: expected %d: got %d:\		stack 0x%x\n",pStackData->length_of_last_txed_bacp_packet,		number_of_bytes_rxed,(UINT32)pluginState->stackObj, 4, 5, 6);		netMblkClChainFree (contiguousPacket);		return;		}	sptr_bacp_rx_packet = mtod (contiguousPacket, BACP_PACKET *);	/* ack packet must have the same id as the request packet acked */	if (sptr_bacp_rx_packet->bacp_header.id != 							pStackData->last_id_of_bacp_packet_sent)		{		logMsg ("PPP_BACP Rx ConfigAck : ID = %d doesn't match sent config request ID %d :\                        stack 0x%x", sptr_bacp_rx_packet->bacp_header.id,\                	pStackData->last_id_of_bacp_packet_sent,\                        (UINT32)pluginState->stackObj, 4, 5, 6);

⌨️ 快捷键说明

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