The goal was to receive eBPF
kprobes using ebpf2go
.
This will print the following traces when a tcp-v6
packet will arrive or exit:
<...>-70775 [002] d...1 14216.275232: bpf_trace_printk: sys kprobe/tcp_v6_connect exit - 70775
<...>-70775 [002] d...1 14216.275249: bpf_trace_printk: sys kprobe/tcp_v6_connect enter - 70775
<...>-70894 [003] d...1 14231.718191: bpf_trace_printk: sys kprobe/tcp_v6_connect exit - 70894
<...>-70894 [003] d...1 14231.718199: bpf_trace_printk: sys kprobe/tcp_v6_connect enter - 70894
<...>-74347 [009] d...1 14371.919322: bpf_trace_printk: sys kprobe/tcp_v6_connect exit - 74347
<...>-74347 [009] d...1 14371.919332: bpf_trace_printk: sys kprobe/tcp_v6_connect enter - 74347
<...>-74370 [000] d...1 14373.224750: bpf_trace_printk: sys kprobe/tcp_v6_connect exit - 74370
<...>-74370 [000] d...1 14373.224766: bpf_trace_printk: sys kprobe/tcp_v6_connect enter - 74370
<...>-74386 [003] d...1 14374.201845: bpf_trace_printk: sys kprobe/tcp_v6_connect exit - 74386
<...>-74386 [003] d...1 14374.201853: bpf_trace_printk: sys kprobe/tcp_v6_connect enter - 74386
<...>-74405 [002] d...1 14375.136027: bpf_trace_printk: sys kprobe/tcp_v6_connect exit - 74405
<...>-74405 [002] d...1 14375.136032: bpf_trace_printk: sys kprobe/tcp_v6_connect enter - 74405
<...>-74547 [011] d...1 14376.634997: bpf_trace_printk: sys kprobe/tcp_v6_connect exit - 74547
<...>-74547 [011] d...1 14376.635012: bpf_trace_printk: sys kprobe/tcp_v6_connect enter - 74547
This can be recrieted using the following terminal
command:
kubectl exec --tty rabbitmq-0 -n rabbitmq -- curl -g -6 google.com
It will work even if the curl
pod is located on a different kubernetes namespace.
By executing go generate && go build && sudo ./ebpf-xdp
for a couple of seconds and then using ctrl+c
we wrote some traces into /sys/kernel/debug/tracing/trace_pipe
.
They can be viewed by:
sudo cat /sys/kernel/debug/tracing/trace_pipe
If your Linux distribution (e.g. Ubuntu) does not have the tracing subsystem enabled by default, you may not see any output. Use the following command to enable this feature:
sudo mount -t debugfs none /sys/kernel/debug
sudo echo 1 > /sys/kernel/debug/tracing/tracing_on