aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-07-03 08:44:17 +0000
committerJason A. Donenfeld <Jason@zx2c4.com>2019-07-03 08:50:30 +0000
commitb2182e0e9059c97b7951ea45c6f2aba8be222109 (patch)
tree7559bc1a478ecfb81941e86b6e03b95125d29d98
parentReceiving happens at dispatch level due to transition lock (diff)
downloadwintun-b2182e0e9059c97b7951ea45c6f2aba8be222109.tar.xz
wintun-b2182e0e9059c97b7951ea45c6f2aba8be222109.zip
Reorder ReturnNBL and DispatchWrite
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--wintun.c72
1 files changed, 36 insertions, 36 deletions
diff --git a/wintun.c b/wintun.c
index 01b377a..3dadffb 100644
--- a/wintun.c
+++ b/wintun.c
@@ -753,6 +753,42 @@ cleanup_CompleteRequest:
#define IRP_REFCOUNT(irp) ((volatile LONG *)&(irp)->Tail.Overlay.DriverContext[0])
#define NET_BUFFER_LIST_IRP(nbl) (NET_BUFFER_LIST_MINIPORT_RESERVED(nbl)[0])
+static MINIPORT_RETURN_NET_BUFFER_LISTS TunReturnNetBufferLists;
+_Use_decl_annotations_
+static void
+TunReturnNetBufferLists(NDIS_HANDLE MiniportAdapterContext, PNET_BUFFER_LIST NetBufferLists, ULONG ReturnFlags)
+{
+ TUN_CTX *Ctx = (TUN_CTX *)MiniportAdapterContext;
+
+ LONG64 StatSize = 0, StatPacketsOk = 0, StatPacketsError = 0;
+ for (NET_BUFFER_LIST *Nbl = NetBufferLists, *NextNbl; Nbl; Nbl = NextNbl)
+ {
+ NextNbl = NET_BUFFER_LIST_NEXT_NBL(Nbl);
+ NET_BUFFER_LIST_NEXT_NBL(Nbl) = NULL;
+
+ IRP *Irp = NET_BUFFER_LIST_IRP(Nbl);
+ if (NT_SUCCESS(NET_BUFFER_LIST_STATUS(Nbl)))
+ {
+ StatSize += NET_BUFFER_LIST_FIRST_NB(Nbl)->DataLength;
+ StatPacketsOk++;
+ }
+ else
+ StatPacketsError++;
+
+ NdisFreeNetBufferList(Nbl);
+ TunCompletePause(Ctx, TRUE);
+
+ ASSERT(InterlockedGet(IRP_REFCOUNT(Irp)) > 0);
+ if (InterlockedDecrement(IRP_REFCOUNT(Irp)) <= 0)
+ TunCompleteRequest(Ctx, Irp, STATUS_SUCCESS, IO_NETWORK_INCREMENT);
+ }
+
+ InterlockedAdd64((LONG64 *)&Ctx->Statistics.ifHCInOctets, StatSize);
+ InterlockedAdd64((LONG64 *)&Ctx->Statistics.ifHCInUcastOctets, StatSize);
+ InterlockedAdd64((LONG64 *)&Ctx->Statistics.ifHCInUcastPkts, StatPacketsOk);
+ InterlockedAdd64((LONG64 *)&Ctx->Statistics.ifInErrors, StatPacketsError);
+}
+
_IRQL_requires_max_(APC_LEVEL)
_Must_inspect_result_
static NTSTATUS
@@ -909,42 +945,6 @@ cleanup_CompleteRequest:
return Status;
}
-static MINIPORT_RETURN_NET_BUFFER_LISTS TunReturnNetBufferLists;
-_Use_decl_annotations_
-static void
-TunReturnNetBufferLists(NDIS_HANDLE MiniportAdapterContext, PNET_BUFFER_LIST NetBufferLists, ULONG ReturnFlags)
-{
- TUN_CTX *Ctx = (TUN_CTX *)MiniportAdapterContext;
-
- LONG64 StatSize = 0, StatPacketsOk = 0, StatPacketsError = 0;
- for (NET_BUFFER_LIST *Nbl = NetBufferLists, *NextNbl; Nbl; Nbl = NextNbl)
- {
- NextNbl = NET_BUFFER_LIST_NEXT_NBL(Nbl);
- NET_BUFFER_LIST_NEXT_NBL(Nbl) = NULL;
-
- IRP *Irp = NET_BUFFER_LIST_IRP(Nbl);
- if (NT_SUCCESS(NET_BUFFER_LIST_STATUS(Nbl)))
- {
- StatSize += NET_BUFFER_LIST_FIRST_NB(Nbl)->DataLength;
- StatPacketsOk++;
- }
- else
- StatPacketsError++;
-
- NdisFreeNetBufferList(Nbl);
- TunCompletePause(Ctx, TRUE);
-
- ASSERT(InterlockedGet(IRP_REFCOUNT(Irp)) > 0);
- if (InterlockedDecrement(IRP_REFCOUNT(Irp)) <= 0)
- TunCompleteRequest(Ctx, Irp, STATUS_SUCCESS, IO_NETWORK_INCREMENT);
- }
-
- InterlockedAdd64((LONG64 *)&Ctx->Statistics.ifHCInOctets, StatSize);
- InterlockedAdd64((LONG64 *)&Ctx->Statistics.ifHCInUcastOctets, StatSize);
- InterlockedAdd64((LONG64 *)&Ctx->Statistics.ifHCInUcastPkts, StatPacketsOk);
- InterlockedAdd64((LONG64 *)&Ctx->Statistics.ifInErrors, StatPacketsError);
-}
-
_IRQL_requires_max_(APC_LEVEL)
_Must_inspect_result_
static NTSTATUS