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

📄 pppoethernet.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	     * session ID.	     */	    if (pppOEMapStackId((pfwStackIdGet(newStackObj) & 0x0000FFFF),				pNewComponentState) != OK)		{		pfwStackDelete(newStackObj);                pfwPluginObjStateRelease(pNewComponentState);		break;		}	    /* make a session packet based on the newly created connection */	    if ((pMblk = pppOEMakePADS(pNewComponentState)) == NULL)		{		pfwStackDelete(newStackObj);                pfwPluginObjStateRelease(pNewComponentState);		break;		}	    /* else we send the session packet using the new stack */	    /* 	     * for the new stack inform underlying adapter of new dest addr	     * and protocol	     */	    ADAPTER_DEST_ADDR_AND_PROTOCOL_SET(pNewStackData,						    ETHERTYPE_PPPOE_DISCOVERY);	    if (pfwSend (pNewComponentState, pMblk) != ERROR)		{		/* 		 * complete the stack Add request for the newly created		 * stack		 */		pNewStackData->state = PPPOE_STATE_SESSION;		/*		 * inform underlying adapter one last time of final dest addr		 * and the session protocol number		 */		ADAPTER_DEST_ADDR_AND_PROTOCOL_SET(pNewStackData,						    ETHERTYPE_PPPOE_SESSION);		PPPOE_STACK_ADD_DONE(pNewComponentState);#ifdef PPP_DEBUG		if (pppOEDebug )		    printf("AC stack ID = %d created New Stack ID = %d\n",			    pfwStackIdGet(pComponentState->stackObj), 			    pfwStackIdGet(newStackObj));#endif /* PPP_DEBUG */		/* dont give this packet to upper layers */                pfwPluginObjStateRelease(pNewComponentState);		return PFW_OK_TERMINATE;		}	    else                {                pfwPluginObjStateRelease(pNewComponentState);		break;                }	/* the next two cases are encountered by host/client */	case PPPOE_CODE_PADO:	    /* TO DO - evaluate the offer */             if (strlen(pProfileData->acNameTag) != 0)                {                if (((foundTlv = pppOEFindTlv(PPPOE_TAG_AC_NAME,firstTlv,pFrame))                     == NULL) ||                     memcmp(PPPOE_TAG_VALUE(foundTlv),pProfileData->acNameTag,                         PPPOE_TAG_LENGTH(foundTlv)))                   {                   if(foundTlv != NULL)                      printf ("pppOE: Unexpected AC name %s\n",                              PPPOE_TAG_VALUE(foundTlv));                   PPPOE_FREE_RECVD_PKT(pStackData);		   return PFW_OK_TERMINATE;                   }#ifdef PPP_DEBUG                {                char enetBuf[20];                char nameBuf[32];                bzero(enetBuf,20);                bzero(nameBuf,32);                bcopy(PPPOE_TAG_VALUE(foundTlv),nameBuf,                       PPPOE_TAG_LENGTH(foundTlv));                etherEnetToAscii (etherHdr.ether_shost,enetBuf);                printf ("pppOE: Stack 0x%x received Offer from AC %s with enet %s\n"                        , (UINT32) pComponentState->stackObj,                         nameBuf,enetBuf);                }#endif /* PPP_DEBUG */                }	    /* for now simply send a request based on the first offer */	    if (memcmp(pStackData->destEnet,etherBroadcastAddr,ENET_LEN))		{		PPPOE_FREE_RECVD_PKT(pStackData);		return PFW_OK_TERMINATE;		}	    else		{		/* copy source and destination enet address */		memcpy(pStackData->srcEnet, etherHdr.ether_dhost, ENET_LEN);		memcpy(pStackData->destEnet, etherHdr.ether_shost, ENET_LEN);		}	    /* fall through from else */	    if ((pMblk = pppOEMakePADR(pComponentState)) == NULL)		{		/* release AC ethernet address */		memcpy(pStackData->destEnet,etherBroadcastAddr,ENET_LEN);		break;		}	    /*	     * else; cancel PADI timer, release PADI retry packet and	     * send a request for a session	     */	    pfwTimerCancel(pStackData->pTimer);	    PPPOE_FREE_RETRY_PKT(pStackData);	    pStackData->state = PPPOE_STATE_PADR;	    pStackData->pRetryDiscPkt = pMblk;	    if (pppOESendDiscPkt (pComponentState, 0) != ERROR)		{		return PFW_OK_TERMINATE;		}	    else		break;	case PPPOE_CODE_PADS:	    /* reject duplicate session offers */	    if (pStackData->state == PPPOE_STATE_SESSION)		{		PPPOE_FREE_RECVD_PKT(pStackData);		return PFW_OK_TERMINATE;		}	    /*  take the session ID and map it to our stack object */	    if (pppOEHeader.pppOE_session != 0)		{		STATUS  status;		status = pppOEMapStackId (pppOEHeader.pppOE_session,			pComponentState);		/* free the discovery packet */		PPPOE_FREE_RECVD_PKT(pStackData);		if (status != OK)		    {		    /* TO DO - delete stack */		    break;		    }#ifdef PPP_DEBUG		if (pppOEDebug )		    printf("HOST stack ID = %d assigned session ID = %d\n",			    pfwStackIdGet(pComponentState->stackObj),			    pppOEHeader.pppOE_session);#endif /* PPP_DEBUG */		/*		 * this is where the session is established and we say that 		 * the stack Add request is complete		 */		pStackData->state = PPPOE_STATE_SESSION;		/*		 * inform underlying adapter of final dest addr and 		 * session protocol		 */		ADAPTER_DEST_ADDR_AND_PROTOCOL_SET(pStackData,						    ETHERTYPE_PPPOE_SESSION);		PPPOE_STACK_ADD_DONE(pComponentState);		return PFW_OK_TERMINATE;		}	    /* else */	    break;	case PPPOE_CODE_PADT:            /*PPPOE_FREE_RECVD_PKT(pStackData); Done after break*/            pStackData->sendPADT = FALSE;	    if (pStackData->lcpUpFlag)                pfwEventRaise(pComponentState->stackObj,                          pStackData->pppSubordinateLayerDeadEvent,                          NULL);            pfwStackDelete(pComponentState->stackObj);	    break;	case PPPOE_CODE_SESSION:	    /*	     * check if we are in SESSION state before accepting the packet;	     * apart from that there is nothing to do here;	     * PPPOE header is alreay stripped	     */	    if (pStackData->state == PPPOE_STATE_SESSION)		{		*pMblkId = pFrame;		return OK; /* continue with upper layers */		}	    else		{		/* drop the packet silently */		PPPOE_FREE_PKT(pFrame);		RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 				    pStackData->pfwRFC2233CountPair,                                       M2_ctrId_ifInDiscards, 1);		return PFW_OK_TERMINATE;		}			default:		break;	}    PPPOE_FREE_RECVD_PKT(pStackData);    return ERROR;    }/******************************************************************************** pppOESend - PPPOE component send interface ** This interface is invoked only during PPPOE_STATE_SESSION* * RETURNS: OK or ERROR*/LOCAL STATUS pppOESend    (    PFW_PLUGIN_OBJ_STATE * pComponentState,  /* our state for this stack */    M_BLK_ID * pMblkId			     /* pointer to packet to send */    )    {    PPPOE_STACK_DATA * pStackData = 			(PPPOE_STACK_DATA *)(pComponentState->stackData);    M_BLK_ID pMblk = NULL;    M_BLK_ID pPacket = NULL;    if ((pMblkId == NULL) || ((pMblk = *pMblkId) == NULL))        {        RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 				pStackData->pfwRFC2233CountPair,                           M2_ctrId_ifOutErrors, 1);	return ERROR;        }    /* we must be in session state */    if (pStackData->state != PPPOE_STATE_SESSION)        {        RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 				pStackData->pfwRFC2233CountPair,                               M2_ctrId_ifOutDiscards, 1);	return ERROR;        }    /* Update counters */    pStackData->outputPackets ++;    pStackData->outputOctets += pMblk->mBlkPktHdr.len;    if ((pPacket = pppOEAddHeader(PPPOE_CODE_SESSION, pStackData->sessionId, 	    pStackData->destEnet, pMblk)) != NULL)	{	*pMblkId = pPacket;	return OK;	}    else 	{        RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 				pStackData->pfwRFC2233CountPair,                               M2_ctrId_ifOutDiscards, 1);	return ERROR;	}    }/******************************************************************************** pppOEStackShow - show stack data** This interface is invoked only during a call to pfwStackShow().* The purpose of this routine is to display the stack data in human* readable form* * RETURNS: OK or ERROR*/LOCAL STATUS pppOEStackShow     (    PFW_PLUGIN_OBJ_STATE * pComponentState    )    {    PPPOE_STACK_DATA * pStackData = 				(PPPOE_STACK_DATA *)pComponentState->stackData;    char enetAddr[18];    bzero(enetAddr,18);    if (pStackData == NULL)	return ERROR;    printf("Stack ID = %d \n", pfwStackIdGet(pComponentState->stackObj));    printf("Stack state = %s \n",	(pStackData->state == PPPOE_STATE_SESSION) ? "SESSION":"DISCOVERY");    printf("Session ID = %d = 0x%x \n", pStackData->sessionId,	    pStackData->sessionId);    printf("Service Name = %s\n", pStackData->serviceName);    printf("AC Name = %s\n", pStackData->acName);    etherEnetToAscii(pStackData->destEnet,enetAddr);    if (pStackData->connectionMode & PPPOE_AC_MODE)	{	printf("HOST Ethenet Addr. = %s\n", enetAddr);	}    else	{	printf("AC Ethernet Addr. = %s\n", enetAddr);	printf("PADI Retries Remaining = %d\n", pStackData->remPADIRetries);	printf("PADR Retries Remaining = %d\n", pStackData->remPADRRetries);	}    return OK;    }/******************************************************************************** pppOE_connectionMode - connectionMode parameter handler * */LOCAL STATUS pppOE_connectionMode    (    PFW_OBJ * pfw,    PFW_PARAMETER_OPERATION_TYPE operType,	/* operation type */    void * pProfileData,                	/* profile data bucket */    char * value	                 	/* value for this parameter */    )    {    PPPOE_PROFILE_DATA * pPPPOEProfileData =(PPPOE_PROFILE_DATA *)pProfileData;    if (pProfileData == NULL || value == NULL)	return ERROR;    if (operType == PFW_PARAMETER_SET)	{	/* copy the flags */	pPPPOEProfileData->connectionMode = strtoul(value,NULL,16);	return OK;	}    else if (operType == PFW_PARAMETER_GET)	{	sprintf(value, "0x%x", pPPPOEProfileData->connectionMode);	return OK;	}    return ERROR;    }/******************************************************************************** pppOE_discoveryRetries - discoveryRetries parameter handler * */LOCAL STATUS pppOE_discoveryRetries    (    PFW_OBJ * pfw,    PFW_PARAMETER_OPERATION_TYPE operType,	/* operation type */    void * pProfileData,                	/* profile data bucket */    char * value	                 	/* value for this parameter */    )    {    PPPOE_PROFILE_DATA * pPPPOEProfileData =(PPPOE_PROFILE_DATA *)pProfileData;    if (pProfileData == NULL || value == NULL)	return ERROR;    if (operType == PFW_PARAMETER_SET)	{	/* convert from ascii to integer */	pPPPOEProfileData->discoveryRetries = atoi((const char *)value);	if (pPPPOEProfileData->discoveryRetries >= 255)	    {	    pPPPOEProfileData->discoveryRetries = 4;	    return ERROR;	    }	return OK;	}    else if (operType == PFW_PARAMETER_GET)	{	sprintf (value, "%d",pPPPOEProfileData->discoveryRetries);	return OK;	}    return ERROR;    }/

⌨️ 快捷键说明

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