⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nextpdu.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  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. *//* *  Copyright 1995-1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. *//* * $Log: nextpdu.c,v $ * Revision 1.4  2003/01/15 14:05:06  josh * directory structure shifting * * Revision 1.3  2001/11/06 21:50:48  josh * second (and hopefully final) pass of new path hacking * * Revision 1.2  2001/11/06 21:20:16  josh * revised new path hacking * * Revision 1.1.1.1  2001/11/05 17:47:43  tneale * Tornado shuffle * * Revision 9.2.4.3  2001/08/17 20:42:37  meister * Fixed a DYNCFG_IFCFGVBL_BEGIN which should have been a * DYNCFG_IFCFGVBL_END * * Revision 9.2.4.2  2001/08/07 21:53:33  meister * reworked to use dynamic component configuration macros, to allow * separate vxworks agentx components * * Revision 9.2.4.1  2001/08/06 20:05:37  meister * Added dynamic component configuration macros to V3 conditional code * * Revision 9.2  2001/01/19 22:22:22  paul * Update copyright. * * Revision 9.1  2000/03/17 00:19:13  meister * Update copyright message * * Revision 9.0  1998/10/16 22:11:45  sar * Update version stamp to match release * * Revision 8.8  1998/06/17 19:32:51  sar * Moved some code around in the start of the next processing code * to make sure we 0 out the error index and status before sending * a reply packet * * Revision 8.7  1998/06/08 22:05:25  sar * Tidied up some v3 error returns, notably authorization error * * Revision 8.6  1998/06/05 18:53:16  sra * "#include <foo.h>" => "#include <envoy/h/foo.h>". * * Revision 8.5  1998/06/01 20:45:09  sar * Modified the size calculations for too bigs to cover the v3 case. * * Revision 8.4  1998/05/29 04:31:14  sar * Add and use defines for v2 types and v2 protocol pieces.  This allows * us to include the types and pieces for other versions, such as v3, * without having to touch all of the seperate files that use the * types or pieces. * * Revision 8.3  1998/05/24 04:44:06  sar * Added a call to find the view family, in nextpdu also modified the view_check * call to be view_family_check * * Revision 8.2  1998/02/25 15:21:31  sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 8.1  1998/02/25 04:52:08  sra * Update copyrights. * * Revision 8.0  1997/11/18 00:56:53  sar * Updated revision to 8.0 * * Revision 7.5  1997/10/22 03:10:23  sar * Modified the installation options for agentx and the older sub agent scheme * * Also moved the allocation of the locks into envoy_init (env_init.c), * so they can be initialized if necessary. * * Revision 7.4  1997/10/16 00:45:56  sar * Updated for agentx support, with most of the work in mibutils.c to deal * with interior leaves and the pdu processors to deal with agentx leaves, * especially their reference counts. * * Add a bug macro into the get_{read write}_lock calls to give the user * a chance if things start going wrong. * * Fixed a potential problem int the proxy code where we were trying to * stuff a 32 bit quantity into a pointer which may or may not work depending * on the platform. * * Revision 7.3  1997/03/20 06:49:02  sra * DFARS-safe copyright text.  Zap! * * Revision 7.2  1997/02/25 10:49:26  sra * Update copyright notice, dust under the bed. * * Revision 7.1  1996/03/25 15:10:34  sar * If we have a getbulk with no variables requested clean up * the packet and return an empty vb list. * * Revision 7.0  1996/03/18  20:01:11  sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.6  1996/01/15  19:45:11  sar * In the size check for getbulk, made updating the vblcount * be dependent on bufsize <= maxpkt rather than bufzsize < maxpkt. * * Revision 6.5  1995/11/14  22:44:42  sar * Renamed the silentdrops & proxydrops counters to match the mib def * * Revision 6.4  1995/11/02  01:55:22  sar * Moved an endif that was blocking out a } * * Revision 6.3  1995/11/01  00:46:48  sar * Added a default option in the version case statement to allow * new versions such as usec to be added without touching nextpdu * * Revision 6.2  1995/10/20  23:02:48  sar * rearranged the view code so we use the rfc1445 view scheme for both * v1 & v2 if INSTALL_ENVOY_SNMP_RFC1445_VIEWS is installed or the old * scheme if it isn't * * Revision 6.1  1995/06/05  20:58:44  sar * Added a call to clean_vb_data if the instance returned by a nextproc * isn't in our view. * * Revision 6.0  1995/05/31  21:47:35  sra * Release 6.0. * * Revision 1.3  1995/05/03  20:44:14  sar * Moved a variable declaration to be within an ifdefed block to avoid * compiler complaints when that block isn't being compiled. * * Revision 1.2  1995/04/18  21:13:44  sar * Added a check at the start of proxess_next_redo to handle a packet * that has already been tagged with an error. * * Revision 1.1  1995/03/21  00:09:23  sar * 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/snmp/engine/snmpstat.h>#include <wrn/wm/common/bug.h>#include <wrn/wm/common/dyncfg.h>DYNCFG_VBL_DECLARE_EXTERN(envoy_use_v2_protos)DYNCFG_VBL_DECLARE_EXTERN(agentx_master_component)/****************************************************************************NAME:  SNMP_Process_Next_PDUPURPOSE:  Process a next or bulk type pdu in an async fashion.  First we	  find possible objects for all the var binds (checking that the	  objects are in the view).  If any var binds would send us off the	  end of the mib  we flag a end of mib event.  For v1 this means a	  no such error, for v2 an exception.  After we have found all the	  objects we call the nextproc routines to find the value for	  each var bind.PARAMETERS:	SNMP_PKT_T *	The decoded NEXT/BULK PDURETURNS:  int	0 all of the nexts for this rep have been started successfully		1 error of some sort, any error packet has been sent.****************************************************************************/int  SNMP_Process_Next_PDU(SNMP_PKT_T *pktp){VB_T *vbp, *newvbp, *oldvbp;INT_32_T maxreps = 1, *err_stat;int nonreps = 0, count, indx;/* 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);/* get some initial information */oldvbp = pktp->pdu.std_pdu.std_vbl.vblist;count  = pktp->pdu.std_pdu.std_vbl.vbl_count;#if ENVOY_USE_V2_PROTOSDYNCFG_IFCFGVBL_BEGIN(envoy_use_v2_protos)if (pktp->pdu_type == GET_BULK_REQUEST_PDU) {    ALENGTH_T need;    /* Test the packet and see if even an empty var bind list       will casue a too big, if so we drop the packet.  We've       already saved the vblist and count so we 0 those fields       and do a bufsize check, then restore the fields.  */    pktp->pdu.std_pdu.std_vbl.vblist = 0;    pktp->pdu.std_pdu.std_vbl.vbl_count = 0;    need = SNMP_Bufsize_For_Packet(pktp);    pktp->pdu.std_pdu.std_vbl.vblist = oldvbp;    pktp->pdu.std_pdu.std_vbl.vbl_count = count;    if (pktp->maxpkt < need) {        SGRPv2_INC_COUNTER(snmp_stats.snmpSilentDrops);	/* sar may need to add a different return here */	pktp->error_complete(&pktp->pkt_src, &pktp->pkt_dst, 1,			     pktp->async_cookie);	return(1);        }    /* Pull the maxreps and nonreps information from the packet and       rationalize it. */    maxreps = pktp->pdu.std_pdu.error_index;    if (*err_stat < 0)	nonreps = 0;    else if (*err_stat >= count) {	nonreps = count;	maxreps = 1;	}    else	nonreps = (int)(*err_stat & 0xFFFF);          if (maxreps < 1) {	maxreps = 1;	/* This is kinda wierd, the manager sent a bulk packet but doesn't	   want any of the repeaters, adjust the counters */	if (nonreps == 0) {	    Clean_vb_list(&pktp->pdu.std_pdu.std_vbl);	    pktp->pdu.std_pdu.std_vbl.vblist = 0;	    pktp->pdu.std_pdu.std_vbl.vbl_count = 0;	    }	count = nonreps;	}    }DYNCFG_IFCFGVBL_END(envoy_use_v2_protos)#endif /* #if ENVOY_USE_V2_PROTOS *//* assume the packet will work */*err_stat = NO_ERROR;pktp->pdu.std_pdu.error_index = 0;/* Check to see if the user actually wants anything, if not we   are done and we bail out, note that this test must happen   after we set the err status & index fields to 0 */if ((oldvbp == 0) || (count == 0))    return(0);/* Fill in the max_reps and non_reps fields.  If this is a bulk packet   we pulled the information from the error fields. If it isn't   a bulk packet we are using default values */pktp->pdu.std_pdu.max_reps = maxreps;pktp->pdu.std_pdu.non_reps = nonreps;/* Some errors may require us to use the original list so we save the   original and allocate space for a new one.  The objid for the new vbs   will be filled in by the find_next_object routine, but we will need to   clone the object id if find_next_object tells us their aren't any   more objects. */if ((newvbp = VarBindList_Allocate(count)) == 0) {    ENVOY_Send_SNMP_Error_Packet(pktp, GEN_ERR, 0);    return(1);    }pktp->pdu.std_pdu.saved_vbl.vbl_count = pktp->pdu.std_pdu.std_vbl.vbl_count;pktp->pdu.std_pdu.saved_vbl.vblist = oldvbp;pktp->pdu.std_pdu.std_vbl.vbl_count = count;pktp->pdu.std_pdu.std_vbl.vblist = newvbp;/* 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_Next_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);    }#endif/* Attempt to find all the requested objects   Note: if we find an error we set indx = count to break the loop */for(indx = 0, vbp = newvbp; indx < count; indx++, vbp++, oldvbp++) {    switch(find_next_object(vbp, &(oldvbp->vb_obj_id), pktp, 1)) {	case 0:	    /* Nothing was found, generate an error for v1 or	       an exception for v2 */            switch(pktp->snmp_version) {#if INSTALL_ENVOY_SNMP_VERSION_1	        case SNMP_VERSION_1:	            /* If version 1 we send a NO_SUCH_NAME error back.		       We set up the packet for a nosuch name error. */	            *err_stat = NO_SUCH_NAME;		    pktp->pdu.std_pdu.error_index = SNMP_ERROR_INDEX(indx);		    indx = count;		    break;#endif#if ENVOY_USE_V2_PROTOS		case SNMP_VERSION_2:		case SNMP_VERSION_3:		default:                    DYNCFG_IFCFGVBL_BEGIN(envoy_use_v2_protos)		    /* If not version 1 we send a END_OF_MIB exception back.		       We set the data_flags_n_type of the current vbp		       to END_OF_MIB, clone the object id and tag the		       vbp as having been done and continue with the rest */		    vbp->vb_data_flags_n_type = VT_ENDOFMIB;		    vbp->vb_flags |= VFLAG_NEXT_STARTED | VFLAG_NEXT_DONE;		    if (clone_object_id(&oldvbp->vb_obj_id, &vbp->vb_obj_id)) {		        /* We were unable to clone an object so we return			   a gen err */		        *err_stat = GEN_ERR;			indx = count;		        }                    DYNCFG_IFCFGVBL_END(envoy_use_v2_protos)		    break;#endif /* #if ENVOY_USE_V2_PROTOS */		}	    break;	case -1:	    /* An internal error occurred send back a generr */	    *err_stat = GEN_ERR;	    indx = count;	    break;	} /* switch(find_next_object...) */    } /* for(indx = 0...) */ENVOY_AX_MA_RELEASE_WRITE_LOCK(SNMP_infrastructure_lock);if (*err_stat) {    ENVOY_Send_SNMP_Error_Packet(pktp, *err_stat,				 pktp->pdu.std_pdu.error_index);    return(1);    }/* Now we loop through the vblist again and start all the nexts */for(vbp = newvbp; count; count--, vbp++) {    /* If the next started flag is set then either we set it above or       the nextproc 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_NEXT_STARTED | VFLAG_NEXT_DONE))	continue;    ((vbp->vb_ml.ml_leaf)->nextproc)      (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_NEXT_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_NEXT_STARTED))		vbp->vb_flags |= VFLAG_NEXT_STARTED | VFLAG_NEXT_DONE;	break;	}    }return(0);}/****************************************************************************NAME:  SNMP_Process_Next_RedoPURPOSE:  This is the second stage of the next or bulk processing.	  We look through the pdu after all of the first set of nextprocs	  have finished.  For each pdu we have several possibilities	  the next proc may have found something which is in our	  view, it may have found something that isn't in our view	  (if we are using v2 views) or it may not have found anything.	  After we've looked over the entire list we do next procs for	  any vbs in case 2 or 3.PARAMETERS:	SNMP_PKT_T *	The decoded NEXT/BULK PDU

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -