From 69a9bbcee00573476fd403232b6f56501ba9e604 Mon Sep 17 00:00:00 2001 From: Alessio Cosenza Date: Tue, 27 May 2025 15:59:13 +0000 Subject: [PATCH] Add support to ctx in runProgram. Programs of type raw_tp need the input to be passed in the ctx instead of the data. Test: with ag/33648187 Change-Id: I79ac0126d91c9eafd847a0c8709a47a0113a9430 --- .../include/BpfSyscallWrappers.h | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/bpf/syscall_wrappers/include/BpfSyscallWrappers.h b/bpf/syscall_wrappers/include/BpfSyscallWrappers.h index 49de936f8d..43c3ac0f43 100644 --- a/bpf/syscall_wrappers/include/BpfSyscallWrappers.h +++ b/bpf/syscall_wrappers/include/BpfSyscallWrappers.h @@ -235,15 +235,20 @@ inline int detachSingleProgram(bpf_attach_type type, const borrowed_fd& prog_fd, } // Available in 4.12 and later kernels. -inline int runProgram(const borrowed_fd& prog_fd, const void* data, - const uint32_t data_size) { - return bpf(BPF_PROG_RUN, { - .test = { - .prog_fd = static_cast<__u32>(prog_fd.get()), - .data_size_in = data_size, - .data_in = ptr_to_u64(data), - }, - }); +inline int runProgram(const borrowed_fd &prog_fd, const void *data, + const uint32_t data_size, const void *ctx = nullptr, + const uint32_t ctx_size = 0) { + return bpf(BPF_PROG_RUN, + { + .test = + { + .prog_fd = static_cast<__u32>(prog_fd.get()), + .data_size_in = data_size, + .data_in = ptr_to_u64(data), + .ctx_size_in = ctx_size, + .ctx_in = ptr_to_u64(ctx), + }, + }); } // BPF_OBJ_GET_INFO_BY_FD requires 4.14+ kernel