Skip to content

Commit a5b31eb

Browse files
Asphalttbrb
authored andcommitted
Fix broken --filter-trace-xdp caused by go-ebpf v0.17.1
There're two issue: One is `BPF_PROG_ADDR` must be set via `spec.Variable`. Another one is `.bss` map flag must be updated because go-ebpf v0.17.1 set `BPF_F_MMAPABLE` flag to created `.bss` map. As a result, we can reuse `.bss` map. Here's the test result: ```bash $ sudo ./pwru --filter-trace-tc --filter-trace-xdp --filter-func '.*icmp.*' icmp 2025/01/15 15:14:26 Attaching tc-bpf progs... 2025/01/15 15:14:26 Attaching xdp progs... 2025/01/15 15:14:26 Attaching kprobes (via kprobe)... 29 / 29 [--------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s 2025/01/15 15:14:26 Attached (ignored 0) 2025/01/15 15:14:26 Listening for events.. SKB CPU PROCESS NETNS MARK/x IFACE PROTO MTU LEN __sk_buff->cb[] TUPLE FUNC 0xffffb5dd40600b00 6 <empty>:0 4026531840 0 ens33:2 0x0000 1500 98 [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_3b185187f1855c4c_dummy[bpf](xdp) 0xffff995b7756d400 6 <empty>:0 4026531840 0 ens33:2 0x0800 1500 98 [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc) 0xffff995b7756d400 6 <empty>:0 4026531840 0 ens33:2 0x0800 65536 64 [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) icmp_rcv 0xffff995b7756d400 6 <empty>:0 4026531840 0 ens33:2 0x0800 65536 56 [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) icmp_echo 0xffff995b7756d400 6 <empty>:0 4026531840 0 ens33:2 0x0800 65536 56 [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) icmp_reply ^C2025/01/15 15:14:30 Received signal, exiting program.. 2025/01/15 15:14:30 Detaching kprobes... 29 / 29 [------------------------------------------------------------------------------------------------------------------------------------] 100.00% 132 p/s ``` And there's only one `.bss` map: ```bash $ sudo bpftool m | grep -c .bss 1 ``` Signed-off-by: Leon Hwang <[email protected]>
1 parent 1a0c91f commit a5b31eb

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

bpf/kprobe_pwru.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
const static bool TRUE = true;
3131
const static u32 ZERO = 0;
3232

33-
volatile const static __u64 BPF_PROG_ADDR = 0;
33+
volatile const __u64 BPF_PROG_ADDR = 0;
3434

3535
enum {
3636
TRACKED_BY_FILTER = (1 << 0),

internal/pwru/tracing.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ func (t *tracing) traceProg(spec *ebpf.CollectionSpec,
9292
}
9393

9494
spec = spec.Copy()
95-
if err := spec.RewriteConstants(map[string]any{
96-
"BPF_PROG_ADDR": addr,
97-
}); err != nil {
98-
return fmt.Errorf("failed to rewrite bpf prog addr: %w", err)
95+
if err := spec.Variables["BPF_PROG_ADDR"].Set(addr); err != nil {
96+
return fmt.Errorf("failed to set bpf prog addr: %w", err)
9997
}
10098

10199
spec.Programs[tracingName].AttachTarget = prog

0 commit comments

Comments
 (0)