Skip to content

Commit 52874ae

Browse files
authored
Add support for WinDivert packet capture engine (#2019)
1 parent 08d661c commit 52874ae

File tree

15 files changed

+1883
-6
lines changed

15 files changed

+1883
-6
lines changed

.github/workflows/build_and_test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,44 @@ jobs:
699699
env:
700700
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
701701

702+
windivert:
703+
runs-on: windows-latest
704+
steps:
705+
- name: Checkout code
706+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
707+
708+
- name: Add MSBuild to PATH
709+
uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2.0.0
710+
711+
- name: Install WinPcap
712+
run: |
713+
ci\install_winpcap.bat
714+
echo "PCAP_SDK_DIR=C:\\WpdPack" >> $env:GITHUB_ENV
715+
- name: Set WinDivert root
716+
run: echo "WINDIVERT_DIR=C:\\WinDivert" >> $env:GITHUB_ENV
717+
718+
- name: Install WinDivert
719+
shell: pwsh
720+
run: .\ci\install_windivert.ps1 -Target "$env:WINDIVERT_DIR"
721+
722+
- name: Configure PcapPlusPlus (WinDivert)
723+
run: cmake -A x64 -G "Visual Studio 17 2022" -DPCAP_ROOT=${{ env.PCAP_SDK_DIR }} -DPCAPPP_USE_WINDIVERT=ON -DWinDivert_ROOT=${{ env.WINDIVERT_DIR }} -S . -B "$env:BUILD_DIR"
724+
725+
- name: Build PcapPlusPlus
726+
run: cmake --build $env:BUILD_DIR -j
727+
728+
- name: Install tcpreplay
729+
run: ci\install_tcpreplay.bat
730+
731+
- name: Test PcapPlusPlus
732+
shell: pwsh
733+
run: |
734+
Copy-Item "${{ env.WINDIVERT_DIR }}\x64\WinDivert.dll" "Tests\Pcap++Test\Bin\WinDivert.dll" -Force
735+
Copy-Item "${{ env.WINDIVERT_DIR }}\x64\WinDivert64.sys" "Tests\Pcap++Test\Bin\WinDivert64.sys" -Force
736+
737+
python -m pip install -r ci\run_tests\requirements.txt
738+
python ci\run_tests\run_tests_windows.py --include-tests windivert
739+
702740
freebsd:
703741
runs-on: ubuntu-latest
704742
strategy:

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ cmake_dependent_option(
165165
)
166166
option(PCAPPP_USE_PF_RING "Setup PcapPlusPlus with PF_RING. In this case you must also set PF_RING_ROOT")
167167
option(PCAPPP_USE_XDP "Setup PcapPlusPlus with XDP")
168+
option(PCAPPP_USE_WINDIVERT "Setup PcapPlusPlus with WinDivert")
168169
option(PCAPPP_INSTALL "Install Pcap++" ${PCAPPP_MAIN_PROJECT})
169170
option(PCAPPP_PACKAGE "Package Pcap++ could require a recent version of CMake" OFF)
170171

@@ -284,6 +285,11 @@ if(PCAPPP_BUILD_PCAPPP)
284285
endif()
285286
add_definitions(-DUSE_XDP)
286287
endif()
288+
289+
if(PCAPPP_USE_WINDIVERT)
290+
find_package(WinDivert REQUIRED)
291+
add_definitions(-DUSE_WINDIVERT)
292+
endif()
287293
endif()
288294

289295
if(NOT CMAKE_BUILD_TYPE)

Pcap++/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_library(
2121
$<$<BOOL:${PCAPPP_USE_XDP}>:src/XdpDevice.cpp>
2222
src/RawSocketDevice.cpp
2323
$<$<BOOL:${WIN32}>:src/WinPcapLiveDevice.cpp>
24+
$<$<BOOL:${PCAPPP_USE_WINDIVERT}>:src/WinDivertDevice.cpp>
2425
# Force light pcapng to be link fully static
2526
$<TARGET_OBJECTS:light_pcapng>
2627
)
@@ -54,6 +55,10 @@ if(PCAPPP_USE_XDP)
5455
list(APPEND public_headers header/XdpDevice.h)
5556
endif()
5657

58+
if(PCAPPP_USE_WINDIVERT)
59+
list(APPEND public_headers header/WinDivertDevice.h)
60+
endif()
61+
5762
if(LINUX)
5863
list(APPEND public_headers header/LinuxNicInformationSocket.h)
5964
endif()
@@ -97,6 +102,7 @@ target_link_libraries(
97102
$<$<BOOL:${PCAPPP_USE_PF_RING}>:PF_RING::PF_RING>
98103
$<$<BOOL:${PCAPPP_USE_DPDK}>:DPDK::DPDK>
99104
$<$<BOOL:${PCAPPP_USE_XDP}>:BPF::BPF>
105+
$<$<BOOL:${PCAPPP_USE_WINDIVERT}>:WinDivert::WinDivert>
100106
PCAP::PCAP
101107
Threads::Threads
102108
)

0 commit comments

Comments
 (0)