📄 copyvb.c
字号:
/* * Copyright 2000-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. *//* copyvb.c - code to handle copying of varbinds and varbind lists *//*modification history--------------------01b,18apr05,job update copyright notices01a,24nov03,job update copyright information$Log: copyvb.c,v $Revision 1.5 2003/01/15 14:05:02 joshdirectory structure shiftingRevision 1.4 2002/04/19 15:33:30 joshfixing OIDs that are being checked against in SNMP_Convert_VB()Revision 1.3 2001/11/06 21:50:44 joshsecond (and hopefully final) pass of new path hackingRevision 1.2 2001/11/06 21:20:06 joshrevised new path hackingRevision 1.1.1.1 2001/11/05 17:47:42 tnealeTornado shuffleRevision 1.1.2.3 2001/09/27 01:12:04 meisterdynamic config rototillRevision 1.1.2.2 2001/09/21 20:52:29 joshextra cleanup for various combinations of installation optionsRevision 1.1.2.1 2001/09/21 19:21:40 joshmove some functions out to their own source file to make buildingmore modular*//*DESCRIPTIONThis module contains the functions called by proxy and notify code tocopy varbinds from one place to another.INCLUDE FILES: asn1.h, snmp.h, buffer.h, etimer.h, objectid.h, v3_proxy.h, snmpdefs.h, ntfy_chk.h, bug.h *//* includes */#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/etimer.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/v3_trgt.h>#include <wrn/wm/snmp/engine/wkobj.h>#include <wrn/wm/common/dyncfg.h>#include <wrn/wm/common/bug.h>DYNCFG_VBL_DECLARE_EXTERN(envoy_use_v2_types)#if INSTALL_ENVOY_SNMP_COEXISTENCE/* Some well-known OIDs that will be necessary to deal with traps * and proxies */static OIDC_T COEX_SNMPTRAPOID[] = {SNMP_SNMPTRAPOID, 0};static OIDC_T COEX_TRAPENTERPRISE[] = {SNMP_SNMPTRAPENTERPRISE};static OIDC_T COEX_SNMPTRAPS[] = {SNMP_SNMPTRAPS};static OIDC_T COEX_COLDSTART[] = {SNMP_COLDSTART};#if INSTALL_ENVOY_SNMP_V3_PROXYstatic OIDC_T COEX_SYSUPTIME[] = { 1, 3, 6, 1, 2, 1, 1, 3, 0 };static OIDC_T COEX_SNMPTRAPADDRESS[] = { 1, 3, 6, 1, 6, 3, 18, 1, 3, 0 };static OIDC_T COEX_SNMPTRAPCOMMUNITY[] = { 1, 3, 6, 1, 6, 3, 18, 1, 4, 0 };#endif/***************************************************************************** copyVarBind - bind the contents of a varbind into a new packet** This function will bind the contents of an existing varbind into* the appropriate place in a new SNMP_PKT_T** RETURNS: ENVOY_ERR_NOERR if successful* ENVOY_ERR_INSUFFICIENT_MEMORY if a memory allocation error* occurred.**/envoy_err_t copyVarBind ( VB_T * pVb, int vbCount, SNMP_PKT_T * pNewPkt ) { switch (pVb->vb_data_flags_n_type) { case VT_NUMBER: if (SNMP_Bind_Integer (pNewPkt, vbCount, pVb->vb_obj_id.num_components, pVb->vb_obj_id.component_list, VB_GET_INT32 (pVb))) return ENVOY_ERR_INSUFFICIENT_MEMORY; break; case VT_STRING: case VT_OPAQUE: if (SNMP_Bind_String (pNewPkt, vbCount, pVb->vb_obj_id.num_components, pVb->vb_obj_id.component_list, pVb->vb_data_flags_n_type, EBufferUsed (VB_GET_STRING (pVb)), EBufferStart (VB_GET_STRING (pVb)), 0)) return ENVOY_ERR_INSUFFICIENT_MEMORY; break; case VT_OBJECT: if (SNMP_Bind_Object_ID (pNewPkt, vbCount, pVb->vb_obj_id.num_components, pVb->vb_obj_id.component_list, (VB_GET_OBJECT_ID (pVb))->num_components, (VB_GET_OBJECT_ID (pVb))->component_list)) return ENVOY_ERR_INSUFFICIENT_MEMORY; break; case VT_EMPTY: if (SNMP_Bind_Null (pNewPkt, vbCount, pVb->vb_obj_id.num_components, pVb->vb_obj_id.component_list)) return ENVOY_ERR_INSUFFICIENT_MEMORY; break; case VT_IPADDRESS: if (SNMP_Bind_IP_Address (pNewPkt, vbCount, pVb->vb_obj_id.num_components, pVb->vb_obj_id.component_list, VB_GET_IP_ADDRESS (pVb))) return ENVOY_ERR_INSUFFICIENT_MEMORY; break; case VT_COUNTER: case VT_GAUGE: case VT_TIMETICKS: case VT_UINTEGER32: if (SNMP_Bind_Unsigned_Integer (pNewPkt, vbCount, pVb->vb_obj_id.num_components, pVb->vb_obj_id.component_list, pVb->vb_data_flags_n_type, VB_GET_UINT32 (pVb))) return ENVOY_ERR_INSUFFICIENT_MEMORY; break; default: return ENVOY_ERR_UNKNOWN; } return ENVOY_ERR_NOERR; }#endif /* #if INSTALL_ENVOY_SNMP_COEXISTENCE */#if INSTALL_ENVOY_SNMP_V3_PROXY/***************************************************************************** copyNotifyVarBindList - copy and convert a varbind list from an* incoming notification to an outgoing notification** This function will examine the varbind list of the notify to be forwarded* and put the appropriate information in the outgoing varbind list. The* details of this will vary depending on the source and destination versions.* Specifically, translations between v1 and v2c/v3 hosts can get fairly* involved. ** RETURNS: ENVOY_ERR_NOERR if the copy was successful* ENVOY_ERR_INSUFFICIENT_MEMORY if an allocation error occurred**/envoy_err_t copyNotifyVarBindList ( SNMP_PKT_T *pPkt, SNMP_PKT_T *pNewPkt ) {#if INSTALL_ENVOY_SNMP_COEXISTENCE int vbCount; VBL_T pVbl; OBJ_ID_T snmpTrapOID; int need;#endif switch (pPkt->snmp_version) {#if INSTALL_ENVOY_SNMP_COEXISTENCE#if INSTALL_ENVOY_SNMP_VERSION_1 case SNMP_VERSION_1: switch (pNewPkt->snmp_version) { case SNMP_VERSION_1: /* * We don't actually want any translation here, * so we lie to the copy function. */ copyVarBindList (&(pNewPkt->pdu.trap_pdu.trap_vbl), &(pPkt->pdu.trap_pdu.trap_vbl), SNMP_VERSION_MAX); break;#if INSTALL_ENVOY_SNMP_VERSION_2 case SNMP_VERSION_2:#endif case SNMP_VERSION_3: /* We need to derive the value of snmpTrapOID */ if (pPkt->pdu.trap_pdu.generic_trap == ENTERPRISE_SPECIFIC) { snmpTrapOID.num_components = (pPkt->pdu.trap_pdu.enterprise_objid.num_components + 2); need = (sizeof (OIDC_T) * snmpTrapOID.num_components); if ((snmpTrapOID.component_list = (OIDC_T *) SNMP_memory_alloc (need)) == 0) return ENVOY_ERR_INSUFFICIENT_MEMORY; MEMCPY (snmpTrapOID.component_list, pPkt->pdu.trap_pdu.enterprise_objid.component_list, pPkt->pdu.trap_pdu.enterprise_objid.num_components); snmpTrapOID.component_list [snmpTrapOID.num_components - 2] = 0; snmpTrapOID.component_list [snmpTrapOID.num_components - 1] = pPkt->pdu.trap_pdu.specific_trap; } else { if (build_object_id (sizeof (COEX_COLDSTART)/sizeof (OIDC_T), COEX_COLDSTART, &snmpTrapOID) != 0) return ENVOY_ERR_INSUFFICIENT_MEMORY; snmpTrapOID.component_list [snmpTrapOID.num_components - 1] = pPkt->pdu.trap_pdu.generic_trap + 1; } /* * We have to bind in the sysUptime and * snmpTrapOID varbinds. */ SNMP_Bind_Timeticks (pNewPkt, 0, sizeof (COEX_SYSUPTIME) / sizeof (OIDC_T), COEX_SYSUPTIME, pPkt->pdu.trap_pdu.trap_time_ticks); SNMP_Bind_Object_ID (pNewPkt, 1, sizeof (COEX_SNMPTRAPOID) / sizeof (OIDC_T), COEX_SNMPTRAPOID, snmpTrapOID.num_components, snmpTrapOID.component_list); Clean_Obj_ID (&snmpTrapOID); /* * Some clever manipulation to copy the entire * varbind list from the v1 trap to the appropriate * varbinds in the new varbind list. We need to skip * the first two varbinds, which already have * information in them... */ pVbl.vblist = &(pNewPkt->pdu.std_pdu.std_vbl.vblist[2]); pVbl.vbl_count = pNewPkt->pdu.std_pdu.std_vbl.vbl_count-2; copyVarBindList (&pVbl, &(pPkt->pdu.trap_pdu.trap_vbl), pNewPkt->snmp_version); /* * Now we have to add three additional varbinds: * snmpTrapAddress.0, snmpTrapCommunity.0, * and snmpTrapEnterprise.0. */ vbCount = pNewPkt->pdu.std_pdu.std_vbl.vbl_count; SNMP_Bind_IP_Address (pNewPkt, vbCount-3, sizeof (COEX_SNMPTRAPADDRESS) / sizeof (OIDC_T), COEX_SNMPTRAPADDRESS, pPkt->pdu.trap_pdu.net_address); SNMP_Bind_String (pNewPkt, vbCount-2, sizeof (COEX_SNMPTRAPCOMMUNITY) / sizeof (OIDC_T), COEX_SNMPTRAPCOMMUNITY, VT_STRING, EBufferUsed (&pPkt->community), EBufferStart (&pPkt->community), 1); SNMP_Bind_Object_ID
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -