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

📄 pppend.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    pIfnet->if_flags |= IFF_RUNNING;bringUpIpInterfaceFree:    pfwFree(ifName);    pfwFree(srcAddr);    pfwFree(dstAddr);    return;    }/******************************************************************************** bringDownIpInterface -*/LOCAL void bringDownIpInterface    (    char * ifName,    char * srcAddr,    char * dstAddr    )    {    struct ifnet *pIfnet;    /* delete route to peer */    mRouteDelete(dstAddr,0,0,RTF_HOST);    /* delete route to local IP through 127.0.0.1 */    /* mRouteDelete(srcAddr,0,0,RTF_HOST); */    /* Get the ifnet from the interface name */    pIfnet = ifunit (ifName);    if (pIfnet == NULL)	goto bringDownIpInterfaceFree;    if (ifFlagSet (ifName,(pIfnet->if_flags & ~IFF_UP)) == ERROR)	goto bringDownIpInterfaceFree;    /* temporary workaround for NPT patch July 7, 2000 */    pIfnet->if_flags &= ~IFF_RUNNING;bringDownIpInterfaceFree:    pfwFree(ifName);    pfwFree(srcAddr);    pfwFree(dstAddr);    }/********************************************************************************* ipInterfaceDown - Mark IP interface down*/LOCAL STATUS ipInterfaceDown    (    PFW_PLUGIN_OBJ_STATE *state,    char *source,    char *destination    )    {    char * ifName;    char * ifSrcAddr;    char * ifDstAddr;    PFW_STACK_ID connectionId;    PPP_END_STACK_DATA *stackData = (PPP_END_STACK_DATA *)state->stackData;    PFW_ID pfwId;    int unitNum;    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,source);    strcpy(ifDstAddr,destination);    stackData->administrativeInterfaceControl = FALSE;    netJobAdd((FUNCPTR)bringDownIpInterface,(int)ifName,(int)ifSrcAddr,							    (int)ifDstAddr,0,0);    return (OK);    }/********************************************************************************* ipRouteAdd - Add a route **/LOCAL STATUS ipRouteAdd    (    PFW_PLUGIN_OBJ_STATE *state,    char * pDest,    char * pGate,    unsigned long mask,    int    tos,    int    flags        )    {    char * destination;    char * gateway;    PFW_OBJ * pfwObj;    pfwObj = state->pluginObj->pfwObj;    if ((destination = pfwMalloc(pfwObj, strlen(pDest) + 1)) == NULL)	{	return (ERROR);	}    if ((gateway = pfwMalloc(pfwObj, strlen(pGate) + 1)) == NULL)	{	pfwFree(destination);	return (ERROR);	}    strcpy(destination, pDest);    strcpy(gateway, pGate);    netJobAdd((FUNCPTR)pppEndRouteAdd, (int) destination,(int) gateway,			    (int) mask, tos, flags);    return OK;    }/********************************************************************************* ipRouteDelete - Delete a route **/LOCAL STATUS ipRouteDelete    (    PFW_PLUGIN_OBJ_STATE *state,    char * pDest,    unsigned long  mask,    int    tos,    int    flags        )    {    char * destination;    PFW_OBJ * pfwObj;    pfwObj = state->pluginObj->pfwObj;    if ((destination = pfwMalloc(pfwObj, strlen(pDest) + 1)) == NULL)	{	return (ERROR);	}    strcpy(destination, pDest);    netJobAdd((FUNCPTR)pppEndRouteDelete, (int) destination,			    (int) mask, tos, flags, 0);    return OK;    }/********************************************************************************* ipSetIfMask - Set PPP interface mask**/LOCAL STATUS ipSetIfMask    (    PFW_PLUGIN_OBJ_STATE *state,    unsigned long  mask    )    {    char * ifName;    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;    if ((ifName = pfwMalloc(state->pluginObj->pfwObj,PFW_MAX_NAME_LENGTH)) ==	NULL)	{	return (ERROR);	}    sprintf(ifName,"ppp%d",unitNum);    netJobAdd((FUNCPTR)pppEndSetIfMask, (int) ifName,			    (int) mask, 0, 0, 0);    return OK;    }/******************************************************************************** pppEndRouteAdd - complete route addition in netTask context*/LOCAL void pppEndRouteAdd     (    char * pDest,    char * pGate,    unsigned long mask,    int tos,    int flags    )    {    STATUS status;        status = mRouteAdd(pDest, pGate, mask, tos, flags);    printf ("PPP_END: Adding Route Destination %s Gateway %s Mask %lx %s\n",            pDest,  pGate, mask,            ((status == OK) ? "OK" : "FAILED"));    pfwFree(pDest);    pfwFree(pGate);    return;    }/******************************************************************************** pppEndRouteDelete - complete route deletion in netTask context*/LOCAL void pppEndRouteDelete     (    char * pDest,    unsigned long mask,    int tos,    int flags    )    {    STATUS status;        status = mRouteDelete(pDest, mask, tos, flags);    printf ("PPP_END: Deleting Route Destination %s Mask %lx %s\n",            pDest, mask,            ((status == OK) ? "OK" : "FAILED"));    pfwFree(pDest);    return;    }/******************************************************************************** pppEndSetIfMask - complete interface mask setup in netTask context*/LOCAL void pppEndSetIfMask    (    char * ifName,    unsigned long mask    )    {    STATUS status;        status = ifMaskSet(ifName, mask);    printf ("PPP_END: Set Interface Mask ifName %s Mask %lx %s\n",            ifName, mask,            ((status == OK) ? "OK" : "FAILED"));    pfwFree(ifName);    return;    }#ifdef PPP_END_RFC2233_CAPABLE/******************************************************************************** ifCounterUpdateWrap - wraps m2IfCounterUpdate that updates RFC2233 counters*/LOCAL STATUS ifCounterUpdateWrap    (    PFW_PLUGIN_OBJ_STATE * state,    UINT ctrId,    ULONG incrAmount    )    {    PPP_END_STACK_DATA *pStackData = (PPP_END_STACK_DATA *)state->stackData;    M2_ID * pM2Id = NULL;    PPP_DRV_CTRL * pDrvCtrl = NULL;    END_OBJ		* pEnd = NULL;    if ((pStackData == NULL) || ((pDrvCtrl = pStackData->pDrvCtrl) == NULL)	|| ((pEnd = &pDrvCtrl->end) == NULL))	{	return (ERROR);	}    pM2Id = pEnd->pMib2Tbl;        if  (pM2Id != NULL)        {        return(pM2Id->m2CtrUpdateRtn(pM2Id, ctrId, incrAmount));        }    else        {        return ERROR;        }    }/******************************************************************************** ifVariableUpdateWrap - wraps m2IfVariableUpdate; updates RFC2233 variables*/LOCAL STATUS ifVariableUpdateWrap    (    PFW_PLUGIN_OBJ_STATE * state,    UINT varId,    caddr_t pData    )    {    M2_ID * pM2Id = ((PPP_END_STACK_DATA *)(state->stackData))->                    pDrvCtrl->end.pMib2Tbl;        if  (pM2Id != NULL)        {        return(pM2Id->m2VarUpdateRtn(pM2Id, varId, pData));        }    else        {        return ERROR;        }    }/******************************************************************************** ifStackStatusSet - sets the */LOCAL STATUS ifStackStatusSet    (    PFW_PLUGIN_OBJ_STATE * state,    int rowStatus    )    {    return OK;    }#endif /* PPP_END_RFC2233_CAPABLE *//******************************************************************************** pppLinkIdGet - return the ifIndex for the given stack*/LOCAL UINT32 pppLinkIdGet     (    PFW_PLUGIN_OBJ_STATE * state    )    {    PPP_END_STACK_DATA *pStackData = (PPP_END_STACK_DATA *)state->stackData;    return (pStackData->pIfnet->if_index);    }/********************************************************************************* receivePathAcceptableProtocolsGet - get the acceptable protocol list** This routine returns the protocols numbers which are acceptable to* the END component on the receive path of the PPP stack*/LOCAL STATUS receivePathAcceptableProtocolsGet    (    PFW_PLUGIN_OBJ_STATE *state,    ACCEPTABLE_PROTOCOLS_ARRAY **recvProtocols    )    {    *recvProtocols = &recvAcceptableProtocols;    return (OK);    }/********************************************************************************* sendPathAcceptableProtocolsGet - get the acceptable protocol list** This routine returns the protocols numbers which are acceptable to the* END component on the send path of the PPP stack*/LOCAL STATUS sendPathAcceptableProtocolsGet    (    PFW_PLUGIN_OBJ_STATE *state,    ACCEPTABLE_PROTOCOLS_ARRAY **sendProtocols    )    {    *sendProtocols = NULL;    return (OK);    }/******************************************************************************** ipDnsAddressSet - set primary and secondary DNS addresses**/LOCAL void ipDnsAddressSet    (    PFW_PLUGIN_OBJ_STATE * pluginState,    char * primaryDnsAddress,    char * secondaryDnsAddress    )    {    RESOLV_PARAMS_S   resolvParams;    PPP_END_STACK_DATA *pStackData =(PPP_END_STACK_DATA *)pluginState->stackData;    resolvParamsGet (&resolvParams);    /* populate the negotiated DNS addresses */    if (primaryDnsAddress != NULL)	{	/* save primaryDnsAddress in stack Data*/	memcpy (pStackData->primaryDnsAddr, primaryDnsAddress, MAXIPADDRLEN);	/* update with new negotiated value */	memcpy (resolvParams.nameServersAddr[0], 		(char *)primaryDnsAddress, MAXIPADDRLEN);	}    if (secondaryDnsAddress != NULL)	{	/* save secondaryDnsAddress in stack Data*/	memcpy (pStackData->secondaryDnsAddr, secondaryDnsAddress, MAXIPADDRLEN);	/* update with new negotiated value */	memcpy (resolvParams.nameServersAddr[1], 		(char *)secondaryDnsAddress, MAXIPADDRLEN);	}    resolvParamsSet (&resolvParams);        }/******************************************************************************** ipDnsAddressGet - get primary and secondary DNS addresses** caller allocates memory for primary and secondary address and must have* a minimum length of INET_ADDR_LEN*/LOCAL void ipDnsAddressGet    (    PFW_PLUGIN_OBJ_STATE * pluginState,    char * primaryDnsAddress,    char * secondaryDnsAddress    )    {    PPP_END_STACK_DATA *pStackData =(PPP_END_STACK_DATA *)pluginState->stackData;    memcpy (primaryDnsAddress, pStackData->primaryDnsAddr, MAXIPADDRLEN);    memcpy (secondaryDnsAddress, pStackData->secondaryDnsAddr, MAXIPADDRLEN);    }/******************************************************************************** txBlockedEventHandler - subordinate layer cant accept packets to send*/LOCAL STATUS txBlockedEventHandler    (    PFW_PLUGIN_OBJ_STATE * state,    void *eventData    )    {    PPP_END_STACK_DATA *pStackData =(PPP_END_STACK_DATA *)state->stackData;    if (pStackData->txBlocked == TRUE)	{	printf ("PPP_END: PPP_SUB_LAYER_TX_BLOCKED event when already blocked\n");	}    else	{	pStackData->txBlocked = TRUE;#ifdef PPP_DEBUG	printf ("PPP_END: PPP_SUB_LAYER_TX_BLOCKED \n");#endif /* PPP_DEBUG */	}    return OK;    }/******************************************************************************** txUnblockedEventHandler - subordinate layer can now accept packets to send*/LOCAL STATUS txUnblockedEventHandler    (    PFW_PLUGIN_OBJ_STATE * state,    void *eventData    )    {    PPP_END_STACK_DATA *pStackData =(PPP_END_STACK_DATA *)state->stackData;    if (pStackData->txBlocked == FALSE)	{	printf ("PPP_END: PPP_SUB_LAYER_TX_UNBLOCKED event when already unblocked\n");	}    else	{	pStackData->txBlocked = FALSE;#ifdef PPP_DEBUG	 printf ("PPP_END: PPP_SUB_LAYER_TX_UNBLOCKED \n");#endif /* PPP_DEBUG */        netJobAdd ((FUNCPTR) muxTxRestart, (int)&(pStackData->pDrvCtrl->end),                              0, 0, 0, 0);	}    return OK;    }#endif /* (!((defined STACK_NAME) && (STACK_NAME == STACK_NAME_V4_V6))) */

⌨️ 快捷键说明

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