Skip to content

Cleanup of PcapLiveDevice capture machinery. #1838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

Dimi1010
Copy link
Collaborator

@Dimi1010 Dimi1010 commented May 31, 2025

This PR moves the implementation of the capture procedures to internally linked functions in PcapLiveDevice.cpp and aims to reduce the the need for extensive bookkeeping of capture thread only variables.

The static member function callback routines for pcap_dispatch have been replaced with internal linkage free functions to improve readability and encapsulation. The user token is now expected to be a pointer to a specific capture context object instead of the device instance.

Replacement list:

  • onPacketArrivesCallback replaces onPacketArrives. Expects user token of type CaptureContext
  • onPacketArrivesAccumulator replaces onPacketArrivesNoCallback. Expects user token of type AccumulatorCaptureContext
  • onPacketArrivesCallbackWithCancellation replaces onPacketArrivesBlockingMode. Expects user token of type CaptureContextST
  • Added new callback handler onPacketArrivesNoop to be used when no handling is required.

Replaced captureThreadMain static private function with internal linkage free functions. The free functions take their inputs as parameters instead of relying on data from the implicit this pointer, simplifying data ownership and reducing risk of data races.

  • captureThreadMain - used for callback or noop capture.
  • captureThreadMainAccumulator - used for accumulating the packets into a RawPacketVector.

Changed blocking mode capture to utilize onPacketArrivesCallbackWithCancellation. The new infrastructure provides a layer of separation between the device threading machinery and the cancellation requests by relying on requestStop flag to record a cancellation request that is then forwarded to m_StopThread after dispatch finishes instead of directly writing to m_StopThread.

Removed PcapLiveDevice member fields previously only used to store data for the capture thread as that data is now stored in context objects created on demand during capture startup.

Copy link

codecov bot commented May 31, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 55 lines in your changes missing coverage. Please review.

Project coverage is 82.93%. Comparing base (8e3e9cf) to head (4483885).
Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
Pcap++/src/PcapLiveDevice.cpp 66.66% 36 Missing and 19 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1838      +/-   ##
==========================================
- Coverage   82.98%   82.93%   -0.06%     
==========================================
  Files         284      284              
  Lines       48887    49020     +133     
  Branches    10334    10601     +267     
==========================================
+ Hits        40571    40656      +85     
- Misses       7173     7241      +68     
+ Partials     1143     1123      -20     
Flag Coverage Δ
alpine320 75.02% <50.92%> (-0.04%) ⬇️
fedora42 75.12% <51.37%> (-0.03%) ⬇️
macos-13 80.47% <63.76%> (-0.04%) ⬇️
macos-14 80.47% <61.59%> (-0.05%) ⬇️
macos-15 80.45% <61.59%> (-0.04%) ⬇️
mingw32 71.23% <43.92%> (-0.18%) ⬇️
mingw64 71.23% <43.92%> (-0.14%) ⬇️
npcap 84.84% <60.86%> (-0.16%) ⬇️
rhel94 74.88% <48.14%> (-0.06%) ⬇️
ubuntu2004 58.63% <54.54%> (+0.11%) ⬆️
ubuntu2004-zstd 58.75% <54.54%> (+0.11%) ⬆️
ubuntu2204 74.81% <50.92%> (-0.02%) ⬇️
ubuntu2204-icpx 61.44% <51.44%> (-0.02%) ⬇️
ubuntu2404 75.07% <48.14%> (-0.03%) ⬇️
ubuntu2404-arm64 75.06% <50.92%> (-0.03%) ⬇️
unittest 82.93% <66.66%> (-0.06%) ⬇️
windows-2019 84.87% <62.80%> (-0.15%) ⬇️
windows-2022 84.89% <62.60%> (-0.15%) ⬇️
winpcap 85.04% <64.46%> (-0.13%) ⬇️
xdp 50.56% <0.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Dimi1010 Dimi1010 marked this pull request as ready for review May 31, 2025 19:58
@Dimi1010 Dimi1010 requested a review from seladb as a code owner May 31, 2025 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant