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

📄 ax_core.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 4 页
字号:
/* ax_core.c - ax_core.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 1994-1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. *//* * $Log: ax_core.c,v $ * Revision 1.5  2002/03/26 18:44:25  josh * modifications to length calculation functions.  If length * exceeds 65535, envoy_ax_pkt_length() now returns 0. * * Revision 1.4  2001/11/06 21:50:43  josh * second (and hopefully final) pass of new path hacking * * Revision 1.3  2001/11/06 21:20:01  josh * revised new path hacking * * Revision 1.2  2001/11/06 20:11:13  josh * updating include paths to include proper path to layout directory * * Revision 1.1.1.1  2001/11/05 17:47:41  tneale * Tornado shuffle * * Revision 9.5  2001/04/11 20:12:01  josh * merging changes from the kingfisher branch back onto * the trunk * * Revision 9.4  2001/01/19 22:22:15  paul * Update copyright. * * Revision 9.3.2.2  2001/03/12 22:08:06  tneale * Updated copyright * * Revision 9.3.2.1  2000/10/13 21:17:33  josh * function prototypes and static declarations to eliminate warnings * from the Tornado compiler * * Revision 9.3  2000/03/17 00:18:51  meister * Update copyright message * * Revision 9.2  1999/10/29 20:54:50  josh * a new option, ENVOY_AGENTX_2257_RANGE, controls whether the range in * registrations and deregistrations is handled according to RFC2257 or * according to the newer way outlined in the soon-to-be RFC that will * obsolete RFC2257 * * Revision 9.1  1999/01/22 18:06:08  josh * replacing a bitwise & with a logical && to fix a range * registration bug * * Revision 9.0  1998/10/16 22:10:49  sar * Update version stamp to match release * * Revision 8.5  1998/08/01 17:39:34  sar * When decoding a 64 bit integer properly handle the two halves * * Revision 8.4  1998/06/19 20:13:46  sar * make sure all files include asn1conf.h and snmp.h to pick up all of * the common code * * Revision 8.3  1998/06/09 21:46:37  sar * Cleaned up some code that might have called alloc or memcmp with * 0 lenght strings * * Revision 8.2  1998/05/24 04:57:50  sar * Correct use of the include flag so that we can ask for and respond * to a request for the named object during a next. * * Revision 8.1  1998/02/25 04:51:08  sra * Update copyrights. * * Revision 8.0  1997/11/18 00:56:37  sar * Updated revision to 8.0 * * Revision 1.3  1997/10/30 04:21:32  sar * Clean up some type information, convert a number of bits16_ts to ALENGTH_Ts, * also add use of MAX_ALENGTH instead of using a number * * Revision 1.2  1997/10/29 04:11:44  sar * Cleaned up some type mismatches to keep compilers happy * * Revision 1.1  1997/10/16 00:32:31  sar * The base files for the agentx protocol. * ax_core.c  - core encoding and decoding routines, both master and sub * ax_chunk.c - transform a byte stream into agentx packets, both * ax_index.c - support for the index reservation scheme, master * ax_ma.c    - master side routines, master * ax_mth.c   - method routines for the agentx mib, master * ax_sa.c    - sub agent side routines, sub * ax_sa_cr.c - packet creation code, mostly will be used on sub * *//* [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 ax_core.c routines.INCLUDE FILES: snmp.h, agentx.h*/#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/agentx.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/vbdefs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/util/layout/ldbglue.h>#include <wrn/wm/util/layout/agentx.h>/* some well know values, this should be placed   elsewhere for more general use */OIDC_T ax_internet_prefix[]   = {1, 3, 6, 1};/********************************************************************************* envoy_ax_pkt_init - initialize an AgentX packet* SYNOPSIS** \cs* void envoy_ax_pkt_init*     ( ENVOY_AX_PKT_T *  ax_pkt *     )* \ce** DESCRIPTION** This routine initializes an AgentX packet. If you used * envoy_ax_pkt_allocate() to create your packet, you do not need to use this * routine.** PARAMETERS* \is* \i <*ax_pkt>* Specify an AgentX packet.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: envoy_ax_pkt_allocate()*/void  envoy_ax_pkt_init(ENVOY_AX_PKT_T * ax_pkt){MEMSET(ax_pkt, 0, sizeof(ENVOY_AX_PKT_T));EBufferInitialize(&ax_pkt->context);}/****************************************************************************\NOMANUALNAME: envoy_ax_pkt_allocatePURPOSE: allocate space for an agent x structure, and initialize itPARAMETERS: noneRETURNS: ENVOY_AX_PKT_T * AgentX packet structure, 0 on failure****************************************************************************/ENVOY_AX_PKT_T *  envoy_ax_pkt_allocate(){ENVOY_AX_PKT_T *ax_pkt;ax_pkt = (ENVOY_AX_PKT_T *)SNMP_memory_alloc(sizeof(ENVOY_AX_PKT_T));if (ax_pkt == 0)  return(0);envoy_ax_pkt_init(ax_pkt);return(ax_pkt);}/****************************************************************************\NOMANUALNAME: envoy_ax_pkt_cleanPURPOSE: free any space associated with an agent x packet.	 this doesn't free the packet itself, use	 envoy_ax_pkt_free to do thatPARAMETERS: ENVOY_AX_PKT_T *RETURNS: none****************************************************************************/void  envoy_ax_pkt_clean(ENVOY_AX_PKT_T *ax_pkt){EBufferClean(&ax_pkt->context);/* if we have an error routine for the cookie we   call it to clean up the cookie */if (ax_pkt->error)    ax_pkt->error(ax_pkt->cookie, 0);    switch(ax_pkt->type) {    case ENVOY_AX_CLOSE:    case ENVOY_AX_COMMIT:    case ENVOY_AX_UNDO:    case ENVOY_AX_CLEANUP:    case ENVOY_AX_PING:    default:        /* nothing to do for this case */        break;    case ENVOY_AX_OPEN:    case ENVOY_AX_ADD_AC:    case ENVOY_AX_REMOVE_AC:	/* get rid of the agent subid and description field from the	   open data block */	Clean_Obj_ID(&ax_pkt->data.open_data.sub_id);	EBufferClean(&ax_pkt->data.open_data.descr);	break;    case ENVOY_AX_REGISTER:    case ENVOY_AX_UNREGISTER:	/* get rid of the region subid from the registration block */	Clean_Obj_ID(&ax_pkt->data.reg_data.region);	break;    case ENVOY_AX_TEST:	if (ax_pkt->data.proc_data.next_error)	  ax_pkt->data.proc_data.next_error(ax_pkt->data.proc_data.next_cookie,					    0);	/* no break, drop into the following list */    case ENVOY_AX_NEXT:    case ENVOY_AX_BULK:    case ENVOY_AX_GET:    case ENVOY_AX_NOTIFY:    case ENVOY_AX_INDEX_ALLOCATE:    case ENVOY_AX_INDEX_DEALLOCATE:    case ENVOY_AX_RESPONSE:	Clean_vb_list(&ax_pkt->data.proc_data.vbl_str);	break;    }}/********************************************************************************* envoy_ax_pkt_free - free the space currently allocated to an AgentX packet* SYNOPSIS** \cs* void envoy_ax_pkt_free*     (*      ENVOY_AX_PKT_T *  ax_pkt *     )* \ce** DESCRIPTION** This routine frees all the space currently allocated to and associated with * an AgentX packet. In a two-step process, releases any resources associated * with the packet and calls SNMP_memory_alloc(), SNMP_memory_free() to free the * actual memory.** PARAMETERS* \is* \i <*ax_pkt>* Specify an AgentX packet.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_memory_alloc(), SNMP_memory_free()*/void  envoy_ax_pkt_free(ENVOY_AX_PKT_T *ax_pkt){if (ax_pkt != 0) {    envoy_ax_pkt_clean(ax_pkt);    SNMP_memory_free(ax_pkt);    }}/****************************************************************************NAME: ax_is_prefixPURPOSE: Determine if the object id should be prefixed.	 It must have 5 or more subids, must be in the internet	 subtree, the 5th subid must be less than 128 (to fit into	 a 1 byte field) and any range subid must be greater than	 5 so it can be reduced by the 5 subids prefixing would remove.PARAMETERS: OBJ_ID_T *	    bits8_t RETURNS: int 1 = do the prefix, 0 = don't****************************************************************************/static int  ax_is_prefix(OBJ_ID_T *objid,	       bits8_t   range_id){if ((objid->num_components >= 5) &&    (objid->component_list[0] == ax_internet_prefix[0]) &&    (objid->component_list[1] == ax_internet_prefix[1]) &&    (objid->component_list[2] == ax_internet_prefix[2]) &&    (objid->component_list[3] == ax_internet_prefix[3]) &&    (objid->component_list[4] > 0 ) &&    (objid->component_list[4] < 128) &&    ((range_id == 0) || (range_id > 5)))    return(1);return(0);}/****************************************************************************NAME: ax_obj_id_sizePURPOSE: Figure out how big an object id will be.	 The object id should be complete (all subids intact, no	 prefix manipulation occurring) and we will return the	 length including the object header but without any	 prefixable subids.	 The length will be 4 + (4 * non-prefix subids).PARAMETERS: OBJ_ID_T *	    bits8_t   RETURNS: ALENGTH_T the required space, 0 indicates problems.****************************************************************************/static bits32_t  ax_obj_id_size(OBJ_ID_T *objid,		 bits8_t   range_id){if (ax_is_prefix(objid, range_id))    return(SIZEOF_AGENTX_OID + (4 * (objid->num_components - 5)));return(SIZEOF_AGENTX_OID + (4 * objid->num_components));}/****************************************************************************NAME: ax_string_sizePURPOSE: Figure out how big a string will be.	 The length will be 4 + strlen + padding bytesPARAMETERS: EBUFFER_T *RETURNS: bits32_t the required space, 0 indicates problems.****************************************************************************/static bits32_t  ax_string_size(EBUFFER_T *ebuffp){bits32_t temp, need;temp = EBufferUsed(ebuffp);need = temp + SIZEOF_AGENTX_OCT_STR;temp = temp%4;if (temp)    need += (4-temp);return(need);}/****************************************************************************NAME: ax_varbind_sizePURPOSE: Figure out how big a varbind will be.	 The length will be 4 + objectid + dataPARAMETERS: VB_T *RETURNS: bits32_t the required space, 0 indicates problems.****************************************************************************/static bits32_t  ax_varbind_size(VB_T *vbp){bits32_t need;need = 4 + ax_obj_id_size(&vbp->vb_obj_id, 0);switch(vbp->vb_data_flags_n_type) {    default:        /* unknown type, shouldn't get here */        return(0);    case VT_NUMBER:    case VT_COUNTER:    case VT_GAUGE:    case VT_TIMETICKS:	need += SIZEOF_AGENTX_UNSIGNED32;	break;    case VT_STRING:    case VT_OPAQUE:	need += ax_string_size(&vbp->value_u.v_string);	break;    case VT_OBJECT:	need += ax_obj_id_size(&vbp->value_u.v_object, 0);	break;    case VT_EMPTY:    case VT_NOSUCHOBJ:    case VT_NOSUCHINS:    case VT_ENDOFMIB:	break;    case VT_IPADDRESS:	need += SIZEOF_AGENTX_OCT_STR + 4;	break;    case VT_COUNTER64:	need += SIZEOF_AGENTX_UNSIGNED64;	break;    }return(need);}/****************************************************************************NAME: ax_varbind_list_sizePURPOSE: Figure out how big a varbind list will be.	 If the varbind pointer isn't 0 we use it as the root	 for the linked list of varbinds we are interested in,	 otherwise we use the list(s) from the vbl.PARAMETERS: VBL_T *	    VB_T *RETURNS: bits32_t the required space, 0 indicates problems.****************************************************************************/static bits32_t  ax_varbind_list_size(VBL_T *vblp,		       VB_T  *vbp){bits32_t need = 0; VB_T *tempvbp;

⌨️ 快捷键说明

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