📄 snmpdlib.c
字号:
static void timerTask(void)#endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */{bits8_t start_timeout[] = "3";bits8_t end_timeout[] = "4";bits8_t buf[5];unsigned long when_in_ticks = 0;void (*fn_ptr)(void) = 0;#if INSTALL_SNMP_VXWORKS_VIRTUAL_STACK/* * This call will create a new task variable for the timer task allowing it * to execute in the stack context is was spawned in. */if (SNMP_SET_VIRTUAL_STACK (vsNum) == ERROR) { snmpdLog(SNMP_WARN, "Unable to set myStackNum task variable for timer task.\n"); }#endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */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_in_ticks = timerBlock.when ; fn_ptr = timerBlock.what; ENVOY_SNMP_RELEASE_WRITE_LOCK(SNMP_TimerLock); wdStart(tmrWDID, when_in_ticks, (FUNCPTR) snmpTimer, 0); continue; } else if (STRCMP((char *) buf, (char *) end_timeout) == 0) (*fn_ptr)(); }}#if (INSTALL_ENVOY_VXWORKS_TAE || INSTALL_COMMON_DYNAMIC_COMP_CONFIG)/********************************************************************************* usrMib2Init - initialize the MIB-II library** This routine initializes the MIB-II library interface.** RETURNS: OK (always)*/ STATUS usrMib2Init (void) { static M2_OBJECTID sysObjectId = { MIB2_SYS_OBJID_LEN, MIB2_SYS_OBJID }; m2Init (MIB2_SYS_DESCR, MIB2_SYS_CONTACT, MIB2_SYS_LOCATION, &sysObjectId, (FUNCPTR) generateTrap, 0, 0); return (OK); } /********************************************************************************* usrMib2CleanUp - clean up MIB-II state** RETURNS: OK (always)*/ STATUS usrMib2CleanUp (void) { m2Delete (); return (OK); }#if INSTALL_COMMON_DYNAMIC_COMP_CONFIG/**************************************************************************** * * snmpDyncfgInit - initialize any dynamic component configuration variables * and function pointers based on which snmpd components * have been installed. * RETURNS: void */void snmpdDyncfgInit (void){ semTake (snmpdConfigMutex, WAIT_FOREVER); if (snmpdInstalledComponentsValue & SNMPD_VERSION_3_COMPONENT) { #if INSTALL_ENVOY_SNMP_COEXISTENCE DYNCFG_FUNCPTR_SET(SNMP_community_coexistence_lookup, DYNCFG_FUNCPTR(lookup_SNMP_community));#else DYNCFG_FUNCPTR_SET(SNMP_community_coexistence_lookup, snmpIoCommunityValidate);#endif DYNCFG_FUNCALL(v3_add_v3_mibs) (); } else { DYNCFG_FUNCPTR_SET(SNMP_community_coexistence_lookup, snmpIoCommunityValidate); } if (snmpdInstalledComponentsValue & SNMPD_AGENTX_MASTER_COMPONENT) { DYNCFG_FUNCALL(ax_add_ax_mibs) (); } semGive (snmpdConfigMutex);}#endif /* 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){#if INSTALL_COMMON_DYNAMIC_COMP_CONFIG snmpdDyncfgInit ();#endif snmpdInit (snmpMibModules, 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; int vsNum; /* * 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 INSTALL_SNMP_VXWORKS_VIRTUAL_STACK vsNum = myStackNum;#else /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */ vsNum = 0;#endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */ prio = (prio == 0) ? SNMPD_PRIO_DEFAULT : prio; stackSize = (stackSize == 0) ? SNMPD_STACK_DEFAULT : stackSize; pSnmpModules = pModules; /* Start the timer bits. */ /* Watchdog Timer */ tmrWDID = wdCreate(); /* 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 ("tSnmpTmr", TIMER_PRI, 0, TIMER_STK, (FUNCPTR) timerTask, vsNum, 0, 0, 0, 0, 0, 0, 0, 0, 0); if (snmpdTmrTaskId == ERROR) { snmpdCleanup (); return (ERROR); } snmpdTaskId = taskSpawn ("tSnmpd", prio, snmpdTaskOptions, stackSize, (FUNCPTR) snmpdMain, traceLevel, vsNum, 0, 0, 0, 0, 0, 0, 0, 0); if (snmpdTaskId == ERROR) { snmpdCleanup (); return (ERROR); } return (OK); }/******************************************************************************** snmpdMain - entry point for the snmp agent task** RETURNS: ERROR on error else never returns. ** NOMANUAL*/#if INSTALL_SNMP_VXWORKS_VIRTUAL_STACKLOCAL STATUS snmpdMain ( int traceLevel, /* extent of debug msgs to log */ int vsNum )#else /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */LOCAL STATUS snmpdMain ( int traceLevel /* extent of debug msgs to log */ )#endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */ { snmpTraceLevel = traceLevel;#if INSTALL_SNMP_VXWORKS_VIRTUAL_STACK /* * This call will create a new task variable for the main task allowing it * to execute in the stack context is was spawned in. */ if (SNMP_SET_VIRTUAL_STACK (vsNum) == ERROR) { snmpdLog(SNMP_ERROR, "Unable to set myStackNum task variable in snmpdMain.\n"); return (ERROR); } /* store the VS number in which snmpd is running, this is used to restore * the stack context after the method routines are executed. */ snmpdStackNum = vsNum; #endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */#if INSTALL_ENVOY_VXWORKS_TAE (void) taskDeleteHookAdd ((VOIDFUNCPTR) snmpdTaskDelete);#else (void) taskDeleteHookAdd ((FUNCPTR) snmpdTaskDelete);#endif if (snmpGlobalsInit () == ERROR) { return (ERROR); } /* start the uptime clock */ snmpCentiSecsGet (); /* call user provided entry point */ snmpIoMain (); return (ERROR); }/******************************************************************************** * snmpMibsInit - Initialize the mibs** Function to initialize the mibs at startup. Called after the transport is * initialized. Cannot be called prior to that since a trap may be ganerated * if the interfaces group is included.*** RETURNS: N/A** NOMANUAL*/LOCAL void snmpMibsInit (void) { MIB_MODULE * pTmp; if ( pSnmpModules != NULL ) { for (pTmp = pSnmpModules; !((pTmp->mibInitialize == NULL) && (pTmp->mibTerminate == NULL)) ; pTmp++) { if (pTmp->mibInitialize != NULL) { if ((* pTmp->mibInitialize) () == ERROR) { snmpdLog (SNMP_WARN, "Unable to initialize m2 libraries\n"); } } } mibsInitialized = TRUE; } }/********************************************************************************* snmpdPktProcess - process a packet returned by the transport** This routine is invoked by the user-I/O layer to process a received* packet. The buffer <pBuf> (provided by the agent designer) must* contain a packet of size <pktSize>. The source address of the* sending machine is indicated by <pRemoteAddr>, and the address of the* receiver by <pLocalAddr>. These three parameters, <pRemoteAddr>,* <pLocalAddr>, and <pSnmpEndpoint>, are passed down to user-provided* transport routines.** RETURNS: N/A**/void snmpdPktProcess ( int pktSize, /* packe length */ char * pBuf, /* packet buffer */ void * pRemoteAddr, /* remote transport address */ void * pLocalAddr, /* local transport address */ void * pSnmpEndpoint /* snmp transport end point */ ) { Process_Rcvd_SNMP_Packet_Async (pktSize, (uchar_t *) pBuf, pRemoteAddr, pLocalAddr, SNMP_MAX_PACKET_SIZE, snmpAgentOutputRtn, snmpAgentErrorRtn, pSnmpEndpoint); }/********************************************************************************* snmpAgentErrorRtn - process received-packet error** If a response cannot be generated for some received packet,* this routine is invoked when the error is detected.* It is meant for freeing resources, we don't have any, to free* * RETURNS: N/A* * NOMANUAL*/LOCAL void snmpAgentErrorRtn ( SNMPADDR_T * pRemoteAddr, /* remote transport address */ SNMPADDR_T * pLocalAddr, /* local transport address */ int err, /* error code */ PTR_T cookie /* For user specific data */ ) {#if INSTALL_SNMP_VXWORKS_VIRTUAL_STACK /* Restore myStackNum to the value it was before we received a packet. */ SNMP_SET_VIRTUAL_STACK (snmpdStackNum);#endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */ snmpdLog (SNMP_INFO, "Error detected in input packet\n"); return; }/********************************************************************************* snmpAgentOutputRtn - Output routine for received pkt manager.** This is invoked by the received pkt manager when a response is to be sent.* The internal representation of the pkt is converted to ASN.1 form and* transmitted.* * RETURNS: N/A** NOMANUAL*/LOCAL void snmpAgentOutputRtn ( SNMPADDR_T * pRemoteAddr, /* remote transport address */ SNMPADDR_T * pLocalAddr, /* local transport address */ PTR_T pktp, /* internal representation of snmp packet */ ALENGTH_T need, /* buffer size for needed for encoding response */ PTR_T cookie /* For user specific date */ )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -