Skip to content

Commit

Permalink
add support for binding XDP to NDIS provider_address layer (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfriesen authored Nov 14, 2024
1 parent 2886c03 commit d97fb12
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 37 deletions.
25 changes: 23 additions & 2 deletions src/xdp/xdp.inx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ xdpapi.dll = 1
%Msft% = MSFT,NT$ARCH$.10.0...17763

[MSFT.NT$ARCH$.10.0...17763]
%Xdp% = Install, ms_xdp
XDP = Install, ms_xdp
XDP_PA = Install_PA, ms_xdp_pa

[Install]
Characteristics = %NCF_LW_FILTER%
Expand All @@ -29,6 +30,13 @@ CopyFiles = Drivers_Dir
CopyFiles = System_Dir
AddReg = XDP.NDI

[Install_PA]
Characteristics = %NCF_LW_FILTER%
NetCfgInstanceId = "{c0be1ebc-74b8-4ba9-8c1e-ecd227e2be3b}"
CopyFiles = Drivers_Dir
CopyFiles = System_Dir
AddReg = XDP_PA.NDI

[Drivers_Dir]
xdp.sys

Expand All @@ -46,9 +54,23 @@ HKR, Ndi\Interfaces, UpperRange,, "noupper"
HKR, Ndi\Interfaces, LowerRange,, "ndisvf"
HKR, Ndi\Interfaces, FilterMediaTypes,, "ethernet, ndisvf"

[XDP_PA.NDI]
HKR, Ndi, Service,, "xdp"
HKR, Ndi, CoServices, %REG_MULTI_SZ%, "xdp"
HKR, Ndi, HelpText,, "%XdpDescription%"
HKR, Ndi, FilterClass,, provider_address
HKR, Ndi, FilterType, %REG_DWORD%, %FILTER_TYPE_MODIFYING%
HKR, Ndi, FilterRunType, %REG_DWORD%, %FILTER_RUN_TYPE_OPTIONAL%
HKR, Ndi\Interfaces, UpperRange,, "noupper"
HKR, Ndi\Interfaces, LowerRange,, "ndisvf"
HKR, Ndi\Interfaces, FilterMediaTypes,, "ethernet, ndisvf"

[Install.Services]
AddService=xdp,, AddService

[Install_PA.Services]
AddService=xdp,, AddService

[AddService]
DisplayName = %XdpDescription%
ServiceType = 1 ;SERVICE_KERNEL_DRIVER
Expand Down Expand Up @@ -84,7 +106,6 @@ DelService = xdp, %SPSVCINST_STOPSERVICE%
[Strings]
; localizable strings
Msft = "Microsoft Corporation"
Xdp = "XDP"
XdpDescription = "Microsoft XDP Platform Driver"

; non-localizable strings
Expand Down
22 changes: 21 additions & 1 deletion src/xdpinstaller/product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@ SPDX-License-Identifier: MIT
<Feature Id="xdp_ebpf" Level="10" AllowAdvertise="no" Title="XDP eBPF" Description="Experimental eBPF support. NOT officially supported.">
<ComponentGroupRef Id="xdp_ebpf" />
</Feature>
<Feature Id="xdp_pa" Level="10" AllowAdvertise="no" Title="XDP PA Layer" Description="Bind XDP lower in the NDIS filter stack.">
<ComponentGroupRef Id="xdp_pa" />
</Feature>
</Feature>

<InstallExecuteSequence>
<!--Rollback sequence-->
<Custom Action="xdp_uninstall_rollback" Before="xdp_install" Condition="NOT Installed" />
<Custom Action="xdp_ebpf_uninstall_rollback" Before="xdp_ebpf_install" Condition="NOT Installed" />
<Custom Action="xdp_pa_uninstall_rollback" Before="xdp_pa_install" Condition="NOT Installed" />

<!--Install sequence-->
<Custom Action="xdp_install" After="InstallFiles" Condition="NOT Installed" />
<Custom Action="xdp_ebpf_install" After="xdp_install" Condition="(&amp;xdp_ebpf=3) AND NOT(!xdp_ebpf=3)" />
<Custom Action="xdp_pa_install" After="xdp_install" Condition="(&amp;xdp_pa=3) AND NOT(!xdp_pa=3)" />

<!--Uninstall sequence-->
<Custom Action="xdp_ebpf_uninstall" After="InstallInitialize" Condition="(&amp;xdp_ebpf=2) AND (!xdp_ebpf=3)" />
<Custom Action="xdp_pa_uninstall" After="InstallInitialize" Condition="(&amp;xdp_pa=2) AND (!xdp_pa=3)" />
<Custom Action="xdp_ebpf_uninstall" After="xdp_pa_uninstall" Condition="(&amp;xdp_ebpf=2) AND (!xdp_ebpf=3)" />
<Custom Action="xdp_uninstall" After="xdp_ebpf_uninstall" Condition="REMOVE=&quot;ALL&quot;" />
</InstallExecuteSequence>

Expand Down Expand Up @@ -105,6 +111,10 @@ SPDX-License-Identifier: MIT
</Component>
</ComponentGroup>

<ComponentGroup Id="xdp_pa" Directory="INSTALLFOLDER">
<ComponentGroupRef Id="xdp" />
</ComponentGroup>

<!-- Install/Uninstall/Rollback the XDP driver installation -->
<SetProperty Id="xdp_install" Value="&quot;[System64Folder]WindowsPowerShell\v1.0\powershell.exe&quot; -ExecutionPolicy Bypass &quot;&amp; '[#xdp_setup_ps1]' -Install xdp -Verbose&quot;" Before="xdp_install" Sequence="execute" />
<CustomAction Id="xdp_install" DllEntry="WixQuietExec64" Execute="deferred" Return="check" Impersonate="no" BinaryRef="Wix4UtilCA_X86" />
Expand All @@ -124,5 +134,15 @@ SPDX-License-Identifier: MIT

<SetProperty Id="xdp_ebpf_uninstall_rollback" Value="&quot;[System64Folder]WindowsPowerShell\v1.0\powershell.exe&quot; -ExecutionPolicy Bypass &quot;&amp; '[#xdp_setup_ps1]' -Uninstall xdpebpf -Verbose&quot;" Before="xdp_ebpf_uninstall_rollback" Sequence="execute" />
<CustomAction Id="xdp_ebpf_uninstall_rollback" DllEntry="WixQuietExec64" Execute="rollback" Return="ignore" Impersonate="no" BinaryRef="Wix4UtilCA_X86" />

<!-- Install/Uninstall/Rollback the XDP PA driver installation -->
<SetProperty Id="xdp_pa_install" Value="&quot;[System64Folder]WindowsPowerShell\v1.0\powershell.exe&quot; -ExecutionPolicy Bypass &quot;&amp; '[#xdp_setup_ps1]' -Install xdppa -Verbose&quot;" Before="xdp_pa_install" Sequence="execute" />
<CustomAction Id="xdp_pa_install" DllEntry="WixQuietExec64" Execute="deferred" Return="check" Impersonate="no" BinaryRef="Wix4UtilCA_X86" />

<SetProperty Id="xdp_pa_uninstall" Value="&quot;[System64Folder]WindowsPowerShell\v1.0\powershell.exe&quot; -ExecutionPolicy Bypass &quot;&amp; '[#xdp_setup_ps1]' -Uninstall xdppa -Verbose&quot;" Before="xdp_pa_uninstall" Sequence="execute" />
<CustomAction Id="xdp_pa_uninstall" DllEntry="WixQuietExec64" Execute="deferred" Return="ignore" Impersonate="no" BinaryRef="Wix4UtilCA_X86" />

<SetProperty Id="xdp_pa_uninstall_rollback" Value="&quot;[System64Folder]WindowsPowerShell\v1.0\powershell.exe&quot; -ExecutionPolicy Bypass &quot;&amp; '[#xdp_setup_ps1]' -Uninstall xdppa -Verbose&quot;" Before="xdp_pa_uninstall_rollback" Sequence="execute" />
<CustomAction Id="xdp_pa_uninstall_rollback" DllEntry="WixQuietExec64" Execute="rollback" Return="ignore" Impersonate="no" BinaryRef="Wix4UtilCA_X86" />
</Fragment>
</Wix>
81 changes: 50 additions & 31 deletions src/xdpruntime/xdp-setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ This script installs or uninstalls various XDP components.
param (

[Parameter(Mandatory = $false)]
[ValidateSet("", "xdp", "xdpebpf")]
[ValidateSet("", "xdp", "xdpebpf", "xdppa")]
[string]$Install = "",

[Parameter(Mandatory = $false)]
[ValidateSet("", "xdp", "xdpebpf")]
[ValidateSet("", "xdp", "xdpebpf", "xdppa")]
[string]$Uninstall = "",

[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -118,14 +118,13 @@ function Uninstall-Driver($Inf) {
}
}

# Installs the xdp driver.
if ($Install -eq "xdp") {
function Install-XdpComponent($ComponentId) {
if (!(Test-Path "$XdpInf")) {
Write-Error "$XdpInf does not exist!"
}

Write-Verbose "netcfg.exe -v -l '$XdpInf' -c s -i ms_xdp"
netcfg.exe -v -l "$XdpInf" -c s -i ms_xdp | Write-Verbose
Write-Verbose "netcfg.exe -v -l '$XdpInf' -c s -i ms_$ComponentId"
netcfg.exe -v -l "$XdpInf" -c s -i ms_$ComponentId | Write-Verbose
if ($LastExitCode) {
Write-Error "netcfg.exe exit code: $LastExitCode"
}
Expand All @@ -139,6 +138,51 @@ if ($Install -eq "xdp") {
Write-Verbose "xdp.sys install complete!"
}

function Uninstall-XdpComponent($ComponentId) {
Write-Verbose "unlodctr.exe /m:$XdpPcwMan"
unlodctr.exe /m:$XdpPcwMan | Write-Verbose
if ($LastExitCode) {
Write-Error "unlodctr.exe exit code: $LastExitCode"
}

Write-Verbose "netcfg.exe -u ms_$ComponentId"
cmd.exe /c "netcfg.exe -u ms_$ComponentId 2>&1" | Write-Verbose
if (!$?) {
Write-Host "netcfg.exe failed: $LastExitCode"
}

Uninstall-Driver "xdp.inf"

Cleanup-Service xdp

Remove-Item $env:WINDIR\system32\xdpapi.dll -Force
Remove-Item $env:WINDIR\system32\drivers\xdp.sys -Force

Write-Verbose "xdp.sys uninstall complete!"
}

# Installs the xdp driver.
if ($Install -eq "xdp") {
Install-XdpComponent "xdp"
}

# Installs the xdp driver in PA mode. Implicitly uninstalls regular xdp.
if ($Install -eq "xdppa") {
Uninstall-XdpComponent "xdp"
Install-XdpComponent "xdp_pa"
}

# Uninstalls the xdp driver from PA mode. Implicitly installs regular xdp.
if ($Uninstall -eq "xdppa") {
Uninstall-XdpComponent "xdp_pa"
Install-XdpComponent "xdp"
}

# Uninstalls the xdp driver.
if ($Uninstall -eq "xdp") {
Uninstall-XdpComponent "xdp"
}

# Installs the XDP eBPF feature.
if ($Install -eq "xdpebpf") {
Write-Verbose "reg.exe add HKLM\SYSTEM\CurrentControlSet\Services\xdp\Parameters /v XdpEbpfEnabled /d 1 /t REG_DWORD /f"
Expand Down Expand Up @@ -174,28 +218,3 @@ if ($Uninstall -eq "xdpebpf") {

Write-Verbose "XDP eBPF feature uninstall complete!"
}

# Uninstalls the xdp driver.
if ($Uninstall -eq "xdp") {

Write-Verbose "unlodctr.exe /m:$XdpPcwMan"
unlodctr.exe /m:$XdpPcwMan | Write-Verbose
if ($LastExitCode) {
Write-Error "unlodctr.exe exit code: $LastExitCode"
}

Write-Verbose "netcfg.exe -u ms_xdp"
cmd.exe /c "netcfg.exe -u ms_xdp 2>&1" | Write-Verbose
if (!$?) {
Write-Host "netcfg.exe failed: $LastExitCode"
}

Uninstall-Driver "xdp.inf"

Cleanup-Service xdp

Remove-Item $env:WINDIR\system32\xdpapi.dll -Force
Remove-Item $env:WINDIR\system32\drivers\xdp.sys -Force

Write-Verbose "xdp.sys uninstall complete!"
}
12 changes: 12 additions & 0 deletions tools/functional.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ for ($i = 1; $i -le $Iterations; $i++) {
Write-Error "[$i/$Iterations] xdpfunctionaltests failed with $LastExitCode" -ErrorAction Continue
$IterationFailureCount++
}

# Sanity test the XDP_PA installer.

Write-Verbose "Reinstalling XDP at PA layer..."
& "$RootDir\tools\setup.ps1" -Uninstall xdp -Config $Config -Platform $Platform
& "$RootDir\tools\setup.ps1" -Install xdp -Config $Config -Platform $Platform -EnableEbpf -PaLayer
Write-Verbose "Installed XDP PA layer."

if (!(Get-NetAdapterBinding -ComponentID ms_xdp_pa)) {
Write-Error "[$i/$Iterations] XDP_PA failed to install" -ErrorAction Continue
$IterationFailureCount++
}
} finally {
if ($Watchdog -ne $null) {
Remove-Job -Job $Watchdog -Force
Expand Down
15 changes: 12 additions & 3 deletions tools/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ param (
[string]$XdpInstaller = "MSI",

[Parameter(Mandatory = $false)]
[switch]$EnableEbpf = $false
[switch]$EnableEbpf = $false,

[Parameter(Mandatory = $false)]
[switch]$PaLayer = $false
)

Set-StrictMode -Version 'Latest'
Expand Down Expand Up @@ -263,10 +266,16 @@ function Install-Xdp {
if ($XdpInstaller -eq "MSI") {
$XdpPath = Get-XdpInstallPath

$AddLocal = ""
$AddLocal = @()

if ($EnableEbpf) {
$AddLocal = "ADDLOCAL=xdp_ebpf"
$AddLocal += "xdp_ebpf"
}
if ($PaLayer) {
$AddLocal += "xdp_pa"
}
if ($AddLocal) {
$AddLocal = "ADDLOCAL=$($AddLocal -join ",")"
}

Write-Verbose "msiexec.exe /i $XdpMsiFullPath INSTALLFOLDER=$XdpPath $AddLocal /quiet /l*v $LogsDir\xdpinstall.txt"
Expand Down

0 comments on commit d97fb12

Please sign in to comment.