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

📄 ospf_mib_wrn_stub.c

📁 vxworks下ospf协议栈
💻 C
📖 第 1 页 / 共 4 页
字号:
            {                ospfEnvoyPrintf(("wrnOspfEnvoy_getLsdb:no buflen returned by MIB API\n"));                rc = ERROR;                break;            }            pWrnEnvoyReq->octetBufLen = request.pObjectList->valueLen;            pWrnEnvoyReq->pOctetBuf = SNMP_memory_alloc( pWrnEnvoyReq->octetBufLen );            if ( pWrnEnvoyReq->pOctetBuf == NULL )            {                ospfEnvoyPrintf(("wrnOspfEnvoy_getLsdb:memory alloc(%ld) failed\n",                                 pWrnEnvoyReq->octetBufLen));                rc = ERROR;                break;            }            /* clear the request message structure */            memset( (char *)&request, 0, sizeof(mApiRequest_t) );            /* mark this buffer as dynamic */            pWrnEnvoyReq->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, pWrnEnvoyReq, &request,                                 wrnOspfMapiLsdb_OID_OFFSET );    if ( rc == ERROR )    {        /* free the allocated memory only if we have just allocated it in this          * transaction (i.e. pWrnEnvoyReq->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 pWrnEnvoyReq->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          * pWrnEnvoyReq->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 pWrnEnvoyReq->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 ( (pWrnEnvoyReq->pOctetBuf != NULL) && (pWrnEnvoyReq->dynamic == TRUE) )        {            SNMP_memory_free( pWrnEnvoyReq->pOctetBuf );            pWrnEnvoyReq->pOctetBuf = NULL;        }        ospf_envoy_clearBuffer( pWrnEnvoyReq );        ospf_envoy_setGenError( pktp, vbp, reqType );        return;    }    /* send the request to MIB API */    rc = ospfMapiGetWrnLsdb( &request, reqType );    if ( rc == ERROR )    {        if ( (pWrnEnvoyReq->pOctetBuf != NULL) && (pWrnEnvoyReq->dynamic == TRUE) )         {            SNMP_memory_free( pWrnEnvoyReq->pOctetBuf );            pWrnEnvoyReq->pOctetBuf = NULL;        }        ospf_envoy_clearBuffer( pWrnEnvoyReq );        ospf_envoy_processGetRespError( pktp, vbp, reqType, request.error );        return;    }    /* retrieve all the values from the request structure */    ospf_envoy_processGetResp( vbp, pktp, pWrnEnvoyReq, &request, reqType,                               wrnOspfMapiLsdb_OID_OFFSET );    return;}/***************************************************************************************** wrnOspfEnvoy_getLocalLsdb - generic get routine for wrnOspfLocalLsdbTable** This is the generic get routine for wrnOspfLsdbTable. It query the mib api for the row of* table 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 wrnOspfEnvoy_getLocalLsdb( int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp,                                      VB_T *vbp, mApiReqType_t reqType ){    OIDC_T         inst_oid[wrnOspfLocalLsdbEntry_INSTANCE_LEN];    mApiRequest_t  request;    mApiObject_t   object;    VB_T           *group_vbp;    STATUS         rc;    unsigned       inst_len;    if ( wrnOspfEnvoy_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.     */    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_wrnOspfLocalLsdbAdvertisement )                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)*wrnOspfLocalLsdbEntry_INSTANCE_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 +                                                 wrnOspfMapiLocalLsdb_OID_OFFSET;            request.pObjectList->pValueBuf = NULL;            request.pObjectList->valueLen = 0;            rc = ospfMapiGetWrnLocalLsdb( &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(("wrnOspfEnvoy_getLocalLsdb:exception not buffer too short\n"));                rc = ERROR;                break;            }            /* MIB API should return the size of the lsdb */            if ( request.pObjectList->valueLen == 0 )            {                ospfEnvoyPrintf(("wrnOspfEnvoy_getLocalLsdb:no buflen returned by MIB API\n"));                rc = ERROR;                break;            }            pWrnEnvoyReq->octetBufLen = request.pObjectList->valueLen;            pWrnEnvoyReq->pOctetBuf = SNMP_memory_alloc( pWrnEnvoyReq->octetBufLen );            if ( pWrnEnvoyReq->pOctetBuf == NULL )            {                ospfEnvoyPrintf(("wrnOspfEnvoy_getLocalLsdb:memory alloc(%ld) failed\n",                                 pWrnEnvoyReq->octetBufLen));                rc = ERROR;                break;            }            /* clear the request message structure */            memset( (char *)&request, 0, sizeof(mApiRequest_t) );            /* mark this buffer as dynamic */            pWrnEnvoyReq->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, pWrnEnvoyReq, &request,                                 wrnOspfMapiLocalLsdb_OID_OFFSET );    if ( rc == ERROR )    {        /* free the allocated memory only if we have just allocated it in this          * transaction (i.e. pWrnEnvoyReq->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 pWrnEnvoyReq->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          * pWrnEnvoyReq->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 pWrnEnvoyReq->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 ( (pWrnEnvoyReq->pOctetBuf != NULL) && (pWrnEnvoyReq->dynamic == TRUE) )        {            SNMP_memory_free( pWrnEnvoyReq->pOctetBuf );            pWrnEnvoyReq->pOctetBuf = NULL;        }        ospf_envoy_clearBuffer( pWrnEnvoyReq );        ospf_envoy_setGenError( pktp, vbp, reqType );        return;    }    /* send the request to MIB API */    rc = ospfMapiGetWrnLocalLsdb( &request, reqType );    if ( rc == ERROR )    {        if ( (pWrnEnvoyReq->pOctetBuf != NULL) && (pWrnEnvoyReq->dynamic == TRUE) )        {            SNMP_memory_free( pWrnEnvoyReq->pOctetBuf );            pWrnEnvoyReq->pOctetBuf = NULL;        }        ospf_envoy_clearBuffer( pWrnEnvoyReq );        ospf_envoy_processGetRespError( pktp, vbp, reqType, request.error );        return;    }    /* retrieve all the values from the request structure */    ospf_envoy_processGetResp( vbp, pktp, pWrnEnvoyReq, &request, reqType,                               wrnOspfMapiLocalLsdb_OID_OFFSET );    return;}/***************************************************************************************** wrnOspfEnvoy_getExtLsdb - generic get routine for wrnOspfExtLsdbTable** This is the generic get routine for ospfExtLsdbTable. 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 wrnOspfEnvoy_getExtLsdb( 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 ( wrnOspfEnvoy_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.     */    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 ospfExtLsdbTable, ospfExtLsdbAdvertisement is the only octet string             * object             */            if ( group_vbp->vb_ml.ml_last_match != LEAF_wrnOspfExtLsdbAdvertisement )                continue;            pWrnEnvoyReq->octetBufLen = SIZE_wrnOspfExtLsdbAdvertisement;            pWrnEnvoyReq->pOctetBuf = SNMP_memory_alloc( pWrnEnvoyReq->octetBufLen );            if ( pWrnEnvoyReq->pOctetBuf == NULL )            {                ospfEnvoyPrintf(("wrnOspfEnvoy_getExtLsdb:memory alloc(%ld) failed\n",                                 pWrnEnvoyReq->octetBufLen));                rc = ERROR;                break;            }            /* mark this buffer as dynamic */            pWrnEnvoyReq->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, pWrnEnvoyReq, &request,                                 wrnOspfMapiExtLsdb_OID_OFFSET );    if ( rc == ERROR )    {        /* free the allocated memory only if we have just allocated it in this          * transaction (i.e. pWrnEnvoyReq->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 pWrnEnvoyReq->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          * pWrnEnvoyReq->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 pWrnEnvoyReq->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 ( (pWrnEnvoyReq->pOctetBuf != NULL) && (pWrnEnvoyReq->dynamic == TRUE) )        {            SNMP_memory_free( pWrnEnvoyReq->pOctetBuf );            pWrnEnvoyReq->pOctetBuf = NULL;        }        ospf_envoy_clearBuffer( pWrnEnvoyReq );        ospf_envoy_setGenError( pktp, vbp, reqType );        return;    }    /* send the request to MIB API */    rc = ospfMapiGetWrnExtLsdb( &request, reqType );    if ( rc == ERROR )    {        if ( (pWrnEnvoyReq->pOctetBuf != NULL) && (pWrnEnvoyReq->dynamic == TRUE) )        {            SNMP_memory_free( pWrnEnvoyReq->pOctetBuf );            pWrnEnvoyReq->pOctetBuf = NULL;        }        ospf_envoy_clearBuffer( pWrnEnvoyReq );        ospf_envoy_processGetRespError( pktp, vbp, reqType, request.error );        return;    }    /* retrieve all the values from the request structure */    ospf_envoy_processGetResp( vbp, pktp, pWrnEnvoyReq, &request, reqType,                               wrnOspfMapiExtLsdb_OID_OFFSET );    return;}/********** supported public method routines for Envoy SNMP **********//***************************************************************************************** wrnOspf_mApi_destroy - destory the OSPF Envoy Manamgent facilities** This routine releases all resources that have been allocated for the Manamgent Interface.** RETURNS: N/A** ERRNOR: N/A**/

⌨️ 快捷键说明

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