diff options
author | Daniel T. Lee <danieltimlee@gmail.com> | 2022-12-24 10:15:26 +0300 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2022-12-30 01:22:34 +0300 |
commit | c5ffb26375ad309c858453f17e777b716723d527 (patch) | |
tree | 6314268028d2aa23ce0cb14dd57de1153cc8cbdd /samples/bpf/test_probe_write_user.bpf.c | |
parent | 2e5c4dd7f81545a98e9f06317347e760749c020b (diff) | |
download | linux-c5ffb26375ad309c858453f17e777b716723d527.tar.xz |
samples/bpf: Use BPF_KSYSCALL macro in syscall tracing programs
This commit enhances the syscall tracing programs by using the
BPF_SYSCALL macro to reduce the inconvenience of parsing arguments from
pt_regs. By simplifying argument extraction, bpf program will become
clear to understand.
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221224071527.2292-6-danieltimlee@gmail.com
Diffstat (limited to 'samples/bpf/test_probe_write_user.bpf.c')
-rw-r--r-- | samples/bpf/test_probe_write_user.bpf.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/samples/bpf/test_probe_write_user.bpf.c b/samples/bpf/test_probe_write_user.bpf.c index a0f10c5ca273..a4f3798b7fb0 100644 --- a/samples/bpf/test_probe_write_user.bpf.c +++ b/samples/bpf/test_probe_write_user.bpf.c @@ -27,24 +27,22 @@ struct { * of course, across platforms, and over time, the ABI may change. */ SEC("ksyscall/connect") -int bpf_prog1(struct pt_regs *ctx) +int BPF_KSYSCALL(bpf_prog1, int fd, struct sockaddr_in *uservaddr, + int addrlen) { - struct pt_regs *real_regs = (struct pt_regs *)PT_REGS_PARM1_CORE(ctx); - void *sockaddr_arg = (void *)PT_REGS_PARM2_CORE(real_regs); - int sockaddr_len = (int)PT_REGS_PARM3_CORE(real_regs); struct sockaddr_in new_addr, orig_addr = {}; struct sockaddr_in *mapped_addr; - if (sockaddr_len > sizeof(orig_addr)) + if (addrlen > sizeof(orig_addr)) return 0; - if (bpf_probe_read_user(&orig_addr, sizeof(orig_addr), sockaddr_arg) != 0) + if (bpf_probe_read_user(&orig_addr, sizeof(orig_addr), uservaddr) != 0) return 0; mapped_addr = bpf_map_lookup_elem(&dnat_map, &orig_addr); if (mapped_addr != NULL) { memcpy(&new_addr, mapped_addr, sizeof(new_addr)); - bpf_probe_write_user(sockaddr_arg, &new_addr, + bpf_probe_write_user(uservaddr, &new_addr, sizeof(new_addr)); } return 0; |