.\" located in file include/uapi/linux/bpf.h of the Linux kernel sources
.\" (helpers description), and from scripts/bpf_helpers_doc.py in the same
.\" repository (header and footer).
-.
.TH BPF-HELPERS 7 "" "" ""
.SH NAME
BPF-HELPERS \- list of eBPF helper functions
-.
.nr rst2man-indent-level 0
-.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
--
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
0 on success, or a negative error in case of failure.
.UNINDENT
.TP
+.B \fBint bpf_map_push_elem(struct bpf_map *\fP\fImap\fP\fB, const void *\fP\fIvalue\fP\fB, u64\fP \fIflags\fP\fB)\fP
+.INDENT 7.0
+.TP
+.B Description
+Push an element \fIvalue\fP in \fImap\fP\&. \fIflags\fP is one of:
+.sp
+\fBBPF_EXIST\fP
+If the queue/stack is full, the oldest element is removed to
+make room for this.
+.TP
+.B Return
+0 on success, or a negative error in case of failure.
+.UNINDENT
+.TP
.B \fBint bpf_probe_read(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIsrc\fP\fB)\fP
.INDENT 7.0
.TP
.ft C
SEC("kprobe/sys_open")
void bpf_sys_open(struct pt_regs *ctx)
-{
char buf[PATHLEN]; // PATHLEN is defined to 256
int res = bpf_probe_read_str(buf, sizeof(buf),
ctx\->di);
// userspace via bpf_perf_event_output(); we
// can use res (the string length) as event
// size, after checking its boundaries.
-}
.ft P
.fi
.UNINDENT
to value \fIhash\fP\&.
.TP
.B Return
-0
.UNINDENT
.TP
.B \fBint bpf_setsockopt(struct bpf_sock_ops *\fP\fIbpf_socket\fP\fB, int\fP \fIlevel\fP\fB, int\fP \fIoptname\fP\fB, char *\fP\fIoptval\fP\fB, int\fP \fIoptlen\fP\fB)\fP
0 on success, or a negative error in case of failure.
.UNINDENT
.TP
-.B \fBint bpf_skb_adjust_room(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIlen_diff\fP\fB, u32\fP \fImode\fP\fB, u64\fP \fIflags\fP\fB)\fP
+.B \fBint bpf_skb_adjust_room(struct sk_buff *\fP\fIskb\fP\fB, s32\fP \fIlen_diff\fP\fB, u32\fP \fImode\fP\fB, u64\fP \fIflags\fP\fB)\fP
.INDENT 7.0
.TP
.B Description
x86 architecture is the only one to support this feature.
.TP
.B Return
-0
.UNINDENT
.TP
.B \fBint bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *\fP\fIbpf_sock\fP\fB, int\fP \fIargval\fP\fB)\fP
being buffered for \fIbytes\fP and is sent as it is received.
.TP
.B Return
-0
.UNINDENT
.TP
.B \fBint bpf_msg_cork_bytes(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIbytes\fP\fB)\fP
been accumulated.
.TP
.B Return
-0
.UNINDENT
.TP
.B \fBint bpf_msg_pull_data(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIstart\fP\fB, u32\fP \fIend\fP\fB, u64\fP \fIflags\fP\fB)\fP
translated to a keycode using the rc keymap, and reported as
an input key down event. After a period a key up event is
generated. This period can be extended by calling either
-\fBbpf_rc_keydown\fP () again with the same values, or calling
-\fBbpf_rc_repeat\fP ().
+\fBbpf_rc_keydown\fP() again with the same values, or calling
+\fBbpf_rc_repeat\fP().
.sp
Some protocols include a toggle bit, in case the button was
released and pressed again between consecutive scancodes.
"\fBy\fP".
.TP
.B Return
-0
.UNINDENT
.TP
.B \fBint bpf_rc_repeat(void *\fP\fIctx\fP\fB)\fP
"\fBy\fP".
.TP
.B Return
-0
.UNINDENT
.TP
.B \fBuint64_t bpf_skb_cgroup_id(struct sk_buff *\fP\fIskb\fP\fB)\fP
The \fIflags\fP meaning is specific for each map type,
and has to be 0 for cgroup local storage.
.sp
-Depending on the bpf program type, a local storage area
-can be shared between multiple instances of the bpf program,
+Depending on the BPF program type, a local storage area
+can be shared between multiple instances of the BPF program,
running simultaneously.
.sp
A user should care about the synchronization by himself.
-For example, by using the BPF_STX_XADD instruction to alter
+For example, by using the \fBBPF_STX_XADD\fP instruction to alter
the shared data.
.TP
.B Return
-Pointer to the local storage area.
+A pointer to the local storage area.
.UNINDENT
.TP
.B \fBint bpf_sk_select_reuseport(struct sk_reuseport_md *\fP\fIreuse\fP\fB, struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
.INDENT 7.0
.TP
.B Description
-Select a SO_REUSEPORT sk from a BPF_MAP_TYPE_REUSEPORT_ARRAY map
-It checks the selected sk is matching the incoming
-request in the skb.
+Select a \fBSO_REUSEPORT\fP socket from a
+\fBBPF_MAP_TYPE_REUSEPORT_ARRAY\fP \fImap\fP\&.
+It checks the selected socket is matching the incoming
+request in the socket buffer.
.TP
.B Return
0 on success, or a negative error in case of failure.
.UNINDENT
+.TP
+.B \fBstruct bpf_sock *bpf_sk_lookup_tcp(void *\fP\fIctx\fP\fB, struct bpf_sock_tuple *\fP\fItuple\fP\fB, u32\fP \fItuple_size\fP\fB, u64\fP \fInetns\fP\fB, u64\fP \fIflags\fP\fB)\fP
+.INDENT 7.0
+.TP
+.B Description
+Look for TCP socket matching \fItuple\fP, optionally in a child
+network namespace \fInetns\fP\&. The return value must be checked,
+and if non\-\fBNULL\fP, released via \fBbpf_sk_release\fP().
+.sp
+The \fIctx\fP should point to the context of the program, such as
+the skb or socket (depending on the hook in use). This is used
+to determine the base network namespace for the lookup.
+.sp
+\fItuple_size\fP must be one of:
+.INDENT 7.0
+.TP
+.B \fBsizeof\fP(\fItuple\fP\fB\->ipv4\fP)
+Look for an IPv4 socket.
+.TP
+.B \fBsizeof\fP(\fItuple\fP\fB\->ipv6\fP)
+Look for an IPv6 socket.
+.UNINDENT
+.sp
+If the \fInetns\fP is a negative signed 32\-bit integer, then the
+socket lookup table in the netns associated with the \fIctx\fP will
+will be used. For the TC hooks, this is the netns of the device
+in the skb. For socket hooks, this is the netns of the socket.
+If \fInetns\fP is any other signed 32\-bit value greater than or
+equal to zero then it specifies the ID of the netns relative to
+the netns associated with the \fIctx\fP\&. \fInetns\fP values beyond the
+range of 32\-bit integers are reserved for future use.
+.sp
+All values for \fIflags\fP are reserved for future usage, and must
+be left at zero.
+.sp
+This helper is available only if the kernel was compiled with
+\fBCONFIG_NET\fP configuration option.
+.TP
+.B Return
+Pointer to \fBstruct bpf_sock\fP, or \fBNULL\fP in case of failure.
+For sockets with reuseport option, the \fBstruct bpf_sock\fP
+result is from \fBreuse\->socks\fP[] using the hash of the tuple.
+.UNINDENT
+.TP
+.B \fBstruct bpf_sock *bpf_sk_lookup_udp(void *\fP\fIctx\fP\fB, struct bpf_sock_tuple *\fP\fItuple\fP\fB, u32\fP \fItuple_size\fP\fB, u64\fP \fInetns\fP\fB, u64\fP \fIflags\fP\fB)\fP
+.INDENT 7.0
+.TP
+.B Description
+Look for UDP socket matching \fItuple\fP, optionally in a child
+network namespace \fInetns\fP\&. The return value must be checked,
+and if non\-\fBNULL\fP, released via \fBbpf_sk_release\fP().
+.sp
+The \fIctx\fP should point to the context of the program, such as
+the skb or socket (depending on the hook in use). This is used
+to determine the base network namespace for the lookup.
+.sp
+\fItuple_size\fP must be one of:
+.INDENT 7.0
+.TP
+.B \fBsizeof\fP(\fItuple\fP\fB\->ipv4\fP)
+Look for an IPv4 socket.
+.TP
+.B \fBsizeof\fP(\fItuple\fP\fB\->ipv6\fP)
+Look for an IPv6 socket.
+.UNINDENT
+.sp
+If the \fInetns\fP is a negative signed 32\-bit integer, then the
+socket lookup table in the netns associated with the \fIctx\fP will
+will be used. For the TC hooks, this is the netns of the device
+in the skb. For socket hooks, this is the netns of the socket.
+If \fInetns\fP is any other signed 32\-bit value greater than or
+equal to zero then it specifies the ID of the netns relative to
+the netns associated with the \fIctx\fP\&. \fInetns\fP values beyond the
+range of 32\-bit integers are reserved for future use.
+.sp
+All values for \fIflags\fP are reserved for future usage, and must
+be left at zero.
+.sp
+This helper is available only if the kernel was compiled with
+\fBCONFIG_NET\fP configuration option.
+.TP
+.B Return
+Pointer to \fBstruct bpf_sock\fP, or \fBNULL\fP in case of failure.
+For sockets with reuseport option, the \fBstruct bpf_sock\fP
+result is from \fBreuse\->socks\fP[] using the hash of the tuple.
+.UNINDENT
+.TP
+.B \fBint bpf_sk_release(struct bpf_sock *\fP\fIsock\fP\fB)\fP
+.INDENT 7.0
+.TP
+.B Description
+Release the reference held by \fIsock\fP\&. \fIsock\fP must be a
+non\-\fBNULL\fP pointer that was returned from
+\fBbpf_sk_lookup_xxx\fP().
+.TP
+.B Return
+0 on success, or a negative error in case of failure.
+.UNINDENT
+.TP
+.B \fBint bpf_map_pop_elem(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIvalue\fP\fB)\fP
+.INDENT 7.0
+.TP
+.B Description
+Pop an element from \fImap\fP\&.
+.TP
+.B Return
+0 on success, or a negative error in case of failure.
+.UNINDENT
+.TP
+.B \fBint bpf_map_peek_elem(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIvalue\fP\fB)\fP
+.INDENT 7.0
+.TP
+.B Description
+Get an element from \fImap\fP without removing it.
+.TP
+.B Return
+0 on success, or a negative error in case of failure.
+.UNINDENT
+.TP
+.B \fBint bpf_msg_push_data(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIstart\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
+.INDENT 7.0
+.TP
+.B Description
+For socket policies, insert \fIlen\fP bytes into \fImsg\fP at offset
+\fIstart\fP\&.
+.sp
+If a program of type \fBBPF_PROG_TYPE_SK_MSG\fP is run on a
+\fImsg\fP it may want to insert metadata or options into the \fImsg\fP\&.
+This can later be read and used by any of the lower layer BPF
+hooks.
+.sp
+This helper may fail if under memory pressure (a malloc
+fails) in these cases BPF programs will get an appropriate
+error and BPF programs will need to handle them.
+.TP
+.B Return
+0 on success, or a negative error in case of failure.
+.UNINDENT
+.TP
+.B \fBint bpf_msg_pop_data(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIstart\fP\fB, u32\fP \fIpop\fP\fB, u64\fP \fIflags\fP\fB)\fP
+.INDENT 7.0
+.TP
+.B Description
+Will remove \fIpop\fP bytes from a \fImsg\fP starting at byte \fIstart\fP\&.
+This may result in \fBENOMEM\fP errors under certain situations if
+an allocation and copy are required due to a full ring buffer.
+However, the helper will try to avoid doing the allocation
+if possible. Other errors can occur if input parameters are
+invalid either due to \fIstart\fP byte not being valid part of \fImsg\fP
+payload and/or \fIpop\fP value being to large.
+.TP
+.B Return
+0 on success, or a negative error in case of failure.
+.UNINDENT
+.TP
+.B \fBint bpf_rc_pointer_rel(void *\fP\fIctx\fP\fB, s32\fP \fIrel_x\fP\fB, s32\fP \fIrel_y\fP\fB)\fP
+.INDENT 7.0
+.TP
+.B Description
+This helper is used in programs implementing IR decoding, to
+report a successfully decoded pointer movement.
+.sp
+The \fIctx\fP should point to the lirc sample as passed into
+the program.
+.sp
+This helper is only available is the kernel was compiled with
+the \fBCONFIG_BPF_LIRC_MODE2\fP configuration option set to
+"\fBy\fP".
+.TP
+.B Return
+.UNINDENT
.UNINDENT
.SH EXAMPLES
.sp
\fBsocket\fP(7),
\fBtc\-bpf\fP(8)
.\" Generated by docutils manpage writer.
-.