Skip to content

Commit

Permalink
Don't decorate offset
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwinger233 committed Nov 26, 2023
1 parent 6cc78f3 commit 7f6efe5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bpf/bpf_bpfel_x86.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified bpf/bpf_bpfel_x86.o
Binary file not shown.
13 changes: 9 additions & 4 deletions bpf/skbdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ struct skbmeta {
__u64 time_ns;
__u64 rax;

__u16 l2;
__u8 l2;
__u8 ret;
__u32 len;
__u32 ifindex;

Expand Down Expand Up @@ -115,6 +116,7 @@ void handle_skb_tc(struct __sk_buff *skb, bool ingress)
dump->meta.skb = skb_addr;

dump->meta.l2 = 1;
dump->meta.ret = 0;
dump->meta.len = skb->len;
dump->meta.ifindex = skb->ifindex;

Expand Down Expand Up @@ -242,7 +244,8 @@ handle_skb_kprobe(struct sk_buff *skb, struct pt_regs *ctx)
if (!dump)
return 0;

dump->meta.at = ctx->ip - 1;
dump->meta.at = ctx->ip;
dump->meta.ret = 0;
__u64 sp = ctx->sp;
bpf_map_update_elem(&sp2ip, &sp, &dump->meta.at, BPF_ANY);
return collect_skb(skb, ctx, dump);
Expand Down Expand Up @@ -273,7 +276,8 @@ int on_kprobe_tid(struct pt_regs *ctx)
if (!dump)
return 0;

dump->meta.at = ctx->ip - 1;
dump->meta.at = ctx->ip;
dump->meta.ret = 0;
__u64 sp = ctx->sp;
if (!bpf_map_lookup_elem(&sp2ip, &sp))
bpf_map_update_elem(&sp2ip, &sp, &dump->meta.at, BPF_ANY);
Expand All @@ -299,7 +303,8 @@ int on_kretprobe(struct pt_regs *ctx)
if (!dump)
return 0;

dump->meta.at = (*ip) - 1;
dump->meta.at = *ip;
dump->meta.ret = 1;
collect_skb(*skb, ctx, dump);

bpf_map_delete_elem(&sp2ip, &sp);
Expand Down
2 changes: 1 addition & 1 deletion skbprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func skbPrint(skb *bpf.Skbdump, linktype layers.LinkType) {
ksym = fmt.Sprintf("%s+%d", ksym, off)
}
fmt.Printf("%s@%d(%s) ", ksym, skb.Meta.Ifindex, ifname)
if strings.Contains(ksym, "+r") {
if skb.Meta.Ret == 1 {
fmt.Printf("rv=%x ", skb.Meta.Rax)
}

Expand Down
4 changes: 1 addition & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package utils

import (
"fmt"
"log"
"os"
"slices"
Expand Down Expand Up @@ -36,8 +35,7 @@ func init() {
typ, name := parts[1], parts[2]
if typ == "t" || typ == "T" {
kallsymsByAddr[addr] = Symbol{typ, name, addr}
kallsymsByAddr[addr-1] = Symbol{typ, fmt.Sprintf("%s+r", name), addr - 1}
kallsyms = append(kallsyms, kallsymsByAddr[addr], kallsymsByAddr[addr-1])
kallsyms = append(kallsyms, kallsymsByAddr[addr])
}
}
kallsymsByAddr[0] = Symbol{"t", "out", 0}
Expand Down

0 comments on commit 7f6efe5

Please sign in to comment.