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

📄 vslib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* vsLib.c - virtual stack management library *//* Copyright 2000 - 2001 Wind River Systems, Inc. *//*modification history--------------------02a,17jul01,ann  adding virtualStackNameGet/Set routines01z,11jul01,jpf  Added a lot of minor refinements and virtualStackNumGet01y,16apr01,jpf  Fixing this file to work with vs01x,29mar01,spm  file creation: copied from version 01w of tor2_0.open_stack                 branch (wpwr VOB) for unified code base; converted memory                 allocation for protection domain restrictions01w,21jul00,gnn  fixed it not to build when VIRTUAL_STACK is off01v,23jun00,spm  used new routine for ARP initialization (from proxy ARP merge)01u,12jun00,ta   add vsexec Shell command01t,08jun00,ead  moved ARP initialization to arpInit in arpLib.c01s,07jun00,ead  fixed a bug in virtualStackCreate that didn't check for the                 stack name01r,07jun00,ead  modifed vsMakeStack to return a STATUS result01q,26may00,ead  added ipMaxUnits argument to virtualStackInit()01p,25may00,pul  adding ffInit() to virtualStackInit()01o,22may00,ead  modifed vsMakeStack01n,22may00,ead  added llinfo_arp initialization in virtualStackInit                 created the vsMakeStack function01m,19may00,cn   changed all pName buffers to strings.01l,17may00,cn   fixed bug in virtualStackNameTaskIdSet () and                 virtualStackIdGet ().01k,05may00,ann  adding some initializations for m2 libraries01j,05may00,gnn  added virtualStackShow which shows ALL virtual stacks01i,04may00,spm  fixed initialization for UDP and show routines01h,01may00,ann  adding some initializations for sockets and UDP01g,26apr00,spm  updated startup instructions; added routing storage handling01f,26apr00,gnn  fixed strlen/strcpy counting bug01e,25apr00,spm  separated initialization and creation of virtual stacks01d,25apr00,gnn  added clearing of each vsTbl entry as it's created                 added netLibInit() to initialize protocols                 added domain handling code                 fixed netPool handling code01c,24apr00,gnn  added ifnet list handling01b,23apr00,gnn  Added code to start up parts of the stack (splSemInit and                 mbinit) to virtualStackCreate.01a,09mar00,gnn	 written.*/ /*DESCRIPTIONThis module implements the framework for Virtual TCP/IP Stacks.  Each stack isrepresented by a BSD_GLOBAL_DATA structure defined intarget/h/netinet/vsData.h.  Please see that file for information on particularelements of that data structure.The system is an array of pointers to these structures stored in vsTbl andindexed by an integer from 0 to VSID_MAX.  There is a special stack, referredto as the management stack, which is defined as VS_MGMT_STACK.  This isdefined in target/h/netinet/vsLib.h.For tasks calling into the stack we provide a current Virtual Stacknumber concept via a task variable called myTaskNum.  This variable can begotten or set via a set of routines in this module.  Routines called in thecontext of a task (though NEVER tNetTask) it is possible to reference elementsof the stack's virtual stack like this:.CSvsTbl[myTaskNum]->stackGlobalYouWantToLookAt.CEINCLUDE FILES: SEE ALSO: taskVarLib*//* * This huge ifdef means that the file gets run through the compiler but is * empty in the case where we're building the stack without VIRTUAL_STACK * support. */#ifdef VIRTUAL_STACK/* includes */#include "vxWorks.h"#include "semLib.h"#include "logLib.h"#include "sysLib.h"#include "stdio.h"#include "stdlib.h"#include "arpLib.h"#include "hostLib.h"#include "usrConfig.h"#include "taskLib.h"#include "taskVarLib.h"#include "netinet/vsLib.h"#include "netinet/vsData.h"#include "memPartLib.h"#include "errnoLib.h"/* defines *//* globals */BSD_GLOBAL_DATA* vsTbl[VSID_MAX];int myStackNum; /* Task local stack number. */SEM_ID vsTblLock;/* locals *//* forward declarations *//********************************************************************************* virtualStackLibInit - initialize the Virtual Stack system** This routine initializes all the global data required by the virtual stack* system.** RETURNS: OK or ERROR if any resources are unavailable.**/STATUS virtualStackLibInit    (    )    {    int count;    /*     * Create a semaphore to protect our table.     */    vsTblLock = semBCreate (SEM_Q_PRIORITY, SEM_FULL);    if (vsTblLock == NULL)        return (ERROR);        for (count = 0; count < VSID_MAX; count++)        {        vsTbl[count] = NULL;        }    return (OK);    }/********************************************************************************* virtualStackCreate - creates an instance of a virtual stack** This routine creates an instance of a Virtual Stack and returns a pointer* to the VSID on successful completion.  Once this routine returns the* desired initialization sequence may be called to start the appropriate* protocols and initialize the network data structures.** The <pName> argument supplies an optional name for the network stack.* If none is provided, the stack index (i.e.  0 1 2 ...) is assigned.** RETURNS: OK or ERROR. If ERROR is returned the <pVID> contents are * not valid.**/STATUS virtualStackCreate    (    char* pName, 	/* Unique stack name, or NULL for default */    VSID* pVID 		/* Buffer for storing virtual stack identifier */    )    {    int vsIndex, i;    char tempName[VS_NAME_MAX + 1];        /* Lock out access until creation is complete or error is returned. */    semTake (vsTblLock, WAIT_FOREVER);    /* Find the first empty slot. */    for (vsIndex = 0; vsIndex < VSID_MAX; vsIndex++)        {        if (vsTbl[vsIndex] == NULL)            break; /* Hey, we found one! */        }    if (vsIndex == VSID_MAX)        {        semGive (vsTblLock);        return (ERROR);        }    /*     * If no name is passed simply make the name the     * VS number.     */    if (pName == NULL)        sprintf (tempName, "%d", vsIndex);    else        strncpy (tempName, pName, min(VS_NAME_MAX, (strlen(pName) + 1)));    /* null-terminate it, just in case... */    tempName[VS_NAME_MAX] = EOS;    /* Check that a stack with the same name doesn't already exist */    for (i = 0; i < VSID_MAX; i++)        {        if (vsTbl[i] == NULL)  /* empty slot */            continue;        if (strcmp (vsTbl[i]->pName, tempName) == 0)            {            semGive (vsTblLock);            return (ERROR);            }        }    /* Allocate our global structure.  */    vsTbl[vsIndex] = (BSD_GLOBAL_DATA *) KHEAP_ALLOC ((sizeof(BSD_GLOBAL_DATA)));    *pVID = vsTbl[vsIndex];     if (vsTbl[vsIndex] == NULL)        {        semGive (vsTblLock);        return (ERROR);        }    /* Clear out the structure to NULL */    bzero ((char *)*pVID, sizeof (BSD_GLOBAL_DATA));    /* If no name is passed simply make the name the VS number. */    vsTbl[vsIndex]->pName = (char *)&vsTbl[vsIndex]->name;    bcopy (tempName, vsTbl[vsIndex]->pName, sizeof(tempName));    semGive (vsTblLock);    /*     * Set the virtual stack number task variable.     * This allows the initialization code to execute unchanged.     */    virtualStackNumTaskIdSet (vsIndex);    return (OK);    }/********************************************************************************* virtualStackInit - initialize a virtual stack** This routine initializes various data structures within the stack.* Call this function only after calling virtualStackCreate (). Once* virtualStackInit () has been executed, network protocols init functions* can then be called to finish off the virtual stack initialization* process.** RETURNS: OK, or ERROR if initialization fails.*/STATUS virtualStackInit    (    VSID vsId,	  /* Stack identifier from virtualStackCreate() routine */    int  maxUnits /* maximum number of device to be attached to IP */    )    {    int count;    int vsIndex;    if (!vsId)	{	return (ERROR);	}     /* Verify stack identifier. Exit if not found. */    if (virtualStackNumGet (vsId, &vsIndex) == ERROR)	return (ERROR);    /* Set the task variable and initialize the virtual stack. */    virtualStackNumTaskIdSet (vsIndex);     /* Allocate the ipDrvCtrl array based on the given maxUnits */    ipMaxUnits = maxUnits ? maxUnits : 1;    ipDrvCtrl = (IP_DRV_CTRL *)KHEAP_ALLOC(ipMaxUnits * sizeof(IP_DRV_CTRL));    if ( ipDrvCtrl == (IP_DRV_CTRL *) NULL )       return (ERROR);    bzero ((char *)ipDrvCtrl,ipMaxUnits * sizeof(IP_DRV_CTRL));    ipDrvCount = 0;    ipDrvIndex = 0;    /*     * Network buffer initialization: Reset pointers to NULL before     * calling mbinit() routine to force each stack to create separate     * memory pools.     */    mClBlkConfig.memArea = NULL;    for (count = 0; count < clDescTblNumEnt; count++)        clDescTbl[count].memArea = NULL;    sysMclBlkConfig.memArea = NULL;    for (count = 0; count < sysClDescTblNumEnt; count++)        sysClDescTbl[count].memArea = NULL;    pM2IfRoot    = NULL;    pM2IfRootPtr = &pM2IfRoot;    /* Make sure that the list is empty on the first call. */    _ifnet = NULL;                                           /*     * This code performs the same function as the static initialization     * in the (no longer compiled) in_proto.c module. Since we don't get     * auto-initialization from the compiler we have to do the work here.     */        inetdomain.dom_family = AF_INET;    inetdomain.dom_name = KHEAP_ALLOC (strlen("internet") + 1);    strcpy (inetdomain.dom_name, "internet");    inetdomain.dom_init = 0;    inetdomain.dom_externalize = 0;    inetdomain.dom_dispose = 0;    inetdomain.dom_protosw = inetsw;    inetdomain.dom_protoswNPROTOSW =        &inetsw[sizeof(inetsw)/sizeof(inetsw[0])];    inetdomain.dom_next = NULL;    inetdomain.dom_rtattach = rn_inithead;    inetdomain.dom_rtoffset = 27;    inetdomain.dom_maxrtkey = sizeof(struct sockaddr_in);    /* Set up for the protocol initialization. */    bzero ((caddr_t)&inetsw, sizeof(inetsw));    _protoSwIndex = 0;    sb_max = SB_MAX;    /* Set up for domain calls. */    domains = NULL;    raw_sendspace = RAWSNDQ;    raw_recvspace = RAWRCVQ;    route_proto.sp_family = PF_ROUTE;    return (OK);    }/********************************************************************************* virtualStackDelete - delete a virtual TCP/IP stack** This routine deletes the virtual stack referenced by the VSID passed to it.** RETURNS: OK or ERROR if the VSID passed to the call was in some way invalid**/STATUS virtualStackDelete    (    VSID vsid 				/* VID returned by virtualStackCreate */    )    {    int vsIndex;        semTake (vsTblLock, WAIT_FOREVER);        for (vsIndex = 0; vsIndex < VSID_MAX; vsIndex++)        if (vsTbl[vsIndex] == vsid)            break; /* Hey, we found it! */    /* Check that we did find it. */    if (vsIndex == VSID_MAX)        {        semGive (vsTblLock);        return (ERROR);        }    /* Free the structure. */    KHEAP_FREE (vsTbl[vsIndex]);    /* Let's be extra paranoid. */    vsTbl[vsIndex] = NULL;        semGive (vsTblLock);    return (OK);    }/********************************************************************************* virtualStackIdGet - return the VSID named in pName** This routine returns a VSID in the pointer passed to it in pVSID if a stack* with pName is found in the Virtual Stack Table.** RETURNS: OK or ERROR if the stack named in pName was not found**/STATUS virtualStackIdGet    (    char* pName, 			/* Name that was used in virtualStackCreate */    VSID* pVSID    )    {    int vsIndex;    semTake (vsTblLock, WAIT_FOREVER);        for (vsIndex = 0; vsIndex < VSID_MAX; vsIndex++)        if (!strncmp (vsTbl[vsIndex]->pName, pName, 		      min (strlen (pName), VS_NAME_MAX)))            break; /* Hey, we found it! */    /* Check that we did find it. */    if (vsIndex == VSID_MAX)        {        semGive(vsTblLock);        return (ERROR);        }    *pVSID = vsTbl[vsIndex];    semGive (vsTblLock);    return (OK);    }/********************************************************************************* virtualStackNameGet - return the name given the stack id** This routine returns the stack name in the pointer passed to it in pVSName * if a stack with vsid is found in the Virtual Stack Table. This routine* assumes that the caller has allocated the buffer area for the name.** RETURNS: OK or ERROR if the stack id was not found**/STATUS virtualStackNameGet    (    char *    pName,        /* Buffer for the stack name */    int       vsid

⌨️ 快捷键说明

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