📄 snmpdlib.c
字号:
{ EBUFFER_T ebuff; EBufferInitialize (&ebuff); #if INSTALL_SNMP_VXWORKS_VIRTUAL_STACK /* * Set myStackNum to the stack instance we received the packet on, * else we can't write on the socket. Our stack instance may have changed * so the method routines can execute in the correct stack instance. */ SNMP_SET_VIRTUAL_STACK (snmpdStackNum);#endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */ if (SNMP_Process_Finish ((SNMP_PKT_T *) pktp, &ebuff, need) == 0) { snmpIoWrite (cookie, (char*) ebuff.start_bp, need, pRemoteAddr, pLocalAddr); EBufferClean (&ebuff); } } /********************************************************************************* 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) { snmpIoClose (); snmpdViewTblRemove ();#if INSTALL_COMMON_DYNAMIC_COMP_CONFIG#if INSTALL_ENVOY_SNMP_VERSION_3 DYNCFG_IFCFGVBL_BEGIN(snmpv3_component) DYNCFG_FUNCALL(snmpCleanUserTable)(); DYNCFG_FUNCALL(snmpCleanSecurityToGroupTable)(); DYNCFG_FUNCALL(snmpCleanAccessTable)(); DYNCFG_FUNCALL(snmpCleanContextTable)(); DYNCFG_FUNCALL(snmpCleanV3Tree)(); #if INSTALL_ENVOY_SNMP_V3_TARGET DYNCFG_IFCFGVBL_BEGIN(envoy_snmp_target) DYNCFG_FUNCALL(snmpCleanTargetTables)();#if INSTALL_ENVOY_SNMP_V3_NOTIFY DYNCFG_IFCFGVBL_BEGIN(envoy_snmp_notify) DYNCFG_FUNCALL(snmpCleanNotifyTables)(); DYNCFG_IFCFGVBL_END(envoy_snmp_notify)#endif /* INSTALL_ENVOY_SNMP_V3_NOTIFY */#if INSTALL_ENVOY_SNMP_COEXISTENCE DYNCFG_IFCFGVBL_BEGIN(envoy_snmp_coexistence) DYNCFG_FUNCALL(snmpCleanCommunityTable)(); DYNCFG_IFCFGVBL_END(envoy_snmp_coexistence)#endif /* INSTALL_ENVOY_SNMP_COEXISTENCE */#if INSTALL_ENVOY_SNMP_V3_PROXY DYNCFG_IFCFGVBL_BEGIN(envoy_snmp_proxy) DYNCFG_FUNCALL(snmpCleanProxyTable)(); DYNCFG_IFCFGVBL_END(envoy_snmp_proxy) #endif /* INSTALL_ENVOY_SNMP_V3_PROXY */ DYNCFG_IFCFGVBL_END(envoy_snmp_target)#endif /* INSTALL_ENVOY_SNMP_V3_TARGET */ DYNCFG_IFCFGVBL_END(snmpv3_component)#endif /* INSTALL_ENVOY_SNMP_VERSION_3 */#if INSTALL_ENVOY_AGENTX#if INSTALL_ENVOY_AGENTX_MASTER DYNCFG_IFCFGVBL_BEGIN(agentx_master_component) DYNCFG_FUNCALL(snmpCleanAgentXMaster)(); DYNCFG_IFCFGVBL_END(agentx_master_component)#endif /* INSTALL_ENVOY_AGENTX_MASTER */#if INSTALL_ENVOY_AGENTX_SUB DYNCFG_IFCFGVBL_BEGIN(agentx_subagent_component) DYNCFG_FUNCALL(snmpCleanAgentXSubagent)(); DYNCFG_IFCFGVBL_END(agentx_subagent_component)#endif /* INSTALL_ENVOY_AGENTX_SUB */#endif /* INSTALL_ENVOY_AGENTX */#endif /* INSTALL_COMMON_DYNAMIC_COMP_CONFIG */ snmpdCleanup (); wdDelete (tmrWDID); 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); }/********************************************************************************* snmpdTaskDelete - delete hook for snmp task** On deletion of the snmp agent task we close the transport endpoint, remove* resources allocated to the view table and terminate the mibs.** RETURNS: N/A** NOMANUAL*/#if INSTALL_ENVOY_VXWORKS_TAE LOCAL void snmpdTaskDelete#else LOCAL int snmpdTaskDelete#endif ( WIND_TCB * tcb /* Task Control block */ ) { if (tcb->entry == snmpdMain) { snmpIoClose (); snmpdViewTblRemove (); snmpdCleanup (); }#if INSTALL_ENVOY_VXWORKS_TAE return;#else return (OK);#endif }/********************************************************************************* snmpdCleanup - Cleanup routine* * Function to called by if agent fails to allocate some resource during startup.* * RETURNS: N/A** NOMANUAL*/LOCAL void snmpdCleanup (void) { MIB_MODULE * pTmp; if (mibsInitialized) { for (pTmp = pSnmpModules; !((pTmp->mibInitialize == NULL) && (pTmp->mibTerminate == NULL)) ; pTmp++) { if (pTmp->mibTerminate != NULL) { (* pTmp->mibTerminate) (); } } mibsInitialized = FALSE; }#if INSTALL_ENVOY_VXWORKS_TAE (void) taskDeleteHookDelete ((VOIDFUNCPTR) snmpdTaskDelete);#else (void) taskDeleteHookDelete ((FUNCPTR) snmpdTaskDelete);#endif }/********************************************************************************* snmpGlobalsInit - initialize the snmp agent globals on startup.** RETURNS: N/A** NOMANUAL*/LOCAL STATUS snmpGlobalsInit (void) { /* Zero out snmp stats and disable auth traps */ memset (&snmp_stats, 0, sizeof (SNMP_STATS_T)); snmp_stats.snmpEnableAuthTraps = VAL_snmpEnableAuthenTraps_disabled; /* set starting uptime to 0 */ snmpStartCentiSecs = 0; /* Call envoy_init() to declare the locks */ envoy_init (); if (SNMP_CoarseLock == NULL) { snmpdLog (SNMP_ERROR, "Unable to create semaphores\n"); snmpdCleanup (); return (ERROR); } return (OK); }/******************************************************************************** * 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); } }#if INSTALL_ENVOY_SNMP_RFC2275_VIEWS/******************************************************************************** * snmpdView2275EntrySet - install an entry in the view table (2275 version)** This function creates an entry in the view table. The view subtree* is specified by <pTreeOid> and <treeOidLen>.** The installed entry has a name of <pName> and nameLen. The specified* view is included in or excluded from the view table depending on the * value of <viewType> (VIEW_INCLUDED or VIEW_EXCLUDED, respectively). The* entry mask is specified by <pmask>; <maskLen> must be the mask* length in bytes.** RETURNS: OK on success, otherwise ERROR** ERRNO: S_snmpdLib_VIEW_CREATE_FAILURE, S_snmpdLib_VIEW_INSTALL_FAILURE,* S_snmpdLib_VIEW_MASK_FAILURE*/STATUS snmpdView2275EntrySet ( OIDC_T * pTreeOid, /* sub tree for view */ int treeOidLen, /* length of subtree oid */ uchar_t * pName, /* name of entry */ ALENGTH_T nameLen, /* length of name */ uchar_t * pMask, /* mask for entry */ int maskLen, /* mask length in bytes */ int viewType /* type of view (INCLUDED/EXCLUDED) */ ) { VIEWLEAF_T * pLeaf; /* leaf of view tree */ STATUS status; /* error status */ semTake (SNMP_CoarseLock, WAIT_FOREVER); if ((pLeaf = SNMP_View_Create (pTreeOid, treeOidLen)) == NULL ) { snmpdLog (SNMP_WARN, "View create failed\n"); errno = S_snmpdLib_VIEW_CREATE_FAILURE; status = ERROR; goto lockRelease; } if (SNMP_View_2275_Install (pLeaf, pName, nameLen)) { SNMP_View_Delete(pLeaf); (void) snmpdLog (SNMP_WARN, "View install failed\n"); errno = S_snmpdLib_VIEW_INSTALL_FAILURE; status = ERROR; goto lockRelease; } /* We assume volatile storage (STO_VOL) and table entry is active * from start */ SNMP_View_Set_StorageType (pLeaf, STO_VOL); SNMP_View_Set_Status (pLeaf, RS_ACTIVE) ; SNMP_View_Set_Type (pLeaf, viewType) ; if (SNMP_View_Set_Mask (pLeaf, (OCTET_T *) pMask, maskLen)) { SNMP_View_Delete(pLeaf); (void) snmpdLog (SNMP_WARN, "View set mask failed\n") ; errno = S_snmpdLib_VIEW_MASK_FAILURE; status = ERROR; goto lockRelease; } status = OK; /* fall thru to lockRelease */ lockRelease: semGive (SNMP_CoarseLock); return (status); } /********************************************************************************* snmpdViewTblRemove - remove view table and free allocated resources ** This routine removes all the entries in the view table and frees all* allocated resources. It is used at agent-shutdown time.** RETURNS: N/A** NOMANUAL*/LOCAL void snmpdViewTblRemove (void) { VIEWLEAF_T * pLeaf; /* ptr to leaf of view tree */ ENVOY_SNMP_GET_WRITE_LOCK(SNMP_CoarseLock); while ( (pLeaf = SNMP_View_Next (NULL)) != NULL) { SNMP_View_2275_Deinstall (pLeaf); SNMP_View_Delete (pLeaf); } ENVOY_SNMP_RELEASE_WRITE_LOCK(SNMP_CoarseLock); }/********************************************************************************* snmpdView2275EntryRemove - remove an entry from the view table (2275 version)** This routine removes an entry from the view table and deallocates* the associated resources. The entry should have been previously* created with snmpdView2275EntrySet().** RETURNS: N/A** ERRNO: S_snmpdLib_VIEW_LOOKUP_FAILURE, S_snmpdLib_VIEW_DEINSTALL_FAILURE** SEE ALSO: snmpdView2275EntrySet()*/void snmpdView2275EntryRemove ( OIDC_T * pTreeOid, /* oid of view subtree to remove */ int treeOidLen, /* length of view subtree oid */ uchar_t * pName, /* name of entry */ ALENGTH_T nameLen /* length of name */ ) { VIEWLEAF_T * pLeaf; /* ptr to leaf of view tree */ semTake (SNMP_CoarseLock, WAIT_FOREVER); if ((pLeaf = SNMP_View_2275_Lookup (pName, nameLen, pTreeOid, treeOidLen)) == NULL) { snmpdLog (SNMP_WARN, "Unable to lookup view entry\n"); errno = S_snmpdLib_VIEW_LOOKUP_FAILURE; goto lockRelease; } SNMP_View_2275_Deinstall (pLeaf); SNMP_View_Delete (pLeaf); /* fall through to lockRelease */lockRelease: semGive (SNMP_CoarseLock); }#else /* not using 2275 so we must be using 1445 *//******************************************************************************** * snmpdViewEntrySet - install an entry in the view table** This function creates an entry in the view table. The view subtree* is specified by <pTreeOid> and <treeOidLen>.** The installed entry has an index of <index>. The specified view is* included in or excluded from the view table depending on the value* of <viewType> (VIEW_INCLUDED or VIEW_EXCLUDED, respectively). The* entry mask is specified by <pmask>; <maskLen> must be the mask* length in bytes.** RETURNS: OK on success, otherwise ERROR** ERRNO: S_snmpdLib_VIEW_CREATE_FAILURE, S_snmpdLib_VIEW_INSTALL_FAILURE,* S_snmpdLib_VIEW_MASK_FAILURE*/STATUS snmpdViewEntrySet ( OIDC_T * pTreeOid, /* sub tree for view */ int treeOidLen, /* length of subtree oid */ UINT_16_T index, /* index of entry */ uchar_t * pMask, /* mask for entry */ int maskLen, /* mask length in bytes */ int viewType /* type of view (INCLUDED/EXCLUDED) */ ) { VIEWLEAF_T * pLeaf; /* leaf of view tree */ STATUS status; /* error status */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -