Skip to content

Conversation

oferda4
Copy link

@oferda4 oferda4 commented Sep 25, 2025

Make sure these boxes are checked accordingly before submitting your Pull Request -- thank you.

Contribution style:

Our Contribution agreements:

Changes (if applicable):

Describe changes:
Allowing change the behaviour of --pcap-file-delete to only delete pcaps with no alerts via config.

Previous PR: #13896
Changes:

  • Support more cases - only stream, timeout, pseudo

Provide values to any of the below to override the defaults.

  • To use a Suricata-Verify or Suricata-Update pull request,
    link to the pull request in the respective _BRANCH variable.
  • Leave unused overrides blank or remove.

SV_BRANCH=OISF/suricata-verify#2664

Refactor pcap file deletion to use a single delete-when-done option
with three values instead of separate boolean options:
- false (default): No deletion
- true: Always delete files
- "non-alerts": Delete only files with no alerts

Key changes:
- Replace should_delete/delete_non_alerts_only bools with enum
- Move alert counter from global to per-file PcapFileFileVars
- Relocate alert counting from PacketAlertFinalize to pcap module
- Ensure thread safety for both single and continuous pcap modes
- Add comprehensive unit tests for configuration parsing

The --pcap-file-delete command line option overrides YAML config
and forces "always delete" mode for backward compatibility.

Documentation updated to reflect new three-value configuration.

Fixes OISF#7786
Copy link

NOTE: This PR may contain new authors.

Copy link
Member

@victorjulien victorjulien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture method specific logic should not bleed all over the the generic code base. This needs a complete redesign.

* only or pseudo-packet alerts. */
if (p->alerts.cnt > 0) {
/* Best-effort attribute to current pcap file if not already set */
if (p->pcap_v.pfv == NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is invalid - pcap_v is part of a union so the value of pfv is undefined or invalid when other capture methods are in use

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part of the code should not be aware of any capture method

perhaps we need a callback mechanism of sorts to avoid calling the pcap specific code here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this not just move into PcapFileFinalizePacket?

p->payload = NULL;
p->payload_len = 0;

/* In pcap-file mode, associate pseudo end-of-flow packets with the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too we need to keep pcap specific logic out of generic code

}
PKT_SET_SRC(np, PKT_SRC_STREAM_TCP_DETECTLOG_FLUSH);

/* In pcap-file mode, propagate the per-file context so that alerts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stream engine should not be aware of the capture method here

if (p != NULL) {
p->flags |= PKT_PSEUDO_STREAM_END;
PKT_SET_SRC(p, PKT_SRC_CAPTURE_TIMEOUT);
/* In pcap-file mode, attach current pfv so alerts can be counted */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be aware of the capture method

@oferda4
Copy link
Author

oferda4 commented Sep 30, 2025

Thank you for the review! I will try a different approach that won't get capture specific knowledge to the generic code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants