feat(bpf): implement allow_port program#42
Open
leodido wants to merge 4 commits intofeat/allow-ipfrom
Open
Conversation
allow_port program
fntlnz
reviewed
Apr 30, 2026
| return TC_ACT_OK; | ||
| } | ||
|
|
||
| if (ip_is_fragment(skb, l3_offset)) |
fntlnz
reviewed
Apr 30, 2026
| } | ||
|
|
||
| struct iphdr *ip_header = data + l3_offset; | ||
| const int l4_offset = l3_offset + sizeof(*ip_header); |
Collaborator
There was a problem hiding this comment.
I think that we should use the ihl field of the packet here instead of the fixed struct size
| if (data + l4_offset + 4 > data_end) | ||
| { | ||
| bpf_printk("allow_port: [l4] size length check hit: continue"); | ||
| return TC_ACT_OK; |
Allowlist-mode BPF program that drops all TCP/UDP packets except those with destination port equal to the input port number. Non-TCP/UDP protocols (ICMP, etc.) pass through unaffected. Co-authored-by: Ona <no-reply@ona.com>
CLI functional: allows specific port, blocks other ports, does not block ICMP. CLI flags: missing input, invalid port. CNI functional: allow_port via JSON config. CNI flags: missing input rejected. 7 new tests (43 total). Co-authored-by: Ona <no-reply@ona.com>
Co-authored-by: Ona <no-reply@ona.com>
…ary checks - Use IHL field for dynamic IP header length instead of fixed sizeof(iphdr) - Validate IHL >= 5 and bounds-check the full IP header - Drop subsequent fragments (no L4 headers to verify) - Fail-closed (TC_ACT_SHOT) on all boundary check failures - Document passthroughs: non-IPv4 and non-TCP/UDP traffic passes through Co-authored-by: Ona <no-reply@ona.com>
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.
Description
Allowlist-mode BPF program that drops all TCP/UDP packets except those with destination port equal to the input port number. Non-TCP/UDP protocols (ICMP, etc.) pass through unaffected.
This is the inverse of
block_port: instead of blocking one port, it allows only one port and drops all other TCP/UDP traffic. Intended for agent quarantine scenarios where an agent should only communicate on a specific proxy port.Depends on #41 (
allow_ip).Commits
feat(bpf): implement allow_port program— BPF program,api.luaregistration,input_parse.hwiringtest(bpf): add allow_port tests— 7 new tests (43 total)docs: add allow_port to built-in programs— README.txt, docs/README.mdHow to test
xmake clean -a xmake f --generate-vmlinux=y xmake sudo XMAKE_ROOT=y xmake run testAll 43 tests pass (36 from PR #41 + 7 new).