📄 pppncprx.c
字号:
/* pppncprx.c - IPCP receive packet processing *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01j,05nov02,ijm use printf instead of logMsg01i,28may02,rvr fixed build warnings01h,22may02,vk modified the function initialize_ip_ncp for IPV6CP support01g,08nov01,ijm trim excess bytes from packet received, SPR#6433401f,01nov01,ijm free conf request packet received in state CLOSING, STOPPING, or CLOSED. Free termination request packet01e,20mar00,sj on receiving conf ack/nak/reject free last txed conf req01d,03mar00,sj do not accept any packets in INITIAL OR CLOSED states01c,29feb00,cn changed ncp_configure_request_received to check the total packet lenght.01b,23feb00,cn changed NUMBER_OF_PPP_CONTROL_CODES to PPP_IPCP_CONTROL_CODES_NUM.01a,12oct99,sgv created*//**$Log:: /Rtrware/devdrvrs/ppp/pppncpr $ * * 7 10/01/98 11:43a Alex * Updated the PPP source code to conform * to a single build. * * 6 4/30/98 3:03p Alex * Ppp v4.2.0 check in * * 1 4/24/98 12:10a Release Engineer * code cleanup, code style changes, * linted, system level test * PPP v4.2.0*/#include "private/ppp/pppIpv6cpComponentP.h"#include "private/ppp/pppstate.h"#include "private/ppp/pppoptn.h"#include "private/ppp/pppIpcpComponentP.h"#include "private/ppp/pppNcpLibP.h" LOCAL void ncp_configure_request_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void ncp_configure_ack_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void ncp_configure_nak_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void ncp_configure_reject_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void ncp_code_reject_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void ncp_termination_request_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet); LOCAL void ncp_termination_ack_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void illegal_ncp_code_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL TEST process_ncp_configuration_options (PFW_PLUGIN_OBJ_STATE *pluginState, OPTION_LISTS * sptr_option_lists, M_BLK_ID packet);LOCAL TEST process_ncp_configuration_nak_options (PFW_PLUGIN_OBJ_STATE *pluginState, OPTION_LISTS * sptr_option_lists, M_BLK_ID packet);/********************************************************************************* initialize_ip_ncp - intialize IPCP control layer*/void initialize_ip_ncp ( PFW_PLUGIN_OBJ_STATE * pluginState ) { NCP_STACK_DATA * pStackData = (NCP_STACK_DATA * )pluginState->stackData; PPP_NCP_COMPONENT * ncpComponent = (PPP_NCP_COMPONENT * )pluginState->pluginObj; pStackData->stateData.state = PPP_INITIAL_STATE; pStackData->stateData.old_state = PPP_INITIAL_STATE; ncpComponent->fptr_ncp_packet_received[0x00] = illegal_ncp_code_received; ncpComponent->fptr_ncp_packet_received[CONFIGURE_REQUEST] = ncp_configure_request_received; ncpComponent->fptr_ncp_packet_received[CONFIGURE_NAK] = ncp_configure_nak_received; ncpComponent->fptr_ncp_packet_received[CONFIGURE_ACK] = ncp_configure_ack_received; ncpComponent->fptr_ncp_packet_received[CONFIGURE_REJECT] = ncp_configure_reject_received; ncpComponent->fptr_ncp_packet_received[TERMINATION_REQUEST] = ncp_termination_request_received; ncpComponent->fptr_ncp_packet_received[TERMINATION_ACK] = ncp_termination_ack_received; ncpComponent->fptr_ncp_packet_received[CODE_REJECT] = ncp_code_reject_received; ncpComponent->fptr_ncp_packet_received[PROTOCOL_REJECT] = illegal_ncp_code_received; ncpComponent->fptr_ncp_packet_received[PPP_ECHO_REQUEST] = illegal_ncp_code_received; ncpComponent->fptr_ncp_packet_received[PPP_ECHO_REPLY] = illegal_ncp_code_received; ncpComponent->fptr_ncp_packet_received[DISCARD_REQUEST] = illegal_ncp_code_received; }/********************************************************************************* ncp_packet_received - IPCP packet receive handler*/TEST ncp_packet_received ( PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet ) { BYTE packetCode; USHORT number_of_bytes_rxed; NCP_PACKET * sptr_ipcp_rx_packet; NCP_STACK_DATA *pStackData = (NCP_STACK_DATA *)pluginState->stackData; PPP_NCP_COMPONENT * ipcpComponent = (PPP_NCP_COMPONENT * )pluginState->pluginObj; int pppPacketLength; int receivedBytesLessHdr; int excessBytes; if (pluginState == NULL || packet == NULL) return FAIL; sptr_ipcp_rx_packet = mtod(packet, NCP_PACKET *); if (packet->mBlkHdr.mNext != NULL) { number_of_bytes_rxed = packet->mBlkPktHdr.len;/* WindNet Multilink */ if (packet->mBlkHdr.mLen < 16) packet = m_pullup (packet, number_of_bytes_rxed); /* m_pullup was not used!!!*//* WindNet Multilink */ } else number_of_bytes_rxed = packet->mBlkHdr.mLen; pppPacketLength = ntohs(sptr_ipcp_rx_packet->ncp_header.length); receivedBytesLessHdr = number_of_bytes_rxed - sizeof(PPP_HEADER); /* we must have at least what the header says */ if (pppPacketLength > receivedBytesLessHdr) { netMblkClChainFree(packet); return (FAIL); } /* if we get more, trim the excess from the tail */ excessBytes = receivedBytesLessHdr - pppPacketLength; if (excessBytes) { m_adj (packet, -excessBytes);#ifdef PPP_DEBUG printf ("trimming %d excess bytes from NCP packet\n", excessBytes);#endif } if ((pStackData->stateData.state == PPP_INITIAL_STATE) || (pStackData->stateData.state == PPP_STARTING_STATE)) { netMblkClChainFree(packet); return (FAIL); } packetCode = sptr_ipcp_rx_packet->ncp_header.code; if (packetCode > PPP_IPCP_CONTROL_CODES_NUM) { /* force it the illegal_ncp_code_received function */ printf ("ncp_packet_received: code=%d\n", packetCode); packetCode = (BYTE_ENUM (PPP_CONTROL_CODE)) 0x00; } (*ipcpComponent->fptr_ncp_packet_received[packetCode]) (pluginState,packet); ++pStackData->statistics.number_of_rx_control_packets[packetCode]; ++pStackData->statistics.number_of_rx_packets; pStackData->statistics.number_of_rx_bytes += number_of_bytes_rxed; return (PASS); }/********************************************************************************* ncp_configure_request_received - */LOCAL void ncp_configure_request_received ( PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet ) { M_BLK_ID contiguousPacket = packet; NCP_PACKET *sptr_ipcp_rx_packet; USHORT number_of_bytes_rxed; NCP_STACK_DATA *pStackData = (NCP_STACK_DATA *)pluginState->stackData; USHORT number_of_bytes_without_options; if ((pStackData->stateData.state == PPP_CLOSING_STATE) || (pStackData->stateData.state == PPP_STOPPING_STATE)|| (pStackData->stateData.state == PPP_CLOSED_STATE)) { netMblkClChainFree (packet); return; } sptr_ipcp_rx_packet = mtod(packet, NCP_PACKET *); if (packet->mBlkHdr.mNext != NULL) { number_of_bytes_rxed = packet->mBlkPktHdr.len; contiguousPacket = m_pullup(packet, ntohs(sptr_ipcp_rx_packet->ncp_header.length)); if (contiguousPacket == NULL) return; } else number_of_bytes_rxed = packet->mBlkHdr.mLen; pStackData->last_rxed_ncp_configuration_request_packet = contiguousPacket; number_of_bytes_without_options = sizeof (NCP_PACKET); if (number_of_bytes_rxed >= number_of_bytes_without_options) { if (process_ncp_configuration_options (pluginState, &pStackData->option_lists, contiguousPacket) == FAIL) { return; } } execute_ppp_state_machine (pluginState, PPP_RECEIVE_CONFIGURE_REQUEST_GOOD_EVENT, NULL); }/********************************************************************************* ncp_configure_ack_received - */LOCAL void ncp_configure_ack_received ( PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet ) { M_BLK_ID contiguousPacket = packet; NCP_PACKET *sptr_ipcp_rx_packet; USHORT number_of_bytes_rxed; NCP_STACK_DATA *pStackData = (NCP_STACK_DATA *)pluginState->stackData; if (packet == NULL) return; sptr_ipcp_rx_packet = mtod(packet, NCP_PACKET *); /* option processing expects a contiguous buffer */ if (packet->mBlkHdr.mNext != NULL) { number_of_bytes_rxed = packet->mBlkPktHdr.len; contiguousPacket = m_pullup(packet, ntohs(sptr_ipcp_rx_packet->ncp_header.length)); if (contiguousPacket == NULL) return; } else number_of_bytes_rxed = packet->mBlkHdr.mLen; if (number_of_bytes_rxed != pStackData->length_of_last_txed_request) { printf("Number of bytes = %d len of last tx = %d\n", number_of_bytes_rxed, pStackData->length_of_last_txed_request); printf ("PPP:IPCP configuration ACK received with wrong length of \ packet for stack: 0x%x\n", (UINT32)pluginState->stackObj); netMblkClChainFree (contiguousPacket); return; } pStackData->statistics.number_of_rx_bytes += number_of_bytes_rxed; if (pStackData->last_txed_ncp_configuration_request_packet != NULL) { netMblkClChainFree ( pStackData->last_txed_ncp_configuration_request_packet); pStackData->last_txed_ncp_configuration_request_packet = NULL; } netMblkClChainFree (contiguousPacket); execute_ppp_state_machine (pluginState, PPP_RECEIVE_CONFIGURE_ACK_EVENT, NULL); }/********************************************************************************* ncp_configure_nak_received -*/LOCAL void ncp_configure_nak_received (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -