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

📄 ipproto.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** ipTkReceiveRtn - send a packet to the protocol from an NPT device** This routine transfers data to IP when an NPT device receives a packet* from a toolkit driver. The data contained in the <pMblk> argument is an* IP packet (without a link-level header). A toolkit driver updates the* flags in the mBlk to indicate a multicast or broadcast link-level frame.** RETURNS: TRUE, always.** NOMANUAL*/LOCAL BOOL ipTkReceiveRtn    (    void * ipCallbackId,      /* Sent down in muxTkBind call. */    long         type,        /* Protocol type.  */    M_BLK_ID     pMblk,       /* The whole packet. */    void *       pSpareData   /* out of band data */    )    {    IP_DRV_CTRL * pDrvCtrl = (IP_DRV_CTRL *)ipCallbackId;    struct ifnet *  pIfp;#ifdef ROUTER_STACK    struct ip* pIpHdr;    ULONG ipAddr=0;    struct sockaddr_in dstIpAddr;#endif  /* ROUTER_STACK */    if (pDrvCtrl == NULL)        {        logMsg ("ipProto: unknown device\n", 0, 0, 0, 0, 0, 0);        goto ipReceiveError;        }#ifdef IP_DEBUG    if (ipDebug)        logMsg("start of ipTkReceiveRtn!\n", 0, 0, 0, 0, 0, 0);#endif /* IP_DEBUG */    pIfp = (struct ifnet *)&pDrvCtrl->idr;    if ((pIfp->if_flags & IFF_UP) == 0)        {        pIfp->if_ierrors++;        goto ipReceiveError;        }    /* bump statistic */    pIfp->if_ipackets++;            pIfp->if_lastchange = tickGet();    pIfp->if_ibytes += pMblk->mBlkPktHdr.len;    if(pMblk->mBlkHdr.mFlags & M_MCAST)        pIfp->if_imcasts++;    pMblk->mBlkPktHdr.rcvif     = pIfp;    /* hand off the packet to ip layer */#ifdef ROUTER_STACK    /* Check to see if Fastpath is enabled on the received interface */    if (SHOULD_GIVE_PACKET_TO_FF (GET_IPV4_FF_ID, pIfp) &&         type == ETHERTYPE_IP)        {        pIpHdr=mtod(pMblk, struct ip*);        ipAddr=pIpHdr->ip_dst.s_addr;        bzero((char*)&dstIpAddr, sizeof(struct sockaddr_in));        dstIpAddr.sin_len = sizeof(struct sockaddr_in);        dstIpAddr.sin_family=AF_INET;        dstIpAddr.sin_addr.s_addr=NTOHL(ipAddr);        if (FF_NC_CALL (GET_IPV4_FF_ID, ffPktSend, \                        (GET_IPV4_FF_ID, (struct sockaddr*)&dstIpAddr, \                         pMblk, ETHERTYPE_IP, pIfp)) == OK)            {#ifdef DEBUG            logMsg("ipTkReceiveRtn: packet forwarded by Fastpath\n",0,0,0,0,0,0);#endif /* DEBUG */            return (TRUE);            }        }#endif /* ROUTER_STACK */    do_protocol_with_type (type, pMblk , (struct arpcom* )pIfp,                            pMblk->mBlkHdr.mLen);    return (TRUE);    ipReceiveError:         {         if (pMblk != NULL)             netMblkClChainFree (pMblk);         }    return (TRUE);    }/******************************************************************************** ipShutdownRtn - Shutdown the NULL protocol stack gracefully.* * This routine is called by the lower layer upon muxDevUnload or a similar* condition to tell the protocol to shut itself down.** RETURNS: OK, or ERROR if muxUnbind routine fails.** NOMANUAL*/LOCAL STATUS ipShutdownRtn    (    void * 	pCookie, 	/* protocol/device binding from muxBind() */    void * 	pSpare 		/* spare pointer from muxBind() */    )    {    IP_DRV_CTRL * 	pDrvCtrl = (IP_DRV_CTRL *)pSpare;    if (!pDrvCtrl->attached)	return (ERROR);    if_dettach(&pDrvCtrl->idr.ac_if);    KHEAP_FREE(pDrvCtrl->idr.ac_if.if_name);    netMblkFree (_pNetDpool, pDrvCtrl->pSrc);    netClFree (_pNetDpool, pDrvCtrl->pDstAddr);    netMblkFree (_pNetDpool, pDrvCtrl->pDst);    if (muxUnbind (pDrvCtrl->pIpCookie, ETHERTYPE_IP, ipReceiveRtn) != OK)	{	logMsg ("Could not un-bind from the IP MUX!", 0, 0, 0, 0, 0, 0);	return (ERROR);	}    if (pDrvCtrl->pArpCookie == NULL)        {        pDrvCtrl->attached = FALSE;        }    pDrvCtrl->pIpCookie = NULL;    return (OK);    }/******************************************************************************** arpShutdownRtn - Shutdown the NULL protocol stack gracefully.* * This routine is called by the lower layer upon muxDevUnload or a similar* condition to tell the protocol to shut itself down.** RETURNS: OK or ERROR.** NOMANUAL*/LOCAL STATUS arpShutdownRtn    (    void * 	pCookie, 	/* protocol/device binding from muxBind() */    void * 	pSpare 		/* spare pointer from muxBind() */    )    {    IP_DRV_CTRL * pDrvCtrl = (IP_DRV_CTRL *)pSpare;    if (pDrvCtrl == NULL)        return (ERROR);                if (!pDrvCtrl->attached)	return (ERROR);    if (muxUnbind (pDrvCtrl->pArpCookie, ETHERTYPE_ARP, ipReceiveRtn) != OK)	{	logMsg ("Could not un-bind from the ARP MUX!", 0, 0, 0, 0, 0, 0);	return (ERROR);	}    if (pDrvCtrl->pIpCookie == NULL)        {        pDrvCtrl->attached = FALSE;        }    pDrvCtrl->pArpCookie = NULL;    return (OK);    }/******************************************************************************** ipTkShutdownRtn - Shutdown the protocol stack bound to a toolkit driver** This routine is called by the lower layer upon muxDevUnload or a similar* condition to tell the protocol to shut itself down.** RETURNS: OK or ERROR depending on ipDetach.** NOMANUAL*/LOCAL STATUS ipTkShutdownRtn    (    void * ipCallbackId       /* protocol/device binding from muxTkBind() */    )    {    IP_DRV_CTRL * pDrvCtrl = (IP_DRV_CTRL *)ipCallbackId;    if (pDrvCtrl == NULL)        return (ERROR);        if (!pDrvCtrl->attached)        return (ERROR);    if_dettach(&pDrvCtrl->idr.ac_if);    KHEAP_FREE(pDrvCtrl->idr.ac_if.if_name);    netClFree (_pNetDpool, pDrvCtrl->pDstAddr);    if (muxUnbind(pDrvCtrl->pIpCookie, ETHERTYPE_IP, ipTkReceiveRtn) != OK)        {        logMsg("Could not un-bind from the IP MUX!", 1, 2, 3, 4, 5, 6);        return (ERROR);        }    if (pDrvCtrl->pArpCookie == NULL)        {        pDrvCtrl->attached = FALSE;        }    pDrvCtrl->pIpCookie=NULL;    return (OK);    }/******************************************************************************** arpTkShutdownRtn - shutdown the protocol stack bound to a toolkit driver. ** This routine is called by the lower layer upon muxDevUnload or a similar* condition to tell the protocol to shut itself down.** RETURNS: OK or ERROR.** NOMANUAL*/LOCAL STATUS arpTkShutdownRtn    (    void * ipCallbackId       /* Sent down in muxTkBind call. */    )    {    IP_DRV_CTRL * pDrvCtrl = (IP_DRV_CTRL *)ipCallbackId;    if (pDrvCtrl == NULL)        return (ERROR);    if (!pDrvCtrl->attached)        return (ERROR);    if (muxUnbind(pDrvCtrl->pArpCookie, ETHERTYPE_ARP, ipTkReceiveRtn) != OK)        {        logMsg("Could not un-bind from the ARP MUX!", 1, 2, 3, 4, 5, 6);        return (ERROR);        }    if (pDrvCtrl->pIpCookie == NULL)        {        pDrvCtrl->attached = FALSE;        }    pDrvCtrl->pArpCookie=NULL;    return (OK);    }/******************************************************************************** ipTkError - a routine to deal with toolkit device errors** This routine is called by the lower layer to handle a toolkit device error.** RETURNS: N/A** NOMANUAL**/void ipTkError    (    void * ipCallbackId,  /* Sent down in muxTkBind call. */    END_ERR* pError       /* Error message */    )    {    IP_DRV_CTRL * pDrvCtrl = (IP_DRV_CTRL *)ipCallbackId;    END_OBJ * pEnd  = NULL;    if (pDrvCtrl)	 pEnd = PCOOKIE_TO_ENDOBJ (pDrvCtrl->pIpCookie);    if (pDrvCtrl == NULL || pEnd == NULL)        return;    ipError (pEnd, pError, pDrvCtrl);    return;    }/******************************************************************************** ipError - a routine to deal with device errors** This routine handles all errors from NPT and END drivers.** RETURNS: N/A** NOMANUAL*/LOCAL void ipError    (    END_OBJ * 	pEnd, 		/* END reporting the error */    END_ERR * 	pError, 	/* the error message */    void * 	pSpare 		/* spare pointer from muxBind() */    )    {    int s;    IP_DRV_CTRL * pDrvCtrl = (IP_DRV_CTRL *)pSpare;    struct ifnet * pIfp;    USHORT newFlags;    if (pEnd == NULL || pDrvCtrl == NULL)    	return;    pIfp = (struct ifnet *)&pDrvCtrl->idr;    switch (pError->errCode)        {#ifdef IP_DEBUG        case END_ERR_INFO:            if (ipDebug && pError->pMesg != NULL)                logMsg ("INFO: Device: %s Unit: %d Msg: %s\n",                        (int)pEnd->devObject.name, pEnd->devObject.unit,                        (int)pError->pMesg, 0, 0, 0);                break;        case END_ERR_WARN:            if (ipDebug && pError->pMesg != NULL)                logMsg ("WARN: Device: %s Unit: %d Msg: %s\n",                        (int)pEnd->devObject.name, pEnd->devObject.unit,                        (int)pError->pMesg, 0, 0, 0);                break;#endif /* IP_DEBUG */        case END_ERR_RESET:#ifdef IP_DEBUG            if (ipDebug && pError->pMesg != NULL)                logMsg ("RESET: Device: %s Unit: %d Msg: %s\n",                        (int)pEnd->devObject.name, pEnd->devObject.unit,                        (int)pError->pMesg, 0, 0, 0);#endif /* IP_DEBUG */            pDrvCtrl->idr.ac_if.if_lastchange = tickGet();            break;        case END_ERR_UP:#ifdef IP_DEBUG            if (ipDebug && pError->pMesg != NULL)                logMsg ("UP: Device: %s Unit: %d Msg: %s\n",                        (int)pEnd->devObject.name, pEnd->devObject.unit,                        (int)pError->pMesg, 0, 0, 0);#endif /* IP_DEBUG */            if ( (pIfp->if_flags & IFF_UP) == 0)                {                s = splimp ();                if_up (pIfp);                splx (s);                }            pDrvCtrl->idr.ac_if.if_lastchange = tickGet();            ((IFNET *)&pDrvCtrl->idr)->if_flags |= (IFF_UP| IFF_RUNNING);            break;        case END_ERR_DOWN:#ifdef IP_DEBUG            if (ipDebug && pError->pMesg != NULL)                logMsg ("DOWN: Device: %s Unit: %d Msg: %s\n",                        (int)pEnd->devObject.name, pEnd->devObject.unit,                        (int)pError->pMesg, 0, 0, 0);#endif /* IP_DEBUG */            if ( (pIfp->if_flags & IFF_UP))                {                s = splimp ();                if_down (pIfp);                splx (s);                }            pDrvCtrl->idr.ac_if.if_lastchange = tickGet();            ((IFNET *)&pDrvCtrl->idr)->if_flags &= ~(IFF_UP| IFF_RUNNING);            break;        case END_ERR_FLAGS:#ifdef IP_DEBUG            if (ipDebug && pError->pMesg != NULL)                logMsg ("ipError:Msg from device %s Unit: %d Msg: %s\n",                        (int)pEnd->devObject.name, pEnd->devObject.unit,                        (int)pError->pMesg, 0, 0, 0);#endif /* IP_DEBUG */            newFlags = (USHORT) ( (UINT32)pError->pSpare);

⌨️ 快捷键说明

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