[Kprobe] Get Argument Values
Get argument values of an event using Cilium's eBPF
Last updated
Get argument values of an event using Cilium's eBPF
Last updated
When a Kprobe had a event happening, it will call a function with argument named struct pt_regs *ctx
with this, we can know what the register values were using some eBPF functions.
Let's assume that we were watching
kprobe/tcp_v4_rcv
to monitor TCP packet receive events.
For us to use PT_REGS_PARM1
, PT_REGS_RC
macros, we need to have following code:
Since retrieving register values are different by architectures, we need to explictly define target architecture by:
We are assuming that we have x86 system.
If you are using lots of
#include
s, includingvmlinux.h
, the target architecture definition must before any#include
statements. For example, it shall be like below:
If you would like to see the list of available architectures, check for more information on available architectures and their names.
We can retrieve the first parameter value using following statement:
Since tcp_v4_rcv
requires struct sk_buff
's pointer as first argument, this will retrieve the data.
Since we have struct sk_buff *skb
which is a pointer that points to a struct, we might fall into a temptation to use
But, this will return error something looks similar to the following message:
We need to use bpf_probe_read
in order to read the values.