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

📄 pppvsend.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifdef INET6    if ((i = pfwInterfaceRegister(pfw,"PPP_IPV6_INTERFACE")) > 0)        {        pppIpv6Interface = &pComponent->pppIpv6Interface;        pppIpv6Interface->interfaceObj.id = i;        pppIpv6Interface->interfaceObj.pluginObj = pluginObj;        pppIpv6Interface->ipv6InterfaceDown = ipv6InterfaceDown;        pppIpv6Interface->ipv6InterfaceUp = ipv6InterfaceUp;        pfwInterfaceBind (&pppIpv6Interface->interfaceObj);        }#endif /* INET6 */    if ((i = pfwInterfaceRegister(pfw,                "COMPONENT_ACCEPTABLE_PROTOCOLS_INTERFACE")) > 0)        {        componentAcceptableProtocolsInterface =                        &pComponent->componentAcceptableProtocolsInterface;        componentAcceptableProtocolsInterface->interfaceObj.id = i;        componentAcceptableProtocolsInterface->interfaceObj.pluginObj                        = pluginObj;        componentAcceptableProtocolsInterface->            receivePathAcceptableProtocolsGet =                pppVsEndRxPathAcceptableProtocolsGet;        componentAcceptableProtocolsInterface->            sendPathAcceptableProtocolsGet =                pppVsEndSendPathAcceptableProtocolsGet;        pfwInterfaceBind            (&componentAcceptableProtocolsInterface->interfaceObj);        }    if ((i = pfwInterfaceRegister(pfw,"PPP_LINK_ID_INTERFACE")) > 0)        {        pppLinkIdInterface = &pComponent->pppLinkIdInterface;        pppLinkIdInterface->interfaceObj.id = i;        pppLinkIdInterface->interfaceObj.pluginObj = pluginObj;        pppLinkIdInterface->pppLinkIdGet = pppLinkIdGet;        pfwInterfaceBind (&pppLinkIdInterface->interfaceObj);        }    /* Register RFC2233 interfaces */    if  ((i = pfwInterfaceRegister(pfw,"PPP_IF_IFX_TABLE_INTERFACE")) > 0)        {        pppIfIfXTableInterface = &pComponent->pppIfIfXTableInterface;        pppIfIfXTableInterface->interfaceObj.id = i;        pppIfIfXTableInterface->interfaceObj.pluginObj = pluginObj;        pppIfIfXTableInterface->ifIfXCounterUpdate = ifCounterUpdateWrap;        pppIfIfXTableInterface->ifIfXVariableUpdate = ifVariableUpdateWrap;        pfwInterfaceBind (&pppIfIfXTableInterface->interfaceObj);        }    if  ((i = pfwInterfaceRegister(pfw,"PPP_IF_STACK_TABLE_INTERFACE")) > 0)        {        pppIfStackTableInterface = &pComponent->pppIfStackTableInterface;        pppIfStackTableInterface->interfaceObj.id = i;        pppIfStackTableInterface->interfaceObj.pluginObj = pluginObj;        pppIfStackTableInterface->ifStackStatusSet = ifStackStatusSet;        pfwInterfaceBind (&pppIfStackTableInterface->interfaceObj);        }#ifdef VIRTUAL_STACK    if ((i = pfwInterfaceRegister(pfw,"PPP_VSID_INTERFACE")) > 0)        {        pppVsidInterface = &pComponent->pppVsidInterface;        pppVsidInterface->interfaceObj.id = i;        pppVsidInterface->interfaceObj.pluginObj = pluginObj;        pppVsidInterface->pppVsidGet = pppVsidGetByState;        pppVsidInterface->pppVsidSet = pppVsidSetByState;        pfwInterfaceBind (&pppVsidInterface->interfaceObj);        }#endif /* VIRTUAL_STACK */    return (OK);    }/**************************************************************************** pppVsEndStackDataConstruct - initialize stack data*/LOCAL STATUS pppVsEndStackDataConstruct    (    PFW_OBJ * pfw,    void    * stackData,	/* reference to stack data */    void * profileData	/* reference to profile data */    )    {    PPP_VS_END_STACK_DATA *pStackData = stackData;#ifdef VIRTUAL_STACK    PPP_VS_END_PROFILE_DATA	* pEndProfileData =        (PPP_VS_END_PROFILE_DATA *) profileData;#endif /* VIRTUAL_STACK */    memset(pStackData,0,sizeof(PPP_VS_END_STACK_DATA));    pStackData->administrativeInterfaceControl = TRUE;    pStackData->txBlocked = FALSE;    pStackData->mode = END_NORMAL_MODE;    pStackData->receivedPacketQHead = NULL;    pStackData->receivedPacketQTail = NULL;    pStackData->receivedPacketQSize = 0;    pStackData->pDrvCtrl = NULL;    pStackData->recvAcceptableProtocols.numberOfProtocols =        MAXIMUM_END_PROTOCOLS;    pStackData->recvAcceptableProtocols.protocols =        pStackData->ipProtocolType;#ifdef PPP_END_PMP_CAPABLE    pStackData->supportPMP = 0;    pStackData->rasPoolId  = 0;    pStackData->dstIpAddr  = 0;    pStackData->pDstDrvCtrl  = NULL;#endif /* PPP_END_PMP_CAPABLE */#ifdef VIRTUAL_STACK    /* initialize it to the vsid in the profile */    pStackData->vsid = pEndProfileData->vsid;#endif /* VIRTUAL_STACK */    return OK;    } /***************************************************************************** pppVsEndProfileDataConstruct - initialize profile data** RETURNS: OK, or ERROR.*/LOCAL STATUS pppVsEndProfileDataConstruct    (    PFW_OBJ * pfw,    void * pProfileData	/* reference to profile data */    )    {    PPP_VS_END_PROFILE_DATA	* pEndProfileData = pProfileData;#ifdef VIRTUAL_STACK    VSID			vsid;#endif /* VIRTUAL_STACK */    /* initialize this to NULL, stackAdd will set it to the correct value */    pEndProfileData->pEndStackData = NULL;    /* set it to the default value */    pEndProfileData->pollRxQueueSize = DEF_POLL_RX_QUEUE_SIZE;#ifdef VIRTUAL_STACK    if (virtualStackIdGet (PPP_END_MGMT_STACK, &vsid) == ERROR)		{#ifdef PPP_DEBUG	printf ("PPP_VS_END: could not get the default VSID \n");#endif /* PPP_DEBUG */	vsid = NULL;	}    pEndProfileData->vsid = vsid;#endif /* VIRTUAL_STACK */    return OK;    }/***************************************************************************** pppVsEndStackAdd - add PPP VS_END plug-in object to PPP stack** NOMANUAL*/LOCAL STATUS pppVsEndStackAdd    (    PFW_PLUGIN_OBJ_STATE *state,    PFW_PLUGIN_OBJ_CALLBACKS * callbacks    )    {    PPP_VS_END_STACK_DATA *pStackData;    void *cookie;    char str[8];    PFW_EVENT_OBJ * eventObj;    PPP_VS_END_PROFILE_DATA * pEndProfileData = NULL;    PFW_STACK_ID connectionId;    PFW_ID pfwId;    int unitNum;    pStackData = (PPP_VS_END_STACK_DATA *)state->stackData;    pStackData->callbacks = callbacks;    bzero(str, 8);    sprintf(str,"%x",(int)state);    connectionId = pfwStackIdGet(state->stackObj);    pfwId = pfwIdGet (state->pluginObj->pfwObj);    /*     * For every PPP connection attached to IP, the network stack will     * create an ifnet data structures to hold the information related     * to the interface. The if_unit field is a short.  if_name can be     * at most END_NAME_MAX.      *     * Since the combination of a device name and its unit number must be     * unique, for a given device name there can be at most 32767 interfaces     * -- unless  the ifnet definition is changed and the network stack     * code is recompiled.      *     * The default interface name scheme is to use "ppp" as the device name     * for all frameworks and arbitrarily allocate unit numbers among      * frameworks based on the value of PPP_END_MAX_SESSIONS_PER_FRWK.     * Users should devise a scheme suitable to their needs.     */    unitNum = (pfwId - 1)* PPP_END_MAX_SESSIONS_PER_FRWK + connectionId;    cookie = muxDevLoad(unitNum, pppVsEndLoad, str, 0, NULL);    if (cookie == NULL)        {#ifdef PPP_DEBUG        printf  ("PPP END muxDevLoad failed\n");#endif /* PPP_DEBUG */        return ERROR;        }    if(createIpInterface (state) == ERROR)       {#ifdef PPP_DEBUG        printf  ("PPP END createIpInterface failed\n");#endif /* PPP_DEBUG */       return (ERROR);       }    pEndProfileData = (PPP_VS_END_PROFILE_DATA *) state->profileData;         /* Remember the Stack Object this profile belongs to */    pEndProfileData->pEndStackData = pStackData;#ifdef INET    if ((pStackData->interfaceUpEvent =             pfwEventObjGet(state->pluginObj->pfwObj,             "PPP_INTERFACE_UP_EVENT")) == NULL)        {        printf ("PPP_VS_END: no PPP_INTERFACE_UP_EVENT\n");        }    if ((pStackData->interfaceDownEvent =             pfwEventObjGet(state->pluginObj->pfwObj,             "PPP_INTERFACE_DOWN_EVENT")) ==NULL)        {        printf ("PPP_VS_END: no PPP_INTERFACE_DOWN_EVENT\n");        }#endif /* INET */#ifdef INET6    if ((pStackData->ipv6InterfaceUpEvent =             pfwEventObjGet(state->pluginObj->pfwObj,             "PPP_IPV6_INTERFACE_UP_EVENT")) == NULL)        {        printf ("PPP_VS_END: no PPP_IPV6_INTERFACE_UP_EVENT\n");        }    if ((pStackData->ipv6InterfaceDownEvent =             pfwEventObjGet(state->pluginObj->pfwObj,             "PPP_IPV6_INTERFACE_DOWN_EVENT")) ==NULL)        {        printf ("PPP_VS_END: no PPP_IPV6_INTERFACE_DOWN_EVENT\n");        }#endif /* INET6 */    /* subscribe to the TX_BLOCKED and TX_UNBLOCKED events */    if ((eventObj = pfwEventObjGet(state->pluginObj->pfwObj,				    "PPP_SUB_LAYER_TX_BLOCKED")) != NULL)	{	pfwEventStackSubscribe(state,eventObj,txBlockedEventHandler);	}    if ((eventObj = pfwEventObjGet(state->pluginObj->pfwObj,				    "PPP_SUB_LAYER_TX_UNBLOCKED")) != NULL)	{	pfwEventStackSubscribe(state,eventObj,txUnblockedEventHandler);	}    /* Get pfwRFC2233CountPair and set pfwRFC2233CountTest */    RFC2233_COUNT_PAIR_GET(state,                            pStackData->pfwAuxIfId,                            pStackData->pfwRFC2233CountPair,                            pStackData->pfwRFC2233CountTest);    if (pStackData->callbacks && pStackData->callbacks->stackAddComplete)        {        (*pStackData->callbacks->stackAddComplete)             (pStackData->callbacks, state);        return (OK);        }    else        return ERROR;    }/***************************************************************************** pppVsEndStackDelete - delete PPP VS_END plug-in object from PPP stack** NOMANUAL*/LOCAL STATUS pppVsEndStackDelete    (    PFW_PLUGIN_OBJ_STATE *state    )    {    PPP_VS_END_STACK_DATA *pStackData;    pStackData = (PPP_VS_END_STACK_DATA *)state->stackData;    /* Delete the IP interface */    deleteIpInterface (state);    /* delete interface references */    if (pStackData->pfwRFC2233CountTest)       pfwInterfaceReferenceDelete (           pStackData->pfwRFC2233CountPair.interfaceObj);    muxDevUnload("ppp",pStackData->pDrvCtrl->unitNum);    pStackData->pDrvCtrl = NULL;    if (pStackData->callbacks && pStackData->callbacks->stackDeleteComplete)        {        (*pStackData->callbacks->stackDeleteComplete)                                    (pStackData->callbacks ,state);        return (OK);        }    else        return ERROR;    }/***************************************************************************** pppVsEndSend - framework send function ** NOMANUAL*/LOCAL STATUS pppVsEndSend    (    PFW_PLUGIN_OBJ_STATE *state,    M_BLK_ID * packet    )    {    /* MUX calls pppSend END driver function */    printf ("Error: pppVsEndSend was called. Freeing packet\n");    netMblkClChainFree(*packet);    return (ERROR);    }/***************************************************************************** pppVsEndReceive - framework receive function** NOMANUAL*/LOCAL STATUS pppVsEndReceive   (   PFW_PLUGIN_OBJ_STATE *state,   M_BLK_ID *packet   )   {   END_OBJ *end;   char *src, *dst;   M_BLK_ID mBlk = *packet;   M_BLK_ID newMblk;   NET_POOL_ID netPoolId;   unsigned int bufferSize;   int requiredLeadingSpace;    PPP_VS_END_STACK_DATA *stackData =       (PPP_VS_END_STACK_DATA *)state->stackData;   PPP_VS_END_PROFILE_DATA * pEndProfileData = (PPP_VS_END_PROFILE_DATA *) 					     state->profileData;    /* drop packet if we are in POLLED mode and queue is full */   if ((stackData->mode == END_POLLED_MODE) &&       (stackData->receivedPacketQSize == pEndProfileData->pollRxQueueSize))        {        netMblkClChainFree(mBlk);        RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, 				stackData->pfwRFC2233CountPair,                               M2_ctrId_ifInDiscards, 1);                 return OK;        }    /* Get the END_OBJ from the state */   end = &stackData->pDrvCtrl->end;   src = mBlk->mBlkHdr.mData;    bufferSize = mBlk->mBlkHdr.mLen;   /* Is start of IP packet 4-byte aligned? */   if ((requiredLeadingSpace = ((int)src +                                sizeof (PPP_HEADER)) & 0x3) != 0)       {       if (M_LEADINGSPACE(mBlk) >= requiredLeadingSpace)           {           dst = (char *) (((int)src) - requiredLeadingSpace);           bcopy (src, dst, bufferSize);           mBlk->mBlkHdr.mData = dst;           }       else           {           netPoolId = pfwNetPoolIdGet (state->pluginObj->pfwObj);           if ((newMblk = netTupleGet (netPoolId, bufferSize +                                       sizeof (PPP_HEADER),                                        M_DONTWAIT,MT_DATA,TRUE)) == NULL)               {               netMblkClChainFree(mBlk);               /* update RFC1213 counters */               end->mib2Tbl.ifInDiscards++;

⌨️ 快捷键说明

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