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