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

selftests/bpf: Implement BPF programs for kernel socket operations

This patch lays out a set of SYSCALL programs that can be used to invoke
the socket operation kfuncs in bpf_testmod, allowing a test program to
manipulate kernel socket operations from userspace.

Signed-off-by: Jordan Rife <jrife@google.com>
Link: https://lore.kernel.org/r/20240429214529.2644801-4-jrife@google.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

authored by

Jordan Rife and committed by
Martin KaFai Lau
15b6671e bbb1cfdd

+65
+65
tools/testing/selftests/bpf/progs/sock_addr_kern.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright (c) 2024 Google LLC */ 3 + #include <vmlinux.h> 4 + #include <bpf/bpf_helpers.h> 5 + #include "../bpf_testmod/bpf_testmod_kfunc.h" 6 + 7 + SEC("syscall") 8 + int init_sock(struct init_sock_args *args) 9 + { 10 + bpf_kfunc_init_sock(args); 11 + 12 + return 0; 13 + } 14 + 15 + SEC("syscall") 16 + int close_sock(void *ctx) 17 + { 18 + bpf_kfunc_close_sock(); 19 + 20 + return 0; 21 + } 22 + 23 + SEC("syscall") 24 + int kernel_connect(struct addr_args *args) 25 + { 26 + return bpf_kfunc_call_kernel_connect(args); 27 + } 28 + 29 + SEC("syscall") 30 + int kernel_bind(struct addr_args *args) 31 + { 32 + return bpf_kfunc_call_kernel_bind(args); 33 + } 34 + 35 + SEC("syscall") 36 + int kernel_listen(struct addr_args *args) 37 + { 38 + return bpf_kfunc_call_kernel_listen(); 39 + } 40 + 41 + SEC("syscall") 42 + int kernel_sendmsg(struct sendmsg_args *args) 43 + { 44 + return bpf_kfunc_call_kernel_sendmsg(args); 45 + } 46 + 47 + SEC("syscall") 48 + int sock_sendmsg(struct sendmsg_args *args) 49 + { 50 + return bpf_kfunc_call_sock_sendmsg(args); 51 + } 52 + 53 + SEC("syscall") 54 + int kernel_getsockname(struct addr_args *args) 55 + { 56 + return bpf_kfunc_call_kernel_getsockname(args); 57 + } 58 + 59 + SEC("syscall") 60 + int kernel_getpeername(struct addr_args *args) 61 + { 62 + return bpf_kfunc_call_kernel_getpeername(args); 63 + } 64 + 65 + char _license[] SEC("license") = "GPL";