datapath-windows/ovsext/Vport.c
/*
 * --------------------------------------------------------------------------
 * Provides functionality that is partly complementatry to
 * InitOvsVportCommon()/UpdateSwitchCtxWithVport().
 *
 * 'hvDelete' indicates if caller is removing the vport as a result of the
 * port being removed on the Hyper-V switch.
 * 'ovsDelete' indicates if caller is removing the vport as a result of the
 * port being removed from OVS userspace.
 * --------------------------------------------------------------------------
 */
Provides functionality that is partly complementatry to
InitOvsVportCommon()/UpdateSwitchCtxWithVport().

'hvDelete' indicates if caller is removing the vport as a result of the
port being removed on the Hyper-V switch.
'ovsDelete' indicates if caller is removing the vport as a result of the
port being removed from OVS userspace.
Provides functionality that is partly complementatry to InitOvsVportCommon () / UpdateSwitchCtxWithVport () . ' hvDelete ' indicates if caller is removing the vport as a result of the port being removed on the Hyper - V switch . ' ovsDelete ' indicates if caller is removing the vport as a result of the port being removed from OVS userspace .
NTSTATUS
OvsRemoveAndDeleteVport(PVOID usrParamsContext,
                        POVS_SWITCH_CONTEXT switchContext,
                        POVS_VPORT_ENTRY vport,
                        BOOLEAN hvDelete,
                        BOOLEAN ovsDelete)
{
    POVS_USER_PARAMS_CONTEXT usrParamsCtx =
        (POVS_USER_PARAMS_CONTEXT)usrParamsContext;
    BOOLEAN hvSwitchPort = FALSE;
    BOOLEAN deletedOnOvs = FALSE;
    BOOLEAN deletedOnHv = FALSE;
    switch (vport->ovsType) {
    case OVS_VPORT_TYPE_INTERNAL:
        if (hvDelete && vport->isAbsentOnHv == FALSE) {
            switchContext->countInternalVports--;
            ASSERT(switchContext->countInternalVports >= 0);
            OvsUnBindVportWithIpHelper(vport, switchContext);
        }
        hvSwitchPort = TRUE;
        break;
    case OVS_VPORT_TYPE_VXLAN:
    {
        NTSTATUS status;
        status = OvsRemoveTunnelVport(usrParamsCtx, switchContext, vport,
                                      hvDelete, ovsDelete);
        if (status != STATUS_SUCCESS) {
            return status;
        }
    }
    case OVS_VPORT_TYPE_GENEVE:
        OvsCleanupGeneveTunnel(vport);
        break;
    case OVS_VPORT_TYPE_STT:
        OvsCleanupSttTunnel(vport);
        break;
    case OVS_VPORT_TYPE_GRE:
        OvsCleanupGreTunnel(vport);
        break;
    case OVS_VPORT_TYPE_NETDEV:
        if (vport->isExternal) {
            if (vport->nicIndex == 0) {
                ASSERT(hvDelete == TRUE);
                ASSERT(switchContext->numPhysicalNics == 0);
                switchContext->virtualExternalPortId = 0;
                switchContext->virtualExternalVport = NULL;
                OvsFreeMemoryWithTag(vport, OVS_VPORT_POOL_TAG);
                return STATUS_SUCCESS;
            }
        }
        hvSwitchPort = TRUE;
    default:
        break;
    }
    if (vport->isAbsentOnHv == TRUE) {
        deletedOnHv = TRUE;
    }
    if (vport->portNo == OVS_DPPORT_NUMBER_INVALID) {
        deletedOnOvs = TRUE;
    }
    if (hvDelete && !deletedOnHv) {
        vport->isAbsentOnHv = TRUE;
        if (vport->isExternal) {
            ASSERT(vport->nicIndex != 0);
            ASSERT(switchContext->numPhysicalNics);
            switchContext->numPhysicalNics--;
        }
        RemoveEntryList(&vport->portIdLink);
        InitializeListHead(&vport->portIdLink);
        deletedOnHv = TRUE;
    }
    if (ovsDelete && !deletedOnOvs) {
        vport->portNo = OVS_DPPORT_NUMBER_INVALID;
        vport->ovsName[0] = '\0';
        RemoveEntryList(&vport->ovsNameLink);
        InitializeListHead(&vport->ovsNameLink);
        RemoveEntryList(&vport->portNoLink);
        InitializeListHead(&vport->portNoLink);
        if (OvsIsTunnelVportType(vport->ovsType)) {
            RemoveEntryList(&vport->tunnelVportLink);
            InitializeListHead(&vport->tunnelVportLink);
        }
        deletedOnOvs = TRUE;
    }
    if (deletedOnHv && deletedOnOvs) {
        if (hvSwitchPort) {
            switchContext->numHvVports--;
        } else {
            switchContext->numNonHvVports--;
        }
        OvsFreeMemoryWithTag(vport, OVS_VPORT_POOL_TAG);
    }
    return STATUS_SUCCESS;
}
NTSTATUS OvsRemoveAndDeleteVport ( PVOID usrParamsContext , POVS_SWITCH_CONTEXT switchContext , POVS_VPORT_ENTRY vport , BOOLEAN hvDelete , BOOLEAN ovsDelete ) { POVS_USER_PARAMS_CONTEXT usrParamsCtx = ( POVS_USER_PARAMS_CONTEXT ) usrParamsContext ; BOOLEAN hvSwitchPort = FALSE ; BOOLEAN deletedOnOvs = FALSE ; BOOLEAN deletedOnHv = FALSE ; switch ( vport -> ovsType ) { case OVS_VPORT_TYPE_INTERNAL : if ( hvDelete && vport -> isAbsentOnHv == FALSE ) { switchContext -> countInternalVports -- ; ASSERT ( switchContext -> countInternalVports >= 0 ) ; OvsUnBindVportWithIpHelper ( vport , switchContext ) ; } hvSwitchPort = TRUE ; break ; case OVS_VPORT_TYPE_VXLAN : { NTSTATUS status ; status = OvsRemoveTunnelVport ( usrParamsCtx , switchContext , vport , hvDelete , ovsDelete ) ; if ( status != STATUS_SUCCESS ) { return status ; } } case OVS_VPORT_TYPE_GENEVE : OvsCleanupGeneveTunnel ( vport ) ; break ; case OVS_VPORT_TYPE_STT : OvsCleanupSttTunnel ( vport ) ; break ; case OVS_VPORT_TYPE_GRE : OvsCleanupGreTunnel ( vport ) ; break ; case OVS_VPORT_TYPE_NETDEV : if ( vport -> isExternal ) { if ( vport -> nicIndex == 0 ) { ASSERT ( hvDelete == TRUE ) ; ASSERT ( switchContext -> numPhysicalNics == 0 ) ; switchContext -> virtualExternalPortId = 0 ; switchContext -> virtualExternalVport = NULL ; OvsFreeMemoryWithTag ( vport , OVS_VPORT_POOL_TAG ) ; return STATUS_SUCCESS ; } } hvSwitchPort = TRUE ; default : break ; } if ( vport -> isAbsentOnHv == TRUE ) { deletedOnHv = TRUE ; } if ( vport -> portNo == OVS_DPPORT_NUMBER_INVALID ) { deletedOnOvs = TRUE ; } if ( hvDelete && ! deletedOnHv ) { vport -> isAbsentOnHv = TRUE ; if ( vport -> isExternal ) { ASSERT ( vport -> nicIndex != 0 ) ; ASSERT ( switchContext -> numPhysicalNics ) ; switchContext -> numPhysicalNics -- ; } RemoveEntryList ( & vport -> portIdLink ) ; InitializeListHead ( & vport -> portIdLink ) ; deletedOnHv = TRUE ; } if ( ovsDelete && ! deletedOnOvs ) { vport -> portNo = OVS_DPPORT_NUMBER_INVALID ; vport -> ovsName [ 0 ] = ' \0 ' ; RemoveEntryList ( & vport -> ovsNameLink ) ; InitializeListHead ( & vport -> ovsNameLink ) ; RemoveEntryList ( & vport -> portNoLink ) ; InitializeListHead ( & vport -> portNoLink ) ; if ( OvsIsTunnelVportType ( vport -> ovsType ) ) { RemoveEntryList ( & vport -> tunnelVportLink ) ; InitializeListHead ( & vport -> tunnelVportLink ) ; } deletedOnOvs = TRUE ; } if ( deletedOnHv && deletedOnOvs ) { if ( hvSwitchPort ) { switchContext -> numHvVports -- ; } else { switchContext -> numNonHvVports -- ; } OvsFreeMemoryWithTag ( vport , OVS_VPORT_POOL_TAG ) ; } return STATUS_SUCCESS ; }
Provides functionality that is partly complementatry to
 InitOvsVportCommon()/UpdateSwitchCtxWithVport().
Provides functionality that is partly complementatry to InitOvsVportCommon () / UpdateSwitchCtxWithVport () .
/* Such a vport is not part of any of the hash tables, since it
                 * is not exposed to userspace. See Vport.h for explanation. */ /*
     * 'hvDelete' == TRUE indicates that the port should be removed from the
     * 'portIdHashArray', while 'ovsDelete' == TRUE indicates that the port
     * should be removed from 'portNoHashArray' and the 'ovsPortNameHashArray'.
     *
     * Both 'hvDelete' and 'ovsDelete' can be set to TRUE by the caller.
     */ /* Remove the port from the relevant lists. */ /* Remove the port from the relevant lists. */ /*
     * Deallocate the port if it has been deleted on the Hyper-V switch as well
     * as OVS userspace.
     */