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

📄 ospf_mib_stub.c

📁 vxworks下ospf协议栈
💻 C
📖 第 1 页 / 共 5 页
字号:
     * be allocated by the caller. Loop through the varbinds and determine if     * there is an object whose type is octet string.     */    rc = OK;    for (group_vbp = vbp; group_vbp != NULL; group_vbp = group_vbp->vb_link )    {        if ( (group_vbp->vb_ml.ml_leaf->expected_tag == VT_STRING) ||             (group_vbp->vb_ml.ml_leaf->expected_tag == VT_OPAQUE) )        {            /* for ospfLsdbTable, ospfLsdbAdvertisement is the only object using octet             * string.             */            if ( group_vbp->vb_ml.ml_last_match != LEAF_ospfLsdbAdvertisement )                continue;            /* copy instance portion into a buffer. This buffer will be used to return             * the next instance by the MIB API. This is necessary because the main              * purpose for this transaction here is to query MIB API for the size of              * the ospfLsdbAdvertisement object so that we can allocate a buffer             * (with the exact size) that will be used by MIB API to return the value              * of the advertisement. Therefore, we are not really interesting about              * the index value for the next instance.             */            memset( (char *)inst_oid, 0, sizeof(OIDC_T)*ospfLsdbEntry_INST_LEN );            inst_len = tcount;            if ( inst_len != 0 )                copy_oids( inst_oid, tlist, inst_len );            /* send a simple get request to query MIB API for the size of the             * advertisement for this row             */            request.pInstance = (ulong_t *)inst_oid;            request.instanceLen = (ushort_t)inst_len;            request.numObjects = 1;            memset( (char *)&object, 0, sizeof(mApiObject_t) );            request.pObjectList = &object;            request.pObjectList->oidPrefixEnum = group_vbp->vb_ml.ml_last_match +                                                 ospfMapiLsdb_OID_OFFSET;            request.pObjectList->pValueBuf = NULL;            request.pObjectList->valueLen = 0;            rc = ospfMapiGetLsdb( &request, reqType );            if ( rc == ERROR )            {                ospf_envoy_processGetRespError( pktp, vbp, reqType, request.error );                ospfEnvoyPrintf(("ospfEnvoy_getLsdb:failed\n"));                return;            }            /* expect an exception to be set by MIB API */            if ( request.pObjectList->exception != MAPI_BUFFER_TOO_SHORT )            {                ospfEnvoyPrintf(("ospfEnvoy_getLsdb:exception not buffer too short\n"));                rc = ERROR;                break;            }            /* MIB API should return the size of the lsdb */            if ( request.pObjectList->valueLen == 0 )            {                ospfEnvoyPrintf(("ospfEnvoy_getLsdb:no buflen returned by MIB API\n"));                rc = ERROR;                break;            }            pEnvoyReq->octetBufLen = request.pObjectList->valueLen;            pEnvoyReq->pOctetBuf = SNMP_memory_alloc( pEnvoyReq->octetBufLen );            if ( pEnvoyReq->pOctetBuf == NULL )            {                ospfEnvoyPrintf(("ospfEnvoy_getLsdb:memory alloc(%ld) failed\n",                                 pEnvoyReq->octetBufLen));                rc = ERROR;                break;            }            /* clear the request message structure */            memset( (char *)&request, 0, sizeof(mApiRequest_t) );            /* mark this buffer as dynamic */            pEnvoyReq->dynamic = TRUE;            break;  /* there can be only one octet string object in a row */        }    }    if ( rc == ERROR )    {        ospf_envoy_setGenError( pktp, vbp, reqType );        return;    }    /* build the MIB API request message */    memset( (char *)&request, 0, sizeof(mApiRequest_t) );    rc = ospf_envoy_buildGetReq( tcount, tlist, vbp, pEnvoyReq, &request,                                 ospfMapiLsdb_OID_OFFSET );    if ( rc == ERROR )    {        /* free the allocated memory only if we have just allocated it in this          * transaction (i.e. pEnvoyReq->dynamic is set). It is necessary to         * determine if the buffer is allocated within the context of current          * transaction because the buffer pointed to by pEnvoyReq->pOctetBuf         * may have been allocated during a previous transaction and that buffer         * should only be freed by envoy snmp after the packet has been encoded          * (sometimes after getproc_got_string() is called). When the current         * transaction takes place, it is possible that the buffer pointed to by          * pEnvoyReq->pOctetBuf may not be null (i.e. envoy snmp has yet freed          * it). Therefore, we must make sure that we only free the memory that is         * allocated in this transaction, and that can be determined by checking         * the pEnvoyReq->dynamic boolean flag. This flag is cleared at the end         * of each transaction (by ospf_envoy_clearBuffer()) and it is only set         * if a buffer is allocated within the context of the current transaction.         */        if ( (pEnvoyReq->pOctetBuf != NULL) && (pEnvoyReq->dynamic == TRUE) )        {            SNMP_memory_free( pEnvoyReq->pOctetBuf );            pEnvoyReq->pOctetBuf = NULL;        }        ospf_envoy_clearBuffer( pEnvoyReq );        ospf_envoy_processGetRespError( pktp, vbp, reqType, request.error );        return;    }    /* send the request to MIB API */    rc = ospfMapiGetLsdb( &request, reqType );    if ( rc == ERROR )    {                if ( (pEnvoyReq->pOctetBuf != NULL) && (pEnvoyReq->dynamic == TRUE) )        {            SNMP_memory_free( pEnvoyReq->pOctetBuf );            pEnvoyReq->pOctetBuf = NULL;        }        ospf_envoy_clearBuffer( pEnvoyReq );        for ( ; vbp ; vbp = vbp->vb_link )        {            if ( request.error == MAPI_INVALID_INSTANCE )            {                if ( reqType == MAPI_GET_NEXT )                    nextproc_no_next( pktp, vbp );                else                    getproc_nosuchins( pktp, vbp );            }            else            {                if ( reqType == MAPI_GET_NEXT )                    nextproc_error( pktp, vbp, mApi2EnvoyErrorGet( request.error) );                else                    getproc_error( pktp, vbp, mApi2EnvoyErrorGet( request.error) );            }        }        return;    }    /* retrieve all the values from the request structure */    ospf_envoy_processGetResp( vbp, pktp, pEnvoyReq, &request, reqType,                               ospfMapiLsdb_OID_OFFSET );    return;}/***************************************************************************************** ospfEnvoy_getIf - generic get routine for ospfIfTable** This is the generic get routine for ospfIfTable. It query the mib api for the table* row in which the requested object instances can be found. The behavior of the mib api* is based on request type, either GET or GET_NEXT. If it is a GET_NEXT request, the* smallest instance that is larger than the given tcount/tlist will be returned.** RETURNS: N/A** NOMANUAL*/LOCAL void ospfEnvoy_getIf( int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp,                            mApiReqType_t reqType ){    mApiRequest_t  request;    VB_T           *group_vbp;    char           authKey[4];    STATUS         rc;    if ( ospfEnvoy_init_check( pktp, vbp, reqType ) == ERROR )        return;    /* the ospfEnvoy_build_getRequest() expects the buffer for the octet string to     * be allocated by the caller. Loop through the varbinds and determine if     * there is an object whose type is octet string.     */    for ( group_vbp = vbp ; group_vbp != NULL; group_vbp = group_vbp->vb_link )    {        if ( (group_vbp->vb_ml.ml_leaf->expected_tag == VT_STRING) ||             (group_vbp->vb_ml.ml_leaf->expected_tag == VT_OPAQUE) )        {            if ( group_vbp->vb_ml.ml_last_match != LEAF_ospfIfAuthKey )                continue;            /* for ospfIfTable, ospfIfAuthKey is the only object using octet string.             * RFC1850 requires that the ospfIfAuthKey when read, will always returns             * an octet string of length zero. Statically allocate an array of ulong_t             * to satisfy the request             */            memset( authKey, 0, sizeof(authKey) );            pEnvoyReq->pOctetBuf = authKey;            pEnvoyReq->octetBufLen = sizeof(authKey);            /* mark this buffer as static */            pEnvoyReq->dynamic = FALSE;            break;  /* there can be only one octet string object in a row */        }    }    /* build the MIB API request message */    memset( (char *)&request, 0, sizeof(mApiRequest_t) );    rc = ospf_envoy_buildGetReq( tcount, tlist, vbp, pEnvoyReq, &request,                                 ospfMapiIf_OID_OFFSET );    if ( rc == ERROR )    {        ospf_envoy_clearBuffer( pEnvoyReq );        ospf_envoy_setGenError( pktp, vbp, reqType );        return;    }    /* send the request to MIB API */    rc = ospfMapiGetIf( &request, reqType );    if ( rc == ERROR )    {        ospf_envoy_clearBuffer( pEnvoyReq );        ospf_envoy_processGetRespError( pktp, vbp, reqType, request.error );        return;    }    /* retrieve all the values from the request structure */    ospf_envoy_processGetResp( vbp, pktp, pEnvoyReq, &request, reqType,                               ospfMapiIf_OID_OFFSET );    return;}/**************************************************************************************** ospfEnvoy_setIf - generic set function for ospfIfTable** This routine is a generic set function for ospfIfTable. It invokes by testproc and* setproc to test and set objects in varbinds.** RETURNS: N/A** NOMANUAL*/LOCAL void ospfEnvoy_setIf( int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp,                            mApiReqType_t reqType ){    mApiRequest_t  request;    VB_T           *group_vbp;    STATUS         rc;    if ( tcount != ospfIfEntry_INST_LEN )    {        ospf_envoy_setNoSuchNameError( pktp, vbp, reqType );        return;    }    if ( ospfEnvoy_init_check( pktp, vbp, reqType ) == ERROR )        return;    /* use the data provided by the varbinds directly. This eliminates the need     * to copy the data from varbinds to locally allocated buffer.     */    rc = ospf_envoy_buildSetReq( tcount, tlist, pktp, vbp, pEnvoyReq, &request, reqType,                                 ospfMapiIf_OID_OFFSET );    if ( rc == ERROR )    {        ospf_envoy_setGenError( pktp, vbp, reqType );        return;    }    /* send the request to OSPF MIB API for processing */    rc = ospfMapiSetIf( &request, reqType );    if ( rc == ERROR )    {        for (group_vbp = vbp; group_vbp != NULL; group_vbp = group_vbp->vb_link )        {            group_vbp->vb_priv = NULL;            if ( reqType == MAPI_TEST )                testproc_error( pktp, group_vbp, mApi2EnvoyErrorGet( request.error));            else            {                /* tell envoy to start the undo operation. Envoy should call the                 * undo routine immediately once the setproc_error indicates                 * the set process has failed.                 */                group_vbp->undoproc = ospfEnvoy_undo; /* our undo routine */                /* issue a fake undo request to mib api so that it can reset its                 * internal transaction counters.                 */                ospfMapiSetIf( &request, MAPI_UNDO );                setproc_error( pktp, group_vbp, mApi2EnvoyErrorGet( request.error));            }        }        /* tell MIB API we have completed the transaction */        ospfMapiSetIf( &request, MAPI_COMPLETE );        ospf_envoy_clearBuffer( pEnvoyReq );        if (  (pEnvoyReq->dynamic == TRUE) && (pEnvoyReq->pOctetBuf != NULL) )        {            SNMP_memory_free( pEnvoyReq->pOctetBuf );            pEnvoyReq->pOctetBuf = NULL;        }        return;    }    if ( reqType == MAPI_TEST )    {        /* stash the looked up information here for the setproc. Although Envoy         * provide vb_priv in each varbind, only stash it to the first varbind.         * MIB API only allow one cookie per request, and we only need one anyhow         */        vbp->vb_priv = (void *)request.pReqCookie;    }    /* tell MIB API we have completed the transaction */    if ( reqType == MAPI_COMMIT )        ospfMapiSetIf( &request, MAPI_COMPLETE );    /* make the varbind as done and check for any exception in varbinds */    ospf_envoy_markVarbind( vbp, pktp, &request, reqType );    ospf_envoy_clearBuffer( pEnvoyReq );    if (  (pEnvoyReq->dynamic == TRUE ) && (pEnvoyReq->pOctetBuf != NULL) )    {        SNMP_memory_free( pEnvoyReq->pOctetBuf );        pEnvoyReq->pOctetBuf = NULL;    }    return;}/***************************************************************************************** ospfEnvoy_getIfMetric - generic get routine for ospfIfMetricTable** This is the generic get routine for ospfIfMetricTable. It query the mib api for the* table row in which the requested object instances can be found. The behavior of the mib* api is based on request type, either GET or GET_NEXT. If it is a GET_NEXT request, the* smallest instance that is larger than the given tcount/tlist will be returned.** RETURNS: N/A** NOMANUAL*/LOCAL void ospfEnvoy_getIfMetric( int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp,                                  mApiReqType_t reqType ){    mApiRequest_t  request;    STATUS         rc;

⌨️ 快捷键说明

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