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

📄 pppend.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    if (pfwEventPublish(pfw,"PPP_SUB_LAYER_TX_BLOCKED") == NULL)	{	return ERROR;	}    /* This event allows us to call muxTxRestart when we can send again */    if (pfwEventPublish(pfw,"PPP_SUB_LAYER_TX_UNBLOCKED") == NULL)	{	return ERROR;	}   return (OK);   }/********************************************************************************* pppEndComponentDelete - delete the END component from the framework** This routine frees the END plug-in object allocated by * pppEndComponentCreate() if there are no references to this object * from a stack or profile object in the framework.** RETURNS: OK or ERROR*/STATUS pppEndComponentDelete    (    PFW_OBJ *pfw    )    {    PFW_COMPONENT_OBJ *pComponent;    pComponent = pfwComponentObjGetByName (pfw, "PPP_END");    if (pComponent == NULL)        return ERROR;    if (pfwComponentDelete (pComponent) == OK)        {        pfwFree (pComponent);        return OK;        }    return (ERROR);    }/******************************************************************************** endInterfaceBind -** NOMANUAL*/LOCAL STATUS endInterfaceBind    (    PFW_PLUGIN_OBJ * pluginObj    )    {    PPP_END_COMPONENT * pComponent = (PPP_END_COMPONENT *)pluginObj;    PPP_IP_INTERFACE           *pppIpInterface;    PPP_IP_ROUTES_INTERFACE    *pppIpRoutesInterface;    PPP_IP_DNS_INTERFACE       *pppIpDnsInterface;    COMPONENT_ACCEPTABLE_PROTOCOLS_INTERFACE		    *componentAcceptableProtocolsInterface;    PPP_LINK_ID_INTERFACE *pppLinkIdInterface;#ifdef PPP_END_RFC2233_CAPABLE    PPP_IF_IFX_TABLE_INTERFACE * pppIfIfXTableInterface;    PPP_IF_STACK_TABLE_INTERFACE * pppIfStackTableInterface;#endif /* PPP_END_RFC2233_CAPABLE */    PFW_OBJ * pfw = pluginObj->pfwObj;    int i;    if ((i = pfwInterfaceRegister(pfw,"PPP_IP_INTERFACE")) > 0)        {        pppIpInterface = &pComponent->pppIpInterface;        pppIpInterface->interfaceObj.id = i;        pppIpInterface->interfaceObj.pluginObj = pluginObj;        pppIpInterface->ipInterfaceDown = ipInterfaceDown;        pppIpInterface->ipInterfaceUp = ipInterfaceUp;        pfwInterfaceBind (&pppIpInterface->interfaceObj);        }    if ((i = pfwInterfaceRegister(pfw,"PPP_IP_ROUTES_INTERFACE")) > 0)        {        pppIpRoutesInterface = &pComponent->pppIpRoutesInterface;        pppIpRoutesInterface->interfaceObj.id = i;        pppIpRoutesInterface->interfaceObj.pluginObj = pluginObj;        pppIpRoutesInterface->ipRouteAdd = ipRouteAdd;        pppIpRoutesInterface->ipRouteDelete = ipRouteDelete;        pppIpRoutesInterface->ipSetIfMask = ipSetIfMask;        pfwInterfaceBind (&pppIpRoutesInterface->interfaceObj);        }    if ((i = pfwInterfaceRegister(pfw,"PPP_IP_DNS_INTERFACE")) > 0)        {        pppIpDnsInterface = &pComponent->pppIpDnsInterface;        pppIpDnsInterface->interfaceObj.id = i;        pppIpDnsInterface->interfaceObj.pluginObj = pluginObj;        pppIpDnsInterface->ipDnsAddressSet = ipDnsAddressSet;        pppIpDnsInterface->ipDnsAddressGet = ipDnsAddressGet;        pfwInterfaceBind (&pppIpDnsInterface->interfaceObj);        }    if ((i = pfwInterfaceRegister(pfw,                "COMPONENT_ACCEPTABLE_PROTOCOLS_INTERFACE")) > 0)        {        componentAcceptableProtocolsInterface =                        &pComponent->componentAcceptableProtocolsInterface;        componentAcceptableProtocolsInterface->interfaceObj.id = i;        componentAcceptableProtocolsInterface->interfaceObj.pluginObj                        = pluginObj;        componentAcceptableProtocolsInterface->receivePathAcceptableProtocolsGet                        = receivePathAcceptableProtocolsGet;        componentAcceptableProtocolsInterface->sendPathAcceptableProtocolsGet =                        sendPathAcceptableProtocolsGet;        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);        }#ifdef PPP_END_RFC2233_CAPABLE    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);        }#endif /* PPP_END_RFC2233_CAPABLE */    return (OK);    }/******************************************************************************** pppEndStackDataConstruct - initialize stack data*/LOCAL STATUS pppEndStackDataConstruct    (    PFW_OBJ * pfw,    void    * stackData,	/* reference to stack data */    void * profileData	/* reference to profile data */    )    {    PPP_END_STACK_DATA *pStackData = stackData;    memset(pStackData,0,sizeof(PPP_END_STACK_DATA));    pStackData->administrativeInterfaceControl = TRUE;    pStackData->txBlocked = FALSE;    return OK;    }/********************************************************************************* stackAdd -** NOMANUAL*/LOCAL STATUS stackAdd    (    PFW_PLUGIN_OBJ_STATE *state,    PFW_PLUGIN_OBJ_CALLBACKS * callbacks    )    {    PPP_END_STACK_DATA *pStackData;    PFW_STACK_ID connectionId;    PFW_ID pfwId;    void *cookie;    char str[8];    int unitNum;    PFW_EVENT_OBJ * eventObj;    pStackData = (PPP_END_STACK_DATA *)state->stackData;    pStackData->administrativeInterfaceControl = TRUE;    pStackData->callbacks = callbacks;    bzero(str, 8);    sprintf(str,"%x",(int)state);    connectionId = pfwStackIdGet (state->stackObj);    pfwId = pfwIdGet (state->pluginObj->pfwObj);    unitNum = (pfwId -1)* PPP_END_MAX_SESSIONS_PER_FRWK + connectionId;    cookie = muxDevLoad(unitNum, pppLoad, str, 0, NULL);    if (cookie == NULL)        {        return ERROR;        }    if(createIpInterface (state) == ERROR)       return (ERROR);    if ((pStackData->interfaceUpEvent = pfwEventObjGet(state->pluginObj->pfwObj,					    "PPP_INTERFACE_UP_EVENT")) == NULL)	{	printf ("PPP_END: no PPP_INTERFACE_UP_EVENT\n");	}    if ((pStackData->interfaceDownEvent=pfwEventObjGet(state->pluginObj->pfwObj,					    "PPP_INTERFACE_DOWN_EVENT")) ==NULL)	{	printf ("PPP_END: no PPP_INTERFACE_DOWN_EVENT\n");	}    /* 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;    }/********************************************************************************* stackDelete -** NOMANUAL*/LOCAL STATUS stackDelete    (    PFW_PLUGIN_OBJ_STATE *state    )    {    PFW_STACK_ID connectionId;    PFW_ID pfwId;    int unitNum;    PPP_END_STACK_DATA *pStackData;    pStackData = (PPP_END_STACK_DATA *)state->stackData;    connectionId = pfwStackIdGet (state->stackObj);    pfwId = pfwIdGet (state->pluginObj->pfwObj);    unitNum = (pfwId -1)* PPP_END_MAX_SESSIONS_PER_FRWK + connectionId;    /* Delete the IP interface */    deleteIpInterface (state);    /* delete interface references */    if (pStackData->pfwRFC2233CountTest)       pfwInterfaceReferenceDelete(pStackData->pfwRFC2233CountPair.interfaceObj);    muxDevUnload("ppp",unitNum);    pStackData->pDrvCtrl = NULL;    if (pStackData->callbacks && pStackData->callbacks->stackDeleteComplete)        {        (*pStackData->callbacks->stackDeleteComplete)                                    (pStackData->callbacks ,state);        return (OK);        }    else        return ERROR;    }/********************************************************************************* sendIf -** NOMANUAL*/LOCAL STATUS sendIf    (    PFW_PLUGIN_OBJ_STATE *state,    M_BLK_ID * packet    )    {    printf("Error - sendIf called in ppp END driver\n");    return (ERROR);    }/********************************************************************************* createIpInterface -*/LOCAL STATUS createIpInterface    (    PFW_PLUGIN_OBJ_STATE *state    )    {    char ifName[PFW_MAX_NAME_LENGTH];    PFW_STACK_ID connectionId;    PPP_END_STACK_DATA *pStackData;    PFW_ID pfwId;    int unitNum;    struct ifnet *pIfnet;    pStackData = (PPP_END_STACK_DATA *)state->stackData;    connectionId = pfwStackIdGet (state->stackObj);    pfwId = pfwIdGet (state->pluginObj->pfwObj);    unitNum = (pfwId - 1)* PPP_END_MAX_SESSIONS_PER_FRWK + connectionId;    sprintf(ifName,"ppp");    /* Call IP attach to create a interface and attach the IP stack to END */    if (ipAttach (unitNum, ifName) != OK)	return (ERROR);    sprintf(ifName,"ppp%d",unitNum);    ifMaskSet(ifName,0xffffffff);     /* Get the ifnet from the interface name */    pIfnet = ifunit (ifName);    if (pIfnet == NULL)        return (ERROR);    pStackData->pIfnet = pIfnet;    /* allow management of this PPP link via SNMP */    m2pppInterfaceRegister(pIfnet->if_index,state->stackObj);    /* Mark the interface down */    /*if_down (pIfnet);*/    ifMaskSet(ifName,0xffffffff);    ifAddrSet (ifName, "0.0.0.0");    return OK;    }/********************************************************************************* deleteIpInterface -*/LOCAL STATUS deleteIpInterface    (    PFW_PLUGIN_OBJ_STATE *state    )    {    PPP_END_STACK_DATA * pStackData = (PPP_END_STACK_DATA *)state->stackData;    char ifName[PFW_MAX_NAME_LENGTH];    PFW_STACK_ID connectionId;    PFW_ID pfwId;    int unitNum;    connectionId = pfwStackIdGet (state->stackObj);    pfwId = pfwIdGet (state->pluginObj->pfwObj);    unitNum = (pfwId - 1)* PPP_END_MAX_SESSIONS_PER_FRWK + connectionId;    sprintf(ifName,"ppp");    /* remove this PPP link from the management tables */    m2pppInterfaceUnregister(pStackData->pIfnet->if_index);    /* Remove the interface from the system */    if (ipDetach (unitNum, ifName) != OK)        return (ERROR);    return (OK);    }/********************************************************************************* ipInterfaceUp - Mark IP interface UP**/LOCAL STATUS ipInterfaceUp    (    PFW_PLUGIN_OBJ_STATE *state,    char *srcAddr,    char *dstAddr    )    {    char * ifName;    char * ifSrcAddr;    char * ifDstAddr;    PFW_STACK_ID connectionId;    PFW_ID pfwId;    int unitNum;    int id;    int mtu;    PPP_END_STACK_DATA *stackData = (PPP_END_STACK_DATA *)state->stackData;    PPP_LINK_STATUS_ENTRY_INTERFACE * linkStatus;    connectionId = pfwStackIdGet (state->stackObj);    pfwId = pfwIdGet (state->pluginObj->pfwObj);    unitNum = (pfwId - 1)* PPP_END_MAX_SESSIONS_PER_FRWK + connectionId;    if ((ifName = pfwMalloc(state->pluginObj->pfwObj,PFW_MAX_NAME_LENGTH)) ==	NULL)	{	return (ERROR);	}    if ((ifSrcAddr = pfwMalloc(state->pluginObj->pfwObj,PFW_MAX_NAME_LENGTH)) ==	NULL)	{	pfwFree(ifName);	return (ERROR);	}    if ((ifDstAddr = pfwMalloc(state->pluginObj->pfwObj,PFW_MAX_NAME_LENGTH)) ==	NULL)	{	pfwFree(ifName);	pfwFree(ifSrcAddr);	return (ERROR);	}    sprintf(ifName,"ppp%d",unitNum);    strcpy(ifSrcAddr,srcAddr);    strcpy(ifDstAddr,dstAddr);    /* get LCP interfaces */    if ((id = pfwInterfaceIdGet(state->pluginObj->pfwObj,                        "PPP_LINK_STATUS_ENTRY_INTERFACE")) > 0)        {        if (pfwInterfaceObjAndStateGetViaStackObj(state->stackObj,                                id, &stackData->pppLinkStatusInterface) != OK)            return ERROR;        }    else        return ERROR;        linkStatus = (PPP_LINK_STATUS_ENTRY_INTERFACE *)                    stackData->pppLinkStatusInterface.interfaceObj;    mtu = (*linkStatus->pppLinkStatusRemoteMRUGet)(		stackData->pppLinkStatusInterface.state);    pfwInterfaceReferenceDelete (		stackData->pppLinkStatusInterface.interfaceObj);    stackData->administrativeInterfaceControl = FALSE;    netJobAdd((FUNCPTR)bringUpIpInterface,(int)ifName,(int)ifSrcAddr,				    (int)ifDstAddr,mtu, 0);    return (OK);    }/******************************************************************************** bringUpIpInterface - complete IP interface setup in netTask context*/LOCAL void bringUpIpInterface     (    char * ifName,    char * srcAddr,    char * dstAddr,    int    mtu    )    {    struct ifnet *pIfnet = NULL;    /* Get the ifnet from the interface name */    pIfnet = ifunit (ifName);    if (pIfnet == NULL)	goto bringUpIpInterfaceFree;    pIfnet->if_mtu = mtu;    /* Set the IP addresses and add route */    ifMaskSet(ifName,0xffffffff); /* added at VPN workshop */    ifDstAddrSet(ifName,dstAddr);    ifAddrSet (ifName, srcAddr);    /* Mark the interface UP */    ifFlagSet(ifName,  (pIfnet->if_flags | IFF_UP));    /* mRouteAdd(srcAddr,"127.0.0.1",0,0,RTF_HOST);*/    /* ifFlagSet does not allow to do this... */

⌨️ 快捷键说明

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