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

📄 ospf_mib_envoy_api.c

📁 vxworks下ospf协议栈
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ospf_mib_envoy_api.c *//* Copyright 1998-2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02f,04jun03,asr Changed back to use system memory instead of OSPF memory partition02e,02jun03,agi Added #include "ospf.h"02d,02jun03,ram Changed native memory usage to OSPF memory partition02c,21may03,kc  Modified ospf_envoy_processScalarGetResp() and                 ospf_envoy_processGetResp() to invoke nextproc_no_next()                 if received MAPI_NO_SUCH_OBJECT or MAPI_NO_SUCH_INSTANCE                exception from OSPF MIB API.01c,07apr03,xli    remove the unnecessary file "install.h02b,19nov02,mwv Merge TMS code SPR 8428402a,08oct02,agi Fixed compiler warnings01j,21may02,kc  Fixed ospf_envoy_buildGetReq() to correctly check for the number                of octet string that has been processed.01i,21may02,kc  Modified ospf_envoy_mApiInit() to create an array of ulong_t for                object cookie. Modified ospf_envoy_mApiDestroy() to free up the                pointer to the array of object cookie. Explicitly zero out the                array of object cookie in ospf_envoy_clearBuffer(). Modified                 ospf_envoy_buildSetReq() to correctly set the object cookie                 indicating if the object processed is the last object in the                varbind list.01h,15apr02,kc  Modified ospf_envoy_buildSetReq() - rename pCookie to pReqCookie                due to mibApi.h update. Explicitly set pObjCookie to NULL.01g,04feb02,kc  Corrected debug statement for ospf_envoy_mApiInit().01f,10dec01,kc  Fixed callout to nextproc_next_instance() in                 ospf_envoy_processScalarGetResp().01e,25oct01,kc  Added ospf_envoy_setGenError(), ospf_envoy_setNoSuchNameError(),                ospf_envoy_processGetRespError() prototypes.01f,26oct01,kc  Added ospf_envoy_processScalarGetResp() to process MIB API response                for scalar objects.01e,25oct01,kc  Fixed ospf_envoy_buildSetReq() so that it will not retrieve the                pCookie from request message if tcount = 1.01d,24oct01,kc  Fixed ospf_envoy_processGetResp() to correctly process varbinds.01c,22oct01,kc  Added ospf_envoy_snmpdTreeAdd(), ospf_envoy_snmpdTreeRemove() and                ospf_envoy_oidStrToArray() functions.01b,16oct01,kc  Added ospf_envoy_buildGetReq() routine.01a,12oct01,kc  Initial file creation.*//*DESCRIPTIONThis module contains functions that are used to interpret Envoy SNMP varbindsand the MIB API request structures. The intention of this module is to provide an abstraction layer that provides the facility to manipulate the Envoy SNMP varbinds and the MIB API request data strucuture.*//* This include is here to get rid of the "empty file" compiler warning */#include <vxWorks.h>#if defined (__OSPF_MIB__)/* Envoy SNMP includes */#include <buffer.h>#include <snmpdefs.h>#include <auxfuncs.h>/* vxWorks standard includes */#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include "semLib.h"#include "lstLib.h"/* ospf management interface includes */#include "mibApi.h"#include "ospf.h"#include "ospf_mib_envoy_api.h"/* OSPF OID will never exceed 128 */#define MAX_OSPF_OID_LEN       128/******************************************************************************** ospf_envoy_oidStrToArray - Convert oid in string form to oid component array** Convert an oid in string form <pOidStr> to an array of oid components,* <pOidArray> which is a user supplied array and must be of sufficient size.** RETURNS: 0 on failure else number of oid components in the array** NOMANUAL*/LOCAL int ospf_envoy_oidStrToArray( char *pOidStr, OIDC_T *pOidArray ){    int           oidLen = 0;    char *        pIx;    for (pIx = pOidStr; pIx != NULL; ++ pIx )    {        if ( !isdigit( (int)*pIx ))        {            /* Non digit char where we stop must be either '.' or EOS.             * Also when we stop at one of these it must not be the first             * char encountered. This could happen for example if we heve             * 2 consecutive '.' chars in the input or it starts with a '.'.             *             */            if ( (*pIx != '.' && *pIx != EOS) || pIx == pOidStr)            {                ospfEnvoyPrintf(("ospf_envoy_oidStrToArray:Invalid OID syntax\n"));                return (0);            }            pOidArray [oidLen ++] = atol (pOidStr);            if (*pIx == EOS)                break;            pOidStr = pIx + 1;        }    }    return (oidLen);}/******************************************************************************** ospf_envoy_getVbCount - Counts the number of varbinds** This routine count the number of varbinds in the list.** RETURNS: total varbinds in the list** NOMANUAL*/LOCAL int ospf_envoy_getVbCount( VB_T *vbp ){    VB_T *tvbp;    int cnt;    for (cnt = 0, tvbp = vbp; tvbp; tvbp = tvbp->vb_link, cnt++);    return cnt;}/***************************************************************************** getproc_nosuchobj - Set an exception on error in packet** Routine to tag a variable as either a nosuchobj exception in v2* or a nosuchname error in v1.** RETURNS: N/A** NOMANUAL*/LOCAL void getproc_nosuchobj( SNMP_PKT_T *pktp, VB_T *vbp ){    if (pktp->snmp_version == SNMP_VERSION_1)    {        pktp->pdu.std_pdu.error_status = NO_SUCH_NAME;        pktp->pdu.std_pdu.error_index = vbp_to_index(pktp, vbp) + 1;    }    else        vbp->vb_data_flags_n_type = VT_NOSUCHOBJ;    vbp->vb_flags |= VFLAG_GET_DONE;}/************************************************************************************* ospf_envoy_exceptionSet - Set an exception in packet** Routine to tag a variable as either a nosuchobj exception in v2* or a nosuchname error in v1** RETURNS: Envoy SNMP Error Status** NOMANUAL*/LOCAL void ospf_envoy_exceptionSet( SNMP_PKT_T *pktp, VB_T *vbp, mApiException_t exception ){    switch( exception )    {        case MAPI_NO_SUCH_OBJECT:            getproc_nosuchobj( pktp, vbp );            break;        case MAPI_NO_SUCH_INSTANCE:            getproc_nosuchins (pktp, vbp);            break;        case MAPI_NO_EXCEPTION:        case MAPI_END_OF_MIB_VIEW:        case MAPI_BUFFER_TOO_SHORT:            break;    }    return;}/**************************************************************************************** ospf_envoy_getValue - retrieve the values of the variables** This routine retrieve the values of the variables and write the values into the* varbind using the getproc_get_xxx routines. The getproc_get_xxx routine also* set a flag to indicate the varbind has been processed.** RETURNS: NO_ERROR or GEN_ERR** ERRNO: none** NOMANUAL*/LOCAL STATUS ospf_envoy_getValue( SNMP_PKT_T *pktp, VB_T *vbp, mApiObject_t *pObject,                                  envoyRequest_t *pEnvoyReq ){    OCTET_T data_type;    /* converts the mip api exception to snmp exception */    if ( pObject->exception != MAPI_NO_EXCEPTION )    {        ospf_envoy_exceptionSet( pktp, vbp, pObject->exception );        return OK;    }    data_type = vbp->vb_ml.ml_leaf->expected_tag;    switch( data_type )    {        case VT_IPADDRESS:            getproc_got_ip_address( pktp, vbp, *(UINT_32_T *)pObject->pValueBuf );            break;        case VT_COUNTER:        case VT_GAUGE:            getproc_got_uint32( pktp, vbp, *(bits32_t *)pObject->pValueBuf, data_type );            break;        case VT_NUMBER:            getproc_got_int32( pktp, vbp, *(bits32_t *)pObject->pValueBuf );            break;        case VT_STRING:        case VT_OPAQUE:            /* tell 'em that this is a dynamically allocated buffer using the             * SNMP_memory_alloc(). Envoy will free the buffer using the             * SNMP_memory_free() after the packet has been encoded             */            getproc_got_string(pktp, vbp, pObject->valueLen, pObject->pValueBuf,                               pEnvoyReq->dynamic, data_type );            break;        case VT_EMPTY:            getproc_got_empty(pktp, vbp);            break;        case VT_COUNTER64:        case VT_OBJECT:            /* this should never happen. */            getproc_error(pktp, vbp, GEN_ERR);            ospfEnvoyPrintf(("ospf_envoy_getValue:unknown object type\n"));            break;    }    ospfEnvoyPrintf(("ospf_envoy_getValue:completed\n"));    return OK;}/********** Public Method routines for OSPF-Envoy Management Facility **********//**************************************************************************************** copy_oids - copy object identifier** This routine copy the object identifier to the given <best_inst> OIDC_T array. This* routine must be invoked by the xxx_next routine before the varbinds can be processed.** RETURNS: N/A** ERRNO: N/A*/void copy_oids( OIDC_T *best_inst, OIDC_T *tlist, int tcount ){    int tmp = tcount;    OIDC_T *dst = best_inst, *src = tlist;    while( tmp-- )        *dst++ = *src++;    return;}/**************************************************************************************** mApi2EnvoyErrorGet - converts OSPF MIB API status code to envoy SNMP status code** This routine converts the OSPF MIB API status code to the status code defined by* the Envoy SNMP** RETURNS: Envoy status code** ERRNO: N/A*/ushort_t mApi2EnvoyErrorGet( ushort_t mApiError ){    ushort_t envoyError;    switch( mApiError )    {        case MAPI_NO_ERROR:            envoyError = (ushort_t)NO_ERROR;            break;        case MAPI_ERROR_TOO_BIG:            envoyError = (ushort_t)TOO_BIG;            break;        case MAPI_GEN_ERROR:            envoyError = (ushort_t)GEN_ERR;            break;        case MAPI_NO_ACCESS:            envoyError = (ushort_t)NO_ACCESS;            break;        case MAPI_WRONG_TYPE:            envoyError = (ushort_t)WRONG_TYPE;            break;        case MAPI_WRONG_LENGTH:            envoyError = (ushort_t)WRONG_LENGTH;            break;        case MAPI_WRONG_ENCODING:            envoyError = (ushort_t)WRONG_ENCODING;            break;        case MAPI_WRONG_VALUE:            envoyError = (ushort_t)WRONG_VALUE;            break;        case MAPI_NO_CREATION:            envoyError = (ushort_t)NO_CREATION;            break;        case MAPI_INCONSIST_VALUE:            envoyError = (ushort_t)INCONSISTENT_VALUE;            break;        case MAPI_RESOURCE_UNAVAILABLE:            envoyError = (ushort_t)RESOURCE_UNAVAILABLE;            break;        case MAPI_COMMIT_FAILED:            envoyError = (ushort_t)COMMIT_FAILED;            break;        case MAPI_UNDO_FAILED:            envoyError = (ushort_t)UNDO_FAILED;            break;        case MAPI_AUTHORIZATION_ERROR:            envoyError = (ushort_t)AUTHORIZATION_ERROR;            break;        case MAPI_NOT_WRITABLE:            envoyError = (ushort_t)NOT_WRITABLE;            break;        case MAPI_INCONSIST_NAME:            envoyError = (ushort_t)INCONSISTENT_NAME;            break;        default:            envoyError = (ushort_t)GEN_ERR;            break;    }    return envoyError;}/************************************************************************************** ospf_envoy_snmpdTreeRemove - dynamically remove part of the SNMP agent MIB tree** This routine dynamically eletes part of the SNMP agent MIB tree at runtime.** RETURNS: N/A*/void ospf_envoy_snmpdTreeRemove( char *pTreeOidStr, SEM_ID ospf_envoyBSem ){    OBJ_ID_T  treeOid;    OIDC_T    oidArray [MAX_OSPF_OID_LEN];    treeOid.num_components = ospf_envoy_oidStrToArray( pTreeOidStr, oidArray );    if ( treeOid.num_components > 0 )    {        treeOid.component_list = oidArray;        semTake( ospf_envoyBSem, WAIT_FOREVER );        if ( Remove_Node_From_Root (NULL, &treeOid) == NULL )            ospfEnvoyPrintf(("ospf_envoy_snmpdTreeRemove:bogus pointer\n"));        semGive( ospf_envoyBSem );    }    return;}

⌨️ 快捷键说明

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