Skip to content

Commit

Permalink
Trace veth_convert_skb_to_xdp_buff using skb->head
Browse files Browse the repository at this point in the history
After #339, skb_addresses (now
skb_heads) map uses skb->head as key rather than &skb. Kprobe prog on
veth_convert_skb_to_xdp_buff should be adjusted to that change.

Signed-off-by: gray <gray.liang@isovalent.com>
  • Loading branch information
jschwinger233 authored and brb committed Jul 10, 2024
1 parent 5699a37 commit cf5229b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions bpf/kprobe_pwru.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,24 +695,26 @@ int BPF_PROG(fentry_xdp, struct xdp_buff *xdp) {

SEC("kprobe/veth_convert_skb_to_xdp_buff")
int kprobe_veth_convert_skb_to_xdp_buff(struct pt_regs *ctx) {
struct sk_buff **skb = (struct sk_buff **)PT_REGS_PARM3(ctx);
u64 skb_addr;
bpf_probe_read_kernel(&skb_addr, sizeof(skb_addr), (void *)skb);
if (bpf_map_lookup_elem(&skb_heads, &skb_addr)) {
struct sk_buff **pskb = (struct sk_buff **)PT_REGS_PARM3(ctx);
struct sk_buff *skb;
bpf_probe_read_kernel(&skb, sizeof(skb), (void *)pskb);
u64 skb_head = (u64) BPF_CORE_READ(skb, head);
if (bpf_map_lookup_elem(&skb_heads, &skb_head)) {
u64 pid_tgid = bpf_get_current_pid_tgid();
bpf_map_update_elem(&veth_skbs, &pid_tgid, &skb, BPF_ANY);
bpf_map_update_elem(&veth_skbs, &pid_tgid, &pskb, BPF_ANY);
}
return BPF_OK;
}

SEC("kretprobe/veth_convert_skb_to_xdp_buff")
int kretprobe_veth_convert_skb_to_xdp_buff(struct pt_regs *ctx) {
u64 pid_tgid = bpf_get_current_pid_tgid();
struct sk_buff ***skb = (struct sk_buff ***)bpf_map_lookup_elem(&veth_skbs, &pid_tgid);
if (skb && *skb) {
u64 skb_addr;
bpf_probe_read_kernel(&skb_addr, sizeof(skb_addr), (void *)*skb);
bpf_map_update_elem(&skb_heads, &skb_addr, &TRUE, BPF_ANY);
struct sk_buff ***pskb = (struct sk_buff ***)bpf_map_lookup_elem(&veth_skbs, &pid_tgid);
if (pskb && *pskb) {
struct sk_buff *skb;
bpf_probe_read_kernel(&skb, sizeof(skb), (void *)*pskb);
u64 skb_head = (u64) BPF_CORE_READ(skb, head);
bpf_map_update_elem(&skb_heads, &skb_head, &TRUE, BPF_ANY);
bpf_map_delete_elem(&veth_skbs, &pid_tgid);
}
return BPF_OK;
Expand Down

0 comments on commit cf5229b

Please sign in to comment.