diff options
Diffstat (limited to 'network/ndis/extension/samples/forward/MsForwardExt.c')
| -rw-r--r-- | network/ndis/extension/samples/forward/MsForwardExt.c | 798 |
1 files changed, 399 insertions, 399 deletions
diff --git a/network/ndis/extension/samples/forward/MsForwardExt.c b/network/ndis/extension/samples/forward/MsForwardExt.c index cabd6401..69583156 100644 --- a/network/ndis/extension/samples/forward/MsForwardExt.c +++ b/network/ndis/extension/samples/forward/MsForwardExt.c @@ -50,15 +50,15 @@ const NDIS_SWITCH_OBJECT_ID MacAddressPolicyStatusGuid = { 0x4E52, {0xAB, 0x74, 0x13, 0x25, 0x0B, 0xF7, 0xE8, 0xCF} }; - - + + NDIS_STATUS SxExtInitialize() /*++ - + Routine Description: No global information needed. - + --*/ { return NDIS_STATUS_SUCCESS; @@ -68,10 +68,10 @@ Routine Description: VOID SxExtUninitialize() /*++ - + Routine Description: No global information needed. - + --*/ { return; @@ -85,41 +85,41 @@ SxExtCreateSwitch( PNDIS_HANDLE *ExtensionContext ) /*++ - + Routine Description: This function allocated the switch context, and initializes its necessary members. - + --*/ { NDIS_STATUS status = NDIS_STATUS_SUCCESS; PMSFORWARD_CONTEXT switchContext; - + switchContext = ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(MSFORWARD_CONTEXT), SxExtAllocationTag); - + if (switchContext == NULL) { status = NDIS_STATUS_RESOURCES; goto Cleanup; } - + NdisZeroMemory(switchContext, sizeof(MSFORWARD_CONTEXT)); InitializeListHead(&switchContext->NicList); InitializeListHead(&switchContext->PropertyList); - + switchContext->DispatchLock = NdisAllocateRWLock(Switch->NdisFilterHandle); if (switchContext->DispatchLock == NULL) { status = NDIS_STATUS_RESOURCES; goto Cleanup; } - + switchContext->IsInitialRestart = TRUE; - + *ExtensionContext = (NDIS_HANDLE)switchContext; - + Cleanup: if (status != NDIS_STATUS_SUCCESS) { @@ -140,17 +140,17 @@ SxExtDeleteSwitch( NDIS_HANDLE ExtensionContext ) /*++ - + Routine Description: This function deletes the switch by freeing all memory previously allocated. - + --*/ { PMSFORWARD_CONTEXT switchContext = (PMSFORWARD_CONTEXT)ExtensionContext; - + UNREFERENCED_PARAMETER(Switch); - + MsForwardClearNicListUnsafe(switchContext); MsForwardClearPropertyListUnsafe(switchContext); NdisFreeRWLock(switchContext->DispatchLock); @@ -167,7 +167,7 @@ SxExtActivateSwitch( { PMSFORWARD_CONTEXT switchContext = (PMSFORWARD_CONTEXT)ExtensionContext; MsForwardInitSwitch(Switch, switchContext); - + return; } @@ -179,7 +179,7 @@ SxExtRestartSwitch( NDIS_HANDLE ExtensionContext ) /*++ - + Routine Description: This function initializes the switch if it is the first restart. First it queries all of the MAC addresses set as custom @@ -188,7 +188,7 @@ Routine Description: Then it queries the NIC list and verifies it can support all of the NICs currently connected to the switch, and adds the NICs to the NIC list. - + --*/ { NDIS_STATUS status = NDIS_STATUS_SUCCESS; @@ -198,12 +198,12 @@ Routine Description: if (switchContext->IsInitialRestart) { status = SxLibGetSwitchParametersUnsafe(Switch, &switchParameters); - + if (status != NDIS_STATUS_SUCCESS) { goto Cleanup; } - + if (switchParameters.IsActive) { status = MsForwardInitSwitch(Switch, switchContext); @@ -212,11 +212,11 @@ Routine Description: goto Cleanup; } } - + switchContext->IsInitialRestart = FALSE; } - -Cleanup: + +Cleanup: return status; } @@ -228,15 +228,15 @@ SxExtPauseSwitch( NDIS_HANDLE ExtensionContext ) /*++ - + Routine Description: No pause funtionality required. - + --*/ { UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); - + return; } @@ -249,16 +249,16 @@ SxExtCreatePort( PNDIS_SWITCH_PORT_PARAMETERS Port ) /*++ - + Routine Description: This extension does not track ports, only NICs. - + --*/ { UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); UNREFERENCED_PARAMETER(Port); - + return NDIS_STATUS_SUCCESS; } @@ -271,16 +271,16 @@ SxExtUpdatePort( PNDIS_SWITCH_PORT_PARAMETERS Port ) /*++ - + Routine Description: This extension does not track ports, only NICs. - + --*/ { UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); UNREFERENCED_PARAMETER(Port); - + return; } @@ -293,18 +293,18 @@ SxExtCreateNic( PNDIS_SWITCH_NIC_PARAMETERS Nic ) /*++ - + Routine Description: Allocate NIC, add to NIC list, and correlate with policy. - + --*/ { PMSFORWARD_CONTEXT switchContext = (PMSFORWARD_CONTEXT)ExtensionContext; NDIS_STATUS status = NDIS_STATUS_SUCCESS; LOCK_STATE_EX lockState; - + UNREFERENCED_PARAMETER(Switch); - + // // Wait for lists to be initialized. // @@ -312,9 +312,9 @@ Routine Description: { NdisMSleep(100); } - + NdisAcquireRWLockWrite(switchContext->DispatchLock, &lockState, 0); - + status = MsForwardAddNicUnsafe(switchContext, Nic->PermanentMacAddress, Nic->PortId, @@ -322,9 +322,9 @@ Routine Description: Nic->NicType, FALSE); - + NdisReleaseRWLock(switchContext->DispatchLock, &lockState); - + return status; } @@ -337,18 +337,18 @@ SxExtConnectNic( PNDIS_SWITCH_NIC_PARAMETERS Nic ) /*++ - + Routine Description: Mark already created NIC as connected. - + --*/ { PMSFORWARD_CONTEXT switchContext = (PMSFORWARD_CONTEXT)ExtensionContext; PMSFORWARD_NIC_LIST_ENTRY nicEntry = NULL; LOCK_STATE_EX lockState; - + UNREFERENCED_PARAMETER(Switch); - + // // Wait for lists to be initialized. // @@ -356,7 +356,7 @@ Routine Description: { NdisMSleep(100); } - + NdisAcquireRWLockWrite(switchContext->DispatchLock, &lockState, 0); if (Nic->NicType == NdisSwitchNicTypeExternal && Nic->NicIndex != 0 && @@ -372,7 +372,7 @@ Routine Description: nicEntry = MsForwardFindNicByPortIdUnsafe(switchContext, Nic->PortId, Nic->NicIndex); - + if(nicEntry != NULL) { nicEntry->Connected = TRUE; @@ -395,21 +395,21 @@ SxExtUpdateNic( PNDIS_SWITCH_NIC_PARAMETERS Nic ) /*++ - + Routine Description: This extension doesn't use any of the fields that can be updated. - + --*/ { UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); UNREFERENCED_PARAMETER(Nic); - + return; } -_Use_decl_annotations_ +_Use_decl_annotations_ VOID SxExtDisconnectNic( PSX_SWITCH_OBJECT Switch, @@ -417,18 +417,18 @@ SxExtDisconnectNic( PNDIS_SWITCH_NIC_PARAMETERS Nic ) /*++ - + Routine Description: Mark already created NIC as disconnected. - + --*/ { PMSFORWARD_CONTEXT switchContext = (PMSFORWARD_CONTEXT)ExtensionContext; PMSFORWARD_NIC_LIST_ENTRY nicEntry = NULL; LOCK_STATE_EX lockState; - + UNREFERENCED_PARAMETER(Switch); - + // // Wait for lists to be initialized. // @@ -436,12 +436,12 @@ Routine Description: { NdisMSleep(100); } - + NdisAcquireRWLockWrite(switchContext->DispatchLock, &lockState, 0); if (Nic->NicType == NdisSwitchNicTypeExternal) { if (Nic->NicIndex == switchContext->ExternalNicIndex) - { + { --(switchContext->NumDestinations); switchContext->ExternalNicConnected = FALSE; } @@ -451,7 +451,7 @@ Routine Description: nicEntry = MsForwardFindNicByPortIdUnsafe(switchContext, Nic->PortId, Nic->NicIndex); - + if(nicEntry != NULL) { nicEntry->Connected = FALSE; @@ -466,7 +466,7 @@ Routine Description: NdisReleaseRWLock(switchContext->DispatchLock, &lockState); } - + _Use_decl_annotations_ VOID SxExtDeleteNic( @@ -475,18 +475,18 @@ SxExtDeleteNic( PNDIS_SWITCH_NIC_PARAMETERS Nic ) /*++ - + Routine Description: Delete created NIC, free related memory and remove from NIC list. - + --*/ { PMSFORWARD_CONTEXT switchContext = (PMSFORWARD_CONTEXT)ExtensionContext; LOCK_STATE_EX lockState; - + UNREFERENCED_PARAMETER(Switch); - + // // Wait for lists to be initialized. // @@ -494,7 +494,7 @@ Routine Description: { NdisMSleep(100); } - + NdisAcquireRWLockWrite(switchContext->DispatchLock, &lockState, 0); if (Nic->NicType == NdisSwitchNicTypeExternal && Nic->NicIndex == switchContext->ExternalNicIndex) @@ -523,10 +523,10 @@ SxExtTeardownPort( PNDIS_SWITCH_PORT_PARAMETERS Port ) /*++ - + Routine Description: This extension does not track port state. - + --*/ { UNREFERENCED_PARAMETER(Switch); @@ -537,16 +537,16 @@ Routine Description: _Use_decl_annotations_ VOID -SxExtDeletePort( +SxExtDeletePort( PSX_SWITCH_OBJECT Switch, NDIS_HANDLE ExtensionContext, PNDIS_SWITCH_PORT_PARAMETERS Port ) /*++ - + Routine Description: This extension does not track port state. - + --*/ { UNREFERENCED_PARAMETER(Switch); @@ -555,9 +555,9 @@ Routine Description: } -_Use_decl_annotations_ +_Use_decl_annotations_ NDIS_STATUS -SxExtSaveNic( +SxExtSaveNic( PSX_SWITCH_OBJECT Switch, NDIS_HANDLE ExtensionContext, PNDIS_SWITCH_NIC_SAVE_STATE SaveState, @@ -565,63 +565,63 @@ SxExtSaveNic( PULONG BytesNeeded ) /*++ - + Routine Description: This extension does not save any data. - + --*/ -{ +{ UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); UNREFERENCED_PARAMETER(SaveState); - + *BytesWritten = 0; *BytesNeeded = 0; return NDIS_STATUS_SUCCESS; } -_Use_decl_annotations_ +_Use_decl_annotations_ VOID -SxExtSaveNicComplete( +SxExtSaveNicComplete( PSX_SWITCH_OBJECT Switch, NDIS_HANDLE ExtensionContext, PNDIS_SWITCH_NIC_SAVE_STATE SaveState ) /*++ - + Routine Description: This extension does not save any data. - + --*/ { UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); UNREFERENCED_PARAMETER(SaveState); - + return; } -_Use_decl_annotations_ +_Use_decl_annotations_ NDIS_STATUS -SxExtNicRestore( +SxExtNicRestore( PSX_SWITCH_OBJECT Switch, NDIS_HANDLE ExtensionContext, PNDIS_SWITCH_NIC_SAVE_STATE SaveState, PULONG BytesRestored ) /*++ - + Routine Description: This extension does not save any data. - + --*/ { UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); UNREFERENCED_PARAMETER(SaveState); - + *BytesRestored = 0; return NDIS_STATUS_SUCCESS; } @@ -629,22 +629,22 @@ Routine Description: _Use_decl_annotations_ VOID -SxExtNicRestoreComplete( +SxExtNicRestoreComplete( PSX_SWITCH_OBJECT Switch, NDIS_HANDLE ExtensionContext, PNDIS_SWITCH_NIC_SAVE_STATE SaveState ) /*++ - + Routine Description: This extension does not save any data. - + --*/ { UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); UNREFERENCED_PARAMETER(SaveState); - + return; } @@ -657,12 +657,12 @@ SxExtAddSwitchProperty( PNDIS_SWITCH_PROPERTY_PARAMETERS SwitchProperty ) /*++ - + Routine Description: This extension enforces one custom switch policy. The function verifies the switch property is our MAC policy and then adds it to the property list. - + --*/ { NDIS_STATUS status = NDIS_STATUS_NOT_SUPPORTED; @@ -670,14 +670,14 @@ Routine Description: PMSFORWARD_MAC_ADDRESS_POLICY macPolicy; PMSFORWARD_CONTEXT switchContext = (PMSFORWARD_CONTEXT)ExtensionContext; LOCK_STATE_EX lockState; - + UNREFERENCED_PARAMETER(Switch); - + if (SwitchProperty->PropertyType != NdisSwitchPropertyTypeCustom) { goto Cleanup; } - + // // Check if MAC Address Policy for this extension. // @@ -687,17 +687,17 @@ Routine Description: { goto Cleanup; } - + if (SwitchProperty->PropertyVersion != MAC_ADDRESS_POLICY_VERSION) { goto Cleanup; } - + if (SwitchProperty->SerializationVersion != MAC_ADDRESS_POLICY_SERIALIZATION_VERSION) { goto Cleanup; } - + // // Wait for lists to be initialized. // @@ -705,31 +705,31 @@ Routine Description: { NdisMSleep(100); } - + customPolicy = NDIS_SWITCH_PROPERTY_PARAMETERS_GET_PROPERTY(SwitchProperty); macPolicy = NDIS_SWITCH_PROPERTY_CUSTOM_GET_BUFFER(customPolicy); - + if (macPolicy->MacAddressLength != 6) { status = NDIS_STATUS_DATA_NOT_ACCEPTED; - } + } else { NdisAcquireRWLockWrite(switchContext->DispatchLock, &lockState, 0); - + status = MsForwardAddMacPolicyUnsafe(switchContext, macPolicy, &SwitchProperty->PropertyInstanceId); - + NdisReleaseRWLock(switchContext->DispatchLock, &lockState); } - + Cleanup: return status; } -_Use_decl_annotations_ +_Use_decl_annotations_ NDIS_STATUS SxExtUpdateSwitchProperty( PSX_SWITCH_OBJECT Switch, @@ -737,15 +737,15 @@ SxExtUpdateSwitchProperty( PNDIS_SWITCH_PROPERTY_PARAMETERS SwitchProperty ) /*++ - + Routine Description: This extension enforces one custom switch policy, but does not allow updates for that policy. - + --*/ { NDIS_STATUS status = NDIS_STATUS_NOT_SUPPORTED; - + UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); @@ -753,7 +753,7 @@ Routine Description: { goto Cleanup; } - + // // Check if MAC Address Policy for this extension. // @@ -763,19 +763,19 @@ Routine Description: { goto Cleanup; } - + if (SwitchProperty->PropertyVersion != MAC_ADDRESS_POLICY_VERSION) { goto Cleanup; } - + if (SwitchProperty->SerializationVersion != MAC_ADDRESS_POLICY_SERIALIZATION_VERSION) { goto Cleanup; } status = NDIS_STATUS_DATA_NOT_ACCEPTED; - + Cleanup: return status; } @@ -789,25 +789,25 @@ SxExtDeleteSwitchProperty( PNDIS_SWITCH_PROPERTY_DELETE_PARAMETERS SwitchProperty ) /*++ - + Routine Description: This extension enforces one custom switch policy. The function verifies the switch property is our MAC policy and then deletes it from the property list. - + --*/ { BOOLEAN delete = FALSE; PMSFORWARD_CONTEXT switchContext = (PMSFORWARD_CONTEXT)ExtensionContext; LOCK_STATE_EX lockState; - + UNREFERENCED_PARAMETER(Switch); - + if (SwitchProperty->PropertyType != NdisSwitchPropertyTypeCustom) { goto Cleanup; } - + // // Check if MAC Address Policy for this extension. // @@ -817,7 +817,7 @@ Routine Description: { goto Cleanup; } - + // // Wait for lists to be initialized. // @@ -825,23 +825,23 @@ Routine Description: { NdisMSleep(100); } - - + + delete = TRUE; NdisAcquireRWLockWrite(switchContext->DispatchLock, &lockState, 0); - + MsForwardDeleteMacPolicyUnsafe(switchContext, &SwitchProperty->PropertyInstanceId); - + NdisReleaseRWLock(switchContext->DispatchLock, &lockState); - + Cleanup: return delete; } -_Use_decl_annotations_ +_Use_decl_annotations_ NDIS_STATUS SxExtAddPortProperty( PSX_SWITCH_OBJECT Switch, @@ -849,20 +849,20 @@ SxExtAddPortProperty( PNDIS_SWITCH_PORT_PROPERTY_PARAMETERS PortProperty ) /*++ - + Routine Description: This extension does not enforce VLAN. Because of this the extension fails the adding of these policies. - + !! REAL FORWARDING EXTENSIONS SHOULD SUPPORT THESE PROPERTIES !! - + --*/ { NDIS_STATUS status = NDIS_STATUS_NOT_SUPPORTED; - + UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); - + switch(PortProperty->PropertyType) { case NdisSwitchPortPropertyTypeCustom: @@ -870,14 +870,14 @@ Routine Description: // No Custom Port Properties. // break; - + case NdisSwitchPortPropertyTypeSecurity: // // This extension does need to look at security policy, pass it down. // An extension must always pass through Hyper-V security policy. // break; - + case NdisSwitchPortPropertyTypeVlan: // // Forwarding extensions must either enforce VLAN, or fail @@ -886,7 +886,7 @@ Routine Description: // status = NDIS_STATUS_DATA_NOT_ACCEPTED; break; - + case NdisSwitchPortPropertyTypeProfile: // // No Processing of Port Profile. @@ -897,7 +897,7 @@ Routine Description: return status; } -_Use_decl_annotations_ +_Use_decl_annotations_ NDIS_STATUS SxExtUpdatePortProperty( PSX_SWITCH_OBJECT Switch, @@ -905,20 +905,20 @@ SxExtUpdatePortProperty( PNDIS_SWITCH_PORT_PROPERTY_PARAMETERS PortProperty ) /*++ - + Routine Description: This extension does not enforce VLAN. Because of this the extension fails the updating of these policies. - + !! REAL FORWARDING EXTENSIONS SHOULD SUPPORT THESE PROPERTIES !! - + --*/ { NDIS_STATUS status = NDIS_STATUS_NOT_SUPPORTED; - + UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); - + switch(PortProperty->PropertyType) { case NdisSwitchPortPropertyTypeCustom: @@ -926,14 +926,14 @@ Routine Description: // No Custom Port Properties. // break; - + case NdisSwitchPortPropertyTypeSecurity: // // This extension does need to look at security policy, pass it down. // An extension must always pass through Hyper-V security policy. // break; - + case NdisSwitchPortPropertyTypeVlan: // // Forwarding extensions must either enforce VLAN, or fail @@ -942,7 +942,7 @@ Routine Description: // status = NDIS_STATUS_DATA_NOT_ACCEPTED; break; - + case NdisSwitchPortPropertyTypeProfile: // // No Processing of Port Profile. @@ -961,21 +961,21 @@ SxExtDeletePortProperty( PNDIS_SWITCH_PORT_PROPERTY_DELETE_PARAMETERS PortProperty ) /*++ - + Routine Description: This extension does not enforce VLAN. These policies are policies that should be supported by this extension, so it returns TRUE to complete the deletion. - + !! REAL FORWARDING EXTENSIONS SHOULD SUPPORT THESE PROPERTIES !! - + --*/ { BOOLEAN delete = FALSE; - + UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); - + switch(PortProperty->PropertyType) { case NdisSwitchPortPropertyTypeCustom: @@ -983,14 +983,14 @@ Routine Description: // No Custom Port Properties. // break; - + case NdisSwitchPortPropertyTypeSecurity: // // This extension does need to look at security policy, pass it down. // An extension must always pass through Hyper-V security policy. // break; - + case NdisSwitchPortPropertyTypeVlan: // // Forwarding extensions must either enforce VLAN, or fail @@ -999,7 +999,7 @@ Routine Description: // delete = TRUE; break; - + case NdisSwitchPortPropertyTypeProfile: // // No Processing of Port Profile. @@ -1020,11 +1020,11 @@ SxExtQuerySwitchFeatureStatus( PULONG BytesNeeded ) /*++ - + Routine Description: This extension reports the status of its custom MAC policy by returning the list of PortId's currently allowing sends. - + --*/ { BOOLEAN consumed = FALSE; @@ -1041,26 +1041,26 @@ Routine Description: PNDIS_SWITCH_PORT_ID portIdArray; ULONG arrayIndex = 0; ULONG customBufferLength = 0; - + UNREFERENCED_PARAMETER(Switch); - + if (SwitchFeatureStatus->FeatureStatusType != NdisSwitchFeatureStatusTypeCustom) { goto Cleanup; } - + if (!RtlEqualMemory(&SwitchFeatureStatus->FeatureStatusId, &MacAddressPolicyStatusGuid, sizeof(NDIS_SWITCH_OBJECT_ID))) { goto Cleanup; } - + if (SwitchFeatureStatus->SerializationVersion != MAC_ADDRESS_POLICY_STATUS_SERIALIZATION_VERSION) { goto Cleanup; } - + // // Wait for lists to be initialized. // @@ -1068,52 +1068,52 @@ Routine Description: { NdisMSleep(100); } - + NdisAcquireRWLockRead(switchContext->DispatchLock, &lockState, 0); lockHeld = TRUE; - + if (switchContext->ExternalPortId != NDIS_SWITCH_DEFAULT_PORT_ID) { ++numAllowedSourcePorts; } - + if (!IsListEmpty(nicList)) { curEntry = nicList->Flink; - + do { nic = CONTAINING_RECORD(curEntry, MSFORWARD_NIC_LIST_ENTRY, ListEntry); - + if (nic->AllowSends) { ++numAllowedSourcePorts; } curEntry = curEntry->Flink; - + } while(curEntry != nicList); } - + customBufferLength = sizeof(MSFORWARD_MAC_ADDRESS_POLICY_STATUS) + (sizeof(NDIS_SWITCH_PORT_ID) * numAllowedSourcePorts); sizeNeeded = NDIS_SIZEOF_NDIS_SWITCH_FEATURE_STATUS_PARAMETERS_REVISION_1 + NDIS_SIZEOF_NDIS_SWITCH_FEATURE_STATUS_CUSTOM_REVISION_1 + customBufferLength; - + consumed = TRUE; - + if (SwitchFeatureStatus->FeatureStatusBufferLength < sizeof(NDIS_SWITCH_FEATURE_STATUS_CUSTOM)) { *BytesNeeded = sizeNeeded; goto Cleanup; } - + customStatusBuffer = (PNDIS_SWITCH_FEATURE_STATUS_CUSTOM) (((PUINT8)SwitchFeatureStatus) + SwitchFeatureStatus->FeatureStatusBufferOffset); - + if (customStatusBuffer->Header.Type != NDIS_OBJECT_TYPE_DEFAULT || customStatusBuffer->Header.Revision != NDIS_SWITCH_FEATURE_STATUS_CUSTOM_REVISION_1 || customStatusBuffer->Header.Size != NDIS_SIZEOF_NDIS_SWITCH_FEATURE_STATUS_CUSTOM_REVISION_1) @@ -1121,42 +1121,42 @@ Routine Description: consumed = FALSE; goto Cleanup; } - - - + + + if (customStatusBuffer->FeatureStatusCustomBufferLength < customBufferLength) { *BytesNeeded = sizeNeeded; goto Cleanup; } - + macAddressPolicyBuffer = (PMSFORWARD_MAC_ADDRESS_POLICY_STATUS) (((PUINT8)customStatusBuffer) + customStatusBuffer->FeatureStatusCustomBufferOffset); - + macAddressPolicyBuffer->PortArrayLength = numAllowedSourcePorts; macAddressPolicyBuffer->PortArrayOffset = sizeof(MSFORWARD_MAC_ADDRESS_POLICY_STATUS); - + portIdArray = (PNDIS_SWITCH_PORT_ID) (((PUINT8)macAddressPolicyBuffer) + macAddressPolicyBuffer->PortArrayOffset); - - + + if (switchContext->ExternalPortId != NDIS_SWITCH_DEFAULT_PORT_ID) { portIdArray[arrayIndex] = switchContext->ExternalPortId; ++arrayIndex; } - + if (!IsListEmpty(nicList)) { curEntry = nicList->Flink; - + do { nic = CONTAINING_RECORD(curEntry, MSFORWARD_NIC_LIST_ENTRY, ListEntry); - + if (nic->AllowSends) { portIdArray[arrayIndex] = nic->PortId; @@ -1164,7 +1164,7 @@ Routine Description: } curEntry = curEntry->Flink; - + } while(curEntry != nicList); } @@ -1178,7 +1178,7 @@ Cleanup: return consumed; } - + _Use_decl_annotations_ BOOLEAN @@ -1189,17 +1189,17 @@ SxExtQueryPortFeatureStatus( PULONG BytesNeeded ) /*++ - + Routine Description: This extension has no custom port properties. - + --*/ { UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); UNREFERENCED_PARAMETER(PortFeatureStatus); UNREFERENCED_PARAMETER(BytesNeeded); - + return FALSE; } @@ -1216,24 +1216,24 @@ SxExtProcessNicRequest( PNDIS_SWITCH_NIC_INDEX DestinationNicIndex ) /*++ - + Routine Description: - The only NIC request this extension cares about is + The only NIC request this extension cares about is OID_NIC_SWITCH_ALLOCATE_VF. We must fail all VF allocations so that traffic flows through the extension and we can enforce policy. - + --*/ { NDIS_STATUS status = NDIS_STATUS_SUCCESS; - + UNREFERENCED_PARAMETER(Switch); UNREFERENCED_PARAMETER(ExtensionContext); UNREFERENCED_PARAMETER(SourcePortId); UNREFERENCED_PARAMETER(SourceNicIndex); UNREFERENCED_PARAMETER(DestinationPortId); UNREFERENCED_PARAMETER(DestinationNicIndex); - + // // Do not allow VF allocations, as all VM traffic must flow // through our extension. @@ -1243,7 +1243,7 @@ Routine Description: { status = NDIS_STATUS_FAILURE; } - + return status; } @@ -1261,11 +1261,11 @@ SxExtProcessNicRequestComplete( NDIS_STATUS Status ) /*++ - + Routine Description: This function will never be called because we do not redirect or edit any NIC requests. - + --*/ { UNREFERENCED_PARAMETER(Switch); @@ -1276,13 +1276,13 @@ Routine Description: UNREFERENCED_PARAMETER(DestinationPortId); UNREFERENCED_PARAMETER(DestinationNicIndex); UNREFERENCED_PARAMETER(Status); - + // // This function should never be called as we don't set any // source/destination info in SxExtProcessNicRequest. // ASSERT(FALSE); - + return Status; } @@ -1297,11 +1297,11 @@ SxExtProcessNicStatus( NDIS_SWITCH_NIC_INDEX SourceNicIndex ) /*++ - + Routine Description: This extension does not need to process any status indications. - + --*/ { UNREFERENCED_PARAMETER(Switch); @@ -1309,7 +1309,7 @@ Routine Description: UNREFERENCED_PARAMETER(StatusIndication); UNREFERENCED_PARAMETER(SourcePortId); UNREFERENCED_PARAMETER(SourceNicIndex); - + return NDIS_STATUS_SUCCESS; } @@ -1323,7 +1323,7 @@ SxExtStartNetBufferListsIngress( ULONG SendFlags ) /*++ - + Routine Description: The function sets the destination lists of the NBLs forwarded through the switch. @@ -1331,13 +1331,13 @@ Routine Description: Internal NIC, or NICs with MAC Policy set. The extension determines the source by searching for the source MAC address in the NIC list. - + The extension sets destinations by looking at the destination MAC address. If the destination MAC address is a multicast or broadcast address, the extension broadcasts the NBL to all ports, except the source. If the destination MAC is a VM, the extension sets the VM as the destitation. Otherwise the extension sets the External port as the destination. - + --*/ { PMSFORWARD_CONTEXT switchContext = (PMSFORWARD_CONTEXT)ExtensionContext; @@ -1368,13 +1368,13 @@ Routine Description: PNET_BUFFER_LIST nativeForwardedNbls = NULL; PNET_BUFFER_LIST *nextExtForwardNbl = &extForwardedNbls; PNET_BUFFER_LIST *nextNativeForwardedNbl = &nativeForwardedNbls; - + dispatch = NDIS_TEST_SEND_FLAG(SendFlags, NDIS_SEND_FLAGS_DISPATCH_LEVEL); sameSource = NDIS_TEST_SEND_FLAG(SendFlags, NDIS_SEND_FLAGS_SWITCH_SINGLE_SOURCE); - + sendCompleteFlags |= (dispatch) ? NDIS_SEND_COMPLETE_FLAGS_DISPATCH_LEVEL : 0; SendFlags |= NDIS_SEND_FLAGS_SWITCH_DESTINATION_GROUP; - + // // Take DispatchLock so no NICs disconnect while we're setting destinations. // @@ -1384,9 +1384,9 @@ Routine Description: fwdDetail = NET_BUFFER_LIST_SWITCH_FORWARDING_DETAIL(NetBufferLists); sourcePort = fwdDetail->SourcePortId; sourceIndex = (NDIS_SWITCH_NIC_INDEX)fwdDetail->SourceNicIndex; - + sendCompleteFlags |= NDIS_SEND_COMPLETE_FLAGS_SWITCH_SINGLE_SOURCE; - + sourceNicEntry = MsForwardFindNicByPortIdUnsafe(switchContext, sourcePort, sourceIndex); @@ -1398,11 +1398,11 @@ Routine Description: { ++numDropNbls; } - - *nextDropNbl = NetBufferLists; - + + *nextDropNbl = NetBufferLists; + RtlInitUnicodeString(&filterReason, L"Blocked by Source MAC Policy"); - + Switch->NdisSwitchHandlers.ReportFilteredNetBufferLists( Switch->NdisSwitchContext, &SxExtensionGuid, @@ -1412,10 +1412,10 @@ Routine Description: numDropNbls, dropNbl, &filterReason); - + goto Cleanup; } - + // // If nicEntry is not found, and is not external port, // we must have failed to allocate this port. @@ -1428,11 +1428,11 @@ Routine Description: { ++numDropNbls; } - + *nextDropNbl = NetBufferLists; - + RtlInitUnicodeString(&filterReason, L"Low Resources"); - + Switch->NdisSwitchHandlers.ReportFilteredNetBufferLists( Switch->NdisSwitchContext, &SxExtensionGuid, @@ -1442,11 +1442,11 @@ Routine Description: numDropNbls, dropNbl, &filterReason); - + goto Cleanup; - } + } } - + // // Split NBL list into NBLs to be forwarded by us, and those that require // native forwarding. @@ -1467,14 +1467,14 @@ Routine Description: nextExtForwardNbl = &(curNbl->Next); } } - + for (curNbl = extForwardedNbls; curNbl != NULL; curNbl = nextNbl) { nextNbl = curNbl->Next; curNbl->Next = NULL; - + fwdDetail = NET_BUFFER_LIST_SWITCH_FORWARDING_DETAIL(curNbl); - + // // First check for allowed source if not same source. // @@ -1482,15 +1482,15 @@ Routine Description: { sourcePort = fwdDetail->SourcePortId; sourceIndex = (NDIS_SWITCH_NIC_INDEX)fwdDetail->SourceNicIndex; - + sourceNicEntry = MsForwardFindNicByPortIdUnsafe(switchContext, sourcePort, sourceIndex); - + if (sourceNicEntry != NULL && !sourceNicEntry->AllowSends) { RtlInitUnicodeString(&filterReason, L"Blocked by Source MAC Policy"); - + Switch->NdisSwitchHandlers.ReportFilteredNetBufferLists( Switch->NdisSwitchContext, &SxExtensionGuid, @@ -1500,7 +1500,7 @@ Routine Description: 1, curNbl, &filterReason); - + *nextDropNbl = curNbl; nextDropNbl = &curNbl->Next; continue; @@ -1509,7 +1509,7 @@ Routine Description: sourcePort != switchContext->ExternalPortId) { RtlInitUnicodeString(&filterReason, L"Low Resources"); - + Switch->NdisSwitchHandlers.ReportFilteredNetBufferLists( Switch->NdisSwitchContext, &SxExtensionGuid, @@ -1519,13 +1519,13 @@ Routine Description: 1, curNbl, &filterReason); - + *nextDropNbl = curNbl; nextDropNbl = &curNbl->Next; continue; - } + } } - + // // Ethernet Header is a guaranteed safe access. // @@ -1535,7 +1535,7 @@ Routine Description: LowPagePriority | MdlMappingNoExecute); curHeader = (PMSFORWARD_ETHERNET_HEADER) (curBuffer + (NET_BUFFER_LIST_FIRST_NB(curNbl))->CurrentMdlOffset); - + // // Check for broadcast. (Broadcast if multicast) // @@ -1551,11 +1551,11 @@ Routine Description: sendNbl, SendFlags, 0); - + sendNbl = NULL; nextSendNbl = &sendNbl; } - + if (fwdDetail->NumAvailableDestinations < (switchContext->NumDestinations - 1)) { status = Switch->NdisSwitchHandlers.GrowNetBufferListDestinations( @@ -1563,7 +1563,7 @@ Routine Description: curNbl, (switchContext->NumDestinations - 1 - fwdDetail->NumAvailableDestinations), &broadcastArray); - + if (status != NDIS_STATUS_SUCCESS) { RtlInitUnicodeString(&filterReason, L"Failed to grow destination list."); @@ -1576,7 +1576,7 @@ Routine Description: 1, curNbl, &filterReason); - + *nextDropNbl = curNbl; nextDropNbl = &curNbl->Next; continue; @@ -1589,7 +1589,7 @@ Routine Description: curNbl, &broadcastArray); } - + MsForwardMakeBroadcastArrayUnsafe(switchContext, broadcastArray, sourcePort, @@ -1607,26 +1607,26 @@ Routine Description: 1, curNbl, &filterReason); - + *nextDropNbl = curNbl; nextDropNbl = &curNbl->Next; continue; } - + status = Switch->NdisSwitchHandlers.UpdateNetBufferListDestinations( Switch->NdisSwitchContext, curNbl, (switchContext->NumDestinations - 1), broadcastArray); ASSERT(status == NDIS_STATUS_SUCCESS); - + *nextSendNbl = curNbl; nextSendNbl = &(curNbl->Next); broadcast = TRUE; - + continue; } - + if (RtlEqualMemory(prevMacAddress, curHeader->Destination, @@ -1641,7 +1641,7 @@ Routine Description: curHeader->Destination); // // Not a VM or host, send to external. - // + // if (destinationNicEntry == NULL) { // @@ -1659,12 +1659,12 @@ Routine Description: 1, curNbl, &filterReason); - + *nextDropNbl = curNbl; nextDropNbl = &curNbl->Next; continue; } - + if (sourcePort == switchContext->ExternalPortId) { RtlInitUnicodeString(&filterReason, L"Destination == Source"); @@ -1677,12 +1677,12 @@ Routine Description: 1, curNbl, &filterReason); - + *nextDropNbl = curNbl; nextDropNbl = &curNbl->Next; continue; } - + curDestinationPort = switchContext->ExternalPortId; curDestinationIndex = switchContext->ExternalNicIndex; } @@ -1703,27 +1703,27 @@ Routine Description: 1, curNbl, &filterReason); - + *nextDropNbl = curNbl; nextDropNbl = &curNbl->Next; continue; } } - + RtlMoveMemory(prevMacAddress, curHeader->Destination, sizeof(prevMacAddress)); newDestination.PortId = curDestinationPort; newDestination.NicIndex = curDestinationIndex; newDestination.PreserveVLAN = 0; - + ASSERT(fwdDetail->NumAvailableDestinations > 0); status = Switch->NdisSwitchHandlers.AddNetBufferListDestination( Switch->NdisSwitchContext, curNbl, &newDestination); ASSERT(status == NDIS_STATUS_SUCCESS); - - if(sendNbl != NULL && + + if(sendNbl != NULL && (broadcast || (prevDestinationPort != curDestinationPort || prevDestinationIndex != curDestinationIndex))) @@ -1732,14 +1732,14 @@ Routine Description: sendNbl, SendFlags, 0); - + sendNbl = NULL; nextSendNbl = &sendNbl; } - + *nextSendNbl = curNbl; nextSendNbl = &(curNbl->Next); - + // // Done processing this NBL. // @@ -1747,10 +1747,10 @@ Routine Description: prevDestinationIndex = curDestinationIndex; broadcast = FALSE; } - + Cleanup: NdisReleaseRWLock(switchContext->DispatchLock, &lockState); - + if (sendNbl != NULL) { SxLibSendNetBufferListsIngress(Switch, @@ -1758,7 +1758,7 @@ Cleanup: SendFlags, 0); } - + if (nativeForwardedNbls != NULL) { SxLibSendNetBufferListsIngress(Switch, @@ -1766,7 +1766,7 @@ Cleanup: SendFlags, 0); } - + if (dropNbl != NULL) { SxLibCompleteNetBufferListsIngress(Switch, @@ -1786,14 +1786,14 @@ SxExtStartNetBufferListsEgress( ULONG ReceiveFlags ) /*++ - + Routine Description: No egress processing necessary. - + --*/ { UNREFERENCED_PARAMETER(ExtensionContext); - + SxLibSendNetBufferListsEgress(Switch, NetBufferLists, NumberOfNetBufferLists, @@ -1810,14 +1810,14 @@ SxExtStartCompleteNetBufferListsEgress( ULONG ReturnFlags ) /*++ - + Routine Description: No egress processing necessary. - + --*/ { UNREFERENCED_PARAMETER(ExtensionContext); - + SxLibCompleteNetBufferListsEgress(Switch, NetBufferLists, ReturnFlags); @@ -1833,14 +1833,14 @@ SxExtStartCompleteNetBufferListsIngress( ULONG SendCompleteFlags ) /*++ - + Routine Description: No ingress complete processing necessary. - + --*/ { UNREFERENCED_PARAMETER(ExtensionContext); - + SxLibCompleteNetBufferListsIngress(Switch, NetBufferLists, SendCompleteFlags); @@ -1857,46 +1857,46 @@ MsForwardAddNicUnsafe( _In_ BOOLEAN Connected ) /*++ - + Routine Description: Add given NIC to the NIC list and correlate with MAC policy. - + --*/ { NDIS_STATUS status = NDIS_STATUS_SUCCESS; PMSFORWARD_NIC_LIST_ENTRY nicEntry = NULL; PLIST_ENTRY nicList = &SwitchContext->NicList; - + if (NicType == NdisSwitchNicTypeExternal) { goto Cleanup; } - + nicEntry = MsForwardFindNicByPortIdUnsafe(SwitchContext, - PortId, + PortId, NicIndex); - + if (nicEntry == NULL) { nicEntry = ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(MSFORWARD_NIC_LIST_ENTRY), SxExtAllocationTag); - + if (nicEntry == NULL) { status = NDIS_STATUS_RESOURCES; goto Cleanup; } - + NdisZeroMemory(nicEntry, sizeof(MSFORWARD_NIC_LIST_ENTRY)); NdisMoveMemory(nicEntry->MacAddress, MacAddress, MSFORWARD_MAC_LENGTH); - + nicEntry->PortId = PortId; nicEntry->NicIndex = NicIndex; nicEntry->NicType = NicType; nicEntry->Connected = Connected; - + if (NicType == NdisSwitchNicTypeInternal) { nicEntry->AllowSends = TRUE; @@ -1905,10 +1905,10 @@ Routine Description: { nicEntry->AllowSends = MsForwardNicHasPolicy(SwitchContext, MacAddress); } - + InsertHeadList(nicList, &nicEntry->ListEntry); } - + Cleanup: return status; } @@ -1921,46 +1921,46 @@ MsForwardAddMacPolicyUnsafe( _In_ PNDIS_SWITCH_OBJECT_INSTANCE_ID PropertyInstanceId ) /*++ - + Routine Description: Add the given policy to the policy list and correlate with the NIC list. - + --*/ { NDIS_STATUS status = NDIS_STATUS_SUCCESS; PMSFORWARD_MAC_POLICY_LIST_ENTRY newPolicy; PMSFORWARD_NIC_LIST_ENTRY nic; - + newPolicy = MsForwardFindPolicyByMacAddressUnsafe(SwitchContext, MacPolicyBuffer->MacAddress); - + if (newPolicy == NULL) { newPolicy = ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(MSFORWARD_MAC_POLICY_LIST_ENTRY), SxExtAllocationTag); - + if (newPolicy == NULL) { status = NDIS_STATUS_RESOURCES; goto Cleanup; } - + NdisMoveMemory(&newPolicy->MacAddress, MacPolicyBuffer->MacAddress, sizeof(newPolicy->MacAddress)); - + NdisMoveMemory(&newPolicy->PropertyInstanceId, PropertyInstanceId, sizeof(NDIS_SWITCH_OBJECT_INSTANCE_ID)); - + InsertHeadList(&SwitchContext->PropertyList, &newPolicy->ListEntry); - + nic = MsForwardFindNicByMacAddressUnsafe(SwitchContext, MacPolicyBuffer->MacAddress); - + if (nic != NULL) { nic->AllowSends = TRUE; @@ -1970,7 +1970,7 @@ Routine Description: { status = NDIS_STATUS_DATA_NOT_ACCEPTED; } - + Cleanup: return status; } @@ -1982,30 +1982,30 @@ MsForwardDeleteMacPolicyUnsafe( _In_ PNDIS_SWITCH_OBJECT_INSTANCE_ID PropertyInstanceId ) /*++ - + Routine Description: Delete the given MAC policy, and coorelate with the NIC list. - + --*/ { PMSFORWARD_MAC_POLICY_LIST_ENTRY deletePolicy; PMSFORWARD_NIC_LIST_ENTRY nic; - + deletePolicy = MsForwardFindPolicyByPropertyInstanceIdUnsafe( SwitchContext, PropertyInstanceId); - + if (deletePolicy != NULL) { nic = MsForwardFindNicByMacAddressUnsafe(SwitchContext, deletePolicy->MacAddress); - + if (nic != NULL) { nic->AllowSends = FALSE; } - + RemoveEntryList(&deletePolicy->ListEntry); ExFreePoolWithTag(deletePolicy, SxExtAllocationTag); } @@ -2019,38 +2019,38 @@ MsForwardFindNicByPortIdUnsafe( _In_ NDIS_SWITCH_NIC_INDEX NicIndex ) /*++ - + Routine Description: Search for the NIC needed by port ID. - + --*/ { PLIST_ENTRY nicList = &SwitchContext->NicList; PLIST_ENTRY curEntry = nicList->Flink; PMSFORWARD_NIC_LIST_ENTRY nic = NULL; - + if (IsListEmpty(nicList)) { goto Cleanup; } - + do { nic = CONTAINING_RECORD(curEntry, MSFORWARD_NIC_LIST_ENTRY, ListEntry); - + if (nic->PortId == PortId && nic->NicIndex == NicIndex) { goto Cleanup; } - + curEntry = curEntry->Flink; - + } while(curEntry != nicList); - + nic = NULL; - + Cleanup: return nic; } @@ -2062,39 +2062,39 @@ MsForwardFindNicByMacAddressUnsafe( _In_reads_bytes_(6) PUCHAR MacAddress ) /*++ - + Routine Description: Search for the NIC needed by MAC Address. - + --*/ { PLIST_ENTRY nicList = &SwitchContext->NicList; PLIST_ENTRY curEntry = nicList->Flink; PMSFORWARD_NIC_LIST_ENTRY nic = NULL; - + if (IsListEmpty(nicList)) { goto Cleanup; } - + do { nic = CONTAINING_RECORD(curEntry, MSFORWARD_NIC_LIST_ENTRY, ListEntry); - + if (RtlEqualMemory(MacAddress, nic->MacAddress, sizeof(nic->MacAddress))) { goto Cleanup; } - + curEntry = curEntry->Flink; - + } while(curEntry != nicList); - + nic = NULL; - + Cleanup: return nic; } @@ -2106,39 +2106,39 @@ MsForwardFindPolicyByMacAddressUnsafe( _In_reads_bytes_(6) PUCHAR MacAddress ) /*++ - + Routine Description: Search for the policy needed by MAC address. - + --*/ { PLIST_ENTRY propertyList = &SwitchContext->PropertyList; PLIST_ENTRY curEntry = propertyList->Flink; PMSFORWARD_MAC_POLICY_LIST_ENTRY policy = NULL; - + if (IsListEmpty(propertyList)) { goto Cleanup; } - + do { policy = CONTAINING_RECORD(curEntry, MSFORWARD_MAC_POLICY_LIST_ENTRY, ListEntry); - + if (RtlEqualMemory(MacAddress, policy->MacAddress, sizeof(policy->MacAddress))) { goto Cleanup; } - + curEntry = curEntry->Flink; - + } while(curEntry != propertyList); - + policy = NULL; - + Cleanup: return policy; } @@ -2150,44 +2150,44 @@ MsForwardFindPolicyByPropertyInstanceIdUnsafe( _In_ PNDIS_SWITCH_OBJECT_INSTANCE_ID PropertyInstanceId ) /*++ - + Routine Description: Search for the policy needed by PropertyInstanceId. - + --*/ { PLIST_ENTRY propertyList = &SwitchContext->PropertyList; PLIST_ENTRY curEntry = propertyList->Flink; PMSFORWARD_MAC_POLICY_LIST_ENTRY policy = NULL; - + if (IsListEmpty(propertyList)) { goto Cleanup; } - + do { policy = CONTAINING_RECORD(curEntry, MSFORWARD_MAC_POLICY_LIST_ENTRY, ListEntry); - + if (RtlEqualMemory(PropertyInstanceId, &policy->PropertyInstanceId, sizeof(policy->PropertyInstanceId))) { goto Cleanup; } - + curEntry = curEntry->Flink; - + } while(curEntry != propertyList); - + policy = NULL; - + Cleanup: return policy; } - + NDIS_STATUS MsForwardDeleteNicUnsafe( _In_ PMSFORWARD_CONTEXT SwitchContext, @@ -2195,56 +2195,56 @@ MsForwardDeleteNicUnsafe( _In_ NDIS_SWITCH_NIC_INDEX NicIndex ) /*++ - + Routine Description: Remove the NIC represented by the PortId and NicIndex from the NIC list and free its memory. - + --*/ { NDIS_STATUS status = NDIS_STATUS_SUCCESS; - + PMSFORWARD_NIC_LIST_ENTRY nicEntry = MsForwardFindNicByPortIdUnsafe(SwitchContext, PortId, NicIndex); - + if (nicEntry == NULL) { ASSERT(FALSE); goto Cleanup; } - + RemoveEntryList(&nicEntry->ListEntry); ExFreePoolWithTag(nicEntry, SxExtAllocationTag); -Cleanup: +Cleanup: return status; } - - + + VOID MsForwardClearNicListUnsafe( _In_ PMSFORWARD_CONTEXT SwitchContext ) /*++ - + Routine Description: Remove all NICs from the list and free all memory. - + --*/ { PMSFORWARD_NIC_LIST_ENTRY nic; PLIST_ENTRY nicList = &SwitchContext->NicList; PLIST_ENTRY headList = NULL; - + while (!IsListEmpty(nicList)) { headList = RemoveHeadList(nicList); - + nic = CONTAINING_RECORD(headList, MSFORWARD_NIC_LIST_ENTRY, ListEntry); - + ExFreePoolWithTag(nic, SxExtAllocationTag); } @@ -2257,24 +2257,24 @@ MsForwardClearPropertyListUnsafe( _In_ PMSFORWARD_CONTEXT SwitchContext ) /*++ - + Routine Description: Remove all properties from the list and free all memory. - + --*/ { PMSFORWARD_MAC_POLICY_LIST_ENTRY policy; PLIST_ENTRY propertyList = &SwitchContext->PropertyList; PLIST_ENTRY headList = NULL; - + while (!IsListEmpty(propertyList)) { headList = RemoveHeadList(propertyList); - + policy = CONTAINING_RECORD(headList, MSFORWARD_MAC_POLICY_LIST_ENTRY, ListEntry); - + ExFreePoolWithTag(policy, SxExtAllocationTag); } @@ -2288,17 +2288,17 @@ MsForwardNicHasPolicy( _In_reads_bytes_(6) PUCHAR MacAddress ) /*++ - + Routine Description: Returns TRUE if there is a correlated policy to the MAC address given. - + --*/ { return (MsForwardFindPolicyByMacAddressUnsafe(SwitchContext, MacAddress) != NULL); } - + VOID MsForwardMakeBroadcastArrayUnsafe( @@ -2308,11 +2308,11 @@ MsForwardMakeBroadcastArrayUnsafe( _In_ NDIS_SWITCH_NIC_INDEX SourceNicIndex ) /*++ - + Routine Description: Creates the destination array of all connected NICs excluding the source given. - + --*/ { PLIST_ENTRY nicList = &SwitchContext->NicList; @@ -2320,17 +2320,17 @@ Routine Description: PMSFORWARD_NIC_LIST_ENTRY nic = NULL; UINT32 index = BroadcastArray->NumDestinations; PNDIS_SWITCH_PORT_DESTINATION destination; - + if (IsListEmpty(nicList)) { goto Cleanup; } - + do { nic = CONTAINING_RECORD(curEntry, MSFORWARD_NIC_LIST_ENTRY, ListEntry); - + if ((SourcePortId == nic->PortId && SourceNicIndex == nic->NicIndex) || !nic->Connected) @@ -2345,18 +2345,18 @@ Routine Description: continue; } } - + destination = NDIS_SWITCH_PORT_DESTINATION_AT_ARRAY_INDEX(BroadcastArray, index); NdisZeroMemory(destination, sizeof(NDIS_SWITCH_PORT_DESTINATION)); - + destination->PortId = nic->PortId; destination->NicIndex = nic->NicIndex; - + ++index; curEntry = curEntry->Flink; - + } while(curEntry != nicList); - + if (SourcePortId != SwitchContext->ExternalPortId && SwitchContext->ExternalNicConnected) { @@ -2364,7 +2364,7 @@ Routine Description: destination->PortId = SwitchContext->ExternalPortId; destination->NicIndex = SwitchContext->ExternalNicIndex; } - + Cleanup: return; } @@ -2376,10 +2376,10 @@ MsForwardInitSwitch( _In_ PMSFORWARD_CONTEXT SwitchContext ) /*++ - + Routine Description: Initializes the switch state. - + --*/ { NDIS_STATUS status = NDIS_STATUS_SUCCESS; @@ -2393,7 +2393,7 @@ Routine Description: PNDIS_SWITCH_PORT_PROPERTY_ENUM_PARAMETERS portPropertyParameters = NULL; PNDIS_SWITCH_PORT_PROPERTY_ENUM_INFO portPropertyInfo = NULL; PNDIS_SWITCH_PORT_PROPERTY_VLAN vlanProperty; - + ASSERT(!SwitchContext->IsActive); // @@ -2403,25 +2403,25 @@ Routine Description: NdisSwitchPropertyTypeCustom, (PNDIS_SWITCH_OBJECT_ID)&MacAddressPolicyGuid, &switchPropertyParameters); - + if (status != NDIS_STATUS_SUCCESS) { status = NDIS_STATUS_RESOURCES; goto Cleanup; } - + switchPropertyInfo = NDIS_SWITCH_PROPERTY_ENUM_PARAMETERS_GET_FIRST_INFO(switchPropertyParameters); - + for (arrIndex = 0; arrIndex < switchPropertyParameters->NumProperties; ++arrIndex) { // - // Should always get back v1 or later. It is safe to access the + // Should always get back v1 or later. It is safe to access the // v1 version of the structure if newer property is retrieved. // - ASSERT(switchPropertyInfo->PropertyVersion >= + ASSERT(switchPropertyInfo->PropertyVersion >= MAC_ADDRESS_POLICY_VERSION); customPropertyInfo = @@ -2433,35 +2433,35 @@ Routine Description: status = MsForwardAddMacPolicyUnsafe(SwitchContext, macAddressPolicy, &switchPropertyInfo->PropertyInstanceId); - + if (status != NDIS_STATUS_SUCCESS) { goto Cleanup; } - + switchPropertyInfo = NDIS_SWITCH_PROPERTY_ENUM_INFO_GET_NEXT(switchPropertyInfo); } // // Now, get NIC list. - // + // status = SxLibGetNicArrayUnsafe(Switch, &nicArray); if (status != NDIS_STATUS_SUCCESS) { goto Cleanup; } - + for (arrIndex = 0; arrIndex < nicArray->NumElements; ++arrIndex) { curNic = NDIS_SWITCH_NIC_AT_ARRAY_INDEX(nicArray, arrIndex); - + status = Switch->NdisSwitchHandlers.ReferenceSwitchPort( Switch->NdisSwitchContext, curNic->PortId); - + ASSERT(status == NDIS_STATUS_SUCCESS); - + // // Get VLAN Port property to ensure no VLAN set. // @@ -2470,26 +2470,26 @@ Routine Description: NdisSwitchPortPropertyTypeVlan, NULL, &portPropertyParameters); - + if (status != NDIS_STATUS_SUCCESS) { status = NDIS_STATUS_RESOURCES; goto Cleanup; } - + portPropertyInfo = NDIS_SWITCH_PORT_PROPERTY_ENUM_PARAMETERS_GET_FIRST_INFO(portPropertyParameters); // - // Should always get back v1 or later. It is safe to access the v1 + // Should always get back v1 or later. It is safe to access the v1 // version of the structure if newer property is retrieved. // - ASSERT(portPropertyInfo->PropertyVersion >= + ASSERT(portPropertyInfo->PropertyVersion >= NDIS_SWITCH_PORT_PROPERTY_VLAN_REVISION_1); vlanProperty = NDIS_SWITCH_PORT_PROPERTY_ENUM_INFO_GET_PROPERTY(portPropertyInfo); - + // // Real production code should support VLAN, // and not fail SxExtRestartSwitch. @@ -2500,13 +2500,13 @@ Routine Description: status = NDIS_STATUS_FAILURE; goto Cleanup; } - + status = Switch->NdisSwitchHandlers.DereferenceSwitchPort( Switch->NdisSwitchContext, curNic->PortId); - + ASSERT(status == NDIS_STATUS_SUCCESS); - + // // If a VF is assigned to a NIC, then the traffic // flows through the VF and not the switch. This means @@ -2518,36 +2518,36 @@ Routine Description: Switch->NdisSwitchContext, curNic->PortId, curNic->NicIndex); - + ASSERT(status == NDIS_STATUS_SUCCESS); - + SxLibRevokeVfUnsafe(Switch, curNic->PortId); - + status = Switch->NdisSwitchHandlers.DereferenceSwitchNic( Switch->NdisSwitchContext, curNic->PortId, curNic->NicIndex); - + ASSERT(status == NDIS_STATUS_SUCCESS); } - + // // Now we've verified we can support the NIC, so // check if there's a property for it, and add it to // the NIC list. - // + // status = MsForwardAddNicUnsafe(SwitchContext, curNic->PermanentMacAddress, curNic->PortId, curNic->NicIndex, curNic->NicType, (curNic->NicState == NdisSwitchNicStateConnected)); - + if (status != NDIS_STATUS_SUCCESS) { goto Cleanup; } - + if (curNic->NicType == NdisSwitchNicTypeExternal && curNic->NicIndex != 0 && SwitchContext->ExternalPortId == 0) @@ -2562,7 +2562,7 @@ Routine Description: ++(SwitchContext->NumDestinations); } } - + SwitchContext->IsActive = TRUE; Cleanup: @@ -2570,17 +2570,17 @@ Cleanup: { ExFreePoolWithTag(switchPropertyParameters, SxExtAllocationTag); } - + if (portPropertyParameters != NULL) { ExFreePoolWithTag(portPropertyParameters, SxExtAllocationTag); } - + if (nicArray != NULL) { ExFreePoolWithTag(nicArray, SxExtAllocationTag); } - + return status; } |
