?? ospf_mib_api.c
字號:
/* make sure the request message is valid */ if ( pRequest == NULL ) { mApiOspfError(("ospf_mApi_processGetReq:invalid pRequest pointer.\n")); return ERROR; } /* make sure the arguments in request message are valid */ if ( (pRequest->pInstance == NULL) || (pRequest->numObjects == 0) || (pRequest->pObjectList == NULL) ) { pRequest->error = (ushort_t)MAPI_GEN_ERROR; pRequest->errorObjIndex = 0; return ERROR; } pRow = NULL; pRequest->error = (ushort_t)MAPI_NO_ERROR; key.p = (void *)pRequest->pInstance; /* lock mib api mutex for exclusive access to mApiOspfClass_t */ semTake( thisMapi->semMapiMutex, WAIT_FOREVER); /* remember the current request type we are processing */ thisMapi->currMapiReqType = reqType; switch( reqType ) { case MAPI_GET_NEXT: /* instanceLen of zero means the successor is the first entry in the table */ if ( pRequest->instanceLen == 0 ) { pRow = (void *)avlMinimumGet(pOspfAvlTree->pOspfAvlRoot ); } else { /* sanity check the instanceLen */ if ( pRequest->instanceLen != instanceLen ) { pRequest->error = (ushort_t)MAPI_GEN_ERROR; pRequest->errorObjIndex = 0; semGive( thisMapi->semMapiMutex ); mApiOspfError(("ospf_mApi_processGetReq:Invalid instanceLen!\n")); return ERROR; } pRow = (void *)avlSuccessorGet(pOspfAvlTree->pOspfAvlRoot, key, pOspfAvlTree->ospfAvlCompareRtn ); } break; case MAPI_GET: case MAPI_GET_FORCE: /* sanity check the instanceLen */ if ( pRequest->instanceLen != instanceLen ) { pRequest->error = (ushort_t)MAPI_GEN_ERROR; pRequest->errorObjIndex = 0; semGive( thisMapi->semMapiMutex ); mApiOspfError(("ospf_mApi_processGetReq:Invalid instanceLen!\n")); return ERROR; } /* get the exact instance */ pRow = (void *)avlSearch( pOspfAvlTree->pOspfAvlRoot, key, pOspfAvlTree->ospfAvlCompareRtn ); break; case MAPI_TEST: case MAPI_COMMIT: case MAPI_UNDO: case MAPI_COMPLETE: case MAPI_TEST_FORCE: case MAPI_COMMIT_FORCE: pRequest->error = (ushort_t)MAPI_WRONG_TYPE; pRequest->errorObjIndex = 0; thisMapi->mApiBogusReqCnt++; semGive( thisMapi->semMapiMutex ); mApiOspfPrintf(("ospf_mApi_processGetReq:bogus request\n")); return ERROR; } if ( pRow == NULL ) { if ( reqType == MAPI_GET_NEXT ) thisMapi->mApiGetNextReqFailedCnt++; else thisMapi->mApiGetReqFailedCnt++; semGive( thisMapi->semMapiMutex ); pRequest->error = (ushort_t)MAPI_INVALID_INSTANCE; pRequest->errorObjIndex = 0; mApiOspfError(("ospf_mApi_processGetReq:%s - no such instance\n", mApiRequest[reqType])); return ERROR; } /* walk the request lists and determine the value of the objects to return */ for ( numObjects = 0; numObjects < pRequest->numObjects; numObjects++ ) { pObject = &pRequest->pObjectList[numObjects]; if ( ospf_mApi_getHelperRtn( pRow, pRequest, pObject ) == ERROR ) { /* If error ocurrs, then the entire request has failed. No partial data * is returned. We don't clear out all the previously success request. * Application must ignore all the returned data. */ if ( reqType == MAPI_GET_NEXT ) thisMapi->mApiGetNextReqFailedCnt++; else thisMapi->mApiGetReqFailedCnt++; semGive( thisMapi->semMapiMutex ); mApiOspfError(("ospf_mApi_processGetReq:%s failed\n", mApiRequest[reqType])); return ERROR; } } /* update the index values for GET_NEXT request */ if ( reqType == MAPI_GET_NEXT ) ospf_mApi_indexSetRtn( pRow, pRequest); semGive( thisMapi->semMapiMutex ); return OK;}/**************************************************************************************** ospf_mApi_databaseFree - free the specified ospf database** This routine free the specified ospf database. The AVL Tree will be erased and all* allocated memory will be freed.** RETURNS: N/A** NOMANUAL*/LOCAL void ospf_mApi_databaseFree( mApiOspfAvlClass_t *pDatabase ){ void *pNode; if ( pDatabase == NULL ) return; if ( pDatabase->pOspfAvlRoot != NULL ) avlTreeErase( &pDatabase->pOspfAvlRoot ); for (;;) { pNode = (void *)lstGet( &pDatabase->ospfFreePoolList ); if ( pNode == NULL ) break; /* free the allocated memory */ free( (void *)pNode ); pNode = NULL; } /* frees up memory used for nodes */ lstFree( &pDatabase->ospfFreePoolList ); return;}/***************************************************************************************** ospf_mApi_avlTreeErase - erase all avl tree maintained by MIB API** This routine erase all AVL Tree maintained by MIB API. All memory resources will be* freed.** RETURNS: N/A** NOMANUAL*/LOCAL void ospf_mApi_avlTreeErase( void ){ /* free all the management database */ ospf_mApi_databaseFree( &thisMapi->ospfAreaAvl ); ospf_mApi_databaseFree( &thisMapi->ospfStubAvl ); ospf_mApi_databaseFree( &thisMapi->ospfLsdbAvl ); ospf_mApi_databaseFree( &thisMapi->ospfHostAvl ); ospf_mApi_databaseFree( &thisMapi->ospfIfAvl ); ospf_mApi_databaseFree( &thisMapi->ospfIfMetricAvl ); ospf_mApi_databaseFree( &thisMapi->ospfVirtIfAvl ); ospf_mApi_databaseFree( &thisMapi->ospfNbrAvl ); ospf_mApi_databaseFree( &thisMapi->ospfVirtNbrAvl ); ospf_mApi_databaseFree( &thisMapi->ospfExtLsdbAvl ); ospf_mApi_databaseFree( &thisMapi->ospfAreaAgAvl ); ospf_mApi_databaseFree( &thisMapi->wrnOspfAreaAvl ); ospf_mApi_databaseFree( &thisMapi->wrnOspfLsdbAvl ); ospf_mApi_databaseFree( &thisMapi->wrnOspfLsdbAvl ); ospf_mApi_databaseFree( &thisMapi->wrnOspfExtLsdbAvl ); ospf_mApi_databaseFree( &thisMapi->wrnOspfIfAvl ); return;}/********** misc convertions routines **********//**************************************************************************************** ospf_rs2mApi_errorGet - converts RowStatus library error code to mib api status code** This routine converts the RowStatus library error code to mib api status code. This* routine is used in conjunction with the rowStatus library.** ERROR: mib api error code** NOMANUAL*/int ospf_rs2mApi_errorGet( void *pObjInfo, int rsError ){ mApiRequest_t *pRequest; int rc; pRequest = (mApiRequest_t *)pObjInfo; if ( pRequest == NULL ) { mApiOspfError(("ospf_rs2mApi_errorGet:invalid pRequest pointer.\n")); return ERROR; } rc = ERROR; switch( rsError ) { case RS_noError: pRequest->error = (int)MAPI_NO_ERROR; rc = OK; break; case RS_wrongValue: /* only set the error if one has not been set */ if ( pRequest->error == (int)MAPI_NO_ERROR ) pRequest->error = (int)MAPI_WRONG_VALUE; break; case RS_inconsistValue: /* only set the error if one has not been set */ if ( pRequest->error == (int)MAPI_NO_ERROR ) pRequest->error = (int)MAPI_INCONSIST_VALUE; break; case RS_genError: default: /* only set the error if one has not been set */ if ( pRequest->error == (int)MAPI_NO_ERROR ) pRequest->error = (int)MAPI_GEN_ERROR; break; } return rc;}/**************************************************************************************** ospf_rs2mApi_reqTypeGet - convert rowStatus request type to MIB API request type** This routine converts the RowStatus request type to the request tyoe defined by* MIB API. This routine is used in conjunction with the RowStatus library.** RETURNS: OK or Error** ERRNO: none** NOMANUAL*/STATUS ospf_rs2mApi_reqTypeGet( int rsRequest, mApiReqType_t *mApiReqType ){ switch ((rsRequest_t)rsRequest) { case RS_GET_REQUEST: *mApiReqType = MAPI_GET; break; case RS_SET_NVM_REQUEST: *mApiReqType = MAPI_COMMIT_FORCE; break; case RS_VALIDATE_REQUEST: *mApiReqType = MAPI_TEST; break; case RS_COMMIT_REQUEST: *mApiReqType = MAPI_COMMIT; break; /* TODO: define these for rowStatus library? */ case RS_ERROR_REQUEST: default: return ERROR; } return OK;}/******************************************************************************** ospf_mApi_IpAddr2OctetString - convert ulong_t IP Address to OCTET STRING.** RETURNS* Value returned is in network order, ipAddr is in host order.** NOMANUAL*/void ospf_mApi_ipAddr2OctetString( ulong_t ipAddr, uchar_t *octetString ){ octetString[ 0 ] = (uchar_t)((ipAddr >> 24) & 0xFF); octetString[ 1 ] = (uchar_t)((ipAddr >> 16) & 0xFF); octetString[ 2 ] = (uchar_t)((ipAddr >> 8) & 0xFF); octetString[ 3 ] = (uchar_t)((ipAddr >> 0) & 0xFF); return;}/******************************************************************************** ospf_mApi_octetString2IpAddr - convert OCTET STRING to ulong_t IP Address.** RETURNS* Value returned is in host order, octet string is in network order.** NOMANUAL*/ulong_t ospf_mApi_octetString2IpAddr( uchar_t *octetString ){ ulong_t ipAddr; ipAddr = 0; ipAddr |= (octetString[ 0 ] & 0xFF) << 24; ipAddr |= (octetString[ 1 ] & 0xFF) << 16; ipAddr |= (octetString[ 2 ] & 0xFF) << 8; ipAddr |= (octetString[ 3 ] & 0xFF) << 0; return ipAddr;}/**************************************************************************************** * ospf_mApi_ipAddr2IpIndex - convert IP Address to Index * * This routine converts the IP Address (given in ulong_t) to index * * REUTNRS: Index in network order
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -