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

📄 ipproto.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ipProto.c - an interface between the BSD IP protocol and the MUX *//* Copyright 1984 - 1999 Wind River Systems, Inc. *//*modification history--------------------02r,17mar99,spm  added support for identical unit numbers (SPR #20913)02q,09dec98,n_s  lint cleanup.02p,09dec98,n_s  fixed M_BLK leak when attaching and detaching from an END.                 spr 2318802o,06oct98,ham considered multiple IPaddrs in ipIoctl() SPR#22267.02o,06oct98,ham considered multiple IPaddrs in ipIoctl() SPR#22267.02r,03mar99,spm  eliminated buffer overflow when attaching device (SPR #22679);                 cleaned up mod history list02q,03mar99,pul  update the driver flag during ipAttach(), SPR# 2428702p,02mar99,pul  update ifp->if_baudrate during ipAttach(): SPR# 2425602o,25feb99,pul  fixed multicast mapping to invoke resolution func spr#2425502n,08aug98,n_s  fixed ipReceiveRtn to handle M_BLK chains (SPR #22324)02m,26aug98,fle  doc : put library description next line02l,24aug98,ann  fixed copy of ifSpeed field in ipIoctl() spr # 2219802k,21aug98,n_s  fixed if_omcast increment in ipOutout (). spr # 2107402j,16jul98,n_s  fixed ipIoctl () SIOCSIFFLAGS. SPR 2112402i,15jun98,n_s  seperated ipDetach () into ipShutdownRtn () and                  arpShutdownRtn ().  spr # 2154502h,11dec97,gnn  removed IFF_SCAT and IFF_LOAN references.02g,08dec97,gnn  END code review fixes.02f,17oct97,vin  changes reflecting protocol recieveRtn changes.02e,09oct97,vin  added break statements to ipIoctl(). fixed ipReceive().02d,03oct97,gnn  added an error routine02c,25sep97,gnn  SENS beta feedback fixes02b,03sep97,gnn  implemented dropping of packets if the queue is full02a,29aug97,jag  fixed bad parameter causing failure in txRestart routine.01z,25aug97,gnn  documentation fixes for mangen.01y,25aug97,gnn  added a check for attached in the TxRestart routine.01x,19aug97,gnn  changes due to new buffering scheme.01w,12aug97,gnn  name change and changes necessitated by MUX/END update.01v,06jun97,vin  made enhancements, fixed arpReceive for multiple units.01u,02jun97,gnn  put in stuff to deal with memory widths.01t,20may97,gnn  fixed SPR 8627 so that multiple units are possible.01s,15may97,gnn  modified muxUnbind to follow new prototype.01r,30apr97,gnn  put a logMsg behind a debug check.                 cleaned up warnings.01q,25apr97,gnn  fixed SPR 8461 about SNMP ioctls.01p,09apr97,gnn  pass through for IFFLAGS.01o,20mar97,map  Fixed problems in buffer loaning.                 Added gratuitous arp on SIOCSIFADDR.01n,03feb97,gnn  Changed the way in which muxBufAlloc is used.01m,30jan97,gnn  Fixed a bug in the call to build_cluster.01l,24jan97,gnn  Modified vector code to handle holes in mbuf chains.01k,24jan97,gnn  Fixed the bug where we were not checking the length of                 data in an mbuf as well as the next pointer.                 Fixed a bug in initialising for buffer loaning.01j,22jan97,gnn  Added new private flags that is seperate from if flags.01i,21jan97,gnn  Added code to handle scatter/gather.                 Changed the way send is done to deal with freeing buffers.                 Made receive routines return a value for SNARFing.01h,20dec96,vin  fixed problems in send (added semGive, m_freem)                  and recv routines (cleaned up). cleanup ifdefs.01j,17dec96,gnn  added new drvCtrl structures.01i,27nov96,gnn  added MIB 2 if_type handling.01h,07nov96,gnn  fixed the bug where we were getting the flags wrong.01g,23oct96,gnn  removed bcopy hack in initialization.01f,22oct96,gnn  name changes to follow coding standards.                 cleanup of some compilation warnings.01e,22oct96,gnn  removed ENET_HDR definition.01d,22oct96,gnn  Changed all netVectors to netBuffers.                 Removed all private buffer loaning stuff.  That's all now                 in the MUX.01c,23sep96,gnn  Added new buffering scheme information.01b,13sep96,vin  fixed a bug in ipEtherIoctl for SIOCADDMULTI & SIOCDELMULTI 01a,16may96,gnn	 written.*/ /*DESCRIPTIONThis library provides an interface between the Berkeley protocol stackand the MUX interface. The ipAttach() routine binds the IP protocol toa specific device. It is called automatically during network initialization if INCLUDE_END is defined. The ipDetach() routine removes an existingbinding.INCLUDE FILES: end.h muxLib.h etherMultiLib.h sys/ioctl.h etherLib.h*//* includes */#include "vxWorks.h"#include "logLib.h"#include "semLib.h"#include "errnoLib.h"#include "tickLib.h"#include "m2Lib.h"#include "private/m2LibP.h"#include "end.h"#include "muxLib.h"#include "etherMultiLib.h"#include "sys/ioctl.h"#include "etherLib.h"#include "net/protosw.h"#include "sys/socket.h"#include "errno.h"#include "netinet/in.h"#include "netinet/in_systm.h"#include "netinet/in_var.h"#include "netinet/ip.h"#include "netinet/if_ether.h"#include "net/if_subr.h"#include "net/if_dl.h"#include "net/if_llc.h"#include "ipProto.h"#include "stdlib.h"/* defints */#define senderr(e) { error = (e); goto bad;}#define END_HADDR(pEnd) \                ((pEnd)->mib2Tbl.ifPhysAddress.phyAddress)#define END_HADDR_LEN(pEnd) \                ((pEnd)->mib2Tbl.ifPhysAddress.addrLength)/* typedefs */typedef struct arpcom IDR;typedef struct mbuf MBUF;typedef struct ifnet IFNET;                 /* real Interface Data Record */typedef struct sockaddr SOCK;/* globals *//* locals *//* forward declarations */LOCAL BOOL ipReceiveRtn(void* pCookie, long type, M_BLK_ID pBuff,                        LL_HDR_INFO * pLinkHdrInfo, IP_DRV_CTRL* pDrvCtrl);LOCAL STATUS ipShutdownRtn(void* pCookie, IP_DRV_CTRL* pDrvCtrl);LOCAL STATUS arpShutdownRtn (void* pCookie, IP_DRV_CTRL* pDrvCtrl);LOCAL void ipTxStartup(IP_DRV_CTRL *pDrvCtrl);STATUS ipDetach (int unit, char *pDevice);LOCAL int ipIoctl(IDR *ifp, int cmd, caddr_t data );LOCAL int ipTxRestart (void * pCookie, IP_DRV_CTRL* pDrvCtrl);LOCAL int ipOutput(register struct ifnet *ifp, struct mbuf *m0,                        struct sockaddr *dst, struct rtentry *rt0);IMPORT void if_dettach(struct ifnet *ifp);IMPORT int looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,                    struct rtentry *rt);#define IP_DEBUG#ifdef IP_DEBUGint ipDebug 	=	FALSE;#endif/******************************************************************************** ipReceiveRtn - Send a packet from the MUX to the Protocol* * This routine deals with  calling the upper layer protocol.** RETURNS: always TRUE.** NOMANUAL*/BOOL ipReceiveRtn    (    void * 		pCookie,	/* Returned by muxBind() call. */    long                type,           /* Protocol type.  */    M_BLK_ID 		pMblk,	        /* The whole packet. */    LL_HDR_INFO *	pLinkHdrInfo,	/* pointer to link level header info */    IP_DRV_CTRL *	pDrvCtrl	/* ip Drv ctrl */    )    {    END_OBJ * 		pEnd;    struct ifnet * 	pIfp;    M_BLK_ID            pMblkOrig;        if (pDrvCtrl == NULL)        {	logMsg ("ipProto: unknown device\n", 1, 2, 3, 4, 5, 6);	goto ipReceiveError;	}        pIfp = &pDrvCtrl->idr.ac_if;    if ((pIfp->if_flags & IFF_UP) == 0)        {	pIfp->if_ierrors++;	goto ipReceiveError;	}    pEnd = (END_OBJ *)pCookie;    pIfp->if_ipackets++;          /* bump statistic */    pIfp->if_lastchange = tickGet();    pIfp->if_ibytes += pMblk->mBlkPktHdr.len;    /* Make sure the entire Link Hdr is in the first M_BLK */    pMblkOrig = pMblk;    if (pMblk->mBlkHdr.mLen < pLinkHdrInfo->dataOffset	&& (pMblk = m_pullup (pMblk, pLinkHdrInfo->dataOffset)) == NULL)	{	pMblk = pMblkOrig;	goto ipReceiveError;	}        switch (pIfp->if_type)        {        case M2_ifType_ethernet_csmacd:        case M2_ifType_iso88023_csmacd:        case M2_ifType_iso88024_tokenBus:        case M2_ifType_iso88025_tokenRing:        case M2_ifType_iso88026_man:        case M2_ifType_fddi:                  		            if (pMblk->mBlkHdr.mData[0] & 1)                {                if (bcmp((caddr_t)etherbroadcastaddr,                         (caddr_t)pMblk->mBlkHdr.mData,                         sizeof(etherbroadcastaddr)) == 0)                    pMblk->mBlkHdr.mFlags |= M_BCAST;                else                    pMblk->mBlkHdr.mFlags |= M_MCAST;                pIfp->if_imcasts++;                }                        if (pIfp->if_flags & IFF_PROMISC)                {                /*                 * do not hand over the non multicast packets to the ip stack                 * if they are not destined to us, orelse it confuses the                 * ip forwarding logic and keeps sending unnecessary redirects.                 * If packets destined for other hosts have to be snooped they                 * have to done through driver level hooks.                 */                                if (!(pMblk->mBlkHdr.mFlags & (M_BCAST | M_MCAST)))                    {                    if (bcmp ((char *)END_HADDR (pEnd),                              (caddr_t)pMblk->mBlkHdr.mData,                              END_HADDR_LEN (pEnd)) != 0)                        goto ipReceiveError;                    }                }            break;        default:            break;        }    /* point to the ip header, and adjust the length */    pMblk->mBlkHdr.mData 	+= pLinkHdrInfo->dataOffset;    pMblk->mBlkHdr.mLen  	-= pLinkHdrInfo->dataOffset;    pMblk->mBlkPktHdr.len   	-= pLinkHdrInfo->dataOffset;    pMblk->mBlkPktHdr.rcvif 	= &pDrvCtrl->idr.ac_if;    /* hand off the packet to ip layer */    do_protocol_with_type (type, pMblk , &pDrvCtrl->idr			   , pMblk->mBlkPktHdr.len);     goto ipReceiveEnd;    ipReceiveError:   	 {         if (pMblk != NULL)             netMblkClChainFree (pMblk);          }    ipReceiveEnd:    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 depending on ipDetach.** NOMANUAL*/LOCAL STATUS ipShutdownRtn    (    void* pCookie,		/* Returned by muxBind() call. */    IP_DRV_CTRL* pDrvCtrl       /* Sent down in muxBind call. */    )    {    END_OBJ* pEnd = (END_OBJ*)pDrvCtrl->pIpCookie;    if (!pDrvCtrl->attached)	return (ERROR);    if_dettach(&pDrvCtrl->idr.ac_if);    netMblkFree (pEnd->pNetPool, pDrvCtrl->pSrc);    netMblkFree (pEnd->pNetPool, pDrvCtrl->pDst);        if (muxUnbind(pDrvCtrl->pIpCookie, 0x800, ipReceiveRtn) != 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);    }/******************************************************************************** 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,		/* Returned by muxBind() call. */    IP_DRV_CTRL* pDrvCtrl       /* Sent down in muxBind call. */    )    {    if (!pDrvCtrl->attached)	return (ERROR);    if (muxUnbind(pDrvCtrl->pArpCookie, 0x806, ipReceiveRtn) != 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);    }/*******************************************************************************

⌨️ 快捷键说明

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