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

Print drop reason from sk_skb_reason_drop. Catch up with kernel 6.11 changes #430

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bpf/kprobe_pwru.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct event_t {
struct tuple tuple;
s64 print_stack_id;
u64 param_second;
u64 param_third;
u32 cpu_id;
} __attribute__((packed));

Expand Down Expand Up @@ -504,6 +505,7 @@ kprobe_skb(struct sk_buff *skb, struct pt_regs *ctx, bool has_get_func_ip, u64 *
event.skb_addr = (u64) skb;
event.addr = has_get_func_ip ? bpf_get_func_ip(ctx) : PT_REGS_IP(ctx);
event.param_second = PT_REGS_PARM2(ctx);
event.param_third = PT_REGS_PARM3(ctx);
if (CFG.output_caller)
bpf_probe_read_kernel(&event.caller_addr, sizeof(event.caller_addr), (void *)PT_REGS_SP(ctx));

Expand Down
13 changes: 11 additions & 2 deletions internal/pwru/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ func getOutFuncName(o *output, event *Event, addr uint64) string {
} else {
outFuncName = fmt.Sprintf("%s (%d)", funcName, event.ParamSecond)
}
} else if funcName == "sk_skb_reason_drop" {
if reason, ok := o.kfreeReasons[event.ParamThird]; ok {
outFuncName = fmt.Sprintf("%s(%s)", funcName, reason)
} else {
outFuncName = fmt.Sprintf("%s (%d)", funcName, event.ParamThird)
}
}

if event.Type != eventTypeKprobe {
Expand Down Expand Up @@ -478,8 +484,11 @@ func addrToStr(proto uint16, addr [16]byte) string {
// defined in /include/net/dropreason.h.
func getKFreeSKBReasons(spec *btf.Spec) (map[uint64]string, error) {
if _, err := spec.AnyTypeByName("kfree_skb_reason"); err != nil {
// Kernel is too old to have kfree_skb_reason
return nil, nil
if _, err := spec.AnyTypeByName("sk_skb_reason_drop"); err != nil {
// Kernel is too old to have either kfree_skb_reason or sk_skb_reason_drop
// see https://github.com/torvalds/linux/commit/ba8de796baf4bdc03530774fb284fe3c97875566
return nil, nil
}
}

var dropReasonsEnum *btf.Enum
Expand Down
1 change: 1 addition & 0 deletions internal/pwru/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,6 @@ type Event struct {
Tuple Tuple
PrintStackId int64
ParamSecond uint64
ParamThird uint64
CPU uint32
}
Loading