📄 rpktasy.c
字号:
/* rpktasy.c - rpktasy.c routines *//* * 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: rpktasy.c,v $ * Revision 1.4 2003/01/15 14:05:06 josh * directory structure shifting * * Revision 1.3 2001/11/06 21:50:49 josh * second (and hopefully final) pass of new path hacking * * Revision 1.2 2001/11/06 21:20:21 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:43 tneale * Tornado shuffle * * Revision 9.7.4.7 2001/10/12 18:02:58 josh * adding comments to attempt to dissuade customers from using * internal request API * * Revision 9.7.4.6 2001/10/01 18:55:48 meister * still more dnamic configuration rototill * * Revision 9.7.4.5 2001/09/27 13:45:15 meister * dynamic config rototill; missed SNMP_Check_Retrans_List() * * Revision 9.7.4.4 2001/09/27 01:12:35 meister * dynamic config rototill * * Revision 9.7.4.3 2001/08/27 19:48:31 josh * check notifies before checking proxies * * Revision 9.7.4.2 2001/08/24 14:40:23 josh * rewrite of process_packet_one() and general rearrangement of code * to accomodate proxies * * Revision 9.7.4.1 2001/08/06 20:05:37 meister * Added dynamic component configuration macros to V3 conditional code * * Revision 9.7 2001/01/19 22:22:24 paul * Update copyright. * * Revision 9.6 2000/03/17 00:19:16 meister * Update copyright message * * Revision 9.5 2000/01/02 22:55:59 josh * patching up a memory leak here, a broken compare there...per * sar's comments * * Revision 9.4 1999/12/23 14:47:30 josh * cleaning up code per Shawn's comments -- removing extraneous * comments and doing proxy check before notify check * * Revision 9.3 1999/09/27 21:11:46 josh * fixing nits, rewriting engine id <--> address code, adding installation * option * * Revision 9.2 1999/09/21 21:34:27 josh * No need to call SNMP_Check_Retransmit() on anything that isn't a * Response PDU. Also make sure code coexists well with existing * proxy code. * * Revision 9.1 1999/09/14 19:32:30 josh * added code to match incoming packets with retransmit list * * Revision 9.0 1998/10/16 22:11:56 sar * Update version stamp to match release * * Revision 8.5 1998/06/17 19:31:46 sar * changed a v2_types check to check for v2_protos * * Revision 8.4 1998/06/05 18:53:17 sra * "#include <foo.h>" => "#include <envoy/h/foo.h>". * * Revision 8.3 1998/05/29 04:31:15 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.2 1998/02/25 15:21:32 sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 8.1 1998/02/25 04:52:19 sra * Update copyrights. * * Revision 8.0 1997/11/18 00:56:55 sar * Updated revision to 8.0 * * Revision 7.7 1997/10/16 23:51:16 sar * Processing a packet with an unexpected type on an agent (trap, report, * inform or unknown) could result in an attempt to use a stale pointer. * The code has been rearranged to avoid this problem. * * If serialization is enabled processing a packet with an error could * cause other packets to be deferred forever. * * Revision 7.6 1997/10/16 00:45:59 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.5 1997/05/13 15:37:59 sar * Swapped the error_complete and snmp_free lines in * process_packet_one so we aren't trying to operate * on a freed (and cleaned) packet structure. * * Revision 7.4 1997/03/20 06:49:09 sra * DFARS-safe copyright text. Zap! * * Revision 7.3 1997/02/25 10:49:26 sra * Update copyright notice, dust under the bed. * * Revision 7.2 1997/02/10 18:32:16 sar * Changed the translation of some v2 errors to v1 errors to match the * suggested mapping in the v2 to v1 mapping draft. * * Revision 7.1 1996/10/15 14:32:50 sar * Added entry point to allow internally generated packets to be processed * (that is a packet doesn't need to go through the decode routines). * Also moved some of the snmp counting code around in order to make * it consistent with the new routine. * * Revision 7.0 1996/03/18 20:01:11 sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.5 1996/01/10 16:34:47 sar * don't change report type pdus to response type pdus * * Revision 6.4 1995/11/14 22:44:42 sar * Renamed the silentdrops & proxydrops counters to match the mib def * * Revision 6.3 1995/11/04 01:52:51 sar * Modified the code to call proxies to be in line with the * current scheme, this was necessaitated by the demise of parties. * * Revision 6.1 1995/10/20 23:02:48 sar * remvoed party.h and v2 max packet stuff * * Revision 6.0 1995/05/31 21:47:53 sra * Release 6.0. * * Revision 1.6 1995/05/23 23:23:14 sar * Modifed the continue_reentrant code, the continue routines expect * their callers to have gotten the lock and will release it. The callers * must get the lock before modifying the packet. * * Revision 1.5 1995/05/22 19:43:54 sar * Added continue_reentrant code * * Revision 1.4 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.3 1995/05/02 23:34:50 sar * Incr req counter instead of set counter for get/next/bulk requests. * * Revision 1.2 1995/04/28 23:16:40 sar * Moved some stats counting around, add a call to the deferred run routine * to see if anything is on the deferred list, moved some of the packet * processing into a new routine so we have a routine for the GateKeeper. * * Revision 1.1 1995/03/21 00:09:23 sar * Initial revision * * Initial revision. *//* [clearcase]modification history-------------------01d,12may05,job fix apigen comments01c,18apr05,job update copyright notices01b,16feb05,job apigen for documented APIs01a,24nov03,job update copyright information*//*DESCRIPTIONThis library contains rpktasy.c routines.INCLUDE FILES: snmp.h*/#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/localio.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/snmpstat.h>#include <wrn/wm/snmp/engine/objectid.h>#if (INSTALL_ENVOY_SNMP_VERSION_3) && (INSTALL_ENVOY_SNMP_V3_NOTIFY)#include <wrn/wm/snmp/engine/sendntfy.h>#endif#include <wrn/wm/common/bug.h>#include <wrn/wm/common/dyncfg.h>DYNCFG_VBL_DECLARE_EXTERN(envoy_use_v2_types) DYNCFG_VBL_DECLARE_EXTERN(envoy_use_v2_protos) DYNCFG_VBL_DECLARE_EXTERN(envoy_snmp_proxy)DYNCFG_VBL_DECLARE_EXTERN(envoy_snmp_notify)DYNCFG_EXTERN_FUNCPTR9(Send_Report_PDU,SNMP_PKT_T *,SNMP_PKT_T *,LCL_FILE *, bits8_t,OIDC_T *,int,bits32_t,int *,SNMPADDR_T *, SNMPADDR_T *)DYNCFG_EXTERN_FUNCPTR1(SNMP_Check_Retrans_List,void,SNMP_PKT_T *)#if INSTALL_ENVOY_SNMP_V3_PROXYstatic OIDC_T V3_SNMPPROXYDROPS[] = {1, 3, 6, 1, 2, 1, 11, 32, 0};#endif/****************************************************************************NAME: snmp_finish_countersPURPOSE: Do the final counts for outbound snmp packets, generally called just before the call to io_complete.PARAMETERS: SNMP_PKT_T * The packet being encodedRETURNS: void****************************************************************************//*ARGSUSED*/static void snmp_finish_counters(SNMP_PKT_T *pktp){#if INSTALL_ENVOY_SNMP_GROUP_V1/* We successfully encoded the packet and are about to send it so increment any counters that count this packet */inc_counter(snmp_stats.snmpOutPkts);if (pktp->pdu.std_pdu.error_status) { inc_counter(snmp_stats.snmpOutGetResponses); switch (pktp->pdu.std_pdu.error_status) { case TOO_BIG: inc_counter(snmp_stats.snmpOutTooBigs); break; case BAD_VALUE: inc_counter(snmp_stats.snmpOutBadValues); break; case READ_ONLY: inc_counter(snmp_stats.snmpOutReadOnlys); break; case NO_SUCH_NAME: inc_counter(snmp_stats.snmpOutNoSuchNames); break; case GEN_ERR: inc_counter(snmp_stats.snmpOutGenErrs); break; } }else { if (pktp->pdu_type == TRAP_PDU) inc_counter(snmp_stats.snmpOutTraps); }#endif /* INSTALL_ENVOY_SNMP_GROUP_V1 */return;}/****************************************************************************\NOMANUALNAME: ENVOY_Send_SNMP_Error_PacketPURPOSE: Attempt to build and send an error packet, we expect the error status to be set but the pdu type to be that of the original packet (get, next, bulk, set). This routine will set the pdu type to response. If necessary it checks the size of the packet, if the packet is too big it may change the error and remove the vb list. It attempts to encode the packet and send it using the completion routine, if it can't it calls the error routine. PARAMETERS: SNMP_PKT_T * The decoded PDU INT_32_T The error code INT_32_T The error indexRETURNS: void****************************************************************************/void ENVOY_Send_SNMP_Error_Packet(SNMP_PKT_T *pktp, INT_32_T ecode, INT_32_T eindex){ATVALUE_T pdu_type;ALENGTH_T bufsize;/* Install the ecode and eindex in the packet */pktp->pdu.std_pdu.error_status = ecode;pktp->pdu.std_pdu.error_index = eindex;/* If necessary clean up any unneeded vb lists and switch back to the original vb list that we saved earlier */if (pktp->pdu.std_pdu.saved_vbl.vblist != 0) { Clean_vb_list(&pktp->pdu.std_pdu.std_vbl); pktp->pdu.std_pdu.std_vbl.vbl_count = pktp->pdu.std_pdu.saved_vbl.vbl_count; pktp->pdu.std_pdu.std_vbl.vblist = pktp->pdu.std_pdu.saved_vbl.vblist; pktp->pdu.std_pdu.saved_vbl.vblist = 0; pktp->pdu.std_pdu.saved_vbl.vbl_count = 0; }/* Save the pdu type so we can check it later during the error action code, then make the packet a response pdu, and get the bufsize as we will need it in several places */pdu_type = pktp->pdu_type;if (pdu_type != REPORT_PDU) pktp->pdu_type = GET_RESPONSE_PDU;bufsize = SNMP_Bufsize_For_Packet(pktp);#if INSTALL_ENVOY_SNMP_VERSION_1if (pktp->snmp_version == SNMP_VERSION_1) { /* If the pdu type isn't a set we need to determine if the size is acceptable. If it isn't we toss the packet */ if ((pdu_type != SET_REQUEST_PDU) && (bufsize > pktp->maxpkt)) { pktp->error_complete(&pktp->pkt_src, &pktp->pkt_dst, 1, pktp->async_cookie); return; } /* For v1 packets we tranlsate any v2 errors back to v1 codes */ switch (pktp->pdu.std_pdu.error_status) { case NO_ACCESS: case NO_CREATION: case NOT_WRITABLE: case INCONSISTENT_NAME: case AUTHORIZATION_ERROR: pktp->pdu.std_pdu.error_status = NO_SUCH_NAME; break; case WRONG_TYPE: case WRONG_LENGTH: case WRONG_ENCODING: case WRONG_VALUE: case INCONSISTENT_VALUE: pktp->pdu.std_pdu.error_status = BAD_VALUE; break; case RESOURCE_UNAVAILABLE: case COMMIT_FAILED: case UNDO_FAILED: pktp->pdu.std_pdu.error_status = GEN_ERR; break; } }#endif#if ENVOY_USE_V2_TYPESDYNCFG_IFCFGVBL_BEGIN(envoy_use_v2_types)if (pktp->snmp_version != SNMP_VERSION_1) { /* If the packet is tagged as toobig or will be toobig and the pdu isn't BULK we use the alternate pdu which uses a stripped vblist. If the pdu was bulk or the alternate pdu was still too big we discard the packet. */ if ((pktp->pdu.std_pdu.error_status == TOO_BIG) || (bufsize > pktp->maxpkt)) { if (pdu_type == GET_BULK_REQUEST_PDU) { SGRPv2_INC_COUNTER(snmp_stats.snmpSilentDrops); pktp->error_complete(&pktp->pkt_src, &pktp->pkt_dst, 1, pktp->async_cookie); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -