datapath-windows/ovsext/Vport.c
/*
 * --------------------------------------------------------------------------
 * Function to process updates to a NIC on the Hyper-V switch.
 * --------------------------------------------------------------------------
 */
Function to process updates to a NIC on the Hyper-V switch.
Function to process updates to a NIC on the Hyper - V switch .
VOID
HvUpdateNic(POVS_SWITCH_CONTEXT switchContext,
            PNDIS_SWITCH_NIC_PARAMETERS nicParam)
{
    POVS_VPORT_ENTRY vport;
    LOCK_STATE_EX lockState;
    UINT32 event = 0;
    IF_COUNTED_STRING portFriendlyName = {0};
    BOOLEAN nameChanged = FALSE;
    BOOLEAN aliasLookup = FALSE;
    VPORT_NIC_ENTER(nicParam);
    OvsWaitActivate(switchContext, OVS_VPORT_DEFAULT_WAIT_TIME_MICROSEC);
    if (!switchContext->isActivated) {
        OVS_LOG_WARN("Switch is not activated yet.");
        goto update_nic_done;
    }
    if (nicParam->NicType == NdisSwitchNicTypeInternal ||
        OvsIsRealExternalNIC(nicParam->NicType, nicParam->NicIndex)) {
        GetNICAlias(nicParam, &portFriendlyName);
        aliasLookup = TRUE;
    }
    NdisAcquireRWLockWrite(switchContext->dispatchLock, &lockState, 0);
    vport = OvsFindVportByPortIdAndNicIndex(switchContext,
                                            nicParam->PortId,
                                            nicParam->NicIndex);
    if (vport == NULL) {
        NdisReleaseRWLock(switchContext->dispatchLock, &lockState);
        OVS_LOG_WARN("Vport search failed.");
        goto update_nic_done;
    }
    switch (nicParam->NicType) {
    case NdisSwitchNicTypeExternal:
    case NdisSwitchNicTypeInternal:
        RtlCopyMemory(&vport->netCfgInstanceId, &nicParam->NetCfgInstanceId,
                      sizeof (GUID));
        if (aliasLookup) {
            if (RtlCompareMemory(&vport->portFriendlyName,
                    &portFriendlyName, vport->portFriendlyName.Length) !=
                    vport->portFriendlyName.Length) {
                RtlCopyMemory(&vport->portFriendlyName, &portFriendlyName,
                    sizeof portFriendlyName);
                nameChanged = TRUE;
            }
        }
        break;
    case NdisSwitchNicTypeSynthetic:
    case NdisSwitchNicTypeEmulated:
        if (!RtlEqualMemory(vport->vmMacAddress, nicParam->VMMacAddress,
                           sizeof (vport->vmMacAddress))) {
            event |= OVS_EVENT_MAC_CHANGE;
            RtlCopyMemory(vport->vmMacAddress, nicParam->VMMacAddress,
                          sizeof (vport->vmMacAddress));
        }
        break;
    default:
        ASSERT(0);
    }
    if (!RtlEqualMemory(vport->permMacAddress, nicParam->PermanentMacAddress,
                        sizeof (vport->permMacAddress))) {
        RtlCopyMemory(vport->permMacAddress, nicParam->PermanentMacAddress,
                      sizeof (vport->permMacAddress));
        event |= OVS_EVENT_MAC_CHANGE;
    }
    if (!RtlEqualMemory(vport->currMacAddress, nicParam->CurrentMacAddress,
                        sizeof (vport->currMacAddress))) {
        RtlCopyMemory(vport->currMacAddress, nicParam->CurrentMacAddress,
                      sizeof (vport->currMacAddress));
        event |= OVS_EVENT_MAC_CHANGE;
    }
    if (vport->mtu != nicParam->MTU) {
        vport->mtu = nicParam->MTU;
        event |= OVS_EVENT_MTU_CHANGE;
    }
    vport->numaNodeId = nicParam->NumaNodeId;
    if (nameChanged) {
        OVS_VPORT_EVENT_ENTRY evt;
        evt.portNo = vport->portNo;
        evt.ovsType = vport->ovsType;
        evt.upcallPid = vport->upcallPid;
        RtlCopyMemory(&evt.ovsName, &vport->ovsName, sizeof evt.ovsName);
        evt.type = OVS_EVENT_LINK_DOWN;
        OvsRemoveAndDeleteVport(NULL, switchContext, vport, FALSE, TRUE);
        OvsPostVportEvent(&evt);
    }
    NdisReleaseRWLock(switchContext->dispatchLock, &lockState);
update_nic_done:
    VPORT_NIC_EXIT(nicParam);
}
VOID HvUpdateNic ( POVS_SWITCH_CONTEXT switchContext , PNDIS_SWITCH_NIC_PARAMETERS nicParam ) { POVS_VPORT_ENTRY vport ; LOCK_STATE_EX lockState ; UINT32 event = 0 ; IF_COUNTED_STRING portFriendlyName = { 0 } ; BOOLEAN nameChanged = FALSE ; BOOLEAN aliasLookup = FALSE ; VPORT_NIC_ENTER ( nicParam ) ; OvsWaitActivate ( switchContext , OVS_VPORT_DEFAULT_WAIT_TIME_MICROSEC ) ; if ( ! switchContext -> isActivated ) { OVS_LOG_WARN ( " " ) ; goto update_nic_done ; } if ( nicParam -> NicType == NdisSwitchNicTypeInternal || OvsIsRealExternalNIC ( nicParam -> NicType , nicParam -> NicIndex ) ) { GetNICAlias ( nicParam , & portFriendlyName ) ; aliasLookup = TRUE ; } NdisAcquireRWLockWrite ( switchContext -> dispatchLock , & lockState , 0 ) ; vport = OvsFindVportByPortIdAndNicIndex ( switchContext , nicParam -> PortId , nicParam -> NicIndex ) ; if ( vport == NULL ) { NdisReleaseRWLock ( switchContext -> dispatchLock , & lockState ) ; OVS_LOG_WARN ( " " ) ; goto update_nic_done ; } switch ( nicParam -> NicType ) { case NdisSwitchNicTypeExternal : case NdisSwitchNicTypeInternal : RtlCopyMemory ( & vport -> netCfgInstanceId , & nicParam -> NetCfgInstanceId , sizeof ( GUID ) ) ; if ( aliasLookup ) { if ( RtlCompareMemory ( & vport -> portFriendlyName , & portFriendlyName , vport -> portFriendlyName . Length ) != vport -> portFriendlyName . Length ) { RtlCopyMemory ( & vport -> portFriendlyName , & portFriendlyName , sizeof portFriendlyName ) ; nameChanged = TRUE ; } } break ; case NdisSwitchNicTypeSynthetic : case NdisSwitchNicTypeEmulated : if ( ! RtlEqualMemory ( vport -> vmMacAddress , nicParam -> VMMacAddress , sizeof ( vport -> vmMacAddress ) ) ) { event |= OVS_EVENT_MAC_CHANGE ; RtlCopyMemory ( vport -> vmMacAddress , nicParam -> VMMacAddress , sizeof ( vport -> vmMacAddress ) ) ; } break ; default : ASSERT ( 0 ) ; } if ( ! RtlEqualMemory ( vport -> permMacAddress , nicParam -> PermanentMacAddress , sizeof ( vport -> permMacAddress ) ) ) { RtlCopyMemory ( vport -> permMacAddress , nicParam -> PermanentMacAddress , sizeof ( vport -> permMacAddress ) ) ; event |= OVS_EVENT_MAC_CHANGE ; } if ( ! RtlEqualMemory ( vport -> currMacAddress , nicParam -> CurrentMacAddress , sizeof ( vport -> currMacAddress ) ) ) { RtlCopyMemory ( vport -> currMacAddress , nicParam -> CurrentMacAddress , sizeof ( vport -> currMacAddress ) ) ; event |= OVS_EVENT_MAC_CHANGE ; } if ( vport -> mtu != nicParam -> MTU ) { vport -> mtu = nicParam -> MTU ; event |= OVS_EVENT_MTU_CHANGE ; } vport -> numaNodeId = nicParam -> NumaNodeId ; if ( nameChanged ) { OVS_VPORT_EVENT_ENTRY evt ; evt . portNo = vport -> portNo ; evt . ovsType = vport -> ovsType ; evt . upcallPid = vport -> upcallPid ; RtlCopyMemory ( & evt . ovsName , & vport -> ovsName , sizeof evt . ovsName ) ; evt . type = OVS_EVENT_LINK_DOWN ; OvsRemoveAndDeleteVport ( NULL , switchContext , vport , FALSE , TRUE ) ; OvsPostVportEvent ( & evt ) ; } NdisReleaseRWLock ( switchContext -> dispatchLock , & lockState ) ; update_nic_done : VPORT_NIC_EXIT ( nicParam ) ; }
Function to process updates to a NIC on the Hyper-V switch.
Function to process updates to a NIC on the Hyper - V switch .
/* Wait for lists to be initialized. */ /* GetNICAlias() must be called outside of a lock. */ /*
     * XXX: Not sure what kind of event to post here. DPIF is not interested in
     * changes to MAC address. Netdev-windows might be intrested, though.
     * That said, if the name chagnes, not clear what kind of event to be
     * posted. We might have to delete the vport, and have userspace recreate
     * it.
     */