📄 ax_sa.c
字号:
/* ax_sa.c - ax_sa.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_sa.c,v $ * Revision 1.4 2003/01/15 14:05:01 josh * directory structure shifting * * Revision 1.3 2001/11/06 21:50:44 josh * second (and hopefully final) pass of new path hacking * * Revision 1.2 2001/11/06 21:20:03 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:41 tneale * Tornado shuffle * * Revision 9.6 2001/04/11 20:42:57 josh * merge from the kingfisher branch * * Revision 9.5 2001/01/19 22:22:17 paul * Update copyright. * * Revision 9.4 2000/06/13 21:02:05 josh * fix a small program blocking bug * * Revision 9.3.2.3 2001/03/12 22:08:08 tneale * Updated copyright * * Revision 9.3.2.2 2000/10/13 21:17:35 josh * function prototypes and static declarations to eliminate warnings * from the Tornado compiler * * Revision 9.3.2.1 2000/08/30 22:21:46 josh * fixed a set of missing {}, changed a timeout check from * '>' to '>=', and fixed a flag check in undo processing * * Revision 9.3 2000/03/17 00:18:55 meister * Update copyright message * * Revision 9.2 1999/10/18 21:08:30 sar * change the packet type to "response" before calling the error routine * in several places * * Revision 9.1 1999/09/09 19:43:21 sar * Clean the object id before doing the first find next, this avoids * losing memory if we cloned the object previously for the find object * * Revision 9.0 1998/10/16 22:10:56 sar * Update version stamp to match release * * Revision 8.6 1998/08/12 04:44:00 sar * Move the initialization routines around some in order to minimize * the amount of code that gets pulled in for init purposes. * * Revision 8.5 1998/06/19 20:13:48 sar * make sure all files include asn1conf.h and snmp.h to pick up all of * the common code * * Revision 8.4 1998/05/29 17:02:59 josh * Update the locking code to use the new macro * * Revision 8.3 1998/05/24 04:57:51 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.2 1998/02/25 15:21:29 sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 8.1 1998/02/25 04:51:17 sra * Update copyrights. * * Revision 8.0 1997/11/18 00:56:39 sar * Updated revision to 8.0 * * Revision 1.6 1997/11/01 01:20:40 sar * Change the default timeout to 1 second from the testing 10 second period * * Revision 1.5 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.4 1997/10/29 04:11:43 sar * Cleaned up some type mismatches to keep compilers happy * * Revision 1.3 1997/10/22 03:19:01 sar * Tidy up some incorrect variable names * * Revision 1.2 1997/10/21 02:58:26 sar * Move some of the macro defintions out to the port files, * Also move the leaf decrement function to vb_rtns * * Revision 1.1 1997/10/16 00:32:33 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_sa.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/snmpdefs.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/common/bug.h>extern void envoy_ax_sa_test_pdu(SNMP_PKT_T *);extern void envoy_ax_sa_get_pdu(SNMP_PKT_T *);extern void envoy_ax_sa_next_pdu(SNMP_PKT_T *);extern void envoy_ax_sa_undo_pdu(SNMP_PKT_T *);#if (!defined(ENVOY_AX_SA_MIB_ROOT_NODE))#define ENVOY_AX_SA_MIB_ROOT_NODE(CKE, PKT) 0#endif/****************************************************************************NAME: ax_sa_timeoutPURPOSE: routine to try and cleanup set requests if a timeout occurs we walk through the list of sets and see if any are in a done state (test or set done) and have their timer expired. There should be at most one of these.PARAMETERS: ENVOY_TIMER_T * void * pointer to the state blockRETURNS: void****************************************************************************/static void ax_sa_timeout(ENVOY_TIMER_T *tm, void *cookie){ENVOY_AX_PKT_T **ax_pktp, *set_pkt = 0;ENVOY_AX_SA_SB_T *sasb = (ENVOY_AX_SA_SB_T *)cookie;#if INSTALL_ENVOY_SNMP_LOCK/* We don't have any good options if we can't get the lock. So we require the user to not do that, if they do we generate a bug report and if they don't handle that we return which is the least bad thing to do. */if (ENVOY_SNMP_GET_WRITE_LOCK(sasb->list_lock)) { BUG(BUG_ENVOY_LOCKING, BUG_FATAL, 0, (BUG_OUT, "ax_sa_timeout(): locking for list lock is broken", 0)); return; }#endiffor (ax_pktp = &sasb->set_list; *ax_pktp; ax_pktp = &(*ax_pktp)->next) { if ((ENVOY_NOW() - (*ax_pktp)->ts) >= envoy_ax_sa_timeout) { if ((*ax_pktp)->data.proc_data.cur_phase == VFLAG_TEST_DONE) { set_pkt = *ax_pktp; *ax_pktp = set_pkt->next; break; } else if ((*ax_pktp)->data.proc_data.cur_phase == VFLAG_SET_DONE) { set_pkt = *ax_pktp; (*ax_pktp)->data.proc_data.cur_phase = VFLAG_UNDO_STARTED; break; } } }ENVOY_SNMP_RELEASE_WRITE_LOCK(sasb->list_lock);if (set_pkt) { if (set_pkt->data.proc_data.cur_phase == VFLAG_TEST_DONE) { set_pkt->error(set_pkt->cookie, ENVOY_AX_SESS_LOSS); set_pkt->error = 0; SNMP_Free(set_pkt->pktp); envoy_ax_pkt_free(set_pkt);#if (INSTALL_ENVOY_SNMP_SERIALIZE) (void) envoy_tm_set(&sasb->defer, 0);#endif /* (INSTALL_ENVOY_SNMP_SERIALIZE) */ } else {#if (INSTALL_ENVOY_CONTINUE_REENTRANT) /* If necessary we acquire the packet continue write lock here It gets freed when we call the continue routine. We don't have any good options if we can't get the lock. The user shouldn't do that, if they do we generate a bug report and if they don't handle that we return which is the least bad thing to do. */ if (ENVOY_SNMP_GET_WRITE_LOCK(set_pkt->pktp->continue_lock)) { BUG(BUG_ENVOY_LOCKING, BUG_FATAL, 0, (BUG_OUT, "ax_sa_timeout(): packet continue lock is broken", 0)); return; }#endif envoy_ax_sa_undo_pdu(set_pkt->pktp); return; } }}/****************************************************************************NAME: ax_sa_run_deferredsPURPOSE: try to run any deferred operationsPARAMETERS: ENVOY_TIMER_T * void * the state blockRETURNS: void****************************************************************************/static void ax_sa_run_deferreds(ENVOY_TIMER_T *tm, void *cookie){ENVOY_AX_SA_SB_T *sb = (ENVOY_AX_SA_SB_T *)cookie;ENVOY_AX_PKT_T *ax_pkt;SNMP_PKT_T *pktp;if (sb->readers) return;if (sb->set_list) { sb->set_list->data.proc_data.cur_phase = VFLAG_TEST_STARTED; envoy_ax_sa_test_pdu(sb->set_list->pktp); return; }if (sb->gnb_list) { ax_pkt = sb->gnb_list; sb->gnb_list = ax_pkt->next; pktp = ax_pkt->pktp; sb->readers++; if (ax_pkt->type == ENVOY_AX_GET) { pktp->pdu_type = GET_REQUEST_PDU; envoy_ax_sa_get_pdu(pktp); return; } else if (ax_pkt->type == ENVOY_AX_NEXT) pktp->pdu_type = GET_NEXT_REQUEST_PDU; else pktp->pdu_type = GET_BULK_REQUEST_PDU; envoy_ax_sa_next_pdu(pktp); }}/********************************************************************************* envoy_ax_sa_state_init - initialize the subagent state block* SYNOPSIS** \cs* void envoy_ax_sa_state_init* (* ENVOY_AX_SA_SB_T * sasb * )* \ce** DESCRIPTION** This routine initializes the subagent state block <sasb> to a known state.** PARAMETERS* \is* \i <*sasb>* Specify the subagent state block associated with this subagent.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: envoy_ax_sa_state_create(), envoy_ax_sa_handler(), * envoy_ax_sa_session_loss(), 'ENVOY_AX_SA_MIB_ROOT_NODE()'*/void envoy_ax_sa_state_init(ENVOY_AX_SA_SB_T *sb){sb->set_list = 0;sb->gnb_list = 0;sb->readers = 0;envoy_tm_init(&sb->ager);sb->ager.cookie = (void *)sb;sb->ager.handler = ax_sa_timeout;envoy_tm_init(&sb->defer);sb->defer.cookie = (void *)sb;sb->defer.handler = ax_sa_run_deferreds;#if INSTALL_ENVOY_SNMP_LOCKENVOY_SNMP_INIT_LOCK_TAG(sb->list_lock, ENVOY_AXLISTLOCK_TAG);ENVOY_SNMP_INIT_LOCK_TAG(sb->coarse_lock, ENVOY_AXCOARSELOCK_TAG);#endif}/********************************************************************************* envoy_ax_sa_state_create - allocate space for a subagent state block* SYNOPSIS** \cs* ENVOY_AX_SA_SB_T * envoy_ax_sa_state_create* (* void * )* \ce** DESCRIPTION** This routine allocates space for a subagent state block and, if successful, * initializes it.** PARAMETERS* None.** RETURNS: If successful, this routine returns a pointer to the created state * block. Otherwise, it returns 0.** ERRNO: N/A** SEE ALSO: envoy_ax_sa_handler(), envoy_ax_sa_state_init(), * envoy_ax_sa_session_loss(), 'ENVOY_AX_SA_MIB_ROOT_NODE()'*/ENVOY_AX_SA_SB_T * envoy_ax_sa_state_create(void){ENVOY_AX_SA_SB_T *sb;sb = (ENVOY_AX_SA_SB_T *)(SNMP_memory_alloc(sizeof(ENVOY_AX_SA_SB_T)));if (sb) envoy_ax_sa_state_init(sb);return(sb);}/********************************************************************************* envoy_ax_sa_session_loss - clean up any deferred or pending operations* SYNOPSIS** \cs* int envoy_ax_sa_session_loss* ( * ENVOY_AX_SA_SB_T * sasb, * ptr_t cookie, * int sflag, * bits32_t session_id * )* \ce** DESCRIPTION** This routine cleans up any deferred or outstanding operations due to a * connection or session loss. After it examines the connections and sessions * associated with the subagent state block, this routine removes or tags * operations as necessary.* If <cookie> exists and <sflag> is 0, this routine verifies that this is the * correct connection by calling 'ENVOY_AX_COOKIE_CMP() 'to determine whether * <cookie> matches the saved information block given to envoy_ax_sa_handler(). * It checks each connection listed for this session until it finds a match.* Before it actually removes a session, this routine attempts to send a close * message to the master agent providing the error code 'ENVOY_AX_SESS_LOSS' as * the reason for closing.** PARAMETERS* \is* \i <*sasb>* Specify the subagent state block associated with this subagent.* \i <cookie>* Specify the connection.* \i <sflag>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -