📄 ospf_mib_stub.c
字号:
* ospfEnvoy_setNbr - generic set function for ospfNbrTable** This routine is a generic set function for ospfNbrTable. It invokes by testproc and* setproc to test and set objects in varbinds.** RETURNS: N/A** NOMANUAL*/LOCAL void ospfEnvoy_setNbr( 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 != ospfNbrEntry_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, ospfMapiNbr_OID_OFFSET ); if ( rc == ERROR ) { ospf_envoy_setGenError( pktp, vbp, reqType ); return; } /* send the request to OSPF MIB API for processing */ rc = ospfMapiSetNbr( &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. */ ospfMapiSetNbr( &request, MAPI_UNDO ); setproc_error( pktp, group_vbp, mApi2EnvoyErrorGet( request.error)); } } /* tell MIB API we have completed the transaction */ ospfMapiSetNbr( &request, MAPI_COMPLETE ); 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 ) ospfMapiSetNbr( &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 ); return;}/***************************************************************************************** ospfEnvoy_getVirtNbr - generic get routine for ospfVirtNbrTable** This is the generic get routine for ospfVirtNbrTable. 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_getVirtNbr( int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp, mApiReqType_t reqType ){ mApiRequest_t request; STATUS rc; if ( ospfEnvoy_init_check( pktp, vbp, reqType ) == ERROR ) return; /* build the MIB API request message */ memset( (char *)&request, 0, sizeof(mApiRequest_t) ); rc = ospf_envoy_buildGetReq( tcount, tlist, vbp, pEnvoyReq, &request, ospfMapiVirtNbr_OID_OFFSET ); if ( rc == ERROR ) { ospf_envoy_clearBuffer( pEnvoyReq ); ospf_envoy_setGenError( pktp, vbp, reqType ); return; } /* send the request to MIB API */ rc = ospfMapiGetVirtNbr( &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, ospfMapiVirtNbr_OID_OFFSET ); ospf_envoy_clearBuffer( pEnvoyReq ); return;}/***************************************************************************************** ospfEnvoy_getExtLsdb - generic get routine for ospfExtLsdbTable** 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 ospfEnvoy_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 ( 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. */ 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_ospfExtLsdbAdvertisement ) continue; pEnvoyReq->octetBufLen = SIZE_ospfExtLsdbAdvertisement; pEnvoyReq->pOctetBuf = SNMP_memory_alloc( pEnvoyReq->octetBufLen ); if ( pEnvoyReq->pOctetBuf == NULL ) { ospfEnvoyPrintf(("ospfEnvoy_getLsdb:memory alloc(%ld) failed\n", pEnvoyReq->octetBufLen)); rc = ERROR; break; } /* 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, ospfMapiExtLsdb_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_setGenError( pktp, vbp, reqType ); return; } /* send the request to MIB API */ rc = ospfMapiGetExtLsdb( &request, reqType ); if ( rc == ERROR ) { 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; } /* retrieve all the values from the request structure */ ospf_envoy_processGetResp( vbp, pktp, pEnvoyReq, &request, reqType, ospfMapiExtLsdb_OID_OFFSET ); return;}/***************************************************************************************** ospfEnvoy_getAreaAggregate - generic get routine for ospfAreaAggregateTable** This is the generic get routine for ospfAreaAggregateTable. 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_getAreaAggregate( int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp, mApiReqType_t reqType ){ mApiRequest_t request; STATUS rc; if ( ospfEnvoy_init_check( pktp, vbp, reqType ) == ERROR ) return; /* build the MIB API request message */ memset( (char *)&request, 0, sizeof(mApiRequest_t) ); rc = ospf_envoy_buildGetReq( tcount, tlist, vbp, pEnvoyReq, &request, ospfMapiAreaAggregate_OID_OFFSET ); if ( rc == ERROR ) { ospf_envoy_clearBuffer( pEnvoyReq ); ospf_envoy_setGenError( pktp, vbp, reqType ); return; } /* send the request to MIB API */ rc = ospfMapiGetAreaAggregate( &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, ospfMapiAreaAggregate_OID_OFFSET ); return;}/**************************************************************************************** ospfEnvoy_setAreaAggregate - generic set function for ospfAreaAggregateTable** This routine is a generic set function for ospfAreaAggregateTable. It invokes by* testproc and setproc to test and set objects in varbinds.** RETURNS: N/A** NOMANUAL*/LOCAL void ospfEnvoy_setAreaAggregate( 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 != ospfAreaAggregateEntry_INSTANCE_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, ospfMapiAreaAggregate_OID_OFFSET ); if ( rc == ERROR ) { ospf_envoy_setGenError( pktp, vbp, reqType ); return; } /* send the request to OSPF MIB API for processing */ rc = ospfMapiSetAreaAggregate( &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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -