-
-
Notifications
You must be signed in to change notification settings - Fork 198
pwru: Add --filter-skb-expr and --filter-xdp-expr #499
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
base: main
Are you sure you want to change the base?
Conversation
aa80c7c
to
ab85e03
Compare
I like it, it's also the on the roadmap, thank you. |
if this goes stable, we can deprecate --filter-mark --filter-netns --filter-ifname in favor of |
ab85e03
to
050c492
Compare
The RFC makes sense to me. Could we use
How does the filter look like for |
Sure. I will add some tests if I have time for it.
|
It's to avoid such verifier error: ```log ; set_xdp_metadata(xdp, xdp_metadata); 642: (bf) r1 = r10 ; R1_w=fp0 R10=fp0 ; u64 xdp_metadata[4] = {}; 643: (07) r1 += -288 ; R1_w=fp-288 ; __builtin_memcpy(event->skb_metadata, xdp_metadata, sizeof(xdp_metadata)); 644: (79) r2 = *(u64 *)(r10 -40) ; R2_w=ptr_xdp_buff() R10=fp0 fp-40_w=ptr_xdp_buff() 645: (bf) r3 = r2 ; R2_w=ptr_xdp_buff() R3_w=ptr_xdp_buff() 646: (77) r3 >>= 56 R3 pointer arithmetic with >>= operator prohibited ``` It's because `xdp_metadata[0] = xdp` and `xdp` is not allowed to do `>>= 56`. Signed-off-by: Leon Hwang <[email protected]>
Like `--output-skb-metadata` and `--output-xdp-metadata`, implement `--filter-skb-expr` and `--filter-xdp-expr` using `github.com/leonhwangprojects/bice` library. Because the limit of `bice` library, the expr must have three limited parts, left part, operand and right part. 1. left part: limit like `--output-skb-metadata`. 2. operand: must be one of `=, ==, !=, <, <=, >, >=`, and '=' equals to '=='. 3. right part: a number or the enum value for the left part. Signed-off-by: Leon Hwang <[email protected]>
050c492
to
6d4f324
Compare
I will review it next week once I am back from holidays. |
Fixes #11
I'm porting such feature from bpfsnoop's
--filter-arg 'skb->dev->ifindex == 11'
.The following message is valid even though it was wrote for the original draft PR.
If we want to filter some info dynamically like 'skb->dev->ifindex == 11', it is better to compile the simple C expression to bpf instructions directly.
In order to achieve it, we can:
bpf_probe_read_kernel()
based on converted offsets.As a result, add
--filter-skb-expr
to filter skb dynamically, and add--filter-xdp-expr
to filter xdp dynamically.For examples, the jited insns of
--filter-skb-expr 'skb->dev->ifindex == 11'
isThe jited insns of
--filter-xdp-expr 'xdp->rxq->dev->ifindex == 9'
is