?? ospf_mib_api.c
字號(hào):
* * NOMANUAL */void ospf_mApi_ipAddr2IpIndex( ulong_t ulIpAddr, ulong_t *pIndex ){ pIndex[0] = ( ulIpAddr >> 24) & 0xFF; pIndex[1] = ( ulIpAddr >> 16) & 0xFF; pIndex[2] = ( ulIpAddr >> 8) & 0xFF; pIndex[3] = ( ulIpAddr >> 0) & 0xFF; return;}/***************************************************************************************** ospf_mApi_ipIndex2IpAddr - convert IP Address index to ulong_t.** This routine convers the IP Address index to ulong_t (network order to host order)** RETURNS: Host order** NOMANUAL*/ulong_t ospf_mApi_ipIndex2IpAddr( ulong_t *pIndex ){ ulong_t ipAddr; ipAddr = 0; ipAddr |= ( pIndex[0] & 0xFF ) << 24; ipAddr |= ( pIndex[1] & 0xFF ) << 16; ipAddr |= ( pIndex[2] & 0xFF ) << 8; ipAddr |= ( pIndex[3] & 0xFF ) << 0; return ipAddr;}/********** public Management method routines **********//*************************************************************************************** ospfMapiIsInited - determine if the OSPF Management Facility is initialized** This routine determines if the OSPF Management Facility is initialized.** RETURNS: TRUE if the facility is inited, FALSE otherwise.** ERRNO: N/A** NOMANUAL*/BOOL ospfMapiIsInited( void ){ return ospfMapiInitDone;}/***************************************************************************************** ospfMapiDestroy - destroy the OSPF Management facilities** This routine releases all resources that have been allocated for the Management* Interface.** RETURNS: N/A** ERRNOR: N/A*/STATUS ospfMapiDestroy( void ){ if ( thisMapi != NULL ) { semTake( thisMapi->semMapiMutex, WAIT_FOREVER ); /* if the OSPF protocol is running, do not allow mib api to be destoryed. * Otherwise, there will be no way to manage the OSPF protocol. Moreover, * if the mib api is destoryed and later reinitialized again (while OSPF * protoocl is running), the mib api management database will not be able to * synchronize with the OSPF configuration. There is no mechanism for mib * api to query OSPF for its configuration. In fact, it is not feasible for * mib api to do so since that will cause unnecessary disruption to the OSPF * protocol especially if the OSPF is configured in a very complex way and * there are a large number of link state advertisements in the ospf database. */ if ( thisMapi->ospfProtoInit == TRUE ) { semGive( thisMapi->semMapiMutex ); printf("ospfMapiDestory:OSPF Protocol is up running! Operation denied!\n"); return OK; } /* tell 'em that the ospf mib api is no longer inited */ ospfMapiInitDone = FALSE; if ( thisMapi->pMapiOspfGenGroup != NULL ) { free( (void *)thisMapi->pMapiOspfGenGroup ); thisMapi->pMapiOspfGenGroup = NULL; } /* erase all avl nodes from avl tree maintain by mib api */ ospf_mApi_avlTreeErase(); if ( thisMapi->pMapiWrnOspfGenGroup != NULL ) { free( (void *)thisMapi->pMapiWrnOspfGenGroup ); thisMapi->pMapiWrnOspfGenGroup = NULL; } /* free all memory used by the rowStatus handlers */ if ( thisMapi->pMapiOspfAreaRs != NULL ) rsParamsDelete( thisMapi->pMapiOspfAreaRs ); if ( thisMapi->pMapiOspfStubRs != NULL ) rsParamsDelete( thisMapi->pMapiOspfStubRs ); if ( thisMapi->pMapiOspfHostRs != NULL ) rsParamsDelete( thisMapi->pMapiOspfHostRs ); if ( thisMapi->pMapiOspfIfRs != NULL ) rsParamsDelete( thisMapi->pMapiOspfIfRs ); if ( thisMapi->pMapiOspfIfmRs != NULL ) rsParamsDelete(thisMapi->pMapiOspfIfmRs ); if ( thisMapi->pMapiOspfVirtIfRs != NULL ) rsParamsDelete( thisMapi->pMapiOspfVirtIfRs ); if ( thisMapi->pMapiOspfNbrRs != NULL ) rsParamsDelete( thisMapi->pMapiOspfNbrRs ); if ( thisMapi->pMapiOspfAreaAgRs != NULL ) rsParamsDelete( thisMapi->pMapiOspfAreaAgRs ); if ( thisMapi->pMapiWrnOspfIfRs != NULL ) rsParamsDelete( thisMapi->pMapiWrnOspfIfRs ); semDelete( thisMapi->semMapiMutex ); free( (void *)thisMapi ); thisMapi = NULL; mApiOspfPrintf(("ospfMapiDestroy:Router must be restarted now...!!!\n")); } return OK;}/***************************************************************************************** ospfMapiInit - initialize Management Interface for OSPF.** This routine initializes the facilities for managing the OSPF. It allocates the* resources needed to allow access to the RFC1850 and WRN Enterprise MIBs. If any* of the parameters is set to 0, the appropriate default values will be used to* allocate the resources needed.** RETURNS: OK or ERROR** ERRNO: N/A*/STATUS ospfMapiInit( NVRAM_SAVE_FUNCPTR nvramSaveRtn, /* callback function pointer */ NVRAM_DELETE_FUNCPTR nvramDelRtn, /* callback function pointer */ NVRAM_RETRIEVE_FUNCPTR nvramRetrieveRtn /* callback func pointer */ ){ /* if ospf has been initialized, do nothing. This is needed in order to avoid multiple * MIB API initialization been done if ospf is started, shutdown and restarted (the * MIB API facility is not destoryed during ospf shutdown) */ if ( ospfMapiInitDone == TRUE ) { mApiOspfPrintf(("ospfMapiInit: already inited\n")); return OK; } /* create an instance of mApiOspfClass_t */ if ( ( thisMapi = (mApiOspfClass_t *)calloc( 1, sizeof(mApiOspfClass_t))) == NULL ) return ERROR; /* Create Semaphore to make the access to management AVL trees safe. */ thisMapi->semMapiMutex = semMCreate( SEM_Q_PRIORITY | SEM_INVERSION_SAFE ); if ( thisMapi->semMapiMutex == NULL ) { free( (char *)thisMapi ); thisMapi = NULL; return ERROR; } /* lock the semaphore */ semTake( thisMapi->semMapiMutex, WAIT_FOREVER ); /* initialize the timeout value used by ospf2Mapi task for operational and statistical * updates. This is done to avoid the received queue (used by the ospf2Mapi task) * overflow problem. This happens if the ospf2Mapi task failed to acquire the * semMapiMutex semaphore due to some expected problems in the mib api. */ thisMapi->semTimeout = sysClkRateGet() * 5; /* 5 seconds */ /* set protocol features based on the compile-time preprocessors */ thisMapi->ospfProtoInit = FALSE; thisMapi->ospfNssaEnabled = FALSE; /* NSSA is not supported now */#if defined(__OSPF_DB_OVERFLOW_SUPPORT__) thisMapi->ospfDbOverflow = TRUE;#endif /* __OSPF_DB_OVERFLOW_SUPPORT__ */#if defined(__OPAQUE_LSA__) thisMapi->ospfOpaqueEnable = TRUE;#endif /* __OPAQUE_LSA__ */#if defined(__RFC_2328__) thisMapi->ospfRfcProto = EospfProtoType_rfc2328;#else thisMapi->ospfRfcProto = EospfProtoType_rfc1583;#endif /* __RFC_2328__ */ /* remember the callback function that is used for saving ospf configuration to * nvram. This callback function is only applicable for system that uses * nonvolatile memory for saving the system configuration. If this callback * function is not provided, ospf configuration will not be save */ thisMapi->nvramSaveRtn = nvramSaveRtn; if ( thisMapi->nvramSaveRtn == NULL ) mApiOspfPrintf(("ospfMapiInit:nvramSaveRtn callback not registered\n")); thisMapi->nvramDelRtn = nvramDelRtn; if ( thisMapi->nvramDelRtn == NULL ) mApiOspfPrintf(("ospfMapiInit:nvramDelRtn callback not registered\n")); thisMapi->nvramRetrieveRtn = nvramRetrieveRtn; if ( thisMapi->nvramRetrieveRtn == NULL ) mApiOspfPrintf(("ospfMapiInit:nvramRetrieveRtn callback not registered\n")); /* setup system specific configuration parameters for OSPF MIB and WRN-OSPF * Enterprise MIB. */ thisMapi->mApiOspfMaxArea = DEFAULT_OSPF_MAPI_AREA_MAX; thisMapi->mApiWrnOspfMaxArea = DEFAULT_OSPF_MAPI_AREA_MAX; thisMapi->mApiOspfMaxStub = DEFAULT_OSPF_MAPI_STUB_MAX; thisMapi->mApiOspfMaxLsdb = DEFAULT_OSPF_MAPI_LSDB_MAX; thisMapi->mApiOspfMaxHost = DEFAULT_OSPF_MAPI_HOST_MAX; thisMapi->mApiOspfMaxIf = DEFAULT_OSPF_MAPI_INTF_MAX; thisMapi->mApiOspfMaxIfMetric = DEFAULT_OSPF_MAPI_INTF_MAX; thisMapi->mApiOspfMaxVirtIf = DEFAULT_OSPF_MAPI_VIRT_INTF_MAX; thisMapi->mApiOspfMaxVirtNbr = DEFAULT_OSPF_MAPI_VIRT_INTF_MAX; thisMapi->mApiOspfMaxNbr = DEFAULT_OSPF_MAPI_NBR_MAX; thisMapi->mApiOspfMaxExtLsdb = DEFAULT_OSPF_MAPI_EXT_LSDB_MAX; thisMapi->mApiOspfMaxAreaAg = DEFAULT_OSPF_MAPI_AREA_AG_MAX; /* create the OSPF general parameters data structure */ thisMapi->pMapiOspfGenGroup = (void *)calloc( 1, sizeof(mApiOspfGenGroup_t) ); if ( thisMapi->pMapiOspfGenGroup == NULL ) { ospfMapiDestroy(); return ERROR; } /* initialize the rfc1850 ospf general group parameters to default. Tell 'em to * set all read-write objects to default value too */ ospf_mApi_initGeneralGroup( TRUE ); /* initialize the row status library for rfc1850 MIB */ if ( ospf_mApi_initRsLib() == ERROR ) { mApiOspfError(("ospfMapiInit:ospf_mApi_initRsLib failed.\n")); ospfMapiDestroy(); return ERROR; } /* initialize the AVL trees for rfc1850 MIB */ if ( ospf_mApi_initAvlTree() == ERROR ) { mApiOspfError(("ospfMapiInit:ospf_mApi_initAvlTree failed.\n")); ospfMapiDestroy(); return ERROR; } /* setup system specific configuration parameters for OSPF MIB and WRN-OSPF * Enterprise MIB. */ thisMapi->mApiWrnOspfMaxLsdb = DEFAULT_OSPF_MAPI_TYPE10_LSA_MAX; thisMapi->mApiWrnOspfMaxLocalLsdb = DEFAULT_OSPF_MAPI_TYPE9_LSA_MAX; thisMapi->mApiWrnOspfMaxExtLsdb = DEFAULT_OSPF_MAPI_TYPE11_LSA_MAX; thisMapi->mApiWrnOspfMaxIf = DEFAULT_OSPF_MAPI_WRN_INTF_MAX; /* create the OSPF general parameters data structure */ thisMapi->pMapiWrnOspfGenGroup = (void *)calloc( 1, sizeof(mApiWrnOspfGenGroup_t) ); if ( thisMapi->pMapiWrnOspfGenGroup == NULL ) { ospfMapiDestroy(); return ERROR; } /* initialize the wrn ospf enterprise mib general group parameters to default. Tell * 'em to initialize all read-write object to default too */ wrnOspf_mApi_initGeneralGroup( TRUE ); /* initialize the row status library for wrn-ospf enterprise MIB */ if ( wrnOspf_mApi_initRsLib() == ERROR ) { mApiOspfError(("ospfMapiInit:wrnOspf_mApi_initRsLib failed.\n")); ospfMapiDestroy(); return ERROR; } /* initialize the AVL tree for WRN-OSPF Enterprise MIB */ if ( wrnOspf_mApi_initAvlTree() == ERROR ) { mApiOspfError(("ospfMapiInit:ospf_mApi_initWrnAvlTree failed.\n")); ospfMapiDestroy(); return ERROR; } /* make the semaphore avaiable, signal that the management facility is ready */ ospfMapiInitDone = TRUE; /* SPR#86520 - Added INCLUDE_OSPF_MIB_UTILITIES component initialization */#if defined(INCLUDE_OSPF_MIB_SHOW_ROUTINES) ospfMapiShowInit();#endif /* INCLUDE_OSPF_MIB_SHOW_ROUTINES */#if defined(INCLUDE_OSPF_MIB_UTILITIES) (void)ospfMapiUtilitiesInit();#endif /* INCLUDE_OSPF_MIB_UTILITIES */ semGive( thisMapi->semMapiMutex ); mApiOspfPrintf(("ospfMapiInit:completed.\n")); /* invoke the caller nvram retrieve callback function to retrieve the OSPF * configuraitons that are previously save to the nonvolatile memory prior the * router is rebooted. This nvramRetrieveRtn() will populate all the read-write * scalar objects as well as the read-create tabular rows in the OSPF-MIB so * that the manamgenet interface can build its management database. */ if ( nvramRetrieveRtn != NULL ) { mApiOspfPrintf(("ospfMapiInit:retrieving ospf configuration from nvram...\n")); nvramRetrieveRtn(); } return OK;}/************************************************************************************* ospfMapiSetHelper - OSPF MIB API helper routine for SET operation** This OSPF MIB API helper routine is a wrapper routine that encapsulates al
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -