Skip to content

calicovppctl: add BPF filtering support to trace/pcap/dispatch commands#859

Merged
sknat merged 2 commits intomasterfrom
abasu-filter
Jan 29, 2026
Merged

calicovppctl: add BPF filtering support to trace/pcap/dispatch commands#859
sknat merged 2 commits intomasterfrom
abasu-filter

Conversation

@aritrbas
Copy link
Collaborator

@aritrbas aritrbas commented Dec 19, 2025

This PR has 2 commits:

  • The first commit adds BPF filtering support to calicovppctl trace, pcap and dispatch commands:

    • New CLI flags have been added - -srcip, -dstip, -srcport, -dstport and -protocol
    • Empty capture files are now handled gracefully
  • The second commit adds concurrency and cleanup enhancements to calicovppctl:

    • Capture operations (trace/pcap/dispatch) are serialized per VPP pod using an in-pod lock file (/tmp/calicovppctl.lock), preventing parallel captures from multiple clients with error messages.
    • Forced cleanup option (calicovppctl capture clear -node <node>) has been added to deal with situations when a capture fails midway due to different scenarios such as the process being killed with SIGKILL, network disconnects during kubectl exec, system crash or container restart and abrupt terminal closure while a capture is underway. This clears traces, stops pcap trace and pcap dispatch trace, clears BPF filters and restores default filter functions and removes hanging in-pod lock file.

@aritrbas aritrbas changed the title added BPF filtering support to calicovppctl trace/pcap/dispatch commands calicovppctl: add BPF filtering support to trace/pcap/dispatch commands Dec 19, 2025
@aritrbas aritrbas self-assigned this Dec 22, 2025
Copy link
Collaborator

@sknat sknat left a comment

Choose a reason for hiding this comment

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

thanks a lot for putting this together ! Looks neat 😄
I have a bit of a concern on this feature of the caller erroring while running the CLI and failing cleanup. This was probably fine for trace / pcap / dispatch but BPF filter is going to impact performance

useBPF = true
defer func() {
printColored("blue", "Clearing BPF filter...")
err := clearBPFFilter(k, validatedNode, true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am a bit worried of us running into an nondeterministic state
if we fail to run the cleanup function.

Could we look at adding an http server that would provide a backend for BPF filters ?
this CLI would then call something like

kubectl exec -it xxxx -c agent -- curl localhost:9999/api/bpftrace?key=value

The backend could then handle timeouts (if for some reason the caller disconnects) and user conflicts (e.g. two users calling at the same time)

Finally the backend could rely on the binary API, which is expectedly more stable than the CLI

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ack, will work on it.

Copy link
Collaborator Author

@aritrbas aritrbas Jan 8, 2026

Choose a reason for hiding this comment

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

Since adding an HTTP server to the agent will involve creating a new image, have come up with an alternate solution in the second commit to add concurrency and cleanup enhancements:

  • Capture operations (trace/pcap/dispatch) are serialized per VPP pod using an in-pod lock file (/tmp/calicovppctl.lock).
  • Forced cleanup option (calicovppctl capture clear -node <node>) has been added to deal with situations when a capture fails midway to clear traces, stop pcap trace and pcap dispatch trace, clear BPF filters and restore default filter functions and remove hanging in-pod lock file to restore the VPP instance to a clean state.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome ! Thanks a bunch !

@aritrbas aritrbas force-pushed the abasu-filter branch 2 times, most recently from 10449e0 to fed6073 Compare January 8, 2026 19:11
@sknat sknat requested a review from hedibouattour January 9, 2026 10:34
@aritrbas aritrbas requested a review from onong January 14, 2026 07:44
Aritra Basu added 2 commits January 27, 2026 18:40
- Add CLI flags: -srcip, -dstip, -srcport, -dstport, -protocol
- Implement BPF filter building and application using VPP CLI
- Handle empty capture files gracefully
- Support BPF filtering for trace, pcap, and dispatch commands

Signed-off-by: Aritra Basu <aritrbas@cisco.com>
- Serialize capture operations (trace/pcap/dispatch) per VPP pod
  using an in-pod lock file (/tmp/calicovppctl.lock), preventing
  parallel captures from multiple clients
- Provide clear error output when a capture is already running
- Add forced cleanup option: `calicovppctl capture clear -node <node>`
  - clears trace
  - stops `pcap trace` and `pcap dispatch trace`
  - clears BPF filters and restores default filter functions
  - removes hanging in-pod lock file

Signed-off-by: Aritra Basu <aritrbas@cisco.com>
Copy link
Collaborator

@sknat sknat left a comment

Choose a reason for hiding this comment

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

looks neat, thanks a lot, this will be super useful !

useBPF = true
defer func() {
printColored("blue", "Clearing BPF filter...")
err := clearBPFFilter(k, validatedNode, true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome ! Thanks a bunch !

@sknat sknat merged commit 16546c1 into master Jan 29, 2026
5 checks passed
@sknat sknat deleted the abasu-filter branch January 29, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants