Skip to content

Commit c2011f9

Browse files
committed
ebpf: tcp retransmits tracing - kernel versions 5.12+ support
1 parent 3c89d53 commit c2011f9

File tree

6 files changed

+34
-11
lines changed

6 files changed

+34
-11
lines changed

ebpftracer/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ WORKDIR /tmp
88
RUN clang -g -O2 -target bpf -D__TARGET_ARCH_x86 -D__KERNEL=416 -c ebpf.c -o ebpf416.o && llvm-strip --strip-debug ebpf416.o
99
RUN clang -g -O2 -target bpf -D__TARGET_ARCH_x86 -D__KERNEL=420 -c ebpf.c -o ebpf420.o && llvm-strip --strip-debug ebpf420.o
1010
RUN clang -g -O2 -target bpf -D__TARGET_ARCH_x86 -D__KERNEL=506 -c ebpf.c -o ebpf506.o && llvm-strip --strip-debug ebpf506.o
11+
RUN clang -g -O2 -target bpf -D__TARGET_ARCH_x86 -D__KERNEL=512 -c ebpf.c -o ebpf512.o && llvm-strip --strip-debug ebpf512.o
1112

1213
RUN echo -en '// generated - do not edit\npackage ebpftracer\nvar ebpfProg = []struct{v string; p []byte}{\n' > ebpf.go \
14+
&& echo -en '\t{"v5.12", []byte("' >> ebpf.go && hexdump -v -e '"\x" 1/1 "%02x"' ebpf512.o >> ebpf.go && echo '")},' >> ebpf.go \
1315
&& echo -en '\t{"v5.6", []byte("' >> ebpf.go && hexdump -v -e '"\x" 1/1 "%02x"' ebpf506.o >> ebpf.go && echo '")},' >> ebpf.go \
1416
&& echo -en '\t{"v4.20", []byte("' >> ebpf.go && hexdump -v -e '"\x" 1/1 "%02x"' ebpf420.o >> ebpf.go && echo '")},' >> ebpf.go \
1517
&& echo -en '\t{"v4.16", []byte("' >> ebpf.go && hexdump -v -e '"\x" 1/1 "%02x"' ebpf416.o >> ebpf.go && echo '")},' >> ebpf.go \

ebpftracer/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build:
44
docker cp $(shell docker create --rm ebpftracer):/tmp/ebpf.go ./ebpf.go
55
@echo
66

7-
test: test_vm1 test_vm2 test_vm3
7+
test: test_vm1 test_vm2 test_vm3 test_vm4
88

99
define test_in_vm
1010
@echo ===TESTING IN $(1)===
@@ -21,6 +21,9 @@ test_vm2: build
2121
test_vm3: build
2222
$(call test_in_vm,ubuntu2010)
2323

24+
test_vm4: build
25+
$(call test_in_vm,ubuntu2110)
26+
2427
vms_start:
2528
vagrant up
2629

ebpftracer/Vagrantfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ Vagrant.configure("2") do |config|
2828
config.vm.define "ubuntu2010" do |ubuntu2010|
2929
ubuntu2010.vm.box = "generic/ubuntu2010"
3030
end
31+
config.vm.define "ubuntu2110" do |ubuntu2110|
32+
ubuntu2110.vm.box = "generic/ubuntu2110"
33+
end
3134
end

ebpftracer/ebpf.go

Lines changed: 4 additions & 3 deletions
Large diffs are not rendered by default.

ebpftracer/ebpf/tcp_retransmit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ struct trace_event_raw_tcp_event_sk_skb__stub {
1313
#endif
1414
__u16 sport;
1515
__u16 dport;
16+
#if __KERNEL >= 512
17+
__u16 family;
18+
#endif
1619
__u8 saddr[4];
1720
__u8 daddr[4];
1821
__u8 saddr_v6[16];

ebpftracer/tracer_test.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"github.com/containerd/cgroups"
7+
cgroupsV2 "github.com/containerd/cgroups/v2"
78
"github.com/opencontainers/runtime-spec/specs-go"
89
"github.com/stretchr/testify/assert"
910
"github.com/stretchr/testify/require"
@@ -71,14 +72,24 @@ func TestProcessEvents(t *testing.T) {
7172
assert.Equal(t, Event{Type: EventTypeProcessExit, Pid: uint32(p2.Process.Pid)}, *getEvent())
7273

7374
var limit int64 = 200 * 1024 * 1024
74-
control, err := cgroups.New(cgroups.V1, cgroups.StaticPath("/program"), &specs.LinuxResources{
75-
Memory: &specs.LinuxMemory{Limit: &limit},
76-
})
77-
require.NoError(t, err)
78-
defer control.Delete()
7975
// p3 should be killed by the OOM killer, because 300 MB > 200 MB cgroup limit
80-
p3 := exec.Command("cgexec", "-g", "memory:program", program, "300", "1s")
81-
require.Error(t, p3.Run())
76+
p3 := exec.Command(program, "300", "3s")
77+
require.NoError(t, p3.Start())
78+
switch cgroups.Mode() {
79+
case cgroups.Legacy, cgroups.Hybrid:
80+
control, err := cgroups.New(cgroups.V1, cgroups.StaticPath("/program"), &specs.LinuxResources{
81+
Memory: &specs.LinuxMemory{Limit: &limit},
82+
})
83+
require.NoError(t, err)
84+
defer control.Delete()
85+
require.NoError(t, control.Add(cgroups.Process{Pid: p3.Process.Pid}))
86+
case cgroups.Unified:
87+
control, err := cgroupsV2.NewManager("/sys/fs/cgroup", "/program", &cgroupsV2.Resources{Memory: &cgroupsV2.Memory{Max: &limit}})
88+
require.NoError(t, err)
89+
defer control.Delete()
90+
require.NoError(t, control.AddProc(uint64(p3.Process.Pid)))
91+
}
92+
require.Error(t, p3.Wait())
8293
assert.Equal(t, Event{Type: EventTypeProcessStart, Pid: uint32(p3.Process.Pid)}, *getEvent())
8394
assert.Equal(t, Event{Type: EventTypeProcessExit, Reason: EventReasonOOMKill, Pid: uint32(p3.Process.Pid)}, *getEvent())
8495

0 commit comments

Comments
 (0)