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

📄 ax_chunk.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* ax_chunk.c - ax_chunk.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_chunk.c,v $ * Revision 1.4  2001/11/06 21:50:42  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:12  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.2  2001/01/19 22:22:15  paul * Update copyright. * * Revision 9.1  2000/03/17 00:18:51  meister * Update copyright message * * Revision 9.0  1998/10/16 22:10:47  sar * Update version stamp to match release * * Revision 8.3  1998/08/01 17:38:15  sar * When adding to an already started buffer use ebuffernext instead * of ebufferstart to get the pointer to the proper space. * * Revision 8.2  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.1  1998/02/25 04:51:06  sra * Update copyrights. * * Revision 8.0  1997/11/18 00:56:36  sar * Updated revision to 8.0 * * Revision 1.3  1997/10/30 04:21:30  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:32  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_chunk.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/tree.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/util/layout/ldbglue.h>#include <wrn/wm/util/layout/agentx.h>/********************************************************************************* envoy_ax_chunk_init - initialize <chunk> to a known empty state* SYNOPSIS** \cs* void envoy_ax_chunk_init*     ( *     ENVOY_AX_CHUNK_T *  chunk *     )* \ce** DESCRIPTION** This routine initializes <chunk> to a known empty state. It is your * responsibility to allocate <chunk>.** \&NOTE: If you run AgentX over a stream based transport layer, you can use * this routine to convert to packets for use with the Envoy AgentX API.** PARAMETERS* \is* \i <*chunk>* Specify the structure that holds the incoming information. Envoy uses this * structure to hold data from a stream until a full packet has been collected.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: envoy_ax_chunk_clean(), envoy_ax_chunk_handler()*/void  envoy_ax_chunk_init(ENVOY_AX_CHUNK_T *chunk){EBufferInitialize(&chunk->chunk);}/********************************************************************************* envoy_ax_chunk_clean - free any resources associated with <chunk>* SYNOPSIS** \cs* int envoy_ax_chunk_clean*     ( *     ENVOY_AX_CHUNK_T *  chunk*     )* \ce** DESCRIPTION** This routine frees any resources associated with <chunk>.** \&NOTE: If you run AgentX over a stream based transport layer, you can use * this routine to convert to packets for use with the Envoy AgentX API.** PARAMETERS* \is* \i <*chunk>* Specify the structure that holds the incoming information. Envoy uses this * structure to hold data from a stream until a full packet has been collected.* \ie** RETURNS: If the packet did not need to be cleaned, this routine returns 0. If * this routine actually freed some memory, it returns 1.** ERRNO: N/A** SEE ALSO: envoy_ax_chunk_handler(), envoy_ax_chunk_init()*/int  envoy_ax_chunk_clean(ENVOY_AX_CHUNK_T *chunk){if (EBufferStart(&chunk->chunk)) {    EBufferClean(&chunk->chunk);    return(1);    }return(0);}/********************************************************************************* envoy_ax_chunk_handler - assemble bytes from a byte stream into a packet buffer* SYNOPSIS** \cs* int envoy_ax_chunk_handler*     ( *     bits8_t            *  pkt_str, *     ALENGTH_T             pkt_len, *     ENVOY_AX_HANDLER_T *  handler, *     ENVOY_AX_CHUNK_T   *  chunk, *     ENVOY_AX_SA_SB_T   *  sasb, *     ENVOY_AX_ADMIN_T   *  admin_rtn, *     ENVOY_AX_SEND_T    *  send_rtn, *     ENVOY_AX_ERROR_T   *  error_rtn, *     ENVOY_AX_ADD_T     *  add_rtn, *     ptr_t                 send_cookie *     )* \ce** DESCRIPTION** This routine assembles bytes from a byte stream into a packet buffer and * calls the AgentX packet handler. This routine passes <sasb>, <admin_rtn>, * <send_rtn>, <error_rtn>, and <send_cookie> directly to the handler.** \&NOTE: If you run AgentX over a stream based transport layer, you can use * this routine to convert to packets for use with the Envoy AgentX API.** PARAMETERS* \is* \i <*pkt_str>* Specify an incoming message buffer to add to the contents of <chunk> and * process.* \i <pkt_len>* Specify the length in bytes of <pkt_str>.* \i <*handler>* Specify either the subagent handler, envoy_ax_sa_handler(), or the master * agent handler, envoy_ax_ma_handler().* \i <*chunk>* Specify the structure that holds the incoming information. Envoy uses this * structure to hold data from a stream until a full packet has been collected.* \i <*sasb>* Specify the subagent state block associated with this subagent. This value * should be 0 for master agents.* \i <*admin_rtn>* Specify a customer-provided routine that is called when an 'OPEN' PDU * establishes that the session is open or when an AgentX 'TRAP' PDU is * received.* \i <*send_rtn>* Specify a customer-provided routine that is called to send packets.* \i <*error_rtn>* Specify a customer-provided routine that is called to handle errors.* \i <*add_rtn>* Specify a customer-provided routine that is called to update the reference * counter. <add_rtn> is called once for each call to the handler.* \i <send_cookie>* Specify the cookie, which might contain an address for UDP or a pointer to a * TCP block.* \ie** RETURNS: If successful, this routine returns 0. Otherwise, it returns 1.** ERRNO: N/A** SEE ALSO: envoy_ax_chunk_clean(), envoy_ax_chunk_init(), * envoy_ax_ma_handler(), envoy_ax_sa_handler(), ENVOY_AX_ADD_T(), * ENVOY_AX_ADMIN_T(), ENVOY_AX_ERROR_T(), ENVOY_AX_SEND_T()*/int  envoy_ax_chunk_handler(bits8_t            * pkt_str,			 ALENGTH_T            pkt_len,			 ENVOY_AX_HANDLER_T * handler,			 ENVOY_AX_CHUNK_T   * chunk,			 ENVOY_AX_SA_SB_T   * sb,			 ENVOY_AX_ADMIN_T   * admin_rtn,			 ENVOY_AX_SEND_T    * send_rtn,			 ENVOY_AX_ERROR_T   * error_rtn,			 ENVOY_AX_ADD_T     * add_rtn,			 ptr_t                send_cookie){bits32_t tneed;ALENGTH_T eused, need;bits8_t *bufp;EBUFFER_T *ebp = &chunk->chunk;while(pkt_len) {    eused = EBufferUsed(ebp);    if (eused == 0) {        /* no bytes from a previous call	   we default need to size of an agentx header then	   we check the size of the packet if its longer than	   the header we dig out the encoded size of the packet.	   if we have the entire packet we call the handler	   then adjust the packet info and continue in case	   we have another packet	   if not we allocate space for the packet - either	   for the header or for the entire packet if we	   know how long it is. */        tneed = need = SIZEOF_AGENTX_PDU;        if (pkt_len >= SIZEOF_AGENTX_PDU) {	    /* we have the entire header at least */	    if ((GET_AGENTX_PDU_FLAGS(pkt_str)) & ENVOY_AX_BIT_BYTE_ORDER)	        tneed += GET_AGENTX_PDU_PAYLOAD_LEN_B(pkt_str);	    else	        tneed += GET_AGENTX_PDU_PAYLOAD_LEN_L(pkt_str);	    if (tneed > MAX_ALENGTH)	        return(1);	    need = (ALENGTH_T)(tneed & MAX_ALENGTH);	    if (need <= pkt_len) {	        add_rtn(send_cookie);		handler(pkt_str, pkt_len, sb, admin_rtn,			send_rtn, error_rtn, send_cookie);		pkt_len -= need;		pkt_str += need;		continue;	        }	    }		bufp = (bits8_t *)SNMP_memory_alloc(need);	if (bufp == 0)	    return(1);	add_rtn(send_cookie);	EBufferSetup(BFL_IS_DYNAMIC, ebp, bufp, need);	MEMCPY(bufp, pkt_str, pkt_len);	EBufferSeek(ebp, pkt_len, 1);	return(0);        }    else {        /* we have bytes from some previous call.	   we first figure out what we previously allocated	   if it was just space for the header we try to fill	   it up, if we can do so we work out the full packet	   size and allocate space for it.	   if we already know the full packet size we copy	   bytes until we fill up that size then call the handler	   routine */        if ((EBufferUsed(ebp) + EBufferRemaining(ebp)) == SIZEOF_AGENTX_PDU) {	    if ((eused + pkt_len) < SIZEOF_AGENTX_PDU) {	        MEMCPY(EBufferNext(ebp), pkt_str, pkt_len);		EBufferSeek(ebp, pkt_len, 1);		return(0);	        }	    else {	        need = EBufferRemaining(ebp);	        MEMCPY(EBufferNext(ebp), pkt_str, need);		pkt_len -= need;		pkt_str += need;		bufp = EBufferStart(ebp);		tneed = SIZEOF_AGENTX_PDU;		if ((GET_AGENTX_PDU_FLAGS(bufp)) & ENVOY_AX_BIT_BYTE_ORDER)		    tneed += GET_AGENTX_PDU_PAYLOAD_LEN_B(bufp);		else		    tneed += GET_AGENTX_PDU_PAYLOAD_LEN_L(bufp);		if (tneed > MAX_ALENGTH) {		    EBufferClean(ebp);		    return(1);		    }		need = (ALENGTH_T)(tneed & MAX_ALENGTH);		bufp = (bits8_t *)SNMP_memory_alloc(need);		if (bufp == 0) {		    EBufferClean(ebp);		    return(1);		    }		MEMCPY(bufp, EBufferStart(ebp), SIZEOF_AGENTX_PDU);		EBufferClean(ebp);		EBufferSetup(BFL_IS_DYNAMIC, ebp, bufp, need);		EBufferSeek(ebp, SIZEOF_AGENTX_PDU, 1);	        }	    }	need = EBufferRemaining(ebp);	if (pkt_len >= need) {	    MEMCPY(EBufferNext(ebp), pkt_str, need);	    pkt_len -= need;	    pkt_str += need;	    add_rtn(send_cookie);	    handler(EBufferStart(ebp), EBufferUsed(ebp) + need,		    sb, admin_rtn, send_rtn, error_rtn, send_cookie);	    EBufferClean(ebp);	    error_rtn(send_cookie, 0);	    continue;	    }	else {	    MEMCPY(EBufferNext(ebp), pkt_str, pkt_len);	    EBufferSeek(ebp, pkt_len, 1);	    return(0);	    }        }    }return(0);}

⌨️ 快捷键说明

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