Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ForTun/ForTun.inf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Class=Net
ClassGuid={4d36e972-e325-11ce-bfc1-08002be10318}
Provider=%ManufacturerName%
CatalogFile=ForTun.cat
;DriverVer=0.0.1
PnpLockdown=1

[DestinationDirs]
Expand Down
15 changes: 14 additions & 1 deletion ForTun/ForTun.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<None Include="fortun.ddf" />
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
Expand All @@ -44,7 +45,9 @@
<ClInclude Include="TXQueue.h" />
</ItemGroup>
<ItemGroup>
<Inf Include="ForTun.inf" />
<Inf Include="ForTun.inf">
<TimeStamp Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">*</TimeStamp>
</Inf>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4EF57910-A75E-48FB-89A0-B4005D9F609B}</ProjectGuid>
Expand Down Expand Up @@ -113,6 +116,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<Inf2CatUseLocalTime>true</Inf2CatUseLocalTime>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
Expand All @@ -131,6 +135,12 @@
<DriverSign>
<FileDigestAlgorithm>sha256</FileDigestAlgorithm>
</DriverSign>
<Inf>
<SpecifyDriverVerDirectiveVersion>true</SpecifyDriverVerDirectiveVersion>
</Inf>
<Inf>
<TimeStamp>*</TimeStamp>
</Inf>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand All @@ -142,6 +152,9 @@
<DriverSign>
<FileDigestAlgorithm>sha256</FileDigestAlgorithm>
</DriverSign>
<Inf>
<TimeStamp>$(FOR_TUN_VERSION_MAJOR).$(FOR_TUN_VERSION_MINOR).$(FOR_TUN_VERSION_PATCH)</TimeStamp>
</Inf>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<ClCompile>
Expand Down
1 change: 1 addition & 0 deletions ForTun/ForTun.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
<None Include="fortun.ddf" />
</ItemGroup>
<ItemGroup>
<Inf Include="ForTun.inf">
Expand Down
27 changes: 9 additions & 18 deletions ForTun/Queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Return Value:
//
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(
&queueConfig,
//WdfIoQueueDispatchParallel
WdfIoQueueDispatchSequential
);

Expand Down Expand Up @@ -94,10 +95,7 @@ Return Value:
TraceEvents(TRACE_LEVEL_ERROR, TRACE_QUEUE, "create read queue failed %!STATUS!", status);
return status;
}
//status = WdfDeviceConfigureRequestDispatching(Device, readQueue, WdfRequestTypeRead);
//if (!NT_SUCCESS(status)) {
// goto done;
//}

WDFQUEUE writeQueue;
WDF_IO_QUEUE_CONFIG_INIT(&queueConfig, WdfIoQueueDispatchManual);
status = WdfIoQueueCreate(Device, &queueConfig, WDF_NO_OBJECT_ATTRIBUTES, &writeQueue);
Expand All @@ -106,22 +104,10 @@ Return Value:
TraceEvents(TRACE_LEVEL_ERROR, TRACE_QUEUE, "create write queue failed %!STATUS!", status);
return status;
}
//status = WdfDeviceConfigureRequestDispatching(Device, writeQueue, WdfRequestTypeWrite);

PDEVICE_CONTEXT device_context = DeviceGetContext(Device);

/*
WDF_OBJECT_ATTRIBUTES attr;
WDF_OBJECT_ATTRIBUTES_INIT(&attr);
attr.ParentObject = Device;
WDFMEMORY BufferHandler;
status = WdfMemoryCreate(&attr, NonPagedPool, 'FTun', READ_POOL_SIZE, &BufferHandler, &device_context->PReadBuffer);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR, TRACE_QUEUE, "create ReadBuffer failed %!STATUS!", status);
goto done;
}
RtlZeroMemory(device_context->PReadBuffer, READ_POOL_SIZE);
RingBufferInitialize(&device_context->ReadRingBuffer, device_context->PReadBuffer, READ_POOL_SIZE);
*/

PPOOL_QUEUE poolQueue;
status = PoolQueueCreate(&poolQueue);
if (!NT_SUCCESS(status)) {
Expand Down Expand Up @@ -277,6 +263,7 @@ ForTunEvtIoRead(
IN size_t Length
)
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_QUEUE, "Io Read has trigger");
UNREFERENCED_PARAMETER(Length);
NTSTATUS status;

Expand All @@ -294,6 +281,7 @@ ForTunEvtIoRead(
PPOOL_QUEUE_ITEM poolQueueItem = PoolQueueGetFromQueue(deviceContext->PoolQueue);

if (poolQueueItem) {
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_QUEUE, "Pool Has Item");
RtlCopyMemory(readBuffer, &poolQueueItem->Data, poolQueueItem->DataSize);
size_t dataSize = poolQueueItem->DataSize;
PoolQueuePutToPool(deviceContext->PoolQueue, poolQueueItem);
Expand All @@ -312,6 +300,7 @@ ForTunEvtIoRead(
}*/
else {
status = WdfRequestForwardToIoQueue(Request, deviceContext->PendingReadQueue);
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_QUEUE, "Append Request To Queue");
WdfSpinLockRelease(deviceContext->readLock);
if (!NT_SUCCESS(status)) {
goto logErr;
Expand All @@ -332,6 +321,7 @@ ForTunEvtIoWrite(
)
{
UNREFERENCED_PARAMETER(Length);
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_QUEUE, "Write item");

PDEVICE_CONTEXT context = DeviceGetContext(WdfIoQueueGetDevice(Queue));

Expand All @@ -345,6 +335,7 @@ ForTunEvtIoWrite(

//this should always be success
ForTunAdapterNotifyRx(context->Adapter);


return;
logErr:
Expand Down
9 changes: 7 additions & 2 deletions ForTun/TXQueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ ForTunTxQueueSetNotificationEnabled(_In_ NETPACKETQUEUE PacketQueue, _In_ BOOLEA
VOID
ForTunTxQueueAdvance(_In_ NETPACKETQUEUE PacketQueue)
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_ADAPTER, "%!FUNC! Entry");
TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_ADAPTER, "%!FUNC! Entry");

PTXQUEUE_CONTEXT context = TxQueueGetContext(PacketQueue);
PDEVICE_CONTEXT deviceContext = context->AdapterContext->DeviceContext;

NET_RING_COLLECTION const* ringCollection = context->RingCollection;
NET_RING_PACKET_ITERATOR pi = NetRingGetAllPackets(ringCollection);
SIZE_T length = 0;

NTSTATUS status = STATUS_SUCCESS;
// in
Expand All @@ -63,6 +64,7 @@ ForTunTxQueueAdvance(_In_ NETPACKETQUEUE PacketQueue)
// Process
NET_RING_FRAGMENT_ITERATOR fi = NetPacketIteratorGetFragments(&pi);
WDFREQUEST request;
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_ADAPTER, "TXQueue begin to acquire readLock");
WdfSpinLockAcquire(deviceContext->readLock);
status = WdfIoQueueRetrieveNextRequest(deviceContext->PendingReadQueue, &request);
UCHAR* buffer = NULL;
Expand All @@ -89,11 +91,11 @@ ForTunTxQueueAdvance(_In_ NETPACKETQUEUE PacketQueue)
}

if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_ADAPTER, "TXQueue begin to release readLock for %!STATUS!", status);
WdfSpinLockRelease(deviceContext->readLock);
NetFragmentIteratorSet(&fi);
}
else {
SIZE_T length = 0;
while (NetFragmentIteratorHasAny(&fi)) {
NET_FRAGMENT* fragment = NetFragmentIteratorGetFragment(&fi);
BYTE* netBuf = (BYTE *)NetExtensionGetFragmentVirtualAddressOffset(fragment, &context->VirtualAddressExtension, NetFragmentIteratorGetIndex(&fi));
Expand All @@ -108,12 +110,15 @@ ForTunTxQueueAdvance(_In_ NETPACKETQUEUE PacketQueue)
NetFragmentIteratorAdvance(&fi);
}
if (buffer) {
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_ADAPTER, "wdf request complete length: %I64d", length);
WdfRequestCompleteWithInformation(request, status, length);
}
else if(poolQueueItem){
poolQueueItem->DataSize = length;
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_ADAPTER, "push pool queue length: %I64d", length);
PoolQueuePutToQueue(deviceContext->PoolQueue, poolQueueItem);
}
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_ADAPTER, "TXQueue begin to release readLock");
WdfSpinLockRelease(deviceContext->readLock);
}

Expand Down
1 change: 0 additions & 1 deletion ForTunCli/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/target
.idea
/win11
/examples
driver
Loading