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

📄 pppnetworklayer.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* pppNetworkLayer.c - PPP Network Layer module *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01o,26nov02,ijm  add check for protocol = 0 in networkLayerReceive01n,05nov02,ijm  use printf instead of logMsg01m,21aug02,ijm  corrected debug logMsg01l,23jul02,ijm  add default acceptable protocols to pass PPP_IP_PROTOCOL                 and PPP_IPV6_PROTOCOL packets to the next layer in case                 neither VJC nor HC is negotiated.01k,03nov01,ijm  delete VJC acceptable protocols when VJC is deleted,                 SPR# 6987101j,28feb01,ijm  release interfaces when stack is deleted (SPR #63868)01i,22nov00,ijm  changed networkLayerStackDelete to handle NULL VJC01h,20mar00,cn   added missing updates to lastDeletedComponent.01g,01mar00,sj   use LCP_PACKET_SEND_INTERFACE to reject packets01f,23feb00,sj   Pedantic ANSI fixes01e,29nov99,sgv  Added comments01d,29oct99,sgv  modified to latest version of framework01c,23aug99,sgv  modified for generic framework01b,12jul99,koz  included new framework header files and updated interfaces                 accordingly01a,07jul99,koz  created.*//*DESCRIPTIONThis module implements the PPP Network Layer in the data plane*//* includes */#include "stdio.h"#include "stdlib.h"#include "string.h"#include "vxWorks.h"#include "logLib.h"#include "netBufLib.h"#include "ppp/kstart.h"#include "ppp/kppp.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "pfw/pfwLayer.h"#include "pfw/pfwMemory.h"#include "ppp/pppNetworkLayer.h"#include "ppp/interfaces/componentAcceptableProtocolsInterface.h"#include "ppp/interfaces/lcpInterfaces.h"#include "sllLib.h"/* defines *//* typedefs */typedef struct nlProtocolItem    {    struct nlProtocolItem *next;    PFW_PLUGIN_OBJ_STATE *state;    ACCEPTABLE_PROTOCOLS_ARRAY *acceptableProtocols;    } NL_PROTOCOL_ITEM;typedef struct networkLayerStackData   {   SL_LIST 	recvAcceptableProtocols;   SL_LIST 	sendAcceptableProtocols;   PFW_INTERFACE_STATE_PAIR   lcpPacketSend;   PFW_PLUGIN_OBJ_CALLBACKS   componentCallbacks;   PFW_PLUGIN_OBJ_CALLBACKS * callbacks;   PFW_PLUGIN_OBJ_STATE *     lastAddedComponent;   PFW_PLUGIN_OBJ_STATE *     lastDeletedComponent;   } NETWORK_LAYER_STACK_DATA;/* locals */LOCAL STATUS networkLayerSend ( PFW_PLUGIN_OBJ_STATE *state, M_BLK_ID *packet);LOCAL STATUS networkLayerReceive ( PFW_PLUGIN_OBJ_STATE *state, 	M_BLK_ID *packet);LOCAL STATUS networkLayerStackAdd ( PFW_PLUGIN_OBJ_STATE *state,    PFW_PLUGIN_OBJ_CALLBACKS * callbacks);LOCAL STATUS networkLayerStackDelete ( PFW_PLUGIN_OBJ_STATE *state);LOCAL STATUS networkLayerStackDataConstruct ( PFW_OBJ * pfw, void * stackData,    void * profileData);LOCAL STATUS networkLayerStackDataDestruct ( PFW_OBJ * pfw, void * stackData,    void * profileData);LOCAL void componentStackAddDone (PFW_PLUGIN_OBJ_CALLBACKS *,                                    PFW_PLUGIN_OBJ_STATE *componentState);LOCAL void componentStackDelDone (PFW_PLUGIN_OBJ_CALLBACKS *,                                    PFW_PLUGIN_OBJ_STATE *componentState);LOCAL STATUS componentAdd (PFW_COMPONENT_OBJ *);LOCAL BOOLEAN nlProtocolItemFree ( NL_PROTOCOL_ITEM * nlProtocolItem, int arg);LOCAL STATUS componentStackDynamicAdd (PFW_PLUGIN_OBJ_STATE *layerState,                                PFW_PLUGIN_OBJ_STATE *componentState);LOCAL STATUS componentStackDynamicDel (PFW_PLUGIN_OBJ_STATE *layerState,                                PFW_PLUGIN_OBJ_STATE *componentState);LOCAL UINT nlDefaultProtocolTypes[2] = {PPP_IP_PROTOCOL, PPP_IPV6_PROTOCOL};LOCAL ACCEPTABLE_PROTOCOLS_ARRAY nlDefaultRecvAcceptableProtocols =                                                {2, nlDefaultProtocolTypes};LOCAL BOOL protocolIsInDefaultList (USHORT protocol);/* forwards *//********************************************************************************* pppNetworkLayerCreate - create and initialize the ppp network layer** This routine is called to create the ppp network layer. It populates * the network layer object and adds the object to the ppp framework by * calling pfwLayerAdd routine.** RETURNS: OK or ERROR**/STATUS pppNetworkLayerCreate    (    PFW_OBJ *pfw    )    {    PFW_LAYER_OBJ *pNetworkLayer;    pNetworkLayer = (PFW_LAYER_OBJ *) pfwMalloc (pfw, sizeof (PFW_LAYER_OBJ));       if (pNetworkLayer == NULL)	{	printf ("pppNetworkLayerInit Unable to allocate memory\n");	return (ERROR);	}    bzero ((void *)pNetworkLayer, sizeof (PFW_LAYER_OBJ));    strcpy(pNetworkLayer->pluginObj.name, "NETWORK_LAYER");    pNetworkLayer->pluginObj.pfwObj = pfw;    pNetworkLayer->pluginObj.profileDataSize = 0;    pNetworkLayer->pluginObj.stackDataSize = sizeof (NETWORK_LAYER_STACK_DATA);    pNetworkLayer->pluginObj.stackDataConstruct 					   = networkLayerStackDataConstruct;    pNetworkLayer->pluginObj.stackDataDestruct = networkLayerStackDataDestruct;    pNetworkLayer->pluginObj.profileDataConstruct = NULL;    pNetworkLayer->pluginObj.profileDataDestruct = NULL;    pNetworkLayer->pluginObj.profileDataCopy = NULL;    pNetworkLayer->planeId = DATA_PLANE;    pNetworkLayer->position = 1;    pNetworkLayer->type = OPERATIONAL_LAYER;    pNetworkLayer->componentAdd = componentAdd;    pNetworkLayer->componentDelete = NULL;    pNetworkLayer->pluginObj.stackAdd = networkLayerStackAdd;    pNetworkLayer->pluginObj.stackDelete = networkLayerStackDelete;    pNetworkLayer->pluginObj.receive = networkLayerReceive;    pNetworkLayer->pluginObj.send = networkLayerSend;    pNetworkLayer->addDynamicComponentToStack = componentStackDynamicAdd;    pNetworkLayer->deleteDynamicComponentFromStack = componentStackDynamicDel;        if (pfwLayerAdd (pNetworkLayer) == ERROR)        {        printf ("pppNetworkLayerInit Network layer could not be added to the \                stack\n");        return (ERROR);        }    return (OK);    }/********************************************************************************* pppNetworkLayerDelete - delete the ppp network layer** This routine is called to delete the ppp network layer object from the ppp* framework by calling the pfwLayerDelete function.** RETURNS: OK or ERROR*/STATUS pppNetworkLayerDelete    (    PFW_OBJ *pfw    )    {    PFW_LAYER_OBJ *pNetworkLayer;    pNetworkLayer = (PFW_LAYER_OBJ *)pfwLayerObjGet (pfw, "NETWORK_LAYER");    if (pNetworkLayer == NULL)        return ERROR;    if (pfwLayerDelete (pNetworkLayer) == OK)        {        pfwFree (pNetworkLayer);        return OK;        }    return (ERROR);    }LOCAL STATUS componentAdd        (    PFW_COMPONENT_OBJ *obj     )    {    return (OK);    }	/********************************************************************************* networkLayerStackDataConstruct -**/LOCAL STATUS networkLayerStackDataConstruct    (    PFW_OBJ * pfw,    void * stackData,    void * profileData    )    {    NETWORK_LAYER_STACK_DATA *pStackData = 					(NETWORK_LAYER_STACK_DATA *)stackData;    sllInit ((SL_LIST *)&pStackData->recvAcceptableProtocols);    sllInit ((SL_LIST *)&pStackData->sendAcceptableProtocols);    pStackData->componentCallbacks.stackAddComplete = componentStackAddDone;    pStackData->componentCallbacks.stackDeleteComplete = componentStackDelDone;    return (OK);    }/******************************************************************************** networkLayerStackDataDestruct -*/LOCAL STATUS networkLayerStackDataDestruct    (    PFW_OBJ * pfw,    void * stackData,    void * profileData    )    {    NETWORK_LAYER_STACK_DATA * pStackData =                            (NETWORK_LAYER_STACK_DATA * )stackData;    sllEach ((SL_LIST *)&pStackData->recvAcceptableProtocols, 			nlProtocolItemFree, 0);    sllEach ((SL_LIST *)&pStackData->sendAcceptableProtocols,			nlProtocolItemFree, 0);    return OK;    }/********************************************************************************* networkLayerStackDelete -*/LOCAL STATUS networkLayerStackDelete    (    PFW_PLUGIN_OBJ_STATE *state    )    {    PFW_PLUGIN_OBJ_STATE * componentState;    NETWORK_LAYER_STACK_DATA *pStackData = 			(NETWORK_LAYER_STACK_DATA *) state->stackData;    /* Release interfaces */    if (pStackData->lcpPacketSend.interfaceObj != NULL)	pfwInterfaceReferenceDelete(	    (PFW_INTERFACE_OBJ *)pStackData->lcpPacketSend.interfaceObj);    if ((componentState = pfwFirstComponentStateGet (state)) == NULL)        {	/* The vjc component is deleted when pppConnectionClose is called	 * prior to pfwStackDelete	 */	pStackData->lastDeletedComponent = NULL;		if (pStackData->callbacks &&	    pStackData->callbacks->stackDeleteComplete)	    (*pStackData->callbacks->stackDeleteComplete)		    (pStackData->callbacks ,state);	return (OK);	}    pStackData->lastDeletedComponent = componentState;    return ((*componentState->pluginObj->stackDelete)(componentState));    }/********************************************************************************* networkLayerReceive -*/LOCAL STATUS networkLayerReceive   (   PFW_PLUGIN_OBJ_STATE *state,   M_BLK_ID *packet   )   {   NL_PROTOCOL_ITEM * nlProtocolItem = NULL;   PFW_COMPONENT_OBJ * componentObj;   int i;   struct mbuf *m;   BOOL found = FALSE;   USHORT protocol = 0;   NETWORK_LAYER_STACK_DATA *pStackData = 			(NETWORK_LAYER_STACK_DATA *)state->stackData;   LCP_PACKET_SEND_INTERFACE * lcpPacketSendInterface =	   (LCP_PACKET_SEND_INTERFACE *) pStackData->lcpPacketSend.interfaceObj;   m = (struct mbuf *)*packet;   /* Get the protocol id from the packet */   protocol = ((m->m_data[0]&0xff) << 8) + (m->m_data[1]&0xff);   nlProtocolItem = (NL_PROTOCOL_ITEM *)                     SLL_FIRST(&pStackData->recvAcceptableProtocols);   while (nlProtocolItem != NULL)       {       componentObj =                (PFW_COMPONENT_OBJ *)nlProtocolItem->state->pluginObj;       for (i = 0; i < nlProtocolItem->acceptableProtocols->numberOfProtocols;	    i++)       {       if (nlProtocolItem->acceptableProtocols->protocols[i] == protocol)	   {	   found = TRUE;#ifdef PPP_DEBUG           printf ("Rx proto = 0x%x ",                    nlProtocolItem->acceptableProtocols->protocols[i]);#endif /* PPP_DEBUG */	   break;	   }       if (found == TRUE)	   break;       }       if (!found)           nlProtocolItem = (NL_PROTOCOL_ITEM *)SLL_NEXT(nlProtocolItem);       else	   break;       }   if (nlProtocolItem == NULL || protocol == 0x0)       {       if (protocolIsInDefaultList (protocol) == TRUE)           {#ifdef PPP_DEBUG           printf ("Rx proto = 0x%x ",                   protocol);#endif /* PPP_DEBUG */           return (OK);           }#ifdef PPP_DEBUG       printf ("PPP: Unknown Protocol 0x%x rejected\n",(int)protocol);#endif /* PPP_DEBUG */       lcpPacketSendInterface->lcpProtocolRejectSend(				   pStackData->lcpPacketSend.state, *packet);       return (ERROR);       }   return (*nlProtocolItem->state->pluginObj->receive) (nlProtocolItem->state,						       packet);   }/********************************************************************************* networkLayerSend -*/LOCAL STATUS networkLayerSend   (   PFW_PLUGIN_OBJ_STATE *state,   M_BLK_ID *packet   )   {   NL_PROTOCOL_ITEM * nlProtocolItem = NULL;   PFW_COMPONENT_OBJ * componentObj;   USHORT protocol = 0;   BOOL found = FALSE;   struct mbuf *m;   int i;   NETWORK_LAYER_STACK_DATA *pStackData = 		(NETWORK_LAYER_STACK_DATA *)state->stackData;   /* Get the protocol id from the packet */   m = *packet;   protocol = ((m->m_data[0]&0xff) << 8) + (m->m_data[1]&0xff);

⌨️ 快捷键说明

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