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

📄 ipproto.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ipProto.c - an interface between the BSD IP protocol and the MUX *//* Copyright 1984 - 2002 Wind River Systems, Inc. *//*modification history--------------------03k,15may02,tcr  Make WV_NETEVENT_ETHEROUT_NOBUFS match uses elsewhere03j,24apr02,rae  Fixed muxTxRestart race condition (SPR #74565)03i,19apr02,wap  call ip_mloopback() rather than calling looutput() directly                 (SPR #72246)03h,26mar02,vvv  fixed proxy broadcast storm (SPR #74518)03g,02jan02,vvv  changed ipAttach failure message when device not found03f,01nov01,rae  ipError frees buffers on END_ERR_NO_BUF (SPR #70545)03e,15oct01,rae  merge from truestack ver 03r, base 02r(1) (SPRs 69573, 69112,                 29668, ROUTER_STACK etc.)03d,24jul01,r_s  changed code to be ANSI compatible so that it compiles with                 diab. made asm macro changes for diab03f,12jun01,rae  ipDetach checks for npt03e,01jun01,rae  fix problem with last checkin03d,08may01,rae  limited ARP binding to appropriate device types (SPR #33657)03c,07feb01,spm  fixed modification history for branches and merges03b,22nov00,rae  fixed problem with zeros in ethernet address (SPR# 29152)03a,14nov00,rae  fix SIOC[ADD,DEL]MULTI for non-ethernet devices (SPR# 35459)02z,13nov00,niq  merged from version 03o of tor2_0.open_stack-f1 brranh:                 added RFC 2233 support02y,10nov00,ham  enhanced sanity check for memory allocation (SPR #62262)02x,07nov00,spm  moved nptFlag from END_OBJ for T2 END binary compatibility02w,23oct00,spm  removed duplicate free (corrects SPR #22324 fix) (SPR #30465)02v,17oct00,spm  removed modification history from tor2_0_0.toolkit branch;                 merged from ver. 02z of tor3_0_x branch (base 02t): corrected                 attach routine (SPR #31351), added backward compatibility for                 END devices, and included general code cleanup02u,17oct00,spm  updated for new if_attach: reports memory allocation failures02t,17mar99,spm  added support for identical unit numbers (SPR #20913)02s,16mar99,spm  recovered orphaned code from version 02q of tor2_0_x branch                 (base version 02n) (SPR #25570)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 for both NPT and END devices. The ipAttach() routinebinds the IP protocol to a specific device. It is called automaticallyduring network initialization if INCLUDE_END is defined. The ipDetach()routine removes an existing binding to an END device.NOTE: The library can only transmit data to link-level destination addresses      less than or equal to 64 bytes in length.INCLUDE FILES: end.h muxLib.h etherMultiLib.h sys/ioctl.h*//* includes */#include "vxWorks.h"#include "stdio.h"#include "logLib.h"#include "semLib.h"#include "errnoLib.h"#include "tickLib.h"#include "intLib.h"#include "m2Lib.h"#include "private/m2LibP.h"#include "end.h"#include "muxLib.h"#include "private/muxLibP.h"#include "muxTkLib.h"#include "etherMultiLib.h"#include "sys/ioctl.h"#include "net/protosw.h"#include "sys/socket.h"#include "errno.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 "net/mbuf.h"#include "ipProto.h"#include "netinet/ip_var.h"#include "stdlib.h"#include "memPartLib.h"#ifdef VIRTUAL_STACK#include "netinet/vsLib.h"#endif /* VIRTUAL_STACK */#ifdef ROUTER_STACK#include "wrn/fastPath/fastPathLib.h"#endif /* ROUTER_STACK */#ifdef WV_INSTRUMENTATION#ifdef INCLUDE_WVNET#include "wvNetLib.h"#endif /* INCLUDE_WVNET */#endif /* WV_INSTRUMENTATION */#ifdef WV_INSTRUMENTATION#ifdef INCLUDE_WVNET    /* Set common fields of event identifiers for this module. */LOCAL UCHAR wvNetModuleId = WV_NET_IPPROTO_MODULE;   /* Value for ipProto.c */LOCAL UCHAR wvNetLocalFilter = WV_NET_NONE;     /* Available event filter */LOCAL ULONG wvNetEventId;       /* Event identifier: see wvNetLib.h */#endif    /* INCLUDE_WVNET */#endif	  /* WV_INSTRUMENTATION *//* defines */#define MAX_ADDRLEN 64 	/* Largest link-level destination for NPT devices. */#define senderr(e) { error = (e); goto bad;}/* typedefs */typedef struct arpcom IDR;typedef struct mbuf MBUF;typedef struct ifnet IFNET;                 /* real Interface Data Record */typedef struct sockaddr SOCK;/* externs */IMPORT void if_dettach(struct ifnet *ifp);IMPORT void ip_mloopback(struct ifnet *, struct mbuf *, struct sockaddr_in *,                    struct rtentry *rt);/* globals */#ifdef ROUTER_STACK/* * Pointer to the Fastpath library function table. This is set to * point to the function table inside of ffLibInit() when it is called */FF_LIB_FUNCTIONS *	pFFLibFuncs = NULL;#endif /* ROUTER_STACK *//* locals *//* forward declarations */LOCAL BOOL ipReceiveRtn (void * pCookie, long type, M_BLK_ID pBuff,                         LL_HDR_INFO * pLinkHdrInfo, void * pSpare);LOCAL BOOL ipTkReceiveRtn (void * callbackId ,long type, M_BLK_ID pBuff,                          void * pSpareData);LOCAL STATUS ipShutdownRtn (void * pCookie, void * pSpare);LOCAL STATUS ipTkShutdownRtn (void * callbackId);LOCAL STATUS arpShutdownRtn (void * pCookie, void * pSpare);LOCAL STATUS arpTkShutdownRtn (void * callbackId);LOCAL void ipTxStartup (IP_DRV_CTRL* pDrvCtrl);LOCAL int ipIoctl (IDR * ifp, int cmd, caddr_t data );LOCAL int ipTxRestart (void * pCookie, IP_DRV_CTRL* pDrvCtrl);LOCAL int ipTkTxRestart (void * pSpare);LOCAL int ipOutput (register struct ifnet *ifp, struct mbuf *m0,                        struct sockaddr *dst, struct rtentry *rt0);LOCAL void ipError (END_OBJ* pEnd, END_ERR* pError, void * pSpare);LOCAL int ipOutputResume (struct mbuf*, struct sockaddr*, void*, void*);LOCAL int ipMcastResume (struct mbuf* pMbuf, struct sockaddr* ipDstAddr,                             void* pIfp, void* rt);#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,   /* protocol/device binding from muxBind() */    long                type,           /* Protocol type.  */    M_BLK_ID 		pMblk,	        /* The whole packet. */    LL_HDR_INFO *	pLinkHdrInfo,	/* pointer to link level header info */    void * 		pSpare 		/* ip Drv ctrl */    )    {    END_OBJ * 		pEnd;    struct ifnet * 	pIfp;    M_BLK_ID            pMblkOrig;    IP_DRV_CTRL * 	pDrvCtrl = (IP_DRV_CTRL *)pSpare;#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;        }        pIfp = &pDrvCtrl->idr.ac_if;#ifdef WV_INSTRUMENTATION#ifdef INCLUDE_WVNET    /* WV_NET_NOTICE event */    WV_NET_EVENT_1 (NET_CORE_EVENT, WV_NET_NOTICE, 4, 13,                    WV_NETEVENT_ETHERIN_START, WV_NET_RECV, pIfp)#endif  /* INCLUDE_WVNET */#endif    if ((pIfp->if_flags & IFF_UP) == 0)        {        pIfp->if_ierrors++;        goto ipReceiveError;        }    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_ethernetCsmacd:        case M2_ifType_iso88023Csmacd:        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)                {#ifdef ROUTER_STACK		/* UNNUMBERED_SUPPORT */		/* No point to reject if we are on an unnumbered P2P network */		if (pIfp->if_flags & IFF_UNNUMBERED)		    break;#endif /* ROUTER_STACK */                /*                 * 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)))                    {                    pEnd = PCOOKIE_TO_ENDOBJ(pCookie);                    if (pEnd->flags & END_MIB_2233)                        {                        if (bcmp ((char *)END_ALT_HADDR (pEnd),                                  (caddr_t)pMblk->mBlkHdr.mData,                                  END_ALT_HADDR_LEN (pEnd)) != 0)                            goto ipReceiveError;                        }                    else /* (RFC1213 style of counters supported) XXX */                        {                        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;#ifdef VIRTUAL_STACK     /* Set the virtual stack ID so the received packet      * will be processed by the correct stack.      */      virtualStackNumTaskIdSet(pMblk->mBlkPktHdr.rcvif->vsNum);#endif /* VIRTUAL_STACK */#ifdef ROUTER_STACK    /*     * The algorithm explained...     * Check if Fastpath is enabled and this is an Ip packet.     * If so hand the packet over to the Fastpath code.     * If Fastpath is not enabled or if the Fastpath packet send function     * returns false, hand over the packet to tNetTask for normal processing.     */    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=(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("ipReceiveRtn: packet forwarded by Fastpath\n",0,0,0,0,0,0);#endif /* DEBUG */            return (TRUE);            }        }#endif /* ROUTER_STACK */    do_protocol_with_type (type, pMblk , &pDrvCtrl->idr,                            pMblk->mBlkPktHdr.len);    return (TRUE);ipReceiveError:    if (pMblk != NULL)        netMblkClChainFree (pMblk);    return (TRUE);    }

⌨️ 快捷键说明

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