datapath-windows/ovsext/Vport.c
/*
 * --------------------------------------------------------------------------
 * Utility function that populates a 'OVS_VPORT_EXT_INFO' structure for the
 * specified vport.
 * --------------------------------------------------------------------------
 */
Utility function that populates a 'OVS_VPORT_EXT_INFO' structure for the
specified vport.
Utility function that populates a ' OVS_VPORT_EXT_INFO ' structure for the specified vport .
NTSTATUS
OvsGetExtInfoIoctl(POVS_VPORT_GET vportGet,
                   POVS_VPORT_EXT_INFO extInfo)
{
    POVS_VPORT_ENTRY vport;
    LOCK_STATE_EX lockState;
    NTSTATUS status = STATUS_SUCCESS;
    BOOLEAN doConvert = FALSE;
    RtlZeroMemory(extInfo, sizeof (POVS_VPORT_EXT_INFO));
    NdisAcquireRWLockRead(gOvsSwitchContext->dispatchLock, &lockState, 0);
    if (vportGet->portNo == 0) {
        vport = OvsFindVportByHvNameA(gOvsSwitchContext, vportGet->name);
        if (vport == NULL) {
            vport = OvsFindVportByOvsName(gOvsSwitchContext, vportGet->name);
        }
    } else {
        vport = OvsFindVportByPortNo(gOvsSwitchContext, vportGet->portNo);
    }
    if (vport == NULL || (vport->ovsState != OVS_STATE_CONNECTED &&
                          vport->ovsState != OVS_STATE_NIC_CREATED)) {
        NdisReleaseRWLock(gOvsSwitchContext->dispatchLock, &lockState);
        if (vportGet->portNo) {
            OVS_LOG_WARN("vport %u does not exist any more", vportGet->portNo);
        } else {
            OVS_LOG_WARN("vport %s does not exist any more", vportGet->name);
        }
        status = STATUS_DEVICE_DOES_NOT_EXIST;
        goto ext_info_done;
    }
    extInfo->dpNo = vportGet->dpNo;
    extInfo->portNo = vport->portNo;
    RtlCopyMemory(extInfo->macAddress, vport->currMacAddress,
                  sizeof (vport->currMacAddress));
    RtlCopyMemory(extInfo->permMACAddress, vport->permMacAddress,
                  sizeof (vport->permMacAddress));
    if (vport->ovsType == OVS_VPORT_TYPE_NETDEV) {
        RtlCopyMemory(extInfo->vmMACAddress, vport->vmMacAddress,
                      sizeof (vport->vmMacAddress));
    }
    extInfo->nicIndex = vport->nicIndex;
    extInfo->portId = vport->portId;
    extInfo->type = vport->ovsType;
    extInfo->mtu = vport->mtu;
    if (vport->ovsState == OVS_STATE_NIC_CREATED) {
       extInfo->status = OVS_EVENT_CONNECT | OVS_EVENT_LINK_DOWN;
    } else if (vport->ovsState == OVS_STATE_CONNECTED) {
       extInfo->status = OVS_EVENT_CONNECT | OVS_EVENT_LINK_UP;
    } else {
       extInfo->status = OVS_EVENT_DISCONNECT;
    }
    if (extInfo->type == OVS_VPORT_TYPE_NETDEV &&
        (vport->ovsState == OVS_STATE_NIC_CREATED  ||
         vport->ovsState == OVS_STATE_CONNECTED)) {
        doConvert = TRUE;
    } else {
        extInfo->vmUUID[0] = 0;
        extInfo->vifUUID[0] = 0;
    }
    NdisReleaseRWLock(gOvsSwitchContext->dispatchLock, &lockState);
    if (doConvert) {
        status = OvsConvertIfCountedStrToAnsiStr(&vport->portFriendlyName,
                                                 extInfo->name,
                                                 OVS_MAX_PORT_NAME_LENGTH);
        if (status != STATUS_SUCCESS) {
            OVS_LOG_INFO("Fail to convert NIC name.");
            extInfo->name[0] = 0;
        }
        status = OvsConvertIfCountedStrToAnsiStr(&vport->vmName,
                                                 extInfo->vmUUID,
                                                 OVS_MAX_VM_UUID_LEN);
        if (status != STATUS_SUCCESS) {
            OVS_LOG_INFO("Fail to convert VM name.");
            extInfo->vmUUID[0] = 0;
        }
        status = OvsConvertIfCountedStrToAnsiStr(&vport->nicName,
                                                 extInfo->vifUUID,
                                                 OVS_MAX_VIF_UUID_LEN);
        if (status != STATUS_SUCCESS) {
            OVS_LOG_INFO("Fail to convert nic UUID");
            extInfo->vifUUID[0] = 0;
        }
        status = STATUS_SUCCESS;
    }
ext_info_done:
    return status;
}
NTSTATUS OvsGetExtInfoIoctl ( POVS_VPORT_GET vportGet , POVS_VPORT_EXT_INFO extInfo ) { POVS_VPORT_ENTRY vport ; LOCK_STATE_EX lockState ; NTSTATUS status = STATUS_SUCCESS ; BOOLEAN doConvert = FALSE ; RtlZeroMemory ( extInfo , sizeof ( POVS_VPORT_EXT_INFO ) ) ; NdisAcquireRWLockRead ( gOvsSwitchContext -> dispatchLock , & lockState , 0 ) ; if ( vportGet -> portNo == 0 ) { vport = OvsFindVportByHvNameA ( gOvsSwitchContext , vportGet -> name ) ; if ( vport == NULL ) { vport = OvsFindVportByOvsName ( gOvsSwitchContext , vportGet -> name ) ; } } else { vport = OvsFindVportByPortNo ( gOvsSwitchContext , vportGet -> portNo ) ; } if ( vport == NULL || ( vport -> ovsState != OVS_STATE_CONNECTED && vport -> ovsState != OVS_STATE_NIC_CREATED ) ) { NdisReleaseRWLock ( gOvsSwitchContext -> dispatchLock , & lockState ) ; if ( vportGet -> portNo ) { OVS_LOG_WARN ( " " , vportGet -> portNo ) ; } else { OVS_LOG_WARN ( " " , vportGet -> name ) ; } status = STATUS_DEVICE_DOES_NOT_EXIST ; goto ext_info_done ; } extInfo -> dpNo = vportGet -> dpNo ; extInfo -> portNo = vport -> portNo ; RtlCopyMemory ( extInfo -> macAddress , vport -> currMacAddress , sizeof ( vport -> currMacAddress ) ) ; RtlCopyMemory ( extInfo -> permMACAddress , vport -> permMacAddress , sizeof ( vport -> permMacAddress ) ) ; if ( vport -> ovsType == OVS_VPORT_TYPE_NETDEV ) { RtlCopyMemory ( extInfo -> vmMACAddress , vport -> vmMacAddress , sizeof ( vport -> vmMacAddress ) ) ; } extInfo -> nicIndex = vport -> nicIndex ; extInfo -> portId = vport -> portId ; extInfo -> type = vport -> ovsType ; extInfo -> mtu = vport -> mtu ; if ( vport -> ovsState == OVS_STATE_NIC_CREATED ) { extInfo -> status = OVS_EVENT_CONNECT | OVS_EVENT_LINK_DOWN ; } else if ( vport -> ovsState == OVS_STATE_CONNECTED ) { extInfo -> status = OVS_EVENT_CONNECT | OVS_EVENT_LINK_UP ; } else { extInfo -> status = OVS_EVENT_DISCONNECT ; } if ( extInfo -> type == OVS_VPORT_TYPE_NETDEV && ( vport -> ovsState == OVS_STATE_NIC_CREATED || vport -> ovsState == OVS_STATE_CONNECTED ) ) { doConvert = TRUE ; } else { extInfo -> vmUUID [ 0 ] = 0 ; extInfo -> vifUUID [ 0 ] = 0 ; } NdisReleaseRWLock ( gOvsSwitchContext -> dispatchLock , & lockState ) ; if ( doConvert ) { status = OvsConvertIfCountedStrToAnsiStr ( & vport -> portFriendlyName , extInfo -> name , OVS_MAX_PORT_NAME_LENGTH ) ; if ( status != STATUS_SUCCESS ) { OVS_LOG_INFO ( " " ) ; extInfo -> name [ 0 ] = 0 ; } status = OvsConvertIfCountedStrToAnsiStr ( & vport -> vmName , extInfo -> vmUUID , OVS_MAX_VM_UUID_LEN ) ; if ( status != STATUS_SUCCESS ) { OVS_LOG_INFO ( " " ) ; extInfo -> vmUUID [ 0 ] = 0 ; } status = OvsConvertIfCountedStrToAnsiStr ( & vport -> nicName , extInfo -> vifUUID , OVS_MAX_VIF_UUID_LEN ) ; if ( status != STATUS_SUCCESS ) { OVS_LOG_INFO ( " " ) ; extInfo -> vifUUID [ 0 ] = 0 ; } status = STATUS_SUCCESS ; } ext_info_done : return status ; }
Utility function that populates a 'OVS_VPORT_EXT_INFO' structure for the
 specified vport.
Utility function that populates a ' OVS_VPORT_EXT_INFO ' structure for the specified vport .
/* If the port is not a Hyper-V port and it has been added earlier,
             * we'll find it in 'ovsPortNameHashArray'. */ /*
     * TO be revisit XXX
     */ /*
         * for now ignore status
         */