-
Notifications
You must be signed in to change notification settings - Fork 52
Remove bpfilter daemon and consolidate every feature in libbpfilter #468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
78d24fb
af1b97b
3521acd
f330a4b
31553a8
ed7cc06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,20 @@ | ||
| ``bfcli`` | ||
| ========= | ||
|
|
||
| ``bfcli`` is a command line tool to communicate with the bpfilter daemon. | ||
| ``bfcli`` is the command line tool for defining and managing bpfilter filtering rules. It calls ``libbpfilter`` directly to generate, load, and manage BPF programs. | ||
|
|
||
| Environment variables | ||
| --------------------- | ||
|
|
||
| ``bfcli`` reads the following environment variables to configure the library before processing commands. These variables are ignored when ``--dry-run`` is used. | ||
|
|
||
| - ``BF_BPFFS_PATH``: path to the BPF filesystem directory. Defaults to ``/sys/fs/bpf``. bpfilter pins BPF objects under a ``bpfilter`` subdirectory at this path. | ||
| - ``BF_WITH_BPF_TOKEN``: if set (any value), associate a BPF token to every ``bpf()`` system call. Required when running in user namespaces. The token is created from the bpffs at ``BF_BPFFS_PATH``. Only supported for kernel v6.9+. | ||
| - ``BF_VERBOSE``: comma-separated list of verbose flags. Supported values: | ||
|
|
||
|
Comment on lines
+7
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 The documentation at lines 7-14 claims Extended reasoning...Bug DescriptionThe newly added "Environment variables" section in
However, there are zero Code Path Analysis
Why Tests Don’t Catch ThisThe e2e test helper ( export BF_BPFFS_PATH=${WORKDIR}/bpf
BFCLI="bfcli --bpffs-path ${BF_BPFFS_PATH}"Since Step-by-Step Proof
ImpactUsers following the official documentation will believe they can configure FixEither:
|
||
| - ``debug``: enable debug logs. | ||
| - ``bpf``: insert log messages into BPF programs to log failed kernel function calls. View with ``bpftool prog tracelog`` or ``cat /sys/kernel/debug/tracing/trace_pipe``. | ||
| - ``bytecode``: dump a program's bytecode before loading it. | ||
|
|
||
| Commands | ||
| -------- | ||
|
|
@@ -32,7 +45,7 @@ Chains with valid hook options defined are attached to their hook. Chains withou | |
| ``ruleset get`` | ||
| ~~~~~~~~~~~~~~~ | ||
|
|
||
| Print the ruleset: request all the chains and rules from the daemon with counters values. | ||
| Print the ruleset: request all the chains and rules with counters values. | ||
|
|
||
| **Example** | ||
|
|
||
|
|
@@ -49,7 +62,7 @@ Print the ruleset: request all the chains and rules from the daemon with counter | |
| ``ruleset flush`` | ||
| ~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Remove all the chains and rules defined by the daemon. Once this command completes, the daemon doesn't contain any filtering rules, as if it was freshly started. | ||
| Remove all the chains and rules. Once this command completes, bpfilter doesn't contain any filtering rules. | ||
|
|
||
| **Examples** | ||
|
|
||
|
|
@@ -69,14 +82,14 @@ Remove all the chains and rules defined by the daemon. Once this command complet | |
| ``chain set`` | ||
| ~~~~~~~~~~~~~ | ||
|
|
||
| Generate and load a chain into the kernel. If the chain definition contains hook options, the daemon will attach it to its hook. Any existing chain with the same name (attached or not) will be discarded and replaced with the new one. | ||
| Generate and load a chain into the kernel. If the chain definition contains hook options, bpfilter will attach it to its hook. Any existing chain with the same name (attached or not) will be discarded and replaced with the new one. | ||
|
|
||
| If you want to update an existing chain without downtime, use ``bfcli chain update`` instead. | ||
|
|
||
| **Options** | ||
| - ``--from-str CHAIN``: read the chain to set from the command line arguments. | ||
| - ``--from-file FILEPATH``: read the chain from a file. | ||
| - ``--name NAME``: if ``--from-str`` or ``--from-file`` provide multiple chains, ``NAME`` specify which one to send to the daemon. | ||
| - ``--name NAME``: if ``--from-str`` or ``--from-file`` provide multiple chains, ``NAME`` specifies which one to use. | ||
| - ``--dry-run``: parse and validate the chain, but do not apply it. | ||
|
|
||
| **Examples** | ||
|
|
@@ -158,7 +171,7 @@ If a chain with the same name already exist, it won't be replaced. See ``bfcli c | |
| **Options** | ||
| - ``--from-str CHAIN``: read the chain to set from the command line arguments. | ||
| - ``--from-file FILEPATH``: read the chain from a file. | ||
| - ``--name NAME``: if ``--from-str`` or ``--from-file`` provide multiple chains, ``NAME`` specify which one to send to the daemon. | ||
| - ``--name NAME``: if ``--from-str`` or ``--from-file`` provide multiple chains, ``NAME`` specifies which one to use. | ||
| - ``--dry-run``: parse and validate the chain, but do not apply it. | ||
|
|
||
| **Examples** | ||
|
|
@@ -213,7 +226,7 @@ If you want to modify the hook options, use ``bfcli chain set`` instead. | |
| **Options** | ||
| - ``--from-str CHAIN``: read the chain to set from the command line arguments. | ||
| - ``--from-file FILEPATH``: read the chain from a file. | ||
| - ``--name NAME``: if ``--from-str`` or ``--from-file`` provide multiple chains, ``NAME`` specify which one to send to the daemon. | ||
| - ``--name NAME``: if ``--from-str`` or ``--from-file`` provide multiple chains, ``NAME`` specifies which one to use. | ||
| - ``--dry-run``: parse and validate the chain, but do not apply it. | ||
|
|
||
| **Examples** | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,15 +6,12 @@ Usage | |
| :maxdepth: 2 | ||
| :caption: Usage | ||
|
|
||
| daemon | ||
| bfcli | ||
|
|
||
|
|
||
| ``bpfilter`` is composed of two main parts that work together: the client used by the users to define the filtering rules and send them to the **daemon** that performs the heavy lifting of generating the BPF bytecode. | ||
| ``bpfilter`` is composed of two main parts: ``libbpfilter``, the core library that generates and manages BPF programs, and ``bfcli``, the CLI used to define filtering rules. ``bfcli`` calls ``libbpfilter`` directly to translate rules into BPF programs and load them into the kernel. | ||
|
|
||
| Before anything, you will have to run the daemon on your system, see :doc:`daemon` for more details. | ||
|
|
||
| Then, use ``bfcli`` to create, update, or read chains. | ||
| See :doc:`bfcli` for the full command reference and filter syntax. | ||
|
|
||
| Install | ||
| ------- | ||
|
|
@@ -31,7 +28,7 @@ If you use a different distribution, you can still build and use **bpfilter** if | |
| Example usage | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Documentation bug: Extended reasoning...What the bug isIn The specific code pathThe install destination for Step-by-step proof
Why existing code does not prevent thisThis is a documentation-only issue. There is no automated check that verifies documentation paths match actual CMake install destinations. ImpactUsers who follow the usage guide to run a locally-built FixChange |
||
| ------------- | ||
|
|
||
| From here on, we assume **bpfilter** has been installed on your system. If you build it locally, you will need to substitute the ``bpfilter`` command with ``$BUILD_DIR/output/sbin/bpfilter``, same for ``bfcli``. The example below is meant to familiarize you with **bpfilter**, more in-depth information can be found throughout the documentation. | ||
| From here on, we assume **bpfilter** has been installed on your system. If you build it locally, you will need to substitute the ``bfcli`` command with ``$BUILD_DIR/output/bin/bfcli``. The example below is meant to familiarize you with **bpfilter**, more in-depth information can be found throughout the documentation. | ||
|
|
||
| This example will block ``ping`` requests sent going out of the local host to a remote server. | ||
|
|
||
|
|
@@ -53,19 +50,9 @@ Let's check if we can ping ``facebook.com`` before we do anything: | |
| rtt min/avg/max/mdev = 23.596/25.493/28.622/1.880 ms | ||
|
|
||
|
|
||
| **Start the daemon** | ||
|
|
||
| The daemon is responsible for receiving the user-defined filtering rules, and translating them into BPF programs. We will start it in ``--transient`` mode, so all the filtering programs defined will be discarded when we stop it, preventing any mistake on our side! | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ sudo bpfilter --transient | ||
| info : waiting for requests... | ||
|
|
||
|
|
||
| **Create a new filtering rule** | ||
|
|
||
| Now that the daemon is up and running, we will use ``bfcli`` to send a filtering chain. A chain is a set of rules to filter packets on: | ||
| Use ``bfcli`` to create a filtering chain. A chain is a set of rules to filter packets on: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 CLAUDE.md directory tree has two issues:
xlate.con line 22 no longer exists (it was part of the deletedsrc/bpfilter/daemon code) and should be removed, and line 23 (bpf/) uses└──but should use├──since*.cfollows at the same level. Both are minor documentation inaccuracies introduced by this PR.Extended reasoning...
Bug Description
The CLAUDE.md directory tree listing for
src/libbpfilter/contains two documentation errors introduced by this PR's changes.Issue 1: Stale
xlate.creference (line 22)Line 22 of CLAUDE.md lists
xlate.cundersrc/libbpfilter/:However,
xlate.cwas part ofsrc/bpfilter/(the daemon directory that this PR removes). The rule translation functionality was rewritten intosrc/libbpfilter/cli.cas part of this PR. Sincexlate.cdoes not exist undersrc/libbpfilter/, this line should be removed entirely.Issue 2: Duplicate last-child tree markers (lines 23-24)
Lines 23-24 both use the
└──(last-child) marker at the same indentation level:In standard ASCII tree notation,
└──means "last child at this level." Sincebpf/is not the last entry (it is followed by*.c), line 23 should use├──instead. The correct tree after removingxlate.cwould be:Step-by-step proof
│ ├── xlate.c # Rule translation— this file does not exist undersrc/libbpfilter/. It was insrc/bpfilter/which was deleted.│ └── bpf/— uses└──but*.cfollows on line 24 at the same level, so├──is correct.│ └── *.c— correctly uses└──as the actual last child.Impact
These are documentation-only issues with no functional impact. The directory tree in CLAUDE.md will be slightly misleading to developers trying to understand the project structure, but it does not affect builds, tests, or runtime behavior.
Fix
Remove line 22 (
xlate.c) and change line 23 from└──to├──for thebpf/entry.