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

📄 muxtklib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* muxTkLib.c - MUX toolkit Network Interface Library *//* Copyright 1984 - 2001 Wind River Systems, Inc. *//*modification history--------------------02k,05nov01,vvv  fixed compilation warning02j,15oct01,rae  merge from truestack ver 02m, base 02i (SPR #70512 etc)02i,09nov00,spm  removed pNptCookie from END_OBJ for binary compatibility;                 fixed handling of output protocols02h,29oct00,ham  doc: removed reference to old SENS docs(SPR #35134).02h,24oct00,niq  Merging in RFC2233 changes from tor2_0.open_stack-f1 branch                 02f,18oct00,ann  applyingthe fix for Jitterbug #25 regarding                 mac address not being filled correctly                 02e,16may00,ann merging from post R1 on openstack branch to                 incorporate RFC2233 implementation                 02c,10mar00,ead fixed MIB-2 counter updates to use new                 RFC 2233 m2IfLib02g,18oct00,niq  Correct the order in which protocols are inserted in the                 muxTkBind call02f,16oct00,spm  merged version 02g from tor3_0_x branch (base version 02b):                 adds multiple SNARF protocol support, code cleanup, and                 backward compatibility fixes; overrides 02d and 02e changes02e,25apr00,pul  fixing SPR 3058402d,17apr00,pul  fixed TSR 153280, TSR 156655 which are part of the NPT patch02c,12apr00,pul  modified _muxTkSend() to free an MBlk that could be allocated                 by the addressForm() routine when the driver send() routine                 returns an error02b,06oct99,pul  removing references to mCastMapFunc and rtRequestFunc02a,04oct99,pul  adding a new semaphore to protect the Bib entry traversal 	 	 + fixed SPR # 2842701z,07jul99,pul  To modify description for man page generation01y,07jun99,sj   resurrect network layer pkt in _muxTkSend if endSend fails 01x,29apr99,pul  Upgraded NPT phase3 code to tor2.0.001w,29mar99,pul  altered bind query, member name01v,29mar99,pul  altered muxTkPollReceive to return correct error.01u,26mar99,pul  removed all muxSvcFunc related stuff.01t,25mar99,sj   muxEndRcvRtn undoes MAC header strip after calling outputFilter01s,24mar99,sj   MUX_ID is installed as pSpare by muxTkBind + hook re-org01r,19mar99,sj   copy protocol type in to the BIB in muxTkBindUpdate01q,18mar99,sj   some clean up: collocated future release code at the end 01p,09mar99,sj   muxTkBind can bind to ENDs01o,05mar99,sj   eliminated hooks; not cleanly though. next version will do that01n,22feb99,sj 	 added muxTkSend and muxTkPollSend and muxTkPollReceive01m,26jan99,sj 	 moved BIB entry definition from here to muxLibP.h01l,10Nov98,sj 	 more doc fixes01k,09Nov98,sj 	 made logMsgs in muxTkLibInit conditional on muxTkDebug01j,09Nov98,sj 	 return OK from muxTkLibInit01i,08Nov98,sj   populate hooks only if not done already01h,06Nov98,sj   forward declaration for nptHookRtn01g,03Nov98,pul  modified muxMCastMapFuncGet to accept net svc type and net                 drv type 01f,03Nov98,pul  added muxMCastMapFuncGet, muxMCastMapFuncDel and comments01e,03Nov98,pul  moved definition of MUX_BIND_ENTRY and MUX_SVC_FUNCS here.		 modified muxTkLibInit to populate nptHook. Allocated                 muxBindBase array during muxTkBibInit().01d,02Nov98,sj   doc update01c,27Oct98,pul  removed muxTkSend for future release 01b,10Oct98,pul  Introduced hooks for ipProto module01a,05Oct98,pul  Written*//*DESCRIPTIONThis library provides additional APIs offered by the Network ProtocolToolkit (NPT) architecture.  These APIs extend the original release ofthe MUX interface.A NPT driver is an enhanced END but retains all of the END's functionality.NPT also introduces the term "network service sublayer" or simply "servicesublayer" which is the component that interfaces between the network service(or network protocol) and the MUX.  This service sublayer may be built into the network service or protocol rather than being a separate component.INTERNALThe muxLib routines for binding protocols to END drivers also use certainroutines from this library so that the BIB accurately reflects all bindingsbetween protocols and drivers. Since all information in the BIB is alsostored elsewhere, the BIB array should be removed to avoid the predefinedlimit it imposes on the number of active bindings.INCLUDE FILES: vxWorks.h, taskLib.h, stdio.h, errno.herrnoLib.h, lstlib.h,logLib.h, string.h, m2Lib.h, net/if.h, bufLib.h, semlib.h, end.h, muxLib.h,muxTkLib.h, netinet/if_ether.h, net/mbuf.h*//* includes */#include "vxWorks.h"#include "taskLib.h"#include "stdio.h"#include "errno.h"#include "errnoLib.h"#include "lstLib.h"#include "logLib.h"#include "string.h"#include "m2Lib.h"#include "net/if.h"             /* Needed for IFF_LOAN flag. */#include "bufLib.h"#include "semLib.h"#include "end.h"		/* Necessary for any END as well as the MUX */#include "muxLib.h"#include "private/muxLibP.h"#include "muxTkLib.h"#include "netinet/if_ether.h"#include "net/mbuf.h"#include "memPartLib.h"#ifdef VIRTUAL_STACK#include "netinet/vsLib.h"#endif    /* VIRTUAL_STACK *//* defines */#define STREQ(A, B) (strcmp ( (A), (B)) == 0)#define TK_DRV_CHECK(pBib) ((((MUX_ID)pBib)->flags & BIB_TK_DRV) ? TRUE : FALSE)#define TK_DRV_SET(pBib)   (((MUX_ID)pBib)->flags |= BIB_TK_DRV)#define TK_DRV_CLEAR(pBib) (((MUX_ID)pBib)->flags &= ~BIB_TK_DRV)#define DRV_ENTRY_CHECK(pBib) ((((MUX_ID)pBib)->flags & BIB_DRV_ENTRY) ? TRUE :\				    FALSE)#define PROTO_ENTRY_CHECK(pBib) ((((MUX_ID)pBib)->flags & BIB_PROTO_ENTRY) ?\				TRUE : FALSE)/* externs *//* globals */SEM_ID muxBibLock = NULL; /* To protect the traversal of Bib entries */int muxTkDebug = 0;int muxMaxBinds = 8;    /* Default (unless overridden by project facility). *//* locals */LOCAL MUX_ID muxBindBase;/* forward declarations */LOCAL int  muxTkBibEntryGet (END_OBJ * pEnd);LOCAL void muxTkBibEntryFill (int index, int netSvcType, void * netCallbackId);LOCAL void muxTkBibEntryFree (MUX_ID muxId);LOCAL int  muxEndRcvRtn (void *, long, M_BLK_ID, LL_HDR_INFO *, void *);/******************************************************************************* muxTkDrvCheck - checks if the device is an NPT or an END interface** This function returns 1 if the driver indicated by <pDevName> is of the* Toolkit (NPT) paradigm, and 0 (zero) if it is an END.  This routine is* called by the network service sublayer so that it can discover the driver* type before it binds to it via the MUX.** INTERNAL:* All network drivers having the same device name but different unit numbers* are of the same type (NPT or END), so passing just the device name as an* argument is sufficient** .IP <pDevName>* Expects a pointer to a string containing the name of the device** RETURNS: 1 for an NPT driver, 0 for an END or other driver, or ERROR (-1) * if no device is found with the given name** SEE ALSO: muxTkBind(), muxBind()*/int muxTkDrvCheck    (    char * pDevName	/* device name */    )    {    int    count;    BOOL   found = FALSE;    /* find the BIB entry for the device and return the tkFlag status */    semTake (muxBibLock, WAIT_FOREVER);    for (count = 0; count < muxMaxBinds; count++)        {        if (STREQ(muxBindBase[count].devName, pDevName))	    {	    found = TRUE;            break;	    }        }    semGive (muxBibLock);    if (found)	return (TK_DRV_CHECK(&muxBindBase[count]));    else	return (ERROR);    }/******************************************************************************* muxTkCookieGet - returns the cookie for a device** This routine returns the cookie for a device.** RETURNS: a cookie to the device or NULL if unsuccessful**/void *muxTkCookieGet    (    char *pName,		/* Device Name */    int unit			/* Device Unit */    )    {    int    count = 0;    END_OBJ *pEnd;    pEnd = endFindByName (pName, unit);    if (pEnd == NULL)	{	errnoSet (S_muxLib_NO_DEVICE);	return (NULL);	}    /* find the BIB entry for the device */    for (; (count < muxMaxBinds) && (muxBindBase[count].pEnd != pEnd); count++);    /* if there is a match, return it */    if (muxBindBase[count].pEnd == pEnd)	return (&muxBindBase[count]);    return (NULL);    }  /******************************************************************************** muxTkBind - bind an NPT protocol to a driver** A network protocol, network service, or service sublayer uses this routine* to bind to a specific driver.  This bind routine is valid both for END and* NPT drivers, but the specified stack routine parameters must use the NPT* function prototypes, and are somewhat different from those used with* muxBind().** The driver is specified by the <pName> and <unit> arguments, (for example,* ln and 0, ln and 1, or ei and 0).** .IP <pName> 20* Expects a pointer to a character string that contains the name of the* device that this network service wants to use to send and receive packets.* .IP <unit>* Expects the unit number of the device of the type indicated by <pName>.* .IP <stackRcvRtn>* Expects a pointer to the function that the MUX will call when it* wants to pass a packet up to the network service.  For a description of* how to write this routine, see the  * .I "WindNet TCP/IP Network Programmer's Guide"* .IP <stackShutdownRtn>* Expects a pointer to the function that the MUX will call to* shutdown the network service.  For a description of how to write such* a routine, see the * .I "WindNet TCP/IP Network Programmer's Guide"* .IP <stackTxRestartRtn>* Expects a pointer to the function that the MUX will call after packet* transmission has been suspended, to tell the network service that it can* continue transmitting packets.  For a description of how to write this* routine, see the * .I "WindNet TCP/IP Network Programmer's Guide"* .IP <stackErrorRtn>* Expects a pointer to the function that the MUX will call to give errors* to the network service.  For a description of how to write this routine,* see the section* .I "WindNet TCP/IP Network Programmer's Guide"* .IP <type>* Expects a value that indicates the protocol type.  The MUX uses this type* to prioritize a network service as well as to modify its capabilities.  For* example, a network service of type MUX_PROTO_SNARF has the highest priority* (see the description of protocol prioritizing provided in* .I "WindNet TCP/IP Network Programmer's Guide."* Aside from MUX_PROTO_SNARF and MUX_PROTO_PROMISC, valid network service* types include any of the values specified in RFC 1700, or can be* user-defined.** The <stackRcvRtn> is called whenever the MUX has a packet of the specified* type.  If the type is MUX_PROTO_PROMISC, the protocol is considered* promiscuous and will get all of the packets that have not been consumed* by any other protocol.  If the type is MUX_PROTO_SNARF, it will get all of* the packets that the MUX sees.** If the type is MUX_PROTO_OUTPUT, this network service is an output protocol* and all packets that are to be output on this device are first passed to* <stackRcvRtn> routine rather than being sent to the device.  This can be* used by a network service that needs to send packets directly to another* network service, or in a loop-back test.  If the <stackRcvRtn> returns OK,* the packet is consumed and as no longer available.  The <stackRcvRtn> for an* output protocol may return ERROR to indicate that it wants to look at the* packet without consuming it.* .IP <pProtoName>* Expects a pointer to a character string for the name of this* network service.  This string can be NULL, in which case a network service* name is assigned internally.* .IP <pNetCallbackId>* Expects a pointer to a structure defined by the protocol.  This argument* is passed up to the protocol as the first argument of all the callbacks.* This argument corresponds to the <pSpare> argument in muxBind()* .IP <pNetSvcInfo>* Reference to an optional structure specifying network service layer* information needed by the driver* .IP <pNetDrvInfo>* Reference to an optional structure specifying network driver information* needed by the network protocol, network service, or service sublayer** RETURNS: A cookie that uniquely represents the binding instance, or NULL* if the bind fails.** ERRNO: S_muxLib_NO_DEVICE, S_muxLib_END_BIND_FAILED, S_muxLib_NO_TK_DEVICE,* S_muxLib_NOT_A_TK_DEVICE, S_muxLib_ALREADY_BOUND, S_muxLib_ALLOC_FAILED** SEE ALSO: muxBind()**/void * muxTkBind    (    char * pName,		/* interface name, for example, ln, ei,... */    int    unit,		/* unit number */    BOOL   (*stackRcvRtn) (void*,long, M_BLK_ID, void *),                                /* receive function to be called. */    STATUS (*stackShutdownRtn) (void *),                                /* routine to call to shutdown the stack */    STATUS (*stackTxRestartRtn) (void *),                                /* routine to tell the stack it can transmit */    void   (*stackErrorRtn) (void*, END_ERR*),                                /* routine to call on an error. */    long   type,		/* protocol type from RFC1700 and many */                                /* other sources (for example, 0x800 is IP) */    char * pProtoName,          /* string name for protocol  */    void * pNetCallbackId,      /* returned to network service sublayer during recv */    void * pNetSvcInfo,         /* reference to netSrvInfo structure */    void * pNetDrvInfo          /* reference to netDrvInfo structure */    )    {    NET_PROTOCOL * pNewProto = NULL;    NET_PROTOCOL * pNode = NULL;    NODE *         pFinal = NULL;    /* Last snarf protocol, if any. */    END_OBJ *      pEnd;    int            index = 0;    FUNCPTR        ioctlRtn = NULL;    BOOL           tkFlag = FALSE;    if (muxTkDebug)	logMsg ("Start of muxTkBind\n", 1, 2, 3, 4, 5, 6);    /* Check to see if we have a valid device. */    pEnd = endFindByName (pName, unit);    if (pEnd == NULL)        {        errnoSet (S_muxLib_NO_DEVICE);        return (NULL);        }    if (muxTkDebug)	logMsg ("Found the END object\n", 1, 2, 3, 4, 5, 6);    /*     * Query for the END bind routine and call it if available;     * if the driver rejects the bind there's no need to proceed     */    if((ioctlRtn = pEnd->pFuncTable->ioctl) != NULL)        {	FUNCPTR   bindRtn = NULL;	END_QUERY endQuery = {END_BIND_QUERY, 4, {0,0,0,0} };	if ((*ioctlRtn) (pEnd,EIOCQUERY, &endQuery) == OK)	    {	    bindRtn = *(FUNCPTR *)endQuery.queryData;	    if ((*bindRtn) (pEnd, pNetSvcInfo,			    pNetDrvInfo, type) == ERROR)		{		if (muxTkDebug)		    logMsg ("muxTkBind: EndBind failed\n", 1, 2, 3, 4, 5, 6);		return (NULL);		}	    }	}    /* check if we are allowed to continue with this protocol type */    if (type == MUX_PROTO_OUTPUT)	{	/*	 * Check to see if this is an OUTPUT protocol and allow only	 * one output filter per END	 */        if (pEnd->outputFilter)            {            errnoSet (S_muxLib_ALREADY_BOUND);            return (NULL);            }	}    else	{        /*         * Get the appropriate place in the protocol list if necessary.         * For standard protocols, also check if the protocol number         * is available.         */         if (type != MUX_PROTO_PROMISC)            {            /* Get the first standard protocol and last snarf protocol, if any. */            if (pEnd->snarfCount)                {                pFinal = lstNth (&pEnd->protocols, pEnd->snarfCount);                pNode = (NET_PROTOCOL *)lstNext (pFinal);                }            else                pNode = (NET_PROTOCOL *)lstFirst (&pEnd->protocols);            }        if (type != MUX_PROTO_SNARF && type != MUX_PROTO_PROMISC)            {            for ( ; pNode != NULL;                  pNode = (NET_PROTOCOL *)lstNext (&pNode->node) )                {                if (pNode->type == type)                    {                    errnoSet (S_muxLib_ALREADY_BOUND);                    return (NULL);                    }                }            }	}   /* find an empty slot in the BIB */

⌨️ 快捷键说明

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