Skip to content

Commit 2ed349d

Browse files
Dan Partellybrb
Dan Partelly
authored andcommitted
Print drop reason from sk_skb_reason_drop
This commit extracts a drop reason from sk_skb_reason_drop(), and prints it when sk_skb_drop_reason() is called. This function was introduced in kernel v6.11-rc1. At the same time, kfree_skb_reason() became an inline helper which just calls sk_skb_reason_drop(). See: torvalds/linux@ba8de79
1 parent 0dc9829 commit 2ed349d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

bpf/kprobe_pwru.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct event_t {
8686
struct tuple tuple;
8787
s64 print_stack_id;
8888
u64 param_second;
89+
u64 param_third;
8990
u32 cpu_id;
9091
} __attribute__((packed));
9192

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

internal/pwru/output.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ func getOutFuncName(o *output, event *Event, addr uint64) string {
351351
} else {
352352
outFuncName = fmt.Sprintf("%s (%d)", funcName, event.ParamSecond)
353353
}
354+
} else if funcName == "sk_skb_reason_drop" {
355+
if reason, ok := o.kfreeReasons[event.ParamThird]; ok {
356+
outFuncName = fmt.Sprintf("%s(%s)", funcName, reason)
357+
} else {
358+
outFuncName = fmt.Sprintf("%s (%d)", funcName, event.ParamThird)
359+
}
354360
}
355361

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

485494
var dropReasonsEnum *btf.Enum

internal/pwru/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,6 @@ type Event struct {
150150
Tuple Tuple
151151
PrintStackId int64
152152
ParamSecond uint64
153+
ParamThird uint64
153154
CPU uint32
154155
}

0 commit comments

Comments
 (0)