📄 getpdu.c
字号:
* Added static argument to getproc calls for strings. * * Revision 2.103 91/08/15 12:31:01 dab * Removed <libfuncs.h>. * * Revision 2.102 91/08/14 10:46:53 dab * Added trace functions that Karl put in as macros. * * Revision 2.101 91/08/12 12:47:38 dab * Cast arguments to memcpy() and memset() to PTR_T. * * Revision 2.100 91/08/09 14:08:21 dab * Update version. * * Revision 1.1 91/07/30 02:23:43 romkey * Initial revision * * * Rev 2.0 31 Mar 1990 15:06:34 * Release 2.00 * * Rev 1.9 27 Apr 1989 15:56:24 * Removed unused variables * * Rev 1.8 19 Mar 1989 12:28:28 * A call to memcpy was being made when the correct routine was memset. * This resulted in a copy of 4 bytes from address zero. This occurred * when an attempt to get an IP address failed. * * Rev 1.7 17 Mar 1989 21:41:38 * Calls to memcpy/memset protected against zero lengths * * Rev 1.6 19 Sep 1988 17:26:06 * Made changes to make the Sun C compiler happy. * * Rev 1.5 19 Sep 1988 9:24:02 * Reversed change made in revision 1.2 * * Rev 1.4 15 Sep 1988 21:35:40 * On the previous update, not all of the get procedures had the necessary * casts added. This update fixes that. * * Rev 1.3 15 Sep 1988 21:22:06 * Added casts to calls to the getproc to avoid improper type conversions * when "int" and pointers are of different sizes. * * Rev 1.2 15 Sep 1988 20:03:50 * Recalculated size of outgoing packet before transmission. * * Rev 1.1 14 Sep 1988 17:57:06 * Moved includes of system include files into libfuncs.h. * * Rev 1.0 12 Sep 1988 10:46:58 * Initial revision.*//* [clearcase]modification history-------------------01b,18apr05,job update copyright notices01a,24nov03,job update copyright information*/#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/mib.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/view.h>#include <wrn/wm/common/bug.h>#include <wrn/wm/common/dyncfg.h>DYNCFG_VBL_DECLARE_EXTERN(agentx_master_component)DYNCFG_VBL_DECLARE_EXTERN(agentx_subagent_component)/****************************************************************************NAME: SNMP_Process_Get_PDUPURPOSE: Process a get type pdu in an async fashion. First we find objects for all the var binds (checking that the objects are in the view). If any var binds don't point to a valid object we flag a no such event. For v1 this means an error, for v2 an exception. After we have found all the objects we call the getproc routines to find the value for each var bind.PARAMETERS: SNMP_PKT_T * The decoded GET PDURETURNS: int 0 all of the gets have been started successfully 1 error of some sort, any error packet has been sent.****************************************************************************/int SNMP_Process_Get_PDU(SNMP_PKT_T *pktp){VB_T *vbp, *newvbp, *oldvbp;int count, indx, eret;sbits32_t *err_stat;/* get some initial information */if (((oldvbp = pktp->pdu.std_pdu.std_vbl.vblist) == 0) || ((count = pktp->pdu.std_pdu.std_vbl.vbl_count) == 0)) return(0);/* We will be looking at the error status a lot so we get a local pointer to it to make things easier */err_stat = &(pktp->pdu.std_pdu.error_status);/* assume that everything will work */*err_stat = NO_ERROR;pktp->pdu.std_pdu.error_index = 0;/* Copy the vb list so we can use the original list if we have an error */if ((newvbp = VarBindList_Allocate(count)) == 0) { ENVOY_Send_SNMP_Error_Packet(pktp, GEN_ERR, 0); return(1); }for(indx = count, vbp = newvbp; indx; indx--, oldvbp++, vbp++) { vbp->vb_data_flags_n_type = VT_EMPTY; if (clone_object_id(&oldvbp->vb_obj_id, &vbp->vb_obj_id)) break; }if (indx != 0) { /* we had an error trying to clone an object id (probably couldn't get the space), clean up any vbs we modified and free the newvbp space */ for(vbp = newvbp; indx < count; indx++, vbp++) Clean_vb(vbp); SNMP_memory_free(newvbp); ENVOY_Send_SNMP_Error_Packet(pktp, GEN_ERR, 0); return(1); }/* We have successfully copied the sections of the vblist we need move the old vblist to the saved area and install the new vblist into the current area */pktp->pdu.std_pdu.saved_vbl.vbl_count = count;pktp->pdu.std_pdu.saved_vbl.vblist = pktp->pdu.std_pdu.std_vbl.vblist;pktp->pdu.std_pdu.std_vbl.vblist = newvbp;/* Attempt to find all the requested objects *//* Try to get the infrastructure lock, we release it using the ENVOY_AX_MA_RELEASE_WRITE_LOCK macro */#if (INSTALL_ENVOY_AGENTX_MASTER && INSTALL_ENVOY_SNMP_LOCK)DYNCFG_IFCFGVBL_BEGIN(agentx_master_component)if (ENVOY_SNMP_GET_WRITE_LOCK(SNMP_infrastructure_lock)) { BUG(BUG_ENVOY_LOCKING, BUG_CONTINUABLE, 0, (BUG_OUT, "SNMP_Process_Get_PDU: infrastructure lock broken", 0)); ENVOY_Send_SNMP_Error_Packet(pktp, GEN_ERR, 0); return(1); }DYNCFG_IFCFGVBL_END(agentx_master_component)#endif/* If necessary try to find the view index structure, if we want to do rfc1445 view checking find_object_node will expect this routine to have been run and to have inserted a pointer into pktp */#if (INSTALL_ENVOY_SNMP_DYNAMIC_VIEWS)if (SNMP_View_Find_Family(pktp) && (pktp->snmp_version == SNMP_VERSION_3)) { ENVOY_AX_MA_RELEASE_WRITE_LOCK(SNMP_infrastructure_lock); ENVOY_Send_SNMP_Error_Packet(pktp, AUTHORIZATION_ERROR, 0); return(1); }#endiffor(indx = 0, vbp = newvbp; indx < count; indx++, vbp++) { eret = find_object_node(vbp, pktp, 1);#if (INSTALL_ENVOY_AGENTX_MASTER)DYNCFG_IFCFGVBL_BEGIN(agentx_master_component) if (eret == -3) { ENVOY_AX_MA_RELEASE_WRITE_LOCK(SNMP_infrastructure_lock); ENVOY_Send_SNMP_Error_Packet(pktp, GEN_ERR, 0); return(1); }DYNCFG_IFCFGVBL_END(agentx_master_component)#endif if ((eret != 0) || ((vbp->vb_ml.ml_flags & ML_IS_LEAF) == 0) || (((vbp->vb_ml.ml_leaf)->access_type & READ_ACCESS) == 0)) { switch(pktp->snmp_version) {#if INSTALL_ENVOY_SNMP_VERSION_1 case SNMP_VERSION_1: ENVOY_AX_MA_RELEASE_WRITE_LOCK(SNMP_infrastructure_lock); /* If version 1 we send a NO_SUCH_NAME error back. We set up the packet for a nosuch name error, then attempt to send it */ ENVOY_Send_SNMP_Error_Packet(pktp, NO_SUCH_NAME, (sbits32_t)(SNMP_ERROR_INDEX(indx))); return(1);#endif /* INSTALL_ENVOY_SNMP_VERSION_2 */#if ENVOY_USE_V2_PROTOS case SNMP_VERSION_2: case SNMP_VERSION_3: default: /* If not version 1 we send a NO_SUCH_OBJECT exception back. We set the data_flags_n_type of the current vbp to NO_SUCH_OBJECT, tag the vbp as having been done and continue with the rest */ vbp->vb_data_flags_n_type = VT_NOSUCHOBJ; vbp->vb_flags |= VFLAG_GET_STARTED | VFLAG_GET_DONE; break;#endif /* #if ENVOY_USE_V2_PROTOS */ } } /* if ((find_object...) */ } /* for(indx = 0...) */ENVOY_AX_MA_RELEASE_WRITE_LOCK(SNMP_infrastructure_lock);/* Now we loop through the vblist again and start all the gets */for(vbp = newvbp; count; count--, vbp++) { /* If the get started flag is set then either we set it above or the getproc of some other var bind has claimed responsibility for this var bind. In either case we skip this var bind and continue */ if (vbp->vb_flags & (VFLAG_GET_STARTED | VFLAG_GET_DONE)) continue; ((vbp->vb_ml.ml_leaf)->getproc) (vbp->vb_ml.ml_last_match, vbp->vb_ml.ml_remaining_objid.num_components, vbp->vb_ml.ml_remaining_objid.component_list, pktp, vbp); vbp->vb_flags |= VFLAG_GET_STARTED; /* test the error code, if we had an error then mark any remaining vbs as having been gotten (so we won't trip over them later). We need to skip the first vb as that is the one that caused the failure. Then break because we are done */ if (*err_stat) { for (vbp++, count--; count; count--, vbp++) if (!(vbp->vb_flags & VFLAG_GET_STARTED)) vbp->vb_flags |= VFLAG_GET_STARTED | VFLAG_GET_DONE; break; } }return(0);}/*lint +e715 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -