datapath-windows/ovsext/Vport.c
/*
 * --------------------------------------------------------------------------
 * Function to process disconnect event of a NIC on the Hyper-V switch.
 * --------------------------------------------------------------------------
 */
Function to process disconnect event of a NIC on the Hyper-V switch.
Function to process disconnect event of a NIC on the Hyper - V switch .
VOID
HvDisconnectNic(POVS_SWITCH_CONTEXT switchContext,
                PNDIS_SWITCH_NIC_PARAMETERS nicParam)
{
    POVS_VPORT_ENTRY vport;
    LOCK_STATE_EX lockState;
    BOOLEAN isInternalPort = FALSE;
    OVS_VPORT_EVENT_ENTRY event;
    VPORT_NIC_ENTER(nicParam);
    OvsWaitActivate(switchContext, OVS_VPORT_DEFAULT_WAIT_TIME_MICROSEC);
    if (!switchContext->isActivated) {
        OVS_LOG_WARN("Switch is not activated yet.");
        goto done;
    }
    NdisAcquireRWLockWrite(switchContext->dispatchLock, &lockState, 0);
    vport = OvsFindVportByPortIdAndNicIndex(switchContext,
                                            nicParam->PortId,
                                            nicParam->NicIndex);
    if (!vport) {
        OVS_LOG_WARN("Vport not present.");
        NdisReleaseRWLock(switchContext->dispatchLock, &lockState);
        goto done;
    }
    vport->nicState = NdisSwitchNicStateDisconnected;
    vport->ovsState = OVS_STATE_NIC_CREATED;
    if (vport->ovsType == OVS_VPORT_TYPE_INTERNAL) {
        isInternalPort = TRUE;
    }
    event.portNo = vport->portNo;
    event.ovsType = vport->ovsType;
    event.upcallPid = vport->upcallPid;
    RtlCopyMemory(&event.ovsName, &vport->ovsName, sizeof event.ovsName);
    event.type = OVS_EVENT_LINK_DOWN;
    OvsPostVportEvent(&event);
    if (OvsIsRealExternalVport(vport)) {
        OvsRemoveAndDeleteVport(NULL, switchContext, vport, FALSE, TRUE);
    }
    if (isInternalPort) {
        OvsUnBindVportWithIpHelper(vport, switchContext);
    }
    NdisReleaseRWLock(switchContext->dispatchLock, &lockState);
done:
    VPORT_NIC_EXIT(nicParam);
}
VOID HvDisconnectNic ( POVS_SWITCH_CONTEXT switchContext , PNDIS_SWITCH_NIC_PARAMETERS nicParam ) { POVS_VPORT_ENTRY vport ; LOCK_STATE_EX lockState ; BOOLEAN isInternalPort = FALSE ; OVS_VPORT_EVENT_ENTRY event ; VPORT_NIC_ENTER ( nicParam ) ; OvsWaitActivate ( switchContext , OVS_VPORT_DEFAULT_WAIT_TIME_MICROSEC ) ; if ( ! switchContext -> isActivated ) { OVS_LOG_WARN ( " " ) ; goto done ; } NdisAcquireRWLockWrite ( switchContext -> dispatchLock , & lockState , 0 ) ; vport = OvsFindVportByPortIdAndNicIndex ( switchContext , nicParam -> PortId , nicParam -> NicIndex ) ; if ( ! vport ) { OVS_LOG_WARN ( " " ) ; NdisReleaseRWLock ( switchContext -> dispatchLock , & lockState ) ; goto done ; } vport -> nicState = NdisSwitchNicStateDisconnected ; vport -> ovsState = OVS_STATE_NIC_CREATED ; if ( vport -> ovsType == OVS_VPORT_TYPE_INTERNAL ) { isInternalPort = TRUE ; } event . portNo = vport -> portNo ; event . ovsType = vport -> ovsType ; event . upcallPid = vport -> upcallPid ; RtlCopyMemory ( & event . ovsName , & vport -> ovsName , sizeof event . ovsName ) ; event . type = OVS_EVENT_LINK_DOWN ; OvsPostVportEvent ( & event ) ; if ( OvsIsRealExternalVport ( vport ) ) { OvsRemoveAndDeleteVport ( NULL , switchContext , vport , FALSE , TRUE ) ; } if ( isInternalPort ) { OvsUnBindVportWithIpHelper ( vport , switchContext ) ; } NdisReleaseRWLock ( switchContext -> dispatchLock , & lockState ) ; done : VPORT_NIC_EXIT ( nicParam ) ; }
Function to process disconnect event of a NIC on the Hyper-V switch.
Function to process disconnect event of a NIC on the Hyper - V switch .
/* Wait for lists to be initialized. */ /*
     * Delete the port from the hash tables accessible to userspace. After this
     * point, userspace should not be able to access this port.
     */ /*
         * Don't delete the port from the hash tables here for internal port
         * because the internal port cannot be recreated in HvCreateNic(). It
         * only can be created in HvCreatePort() by issuing
         * OID_SWITCH_PORT_CREATE. We should wait extensible switch interface
         * to issue OID_SWITCH_PORT_TEARDOWN and OID_SWITCH_PORT_DELETE to
         * delete the internal port.
         */