Skip to content

chore(refactor): collapse conntrack into packetparser#2251

Draft
nddq wants to merge 1 commit into
mainfrom
refactor/conntrack-into-packetparser
Draft

chore(refactor): collapse conntrack into packetparser#2251
nddq wants to merge 1 commit into
mainfrom
refactor/conntrack-into-packetparser

Conversation

@nddq
Copy link
Copy Markdown
Member

@nddq nddq commented Apr 27, 2026

Description

pkg/plugin/conntrack/ lived under pkg/plugin/ but was never actually a plugin — it didn't implement the plugin interface, didn't self-register in include_linux.go, and its only real consumers were packetparser (which #included conntrack's C code directly) and a GC loop that pluginmanager launched iff packetparser was enabled. The arrangement obscured the fact that conntrack is a component of packetparser.

This PR collapses conntrack into the packetparser package so the relationship is explicit.

  • C: Merge _cprog/conntrack.c into _cprog/conntrack.h and move it into packetparser's _cprog/. packetparser.c now includes conntrack.h once (previously included both .c and .h). Drop the separate bpf2go target — packetparser.o owns the retina_conntrack map via LIBBPF_PIN_BY_NAME.
  • Go: Move the userspace GC loop into pkg/plugin/packetparser/conntrack_linux.go as a free function. packetParser.Start() launches it; it operates on p.objs.RetinaConntrack directly (no more ebpf.LoadPinnedMap).
  • Init path: Add packetparser.InitConntrackMap() for the init container to pre-create and pin the map from packetparser's generated spec. The agent container isn't privileged enough to pin new maps, so the pin must already exist when packetparser.o is loaded in the agent container.
  • Pluginmanager: Drop the pluginNamePacketparser special case and the associated conntrack.New/Run block — packetparser owns its own lifecycle now.
  • Tests: packetparser_ebpf_test.go drops the separate conntrack dynamic.h write and the -I../conntrack/_cprog/ include.

Related Issue

N/A

Checklist

  • I have read the contributing documentation.
  • I signed and signed-off the commits (git commit -S -s ...). See this documentation on signing commits.
  • I have correctly attributed the author(s) of the code.
  • I have tested the changes locally.
  • I have followed the project's style guidelines.
  • I have updated the documentation, if necessary (no user-facing changes).
  • I have added tests, if applicable (pure refactor — existing tests cover behavior).

Screenshots (if applicable) or Testing Completed

Additional Notes

Conntrack wasn't a plugin — it never implemented the plugin interface
or self-registered, and its only real consumers were packetparser and
a GC loop that ran iff packetparser was enabled. Move it into the
packetparser package so the relationship is explicit.

- Merge _cprog/conntrack.c into _cprog/conntrack.h; packetparser.c
  includes it directly and packetparser.o now owns the
  retina_conntrack map via LIBBPF_PIN_BY_NAME. Drop the separate
  bpf2go target.
- Move the userspace GC loop into packetparser as a free function;
  packetParser.Start() launches it.
- Add packetparser.InitConntrackMap() for the init container to
  pre-create and pin the map from packetparser's generated spec.
  The agent container isn't privileged enough to pin new maps, so
  the pin must already exist when packetparser.o is loaded.
- Drop the packetparser-enabled special case from pluginmanager —
  packetparser owns its own conntrack lifecycle now.

Signed-off-by: Quang Nguyen <nguyenquang@microsoft.com>
@nddq nddq force-pushed the refactor/conntrack-into-packetparser branch from e18a24e to f1ee412 Compare April 27, 2026 13:28
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