📄 vsutillib.c
字号:
int vsnum ) { char buf[MAXSIZE_entLogicalCommunity]; int buf_len; sprintf (buf, "%s%d", vsNamingScopePrefix, vsnum); buf_len = strlen (buf); contextNameRegister ((bits8_t *) buf, buf_len, VIEW_TYPE_GET, (bits8_t *) "two", 3, vsnum); }#endif /* INSTALL_ENVOY_SNMP_VERSION_3 */ /****************************************************************************** * * vsSnmpUtilVSAdd - vsSnmpUtil instInit function * * This routine adds new community string (resp. context name) to the list of * acceptable community strings (resp. context names). * * If INSTALL_SNMP_VXWORKS_VS_ENTITY is defined it also * adds a new entry into the Entity MIB Logical Table. Each Virtual * Stack has its own entry in this table. The routine also adds entry into the * vsToEntLogical Table to add mapping between vsnum and entLogicalIndex. * * RETURNS: OK or ERROR * */ static STATUS vsSnmpUtilVSAdd (int vsNum) {#if INSTALL_SNMP_VXWORKS_VS_ENTITY char buf[MAXSIZE_entLogicalCommunity]; int buf_len; ENT_LOGICAL_T * pEntLogical; int ent_index; int defaultIndex; int result; OIDC_T mib2domain[] = { SNMP_MIB2 }; /* mib-2 oid */ OIDC_T snmpUDPDomain[] = { SNMP_UDPDOMAIN }; /* snmpUDPDomain oid */ /* * The SNMP Agent runs in the Management Stack. Its socket, snmpSocket, is * bound to the IP address INADDR_ANY and the SNMP port. These two values * are needed for inititialization of the entLogicalTAddress object. Get * the value of the port from the socket via getsockname(). The return * value for the IP address from this call is 0 (because of INADDR_ANY). * The Agent can listen on more interfaces. An IP address one of these * interfaces is defined in envoy.h as ENT_LOGICAL_TADDRESS */ if (myStackNum == VS_MGMT_STACK) { memset (&snmp_srvr, 0, sizeof (struct sockaddr)); buf_len = sizeof (struct sockaddr_in); if (getsockname (snmpSocket, (struct sockaddr *)&snmp_srvr, &buf_len) < 0) {#if SNMP_VS_UTIL_DEBUG printf ("vsSnmpUtilVSAdd: unable to getsockname %d\n",snmpSocket);#endif /* SNMP_VS_UTIL_DEBUG */ return (ERROR); } inet_aton(ENT_LOGICAL_TADDRESS, &snmp_srvr.sin_addr); } /* create and initialize a logical entity object */ pEntLogical = Ent_Logical_Create (); if (pEntLogical == 0) return (ERROR); /* set logical entity entry objects */ /* entLogicalDesc */ sprintf (buf, "%d", vsNum); if ((strlen (ENT_LOGICAL_DESCR) + strlen (buf) + 1) > MAXSIZE_entLogicalCommunity) { Ent_Logical_Destroy(pEntLogical); return (ERROR); } sprintf (buf, "%s%d", ENT_LOGICAL_DESCR, vsNum); buf_len = strlen (buf); Ent_Logical_Set_Descr (pEntLogical, (bits8_t *)buf, buf_len, BFL_IS_ALLOC); /* entLogicalType */ Ent_Logical_Set_Type (pEntLogical, mib2domain, sizeof(mib2domain)/sizeof(OIDC_T)); /* entLogicalCommunity */ sprintf (buf, "%s%d", vsNamingScopePrefix, vsNum); buf_len = strlen (buf); Ent_Logical_Set_Community (pEntLogical, (bits8_t *)buf, buf_len, BFL_IS_ALLOC); /* entLogicalTAddress */ sprintf (buf, "%.8x%.4x", (unsigned int)snmp_srvr.sin_addr.s_addr, snmp_srvr.sin_port); buf_len = strlen (buf); Ent_Logical_Set_TAddress (pEntLogical, (bits8_t *)buf, buf_len, BFL_IS_ALLOC); /* entLogicalTDomain */ Ent_Logical_Set_TDomain (pEntLogical, snmpUDPDomain, sizeof(snmpUDPDomain)/sizeof(OIDC_T)); /* entLogicalContextEngineID */#if (INSTALL_ENVOY_SNMP_VERSION_3) DYNCFG_IFCFGVBL_BEGIN(snmpv3_component) if (snmpdInstalledComponentsValue & SNMPD_VERSION_3_COMPONENT) { DYNCFG_FUNCALL(_vs_v3engine_set)(pEntLogical); /* entLogicalContextName */ sprintf (buf, "%s%d", vsNamingScopePrefix, vsNum); buf_len = strlen (buf); Ent_Logical_Set_Context_Name (pEntLogical, (bits8_t *)buf, buf_len, BFL_IS_ALLOC); } DYNCFG_IFCFGVBL_END(snmpv3_component)#endif /* INSTALL_ENVOY_SNMP_VERSION_3 */ /* * install the logical entity into the logical entity table * * If the index vsNum+1 already exists in the logical entity table, * try to insert increased index until maximum of ETC_ENT_LOGICAL_MAX_INDEX */ ENVOY_SNMP_GET_WRITE_LOCK(SNMP_CoarseLock); defaultIndex = vsNum; do { defaultIndex++; result = Ent_Logical_Install (pEntLogical, defaultIndex); } while ((result != ENVOY_ERR_NOERR) && (defaultIndex < ETC_ENT_LOGICAL_MAX_INDEX)); ENVOY_SNMP_RELEASE_WRITE_LOCK(SNMP_CoarseLock); if (result != ENVOY_ERR_NOERR) {#if SNMP_VS_UTIL_DEBUG printf ("vsSnmpUtilVSAdd: unable to install struct into logical entity list\n");#endif /* SNMP_VS_UTIL_DEBUG */ Ent_Logical_Destroy(pEntLogical); return (ERROR); } /* Add the mapping between vsNum and entLogicalIndex */ ent_index = Ent_Logical_Get_Index (pEntLogical); if (vsSnmpUtilEntLogicalAdd (vsNum, ent_index) != OK) { ENVOY_SNMP_GET_WRITE_LOCK(SNMP_CoarseLock); Ent_Logical_Deinstall (pEntLogical); Ent_Logical_Destroy(pEntLogical); ENVOY_SNMP_RELEASE_WRITE_LOCK(SNMP_CoarseLock); return (ERROR); }#if SNMP_VS_UTIL_DEBUG printf ("vsSnmpUtilVSAdd: new entry in the logical entity table, Naming Scope %s\n", buf);#endif /* SNMP_VS_UTIL_DEBUG */ #endif /* INSTALL_SNMP_VXWORKS_VS_ENTITY */ /* * Add new community string to the list of acceptable community strings. * #define for VS_COMMUNITY_REGISTER is in envoy.h */ VS_COMMUNITY_REGISTER (vsNum); #if INSTALL_ENVOY_SNMP_VERSION_3 if (snmpdInstalledComponentsValue & SNMPD_VERSION_3_COMPONENT) { /* * Add new context name to the list of acceptable context names * #define for VS_CONTEXT_REGISTER is in envoy.h */ VS_CONTEXT_REGISTER (vsNum); if (DYNCFG_FUNCPTR(_nvhard_vs_add)) if (DYNCFG_FUNCALL(_nvhard_vs_add)(vsNum) != 0) return (ERROR); } #endif /* INSTALL_ENVOY_SNMP_VERSION_3 */ return (OK); } /****************************************************************************** * * vsSnmpUtilVSRemove - vsSnmpUtil Destructor function * * This routine removes the community string (resp. context name) from the * list of acceptable community string (resp. context names). * * If INSTALL_SNMP_ADD_VS_LOGICAL_ENTITY is defined it also * removes an entry from the Entity MIB Logical Table and * vsToEntLogical Table. * * RETURNS: OK or ERROR * */ STATUS vsSnmpUtilVSRemove ( int vsNum ) { #if INSTALL_SNMP_VXWORKS_VS_ENTITY ENT_LOGICAL_T * pEntLogical; int ent_index;#endif /* INSTALL_SNMP_VXWORKS_VS_ENTITY */ ENVOY_SNMP_GET_WRITE_LOCK(SNMP_CoarseLock); #if INSTALL_SNMP_VXWORKS_VS_ENTITY /* remove the entry from the Entity MIB Logical Table */ ent_index = vsSnmpUtilEntLogicalGet (vsNum); pEntLogical = Ent_Logical_Lookup (ent_index); if (pEntLogical == NULL) { ENVOY_SNMP_RELEASE_WRITE_LOCK(SNMP_CoarseLock); return (ERROR); } Ent_Logical_Deinstall (pEntLogical); Ent_Logical_Destroy(pEntLogical); /* remove the entry from the vsToEntLogical table */ vsSnmpUtilEntLogicalRemove (vsNum);#if SNMP_VS_UTIL_DEBUG printf ("vsSnmpUtilVSRemove: entry removed from the logical entity table, vsnum %d\n", vsNum);#endif /* SNMP_VS_UTIL_DEBUG */ #endif /* INSTALL_SNMP_VXWORKS_VS_ENTITY */ /* remove the community string from the list of acceptable community string */ communityStringDeregister (NULL, 0, 0, vsNum); /* remove the context name from the list of acceptable context names */ #if INSTALL_ENVOY_SNMP_VERSION_3 if (snmpdInstalledComponentsValue & SNMPD_VERSION_3_COMPONENT) { contextNameDeregister (NULL, 0, 0, vsNum); if (DYNCFG_FUNCPTR (_nvhard_vs_remove)) if (DYNCFG_FUNCALL(_nvhard_vs_remove)(vsNum) != 0) { ENVOY_SNMP_RELEASE_WRITE_LOCK(SNMP_CoarseLock); return (ERROR); } } #endif /* INSTALL_ENVOY_SNMP_VERSION_3 */ ENVOY_SNMP_RELEASE_WRITE_LOCK(SNMP_CoarseLock); return (OK); } /****************************************************************************** * * usrVsSnmpUtilStart - register vsSnmpUtil component * * This function initializes the vs mapping modules and then calls * vsSnmpUtilVSAdd() for the management stack instance. * * RETURNS: OK or ERROR * */ STATUS usrVsSnmpUtilStart (void) { int i; if (vsSnmpUtilInit(NAMING_SCOPE_PREFIX) != OK) return (ERROR); /* run vsSnmpUtilVSAdd for the management stack instance (vsnum = 0)*/ if (vsSnmpUtilVSAdd(0) != OK) return (ERROR); /* Add other possible management stacks */ for (i = 1; i < SNMP_VIRTUAL_STACK_NUM; i++) { if (vsSnmpUtilVSAdd(i) != OK) return(ERROR); } return (OK); }#endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -