📄 view_rts.c
字号:
/* view_rts.c - view_rts.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 1995-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. *//* * $Log: view_rts.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:44 tneale * Tornado shuffle * * Revision 9.3 2001/01/19 22:22:31 paul * Update copyright. * * Revision 9.2 2000/03/17 00:19:35 meister * Update copyright message * * Revision 9.1 2000/02/04 21:56:15 josh * functions which are clearly static have been declared as such. * this makes the vxWorks compiler happy. * * Revision 9.0 1998/10/16 22:12:45 sar * Update version stamp to match release * * Revision 8.7 1998/06/20 17:49:45 sar * Modified the names and calling sequences for snmp_rfc2275 functions * * Revision 8.6 1998/06/18 04:35:30 sar * Modify the deinstall routine to take a pointe to a viewleaf_t instead * of the naming info * * Revision 8.5 1998/06/16 05:18:33 sar * tidy up an unreachable return * * Revision 8.4 1998/06/09 21:46:33 sar * Cleaned up some code that might have called alloc or memcmp with * 0 lenght strings * * Revision 8.3 1998/06/05 18:53:26 sra * "#include <foo.h>" => "#include <envoy/h/foo.h>". * * Revision 8.2 1998/05/24 04:28:03 sar * Added code for rfc2275 views and meshed it in with the code for rfc1445. * While the indexing is different the base match is similar so we share * code where possible. In the view check code the function was split * to allow the family to be looked up only once per iteration of get, * next or bulk. * * Revision 8.1 1998/02/25 04:52:57 sra * Update copyrights. * * Revision 8.0 1997/11/18 00:57:06 sar * Updated revision to 8.0 * * Revision 7.2 1997/03/20 06:49:26 sra * DFARS-safe copyright text. Zap! * * Revision 7.1 1997/02/25 10:49:26 sra * Update copyright notice, dust under the bed. * * Revision 7.0 1996/03/18 20:01:11 sar * Updated revision to 7.0 and copyright to 96 * * Revision 1.1 1995/11/11 00:07:30 sar * Initial revision * *//* [clearcase]modification history-------------------01d,12may05,job fix apigen comments01c,18apr05,job update copyright notices01b,23feb05,job apigen for documented APIs01a,24nov03,job update copyright information*//*DESCRIPTIONThis library contains view_rts.c routines.INCLUDE FILES: snmp.h, view.h*//* This file and it's companions contain code to build two slightly different view schemes, rfc1445/1447 and rfc2275. 2275 is specified for v3 and should be used if possible, 1445 is included for backwards compatibility reasons. The differences lie in the naming conventions. 1445 used a single integer followed by an implied oidc as the index 2275 uses a string followed by an (non-implied) oidc. The routines are written to take advantage of common code where possible */#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/view.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#if !defined(SNMP_VIEW_DESTROY_HOOK)#define SNMP_VIEW_DESTROY_HOOK(VIEW)#endif/********************************************************************************* SNMP_View_Create - create and initialize a view* SYNOPSIS** \cs* VIEWLEAF_T * SNMP_View_Create * (* OIDC_T * oidc, * int oidclen * )* \ce** DESCRIPTION** This routine creates a view ('vacmViewTreeFamilyTable') and allocates space * for the new 'VIEWLEAF_T' structure. It initializes the view to the default * values and the specified object Id. Before you can use the newly created * view, you must call SNMP_View_2275_Install() to install it. You can call this * routine during initialization to reconstruct the view table from non-volatile * memory or while the process is running to add new views.** \&NOTE: If you modify a view, the calling routine must ensure two things: no * changes can occur when a packet is using a view and all views must remain in * a consistent state.** Parameters:* \is* \i <*oidc>* Specify the object ID as an 'OIDC' index.* \i <oidclen>* Specify the length of the 'OIDC'.* \ie** RETURNS: If successful, this routine returns a pointer to the newly created * view. Otherwise, it returns a null pointer.** ERRNO: N/A** SEE ALSO: SNMP_View_Delete(), SNMP_View_2275_Install(), SNMP_View_Set_Mask(), * SNMP View Routines*/VIEWLEAF_T * SNMP_View_Create(OIDC_T *oidc, int oidclen){VIEWLEAF_T *view;view = (VIEWLEAF_T *)SNMP_memory_alloc(sizeof(VIEWLEAF_T));if (view == 0) return (0);if (build_object_id(oidclen, oidc, &view->subtree) != 0) { SNMP_memory_free(view); return (0); }SNMP_View_Set_Defaults(view);return(view);}/********************************************************************************* SNMP_View_Delete - free the space associated with the specified <view>* SYNOPSIS** \cs* void SNMP_View_Delete* (* VIEWLEAF_T * view * )* \ce** DESCRIPTION** This routine frees the space associated with the specified <view>. Before you * delete a view, you must call SNMP_View_2275_Deinstall() to remove <view> from * the view table. You can call this routine the process is running to remove * views.** \&NOTE: If you modify a view, the calling routine must ensure two things: no * changes can occur when a packet is using a view and all views must remain in * a consistent state.** Parameters:* \is* \i <*view>* Specify a 'VIEWLEAF_T' structure.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_View_Create(), SNMP_View_2275_Deinstall(), SNMP View Routines*/void SNMP_View_Delete(VIEWLEAF_T *view){if (view == 0) return;Clean_Obj_ID(&view->subtree);EBufferClean(&view->mask);SNMP_memory_free(view);}/********************************************************************************* SNMP_View_Next - find the next view in the database after the specified <view>* SYNOPSIS** \cs* VIEWLEAF_T * * (* SNMP_View_Next( VIEWLEAF_T * view * )* \ce** DESCRIPTION** This routine finds the next view in the database after the specified <view>.** Parameters:* \is* \i <*view>* Specify a 'VIEWLEAF_T' structure. To request the first view, set this value * to 0. This allows you to walk through the database.* \ie** RETURNS: This routine returns a pointer to the next view. If the specified * <view> is the last entry in the database, this routine returns 0.** ERRNO: N/A** SEE ALSO: SNMP_View_Create(), SNMP_View_2275_Name(), SNMP View Routines*/VIEWLEAF_T * SNMP_View_Next(VIEWLEAF_T *view){/* if we don't have a view we get the very first view */if (view == 0) { if (viewroot == 0) return(0); return(viewroot->lexilist); }/* see if we have another view in this family */if (view->lexinext != 0) return(view->lexinext);/* we don't have another view in this family so we find the next family. we follow the parent pointer back and step to the next family */if ((view->parent == 0) || (view->parent->next == 0)) return(0);return(view->parent->next->lexilist);}/********************************************************************************* SNMP_View_Set_Mask - set the mask in the specified <view>* SYNOPSIS** \cs* int SNMP_View_Set_Mask * (* VIEWLEAF_T * view, * OCTET_T * buf, * int buflen * )* \ce** DESCRIPTION** This routine sets the mask in the specified <view>. If necessary, this * routine can allocate more space and free the current space.** Parameters:* \is* \i <*view>* Specify a 'VIEWLEAF_T' structure.* \i <*buf>* Point to the new mask.* \i <buflen>* Specify the length in bytes of the new mask.* \ie** RETURNS: If successful, this routine returns 0. Otherwise, it returns -1.** ERRNO: N/A** SEE ALSO: SNMP_View_Create(), SNMP_View_2275_Install(), SNMP View Routines*/int SNMP_View_Set_Mask(VIEWLEAF_T *view, bits8_t *buf, int buflen){if ((buflen < 0) || (buflen > 16)) return(-1);/* copy the new mask into the old mask area */return(EBufferReplace(&view->mask, buf, (ALENGTH_T)buflen));}/****************************************************************************NAME: install_view_in_masksPURPOSE: install the given view in the mask listPARAMETERS: VIEWINDEX_T * the index to add the view to VIEWLEAF_T * The view to stick in the view areaRETURNS: int Success = 0, Failure = non zero****************************************************************************/static int install_view_in_masks(VIEWINDEX_T *vindex, VIEWLEAF_T *view){VIEWLEAF_T **vpp;int order;for(vpp = &(vindex->masklist); *vpp; vpp = &((*vpp)->masknext)) { if (view->subtree.num_components > (*vpp)->subtree.num_components) break; if (view->subtree.num_components == (*vpp)->subtree.num_components) { order = oidcmp2(view->subtree.num_components, view->subtree.component_list, view->subtree.num_components, (*vpp)->subtree.component_list); if (order == 1) break; if (order == 0) return(-1); } }view->masknext = *vpp;*vpp = view;return(0);}#if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS)/* We use these functions if rfc1445 is installed, we have another set for use with rfc2275, see below *//****************************************************************************NAME: remove_view_from_masksPURPOSE: find the requested view in the mask list. the mask list is ordered by number of components (largest first) then by oid (lexi last first). So if we find a size less than ours, ours doesn't exist and we are done.PARAMETERS: VIEWINDEX_T * the index to remove the view from OIDC_T * The component list of the subtree int The length of the component listRETURNS: int Success = 0, Failure = non zero****************************************************************************/static int remove_view_from_masks(VIEWINDEX_T *vindex, OIDC_T *oidc, int oidclen){VIEWLEAF_T **vpp;for(vpp = &(vindex->masklist); *vpp && (oidclen <= (*vpp)->subtree.num_components); vpp = &((*vpp)->masknext)) { if (oidcmp2(oidclen, oidc, (*vpp)->subtree.num_components, (*vpp)->subtree.component_list) == 0) { /* unlink the view */ SNMP_VIEW_DESTROY_HOOK(*vpp); (*vpp)->parent = 0; *vpp = (*vpp)->masknext; return(0); } }return(-1);}/****************************************************************************\NOMANUALNAME: SNMP_View_InstallPURPOSE: Given a view, index and objid install the view in the view areaPARAMETERS: bits16_t The view index VIEWLEAF_T * The view to stick in the view areaRETURNS: int Success = 0, Failure = non zero****************************************************************************/int SNMP_View_Install(bits16_t indx, VIEWLEAF_T *view){VIEWINDEX_T *vindex, **ipp;VIEWLEAF_T **vpp;int order;/* look through the index list, if we can't find an index create one and link the view to it and it into the list. */ipp = &viewroot;while (1) { if ((*ipp == 0) || ((*ipp)->index > indx)) { vindex = (VIEWINDEX_T *)SNMP_memory_alloc(sizeof(VIEWINDEX_T)); if (vindex == 0) return(-1); vindex->next = *ipp; *ipp = vindex; vindex->index = indx; vindex->lexilist = view; vindex->masklist = view; view->parent = vindex; view->index = indx; return(0); } if ((*ipp)->index == indx) break; ipp = &((*ipp)->next); }/* the index already exists */vindex = *ipp;/* install the view in the masklist */if (install_view_in_masks(vindex, view)) return(-1);/* install the view in the lexilist */for(vpp = &(vindex->lexilist); *vpp; vpp = &((*vpp)->lexinext)) { order = oidcmp2(view->subtree.num_components, view->subtree.component_list, (*vpp)->subtree.num_components, (*vpp)->subtree.component_list); if (order == -1) break; if (order == 0) return(-1); }view->lexinext = *vpp;*vpp = view;/* attach the backpointer to the index leaf for admin purposes */view->parent = vindex;view->index = indx;return(0);}/****************************************************************************\NOMANUALNAME: SNMP_View_NamePURPOSE: Given a view get it's name (oidc)PARAMETERS: VIEWEAF_T * A pointer to the view bits16_t * The index of the view
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -