Skip to content

lib: matcher: make set ownership explicit - #627

Merged
qdeslandes merged 3 commits into
meta:mainfrom
qdeslandes:sets-ownership
Oct 30, 2026
Merged

qdeslandes merged 3 commits into
meta:mainfrom
qdeslandes:sets-ownership

Conversation

@qdeslandes

@qdeslandes qdeslandes commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Give named and anonymous sets distinct owners. Chains own their rules, and rules own their matchers.

Set kind Owner Matcher reference
Named The chain, through chain->sets A borrowed pointer to that chain's set, which multiple matchers can share
Anonymous The individual matcher An owned pointer to a private set created by the matcher constructor

Named-set references must point to the actual set object owned by the destination chain.

Anonymous sets have no generated names and are never inserted into chain->sets. A matcher frees its anonymous set when destroyed. The chain destroys its rules and matchers before freeing named sets, keeping borrowed pointers valid during cleanup.

Copying a matcher or rule deep-copies anonymous sets and preserves borrowed pointers to named sets. The named sets' owner must outlive those copies. Copying a complete chain also copies its named sets and rebinds the copied matchers to them.

Serialization stores named sets in the chain and their names in matchers. Loading resolves those names to pointers into the chain's set collection. Anonymous sets are serialized inside their matchers. Program generation collects sets from both owners when building BPF maps.

Related issue

N/A.

Testing

Full test suite passed.

Notes for the reviewer

Revert the anonymous-set naming change for a more consistent approach with a clear ownership model.

AI disclosure

AI assisted change, reviewed and owned by me.

Checklist

  • I understand every line in this PR and can explain why it is correct
  • I built the project and ran the tests covering this change
  • make -C $BUILD test_bin test passes and the code follows the style guide
  • Commits are formatted as component: subcomponent: short description
  • I have disclosed any AI usage above

Separate group insertion from set discovery so generation can collect
sets from more than one owner.
Set matchers currently copy only the set name. Adding a rule to a chain
can therefore make it use a different set with the same name.

Store a borrowed set pointer in each matcher. Reject rules that refer to
sets the chain does not own.

When loading a chain, look up each set name to get its pointer. When
copying a chain, point the copied matchers at the copied sets.
Let each matcher own its anonymous set and reserve chain collections
for named declarations. Construct anonymous sets inside matchers so
callers never transfer raw anonymous set pointers.

Serialize anonymous sets inside their matchers and deep-copy them when
copying a matcher. Collect named and anonymous sets during generation.
@qdeslandes
qdeslandes merged commit 6ceafec into meta:main Oct 30, 2026
38 checks passed
@qdeslandes
qdeslandes deleted the sets-ownership branch October 30, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant