On 3/29/24 12:18 PM, Jordan Rife wrote:
+static int do_sock_op(int op, struct sockaddr *addr, int addrlen)
This function can be made as a new kfunc in bpf_testmod.c. The
sock_create_kern() could be moved to here also. Take a look at the
register_btf_kfunc_id_set() usage in bpf_testmod.c and how those registered
kfunc(s) can be called by the bpf prog in progs/*.
If the do_kernel_{bind,connect,sendmsg} and the sock_create_kern need a
sleepable context, it will need to mark the kfunc KF_SLEEPABLE. The kfunc can be
registered to the BPF_PROG_TYPE_SYSCALL sleepable prog type. There are some
examples in progs/kfunc_call_test.c and how the "syscall" bpf prog can be run by
bpf_prog_test_run_opts().
The result (e.g. ensuring the addr and addrlen have not been changed) can be
checked in the bpf prog itself. Then the new sock_addr_testmod is not needed.
+{
+ switch (op) {
+ case BIND:
+ return do_kernel_bind(addr, addrlen);
+ case CONNECT:
+ return do_kernel_connect(addr, addrlen);
+ case SENDMSG:
+ return do_kernel_sendmsg(addr, addrlen);
+ default:
+ return -EINVAL;
+ }
+}
+