📄 viewmth.c
字号:
/* * 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: viewmth.c,v $ * Revision 1.2 2001/11/06 21:20:35 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:41 tneale * Tornado shuffle * * Revision 9.5 2001/01/19 22:22:01 paul * Update copyright. * * Revision 9.4 2000/03/17 00:17:50 meister * Update copyright message * * Revision 9.3 2000/03/09 15:34:37 tneale * Added "static" to function prototypes to avoid "No Previous Prototype" warning * * Revision 9.2 1999/05/24 20:12:09 josh * 'compc' and 'compl' have been replaced by 'tcount' and 'tlist' * to avoid C++ compiler errors. * * Revision 9.1 1999/04/09 20:36:58 josh * Obsoleting ENVOY_SNMP_VERSON_USEC and ENVOY_40_VB_FREE_COMPAT * * Revision 9.0 1998/10/16 22:09:59 sar * Update version stamp to match release * * Revision 8.3 1998/08/12 20:33:53 josh * removinga compiler warning * * Revision 8.2 1998/06/05 18:53:01 sra * "#include <foo.h>" => "#include <envoy/h/foo.h>". * * Revision 8.1 1998/02/25 04:50:14 sra * Update copyrights. * * Revision 8.0 1997/11/18 00:56:18 sar * Updated revision to 8.0 * * Revision 7.3 1997/03/20 06:50:31 sra * DFARS-safe copyright text. Zap! * * Revision 7.2 1997/02/25 10:49:26 sra * Update copyright notice, dust under the bed. * * Revision 7.1 1996/12/04 20:45:13 sar * corrected some error codes * tproc_resource_unavailable -> resource_unavailable * no_such_instance -> no_creation * * Revision 7.0 1996/03/15 22:21:24 sar * Updated revision to 7.0 and copyright to 96 * * Revision 1.2 1995/11/11 00:00:48 sar * added snmp_view_destroy_backout which will be called after a * destroy_test succeeds but we need to backout any changes * added viewtable_destory_cleanup as a vb_priv_free to call the destroy * backout macro * added snmp_view_finished which will be called if the packet completes * successfully (so that data can be flushed). * mark the sets & undos as done if we have a request to destroy a view * that doesn't exist * added a return clause in viewtable_set if we can't deinstall a view. * * Revision 1.1 1995/11/01 00:55:20 sar * Initial revision * * Revision 1.1 1995/09/18 19:27:22 sar * Initial revision * *//* [clearcase]modification history-------------------01b,18apr05,job update copyright notices01a,24nov03,job update copyright information*/#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/objectid.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/mib.h>#include <wrn/wm/snmp/engine/view.h>#include <wrn/wm/snmp/engine/auxfuncs.h>extern VIEWINDEX_T *viewroot;#if !defined(SNMP_VIEW_FINISHED)#define SNMP_VIEW_FINISHED#endif#if !defined(SNMP_VIEW_CREATE_HOOK)#define SNMP_VIEW_CREATE_HOOK(NEW)#endif#if !defined(SNMP_VIEW_UPDATE_HOOK)#define SNMP_VIEW_UPDATE_HOOK(OLD, NEW)#endif#if !defined(SNMP_VIEW_DESTROY_HOOK)#define SNMP_VIEW_DESTROY_HOOK(OLD)#endif#if !defined(SNMP_VIEW_BACKOUT_HOOK)#define SNMP_VIEW_BACKOUT_HOOK(NEW)#endif#if !defined(SNMP_VIEW_CREATE_TEST)#define SNMP_VIEW_CREATE_TEST(PKT, NEW) TPROC_GOOD#endif#if !defined(SNMP_VIEW_UPDATE_TEST)#define SNMP_VIEW_UPDATE_TEST(PKT, OLD, NEW) TPROC_GOOD#endif#if !defined(SNMP_VIEW_DESTROY_TEST)#define SNMP_VIEW_DESTROY_TEST(PKT, OLD) TPROC_GOOD#endif/* view table lastmatch values */#define LM_viewIndex 1#define LM_viewSubtree 2#define LM_viewMask 3#define LM_viewType 4#define LM_viewStorageType 5#define LM_viewStatus 6extern MIBLEAF_T viewMask_leaf, viewType_leaf, viewStorageType_leaf;extern MIBLEAF_T viewStatus_leaf;/****************************************************************************NAME: viewtable_destroy_cleanupPURPOSE: Cleanup after a view test (delete) succeeded but some other test failed. We merely call the DESTROY_BACKOUT macro to allow the customer to restore any changed state. Expects a PTR_T or VB_T rather than a VIEWLEAF_TPARAMETERS: PTR_T A pointer to the View to delete or A pointer to the vb that points to the view to delete case as a PTR_TRETURNS: Nothing****************************************************************************/static void viewtable_destroy_cleanup(PTR_T viewptr){#if defined(SNMP_VIEW_DESTROY_BACKOUT)VIEWLEAF_T *view;view = (VIEWLEAF_T *)(((VB_T *)viewptr)->vb_priv);SNMP_VIEW_DESTROY_BACKOUT(view);#endif /* #if defined(SNMP_VIEW_DESTROY_BACKOUT) */}/****************************************************************************NAME: viewtable_test_cleanupPURPOSE: Cleanup after a view test succeeded but some other test failed. Delete the view, free the space and run BACKOUT_HOOK. Expects a PTR_T or VB_T rather than a VIEWLEAF_TPARAMETERS: PTR_T A pointer to the View to delete or A pointer to the vb that points to the view to delete case as a PTR_TRETURNS: Nothing****************************************************************************/static void viewtable_test_cleanup(PTR_T viewptr){VIEWLEAF_T *view;view = (VIEWLEAF_T *)(((VB_T *)viewptr)->vb_priv);/* If this was a create then the same view was installed in the view tree and pointed to by the vb_priv pointer. In this case we need to deinstall the view as we cleanup. */if (SNMP_View_Lookup(view->index, view->subtree.component_list, view->subtree.num_components) == view) SNMP_View_Deinstall(view->index, view->subtree.component_list, view->subtree.num_components);SNMP_VIEW_BACKOUT_HOOK(view);SNMP_View_Delete(view);}/****************************************************************************NAME: viewtable_set_cleanupPURPOSE: Free the given view. Expects a PTR_T or VB_T rather than a VIEWLEAF_TPARAMETERS: PTR_T A pointer to the View to delete or A pointer to the vb that points to the view to delete case as a PTR_TRETURNS: Nothing****************************************************************************/static void viewtable_set_cleanup(PTR_T viewptr){if (viewptr) { SNMP_View_Delete((VIEWLEAF_T *)(((VB_T *)viewptr)->vb_priv)); }SNMP_VIEW_FINISHED;}/****************************************************************************NAME: viewtable_undoPURPOSE: This routine attempts to undo a previous set. It expects the the old information to be pointed to be vb_priv and swaps the old with the new. If vb_priv is empty it means that this was a creation and we deinstall the entry. Finally we delete the new entry.PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processsed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/static void viewtable_undo(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){VIEWLEAF_T *newview, *oldview;oldview = (VIEWLEAF_T *)vbp->vb_priv;newview = SNMP_View_Lookup((UINT_16_T)tlist[0], tlist + 1, tcount -1);/* reset the vb_priv information so we don't have any accidents */vbp->vb_priv = 0;vbp->vb_free_priv = 0;/* If vb_priv is empty then this was a creation so we deinstall and free the entry */if (oldview == 0) { if (newview != 0) {#if defined(SNMP_VIEW_CREATE_UNDO) if (SNMP_VIEW_CREATE_UNDO(newview)) undoproc_error(pktp, vbp, UNDO_FAILED); else#endif { if (SNMP_View_Deinstall((UINT_16_T)tlist[0], tlist + 1, tcount -1) == 0) SNMP_View_Delete(newview); } } }else { /* Otherwise we either modifed the entry (if newparty != 0) or deleted the old entry. For a modification we swap them and free the new block. For a deletion we attempt to reinstall the old block and generate a failure if we can't. */ if (newview) {#if defined(SNMP_VIEW_UPDATE_UNDO) if (SNMP_VIEW_UPDATE_UNDO(oldview, newview)) { undoproc_error(pktp, vbp, UNDO_FAILED); } else#endif { /* copy the old stuff to the new block. we use the new block as it is the one threaded onto the view lists. */ newview->type = oldview->type; newview->storage = oldview->storage; newview->status = oldview->status; EBufferClean(&newview->mask); MEMCPY(&newview->mask, &oldview->mask, sizeof(EBUFFER_T)); EBufferInitialize(&oldview->mask); } SNMP_View_Delete(oldview); } else { if (SNMP_View_Install((UINT_16_T)tlist[0], oldview)) { SNMP_View_Delete(oldview); undoproc_error(pktp, vbp, UNDO_FAILED); }#if defined(SNMP_VIEW_DESTROY_UNDO) else if (SNMP_VIEW_DESTROY_UNDO(oldview)) { undoproc_error(pktp, vbp, UNDO_FAILED); if (SNMP_View_Deinstall((UINT_16_T)tlist[0], tlist + 1, tcount -1) == 0) SNMP_View_Delete(oldview); }#endif } }undoproc_good(pktp, vbp);return;}/****************************************************************************NAME: viewtable_testPURPOSE: This routine collects all of the var binds that want to be set in a row and does value and consistency checking on those varbinds before trying to allocate any space. PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processsed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/void viewtable_test(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){VIEWLEAF_T *view, tempview, *newview;INT_32_T value;int ptret, cago = 0, create_row = 0;ALENGTH_T nlen = 0;VB_T *vbplist, *tvbp, *setvbp;/* The status vb (if it exists) must be the first leaf in the vb chain and the vb for which the set is called for the set routine to work properly. To arrange this it must be the last leaf in the leaves list. */static MIBLEAF_T *leaves[] = {&viewMask_leaf, &viewType_leaf, &viewStorageType_leaf, &viewStatus_leaf, 0}; /* we need an index that is less than 65536 */if ((tcount < 1) || (tlist[0] > VIEW_MAXINDEXL)) { testproc_error(pktp, vbp, NO_CREATION); return; }view = SNMP_View_Lookup((UINT_16_T)tlist[0], tlist + 1, tcount - 1);/* Note that the check for status is simpler than the general case as this table has few objects and all but status have defvals. This means that several conditions can't occur. So create and go is always acceptable and is almost the same as create and wait, active and not in service are also similiar. *//* is the leaf writable, (if it's permanent it isn't writable) */if (view != 0) { if (SNMP_View_Get_StorageType(view) == STO_PERM) { testproc_error(pktp, vbp, NOT_WRITABLE); return; } MEMCPY(&tempview, view, sizeof(VIEWLEAF_T)); }else { SNMP_View_Set_Defaults(&tempview); create_row = 1; } /* now get the list of var binds that may go into this structure */vbplist = vb_extract_row_loose(pktp, vbp_to_index(pktp, vbp), leaves, tcount, tlist);/* Mark the incoming vbp as done, this allows us to return from anywhere in the routine without having to either have many calls to set the done bit or to bring everything into one spot. This is ok because errors will set the correct bits anyway and this routine will not defer so when it returns the vbp will be done. */testproc_good(pktp, vbp);for (setvbp = vbplist, tvbp = vbplist; tvbp; tvbp = tvbp->vb_link) { switch (tvbp->vb_ml.ml_last_match) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -