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
diff --git a/bpf/syscall_wrappers/include/BpfSyscallWrappers.h b/bpf/syscall_wrappers/include/BpfSyscallWrappers.h
index 49de936..43c3ac0 100644
--- a/bpf/syscall_wrappers/include/BpfSyscallWrappers.h
+++ b/bpf/syscall_wrappers/include/BpfSyscallWrappers.h
@@ -235,15 +235,20 @@
}
// 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