datapath-windows: Added new function for native forwarded traffic
authorSorin Vinturis <svinturis@cloudbasesolutions.com>
Fri, 8 May 2015 06:16:51 +0000 (06:16 +0000)
committerBen Pfaff <blp@nicira.com>
Fri, 8 May 2015 16:32:56 +0000 (09:32 -0700)
Signed-off-by: Sorin Vinturis <svinturis@cloudbasesolutions.com>
Acked-by: Nithin Raju <nithin@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath-windows/ovsext/PacketIO.c

index 1f5c8b0..902e9aa 100644 (file)
@@ -176,6 +176,29 @@ OvsStartNBLIngressError(POVS_SWITCH_CONTEXT switchContext,
                                     sendCompleteFlags);
 }
 
+static VOID
+OvsAppendNativeForwardedPacket(POVS_SWITCH_CONTEXT switchContext,
+                               PNET_BUFFER_LIST curNbl,
+                               PNET_BUFFER_LIST *nativeNbls,
+                               ULONG flags,
+                               BOOLEAN isRecv)
+{
+    POVS_BUFFER_CONTEXT ctx = { 0 };
+    NDIS_STRING filterReason;
+
+    *nativeNbls = curNbl;
+    nativeNbls = &(curNbl->Next);
+
+    ctx = OvsInitExternalNBLContext(switchContext, curNbl, isRecv);
+    if (ctx == NULL) {
+        RtlInitUnicodeString(&filterReason,
+                             L"Cannot allocate native NBL context.");
+
+        OvsStartNBLIngressError(switchContext, curNbl, flags, &filterReason,
+                                NDIS_STATUS_RESOURCES);
+    }
+}
+
 static VOID
 OvsStartNBLIngress(POVS_SWITCH_CONTEXT switchContext,
                    PNET_BUFFER_LIST netBufferLists,
@@ -193,9 +216,7 @@ OvsStartNBLIngress(POVS_SWITCH_CONTEXT switchContext,
     LIST_ENTRY missedPackets;
     UINT32 num = 0;
     OvsCompletionList completionList;
-    PNET_BUFFER_LIST ovsForwardedNbls = NULL;
     PNET_BUFFER_LIST nativeForwardedNbls = NULL;
-    PNET_BUFFER_LIST *nextOvsForwardNbl = &ovsForwardedNbls;
     PNET_BUFFER_LIST *nextNativeForwardedNbl = &nativeForwardedNbls;
 
     dispatch = NDIS_TEST_SEND_AT_DISPATCH_LEVEL(SendFlags)?
@@ -206,48 +227,7 @@ OvsStartNBLIngress(POVS_SWITCH_CONTEXT switchContext,
     InitializeListHead(&missedPackets);
     OvsInitCompletionList(&completionList, switchContext, sendCompleteFlags);
 
-#if (NDIS_SUPPORT_NDIS640)
-    /*
-     * Split NBL list into NBLs to be forwarded by us, and those that require
-     * native forwarding.
-     */
     for (curNbl = netBufferLists; curNbl != NULL; curNbl = nextNbl) {
-        nextNbl = curNbl->Next;
-        curNbl->Next = NULL;
-        fwdDetail = NET_BUFFER_LIST_SWITCH_FORWARDING_DETAIL(curNbl);
-
-        if (fwdDetail->NativeForwardingRequired) {
-            POVS_BUFFER_CONTEXT ctx;
-
-            *nextNativeForwardedNbl = curNbl;
-            nextNativeForwardedNbl = &(curNbl->Next);
-
-            ctx = OvsInitExternalNBLContext(switchContext, curNbl,
-                sourcePort == switchContext->virtualExternalPortId);
-            if (ctx == NULL) {
-                RtlInitUnicodeString(&filterReason,
-                    L"Cannot allocate native NBL context.");
-
-                OvsStartNBLIngressError(switchContext, curNbl,
-                    sendCompleteFlags, &filterReason,
-                    NDIS_STATUS_RESOURCES);
-
-                continue;
-            }
-        } else {
-            *nextOvsForwardNbl = curNbl;
-            nextOvsForwardNbl = &(curNbl->Next);
-        }
-    }
-#else
-    UNREFERENCED_PARAMETER(nativeForwardedNbls);
-    UNREFERENCED_PARAMETER(nextNativeForwardedNbl);
-    UNREFERENCED_PARAMETER(nextOvsForwardNbl);
-
-    ovsForwardedNbls = netBufferLists;
-#endif
-
-    for (curNbl = ovsForwardedNbls; curNbl != NULL; curNbl = nextNbl) {
         POVS_VPORT_ENTRY vport;
         UINT32 portNo;
         OVS_DATAPATH *datapath = &switchContext->datapath;
@@ -259,6 +239,23 @@ OvsStartNBLIngress(POVS_SWITCH_CONTEXT switchContext,
         nextNbl = curNbl->Next;
         curNbl->Next = NULL;
 
+        fwdDetail = NET_BUFFER_LIST_SWITCH_FORWARDING_DETAIL(curNbl);
+        sourcePort = fwdDetail->SourcePortId;
+        sourceIndex = (NDIS_SWITCH_NIC_INDEX)fwdDetail->SourceNicIndex;
+
+#if (NDIS_SUPPORT_NDIS640)
+        if (fwdDetail->NativeForwardingRequired) {
+            /* Add current NBL to those that require native forwarding. */
+            OvsAppendNativeForwardedPacket(
+                switchContext,
+                curNbl,
+                nextNativeForwardedNbl,
+                sendCompleteFlags,
+                sourcePort == switchContext->virtualExternalPortId);
+            continue;
+        }
+#endif
+
         /* Ethernet Header is a guaranteed safe access. */
         curNb = NET_BUFFER_LIST_FIRST_NB(curNbl);
         if (curNb->Next != NULL) {
@@ -273,10 +270,6 @@ OvsStartNBLIngress(POVS_SWITCH_CONTEXT switchContext,
             POVS_BUFFER_CONTEXT ctx;
             OvsFlow *flow;
 
-            fwdDetail = NET_BUFFER_LIST_SWITCH_FORWARDING_DETAIL(curNbl);
-            sourcePort = fwdDetail->SourcePortId;
-            sourceIndex = (NDIS_SWITCH_NIC_INDEX)fwdDetail->SourceNicIndex;
-
             /* Take the DispatchLock so none of the VPORTs disconnect while
              * we are setting destination ports.
              *