-
Notifications
You must be signed in to change notification settings - Fork 1.7k
pcap-file: move packet counter to PCAP packet structure v5.2 #14657
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
Conversation
Use of t_pcapcnt is only relevant when compiled in debug mode only. This patch adds additional debug guard to also shield the declaration and assignment.
For an easier review process, this is a two-step change process, in which pcap_cnt is first accessed by functions-to-be, implemented as simple macros. In the follow-up commit, the actual refactor is implemented with the new function. The old macros are deleted. Ticket: 7835
Code refactor to gather all PCAP-related structure members under one structure. New pcap_v structure guards protect the union variables from other capture modes trying to access the packet number incorrectly. Ticket: 7835
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the packet counter handling by moving the pcap_cnt field from the main Packet structure into the PcapPacketVars structure (pcap_v), which is part of the existing union for packet source-specific variables. This consolidates all PCAP-related structure members under one structure.
Changes:
- Introduced getter/setter functions (
PcapPacketCntGet,PcapPacketCntSet) with runmode validation to control access topcap_cnt - Updated all code references to use the getter/setter functions instead of direct field access
- Moved the
pcap_cntfield from the Packet structure to thePcapPacketVarsstructure
Reviewed changes
Copilot reviewed 45 out of 45 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/decode.h | Removed pcap_cnt from Packet structure; added function declarations for getter/setter |
| src/decode.c | Implemented getter/setter functions with runmode validation logic |
| src/source-pcap.h | Added pcap_cnt field to PcapPacketVars structure |
| src/source-pcap-file-helper.c | Direct access to p->pcap_v.pcap_cnt in PCAP-native code |
| src/packet.c | Removed pcap_cnt initialization from PacketReinit |
| src/stream-tcp.c | Moved t_pcapcnt extern declaration inside DEBUG block; converted all access to use getter |
| src/stream-tcp-reassemble.c | Moved t_pcapcnt declaration inside DEBUG block |
| src/stream-tcp-private.h | Updated macro to use getter function |
| src/stream-tcp-sack.c | Converted to use getter function in debug logging |
| src/util-profiling.c | Converted to use getter function |
| src/util-lua-packetlib.c | Converted to use getter function |
| src/util-exception-policy.c | Converted to use getter function in debug logging |
| src/output-tx.c | Converted to use getter function in debug logging |
| src/output-json.c | Converted to use getter with local variable caching |
| src/output-json-alert.c | Converted to use getter with local variable caching |
| src/log-tlsstore.c | Converted to use getter with local variable caching |
| src/flow.c | Converted to use getter function in debug logging |
| src/flow-worker.c | Converted to use getter function in debug logging |
| src/flow-hash.c | Converted to use getter function in DEBUG code |
| src/detect.c | Converted to use getter function in debug logging |
| src/detect-*.c | Converted to use getter function in debug logging across multiple detect modules |
| src/defrag.c | Converted to use getter function in DEBUG code |
| src/defrag-hash.c | Converted to use getter function in DEBUG code |
| src/app-layer.c | Converted to use getter function in debug logging |
| src/alert-*.c | Converted to use getter with local variable caching for output formatting |
| src/tests/fuzz/*.c | Converted to use setter function |
| src/tests/detect-*.c | Converted to use setter function in test setup |
| plugins/ndpi/ndpi.c | Converted to use getter function in debug logging |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #14657 +/- ##
==========================================
- Coverage 82.11% 82.11% -0.01%
==========================================
Files 1011 1011
Lines 262812 262863 +51
==========================================
+ Hits 215812 215847 +35
- Misses 47000 47016 +16
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
| SCJbSetString(js, "proto", addr.proto); | ||
|
|
||
| SCJbSetUint(js, "depth", p->recursion_level); | ||
| uint64_t pcap_cnt = PcapPacketCntGet(p->root); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds an additional check, once for PcapPacketCntRunmodeCanAccess then for the result of PcapPacketCntGet. Could be a nice micro optimization to do something like
if (PcapPacketCntRunmodeCanAccess()) {
pcap_cnt = PcapPacketCntGet ...
if (pcap_cnt != 0) {
...| /* pcap_cnt */ | ||
| if (p->pcap_cnt != 0) { | ||
| SCJbSetUint(js, "pcap_cnt", p->pcap_cnt); | ||
| uint64_t pcap_cnt = PcapPacketCntGet(p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same micro optimization opportunity here
victorjulien
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Minor comments inline, that can be addressed in a follow up post-merge.
|
Information: QA ran without warnings. Pipeline = 29241 |
|
Merged in #14673, thanks! |
Follow-up of #14656
Code refactoring to gather all PCAP-related structure members under one structure.
Link to ticket: https://redmine.openinfosecfoundation.org/issues/7835
Some considerations:
The PR has been previously OKAY-ed by Philippe (#13972 ).
Describe changes:
v5.2:
v5.1 (address copilot review comments):
v5:
v4.2
v4.1
v4
v2+3
v1