Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples/bpf: refactor syscall tracing programs using BPF_KSYSCALL macro

This commit refactors the syscall tracing programs by adopting the
BPF_KSYSCALL macro. This change aims to enhance the clarity and
simplicity of the BPF programs by reducing the complexity of argument
parsing from pt_regs.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Link: https://lore.kernel.org/r/20230818090119.477441-9-danieltimlee@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Daniel T. Lee and committed by
Alexei Starovoitov
8dc80551 d93a7cf6

+3 -7
+3 -7
samples/bpf/test_map_in_map.bpf.c
··· 103 103 return result ? *result : -ENOENT; 104 104 } 105 105 106 - SEC("kprobe/__sys_connect") 107 - int trace_sys_connect(struct pt_regs *ctx) 106 + SEC("ksyscall/connect") 107 + int BPF_KSYSCALL(trace_sys_connect, unsigned int fd, struct sockaddr_in6 *in6, int addrlen) 108 108 { 109 - struct sockaddr_in6 *in6; 110 109 u16 test_case, port, dst6[8]; 111 - int addrlen, ret, inline_ret, ret_key = 0; 110 + int ret, inline_ret, ret_key = 0; 112 111 u32 port_key; 113 112 void *outer_map, *inner_map; 114 113 bool inline_hash = false; 115 - 116 - in6 = (struct sockaddr_in6 *)PT_REGS_PARM2_CORE(ctx); 117 - addrlen = (int)PT_REGS_PARM3_CORE(ctx); 118 114 119 115 if (addrlen != sizeof(*in6)) 120 116 return 0;