Skip to content
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

[RFC] pwru: Support --output-skb-metadata #509

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Asphaltt
Copy link
Contributor

Fixes #502

I'm porting such feature from btrace's --output-arg 'skb->hash'.


It's really useful to output specified metadatas of skb instead of outputing the whole skb btf data.

However, it's not easy to --output-skb-metadata 'skb->mark' because the metadata is provided by users.

Here're the steps to achieve it:

  1. Parse the text to C AST.
  2. Convert the C AST to bpf insns with skb btf type info.
  3. Inject the set_skb_metadata stub with the generated insns.
  4. Output the metadata with the provided field's btf type info.

e.g.

$ sudo ./pwru --filter-func 'icmp_rcv' --output-skb-metadata 'skb->hash' --output-skb-metadata 'skb->sw_hash' --output-skb-metadata 'skb->l4_hash' --output-skb-metadata 'skb->mark' host 1.1.1.1
2025/03/19 16:27:18 Attaching kprobes (via kprobe-multi)...
1 / 1 [----------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s
2025/03/19 16:27:18 Attached (ignored 0)
2025/03/19 16:27:18 Listening for events..
SKB                CPU PROCESS          NETNS      MARK/x        IFACE       PROTO  MTU   LEN   TUPLE FUNC
0xffff991f3ec49600 6   <empty>:0        4026531840 0            ens33:2      0x0800 65536 64    1.1.1.1:0->192.168.241.133:0(icmp) icmp_rcv hash=0 sw_hash=0 l4_hash=0 mark=0
^C2025/03/19 16:32:56 Received signal, exiting program..
2025/03/19 16:32:56 Detaching kprobes...
1 / 1 [----------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s

@Asphaltt Asphaltt force-pushed the feature/output-skb-meta branch from 126daa9 to 565250b Compare March 20, 2025 12:33
It's really useful to output specified metadatas of skb instead of
outputing the whole skb btf data.

However, it's not easy to `--output-skb-metadata 'skb->mark'` because
the metadata is provided by users.

Here're the steps to achieve it:

1. Parse the text to C AST.
2. Convert the C AST to bpf insns with `skb` btf type info.
3. Inject the `set_skb_metadata` stub with the generated insns.
4. Output the metadata with the provided field's btf type info.

e.g.

```bash
$ sudo ./pwru --filter-func 'icmp_rcv' --output-skb-metadata 'skb->hash' --output-skb-metadata 'skb->sw_hash' --output-skb-metadata 'skb->l4_hash' --output-skb-metadata 'skb->mark' host 1.1.1.1
2025/03/19 16:27:18 Attaching kprobes (via kprobe-multi)...
1 / 1 [----------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s
2025/03/19 16:27:18 Attached (ignored 0)
2025/03/19 16:27:18 Listening for events..
SKB                CPU PROCESS          NETNS      MARK/x        IFACE       PROTO  MTU   LEN   TUPLE FUNC
0xffff991f3ec49600 6   <empty>:0        4026531840 0            ens33:2      0x0800 65536 64    1.1.1.1:0->192.168.241.133:0(icmp) icmp_rcv hash=0 sw_hash=0 l4_hash=0 mark=0
^C2025/03/19 16:32:56 Received signal, exiting program..
2025/03/19 16:32:56 Detaching kprobes...
1 / 1 [----------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s
```

Signed-off-by: Leon Hwang <[email protected]>
@Asphaltt Asphaltt force-pushed the feature/output-skb-meta branch from 565250b to e97a6da Compare March 20, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support dumping skb hash
1 participant