Skip to content

fix: load eBPF counters again, count with TC only and skip lo - #172

Merged
beneiltis merged 1 commit into
mainfrom
fix/ebpf-load-tc-only
Nov 13, 2026
Merged

beneiltis merged 1 commit into
mainfrom
fix/ebpf-load-tc-only

Conversation

@beneiltis

Copy link
Copy Markdown
Contributor

Problem

Since v0.4.0 (2026-07-03) snoopy loads no eBPF program at all. aya_log::EbpfLogger::init_with_logger returns the logger that owns the AYA_LOGS ring buffer; snoopy dropped it right away, which closed the map fd that every program references. Every BPF_PROG_LOAD then fails with EBADF (seen with strace on kernel 6.8). The attach results were discarded via .is_ok(), so every interface reported ingress_implementation: none / egress_implementation: none and the operator silently fell back to /proc/net/dev.

Checked with the release binaries in an isolated netns: v0.3.12 attaches, v0.4.0, v0.4.37 and v0.4.38 do not.

Simply keeping the logger alive would bring back what v0.3.12 did: XDP on the pod's veth, which clears TSO on its peer (tx-tcp-segmentation: off [fixed], verified), and generic XDP on lo. That costs the workloads, not snoopy. So this PR fixes the load and the attach strategy together.

Changes

  • No aya-log: removed from the eBPF program and userspace. The only error path was a lookup of index 0 in a 1-entry array, and each loaded object paid a 128 KiB ring buffer for it.
  • TC only: ingress uses the classifier instead of XDP; the XDP program is gone.
  • Skip lo: --exclude-interface (repeatable), defaults to lo. The operator never reported loopback traffic.
  • Visible errors: attach errors are logged; if both directions fail, InterfaceBpfInitializationFailed is emitted so the operator sees it.
  • Graceful shutdown: SIGTERM/SIGINT detaches the programs. On kernels without tcx (<6.6) netlink TC filters outlive a killed process.
  • Egress byte count: ctx.len() (skb->len) instead of data_end - data, which only covered the linear head of GSO packets.

Verification (homeserver, kernel 6.8, isolated netns)

  • 2 programs loaded per veth, none on lo, no XDP, peer keeps tx-tcp-segmentation: on
  • 50 pings × 1000 B → ~52 KB counted in both directions
  • SIGTERM → shutting down, detaching 1 ebpf module(s), no programs left
  • 60 instances with 2 veths each: 10.3 MB PSS / 240 programs vs v0.3.12 58.3 MB / 360 programs
  • cargo fmt --check, cargo clippy --release, cargo test clean

The operator side (one snoopy per pod, SIGTERM, eBPF-attached tracking) is in mogenius/mogenius-operator branch perf/node-metrics-snoopy-per-pod; it works with both the old and the new snoopy.

🤖 Generated with Claude Code

Since v0.4.0 no eBPF program loaded anywhere: the EbpfLogger returned by
aya_log::EbpfLogger::init_with_logger was dropped right away, which closed
the AYA_LOGS ring buffer that every program references, so each
BPF_PROG_LOAD failed with EBADF. The attach results were discarded with
`.is_ok()`, so every interface reported `none` and the operator silently
fell back to /proc/net/dev.

- drop aya-log from the eBPF program and userspace: the only error path
  was a lookup of index 0 in a 1-entry array, and each loaded object
  paid a 128 KiB ring buffer for it
- count ingress with a TC classifier instead of XDP: an XDP program on a
  veth clears TSO on its peer (`tx-tcp-segmentation: off [fixed]`) and on
  lo it ran as generic XDP on every loopback packet
- skip lo by default (`--exclude-interface`, repeatable)
- report attach errors; if both directions fail, emit
  InterfaceBpfInitializationFailed
- detach on SIGTERM/SIGINT instead of dying with programs left attached
  (netlink TC filters outlive the process on kernels without tcx)
- count egress with skb->len instead of the linear head only

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@beneiltis
beneiltis merged commit 0d96658 into main Nov 13, 2026
2 checks passed
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.

1 participant