datapath-windows/ovsext/Vport.c
/*
 * --------------------------------------------------------------------------
 * Function to process addition of a NIC connection on the Hyper-V switch.
 * XXX: Posting an event to DPIF is incorrect here. However, it might be useful
 * to post an event to netdev-windows.c.
 * --------------------------------------------------------------------------
 */
Function to process addition of a NIC connection on the Hyper-V switch.
XXX: Posting an event to DPIF is incorrect here. However, it might be useful
to post an event to netdev-windows.c.
Function to process addition of a NIC connection on the Hyper - V switch . XXX : Posting an event to DPIF is incorrect here . However it might be useful to post an event to netdev - windows . c .
NDIS_STATUS
HvCreateNic(POVS_SWITCH_CONTEXT switchContext,
            PNDIS_SWITCH_NIC_PARAMETERS nicParam)
{
    POVS_VPORT_ENTRY vport;
    NDIS_STATUS status = NDIS_STATUS_SUCCESS;
    IF_COUNTED_STRING portFriendlyName = {0};
    LOCK_STATE_EX lockState;
    VPORT_NIC_ENTER(nicParam);
    OvsWaitActivate(switchContext, OVS_VPORT_DEFAULT_WAIT_TIME_MICROSEC);
    if (!switchContext->isActivated) {
        OVS_LOG_WARN("Switch is not activated yet.");
        status = NDIS_STATUS_NOT_SUPPORTED;
        goto done;
    }
    if (OvsIsInternalNIC(nicParam->NicType) ||
        OvsIsRealExternalNIC(nicParam->NicType, nicParam->NicIndex)) {
        GetNICAlias(nicParam, &portFriendlyName);
    }
    NdisAcquireRWLockWrite(switchContext->dispatchLock, &lockState, 0);
    if (OvsIsRealExternalNIC(nicParam->NicType, nicParam->NicIndex)) {
        ASSERT(OvsFindVportByPortIdAndNicIndex(switchContext,
                                               nicParam->PortId,
                                               nicParam->NicIndex) == NULL);
        char convertString[256];
        RtlZeroMemory(convertString, 256);
        NdisReleaseRWLock(switchContext->dispatchLock, &lockState);
        status = OvsConvertIfCountedStrToAnsiStr(&portFriendlyName,
                                                 convertString,
                                                 OVS_MAX_PORT_NAME_LENGTH);
        NdisAcquireRWLockWrite(switchContext->dispatchLock, &lockState, 0);
        if (status != NDIS_STATUS_SUCCESS) {
            goto add_nic_done;
        }
        POVS_VPORT_ENTRY ovsVport = OvsFindVportByOvsName(switchContext,
                                                          convertString);
        if (ovsVport != NULL) {
            UpdateSwitchCtxWithVport(switchContext, ovsVport, FALSE);
        } else {
            NDIS_SWITCH_PORT_PARAMETERS portParam;
            POVS_VPORT_ENTRY virtExtVport =
                (POVS_VPORT_ENTRY)switchContext->virtualExternalVport;
            ASSERT(virtExtVport);
            OvsCopyPortParamsFromVport(virtExtVport, &portParam);
            NdisReleaseRWLock(switchContext->dispatchLock, &lockState);
            status = HvCreatePort(switchContext, &portParam,
                                  nicParam->NicIndex);
            NdisAcquireRWLockWrite(switchContext->dispatchLock, &lockState, 0);
            if (status != NDIS_STATUS_SUCCESS) {
                goto add_nic_done;
            }
        }
    }
    vport = OvsFindVportByPortIdAndNicIndex(switchContext, nicParam->PortId,
                                            nicParam->NicIndex);
    if (vport == NULL) {
        OVS_LOG_ERROR("Create NIC without Switch Port,"
                      " PortId: %x, NicIndex: %d",
                      nicParam->PortId, nicParam->NicIndex);
        status = NDIS_STATUS_INVALID_PARAMETER;
        goto add_nic_done;
    }
    OvsInitVportWithNicParam(switchContext, vport, nicParam);
    if (OvsIsInternalNIC(nicParam->NicType) ||
        OvsIsRealExternalNIC(nicParam->NicType, nicParam->NicIndex)) {
        RtlCopyMemory(&vport->portFriendlyName, &portFriendlyName,
                      sizeof portFriendlyName);
    }
add_nic_done:
    NdisReleaseRWLock(switchContext->dispatchLock, &lockState);
done:
    VPORT_NIC_EXIT(nicParam);
    OVS_LOG_TRACE("Exit: status %8x.\n", status);
    return status;
}
NDIS_STATUS HvCreateNic ( POVS_SWITCH_CONTEXT switchContext , PNDIS_SWITCH_NIC_PARAMETERS nicParam ) { POVS_VPORT_ENTRY vport ; NDIS_STATUS status = NDIS_STATUS_SUCCESS ; IF_COUNTED_STRING portFriendlyName = { 0 } ; LOCK_STATE_EX lockState ; VPORT_NIC_ENTER ( nicParam ) ; OvsWaitActivate ( switchContext , OVS_VPORT_DEFAULT_WAIT_TIME_MICROSEC ) ; if ( ! switchContext -> isActivated ) { OVS_LOG_WARN ( " " ) ; status = NDIS_STATUS_NOT_SUPPORTED ; goto done ; } if ( OvsIsInternalNIC ( nicParam -> NicType ) || OvsIsRealExternalNIC ( nicParam -> NicType , nicParam -> NicIndex ) ) { GetNICAlias ( nicParam , & portFriendlyName ) ; } NdisAcquireRWLockWrite ( switchContext -> dispatchLock , & lockState , 0 ) ; if ( OvsIsRealExternalNIC ( nicParam -> NicType , nicParam -> NicIndex ) ) { ASSERT ( OvsFindVportByPortIdAndNicIndex ( switchContext , nicParam -> PortId , nicParam -> NicIndex ) == NULL ) ; char convertString [ 256 ] ; RtlZeroMemory ( convertString , 256 ) ; NdisReleaseRWLock ( switchContext -> dispatchLock , & lockState ) ; status = OvsConvertIfCountedStrToAnsiStr ( & portFriendlyName , convertString , OVS_MAX_PORT_NAME_LENGTH ) ; NdisAcquireRWLockWrite ( switchContext -> dispatchLock , & lockState , 0 ) ; if ( status != NDIS_STATUS_SUCCESS ) { goto add_nic_done ; } POVS_VPORT_ENTRY ovsVport = OvsFindVportByOvsName ( switchContext , convertString ) ; if ( ovsVport != NULL ) { UpdateSwitchCtxWithVport ( switchContext , ovsVport , FALSE ) ; } else { NDIS_SWITCH_PORT_PARAMETERS portParam ; POVS_VPORT_ENTRY virtExtVport = ( POVS_VPORT_ENTRY ) switchContext -> virtualExternalVport ; ASSERT ( virtExtVport ) ; OvsCopyPortParamsFromVport ( virtExtVport , & portParam ) ; NdisReleaseRWLock ( switchContext -> dispatchLock , & lockState ) ; status = HvCreatePort ( switchContext , & portParam , nicParam -> NicIndex ) ; NdisAcquireRWLockWrite ( switchContext -> dispatchLock , & lockState , 0 ) ; if ( status != NDIS_STATUS_SUCCESS ) { goto add_nic_done ; } } } vport = OvsFindVportByPortIdAndNicIndex ( switchContext , nicParam -> PortId , nicParam -> NicIndex ) ; if ( vport == NULL ) { OVS_LOG_ERROR ( " " " " , nicParam -> PortId , nicParam -> NicIndex ) ; status = NDIS_STATUS_INVALID_PARAMETER ; goto add_nic_done ; } OvsInitVportWithNicParam ( switchContext , vport , nicParam ) ; if ( OvsIsInternalNIC ( nicParam -> NicType ) || OvsIsRealExternalNIC ( nicParam -> NicType , nicParam -> NicIndex ) ) { RtlCopyMemory ( & vport -> portFriendlyName , & portFriendlyName , sizeof portFriendlyName ) ; } add_nic_done : NdisReleaseRWLock ( switchContext -> dispatchLock , & lockState ) ; done : VPORT_NIC_EXIT ( nicParam ) ; OVS_LOG_TRACE ( " \n " , status ) ; return status ; }
Function to process addition of a NIC connection on the Hyper-V switch.
Function to process addition of a NIC connection on the Hyper - V switch .
/* Wait for lists to be initialized. */ /* Veto the creation of nic */ /*
     * There can be one or more NICs for the external port. We create a vport
     * structure for each such NIC, and each NIC inherits a lot of properties
     * from the parent external port.
     */ /* The VPORT can be bound to OVS datapath already. Search for it
         * using its friendly name and if not found allocate a new port
         */