Debian Codegraph @

upstream/fedora-44/man7/bpf-helpers.7

raw
1 .\" Man page generated from reStructuredText.
2 .
3 .
4 .nr rst2man-indent-level 0
5 .
6 .de1 rstReportMargin
7 \\$1 \\n[an-margin]
8 level \\n[rst2man-indent-level]
9 level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
10 -
11 \\n[rst2man-indent0]
12 \\n[rst2man-indent1]
13 \\n[rst2man-indent2]
14 ..
15 .de1 INDENT
16 .\" .rstReportMargin pre:
17 . RS \\$1
18 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
19 . nr rst2man-indent-level +1
20 .\" .rstReportMargin post:
21 ..
22 .de UNINDENT
23 . RE
24 .\" indent \\n[an-margin]
25 .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
26 .nr rst2man-indent-level -1
27 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
28 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
29 ..
30 .TH "BPF-HELPERS" "7" "2024-10-10" "Linux v6.13"
31 .SH NAME
32 BPF-HELPERS \- list of eBPF helper functions
33 .\" Copyright (C) All BPF authors and contributors from 2014 to present.
34 .
35 .\" See git log include/uapi/linux/bpf.h in kernel tree for details.
36 .
37 .\"
38 .
39 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
40 .
41 .\"
42 .
43 .\" Please do not edit this file. It was generated from the documentation
44 .
45 .\" located in file include/uapi/linux/bpf.h of the Linux kernel sources
46 .
47 .\" (helpers description), and from scripts/bpf_doc.py in the same
48 .
49 .\" repository (header and footer).
50 .
51 .SH DESCRIPTION
52 .sp
53 The extended Berkeley Packet Filter (eBPF) subsystem consists in programs
54 written in a pseudo\-assembly language, then attached to one of the several
55 kernel hooks and run in reaction of specific events. This framework differs
56 from the older, \(dqclassic\(dq BPF (or \(dqcBPF\(dq) in several aspects, one of them being
57 the ability to call special functions (or \(dqhelpers\(dq) from within a program.
58 These functions are restricted to a white\-list of helpers defined in the
59 kernel.
60 .sp
61 These helpers are used by eBPF programs to interact with the system, or with
62 the context in which they work. For instance, they can be used to print
63 debugging messages, to get the time since the system was booted, to interact
64 with eBPF maps, or to manipulate network packets. Since there are several eBPF
65 program types, and that they do not run in the same context, each program type
66 can only call a subset of those helpers.
67 .sp
68 Due to eBPF conventions, a helper can not have more than five arguments.
69 .sp
70 Internally, eBPF programs call directly into the compiled helper functions
71 without requiring any foreign\-function interface. As a result, calling helpers
72 introduces no overhead, thus offering excellent performance.
73 .sp
74 This document is an attempt to list and document the helpers available to eBPF
75 developers. They are sorted by chronological order (the oldest helpers in the
76 kernel at the top).
77 .SH HELPERS
78 .INDENT 0.0
79 .TP
80 .B \fBvoid *bpf_map_lookup_elem(struct bpf_map *\fP\fImap\fP\fB, const void *\fP\fIkey\fP\fB)\fP
81 .INDENT 7.0
82 .TP
83 .B Description
84 Perform a lookup in \fImap\fP for an entry associated to \fIkey\fP\&.
85 .TP
86 .B Return
87 Map value associated to \fIkey\fP, or \fBNULL\fP if no entry was
88 found.
89 .UNINDENT
90 .TP
91 .B \fBlong 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
92 .INDENT 7.0
93 .TP
94 .B Description
95 Add or update the value of the entry associated to \fIkey\fP in
96 \fImap\fP with \fIvalue\fP\&. \fIflags\fP is one of:
97 .INDENT 7.0
98 .TP
99 .B \fBBPF_NOEXIST\fP
100 The entry for \fIkey\fP must not exist in the map.
101 .TP
102 .B \fBBPF_EXIST\fP
103 The entry for \fIkey\fP must already exist in the map.
104 .TP
105 .B \fBBPF_ANY\fP
106 No condition on the existence of the entry for \fIkey\fP\&.
107 .UNINDENT
108 .sp
109 Flag value \fBBPF_NOEXIST\fP cannot be used for maps of types
110 \fBBPF_MAP_TYPE_ARRAY\fP or \fBBPF_MAP_TYPE_PERCPU_ARRAY\fP (all
111 elements always exist), the helper would return an error.
112 .TP
113 .B Return
114 0 on success, or a negative error in case of failure.
115 .UNINDENT
116 .TP
117 .B \fBlong bpf_map_delete_elem(struct bpf_map *\fP\fImap\fP\fB, const void *\fP\fIkey\fP\fB)\fP
118 .INDENT 7.0
119 .TP
120 .B Description
121 Delete entry with \fIkey\fP from \fImap\fP\&.
122 .TP
123 .B Return
124 0 on success, or a negative error in case of failure.
125 .UNINDENT
126 .TP
127 .B \fBlong bpf_probe_read(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
128 .INDENT 7.0
129 .TP
130 .B Description
131 For tracing programs, safely attempt to read \fIsize\fP bytes from
132 kernel space address \fIunsafe_ptr\fP and store the data in \fIdst\fP\&.
133 .sp
134 Generally, use \fBbpf_probe_read_user\fP() or
135 \fBbpf_probe_read_kernel\fP() instead.
136 .TP
137 .B Return
138 0 on success, or a negative error in case of failure.
139 .UNINDENT
140 .TP
141 .B \fBu64 bpf_ktime_get_ns(void)\fP
142 .INDENT 7.0
143 .TP
144 .B Description
145 Return the time elapsed since system boot, in nanoseconds.
146 Does not include time the system was suspended.
147 See: \fBclock_gettime\fP(\fBCLOCK_MONOTONIC\fP)
148 .TP
149 .B Return
150 Current \fIktime\fP\&.
151 .UNINDENT
152 .TP
153 .B \fBlong bpf_trace_printk(const char *\fP\fIfmt\fP\fB, u32\fP \fIfmt_size\fP\fB, ...)\fP
154 .INDENT 7.0
155 .TP
156 .B Description
157 This helper is a \(dqprintk()\-like\(dq facility for debugging. It
158 prints a message defined by format \fIfmt\fP (of size \fIfmt_size\fP)
159 to file \fI/sys/kernel/tracing/trace\fP from TraceFS, if
160 available. It can take up to three additional \fBu64\fP
161 arguments (as an eBPF helpers, the total number of arguments is
162 limited to five).
163 .sp
164 Each time the helper is called, it appends a line to the trace.
165 Lines are discarded while \fI/sys/kernel/tracing/trace\fP is
166 open, use \fI/sys/kernel/tracing/trace_pipe\fP to avoid this.
167 The format of the trace is customizable, and the exact output
168 one will get depends on the options set in
169 \fI/sys/kernel/tracing/trace_options\fP (see also the
170 \fIREADME\fP file under the same directory). However, it usually
171 defaults to something like:
172 .INDENT 7.0
173 .INDENT 3.5
174 .sp
175 .EX
176 telnet\-470 [001] .N.. 419421.045894: 0x00000001: <formatted msg>
177 .EE
178 .UNINDENT
179 .UNINDENT
180 .sp
181 In the above:
182 .INDENT 7.0
183 .INDENT 3.5
184 .INDENT 0.0
185 .IP \(bu 2
186 \fBtelnet\fP is the name of the current task.
187 .IP \(bu 2
188 \fB470\fP is the PID of the current task.
189 .IP \(bu 2
190 \fB001\fP is the CPU number on which the task is
191 running.
192 .IP \(bu 2
193 In \fB\&.N..\fP, each character refers to a set of
194 options (whether irqs are enabled, scheduling
195 options, whether hard/softirqs are running, level of
196 preempt_disabled respectively). \fBN\fP means that
197 \fBTIF_NEED_RESCHED\fP and \fBPREEMPT_NEED_RESCHED\fP
198 are set.
199 .IP \(bu 2
200 \fB419421.045894\fP is a timestamp.
201 .IP \(bu 2
202 \fB0x00000001\fP is a fake value used by BPF for the
203 instruction pointer register.
204 .IP \(bu 2
205 \fB<formatted msg>\fP is the message formatted with
206 \fIfmt\fP\&.
207 .UNINDENT
208 .UNINDENT
209 .UNINDENT
210 .sp
211 The conversion specifiers supported by \fIfmt\fP are similar, but
212 more limited than for printk(). They are \fB%d\fP, \fB%i\fP,
213 \fB%u\fP, \fB%x\fP, \fB%ld\fP, \fB%li\fP, \fB%lu\fP, \fB%lx\fP, \fB%lld\fP,
214 \fB%lli\fP, \fB%llu\fP, \fB%llx\fP, \fB%p\fP, \fB%s\fP\&. No modifier (size
215 of field, padding with zeroes, etc.) is available, and the
216 helper will return \fB\-EINVAL\fP (but print nothing) if it
217 encounters an unknown specifier.
218 .sp
219 Also, note that \fBbpf_trace_printk\fP() is slow, and should
220 only be used for debugging purposes. For this reason, a notice
221 block (spanning several lines) is printed to kernel logs and
222 states that the helper should not be used \(dqfor production use\(dq
223 the first time this helper is used (or more precisely, when
224 \fBtrace_printk\fP() buffers are allocated). For passing values
225 to user space, perf events should be preferred.
226 .TP
227 .B Return
228 The number of bytes written to the buffer, or a negative error
229 in case of failure.
230 .UNINDENT
231 .TP
232 .B \fBu32 bpf_get_prandom_u32(void)\fP
233 .INDENT 7.0
234 .TP
235 .B Description
236 Get a pseudo\-random number.
237 .sp
238 From a security point of view, this helper uses its own
239 pseudo\-random internal state, and cannot be used to infer the
240 seed of other random functions in the kernel. However, it is
241 essential to note that the generator used by the helper is not
242 cryptographically secure.
243 .TP
244 .B Return
245 A random 32\-bit unsigned value.
246 .UNINDENT
247 .TP
248 .B \fBu32 bpf_get_smp_processor_id(void)\fP
249 .INDENT 7.0
250 .TP
251 .B Description
252 Get the SMP (symmetric multiprocessing) processor id. Note that
253 all programs run with migration disabled, which means that the
254 SMP processor id is stable during all the execution of the
255 program.
256 .TP
257 .B Return
258 The SMP id of the processor running the program.
259 .UNINDENT
260 .TP
261 .B \fBlong 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
262 .INDENT 7.0
263 .TP
264 .B Description
265 Store \fIlen\fP bytes from address \fIfrom\fP into the packet
266 associated to \fIskb\fP, at \fIoffset\fP\&. \fIflags\fP are a combination of
267 \fBBPF_F_RECOMPUTE_CSUM\fP (automatically recompute the
268 checksum for the packet after storing the bytes) and
269 \fBBPF_F_INVALIDATE_HASH\fP (set \fIskb\fP\fB\->hash\fP, \fIskb\fP\fB\->swhash\fP and \fIskb\fP\fB\->l4hash\fP to 0).
270 .sp
271 A call to this helper is susceptible to change the underlying
272 packet buffer. Therefore, at load time, all checks on pointers
273 previously done by the verifier are invalidated and must be
274 performed again, if the helper is used in combination with
275 direct packet access.
276 .TP
277 .B Return
278 0 on success, or a negative error in case of failure.
279 .UNINDENT
280 .TP
281 .B \fBlong 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
282 .INDENT 7.0
283 .TP
284 .B Description
285 Recompute the layer 3 (e.g. IP) checksum for the packet
286 associated to \fIskb\fP\&. Computation is incremental, so the helper
287 must know the former value of the header field that was
288 modified (\fIfrom\fP), the new value of this field (\fIto\fP), and the
289 number of bytes (2 or 4) for this field, stored in \fIsize\fP\&.
290 Alternatively, it is possible to store the difference between
291 the previous and the new values of the header field in \fIto\fP, by
292 setting \fIfrom\fP and \fIsize\fP to 0. For both methods, \fIoffset\fP
293 indicates the location of the IP checksum within the packet.
294 .sp
295 This helper works in combination with \fBbpf_csum_diff\fP(),
296 which does not update the checksum in\-place, but offers more
297 flexibility and can handle sizes larger than 2 or 4 for the
298 checksum to update.
299 .sp
300 A call to this helper is susceptible to change the underlying
301 packet buffer. Therefore, at load time, all checks on pointers
302 previously done by the verifier are invalidated and must be
303 performed again, if the helper is used in combination with
304 direct packet access.
305 .TP
306 .B Return
307 0 on success, or a negative error in case of failure.
308 .UNINDENT
309 .TP
310 .B \fBlong 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
311 .INDENT 7.0
312 .TP
313 .B Description
314 Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
315 packet associated to \fIskb\fP\&. Computation is incremental, so the
316 helper must know the former value of the header field that was
317 modified (\fIfrom\fP), the new value of this field (\fIto\fP), and the
318 number of bytes (2 or 4) for this field, stored on the lowest
319 four bits of \fIflags\fP\&. Alternatively, it is possible to store
320 the difference between the previous and the new values of the
321 header field in \fIto\fP, by setting \fIfrom\fP and the four lowest
322 bits of \fIflags\fP to 0. For both methods, \fIoffset\fP indicates the
323 location of the IP checksum within the packet. In addition to
324 the size of the field, \fIflags\fP can be added (bitwise OR) actual
325 flags. With \fBBPF_F_MARK_MANGLED_0\fP, a null checksum is left
326 untouched (unless \fBBPF_F_MARK_ENFORCE\fP is added as well), and
327 for updates resulting in a null checksum the value is set to
328 \fBCSUM_MANGLED_0\fP instead. Flag \fBBPF_F_PSEUDO_HDR\fP indicates
329 the checksum is to be computed against a pseudo\-header.
330 .sp
331 This helper works in combination with \fBbpf_csum_diff\fP(),
332 which does not update the checksum in\-place, but offers more
333 flexibility and can handle sizes larger than 2 or 4 for the
334 checksum to update.
335 .sp
336 A call to this helper is susceptible to change the underlying
337 packet buffer. Therefore, at load time, all checks on pointers
338 previously done by the verifier are invalidated and must be
339 performed again, if the helper is used in combination with
340 direct packet access.
341 .TP
342 .B Return
343 0 on success, or a negative error in case of failure.
344 .UNINDENT
345 .TP
346 .B \fBlong bpf_tail_call(void *\fP\fIctx\fP\fB, struct bpf_map *\fP\fIprog_array_map\fP\fB, u32\fP \fIindex\fP\fB)\fP
347 .INDENT 7.0
348 .TP
349 .B Description
350 This special helper is used to trigger a \(dqtail call\(dq, or in
351 other words, to jump into another eBPF program. The same stack
352 frame is used (but values on stack and in registers for the
353 caller are not accessible to the callee). This mechanism allows
354 for program chaining, either for raising the maximum number of
355 available eBPF instructions, or to execute given programs in
356 conditional blocks. For security reasons, there is an upper
357 limit to the number of successive tail calls that can be
358 performed.
359 .sp
360 Upon call of this helper, the program attempts to jump into a
361 program referenced at index \fIindex\fP in \fIprog_array_map\fP, a
362 special map of type \fBBPF_MAP_TYPE_PROG_ARRAY\fP, and passes
363 \fIctx\fP, a pointer to the context.
364 .sp
365 If the call succeeds, the kernel immediately runs the first
366 instruction of the new program. This is not a function call,
367 and it never returns to the previous program. If the call
368 fails, then the helper has no effect, and the caller continues
369 to run its subsequent instructions. A call can fail if the
370 destination program for the jump does not exist (i.e. \fIindex\fP
371 is superior to the number of entries in \fIprog_array_map\fP), or
372 if the maximum number of tail calls has been reached for this
373 chain of programs. This limit is defined in the kernel by the
374 macro \fBMAX_TAIL_CALL_CNT\fP (not accessible to user space),
375 which is currently set to 33.
376 .TP
377 .B Return
378 0 on success, or a negative error in case of failure.
379 .UNINDENT
380 .TP
381 .B \fBlong bpf_clone_redirect(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIifindex\fP\fB, u64\fP \fIflags\fP\fB)\fP
382 .INDENT 7.0
383 .TP
384 .B Description
385 Clone and redirect the packet associated to \fIskb\fP to another
386 net device of index \fIifindex\fP\&. Both ingress and egress
387 interfaces can be used for redirection. The \fBBPF_F_INGRESS\fP
388 value in \fIflags\fP is used to make the distinction (ingress path
389 is selected if the flag is present, egress path otherwise).
390 This is the only flag supported for now.
391 .sp
392 In comparison with \fBbpf_redirect\fP() helper,
393 \fBbpf_clone_redirect\fP() has the associated cost of
394 duplicating the packet buffer, but this can be executed out of
395 the eBPF program. Conversely, \fBbpf_redirect\fP() is more
396 efficient, but it is handled through an action code where the
397 redirection happens only after the eBPF program has returned.
398 .sp
399 A call to this helper is susceptible to change the underlying
400 packet buffer. Therefore, at load time, all checks on pointers
401 previously done by the verifier are invalidated and must be
402 performed again, if the helper is used in combination with
403 direct packet access.
404 .TP
405 .B Return
406 0 on success, or a negative error in case of failure. Positive
407 error indicates a potential drop or congestion in the target
408 device. The particular positive error codes are not defined.
409 .UNINDENT
410 .TP
411 .B \fBu64 bpf_get_current_pid_tgid(void)\fP
412 .INDENT 7.0
413 .TP
414 .B Description
415 Get the current pid and tgid.
416 .TP
417 .B Return
418 A 64\-bit integer containing the current tgid and pid, and
419 created as such:
420 \fIcurrent_task\fP\fB\->tgid << 32 |\fP
421 \fIcurrent_task\fP\fB\->pid\fP\&.
422 .UNINDENT
423 .TP
424 .B \fBu64 bpf_get_current_uid_gid(void)\fP
425 .INDENT 7.0
426 .TP
427 .B Description
428 Get the current uid and gid.
429 .TP
430 .B Return
431 A 64\-bit integer containing the current GID and UID, and
432 created as such: \fIcurrent_gid\fP \fB<< 32 |\fP \fIcurrent_uid\fP\&.
433 .UNINDENT
434 .TP
435 .B \fBlong bpf_get_current_comm(void *\fP\fIbuf\fP\fB, u32\fP \fIsize_of_buf\fP\fB)\fP
436 .INDENT 7.0
437 .TP
438 .B Description
439 Copy the \fBcomm\fP attribute of the current task into \fIbuf\fP of
440 \fIsize_of_buf\fP\&. The \fBcomm\fP attribute contains the name of
441 the executable (excluding the path) for the current task. The
442 \fIsize_of_buf\fP must be strictly positive. On success, the
443 helper makes sure that the \fIbuf\fP is NUL\-terminated. On failure,
444 it is filled with zeroes.
445 .TP
446 .B Return
447 0 on success, or a negative error in case of failure.
448 .UNINDENT
449 .TP
450 .B \fBu32 bpf_get_cgroup_classid(struct sk_buff *\fP\fIskb\fP\fB)\fP
451 .INDENT 7.0
452 .TP
453 .B Description
454 Retrieve the classid for the current task, i.e. for the net_cls
455 cgroup to which \fIskb\fP belongs.
456 .sp
457 This helper can be used on TC egress path, but not on ingress.
458 .sp
459 The net_cls cgroup provides an interface to tag network packets
460 based on a user\-provided identifier for all traffic coming from
461 the tasks belonging to the related cgroup. See also the related
462 kernel documentation, available from the Linux sources in file
463 \fIDocumentation/admin\-guide/cgroup\-v1/net_cls.rst\fP\&.
464 .sp
465 The Linux kernel has two versions for cgroups: there are
466 cgroups v1 and cgroups v2. Both are available to users, who can
467 use a mixture of them, but note that the net_cls cgroup is for
468 cgroup v1 only. This makes it incompatible with BPF programs
469 run on cgroups, which is a cgroup\-v2\-only feature (a socket can
470 only hold data for one version of cgroups at a time).
471 .sp
472 This helper is only available is the kernel was compiled with
473 the \fBCONFIG_CGROUP_NET_CLASSID\fP configuration option set to
474 \(dq\fBy\fP\(dq or to \(dq\fBm\fP\(dq.
475 .TP
476 .B Return
477 The classid, or 0 for the default unconfigured classid.
478 .UNINDENT
479 .TP
480 .B \fBlong bpf_skb_vlan_push(struct sk_buff *\fP\fIskb\fP\fB, __be16\fP \fIvlan_proto\fP\fB, u16\fP \fIvlan_tci\fP\fB)\fP
481 .INDENT 7.0
482 .TP
483 .B Description
484 Push a \fIvlan_tci\fP (VLAN tag control information) of protocol
485 \fIvlan_proto\fP to the packet associated to \fIskb\fP, then update
486 the checksum. Note that if \fIvlan_proto\fP is different from
487 \fBETH_P_8021Q\fP and \fBETH_P_8021AD\fP, it is considered to
488 be \fBETH_P_8021Q\fP\&.
489 .sp
490 A call to this helper is susceptible to change the underlying
491 packet buffer. Therefore, at load time, all checks on pointers
492 previously done by the verifier are invalidated and must be
493 performed again, if the helper is used in combination with
494 direct packet access.
495 .TP
496 .B Return
497 0 on success, or a negative error in case of failure.
498 .UNINDENT
499 .TP
500 .B \fBlong bpf_skb_vlan_pop(struct sk_buff *\fP\fIskb\fP\fB)\fP
501 .INDENT 7.0
502 .TP
503 .B Description
504 Pop a VLAN header from the packet associated to \fIskb\fP\&.
505 .sp
506 A call to this helper is susceptible to change the underlying
507 packet buffer. Therefore, at load time, all checks on pointers
508 previously done by the verifier are invalidated and must be
509 performed again, if the helper is used in combination with
510 direct packet access.
511 .TP
512 .B Return
513 0 on success, or a negative error in case of failure.
514 .UNINDENT
515 .TP
516 .B \fBlong 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
517 .INDENT 7.0
518 .TP
519 .B Description
520 Get tunnel metadata. This helper takes a pointer \fIkey\fP to an
521 empty \fBstruct bpf_tunnel_key\fP of \fBsize\fP, that will be
522 filled with tunnel metadata for the packet associated to \fIskb\fP\&.
523 The \fIflags\fP can be set to \fBBPF_F_TUNINFO_IPV6\fP, which
524 indicates that the tunnel is based on IPv6 protocol instead of
525 IPv4.
526 .sp
527 The \fBstruct bpf_tunnel_key\fP is an object that generalizes the
528 principal parameters used by various tunneling protocols into a
529 single struct. This way, it can be used to easily make a
530 decision based on the contents of the encapsulation header,
531 \(dqsummarized\(dq in this struct. In particular, it holds the IP
532 address of the remote end (IPv4 or IPv6, depending on the case)
533 in \fIkey\fP\fB\->remote_ipv4\fP or \fIkey\fP\fB\->remote_ipv6\fP\&. Also,
534 this struct exposes the \fIkey\fP\fB\->tunnel_id\fP, which is
535 generally mapped to a VNI (Virtual Network Identifier), making
536 it programmable together with the \fBbpf_skb_set_tunnel_key\fP() helper.
537 .sp
538 Let\(aqs imagine that the following code is part of a program
539 attached to the TC ingress interface, on one end of a GRE
540 tunnel, and is supposed to filter out all messages coming from
541 remote ends with IPv4 address other than 10.0.0.1:
542 .INDENT 7.0
543 .INDENT 3.5
544 .sp
545 .EX
546 int ret;
547 struct bpf_tunnel_key key = {};
548
549 ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
550 if (ret < 0)
551 return TC_ACT_SHOT; // drop packet
552
553 if (key.remote_ipv4 != 0x0a000001)
554 return TC_ACT_SHOT; // drop packet
555
556 return TC_ACT_OK; // accept packet
557 .EE
558 .UNINDENT
559 .UNINDENT
560 .sp
561 This interface can also be used with all encapsulation devices
562 that can operate in \(dqcollect metadata\(dq mode: instead of having
563 one network device per specific configuration, the \(dqcollect
564 metadata\(dq mode only requires a single device where the
565 configuration can be extracted from this helper.
566 .sp
567 This can be used together with various tunnels such as VXLan,
568 Geneve, GRE or IP in IP (IPIP).
569 .TP
570 .B Return
571 0 on success, or a negative error in case of failure.
572 .UNINDENT
573 .TP
574 .B \fBlong 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
578 Populate tunnel metadata for packet associated to \fIskb.\fP The
579 tunnel 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
584 Indicate that the tunnel is based on IPv6 protocol
585 instead of IPv4.
586 .TP
587 .B \fBBPF_F_ZERO_CSUM_TX\fP
588 For IPv4 packets, add a flag to tunnel metadata
589 indicating that checksum computation should be skipped
590 and checksum set to zeroes.
591 .TP
592 .B \fBBPF_F_DONT_FRAGMENT\fP
593 Add a flag to tunnel metadata indicating that the
594 packet should not be fragmented.
595 .TP
596 .B \fBBPF_F_SEQ_NUMBER\fP
597 Add a flag to tunnel metadata indicating that a
598 sequence number should be added to tunnel header before
599 sending the packet. This flag was added for GRE
600 encapsulation, but might be used with other protocols
601 as well in the future.
602 .TP
603 .B \fBBPF_F_NO_TUNNEL_KEY\fP
604 Add a flag to tunnel metadata indicating that no tunnel
605 key should be set in the resulting tunnel header.
606 .UNINDENT
607 .sp
608 Here is a typical usage on the transmit path:
609 .INDENT 7.0
610 .INDENT 3.5
611 .sp
612 .EX
613 struct bpf_tunnel_key key;
614 populate key ...
615 bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
616 bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
617 .EE
618 .UNINDENT
619 .UNINDENT
620 .sp
621 See also the description of the \fBbpf_skb_get_tunnel_key\fP()
622 helper for additional information.
623 .TP
624 .B Return
625 0 on success, or a negative error in case of failure.
626 .UNINDENT
627 .TP
628 .B \fBu64 bpf_perf_event_read(struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB)\fP
629 .INDENT 7.0
630 .TP
631 .B Description
632 Read the value of a perf event counter. This helper relies on a
633 \fImap\fP of type \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. The nature of
634 the perf event counter is selected when \fImap\fP is updated with
635 perf event file descriptors. The \fImap\fP is an array whose size
636 is the number of available CPUs, and each cell contains a value
637 relative to one CPU. The value to retrieve is indicated by
638 \fIflags\fP, that contains the index of the CPU to look up, masked
639 with \fBBPF_F_INDEX_MASK\fP\&. Alternatively, \fIflags\fP can be set to
640 \fBBPF_F_CURRENT_CPU\fP to indicate that the value for the
641 current CPU should be retrieved.
642 .sp
643 Note that before Linux 4.13, only hardware perf event can be
644 retrieved.
645 .sp
646 Also, be aware that the newer helper
647 \fBbpf_perf_event_read_value\fP() is recommended over
648 \fBbpf_perf_event_read\fP() in general. The latter has some ABI
649 quirks where error and counter value are used as a return code
650 (which is wrong to do since ranges may overlap). This issue is
651 fixed with \fBbpf_perf_event_read_value\fP(), which at the same
652 time provides more features over the \fBbpf_perf_event_read\fP() interface. Please refer to the description of
653 \fBbpf_perf_event_read_value\fP() for details.
654 .TP
655 .B Return
656 The value of the perf event counter read from the map, or a
657 negative error code in case of failure.
658 .UNINDENT
659 .TP
660 .B \fBlong bpf_redirect(u32\fP \fIifindex\fP\fB, u64\fP \fIflags\fP\fB)\fP
661 .INDENT 7.0
662 .TP
663 .B Description
664 Redirect the packet to another net device of index \fIifindex\fP\&.
665 This helper is somewhat similar to \fBbpf_clone_redirect\fP(), except that the packet is not cloned, which provides
666 increased performance.
667 .sp
668 Except for XDP, both ingress and egress interfaces can be used
669 for redirection. The \fBBPF_F_INGRESS\fP value in \fIflags\fP is used
670 to make the distinction (ingress path is selected if the flag
671 is present, egress path otherwise). Currently, XDP only
672 supports redirection to the egress interface, and accepts no
673 flag at all.
674 .sp
675 The same effect can also be attained with the more generic
676 \fBbpf_redirect_map\fP(), which uses a BPF map to store the
677 redirect target instead of providing it directly to the helper.
678 .TP
679 .B Return
680 For XDP, the helper returns \fBXDP_REDIRECT\fP on success or
681 \fBXDP_ABORTED\fP on error. For other program types, the values
682 are \fBTC_ACT_REDIRECT\fP on success or \fBTC_ACT_SHOT\fP on
683 error.
684 .UNINDENT
685 .TP
686 .B \fBu32 bpf_get_route_realm(struct sk_buff *\fP\fIskb\fP\fB)\fP
687 .INDENT 7.0
688 .TP
689 .B Description
690 Retrieve the realm or the route, that is to say the
691 \fBtclassid\fP field of the destination for the \fIskb\fP\&. The
692 identifier retrieved is a user\-provided tag, similar to the
693 one used with the net_cls cgroup (see description for
694 \fBbpf_get_cgroup_classid\fP() helper), but here this tag is
695 held by a route (a destination entry), not by a task.
696 .sp
697 Retrieving this identifier works with the clsact TC egress hook
698 (see also \fBtc\-bpf(8)\fP), or alternatively on conventional
699 classful egress qdiscs, but not on TC ingress path. In case of
700 clsact TC egress hook, this has the advantage that, internally,
701 the destination entry has not been dropped yet in the transmit
702 path. Therefore, the destination entry does not need to be
703 artificially held via \fBnetif_keep_dst\fP() for a classful
704 qdisc until the \fIskb\fP is freed.
705 .sp
706 This helper is available only if the kernel was compiled with
707 \fBCONFIG_IP_ROUTE_CLASSID\fP configuration option.
708 .TP
709 .B Return
710 The realm of the route for the packet associated to \fIskb\fP, or 0
711 if none was found.
712 .UNINDENT
713 .TP
714 .B \fBlong bpf_perf_event_output(void *\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
715 .INDENT 7.0
716 .TP
717 .B Description
718 Write raw \fIdata\fP blob into a special BPF perf event held by
719 \fImap\fP of type \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. This perf
720 event must have the following attributes: \fBPERF_SAMPLE_RAW\fP
721 as \fBsample_type\fP, \fBPERF_TYPE_SOFTWARE\fP as \fBtype\fP, and
722 \fBPERF_COUNT_SW_BPF_OUTPUT\fP as \fBconfig\fP\&.
723 .sp
724 The \fIflags\fP are used to indicate the index in \fImap\fP for which
725 the value must be put, masked with \fBBPF_F_INDEX_MASK\fP\&.
726 Alternatively, \fIflags\fP can be set to \fBBPF_F_CURRENT_CPU\fP
727 to indicate that the index of the current CPU core should be
728 used.
729 .sp
730 The value to write, of \fIsize\fP, is passed through eBPF stack and
731 pointed by \fIdata\fP\&.
732 .sp
733 The context of the program \fIctx\fP needs also be passed to the
734 helper.
735 .sp
736 On user space, a program willing to read the values needs to
737 call \fBperf_event_open\fP() on the perf event (either for
738 one or for all CPUs) and to store the file descriptor into the
739 \fImap\fP\&. This must be done before the eBPF program can send data
740 into it. An example is available in file
741 \fIsamples/bpf/trace_output_user.c\fP in the Linux kernel source
742 tree (the eBPF program counterpart is in
743 \fIsamples/bpf/trace_output_kern.c\fP).
744 .sp
745 \fBbpf_perf_event_output\fP() achieves better performance
746 than \fBbpf_trace_printk\fP() for sharing data with user
747 space, and is much better suitable for streaming data from eBPF
748 programs.
749 .sp
750 Note that this helper is not restricted to tracing use cases
751 and can be used with programs attached to TC or XDP as well,
752 where it allows for passing data to user space listeners. Data
753 can be:
754 .INDENT 7.0
755 .IP \(bu 2
756 Only custom structs,
757 .IP \(bu 2
758 Only the packet payload, or
759 .IP \(bu 2
760 A combination of both.
761 .UNINDENT
762 .TP
763 .B Return
764 0 on success, or a negative error in case of failure.
765 .UNINDENT
766 .TP
767 .B \fBlong bpf_skb_load_bytes(const void *\fP\fIskb\fP\fB, u32\fP \fIoffset\fP\fB, void *\fP\fIto\fP\fB, u32\fP \fIlen\fP\fB)\fP
768 .INDENT 7.0
769 .TP
770 .B Description
771 This helper was provided as an easy way to load data from a
772 packet. It can be used to load \fIlen\fP bytes from \fIoffset\fP from
773 the packet associated to \fIskb\fP, into the buffer pointed by
774 \fIto\fP\&.
775 .sp
776 Since Linux 4.7, usage of this helper has mostly been replaced
777 by \(dqdirect packet access\(dq, enabling packet data to be
778 manipulated with \fIskb\fP\fB\->data\fP and \fIskb\fP\fB\->data_end\fP
779 pointing respectively to the first byte of packet data and to
780 the byte after the last byte of packet data. However, it
781 remains useful if one wishes to read large quantities of data
782 at once from a packet into the eBPF stack.
783 .TP
784 .B Return
785 0 on success, or a negative error in case of failure.
786 .UNINDENT
787 .TP
788 .B \fBlong bpf_get_stackid(void *\fP\fIctx\fP\fB, struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB)\fP
789 .INDENT 7.0
790 .TP
791 .B Description
792 Walk a user or a kernel stack and return its id. To achieve
793 this, the helper needs \fIctx\fP, which is a pointer to the context
794 on which the tracing program is executed, and a pointer to a
795 \fImap\fP of type \fBBPF_MAP_TYPE_STACK_TRACE\fP\&.
796 .sp
797 The last argument, \fIflags\fP, holds the number of stack frames to
798 skip (from 0 to 255), masked with
799 \fBBPF_F_SKIP_FIELD_MASK\fP\&. The next bits can be used to set
800 a combination of the following flags:
801 .INDENT 7.0
802 .TP
803 .B \fBBPF_F_USER_STACK\fP
804 Collect a user space stack instead of a kernel stack.
805 .TP
806 .B \fBBPF_F_FAST_STACK_CMP\fP
807 Compare stacks by hash only.
808 .TP
809 .B \fBBPF_F_REUSE_STACKID\fP
810 If two different stacks hash into the same \fIstackid\fP,
811 discard the old one.
812 .UNINDENT
813 .sp
814 The stack id retrieved is a 32 bit long integer handle which
815 can be further combined with other data (including other stack
816 ids) and used as a key into maps. This can be useful for
817 generating a variety of graphs (such as flame graphs or off\-cpu
818 graphs).
819 .sp
820 For walking a stack, this helper is an improvement over
821 \fBbpf_probe_read\fP(), which can be used with unrolled loops
822 but is not efficient and consumes a lot of eBPF instructions.
823 Instead, \fBbpf_get_stackid\fP() can collect up to
824 \fBPERF_MAX_STACK_DEPTH\fP both kernel and user frames. Note that
825 this limit can be controlled with the \fBsysctl\fP program, and
826 that it should be manually increased in order to profile long
827 user stacks (such as stacks for Java programs). To do so, use:
828 .INDENT 7.0
829 .INDENT 3.5
830 .sp
831 .EX
832 # sysctl kernel.perf_event_max_stack=<new value>
833 .EE
834 .UNINDENT
835 .UNINDENT
836 .TP
837 .B Return
838 The positive or null stack id on success, or a negative error
839 in 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
846 Compute a checksum difference, from the raw buffer pointed by
847 \fIfrom\fP, of length \fIfrom_size\fP (that must be a multiple of 4),
848 towards 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
851 to the helper).
852 .sp
853 This is flexible enough to be used in several ways:
854 .INDENT 7.0
855 .IP \(bu 2
856 With \fIfrom_size\fP == 0, \fIto_size\fP > 0 and \fIseed\fP set to
857 checksum, it can be used when pushing new data.
858 .IP \(bu 2
859 With \fIfrom_size\fP > 0, \fIto_size\fP == 0 and \fIseed\fP set to
860 checksum, it can be used when removing data from a packet.
861 .IP \(bu 2
862 With \fIfrom_size\fP > 0, \fIto_size\fP > 0 and \fIseed\fP set to 0, it
863 can 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
867 This helper can be used in combination with
868 \fBbpf_l3_csum_replace\fP() and \fBbpf_l4_csum_replace\fP(), to
869 which one can feed in the difference computed with
870 \fBbpf_csum_diff\fP().
871 .TP
872 .B Return
873 The checksum result, or a negative error code in case of
874 failure.
875 .UNINDENT
876 .TP
877 .B \fBlong bpf_skb_get_tunnel_opt(struct sk_buff *\fP\fIskb\fP\fB, void *\fP\fIopt\fP\fB, u32\fP \fIsize\fP\fB)\fP
878 .INDENT 7.0
879 .TP
880 .B Description
881 Retrieve tunnel options metadata for the packet associated to
882 \fIskb\fP, and store the raw tunnel option data to the buffer \fIopt\fP
883 of \fIsize\fP\&.
884 .sp
885 This helper can be used with encapsulation devices that can
886 operate in \(dqcollect metadata\(dq mode (please refer to the related
887 note in the description of \fBbpf_skb_get_tunnel_key\fP() for
888 more details). A particular example where this can be used is
889 in combination with the Geneve encapsulation protocol, where it
890 allows for pushing (with \fBbpf_skb_get_tunnel_opt\fP() helper)
891 and retrieving arbitrary TLVs (Type\-Length\-Value headers) from
892 the eBPF program. This allows for full customization of these
893 headers.
894 .TP
895 .B Return
896 The size of the option data retrieved.
897 .UNINDENT
898 .TP
899 .B \fBlong bpf_skb_set_tunnel_opt(struct sk_buff *\fP\fIskb\fP\fB, void *\fP\fIopt\fP\fB, u32\fP \fIsize\fP\fB)\fP
900 .INDENT 7.0
901 .TP
902 .B Description
903 Set tunnel options metadata for the packet associated to \fIskb\fP
904 to the option data contained in the raw buffer \fIopt\fP of \fIsize\fP\&.
905 .sp
906 See also the description of the \fBbpf_skb_get_tunnel_opt\fP()
907 helper for additional information.
908 .TP
909 .B Return
910 0 on success, or a negative error in case of failure.
911 .UNINDENT
912 .TP
913 .B \fBlong 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
917 Change the protocol of the \fIskb\fP to \fIproto\fP\&. Currently
918 supported are transition from IPv4 to IPv6, and from IPv6 to
919 IPv4. The helper takes care of the groundwork for the
920 transition, including resizing the socket buffer. The eBPF
921 program 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
924 operations out of an eBPF program.
925 .sp
926 Internally, the GSO type is marked as dodgy so that headers are
927 checked and segments are recalculated by the GSO/GRO engine.
928 The size for GSO target is adapted as well.
929 .sp
930 All values for \fIflags\fP are reserved for future usage, and must
931 be left at zero.
932 .sp
933 A call to this helper is susceptible to change the underlying
934 packet buffer. Therefore, at load time, all checks on pointers
935 previously done by the verifier are invalidated and must be
936 performed again, if the helper is used in combination with
937 direct packet access.
938 .TP
939 .B Return
940 0 on success, or a negative error in case of failure.
941 .UNINDENT
942 .TP
943 .B \fBlong 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
947 Change the packet type for the packet associated to \fIskb\fP\&. This
948 comes down to setting \fIskb\fP\fB\->pkt_type\fP to \fItype\fP, except
949 the eBPF program does not have a write access to \fIskb\fP\fB\->pkt_type\fP beside this helper. Using a helper here allows
950 for graceful handling of errors.
951 .sp
952 The major use case is to change incoming \fIskb*s to
953 **PACKET_HOST*\fP in a programmatic way instead of having to
954 recirculate via \fBredirect\fP(..., \fBBPF_F_INGRESS\fP), for
955 example.
956 .sp
957 Note that \fItype\fP only allows certain values. At this time, they
958 are:
959 .INDENT 7.0
960 .TP
961 .B \fBPACKET_HOST\fP
962 Packet is for us.
963 .TP
964 .B \fBPACKET_BROADCAST\fP
965 Send packet to all.
966 .TP
967 .B \fBPACKET_MULTICAST\fP
968 Send packet to group.
969 .TP
970 .B \fBPACKET_OTHERHOST\fP
971 Send packet to someone else.
972 .UNINDENT
973 .TP
974 .B Return
975 0 on success, or a negative error in case of failure.
976 .UNINDENT
977 .TP
978 .B \fBlong 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
982 Check 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
986 The return value depends on the result of the test, and can be:
987 .INDENT 7.0
988 .IP \(bu 2
989 0, if the \fIskb\fP failed the cgroup2 descendant test.
990 .IP \(bu 2
991 1, if the \fIskb\fP succeeded the cgroup2 descendant test.
992 .IP \(bu 2
993 A 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
1001 Retrieve the hash of the packet, \fIskb\fP\fB\->hash\fP\&. If it is
1002 not set, in particular if the hash was cleared due to mangling,
1003 recompute this hash. Later accesses to the hash can be done
1004 directly with \fIskb\fP\fB\->hash\fP\&.
1005 .sp
1006 Calling \fBbpf_set_hash_invalid\fP(), changing a packet
1007 prototype 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
1010 the hash and to trigger a new computation for the next call to
1011 \fBbpf_get_hash_recalc\fP().
1012 .TP
1013 .B Return
1014 The 32\-bit hash.
1015 .UNINDENT
1016 .TP
1017 .B \fBu64 bpf_get_current_task(void)\fP
1018 .INDENT 7.0
1019 .TP
1020 .B Description
1021 Get the current task.
1022 .TP
1023 .B Return
1024 A pointer to the current task struct.
1025 .UNINDENT
1026 .TP
1027 .B \fBlong bpf_probe_write_user(void *\fP\fIdst\fP\fB, const void *\fP\fIsrc\fP\fB, u32\fP \fIlen\fP\fB)\fP
1028 .INDENT 7.0
1029 .TP
1030 .B Description
1031 Attempt in a safe way to write \fIlen\fP bytes from the buffer
1032 \fIsrc\fP to \fIdst\fP in memory. It only works for threads that are in
1033 user context, and \fIdst\fP must be a valid user space address.
1034 .sp
1035 This helper should not be used to implement any kind of
1036 security mechanism because of TOC\-TOU attacks, but rather to
1037 debug, divert, and manipulate execution of semi\-cooperative
1038 processes.
1039 .sp
1040 Keep in mind that this feature is meant for experiments, and it
1041 has a risk of crashing the system and running programs.
1042 Therefore, when an eBPF program using this helper is attached,
1043 a warning including PID and process name is printed to kernel
1044 logs.
1045 .TP
1046 .B Return
1047 0 on success, or a negative error in case of failure.
1048 .UNINDENT
1049 .TP
1050 .B \fBlong bpf_current_task_under_cgroup(struct bpf_map *\fP\fImap\fP\fB, u32\fP \fIindex\fP\fB)\fP
1051 .INDENT 7.0
1052 .TP
1053 .B Description
1054 Check whether the probe is being run is the context of a given
1055 subset of the cgroup2 hierarchy. The cgroup2 to test is held by
1056 \fImap\fP of type \fBBPF_MAP_TYPE_CGROUP_ARRAY\fP, at \fIindex\fP\&.
1057 .TP
1058 .B Return
1059 The return value depends on the result of the test, and can be:
1060 .INDENT 7.0
1061 .IP \(bu 2
1062 1, if current task belongs to the cgroup2.
1063 .IP \(bu 2
1064 0, if current task does not belong to the cgroup2.
1065 .IP \(bu 2
1066 A negative error code, if an error occurred.
1067 .UNINDENT
1068 .UNINDENT
1069 .TP
1070 .B \fBlong bpf_skb_change_tail(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
1071 .INDENT 7.0
1072 .TP
1073 .B Description
1074 Resize (trim or grow) the packet associated to \fIskb\fP to the
1075 new \fIlen\fP\&. The \fIflags\fP are reserved for future usage, and must
1076 be left at zero.
1077 .sp
1078 The basic idea is that the helper performs the needed work to
1079 change the size of the packet, then the eBPF program rewrites
1080 the rest via helpers like \fBbpf_skb_store_bytes\fP(),
1081 \fBbpf_l3_csum_replace\fP(), \fBbpf_l3_csum_replace\fP()
1082 and others. This helper is a slow path utility intended for
1083 replies with control messages. And because it is targeted for
1084 slow path, the helper itself can afford to be slow: it
1085 implicitly linearizes, unclones and drops offloads from the
1086 \fIskb\fP\&.
1087 .sp
1088 A call to this helper is susceptible to change the underlying
1089 packet buffer. Therefore, at load time, all checks on pointers
1090 previously done by the verifier are invalidated and must be
1091 performed again, if the helper is used in combination with
1092 direct packet access.
1093 .TP
1094 .B Return
1095 0 on success, or a negative error in case of failure.
1096 .UNINDENT
1097 .TP
1098 .B \fBlong bpf_skb_pull_data(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIlen\fP\fB)\fP
1099 .INDENT 7.0
1100 .TP
1101 .B Description
1102 Pull in non\-linear data in case the \fIskb\fP is non\-linear and not
1103 all of \fIlen\fP are part of the linear section. Make \fIlen\fP bytes
1104 from \fIskb\fP readable and writable. If a zero value is passed for
1105 \fIlen\fP, then all bytes in the linear part of \fIskb\fP will be made
1106 readable and writable.
1107 .sp
1108 This helper is only needed for reading and writing with direct
1109 packet access.
1110 .sp
1111 For direct packet access, testing that offsets to access
1112 are within packet boundaries (test on \fIskb\fP\fB\->data_end\fP) is
1113 susceptible to fail if offsets are invalid, or if the requested
1114 data is in non\-linear parts of the \fIskb\fP\&. On failure the
1115 program can just bail out, or in the case of a non\-linear
1116 buffer, use a helper to make the data available. The
1117 \fBbpf_skb_load_bytes\fP() helper is a first solution to access
1118 the data. Another one consists in using \fBbpf_skb_pull_data\fP
1119 to pull in once the non\-linear parts, then retesting and
1120 eventually access the data.
1121 .sp
1122 At the same time, this also makes sure the \fIskb\fP is uncloned,
1123 which is a necessary condition for direct write. As this needs
1124 to be an invariant for the write part only, the verifier
1125 detects writes and adds a prologue that is calling
1126 \fBbpf_skb_pull_data()\fP to effectively unclone the \fIskb\fP from
1127 the very beginning in case it is indeed cloned.
1128 .sp
1129 A call to this helper is susceptible to change the underlying
1130 packet buffer. Therefore, at load time, all checks on pointers
1131 previously done by the verifier are invalidated and must be
1132 performed again, if the helper is used in combination with
1133 direct packet access.
1134 .TP
1135 .B Return
1136 0 on success, or a negative error in case of failure.
1137 .UNINDENT
1138 .TP
1139 .B \fBs64 bpf_csum_update(struct sk_buff *\fP\fIskb\fP\fB, __wsum\fP \fIcsum\fP\fB)\fP
1140 .INDENT 7.0
1141 .TP
1142 .B Description
1143 Add the checksum \fIcsum\fP into \fIskb\fP\fB\->csum\fP in case the
1144 driver has supplied a checksum for the entire packet into that
1145 field. Return an error otherwise. This helper is intended to be
1146 used in combination with \fBbpf_csum_diff\fP(), in particular
1147 when the checksum needs to be updated after data has been
1148 written into the packet through direct packet access.
1149 .TP
1150 .B Return
1151 The checksum on success, or a negative error code in case of
1152 failure.
1153 .UNINDENT
1154 .TP
1155 .B \fBvoid bpf_set_hash_invalid(struct sk_buff *\fP\fIskb\fP\fB)\fP
1156 .INDENT 7.0
1157 .TP
1158 .B Description
1159 Invalidate the current \fIskb\fP\fB\->hash\fP\&. It can be used after
1160 mangling on headers through direct packet access, in order to
1161 indicate that the hash is outdated and to trigger a
1162 recalculation the next time the kernel tries to access this
1163 hash or when the \fBbpf_get_hash_recalc\fP() helper is called.
1164 .TP
1165 .B Return
1166 void.
1167 .UNINDENT
1168 .TP
1169 .B \fBlong bpf_get_numa_node_id(void)\fP
1170 .INDENT 7.0
1171 .TP
1172 .B Description
1173 Return the id of the current NUMA node. The primary use case
1174 for this helper is the selection of sockets for the local NUMA
1175 node, when the program is attached to sockets using the
1176 \fBSO_ATTACH_REUSEPORT_EBPF\fP option (see also \fBsocket(7)\fP),
1177 but the helper is also available to other eBPF program types,
1178 similarly to \fBbpf_get_smp_processor_id\fP().
1179 .TP
1180 .B Return
1181 The id of current NUMA node.
1182 .UNINDENT
1183 .TP
1184 .B \fBlong bpf_skb_change_head(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
1185 .INDENT 7.0
1186 .TP
1187 .B Description
1188 Grows headroom of packet associated to \fIskb\fP and adjusts the
1189 offset of the MAC header accordingly, adding \fIlen\fP bytes of
1190 space. It automatically extends and reallocates memory as
1191 required.
1192 .sp
1193 This helper can be used on a layer 3 \fIskb\fP to push a MAC header
1194 for redirection into a layer 2 device.
1195 .sp
1196 All values for \fIflags\fP are reserved for future usage, and must
1197 be left at zero.
1198 .sp
1199 A call to this helper is susceptible to change the underlying
1200 packet buffer. Therefore, at load time, all checks on pointers
1201 previously done by the verifier are invalidated and must be
1202 performed again, if the helper is used in combination with
1203 direct packet access.
1204 .TP
1205 .B Return
1206 0 on success, or a negative error in case of failure.
1207 .UNINDENT
1208 .TP
1209 .B \fBlong bpf_xdp_adjust_head(struct xdp_buff *\fP\fIxdp_md\fP\fB, int\fP \fIdelta\fP\fB)\fP
1210 .INDENT 7.0
1211 .TP
1212 .B Description
1213 Adjust (move) \fIxdp_md\fP\fB\->data\fP by \fIdelta\fP bytes. Note that
1214 it is possible to use a negative value for \fIdelta\fP\&. This helper
1215 can be used to prepare the packet for pushing or popping
1216 headers.
1217 .sp
1218 A call to this helper is susceptible to change the underlying
1219 packet buffer. Therefore, at load time, all checks on pointers
1220 previously done by the verifier are invalidated and must be
1221 performed again, if the helper is used in combination with
1222 direct packet access.
1223 .TP
1224 .B Return
1225 0 on success, or a negative error in case of failure.
1226 .UNINDENT
1227 .TP
1228 .B \fBlong bpf_probe_read_str(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
1229 .INDENT 7.0
1230 .TP
1231 .B Description
1232 Copy a NUL terminated string from an unsafe kernel address
1233 \fIunsafe_ptr\fP to \fIdst\fP\&. See \fBbpf_probe_read_kernel_str\fP() for
1234 more details.
1235 .sp
1236 Generally, use \fBbpf_probe_read_user_str\fP() or
1237 \fBbpf_probe_read_kernel_str\fP() instead.
1238 .TP
1239 .B Return
1240 On success, the strictly positive length of the string,
1241 including the trailing NUL character. On error, a negative
1242 value.
1243 .UNINDENT
1244 .TP
1245 .B \fBu64 bpf_get_socket_cookie(struct sk_buff *\fP\fIskb\fP\fB)\fP
1246 .INDENT 7.0
1247 .TP
1248 .B Description
1249 If the \fBstruct sk_buff\fP pointed by \fIskb\fP has a known socket,
1250 retrieve the cookie (generated by the kernel) of this socket.
1251 If no cookie has been set yet, generate a new cookie. Once
1252 generated, the socket cookie remains stable for the life of the
1253 socket. This helper can be useful for monitoring per socket
1254 networking traffic statistics as it provides a global socket
1255 identifier that can be assumed unique.
1256 .TP
1257 .B Return
1258 A 8\-byte long unique number on success, or 0 if the socket
1259 field is missing inside \fIskb\fP\&.
1260 .UNINDENT
1261 .TP
1262 .B \fBu64 bpf_get_socket_cookie(struct bpf_sock_addr *\fP\fIctx\fP\fB)\fP
1263 .INDENT 7.0
1264 .TP
1265 .B Description
1266 Equivalent to bpf_get_socket_cookie() helper that accepts
1267 \fIskb\fP, but gets socket from \fBstruct bpf_sock_addr\fP context.
1268 .TP
1269 .B Return
1270 A 8\-byte long unique number.
1271 .UNINDENT
1272 .TP
1273 .B \fBu64 bpf_get_socket_cookie(struct bpf_sock_ops *\fP\fIctx\fP\fB)\fP
1274 .INDENT 7.0
1275 .TP
1276 .B Description
1277 Equivalent to \fBbpf_get_socket_cookie\fP() helper that accepts
1278 \fIskb\fP, but gets socket from \fBstruct bpf_sock_ops\fP context.
1279 .TP
1280 .B Return
1281 A 8\-byte long unique number.
1282 .UNINDENT
1283 .TP
1284 .B \fBu64 bpf_get_socket_cookie(struct sock *\fP\fIsk\fP\fB)\fP
1285 .INDENT 7.0
1286 .TP
1287 .B Description
1288 Equivalent to \fBbpf_get_socket_cookie\fP() helper that accepts
1289 \fIsk\fP, but gets socket from a BTF \fBstruct sock\fP\&. This helper
1290 also works for sleepable programs.
1291 .TP
1292 .B Return
1293 A 8\-byte long unique number or 0 if \fIsk\fP is NULL.
1294 .UNINDENT
1295 .TP
1296 .B \fBu32 bpf_get_socket_uid(struct sk_buff *\fP\fIskb\fP\fB)\fP
1297 .INDENT 7.0
1298 .TP
1299 .B Description
1300 Get the owner UID of the socked associated to \fIskb\fP\&.
1301 .TP
1302 .B Return
1303 The owner UID of the socket associated to \fIskb\fP\&. If the socket
1304 is \fBNULL\fP, or if it is not a full socket (i.e. if it is a
1305 time\-wait or a request socket instead), \fBoverflowuid\fP value
1306 is returned (note that \fBoverflowuid\fP might also be the actual
1307 UID value for the socket).
1308 .UNINDENT
1309 .TP
1310 .B \fBlong bpf_set_hash(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIhash\fP\fB)\fP
1311 .INDENT 7.0
1312 .TP
1313 .B Description
1314 Set the full hash for \fIskb\fP (set the field \fIskb\fP\fB\->hash\fP)
1315 to value \fIhash\fP\&.
1316 .TP
1317 .B Return
1318 0
1319 .UNINDENT
1320 .TP
1321 .B \fBlong bpf_setsockopt(void *\fP\fIbpf_socket\fP\fB, int\fP \fIlevel\fP\fB, int\fP \fIoptname\fP\fB, void *\fP\fIoptval\fP\fB, int\fP \fIoptlen\fP\fB)\fP
1322 .INDENT 7.0
1323 .TP
1324 .B Description
1325 Emulate a call to \fBsetsockopt()\fP on the socket associated to
1326 \fIbpf_socket\fP, which must be a full socket. The \fIlevel\fP at
1327 which the option resides and the name \fIoptname\fP of the option
1328 must be specified, see \fBsetsockopt(2)\fP for more information.
1329 The option value of length \fIoptlen\fP is pointed by \fIoptval\fP\&.
1330 .sp
1331 \fIbpf_socket\fP should be one of the following:
1332 .INDENT 7.0
1333 .IP \(bu 2
1334 \fBstruct bpf_sock_ops\fP for \fBBPF_PROG_TYPE_SOCK_OPS\fP\&.
1335 .IP \(bu 2
1336 \fBstruct bpf_sock_addr\fP for \fBBPF_CGROUP_INET4_CONNECT\fP,
1337 \fBBPF_CGROUP_INET6_CONNECT\fP and \fBBPF_CGROUP_UNIX_CONNECT\fP\&.
1338 .UNINDENT
1339 .sp
1340 This helper actually implements a subset of \fBsetsockopt()\fP\&.
1341 It supports the following \fIlevel\fPs:
1342 .INDENT 7.0
1343 .IP \(bu 2
1344 \fBSOL_SOCKET\fP, which supports the following \fIoptname\fPs:
1345 \fBSO_RCVBUF\fP, \fBSO_SNDBUF\fP, \fBSO_MAX_PACING_RATE\fP,
1346 \fBSO_PRIORITY\fP, \fBSO_RCVLOWAT\fP, \fBSO_MARK\fP,
1347 \fBSO_BINDTODEVICE\fP, \fBSO_KEEPALIVE\fP, \fBSO_REUSEADDR\fP,
1348 \fBSO_REUSEPORT\fP, \fBSO_BINDTOIFINDEX\fP, \fBSO_TXREHASH\fP\&.
1349 .IP \(bu 2
1350 \fBIPPROTO_TCP\fP, which supports the following \fIoptname\fPs:
1351 \fBTCP_CONGESTION\fP, \fBTCP_BPF_IW\fP,
1352 \fBTCP_BPF_SNDCWND_CLAMP\fP, \fBTCP_SAVE_SYN\fP,
1353 \fBTCP_KEEPIDLE\fP, \fBTCP_KEEPINTVL\fP, \fBTCP_KEEPCNT\fP,
1354 \fBTCP_SYNCNT\fP, \fBTCP_USER_TIMEOUT\fP, \fBTCP_NOTSENT_LOWAT\fP,
1355 \fBTCP_NODELAY\fP, \fBTCP_MAXSEG\fP, \fBTCP_WINDOW_CLAMP\fP,
1356 \fBTCP_THIN_LINEAR_TIMEOUTS\fP, \fBTCP_BPF_DELACK_MAX\fP,
1357 \fBTCP_BPF_RTO_MIN\fP, \fBTCP_BPF_SOCK_OPS_CB_FLAGS\fP\&.
1358 .IP \(bu 2
1359 \fBIPPROTO_IP\fP, which supports \fIoptname\fP \fBIP_TOS\fP\&.
1360 .IP \(bu 2
1361 \fBIPPROTO_IPV6\fP, which supports the following \fIoptname\fPs:
1362 \fBIPV6_TCLASS\fP, \fBIPV6_AUTOFLOWLABEL\fP\&.
1363 .UNINDENT
1364 .TP
1365 .B Return
1366 0 on success, or a negative error in case of failure.
1367 .UNINDENT
1368 .TP
1369 .B \fBlong bpf_skb_adjust_room(struct sk_buff *\fP\fIskb\fP\fB, s32\fP \fIlen_diff\fP\fB, u32\fP \fImode\fP\fB, u64\fP \fIflags\fP\fB)\fP
1370 .INDENT 7.0
1371 .TP
1372 .B Description
1373 Grow or shrink the room for data in the packet associated to
1374 \fIskb\fP by \fIlen_diff\fP, and according to the selected \fImode\fP\&.
1375 .sp
1376 By default, the helper will reset any offloaded checksum
1377 indicator of the skb to CHECKSUM_NONE. This can be avoided
1378 by the following flag:
1379 .INDENT 7.0
1380 .IP \(bu 2
1381 \fBBPF_F_ADJ_ROOM_NO_CSUM_RESET\fP: Do not reset offloaded
1382 checksum data of the skb to CHECKSUM_NONE.
1383 .UNINDENT
1384 .sp
1385 There are two supported modes at this time:
1386 .INDENT 7.0
1387 .IP \(bu 2
1388 \fBBPF_ADJ_ROOM_MAC\fP: Adjust room at the mac layer
1389 (room space is added or removed between the layer 2 and
1390 layer 3 headers).
1391 .IP \(bu 2
1392 \fBBPF_ADJ_ROOM_NET\fP: Adjust room at the network layer
1393 (room space is added or removed between the layer 3 and
1394 layer 4 headers).
1395 .UNINDENT
1396 .sp
1397 The following flags are supported at this time:
1398 .INDENT 7.0
1399 .IP \(bu 2
1400 \fBBPF_F_ADJ_ROOM_FIXED_GSO\fP: Do not adjust gso_size.
1401 Adjusting mss in this way is not allowed for datagrams.
1402 .IP \(bu 2
1403 \fBBPF_F_ADJ_ROOM_ENCAP_L3_IPV4\fP,
1404 \fBBPF_F_ADJ_ROOM_ENCAP_L3_IPV6\fP:
1405 Any new space is reserved to hold a tunnel header.
1406 Configure skb offsets and other fields accordingly.
1407 .IP \(bu 2
1408 \fBBPF_F_ADJ_ROOM_ENCAP_L4_GRE\fP,
1409 \fBBPF_F_ADJ_ROOM_ENCAP_L4_UDP\fP:
1410 Use with ENCAP_L3 flags to further specify the tunnel type.
1411 .IP \(bu 2
1412 \fBBPF_F_ADJ_ROOM_ENCAP_L2\fP(\fIlen\fP):
1413 Use with ENCAP_L3/L4 flags to further specify the tunnel
1414 type; \fIlen\fP is the length of the inner MAC header.
1415 .IP \(bu 2
1416 \fBBPF_F_ADJ_ROOM_ENCAP_L2_ETH\fP:
1417 Use with BPF_F_ADJ_ROOM_ENCAP_L2 flag to further specify the
1418 L2 type as Ethernet.
1419 .IP \(bu 2
1420 \fBBPF_F_ADJ_ROOM_DECAP_L3_IPV4\fP,
1421 \fBBPF_F_ADJ_ROOM_DECAP_L3_IPV6\fP:
1422 Indicate the new IP header version after decapsulating the outer
1423 IP header. Used when the inner and outer IP versions are different.
1424 .UNINDENT
1425 .sp
1426 A call to this helper is susceptible to change the underlying
1427 packet buffer. Therefore, at load time, all checks on pointers
1428 previously done by the verifier are invalidated and must be
1429 performed again, if the helper is used in combination with
1430 direct packet access.
1431 .TP
1432 .B Return
1433 0 on success, or a negative error in case of failure.
1434 .UNINDENT
1435 .TP
1436 .B \fBlong bpf_redirect_map(struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
1437 .INDENT 7.0
1438 .TP
1439 .B Description
1440 Redirect the packet to the endpoint referenced by \fImap\fP at
1441 index \fIkey\fP\&. Depending on its type, this \fImap\fP can contain
1442 references to net devices (for forwarding packets through other
1443 ports), or to CPUs (for redirecting XDP frames to another CPU;
1444 but this is only implemented for native XDP (with driver
1445 support) as of this writing).
1446 .sp
1447 The lower two bits of \fIflags\fP are used as the return code if
1448 the map lookup fails. This is so that the return value can be
1449 one of the XDP program return codes up to \fBXDP_TX\fP, as chosen
1450 by the caller. The higher bits of \fIflags\fP can be set to
1451 BPF_F_BROADCAST or BPF_F_EXCLUDE_INGRESS as defined below.
1452 .sp
1453 With BPF_F_BROADCAST the packet will be broadcasted to all the
1454 interfaces in the map, with BPF_F_EXCLUDE_INGRESS the ingress
1455 interface will be excluded when do broadcasting.
1456 .sp
1457 See also \fBbpf_redirect\fP(), which only supports redirecting
1458 to an ifindex, but doesn\(aqt require a map to do so.
1459 .TP
1460 .B Return
1461 \fBXDP_REDIRECT\fP on success, or the value of the two lower bits
1462 of the \fIflags\fP argument on error.
1463 .UNINDENT
1464 .TP
1465 .B \fBlong bpf_sk_redirect_map(struct sk_buff *\fP\fIskb\fP\fB, struct bpf_map *\fP\fImap\fP\fB, u32\fP \fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
1466 .INDENT 7.0
1467 .TP
1468 .B Description
1469 Redirect the packet to the socket referenced by \fImap\fP (of type
1470 \fBBPF_MAP_TYPE_SOCKMAP\fP) at index \fIkey\fP\&. Both ingress and
1471 egress interfaces can be used for redirection. The
1472 \fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
1473 distinction (ingress path is selected if the flag is present,
1474 egress path otherwise). This is the only flag supported for now.
1475 .TP
1476 .B Return
1477 \fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
1478 .UNINDENT
1479 .TP
1480 .B \fBlong 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
1481 .INDENT 7.0
1482 .TP
1483 .B Description
1484 Add an entry to, or update a \fImap\fP referencing sockets. The
1485 \fIskops\fP is used as a new value for the entry associated to
1486 \fIkey\fP\&. \fIflags\fP is one of:
1487 .INDENT 7.0
1488 .TP
1489 .B \fBBPF_NOEXIST\fP
1490 The entry for \fIkey\fP must not exist in the map.
1491 .TP
1492 .B \fBBPF_EXIST\fP
1493 The entry for \fIkey\fP must already exist in the map.
1494 .TP
1495 .B \fBBPF_ANY\fP
1496 No condition on the existence of the entry for \fIkey\fP\&.
1497 .UNINDENT
1498 .sp
1499 If the \fImap\fP has eBPF programs (parser and verdict), those will
1500 be inherited by the socket being added. If the socket is
1501 already attached to eBPF programs, this results in an error.
1502 .TP
1503 .B Return
1504 0 on success, or a negative error in case of failure.
1505 .UNINDENT
1506 .TP
1507 .B \fBlong bpf_xdp_adjust_meta(struct xdp_buff *\fP\fIxdp_md\fP\fB, int\fP \fIdelta\fP\fB)\fP
1508 .INDENT 7.0
1509 .TP
1510 .B Description
1511 Adjust the address pointed by \fIxdp_md\fP\fB\->data_meta\fP by
1512 \fIdelta\fP (which can be positive or negative). Note that this
1513 operation modifies the address stored in \fIxdp_md\fP\fB\->data\fP,
1514 so the latter must be loaded only after the helper has been
1515 called.
1516 .sp
1517 The use of \fIxdp_md\fP\fB\->data_meta\fP is optional and programs
1518 are not required to use it. The rationale is that when the
1519 packet is processed with XDP (e.g. as DoS filter), it is
1520 possible to push further meta data along with it before passing
1521 to the stack, and to give the guarantee that an ingress eBPF
1522 program attached as a TC classifier on the same device can pick
1523 this up for further post\-processing. Since TC works with socket
1524 buffers, it remains possible to set from XDP the \fBmark\fP or
1525 \fBpriority\fP pointers, or other pointers for the socket buffer.
1526 Having this scratch space generic and programmable allows for
1527 more flexibility as the user is free to store whatever meta
1528 data they need.
1529 .sp
1530 A call to this helper is susceptible to change the underlying
1531 packet buffer. Therefore, at load time, all checks on pointers
1532 previously done by the verifier are invalidated and must be
1533 performed again, if the helper is used in combination with
1534 direct packet access.
1535 .TP
1536 .B Return
1537 0 on success, or a negative error in case of failure.
1538 .UNINDENT
1539 .TP
1540 .B \fBlong 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
1541 .INDENT 7.0
1542 .TP
1543 .B Description
1544 Read the value of a perf event counter, and store it into \fIbuf\fP
1545 of size \fIbuf_size\fP\&. This helper relies on a \fImap\fP of type
1546 \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. The nature of the perf event
1547 counter is selected when \fImap\fP is updated with perf event file
1548 descriptors. The \fImap\fP is an array whose size is the number of
1549 available CPUs, and each cell contains a value relative to one
1550 CPU. The value to retrieve is indicated by \fIflags\fP, that
1551 contains the index of the CPU to look up, masked with
1552 \fBBPF_F_INDEX_MASK\fP\&. Alternatively, \fIflags\fP can be set to
1553 \fBBPF_F_CURRENT_CPU\fP to indicate that the value for the
1554 current CPU should be retrieved.
1555 .sp
1556 This helper behaves in a way close to
1557 \fBbpf_perf_event_read\fP() helper, save that instead of
1558 just returning the value observed, it fills the \fIbuf\fP
1559 structure. This allows for additional data to be retrieved: in
1560 particular, the enabled and running times (in \fIbuf\fP\fB\->enabled\fP and \fIbuf\fP\fB\->running\fP, respectively) are
1561 copied. In general, \fBbpf_perf_event_read_value\fP() is
1562 recommended over \fBbpf_perf_event_read\fP(), which has some
1563 ABI issues and provides fewer functionalities.
1564 .sp
1565 These values are interesting, because hardware PMU (Performance
1566 Monitoring Unit) counters are limited resources. When there are
1567 more PMU based perf events opened than available counters,
1568 kernel will multiplex these events so each event gets certain
1569 percentage (but not all) of the PMU time. In case that
1570 multiplexing happens, the number of samples or counter value
1571 will not reflect the case compared to when no multiplexing
1572 occurs. This makes comparison between different runs difficult.
1573 Typically, the counter value should be normalized before
1574 comparing to other experiments. The usual normalization is done
1575 as follows.
1576 .INDENT 7.0
1577 .INDENT 3.5
1578 .sp
1579 .EX
1580 normalized_counter = counter * t_enabled / t_running
1581 .EE
1582 .UNINDENT
1583 .UNINDENT
1584 .sp
1585 Where t_enabled is the time enabled for event and t_running is
1586 the time running for event since last normalization. The
1587 enabled and running times are accumulated since the perf event
1588 open. To achieve scaling factor between two invocations of an
1589 eBPF program, users can use CPU id as the key (which is
1590 typical for perf array usage model) to remember the previous
1591 value and do the calculation inside the eBPF program.
1592 .TP
1593 .B Return
1594 0 on success, or a negative error in case of failure.
1595 .UNINDENT
1596 .TP
1597 .B \fBlong 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
1598 .INDENT 7.0
1599 .TP
1600 .B Description
1601 For an eBPF program attached to a perf event, retrieve the
1602 value of the event counter associated to \fIctx\fP and store it in
1603 the structure pointed by \fIbuf\fP and of size \fIbuf_size\fP\&. Enabled
1604 and running times are also stored in the structure (see
1605 description of helper \fBbpf_perf_event_read_value\fP() for
1606 more details).
1607 .TP
1608 .B Return
1609 0 on success, or a negative error in case of failure.
1610 .UNINDENT
1611 .TP
1612 .B \fBlong bpf_getsockopt(void *\fP\fIbpf_socket\fP\fB, int\fP \fIlevel\fP\fB, int\fP \fIoptname\fP\fB, void *\fP\fIoptval\fP\fB, int\fP \fIoptlen\fP\fB)\fP
1613 .INDENT 7.0
1614 .TP
1615 .B Description
1616 Emulate a call to \fBgetsockopt()\fP on the socket associated to
1617 \fIbpf_socket\fP, which must be a full socket. The \fIlevel\fP at
1618 which the option resides and the name \fIoptname\fP of the option
1619 must be specified, see \fBgetsockopt(2)\fP for more information.
1620 The retrieved value is stored in the structure pointed by
1621 \fIopval\fP and of length \fIoptlen\fP\&.
1622 .sp
1623 \fIbpf_socket\fP should be one of the following:
1624 .INDENT 7.0
1625 .IP \(bu 2
1626 \fBstruct bpf_sock_ops\fP for \fBBPF_PROG_TYPE_SOCK_OPS\fP\&.
1627 .IP \(bu 2
1628 \fBstruct bpf_sock_addr\fP for \fBBPF_CGROUP_INET4_CONNECT\fP,
1629 \fBBPF_CGROUP_INET6_CONNECT\fP and \fBBPF_CGROUP_UNIX_CONNECT\fP\&.
1630 .UNINDENT
1631 .sp
1632 This helper actually implements a subset of \fBgetsockopt()\fP\&.
1633 It supports the same set of \fIoptname\fPs that is supported by
1634 the \fBbpf_setsockopt\fP() helper. The exceptions are
1635 \fBTCP_BPF_*\fP is \fBbpf_setsockopt\fP() only and
1636 \fBTCP_SAVED_SYN\fP is \fBbpf_getsockopt\fP() only.
1637 .TP
1638 .B Return
1639 0 on success, or a negative error in case of failure.
1640 .UNINDENT
1641 .TP
1642 .B \fBlong bpf_override_return(struct pt_regs *\fP\fIregs\fP\fB, u64\fP \fIrc\fP\fB)\fP
1643 .INDENT 7.0
1644 .TP
1645 .B Description
1646 Used for error injection, this helper uses kprobes to override
1647 the return value of the probed function, and to set it to \fIrc\fP\&.
1648 The first argument is the context \fIregs\fP on which the kprobe
1649 works.
1650 .sp
1651 This helper works by setting the PC (program counter)
1652 to an override function which is run in place of the original
1653 probed function. This means the probed function is not run at
1654 all. The replacement function just returns with the required
1655 value.
1656 .sp
1657 This helper has security implications, and thus is subject to
1658 restrictions. It is only available if the kernel was compiled
1659 with the \fBCONFIG_BPF_KPROBE_OVERRIDE\fP configuration
1660 option, and in this case it only works on functions tagged with
1661 \fBALLOW_ERROR_INJECTION\fP in the kernel code.
1662 .TP
1663 .B Return
1664 0
1665 .UNINDENT
1666 .TP
1667 .B \fBlong bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *\fP\fIbpf_sock\fP\fB, int\fP \fIargval\fP\fB)\fP
1668 .INDENT 7.0
1669 .TP
1670 .B Description
1671 Attempt to set the value of the \fBbpf_sock_ops_cb_flags\fP field
1672 for the full TCP socket associated to \fIbpf_sock_ops\fP to
1673 \fIargval\fP\&.
1674 .sp
1675 The primary use of this field is to determine if there should
1676 be calls to eBPF programs of type
1677 \fBBPF_PROG_TYPE_SOCK_OPS\fP at various points in the TCP
1678 code. A program of the same type can change its value, per
1679 connection and as necessary, when the connection is
1680 established. This field is directly accessible for reading, but
1681 this helper must be used for updates in order to return an
1682 error if an eBPF program tries to set a callback that is not
1683 supported in the current kernel.
1684 .sp
1685 \fIargval\fP is a flag array which can combine these flags:
1686 .INDENT 7.0
1687 .IP \(bu 2
1688 \fBBPF_SOCK_OPS_RTO_CB_FLAG\fP (retransmission time out)
1689 .IP \(bu 2
1690 \fBBPF_SOCK_OPS_RETRANS_CB_FLAG\fP (retransmission)
1691 .IP \(bu 2
1692 \fBBPF_SOCK_OPS_STATE_CB_FLAG\fP (TCP state change)
1693 .IP \(bu 2
1694 \fBBPF_SOCK_OPS_RTT_CB_FLAG\fP (every RTT)
1695 .UNINDENT
1696 .sp
1697 Therefore, this function can be used to clear a callback flag by
1698 setting the appropriate bit to zero. e.g. to disable the RTO
1699 callback:
1700 .INDENT 7.0
1701 .TP
1702 .B \fBbpf_sock_ops_cb_flags_set(bpf_sock,\fP
1703 \fBbpf_sock\->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)\fP
1704 .UNINDENT
1705 .sp
1706 Here are some examples of where one could call such eBPF
1707 program:
1708 .INDENT 7.0
1709 .IP \(bu 2
1710 When RTO fires.
1711 .IP \(bu 2
1712 When a packet is retransmitted.
1713 .IP \(bu 2
1714 When the connection terminates.
1715 .IP \(bu 2
1716 When a packet is sent.
1717 .IP \(bu 2
1718 When a packet is received.
1719 .UNINDENT
1720 .TP
1721 .B Return
1722 Code \fB\-EINVAL\fP if the socket is not a full TCP socket;
1723 otherwise, a positive number containing the bits that could not
1724 be set is returned (which comes down to 0 if all bits were set
1725 as required).
1726 .UNINDENT
1727 .TP
1728 .B \fBlong 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
1729 .INDENT 7.0
1730 .TP
1731 .B Description
1732 This helper is used in programs implementing policies at the
1733 socket level. If the message \fImsg\fP is allowed to pass (i.e. if
1734 the verdict eBPF program returns \fBSK_PASS\fP), redirect it to
1735 the socket referenced by \fImap\fP (of type
1736 \fBBPF_MAP_TYPE_SOCKMAP\fP) at index \fIkey\fP\&. Both ingress and
1737 egress interfaces can be used for redirection. The
1738 \fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
1739 distinction (ingress path is selected if the flag is present,
1740 egress path otherwise). This is the only flag supported for now.
1741 .TP
1742 .B Return
1743 \fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
1744 .UNINDENT
1745 .TP
1746 .B \fBlong bpf_msg_apply_bytes(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIbytes\fP\fB)\fP
1747 .INDENT 7.0
1748 .TP
1749 .B Description
1750 For socket policies, apply the verdict of the eBPF program to
1751 the next \fIbytes\fP (number of bytes) of message \fImsg\fP\&.
1752 .sp
1753 For example, this helper can be used in the following cases:
1754 .INDENT 7.0
1755 .IP \(bu 2
1756 A single \fBsendmsg\fP() or \fBsendfile\fP() system call
1757 contains multiple logical messages that the eBPF program is
1758 supposed to read and for which it should apply a verdict.
1759 .IP \(bu 2
1760 An eBPF program only cares to read the first \fIbytes\fP of a
1761 \fImsg\fP\&. If the message has a large payload, then setting up
1762 and calling the eBPF program repeatedly for all bytes, even
1763 though the verdict is already known, would create unnecessary
1764 overhead.
1765 .UNINDENT
1766 .sp
1767 When called from within an eBPF program, the helper sets a
1768 counter internal to the BPF infrastructure, that is used to
1769 apply the last verdict to the next \fIbytes\fP\&. If \fIbytes\fP is
1770 smaller than the current data being processed from a
1771 \fBsendmsg\fP() or \fBsendfile\fP() system call, the first
1772 \fIbytes\fP will be sent and the eBPF program will be re\-run with
1773 the pointer for start of data pointing to byte number \fIbytes\fP
1774 \fB+ 1\fP\&. If \fIbytes\fP is larger than the current data being
1775 processed, then the eBPF verdict will be applied to multiple
1776 \fBsendmsg\fP() or \fBsendfile\fP() calls until \fIbytes\fP are
1777 consumed.
1778 .sp
1779 Note that if a socket closes with the internal counter holding
1780 a non\-zero value, this is not a problem because data is not
1781 being buffered for \fIbytes\fP and is sent as it is received.
1782 .TP
1783 .B Return
1784 0
1785 .UNINDENT
1786 .TP
1787 .B \fBlong bpf_msg_cork_bytes(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIbytes\fP\fB)\fP
1788 .INDENT 7.0
1789 .TP
1790 .B Description
1791 For socket policies, prevent the execution of the verdict eBPF
1792 program for message \fImsg\fP until \fIbytes\fP (byte number) have been
1793 accumulated.
1794 .sp
1795 This can be used when one needs a specific number of bytes
1796 before a verdict can be assigned, even if the data spans
1797 multiple \fBsendmsg\fP() or \fBsendfile\fP() calls. The extreme
1798 case would be a user calling \fBsendmsg\fP() repeatedly with
1799 1\-byte long message segments. Obviously, this is bad for
1800 performance, but it is still valid. If the eBPF program needs
1801 \fIbytes\fP bytes to validate a header, this helper can be used to
1802 prevent the eBPF program to be called again until \fIbytes\fP have
1803 been accumulated.
1804 .TP
1805 .B Return
1806 0
1807 .UNINDENT
1808 .TP
1809 .B \fBlong 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
1810 .INDENT 7.0
1811 .TP
1812 .B Description
1813 For socket policies, pull in non\-linear data from user space
1814 for \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,
1815 respectively.
1816 .sp
1817 If a program of type \fBBPF_PROG_TYPE_SK_MSG\fP is run on a
1818 \fImsg\fP it can only parse data that the (\fBdata\fP, \fBdata_end\fP)
1819 pointers have already consumed. For \fBsendmsg\fP() hooks this
1820 is likely the first scatterlist element. But for calls relying
1821 on the \fBsendpage\fP handler (e.g. \fBsendfile\fP()) this will
1822 be the range (\fB0\fP, \fB0\fP) because the data is shared with
1823 user space and by default the objective is to avoid allowing
1824 user space to modify data while (or after) eBPF verdict is
1825 being decided. This helper can be used to pull in data and to
1826 set the start and end pointer to given values. Data will be
1827 copied if necessary (i.e. if data was not linear and if start
1828 and end pointers do not point to the same chunk).
1829 .sp
1830 A call to this helper is susceptible to change the underlying
1831 packet buffer. Therefore, at load time, all checks on pointers
1832 previously done by the verifier are invalidated and must be
1833 performed again, if the helper is used in combination with
1834 direct packet access.
1835 .sp
1836 All values for \fIflags\fP are reserved for future usage, and must
1837 be left at zero.
1838 .TP
1839 .B Return
1840 0 on success, or a negative error in case of failure.
1841 .UNINDENT
1842 .TP
1843 .B \fBlong bpf_bind(struct bpf_sock_addr *\fP\fIctx\fP\fB, struct sockaddr *\fP\fIaddr\fP\fB, int\fP \fIaddr_len\fP\fB)\fP
1844 .INDENT 7.0
1845 .TP
1846 .B Description
1847 Bind the socket associated to \fIctx\fP to the address pointed by
1848 \fIaddr\fP, of length \fIaddr_len\fP\&. This allows for making outgoing
1849 connection from the desired IP address, which can be useful for
1850 example when all processes inside a cgroup should use one
1851 single IP address on a host that has multiple IP configured.
1852 .sp
1853 This helper works for IPv4 and IPv6, TCP and UDP sockets. The
1854 domain (\fIaddr\fP\fB\->sa_family\fP) must be \fBAF_INET\fP (or
1855 \fBAF_INET6\fP). It\(aqs advised to pass zero port (\fBsin_port\fP
1856 or \fBsin6_port\fP) which triggers IP_BIND_ADDRESS_NO_PORT\-like
1857 behavior and lets the kernel efficiently pick up an unused
1858 port as long as 4\-tuple is unique. Passing non\-zero port might
1859 lead to degraded performance.
1860 .TP
1861 .B Return
1862 0 on success, or a negative error in case of failure.
1863 .UNINDENT
1864 .TP
1865 .B \fBlong bpf_xdp_adjust_tail(struct xdp_buff *\fP\fIxdp_md\fP\fB, int\fP \fIdelta\fP\fB)\fP
1866 .INDENT 7.0
1867 .TP
1868 .B Description
1869 Adjust (move) \fIxdp_md\fP\fB\->data_end\fP by \fIdelta\fP bytes. It is
1870 possible to both shrink and grow the packet tail.
1871 Shrink done via \fIdelta\fP being a negative integer.
1872 .sp
1873 A call to this helper is susceptible to change the underlying
1874 packet buffer. Therefore, at load time, all checks on pointers
1875 previously done by the verifier are invalidated and must be
1876 performed again, if the helper is used in combination with
1877 direct packet access.
1878 .TP
1879 .B Return
1880 0 on success, or a negative error in case of failure.
1881 .UNINDENT
1882 .TP
1883 .B \fBlong 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
1884 .INDENT 7.0
1885 .TP
1886 .B Description
1887 Retrieve the XFRM state (IP transform framework, see also
1888 \fBip\-xfrm(8)\fP) at \fIindex\fP in XFRM \(dqsecurity path\(dq for \fIskb\fP\&.
1889 .sp
1890 The retrieved value is stored in the \fBstruct bpf_xfrm_state\fP
1891 pointed by \fIxfrm_state\fP and of length \fIsize\fP\&.
1892 .sp
1893 All values for \fIflags\fP are reserved for future usage, and must
1894 be left at zero.
1895 .sp
1896 This helper is available only if the kernel was compiled with
1897 \fBCONFIG_XFRM\fP configuration option.
1898 .TP
1899 .B Return
1900 0 on success, or a negative error in case of failure.
1901 .UNINDENT
1902 .TP
1903 .B \fBlong bpf_get_stack(void *\fP\fIctx\fP\fB, void *\fP\fIbuf\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
1904 .INDENT 7.0
1905 .TP
1906 .B Description
1907 Return a user or a kernel stack in bpf program provided buffer.
1908 To achieve this, the helper needs \fIctx\fP, which is a pointer
1909 to the context on which the tracing program is executed.
1910 To store the stacktrace, the bpf program provides \fIbuf\fP with
1911 a nonnegative \fIsize\fP\&.
1912 .sp
1913 The last argument, \fIflags\fP, holds the number of stack frames to
1914 skip (from 0 to 255), masked with
1915 \fBBPF_F_SKIP_FIELD_MASK\fP\&. The next bits can be used to set
1916 the following flags:
1917 .INDENT 7.0
1918 .TP
1919 .B \fBBPF_F_USER_STACK\fP
1920 Collect a user space stack instead of a kernel stack.
1921 .TP
1922 .B \fBBPF_F_USER_BUILD_ID\fP
1923 Collect (build_id, file_offset) instead of ips for user
1924 stack, only valid if \fBBPF_F_USER_STACK\fP is also
1925 specified.
1926 .sp
1927 \fIfile_offset\fP is an offset relative to the beginning
1928 of the executable or shared object file backing the vma
1929 which the \fIip\fP falls in. It is \fInot\fP an offset relative
1930 to that object\(aqs base address. Accordingly, it must be
1931 adjusted by adding (sh_addr \- sh_offset), where
1932 sh_{addr,offset} correspond to the executable section
1933 containing \fIfile_offset\fP in the object, for comparisons
1934 to symbols\(aq st_value to be valid.
1935 .UNINDENT
1936 .sp
1937 \fBbpf_get_stack\fP() can collect up to
1938 \fBPERF_MAX_STACK_DEPTH\fP both kernel and user frames, subject
1939 to sufficient large buffer size. Note that
1940 this limit can be controlled with the \fBsysctl\fP program, and
1941 that it should be manually increased in order to profile long
1942 user stacks (such as stacks for Java programs). To do so, use:
1943 .INDENT 7.0
1944 .INDENT 3.5
1945 .sp
1946 .EX
1947 # sysctl kernel.perf_event_max_stack=<new value>
1948 .EE
1949 .UNINDENT
1950 .UNINDENT
1951 .TP
1952 .B Return
1953 The non\-negative copied \fIbuf\fP length equal to or less than
1954 \fIsize\fP on success, or a negative error in case of failure.
1955 .UNINDENT
1956 .TP
1957 .B \fBlong bpf_skb_load_bytes_relative(const void *\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
1958 .INDENT 7.0
1959 .TP
1960 .B Description
1961 This helper is similar to \fBbpf_skb_load_bytes\fP() in that
1962 it provides an easy way to load \fIlen\fP bytes from \fIoffset\fP
1963 from the packet associated to \fIskb\fP, into the buffer pointed
1964 by \fIto\fP\&. The difference to \fBbpf_skb_load_bytes\fP() is that
1965 a fifth argument \fIstart_header\fP exists in order to select a
1966 base offset to start from. \fIstart_header\fP can be one of:
1967 .INDENT 7.0
1968 .TP
1969 .B \fBBPF_HDR_START_MAC\fP
1970 Base offset to load data from is \fIskb\fP\(aqs mac header.
1971 .TP
1972 .B \fBBPF_HDR_START_NET\fP
1973 Base offset to load data from is \fIskb\fP\(aqs network header.
1974 .UNINDENT
1975 .sp
1976 In general, \(dqdirect packet access\(dq is the preferred method to
1977 access packet data, however, this helper is in particular useful
1978 in socket filters where \fIskb\fP\fB\->data\fP does not always point
1979 to the start of the mac header and where \(dqdirect packet access\(dq
1980 is not available.
1981 .TP
1982 .B Return
1983 0 on success, or a negative error in case of failure.
1984 .UNINDENT
1985 .TP
1986 .B \fBlong 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
1987 .INDENT 7.0
1988 .TP
1989 .B Description
1990 Do FIB lookup in kernel tables using parameters in \fIparams\fP\&.
1991 If lookup is successful and result shows packet is to be
1992 forwarded, the neighbor tables are searched for the nexthop.
1993 If successful (ie., FIB lookup shows forwarding and nexthop
1994 is resolved), the nexthop address is returned in ipv4_dst
1995 or ipv6_dst based on family, smac is set to mac address of
1996 egress device, dmac is set to nexthop mac address, rt_metric
1997 is set to metric from route (IPv4/IPv6 only), and ifindex
1998 is set to the device index of the nexthop from the FIB lookup.
1999 .sp
2000 \fIplen\fP argument is the size of the passed in struct.
2001 \fIflags\fP argument can be a combination of one or more of the
2002 following values:
2003 .INDENT 7.0
2004 .TP
2005 .B \fBBPF_FIB_LOOKUP_DIRECT\fP
2006 Do a direct table lookup vs full lookup using FIB
2007 rules.
2008 .TP
2009 .B \fBBPF_FIB_LOOKUP_TBID\fP
2010 Used with BPF_FIB_LOOKUP_DIRECT.
2011 Use the routing table ID present in \fIparams\fP\->tbid
2012 for the fib lookup.
2013 .TP
2014 .B \fBBPF_FIB_LOOKUP_OUTPUT\fP
2015 Perform lookup from an egress perspective (default is
2016 ingress).
2017 .TP
2018 .B \fBBPF_FIB_LOOKUP_SKIP_NEIGH\fP
2019 Skip the neighbour table lookup. \fIparams\fP\->dmac
2020 and \fIparams\fP\->smac will not be set as output. A common
2021 use case is to call \fBbpf_redirect_neigh\fP() after
2022 doing \fBbpf_fib_lookup\fP().
2023 .TP
2024 .B \fBBPF_FIB_LOOKUP_SRC\fP
2025 Derive and set source IP addr in \fIparams\fP\->ipv{4,6}_src
2026 for the nexthop. If the src addr cannot be derived,
2027 \fBBPF_FIB_LKUP_RET_NO_SRC_ADDR\fP is returned. In this
2028 case, \fIparams\fP\->dmac and \fIparams\fP\->smac are not set either.
2029 .TP
2030 .B \fBBPF_FIB_LOOKUP_MARK\fP
2031 Use the mark present in \fIparams\fP\->mark for the fib lookup.
2032 This option should not be used with BPF_FIB_LOOKUP_DIRECT,
2033 as it only has meaning for full lookups.
2034 .UNINDENT
2035 .sp
2036 \fIctx\fP is either \fBstruct xdp_md\fP for XDP programs or
2037 \fBstruct sk_buff\fP tc cls_act programs.
2038 .TP
2039 .B Return
2040 .INDENT 7.0
2041 .IP \(bu 2
2042 < 0 if any input argument is invalid
2043 .IP \(bu 2
2044 0 on success (packet is forwarded, nexthop neighbor exists)
2045 .IP \(bu 2
2046 > 0 one of \fBBPF_FIB_LKUP_RET_\fP codes explaining why the
2047 packet is not forwarded or needs assist from full stack
2048 .UNINDENT
2049 .sp
2050 If lookup fails with BPF_FIB_LKUP_RET_FRAG_NEEDED, then the MTU
2051 was exceeded and output params\->mtu_result contains the MTU.
2052 .UNINDENT
2053 .TP
2054 .B \fBlong bpf_sock_hash_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
2055 .INDENT 7.0
2056 .TP
2057 .B Description
2058 Add an entry to, or update a sockhash \fImap\fP referencing sockets.
2059 The \fIskops\fP is used as a new value for the entry associated to
2060 \fIkey\fP\&. \fIflags\fP is one of:
2061 .INDENT 7.0
2062 .TP
2063 .B \fBBPF_NOEXIST\fP
2064 The entry for \fIkey\fP must not exist in the map.
2065 .TP
2066 .B \fBBPF_EXIST\fP
2067 The entry for \fIkey\fP must already exist in the map.
2068 .TP
2069 .B \fBBPF_ANY\fP
2070 No condition on the existence of the entry for \fIkey\fP\&.
2071 .UNINDENT
2072 .sp
2073 If the \fImap\fP has eBPF programs (parser and verdict), those will
2074 be inherited by the socket being added. If the socket is
2075 already attached to eBPF programs, this results in an error.
2076 .TP
2077 .B Return
2078 0 on success, or a negative error in case of failure.
2079 .UNINDENT
2080 .TP
2081 .B \fBlong 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
2082 .INDENT 7.0
2083 .TP
2084 .B Description
2085 This helper is used in programs implementing policies at the
2086 socket level. If the message \fImsg\fP is allowed to pass (i.e. if
2087 the verdict eBPF program returns \fBSK_PASS\fP), redirect it to
2088 the socket referenced by \fImap\fP (of type
2089 \fBBPF_MAP_TYPE_SOCKHASH\fP) using hash \fIkey\fP\&. Both ingress and
2090 egress interfaces can be used for redirection. The
2091 \fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
2092 distinction (ingress path is selected if the flag is present,
2093 egress path otherwise). This is the only flag supported for now.
2094 .TP
2095 .B Return
2096 \fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
2097 .UNINDENT
2098 .TP
2099 .B \fBlong 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
2100 .INDENT 7.0
2101 .TP
2102 .B Description
2103 This helper is used in programs implementing policies at the
2104 skb socket level. If the sk_buff \fIskb\fP is allowed to pass (i.e.
2105 if the verdict eBPF program returns \fBSK_PASS\fP), redirect it
2106 to the socket referenced by \fImap\fP (of type
2107 \fBBPF_MAP_TYPE_SOCKHASH\fP) using hash \fIkey\fP\&. Both ingress and
2108 egress interfaces can be used for redirection. The
2109 \fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
2110 distinction (ingress path is selected if the flag is present,
2111 egress otherwise). This is the only flag supported for now.
2112 .TP
2113 .B Return
2114 \fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
2115 .UNINDENT
2116 .TP
2117 .B \fBlong 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
2118 .INDENT 7.0
2119 .TP
2120 .B Description
2121 Encapsulate the packet associated to \fIskb\fP within a Layer 3
2122 protocol header. This header is provided in the buffer at
2123 address \fIhdr\fP, with \fIlen\fP its size in bytes. \fItype\fP indicates
2124 the protocol of the header and can be one of:
2125 .INDENT 7.0
2126 .TP
2127 .B \fBBPF_LWT_ENCAP_SEG6\fP
2128 IPv6 encapsulation with Segment Routing Header
2129 (\fBstruct ipv6_sr_hdr\fP). \fIhdr\fP only contains the SRH,
2130 the IPv6 header is computed by the kernel.
2131 .TP
2132 .B \fBBPF_LWT_ENCAP_SEG6_INLINE\fP
2133 Only works if \fIskb\fP contains an IPv6 packet. Insert a
2134 Segment Routing Header (\fBstruct ipv6_sr_hdr\fP) inside
2135 the IPv6 header.
2136 .TP
2137 .B \fBBPF_LWT_ENCAP_IP\fP
2138 IP encapsulation (GRE/GUE/IPIP/etc). The outer header
2139 must be IPv4 or IPv6, followed by zero or more
2140 additional headers, up to \fBLWT_BPF_MAX_HEADROOM\fP
2141 total bytes in all prepended headers. Please note that
2142 if \fBskb_is_gso\fP(\fIskb\fP) is true, no more than two
2143 headers can be prepended, and the inner header, if
2144 present, should be either GRE or UDP/GUE.
2145 .UNINDENT
2146 .sp
2147 \fBBPF_LWT_ENCAP_SEG6\fP* types can be called by BPF programs
2148 of type \fBBPF_PROG_TYPE_LWT_IN\fP; \fBBPF_LWT_ENCAP_IP\fP type can
2149 be called by bpf programs of types \fBBPF_PROG_TYPE_LWT_IN\fP and
2150 \fBBPF_PROG_TYPE_LWT_XMIT\fP\&.
2151 .sp
2152 A call to this helper is susceptible to change the underlying
2153 packet buffer. Therefore, at load time, all checks on pointers
2154 previously done by the verifier are invalidated and must be
2155 performed again, if the helper is used in combination with
2156 direct packet access.
2157 .TP
2158 .B Return
2159 0 on success, or a negative error in case of failure.
2160 .UNINDENT
2161 .TP
2162 .B \fBlong 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
2163 .INDENT 7.0
2164 .TP
2165 .B Description
2166 Store \fIlen\fP bytes from address \fIfrom\fP into the packet
2167 associated to \fIskb\fP, at \fIoffset\fP\&. Only the flags, tag and TLVs
2168 inside the outermost IPv6 Segment Routing Header can be
2169 modified through this helper.
2170 .sp
2171 A call to this helper is susceptible to change the underlying
2172 packet buffer. Therefore, at load time, all checks on pointers
2173 previously done by the verifier are invalidated and must be
2174 performed again, if the helper is used in combination with
2175 direct packet access.
2176 .TP
2177 .B Return
2178 0 on success, or a negative error in case of failure.
2179 .UNINDENT
2180 .TP
2181 .B \fBlong bpf_lwt_seg6_adjust_srh(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIoffset\fP\fB, s32\fP \fIdelta\fP\fB)\fP
2182 .INDENT 7.0
2183 .TP
2184 .B Description
2185 Adjust the size allocated to TLVs in the outermost IPv6
2186 Segment Routing Header contained in the packet associated to
2187 \fIskb\fP, at position \fIoffset\fP by \fIdelta\fP bytes. Only offsets
2188 after the segments are accepted. \fIdelta\fP can be as well
2189 positive (growing) as negative (shrinking).
2190 .sp
2191 A call to this helper is susceptible to change the underlying
2192 packet buffer. Therefore, at load time, all checks on pointers
2193 previously done by the verifier are invalidated and must be
2194 performed again, if the helper is used in combination with
2195 direct packet access.
2196 .TP
2197 .B Return
2198 0 on success, or a negative error in case of failure.
2199 .UNINDENT
2200 .TP
2201 .B \fBlong 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
2202 .INDENT 7.0
2203 .TP
2204 .B Description
2205 Apply an IPv6 Segment Routing action of type \fIaction\fP to the
2206 packet associated to \fIskb\fP\&. Each action takes a parameter
2207 contained at address \fIparam\fP, and of length \fIparam_len\fP bytes.
2208 \fIaction\fP can be one of:
2209 .INDENT 7.0
2210 .TP
2211 .B \fBSEG6_LOCAL_ACTION_END_X\fP
2212 End.X action: Endpoint with Layer\-3 cross\-connect.
2213 Type of \fIparam\fP: \fBstruct in6_addr\fP\&.
2214 .TP
2215 .B \fBSEG6_LOCAL_ACTION_END_T\fP
2216 End.T action: Endpoint with specific IPv6 table lookup.
2217 Type of \fIparam\fP: \fBint\fP\&.
2218 .TP
2219 .B \fBSEG6_LOCAL_ACTION_END_B6\fP
2220 End.B6 action: Endpoint bound to an SRv6 policy.
2221 Type of \fIparam\fP: \fBstruct ipv6_sr_hdr\fP\&.
2222 .TP
2223 .B \fBSEG6_LOCAL_ACTION_END_B6_ENCAP\fP
2224 End.B6.Encap action: Endpoint bound to an SRv6
2225 encapsulation policy.
2226 Type of \fIparam\fP: \fBstruct ipv6_sr_hdr\fP\&.
2227 .UNINDENT
2228 .sp
2229 A call to this helper is susceptible to change the underlying
2230 packet buffer. Therefore, at load time, all checks on pointers
2231 previously done by the verifier are invalidated and must be
2232 performed again, if the helper is used in combination with
2233 direct packet access.
2234 .TP
2235 .B Return
2236 0 on success, or a negative error in case of failure.
2237 .UNINDENT
2238 .TP
2239 .B \fBlong bpf_rc_repeat(void *\fP\fIctx\fP\fB)\fP
2240 .INDENT 7.0
2241 .TP
2242 .B Description
2243 This helper is used in programs implementing IR decoding, to
2244 report a successfully decoded repeat key message. This delays
2245 the generation of a key up event for previously generated
2246 key down event.
2247 .sp
2248 Some IR protocols like NEC have a special IR message for
2249 repeating last button, for when a button is held down.
2250 .sp
2251 The \fIctx\fP should point to the lirc sample as passed into
2252 the program.
2253 .sp
2254 This helper is only available is the kernel was compiled with
2255 the \fBCONFIG_BPF_LIRC_MODE2\fP configuration option set to
2256 \(dq\fBy\fP\(dq.
2257 .TP
2258 .B Return
2259 0
2260 .UNINDENT
2261 .TP
2262 .B \fBlong bpf_rc_keydown(void *\fP\fIctx\fP\fB, u32\fP \fIprotocol\fP\fB, u64\fP \fIscancode\fP\fB, u32\fP \fItoggle\fP\fB)\fP
2263 .INDENT 7.0
2264 .TP
2265 .B Description
2266 This helper is used in programs implementing IR decoding, to
2267 report a successfully decoded key press with \fIscancode\fP,
2268 \fItoggle\fP value in the given \fIprotocol\fP\&. The scancode will be
2269 translated to a keycode using the rc keymap, and reported as
2270 an input key down event. After a period a key up event is
2271 generated. This period can be extended by calling either
2272 \fBbpf_rc_keydown\fP() again with the same values, or calling
2273 \fBbpf_rc_repeat\fP().
2274 .sp
2275 Some protocols include a toggle bit, in case the button was
2276 released and pressed again between consecutive scancodes.
2277 .sp
2278 The \fIctx\fP should point to the lirc sample as passed into
2279 the program.
2280 .sp
2281 The \fIprotocol\fP is the decoded protocol number (see
2282 \fBenum rc_proto\fP for some predefined values).
2283 .sp
2284 This helper is only available is the kernel was compiled with
2285 the \fBCONFIG_BPF_LIRC_MODE2\fP configuration option set to
2286 \(dq\fBy\fP\(dq.
2287 .TP
2288 .B Return
2289 0
2290 .UNINDENT
2291 .TP
2292 .B \fBu64 bpf_skb_cgroup_id(struct sk_buff *\fP\fIskb\fP\fB)\fP
2293 .INDENT 7.0
2294 .TP
2295 .B Description
2296 Return the cgroup v2 id of the socket associated with the \fIskb\fP\&.
2297 This is roughly similar to the \fBbpf_get_cgroup_classid\fP()
2298 helper for cgroup v1 by providing a tag resp. identifier that
2299 can be matched on or used for map lookups e.g. to implement
2300 policy. The cgroup v2 id of a given path in the hierarchy is
2301 exposed in user space through the f_handle API in order to get
2302 to the same 64\-bit id.
2303 .sp
2304 This helper can be used on TC egress path, but not on ingress,
2305 and is available only if the kernel was compiled with the
2306 \fBCONFIG_SOCK_CGROUP_DATA\fP configuration option.
2307 .TP
2308 .B Return
2309 The id is returned or 0 in case the id could not be retrieved.
2310 .UNINDENT
2311 .TP
2312 .B \fBu64 bpf_get_current_cgroup_id(void)\fP
2313 .INDENT 7.0
2314 .TP
2315 .B Description
2316 Get the current cgroup id based on the cgroup within which
2317 the current task is running.
2318 .TP
2319 .B Return
2320 A 64\-bit integer containing the current cgroup id based
2321 on the cgroup within which the current task is running.
2322 .UNINDENT
2323 .TP
2324 .B \fBvoid *bpf_get_local_storage(void *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB)\fP
2325 .INDENT 7.0
2326 .TP
2327 .B Description
2328 Get the pointer to the local storage area.
2329 The type and the size of the local storage is defined
2330 by the \fImap\fP argument.
2331 The \fIflags\fP meaning is specific for each map type,
2332 and has to be 0 for cgroup local storage.
2333 .sp
2334 Depending on the BPF program type, a local storage area
2335 can be shared between multiple instances of the BPF program,
2336 running simultaneously.
2337 .sp
2338 A user should care about the synchronization by himself.
2339 For example, by using the \fBBPF_ATOMIC\fP instructions to alter
2340 the shared data.
2341 .TP
2342 .B Return
2343 A pointer to the local storage area.
2344 .UNINDENT
2345 .TP
2346 .B \fBlong 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
2347 .INDENT 7.0
2348 .TP
2349 .B Description
2350 Select a \fBSO_REUSEPORT\fP socket from a
2351 \fBBPF_MAP_TYPE_REUSEPORT_SOCKARRAY\fP \fImap\fP\&.
2352 It checks the selected socket is matching the incoming
2353 request in the socket buffer.
2354 .TP
2355 .B Return
2356 0 on success, or a negative error in case of failure.
2357 .UNINDENT
2358 .TP
2359 .B \fBu64 bpf_skb_ancestor_cgroup_id(struct sk_buff *\fP\fIskb\fP\fB, int\fP \fIancestor_level\fP\fB)\fP
2360 .INDENT 7.0
2361 .TP
2362 .B Description
2363 Return id of cgroup v2 that is ancestor of cgroup associated
2364 with the \fIskb\fP at the \fIancestor_level\fP\&. The root cgroup is at
2365 \fIancestor_level\fP zero and each step down the hierarchy
2366 increments the level. If \fIancestor_level\fP == level of cgroup
2367 associated with \fIskb\fP, then return value will be same as that
2368 of \fBbpf_skb_cgroup_id\fP().
2369 .sp
2370 The helper is useful to implement policies based on cgroups
2371 that are upper in hierarchy than immediate cgroup associated
2372 with \fIskb\fP\&.
2373 .sp
2374 The format of returned id and helper limitations are same as in
2375 \fBbpf_skb_cgroup_id\fP().
2376 .TP
2377 .B Return
2378 The id is returned or 0 in case the id could not be retrieved.
2379 .UNINDENT
2380 .TP
2381 .B \fBstruct bpf_sock *bpf_sk_lookup_tcp(void *\fP\fIctx\fP\fB, struct bpf_sock_tuple *\fP\fItuple\fP\fB, u32\fP \fItuple_size\fP\fB, u64\fP \fInetns\fP\fB, u64\fP \fIflags\fP\fB)\fP
2382 .INDENT 7.0
2383 .TP
2384 .B Description
2385 Look for TCP socket matching \fItuple\fP, optionally in a child
2386 network namespace \fInetns\fP\&. The return value must be checked,
2387 and if non\-\fBNULL\fP, released via \fBbpf_sk_release\fP().
2388 .sp
2389 The \fIctx\fP should point to the context of the program, such as
2390 the skb or socket (depending on the hook in use). This is used
2391 to determine the base network namespace for the lookup.
2392 .sp
2393 \fItuple_size\fP must be one of:
2394 .INDENT 7.0
2395 .TP
2396 .B \fBsizeof\fP(\fItuple\fP\fB\->ipv4\fP)
2397 Look for an IPv4 socket.
2398 .TP
2399 .B \fBsizeof\fP(\fItuple\fP\fB\->ipv6\fP)
2400 Look for an IPv6 socket.
2401 .UNINDENT
2402 .sp
2403 If the \fInetns\fP is a negative signed 32\-bit integer, then the
2404 socket lookup table in the netns associated with the \fIctx\fP
2405 will be used. For the TC hooks, this is the netns of the device
2406 in the skb. For socket hooks, this is the netns of the socket.
2407 If \fInetns\fP is any other signed 32\-bit value greater than or
2408 equal to zero then it specifies the ID of the netns relative to
2409 the netns associated with the \fIctx\fP\&. \fInetns\fP values beyond the
2410 range of 32\-bit integers are reserved for future use.
2411 .sp
2412 All values for \fIflags\fP are reserved for future usage, and must
2413 be left at zero.
2414 .sp
2415 This helper is available only if the kernel was compiled with
2416 \fBCONFIG_NET\fP configuration option.
2417 .TP
2418 .B Return
2419 Pointer to \fBstruct bpf_sock\fP, or \fBNULL\fP in case of failure.
2420 For sockets with reuseport option, the \fBstruct bpf_sock\fP
2421 result is from \fIreuse\fP\fB\->socks\fP[] using the hash of the
2422 tuple.
2423 .UNINDENT
2424 .TP
2425 .B \fBstruct bpf_sock *bpf_sk_lookup_udp(void *\fP\fIctx\fP\fB, struct bpf_sock_tuple *\fP\fItuple\fP\fB, u32\fP \fItuple_size\fP\fB, u64\fP \fInetns\fP\fB, u64\fP \fIflags\fP\fB)\fP
2426 .INDENT 7.0
2427 .TP
2428 .B Description
2429 Look for UDP socket matching \fItuple\fP, optionally in a child
2430 network namespace \fInetns\fP\&. The return value must be checked,
2431 and if non\-\fBNULL\fP, released via \fBbpf_sk_release\fP().
2432 .sp
2433 The \fIctx\fP should point to the context of the program, such as
2434 the skb or socket (depending on the hook in use). This is used
2435 to determine the base network namespace for the lookup.
2436 .sp
2437 \fItuple_size\fP must be one of:
2438 .INDENT 7.0
2439 .TP
2440 .B \fBsizeof\fP(\fItuple\fP\fB\->ipv4\fP)
2441 Look for an IPv4 socket.
2442 .TP
2443 .B \fBsizeof\fP(\fItuple\fP\fB\->ipv6\fP)
2444 Look for an IPv6 socket.
2445 .UNINDENT
2446 .sp
2447 If the \fInetns\fP is a negative signed 32\-bit integer, then the
2448 socket lookup table in the netns associated with the \fIctx\fP
2449 will be used. For the TC hooks, this is the netns of the device
2450 in the skb. For socket hooks, this is the netns of the socket.
2451 If \fInetns\fP is any other signed 32\-bit value greater than or
2452 equal to zero then it specifies the ID of the netns relative to
2453 the netns associated with the \fIctx\fP\&. \fInetns\fP values beyond the
2454 range of 32\-bit integers are reserved for future use.
2455 .sp
2456 All values for \fIflags\fP are reserved for future usage, and must
2457 be left at zero.
2458 .sp
2459 This helper is available only if the kernel was compiled with
2460 \fBCONFIG_NET\fP configuration option.
2461 .TP
2462 .B Return
2463 Pointer to \fBstruct bpf_sock\fP, or \fBNULL\fP in case of failure.
2464 For sockets with reuseport option, the \fBstruct bpf_sock\fP
2465 result is from \fIreuse\fP\fB\->socks\fP[] using the hash of the
2466 tuple.
2467 .UNINDENT
2468 .TP
2469 .B \fBlong bpf_sk_release(void *\fP\fIsock\fP\fB)\fP
2470 .INDENT 7.0
2471 .TP
2472 .B Description
2473 Release the reference held by \fIsock\fP\&. \fIsock\fP must be a
2474 non\-\fBNULL\fP pointer that was returned from
2475 \fBbpf_sk_lookup_xxx\fP().
2476 .TP
2477 .B Return
2478 0 on success, or a negative error in case of failure.
2479 .UNINDENT
2480 .TP
2481 .B \fBlong bpf_map_push_elem(struct bpf_map *\fP\fImap\fP\fB, const void *\fP\fIvalue\fP\fB, u64\fP \fIflags\fP\fB)\fP
2482 .INDENT 7.0
2483 .TP
2484 .B Description
2485 Push an element \fIvalue\fP in \fImap\fP\&. \fIflags\fP is one of:
2486 .INDENT 7.0
2487 .TP
2488 .B \fBBPF_EXIST\fP
2489 If the queue/stack is full, the oldest element is
2490 removed to make room for this.
2491 .UNINDENT
2492 .TP
2493 .B Return
2494 0 on success, or a negative error in case of failure.
2495 .UNINDENT
2496 .TP
2497 .B \fBlong bpf_map_pop_elem(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIvalue\fP\fB)\fP
2498 .INDENT 7.0
2499 .TP
2500 .B Description
2501 Pop an element from \fImap\fP\&.
2502 .TP
2503 .B Return
2504 0 on success, or a negative error in case of failure.
2505 .UNINDENT
2506 .TP
2507 .B \fBlong bpf_map_peek_elem(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIvalue\fP\fB)\fP
2508 .INDENT 7.0
2509 .TP
2510 .B Description
2511 Get an element from \fImap\fP without removing it.
2512 .TP
2513 .B Return
2514 0 on success, or a negative error in case of failure.
2515 .UNINDENT
2516 .TP
2517 .B \fBlong bpf_msg_push_data(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIstart\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
2518 .INDENT 7.0
2519 .TP
2520 .B Description
2521 For socket policies, insert \fIlen\fP bytes into \fImsg\fP at offset
2522 \fIstart\fP\&.
2523 .sp
2524 If a program of type \fBBPF_PROG_TYPE_SK_MSG\fP is run on a
2525 \fImsg\fP it may want to insert metadata or options into the \fImsg\fP\&.
2526 This can later be read and used by any of the lower layer BPF
2527 hooks.
2528 .sp
2529 This helper may fail if under memory pressure (a malloc
2530 fails) in these cases BPF programs will get an appropriate
2531 error and BPF programs will need to handle them.
2532 .TP
2533 .B Return
2534 0 on success, or a negative error in case of failure.
2535 .UNINDENT
2536 .TP
2537 .B \fBlong bpf_msg_pop_data(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIstart\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
2538 .INDENT 7.0
2539 .TP
2540 .B Description
2541 Will remove \fIlen\fP bytes from a \fImsg\fP starting at byte \fIstart\fP\&.
2542 This may result in \fBENOMEM\fP errors under certain situations if
2543 an allocation and copy are required due to a full ring buffer.
2544 However, the helper will try to avoid doing the allocation
2545 if possible. Other errors can occur if input parameters are
2546 invalid either due to \fIstart\fP byte not being valid part of \fImsg\fP
2547 payload and/or \fIpop\fP value being to large.
2548 .TP
2549 .B Return
2550 0 on success, or a negative error in case of failure.
2551 .UNINDENT
2552 .TP
2553 .B \fBlong bpf_rc_pointer_rel(void *\fP\fIctx\fP\fB, s32\fP \fIrel_x\fP\fB, s32\fP \fIrel_y\fP\fB)\fP
2554 .INDENT 7.0
2555 .TP
2556 .B Description
2557 This helper is used in programs implementing IR decoding, to
2558 report a successfully decoded pointer movement.
2559 .sp
2560 The \fIctx\fP should point to the lirc sample as passed into
2561 the program.
2562 .sp
2563 This helper is only available is the kernel was compiled with
2564 the \fBCONFIG_BPF_LIRC_MODE2\fP configuration option set to
2565 \(dq\fBy\fP\(dq.
2566 .TP
2567 .B Return
2568 0
2569 .UNINDENT
2570 .TP
2571 .B \fBlong bpf_spin_lock(struct bpf_spin_lock *\fP\fIlock\fP\fB)\fP
2572 .INDENT 7.0
2573 .TP
2574 .B Description
2575 Acquire a spinlock represented by the pointer \fIlock\fP, which is
2576 stored as part of a value of a map. Taking the lock allows to
2577 safely update the rest of the fields in that value. The
2578 spinlock can (and must) later be released with a call to
2579 \fBbpf_spin_unlock\fP(\fIlock\fP).
2580 .sp
2581 Spinlocks in BPF programs come with a number of restrictions
2582 and constraints:
2583 .INDENT 7.0
2584 .IP \(bu 2
2585 \fBbpf_spin_lock\fP objects are only allowed inside maps of
2586 types \fBBPF_MAP_TYPE_HASH\fP and \fBBPF_MAP_TYPE_ARRAY\fP (this
2587 list could be extended in the future).
2588 .IP \(bu 2
2589 BTF description of the map is mandatory.
2590 .IP \(bu 2
2591 The BPF program can take ONE lock at a time, since taking two
2592 or more could cause dead locks.
2593 .IP \(bu 2
2594 Only one \fBstruct bpf_spin_lock\fP is allowed per map element.
2595 .IP \(bu 2
2596 When the lock is taken, calls (either BPF to BPF or helpers)
2597 are not allowed.
2598 .IP \(bu 2
2599 The \fBBPF_LD_ABS\fP and \fBBPF_LD_IND\fP instructions are not
2600 allowed inside a spinlock\-ed region.
2601 .IP \(bu 2
2602 The BPF program MUST call \fBbpf_spin_unlock\fP() to release
2603 the lock, on all execution paths, before it returns.
2604 .IP \(bu 2
2605 The BPF program can access \fBstruct bpf_spin_lock\fP only via
2606 the \fBbpf_spin_lock\fP() and \fBbpf_spin_unlock\fP()
2607 helpers. Loading or storing data into the \fBstruct
2608 bpf_spin_lock\fP \fIlock\fP\fB;\fP field of a map is not allowed.
2609 .IP \(bu 2
2610 To use the \fBbpf_spin_lock\fP() helper, the BTF description
2611 of the map value must be a struct and have \fBstruct
2612 bpf_spin_lock\fP \fIanyname\fP\fB;\fP field at the top level.
2613 Nested lock inside another struct is not allowed.
2614 .IP \(bu 2
2615 The \fBstruct bpf_spin_lock\fP \fIlock\fP field in a map value must
2616 be aligned on a multiple of 4 bytes in that value.
2617 .IP \(bu 2
2618 Syscall with command \fBBPF_MAP_LOOKUP_ELEM\fP does not copy
2619 the \fBbpf_spin_lock\fP field to user space.
2620 .IP \(bu 2
2621 Syscall with command \fBBPF_MAP_UPDATE_ELEM\fP, or update from
2622 a BPF program, do not update the \fBbpf_spin_lock\fP field.
2623 .IP \(bu 2
2624 \fBbpf_spin_lock\fP cannot be on the stack or inside a
2625 networking packet (it can only be inside of a map values).
2626 .IP \(bu 2
2627 \fBbpf_spin_lock\fP is available to root only.
2628 .IP \(bu 2
2629 Tracing programs and socket filter programs cannot use
2630 \fBbpf_spin_lock\fP() due to insufficient preemption checks
2631 (but this may change in the future).
2632 .IP \(bu 2
2633 \fBbpf_spin_lock\fP is not allowed in inner maps of map\-in\-map.
2634 .UNINDENT
2635 .TP
2636 .B Return
2637 0
2638 .UNINDENT
2639 .TP
2640 .B \fBlong bpf_spin_unlock(struct bpf_spin_lock *\fP\fIlock\fP\fB)\fP
2641 .INDENT 7.0
2642 .TP
2643 .B Description
2644 Release the \fIlock\fP previously locked by a call to
2645 \fBbpf_spin_lock\fP(\fIlock\fP).
2646 .TP
2647 .B Return
2648 0
2649 .UNINDENT
2650 .TP
2651 .B \fBstruct bpf_sock *bpf_sk_fullsock(struct bpf_sock *\fP\fIsk\fP\fB)\fP
2652 .INDENT 7.0
2653 .TP
2654 .B Description
2655 This helper gets a \fBstruct bpf_sock\fP pointer such
2656 that all the fields in this \fBbpf_sock\fP can be accessed.
2657 .TP
2658 .B Return
2659 A \fBstruct bpf_sock\fP pointer on success, or \fBNULL\fP in
2660 case of failure.
2661 .UNINDENT
2662 .TP
2663 .B \fBstruct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *\fP\fIsk\fP\fB)\fP
2664 .INDENT 7.0
2665 .TP
2666 .B Description
2667 This helper gets a \fBstruct bpf_tcp_sock\fP pointer from a
2668 \fBstruct bpf_sock\fP pointer.
2669 .TP
2670 .B Return
2671 A \fBstruct bpf_tcp_sock\fP pointer on success, or \fBNULL\fP in
2672 case of failure.
2673 .UNINDENT
2674 .TP
2675 .B \fBlong bpf_skb_ecn_set_ce(struct sk_buff *\fP\fIskb\fP\fB)\fP
2676 .INDENT 7.0
2677 .TP
2678 .B Description
2679 Set ECN (Explicit Congestion Notification) field of IP header
2680 to \fBCE\fP (Congestion Encountered) if current value is \fBECT\fP
2681 (ECN Capable Transport). Otherwise, do nothing. Works with IPv6
2682 and IPv4.
2683 .TP
2684 .B Return
2685 1 if the \fBCE\fP flag is set (either by the current helper call
2686 or because it was already present), 0 if it is not set.
2687 .UNINDENT
2688 .TP
2689 .B \fBstruct bpf_sock *bpf_get_listener_sock(struct bpf_sock *\fP\fIsk\fP\fB)\fP
2690 .INDENT 7.0
2691 .TP
2692 .B Description
2693 Return a \fBstruct bpf_sock\fP pointer in \fBTCP_LISTEN\fP state.
2694 \fBbpf_sk_release\fP() is unnecessary and not allowed.
2695 .TP
2696 .B Return
2697 A \fBstruct bpf_sock\fP pointer on success, or \fBNULL\fP in
2698 case of failure.
2699 .UNINDENT
2700 .TP
2701 .B \fBstruct bpf_sock *bpf_skc_lookup_tcp(void *\fP\fIctx\fP\fB, struct bpf_sock_tuple *\fP\fItuple\fP\fB, u32\fP \fItuple_size\fP\fB, u64\fP \fInetns\fP\fB, u64\fP \fIflags\fP\fB)\fP
2702 .INDENT 7.0
2703 .TP
2704 .B Description
2705 Look for TCP socket matching \fItuple\fP, optionally in a child
2706 network namespace \fInetns\fP\&. The return value must be checked,
2707 and if non\-\fBNULL\fP, released via \fBbpf_sk_release\fP().
2708 .sp
2709 This function is identical to \fBbpf_sk_lookup_tcp\fP(), except
2710 that it also returns timewait or request sockets. Use
2711 \fBbpf_sk_fullsock\fP() or \fBbpf_tcp_sock\fP() to access the
2712 full structure.
2713 .sp
2714 This helper is available only if the kernel was compiled with
2715 \fBCONFIG_NET\fP configuration option.
2716 .TP
2717 .B Return
2718 Pointer to \fBstruct bpf_sock\fP, or \fBNULL\fP in case of failure.
2719 For sockets with reuseport option, the \fBstruct bpf_sock\fP
2720 result is from \fIreuse\fP\fB\->socks\fP[] using the hash of the
2721 tuple.
2722 .UNINDENT
2723 .TP
2724 .B \fBlong bpf_tcp_check_syncookie(void *\fP\fIsk\fP\fB, void *\fP\fIiph\fP\fB, u32\fP \fIiph_len\fP\fB, struct tcphdr *\fP\fIth\fP\fB, u32\fP \fIth_len\fP\fB)\fP
2725 .INDENT 7.0
2726 .TP
2727 .B Description
2728 Check whether \fIiph\fP and \fIth\fP contain a valid SYN cookie ACK for
2729 the listening socket in \fIsk\fP\&.
2730 .sp
2731 \fIiph\fP points to the start of the IPv4 or IPv6 header, while
2732 \fIiph_len\fP contains \fBsizeof\fP(\fBstruct iphdr\fP) or
2733 \fBsizeof\fP(\fBstruct ipv6hdr\fP).
2734 .sp
2735 \fIth\fP points to the start of the TCP header, while \fIth_len\fP
2736 contains the length of the TCP header (at least
2737 \fBsizeof\fP(\fBstruct tcphdr\fP)).
2738 .TP
2739 .B Return
2740 0 if \fIiph\fP and \fIth\fP are a valid SYN cookie ACK, or a negative
2741 error otherwise.
2742 .UNINDENT
2743 .TP
2744 .B \fBlong bpf_sysctl_get_name(struct bpf_sysctl *\fP\fIctx\fP\fB, char *\fP\fIbuf\fP\fB, size_t\fP \fIbuf_len\fP\fB, u64\fP \fIflags\fP\fB)\fP
2745 .INDENT 7.0
2746 .TP
2747 .B Description
2748 Get name of sysctl in /proc/sys/ and copy it into provided by
2749 program buffer \fIbuf\fP of size \fIbuf_len\fP\&.
2750 .sp
2751 The buffer is always NUL terminated, unless it\(aqs zero\-sized.
2752 .sp
2753 If \fIflags\fP is zero, full name (e.g. \(dqnet/ipv4/tcp_mem\(dq) is
2754 copied. Use \fBBPF_F_SYSCTL_BASE_NAME\fP flag to copy base name
2755 only (e.g. \(dqtcp_mem\(dq).
2756 .TP
2757 .B Return
2758 Number of character copied (not including the trailing NUL).
2759 .sp
2760 \fB\-E2BIG\fP if the buffer wasn\(aqt big enough (\fIbuf\fP will contain
2761 truncated name in this case).
2762 .UNINDENT
2763 .TP
2764 .B \fBlong bpf_sysctl_get_current_value(struct bpf_sysctl *\fP\fIctx\fP\fB, char *\fP\fIbuf\fP\fB, size_t\fP \fIbuf_len\fP\fB)\fP
2765 .INDENT 7.0
2766 .TP
2767 .B Description
2768 Get current value of sysctl as it is presented in /proc/sys
2769 (incl. newline, etc), and copy it as a string into provided
2770 by program buffer \fIbuf\fP of size \fIbuf_len\fP\&.
2771 .sp
2772 The whole value is copied, no matter what file position user
2773 space issued e.g. sys_read at.
2774 .sp
2775 The buffer is always NUL terminated, unless it\(aqs zero\-sized.
2776 .TP
2777 .B Return
2778 Number of character copied (not including the trailing NUL).
2779 .sp
2780 \fB\-E2BIG\fP if the buffer wasn\(aqt big enough (\fIbuf\fP will contain
2781 truncated name in this case).
2782 .sp
2783 \fB\-EINVAL\fP if current value was unavailable, e.g. because
2784 sysctl is uninitialized and read returns \-EIO for it.
2785 .UNINDENT
2786 .TP
2787 .B \fBlong bpf_sysctl_get_new_value(struct bpf_sysctl *\fP\fIctx\fP\fB, char *\fP\fIbuf\fP\fB, size_t\fP \fIbuf_len\fP\fB)\fP
2788 .INDENT 7.0
2789 .TP
2790 .B Description
2791 Get new value being written by user space to sysctl (before
2792 the actual write happens) and copy it as a string into
2793 provided by program buffer \fIbuf\fP of size \fIbuf_len\fP\&.
2794 .sp
2795 User space may write new value at file position > 0.
2796 .sp
2797 The buffer is always NUL terminated, unless it\(aqs zero\-sized.
2798 .TP
2799 .B Return
2800 Number of character copied (not including the trailing NUL).
2801 .sp
2802 \fB\-E2BIG\fP if the buffer wasn\(aqt big enough (\fIbuf\fP will contain
2803 truncated name in this case).
2804 .sp
2805 \fB\-EINVAL\fP if sysctl is being read.
2806 .UNINDENT
2807 .TP
2808 .B \fBlong bpf_sysctl_set_new_value(struct bpf_sysctl *\fP\fIctx\fP\fB, const char *\fP\fIbuf\fP\fB, size_t\fP \fIbuf_len\fP\fB)\fP
2809 .INDENT 7.0
2810 .TP
2811 .B Description
2812 Override new value being written by user space to sysctl with
2813 value provided by program in buffer \fIbuf\fP of size \fIbuf_len\fP\&.
2814 .sp
2815 \fIbuf\fP should contain a string in same form as provided by user
2816 space on sysctl write.
2817 .sp
2818 User space may write new value at file position > 0. To override
2819 the whole sysctl value file position should be set to zero.
2820 .TP
2821 .B Return
2822 0 on success.
2823 .sp
2824 \fB\-E2BIG\fP if the \fIbuf_len\fP is too big.
2825 .sp
2826 \fB\-EINVAL\fP if sysctl is being read.
2827 .UNINDENT
2828 .TP
2829 .B \fBlong bpf_strtol(const char *\fP\fIbuf\fP\fB, size_t\fP \fIbuf_len\fP\fB, u64\fP \fIflags\fP\fB, long *\fP\fIres\fP\fB)\fP
2830 .INDENT 7.0
2831 .TP
2832 .B Description
2833 Convert the initial part of the string from buffer \fIbuf\fP of
2834 size \fIbuf_len\fP to a long integer according to the given base
2835 and save the result in \fIres\fP\&.
2836 .sp
2837 The string may begin with an arbitrary amount of white space
2838 (as determined by \fBisspace\fP(3)) followed by a single
2839 optional \(aq\fB\-\fP\(aq sign.
2840 .sp
2841 Five least significant bits of \fIflags\fP encode base, other bits
2842 are currently unused.
2843 .sp
2844 Base must be either 8, 10, 16 or 0 to detect it automatically
2845 similar to user space \fBstrtol\fP(3).
2846 .TP
2847 .B Return
2848 Number of characters consumed on success. Must be positive but
2849 no more than \fIbuf_len\fP\&.
2850 .sp
2851 \fB\-EINVAL\fP if no valid digits were found or unsupported base
2852 was provided.
2853 .sp
2854 \fB\-ERANGE\fP if resulting value was out of range.
2855 .UNINDENT
2856 .TP
2857 .B \fBlong bpf_strtoul(const char *\fP\fIbuf\fP\fB, size_t\fP \fIbuf_len\fP\fB, u64\fP \fIflags\fP\fB, unsigned long *\fP\fIres\fP\fB)\fP
2858 .INDENT 7.0
2859 .TP
2860 .B Description
2861 Convert the initial part of the string from buffer \fIbuf\fP of
2862 size \fIbuf_len\fP to an unsigned long integer according to the
2863 given base and save the result in \fIres\fP\&.
2864 .sp
2865 The string may begin with an arbitrary amount of white space
2866 (as determined by \fBisspace\fP(3)).
2867 .sp
2868 Five least significant bits of \fIflags\fP encode base, other bits
2869 are currently unused.
2870 .sp
2871 Base must be either 8, 10, 16 or 0 to detect it automatically
2872 similar to user space \fBstrtoul\fP(3).
2873 .TP
2874 .B Return
2875 Number of characters consumed on success. Must be positive but
2876 no more than \fIbuf_len\fP\&.
2877 .sp
2878 \fB\-EINVAL\fP if no valid digits were found or unsupported base
2879 was provided.
2880 .sp
2881 \fB\-ERANGE\fP if resulting value was out of range.
2882 .UNINDENT
2883 .TP
2884 .B \fBvoid *bpf_sk_storage_get(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIsk\fP\fB, void *\fP\fIvalue\fP\fB, u64\fP \fIflags\fP\fB)\fP
2885 .INDENT 7.0
2886 .TP
2887 .B Description
2888 Get a bpf\-local\-storage from a \fIsk\fP\&.
2889 .sp
2890 Logically, it could be thought of getting the value from
2891 a \fImap\fP with \fIsk\fP as the \fBkey\fP\&. From this
2892 perspective, the usage is not much different from
2893 \fBbpf_map_lookup_elem\fP(\fImap\fP, \fB&\fP\fIsk\fP) except this
2894 helper enforces the key must be a full socket and the map must
2895 be a \fBBPF_MAP_TYPE_SK_STORAGE\fP also.
2896 .sp
2897 Underneath, the value is stored locally at \fIsk\fP instead of
2898 the \fImap\fP\&. The \fImap\fP is used as the bpf\-local\-storage
2899 \(dqtype\(dq. The bpf\-local\-storage \(dqtype\(dq (i.e. the \fImap\fP) is
2900 searched against all bpf\-local\-storages residing at \fIsk\fP\&.
2901 .sp
2902 \fIsk\fP is a kernel \fBstruct sock\fP pointer for LSM program.
2903 \fIsk\fP is a \fBstruct bpf_sock\fP pointer for other program types.
2904 .sp
2905 An optional \fIflags\fP (\fBBPF_SK_STORAGE_GET_F_CREATE\fP) can be
2906 used such that a new bpf\-local\-storage will be
2907 created if one does not exist. \fIvalue\fP can be used
2908 together with \fBBPF_SK_STORAGE_GET_F_CREATE\fP to specify
2909 the initial value of a bpf\-local\-storage. If \fIvalue\fP is
2910 \fBNULL\fP, the new bpf\-local\-storage will be zero initialized.
2911 .TP
2912 .B Return
2913 A bpf\-local\-storage pointer is returned on success.
2914 .sp
2915 \fBNULL\fP if not found or there was an error in adding
2916 a new bpf\-local\-storage.
2917 .UNINDENT
2918 .TP
2919 .B \fBlong bpf_sk_storage_delete(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIsk\fP\fB)\fP
2920 .INDENT 7.0
2921 .TP
2922 .B Description
2923 Delete a bpf\-local\-storage from a \fIsk\fP\&.
2924 .TP
2925 .B Return
2926 0 on success.
2927 .sp
2928 \fB\-ENOENT\fP if the bpf\-local\-storage cannot be found.
2929 \fB\-EINVAL\fP if sk is not a fullsock (e.g. a request_sock).
2930 .UNINDENT
2931 .TP
2932 .B \fBlong bpf_send_signal(u32\fP \fIsig\fP\fB)\fP
2933 .INDENT 7.0
2934 .TP
2935 .B Description
2936 Send signal \fIsig\fP to the process of the current task.
2937 The signal may be delivered to any of this process\(aqs threads.
2938 .TP
2939 .B Return
2940 0 on success or successfully queued.
2941 .sp
2942 \fB\-EBUSY\fP if work queue under nmi is full.
2943 .sp
2944 \fB\-EINVAL\fP if \fIsig\fP is invalid.
2945 .sp
2946 \fB\-EPERM\fP if no permission to send the \fIsig\fP\&.
2947 .sp
2948 \fB\-EAGAIN\fP if bpf program can try again.
2949 .UNINDENT
2950 .TP
2951 .B \fBs64 bpf_tcp_gen_syncookie(void *\fP\fIsk\fP\fB, void *\fP\fIiph\fP\fB, u32\fP \fIiph_len\fP\fB, struct tcphdr *\fP\fIth\fP\fB, u32\fP \fIth_len\fP\fB)\fP
2952 .INDENT 7.0
2953 .TP
2954 .B Description
2955 Try to issue a SYN cookie for the packet with corresponding
2956 IP/TCP headers, \fIiph\fP and \fIth\fP, on the listening socket in \fIsk\fP\&.
2957 .sp
2958 \fIiph\fP points to the start of the IPv4 or IPv6 header, while
2959 \fIiph_len\fP contains \fBsizeof\fP(\fBstruct iphdr\fP) or
2960 \fBsizeof\fP(\fBstruct ipv6hdr\fP).
2961 .sp
2962 \fIth\fP points to the start of the TCP header, while \fIth_len\fP
2963 contains the length of the TCP header with options (at least
2964 \fBsizeof\fP(\fBstruct tcphdr\fP)).
2965 .TP
2966 .B Return
2967 On success, lower 32 bits hold the generated SYN cookie in
2968 followed by 16 bits which hold the MSS value for that cookie,
2969 and the top 16 bits are unused.
2970 .sp
2971 On failure, the returned value is one of the following:
2972 .sp
2973 \fB\-EINVAL\fP SYN cookie cannot be issued due to error
2974 .sp
2975 \fB\-ENOENT\fP SYN cookie should not be issued (no SYN flood)
2976 .sp
2977 \fB\-EOPNOTSUPP\fP kernel configuration does not enable SYN cookies
2978 .sp
2979 \fB\-EPROTONOSUPPORT\fP IP packet version is not 4 or 6
2980 .UNINDENT
2981 .TP
2982 .B \fBlong bpf_skb_output(void *\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
2983 .INDENT 7.0
2984 .TP
2985 .B Description
2986 Write raw \fIdata\fP blob into a special BPF perf event held by
2987 \fImap\fP of type \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. This perf
2988 event must have the following attributes: \fBPERF_SAMPLE_RAW\fP
2989 as \fBsample_type\fP, \fBPERF_TYPE_SOFTWARE\fP as \fBtype\fP, and
2990 \fBPERF_COUNT_SW_BPF_OUTPUT\fP as \fBconfig\fP\&.
2991 .sp
2992 The \fIflags\fP are used to indicate the index in \fImap\fP for which
2993 the value must be put, masked with \fBBPF_F_INDEX_MASK\fP\&.
2994 Alternatively, \fIflags\fP can be set to \fBBPF_F_CURRENT_CPU\fP
2995 to indicate that the index of the current CPU core should be
2996 used.
2997 .sp
2998 The value to write, of \fIsize\fP, is passed through eBPF stack and
2999 pointed by \fIdata\fP\&.
3000 .sp
3001 \fIctx\fP is a pointer to in\-kernel struct sk_buff.
3002 .sp
3003 This helper is similar to \fBbpf_perf_event_output\fP() but
3004 restricted to raw_tracepoint bpf programs.
3005 .TP
3006 .B Return
3007 0 on success, or a negative error in case of failure.
3008 .UNINDENT
3009 .TP
3010 .B \fBlong bpf_probe_read_user(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
3011 .INDENT 7.0
3012 .TP
3013 .B Description
3014 Safely attempt to read \fIsize\fP bytes from user space address
3015 \fIunsafe_ptr\fP and store the data in \fIdst\fP\&.
3016 .TP
3017 .B Return
3018 0 on success, or a negative error in case of failure.
3019 .UNINDENT
3020 .TP
3021 .B \fBlong bpf_probe_read_kernel(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
3022 .INDENT 7.0
3023 .TP
3024 .B Description
3025 Safely attempt to read \fIsize\fP bytes from kernel space address
3026 \fIunsafe_ptr\fP and store the data in \fIdst\fP\&.
3027 .TP
3028 .B Return
3029 0 on success, or a negative error in case of failure.
3030 .UNINDENT
3031 .TP
3032 .B \fBlong bpf_probe_read_user_str(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
3033 .INDENT 7.0
3034 .TP
3035 .B Description
3036 Copy a NUL terminated string from an unsafe user address
3037 \fIunsafe_ptr\fP to \fIdst\fP\&. The \fIsize\fP should include the
3038 terminating NUL byte. In case the string length is smaller than
3039 \fIsize\fP, the target is not padded with further NUL bytes. If the
3040 string length is larger than \fIsize\fP, just \fIsize\fP\-1 bytes are
3041 copied and the last byte is set to NUL.
3042 .sp
3043 On success, returns the number of bytes that were written,
3044 including the terminal NUL. This makes this helper useful in
3045 tracing programs for reading strings, and more importantly to
3046 get its length at runtime. See the following snippet:
3047 .INDENT 7.0
3048 .INDENT 3.5
3049 .sp
3050 .EX
3051 SEC(\(dqkprobe/sys_open\(dq)
3052 void bpf_sys_open(struct pt_regs *ctx)
3053 {
3054 char buf[PATHLEN]; // PATHLEN is defined to 256
3055 int res = bpf_probe_read_user_str(buf, sizeof(buf),
3056 ctx\->di);
3057
3058 // Consume buf, for example push it to
3059 // userspace via bpf_perf_event_output(); we
3060 // can use res (the string length) as event
3061 // size, after checking its boundaries.
3062 }
3063 .EE
3064 .UNINDENT
3065 .UNINDENT
3066 .sp
3067 In comparison, using \fBbpf_probe_read_user\fP() helper here
3068 instead to read the string would require to estimate the length
3069 at compile time, and would often result in copying more memory
3070 than necessary.
3071 .sp
3072 Another useful use case is when parsing individual process
3073 arguments or individual environment variables navigating
3074 \fIcurrent\fP\fB\->mm\->arg_start\fP and \fIcurrent\fP\fB\->mm\->env_start\fP: using this helper and the return value,
3075 one can quickly iterate at the right offset of the memory area.
3076 .TP
3077 .B Return
3078 On success, the strictly positive length of the output string,
3079 including the trailing NUL character. On error, a negative
3080 value.
3081 .UNINDENT
3082 .TP
3083 .B \fBlong bpf_probe_read_kernel_str(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
3084 .INDENT 7.0
3085 .TP
3086 .B Description
3087 Copy a NUL terminated string from an unsafe kernel address \fIunsafe_ptr\fP
3088 to \fIdst\fP\&. Same semantics as with \fBbpf_probe_read_user_str\fP() apply.
3089 .TP
3090 .B Return
3091 On success, the strictly positive length of the string, including
3092 the trailing NUL character. On error, a negative value.
3093 .UNINDENT
3094 .TP
3095 .B \fBlong bpf_tcp_send_ack(void *\fP\fItp\fP\fB, u32\fP \fIrcv_nxt\fP\fB)\fP
3096 .INDENT 7.0
3097 .TP
3098 .B Description
3099 Send out a tcp\-ack. \fItp\fP is the in\-kernel struct \fBtcp_sock\fP\&.
3100 \fIrcv_nxt\fP is the ack_seq to be sent out.
3101 .TP
3102 .B Return
3103 0 on success, or a negative error in case of failure.
3104 .UNINDENT
3105 .TP
3106 .B \fBlong bpf_send_signal_thread(u32\fP \fIsig\fP\fB)\fP
3107 .INDENT 7.0
3108 .TP
3109 .B Description
3110 Send signal \fIsig\fP to the thread corresponding to the current task.
3111 .TP
3112 .B Return
3113 0 on success or successfully queued.
3114 .sp
3115 \fB\-EBUSY\fP if work queue under nmi is full.
3116 .sp
3117 \fB\-EINVAL\fP if \fIsig\fP is invalid.
3118 .sp
3119 \fB\-EPERM\fP if no permission to send the \fIsig\fP\&.
3120 .sp
3121 \fB\-EAGAIN\fP if bpf program can try again.
3122 .UNINDENT
3123 .TP
3124 .B \fBu64 bpf_jiffies64(void)\fP
3125 .INDENT 7.0
3126 .TP
3127 .B Description
3128 Obtain the 64bit jiffies
3129 .TP
3130 .B Return
3131 The 64 bit jiffies
3132 .UNINDENT
3133 .TP
3134 .B \fBlong bpf_read_branch_records(struct bpf_perf_event_data *\fP\fIctx\fP\fB, void *\fP\fIbuf\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
3135 .INDENT 7.0
3136 .TP
3137 .B Description
3138 For an eBPF program attached to a perf event, retrieve the
3139 branch records (\fBstruct perf_branch_entry\fP) associated to \fIctx\fP
3140 and store it in the buffer pointed by \fIbuf\fP up to size
3141 \fIsize\fP bytes.
3142 .TP
3143 .B Return
3144 On success, number of bytes written to \fIbuf\fP\&. On error, a
3145 negative value.
3146 .sp
3147 The \fIflags\fP can be set to \fBBPF_F_GET_BRANCH_RECORDS_SIZE\fP to
3148 instead return the number of bytes required to store all the
3149 branch entries. If this flag is set, \fIbuf\fP may be NULL.
3150 .sp
3151 \fB\-EINVAL\fP if arguments invalid or \fBsize\fP not a multiple
3152 of \fBsizeof\fP(\fBstruct perf_branch_entry\fP).
3153 .sp
3154 \fB\-ENOENT\fP if architecture does not support branch records.
3155 .UNINDENT
3156 .TP
3157 .B \fBlong bpf_get_ns_current_pid_tgid(u64\fP \fIdev\fP\fB, u64\fP \fIino\fP\fB, struct bpf_pidns_info *\fP\fInsdata\fP\fB, u32\fP \fIsize\fP\fB)\fP
3158 .INDENT 7.0
3159 .TP
3160 .B Description
3161 Returns 0 on success, values for \fIpid\fP and \fItgid\fP as seen from the current
3162 \fInamespace\fP will be returned in \fInsdata\fP\&.
3163 .TP
3164 .B Return
3165 0 on success, or one of the following in case of failure:
3166 .sp
3167 \fB\-EINVAL\fP if dev and inum supplied don\(aqt match dev_t and inode number
3168 with nsfs of current task, or if dev conversion to dev_t lost high bits.
3169 .sp
3170 \fB\-ENOENT\fP if pidns does not exists for the current task.
3171 .UNINDENT
3172 .TP
3173 .B \fBlong bpf_xdp_output(void *\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
3174 .INDENT 7.0
3175 .TP
3176 .B Description
3177 Write raw \fIdata\fP blob into a special BPF perf event held by
3178 \fImap\fP of type \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. This perf
3179 event must have the following attributes: \fBPERF_SAMPLE_RAW\fP
3180 as \fBsample_type\fP, \fBPERF_TYPE_SOFTWARE\fP as \fBtype\fP, and
3181 \fBPERF_COUNT_SW_BPF_OUTPUT\fP as \fBconfig\fP\&.
3182 .sp
3183 The \fIflags\fP are used to indicate the index in \fImap\fP for which
3184 the value must be put, masked with \fBBPF_F_INDEX_MASK\fP\&.
3185 Alternatively, \fIflags\fP can be set to \fBBPF_F_CURRENT_CPU\fP
3186 to indicate that the index of the current CPU core should be
3187 used.
3188 .sp
3189 The value to write, of \fIsize\fP, is passed through eBPF stack and
3190 pointed by \fIdata\fP\&.
3191 .sp
3192 \fIctx\fP is a pointer to in\-kernel struct xdp_buff.
3193 .sp
3194 This helper is similar to \fBbpf_perf_eventoutput\fP() but
3195 restricted to raw_tracepoint bpf programs.
3196 .TP
3197 .B Return
3198 0 on success, or a negative error in case of failure.
3199 .UNINDENT
3200 .TP
3201 .B \fBu64 bpf_get_netns_cookie(void *\fP\fIctx\fP\fB)\fP
3202 .INDENT 7.0
3203 .TP
3204 .B Description
3205 Retrieve the cookie (generated by the kernel) of the network
3206 namespace the input \fIctx\fP is associated with. The network
3207 namespace cookie remains stable for its lifetime and provides
3208 a global identifier that can be assumed unique. If \fIctx\fP is
3209 NULL, then the helper returns the cookie for the initial
3210 network namespace. The cookie itself is very similar to that
3211 of \fBbpf_get_socket_cookie\fP() helper, but for network
3212 namespaces instead of sockets.
3213 .TP
3214 .B Return
3215 A 8\-byte long opaque number.
3216 .UNINDENT
3217 .TP
3218 .B \fBu64 bpf_get_current_ancestor_cgroup_id(int\fP \fIancestor_level\fP\fB)\fP
3219 .INDENT 7.0
3220 .TP
3221 .B Description
3222 Return id of cgroup v2 that is ancestor of the cgroup associated
3223 with the current task at the \fIancestor_level\fP\&. The root cgroup
3224 is at \fIancestor_level\fP zero and each step down the hierarchy
3225 increments the level. If \fIancestor_level\fP == level of cgroup
3226 associated with the current task, then return value will be the
3227 same as that of \fBbpf_get_current_cgroup_id\fP().
3228 .sp
3229 The helper is useful to implement policies based on cgroups
3230 that are upper in hierarchy than immediate cgroup associated
3231 with the current task.
3232 .sp
3233 The format of returned id and helper limitations are same as in
3234 \fBbpf_get_current_cgroup_id\fP().
3235 .TP
3236 .B Return
3237 The id is returned or 0 in case the id could not be retrieved.
3238 .UNINDENT
3239 .TP
3240 .B \fBlong bpf_sk_assign(struct sk_buff *\fP\fIskb\fP\fB, void *\fP\fIsk\fP\fB, u64\fP \fIflags\fP\fB)\fP
3241 .INDENT 7.0
3242 .TP
3243 .B Description
3244 Helper is overloaded depending on BPF program type. This
3245 description applies to \fBBPF_PROG_TYPE_SCHED_CLS\fP and
3246 \fBBPF_PROG_TYPE_SCHED_ACT\fP programs.
3247 .sp
3248 Assign the \fIsk\fP to the \fIskb\fP\&. When combined with appropriate
3249 routing configuration to receive the packet towards the socket,
3250 will cause \fIskb\fP to be delivered to the specified socket.
3251 Subsequent redirection of \fIskb\fP via \fBbpf_redirect\fP(),
3252 \fBbpf_clone_redirect\fP() or other methods outside of BPF may
3253 interfere with successful delivery to the socket.
3254 .sp
3255 This operation is only valid from TC ingress path.
3256 .sp
3257 The \fIflags\fP argument must be zero.
3258 .TP
3259 .B Return
3260 0 on success, or a negative error in case of failure:
3261 .sp
3262 \fB\-EINVAL\fP if specified \fIflags\fP are not supported.
3263 .sp
3264 \fB\-ENOENT\fP if the socket is unavailable for assignment.
3265 .sp
3266 \fB\-ENETUNREACH\fP if the socket is unreachable (wrong netns).
3267 .sp
3268 \fB\-EOPNOTSUPP\fP if the operation is not supported, for example
3269 a call from outside of TC ingress.
3270 .UNINDENT
3271 .TP
3272 .B \fBlong bpf_sk_assign(struct bpf_sk_lookup *\fP\fIctx\fP\fB, struct bpf_sock *\fP\fIsk\fP\fB, u64\fP \fIflags\fP\fB)\fP
3273 .INDENT 7.0
3274 .TP
3275 .B Description
3276 Helper is overloaded depending on BPF program type. This
3277 description applies to \fBBPF_PROG_TYPE_SK_LOOKUP\fP programs.
3278 .sp
3279 Select the \fIsk\fP as a result of a socket lookup.
3280 .sp
3281 For the operation to succeed passed socket must be compatible
3282 with the packet description provided by the \fIctx\fP object.
3283 .sp
3284 L4 protocol (\fBIPPROTO_TCP\fP or \fBIPPROTO_UDP\fP) must
3285 be an exact match. While IP family (\fBAF_INET\fP or
3286 \fBAF_INET6\fP) must be compatible, that is IPv6 sockets
3287 that are not v6\-only can be selected for IPv4 packets.
3288 .sp
3289 Only TCP listeners and UDP unconnected sockets can be
3290 selected. \fIsk\fP can also be NULL to reset any previous
3291 selection.
3292 .sp
3293 \fIflags\fP argument can combination of following values:
3294 .INDENT 7.0
3295 .IP \(bu 2
3296 \fBBPF_SK_LOOKUP_F_REPLACE\fP to override the previous
3297 socket selection, potentially done by a BPF program
3298 that ran before us.
3299 .IP \(bu 2
3300 \fBBPF_SK_LOOKUP_F_NO_REUSEPORT\fP to skip
3301 load\-balancing within reuseport group for the socket
3302 being selected.
3303 .UNINDENT
3304 .sp
3305 On success \fIctx\->sk\fP will point to the selected socket.
3306 .TP
3307 .B Return
3308 0 on success, or a negative errno in case of failure.
3309 .INDENT 7.0
3310 .IP \(bu 2
3311 \fB\-EAFNOSUPPORT\fP if socket family (\fIsk\->family\fP) is
3312 not compatible with packet family (\fIctx\->family\fP).
3313 .IP \(bu 2
3314 \fB\-EEXIST\fP if socket has been already selected,
3315 potentially by another program, and
3316 \fBBPF_SK_LOOKUP_F_REPLACE\fP flag was not specified.
3317 .IP \(bu 2
3318 \fB\-EINVAL\fP if unsupported flags were specified.
3319 .IP \(bu 2
3320 \fB\-EPROTOTYPE\fP if socket L4 protocol
3321 (\fIsk\->protocol\fP) doesn\(aqt match packet protocol
3322 (\fIctx\->protocol\fP).
3323 .IP \(bu 2
3324 \fB\-ESOCKTNOSUPPORT\fP if socket is not in allowed
3325 state (TCP listening or UDP unconnected).
3326 .UNINDENT
3327 .UNINDENT
3328 .TP
3329 .B \fBu64 bpf_ktime_get_boot_ns(void)\fP
3330 .INDENT 7.0
3331 .TP
3332 .B Description
3333 Return the time elapsed since system boot, in nanoseconds.
3334 Does include the time the system was suspended.
3335 See: \fBclock_gettime\fP(\fBCLOCK_BOOTTIME\fP)
3336 .TP
3337 .B Return
3338 Current \fIktime\fP\&.
3339 .UNINDENT
3340 .TP
3341 .B \fBlong bpf_seq_printf(struct seq_file *\fP\fIm\fP\fB, const char *\fP\fIfmt\fP\fB, u32\fP \fIfmt_size\fP\fB, const void *\fP\fIdata\fP\fB, u32\fP \fIdata_len\fP\fB)\fP
3342 .INDENT 7.0
3343 .TP
3344 .B Description
3345 \fBbpf_seq_printf\fP() uses seq_file \fBseq_printf\fP() to print
3346 out the format string.
3347 The \fIm\fP represents the seq_file. The \fIfmt\fP and \fIfmt_size\fP are for
3348 the format string itself. The \fIdata\fP and \fIdata_len\fP are format string
3349 arguments. The \fIdata\fP are a \fBu64\fP array and corresponding format string
3350 values are stored in the array. For strings and pointers where pointees
3351 are accessed, only the pointer values are stored in the \fIdata\fP array.
3352 The \fIdata_len\fP is the size of \fIdata\fP in bytes \- must be a multiple of 8.
3353 .sp
3354 Formats \fB%s\fP, \fB%p{i,I}{4,6}\fP requires to read kernel memory.
3355 Reading kernel memory may fail due to either invalid address or
3356 valid address but requiring a major memory fault. If reading kernel memory
3357 fails, the string for \fB%s\fP will be an empty string, and the ip
3358 address for \fB%p{i,I}{4,6}\fP will be 0. Not returning error to
3359 bpf program is consistent with what \fBbpf_trace_printk\fP() does for now.
3360 .TP
3361 .B Return
3362 0 on success, or a negative error in case of failure:
3363 .sp
3364 \fB\-EBUSY\fP if per\-CPU memory copy buffer is busy, can try again
3365 by returning 1 from bpf program.
3366 .sp
3367 \fB\-EINVAL\fP if arguments are invalid, or if \fIfmt\fP is invalid/unsupported.
3368 .sp
3369 \fB\-E2BIG\fP if \fIfmt\fP contains too many format specifiers.
3370 .sp
3371 \fB\-EOVERFLOW\fP if an overflow happened: The same object will be tried again.
3372 .UNINDENT
3373 .TP
3374 .B \fBlong bpf_seq_write(struct seq_file *\fP\fIm\fP\fB, const void *\fP\fIdata\fP\fB, u32\fP \fIlen\fP\fB)\fP
3375 .INDENT 7.0
3376 .TP
3377 .B Description
3378 \fBbpf_seq_write\fP() uses seq_file \fBseq_write\fP() to write the data.
3379 The \fIm\fP represents the seq_file. The \fIdata\fP and \fIlen\fP represent the
3380 data to write in bytes.
3381 .TP
3382 .B Return
3383 0 on success, or a negative error in case of failure:
3384 .sp
3385 \fB\-EOVERFLOW\fP if an overflow happened: The same object will be tried again.
3386 .UNINDENT
3387 .TP
3388 .B \fBu64 bpf_sk_cgroup_id(void *\fP\fIsk\fP\fB)\fP
3389 .INDENT 7.0
3390 .TP
3391 .B Description
3392 Return the cgroup v2 id of the socket \fIsk\fP\&.
3393 .sp
3394 \fIsk\fP must be a non\-\fBNULL\fP pointer to a socket, e.g. one
3395 returned from \fBbpf_sk_lookup_xxx\fP(),
3396 \fBbpf_sk_fullsock\fP(), etc. The format of returned id is
3397 same as in \fBbpf_skb_cgroup_id\fP().
3398 .sp
3399 This helper is available only if the kernel was compiled with
3400 the \fBCONFIG_SOCK_CGROUP_DATA\fP configuration option.
3401 .TP
3402 .B Return
3403 The id is returned or 0 in case the id could not be retrieved.
3404 .UNINDENT
3405 .TP
3406 .B \fBu64 bpf_sk_ancestor_cgroup_id(void *\fP\fIsk\fP\fB, int\fP \fIancestor_level\fP\fB)\fP
3407 .INDENT 7.0
3408 .TP
3409 .B Description
3410 Return id of cgroup v2 that is ancestor of cgroup associated
3411 with the \fIsk\fP at the \fIancestor_level\fP\&. The root cgroup is at
3412 \fIancestor_level\fP zero and each step down the hierarchy
3413 increments the level. If \fIancestor_level\fP == level of cgroup
3414 associated with \fIsk\fP, then return value will be same as that
3415 of \fBbpf_sk_cgroup_id\fP().
3416 .sp
3417 The helper is useful to implement policies based on cgroups
3418 that are upper in hierarchy than immediate cgroup associated
3419 with \fIsk\fP\&.
3420 .sp
3421 The format of returned id and helper limitations are same as in
3422 \fBbpf_sk_cgroup_id\fP().
3423 .TP
3424 .B Return
3425 The id is returned or 0 in case the id could not be retrieved.
3426 .UNINDENT
3427 .TP
3428 .B \fBlong bpf_ringbuf_output(void *\fP\fIringbuf\fP\fB, void *\fP\fIdata\fP\fB, u64\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
3429 .INDENT 7.0
3430 .TP
3431 .B Description
3432 Copy \fIsize\fP bytes from \fIdata\fP into a ring buffer \fIringbuf\fP\&.
3433 If \fBBPF_RB_NO_WAKEUP\fP is specified in \fIflags\fP, no notification
3434 of new data availability is sent.
3435 If \fBBPF_RB_FORCE_WAKEUP\fP is specified in \fIflags\fP, notification
3436 of new data availability is sent unconditionally.
3437 If \fB0\fP is specified in \fIflags\fP, an adaptive notification
3438 of new data availability is sent.
3439 .sp
3440 An adaptive notification is a notification sent whenever the user\-space
3441 process has caught up and consumed all available payloads. In case the user\-space
3442 process is still processing a previous payload, then no notification is needed
3443 as it will process the newly added payload automatically.
3444 .TP
3445 .B Return
3446 0 on success, or a negative error in case of failure.
3447 .UNINDENT
3448 .TP
3449 .B \fBvoid *bpf_ringbuf_reserve(void *\fP\fIringbuf\fP\fB, u64\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
3450 .INDENT 7.0
3451 .TP
3452 .B Description
3453 Reserve \fIsize\fP bytes of payload in a ring buffer \fIringbuf\fP\&.
3454 \fIflags\fP must be 0.
3455 .TP
3456 .B Return
3457 Valid pointer with \fIsize\fP bytes of memory available; NULL,
3458 otherwise.
3459 .UNINDENT
3460 .TP
3461 .B \fBvoid bpf_ringbuf_submit(void *\fP\fIdata\fP\fB, u64\fP \fIflags\fP\fB)\fP
3462 .INDENT 7.0
3463 .TP
3464 .B Description
3465 Submit reserved ring buffer sample, pointed to by \fIdata\fP\&.
3466 If \fBBPF_RB_NO_WAKEUP\fP is specified in \fIflags\fP, no notification
3467 of new data availability is sent.
3468 If \fBBPF_RB_FORCE_WAKEUP\fP is specified in \fIflags\fP, notification
3469 of new data availability is sent unconditionally.
3470 If \fB0\fP is specified in \fIflags\fP, an adaptive notification
3471 of new data availability is sent.
3472 .sp
3473 See \(aqbpf_ringbuf_output()\(aq for the definition of adaptive notification.
3474 .TP
3475 .B Return
3476 Nothing. Always succeeds.
3477 .UNINDENT
3478 .TP
3479 .B \fBvoid bpf_ringbuf_discard(void *\fP\fIdata\fP\fB, u64\fP \fIflags\fP\fB)\fP
3480 .INDENT 7.0
3481 .TP
3482 .B Description
3483 Discard reserved ring buffer sample, pointed to by \fIdata\fP\&.
3484 If \fBBPF_RB_NO_WAKEUP\fP is specified in \fIflags\fP, no notification
3485 of new data availability is sent.
3486 If \fBBPF_RB_FORCE_WAKEUP\fP is specified in \fIflags\fP, notification
3487 of new data availability is sent unconditionally.
3488 If \fB0\fP is specified in \fIflags\fP, an adaptive notification
3489 of new data availability is sent.
3490 .sp
3491 See \(aqbpf_ringbuf_output()\(aq for the definition of adaptive notification.
3492 .TP
3493 .B Return
3494 Nothing. Always succeeds.
3495 .UNINDENT
3496 .TP
3497 .B \fBu64 bpf_ringbuf_query(void *\fP\fIringbuf\fP\fB, u64\fP \fIflags\fP\fB)\fP
3498 .INDENT 7.0
3499 .TP
3500 .B Description
3501 Query various characteristics of provided ring buffer. What
3502 exactly is queries is determined by \fIflags\fP:
3503 .INDENT 7.0
3504 .IP \(bu 2
3505 \fBBPF_RB_AVAIL_DATA\fP: Amount of data not yet consumed.
3506 .IP \(bu 2
3507 \fBBPF_RB_RING_SIZE\fP: The size of ring buffer.
3508 .IP \(bu 2
3509 \fBBPF_RB_CONS_POS\fP: Consumer position (can wrap around).
3510 .IP \(bu 2
3511 \fBBPF_RB_PROD_POS\fP: Producer(s) position (can wrap around).
3512 .UNINDENT
3513 .sp
3514 Data returned is just a momentary snapshot of actual values
3515 and could be inaccurate, so this facility should be used to
3516 power heuristics and for reporting, not to make 100% correct
3517 calculation.
3518 .TP
3519 .B Return
3520 Requested value, or 0, if \fIflags\fP are not recognized.
3521 .UNINDENT
3522 .TP
3523 .B \fBlong bpf_csum_level(struct sk_buff *\fP\fIskb\fP\fB, u64\fP \fIlevel\fP\fB)\fP
3524 .INDENT 7.0
3525 .TP
3526 .B Description
3527 Change the skbs checksum level by one layer up or down, or
3528 reset it entirely to none in order to have the stack perform
3529 checksum validation. The level is applicable to the following
3530 protocols: TCP, UDP, GRE, SCTP, FCOE. For example, a decap of
3531 | ETH | IP | UDP | GUE | IP | TCP | into | ETH | IP | TCP |
3532 through \fBbpf_skb_adjust_room\fP() helper with passing in
3533 \fBBPF_F_ADJ_ROOM_NO_CSUM_RESET\fP flag would require one call
3534 to \fBbpf_csum_level\fP() with \fBBPF_CSUM_LEVEL_DEC\fP since
3535 the UDP header is removed. Similarly, an encap of the latter
3536 into the former could be accompanied by a helper call to
3537 \fBbpf_csum_level\fP() with \fBBPF_CSUM_LEVEL_INC\fP if the
3538 skb is still intended to be processed in higher layers of the
3539 stack instead of just egressing at tc.
3540 .sp
3541 There are three supported level settings at this time:
3542 .INDENT 7.0
3543 .IP \(bu 2
3544 \fBBPF_CSUM_LEVEL_INC\fP: Increases skb\->csum_level for skbs
3545 with CHECKSUM_UNNECESSARY.
3546 .IP \(bu 2
3547 \fBBPF_CSUM_LEVEL_DEC\fP: Decreases skb\->csum_level for skbs
3548 with CHECKSUM_UNNECESSARY.
3549 .IP \(bu 2
3550 \fBBPF_CSUM_LEVEL_RESET\fP: Resets skb\->csum_level to 0 and
3551 sets CHECKSUM_NONE to force checksum validation by the stack.
3552 .IP \(bu 2
3553 \fBBPF_CSUM_LEVEL_QUERY\fP: No\-op, returns the current
3554 skb\->csum_level.
3555 .UNINDENT
3556 .TP
3557 .B Return
3558 0 on success, or a negative error in case of failure. In the
3559 case of \fBBPF_CSUM_LEVEL_QUERY\fP, the current skb\->csum_level
3560 is returned or the error code \-EACCES in case the skb is not
3561 subject to CHECKSUM_UNNECESSARY.
3562 .UNINDENT
3563 .TP
3564 .B \fBstruct tcp6_sock *bpf_skc_to_tcp6_sock(void *\fP\fIsk\fP\fB)\fP
3565 .INDENT 7.0
3566 .TP
3567 .B Description
3568 Dynamically cast a \fIsk\fP pointer to a \fItcp6_sock\fP pointer.
3569 .TP
3570 .B Return
3571 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
3572 .UNINDENT
3573 .TP
3574 .B \fBstruct tcp_sock *bpf_skc_to_tcp_sock(void *\fP\fIsk\fP\fB)\fP
3575 .INDENT 7.0
3576 .TP
3577 .B Description
3578 Dynamically cast a \fIsk\fP pointer to a \fItcp_sock\fP pointer.
3579 .TP
3580 .B Return
3581 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
3582 .UNINDENT
3583 .TP
3584 .B \fBstruct tcp_timewait_sock *bpf_skc_to_tcp_timewait_sock(void *\fP\fIsk\fP\fB)\fP
3585 .INDENT 7.0
3586 .TP
3587 .B Description
3588 Dynamically cast a \fIsk\fP pointer to a \fItcp_timewait_sock\fP pointer.
3589 .TP
3590 .B Return
3591 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
3592 .UNINDENT
3593 .TP
3594 .B \fBstruct tcp_request_sock *bpf_skc_to_tcp_request_sock(void *\fP\fIsk\fP\fB)\fP
3595 .INDENT 7.0
3596 .TP
3597 .B Description
3598 Dynamically cast a \fIsk\fP pointer to a \fItcp_request_sock\fP pointer.
3599 .TP
3600 .B Return
3601 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
3602 .UNINDENT
3603 .TP
3604 .B \fBstruct udp6_sock *bpf_skc_to_udp6_sock(void *\fP\fIsk\fP\fB)\fP
3605 .INDENT 7.0
3606 .TP
3607 .B Description
3608 Dynamically cast a \fIsk\fP pointer to a \fIudp6_sock\fP pointer.
3609 .TP
3610 .B Return
3611 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
3612 .UNINDENT
3613 .TP
3614 .B \fBlong bpf_get_task_stack(struct task_struct *\fP\fItask\fP\fB, void *\fP\fIbuf\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
3615 .INDENT 7.0
3616 .TP
3617 .B Description
3618 Return a user or a kernel stack in bpf program provided buffer.
3619 Note: the user stack will only be populated if the \fItask\fP is
3620 the current task; all other tasks will return \-EOPNOTSUPP.
3621 To achieve this, the helper needs \fItask\fP, which is a valid
3622 pointer to \fBstruct task_struct\fP\&. To store the stacktrace, the
3623 bpf program provides \fIbuf\fP with a nonnegative \fIsize\fP\&.
3624 .sp
3625 The last argument, \fIflags\fP, holds the number of stack frames to
3626 skip (from 0 to 255), masked with
3627 \fBBPF_F_SKIP_FIELD_MASK\fP\&. The next bits can be used to set
3628 the following flags:
3629 .INDENT 7.0
3630 .TP
3631 .B \fBBPF_F_USER_STACK\fP
3632 Collect a user space stack instead of a kernel stack.
3633 The \fItask\fP must be the current task.
3634 .TP
3635 .B \fBBPF_F_USER_BUILD_ID\fP
3636 Collect buildid+offset instead of ips for user stack,
3637 only valid if \fBBPF_F_USER_STACK\fP is also specified.
3638 .UNINDENT
3639 .sp
3640 \fBbpf_get_task_stack\fP() can collect up to
3641 \fBPERF_MAX_STACK_DEPTH\fP both kernel and user frames, subject
3642 to sufficient large buffer size. Note that
3643 this limit can be controlled with the \fBsysctl\fP program, and
3644 that it should be manually increased in order to profile long
3645 user stacks (such as stacks for Java programs). To do so, use:
3646 .INDENT 7.0
3647 .INDENT 3.5
3648 .sp
3649 .EX
3650 # sysctl kernel.perf_event_max_stack=<new value>
3651 .EE
3652 .UNINDENT
3653 .UNINDENT
3654 .TP
3655 .B Return
3656 The non\-negative copied \fIbuf\fP length equal to or less than
3657 \fIsize\fP on success, or a negative error in case of failure.
3658 .UNINDENT
3659 .TP
3660 .B \fBlong bpf_load_hdr_opt(struct bpf_sock_ops *\fP\fIskops\fP\fB, void *\fP\fIsearchby_res\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
3661 .INDENT 7.0
3662 .TP
3663 .B Description
3664 Load header option. Support reading a particular TCP header
3665 option for bpf program (\fBBPF_PROG_TYPE_SOCK_OPS\fP).
3666 .sp
3667 If \fIflags\fP is 0, it will search the option from the
3668 \fIskops\fP\fB\->skb_data\fP\&. The comment in \fBstruct bpf_sock_ops\fP
3669 has details on what skb_data contains under different
3670 \fIskops\fP\fB\->op\fP\&.
3671 .sp
3672 The first byte of the \fIsearchby_res\fP specifies the
3673 kind that it wants to search.
3674 .sp
3675 If the searching kind is an experimental kind
3676 (i.e. 253 or 254 according to RFC6994). It also
3677 needs to specify the \(dqmagic\(dq which is either
3678 2 bytes or 4 bytes. It then also needs to
3679 specify the size of the magic by using
3680 the 2nd byte which is \(dqkind\-length\(dq of a TCP
3681 header option and the \(dqkind\-length\(dq also
3682 includes the first 2 bytes \(dqkind\(dq and \(dqkind\-length\(dq
3683 itself as a normal TCP header option also does.
3684 .sp
3685 For example, to search experimental kind 254 with
3686 2 byte magic 0xeB9F, the searchby_res should be
3687 [ 254, 4, 0xeB, 0x9F, 0, 0, .... 0 ].
3688 .sp
3689 To search for the standard window scale option (3),
3690 the \fIsearchby_res\fP should be [ 3, 0, 0, .... 0 ].
3691 Note, kind\-length must be 0 for regular option.
3692 .sp
3693 Searching for No\-Op (0) and End\-of\-Option\-List (1) are
3694 not supported.
3695 .sp
3696 \fIlen\fP must be at least 2 bytes which is the minimal size
3697 of a header option.
3698 .sp
3699 Supported flags:
3700 .INDENT 7.0
3701 .IP \(bu 2
3702 \fBBPF_LOAD_HDR_OPT_TCP_SYN\fP to search from the
3703 saved_syn packet or the just\-received syn packet.
3704 .UNINDENT
3705 .TP
3706 .B Return
3707 > 0 when found, the header option is copied to \fIsearchby_res\fP\&.
3708 The return value is the total length copied. On failure, a
3709 negative error code is returned:
3710 .sp
3711 \fB\-EINVAL\fP if a parameter is invalid.
3712 .sp
3713 \fB\-ENOMSG\fP if the option is not found.
3714 .sp
3715 \fB\-ENOENT\fP if no syn packet is available when
3716 \fBBPF_LOAD_HDR_OPT_TCP_SYN\fP is used.
3717 .sp
3718 \fB\-ENOSPC\fP if there is not enough space. Only \fIlen\fP number of
3719 bytes are copied.
3720 .sp
3721 \fB\-EFAULT\fP on failure to parse the header options in the
3722 packet.
3723 .sp
3724 \fB\-EPERM\fP if the helper cannot be used under the current
3725 \fIskops\fP\fB\->op\fP\&.
3726 .UNINDENT
3727 .TP
3728 .B \fBlong bpf_store_hdr_opt(struct bpf_sock_ops *\fP\fIskops\fP\fB, const void *\fP\fIfrom\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
3729 .INDENT 7.0
3730 .TP
3731 .B Description
3732 Store header option. The data will be copied
3733 from buffer \fIfrom\fP with length \fIlen\fP to the TCP header.
3734 .sp
3735 The buffer \fIfrom\fP should have the whole option that
3736 includes the kind, kind\-length, and the actual
3737 option data. The \fIlen\fP must be at least kind\-length
3738 long. The kind\-length does not have to be 4 byte
3739 aligned. The kernel will take care of the padding
3740 and setting the 4 bytes aligned value to th\->doff.
3741 .sp
3742 This helper will check for duplicated option
3743 by searching the same option in the outgoing skb.
3744 .sp
3745 This helper can only be called during
3746 \fBBPF_SOCK_OPS_WRITE_HDR_OPT_CB\fP\&.
3747 .TP
3748 .B Return
3749 0 on success, or negative error in case of failure:
3750 .sp
3751 \fB\-EINVAL\fP If param is invalid.
3752 .sp
3753 \fB\-ENOSPC\fP if there is not enough space in the header.
3754 Nothing has been written
3755 .sp
3756 \fB\-EEXIST\fP if the option already exists.
3757 .sp
3758 \fB\-EFAULT\fP on failure to parse the existing header options.
3759 .sp
3760 \fB\-EPERM\fP if the helper cannot be used under the current
3761 \fIskops\fP\fB\->op\fP\&.
3762 .UNINDENT
3763 .TP
3764 .B \fBlong bpf_reserve_hdr_opt(struct bpf_sock_ops *\fP\fIskops\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
3765 .INDENT 7.0
3766 .TP
3767 .B Description
3768 Reserve \fIlen\fP bytes for the bpf header option. The
3769 space will be used by \fBbpf_store_hdr_opt\fP() later in
3770 \fBBPF_SOCK_OPS_WRITE_HDR_OPT_CB\fP\&.
3771 .sp
3772 If \fBbpf_reserve_hdr_opt\fP() is called multiple times,
3773 the total number of bytes will be reserved.
3774 .sp
3775 This helper can only be called during
3776 \fBBPF_SOCK_OPS_HDR_OPT_LEN_CB\fP\&.
3777 .TP
3778 .B Return
3779 0 on success, or negative error in case of failure:
3780 .sp
3781 \fB\-EINVAL\fP if a parameter is invalid.
3782 .sp
3783 \fB\-ENOSPC\fP if there is not enough space in the header.
3784 .sp
3785 \fB\-EPERM\fP if the helper cannot be used under the current
3786 \fIskops\fP\fB\->op\fP\&.
3787 .UNINDENT
3788 .TP
3789 .B \fBvoid *bpf_inode_storage_get(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIinode\fP\fB, void *\fP\fIvalue\fP\fB, u64\fP \fIflags\fP\fB)\fP
3790 .INDENT 7.0
3791 .TP
3792 .B Description
3793 Get a bpf_local_storage from an \fIinode\fP\&.
3794 .sp
3795 Logically, it could be thought of as getting the value from
3796 a \fImap\fP with \fIinode\fP as the \fBkey\fP\&. From this
3797 perspective, the usage is not much different from
3798 \fBbpf_map_lookup_elem\fP(\fImap\fP, \fB&\fP\fIinode\fP) except this
3799 helper enforces the key must be an inode and the map must also
3800 be a \fBBPF_MAP_TYPE_INODE_STORAGE\fP\&.
3801 .sp
3802 Underneath, the value is stored locally at \fIinode\fP instead of
3803 the \fImap\fP\&. The \fImap\fP is used as the bpf\-local\-storage
3804 \(dqtype\(dq. The bpf\-local\-storage \(dqtype\(dq (i.e. the \fImap\fP) is
3805 searched against all bpf_local_storage residing at \fIinode\fP\&.
3806 .sp
3807 An optional \fIflags\fP (\fBBPF_LOCAL_STORAGE_GET_F_CREATE\fP) can be
3808 used such that a new bpf_local_storage will be
3809 created if one does not exist. \fIvalue\fP can be used
3810 together with \fBBPF_LOCAL_STORAGE_GET_F_CREATE\fP to specify
3811 the initial value of a bpf_local_storage. If \fIvalue\fP is
3812 \fBNULL\fP, the new bpf_local_storage will be zero initialized.
3813 .TP
3814 .B Return
3815 A bpf_local_storage pointer is returned on success.
3816 .sp
3817 \fBNULL\fP if not found or there was an error in adding
3818 a new bpf_local_storage.
3819 .UNINDENT
3820 .TP
3821 .B \fBint bpf_inode_storage_delete(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIinode\fP\fB)\fP
3822 .INDENT 7.0
3823 .TP
3824 .B Description
3825 Delete a bpf_local_storage from an \fIinode\fP\&.
3826 .TP
3827 .B Return
3828 0 on success.
3829 .sp
3830 \fB\-ENOENT\fP if the bpf_local_storage cannot be found.
3831 .UNINDENT
3832 .TP
3833 .B \fBlong bpf_d_path(struct path *\fP\fIpath\fP\fB, char *\fP\fIbuf\fP\fB, u32\fP \fIsz\fP\fB)\fP
3834 .INDENT 7.0
3835 .TP
3836 .B Description
3837 Return full path for given \fBstruct path\fP object, which
3838 needs to be the kernel BTF \fIpath\fP object. The path is
3839 returned in the provided buffer \fIbuf\fP of size \fIsz\fP and
3840 is zero terminated.
3841 .TP
3842 .B Return
3843 On success, the strictly positive length of the string,
3844 including the trailing NUL character. On error, a negative
3845 value.
3846 .UNINDENT
3847 .TP
3848 .B \fBlong bpf_copy_from_user(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIuser_ptr\fP\fB)\fP
3849 .INDENT 7.0
3850 .TP
3851 .B Description
3852 Read \fIsize\fP bytes from user space address \fIuser_ptr\fP and store
3853 the data in \fIdst\fP\&. This is a wrapper of \fBcopy_from_user\fP().
3854 .TP
3855 .B Return
3856 0 on success, or a negative error in case of failure.
3857 .UNINDENT
3858 .TP
3859 .B \fBlong bpf_snprintf_btf(char *\fP\fIstr\fP\fB, u32\fP \fIstr_size\fP\fB, struct btf_ptr *\fP\fIptr\fP\fB, u32\fP \fIbtf_ptr_size\fP\fB, u64\fP \fIflags\fP\fB)\fP
3860 .INDENT 7.0
3861 .TP
3862 .B Description
3863 Use BTF to store a string representation of \fIptr\fP\->ptr in \fIstr\fP,
3864 using \fIptr\fP\->type_id. This value should specify the type
3865 that \fIptr\fP\->ptr points to. LLVM __builtin_btf_type_id(type, 1)
3866 can be used to look up vmlinux BTF type ids. Traversing the
3867 data structure using BTF, the type information and values are
3868 stored in the first \fIstr_size\fP \- 1 bytes of \fIstr\fP\&. Safe copy of
3869 the pointer data is carried out to avoid kernel crashes during
3870 operation. Smaller types can use string space on the stack;
3871 larger programs can use map data to store the string
3872 representation.
3873 .sp
3874 The string can be subsequently shared with userspace via
3875 bpf_perf_event_output() or ring buffer interfaces.
3876 bpf_trace_printk() is to be avoided as it places too small
3877 a limit on string size to be useful.
3878 .sp
3879 \fIflags\fP is a combination of
3880 .INDENT 7.0
3881 .TP
3882 .B \fBBTF_F_COMPACT\fP
3883 no formatting around type information
3884 .TP
3885 .B \fBBTF_F_NONAME\fP
3886 no struct/union member names/types
3887 .TP
3888 .B \fBBTF_F_PTR_RAW\fP
3889 show raw (unobfuscated) pointer values;
3890 equivalent to printk specifier %px.
3891 .TP
3892 .B \fBBTF_F_ZERO\fP
3893 show zero\-valued struct/union members; they
3894 are not displayed by default
3895 .UNINDENT
3896 .TP
3897 .B Return
3898 The number of bytes that were written (or would have been
3899 written if output had to be truncated due to string size),
3900 or a negative error in cases of failure.
3901 .UNINDENT
3902 .TP
3903 .B \fBlong bpf_seq_printf_btf(struct seq_file *\fP\fIm\fP\fB, struct btf_ptr *\fP\fIptr\fP\fB, u32\fP \fIptr_size\fP\fB, u64\fP \fIflags\fP\fB)\fP
3904 .INDENT 7.0
3905 .TP
3906 .B Description
3907 Use BTF to write to seq_write a string representation of
3908 \fIptr\fP\->ptr, using \fIptr\fP\->type_id as per bpf_snprintf_btf().
3909 \fIflags\fP are identical to those used for bpf_snprintf_btf.
3910 .TP
3911 .B Return
3912 0 on success or a negative error in case of failure.
3913 .UNINDENT
3914 .TP
3915 .B \fBu64 bpf_skb_cgroup_classid(struct sk_buff *\fP\fIskb\fP\fB)\fP
3916 .INDENT 7.0
3917 .TP
3918 .B Description
3919 See \fBbpf_get_cgroup_classid\fP() for the main description.
3920 This helper differs from \fBbpf_get_cgroup_classid\fP() in that
3921 the cgroup v1 net_cls class is retrieved only from the \fIskb\fP\(aqs
3922 associated socket instead of the current process.
3923 .TP
3924 .B Return
3925 The id is returned or 0 in case the id could not be retrieved.
3926 .UNINDENT
3927 .TP
3928 .B \fBlong bpf_redirect_neigh(u32\fP \fIifindex\fP\fB, struct bpf_redir_neigh *\fP\fIparams\fP\fB, int\fP \fIplen\fP\fB, u64\fP \fIflags\fP\fB)\fP
3929 .INDENT 7.0
3930 .TP
3931 .B Description
3932 Redirect the packet to another net device of index \fIifindex\fP
3933 and fill in L2 addresses from neighboring subsystem. This helper
3934 is somewhat similar to \fBbpf_redirect\fP(), except that it
3935 populates L2 addresses as well, meaning, internally, the helper
3936 relies on the neighbor lookup for the L2 address of the nexthop.
3937 .sp
3938 The helper will perform a FIB lookup based on the skb\(aqs
3939 networking header to get the address of the next hop, unless
3940 this is supplied by the caller in the \fIparams\fP argument. The
3941 \fIplen\fP argument indicates the len of \fIparams\fP and should be set
3942 to 0 if \fIparams\fP is NULL.
3943 .sp
3944 The \fIflags\fP argument is reserved and must be 0. The helper is
3945 currently only supported for tc BPF program types, and enabled
3946 for IPv4 and IPv6 protocols.
3947 .TP
3948 .B Return
3949 The helper returns \fBTC_ACT_REDIRECT\fP on success or
3950 \fBTC_ACT_SHOT\fP on error.
3951 .UNINDENT
3952 .TP
3953 .B \fBvoid *bpf_per_cpu_ptr(const void *\fP\fIpercpu_ptr\fP\fB, u32\fP \fIcpu\fP\fB)\fP
3954 .INDENT 7.0
3955 .TP
3956 .B Description
3957 Take a pointer to a percpu ksym, \fIpercpu_ptr\fP, and return a
3958 pointer to the percpu kernel variable on \fIcpu\fP\&. A ksym is an
3959 extern variable decorated with \(aq__ksym\(aq. For ksym, there is a
3960 global var (either static or global) defined of the same name
3961 in the kernel. The ksym is percpu if the global var is percpu.
3962 The returned pointer points to the global percpu var on \fIcpu\fP\&.
3963 .sp
3964 bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the
3965 kernel, except that bpf_per_cpu_ptr() may return NULL. This
3966 happens if \fIcpu\fP is larger than nr_cpu_ids. The caller of
3967 bpf_per_cpu_ptr() must check the returned value.
3968 .TP
3969 .B Return
3970 A pointer pointing to the kernel percpu variable on \fIcpu\fP, or
3971 NULL, if \fIcpu\fP is invalid.
3972 .UNINDENT
3973 .TP
3974 .B \fBvoid *bpf_this_cpu_ptr(const void *\fP\fIpercpu_ptr\fP\fB)\fP
3975 .INDENT 7.0
3976 .TP
3977 .B Description
3978 Take a pointer to a percpu ksym, \fIpercpu_ptr\fP, and return a
3979 pointer to the percpu kernel variable on this cpu. See the
3980 description of \(aqksym\(aq in \fBbpf_per_cpu_ptr\fP().
3981 .sp
3982 bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in
3983 the kernel. Different from \fBbpf_per_cpu_ptr\fP(), it would
3984 never return NULL.
3985 .TP
3986 .B Return
3987 A pointer pointing to the kernel percpu variable on this cpu.
3988 .UNINDENT
3989 .TP
3990 .B \fBlong bpf_redirect_peer(u32\fP \fIifindex\fP\fB, u64\fP \fIflags\fP\fB)\fP
3991 .INDENT 7.0
3992 .TP
3993 .B Description
3994 Redirect the packet to another net device of index \fIifindex\fP\&.
3995 This helper is somewhat similar to \fBbpf_redirect\fP(), except
3996 that the redirection happens to the \fIifindex\fP\(aq peer device and
3997 the netns switch takes place from ingress to ingress without
3998 going through the CPU\(aqs backlog queue.
3999 .sp
4000 The \fIflags\fP argument is reserved and must be 0. The helper is
4001 currently only supported for tc BPF program types at the
4002 ingress hook and for veth and netkit target device types. The
4003 peer device must reside in a different network namespace.
4004 .TP
4005 .B Return
4006 The helper returns \fBTC_ACT_REDIRECT\fP on success or
4007 \fBTC_ACT_SHOT\fP on error.
4008 .UNINDENT
4009 .TP
4010 .B \fBvoid *bpf_task_storage_get(struct bpf_map *\fP\fImap\fP\fB, struct task_struct *\fP\fItask\fP\fB, void *\fP\fIvalue\fP\fB, u64\fP \fIflags\fP\fB)\fP
4011 .INDENT 7.0
4012 .TP
4013 .B Description
4014 Get a bpf_local_storage from the \fItask\fP\&.
4015 .sp
4016 Logically, it could be thought of as getting the value from
4017 a \fImap\fP with \fItask\fP as the \fBkey\fP\&. From this
4018 perspective, the usage is not much different from
4019 \fBbpf_map_lookup_elem\fP(\fImap\fP, \fB&\fP\fItask\fP) except this
4020 helper enforces the key must be a task_struct and the map must also
4021 be a \fBBPF_MAP_TYPE_TASK_STORAGE\fP\&.
4022 .sp
4023 Underneath, the value is stored locally at \fItask\fP instead of
4024 the \fImap\fP\&. The \fImap\fP is used as the bpf\-local\-storage
4025 \(dqtype\(dq. The bpf\-local\-storage \(dqtype\(dq (i.e. the \fImap\fP) is
4026 searched against all bpf_local_storage residing at \fItask\fP\&.
4027 .sp
4028 An optional \fIflags\fP (\fBBPF_LOCAL_STORAGE_GET_F_CREATE\fP) can be
4029 used such that a new bpf_local_storage will be
4030 created if one does not exist. \fIvalue\fP can be used
4031 together with \fBBPF_LOCAL_STORAGE_GET_F_CREATE\fP to specify
4032 the initial value of a bpf_local_storage. If \fIvalue\fP is
4033 \fBNULL\fP, the new bpf_local_storage will be zero initialized.
4034 .TP
4035 .B Return
4036 A bpf_local_storage pointer is returned on success.
4037 .sp
4038 \fBNULL\fP if not found or there was an error in adding
4039 a new bpf_local_storage.
4040 .UNINDENT
4041 .TP
4042 .B \fBlong bpf_task_storage_delete(struct bpf_map *\fP\fImap\fP\fB, struct task_struct *\fP\fItask\fP\fB)\fP
4043 .INDENT 7.0
4044 .TP
4045 .B Description
4046 Delete a bpf_local_storage from a \fItask\fP\&.
4047 .TP
4048 .B Return
4049 0 on success.
4050 .sp
4051 \fB\-ENOENT\fP if the bpf_local_storage cannot be found.
4052 .UNINDENT
4053 .TP
4054 .B \fBstruct task_struct *bpf_get_current_task_btf(void)\fP
4055 .INDENT 7.0
4056 .TP
4057 .B Description
4058 Return a BTF pointer to the \(dqcurrent\(dq task.
4059 This pointer can also be used in helpers that accept an
4060 \fIARG_PTR_TO_BTF_ID\fP of type \fItask_struct\fP\&.
4061 .TP
4062 .B Return
4063 Pointer to the current task.
4064 .UNINDENT
4065 .TP
4066 .B \fBlong bpf_bprm_opts_set(struct linux_binprm *\fP\fIbprm\fP\fB, u64\fP \fIflags\fP\fB)\fP
4067 .INDENT 7.0
4068 .TP
4069 .B Description
4070 Set or clear certain options on \fIbprm\fP:
4071 .sp
4072 \fBBPF_F_BPRM_SECUREEXEC\fP Set the secureexec bit
4073 which sets the \fBAT_SECURE\fP auxv for glibc. The bit
4074 is cleared if the flag is not specified.
4075 .TP
4076 .B Return
4077 \fB\-EINVAL\fP if invalid \fIflags\fP are passed, zero otherwise.
4078 .UNINDENT
4079 .TP
4080 .B \fBu64 bpf_ktime_get_coarse_ns(void)\fP
4081 .INDENT 7.0
4082 .TP
4083 .B Description
4084 Return a coarse\-grained version of the time elapsed since
4085 system boot, in nanoseconds. Does not include time the system
4086 was suspended.
4087 .sp
4088 See: \fBclock_gettime\fP(\fBCLOCK_MONOTONIC_COARSE\fP)
4089 .TP
4090 .B Return
4091 Current \fIktime\fP\&.
4092 .UNINDENT
4093 .TP
4094 .B \fBlong bpf_ima_inode_hash(struct inode *\fP\fIinode\fP\fB, void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB)\fP
4095 .INDENT 7.0
4096 .TP
4097 .B Description
4098 Returns the stored IMA hash of the \fIinode\fP (if it\(aqs available).
4099 If the hash is larger than \fIsize\fP, then only \fIsize\fP
4100 bytes will be copied to \fIdst\fP
4101 .TP
4102 .B Return
4103 The \fBhash_algo\fP is returned on success,
4104 \fB\-EOPNOTSUPP\fP if IMA is disabled or \fB\-EINVAL\fP if
4105 invalid arguments are passed.
4106 .UNINDENT
4107 .TP
4108 .B \fBstruct socket *bpf_sock_from_file(struct file *\fP\fIfile\fP\fB)\fP
4109 .INDENT 7.0
4110 .TP
4111 .B Description
4112 If the given file represents a socket, returns the associated
4113 socket.
4114 .TP
4115 .B Return
4116 A pointer to a struct socket on success or NULL if the file is
4117 not a socket.
4118 .UNINDENT
4119 .TP
4120 .B \fBlong bpf_check_mtu(void *\fP\fIctx\fP\fB, u32\fP \fIifindex\fP\fB, u32 *\fP\fImtu_len\fP\fB, s32\fP \fIlen_diff\fP\fB, u64\fP \fIflags\fP\fB)\fP
4121 .INDENT 7.0
4122 .TP
4123 .B Description
4124 Check packet size against exceeding MTU of net device (based
4125 on \fIifindex\fP). This helper will likely be used in combination
4126 with helpers that adjust/change the packet size.
4127 .sp
4128 The argument \fIlen_diff\fP can be used for querying with a planned
4129 size change. This allows to check MTU prior to changing packet
4130 ctx. Providing a \fIlen_diff\fP adjustment that is larger than the
4131 actual packet size (resulting in negative packet size) will in
4132 principle not exceed the MTU, which is why it is not considered
4133 a failure. Other BPF helpers are needed for performing the
4134 planned size change; therefore the responsibility for catching
4135 a negative packet size belongs in those helpers.
4136 .sp
4137 Specifying \fIifindex\fP zero means the MTU check is performed
4138 against the current net device. This is practical if this isn\(aqt
4139 used prior to redirect.
4140 .sp
4141 On input \fImtu_len\fP must be a valid pointer, else verifier will
4142 reject BPF program. If the value \fImtu_len\fP is initialized to
4143 zero then the ctx packet size is use. When value \fImtu_len\fP is
4144 provided as input this specify the L3 length that the MTU check
4145 is done against. Remember XDP and TC length operate at L2, but
4146 this value is L3 as this correlate to MTU and IP\-header tot_len
4147 values which are L3 (similar behavior as bpf_fib_lookup).
4148 .sp
4149 The Linux kernel route table can configure MTUs on a more
4150 specific per route level, which is not provided by this helper.
4151 For route level MTU checks use the \fBbpf_fib_lookup\fP()
4152 helper.
4153 .sp
4154 \fIctx\fP is either \fBstruct xdp_md\fP for XDP programs or
4155 \fBstruct sk_buff\fP for tc cls_act programs.
4156 .sp
4157 The \fIflags\fP argument can be a combination of one or more of the
4158 following values:
4159 .INDENT 7.0
4160 .TP
4161 .B \fBBPF_MTU_CHK_SEGS\fP
4162 This flag will only works for \fIctx\fP \fBstruct sk_buff\fP\&.
4163 If packet context contains extra packet segment buffers
4164 (often knows as GSO skb), then MTU check is harder to
4165 check at this point, because in transmit path it is
4166 possible for the skb packet to get re\-segmented
4167 (depending on net device features). This could still be
4168 a MTU violation, so this flag enables performing MTU
4169 check against segments, with a different violation
4170 return code to tell it apart. Check cannot use len_diff.
4171 .UNINDENT
4172 .sp
4173 On return \fImtu_len\fP pointer contains the MTU value of the net
4174 device. Remember the net device configured MTU is the L3 size,
4175 which is returned here and XDP and TC length operate at L2.
4176 Helper take this into account for you, but remember when using
4177 MTU value in your BPF\-code.
4178 .TP
4179 .B Return
4180 .INDENT 7.0
4181 .IP \(bu 2
4182 0 on success, and populate MTU value in \fImtu_len\fP pointer.
4183 .IP \(bu 2
4184 < 0 if any input argument is invalid (\fImtu_len\fP not updated)
4185 .UNINDENT
4186 .sp
4187 MTU violations return positive values, but also populate MTU
4188 value in \fImtu_len\fP pointer, as this can be needed for
4189 implementing PMTU handing:
4190 .INDENT 7.0
4191 .IP \(bu 2
4192 \fBBPF_MTU_CHK_RET_FRAG_NEEDED\fP
4193 .IP \(bu 2
4194 \fBBPF_MTU_CHK_RET_SEGS_TOOBIG\fP
4195 .UNINDENT
4196 .UNINDENT
4197 .TP
4198 .B \fBlong bpf_for_each_map_elem(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIcallback_fn\fP\fB, void *\fP\fIcallback_ctx\fP\fB, u64\fP \fIflags\fP\fB)\fP
4199 .INDENT 7.0
4200 .TP
4201 .B Description
4202 For each element in \fBmap\fP, call \fBcallback_fn\fP function with
4203 \fBmap\fP, \fBcallback_ctx\fP and other map\-specific parameters.
4204 The \fBcallback_fn\fP should be a static function and
4205 the \fBcallback_ctx\fP should be a pointer to the stack.
4206 The \fBflags\fP is used to control certain aspects of the helper.
4207 Currently, the \fBflags\fP must be 0.
4208 .sp
4209 The following are a list of supported map types and their
4210 respective expected callback signatures:
4211 .sp
4212 BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERCPU_HASH,
4213 BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH,
4214 BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_PERCPU_ARRAY
4215 .sp
4216 long (*callback_fn)(struct bpf_map *map, const void *key, void *value, void *ctx);
4217 .sp
4218 For per_cpu maps, the map_value is the value on the cpu where the
4219 bpf_prog is running.
4220 .sp
4221 If \fBcallback_fn\fP return 0, the helper will continue to the next
4222 element. If return value is 1, the helper will skip the rest of
4223 elements and return. Other return values are not used now.
4224 .TP
4225 .B Return
4226 The number of traversed map elements for success, \fB\-EINVAL\fP for
4227 invalid \fBflags\fP\&.
4228 .UNINDENT
4229 .TP
4230 .B \fBlong bpf_snprintf(char *\fP\fIstr\fP\fB, u32\fP \fIstr_size\fP\fB, const char *\fP\fIfmt\fP\fB, u64 *\fP\fIdata\fP\fB, u32\fP \fIdata_len\fP\fB)\fP
4231 .INDENT 7.0
4232 .TP
4233 .B Description
4234 Outputs a string into the \fBstr\fP buffer of size \fBstr_size\fP
4235 based on a format string stored in a read\-only map pointed by
4236 \fBfmt\fP\&.
4237 .sp
4238 Each format specifier in \fBfmt\fP corresponds to one u64 element
4239 in the \fBdata\fP array. For strings and pointers where pointees
4240 are accessed, only the pointer values are stored in the \fIdata\fP
4241 array. The \fIdata_len\fP is the size of \fIdata\fP in bytes \- must be
4242 a multiple of 8.
4243 .sp
4244 Formats \fB%s\fP and \fB%p{i,I}{4,6}\fP require to read kernel
4245 memory. Reading kernel memory may fail due to either invalid
4246 address or valid address but requiring a major memory fault. If
4247 reading kernel memory fails, the string for \fB%s\fP will be an
4248 empty string, and the ip address for \fB%p{i,I}{4,6}\fP will be 0.
4249 Not returning error to bpf program is consistent with what
4250 \fBbpf_trace_printk\fP() does for now.
4251 .TP
4252 .B Return
4253 The strictly positive length of the formatted string, including
4254 the trailing zero character. If the return value is greater than
4255 \fBstr_size\fP, \fBstr\fP contains a truncated string, guaranteed to
4256 be zero\-terminated except when \fBstr_size\fP is 0.
4257 .sp
4258 Or \fB\-EBUSY\fP if the per\-CPU memory copy buffer is busy.
4259 .UNINDENT
4260 .TP
4261 .B \fBlong bpf_sys_bpf(u32\fP \fIcmd\fP\fB, void *\fP\fIattr\fP\fB, u32\fP \fIattr_size\fP\fB)\fP
4262 .INDENT 7.0
4263 .TP
4264 .B Description
4265 Execute bpf syscall with given arguments.
4266 .TP
4267 .B Return
4268 A syscall result.
4269 .UNINDENT
4270 .TP
4271 .B \fBlong bpf_btf_find_by_name_kind(char *\fP\fIname\fP\fB, int\fP \fIname_sz\fP\fB, u32\fP \fIkind\fP\fB, int\fP \fIflags\fP\fB)\fP
4272 .INDENT 7.0
4273 .TP
4274 .B Description
4275 Find BTF type with given name and kind in vmlinux BTF or in module\(aqs BTFs.
4276 .TP
4277 .B Return
4278 Returns btf_id and btf_obj_fd in lower and upper 32 bits.
4279 .UNINDENT
4280 .TP
4281 .B \fBlong bpf_sys_close(u32\fP \fIfd\fP\fB)\fP
4282 .INDENT 7.0
4283 .TP
4284 .B Description
4285 Execute close syscall for given FD.
4286 .TP
4287 .B Return
4288 A syscall result.
4289 .UNINDENT
4290 .TP
4291 .B \fBlong bpf_timer_init(struct bpf_timer *\fP\fItimer\fP\fB, struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB)\fP
4292 .INDENT 7.0
4293 .TP
4294 .B Description
4295 Initialize the timer.
4296 First 4 bits of \fIflags\fP specify clockid.
4297 Only CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_BOOTTIME are allowed.
4298 All other bits of \fIflags\fP are reserved.
4299 The verifier will reject the program if \fItimer\fP is not from
4300 the same \fImap\fP\&.
4301 .TP
4302 .B Return
4303 0 on success.
4304 \fB\-EBUSY\fP if \fItimer\fP is already initialized.
4305 \fB\-EINVAL\fP if invalid \fIflags\fP are passed.
4306 \fB\-EPERM\fP if \fItimer\fP is in a map that doesn\(aqt have any user references.
4307 The user space should either hold a file descriptor to a map with timers
4308 or pin such map in bpffs. When map is unpinned or file descriptor is
4309 closed all timers in the map will be cancelled and freed.
4310 .UNINDENT
4311 .TP
4312 .B \fBlong bpf_timer_set_callback(struct bpf_timer *\fP\fItimer\fP\fB, void *\fP\fIcallback_fn\fP\fB)\fP
4313 .INDENT 7.0
4314 .TP
4315 .B Description
4316 Configure the timer to call \fIcallback_fn\fP static function.
4317 .TP
4318 .B Return
4319 0 on success.
4320 \fB\-EINVAL\fP if \fItimer\fP was not initialized with bpf_timer_init() earlier.
4321 \fB\-EPERM\fP if \fItimer\fP is in a map that doesn\(aqt have any user references.
4322 The user space should either hold a file descriptor to a map with timers
4323 or pin such map in bpffs. When map is unpinned or file descriptor is
4324 closed all timers in the map will be cancelled and freed.
4325 .UNINDENT
4326 .TP
4327 .B \fBlong bpf_timer_start(struct bpf_timer *\fP\fItimer\fP\fB, u64\fP \fInsecs\fP\fB, u64\fP \fIflags\fP\fB)\fP
4328 .INDENT 7.0
4329 .TP
4330 .B Description
4331 Set timer expiration N nanoseconds from the current time. The
4332 configured callback will be invoked in soft irq context on some cpu
4333 and will not repeat unless another bpf_timer_start() is made.
4334 In such case the next invocation can migrate to a different cpu.
4335 Since struct bpf_timer is a field inside map element the map
4336 owns the timer. The bpf_timer_set_callback() will increment refcnt
4337 of BPF program to make sure that callback_fn code stays valid.
4338 When user space reference to a map reaches zero all timers
4339 in a map are cancelled and corresponding program\(aqs refcnts are
4340 decremented. This is done to make sure that Ctrl\-C of a user
4341 process doesn\(aqt leave any timers running. If map is pinned in
4342 bpffs the callback_fn can re\-arm itself indefinitely.
4343 bpf_map_update/delete_elem() helpers and user space sys_bpf commands
4344 cancel and free the timer in the given map element.
4345 The map can contain timers that invoke callback_fn\-s from different
4346 programs. The same callback_fn can serve different timers from
4347 different maps if key/value layout matches across maps.
4348 Every bpf_timer_set_callback() can have different callback_fn.
4349 .sp
4350 \fIflags\fP can be one of:
4351 .INDENT 7.0
4352 .TP
4353 .B \fBBPF_F_TIMER_ABS\fP
4354 Start the timer in absolute expire value instead of the
4355 default relative one.
4356 .TP
4357 .B \fBBPF_F_TIMER_CPU_PIN\fP
4358 Timer will be pinned to the CPU of the caller.
4359 .UNINDENT
4360 .TP
4361 .B Return
4362 0 on success.
4363 \fB\-EINVAL\fP if \fItimer\fP was not initialized with bpf_timer_init() earlier
4364 or invalid \fIflags\fP are passed.
4365 .UNINDENT
4366 .TP
4367 .B \fBlong bpf_timer_cancel(struct bpf_timer *\fP\fItimer\fP\fB)\fP
4368 .INDENT 7.0
4369 .TP
4370 .B Description
4371 Cancel the timer and wait for callback_fn to finish if it was running.
4372 .TP
4373 .B Return
4374 0 if the timer was not active.
4375 1 if the timer was active.
4376 \fB\-EINVAL\fP if \fItimer\fP was not initialized with bpf_timer_init() earlier.
4377 \fB\-EDEADLK\fP if callback_fn tried to call bpf_timer_cancel() on its
4378 own timer which would have led to a deadlock otherwise.
4379 .UNINDENT
4380 .TP
4381 .B \fBu64 bpf_get_func_ip(void *\fP\fIctx\fP\fB)\fP
4382 .INDENT 7.0
4383 .TP
4384 .B Description
4385 Get address of the traced function (for tracing and kprobe programs).
4386 .sp
4387 When called for kprobe program attached as uprobe it returns
4388 probe address for both entry and return uprobe.
4389 .TP
4390 .B Return
4391 Address of the traced function for kprobe.
4392 0 for kprobes placed within the function (not at the entry).
4393 Address of the probe for uprobe and return uprobe.
4394 .UNINDENT
4395 .TP
4396 .B \fBu64 bpf_get_attach_cookie(void *\fP\fIctx\fP\fB)\fP
4397 .INDENT 7.0
4398 .TP
4399 .B Description
4400 Get bpf_cookie value provided (optionally) during the program
4401 attachment. It might be different for each individual
4402 attachment, even if BPF program itself is the same.
4403 Expects BPF program context \fIctx\fP as a first argument.
4404 .INDENT 7.0
4405 .TP
4406 .B Supported for the following program types:
4407 .INDENT 7.0
4408 .IP \(bu 2
4409 kprobe/uprobe;
4410 .IP \(bu 2
4411 tracepoint;
4412 .IP \(bu 2
4413 perf_event.
4414 .UNINDENT
4415 .UNINDENT
4416 .TP
4417 .B Return
4418 Value specified by user at BPF link creation/attachment time
4419 or 0, if it was not specified.
4420 .UNINDENT
4421 .TP
4422 .B \fBlong bpf_task_pt_regs(struct task_struct *\fP\fItask\fP\fB)\fP
4423 .INDENT 7.0
4424 .TP
4425 .B Description
4426 Get the struct pt_regs associated with \fBtask\fP\&.
4427 .TP
4428 .B Return
4429 A pointer to struct pt_regs.
4430 .UNINDENT
4431 .TP
4432 .B \fBlong bpf_get_branch_snapshot(void *\fP\fIentries\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
4433 .INDENT 7.0
4434 .TP
4435 .B Description
4436 Get branch trace from hardware engines like Intel LBR. The
4437 hardware engine is stopped shortly after the helper is
4438 called. Therefore, the user need to filter branch entries
4439 based on the actual use case. To capture branch trace
4440 before the trigger point of the BPF program, the helper
4441 should be called at the beginning of the BPF program.
4442 .sp
4443 The data is stored as struct perf_branch_entry into output
4444 buffer \fIentries\fP\&. \fIsize\fP is the size of \fIentries\fP in bytes.
4445 \fIflags\fP is reserved for now and must be zero.
4446 .TP
4447 .B Return
4448 On success, number of bytes written to \fIbuf\fP\&. On error, a
4449 negative value.
4450 .sp
4451 \fB\-EINVAL\fP if \fIflags\fP is not zero.
4452 .sp
4453 \fB\-ENOENT\fP if architecture does not support branch records.
4454 .UNINDENT
4455 .TP
4456 .B \fBlong bpf_trace_vprintk(const char *\fP\fIfmt\fP\fB, u32\fP \fIfmt_size\fP\fB, const void *\fP\fIdata\fP\fB, u32\fP \fIdata_len\fP\fB)\fP
4457 .INDENT 7.0
4458 .TP
4459 .B Description
4460 Behaves like \fBbpf_trace_printk\fP() helper, but takes an array of u64
4461 to format and can handle more format args as a result.
4462 .sp
4463 Arguments are to be used as in \fBbpf_seq_printf\fP() helper.
4464 .TP
4465 .B Return
4466 The number of bytes written to the buffer, or a negative error
4467 in case of failure.
4468 .UNINDENT
4469 .TP
4470 .B \fBstruct unix_sock *bpf_skc_to_unix_sock(void *\fP\fIsk\fP\fB)\fP
4471 .INDENT 7.0
4472 .TP
4473 .B Description
4474 Dynamically cast a \fIsk\fP pointer to a \fIunix_sock\fP pointer.
4475 .TP
4476 .B Return
4477 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
4478 .UNINDENT
4479 .TP
4480 .B \fBlong bpf_kallsyms_lookup_name(const char *\fP\fIname\fP\fB, int\fP \fIname_sz\fP\fB, int\fP \fIflags\fP\fB, u64 *\fP\fIres\fP\fB)\fP
4481 .INDENT 7.0
4482 .TP
4483 .B Description
4484 Get the address of a kernel symbol, returned in \fIres\fP\&. \fIres\fP is
4485 set to 0 if the symbol is not found.
4486 .TP
4487 .B Return
4488 On success, zero. On error, a negative value.
4489 .sp
4490 \fB\-EINVAL\fP if \fIflags\fP is not zero.
4491 .sp
4492 \fB\-EINVAL\fP if string \fIname\fP is not the same size as \fIname_sz\fP\&.
4493 .sp
4494 \fB\-ENOENT\fP if symbol is not found.
4495 .sp
4496 \fB\-EPERM\fP if caller does not have permission to obtain kernel address.
4497 .UNINDENT
4498 .TP
4499 .B \fBlong bpf_find_vma(struct task_struct *\fP\fItask\fP\fB, u64\fP \fIaddr\fP\fB, void *\fP\fIcallback_fn\fP\fB, void *\fP\fIcallback_ctx\fP\fB, u64\fP \fIflags\fP\fB)\fP
4500 .INDENT 7.0
4501 .TP
4502 .B Description
4503 Find vma of \fItask\fP that contains \fIaddr\fP, call \fIcallback_fn\fP
4504 function with \fItask\fP, \fIvma\fP, and \fIcallback_ctx\fP\&.
4505 The \fIcallback_fn\fP should be a static function and
4506 the \fIcallback_ctx\fP should be a pointer to the stack.
4507 The \fIflags\fP is used to control certain aspects of the helper.
4508 Currently, the \fIflags\fP must be 0.
4509 .sp
4510 The expected callback signature is
4511 .sp
4512 long (*callback_fn)(struct task_struct *task, struct vm_area_struct *vma, void *callback_ctx);
4513 .TP
4514 .B Return
4515 0 on success.
4516 \fB\-ENOENT\fP if \fItask\->mm\fP is NULL, or no vma contains \fIaddr\fP\&.
4517 \fB\-EBUSY\fP if failed to try lock mmap_lock.
4518 \fB\-EINVAL\fP for invalid \fBflags\fP\&.
4519 .UNINDENT
4520 .TP
4521 .B \fBlong bpf_loop(u32\fP \fInr_loops\fP\fB, void *\fP\fIcallback_fn\fP\fB, void *\fP\fIcallback_ctx\fP\fB, u64\fP \fIflags\fP\fB)\fP
4522 .INDENT 7.0
4523 .TP
4524 .B Description
4525 For \fBnr_loops\fP, call \fBcallback_fn\fP function
4526 with \fBcallback_ctx\fP as the context parameter.
4527 The \fBcallback_fn\fP should be a static function and
4528 the \fBcallback_ctx\fP should be a pointer to the stack.
4529 The \fBflags\fP is used to control certain aspects of the helper.
4530 Currently, the \fBflags\fP must be 0. Currently, nr_loops is
4531 limited to 1 << 23 (~8 million) loops.
4532 .sp
4533 long (*callback_fn)(u64 index, void *ctx);
4534 .sp
4535 where \fBindex\fP is the current index in the loop. The index
4536 is zero\-indexed.
4537 .sp
4538 If \fBcallback_fn\fP returns 0, the helper will continue to the next
4539 loop. If return value is 1, the helper will skip the rest of
4540 the loops and return. Other return values are not used now,
4541 and will be rejected by the verifier.
4542 .TP
4543 .B Return
4544 The number of loops performed, \fB\-EINVAL\fP for invalid \fBflags\fP,
4545 \fB\-E2BIG\fP if \fBnr_loops\fP exceeds the maximum number of loops.
4546 .UNINDENT
4547 .TP
4548 .B \fBlong bpf_strncmp(const char *\fP\fIs1\fP\fB, u32\fP \fIs1_sz\fP\fB, const char *\fP\fIs2\fP\fB)\fP
4549 .INDENT 7.0
4550 .TP
4551 .B Description
4552 Do strncmp() between \fBs1\fP and \fBs2\fP\&. \fBs1\fP doesn\(aqt need
4553 to be null\-terminated and \fBs1_sz\fP is the maximum storage
4554 size of \fBs1\fP\&. \fBs2\fP must be a read\-only string.
4555 .TP
4556 .B Return
4557 An integer less than, equal to, or greater than zero
4558 if the first \fBs1_sz\fP bytes of \fBs1\fP is found to be
4559 less than, to match, or be greater than \fBs2\fP\&.
4560 .UNINDENT
4561 .TP
4562 .B \fBlong bpf_get_func_arg(void *\fP\fIctx\fP\fB, u32\fP \fIn\fP\fB, u64 *\fP\fIvalue\fP\fB)\fP
4563 .INDENT 7.0
4564 .TP
4565 .B Description
4566 Get \fBn\fP\-th argument register (zero based) of the traced function (for tracing programs)
4567 returned in \fBvalue\fP\&.
4568 .TP
4569 .B Return
4570 0 on success.
4571 \fB\-EINVAL\fP if n >= argument register count of traced function.
4572 .UNINDENT
4573 .TP
4574 .B \fBlong bpf_get_func_ret(void *\fP\fIctx\fP\fB, u64 *\fP\fIvalue\fP\fB)\fP
4575 .INDENT 7.0
4576 .TP
4577 .B Description
4578 Get return value of the traced function (for tracing programs)
4579 in \fBvalue\fP\&.
4580 .TP
4581 .B Return
4582 0 on success.
4583 \fB\-EOPNOTSUPP\fP for tracing programs other than BPF_TRACE_FEXIT or BPF_MODIFY_RETURN.
4584 .UNINDENT
4585 .TP
4586 .B \fBlong bpf_get_func_arg_cnt(void *\fP\fIctx\fP\fB)\fP
4587 .INDENT 7.0
4588 .TP
4589 .B Description
4590 Get number of registers of the traced function (for tracing programs) where
4591 function arguments are stored in these registers.
4592 .TP
4593 .B Return
4594 The number of argument registers of the traced function.
4595 .UNINDENT
4596 .TP
4597 .B \fBint bpf_get_retval(void)\fP
4598 .INDENT 7.0
4599 .TP
4600 .B Description
4601 Get the BPF program\(aqs return value that will be returned to the upper layers.
4602 .sp
4603 This helper is currently supported by cgroup programs and only by the hooks
4604 where BPF program\(aqs return value is returned to the userspace via errno.
4605 .TP
4606 .B Return
4607 The BPF program\(aqs return value.
4608 .UNINDENT
4609 .TP
4610 .B \fBint bpf_set_retval(int\fP \fIretval\fP\fB)\fP
4611 .INDENT 7.0
4612 .TP
4613 .B Description
4614 Set the BPF program\(aqs return value that will be returned to the upper layers.
4615 .sp
4616 This helper is currently supported by cgroup programs and only by the hooks
4617 where BPF program\(aqs return value is returned to the userspace via errno.
4618 .sp
4619 Note that there is the following corner case where the program exports an error
4620 via bpf_set_retval but signals success via \(aqreturn 1\(aq:
4621 .INDENT 7.0
4622 .INDENT 3.5
4623 bpf_set_retval(\-EPERM);
4624 return 1;
4625 .UNINDENT
4626 .UNINDENT
4627 .sp
4628 In this case, the BPF program\(aqs return value will use helper\(aqs \-EPERM. This
4629 still holds true for cgroup/bind{4,6} which supports extra \(aqreturn 3\(aq success case.
4630 .TP
4631 .B Return
4632 0 on success, or a negative error in case of failure.
4633 .UNINDENT
4634 .TP
4635 .B \fBu64 bpf_xdp_get_buff_len(struct xdp_buff *\fP\fIxdp_md\fP\fB)\fP
4636 .INDENT 7.0
4637 .TP
4638 .B Description
4639 Get the total size of a given xdp buff (linear and paged area)
4640 .TP
4641 .B Return
4642 The total size of a given xdp buffer.
4643 .UNINDENT
4644 .TP
4645 .B \fBlong bpf_xdp_load_bytes(struct xdp_buff *\fP\fIxdp_md\fP\fB, u32\fP \fIoffset\fP\fB, void *\fP\fIbuf\fP\fB, u32\fP \fIlen\fP\fB)\fP
4646 .INDENT 7.0
4647 .TP
4648 .B Description
4649 This helper is provided as an easy way to load data from a
4650 xdp buffer. It can be used to load \fIlen\fP bytes from \fIoffset\fP from
4651 the frame associated to \fIxdp_md\fP, into the buffer pointed by
4652 \fIbuf\fP\&.
4653 .TP
4654 .B Return
4655 0 on success, or a negative error in case of failure.
4656 .UNINDENT
4657 .TP
4658 .B \fBlong bpf_xdp_store_bytes(struct xdp_buff *\fP\fIxdp_md\fP\fB, u32\fP \fIoffset\fP\fB, void *\fP\fIbuf\fP\fB, u32\fP \fIlen\fP\fB)\fP
4659 .INDENT 7.0
4660 .TP
4661 .B Description
4662 Store \fIlen\fP bytes from buffer \fIbuf\fP into the frame
4663 associated to \fIxdp_md\fP, at \fIoffset\fP\&.
4664 .TP
4665 .B Return
4666 0 on success, or a negative error in case of failure.
4667 .UNINDENT
4668 .TP
4669 .B \fBlong bpf_copy_from_user_task(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIuser_ptr\fP\fB, struct task_struct *\fP\fItsk\fP\fB, u64\fP \fIflags\fP\fB)\fP
4670 .INDENT 7.0
4671 .TP
4672 .B Description
4673 Read \fIsize\fP bytes from user space address \fIuser_ptr\fP in \fItsk\fP\(aqs
4674 address space, and stores the data in \fIdst\fP\&. \fIflags\fP is not
4675 used yet and is provided for future extensibility. This helper
4676 can only be used by sleepable programs.
4677 .TP
4678 .B Return
4679 0 on success, or a negative error in case of failure. On error
4680 \fIdst\fP buffer is zeroed out.
4681 .UNINDENT
4682 .TP
4683 .B \fBlong bpf_skb_set_tstamp(struct sk_buff *\fP\fIskb\fP\fB, u64\fP \fItstamp\fP\fB, u32\fP \fItstamp_type\fP\fB)\fP
4684 .INDENT 7.0
4685 .TP
4686 .B Description
4687 Change the __sk_buff\->tstamp_type to \fItstamp_type\fP
4688 and set \fItstamp\fP to the __sk_buff\->tstamp together.
4689 .sp
4690 If there is no need to change the __sk_buff\->tstamp_type,
4691 the tstamp value can be directly written to __sk_buff\->tstamp
4692 instead.
4693 .sp
4694 BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that
4695 will be kept during bpf_redirect_*(). A non zero
4696 \fItstamp\fP must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO
4697 \fItstamp_type\fP\&.
4698 .sp
4699 A BPF_SKB_TSTAMP_UNSPEC \fItstamp_type\fP can only be used
4700 with a zero \fItstamp\fP\&.
4701 .sp
4702 Only IPv4 and IPv6 skb\->protocol are supported.
4703 .sp
4704 This function is most useful when it needs to set a
4705 mono delivery time to __sk_buff\->tstamp and then
4706 bpf_redirect_*() to the egress of an iface. For example,
4707 changing the (rcv) timestamp in __sk_buff\->tstamp at
4708 ingress to a mono delivery time and then bpf_redirect_*()
4709 to <sch_fq@phy\-dev> \&.
4710 .TP
4711 .B Return
4712 0 on success.
4713 \fB\-EINVAL\fP for invalid input
4714 \fB\-EOPNOTSUPP\fP for unsupported protocol
4715 .UNINDENT
4716 .TP
4717 .B \fBlong bpf_ima_file_hash(struct file *\fP\fIfile\fP\fB, void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB)\fP
4718 .INDENT 7.0
4719 .TP
4720 .B Description
4721 Returns a calculated IMA hash of the \fIfile\fP\&.
4722 If the hash is larger than \fIsize\fP, then only \fIsize\fP
4723 bytes will be copied to \fIdst\fP
4724 .TP
4725 .B Return
4726 The \fBhash_algo\fP is returned on success,
4727 \fB\-EOPNOTSUPP\fP if the hash calculation failed or \fB\-EINVAL\fP if
4728 invalid arguments are passed.
4729 .UNINDENT
4730 .TP
4731 .B \fBvoid *bpf_kptr_xchg(void *\fP\fIdst\fP\fB, void *\fP\fIptr\fP\fB)\fP
4732 .INDENT 7.0
4733 .TP
4734 .B Description
4735 Exchange kptr at pointer \fIdst\fP with \fIptr\fP, and return the old value.
4736 \fIdst\fP can be map value or local kptr. \fIptr\fP can be NULL, otherwise
4737 it must be a referenced pointer which will be released when this helper
4738 is called.
4739 .TP
4740 .B Return
4741 The old value of kptr (which can be NULL). The returned pointer
4742 if not NULL, is a reference which must be released using its
4743 corresponding release function, or moved into a BPF map before
4744 program exit.
4745 .UNINDENT
4746 .TP
4747 .B \fBvoid *bpf_map_lookup_percpu_elem(struct bpf_map *\fP\fImap\fP\fB, const void *\fP\fIkey\fP\fB, u32\fP \fIcpu\fP\fB)\fP
4748 .INDENT 7.0
4749 .TP
4750 .B Description
4751 Perform a lookup in \fIpercpu map\fP for an entry associated to
4752 \fIkey\fP on \fIcpu\fP\&.
4753 .TP
4754 .B Return
4755 Map value associated to \fIkey\fP on \fIcpu\fP, or \fBNULL\fP if no entry
4756 was found or \fIcpu\fP is invalid.
4757 .UNINDENT
4758 .TP
4759 .B \fBstruct mptcp_sock *bpf_skc_to_mptcp_sock(void *\fP\fIsk\fP\fB)\fP
4760 .INDENT 7.0
4761 .TP
4762 .B Description
4763 Dynamically cast a \fIsk\fP pointer to a \fImptcp_sock\fP pointer.
4764 .TP
4765 .B Return
4766 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
4767 .UNINDENT
4768 .TP
4769 .B \fBlong bpf_dynptr_from_mem(void *\fP\fIdata\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB, struct bpf_dynptr *\fP\fIptr\fP\fB)\fP
4770 .INDENT 7.0
4771 .TP
4772 .B Description
4773 Get a dynptr to local memory \fIdata\fP\&.
4774 .sp
4775 \fIdata\fP must be a ptr to a map value.
4776 The maximum \fIsize\fP supported is DYNPTR_MAX_SIZE.
4777 \fIflags\fP is currently unused.
4778 .TP
4779 .B Return
4780 0 on success, \-E2BIG if the size exceeds DYNPTR_MAX_SIZE,
4781 \-EINVAL if flags is not 0.
4782 .UNINDENT
4783 .TP
4784 .B \fBlong bpf_ringbuf_reserve_dynptr(void *\fP\fIringbuf\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB, struct bpf_dynptr *\fP\fIptr\fP\fB)\fP
4785 .INDENT 7.0
4786 .TP
4787 .B Description
4788 Reserve \fIsize\fP bytes of payload in a ring buffer \fIringbuf\fP
4789 through the dynptr interface. \fIflags\fP must be 0.
4790 .sp
4791 Please note that a corresponding bpf_ringbuf_submit_dynptr or
4792 bpf_ringbuf_discard_dynptr must be called on \fIptr\fP, even if the
4793 reservation fails. This is enforced by the verifier.
4794 .TP
4795 .B Return
4796 0 on success, or a negative error in case of failure.
4797 .UNINDENT
4798 .TP
4799 .B \fBvoid bpf_ringbuf_submit_dynptr(struct bpf_dynptr *\fP\fIptr\fP\fB, u64\fP \fIflags\fP\fB)\fP
4800 .INDENT 7.0
4801 .TP
4802 .B Description
4803 Submit reserved ring buffer sample, pointed to by \fIdata\fP,
4804 through the dynptr interface. This is a no\-op if the dynptr is
4805 invalid/null.
4806 .sp
4807 For more information on \fIflags\fP, please see
4808 \(aqbpf_ringbuf_submit\(aq.
4809 .TP
4810 .B Return
4811 Nothing. Always succeeds.
4812 .UNINDENT
4813 .TP
4814 .B \fBvoid bpf_ringbuf_discard_dynptr(struct bpf_dynptr *\fP\fIptr\fP\fB, u64\fP \fIflags\fP\fB)\fP
4815 .INDENT 7.0
4816 .TP
4817 .B Description
4818 Discard reserved ring buffer sample through the dynptr
4819 interface. This is a no\-op if the dynptr is invalid/null.
4820 .sp
4821 For more information on \fIflags\fP, please see
4822 \(aqbpf_ringbuf_discard\(aq.
4823 .TP
4824 .B Return
4825 Nothing. Always succeeds.
4826 .UNINDENT
4827 .TP
4828 .B \fBlong bpf_dynptr_read(void *\fP\fIdst\fP\fB, u32\fP \fIlen\fP\fB, const struct bpf_dynptr *\fP\fIsrc\fP\fB, u32\fP \fIoffset\fP\fB, u64\fP \fIflags\fP\fB)\fP
4829 .INDENT 7.0
4830 .TP
4831 .B Description
4832 Read \fIlen\fP bytes from \fIsrc\fP into \fIdst\fP, starting from \fIoffset\fP
4833 into \fIsrc\fP\&.
4834 \fIflags\fP is currently unused.
4835 .TP
4836 .B Return
4837 0 on success, \-E2BIG if \fIoffset\fP + \fIlen\fP exceeds the length
4838 of \fIsrc\fP\(aqs data, \-EINVAL if \fIsrc\fP is an invalid dynptr or if
4839 \fIflags\fP is not 0.
4840 .UNINDENT
4841 .TP
4842 .B \fBlong bpf_dynptr_write(const struct bpf_dynptr *\fP\fIdst\fP\fB, u32\fP \fIoffset\fP\fB, void *\fP\fIsrc\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
4843 .INDENT 7.0
4844 .TP
4845 .B Description
4846 Write \fIlen\fP bytes from \fIsrc\fP into \fIdst\fP, starting from \fIoffset\fP
4847 into \fIdst\fP\&.
4848 .sp
4849 \fIflags\fP must be 0 except for skb\-type dynptrs.
4850 .INDENT 7.0
4851 .TP
4852 .B For skb\-type dynptrs:
4853 .INDENT 7.0
4854 .IP \(bu 2
4855 All data slices of the dynptr are automatically
4856 invalidated after \fBbpf_dynptr_write\fP(). This is
4857 because writing may pull the skb and change the
4858 underlying packet buffer.
4859 .IP \(bu 2
4860 For \fIflags\fP, please see the flags accepted by
4861 \fBbpf_skb_store_bytes\fP().
4862 .UNINDENT
4863 .UNINDENT
4864 .TP
4865 .B Return
4866 0 on success, \-E2BIG if \fIoffset\fP + \fIlen\fP exceeds the length
4867 of \fIdst\fP\(aqs data, \-EINVAL if \fIdst\fP is an invalid dynptr or if \fIdst\fP
4868 is a read\-only dynptr or if \fIflags\fP is not correct. For skb\-type dynptrs,
4869 other errors correspond to errors returned by \fBbpf_skb_store_bytes\fP().
4870 .UNINDENT
4871 .TP
4872 .B \fBvoid *bpf_dynptr_data(const struct bpf_dynptr *\fP\fIptr\fP\fB, u32\fP \fIoffset\fP\fB, u32\fP \fIlen\fP\fB)\fP
4873 .INDENT 7.0
4874 .TP
4875 .B Description
4876 Get a pointer to the underlying dynptr data.
4877 .sp
4878 \fIlen\fP must be a statically known value. The returned data slice
4879 is invalidated whenever the dynptr is invalidated.
4880 .sp
4881 skb and xdp type dynptrs may not use bpf_dynptr_data. They should
4882 instead use bpf_dynptr_slice and bpf_dynptr_slice_rdwr.
4883 .TP
4884 .B Return
4885 Pointer to the underlying dynptr data, NULL if the dynptr is
4886 read\-only, if the dynptr is invalid, or if the offset and length
4887 is out of bounds.
4888 .UNINDENT
4889 .TP
4890 .B \fBs64 bpf_tcp_raw_gen_syncookie_ipv4(struct iphdr *\fP\fIiph\fP\fB, struct tcphdr *\fP\fIth\fP\fB, u32\fP \fIth_len\fP\fB)\fP
4891 .INDENT 7.0
4892 .TP
4893 .B Description
4894 Try to issue a SYN cookie for the packet with corresponding
4895 IPv4/TCP headers, \fIiph\fP and \fIth\fP, without depending on a
4896 listening socket.
4897 .sp
4898 \fIiph\fP points to the IPv4 header.
4899 .sp
4900 \fIth\fP points to the start of the TCP header, while \fIth_len\fP
4901 contains the length of the TCP header (at least
4902 \fBsizeof\fP(\fBstruct tcphdr\fP)).
4903 .TP
4904 .B Return
4905 On success, lower 32 bits hold the generated SYN cookie in
4906 followed by 16 bits which hold the MSS value for that cookie,
4907 and the top 16 bits are unused.
4908 .sp
4909 On failure, the returned value is one of the following:
4910 .sp
4911 \fB\-EINVAL\fP if \fIth_len\fP is invalid.
4912 .UNINDENT
4913 .TP
4914 .B \fBs64 bpf_tcp_raw_gen_syncookie_ipv6(struct ipv6hdr *\fP\fIiph\fP\fB, struct tcphdr *\fP\fIth\fP\fB, u32\fP \fIth_len\fP\fB)\fP
4915 .INDENT 7.0
4916 .TP
4917 .B Description
4918 Try to issue a SYN cookie for the packet with corresponding
4919 IPv6/TCP headers, \fIiph\fP and \fIth\fP, without depending on a
4920 listening socket.
4921 .sp
4922 \fIiph\fP points to the IPv6 header.
4923 .sp
4924 \fIth\fP points to the start of the TCP header, while \fIth_len\fP
4925 contains the length of the TCP header (at least
4926 \fBsizeof\fP(\fBstruct tcphdr\fP)).
4927 .TP
4928 .B Return
4929 On success, lower 32 bits hold the generated SYN cookie in
4930 followed by 16 bits which hold the MSS value for that cookie,
4931 and the top 16 bits are unused.
4932 .sp
4933 On failure, the returned value is one of the following:
4934 .sp
4935 \fB\-EINVAL\fP if \fIth_len\fP is invalid.
4936 .sp
4937 \fB\-EPROTONOSUPPORT\fP if CONFIG_IPV6 is not builtin.
4938 .UNINDENT
4939 .TP
4940 .B \fBlong bpf_tcp_raw_check_syncookie_ipv4(struct iphdr *\fP\fIiph\fP\fB, struct tcphdr *\fP\fIth\fP\fB)\fP
4941 .INDENT 7.0
4942 .TP
4943 .B Description
4944 Check whether \fIiph\fP and \fIth\fP contain a valid SYN cookie ACK
4945 without depending on a listening socket.
4946 .sp
4947 \fIiph\fP points to the IPv4 header.
4948 .sp
4949 \fIth\fP points to the TCP header.
4950 .TP
4951 .B Return
4952 0 if \fIiph\fP and \fIth\fP are a valid SYN cookie ACK.
4953 .sp
4954 On failure, the returned value is one of the following:
4955 .sp
4956 \fB\-EACCES\fP if the SYN cookie is not valid.
4957 .UNINDENT
4958 .TP
4959 .B \fBlong bpf_tcp_raw_check_syncookie_ipv6(struct ipv6hdr *\fP\fIiph\fP\fB, struct tcphdr *\fP\fIth\fP\fB)\fP
4960 .INDENT 7.0
4961 .TP
4962 .B Description
4963 Check whether \fIiph\fP and \fIth\fP contain a valid SYN cookie ACK
4964 without depending on a listening socket.
4965 .sp
4966 \fIiph\fP points to the IPv6 header.
4967 .sp
4968 \fIth\fP points to the TCP header.
4969 .TP
4970 .B Return
4971 0 if \fIiph\fP and \fIth\fP are a valid SYN cookie ACK.
4972 .sp
4973 On failure, the returned value is one of the following:
4974 .sp
4975 \fB\-EACCES\fP if the SYN cookie is not valid.
4976 .sp
4977 \fB\-EPROTONOSUPPORT\fP if CONFIG_IPV6 is not builtin.
4978 .UNINDENT
4979 .TP
4980 .B \fBu64 bpf_ktime_get_tai_ns(void)\fP
4981 .INDENT 7.0
4982 .TP
4983 .B Description
4984 A nonsettable system\-wide clock derived from wall\-clock time but
4985 ignoring leap seconds. This clock does not experience
4986 discontinuities and backwards jumps caused by NTP inserting leap
4987 seconds as CLOCK_REALTIME does.
4988 .sp
4989 See: \fBclock_gettime\fP(\fBCLOCK_TAI\fP)
4990 .TP
4991 .B Return
4992 Current \fIktime\fP\&.
4993 .UNINDENT
4994 .TP
4995 .B \fBlong bpf_user_ringbuf_drain(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIcallback_fn\fP\fB, void *\fP\fIctx\fP\fB, u64\fP \fIflags\fP\fB)\fP
4996 .INDENT 7.0
4997 .TP
4998 .B Description
4999 Drain samples from the specified user ring buffer, and invoke
5000 the provided callback for each such sample:
5001 .sp
5002 long (*callback_fn)(const struct bpf_dynptr *dynptr, void *ctx);
5003 .sp
5004 If \fBcallback_fn\fP returns 0, the helper will continue to try
5005 and drain the next sample, up to a maximum of
5006 BPF_MAX_USER_RINGBUF_SAMPLES samples. If the return value is 1,
5007 the helper will skip the rest of the samples and return. Other
5008 return values are not used now, and will be rejected by the
5009 verifier.
5010 .TP
5011 .B Return
5012 The number of drained samples if no error was encountered while
5013 draining samples, or 0 if no samples were present in the ring
5014 buffer. If a user\-space producer was epoll\-waiting on this map,
5015 and at least one sample was drained, they will receive an event
5016 notification notifying them of available space in the ring
5017 buffer. If the BPF_RB_NO_WAKEUP flag is passed to this
5018 function, no wakeup notification will be sent. If the
5019 BPF_RB_FORCE_WAKEUP flag is passed, a wakeup notification will
5020 be sent even if no sample was drained.
5021 .sp
5022 On failure, the returned value is one of the following:
5023 .sp
5024 \fB\-EBUSY\fP if the ring buffer is contended, and another calling
5025 context was concurrently draining the ring buffer.
5026 .sp
5027 \fB\-EINVAL\fP if user\-space is not properly tracking the ring
5028 buffer due to the producer position not being aligned to 8
5029 bytes, a sample not being aligned to 8 bytes, or the producer
5030 position not matching the advertised length of a sample.
5031 .sp
5032 \fB\-E2BIG\fP if user\-space has tried to publish a sample which is
5033 larger than the size of the ring buffer, or which cannot fit
5034 within a struct bpf_dynptr.
5035 .UNINDENT
5036 .TP
5037 .B \fBvoid *bpf_cgrp_storage_get(struct bpf_map *\fP\fImap\fP\fB, struct cgroup *\fP\fIcgroup\fP\fB, void *\fP\fIvalue\fP\fB, u64\fP \fIflags\fP\fB)\fP
5038 .INDENT 7.0
5039 .TP
5040 .B Description
5041 Get a bpf_local_storage from the \fIcgroup\fP\&.
5042 .sp
5043 Logically, it could be thought of as getting the value from
5044 a \fImap\fP with \fIcgroup\fP as the \fBkey\fP\&. From this
5045 perspective, the usage is not much different from
5046 \fBbpf_map_lookup_elem\fP(\fImap\fP, \fB&\fP\fIcgroup\fP) except this
5047 helper enforces the key must be a cgroup struct and the map must also
5048 be a \fBBPF_MAP_TYPE_CGRP_STORAGE\fP\&.
5049 .sp
5050 In reality, the local\-storage value is embedded directly inside of the
5051 \fIcgroup\fP object itself, rather than being located in the
5052 \fBBPF_MAP_TYPE_CGRP_STORAGE\fP map. When the local\-storage value is
5053 queried for some \fImap\fP on a \fIcgroup\fP object, the kernel will perform an
5054 O(n) iteration over all of the live local\-storage values for that
5055 \fIcgroup\fP object until the local\-storage value for the \fImap\fP is found.
5056 .sp
5057 An optional \fIflags\fP (\fBBPF_LOCAL_STORAGE_GET_F_CREATE\fP) can be
5058 used such that a new bpf_local_storage will be
5059 created if one does not exist. \fIvalue\fP can be used
5060 together with \fBBPF_LOCAL_STORAGE_GET_F_CREATE\fP to specify
5061 the initial value of a bpf_local_storage. If \fIvalue\fP is
5062 \fBNULL\fP, the new bpf_local_storage will be zero initialized.
5063 .TP
5064 .B Return
5065 A bpf_local_storage pointer is returned on success.
5066 .sp
5067 \fBNULL\fP if not found or there was an error in adding
5068 a new bpf_local_storage.
5069 .UNINDENT
5070 .TP
5071 .B \fBlong bpf_cgrp_storage_delete(struct bpf_map *\fP\fImap\fP\fB, struct cgroup *\fP\fIcgroup\fP\fB)\fP
5072 .INDENT 7.0
5073 .TP
5074 .B Description
5075 Delete a bpf_local_storage from a \fIcgroup\fP\&.
5076 .TP
5077 .B Return
5078 0 on success.
5079 .sp
5080 \fB\-ENOENT\fP if the bpf_local_storage cannot be found.
5081 .UNINDENT
5082 .UNINDENT
5083 .SH EXAMPLES
5084 .sp
5085 Example usage for most of the eBPF helpers listed in this manual page are
5086 available within the Linux kernel sources, at the following locations:
5087 .INDENT 0.0
5088 .IP \(bu 2
5089 \fIsamples/bpf/\fP
5090 .IP \(bu 2
5091 \fItools/testing/selftests/bpf/\fP
5092 .UNINDENT
5093 .SH LICENSE
5094 .sp
5095 eBPF programs can have an associated license, passed along with the bytecode
5096 instructions to the kernel when the programs are loaded. The format for that
5097 string is identical to the one in use for kernel modules (Dual licenses, such
5098 as \(dqDual BSD/GPL\(dq, may be used). Some helper functions are only accessible to
5099 programs that are compatible with the GNU General Public License (GNU GPL).
5100 .sp
5101 In order to use such helpers, the eBPF program must be loaded with the correct
5102 license string passed (via \fBattr\fP) to the \fBbpf\fP() system call, and this
5103 generally translates into the C source code of the program containing a line
5104 similar to the following:
5105 .INDENT 0.0
5106 .INDENT 3.5
5107 .sp
5108 .EX
5109 char ____license[] __attribute__((section(\(dqlicense\(dq), used)) = \(dqGPL\(dq;
5110 .EE
5111 .UNINDENT
5112 .UNINDENT
5113 .SH IMPLEMENTATION
5114 .sp
5115 This manual page is an effort to document the existing eBPF helper functions.
5116 But as of this writing, the BPF sub\-system is under heavy development. New eBPF
5117 program or map types are added, along with new helper functions. Some helpers
5118 are occasionally made available for additional program types. So in spite of
5119 the efforts of the community, this page might not be up\-to\-date. If you want to
5120 check by yourself what helper functions exist in your kernel, or what types of
5121 programs they can support, here are some files among the kernel tree that you
5122 may be interested in:
5123 .INDENT 0.0
5124 .IP \(bu 2
5125 \fIinclude/uapi/linux/bpf.h\fP is the main BPF header. It contains the full list
5126 of all helper functions, as well as many other BPF definitions including most
5127 of the flags, structs or constants used by the helpers.
5128 .IP \(bu 2
5129 \fInet/core/filter.c\fP contains the definition of most network\-related helper
5130 functions, and the list of program types from which they can be used.
5131 .IP \(bu 2
5132 \fIkernel/trace/bpf_trace.c\fP is the equivalent for most tracing program\-related
5133 helpers.
5134 .IP \(bu 2
5135 \fIkernel/bpf/verifier.c\fP contains the functions used to check that valid types
5136 of eBPF maps are used with a given helper function.
5137 .IP \(bu 2
5138 \fIkernel/bpf/\fP directory contains other files in which additional helpers are
5139 defined (for cgroups, sockmaps, etc.).
5140 .IP \(bu 2
5141 The bpftool utility can be used to probe the availability of helper functions
5142 on the system (as well as supported program and map types, and a number of
5143 other parameters). To do so, run \fBbpftool feature probe\fP (see
5144 \fBbpftool\-feature\fP(8) for details). Add the \fBunprivileged\fP keyword to
5145 list features available to unprivileged users.
5146 .UNINDENT
5147 .sp
5148 Compatibility between helper functions and program types can generally be found
5149 in the files where helper functions are defined. Look for the \fBstruct
5150 bpf_func_proto\fP objects and for functions returning them: these functions
5151 contain a list of helpers that a given program type can call. Note that the
5152 \fBdefault:\fP label of the \fBswitch ... case\fP used to filter helpers can call
5153 other functions, themselves allowing access to additional helpers. The
5154 requirement for GPL license is also in those \fBstruct bpf_func_proto\fP\&.
5155 .sp
5156 Compatibility between helper functions and map types can be found in the
5157 \fBcheck_map_func_compatibility\fP() function in file \fIkernel/bpf/verifier.c\fP\&.
5158 .sp
5159 Helper functions that invalidate the checks on \fBdata\fP and \fBdata_end\fP
5160 pointers for network processing are listed in function
5161 \fBbpf_helper_changes_pkt_data\fP() in file \fInet/core/filter.c\fP\&.
5162 .SH SEE ALSO
5163 .sp
5164 \fBbpf\fP(2),
5165 \fBbpftool\fP(8),
5166 \fBcgroups\fP(7),
5167 \fBip\fP(8),
5168 \fBperf_event_open\fP(2),
5169 \fBsendmsg\fP(2),
5170 \fBsocket\fP(7),
5171 \fBtc\-bpf\fP(8)
5172 .\" Generated by docutils manpage writer.
5173 .