Add NEXT verdict for BPF program chaining#474
Open
qdeslandes wants to merge 6 commits intofacebook:mainfrom
Open
Add NEXT verdict for BPF program chaining#474qdeslandes wants to merge 6 commits intofacebook:mainfrom
qdeslandes wants to merge 6 commits intofacebook:mainfrom
Conversation
Claude review of PR #474 (982fc4e)Must fix
Suggestions
Nits
|
6f87be7 to
c6df7a7
Compare
c6df7a7 to
6edf970
Compare
6edf970 to
b5166ab
Compare
b5166ab to
dc6e84c
Compare
The get_verdict flavor callback returns the BPF return code directly, using negative values for errors. This will conflict with TCX_NEXT (-1) when adding the NEXT verdict. Switch to an output parameter so that the return value is reserved for error reporting. No functional change.
Add a new terminal verdict BF_VERDICT_NEXT that means "pass to next BPF program." For TC this will map to TCX_NEXT; for other flavors it maps to the same return code as ACCEPT. Replace the _BF_TERMINAL_VERDICT_MAX sentinel with an explicit bf_verdict_is_valid_policy() function, which is easier to reason about and extend. Update chain creation and the CLI parser to use it. Add NEXT to the lexer so it is recognised as a verdict token.
Map BF_VERDICT_NEXT to flavor-specific return codes: - TC: TCX_NEXT (-1), distinct from TCX_PASS - Netfilter: NF_ACCEPT (same as ACCEPT) - XDP: XDP_PASS (same as ACCEPT) - cgroup_skb: 1 (same as ACCEPT) Handle NEXT as a terminal verdict in rule codegen, alongside ACCEPT and DROP.
Update bfcli usage documentation to describe the NEXT verdict for both chain policies and rule verdicts. Note that NEXT has distinct behavior only for TC hooks (TCX_NEXT); for NF, XDP, and cgroup_skb it maps to the same return code as ACCEPT.
dc6e84c to
982fc4e
Compare
jordalgo
reviewed
Mar 18, 2026
|
|
||
| - ``ACCEPT``: forward the packet to the kernel. | ||
| - ``DROP``: discard the packet. | ||
| - ``NEXT``: pass the packet to the next BPF program. For TC hooks, this maps to ``TCX_NEXT``, deferring the decision to the next program in the TCX link. For NF, XDP, and cgroup_skb hooks, ``NEXT`` behaves identically to ``ACCEPT`` since these hooks do not distinguish between "accept" and "pass to next program." |
There was a problem hiding this comment.
Do you want to call out that if there are no other BPF programs then this acts like ACCEPT?
| - ``counter``: optional literal. If set, the filter will counter the number of packets and bytes matched by the rule. | ||
| - ``mark``: optional, ``$MARK`` must be a valid decimal or hexadecimal 32-bits value. If set, write the packet's marker value. This marker can be used later on in a rule (see ``meta.mark``) or with a TC filter. | ||
| - ``$VERDICT``: action taken by the rule if the packet is matched against **all** the criteria: either ``ACCEPT``, ``DROP``, ``CONTINUE``, or ``REDIRECT``. | ||
| - ``$VERDICT``: action taken by the rule if the packet is matched against **all** the criteria: either ``ACCEPT``, ``DROP``, ``CONTINUE``, ``NEXT``, or ``REDIRECT``. |
There was a problem hiding this comment.
nit:
Suggested change
| - ``$VERDICT``: action taken by the rule if the packet is matched against **all** the criteria: either ``ACCEPT``, ``DROP``, ``CONTINUE``, ``NEXT``, or ``REDIRECT``. | |
| - ``$VERDICT``: action taken by the rule if the packet is matched against **all** the criteria. One of the following: |
Not sure why you want to list the verdicts and then list them again with descriptions
|
|
||
| .. note:: | ||
|
|
||
| ``NEXT`` has distinct behavior only for TC hooks (``BF_HOOK_TC_INGRESS``, ``BF_HOOK_TC_EGRESS``), where it maps to ``TCX_NEXT`` and defers to the next BPF program in the TCX link. For all other hooks (Netfilter, XDP, cgroup_skb), ``NEXT`` produces the same return code as ``ACCEPT``. |
There was a problem hiding this comment.
nit
Suggested change
| ``NEXT`` has distinct behavior only for TC hooks (``BF_HOOK_TC_INGRESS``, ``BF_HOOK_TC_EGRESS``), where it maps to ``TCX_NEXT`` and defers to the next BPF program in the TCX link. For all other hooks (Netfilter, XDP, cgroup_skb), ``NEXT`` produces the same return code as ``ACCEPT``. | |
| ``NEXT`` has distinct behavior only for TC hooks (``BF_HOOK_TC_INGRESS``, ``BF_HOOK_TC_EGRESS``), where it maps to ``TCX_NEXT`` and defers to the next BPF program in the TCX link. For all other hooks (Netfilter, XDP, cgroup_skb), ``NEXT`` is equivalent to ``ACCEPT``. |
| * @return 0 on success, or a negative errno value on failure. | ||
| */ | ||
| static int _bf_cgroup_skb_get_verdict(enum bf_verdict verdict) | ||
| static int _bf_cgroup_skb_get_verdict(enum bf_verdict verdict, int *ret_code) |
There was a problem hiding this comment.
Since these are internal APIs, I think you could have kept the same return mechanism without adding the ret_code param and just check for -ENOTSUP on the caller. Obviously a matter of style but less changes.
| case BF_VERDICT_DROP: | ||
| case BF_VERDICT_NEXT: | ||
| return true; | ||
| default: |
There was a problem hiding this comment.
As mentioned on another diff, it would be nice if this is an exhaustive check instead of using default
jordalgo
pushed a commit
to jordalgo/bpftrace
that referenced
this pull request
Mar 18, 2026
Integrates Claude Code as an AI assistant for reviewing pull requests. This is experimental and relies on a subscription provided by Meta. Example of what this review looks like: facebook/bpfilter#474 (comment) Signed-off-by: Jordan Rome <linux@jordanrome.com>
3 tasks
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.
Add a new BF_VERDICT_NEXT terminal verdict, meaning "pass to the next BPF program.".
On TC, this maps to TCX_NEXT which defers packet processing to the next program in the TCX link, distinct from TCX_PASS which accepts the packet and bypasses subsequent programs.
For NF, XDP, and cgroup_skb, NEXT maps to the same return code as ACCEPT since these hooks don't distinguish between the two.