Allow users to name and reuse sets#314
Merged
Merged
Conversation
Add a name field to bf_set, so users can define named sets. Subsequent commits will use this feature to reuse pre-defined set more than once in a ruleset.
Add grammar and logic to allow users to name his sets and refer to them later on in a rule. This change allows sets to be reused in multiple rules.
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for named sets in bpfilter, allowing users to define reusable sets at the chain level and reference them in multiple rules. Previously, sets were anonymous and defined inline within individual rules, leading to duplication when the same set was needed across multiple rules.
Key changes include:
- Adding a
namefield to thebf_setstructure to support named sets - Updating set creation functions to accept an optional name parameter
- Extending the parser to handle named set declarations and references
- Adding comprehensive test coverage for the new named set functionality
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/core/set.h | Adds name field to bf_set structure and updates function signatures |
| src/core/set.c | Implements named set functionality with memory management for set names |
| src/bfcli/parser.y | Adds grammar rules for named set declarations and references |
| src/bfcli/lexer.l | Updates lexer to handle 'set' keyword and improved whitespace handling |
| src/bfcli/print.c | Adds printing support for named sets in ruleset output |
| tests/unit/core/set.c | Updates all test calls to use new function signatures |
| tests/harness/filters.c | Updates test helper to use new bf_set_new signature |
| tests/e2e/cli.sh | Adds comprehensive end-to-end tests for named set functionality |
| tests/rules.bpfilter | Adds example usage of named sets in test ruleset |
| doc/usage/bfcli.rst | Documents the new named set syntax and usage |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, users can use sets to efficiently filter packets against a large pool of similarly formatted data. Sets are defined as part of a rule, and can't be reused for other rules. If a user wants to filter on the same 10k elements sets in 2 different rules, bpfilter will create the set twice.
This change adds a new syntax to allow users to create named sets at the beginning of a chain, then filter on it in a rule using its name: