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

📄 ospf_mib_helper.c

📁 vxworks下ospf协议栈
💻 C
📖 第 1 页 / 共 5 页
字号:
        }    }    if ( (clientType == EmApiOspfClientType_nbr) ||         (clientType == EmApiOspfClientType_ag) )    {        mApiOspfPrintf(("ospf_mApi_areaRegisterIf:can't register invalid client type\n"));        return ERROR;    }    /* if we are here, the interface is not on the listIfAttached list */    pAttachedClient = (mApiOspfClient_t *)calloc( 1, sizeof(mApiOspfClient_t) );    if ( pAttachedClient == NULL )    {        mApiOspfPrintf(("ospf_mApi_areaRegisterIf:can't calloc mApiOspfClient_t\n"));        return ERROR;    }    pAttachedClient->clientType = clientType;    pAttachedClient->oldStatus = oldStatus;    pAttachedClient->pClient = pNewClient;    switch( clientType )    {        case EmApiOspfClientType_intf:        {            mApiOspfIf_t *pIf;            /* we have one more interface attached to this area */            pArea->numIfAttached++;            /* only increment the numActiveIf counter if the row status for this             * interface is active and its adminstrative status is also set             */            pIf = (mApiOspfIf_t *)pNewClient;            if ( (pIf->ospfIfStatus == EmApiOspfRowStatus_active) &&                 (pIf->ospfIfAdminStat == EmApiOspf_enabled) )                pArea->numActiveIf++;            /* tell this client interface to remember the area it connects */            pIf->pArea = (void *)pArea;        }        break;        case EmApiOspfClientType_vintf:        {            mApiOspfVirtIf_t *pVirtIf;            /* we have one more virtual interface attached to this area */            pArea->numVirtIfAttached++;            pVirtIf = (mApiOspfVirtIf_t *)pNewClient;            if ( pVirtIf->ospfVirtIfStatus == EmApiOspfRowStatus_active )                pArea->numActiveVirtIf++;            /* tell this client interface to remember the area it connects */            pVirtIf->pArea = (void *)pArea;        }        break;        case EmApiOspfClientType_host:        {            mApiOspfHost_t *pHostIf;            /* we have one more host interface attached to this area */            pArea->numHostAttached++;            pHostIf = (mApiOspfHost_t *)pNewClient;            if ( pHostIf->ospfHostStatus == EmApiOspfRowStatus_active )                pArea->numActiveHost++;            /* tell this client interface to remember the area it connects */            pHostIf->pArea = (void *)pArea;        }        break;        case EmApiOspfClientType_nbr:        case EmApiOspfClientType_ag:            return ERROR;  /* will never get here at all */    }    /* append this node to the end of the listIfAttached linked list */    lstAdd( &pArea->listIfAttached, &pAttachedClient->node );    /* update the area attributes, if necessary */    ospf_mApi_areaStatusUpdate( pArea, initialActiveIf, initialActiveHost );    return OK;}/**************************************************************************************** ospf_mApi_areaDeregisterIf - de-register a client interface from the area** This routine de-register a client interface from the listIfAttached linked list. There* are three types of client that gets onto the list: physical interface, virtual* interface and host interface. This routine is called when (1) a client interface is* deleted (2) an OSPF Area has been deleted (all the client attached to the area must* then be removed).** RETURNS: N/A** NOMANUAL*/LOCAL void ospf_mApi_areaDeregisterIf( mApiOspfArea_t *pArea, void *pCurrClient ){    mApiOspfClient_t *pAttachedClient;    ushort_t         initialActiveIf;    ushort_t         initialActiveHost;    /* save the current active interface count for later comparison */    initialActiveIf = pArea->numActiveIf;    initialActiveHost = pArea->numActiveHost;    for ( pAttachedClient = (mApiOspfClient_t *)lstFirst( &pArea->listIfAttached);          pAttachedClient != NULL;          pAttachedClient = (mApiOspfClient_t *)lstNext( &pAttachedClient->node ) )    {        if ( pAttachedClient->pClient == pCurrClient )        {            switch( pAttachedClient->clientType )            {                case EmApiOspfClientType_intf:                    {                        mApiOspfIf_t *pIf;                        pArea->numIfAttached--;                        pIf = (mApiOspfIf_t *)pCurrClient;                        if ( (pIf->ospfIfStatus == EmApiOspfRowStatus_active) &&                             (pIf->ospfIfAdminStat == EmApiOspf_enabled) )                        {                            if ( pArea->numActiveIf > 0 )                                pArea->numActiveIf--;                        }                    }                    break;                case EmApiOspfClientType_vintf:                    {                        mApiOspfVirtIf_t *pVirtIf;                        pArea->numVirtIfAttached--;                        pVirtIf = (mApiOspfVirtIf_t *)pCurrClient;                        if ( pVirtIf->ospfVirtIfStatus == EmApiOspfRowStatus_active )                        {                            if ( pArea->numActiveVirtIf > 0 )                                pArea->numActiveVirtIf--;                        }                    }                    break;                case EmApiOspfClientType_host:                    {                        mApiOspfHost_t *pHost;                        pArea->numHostAttached--;                        pHost = (mApiOspfHost_t *)pCurrClient;                        if ( pHost->ospfHostStatus == EmApiOspfRowStatus_active )                        {                            if ( pArea->numActiveHost > 0 )                                pArea->numActiveHost--;                        }                    }                    break;                case EmApiOspfClientType_nbr:                case EmApiOspfClientType_ag:                   mApiOspfPrintf(("ospf_mApi_areaDeregisterIf:Incorrect client type\n"));                   break;            }            /* delete the node pointed to by pIfClient */            lstDelete( &pArea->listIfAttached, &pAttachedClient->node );            /* free the allocated memory */            free( (void *)pAttachedClient );            pAttachedClient = NULL;            break;        }    }    /* update the area attributes, if necessary */    ospf_mApi_areaStatusUpdate( pArea, initialActiveIf, initialActiveHost );    return;}/***************************************************************************************** ospf_mApi_ifRegisterNbr - register neighbor to an interface** This routine add a statically configured neighbor to the listNbrAttached linked* list for an interface. This routine is invoked each time a neighbor is statically* created.** RETURNS: OK or ERROR** NOMANUAL*/LOCAL STATUS ospf_mApi_ifRegisterNbr( mApiOspfIf_t *pIf, mApiOspfNbr_t *pNbr ){    mApiOspfClient_t     *pAttachedClient;    mApiOspfNbr_t        *pAttachedNbr;    /* make sure we don't have a duplicate entry */    for ( pAttachedClient = (mApiOspfClient_t *)lstFirst( &pIf->listNbrAttached );          pAttachedClient != NULL;          pAttachedClient = (mApiOspfClient_t *)lstNext( &pAttachedClient->node ) )    {        pAttachedNbr = (mApiOspfNbr_t *)pAttachedClient->pClient;        if ( (pAttachedNbr->ospfNbrIpAddr == pNbr->ospfNbrIpAddr) &&             (pAttachedNbr->ospfNbrAddressLessIndex == pNbr->ospfNbrAddressLessIndex) )        {            mApiOspfPrintf(("ospf_mApi_ifRegisterNbr:found neighbor\n"));            /* neighbor already registered. */            return OK;        }    }    /* if we are here, neighbor is not found on the listNbrAttached list */    pAttachedClient = (mApiOspfClient_t *)calloc( 1, sizeof(mApiOspfClient_t) );    if ( pAttachedClient == NULL )    {        pNbr->pIf = NULL;        mApiOspfError(("ospf_mApi_ifRegisterNbr:can't calloc mApiOspfClient_t\n"));        return ERROR;    }    /* save the neighbor information */    pAttachedClient->clientType = EmApiOspfClientType_nbr;    pAttachedClient->pClient = pNbr;    /* tell neighbor about this interface that it registered to */    pNbr->pIf = (void *)pIf;    /* append this node to the end of the listNbrAttached linked list */    lstAdd( &pIf->listNbrAttached, &pAttachedClient->node );    pIf->numNbrAttached++;    return OK;}/**************************************************************************************** ospf_mApi_ifDeregisterNbr - de-regsiter this given neighbor from the interface** This routine de-register the statically configured neighbor from the listNbrAttached* linked list found in the interface instance. This routine is called each time the* statically configured neighbor is deleted.**/LOCAL void ospf_mApi_ifDeregisterNbr( mApiOspfIf_t *pIf, mApiOspfNbr_t *pNbr ){    mApiOspfClient_t *pAttachedClient;    for ( pAttachedClient = (mApiOspfClient_t *)lstFirst( &pIf->listNbrAttached );          pAttachedClient != NULL;          pAttachedClient = (mApiOspfClient_t *)lstNext( &pAttachedClient->node ) )    {        if ( pAttachedClient->pClient == pNbr )        {            /* tell neighbor it is no longer register to this interface */            pNbr->pIf = NULL;            /* found the attached neighbor */            pIf->numNbrAttached--;            /* delete the node pointed to by pAttachedClient */            lstDelete( &pIf->listNbrAttached, &pAttachedClient->node );            /* free the allocated memory */            free( (void *)pAttachedClient );            pAttachedClient = NULL;            mApiOspfPrintf(("ospf_mApi_ifDeregisterNbr:found neighbor.\n"));            return;        }    }    /* if we are here, neighbor is not found */    mApiOspfPrintf(("ospf_mApi_ifDeregisterNbr:neighbor not found\n"));    return;}/***************************************************************************************** ospf_mApi_areaRegisterAg - register area aggregate instanc

⌨️ 快捷键说明

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