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

📄 snmpdlib.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* snmpdLib.c  - entry points to the SNMP v1/v2c agent *//* *  Copyright 1984-2005 Wind River Systems, Inc. *  All rights reserved.  Provided under license only. *  Distribution or other use of this software is only *  permitted pursuant to the terms of a license agreement *  from Wind River Systems (and is otherwise prohibited). *  Refer to that license agreement for terms of use. */#include <copyright_wrs.h>/* modification history -------------------------01c,19apr05,job  update copyright notices01b,19may04,job  code cleanup01a,08mar04,job  basic IO and core code*//* includes */#include <wrn/wm/snmp/engine/auxfuncs.h>#include <wrn/wm/snmp/vxagent/snmpdInit.h>#include <wrn/wm/snmp/vxagent/snmpdLib.h>#include <taskLib.h>#include <timers.h>#include <msgQLib.h>#include <wrn/wm/snmp/engine/etimer.h>#include <wrn/wm/snmp/engine/vxcmpnts.h>#include <wrn/wm/snmp/vxagent/snmpIoLib.h>#include <wrn/wm/snmp/engine/snmpstat.h>#include <tickLib.h>#include <wrn/wm/snmp/vxagent/mibleaf.h>#include <wrn/wm/snmp/engine/view.h>#include <stdlib.h>#include <ctype.h>#include <stdio.h>#include <semLib.h>#include <wrn/wm/snmp/engine/buildpkt.h>#include <wrn/wm/snmp/engine/objectid.h>SEM_ID snmpdInitFinishedSem;BOOL snmpInitDone = 0;           /* has init completed? */extern SEM_ID snmpdConfigMutex;extern unsigned int snmpdInstalledComponentsValue;STATUS axSubagentIoInit (void);void snmpAxSubagentSpawn (void);/* defines */#define SNMPD_PRIO_DEFAULT      150#define SNMPD_STACK_DEFAULT     0x7000#define SNMPD_OPT_DEFAULT       0/* locals  */LOCAL MIB_MODULE *       pSnmpModules;               /* Mibs for this agent */LOCAL int                snmpdTaskId;                /* snmp agent task id */LOCAL int                snmpdTmrTaskId;             /* snmp timer task id */#if 0LOCAL ulong_t            snmpStartCentiSecs;         /*  start time */#endifLOCAL timer_t       snmpTimer;LOCAL VOIDFUNCPTR   snmpHkPrivRlseRtn;     /* user hook private release rtn */LOCAL FUNCPTR       snmpHkSetPduVldtRtn;   /* user hook set pdu validate rtn */LOCAL FUNCPTR       snmpHkPreSetRtn;       /* user hook pre set rtn */LOCAL FUNCPTR       snmpHkPostSetRtn;      /* user hook post set rtn */LOCAL FUNCPTR       snmpHkSetFailedRtn;    /* user hook set failed rtn */LOCAL void     snmpReady (int);#if (INSTALL_ENVOY_VXWORKS_TAE || INSTALL_COMMON_DYNAMIC_COMP_CONFIG)#if INSTALL_COMMON_DYNAMIC_COMP_CONFIG/* Forward declaration of initialization routine */STATUS usrSnmpInit (void);void initStartSnmpd (void){    int task_mode;#if INSTALL_ENVOY_VXWORKS_TAE    task_mode = VX_USER_MODE;#else    task_mode = 0x0000;#endif     snmpdInitFinishedSem = semBCreate(SEM_Q_PRIORITY, SEM_FULL);     snmpInitDone = 0;     semTake (snmpdConfigMutex,WAIT_FOREVER);     snmpdLog (SNMP_INFO, " initialize AgentX listener\n");     taskSpawn ("tStartSnmpd", ENVOY_VXWORKS_SNMPD_PRIORITY, task_mode,                 8182, (FUNCPTR) usrSnmpInit,                0,0,0,0,0,0,0,0,0,0);     semGive (snmpdConfigMutex);     snmpReady (WAIT_FOREVER);}#endif /* #if INSTALL_COMMON_DYNAMIC_COMP_CONFIG */#endif /* #if (INSTALL_ENVOY_VXWORKS_TAE) */struct Timer_Block timerBlock;MSG_Q_ID           tmrQID;#define TIMER_PRI 200#define TIMER_STK 4096/* globals */int                    snmpTraceLevel;         /* Trace level for agent logs *//* Functions to link in. Just need to refer to these funcs somewhere. * Should be local but that causes compiler to crib unused variable.  */FUNCPTR            snmpFuncsToLink [] =      {    SNMP_Bind_Null,    (FUNCPTR) SNMP_Bind_64_Unsigned_Integer,    (FUNCPTR) SNMP_Bind_String,    SNMP_Bind_Object_ID,    SNMP_Bind_IP_Address,    SNMP_Bind_Integer,    (FUNCPTR) SNMP_Bind_Unsigned_Integer    };/* forward declarations */LOCAL void     snmpdCleanup (void);/************************************************************************  * snmpReady: Called to ensure that SNMP has completed executing.       * *            Blocks until SNMP enters main IO loop.                    * * RETURNS: nothing                                                     *  ************************************************************************/LOCAL void snmpReady (int timeout)    {    if (snmpInitDone != 0)        {        return;        }    semTake (snmpdInitFinishedSem, timeout);    /*     * As soon as we take it, we release it to let everyone else through.     */    semGive (snmpdInitFinishedSem);    }/************************************************************************  * snmpTimer: function called by a POSIX timer.  All it can safely      * *            do is send a message to a preestablished message queue.   * * RETURNS: nothing                                                     *  ************************************************************************/static void snmpTimeout    (    timer_t TimerID,    int     arg    )    {    bits8_t end_timeout[] = "4";    msgQSend(tmrQID, (char *) end_timeout, 1, NO_WAIT, MSG_PRI_NORMAL);    }/************************************************************************  * timerTask:   a looping task that handles timer issues in a non-ISR   *  *              context.                                                *  * RETURNS: nothing                                                     *  ************************************************************************/static void timerTask(void)    {    bits8_t start_timeout[] = "3";    bits8_t end_timeout[] = "4";    bits8_t buf[5];    unsigned long when = 0;    void (*fn_ptr)(void) = 0;    struct itimerspec timeLen;    MEMSET(&timeLen, 0, sizeof(struct itimerspec));    /* create the timer */    timer_create(CLOCK_REALTIME, NULL, &snmpTimer);    /* hook up the handler function */    timer_connect(snmpTimer, (VOIDFUNCPTR) snmpTimeout, NULL);    while (1)        {        MEMSET(buf, 0, 5);        if ((msgQReceive(tmrQID, (char *) buf, 2, WAIT_FOREVER)) == ERROR)            {            continue;            }          if (STRCMP((char *) buf, (char *) start_timeout) == 0)            {            /* Now, wake up after the reqd time and invoke callback */            ENVOY_SNMP_GET_WRITE_LOCK(SNMP_TimerLock);            when = timerBlock.when ;            fn_ptr = timerBlock.what;            ENVOY_SNMP_RELEASE_WRITE_LOCK(SNMP_TimerLock);            timeLen.it_value.tv_sec = (when / 1000);            timeLen.it_value.tv_nsec = ((when % 1000) * 1000);                        timer_settime(snmpTimer, TIMER_RELTIME, &timeLen, 0);                        continue;            }        else if (STRCMP((char *) buf, (char *) end_timeout) == 0)            (*fn_ptr)();        }    }#if (INSTALL_ENVOY_VXWORKS_TAE || INSTALL_COMMON_DYNAMIC_COMP_CONFIG)/********************************************************************************* usrSnmpInit - entry point to start up the SNMP daemon.  Also provides*               pointers to the Mib init and cleanup routines.** RETURNS: OK (always)*/STATUS usrSnmpInit (void)    {    snmpdInit (0, 0, 0, 0);    return (OK);    }#endif /* #if (INSTALL_ENVOY_VXWORKS_TAE) */ /******************************************************************************** snmpdInit - initialize the SNMP agent** This routine initializes the SNMP agent.  The <prio> parameter specifies* the priority of the SNMP agent task; if 0, the default value of 150 is* used.  <stackSize> specifies the stack size of the task; if 0, the default* value of 0x7000 is used.** The <pModules> parameter points to an array of MIB module routines.* These routines are used for the initialization and cleanup of MIB* modules supported by the agent.  The MIB_MODULE structure has two* elements, <mibInitialize> and <mibTerminate>.  The routines pointed* to by <pModules>-><mibInitialize> are called on agent startup.  The* routines pointed to by <pModules>-><mibTerminate> are called when the* agent is deleted.  The last element in the array must have an entry* where both <pModules>-><mibInitialize> and <pModules>-><mibTerminate>* have the value of 0.** The <traceLevel> parameter specifies the level of messages logged* by the agent.** RETURNS: OK on successful initialization, otherwise ERROR.** NOMANUAL**/STATUS snmpdInit    (    MIB_MODULE *           pModules,            /* MIB modules */    int                    traceLevel,          /* trace level */    int                    prio,                /* agent task priority */    int                    stackSize           /* agent task stack size */    )    {    int snmpdTaskOptions = SNMPD_OPT_DEFAULT;    /*     * vsNum is used to pass the stack number that a spawned task, see      * below, should use. This is only relevant if we are using      * multi-instance and therefore if we are not, stackNum gets initialised     * to zero.     */    if (prio == 0)        prio = SNMPD_PRIO_DEFAULT;    if (stackSize == 0)        stackSize = SNMPD_STACK_DEFAULT;        pSnmpModules = pModules;    envoy_init();    /* Start the timer bits.  */    /* Timer Message Queue */        tmrQID = msgQCreate(3, 2, MSG_Q_PRIORITY);     /* Timer Task */    /*     * If using virtual stacks, pass the current stack number to the new     * tasks to allow them to work in any stack context, not just stack 0     */    snmpdTmrTaskId = taskSpawn ("tSubSnmpTmr", TIMER_PRI, 0, TIMER_STK,                                (FUNCPTR) timerTask, 0,                                0, 0, 0, 0, 0, 0, 0, 0, 0);    if (snmpdTmrTaskId == ERROR)        {        snmpdCleanup ();        return (ERROR);        }    snmpdLog (SNMP_INFO, "Initializing AgentX subagent\n");    if (axSubagentIoInit () == ERROR)        snmpdLog (SNMP_WARN, "Error: could not initialize AgentX subagent\n");    snmpAxSubagentSpawn();        return (OK);    }/********************************************************************************* snmpdShutdown  -  clean up SNMP and delete associated tasks** On deletion of the snmp agent task we close the transport endpoint, remove* resources allocated to the view table and terminate the mibs.** NOTE:  This is not a complete function at this point.  It will work* for v1/v2c agents only -- it will perform the same functions for v3 and* AgentX-enabled agents, but it won't clean up v3 tables or AgentX tasks.** RETURNS: N/A** NOMANUAL*/void snmpdShutdown (void)    {    snmpdCleanup ();    timer_delete(snmpTimer);    msgQDelete (tmrQID);    taskDelete (snmpdTmrTaskId);    taskDelete (snmpdTaskId);    semDelete (snmpdInitFinishedSem);    snmpInitDone = 0;    ENVOY_SNMP_FREE_LOCK_TAG (SNMP_CoarseLock, SNMP_COARSELOCK_TAG);    ENVOY_SNMP_FREE_LOCK_TAG (SNMP_infrastructure_lock,                              SNMP_INFRASTRUCTURELOCK_TAG);    ENVOY_SNMP_FREE_LOCK_TAG (SNMP_TimerLock, SNMP_TIMERLOCK_TAG);    }/********************************************************************************* snmpdCleanup - Cleanup routine* * Function to called by if agent fails to allocate some resource  during startup.* * RETURNS: N/A** NOMANUAL*/LOCAL void snmpdCleanup (void)    {    if (SNMP_CoarseLock != NULL)        {        semDelete (SNMP_CoarseLock);        }    SNMP_CoarseLock = NULL;    }/******************************************************************************** * snmpdLog - log messages from the SNMP agent ** This routine logs messages generated by the SNMP agent.  Messages are* sent to the standard console.  If <level> is less than or equal to* SNMP_TRACE_LEVEL (defined in the configuration header file), the* message is printed, otherwise* it is ignored. The value of <level> must be one of 1, 2, or 3.** RETURNS: N/A**/void snmpdLog    (    int       level,  /* level of this message */    char *    pString  /* message string */    )    {    if (snmpTraceLevel >= level)        {        printf ("tSnmpd: %s",  pString);        }    }/********************************************************************************* snmpdTreeAdd - dynamically add a subtree to the SNMP agent MIB tree** This routine adds the specified MIB subtree, located in memory at* the address <pTreeAddr>, to the agent's MIB data tree at the node* with the object identifier specified by <pTreeOidStr>. This subtree* is normally generated with the `-start' option to `mibcomp'.** RETURNS: OK on success, otherwise ERROR.** SEE ALSO:* .I WindNet SNMPv1v2c VxWorks Component Release Supplement*/

⌨️ 快捷键说明

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