ppplcprx.c

来自「这是全套的PPP协议的源码」· C语言 代码 · 共 1,396 行 · 第 1/3 页

C
1,396 行
字号
        ntohs(sptr_lcp_rx_packet->length) <        (sizeof(LCP_HEADER) + sizeof(PPP_PROTOCOL_TYPE))       )        {        /* silently drop bad length packets */#ifdef PPP_DEBUG        printf ("LCP:Bad Length Protocol Reject Received: stack 0x%x\n",                        (UINT32)pluginState->stackObj);#endif /* PPP_DEBUG */        netMblkClChainFree (packet);        return;        }    rejectedProtocol = 	ntohs(sptr_lcp_rx_packet->rejected_protocol_and_information.protocol);    /* all we need is protocol #: free packet */    netMblkClChainFree(packet);    if (pStackData->stateData.state != PPP_OPENED_STATE && 					    rejectedProtocol != LCP_PROTOCOL)	{	/* silently discard bad protocol packets */#ifdef PPP_DEBUG        printf ("LCP:Bad Protocol Reject Received: 0x%x stack 0x%x\n",                rejectedProtocol, (UINT32)pluginState->stackObj);#endif /* PPP_DEBUG */	return;	}#ifdef PPP_DEBUG    printf ("LCP: Protocol Reject Received: 0x%x stack 0x%x\n",            rejectedProtocol,(UINT32) pluginState->stackObj);#endif /* PPP_DEBUG */    execute_ppp_state_machine (pluginState,PPP_RECEIVE_PROTOCOL_REJECT_EVENT,							    NULL);    /* tell control layer that a protocol was rejected*/    pStackData->controlLayerInterface->protocolRejected(pluginState,							    rejectedProtocol);    }/******************************************************************************** echo_request_received -*/LOCAL void echo_request_received    (    PFW_PLUGIN_OBJ_STATE * pluginState,    M_BLK_ID packet    )    {    ULONG magic_number;    ULONG receivedMagic;    ECHO_REQUEST_PACKET *sptr_lcp_rx_packet;    LCP_STACK_DATA *pStackData = (LCP_STACK_DATA *)pluginState->stackData;    if (pStackData->stateData.state != PPP_OPENED_STATE)        {        /* RFC 1661, s5.8: silently discard if not in LCP OPENED state */#ifdef PPP_DEBUG        printf ("LCP:Dropping echo request - state not OPENED: stack 0x%x\n",                        (UINT32)pluginState->stackObj);#endif /* PPP_DEBUG */        netMblkClChainFree (packet);        return;        }    sptr_lcp_rx_packet = mtod(packet,ECHO_REQUEST_PACKET *);    /* echo request packet includes 4 bytes for magic number */    if (ntohs(sptr_lcp_rx_packet->length) < (sizeof(LCP_HEADER) + 4))        {        /* silently drop bad length packets */#ifdef PPP_DEBUG        printf ("LCP:Bad Length Echo Request Received: stack 0x%x\n",                        (UINT32)pluginState->stackObj);#endif /* PPP_DEBUG */        netMblkClChainFree (packet);        return;        }    receivedMagic = (ULONG)(sptr_lcp_rx_packet->magic_number[0] <<24 |                            sptr_lcp_rx_packet->magic_number[1] <<16 |                            sptr_lcp_rx_packet->magic_number[2] <<8  |                            sptr_lcp_rx_packet->magic_number[3]);    if (copy_option (&pStackData->option_lists.rx_accepted,		    LCP_MAGIC_NUMBER, &magic_number,sizeof (magic_number))	== FAIL)	{	if (receivedMagic != DEFAULT_MAGIC_NUMBER)	    {#ifdef PPP_DEBUG	    printf ("LCP:Bad Echo Request Received; non default magic: stack 0x%x\n",			(UINT32)pluginState->stackObj);#endif /* PPP_DEBUG */	    netMblkClChainFree(packet);	    return;	    }	}    else	{	if (receivedMagic != ntohl(magic_number))	    {#ifdef PPP_DEBUG	    printf ("LCP:Bad Echo Request Received bad magic 0x%lx: stack 0x%x\n",		receivedMagic, (UINT32) pluginState->stackObj);#endif /* PPP_DEBUG */	    netMblkClChainFree(packet);	    return;	    }	}#ifdef PPP_DEBUG    printf ("LCP: Echo Request Received: time %ld, ID %d\n",           tickGet(), sptr_lcp_rx_packet->id);#endif /* PPP_DEBUG  */    pStackData->last_rxed_lcp_echo_request_packet = packet;    execute_ppp_state_machine (pluginState,PPP_RECEIVE_ECHO_REQUEST_EVENT,							    NULL);    /*pStackData->number_of_echo_requests = 0x0000;*/    }/******************************************************************************** echo_reply_received -*/LOCAL void echo_reply_received    (    PFW_PLUGIN_OBJ_STATE * pluginState,    M_BLK_ID packet    )    {    ULONG magic_number;    ECHO_REQUEST_PACKET *sptr_lcp_rx_packet;    LCP_STACK_DATA *pStackData = (LCP_STACK_DATA *)pluginState->stackData;    ULONG receivedMagic;    if (packet == NULL)	return;    sptr_lcp_rx_packet = mtod(packet,ECHO_REQUEST_PACKET *);    /* echo reply packet includes 4 bytes for magic number */    if (ntohs(sptr_lcp_rx_packet->length) < (sizeof(LCP_HEADER) + 4))        {        /* silently drop bad length packets */#ifdef PPP_DEBUG        printf ("LCP:Bad Length Echo Reply Received: stack 0x%x\n",                    (UINT32)pluginState->stackObj);#endif  /*PPP_DEBUG*/        netMblkClChainFree (packet);        return;        }    receivedMagic = (ULONG)(sptr_lcp_rx_packet->magic_number[0] <<24 |                            sptr_lcp_rx_packet->magic_number[1] <<16 |                            sptr_lcp_rx_packet->magic_number[2] <<8  |                            sptr_lcp_rx_packet->magic_number[3]);    if (copy_option (&pStackData->option_lists.rx_accepted,		LCP_MAGIC_NUMBER, &magic_number,sizeof (magic_number)) == FAIL)	{	if (receivedMagic != DEFAULT_MAGIC_NUMBER)	    {#ifdef PPP_DEBUG	    printf ("LCP:Bad Echo Reply Received: stack 0x%x\n",		    (UINT32)pluginState->stackObj);#endif  /*PPP_DEBUG*/	    netMblkClChainFree (packet);	    return;	    }	}    else	{	if (receivedMagic != ntohl(magic_number))	    {#ifdef PPP_DEBUG	    printf ("LCP:Bad Echo Reply Received : stack 0x%4x\n",                   (UINT32)pluginState->stackObj);#endif /* PPP_DEBUG */	    netMblkClChainFree (packet);	    return;	    }	}    netMblkClChainFree (packet);    if (pStackData->last_txed_echo_request_packet != NULL)	{	netMblkClChainFree (pStackData->last_txed_echo_request_packet);	pStackData->last_txed_echo_request_packet = NULL;	}#ifdef PPP_DEBUG    printf ("LCP: Echo Reply Received: time %ld, ID %d\n",            tickGet(), sptr_lcp_rx_packet->id);#endif /* PPP_DEBUG  */#if 0 /* WindNet Multilink - NOT SUPPORTED IN THIS RELEASE */ 	if (pStackData->is_mp_timing_the_link)		{		pfwEventRaise (pluginState->stackObj, 					   pStackData->pEchoReplyReceivedEventObj, 					  (void *) pluginState->stackObj);		}#endif /* WindNet Multilink - NOT SUPPORTED IN THIS RELEASE */    execute_ppp_state_machine (pluginState,PPP_RECEIVE_ECHO_REPLY_EVENT, NULL);    pStackData->number_of_echo_requests = 0x0000;    }/******************************************************************************** discard_request_received -*/LOCAL void discard_request_received    (    PFW_PLUGIN_OBJ_STATE * pluginState,    M_BLK_ID packet    )    {    ULONG magic_number;    DISCARD_REQUEST_PACKET *sptr_lcp_rx_packet;    USHORT number_of_bytes_rxed;    LCP_STACK_DATA *pStackData = (LCP_STACK_DATA *)pluginState->stackData;    if (packet == NULL)	return;    sptr_lcp_rx_packet = mtod(packet,DISCARD_REQUEST_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;    if (copy_option (&pStackData->option_lists.rx_accepted,LCP_MAGIC_NUMBER,		&magic_number,sizeof (magic_number)) == FAIL)	{	if (sptr_lcp_rx_packet->magic_number != DEFAULT_MAGIC_NUMBER)	    {	    printf ("LCP:Bad Discard Request Received: stack 0x%x\n",		    (UINT32)pluginState->stackObj);	    netMblkClChainFree (packet);	    return;	    }	}    else	{	if (sptr_lcp_rx_packet->magic_number != magic_number)	    {	    printf ("LCP:Bad Discard Request Received: stack 0x%x\n",		(UINT32)pluginState->stackObj);        netMblkClChainFree (packet);	    return;	    }	}    netMblkClChainFree (packet);    execute_ppp_state_machine (pluginState,PPP_RECEIVE_DISCARD_REQUEST_EVENT,							NULL);    ++pStackData->link_quality_counters.ifInDiscards;    pStackData->link_quality_counters.InGoodOctets -= number_of_bytes_rxed;    }#ifdef OLD_PPP/******************************************************************************** link_quality_report_received -*/LOCAL void link_quality_report_received    (    PFW_PLUGIN_OBJ_STATE * pluginState,    M_BLK_ID packet    )    {    M_BLK_ID contiguousPacket = packet;    LINK_QUALITY_REPORT *sptr_link_quality_report;    LCP_STACK_DATA *pStackData = (LCP_STACK_DATA *)pluginState->stackData;    if (packet == NULL)	return;    sptr_link_quality_report = mtod(packet, LINK_QUALITY_REPORT *);    /* option processing expects a contiguous buffer */    if (packet->mBlkHdr.mNext != NULL)	{	contiguousPacket = m_pullup(packet,sizeof(LINK_QUALITY_REPORT)); 	if (contiguousPacket == NULL)	    return;	}    sptr_link_quality_report = mtod(contiguousPacket, LINK_QUALITY_REPORT *);    ++pStackData->lcp_mibs.pppLqrInLQRs;    ++pStackData->link_quality_counters.InLQRs;    pStackData->most_recently_received_LQR = *sptr_link_quality_report;    pStackData->most_recently_received_LQR.SaveInLQRs =				pStackData->link_quality_counters.InLQRs;    pStackData->most_recently_received_LQR.SaveInPackets = 			    pStackData->link_quality_counters.ifInUniPackets;    pStackData->most_recently_received_LQR.SaveInDiscards = 			    pStackData->link_quality_counters.ifInDiscards;    pStackData->most_recently_received_LQR.SaveInErrors = 			    pStackData->link_quality_counters.ifInErrors;    pStackData->most_recently_received_LQR.SaveInOctets = 			    pStackData->link_quality_counters.InGoodOctets;    pStackData->lcp_mibs.pppLqrExtnsLastReceivedLqrPacket = 						*sptr_link_quality_report;    netMblkClChainFree (contiguousPacket);    }#endif /* OLD_PPP *//******************************************************************************** identification_packet_received -*/LOCAL void identification_packet_received    (    PFW_PLUGIN_OBJ_STATE * pluginState,    M_BLK_ID packet    )    {    USHORT number_of_bytes_in_message;    M_BLK_ID contiguousPacket = packet;    IDENTIFICATION_PACKET *sptr_identification_packet;    LCP_STACK_DATA *pStackData = (LCP_STACK_DATA *)pluginState->stackData;    sptr_identification_packet = mtod(packet, IDENTIFICATION_PACKET *);    /* option processing expects a contiguous buffer */    if (packet->mBlkHdr.mNext != NULL)	{	contiguousPacket = m_pullup(packet, 			ntohs(sptr_identification_packet->length));	if (contiguousPacket == NULL)	    return;	}    sptr_identification_packet = mtod(contiguousPacket,IDENTIFICATION_PACKET *);    number_of_bytes_in_message =	(USHORT) (ntohs (sptr_identification_packet->length) -	sizeof (sptr_identification_packet->magic_number) -sizeof (LCP_HEADER));    if (number_of_bytes_in_message <= 	    sizeof (pStackData->rx_identification_message))	{	number_of_bytes_in_message = 			sizeof (pStackData->rx_identification_message);	}    if (number_of_bytes_in_message >			    sizeof (pStackData->rx_identification_message))	{	printf ("LCP: ERROR Id Packet too large(%d): stack 0x%x\n",			    number_of_bytes_in_message,			    (UINT32)pluginState->stackObj);		memcpy (pStackData->rx_identification_message,			    sptr_identification_packet, 			    sizeof (pStackData->rx_identification_message));	}    else	{		memcpy (pStackData->rx_identification_message,		    sptr_identification_packet, number_of_bytes_in_message);	}#ifdef RW_UPCALL    if (ppp.fptr_event_upcall != NULL)	{	(*ppp.fptr_event_upcall) (PPP_EVENT_LCP_ID_REQUEST_RECEIVED,	    real_port_number,&sptr_identification_packet->message[0]);	}#else    (*pStackData->controlLayerInterface->pppLcpIdRequestReceived)(pluginState,				&sptr_identification_packet->message[0]);#endif    netMblkClChainFree (contiguousPacket);    execute_ppp_state_machine (pluginState,	    PPP_RECEIVE_CODE_REJECT_PERMITTED_EVENT,NULL);    }/******************************************************************************** time_remaining_packet_received -*/LOCAL void time_remaining_packet_received    (    PFW_PLUGIN_OBJ_STATE * pluginState,    M_BLK_ID packet    )    {    M_BLK_ID contiguousPacket = packet;    TIME_REMAINING_PACKET *sptr_time_remaining_packet;    LCP_STACK_DATA *pStackData = (LCP_STACK_DATA *)pluginState->stackData;    sptr_time_remaining_packet = mtod(packet, TIME_REMAINING_PACKET *);    /* option processing expects a contiguous buffer */    if (packet->mBlkHdr.mNext != NULL)	{	contiguousPacket = m_pullup(packet, 			ntohs(sptr_time_remaining_packet->length));	if (contiguousPacket == NULL)	    return;	}    sptr_time_remaining_packet = mtod(contiguousPacket,TIME_REMAINING_PACKET *);     pStackData->client_time_remaining =				sptr_time_remaining_packet->seconds_remaining;#ifdef RW_UPCALL    if (ppp.fptr_event_upcall != NULL)	{	(*ppp.fptr_event_upcall) (PPP_EVENT_LCP_TIME_REMAINING_RECEIVED,	    real_port_number, &sptr_time_remaining_packet->seconds_remaining);	}#else    (*pStackData->controlLayerInterface->pppLcpTimeRemainingReceived)		(pluginState,sptr_time_remaining_packet->seconds_remaining,				    &sptr_time_remaining_packet->message[0]);#endif    /* strip LCP header */    contiguousPacket->mBlkHdr.mLen -= LCP_PACKET_HEADER_SIZE;    contiguousPacket->mBlkHdr.mData += LCP_PACKET_HEADER_SIZE;    execute_ppp_state_machine (pluginState,		    PPP_RECEIVE_CODE_REJECT_PERMITTED_EVENT,contiguousPacket);    }/******************************************************************************** get_my_magic_number -*/LOCAL ULONG get_my_magic_number (void)    {    ULONG my_magic_number;    my_magic_number = random();    while (my_magic_number == 0x00000000L)	    {	    my_magic_number = random();	    }    return (my_magic_number);    }

⌨️ 快捷键说明

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