📄 ax_ma.c
字号:
/* ax_ma.c - ax_ma.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_ma.c,v $ * Revision 1.18 2003/01/15 14:05:01 josh * directory structure shifting * * Revision 1.17 2002/11/19 13:48:13 josh * retooling parts of registration process to speed up handling of * ranges * * Revision 1.16 2002/07/11 22:27:08 josh * clean a free memory read in the registration cleanup code * * Revision 1.15 2002/05/30 17:26:51 andre * Add call to AX_RESPONSE_PREPROCESS in envoy_ax_ma_handler() * * Revision 1.14 2002/05/16 21:00:20 tneale * Changed comment and removed wrongly placed "last changed" update * * Revision 1.13 2002/05/16 15:45:58 tneale * Fix the setting of connection_id in ax_ma_register * * Revision 1.12 2002/04/09 14:16:55 tneale * AgentX registration changed from tree to list to better store ranges * * Revision 1.11 2002/04/05 13:49:18 andre * Remove include of axCFg.h; add include of axapi.h. * * Revision 1.8 2002/03/19 21:46:09 tneale * Changed AgentX protocol error codes per RFC2741 * * Revision 1.7 2002/03/18 16:27:43 tneale * Added support for Agentx Session table * * Revision 1.6 2002/03/12 15:50:32 tneale * Added the Registration table of the Agentx MIB * * Revision 1.5 2002/02/22 20:14:59 andre * Initial checkin for AgentX MIB changes * * 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:02 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:40 tneale * Tornado shuffle * * Revision 9.8 2001/04/11 20:12:01 josh * merging changes from the kingfisher branch back onto * the trunk * * Revision 9.7 2001/01/19 22:22:16 paul * Update copyright. * * Revision 9.6.2.3 2001/03/12 22:08:07 tneale * Updated copyright * * Revision 9.6.2.2 2000/10/13 21:17:34 josh * function prototypes and static declarations to eliminate warnings * from the Tornado compiler * * Revision 9.6.2.1 2000/09/27 20:38:51 josh * make sure we free the session even if the send fails in * ax_prep_and_send_query() * * Revision 9.6 2000/03/17 00:18:53 meister * Update copyright message * * Revision 9.5 2000/01/04 02:45:35 sar * The search function in group_by_session() didn't check that an object * had a leaf before trying to reference through the leaf. * * Revision 9.4 1999/09/08 18:31:45 josh * post compc/compl cleanup * * Revision 9.3 1999/05/24 20:12:13 josh * 'compc' and 'compl' have been replaced by 'tcount' and 'tlist' * to avoid C++ compiler errors. * * Revision 9.2 1999/03/30 15:20:17 josh * feature to allow customer-driven context conversion into AgentX * * Revision 9.1 1998/11/30 21:07:54 sar * Modified the timer code to use ENVOY_TIMER_32_Ts to make sure the 32 bit * ids are properly aligned and saved. * * Revision 9.0 1998/10/16 22:10:52 sar * Update version stamp to match release * * Revision 8.9 1998/08/12 04:43:57 sar * Move the initialization routines around some in order to minimize * the amount of code that gets pulled in for init purposes. * * Revision 8.8 1998/08/01 18:25:47 sar * In the setproc and undoproc add a valid tcount to the ax_prep_and_send_query * call so that we get the right errors back. * * Revision 8.7 1998/08/01 17:36:34 sar * Add code to set the type when transferring an ip address * * Revision 8.6 1998/06/19 20:13:47 sar * make sure all files include asn1conf.h and snmp.h to pick up all of * the common code * * Revision 8.5 1998/06/19 16:27:46 josh * modifications to initialize globals in envoy_init() * * Revision 8.4 1998/05/29 17:01:57 josh * cleanup allocation code * * Revision 8.3 1998/04/22 20:53:29 josh * Some modifications for allocating large variables off of the heap * instead of the stack. * * Revision 8.2 1998/02/25 15:21:27 sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 8.1 1998/02/25 04:51:14 sra * Update copyrights. * * Revision 8.0 1997/11/18 00:56:38 sar * Updated revision to 8.0 * * Revision 1.8 1997/11/01 01:19:56 sar * Use a testproc_error instead of a setproc_error * * Revision 1.7 1997/10/31 03:46:49 sar * Rearrange code to deal with finding an unused index and index comparisons * * Revision 1.6 1997/10/30 04:21:31 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.5 1997/10/29 04:11:42 sar * Cleaned up some type mismatches to keep compilers happy * * Revision 1.4 1997/10/22 03:22:47 sar * Moved the infrastructure lock to envoy_init() * * Revision 1.3 1997/10/21 04:48:21 sar * start incrementing counter for duplications * * Revision 1.2 1997/10/21 02:58:25 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: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-------------------01e,12may05,job fix apigen comments01d,18apr05,job update copyright notices01c,16feb05,job apigen for documented APIs01b,04aug04,job dropped connection handling01a,24nov03,job update copyright information*//*DESCRIPTIONThis library contains ax_ma.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/snmp/engine/axapi.h>#include <wrn/wm/util/layout/ldbglue.h>#include <wrn/wm/util/layout/agentx.h>#include <wrn/wm/common/bug.h>/* Macros that are always defined */#define MAX_SUBIDS 128/* Macros that we have defaults for but that the user can change */#ifndef ENVOY_AX_FIND_MIBextern MIBNODE_T mib_root_node;#define ENVOY_AX_FIND_MIB(CON) (EBufferUsed(CON) ? 0 : &mib_root_node)#endif#ifndef ENVOY_AX_MA_AC_ADD#define ENVOY_AX_MA_AC_ADD(PKTP, MIBROOT) GEN_ERR#endif#ifndef ENVOY_AX_MA_AC_REMOVE#define ENVOY_AX_MA_AC_REMOVE(PKTP, MIBROOT) GEN_ERR#endif#ifndef ENVOY_AX_MA_AC_CLEAN#define ENVOY_AX_MA_AC_CLEAN(SESS_ID) #endifextern void ax_testproc(OIDC_T, int, OIDC_T *, SNMP_PKT_T *, VB_T *);extern void ax_setproc(OIDC_T, int, OIDC_T *, SNMP_PKT_T *, VB_T *);extern void ax_getproc(OIDC_T, int, OIDC_T *, SNMP_PKT_T *, VB_T *);extern void ax_nextproc(OIDC_T, int, OIDC_T *, SNMP_PKT_T *, VB_T *);extern bits32_t axConnTblLastChg;extern bits32_t axSessTblLastChg;extern bits32_t axRegTblLastChg;static ENVOY_AX_MA_REGLIST_T *registration_matchlist;/****************************************************************************NAME: ax_ma_registration_matchlist_addPURPOSE: Add a REGLIST type to a list of matching registrationsPARAMETERS: ENVOY_AX_MA_REGLIST_T * the registration to addRETURNS: void****************************************************************************/static void ax_ma_registration_matchlist_add (ENVOY_AX_MA_REGLIST_T *reg){ENVOY_AX_MA_REGLIST_T **nodepptr;/* If there is no payload then there is nothing useful to do so return */ if (!reg) return;/* If this is the first add then the list is empty, * just set the list pointer to this node. */ if (!registration_matchlist) { registration_matchlist = reg; return; }/* Otherwise I need to navigate the list to find the position needed */ for (nodepptr = ®istration_matchlist; *nodepptr; nodepptr = &((*nodepptr)->match)) { if (reg->priority < (*nodepptr)->priority) { reg->match = *nodepptr; *nodepptr = reg; return; } }/* All the way to the end of the list and didn't * find a place, so I'll add it at the end */ *nodepptr = reg;return;}/****************************************************************************NAME: ax_ma_get_registration_matchlistPURPOSE: Makes a list of REGLIST types whose subtree overlaps the given OID. It generates this list by going through the registration list and chaining together those registrations that match.PARAMETERS: OBJ_ID_T * the OID to look for bits32_t index of the context for this registrationRETURNS: pointer to head of list, or 0 if no matches found****************************************************************************/static ENVOY_AX_MA_REGLIST_T * ax_ma_get_registration_matchlist (OBJ_ID_T *objid, bits32_t context_id){ENVOY_AX_MA_REGLIST_T *regptr;int range_index;int remaining;/* OK to set the pointer to 0 initially since there is no allocated memory */registration_matchlist = 0;for (regptr = envoy_ax_registration_list; regptr; regptr = regptr->next) { if ((context_id == regptr->context_id) && (objid->num_components == regptr->start_oid.num_components)) { if (regptr->range_id) { range_index = regptr->range_id - 1; if ((objid->component_list[range_index] < regptr->start_oid.component_list[range_index]) || (objid->component_list[range_index] > regptr->bound)) continue; if ((range_index > 0) && (oidcmp(range_index, objid->component_list, range_index, regptr->start_oid.component_list) == 0)) continue; remaining = regptr->start_oid.num_components - regptr->range_id; if ((remaining > 0) && (oidcmp(remaining, &(objid->component_list[range_index + 1]), remaining, &(regptr->start_oid.component_list[range_index + 1])) == 0)) continue; /* We've found a match... */ ax_ma_registration_matchlist_add (regptr); } else { if (oidcmp (objid->num_components, objid->component_list, regptr->start_oid.num_components, regptr->start_oid.component_list)) ax_ma_registration_matchlist_add (regptr); } } }return (registration_matchlist);}/****************************************************************************NAME: ax_ma_find_matching_registrationPURPOSE: Check if a given OID has already been registered by going through The registration list.PARAMETERS: OBJ_ID_T * the OID to search for bits8_t priority (looking for an exact match) bits8_t index of the context to search in (also exact match) ENVOY_AX_MA_REGLIST_T ** the list, if found RETURNS: 0 if no conflicting registrations are found 1 otherwise****************************************************************************/static int ax_ma_find_matching_registration (OBJ_ID_T *objid, bits8_t priority, bits32_t context_id, ENVOY_AX_MA_REGLIST_T **reglist){ENVOY_AX_MA_REGLIST_T *regptr;*(reglist) = ax_ma_get_registration_matchlist (objid, context_id);for (regptr = (*reglist); regptr; regptr = regptr->match) { if (regptr->priority == priority) return (0); }return (1);}/****************************************************************************NAME: ax_ma_reglist_addPURPOSE: Add a REGLIST type to the registration listPARAMETERS: ENVOY_AX_MA_REGLIST_T * the node to add to the listRETURNS: 0 if success, -1 if failure****************************************************************************/static void ax_ma_reglist_add (ENVOY_AX_MA_REGLIST_T *rp){ENVOY_AX_MA_REGLIST_T **trp;ENVOY_AX_MA_REGLIST_T *thisptr;if (!rp) return;for (trp = &envoy_ax_registration_list; *trp != NULL; trp = &((*trp)->next)) { thisptr = *trp; if ((thisptr->connection_id < rp->connection_id) || ((thisptr->connection_id == rp->connection_id) && ((thisptr->session_id < rp->session_id) || ((thisptr->session_id == rp->session_id) && (thisptr->reg_index < rp->reg_index))))) continue; else { rp->next = *trp; *trp = rp; return; } }/* Have to attach at end of reglist, maybe because this is first registration */*trp = rp;return;}/****************************************************************************NAME: ax_ma_reglist_removePURPOSE: Remove a REGLIST node from the registration list
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -