Skip to content

Commit

Permalink
Add RX checksum offload support for Win11 version
Browse files Browse the repository at this point in the history
Indicate RX checksum offload and set validation result
always as valid thus saving some CPU cycles on software validation.
Since we have authenticated encryption, we can be sure that
checksums weren't altered on the wire.

Before NetAdapterCx 2.1, checksum offload support indication
doesn't distinguish between TX and RX. This means if we want to
indicate RX checksum offload, we have to calculate checkums on TX
path, too.

Complexity of TX checksum calculation doesn't justify performace
gain, so additional Debug/Release-Win11 build configurations were created
which target NetAdapterCx 2.1 and newer. This can be used on
Windows 11 and Windows Server 2022 (kernel 10.0.20348 and newer).

Signed-off-by: Lev Stipakov <[email protected]>
  • Loading branch information
lstipakov committed Apr 13, 2022
1 parent 41eb310 commit 7ee61eb
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
arch: [x64, x86, ARM64]
build_conf: [Debug, Release]
build_conf: [Debug, Release, Debug-Win11, Release-Win11]

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 1 addition & 11 deletions PropertySheet.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<PropertyGroup Label="UserMacros">
<OVPN_DCO_VERSION_MAJOR>0</OVPN_DCO_VERSION_MAJOR>
<OVPN_DCO_VERSION_MINOR>7</OVPN_DCO_VERSION_MINOR>
<OVPN_DCO_VERSION_PATCH>0</OVPN_DCO_VERSION_PATCH>
<NETADAPTER_INC_PATH>$(DDK_INC_PATH)\netcx\kmdf\adapter\2.0\</NETADAPTER_INC_PATH>
<NETADAPTER_LIB_PATH>$(DDK_LIB_PATH)\netcx\kmdf\adapter\2.0\</NETADAPTER_LIB_PATH>
<OVPN_DCO_VERSION_PATCH>1</OVPN_DCO_VERSION_PATCH>
</PropertyGroup>
<PropertyGroup />
<ItemDefinitionGroup>
Expand All @@ -30,13 +28,5 @@
<Value>$(OVPN_DCO_VERSION_PATCH)</Value>
<EnvironmentVariable>true</EnvironmentVariable>
</BuildMacro>
<BuildMacro Include="NETADAPTER_INC_PATH">
<Value>$(NETADAPTER_INC_PATH)</Value>
<EnvironmentVariable>true</EnvironmentVariable>
</BuildMacro>
<BuildMacro Include="NETADAPTER_LIB_PATH">
<Value>$(NETADAPTER_LIB_PATH)</Value>
<EnvironmentVariable>true</EnvironmentVariable>
</BuildMacro>
</ItemGroup>
</Project>
46 changes: 41 additions & 5 deletions adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,41 @@
// maximum link speed for send and recv in bps
#define OVPN_MEDIA_MAX_SPEED 1'000'000'000

static void
#if (NETADAPTER_VERSION_MAJOR >= 2) && (NETADAPTER_VERSION_MINOR >= 1)

EVT_NET_ADAPTER_OFFLOAD_SET_RX_CHECKSUM OvpnEvtAdapterOffloadSetRxChecksum;

_Use_decl_annotations_
VOID
OvpnEvtAdapterOffloadSetRxChecksum(NETADAPTER netAdapter, NETOFFLOAD offload)
{
UNREFERENCED_PARAMETER(netAdapter);

LOG_INFO("Checksum offload settings changed",
TraceLoggingValue(NetOffloadIsRxChecksumIPv4Enabled(offload), "ipv4"),
TraceLoggingValue(NetOffloadIsRxChecksumTcpEnabled(offload), "tcp"),
TraceLoggingValue(NetOffloadIsRxChecksumUdpEnabled(offload), "udp"));

// we don't really care about those settings, since we always report tunnel checksums as valid
}

static
VOID
OvpnAdapterSetOffloadCapabilities(_In_ POVPN_ADAPTER adapter)
{
// Configure the hardware's Rx checksum offload capabilities
NET_ADAPTER_OFFLOAD_RX_CHECKSUM_CAPABILITIES rxChecksumOffloadCapabilities;

NET_ADAPTER_OFFLOAD_RX_CHECKSUM_CAPABILITIES_INIT(&rxChecksumOffloadCapabilities, OvpnEvtAdapterOffloadSetRxChecksum);

// Set the current Rx checksum offload capabilities and register the callback for future changes in active capabilities
NetAdapterOffloadSetRxChecksumCapabilities(adapter->NetAdapter, &rxChecksumOffloadCapabilities);
}

#endif

static
VOID
OvpnAdapterSetDatapathCapabilities(_In_ POVPN_ADAPTER adapter)
{
NET_ADAPTER_TX_CAPABILITIES txCapabilities;
Expand All @@ -41,7 +75,7 @@ OvpnAdapterSetDatapathCapabilities(_In_ POVPN_ADAPTER adapter)
}

static
void
VOID
OvpnAdapterSetLinkLayerCapabilities(_In_ POVPN_ADAPTER adapter)
{
ULONG64 maxXmitLinkSpeed = OVPN_MEDIA_MAX_SPEED;
Expand All @@ -57,7 +91,7 @@ OvpnAdapterSetLinkLayerCapabilities(_In_ POVPN_ADAPTER adapter)
}

static
void
VOID
OvpnAdapterSetLinkState(_In_ POVPN_ADAPTER adapter)
{
NET_ADAPTER_LINK_STATE linkState;
Expand Down Expand Up @@ -149,8 +183,6 @@ OvpnAdapterCreate(OVPN_DEVICE * device) {
NET_ADAPTER_DATAPATH_CALLBACKS_INIT(&datapathCallbacks, OvpnEvtAdapterCreateTxQueue, OvpnEvtAdapterCreateRxQueue);
NetAdapterInitSetDatapathCallbacks(adapterInit, &datapathCallbacks);

NetAdapterInitSetDatapathCallbacks(adapterInit, &datapathCallbacks);

WDF_OBJECT_ATTRIBUTES adapterAttributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&adapterAttributes, OVPN_ADAPTER);

Expand All @@ -167,6 +199,10 @@ OvpnAdapterCreate(OVPN_DEVICE * device) {
OvpnAdapterSetDatapathCapabilities(adapter);
OvpnAdapterSetLinkLayerCapabilities(adapter);

#if (NETADAPTER_VERSION_MAJOR >= 2) && (NETADAPTER_VERSION_MINOR >= 1)
OvpnAdapterSetOffloadCapabilities(adapter);
#endif

OvpnAdapterSetLinkState(adapter);

status = NetAdapterStart(adapter->NetAdapter);
Expand Down
34 changes: 34 additions & 0 deletions ovpn-dco-win.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ Global
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Debug-Win11|Any CPU = Debug-Win11|Any CPU
Debug-Win11|ARM64 = Debug-Win11|ARM64
Debug-Win11|x64 = Debug-Win11|x64
Debug-Win11|x86 = Debug-Win11|x86
Release|Any CPU = Release|Any CPU
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
Release-Win11|Any CPU = Release-Win11|Any CPU
Release-Win11|ARM64 = Release-Win11|ARM64
Release-Win11|x64 = Release-Win11|x64
Release-Win11|x86 = Release-Win11|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug|Any CPU.ActiveCfg = Debug|Win32
Expand All @@ -29,6 +37,14 @@ Global
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug|x86.ActiveCfg = Debug|Win32
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug|x86.Build.0 = Debug|Win32
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug|x86.Deploy.0 = Debug|Win32
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug-Win11|Any CPU.ActiveCfg = Debug-Win11|ARM
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug-Win11|Any CPU.Build.0 = Debug-Win11|ARM
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug-Win11|ARM64.ActiveCfg = Debug-Win11|ARM64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug-Win11|ARM64.Build.0 = Debug-Win11|ARM64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug-Win11|x64.ActiveCfg = Debug-Win11|x64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug-Win11|x64.Build.0 = Debug-Win11|x64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug-Win11|x86.ActiveCfg = Debug-Win11|x64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Debug-Win11|x86.Build.0 = Debug-Win11|x64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release|Any CPU.ActiveCfg = Release|Win32
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release|ARM64.ActiveCfg = Release|ARM64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release|ARM64.Build.0 = Release|ARM64
Expand All @@ -39,19 +55,37 @@ Global
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release|x86.ActiveCfg = Release|Win32
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release|x86.Build.0 = Release|Win32
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release|x86.Deploy.0 = Release|Win32
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release-Win11|Any CPU.ActiveCfg = Release-Win11|ARM
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release-Win11|Any CPU.Build.0 = Release-Win11|ARM
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release-Win11|ARM64.ActiveCfg = Release-Win11|ARM64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release-Win11|ARM64.Build.0 = Release-Win11|ARM64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release-Win11|x64.ActiveCfg = Release-Win11|x64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release-Win11|x64.Build.0 = Release-Win11|x64
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release-Win11|x86.ActiveCfg = Release-Win11|Win32
{C91D6DBF-F373-44CD-8179-D0F55888A015}.Release-Win11|x86.Build.0 = Release-Win11|Win32
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug|Any CPU.ActiveCfg = Debug|Win32
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug|ARM64.ActiveCfg = Debug|ARM64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug|x64.ActiveCfg = Debug|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug|x64.Build.0 = Debug|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug|x86.ActiveCfg = Debug|Win32
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug|x86.Build.0 = Debug|Win32
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug-Win11|Any CPU.ActiveCfg = Release-Win11|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug-Win11|ARM64.ActiveCfg = Debug|ARM64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug-Win11|x64.ActiveCfg = Debug|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug-Win11|x64.Build.0 = Debug|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Debug-Win11|x86.ActiveCfg = Debug|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release|Any CPU.ActiveCfg = Release|Win32
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release|ARM64.ActiveCfg = Release|ARM64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release|ARM64.Build.0 = Release|ARM64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release|x64.ActiveCfg = Release|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release|x64.Build.0 = Release|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release|x86.ActiveCfg = Release|Win32
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release|x86.Build.0 = Release|Win32
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release-Win11|Any CPU.ActiveCfg = Release-Win11|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release-Win11|ARM64.ActiveCfg = Release|ARM64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release-Win11|x64.ActiveCfg = Release|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release-Win11|x64.Build.0 = Release|x64
{BA23900A-7FAC-49CF-9AC7-C20CD52F42AF}.Release-Win11|x86.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading

0 comments on commit 7ee61eb

Please sign in to comment.