ppplcprx.c
来自「这是全套的PPP协议的源码」· C语言 代码 · 共 1,396 行 · 第 1/3 页
C
1,396 行
/* ppplcprx.c - LCP received packet processing *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01x,05nov02,ijm use printf instead of logMsg01w,28may02,rvr fixed build warnings 01v,15jan02,ijm in protocol_reject_received, free packet in echo_request_received drop packet if not in OPENED state01u,07jan02,ijm discard LCP packets of length < LCP_HEADER, bad length protocol reject, echo requests/replies01t,03jan02,ijm do not drop unsolicited termination acks. in lcp_configure_request_received, free pStackData->last_rxed_lcp_configuration_request_packet01s,13nov01,ijm free last_rxed_lcp_termination_request_packet01r,08nov01,ijm trim excess bytes from received packet,SPR#6433401q,18sep01,ak free packet in lcp_configure_ack_received01p,06sep01,ijm free packet in discard_request_received, SPR#7028601o,20jun01,ak MP_LINK_TIME Interface01n,21feb01,ijm added missing ntohl conversions of magic_number to echo_reply_received and echo_request_received01m,18jan01,sj free contiguousPacket when recvd ACK does not match Rh REQ01l,15dec00,md use Minh Duong's version of previous fix(01k,13nov00,cn)01k,13nov00,cn replaced lcpDupRecvPkt() with lcpRecvPcktCopy() (SPR# 62317).01j,01aug00,adb Merging with openstack view01i,11jul00,md stored initial receive and last receive to support proxy authentication01h,17mar00,sj make sure that peer's magic number is not ours01g,02mar00,sj always accept packets length = default MRU = 150001f,01mar00,sj drop echo_request packets with bad magic numbers + check the length of PPP information is <= local MRU + debug Messages01e,25feb00,sj fixed protocol_reject, code_reject and length check in lcp_packet_received01d,24feb00,sj verify length of packet with length in LCP header01c,10jan00,sj magic in echo packets is a byte array01b,09nov99,sj do not pass rxed config request packet by argument01a,10oct99,sj created*/#include "private/ppp/pppstate.h"#include "private/ppp/pppoptn.h"#include "private/ppp/pppLcpComponentP.h"#define LOOP_BACK_DETECTION_USING_MAGIC_NUMBER/* * during LCP negotiation, we reject packets bigger than a default * MRU size (1500) plus PPP header (2) */#define PPP_LCP_MAX_RX_PCKT_SZ 1502LOCAL ULONG get_my_magic_number (void); /* XXX too many copies of this exist.*//**$Log:: /Rtrware/devdrvrs/ppp/ppplcpr $ * * 9 2/08/99 12:18p Nishit * lcp_configure_request_received() and * identification_packet_received() copy * the packet in the port class, and if * the packet size is larger than the * pre-allocated space, we had a memory * overwrite problem - fixed * * 8 10/06/98 7:36p Nishit * lcp_termination_ack_received: port * disabled if CLOSED * * 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*/LOCAL void lcp_configure_request_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void lcp_configure_ack_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void lcp_configure_nak_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void lcp_configure_reject_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void code_reject_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void protocol_reject_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void lcp_termination_request_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void lcp_termination_ack_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void echo_request_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void echo_reply_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void discard_request_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void identification_packet_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);#if defined (OLD_PPP)LOCAL void link_quality_report_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);#endifLOCAL void time_remaining_packet_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL void lcp_code_zero_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL FPTR_LCP_PACKET_RECEIVED lcp_received_packet_processors[] = { lcp_code_zero_received, lcp_configure_request_received, lcp_configure_ack_received, lcp_configure_nak_received, lcp_configure_reject_received, lcp_termination_request_received, lcp_termination_ack_received, code_reject_received, protocol_reject_received, echo_request_received, echo_reply_received, discard_request_received, identification_packet_received, time_remaining_packet_received };/******************************************************************************** lcpSetReceiveFunctions - set receive function pointers*/void lcpSetReceiveFunctions ( PPP_LCP_COMPONENT * lcpComponent ) { lcpComponent->fptr_lcp_packet_received = lcp_received_packet_processors; }/******************************************************************************** lcp_code_zero_received - */LOCAL void lcp_code_zero_received ( PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet ) { printf ("lcp_code_zero_received\n"); if (packet != NULL) netMblkClChainFree (packet); }/******************************************************************************** lcpRecvPcktCopy - copy the given packet ** RETURNS: The copied M_BLK_ID for the packet if successful, else NULL**/M_BLK_ID lcpRecvPcktCopy ( PFW_OBJ * pfwObj, M_BLK_ID pPacket /* packet to DUP */ ) { NET_POOL_ID pNetPool = NULL; M_BLK_ID pNewPacket = NULL; int totLen = 0; int copiedBytesNum = 0; if ((pPacket == NULL) || ((pNetPool = pfwNetPoolIdGet (pfwObj)) == NULL)) return NULL; if (pPacket->mBlkHdr.mNext != NULL) totLen = pPacket->mBlkPktHdr.len; else totLen = pPacket->mBlkHdr.mLen; if (totLen > PPP_LCP_MAX_RX_PCKT_SZ) {#ifdef PPP_DEBUG printf ("lcpRecvPcktCopy packet too big: len=%d\n",totLen);#endif /* PPP_DEBUG */ return NULL; } /* get a new mBlk chain */ if ((pNewPacket = netTupleGet (pNetPool, totLen, M_DONTWAIT, MT_DATA, TRUE)) == NULL) {#ifdef PPP_DEBUG printf ("lcpRecvPcktCopy failed to allocate new packet: \n");#endif /* PPP_DEBUG */ return NULL; } /* copy the entire packet */ do { bcopy (pPacket->mBlkHdr.mData, pNewPacket->mBlkHdr.mData + copiedBytesNum, pPacket->mBlkHdr.mLen); copiedBytesNum += pPacket->mBlkHdr.mLen; pPacket = pPacket->mBlkHdr.mNext; } while (pPacket != NULL); /* update the packet and mBlk length */ pNewPacket->mBlkPktHdr.len = copiedBytesNum; pNewPacket->mBlkHdr.mLen = copiedBytesNum;#ifdef PPP_DEBUG printf ("lcpRecvPcktCopy copied LCP packet: len=%d\n",copiedBytesNum);#endif /* PPP_DEBUG */ return pNewPacket; }/******************************************************************************** lcp_packet_received - */TEST lcp_packet_received ( PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet ) { BYTE packetCode; USHORT number_of_bytes_rxed; LCP_PACKET * sptr_lcp_rx_packet; LCP_STACK_DATA *pStackData = (LCP_STACK_DATA *)pluginState->stackData; PPP_LCP_COMPONENT * lcpComponent = (PPP_LCP_COMPONENT * )pluginState->pluginObj; USHORT pppPacketLength; int receivedBytesLessHdr; int excessBytes; if (pluginState == NULL || packet == NULL) return FAIL; if (pStackData->stateData.state < PPP_CLOSED_STATE) { netMblkClChainFree (packet); return FAIL; } sptr_lcp_rx_packet = mtod(packet, LCP_PACKET *); 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; pppPacketLength = ntohs(sptr_lcp_rx_packet->lcp_header.length);#ifdef PPP_DEBUG printf ("LCP Packet Received: code %d, length %d, ID %d\n", sptr_lcp_rx_packet->lcp_header.code, pppPacketLength, sptr_lcp_rx_packet->lcp_header.id);#endif /* PPP_DEBUG */ receivedBytesLessHdr = number_of_bytes_rxed - sizeof(PPP_HEADER); /* * we must have at least what the header says, and at least as much * as the LCP header size */ if (pppPacketLength > receivedBytesLessHdr || pppPacketLength < sizeof(LCP_HEADER)) {#ifdef PPP_DEBUG printf ("LCP Packet dropped: bad length %d, ID %d\n",pppPacketLength, sptr_lcp_rx_packet->lcp_header.id);#endif /* PPP_DEBUG */ netMblkClChainFree(packet); return (PASS); } /* if we get more, trim the excess from the tail */ excessBytes = receivedBytesLessHdr - (int) pppPacketLength; if (excessBytes) m_adj (packet, -excessBytes); /* accept PPP packets of length < local MRU OR default MRU */ if ((pppPacketLength > pStackData->lcp_mibs.pppLinkStatusLocalMRU) && (pppPacketLength != DEFAULT_MAXIMUM_MRU)) {#ifdef PPP_DEBUG printf ("LCP Packet dropped: length %d, ID %d\n",pppPacketLength, sptr_lcp_rx_packet->lcp_header.id);#endif /* PPP_DEBUG */ netMblkClChainFree(packet); return (PASS); } packetCode = sptr_lcp_rx_packet->lcp_header.code; if ((packetCode > NUMBER_OF_PPP_CONTROL_CODES) || (packetCode == (BYTE) 0x00)) { printf ("LCP:Illegal code Received for stack: 0x%x\n", (UINT32)pluginState->stackObj); execute_ppp_state_machine (pluginState,PPP_RECEIVE_UNKNOWN_CODE_EVENT, packet); ++pStackData->link_quality_counters.ifInErrors; pStackData->link_quality_counters.InGoodOctets -= number_of_bytes_rxed; return (PASS); } (*lcpComponent->fptr_lcp_packet_received[packetCode]) (pluginState,packet); ++pStackData->lcp_statistics.number_of_rx_packets; ++pStackData->lcp_statistics.number_of_control_rx_packets[packetCode]; pStackData->lcp_statistics.number_of_rx_bytes += number_of_bytes_rxed; return (PASS); }/******************************************************************************** lcp_configure_request_received -*/LOCAL void lcp_configure_request_received ( PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet ) { M_BLK_ID contiguousPacket = packet; LCP_PACKET *sptr_lcp_rx_packet; USHORT number_of_bytes_rxed; OPTION_PARSE_RESULT parse_result; PPP_EVENT ppp_event = PPP_RECEIVE_CONFIGURE_REQUEST_GOOD_EVENT; LCP_STACK_DATA *pStackData = (LCP_STACK_DATA *)pluginState->stackData;#ifdef LOOP_BACK_DETECTION_USING_MAGIC_NUMBER OPTION_LIST_ENTRY * localMagicOption; OPTION_LIST_ENTRY * peerMagicOption; OPTION_LIST_ENTRY * nakMagicOption; ULONG magic_number;#endif /* LOOP_BACK_DETECTION_USING_MAGIC_NUMBER */ /* shankarj */ /* if (pStackData->stateData.state < PPP_STOPPED_STATE) netMblkClChainFree (packet);*/ sptr_lcp_rx_packet = mtod(packet,LCP_PACKET *);#ifdef PPP_DEBUG printf ("LCP configure request received: time %ld, ID %d\n",tickGet(), sptr_lcp_rx_packet->lcp_header.id);#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_lcp_rx_packet->lcp_header.length)); if (contiguousPacket == NULL) return; } else number_of_bytes_rxed = packet->mBlkHdr.mLen; sptr_lcp_rx_packet = mtod(contiguousPacket,LCP_PACKET *); if (number_of_bytes_rxed >= LCP_PACKET_HEADER_SIZE) { /* strip LCP header */ contiguousPacket->mBlkHdr.mLen -= LCP_PACKET_HEADER_SIZE; contiguousPacket->mBlkHdr.mData += LCP_PACKET_HEADER_SIZE; parse_result = parse_ppp_options_from_configure_request ( pluginState->pluginObj->pfwObj, &pStackData->option_lists,contiguousPacket, pluginState); if (parse_result == OPTION_PARSING_ERROR) { printf ("LCP: received bad Configure Request\n"); netMblkClChainFree(contiguousPacket); return; } if (parse_result == SOME_OPTIONS_ARE_REJECTED) ppp_event = PPP_RECEIVE_CONFIG_REQUEST_BAD_OPTION_EVENT; else if (parse_result == SOME_OPTIONS_ARE_NACKED) ppp_event = PPP_RECEIVE_CONFIGURE_REQUEST_BAD_EVENT; else ppp_event = PPP_RECEIVE_CONFIGURE_REQUEST_GOOD_EVENT;#ifdef LOOP_BACK_DETECTION_USING_MAGIC_NUMBER if (ppp_event == PPP_RECEIVE_CONFIGURE_REQUEST_BAD_EVENT || ppp_event == PPP_RECEIVE_CONFIGURE_REQUEST_GOOD_EVENT) { peerMagicOption = find_matching_option(&pStackData->option_lists.rx_accepted, LCP_MAGIC_NUMBER); if (peerMagicOption != NULL) { localMagicOption = find_matching_option(&pStackData->option_lists.tx_accepted, LCP_MAGIC_NUMBER); if (localMagicOption != NULL) { if (localMagicOption->length == peerMagicOption->length) { if (memcmp (localMagicOption->uptr_data, peerMagicOption->uptr_data, peerMagicOption->length) == (int) NULL) { nakMagicOption = duplicate_option ( pluginState->pluginObj->pfwObj, peerMagicOption); if (nakMagicOption == NULL) { netMblkClChainFree(contiguousPacket); return; } magic_number = get_my_magic_number ();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?