Helper function bpf_ringbuf_submit_dynptr
Definition
Copyright (c) 2015 The Libbpf Authors. All rights reserved.
Submit reserved ring buffer sample, pointed to by data, through the dynptr interface. This is a no-op if the dynptr is invalid/null.
For more information on flags, please see 'bpf_ringbuf_submit'.
Returns
Nothing. Always succeeds.
static void (* const bpf_ringbuf_submit_dynptr)(struct bpf_dynptr *ptr, __u64 flags) = (void *) 199;
Usage
Docs could be improved
This part of the docs is incomplete, contributions are very welcome
Program types
This helper call can be used in the following program types:
BPF_PROG_TYPE_CGROUP_DEVICEBPF_PROG_TYPE_CGROUP_SKBBPF_PROG_TYPE_CGROUP_SOCKBPF_PROG_TYPE_CGROUP_SOCKOPTBPF_PROG_TYPE_CGROUP_SOCK_ADDRBPF_PROG_TYPE_CGROUP_SYSCTLBPF_PROG_TYPE_FLOW_DISSECTORBPF_PROG_TYPE_KPROBEBPF_PROG_TYPE_LSMBPF_PROG_TYPE_LWT_INBPF_PROG_TYPE_LWT_OUTBPF_PROG_TYPE_LWT_SEG6LOCALBPF_PROG_TYPE_LWT_XMITBPF_PROG_TYPE_NETFILTERBPF_PROG_TYPE_PERF_EVENTBPF_PROG_TYPE_RAW_TRACEPOINTBPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLEBPF_PROG_TYPE_SCHED_ACTBPF_PROG_TYPE_SCHED_CLSBPF_PROG_TYPE_SK_LOOKUPBPF_PROG_TYPE_SK_MSGBPF_PROG_TYPE_SK_REUSEPORTBPF_PROG_TYPE_SK_SKBBPF_PROG_TYPE_SOCKET_FILTERBPF_PROG_TYPE_SOCK_OPSBPF_PROG_TYPE_STRUCT_OPSBPF_PROG_TYPE_SYSCALLBPF_PROG_TYPE_TRACEPOINTBPF_PROG_TYPE_TRACINGBPF_PROG_TYPE_XDP
Example
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 256 * 1024);
} ringbuf SEC(".maps");
SEC("tp/syscalls/sys_enter_openat")
int bpf_prog1(void *ctx)
{
char write_data[64] = "hello there, world!!";
char read_data[64] = {};
struct bpf_dynptr ptr;
int i;
int local_err = 0;
local_err = bpf_ringbuf_reserve_dynptr(&ringbuf, sizeof(write_data), 0, &ptr);
if (local_err < 0)
goto discard;
/* Write data into the dynptr */
local_err = bpf_dynptr_write(&ptr, 0, write_data, sizeof(write_data), 0);
if (local_err) {
goto discard;
}
/* Read the data that was written into the dynptr */
local_err = bpf_dynptr_read(read_data, sizeof(read_data), &ptr, 0, 0);
if (local_err) {
goto discard;
}
/* Ensure the data we read matches the data we wrote */
for (i = 0; i < sizeof(read_data); i++) {
if (read_data[i] != write_data[i]) {
break;
}
}
bpf_printk("Read matches write, dynptr API works");
bpf_ringbuf_submit_dynptr(&ptr, 0);
return 0;
discard:
bpf_ringbuf_discard_dynptr(&ptr, 0);
return 0;
}