📄 ospf_mib_envoy_api.c
字号:
{ if ( reqType == MAPI_GET_NEXT ) nextproc_error(pktp, vbp, GEN_ERR ); else getproc_error(pktp, vbp, GEN_ERR ); continue; } /* copy the returned object value to varbind */ rc = ospf_envoy_getValue( pktp, vbp, pObject, pEnvoyReq ); if ( rc == OK ) { if ( reqType == MAPI_GET_NEXT ) { if ( (pObject->exception == MAPI_NO_SUCH_OBJECT) || (pObject->exception == MAPI_NO_SUCH_INSTANCE) ) { /* tell SNMP engine to move on to the next object */ nextproc_no_next(pktp, vbp); } else { /* for GET_NEXT request, mib api will also return the OID * instance value (whose instance is the SNMP lexicographic * successor for tcount/tlist input indentifier) in the OID * instance array pointed to by the pInstance pointer. The * OID length will be returned in the instanceLen. Install * the next instance suffix into varbind. */ nextproc_next_instance(pktp, vbp, 1, &instance ); } } } else { if ( reqType == MAPI_GET_NEXT ) nextproc_error(pktp, vbp, mApi2EnvoyErrorGet(pRequest->error)); else getproc_error(pktp, vbp, GEN_ERR ); } } /* reinitialize buffers used by envoy management facility */ ospf_envoy_clearBuffer( pEnvoyReq ); return;}/***************************************************************************************** ospf_envoy_processGetResp - process MIB API GET/GET NEXT response** This is a generic routine to process all the MIB API GET/GET_NEXT response. It is* invoked by getproc or nextproc after retreiving the values of requested objects from* the MIB API. The value of the objects will be copied into the appropriate varbind.* If exceptions reported by MIB API, the appropriate envoy snmp exception will be raised.** RETURNS: N/A** ERRNO: N/A*/void ospf_envoy_processGetResp( VB_T *vbp, SNMP_PKT_T *pktp, envoyRequest_t *pEnvoyReq, mApiRequest_t *pRequest, mApiReqType_t reqType, int mApiOidOffset){ mApiObject_t *pObject; STATUS rc; int vbcount; vbcount = 0; for ( ; vbp != NULL && vbcount < pRequest->numObjects; vbp = vbp->vb_link, vbcount++ ) { pObject = &pRequest->pObjectList[vbcount]; /* assumed the varbind is serailize with the request message */ if ( vbp->vb_ml.ml_last_match != pObject->oidPrefixEnum - mApiOidOffset ) { if ( reqType == MAPI_GET_NEXT ) nextproc_error(pktp, vbp, GEN_ERR ); else getproc_error(pktp, vbp, GEN_ERR ); continue; } /* copy the returned object value to varbind */ rc = ospf_envoy_getValue( pktp, vbp, pObject, pEnvoyReq ); if ( rc == OK ) { if ( reqType == MAPI_GET_NEXT ) { if ( (pObject->exception == MAPI_NO_SUCH_OBJECT) || (pObject->exception == MAPI_NO_SUCH_INSTANCE) ) { /* tell SNMP engine to move on to the next object */ nextproc_no_next(pktp, vbp); } else { /* for GET_NEXT request, mib api will also return the OID * instance value (whose instance is the SNMP lexicographic * successor for tcount/tlist input indentifier) in the OID * instance array pointed to by the pInstance pointer. The * OID length will be returned in the instanceLen. Install * the next instance suffix into varbind. */ nextproc_next_instance( pktp, vbp, pRequest->instanceLen, pRequest->pInstance ); } } } else { if ( reqType == MAPI_GET_NEXT ) { /* tell envoy that there is no next instance */ nextproc_error( pktp, vbp, mApi2EnvoyErrorGet( pRequest->error) ); } else getproc_error( pktp, vbp, GEN_ERR ); } } /* reinitialize buffers used by envoy management facility */ ospf_envoy_clearBuffer( pEnvoyReq ); return;}/***************************************************************************************** ospf_envoy_buildGetReq - build the MIB API GET/GET_NEXT request** This routine build the MIB API GET/GET_NEXT request message. This routine is based on* the assumption that the number of varbinds will never exceed the number of ulong_t* buffers allocated at init time. It is also assumed that there will be only one* VT_STRING or VT_OPAQUE object type in the varbinds and the exact size of this object* will first be determine by the caller.** RETURNS: OK or ERROR** ERRNO: N/A*/STATUS ospf_envoy_buildGetReq( int tcount, OIDC_T *tlist, VB_T *vbp, envoyRequest_t *pEnvoyReq, mApiRequest_t *pRequest, int mApiOidOffset ){ VB_T *group_vbp; mApiObject_t *pObject; STATUS rc; int vbcount; int bufCnt; int octetCount; if ( pEnvoyReq == NULL || pRequest == NULL ) { ospfEnvoyPrintf(("ospfEnvoy_build_getReq:bogus pointer\n")); return ERROR; } /* get number of varbinds */ pRequest->numObjects = ospf_envoy_getVbCount( vbp ); /* if number of varbinds are more than what we can handle, return ERROR */ if ( pRequest->numObjects > pEnvoyReq->numValueBuf ) { ospfEnvoyPrintf(("ospf_envoy_buildGetReq: vbcount(%i) exceed max(%i)\n", pRequest->numObjects, pEnvoyReq->numValueBuf)); return ERROR; } /* build the mApiRequest_t structure */ pRequest->pInstance = (ulong_t *)tlist; pRequest->instanceLen = (ushort_t)tcount; pRequest->pObjectList = pEnvoyReq->pObjectList; octetCount = 0; group_vbp = vbp; for ( vbcount = 0, bufCnt = 0; group_vbp != NULL && vbcount < pRequest->numObjects && bufCnt < pEnvoyReq->numValueBuf; vbcount++, group_vbp = group_vbp->vb_link ) { pObject = &pEnvoyReq->pObjectList[vbcount]; /* initialize the MIB API mApiObject_t structure */ pObject->oidPrefixEnum = group_vbp->vb_ml.ml_last_match + mApiOidOffset; rc = OK; switch( group_vbp->vb_ml.ml_leaf->expected_tag) { case VT_IPADDRESS: case VT_NUMBER: case VT_COUNTER: case VT_GAUGE: pObject->pValueBuf = &pEnvoyReq->pValueBuf[bufCnt]; pObject->valueLen = sizeof(ulong_t); bufCnt++; break; case VT_STRING: case VT_OPAQUE: /* here we assumed there will be only one octet string object in a * tabular row. If we have already processed one, retrurned error */ if ( octetCount >= 1 ) { ospfEnvoyPrintf(("ospf_envoy_buildGetReq:multiple octet objects!\n")); return ERROR; } if ( (pEnvoyReq->octetBufLen == 0) || (pEnvoyReq->pOctetBuf == NULL) ) { ospfEnvoyPrintf(("ospf_envoy_buildGetReq:No octet buflen!\n")); return ERROR; } pObject->pValueBuf = pEnvoyReq->pOctetBuf; pObject->valueLen = pEnvoyReq->octetBufLen; /* track the number of octet objects that have been processed */ octetCount++; break; case VT_COUNTER64: case VT_OBJECT: case VT_EMPTY: default: ospfEnvoyPrintf(("ospf_envoy_buildGetReq:unsupported object type\n")); return ERROR; } } return OK;}/***************************************************************************************** ospf_envoy_clearBuffer - reinitialize buffers used by OSPF Envoy Management Facility** This routine reinitialize buffers used by OSPF Envoy Manamgenet Facility. It must be* called each time before the getproc, nextproc, testproc, setproc and/or undoproc* terminates. Notice that the pointer to the pOctetBuf is not freed here. For getproc* and nextproc, Envoy SNMP will free the memory using SNMP_memory_free if memory is* dynamically allocated using SNMP_memory_alloc(). For testproc, setproc and/or undoproc,* the caller must free the memory if it is dynamically allocated (Envoy SNMP will not* free any dynamically allocated memory in this case).** RETURNS: N/A** ERRNO: N/A*/void ospf_envoy_clearBuffer( envoyRequest_t *pEnvoyReq ){ if ( pEnvoyReq == NULL ) return; pEnvoyReq->bufUsedCnt = 0; pEnvoyReq->octetBufLen = 0; pEnvoyReq->dynamic = FALSE; memset( (char *)pEnvoyReq->pValueBuf, 0, sizeof(ulong_t) * pEnvoyReq->numValueBuf ); memset( (char *)pEnvoyReq->pObjectList, 0, sizeof(mApiObject_t) * pEnvoyReq->numValueBuf ); memset( (char *)pEnvoyReq->pObjCookie, 0, sizeof(ulong_t) * pEnvoyReq->numValueBuf ); return;}/***************************************************************************************** ospf_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**/void ospf_envoy_mApiDestroy( envoyRequest_t *pEnvoyReq ){ if ( pEnvoyReq != NULL ) { if ( pEnvoyReq->envoyBSem != NULL ) semDelete( pEnvoyReq->envoyBSem ); if ( pEnvoyReq->pValueBuf != NULL ) { free( (void *)pEnvoyReq->pValueBuf ); pEnvoyReq->pValueBuf = NULL; } if ( pEnvoyReq->pObjectList != NULL ) { free( (void *)pEnvoyReq->pObjectList ); pEnvoyReq->pObjectList = NULL; } if ( pEnvoyReq->pObjCookie != NULL ) { free( (void *)pEnvoyReq->pObjCookie ); pEnvoyReq->pObjCookie = NULL; } if ( pEnvoyReq->pOctetBuf != NULL ) SNMP_memory_free( pEnvoyReq->pOctetBuf ); free( (void *)pEnvoyReq ); pEnvoyReq = NULL; } return;}/***************************************************************************************** ospf_envoy_mApiInit - initialize OSPF Envoy Management Facilities.** This routine initialize the facilities for managing the OSPF. The initial resources* are allocated.** RETURNS: OK or ERROR** ERRNO: N/A*/envoyRequest_t *ospf_envoy_mApiInit( int numBuf ){ envoyRequest_t *pEnvoyReq; if ( numBuf <= 0 ) return NULL; pEnvoyReq = (envoyRequest_t *)calloc( 1, sizeof(envoyRequest_t) ); if ( pEnvoyReq == NULL ) { ospfEnvoyPrintf(("ospf_envoy_mAiInit:resource unavailable\n")); return NULL; } /* allocate memory pool that will be used by getproc and getnextproc() */ pEnvoyReq->numValueBuf = numBuf; pEnvoyReq->pValueBuf = (ulong_t *)calloc( numBuf, sizeof(ulong_t) ); if ( pEnvoyReq->pValueBuf == NULL ) { ospfEnvoyPrintf(("ospf_envoy_mApiInit:resource unavailable\n")); free( (void *)pEnvoyReq ); pEnvoyReq = NULL; return NULL; } /* allocate a pool of mApiObject_t data structure */ pEnvoyReq->pObjectList = (mApiObject_t *)calloc( numBuf, sizeof(mApiObject_t) ); if ( pEnvoyReq->pObjectList == NULL ) { ospfEnvoyPrintf(("ospf_envoy_mApiInit:resource unavailable\n")); ospf_envoy_mApiDestroy( pEnvoyReq ); return NULL; } /* allocate a pool of object cookie */ pEnvoyReq->pObjCookie = (ulong_t *)calloc( numBuf, sizeof(ulong_t) ); if ( pEnvoyReq->pObjCookie == NULL ) { ospfEnvoyPrintf(("ospf_envoy_mApiInit:resource unavailable\n")); ospf_envoy_mApiDestroy( pEnvoyReq ); return NULL; } /* create binary semaphore with the initial state full for mutual exclusion */ pEnvoyReq->envoyBSem = semBCreate( SEM_Q_FIFO, SEM_FULL ); if ( pEnvoyReq->envoyBSem == NULL ) { ospfEnvoyPrintf(("ospf_envoy_mApiInit:semBCreate failed\n")); ospf_envoy_mApiDestroy( pEnvoyReq ); return NULL; } /* tell 'em that we are ready */ ospfEnvoyPrintf(("ospf_envoy_mApiInit:completed\n")); return pEnvoyReq;}#endif /* __OSPF_MIB__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -