]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man7/bpf-helpers.7
bpf-helpers.7: Add new man page for eBPF helper functions
[thirdparty/man-pages.git] / man7 / bpf-helpers.7
CommitLineData
53666f6c
MK
1.\" Man page generated from reStructuredText.
2.\" Copyright (C) All BPF authors and contributors from 2014 to present.
3.\" See git log include/uapi/linux/bpf.h in kernel tree for details.
4.\"
5.\" %%%LICENSE_START(VERBATIM)
6.\" Permission is granted to make and distribute verbatim copies of this
7.\" manual provided the copyright notice and this permission notice are
8.\" preserved on all copies.
9.\"
10.\" Permission is granted to copy and distribute modified versions of this
11.\" manual under the conditions for verbatim copying, provided that the
12.\" entire resulting derived work is distributed under the terms of a
13.\" permission notice identical to this one.
14.\"
15.\" Since the Linux kernel and libraries are constantly changing, this
16.\" manual page may be incorrect or out-of-date. The author(s) assume no
17.\" responsibility for errors or omissions, or for damages resulting from
18.\" the use of the information contained herein. The author(s) may not
19.\" have taken the same level of care in the production of this manual,
20.\" which is licensed free of charge, as they might when working
21.\" professionally.
22.\"
23.\" Formatted or processed versions of this manual, if unaccompanied by
24.\" the source, must acknowledge the copyright and authors of this work.
25.\" %%%LICENSE_END
26.\"
27.\" Please do not edit this file. It was generated from the documentation
28.\" located in file include/uapi/linux/bpf.h of the Linux kernel sources
29.\" (helpers description), and from scripts/bpf_helpers_doc.py in the same
30.\" repository (header and footer).
31.
32.TH BPF-HELPERS 7 "" "" ""
33.SH NAME
34BPF-HELPERS \- list of eBPF helper functions
35.
36.nr rst2man-indent-level 0
37.
38.de1 rstReportMargin
39\\$1 \\n[an-margin]
40level \\n[rst2man-indent-level]
41level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
42-
43\\n[rst2man-indent0]
44\\n[rst2man-indent1]
45\\n[rst2man-indent2]
46..
47.de1 INDENT
48.\" .rstReportMargin pre:
49. RS \\$1
50. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
51. nr rst2man-indent-level +1
52.\" .rstReportMargin post:
53..
54.de UNINDENT
55. RE
56.\" indent \\n[an-margin]
57.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
58.nr rst2man-indent-level -1
59.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
60.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
61..
62.SH DESCRIPTION
63.sp
64The extended Berkeley Packet Filter (eBPF) subsystem consists in programs
65written in a pseudo\-assembly language, then attached to one of the several
66kernel hooks and run in reaction of specific events. This framework differs
67from the older, "classic" BPF (or "cBPF") in several aspects, one of them being
68the ability to call special functions (or "helpers") from within a program.
69These functions are restricted to a white\-list of helpers defined in the
70kernel.
71.sp
72These helpers are used by eBPF programs to interact with the system, or with
73the context in which they work. For instance, they can be used to print
74debugging messages, to get the time since the system was booted, to interact
75with eBPF maps, or to manipulate network packets. Since there are several eBPF
76program types, and that they do not run in the same context, each program type
77can only call a subset of those helpers.
78.sp
79Due to eBPF conventions, a helper can not have more than five arguments.
80.sp
81Internally, eBPF programs call directly into the compiled helper functions
82without requiring any foreign\-function interface. As a result, calling helpers
83introduces no overhead, thus offering excellent performance.
84.sp
85This document is an attempt to list and document the helpers available to eBPF
86developers. They are sorted by chronological order (the oldest helpers in the
87kernel at the top).
88.SH HELPERS
89.INDENT 0.0
90.TP
91.B \fBvoid *bpf_map_lookup_elem(struct bpf_map *\fP\fImap\fP\fB, const void *\fP\fIkey\fP\fB)\fP
92.INDENT 7.0
93.TP
94.B Description
95Perform a lookup in \fImap\fP for an entry associated to \fIkey\fP\&.
96.TP
97.B Return
98Map value associated to \fIkey\fP, or \fBNULL\fP if no entry was
99found.
100.UNINDENT
101.TP
102.B \fBint bpf_map_update_elem(struct bpf_map *\fP\fImap\fP\fB, const void *\fP\fIkey\fP\fB, const void *\fP\fIvalue\fP\fB, u64\fP \fIflags\fP\fB)\fP
103.INDENT 7.0
104.TP
105.B Description
106Add or update the value of the entry associated to \fIkey\fP in
107\fImap\fP with \fIvalue\fP\&. \fIflags\fP is one of:
108.INDENT 7.0
109.TP
110.B \fBBPF_NOEXIST\fP
111The entry for \fIkey\fP must not exist in the map.
112.TP
113.B \fBBPF_EXIST\fP
114The entry for \fIkey\fP must already exist in the map.
115.TP
116.B \fBBPF_ANY\fP
117No condition on the existence of the entry for \fIkey\fP\&.
118.UNINDENT
119.sp
120Flag value \fBBPF_NOEXIST\fP cannot be used for maps of types
121\fBBPF_MAP_TYPE_ARRAY\fP or \fBBPF_MAP_TYPE_PERCPU_ARRAY\fP (all
122elements always exist), the helper would return an error.
123.TP
124.B Return
1250 on success, or a negative error in case of failure.
126.UNINDENT
127.TP
128.B \fBint bpf_map_delete_elem(struct bpf_map *\fP\fImap\fP\fB, const void *\fP\fIkey\fP\fB)\fP
129.INDENT 7.0
130.TP
131.B Description
132Delete entry with \fIkey\fP from \fImap\fP\&.
133.TP
134.B Return
1350 on success, or a negative error in case of failure.
136.UNINDENT
137.TP
138.B \fBint bpf_probe_read(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIsrc\fP\fB)\fP
139.INDENT 7.0
140.TP
141.B Description
142For tracing programs, safely attempt to read \fIsize\fP bytes from
143address \fIsrc\fP and store the data in \fIdst\fP\&.
144.TP
145.B Return
1460 on success, or a negative error in case of failure.
147.UNINDENT
148.TP
149.B \fBu64 bpf_ktime_get_ns(void)\fP
150.INDENT 7.0
151.TP
152.B Description
153Return the time elapsed since system boot, in nanoseconds.
154.TP
155.B Return
156Current \fIktime\fP\&.
157.UNINDENT
158.TP
159.B \fBint bpf_trace_printk(const char *\fP\fIfmt\fP\fB, u32\fP \fIfmt_size\fP\fB, ...)\fP
160.INDENT 7.0
161.TP
162.B Description
163This helper is a "printk()\-like" facility for debugging. It
164prints a message defined by format \fIfmt\fP (of size \fIfmt_size\fP)
165to file \fI/sys/kernel/debug/tracing/trace\fP from DebugFS, if
166available. It can take up to three additional \fBu64\fP
167arguments (as an eBPF helpers, the total number of arguments is
168limited to five).
169.sp
170Each time the helper is called, it appends a line to the trace.
171The format of the trace is customizable, and the exact output
172one will get depends on the options set in
173\fI/sys/kernel/debug/tracing/trace_options\fP (see also the
174\fIREADME\fP file under the same directory). However, it usually
175defaults to something like:
176.INDENT 7.0
177.INDENT 3.5
178.sp
179.nf
180.ft C
181telnet\-470 [001] .N.. 419421.045894: 0x00000001: <formatted msg>
182.ft P
183.fi
184.UNINDENT
185.UNINDENT
186.sp
187In the above:
188.INDENT 7.0
189.INDENT 3.5
190.INDENT 0.0
191.IP \(bu 2
192\fBtelnet\fP is the name of the current task.
193.IP \(bu 2
194\fB470\fP is the PID of the current task.
195.IP \(bu 2
196\fB001\fP is the CPU number on which the task is
197running.
198.IP \(bu 2
199In \fB\&.N..\fP, each character refers to a set of
200options (whether irqs are enabled, scheduling
201options, whether hard/softirqs are running, level of
202preempt_disabled respectively). \fBN\fP means that
203\fBTIF_NEED_RESCHED\fP and \fBPREEMPT_NEED_RESCHED\fP
204are set.
205.IP \(bu 2
206\fB419421.045894\fP is a timestamp.
207.IP \(bu 2
208\fB0x00000001\fP is a fake value used by BPF for the
209instruction pointer register.
210.IP \(bu 2
211\fB<formatted msg>\fP is the message formatted with
212\fIfmt\fP\&.
213.UNINDENT
214.UNINDENT
215.UNINDENT
216.sp
217The conversion specifiers supported by \fIfmt\fP are similar, but
218more limited than for printk(). They are \fB%d\fP, \fB%i\fP,
219\fB%u\fP, \fB%x\fP, \fB%ld\fP, \fB%li\fP, \fB%lu\fP, \fB%lx\fP, \fB%lld\fP,
220\fB%lli\fP, \fB%llu\fP, \fB%llx\fP, \fB%p\fP, \fB%s\fP\&. No modifier (size
221of field, padding with zeroes, etc.) is available, and the
222helper will return \fB\-EINVAL\fP (but print nothing) if it
223encounters an unknown specifier.
224.sp
225Also, note that \fBbpf_trace_printk\fP() is slow, and should
226only be used for debugging purposes. For this reason, a notice
227bloc (spanning several lines) is printed to kernel logs and
228states that the helper should not be used "for production use"
229the first time this helper is used (or more precisely, when
230\fBtrace_printk\fP() buffers are allocated). For passing values
231to user space, perf events should be preferred.
232.TP
233.B Return
234The number of bytes written to the buffer, or a negative error
235in case of failure.
236.UNINDENT
237.TP
238.B \fBu32 bpf_get_prandom_u32(void)\fP
239.INDENT 7.0
240.TP
241.B Description
242Get a pseudo\-random number.
243.sp
244From a security point of view, this helper uses its own
245pseudo\-random internal state, and cannot be used to infer the
246seed of other random functions in the kernel. However, it is
247essential to note that the generator used by the helper is not
248cryptographically secure.
249.TP
250.B Return
251A random 32\-bit unsigned value.
252.UNINDENT
253.TP
254.B \fBu32 bpf_get_smp_processor_id(void)\fP
255.INDENT 7.0
256.TP
257.B Description
258Get the SMP (symmetric multiprocessing) processor id. Note that
259all programs run with preemption disabled, which means that the
260SMP processor id is stable during all the execution of the
261program.
262.TP
263.B Return
264The SMP id of the processor running the program.
265.UNINDENT
266.TP
267.B \fBint bpf_skb_store_bytes(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIoffset\fP\fB, const void *\fP\fIfrom\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
268.INDENT 7.0
269.TP
270.B Description
271Store \fIlen\fP bytes from address \fIfrom\fP into the packet
272associated to \fIskb\fP, at \fIoffset\fP\&. \fIflags\fP are a combination of
273\fBBPF_F_RECOMPUTE_CSUM\fP (automatically recompute the
274checksum for the packet after storing the bytes) and
275\fBBPF_F_INVALIDATE_HASH\fP (set \fIskb\fP\fB\->hash\fP, \fIskb\fP\fB\->swhash\fP and \fIskb\fP\fB\->l4hash\fP to 0).
276.sp
277A call to this helper is susceptible to change the underlaying
278packet buffer. Therefore, at load time, all checks on pointers
279previously done by the verifier are invalidated and must be
280performed again, if the helper is used in combination with
281direct packet access.
282.TP
283.B Return
2840 on success, or a negative error in case of failure.
285.UNINDENT
286.TP
287.B \fBint bpf_l3_csum_replace(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIoffset\fP\fB, u64\fP \fIfrom\fP\fB, u64\fP \fIto\fP\fB, u64\fP \fIsize\fP\fB)\fP
288.INDENT 7.0
289.TP
290.B Description
291Recompute the layer 3 (e.g. IP) checksum for the packet
292associated to \fIskb\fP\&. Computation is incremental, so the helper
293must know the former value of the header field that was
294modified (\fIfrom\fP), the new value of this field (\fIto\fP), and the
295number of bytes (2 or 4) for this field, stored in \fIsize\fP\&.
296Alternatively, it is possible to store the difference between
297the previous and the new values of the header field in \fIto\fP, by
298setting \fIfrom\fP and \fIsize\fP to 0. For both methods, \fIoffset\fP
299indicates the location of the IP checksum within the packet.
300.sp
301This helper works in combination with \fBbpf_csum_diff\fP(),
302which does not update the checksum in\-place, but offers more
303flexibility and can handle sizes larger than 2 or 4 for the
304checksum to update.
305.sp
306A call to this helper is susceptible to change the underlaying
307packet buffer. Therefore, at load time, all checks on pointers
308previously done by the verifier are invalidated and must be
309performed again, if the helper is used in combination with
310direct packet access.
311.TP
312.B Return
3130 on success, or a negative error in case of failure.
314.UNINDENT
315.TP
316.B \fBint bpf_l4_csum_replace(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIoffset\fP\fB, u64\fP \fIfrom\fP\fB, u64\fP \fIto\fP\fB, u64\fP \fIflags\fP\fB)\fP
317.INDENT 7.0
318.TP
319.B Description
320Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
321packet associated to \fIskb\fP\&. Computation is incremental, so the
322helper must know the former value of the header field that was
323modified (\fIfrom\fP), the new value of this field (\fIto\fP), and the
324number of bytes (2 or 4) for this field, stored on the lowest
325four bits of \fIflags\fP\&. Alternatively, it is possible to store
326the difference between the previous and the new values of the
327header field in \fIto\fP, by setting \fIfrom\fP and the four lowest
328bits of \fIflags\fP to 0. For both methods, \fIoffset\fP indicates the
329location of the IP checksum within the packet. In addition to
330the size of the field, \fIflags\fP can be added (bitwise OR) actual
331flags. With \fBBPF_F_MARK_MANGLED_0\fP, a null checksum is left
332untouched (unless \fBBPF_F_MARK_ENFORCE\fP is added as well), and
333for updates resulting in a null checksum the value is set to
334\fBCSUM_MANGLED_0\fP instead. Flag \fBBPF_F_PSEUDO_HDR\fP indicates
335the checksum is to be computed against a pseudo\-header.
336.sp
337This helper works in combination with \fBbpf_csum_diff\fP(),
338which does not update the checksum in\-place, but offers more
339flexibility and can handle sizes larger than 2 or 4 for the
340checksum to update.
341.sp
342A call to this helper is susceptible to change the underlaying
343packet buffer. Therefore, at load time, all checks on pointers
344previously done by the verifier are invalidated and must be
345performed again, if the helper is used in combination with
346direct packet access.
347.TP
348.B Return
3490 on success, or a negative error in case of failure.
350.UNINDENT
351.TP
352.B \fBint bpf_tail_call(void *\fP\fIctx\fP\fB, struct bpf_map *\fP\fIprog_array_map\fP\fB, u32\fP \fIindex\fP\fB)\fP
353.INDENT 7.0
354.TP
355.B Description
356This special helper is used to trigger a "tail call", or in
357other words, to jump into another eBPF program. The same stack
358frame is used (but values on stack and in registers for the
359caller are not accessible to the callee). This mechanism allows
360for program chaining, either for raising the maximum number of
361available eBPF instructions, or to execute given programs in
362conditional blocks. For security reasons, there is an upper
363limit to the number of successive tail calls that can be
364performed.
365.sp
366Upon call of this helper, the program attempts to jump into a
367program referenced at index \fIindex\fP in \fIprog_array_map\fP, a
368special map of type \fBBPF_MAP_TYPE_PROG_ARRAY\fP, and passes
369\fIctx\fP, a pointer to the context.
370.sp
371If the call succeeds, the kernel immediately runs the first
372instruction of the new program. This is not a function call,
373and it never returns to the previous program. If the call
374fails, then the helper has no effect, and the caller continues
375to run its subsequent instructions. A call can fail if the
376destination program for the jump does not exist (i.e. \fIindex\fP
377is superior to the number of entries in \fIprog_array_map\fP), or
378if the maximum number of tail calls has been reached for this
379chain of programs. This limit is defined in the kernel by the
380macro \fBMAX_TAIL_CALL_CNT\fP (not accessible to user space),
381which is currently set to 32.
382.TP
383.B Return
3840 on success, or a negative error in case of failure.
385.UNINDENT
386.TP
387.B \fBint bpf_clone_redirect(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIifindex\fP\fB, u64\fP \fIflags\fP\fB)\fP
388.INDENT 7.0
389.TP
390.B Description
391Clone and redirect the packet associated to \fIskb\fP to another
392net device of index \fIifindex\fP\&. Both ingress and egress
393interfaces can be used for redirection. The \fBBPF_F_INGRESS\fP
394value in \fIflags\fP is used to make the distinction (ingress path
395is selected if the flag is present, egress path otherwise).
396This is the only flag supported for now.
397.sp
398In comparison with \fBbpf_redirect\fP() helper,
399\fBbpf_clone_redirect\fP() has the associated cost of
400duplicating the packet buffer, but this can be executed out of
401the eBPF program. Conversely, \fBbpf_redirect\fP() is more
402efficient, but it is handled through an action code where the
403redirection happens only after the eBPF program has returned.
404.sp
405A call to this helper is susceptible to change the underlaying
406packet buffer. Therefore, at load time, all checks on pointers
407previously done by the verifier are invalidated and must be
408performed again, if the helper is used in combination with
409direct packet access.
410.TP
411.B Return
4120 on success, or a negative error in case of failure.
413.UNINDENT
414.TP
415.B \fBu64 bpf_get_current_pid_tgid(void)\fP
416.INDENT 7.0
417.TP
418.B Return
419A 64\-bit integer containing the current tgid and pid, and
420created as such:
421\fIcurrent_task\fP\fB\->tgid << 32 |\fP
422\fIcurrent_task\fP\fB\->pid\fP\&.
423.UNINDENT
424.TP
425.B \fBu64 bpf_get_current_uid_gid(void)\fP
426.INDENT 7.0
427.TP
428.B Return
429A 64\-bit integer containing the current GID and UID, and
430created as such: \fIcurrent_gid\fP \fB<< 32 |\fP \fIcurrent_uid\fP\&.
431.UNINDENT
432.TP
433.B \fBint bpf_get_current_comm(char *\fP\fIbuf\fP\fB, u32\fP \fIsize_of_buf\fP\fB)\fP
434.INDENT 7.0
435.TP
436.B Description
437Copy the \fBcomm\fP attribute of the current task into \fIbuf\fP of
438\fIsize_of_buf\fP\&. The \fBcomm\fP attribute contains the name of
439the executable (excluding the path) for the current task. The
440\fIsize_of_buf\fP must be strictly positive. On success, the
441helper makes sure that the \fIbuf\fP is NUL\-terminated. On failure,
442it is filled with zeroes.
443.TP
444.B Return
4450 on success, or a negative error in case of failure.
446.UNINDENT
447.TP
448.B \fBu32 bpf_get_cgroup_classid(struct sk_buff *\fP\fIskb\fP\fB)\fP
449.INDENT 7.0
450.TP
451.B Description
452Retrieve the classid for the current task, i.e. for the net_cls
453cgroup to which \fIskb\fP belongs.
454.sp
455This helper can be used on TC egress path, but not on ingress.
456.sp
457The net_cls cgroup provides an interface to tag network packets
458based on a user\-provided identifier for all traffic coming from
459the tasks belonging to the related cgroup. See also the related
460kernel documentation, available from the Linux sources in file
461\fIDocumentation/cgroup\-v1/net_cls.txt\fP\&.
462.sp
463The Linux kernel has two versions for cgroups: there are
464cgroups v1 and cgroups v2. Both are available to users, who can
465use a mixture of them, but note that the net_cls cgroup is for
466cgroup v1 only. This makes it incompatible with BPF programs
467run on cgroups, which is a cgroup\-v2\-only feature (a socket can
468only hold data for one version of cgroups at a time).
469.sp
470This helper is only available is the kernel was compiled with
471the \fBCONFIG_CGROUP_NET_CLASSID\fP configuration option set to
472"\fBy\fP" or to "\fBm\fP".
473.TP
474.B Return
475The classid, or 0 for the default unconfigured classid.
476.UNINDENT
477.TP
478.B \fBint bpf_skb_vlan_push(struct sk_buff *\fP\fIskb\fP\fB, __be16\fP \fIvlan_proto\fP\fB, u16\fP \fIvlan_tci\fP\fB)\fP
479.INDENT 7.0
480.TP
481.B Description
482Push a \fIvlan_tci\fP (VLAN tag control information) of protocol
483\fIvlan_proto\fP to the packet associated to \fIskb\fP, then update
484the checksum. Note that if \fIvlan_proto\fP is different from
485\fBETH_P_8021Q\fP and \fBETH_P_8021AD\fP, it is considered to
486be \fBETH_P_8021Q\fP\&.
487.sp
488A call to this helper is susceptible to change the underlaying
489packet buffer. Therefore, at load time, all checks on pointers
490previously done by the verifier are invalidated and must be
491performed again, if the helper is used in combination with
492direct packet access.
493.TP
494.B Return
4950 on success, or a negative error in case of failure.
496.UNINDENT
497.TP
498.B \fBint bpf_skb_vlan_pop(struct sk_buff *\fP\fIskb\fP\fB)\fP
499.INDENT 7.0
500.TP
501.B Description
502Pop a VLAN header from the packet associated to \fIskb\fP\&.
503.sp
504A call to this helper is susceptible to change the underlaying
505packet buffer. Therefore, at load time, all checks on pointers
506previously done by the verifier are invalidated and must be
507performed again, if the helper is used in combination with
508direct packet access.
509.TP
510.B Return
5110 on success, or a negative error in case of failure.
512.UNINDENT
513.TP
514.B \fBint bpf_skb_get_tunnel_key(struct sk_buff *\fP\fIskb\fP\fB, struct bpf_tunnel_key *\fP\fIkey\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
515.INDENT 7.0
516.TP
517.B Description
518Get tunnel metadata. This helper takes a pointer \fIkey\fP to an
519empty \fBstruct bpf_tunnel_key\fP of \fBsize\fP, that will be
520filled with tunnel metadata for the packet associated to \fIskb\fP\&.
521The \fIflags\fP can be set to \fBBPF_F_TUNINFO_IPV6\fP, which
522indicates that the tunnel is based on IPv6 protocol instead of
523IPv4.
524.sp
525The \fBstruct bpf_tunnel_key\fP is an object that generalizes the
526principal parameters used by various tunneling protocols into a
527single struct. This way, it can be used to easily make a
528decision based on the contents of the encapsulation header,
529"summarized" in this struct. In particular, it holds the IP
530address of the remote end (IPv4 or IPv6, depending on the case)
531in \fIkey\fP\fB\->remote_ipv4\fP or \fIkey\fP\fB\->remote_ipv6\fP\&. Also,
532this struct exposes the \fIkey\fP\fB\->tunnel_id\fP, which is
533generally mapped to a VNI (Virtual Network Identifier), making
534it programmable together with the \fBbpf_skb_set_tunnel_key\fP() helper.
535.sp
536Let\(aqs imagine that the following code is part of a program
537attached to the TC ingress interface, on one end of a GRE
538tunnel, and is supposed to filter out all messages coming from
539remote ends with IPv4 address other than 10.0.0.1:
540.INDENT 7.0
541.INDENT 3.5
542.sp
543.nf
544.ft C
545int ret;
546struct bpf_tunnel_key key = {};
547
548ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
549if (ret < 0)
550 return TC_ACT_SHOT; // drop packet
551
552if (key.remote_ipv4 != 0x0a000001)
553 return TC_ACT_SHOT; // drop packet
554
555return TC_ACT_OK; // accept packet
556.ft P
557.fi
558.UNINDENT
559.UNINDENT
560.sp
561This interface can also be used with all encapsulation devices
562that can operate in "collect metadata" mode: instead of having
563one network device per specific configuration, the "collect
564metadata" mode only requires a single device where the
565configuration can be extracted from this helper.
566.sp
567This can be used together with various tunnels such as VXLan,
568Geneve, GRE or IP in IP (IPIP).
569.TP
570.B Return
5710 on success, or a negative error in case of failure.
572.UNINDENT
573.TP
574.B \fBint bpf_skb_set_tunnel_key(struct sk_buff *\fP\fIskb\fP\fB, struct bpf_tunnel_key *\fP\fIkey\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
575.INDENT 7.0
576.TP
577.B Description
578Populate tunnel metadata for packet associated to \fIskb.\fP The
579tunnel metadata is set to the contents of \fIkey\fP, of \fIsize\fP\&. The
580\fIflags\fP can be set to a combination of the following values:
581.INDENT 7.0
582.TP
583.B \fBBPF_F_TUNINFO_IPV6\fP
584Indicate that the tunnel is based on IPv6 protocol
585instead of IPv4.
586.TP
587.B \fBBPF_F_ZERO_CSUM_TX\fP
588For IPv4 packets, add a flag to tunnel metadata
589indicating that checksum computation should be skipped
590and checksum set to zeroes.
591.TP
592.B \fBBPF_F_DONT_FRAGMENT\fP
593Add a flag to tunnel metadata indicating that the
594packet should not be fragmented.
595.TP
596.B \fBBPF_F_SEQ_NUMBER\fP
597Add a flag to tunnel metadata indicating that a
598sequence number should be added to tunnel header before
599sending the packet. This flag was added for GRE
600encapsulation, but might be used with other protocols
601as well in the future.
602.UNINDENT
603.sp
604Here is a typical usage on the transmit path:
605.INDENT 7.0
606.INDENT 3.5
607.sp
608.nf
609.ft C
610struct bpf_tunnel_key key;
611 populate key ...
612bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
613bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
614.ft P
615.fi
616.UNINDENT
617.UNINDENT
618.sp
619See also the description of the \fBbpf_skb_get_tunnel_key\fP()
620helper for additional information.
621.TP
622.B Return
6230 on success, or a negative error in case of failure.
624.UNINDENT
625.TP
626.B \fBu64 bpf_perf_event_read(struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB)\fP
627.INDENT 7.0
628.TP
629.B Description
630Read the value of a perf event counter. This helper relies on a
631\fImap\fP of type \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. The nature of
632the perf event counter is selected when \fImap\fP is updated with
633perf event file descriptors. The \fImap\fP is an array whose size
634is the number of available CPUs, and each cell contains a value
635relative to one CPU. The value to retrieve is indicated by
636\fIflags\fP, that contains the index of the CPU to look up, masked
637with \fBBPF_F_INDEX_MASK\fP\&. Alternatively, \fIflags\fP can be set to
638\fBBPF_F_CURRENT_CPU\fP to indicate that the value for the
639current CPU should be retrieved.
640.sp
641Note that before Linux 4.13, only hardware perf event can be
642retrieved.
643.sp
644Also, be aware that the newer helper
645\fBbpf_perf_event_read_value\fP() is recommended over
646\fBbpf_perf_event_read\fP() in general. The latter has some ABI
647quirks where error and counter value are used as a return code
648(which is wrong to do since ranges may overlap). This issue is
649fixed with \fBbpf_perf_event_read_value\fP(), which at the same
650time provides more features over the \fBbpf_perf_event_read\fP() interface. Please refer to the description of
651\fBbpf_perf_event_read_value\fP() for details.
652.TP
653.B Return
654The value of the perf event counter read from the map, or a
655negative error code in case of failure.
656.UNINDENT
657.TP
658.B \fBint bpf_redirect(u32\fP \fIifindex\fP\fB, u64\fP \fIflags\fP\fB)\fP
659.INDENT 7.0
660.TP
661.B Description
662Redirect the packet to another net device of index \fIifindex\fP\&.
663This helper is somewhat similar to \fBbpf_clone_redirect\fP(), except that the packet is not cloned, which provides
664increased performance.
665.sp
666Except for XDP, both ingress and egress interfaces can be used
667for redirection. The \fBBPF_F_INGRESS\fP value in \fIflags\fP is used
668to make the distinction (ingress path is selected if the flag
669is present, egress path otherwise). Currently, XDP only
670supports redirection to the egress interface, and accepts no
671flag at all.
672.sp
673The same effect can be attained with the more generic
674\fBbpf_redirect_map\fP(), which requires specific maps to be
675used but offers better performance.
676.TP
677.B Return
678For XDP, the helper returns \fBXDP_REDIRECT\fP on success or
679\fBXDP_ABORTED\fP on error. For other program types, the values
680are \fBTC_ACT_REDIRECT\fP on success or \fBTC_ACT_SHOT\fP on
681error.
682.UNINDENT
683.TP
684.B \fBu32 bpf_get_route_realm(struct sk_buff *\fP\fIskb\fP\fB)\fP
685.INDENT 7.0
686.TP
687.B Description
688Retrieve the realm or the route, that is to say the
689\fBtclassid\fP field of the destination for the \fIskb\fP\&. The
690indentifier retrieved is a user\-provided tag, similar to the
691one used with the net_cls cgroup (see description for
692\fBbpf_get_cgroup_classid\fP() helper), but here this tag is
693held by a route (a destination entry), not by a task.
694.sp
695Retrieving this identifier works with the clsact TC egress hook
696(see also \fBtc\-bpf(8)\fP), or alternatively on conventional
697classful egress qdiscs, but not on TC ingress path. In case of
698clsact TC egress hook, this has the advantage that, internally,
699the destination entry has not been dropped yet in the transmit
700path. Therefore, the destination entry does not need to be
701artificially held via \fBnetif_keep_dst\fP() for a classful
702qdisc until the \fIskb\fP is freed.
703.sp
704This helper is available only if the kernel was compiled with
705\fBCONFIG_IP_ROUTE_CLASSID\fP configuration option.
706.TP
707.B Return
708The realm of the route for the packet associated to \fIskb\fP, or 0
709if none was found.
710.UNINDENT
711.TP
712.B \fBint bpf_perf_event_output(struct pt_reg *\fP\fIctx\fP\fB, struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB, void *\fP\fIdata\fP\fB, u64\fP \fIsize\fP\fB)\fP
713.INDENT 7.0
714.TP
715.B Description
716Write raw \fIdata\fP blob into a special BPF perf event held by
717\fImap\fP of type \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. This perf
718event must have the following attributes: \fBPERF_SAMPLE_RAW\fP
719as \fBsample_type\fP, \fBPERF_TYPE_SOFTWARE\fP as \fBtype\fP, and
720\fBPERF_COUNT_SW_BPF_OUTPUT\fP as \fBconfig\fP\&.
721.sp
722The \fIflags\fP are used to indicate the index in \fImap\fP for which
723the value must be put, masked with \fBBPF_F_INDEX_MASK\fP\&.
724Alternatively, \fIflags\fP can be set to \fBBPF_F_CURRENT_CPU\fP
725to indicate that the index of the current CPU core should be
726used.
727.sp
728The value to write, of \fIsize\fP, is passed through eBPF stack and
729pointed by \fIdata\fP\&.
730.sp
731The context of the program \fIctx\fP needs also be passed to the
732helper.
733.sp
734On user space, a program willing to read the values needs to
735call \fBperf_event_open\fP() on the perf event (either for
736one or for all CPUs) and to store the file descriptor into the
737\fImap\fP\&. This must be done before the eBPF program can send data
738into it. An example is available in file
739\fIsamples/bpf/trace_output_user.c\fP in the Linux kernel source
740tree (the eBPF program counterpart is in
741\fIsamples/bpf/trace_output_kern.c\fP).
742.sp
743\fBbpf_perf_event_output\fP() achieves better performance
744than \fBbpf_trace_printk\fP() for sharing data with user
745space, and is much better suitable for streaming data from eBPF
746programs.
747.sp
748Note that this helper is not restricted to tracing use cases
749and can be used with programs attached to TC or XDP as well,
750where it allows for passing data to user space listeners. Data
751can be:
752.INDENT 7.0
753.IP \(bu 2
754Only custom structs,
755.IP \(bu 2
756Only the packet payload, or
757.IP \(bu 2
758A combination of both.
759.UNINDENT
760.TP
761.B Return
7620 on success, or a negative error in case of failure.
763.UNINDENT
764.TP
765.B \fBint bpf_skb_load_bytes(const struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIoffset\fP\fB, void *\fP\fIto\fP\fB, u32\fP \fIlen\fP\fB)\fP
766.INDENT 7.0
767.TP
768.B Description
769This helper was provided as an easy way to load data from a
770packet. It can be used to load \fIlen\fP bytes from \fIoffset\fP from
771the packet associated to \fIskb\fP, into the buffer pointed by
772\fIto\fP\&.
773.sp
774Since Linux 4.7, usage of this helper has mostly been replaced
775by "direct packet access", enabling packet data to be
776manipulated with \fIskb\fP\fB\->data\fP and \fIskb\fP\fB\->data_end\fP
777pointing respectively to the first byte of packet data and to
778the byte after the last byte of packet data. However, it
779remains useful if one wishes to read large quantities of data
780at once from a packet into the eBPF stack.
781.TP
782.B Return
7830 on success, or a negative error in case of failure.
784.UNINDENT
785.TP
786.B \fBint bpf_get_stackid(struct pt_reg *\fP\fIctx\fP\fB, struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB)\fP
787.INDENT 7.0
788.TP
789.B Description
790Walk a user or a kernel stack and return its id. To achieve
791this, the helper needs \fIctx\fP, which is a pointer to the context
792on which the tracing program is executed, and a pointer to a
793\fImap\fP of type \fBBPF_MAP_TYPE_STACK_TRACE\fP\&.
794.sp
795The last argument, \fIflags\fP, holds the number of stack frames to
796skip (from 0 to 255), masked with
797\fBBPF_F_SKIP_FIELD_MASK\fP\&. The next bits can be used to set
798a combination of the following flags:
799.INDENT 7.0
800.TP
801.B \fBBPF_F_USER_STACK\fP
802Collect a user space stack instead of a kernel stack.
803.TP
804.B \fBBPF_F_FAST_STACK_CMP\fP
805Compare stacks by hash only.
806.TP
807.B \fBBPF_F_REUSE_STACKID\fP
808If two different stacks hash into the same \fIstackid\fP,
809discard the old one.
810.UNINDENT
811.sp
812The stack id retrieved is a 32 bit long integer handle which
813can be further combined with other data (including other stack
814ids) and used as a key into maps. This can be useful for
815generating a variety of graphs (such as flame graphs or off\-cpu
816graphs).
817.sp
818For walking a stack, this helper is an improvement over
819\fBbpf_probe_read\fP(), which can be used with unrolled loops
820but is not efficient and consumes a lot of eBPF instructions.
821Instead, \fBbpf_get_stackid\fP() can collect up to
822\fBPERF_MAX_STACK_DEPTH\fP both kernel and user frames. Note that
823this limit can be controlled with the \fBsysctl\fP program, and
824that it should be manually increased in order to profile long
825user stacks (such as stacks for Java programs). To do so, use:
826.INDENT 7.0
827.INDENT 3.5
828.sp
829.nf
830.ft C
831# sysctl kernel.perf_event_max_stack=<new value>
832.ft P
833.fi
834.UNINDENT
835.UNINDENT
836.TP
837.B Return
838The positive or null stack id on success, or a negative error
839in case of failure.
840.UNINDENT
841.TP
842.B \fBs64 bpf_csum_diff(__be32 *\fP\fIfrom\fP\fB, u32\fP \fIfrom_size\fP\fB, __be32 *\fP\fIto\fP\fB, u32\fP \fIto_size\fP\fB, __wsum\fP \fIseed\fP\fB)\fP
843.INDENT 7.0
844.TP
845.B Description
846Compute a checksum difference, from the raw buffer pointed by
847\fIfrom\fP, of length \fIfrom_size\fP (that must be a multiple of 4),
848towards the raw buffer pointed by \fIto\fP, of size \fIto_size\fP
849(same remark). An optional \fIseed\fP can be added to the value
850(this can be cascaded, the seed may come from a previous call
851to the helper).
852.sp
853This is flexible enough to be used in several ways:
854.INDENT 7.0
855.IP \(bu 2
856With \fIfrom_size\fP == 0, \fIto_size\fP > 0 and \fIseed\fP set to
857checksum, it can be used when pushing new data.
858.IP \(bu 2
859With \fIfrom_size\fP > 0, \fIto_size\fP == 0 and \fIseed\fP set to
860checksum, it can be used when removing data from a packet.
861.IP \(bu 2
862With \fIfrom_size\fP > 0, \fIto_size\fP > 0 and \fIseed\fP set to 0, it
863can be used to compute a diff. Note that \fIfrom_size\fP and
864\fIto_size\fP do not need to be equal.
865.UNINDENT
866.sp
867This helper can be used in combination with
868\fBbpf_l3_csum_replace\fP() and \fBbpf_l4_csum_replace\fP(), to
869which one can feed in the difference computed with
870\fBbpf_csum_diff\fP().
871.TP
872.B Return
873The checksum result, or a negative error code in case of
874failure.
875.UNINDENT
876.TP
877.B \fBint bpf_skb_get_tunnel_opt(struct sk_buff *\fP\fIskb\fP\fB, u8 *\fP\fIopt\fP\fB, u32\fP \fIsize\fP\fB)\fP
878.INDENT 7.0
879.TP
880.B Description
881Retrieve tunnel options metadata for the packet associated to
882\fIskb\fP, and store the raw tunnel option data to the buffer \fIopt\fP
883of \fIsize\fP\&.
884.sp
885This helper can be used with encapsulation devices that can
886operate in "collect metadata" mode (please refer to the related
887note in the description of \fBbpf_skb_get_tunnel_key\fP() for
888more details). A particular example where this can be used is
889in combination with the Geneve encapsulation protocol, where it
890allows for pushing (with \fBbpf_skb_get_tunnel_opt\fP() helper)
891and retrieving arbitrary TLVs (Type\-Length\-Value headers) from
892the eBPF program. This allows for full customization of these
893headers.
894.TP
895.B Return
896The size of the option data retrieved.
897.UNINDENT
898.TP
899.B \fBint bpf_skb_set_tunnel_opt(struct sk_buff *\fP\fIskb\fP\fB, u8 *\fP\fIopt\fP\fB, u32\fP \fIsize\fP\fB)\fP
900.INDENT 7.0
901.TP
902.B Description
903Set tunnel options metadata for the packet associated to \fIskb\fP
904to the option data contained in the raw buffer \fIopt\fP of \fIsize\fP\&.
905.sp
906See also the description of the \fBbpf_skb_get_tunnel_opt\fP()
907helper for additional information.
908.TP
909.B Return
9100 on success, or a negative error in case of failure.
911.UNINDENT
912.TP
913.B \fBint bpf_skb_change_proto(struct sk_buff *\fP\fIskb\fP\fB, __be16\fP \fIproto\fP\fB, u64\fP \fIflags\fP\fB)\fP
914.INDENT 7.0
915.TP
916.B Description
917Change the protocol of the \fIskb\fP to \fIproto\fP\&. Currently
918supported are transition from IPv4 to IPv6, and from IPv6 to
919IPv4. The helper takes care of the groundwork for the
920transition, including resizing the socket buffer. The eBPF
921program is expected to fill the new headers, if any, via
922\fBskb_store_bytes\fP() and to recompute the checksums with
923\fBbpf_l3_csum_replace\fP() and \fBbpf_l4_csum_replace\fP(). The main case for this helper is to perform NAT64
924operations out of an eBPF program.
925.sp
926Internally, the GSO type is marked as dodgy so that headers are
927checked and segments are recalculated by the GSO/GRO engine.
928The size for GSO target is adapted as well.
929.sp
930All values for \fIflags\fP are reserved for future usage, and must
931be left at zero.
932.sp
933A call to this helper is susceptible to change the underlaying
934packet buffer. Therefore, at load time, all checks on pointers
935previously done by the verifier are invalidated and must be
936performed again, if the helper is used in combination with
937direct packet access.
938.TP
939.B Return
9400 on success, or a negative error in case of failure.
941.UNINDENT
942.TP
943.B \fBint bpf_skb_change_type(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fItype\fP\fB)\fP
944.INDENT 7.0
945.TP
946.B Description
947Change the packet type for the packet associated to \fIskb\fP\&. This
948comes down to setting \fIskb\fP\fB\->pkt_type\fP to \fItype\fP, except
949the eBPF program does not have a write access to \fIskb\fP\fB\->pkt_type\fP beside this helper. Using a helper here allows
950for graceful handling of errors.
951.sp
952The major use case is to change incoming \fIskb*s to
953**PACKET_HOST*\fP in a programmatic way instead of having to
954recirculate via \fBredirect\fP(..., \fBBPF_F_INGRESS\fP), for
955example.
956.sp
957Note that \fItype\fP only allows certain values. At this time, they
958are:
959.INDENT 7.0
960.TP
961.B \fBPACKET_HOST\fP
962Packet is for us.
963.TP
964.B \fBPACKET_BROADCAST\fP
965Send packet to all.
966.TP
967.B \fBPACKET_MULTICAST\fP
968Send packet to group.
969.TP
970.B \fBPACKET_OTHERHOST\fP
971Send packet to someone else.
972.UNINDENT
973.TP
974.B Return
9750 on success, or a negative error in case of failure.
976.UNINDENT
977.TP
978.B \fBint bpf_skb_under_cgroup(struct sk_buff *\fP\fIskb\fP\fB, struct bpf_map *\fP\fImap\fP\fB, u32\fP \fIindex\fP\fB)\fP
979.INDENT 7.0
980.TP
981.B Description
982Check whether \fIskb\fP is a descendant of the cgroup2 held by
983\fImap\fP of type \fBBPF_MAP_TYPE_CGROUP_ARRAY\fP, at \fIindex\fP\&.
984.TP
985.B Return
986The return value depends on the result of the test, and can be:
987.INDENT 7.0
988.IP \(bu 2
9890, if the \fIskb\fP failed the cgroup2 descendant test.
990.IP \(bu 2
9911, if the \fIskb\fP succeeded the cgroup2 descendant test.
992.IP \(bu 2
993A negative error code, if an error occurred.
994.UNINDENT
995.UNINDENT
996.TP
997.B \fBu32 bpf_get_hash_recalc(struct sk_buff *\fP\fIskb\fP\fB)\fP
998.INDENT 7.0
999.TP
1000.B Description
1001Retrieve the hash of the packet, \fIskb\fP\fB\->hash\fP\&. If it is
1002not set, in particular if the hash was cleared due to mangling,
1003recompute this hash. Later accesses to the hash can be done
1004directly with \fIskb\fP\fB\->hash\fP\&.
1005.sp
1006Calling \fBbpf_set_hash_invalid\fP(), changing a packet
1007prototype with \fBbpf_skb_change_proto\fP(), or calling
1008\fBbpf_skb_store_bytes\fP() with the
1009\fBBPF_F_INVALIDATE_HASH\fP are actions susceptible to clear
1010the hash and to trigger a new computation for the next call to
1011\fBbpf_get_hash_recalc\fP().
1012.TP
1013.B Return
1014The 32\-bit hash.
1015.UNINDENT
1016.TP
1017.B \fBu64 bpf_get_current_task(void)\fP
1018.INDENT 7.0
1019.TP
1020.B Return
1021A pointer to the current task struct.
1022.UNINDENT
1023.TP
1024.B \fBint bpf_probe_write_user(void *\fP\fIdst\fP\fB, const void *\fP\fIsrc\fP\fB, u32\fP \fIlen\fP\fB)\fP
1025.INDENT 7.0
1026.TP
1027.B Description
1028Attempt in a safe way to write \fIlen\fP bytes from the buffer
1029\fIsrc\fP to \fIdst\fP in memory. It only works for threads that are in
1030user context, and \fIdst\fP must be a valid user space address.
1031.sp
1032This helper should not be used to implement any kind of
1033security mechanism because of TOC\-TOU attacks, but rather to
1034debug, divert, and manipulate execution of semi\-cooperative
1035processes.
1036.sp
1037Keep in mind that this feature is meant for experiments, and it
1038has a risk of crashing the system and running programs.
1039Therefore, when an eBPF program using this helper is attached,
1040a warning including PID and process name is printed to kernel
1041logs.
1042.TP
1043.B Return
10440 on success, or a negative error in case of failure.
1045.UNINDENT
1046.TP
1047.B \fBint bpf_current_task_under_cgroup(struct bpf_map *\fP\fImap\fP\fB, u32\fP \fIindex\fP\fB)\fP
1048.INDENT 7.0
1049.TP
1050.B Description
1051Check whether the probe is being run is the context of a given
1052subset of the cgroup2 hierarchy. The cgroup2 to test is held by
1053\fImap\fP of type \fBBPF_MAP_TYPE_CGROUP_ARRAY\fP, at \fIindex\fP\&.
1054.TP
1055.B Return
1056The return value depends on the result of the test, and can be:
1057.INDENT 7.0
1058.IP \(bu 2
10590, if the \fIskb\fP task belongs to the cgroup2.
1060.IP \(bu 2
10611, if the \fIskb\fP task does not belong to the cgroup2.
1062.IP \(bu 2
1063A negative error code, if an error occurred.
1064.UNINDENT
1065.UNINDENT
1066.TP
1067.B \fBint bpf_skb_change_tail(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
1068.INDENT 7.0
1069.TP
1070.B Description
1071Resize (trim or grow) the packet associated to \fIskb\fP to the
1072new \fIlen\fP\&. The \fIflags\fP are reserved for future usage, and must
1073be left at zero.
1074.sp
1075The basic idea is that the helper performs the needed work to
1076change the size of the packet, then the eBPF program rewrites
1077the rest via helpers like \fBbpf_skb_store_bytes\fP(),
1078\fBbpf_l3_csum_replace\fP(), \fBbpf_l3_csum_replace\fP()
1079and others. This helper is a slow path utility intended for
1080replies with control messages. And because it is targeted for
1081slow path, the helper itself can afford to be slow: it
1082implicitly linearizes, unclones and drops offloads from the
1083\fIskb\fP\&.
1084.sp
1085A call to this helper is susceptible to change the underlaying
1086packet buffer. Therefore, at load time, all checks on pointers
1087previously done by the verifier are invalidated and must be
1088performed again, if the helper is used in combination with
1089direct packet access.
1090.TP
1091.B Return
10920 on success, or a negative error in case of failure.
1093.UNINDENT
1094.TP
1095.B \fBint bpf_skb_pull_data(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIlen\fP\fB)\fP
1096.INDENT 7.0
1097.TP
1098.B Description
1099Pull in non\-linear data in case the \fIskb\fP is non\-linear and not
1100all of \fIlen\fP are part of the linear section. Make \fIlen\fP bytes
1101from \fIskb\fP readable and writable. If a zero value is passed for
1102\fIlen\fP, then the whole length of the \fIskb\fP is pulled.
1103.sp
1104This helper is only needed for reading and writing with direct
1105packet access.
1106.sp
1107For direct packet access, testing that offsets to access
1108are within packet boundaries (test on \fIskb\fP\fB\->data_end\fP) is
1109susceptible to fail if offsets are invalid, or if the requested
1110data is in non\-linear parts of the \fIskb\fP\&. On failure the
1111program can just bail out, or in the case of a non\-linear
1112buffer, use a helper to make the data available. The
1113\fBbpf_skb_load_bytes\fP() helper is a first solution to access
1114the data. Another one consists in using \fBbpf_skb_pull_data\fP
1115to pull in once the non\-linear parts, then retesting and
1116eventually access the data.
1117.sp
1118At the same time, this also makes sure the \fIskb\fP is uncloned,
1119which is a necessary condition for direct write. As this needs
1120to be an invariant for the write part only, the verifier
1121detects writes and adds a prologue that is calling
1122\fBbpf_skb_pull_data()\fP to effectively unclone the \fIskb\fP from
1123the very beginning in case it is indeed cloned.
1124.sp
1125A call to this helper is susceptible to change the underlaying
1126packet buffer. Therefore, at load time, all checks on pointers
1127previously done by the verifier are invalidated and must be
1128performed again, if the helper is used in combination with
1129direct packet access.
1130.TP
1131.B Return
11320 on success, or a negative error in case of failure.
1133.UNINDENT
1134.TP
1135.B \fBs64 bpf_csum_update(struct sk_buff *\fP\fIskb\fP\fB, __wsum\fP \fIcsum\fP\fB)\fP
1136.INDENT 7.0
1137.TP
1138.B Description
1139Add the checksum \fIcsum\fP into \fIskb\fP\fB\->csum\fP in case the
1140driver has supplied a checksum for the entire packet into that
1141field. Return an error otherwise. This helper is intended to be
1142used in combination with \fBbpf_csum_diff\fP(), in particular
1143when the checksum needs to be updated after data has been
1144written into the packet through direct packet access.
1145.TP
1146.B Return
1147The checksum on success, or a negative error code in case of
1148failure.
1149.UNINDENT
1150.TP
1151.B \fBvoid bpf_set_hash_invalid(struct sk_buff *\fP\fIskb\fP\fB)\fP
1152.INDENT 7.0
1153.TP
1154.B Description
1155Invalidate the current \fIskb\fP\fB\->hash\fP\&. It can be used after
1156mangling on headers through direct packet access, in order to
1157indicate that the hash is outdated and to trigger a
1158recalculation the next time the kernel tries to access this
1159hash or when the \fBbpf_get_hash_recalc\fP() helper is called.
1160.UNINDENT
1161.TP
1162.B \fBint bpf_get_numa_node_id(void)\fP
1163.INDENT 7.0
1164.TP
1165.B Description
1166Return the id of the current NUMA node. The primary use case
1167for this helper is the selection of sockets for the local NUMA
1168node, when the program is attached to sockets using the
1169\fBSO_ATTACH_REUSEPORT_EBPF\fP option (see also \fBsocket(7)\fP),
1170but the helper is also available to other eBPF program types,
1171similarly to \fBbpf_get_smp_processor_id\fP().
1172.TP
1173.B Return
1174The id of current NUMA node.
1175.UNINDENT
1176.TP
1177.B \fBint bpf_skb_change_head(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
1178.INDENT 7.0
1179.TP
1180.B Description
1181Grows headroom of packet associated to \fIskb\fP and adjusts the
1182offset of the MAC header accordingly, adding \fIlen\fP bytes of
1183space. It automatically extends and reallocates memory as
1184required.
1185.sp
1186This helper can be used on a layer 3 \fIskb\fP to push a MAC header
1187for redirection into a layer 2 device.
1188.sp
1189All values for \fIflags\fP are reserved for future usage, and must
1190be left at zero.
1191.sp
1192A call to this helper is susceptible to change the underlaying
1193packet buffer. Therefore, at load time, all checks on pointers
1194previously done by the verifier are invalidated and must be
1195performed again, if the helper is used in combination with
1196direct packet access.
1197.TP
1198.B Return
11990 on success, or a negative error in case of failure.
1200.UNINDENT
1201.TP
1202.B \fBint bpf_xdp_adjust_head(struct xdp_buff *\fP\fIxdp_md\fP\fB, int\fP \fIdelta\fP\fB)\fP
1203.INDENT 7.0
1204.TP
1205.B Description
1206Adjust (move) \fIxdp_md\fP\fB\->data\fP by \fIdelta\fP bytes. Note that
1207it is possible to use a negative value for \fIdelta\fP\&. This helper
1208can be used to prepare the packet for pushing or popping
1209headers.
1210.sp
1211A call to this helper is susceptible to change the underlaying
1212packet buffer. Therefore, at load time, all checks on pointers
1213previously done by the verifier are invalidated and must be
1214performed again, if the helper is used in combination with
1215direct packet access.
1216.TP
1217.B Return
12180 on success, or a negative error in case of failure.
1219.UNINDENT
1220.TP
1221.B \fBint bpf_probe_read_str(void *\fP\fIdst\fP\fB, int\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
1222.INDENT 7.0
1223.TP
1224.B Description
1225Copy a NUL terminated string from an unsafe address
1226\fIunsafe_ptr\fP to \fIdst\fP\&. The \fIsize\fP should include the
1227terminating NUL byte. In case the string length is smaller than
1228\fIsize\fP, the target is not padded with further NUL bytes. If the
1229string length is larger than \fIsize\fP, just \fIsize\fP\-1 bytes are
1230copied and the last byte is set to NUL.
1231.sp
1232On success, the length of the copied string is returned. This
1233makes this helper useful in tracing programs for reading
1234strings, and more importantly to get its length at runtime. See
1235the following snippet:
1236.INDENT 7.0
1237.INDENT 3.5
1238.sp
1239.nf
1240.ft C
1241SEC("kprobe/sys_open")
1242void bpf_sys_open(struct pt_regs *ctx)
1243{
1244 char buf[PATHLEN]; // PATHLEN is defined to 256
1245 int res = bpf_probe_read_str(buf, sizeof(buf),
1246 ctx\->di);
1247
1248 // Consume buf, for example push it to
1249 // userspace via bpf_perf_event_output(); we
1250 // can use res (the string length) as event
1251 // size, after checking its boundaries.
1252}
1253.ft P
1254.fi
1255.UNINDENT
1256.UNINDENT
1257.sp
1258In comparison, using \fBbpf_probe_read()\fP helper here instead
1259to read the string would require to estimate the length at
1260compile time, and would often result in copying more memory
1261than necessary.
1262.sp
1263Another useful use case is when parsing individual process
1264arguments or individual environment variables navigating
1265\fIcurrent\fP\fB\->mm\->arg_start\fP and \fIcurrent\fP\fB\->mm\->env_start\fP: using this helper and the return value,
1266one can quickly iterate at the right offset of the memory area.
1267.TP
1268.B Return
1269On success, the strictly positive length of the string,
1270including the trailing NUL character. On error, a negative
1271value.
1272.UNINDENT
1273.TP
1274.B \fBu64 bpf_get_socket_cookie(struct sk_buff *\fP\fIskb\fP\fB)\fP
1275.INDENT 7.0
1276.TP
1277.B Description
1278If the \fBstruct sk_buff\fP pointed by \fIskb\fP has a known socket,
1279retrieve the cookie (generated by the kernel) of this socket.
1280If no cookie has been set yet, generate a new cookie. Once
1281generated, the socket cookie remains stable for the life of the
1282socket. This helper can be useful for monitoring per socket
1283networking traffic statistics as it provides a unique socket
1284identifier per namespace.
1285.TP
1286.B Return
1287A 8\-byte long non\-decreasing number on success, or 0 if the
1288socket field is missing inside \fIskb\fP\&.
1289.UNINDENT
1290.TP
1291.B \fBu64 bpf_get_socket_cookie(struct bpf_sock_addr *\fP\fIctx\fP\fB)\fP
1292.INDENT 7.0
1293.TP
1294.B Description
1295Equivalent to bpf_get_socket_cookie() helper that accepts
1296\fIskb\fP, but gets socket from \fBstruct bpf_sock_addr\fP contex.
1297.TP
1298.B Return
1299A 8\-byte long non\-decreasing number.
1300.UNINDENT
1301.TP
1302.B \fBu64 bpf_get_socket_cookie(struct bpf_sock_ops *\fP\fIctx\fP\fB)\fP
1303.INDENT 7.0
1304.TP
1305.B Description
1306Equivalent to bpf_get_socket_cookie() helper that accepts
1307\fIskb\fP, but gets socket from \fBstruct bpf_sock_ops\fP contex.
1308.TP
1309.B Return
1310A 8\-byte long non\-decreasing number.
1311.UNINDENT
1312.TP
1313.B \fBu32 bpf_get_socket_uid(struct sk_buff *\fP\fIskb\fP\fB)\fP
1314.INDENT 7.0
1315.TP
1316.B Return
1317The owner UID of the socket associated to \fIskb\fP\&. If the socket
1318is \fBNULL\fP, or if it is not a full socket (i.e. if it is a
1319time\-wait or a request socket instead), \fBoverflowuid\fP value
1320is returned (note that \fBoverflowuid\fP might also be the actual
1321UID value for the socket).
1322.UNINDENT
1323.TP
1324.B \fBu32 bpf_set_hash(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIhash\fP\fB)\fP
1325.INDENT 7.0
1326.TP
1327.B Description
1328Set the full hash for \fIskb\fP (set the field \fIskb\fP\fB\->hash\fP)
1329to value \fIhash\fP\&.
1330.TP
1331.B Return
13320
1333.UNINDENT
1334.TP
1335.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
1336.INDENT 7.0
1337.TP
1338.B Description
1339Emulate a call to \fBsetsockopt()\fP on the socket associated to
1340\fIbpf_socket\fP, which must be a full socket. The \fIlevel\fP at
1341which the option resides and the name \fIoptname\fP of the option
1342must be specified, see \fBsetsockopt(2)\fP for more information.
1343The option value of length \fIoptlen\fP is pointed by \fIoptval\fP\&.
1344.sp
1345This helper actually implements a subset of \fBsetsockopt()\fP\&.
1346It supports the following \fIlevel\fPs:
1347.INDENT 7.0
1348.IP \(bu 2
1349\fBSOL_SOCKET\fP, which supports the following \fIoptname\fPs:
1350\fBSO_RCVBUF\fP, \fBSO_SNDBUF\fP, \fBSO_MAX_PACING_RATE\fP,
1351\fBSO_PRIORITY\fP, \fBSO_RCVLOWAT\fP, \fBSO_MARK\fP\&.
1352.IP \(bu 2
1353\fBIPPROTO_TCP\fP, which supports the following \fIoptname\fPs:
1354\fBTCP_CONGESTION\fP, \fBTCP_BPF_IW\fP,
1355\fBTCP_BPF_SNDCWND_CLAMP\fP\&.
1356.IP \(bu 2
1357\fBIPPROTO_IP\fP, which supports \fIoptname\fP \fBIP_TOS\fP\&.
1358.IP \(bu 2
1359\fBIPPROTO_IPV6\fP, which supports \fIoptname\fP \fBIPV6_TCLASS\fP\&.
1360.UNINDENT
1361.TP
1362.B Return
13630 on success, or a negative error in case of failure.
1364.UNINDENT
1365.TP
1366.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
1367.INDENT 7.0
1368.TP
1369.B Description
1370Grow or shrink the room for data in the packet associated to
1371\fIskb\fP by \fIlen_diff\fP, and according to the selected \fImode\fP\&.
1372.sp
1373There is a single supported mode at this time:
1374.INDENT 7.0
1375.IP \(bu 2
1376\fBBPF_ADJ_ROOM_NET\fP: Adjust room at the network layer
1377(room space is added or removed below the layer 3 header).
1378.UNINDENT
1379.sp
1380All values for \fIflags\fP are reserved for future usage, and must
1381be left at zero.
1382.sp
1383A call to this helper is susceptible to change the underlaying
1384packet buffer. Therefore, at load time, all checks on pointers
1385previously done by the verifier are invalidated and must be
1386performed again, if the helper is used in combination with
1387direct packet access.
1388.TP
1389.B Return
13900 on success, or a negative error in case of failure.
1391.UNINDENT
1392.TP
1393.B \fBint bpf_redirect_map(struct bpf_map *\fP\fImap\fP\fB, u32\fP \fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
1394.INDENT 7.0
1395.TP
1396.B Description
1397Redirect the packet to the endpoint referenced by \fImap\fP at
1398index \fIkey\fP\&. Depending on its type, this \fImap\fP can contain
1399references to net devices (for forwarding packets through other
1400ports), or to CPUs (for redirecting XDP frames to another CPU;
1401but this is only implemented for native XDP (with driver
1402support) as of this writing).
1403.sp
1404All values for \fIflags\fP are reserved for future usage, and must
1405be left at zero.
1406.sp
1407When used to redirect packets to net devices, this helper
1408provides a high performance increase over \fBbpf_redirect\fP().
1409This is due to various implementation details of the underlying
1410mechanisms, one of which is the fact that \fBbpf_redirect_map\fP() tries to send packet as a "bulk" to the device.
1411.TP
1412.B Return
1413\fBXDP_REDIRECT\fP on success, or \fBXDP_ABORTED\fP on error.
1414.UNINDENT
1415.TP
1416.B \fBint bpf_sk_redirect_map(struct bpf_map *\fP\fImap\fP\fB, u32\fP \fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
1417.INDENT 7.0
1418.TP
1419.B Description
1420Redirect the packet to the socket referenced by \fImap\fP (of type
1421\fBBPF_MAP_TYPE_SOCKMAP\fP) at index \fIkey\fP\&. Both ingress and
1422egress interfaces can be used for redirection. The
1423\fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
1424distinction (ingress path is selected if the flag is present,
1425egress path otherwise). This is the only flag supported for now.
1426.TP
1427.B Return
1428\fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
1429.UNINDENT
1430.TP
1431.B \fBint bpf_sock_map_update(struct bpf_sock_ops *\fP\fIskops\fP\fB, struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
1432.INDENT 7.0
1433.TP
1434.B Description
1435Add an entry to, or update a \fImap\fP referencing sockets. The
1436\fIskops\fP is used as a new value for the entry associated to
1437\fIkey\fP\&. \fIflags\fP is one of:
1438.INDENT 7.0
1439.TP
1440.B \fBBPF_NOEXIST\fP
1441The entry for \fIkey\fP must not exist in the map.
1442.TP
1443.B \fBBPF_EXIST\fP
1444The entry for \fIkey\fP must already exist in the map.
1445.TP
1446.B \fBBPF_ANY\fP
1447No condition on the existence of the entry for \fIkey\fP\&.
1448.UNINDENT
1449.sp
1450If the \fImap\fP has eBPF programs (parser and verdict), those will
1451be inherited by the socket being added. If the socket is
1452already attached to eBPF programs, this results in an error.
1453.TP
1454.B Return
14550 on success, or a negative error in case of failure.
1456.UNINDENT
1457.TP
1458.B \fBint bpf_xdp_adjust_meta(struct xdp_buff *\fP\fIxdp_md\fP\fB, int\fP \fIdelta\fP\fB)\fP
1459.INDENT 7.0
1460.TP
1461.B Description
1462Adjust the address pointed by \fIxdp_md\fP\fB\->data_meta\fP by
1463\fIdelta\fP (which can be positive or negative). Note that this
1464operation modifies the address stored in \fIxdp_md\fP\fB\->data\fP,
1465so the latter must be loaded only after the helper has been
1466called.
1467.sp
1468The use of \fIxdp_md\fP\fB\->data_meta\fP is optional and programs
1469are not required to use it. The rationale is that when the
1470packet is processed with XDP (e.g. as DoS filter), it is
1471possible to push further meta data along with it before passing
1472to the stack, and to give the guarantee that an ingress eBPF
1473program attached as a TC classifier on the same device can pick
1474this up for further post\-processing. Since TC works with socket
1475buffers, it remains possible to set from XDP the \fBmark\fP or
1476\fBpriority\fP pointers, or other pointers for the socket buffer.
1477Having this scratch space generic and programmable allows for
1478more flexibility as the user is free to store whatever meta
1479data they need.
1480.sp
1481A call to this helper is susceptible to change the underlaying
1482packet buffer. Therefore, at load time, all checks on pointers
1483previously done by the verifier are invalidated and must be
1484performed again, if the helper is used in combination with
1485direct packet access.
1486.TP
1487.B Return
14880 on success, or a negative error in case of failure.
1489.UNINDENT
1490.TP
1491.B \fBint bpf_perf_event_read_value(struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB, struct bpf_perf_event_value *\fP\fIbuf\fP\fB, u32\fP \fIbuf_size\fP\fB)\fP
1492.INDENT 7.0
1493.TP
1494.B Description
1495Read the value of a perf event counter, and store it into \fIbuf\fP
1496of size \fIbuf_size\fP\&. This helper relies on a \fImap\fP of type
1497\fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. The nature of the perf event
1498counter is selected when \fImap\fP is updated with perf event file
1499descriptors. The \fImap\fP is an array whose size is the number of
1500available CPUs, and each cell contains a value relative to one
1501CPU. The value to retrieve is indicated by \fIflags\fP, that
1502contains the index of the CPU to look up, masked with
1503\fBBPF_F_INDEX_MASK\fP\&. Alternatively, \fIflags\fP can be set to
1504\fBBPF_F_CURRENT_CPU\fP to indicate that the value for the
1505current CPU should be retrieved.
1506.sp
1507This helper behaves in a way close to
1508\fBbpf_perf_event_read\fP() helper, save that instead of
1509just returning the value observed, it fills the \fIbuf\fP
1510structure. This allows for additional data to be retrieved: in
1511particular, the enabled and running times (in \fIbuf\fP\fB\->enabled\fP and \fIbuf\fP\fB\->running\fP, respectively) are
1512copied. In general, \fBbpf_perf_event_read_value\fP() is
1513recommended over \fBbpf_perf_event_read\fP(), which has some
1514ABI issues and provides fewer functionalities.
1515.sp
1516These values are interesting, because hardware PMU (Performance
1517Monitoring Unit) counters are limited resources. When there are
1518more PMU based perf events opened than available counters,
1519kernel will multiplex these events so each event gets certain
1520percentage (but not all) of the PMU time. In case that
1521multiplexing happens, the number of samples or counter value
1522will not reflect the case compared to when no multiplexing
1523occurs. This makes comparison between different runs difficult.
1524Typically, the counter value should be normalized before
1525comparing to other experiments. The usual normalization is done
1526as follows.
1527.INDENT 7.0
1528.INDENT 3.5
1529.sp
1530.nf
1531.ft C
1532normalized_counter = counter * t_enabled / t_running
1533.ft P
1534.fi
1535.UNINDENT
1536.UNINDENT
1537.sp
1538Where t_enabled is the time enabled for event and t_running is
1539the time running for event since last normalization. The
1540enabled and running times are accumulated since the perf event
1541open. To achieve scaling factor between two invocations of an
1542eBPF program, users can can use CPU id as the key (which is
1543typical for perf array usage model) to remember the previous
1544value and do the calculation inside the eBPF program.
1545.TP
1546.B Return
15470 on success, or a negative error in case of failure.
1548.UNINDENT
1549.TP
1550.B \fBint bpf_perf_prog_read_value(struct bpf_perf_event_data *\fP\fIctx\fP\fB, struct bpf_perf_event_value *\fP\fIbuf\fP\fB, u32\fP \fIbuf_size\fP\fB)\fP
1551.INDENT 7.0
1552.TP
1553.B Description
1554For en eBPF program attached to a perf event, retrieve the
1555value of the event counter associated to \fIctx\fP and store it in
1556the structure pointed by \fIbuf\fP and of size \fIbuf_size\fP\&. Enabled
1557and running times are also stored in the structure (see
1558description of helper \fBbpf_perf_event_read_value\fP() for
1559more details).
1560.TP
1561.B Return
15620 on success, or a negative error in case of failure.
1563.UNINDENT
1564.TP
1565.B \fBint bpf_getsockopt(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
1566.INDENT 7.0
1567.TP
1568.B Description
1569Emulate a call to \fBgetsockopt()\fP on the socket associated to
1570\fIbpf_socket\fP, which must be a full socket. The \fIlevel\fP at
1571which the option resides and the name \fIoptname\fP of the option
1572must be specified, see \fBgetsockopt(2)\fP for more information.
1573The retrieved value is stored in the structure pointed by
1574\fIopval\fP and of length \fIoptlen\fP\&.
1575.sp
1576This helper actually implements a subset of \fBgetsockopt()\fP\&.
1577It supports the following \fIlevel\fPs:
1578.INDENT 7.0
1579.IP \(bu 2
1580\fBIPPROTO_TCP\fP, which supports \fIoptname\fP
1581\fBTCP_CONGESTION\fP\&.
1582.IP \(bu 2
1583\fBIPPROTO_IP\fP, which supports \fIoptname\fP \fBIP_TOS\fP\&.
1584.IP \(bu 2
1585\fBIPPROTO_IPV6\fP, which supports \fIoptname\fP \fBIPV6_TCLASS\fP\&.
1586.UNINDENT
1587.TP
1588.B Return
15890 on success, or a negative error in case of failure.
1590.UNINDENT
1591.TP
1592.B \fBint bpf_override_return(struct pt_reg *\fP\fIregs\fP\fB, u64\fP \fIrc\fP\fB)\fP
1593.INDENT 7.0
1594.TP
1595.B Description
1596Used for error injection, this helper uses kprobes to override
1597the return value of the probed function, and to set it to \fIrc\fP\&.
1598The first argument is the context \fIregs\fP on which the kprobe
1599works.
1600.sp
1601This helper works by setting setting the PC (program counter)
1602to an override function which is run in place of the original
1603probed function. This means the probed function is not run at
1604all. The replacement function just returns with the required
1605value.
1606.sp
1607This helper has security implications, and thus is subject to
1608restrictions. It is only available if the kernel was compiled
1609with the \fBCONFIG_BPF_KPROBE_OVERRIDE\fP configuration
1610option, and in this case it only works on functions tagged with
1611\fBALLOW_ERROR_INJECTION\fP in the kernel code.
1612.sp
1613Also, the helper is only available for the architectures having
1614the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,
1615x86 architecture is the only one to support this feature.
1616.TP
1617.B Return
16180
1619.UNINDENT
1620.TP
1621.B \fBint bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *\fP\fIbpf_sock\fP\fB, int\fP \fIargval\fP\fB)\fP
1622.INDENT 7.0
1623.TP
1624.B Description
1625Attempt to set the value of the \fBbpf_sock_ops_cb_flags\fP field
1626for the full TCP socket associated to \fIbpf_sock_ops\fP to
1627\fIargval\fP\&.
1628.sp
1629The primary use of this field is to determine if there should
1630be calls to eBPF programs of type
1631\fBBPF_PROG_TYPE_SOCK_OPS\fP at various points in the TCP
1632code. A program of the same type can change its value, per
1633connection and as necessary, when the connection is
1634established. This field is directly accessible for reading, but
1635this helper must be used for updates in order to return an
1636error if an eBPF program tries to set a callback that is not
1637supported in the current kernel.
1638.sp
1639The supported callback values that \fIargval\fP can combine are:
1640.INDENT 7.0
1641.IP \(bu 2
1642\fBBPF_SOCK_OPS_RTO_CB_FLAG\fP (retransmission time out)
1643.IP \(bu 2
1644\fBBPF_SOCK_OPS_RETRANS_CB_FLAG\fP (retransmission)
1645.IP \(bu 2
1646\fBBPF_SOCK_OPS_STATE_CB_FLAG\fP (TCP state change)
1647.UNINDENT
1648.sp
1649Here are some examples of where one could call such eBPF
1650program:
1651.INDENT 7.0
1652.IP \(bu 2
1653When RTO fires.
1654.IP \(bu 2
1655When a packet is retransmitted.
1656.IP \(bu 2
1657When the connection terminates.
1658.IP \(bu 2
1659When a packet is sent.
1660.IP \(bu 2
1661When a packet is received.
1662.UNINDENT
1663.TP
1664.B Return
1665Code \fB\-EINVAL\fP if the socket is not a full TCP socket;
1666otherwise, a positive number containing the bits that could not
1667be set is returned (which comes down to 0 if all bits were set
1668as required).
1669.UNINDENT
1670.TP
1671.B \fBint bpf_msg_redirect_map(struct sk_msg_buff *\fP\fImsg\fP\fB, struct bpf_map *\fP\fImap\fP\fB, u32\fP \fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
1672.INDENT 7.0
1673.TP
1674.B Description
1675This helper is used in programs implementing policies at the
1676socket level. If the message \fImsg\fP is allowed to pass (i.e. if
1677the verdict eBPF program returns \fBSK_PASS\fP), redirect it to
1678the socket referenced by \fImap\fP (of type
1679\fBBPF_MAP_TYPE_SOCKMAP\fP) at index \fIkey\fP\&. Both ingress and
1680egress interfaces can be used for redirection. The
1681\fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
1682distinction (ingress path is selected if the flag is present,
1683egress path otherwise). This is the only flag supported for now.
1684.TP
1685.B Return
1686\fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
1687.UNINDENT
1688.TP
1689.B \fBint bpf_msg_apply_bytes(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIbytes\fP\fB)\fP
1690.INDENT 7.0
1691.TP
1692.B Description
1693For socket policies, apply the verdict of the eBPF program to
1694the next \fIbytes\fP (number of bytes) of message \fImsg\fP\&.
1695.sp
1696For example, this helper can be used in the following cases:
1697.INDENT 7.0
1698.IP \(bu 2
1699A single \fBsendmsg\fP() or \fBsendfile\fP() system call
1700contains multiple logical messages that the eBPF program is
1701supposed to read and for which it should apply a verdict.
1702.IP \(bu 2
1703An eBPF program only cares to read the first \fIbytes\fP of a
1704\fImsg\fP\&. If the message has a large payload, then setting up
1705and calling the eBPF program repeatedly for all bytes, even
1706though the verdict is already known, would create unnecessary
1707overhead.
1708.UNINDENT
1709.sp
1710When called from within an eBPF program, the helper sets a
1711counter internal to the BPF infrastructure, that is used to
1712apply the last verdict to the next \fIbytes\fP\&. If \fIbytes\fP is
1713smaller than the current data being processed from a
1714\fBsendmsg\fP() or \fBsendfile\fP() system call, the first
1715\fIbytes\fP will be sent and the eBPF program will be re\-run with
1716the pointer for start of data pointing to byte number \fIbytes\fP
1717\fB+ 1\fP\&. If \fIbytes\fP is larger than the current data being
1718processed, then the eBPF verdict will be applied to multiple
1719\fBsendmsg\fP() or \fBsendfile\fP() calls until \fIbytes\fP are
1720consumed.
1721.sp
1722Note that if a socket closes with the internal counter holding
1723a non\-zero value, this is not a problem because data is not
1724being buffered for \fIbytes\fP and is sent as it is received.
1725.TP
1726.B Return
17270
1728.UNINDENT
1729.TP
1730.B \fBint bpf_msg_cork_bytes(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIbytes\fP\fB)\fP
1731.INDENT 7.0
1732.TP
1733.B Description
1734For socket policies, prevent the execution of the verdict eBPF
1735program for message \fImsg\fP until \fIbytes\fP (byte number) have been
1736accumulated.
1737.sp
1738This can be used when one needs a specific number of bytes
1739before a verdict can be assigned, even if the data spans
1740multiple \fBsendmsg\fP() or \fBsendfile\fP() calls. The extreme
1741case would be a user calling \fBsendmsg\fP() repeatedly with
17421\-byte long message segments. Obviously, this is bad for
1743performance, but it is still valid. If the eBPF program needs
1744\fIbytes\fP bytes to validate a header, this helper can be used to
1745prevent the eBPF program to be called again until \fIbytes\fP have
1746been accumulated.
1747.TP
1748.B Return
17490
1750.UNINDENT
1751.TP
1752.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
1753.INDENT 7.0
1754.TP
1755.B Description
1756For socket policies, pull in non\-linear data from user space
1757for \fImsg\fP and set pointers \fImsg\fP\fB\->data\fP and \fImsg\fP\fB\->data_end\fP to \fIstart\fP and \fIend\fP bytes offsets into \fImsg\fP,
1758respectively.
1759.sp
1760If a program of type \fBBPF_PROG_TYPE_SK_MSG\fP is run on a
1761\fImsg\fP it can only parse data that the (\fBdata\fP, \fBdata_end\fP)
1762pointers have already consumed. For \fBsendmsg\fP() hooks this
1763is likely the first scatterlist element. But for calls relying
1764on the \fBsendpage\fP handler (e.g. \fBsendfile\fP()) this will
1765be the range (\fB0\fP, \fB0\fP) because the data is shared with
1766user space and by default the objective is to avoid allowing
1767user space to modify data while (or after) eBPF verdict is
1768being decided. This helper can be used to pull in data and to
1769set the start and end pointer to given values. Data will be
1770copied if necessary (i.e. if data was not linear and if start
1771and end pointers do not point to the same chunk).
1772.sp
1773A call to this helper is susceptible to change the underlaying
1774packet buffer. Therefore, at load time, all checks on pointers
1775previously done by the verifier are invalidated and must be
1776performed again, if the helper is used in combination with
1777direct packet access.
1778.sp
1779All values for \fIflags\fP are reserved for future usage, and must
1780be left at zero.
1781.TP
1782.B Return
17830 on success, or a negative error in case of failure.
1784.UNINDENT
1785.TP
1786.B \fBint bpf_bind(struct bpf_sock_addr *\fP\fIctx\fP\fB, struct sockaddr *\fP\fIaddr\fP\fB, int\fP \fIaddr_len\fP\fB)\fP
1787.INDENT 7.0
1788.TP
1789.B Description
1790Bind the socket associated to \fIctx\fP to the address pointed by
1791\fIaddr\fP, of length \fIaddr_len\fP\&. This allows for making outgoing
1792connection from the desired IP address, which can be useful for
1793example when all processes inside a cgroup should use one
1794single IP address on a host that has multiple IP configured.
1795.sp
1796This helper works for IPv4 and IPv6, TCP and UDP sockets. The
1797domain (\fIaddr\fP\fB\->sa_family\fP) must be \fBAF_INET\fP (or
1798\fBAF_INET6\fP). Looking for a free port to bind to can be
1799expensive, therefore binding to port is not permitted by the
1800helper: \fIaddr\fP\fB\->sin_port\fP (or \fBsin6_port\fP, respectively)
1801must be set to zero.
1802.TP
1803.B Return
18040 on success, or a negative error in case of failure.
1805.UNINDENT
1806.TP
1807.B \fBint bpf_xdp_adjust_tail(struct xdp_buff *\fP\fIxdp_md\fP\fB, int\fP \fIdelta\fP\fB)\fP
1808.INDENT 7.0
1809.TP
1810.B Description
1811Adjust (move) \fIxdp_md\fP\fB\->data_end\fP by \fIdelta\fP bytes. It is
1812only possible to shrink the packet as of this writing,
1813therefore \fIdelta\fP must be a negative integer.
1814.sp
1815A call to this helper is susceptible to change the underlaying
1816packet buffer. Therefore, at load time, all checks on pointers
1817previously done by the verifier are invalidated and must be
1818performed again, if the helper is used in combination with
1819direct packet access.
1820.TP
1821.B Return
18220 on success, or a negative error in case of failure.
1823.UNINDENT
1824.TP
1825.B \fBint bpf_skb_get_xfrm_state(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIindex\fP\fB, struct bpf_xfrm_state *\fP\fIxfrm_state\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
1826.INDENT 7.0
1827.TP
1828.B Description
1829Retrieve the XFRM state (IP transform framework, see also
1830\fBip\-xfrm(8)\fP) at \fIindex\fP in XFRM "security path" for \fIskb\fP\&.
1831.sp
1832The retrieved value is stored in the \fBstruct bpf_xfrm_state\fP
1833pointed by \fIxfrm_state\fP and of length \fIsize\fP\&.
1834.sp
1835All values for \fIflags\fP are reserved for future usage, and must
1836be left at zero.
1837.sp
1838This helper is available only if the kernel was compiled with
1839\fBCONFIG_XFRM\fP configuration option.
1840.TP
1841.B Return
18420 on success, or a negative error in case of failure.
1843.UNINDENT
1844.TP
1845.B \fBint bpf_get_stack(struct pt_regs *\fP\fIregs\fP\fB, void *\fP\fIbuf\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
1846.INDENT 7.0
1847.TP
1848.B Description
1849Return a user or a kernel stack in bpf program provided buffer.
1850To achieve this, the helper needs \fIctx\fP, which is a pointer
1851to the context on which the tracing program is executed.
1852To store the stacktrace, the bpf program provides \fIbuf\fP with
1853a nonnegative \fIsize\fP\&.
1854.sp
1855The last argument, \fIflags\fP, holds the number of stack frames to
1856skip (from 0 to 255), masked with
1857\fBBPF_F_SKIP_FIELD_MASK\fP\&. The next bits can be used to set
1858the following flags:
1859.INDENT 7.0
1860.TP
1861.B \fBBPF_F_USER_STACK\fP
1862Collect a user space stack instead of a kernel stack.
1863.TP
1864.B \fBBPF_F_USER_BUILD_ID\fP
1865Collect buildid+offset instead of ips for user stack,
1866only valid if \fBBPF_F_USER_STACK\fP is also specified.
1867.UNINDENT
1868.sp
1869\fBbpf_get_stack\fP() can collect up to
1870\fBPERF_MAX_STACK_DEPTH\fP both kernel and user frames, subject
1871to sufficient large buffer size. Note that
1872this limit can be controlled with the \fBsysctl\fP program, and
1873that it should be manually increased in order to profile long
1874user stacks (such as stacks for Java programs). To do so, use:
1875.INDENT 7.0
1876.INDENT 3.5
1877.sp
1878.nf
1879.ft C
1880# sysctl kernel.perf_event_max_stack=<new value>
1881.ft P
1882.fi
1883.UNINDENT
1884.UNINDENT
1885.TP
1886.B Return
1887A non\-negative value equal to or less than \fIsize\fP on success,
1888or a negative error in case of failure.
1889.UNINDENT
1890.TP
1891.B \fBint bpf_skb_load_bytes_relative(const struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIoffset\fP\fB, void *\fP\fIto\fP\fB, u32\fP \fIlen\fP\fB, u32\fP \fIstart_header\fP\fB)\fP
1892.INDENT 7.0
1893.TP
1894.B Description
1895This helper is similar to \fBbpf_skb_load_bytes\fP() in that
1896it provides an easy way to load \fIlen\fP bytes from \fIoffset\fP
1897from the packet associated to \fIskb\fP, into the buffer pointed
1898by \fIto\fP\&. The difference to \fBbpf_skb_load_bytes\fP() is that
1899a fifth argument \fIstart_header\fP exists in order to select a
1900base offset to start from. \fIstart_header\fP can be one of:
1901.INDENT 7.0
1902.TP
1903.B \fBBPF_HDR_START_MAC\fP
1904Base offset to load data from is \fIskb\fP\(aqs mac header.
1905.TP
1906.B \fBBPF_HDR_START_NET\fP
1907Base offset to load data from is \fIskb\fP\(aqs network header.
1908.UNINDENT
1909.sp
1910In general, "direct packet access" is the preferred method to
1911access packet data, however, this helper is in particular useful
1912in socket filters where \fIskb\fP\fB\->data\fP does not always point
1913to the start of the mac header and where "direct packet access"
1914is not available.
1915.TP
1916.B Return
19170 on success, or a negative error in case of failure.
1918.UNINDENT
1919.TP
1920.B \fBint bpf_fib_lookup(void *\fP\fIctx\fP\fB, struct bpf_fib_lookup *\fP\fIparams\fP\fB, int\fP \fIplen\fP\fB, u32\fP \fIflags\fP\fB)\fP
1921.INDENT 7.0
1922.TP
1923.B Description
1924Do FIB lookup in kernel tables using parameters in \fIparams\fP\&.
1925If lookup is successful and result shows packet is to be
1926forwarded, the neighbor tables are searched for the nexthop.
1927If successful (ie., FIB lookup shows forwarding and nexthop
1928is resolved), the nexthop address is returned in ipv4_dst
1929or ipv6_dst based on family, smac is set to mac address of
1930egress device, dmac is set to nexthop mac address, rt_metric
1931is set to metric from route (IPv4/IPv6 only), and ifindex
1932is set to the device index of the nexthop from the FIB lookup.
1933.sp
1934\fIplen\fP argument is the size of the passed in struct.
1935\fIflags\fP argument can be a combination of one or more of the
1936following values:
1937.INDENT 7.0
1938.TP
1939.B \fBBPF_FIB_LOOKUP_DIRECT\fP
1940Do a direct table lookup vs full lookup using FIB
1941rules.
1942.TP
1943.B \fBBPF_FIB_LOOKUP_OUTPUT\fP
1944Perform lookup from an egress perspective (default is
1945ingress).
1946.UNINDENT
1947.sp
1948\fIctx\fP is either \fBstruct xdp_md\fP for XDP programs or
1949\fBstruct sk_buff\fP tc cls_act programs.
1950.TP
1951.B Return
1952.INDENT 7.0
1953.IP \(bu 2
1954< 0 if any input argument is invalid
1955.IP \(bu 2
19560 on success (packet is forwarded, nexthop neighbor exists)
1957.IP \(bu 2
1958> 0 one of \fBBPF_FIB_LKUP_RET_\fP codes explaining why the
1959packet is not forwarded or needs assist from full stack
1960.UNINDENT
1961.UNINDENT
1962.TP
1963.B \fBint bpf_sock_hash_update(struct bpf_sock_ops_kern *\fP\fIskops\fP\fB, struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
1964.INDENT 7.0
1965.TP
1966.B Description
1967Add an entry to, or update a sockhash \fImap\fP referencing sockets.
1968The \fIskops\fP is used as a new value for the entry associated to
1969\fIkey\fP\&. \fIflags\fP is one of:
1970.INDENT 7.0
1971.TP
1972.B \fBBPF_NOEXIST\fP
1973The entry for \fIkey\fP must not exist in the map.
1974.TP
1975.B \fBBPF_EXIST\fP
1976The entry for \fIkey\fP must already exist in the map.
1977.TP
1978.B \fBBPF_ANY\fP
1979No condition on the existence of the entry for \fIkey\fP\&.
1980.UNINDENT
1981.sp
1982If the \fImap\fP has eBPF programs (parser and verdict), those will
1983be inherited by the socket being added. If the socket is
1984already attached to eBPF programs, this results in an error.
1985.TP
1986.B Return
19870 on success, or a negative error in case of failure.
1988.UNINDENT
1989.TP
1990.B \fBint bpf_msg_redirect_hash(struct sk_msg_buff *\fP\fImsg\fP\fB, struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
1991.INDENT 7.0
1992.TP
1993.B Description
1994This helper is used in programs implementing policies at the
1995socket level. If the message \fImsg\fP is allowed to pass (i.e. if
1996the verdict eBPF program returns \fBSK_PASS\fP), redirect it to
1997the socket referenced by \fImap\fP (of type
1998\fBBPF_MAP_TYPE_SOCKHASH\fP) using hash \fIkey\fP\&. Both ingress and
1999egress interfaces can be used for redirection. The
2000\fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
2001distinction (ingress path is selected if the flag is present,
2002egress path otherwise). This is the only flag supported for now.
2003.TP
2004.B Return
2005\fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
2006.UNINDENT
2007.TP
2008.B \fBint bpf_sk_redirect_hash(struct sk_buff *\fP\fIskb\fP\fB, struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
2009.INDENT 7.0
2010.TP
2011.B Description
2012This helper is used in programs implementing policies at the
2013skb socket level. If the sk_buff \fIskb\fP is allowed to pass (i.e.
2014if the verdeict eBPF program returns \fBSK_PASS\fP), redirect it
2015to the socket referenced by \fImap\fP (of type
2016\fBBPF_MAP_TYPE_SOCKHASH\fP) using hash \fIkey\fP\&. Both ingress and
2017egress interfaces can be used for redirection. The
2018\fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
2019distinction (ingress path is selected if the flag is present,
2020egress otherwise). This is the only flag supported for now.
2021.TP
2022.B Return
2023\fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
2024.UNINDENT
2025.TP
2026.B \fBint bpf_lwt_push_encap(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fItype\fP\fB, void *\fP\fIhdr\fP\fB, u32\fP \fIlen\fP\fB)\fP
2027.INDENT 7.0
2028.TP
2029.B Description
2030Encapsulate the packet associated to \fIskb\fP within a Layer 3
2031protocol header. This header is provided in the buffer at
2032address \fIhdr\fP, with \fIlen\fP its size in bytes. \fItype\fP indicates
2033the protocol of the header and can be one of:
2034.INDENT 7.0
2035.TP
2036.B \fBBPF_LWT_ENCAP_SEG6\fP
2037IPv6 encapsulation with Segment Routing Header
2038(\fBstruct ipv6_sr_hdr\fP). \fIhdr\fP only contains the SRH,
2039the IPv6 header is computed by the kernel.
2040.TP
2041.B \fBBPF_LWT_ENCAP_SEG6_INLINE\fP
2042Only works if \fIskb\fP contains an IPv6 packet. Insert a
2043Segment Routing Header (\fBstruct ipv6_sr_hdr\fP) inside
2044the IPv6 header.
2045.UNINDENT
2046.sp
2047A call to this helper is susceptible to change the underlaying
2048packet buffer. Therefore, at load time, all checks on pointers
2049previously done by the verifier are invalidated and must be
2050performed again, if the helper is used in combination with
2051direct packet access.
2052.TP
2053.B Return
20540 on success, or a negative error in case of failure.
2055.UNINDENT
2056.TP
2057.B \fBint bpf_lwt_seg6_store_bytes(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIoffset\fP\fB, const void *\fP\fIfrom\fP\fB, u32\fP \fIlen\fP\fB)\fP
2058.INDENT 7.0
2059.TP
2060.B Description
2061Store \fIlen\fP bytes from address \fIfrom\fP into the packet
2062associated to \fIskb\fP, at \fIoffset\fP\&. Only the flags, tag and TLVs
2063inside the outermost IPv6 Segment Routing Header can be
2064modified through this helper.
2065.sp
2066A call to this helper is susceptible to change the underlaying
2067packet buffer. Therefore, at load time, all checks on pointers
2068previously done by the verifier are invalidated and must be
2069performed again, if the helper is used in combination with
2070direct packet access.
2071.TP
2072.B Return
20730 on success, or a negative error in case of failure.
2074.UNINDENT
2075.TP
2076.B \fBint bpf_lwt_seg6_adjust_srh(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIoffset\fP\fB, s32\fP \fIdelta\fP\fB)\fP
2077.INDENT 7.0
2078.TP
2079.B Description
2080Adjust the size allocated to TLVs in the outermost IPv6
2081Segment Routing Header contained in the packet associated to
2082\fIskb\fP, at position \fIoffset\fP by \fIdelta\fP bytes. Only offsets
2083after the segments are accepted. \fIdelta\fP can be as well
2084positive (growing) as negative (shrinking).
2085.sp
2086A call to this helper is susceptible to change the underlaying
2087packet buffer. Therefore, at load time, all checks on pointers
2088previously done by the verifier are invalidated and must be
2089performed again, if the helper is used in combination with
2090direct packet access.
2091.TP
2092.B Return
20930 on success, or a negative error in case of failure.
2094.UNINDENT
2095.TP
2096.B \fBint bpf_lwt_seg6_action(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIaction\fP\fB, void *\fP\fIparam\fP\fB, u32\fP \fIparam_len\fP\fB)\fP
2097.INDENT 7.0
2098.TP
2099.B Description
2100Apply an IPv6 Segment Routing action of type \fIaction\fP to the
2101packet associated to \fIskb\fP\&. Each action takes a parameter
2102contained at address \fIparam\fP, and of length \fIparam_len\fP bytes.
2103\fIaction\fP can be one of:
2104.INDENT 7.0
2105.TP
2106.B \fBSEG6_LOCAL_ACTION_END_X\fP
2107End.X action: Endpoint with Layer\-3 cross\-connect.
2108Type of \fIparam\fP: \fBstruct in6_addr\fP\&.
2109.TP
2110.B \fBSEG6_LOCAL_ACTION_END_T\fP
2111End.T action: Endpoint with specific IPv6 table lookup.
2112Type of \fIparam\fP: \fBint\fP\&.
2113.TP
2114.B \fBSEG6_LOCAL_ACTION_END_B6\fP
2115End.B6 action: Endpoint bound to an SRv6 policy.
2116Type of param: \fBstruct ipv6_sr_hdr\fP\&.
2117.TP
2118.B \fBSEG6_LOCAL_ACTION_END_B6_ENCAP\fP
2119End.B6.Encap action: Endpoint bound to an SRv6
2120encapsulation policy.
2121Type of param: \fBstruct ipv6_sr_hdr\fP\&.
2122.UNINDENT
2123.sp
2124A call to this helper is susceptible to change the underlaying
2125packet buffer. Therefore, at load time, all checks on pointers
2126previously done by the verifier are invalidated and must be
2127performed again, if the helper is used in combination with
2128direct packet access.
2129.TP
2130.B Return
21310 on success, or a negative error in case of failure.
2132.UNINDENT
2133.TP
2134.B \fBint bpf_rc_keydown(void *\fP\fIctx\fP\fB, u32\fP \fIprotocol\fP\fB, u64\fP \fIscancode\fP\fB, u32\fP \fItoggle\fP\fB)\fP
2135.INDENT 7.0
2136.TP
2137.B Description
2138This helper is used in programs implementing IR decoding, to
2139report a successfully decoded key press with \fIscancode\fP,
2140\fItoggle\fP value in the given \fIprotocol\fP\&. The scancode will be
2141translated to a keycode using the rc keymap, and reported as
2142an input key down event. After a period a key up event is
2143generated. This period can be extended by calling either
2144\fBbpf_rc_keydown\fP () again with the same values, or calling
2145\fBbpf_rc_repeat\fP ().
2146.sp
2147Some protocols include a toggle bit, in case the button was
2148released and pressed again between consecutive scancodes.
2149.sp
2150The \fIctx\fP should point to the lirc sample as passed into
2151the program.
2152.sp
2153The \fIprotocol\fP is the decoded protocol number (see
2154\fBenum rc_proto\fP for some predefined values).
2155.sp
2156This helper is only available is the kernel was compiled with
2157the \fBCONFIG_BPF_LIRC_MODE2\fP configuration option set to
2158"\fBy\fP".
2159.TP
2160.B Return
21610
2162.UNINDENT
2163.TP
2164.B \fBint bpf_rc_repeat(void *\fP\fIctx\fP\fB)\fP
2165.INDENT 7.0
2166.TP
2167.B Description
2168This helper is used in programs implementing IR decoding, to
2169report a successfully decoded repeat key message. This delays
2170the generation of a key up event for previously generated
2171key down event.
2172.sp
2173Some IR protocols like NEC have a special IR message for
2174repeating last button, for when a button is held down.
2175.sp
2176The \fIctx\fP should point to the lirc sample as passed into
2177the program.
2178.sp
2179This helper is only available is the kernel was compiled with
2180the \fBCONFIG_BPF_LIRC_MODE2\fP configuration option set to
2181"\fBy\fP".
2182.TP
2183.B Return
21840
2185.UNINDENT
2186.TP
2187.B \fBuint64_t bpf_skb_cgroup_id(struct sk_buff *\fP\fIskb\fP\fB)\fP
2188.INDENT 7.0
2189.TP
2190.B Description
2191Return the cgroup v2 id of the socket associated with the \fIskb\fP\&.
2192This is roughly similar to the \fBbpf_get_cgroup_classid\fP()
2193helper for cgroup v1 by providing a tag resp. identifier that
2194can be matched on or used for map lookups e.g. to implement
2195policy. The cgroup v2 id of a given path in the hierarchy is
2196exposed in user space through the f_handle API in order to get
2197to the same 64\-bit id.
2198.sp
2199This helper can be used on TC egress path, but not on ingress,
2200and is available only if the kernel was compiled with the
2201\fBCONFIG_SOCK_CGROUP_DATA\fP configuration option.
2202.TP
2203.B Return
2204The id is returned or 0 in case the id could not be retrieved.
2205.UNINDENT
2206.TP
2207.B \fBu64 bpf_skb_ancestor_cgroup_id(struct sk_buff *\fP\fIskb\fP\fB, int\fP \fIancestor_level\fP\fB)\fP
2208.INDENT 7.0
2209.TP
2210.B Description
2211Return id of cgroup v2 that is ancestor of cgroup associated
2212with the \fIskb\fP at the \fIancestor_level\fP\&. The root cgroup is at
2213\fIancestor_level\fP zero and each step down the hierarchy
2214increments the level. If \fIancestor_level\fP == level of cgroup
2215associated with \fIskb\fP, then return value will be same as that
2216of \fBbpf_skb_cgroup_id\fP().
2217.sp
2218The helper is useful to implement policies based on cgroups
2219that are upper in hierarchy than immediate cgroup associated
2220with \fIskb\fP\&.
2221.sp
2222The format of returned id and helper limitations are same as in
2223\fBbpf_skb_cgroup_id\fP().
2224.TP
2225.B Return
2226The id is returned or 0 in case the id could not be retrieved.
2227.UNINDENT
2228.TP
2229.B \fBu64 bpf_get_current_cgroup_id(void)\fP
2230.INDENT 7.0
2231.TP
2232.B Return
2233A 64\-bit integer containing the current cgroup id based
2234on the cgroup within which the current task is running.
2235.UNINDENT
2236.TP
2237.B \fBvoid* get_local_storage(void *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB)\fP
2238.INDENT 7.0
2239.TP
2240.B Description
2241Get the pointer to the local storage area.
2242The type and the size of the local storage is defined
2243by the \fImap\fP argument.
2244The \fIflags\fP meaning is specific for each map type,
2245and has to be 0 for cgroup local storage.
2246.sp
2247Depending on the bpf program type, a local storage area
2248can be shared between multiple instances of the bpf program,
2249running simultaneously.
2250.sp
2251A user should care about the synchronization by himself.
2252For example, by using the BPF_STX_XADD instruction to alter
2253the shared data.
2254.TP
2255.B Return
2256Pointer to the local storage area.
2257.UNINDENT
2258.TP
2259.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
2260.INDENT 7.0
2261.TP
2262.B Description
2263Select a SO_REUSEPORT sk from a BPF_MAP_TYPE_REUSEPORT_ARRAY map
2264It checks the selected sk is matching the incoming
2265request in the skb.
2266.TP
2267.B Return
22680 on success, or a negative error in case of failure.
2269.UNINDENT
2270.UNINDENT
2271.SH EXAMPLES
2272.sp
2273Example usage for most of the eBPF helpers listed in this manual page are
2274available within the Linux kernel sources, at the following locations:
2275.INDENT 0.0
2276.IP \(bu 2
2277\fIsamples/bpf/\fP
2278.IP \(bu 2
2279\fItools/testing/selftests/bpf/\fP
2280.UNINDENT
2281.SH LICENSE
2282.sp
2283eBPF programs can have an associated license, passed along with the bytecode
2284instructions to the kernel when the programs are loaded. The format for that
2285string is identical to the one in use for kernel modules (Dual licenses, such
2286as "Dual BSD/GPL", may be used). Some helper functions are only accessible to
2287programs that are compatible with the GNU Privacy License (GPL).
2288.sp
2289In order to use such helpers, the eBPF program must be loaded with the correct
2290license string passed (via \fBattr\fP) to the \fBbpf\fP() system call, and this
2291generally translates into the C source code of the program containing a line
2292similar to the following:
2293.INDENT 0.0
2294.INDENT 3.5
2295.sp
2296.nf
2297.ft C
2298char ____license[] __attribute__((section("license"), used)) = "GPL";
2299.ft P
2300.fi
2301.UNINDENT
2302.UNINDENT
2303.SH IMPLEMENTATION
2304.sp
2305This manual page is an effort to document the existing eBPF helper functions.
2306But as of this writing, the BPF sub\-system is under heavy development. New eBPF
2307program or map types are added, along with new helper functions. Some helpers
2308are occasionally made available for additional program types. So in spite of
2309the efforts of the community, this page might not be up\-to\-date. If you want to
2310check by yourself what helper functions exist in your kernel, or what types of
2311programs they can support, here are some files among the kernel tree that you
2312may be interested in:
2313.INDENT 0.0
2314.IP \(bu 2
2315\fIinclude/uapi/linux/bpf.h\fP is the main BPF header. It contains the full list
2316of all helper functions, as well as many other BPF definitions including most
2317of the flags, structs or constants used by the helpers.
2318.IP \(bu 2
2319\fInet/core/filter.c\fP contains the definition of most network\-related helper
2320functions, and the list of program types from which they can be used.
2321.IP \(bu 2
2322\fIkernel/trace/bpf_trace.c\fP is the equivalent for most tracing program\-related
2323helpers.
2324.IP \(bu 2
2325\fIkernel/bpf/verifier.c\fP contains the functions used to check that valid types
2326of eBPF maps are used with a given helper function.
2327.IP \(bu 2
2328\fIkernel/bpf/\fP directory contains other files in which additional helpers are
2329defined (for cgroups, sockmaps, etc.).
2330.UNINDENT
2331.sp
2332Compatibility between helper functions and program types can generally be found
2333in the files where helper functions are defined. Look for the \fBstruct
2334bpf_func_proto\fP objects and for functions returning them: these functions
2335contain a list of helpers that a given program type can call. Note that the
2336\fBdefault:\fP label of the \fBswitch ... case\fP used to filter helpers can call
2337other functions, themselves allowing access to additional helpers. The
2338requirement for GPL license is also in those \fBstruct bpf_func_proto\fP\&.
2339.sp
2340Compatibility between helper functions and map types can be found in the
2341\fBcheck_map_func_compatibility\fP() function in file \fIkernel/bpf/verifier.c\fP\&.
2342.sp
2343Helper functions that invalidate the checks on \fBdata\fP and \fBdata_end\fP
2344pointers for network processing are listed in function
2345\fBbpf_helper_changes_pkt_data\fP() in file \fInet/core/filter.c\fP\&.
2346.SH SEE ALSO
2347.sp
2348\fBbpf\fP(2),
2349\fBcgroups\fP(7),
2350\fBip\fP(8),
2351\fBperf_event_open\fP(2),
2352\fBsendmsg\fP(2),
2353\fBsocket\fP(7),
2354\fBtc\-bpf\fP(8)
2355.\" Generated by docutils manpage writer.
2356.