1 .\" Man page generated from reStructuredText.
4 .nr rst2man-indent-level 0
8 level \\n[rst2man-indent-level]
9 level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
16 .\" .rstReportMargin pre:
18 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
19 . nr rst2man-indent-level +1
20 .\" .rstReportMargin post:
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 "2022-09-26" "Linux v6.1"
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.
39 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
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).
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, \[dq]classic\[dq] BPF (or \[dq]cBPF\[dq]) in several aspects, one of them being
57 the ability to call special functions (or \[dq]helpers\[dq]) from within a program.
58 These functions are restricted to a white\-list of helpers defined in the
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.
68 Due to eBPF conventions, a helper can not have more than five arguments.
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.
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
80 .B \fBvoid *bpf_map_lookup_elem(struct bpf_map *\fP\fImap\fP\fB, const void *\fP\fIkey\fP\fB)\fP
84 Perform a lookup in \fImap\fP for an entry associated to \fIkey\fP\&.
87 Map value associated to \fIkey\fP, or \fBNULL\fP if no entry was
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
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:
100 The entry for \fIkey\fP must not exist in the map.
103 The entry for \fIkey\fP must already exist in the map.
106 No condition on the existence of the entry for \fIkey\fP\&.
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.
114 0 on success, or a negative error in case of failure.
117 .B \fBlong bpf_map_delete_elem(struct bpf_map *\fP\fImap\fP\fB, const void *\fP\fIkey\fP\fB)\fP
121 Delete entry with \fIkey\fP from \fImap\fP\&.
124 0 on success, or a negative error in case of failure.
127 .B \fBlong bpf_probe_read(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
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.
138 0 on success, or a negative error in case of failure.
141 .B \fBu64 bpf_ktime_get_ns(void)\fP
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)
150 Current \fIktime\fP\&.
153 .B \fBlong bpf_trace_printk(const char *\fP\fIfmt\fP\fB, u32\fP \fIfmt_size\fP\fB, ...)\fP
157 This helper is a \[dq]printk()\-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
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:
177 telnet\-470 [001] .N.. 419421.045894: 0x00000001: <formatted msg>
188 \fBtelnet\fP is the name of the current task.
190 \fB470\fP is the PID of the current task.
192 \fB001\fP is the CPU number on which the task is
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
202 \fB419421.045894\fP is a timestamp.
204 \fB0x00000001\fP is a fake value used by BPF for the
205 instruction pointer register.
207 \fB<formatted msg>\fP is the message formatted with
213 The conversion specifiers supported by \fIfmt\fP are similar, but
214 more limited than for printk(). They are \fB%d\fP, \fB%i\fP,
215 \fB%u\fP, \fB%x\fP, \fB%ld\fP, \fB%li\fP, \fB%lu\fP, \fB%lx\fP, \fB%lld\fP,
216 \fB%lli\fP, \fB%llu\fP, \fB%llx\fP, \fB%p\fP, \fB%s\fP\&. No modifier (size
217 of field, padding with zeroes, etc.) is available, and the
218 helper will return \fB\-EINVAL\fP (but print nothing) if it
219 encounters an unknown specifier.
221 Also, note that \fBbpf_trace_printk\fP() is slow, and should
222 only be used for debugging purposes. For this reason, a notice
223 block (spanning several lines) is printed to kernel logs and
224 states that the helper should not be used \[dq]for production use\[dq]
225 the first time this helper is used (or more precisely, when
226 \fBtrace_printk\fP() buffers are allocated). For passing values
227 to user space, perf events should be preferred.
230 The number of bytes written to the buffer, or a negative error
234 .B \fBu32 bpf_get_prandom_u32(void)\fP
238 Get a pseudo\-random number.
240 From a security point of view, this helper uses its own
241 pseudo\-random internal state, and cannot be used to infer the
242 seed of other random functions in the kernel. However, it is
243 essential to note that the generator used by the helper is not
244 cryptographically secure.
247 A random 32\-bit unsigned value.
250 .B \fBu32 bpf_get_smp_processor_id(void)\fP
254 Get the SMP (symmetric multiprocessing) processor id. Note that
255 all programs run with migration disabled, which means that the
256 SMP processor id is stable during all the execution of the
260 The SMP id of the processor running the program.
263 .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
267 Store \fIlen\fP bytes from address \fIfrom\fP into the packet
268 associated to \fIskb\fP, at \fIoffset\fP\&. \fIflags\fP are a combination of
269 \fBBPF_F_RECOMPUTE_CSUM\fP (automatically recompute the
270 checksum for the packet after storing the bytes) and
271 \fBBPF_F_INVALIDATE_HASH\fP (set \fIskb\fP\fB\->hash\fP, \fIskb\fP\fB\->swhash\fP and \fIskb\fP\fB\->l4hash\fP to 0).
273 A call to this helper is susceptible to change the underlying
274 packet buffer. Therefore, at load time, all checks on pointers
275 previously done by the verifier are invalidated and must be
276 performed again, if the helper is used in combination with
277 direct packet access.
280 0 on success, or a negative error in case of failure.
283 .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
287 Recompute the layer 3 (e.g. IP) checksum for the packet
288 associated to \fIskb\fP\&. Computation is incremental, so the helper
289 must know the former value of the header field that was
290 modified (\fIfrom\fP), the new value of this field (\fIto\fP), and the
291 number of bytes (2 or 4) for this field, stored in \fIsize\fP\&.
292 Alternatively, it is possible to store the difference between
293 the previous and the new values of the header field in \fIto\fP, by
294 setting \fIfrom\fP and \fIsize\fP to 0. For both methods, \fIoffset\fP
295 indicates the location of the IP checksum within the packet.
297 This helper works in combination with \fBbpf_csum_diff\fP(),
298 which does not update the checksum in\-place, but offers more
299 flexibility and can handle sizes larger than 2 or 4 for the
302 A call to this helper is susceptible to change the underlying
303 packet buffer. Therefore, at load time, all checks on pointers
304 previously done by the verifier are invalidated and must be
305 performed again, if the helper is used in combination with
306 direct packet access.
309 0 on success, or a negative error in case of failure.
312 .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
316 Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
317 packet associated to \fIskb\fP\&. Computation is incremental, so the
318 helper must know the former value of the header field that was
319 modified (\fIfrom\fP), the new value of this field (\fIto\fP), and the
320 number of bytes (2 or 4) for this field, stored on the lowest
321 four bits of \fIflags\fP\&. Alternatively, it is possible to store
322 the difference between the previous and the new values of the
323 header field in \fIto\fP, by setting \fIfrom\fP and the four lowest
324 bits of \fIflags\fP to 0. For both methods, \fIoffset\fP indicates the
325 location of the IP checksum within the packet. In addition to
326 the size of the field, \fIflags\fP can be added (bitwise OR) actual
327 flags. With \fBBPF_F_MARK_MANGLED_0\fP, a null checksum is left
328 untouched (unless \fBBPF_F_MARK_ENFORCE\fP is added as well), and
329 for updates resulting in a null checksum the value is set to
330 \fBCSUM_MANGLED_0\fP instead. Flag \fBBPF_F_PSEUDO_HDR\fP indicates
331 the checksum is to be computed against a pseudo\-header.
333 This helper works in combination with \fBbpf_csum_diff\fP(),
334 which does not update the checksum in\-place, but offers more
335 flexibility and can handle sizes larger than 2 or 4 for the
338 A call to this helper is susceptible to change the underlying
339 packet buffer. Therefore, at load time, all checks on pointers
340 previously done by the verifier are invalidated and must be
341 performed again, if the helper is used in combination with
342 direct packet access.
345 0 on success, or a negative error in case of failure.
348 .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
352 This special helper is used to trigger a \[dq]tail call\[dq], or in
353 other words, to jump into another eBPF program. The same stack
354 frame is used (but values on stack and in registers for the
355 caller are not accessible to the callee). This mechanism allows
356 for program chaining, either for raising the maximum number of
357 available eBPF instructions, or to execute given programs in
358 conditional blocks. For security reasons, there is an upper
359 limit to the number of successive tail calls that can be
362 Upon call of this helper, the program attempts to jump into a
363 program referenced at index \fIindex\fP in \fIprog_array_map\fP, a
364 special map of type \fBBPF_MAP_TYPE_PROG_ARRAY\fP, and passes
365 \fIctx\fP, a pointer to the context.
367 If the call succeeds, the kernel immediately runs the first
368 instruction of the new program. This is not a function call,
369 and it never returns to the previous program. If the call
370 fails, then the helper has no effect, and the caller continues
371 to run its subsequent instructions. A call can fail if the
372 destination program for the jump does not exist (i.e. \fIindex\fP
373 is superior to the number of entries in \fIprog_array_map\fP), or
374 if the maximum number of tail calls has been reached for this
375 chain of programs. This limit is defined in the kernel by the
376 macro \fBMAX_TAIL_CALL_CNT\fP (not accessible to user space),
377 which is currently set to 33.
380 0 on success, or a negative error in case of failure.
383 .B \fBlong bpf_clone_redirect(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIifindex\fP\fB, u64\fP \fIflags\fP\fB)\fP
387 Clone and redirect the packet associated to \fIskb\fP to another
388 net device of index \fIifindex\fP\&. Both ingress and egress
389 interfaces can be used for redirection. The \fBBPF_F_INGRESS\fP
390 value in \fIflags\fP is used to make the distinction (ingress path
391 is selected if the flag is present, egress path otherwise).
392 This is the only flag supported for now.
394 In comparison with \fBbpf_redirect\fP() helper,
395 \fBbpf_clone_redirect\fP() has the associated cost of
396 duplicating the packet buffer, but this can be executed out of
397 the eBPF program. Conversely, \fBbpf_redirect\fP() is more
398 efficient, but it is handled through an action code where the
399 redirection happens only after the eBPF program has returned.
401 A call to this helper is susceptible to change the underlying
402 packet buffer. Therefore, at load time, all checks on pointers
403 previously done by the verifier are invalidated and must be
404 performed again, if the helper is used in combination with
405 direct packet access.
408 0 on success, or a negative error in case of failure.
411 .B \fBu64 bpf_get_current_pid_tgid(void)\fP
415 Get the current pid and tgid.
418 A 64\-bit integer containing the current tgid and pid, and
420 \fIcurrent_task\fP\fB\->tgid << 32 |\fP
421 \fIcurrent_task\fP\fB\->pid\fP\&.
424 .B \fBu64 bpf_get_current_uid_gid(void)\fP
428 Get the current uid and gid.
431 A 64\-bit integer containing the current GID and UID, and
432 created as such: \fIcurrent_gid\fP \fB<< 32 |\fP \fIcurrent_uid\fP\&.
435 .B \fBlong bpf_get_current_comm(void *\fP\fIbuf\fP\fB, u32\fP \fIsize_of_buf\fP\fB)\fP
439 Copy the \fBcomm\fP attribute of the current task into \fIbuf\fP of
440 \fIsize_of_buf\fP\&. The \fBcomm\fP attribute contains the name of
441 the executable (excluding the path) for the current task. The
442 \fIsize_of_buf\fP must be strictly positive. On success, the
443 helper makes sure that the \fIbuf\fP is NUL\-terminated. On failure,
444 it is filled with zeroes.
447 0 on success, or a negative error in case of failure.
450 .B \fBu32 bpf_get_cgroup_classid(struct sk_buff *\fP\fIskb\fP\fB)\fP
454 Retrieve the classid for the current task, i.e. for the net_cls
455 cgroup to which \fIskb\fP belongs.
457 This helper can be used on TC egress path, but not on ingress.
459 The net_cls cgroup provides an interface to tag network packets
460 based on a user\-provided identifier for all traffic coming from
461 the tasks belonging to the related cgroup. See also the related
462 kernel documentation, available from the Linux sources in file
463 \fIDocumentation/admin\-guide/cgroup\-v1/net_cls.rst\fP\&.
465 The Linux kernel has two versions for cgroups: there are
466 cgroups v1 and cgroups v2. Both are available to users, who can
467 use a mixture of them, but note that the net_cls cgroup is for
468 cgroup v1 only. This makes it incompatible with BPF programs
469 run on cgroups, which is a cgroup\-v2\-only feature (a socket can
470 only hold data for one version of cgroups at a time).
472 This helper is only available is the kernel was compiled with
473 the \fBCONFIG_CGROUP_NET_CLASSID\fP configuration option set to
474 \[dq]\fBy\fP\[dq] or to \[dq]\fBm\fP\[dq].
477 The classid, or 0 for the default unconfigured classid.
480 .B \fBlong bpf_skb_vlan_push(struct sk_buff *\fP\fIskb\fP\fB, __be16\fP \fIvlan_proto\fP\fB, u16\fP \fIvlan_tci\fP\fB)\fP
484 Push a \fIvlan_tci\fP (VLAN tag control information) of protocol
485 \fIvlan_proto\fP to the packet associated to \fIskb\fP, then update
486 the checksum. Note that if \fIvlan_proto\fP is different from
487 \fBETH_P_8021Q\fP and \fBETH_P_8021AD\fP, it is considered to
488 be \fBETH_P_8021Q\fP\&.
490 A call to this helper is susceptible to change the underlying
491 packet buffer. Therefore, at load time, all checks on pointers
492 previously done by the verifier are invalidated and must be
493 performed again, if the helper is used in combination with
494 direct packet access.
497 0 on success, or a negative error in case of failure.
500 .B \fBlong bpf_skb_vlan_pop(struct sk_buff *\fP\fIskb\fP\fB)\fP
504 Pop a VLAN header from the packet associated to \fIskb\fP\&.
506 A call to this helper is susceptible to change the underlying
507 packet buffer. Therefore, at load time, all checks on pointers
508 previously done by the verifier are invalidated and must be
509 performed again, if the helper is used in combination with
510 direct packet access.
513 0 on success, or a negative error in case of failure.
516 .B \fBlong bpf_skb_get_tunnel_key(struct sk_buff *\fP\fIskb\fP\fB, struct bpf_tunnel_key *\fP\fIkey\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
520 Get tunnel metadata. This helper takes a pointer \fIkey\fP to an
521 empty \fBstruct bpf_tunnel_key\fP of \fBsize\fP, that will be
522 filled with tunnel metadata for the packet associated to \fIskb\fP\&.
523 The \fIflags\fP can be set to \fBBPF_F_TUNINFO_IPV6\fP, which
524 indicates that the tunnel is based on IPv6 protocol instead of
527 The \fBstruct bpf_tunnel_key\fP is an object that generalizes the
528 principal parameters used by various tunneling protocols into a
529 single struct. This way, it can be used to easily make a
530 decision based on the contents of the encapsulation header,
531 \[dq]summarized\[dq] in this struct. In particular, it holds the IP
532 address of the remote end (IPv4 or IPv6, depending on the case)
533 in \fIkey\fP\fB\->remote_ipv4\fP or \fIkey\fP\fB\->remote_ipv6\fP\&. Also,
534 this struct exposes the \fIkey\fP\fB\->tunnel_id\fP, which is
535 generally mapped to a VNI (Virtual Network Identifier), making
536 it programmable together with the \fBbpf_skb_set_tunnel_key\fP() helper.
538 Let\[aq]s imagine that the following code is part of a program
539 attached to the TC ingress interface, on one end of a GRE
540 tunnel, and is supposed to filter out all messages coming from
541 remote ends with IPv4 address other than 10.0.0.1:
548 struct bpf_tunnel_key key = {};
550 ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
552 return TC_ACT_SHOT; // drop packet
554 if (key.remote_ipv4 != 0x0a000001)
555 return TC_ACT_SHOT; // drop packet
557 return TC_ACT_OK; // accept packet
563 This interface can also be used with all encapsulation devices
564 that can operate in \[dq]collect metadata\[dq] mode: instead of having
565 one network device per specific configuration, the \[dq]collect
566 metadata\[dq] mode only requires a single device where the
567 configuration can be extracted from this helper.
569 This can be used together with various tunnels such as VXLan,
570 Geneve, GRE or IP in IP (IPIP).
573 0 on success, or a negative error in case of failure.
576 .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
580 Populate tunnel metadata for packet associated to \fIskb.\fP The
581 tunnel metadata is set to the contents of \fIkey\fP, of \fIsize\fP\&. The
582 \fIflags\fP can be set to a combination of the following values:
585 .B \fBBPF_F_TUNINFO_IPV6\fP
586 Indicate that the tunnel is based on IPv6 protocol
589 .B \fBBPF_F_ZERO_CSUM_TX\fP
590 For IPv4 packets, add a flag to tunnel metadata
591 indicating that checksum computation should be skipped
592 and checksum set to zeroes.
594 .B \fBBPF_F_DONT_FRAGMENT\fP
595 Add a flag to tunnel metadata indicating that the
596 packet should not be fragmented.
598 .B \fBBPF_F_SEQ_NUMBER\fP
599 Add a flag to tunnel metadata indicating that a
600 sequence number should be added to tunnel header before
601 sending the packet. This flag was added for GRE
602 encapsulation, but might be used with other protocols
603 as well in the future.
606 Here is a typical usage on the transmit path:
612 struct bpf_tunnel_key key;
614 bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
615 bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
621 See also the description of the \fBbpf_skb_get_tunnel_key\fP()
622 helper for additional information.
625 0 on success, or a negative error in case of failure.
628 .B \fBu64 bpf_perf_event_read(struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB)\fP
632 Read the value of a perf event counter. This helper relies on a
633 \fImap\fP of type \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. The nature of
634 the perf event counter is selected when \fImap\fP is updated with
635 perf event file descriptors. The \fImap\fP is an array whose size
636 is the number of available CPUs, and each cell contains a value
637 relative to one CPU. The value to retrieve is indicated by
638 \fIflags\fP, that contains the index of the CPU to look up, masked
639 with \fBBPF_F_INDEX_MASK\fP\&. Alternatively, \fIflags\fP can be set to
640 \fBBPF_F_CURRENT_CPU\fP to indicate that the value for the
641 current CPU should be retrieved.
643 Note that before Linux 4.13, only hardware perf event can be
646 Also, be aware that the newer helper
647 \fBbpf_perf_event_read_value\fP() is recommended over
648 \fBbpf_perf_event_read\fP() in general. The latter has some ABI
649 quirks where error and counter value are used as a return code
650 (which is wrong to do since ranges may overlap). This issue is
651 fixed with \fBbpf_perf_event_read_value\fP(), which at the same
652 time provides more features over the \fBbpf_perf_event_read\fP() interface. Please refer to the description of
653 \fBbpf_perf_event_read_value\fP() for details.
656 The value of the perf event counter read from the map, or a
657 negative error code in case of failure.
660 .B \fBlong bpf_redirect(u32\fP \fIifindex\fP\fB, u64\fP \fIflags\fP\fB)\fP
664 Redirect the packet to another net device of index \fIifindex\fP\&.
665 This helper is somewhat similar to \fBbpf_clone_redirect\fP(), except that the packet is not cloned, which provides
666 increased performance.
668 Except for XDP, both ingress and egress interfaces can be used
669 for redirection. The \fBBPF_F_INGRESS\fP value in \fIflags\fP is used
670 to make the distinction (ingress path is selected if the flag
671 is present, egress path otherwise). Currently, XDP only
672 supports redirection to the egress interface, and accepts no
675 The same effect can also be attained with the more generic
676 \fBbpf_redirect_map\fP(), which uses a BPF map to store the
677 redirect target instead of providing it directly to the helper.
680 For XDP, the helper returns \fBXDP_REDIRECT\fP on success or
681 \fBXDP_ABORTED\fP on error. For other program types, the values
682 are \fBTC_ACT_REDIRECT\fP on success or \fBTC_ACT_SHOT\fP on
686 .B \fBu32 bpf_get_route_realm(struct sk_buff *\fP\fIskb\fP\fB)\fP
690 Retrieve the realm or the route, that is to say the
691 \fBtclassid\fP field of the destination for the \fIskb\fP\&. The
692 identifier retrieved is a user\-provided tag, similar to the
693 one used with the net_cls cgroup (see description for
694 \fBbpf_get_cgroup_classid\fP() helper), but here this tag is
695 held by a route (a destination entry), not by a task.
697 Retrieving this identifier works with the clsact TC egress hook
698 (see also \fBtc\-bpf(8)\fP), or alternatively on conventional
699 classful egress qdiscs, but not on TC ingress path. In case of
700 clsact TC egress hook, this has the advantage that, internally,
701 the destination entry has not been dropped yet in the transmit
702 path. Therefore, the destination entry does not need to be
703 artificially held via \fBnetif_keep_dst\fP() for a classful
704 qdisc until the \fIskb\fP is freed.
706 This helper is available only if the kernel was compiled with
707 \fBCONFIG_IP_ROUTE_CLASSID\fP configuration option.
710 The realm of the route for the packet associated to \fIskb\fP, or 0
714 .B \fBlong bpf_perf_event_output(void *\fP\fIctx\fP\fB, struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB, void *\fP\fIdata\fP\fB, u64\fP \fIsize\fP\fB)\fP
718 Write raw \fIdata\fP blob into a special BPF perf event held by
719 \fImap\fP of type \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. This perf
720 event must have the following attributes: \fBPERF_SAMPLE_RAW\fP
721 as \fBsample_type\fP, \fBPERF_TYPE_SOFTWARE\fP as \fBtype\fP, and
722 \fBPERF_COUNT_SW_BPF_OUTPUT\fP as \fBconfig\fP\&.
724 The \fIflags\fP are used to indicate the index in \fImap\fP for which
725 the value must be put, masked with \fBBPF_F_INDEX_MASK\fP\&.
726 Alternatively, \fIflags\fP can be set to \fBBPF_F_CURRENT_CPU\fP
727 to indicate that the index of the current CPU core should be
730 The value to write, of \fIsize\fP, is passed through eBPF stack and
731 pointed by \fIdata\fP\&.
733 The context of the program \fIctx\fP needs also be passed to the
736 On user space, a program willing to read the values needs to
737 call \fBperf_event_open\fP() on the perf event (either for
738 one or for all CPUs) and to store the file descriptor into the
739 \fImap\fP\&. This must be done before the eBPF program can send data
740 into it. An example is available in file
741 \fIsamples/bpf/trace_output_user.c\fP in the Linux kernel source
742 tree (the eBPF program counterpart is in
743 \fIsamples/bpf/trace_output_kern.c\fP).
745 \fBbpf_perf_event_output\fP() achieves better performance
746 than \fBbpf_trace_printk\fP() for sharing data with user
747 space, and is much better suitable for streaming data from eBPF
750 Note that this helper is not restricted to tracing use cases
751 and can be used with programs attached to TC or XDP as well,
752 where it allows for passing data to user space listeners. Data
758 Only the packet payload, or
760 A combination of both.
764 0 on success, or a negative error in case of failure.
767 .B \fBlong bpf_skb_load_bytes(const void *\fP\fIskb\fP\fB, u32\fP \fIoffset\fP\fB, void *\fP\fIto\fP\fB, u32\fP \fIlen\fP\fB)\fP
771 This helper was provided as an easy way to load data from a
772 packet. It can be used to load \fIlen\fP bytes from \fIoffset\fP from
773 the packet associated to \fIskb\fP, into the buffer pointed by
776 Since Linux 4.7, usage of this helper has mostly been replaced
777 by \[dq]direct packet access\[dq], enabling packet data to be
778 manipulated with \fIskb\fP\fB\->data\fP and \fIskb\fP\fB\->data_end\fP
779 pointing respectively to the first byte of packet data and to
780 the byte after the last byte of packet data. However, it
781 remains useful if one wishes to read large quantities of data
782 at once from a packet into the eBPF stack.
785 0 on success, or a negative error in case of failure.
788 .B \fBlong bpf_get_stackid(void *\fP\fIctx\fP\fB, struct bpf_map *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB)\fP
792 Walk a user or a kernel stack and return its id. To achieve
793 this, the helper needs \fIctx\fP, which is a pointer to the context
794 on which the tracing program is executed, and a pointer to a
795 \fImap\fP of type \fBBPF_MAP_TYPE_STACK_TRACE\fP\&.
797 The last argument, \fIflags\fP, holds the number of stack frames to
798 skip (from 0 to 255), masked with
799 \fBBPF_F_SKIP_FIELD_MASK\fP\&. The next bits can be used to set
800 a combination of the following flags:
803 .B \fBBPF_F_USER_STACK\fP
804 Collect a user space stack instead of a kernel stack.
806 .B \fBBPF_F_FAST_STACK_CMP\fP
807 Compare stacks by hash only.
809 .B \fBBPF_F_REUSE_STACKID\fP
810 If two different stacks hash into the same \fIstackid\fP,
814 The stack id retrieved is a 32 bit long integer handle which
815 can be further combined with other data (including other stack
816 ids) and used as a key into maps. This can be useful for
817 generating a variety of graphs (such as flame graphs or off\-cpu
820 For walking a stack, this helper is an improvement over
821 \fBbpf_probe_read\fP(), which can be used with unrolled loops
822 but is not efficient and consumes a lot of eBPF instructions.
823 Instead, \fBbpf_get_stackid\fP() can collect up to
824 \fBPERF_MAX_STACK_DEPTH\fP both kernel and user frames. Note that
825 this limit can be controlled with the \fBsysctl\fP program, and
826 that it should be manually increased in order to profile long
827 user stacks (such as stacks for Java programs). To do so, use:
833 # sysctl kernel.perf_event_max_stack=<new value>
840 The positive or null stack id on success, or a negative error
844 .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
848 Compute a checksum difference, from the raw buffer pointed by
849 \fIfrom\fP, of length \fIfrom_size\fP (that must be a multiple of 4),
850 towards the raw buffer pointed by \fIto\fP, of size \fIto_size\fP
851 (same remark). An optional \fIseed\fP can be added to the value
852 (this can be cascaded, the seed may come from a previous call
855 This is flexible enough to be used in several ways:
858 With \fIfrom_size\fP == 0, \fIto_size\fP > 0 and \fIseed\fP set to
859 checksum, it can be used when pushing new data.
861 With \fIfrom_size\fP > 0, \fIto_size\fP == 0 and \fIseed\fP set to
862 checksum, it can be used when removing data from a packet.
864 With \fIfrom_size\fP > 0, \fIto_size\fP > 0 and \fIseed\fP set to 0, it
865 can be used to compute a diff. Note that \fIfrom_size\fP and
866 \fIto_size\fP do not need to be equal.
869 This helper can be used in combination with
870 \fBbpf_l3_csum_replace\fP() and \fBbpf_l4_csum_replace\fP(), to
871 which one can feed in the difference computed with
872 \fBbpf_csum_diff\fP().
875 The checksum result, or a negative error code in case of
879 .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
883 Retrieve tunnel options metadata for the packet associated to
884 \fIskb\fP, and store the raw tunnel option data to the buffer \fIopt\fP
887 This helper can be used with encapsulation devices that can
888 operate in \[dq]collect metadata\[dq] mode (please refer to the related
889 note in the description of \fBbpf_skb_get_tunnel_key\fP() for
890 more details). A particular example where this can be used is
891 in combination with the Geneve encapsulation protocol, where it
892 allows for pushing (with \fBbpf_skb_get_tunnel_opt\fP() helper)
893 and retrieving arbitrary TLVs (Type\-Length\-Value headers) from
894 the eBPF program. This allows for full customization of these
898 The size of the option data retrieved.
901 .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
905 Set tunnel options metadata for the packet associated to \fIskb\fP
906 to the option data contained in the raw buffer \fIopt\fP of \fIsize\fP\&.
908 See also the description of the \fBbpf_skb_get_tunnel_opt\fP()
909 helper for additional information.
912 0 on success, or a negative error in case of failure.
915 .B \fBlong bpf_skb_change_proto(struct sk_buff *\fP\fIskb\fP\fB, __be16\fP \fIproto\fP\fB, u64\fP \fIflags\fP\fB)\fP
919 Change the protocol of the \fIskb\fP to \fIproto\fP\&. Currently
920 supported are transition from IPv4 to IPv6, and from IPv6 to
921 IPv4. The helper takes care of the groundwork for the
922 transition, including resizing the socket buffer. The eBPF
923 program is expected to fill the new headers, if any, via
924 \fBskb_store_bytes\fP() and to recompute the checksums with
925 \fBbpf_l3_csum_replace\fP() and \fBbpf_l4_csum_replace\fP(). The main case for this helper is to perform NAT64
926 operations out of an eBPF program.
928 Internally, the GSO type is marked as dodgy so that headers are
929 checked and segments are recalculated by the GSO/GRO engine.
930 The size for GSO target is adapted as well.
932 All values for \fIflags\fP are reserved for future usage, and must
935 A call to this helper is susceptible to change the underlying
936 packet buffer. Therefore, at load time, all checks on pointers
937 previously done by the verifier are invalidated and must be
938 performed again, if the helper is used in combination with
939 direct packet access.
942 0 on success, or a negative error in case of failure.
945 .B \fBlong bpf_skb_change_type(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fItype\fP\fB)\fP
949 Change the packet type for the packet associated to \fIskb\fP\&. This
950 comes down to setting \fIskb\fP\fB\->pkt_type\fP to \fItype\fP, except
951 the eBPF program does not have a write access to \fIskb\fP\fB\->pkt_type\fP beside this helper. Using a helper here allows
952 for graceful handling of errors.
954 The major use case is to change incoming \fIskb*s to
955 **PACKET_HOST*\fP in a programmatic way instead of having to
956 recirculate via \fBredirect\fP(..., \fBBPF_F_INGRESS\fP), for
959 Note that \fItype\fP only allows certain values. At this time, they
966 .B \fBPACKET_BROADCAST\fP
969 .B \fBPACKET_MULTICAST\fP
970 Send packet to group.
972 .B \fBPACKET_OTHERHOST\fP
973 Send packet to someone else.
977 0 on success, or a negative error in case of failure.
980 .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
984 Check whether \fIskb\fP is a descendant of the cgroup2 held by
985 \fImap\fP of type \fBBPF_MAP_TYPE_CGROUP_ARRAY\fP, at \fIindex\fP\&.
988 The return value depends on the result of the test, and can be:
991 0, if the \fIskb\fP failed the cgroup2 descendant test.
993 1, if the \fIskb\fP succeeded the cgroup2 descendant test.
995 A negative error code, if an error occurred.
999 .B \fBu32 bpf_get_hash_recalc(struct sk_buff *\fP\fIskb\fP\fB)\fP
1003 Retrieve the hash of the packet, \fIskb\fP\fB\->hash\fP\&. If it is
1004 not set, in particular if the hash was cleared due to mangling,
1005 recompute this hash. Later accesses to the hash can be done
1006 directly with \fIskb\fP\fB\->hash\fP\&.
1008 Calling \fBbpf_set_hash_invalid\fP(), changing a packet
1009 prototype with \fBbpf_skb_change_proto\fP(), or calling
1010 \fBbpf_skb_store_bytes\fP() with the
1011 \fBBPF_F_INVALIDATE_HASH\fP are actions susceptible to clear
1012 the hash and to trigger a new computation for the next call to
1013 \fBbpf_get_hash_recalc\fP().
1019 .B \fBu64 bpf_get_current_task(void)\fP
1023 Get the current task.
1026 A pointer to the current task struct.
1029 .B \fBlong bpf_probe_write_user(void *\fP\fIdst\fP\fB, const void *\fP\fIsrc\fP\fB, u32\fP \fIlen\fP\fB)\fP
1033 Attempt in a safe way to write \fIlen\fP bytes from the buffer
1034 \fIsrc\fP to \fIdst\fP in memory. It only works for threads that are in
1035 user context, and \fIdst\fP must be a valid user space address.
1037 This helper should not be used to implement any kind of
1038 security mechanism because of TOC\-TOU attacks, but rather to
1039 debug, divert, and manipulate execution of semi\-cooperative
1042 Keep in mind that this feature is meant for experiments, and it
1043 has a risk of crashing the system and running programs.
1044 Therefore, when an eBPF program using this helper is attached,
1045 a warning including PID and process name is printed to kernel
1049 0 on success, or a negative error in case of failure.
1052 .B \fBlong bpf_current_task_under_cgroup(struct bpf_map *\fP\fImap\fP\fB, u32\fP \fIindex\fP\fB)\fP
1056 Check whether the probe is being run is the context of a given
1057 subset of the cgroup2 hierarchy. The cgroup2 to test is held by
1058 \fImap\fP of type \fBBPF_MAP_TYPE_CGROUP_ARRAY\fP, at \fIindex\fP\&.
1061 The return value depends on the result of the test, and can be:
1064 1, if current task belongs to the cgroup2.
1066 0, if current task does not belong to the cgroup2.
1068 A negative error code, if an error occurred.
1072 .B \fBlong bpf_skb_change_tail(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
1076 Resize (trim or grow) the packet associated to \fIskb\fP to the
1077 new \fIlen\fP\&. The \fIflags\fP are reserved for future usage, and must
1080 The basic idea is that the helper performs the needed work to
1081 change the size of the packet, then the eBPF program rewrites
1082 the rest via helpers like \fBbpf_skb_store_bytes\fP(),
1083 \fBbpf_l3_csum_replace\fP(), \fBbpf_l3_csum_replace\fP()
1084 and others. This helper is a slow path utility intended for
1085 replies with control messages. And because it is targeted for
1086 slow path, the helper itself can afford to be slow: it
1087 implicitly linearizes, unclones and drops offloads from the
1090 A call to this helper is susceptible to change the underlying
1091 packet buffer. Therefore, at load time, all checks on pointers
1092 previously done by the verifier are invalidated and must be
1093 performed again, if the helper is used in combination with
1094 direct packet access.
1097 0 on success, or a negative error in case of failure.
1100 .B \fBlong bpf_skb_pull_data(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIlen\fP\fB)\fP
1104 Pull in non\-linear data in case the \fIskb\fP is non\-linear and not
1105 all of \fIlen\fP are part of the linear section. Make \fIlen\fP bytes
1106 from \fIskb\fP readable and writable. If a zero value is passed for
1107 \fIlen\fP, then all bytes in the linear part of \fIskb\fP will be made
1108 readable and writable.
1110 This helper is only needed for reading and writing with direct
1113 For direct packet access, testing that offsets to access
1114 are within packet boundaries (test on \fIskb\fP\fB\->data_end\fP) is
1115 susceptible to fail if offsets are invalid, or if the requested
1116 data is in non\-linear parts of the \fIskb\fP\&. On failure the
1117 program can just bail out, or in the case of a non\-linear
1118 buffer, use a helper to make the data available. The
1119 \fBbpf_skb_load_bytes\fP() helper is a first solution to access
1120 the data. Another one consists in using \fBbpf_skb_pull_data\fP
1121 to pull in once the non\-linear parts, then retesting and
1122 eventually access the data.
1124 At the same time, this also makes sure the \fIskb\fP is uncloned,
1125 which is a necessary condition for direct write. As this needs
1126 to be an invariant for the write part only, the verifier
1127 detects writes and adds a prologue that is calling
1128 \fBbpf_skb_pull_data()\fP to effectively unclone the \fIskb\fP from
1129 the very beginning in case it is indeed cloned.
1131 A call to this helper is susceptible to change the underlying
1132 packet buffer. Therefore, at load time, all checks on pointers
1133 previously done by the verifier are invalidated and must be
1134 performed again, if the helper is used in combination with
1135 direct packet access.
1138 0 on success, or a negative error in case of failure.
1141 .B \fBs64 bpf_csum_update(struct sk_buff *\fP\fIskb\fP\fB, __wsum\fP \fIcsum\fP\fB)\fP
1145 Add the checksum \fIcsum\fP into \fIskb\fP\fB\->csum\fP in case the
1146 driver has supplied a checksum for the entire packet into that
1147 field. Return an error otherwise. This helper is intended to be
1148 used in combination with \fBbpf_csum_diff\fP(), in particular
1149 when the checksum needs to be updated after data has been
1150 written into the packet through direct packet access.
1153 The checksum on success, or a negative error code in case of
1157 .B \fBvoid bpf_set_hash_invalid(struct sk_buff *\fP\fIskb\fP\fB)\fP
1161 Invalidate the current \fIskb\fP\fB\->hash\fP\&. It can be used after
1162 mangling on headers through direct packet access, in order to
1163 indicate that the hash is outdated and to trigger a
1164 recalculation the next time the kernel tries to access this
1165 hash or when the \fBbpf_get_hash_recalc\fP() helper is called.
1171 .B \fBlong bpf_get_numa_node_id(void)\fP
1175 Return the id of the current NUMA node. The primary use case
1176 for this helper is the selection of sockets for the local NUMA
1177 node, when the program is attached to sockets using the
1178 \fBSO_ATTACH_REUSEPORT_EBPF\fP option (see also \fBsocket(7)\fP),
1179 but the helper is also available to other eBPF program types,
1180 similarly to \fBbpf_get_smp_processor_id\fP().
1183 The id of current NUMA node.
1186 .B \fBlong bpf_skb_change_head(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIlen\fP\fB, u64\fP \fIflags\fP\fB)\fP
1190 Grows headroom of packet associated to \fIskb\fP and adjusts the
1191 offset of the MAC header accordingly, adding \fIlen\fP bytes of
1192 space. It automatically extends and reallocates memory as
1195 This helper can be used on a layer 3 \fIskb\fP to push a MAC header
1196 for redirection into a layer 2 device.
1198 All values for \fIflags\fP are reserved for future usage, and must
1201 A call to this helper is susceptible to change the underlying
1202 packet buffer. Therefore, at load time, all checks on pointers
1203 previously done by the verifier are invalidated and must be
1204 performed again, if the helper is used in combination with
1205 direct packet access.
1208 0 on success, or a negative error in case of failure.
1211 .B \fBlong bpf_xdp_adjust_head(struct xdp_buff *\fP\fIxdp_md\fP\fB, int\fP \fIdelta\fP\fB)\fP
1215 Adjust (move) \fIxdp_md\fP\fB\->data\fP by \fIdelta\fP bytes. Note that
1216 it is possible to use a negative value for \fIdelta\fP\&. This helper
1217 can be used to prepare the packet for pushing or popping
1220 A call to this helper is susceptible to change the underlying
1221 packet buffer. Therefore, at load time, all checks on pointers
1222 previously done by the verifier are invalidated and must be
1223 performed again, if the helper is used in combination with
1224 direct packet access.
1227 0 on success, or a negative error in case of failure.
1230 .B \fBlong bpf_probe_read_str(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
1234 Copy a NUL terminated string from an unsafe kernel address
1235 \fIunsafe_ptr\fP to \fIdst\fP\&. See \fBbpf_probe_read_kernel_str\fP() for
1238 Generally, use \fBbpf_probe_read_user_str\fP() or
1239 \fBbpf_probe_read_kernel_str\fP() instead.
1242 On success, the strictly positive length of the string,
1243 including the trailing NUL character. On error, a negative
1247 .B \fBu64 bpf_get_socket_cookie(struct sk_buff *\fP\fIskb\fP\fB)\fP
1251 If the \fBstruct sk_buff\fP pointed by \fIskb\fP has a known socket,
1252 retrieve the cookie (generated by the kernel) of this socket.
1253 If no cookie has been set yet, generate a new cookie. Once
1254 generated, the socket cookie remains stable for the life of the
1255 socket. This helper can be useful for monitoring per socket
1256 networking traffic statistics as it provides a global socket
1257 identifier that can be assumed unique.
1260 A 8\-byte long unique number on success, or 0 if the socket
1261 field is missing inside \fIskb\fP\&.
1264 .B \fBu64 bpf_get_socket_cookie(struct bpf_sock_addr *\fP\fIctx\fP\fB)\fP
1268 Equivalent to bpf_get_socket_cookie() helper that accepts
1269 \fIskb\fP, but gets socket from \fBstruct bpf_sock_addr\fP context.
1272 A 8\-byte long unique number.
1275 .B \fBu64 bpf_get_socket_cookie(struct bpf_sock_ops *\fP\fIctx\fP\fB)\fP
1279 Equivalent to \fBbpf_get_socket_cookie\fP() helper that accepts
1280 \fIskb\fP, but gets socket from \fBstruct bpf_sock_ops\fP context.
1283 A 8\-byte long unique number.
1286 .B \fBu64 bpf_get_socket_cookie(struct sock *\fP\fIsk\fP\fB)\fP
1290 Equivalent to \fBbpf_get_socket_cookie\fP() helper that accepts
1291 \fIsk\fP, but gets socket from a BTF \fBstruct sock\fP\&. This helper
1292 also works for sleepable programs.
1295 A 8\-byte long unique number or 0 if \fIsk\fP is NULL.
1298 .B \fBu32 bpf_get_socket_uid(struct sk_buff *\fP\fIskb\fP\fB)\fP
1302 Get the owner UID of the socked associated to \fIskb\fP\&.
1305 The owner UID of the socket associated to \fIskb\fP\&. If the socket
1306 is \fBNULL\fP, or if it is not a full socket (i.e. if it is a
1307 time\-wait or a request socket instead), \fBoverflowuid\fP value
1308 is returned (note that \fBoverflowuid\fP might also be the actual
1309 UID value for the socket).
1312 .B \fBlong bpf_set_hash(struct sk_buff *\fP\fIskb\fP\fB, u32\fP \fIhash\fP\fB)\fP
1316 Set the full hash for \fIskb\fP (set the field \fIskb\fP\fB\->hash\fP)
1317 to value \fIhash\fP\&.
1323 .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
1327 Emulate a call to \fBsetsockopt()\fP on the socket associated to
1328 \fIbpf_socket\fP, which must be a full socket. The \fIlevel\fP at
1329 which the option resides and the name \fIoptname\fP of the option
1330 must be specified, see \fBsetsockopt(2)\fP for more information.
1331 The option value of length \fIoptlen\fP is pointed by \fIoptval\fP\&.
1333 \fIbpf_socket\fP should be one of the following:
1336 \fBstruct bpf_sock_ops\fP for \fBBPF_PROG_TYPE_SOCK_OPS\fP\&.
1338 \fBstruct bpf_sock_addr\fP for \fBBPF_CGROUP_INET4_CONNECT\fP
1339 and \fBBPF_CGROUP_INET6_CONNECT\fP\&.
1342 This helper actually implements a subset of \fBsetsockopt()\fP\&.
1343 It supports the following \fIlevel\fPs:
1346 \fBSOL_SOCKET\fP, which supports the following \fIoptname\fPs:
1347 \fBSO_RCVBUF\fP, \fBSO_SNDBUF\fP, \fBSO_MAX_PACING_RATE\fP,
1348 \fBSO_PRIORITY\fP, \fBSO_RCVLOWAT\fP, \fBSO_MARK\fP,
1349 \fBSO_BINDTODEVICE\fP, \fBSO_KEEPALIVE\fP\&.
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\&.
1357 \fBIPPROTO_IP\fP, which supports \fIoptname\fP \fBIP_TOS\fP\&.
1359 \fBIPPROTO_IPV6\fP, which supports \fIoptname\fP \fBIPV6_TCLASS\fP\&.
1363 0 on success, or a negative error in case of failure.
1366 .B \fBlong bpf_skb_adjust_room(struct sk_buff *\fP\fIskb\fP\fB, s32\fP \fIlen_diff\fP\fB, u32\fP \fImode\fP\fB, u64\fP \fIflags\fP\fB)\fP
1370 Grow or shrink the room for data in the packet associated to
1371 \fIskb\fP by \fIlen_diff\fP, and according to the selected \fImode\fP\&.
1373 By default, the helper will reset any offloaded checksum
1374 indicator of the skb to CHECKSUM_NONE. This can be avoided
1375 by the following flag:
1378 \fBBPF_F_ADJ_ROOM_NO_CSUM_RESET\fP: Do not reset offloaded
1379 checksum data of the skb to CHECKSUM_NONE.
1382 There are two supported modes at this time:
1385 \fBBPF_ADJ_ROOM_MAC\fP: Adjust room at the mac layer
1386 (room space is added or removed between the layer 2 and
1389 \fBBPF_ADJ_ROOM_NET\fP: Adjust room at the network layer
1390 (room space is added or removed between the layer 3 and
1394 The following flags are supported at this time:
1397 \fBBPF_F_ADJ_ROOM_FIXED_GSO\fP: Do not adjust gso_size.
1398 Adjusting mss in this way is not allowed for datagrams.
1400 \fBBPF_F_ADJ_ROOM_ENCAP_L3_IPV4\fP,
1401 \fBBPF_F_ADJ_ROOM_ENCAP_L3_IPV6\fP:
1402 Any new space is reserved to hold a tunnel header.
1403 Configure skb offsets and other fields accordingly.
1405 \fBBPF_F_ADJ_ROOM_ENCAP_L4_GRE\fP,
1406 \fBBPF_F_ADJ_ROOM_ENCAP_L4_UDP\fP:
1407 Use with ENCAP_L3 flags to further specify the tunnel type.
1409 \fBBPF_F_ADJ_ROOM_ENCAP_L2\fP(\fIlen\fP):
1410 Use with ENCAP_L3/L4 flags to further specify the tunnel
1411 type; \fIlen\fP is the length of the inner MAC header.
1413 \fBBPF_F_ADJ_ROOM_ENCAP_L2_ETH\fP:
1414 Use with BPF_F_ADJ_ROOM_ENCAP_L2 flag to further specify the
1415 L2 type as Ethernet.
1418 A call to this helper is susceptible to change the underlying
1419 packet buffer. Therefore, at load time, all checks on pointers
1420 previously done by the verifier are invalidated and must be
1421 performed again, if the helper is used in combination with
1422 direct packet access.
1425 0 on success, or a negative error in case of failure.
1428 .B \fBlong bpf_redirect_map(struct bpf_map *\fP\fImap\fP\fB, u32\fP \fIkey\fP\fB, u64\fP \fIflags\fP\fB)\fP
1432 Redirect the packet to the endpoint referenced by \fImap\fP at
1433 index \fIkey\fP\&. Depending on its type, this \fImap\fP can contain
1434 references to net devices (for forwarding packets through other
1435 ports), or to CPUs (for redirecting XDP frames to another CPU;
1436 but this is only implemented for native XDP (with driver
1437 support) as of this writing).
1439 The lower two bits of \fIflags\fP are used as the return code if
1440 the map lookup fails. This is so that the return value can be
1441 one of the XDP program return codes up to \fBXDP_TX\fP, as chosen
1442 by the caller. The higher bits of \fIflags\fP can be set to
1443 BPF_F_BROADCAST or BPF_F_EXCLUDE_INGRESS as defined below.
1445 With BPF_F_BROADCAST the packet will be broadcasted to all the
1446 interfaces in the map, with BPF_F_EXCLUDE_INGRESS the ingress
1447 interface will be excluded when do broadcasting.
1449 See also \fBbpf_redirect\fP(), which only supports redirecting
1450 to an ifindex, but doesn\[aq]t require a map to do so.
1453 \fBXDP_REDIRECT\fP on success, or the value of the two lower bits
1454 of the \fIflags\fP argument on error.
1457 .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
1461 Redirect the packet to the socket referenced by \fImap\fP (of type
1462 \fBBPF_MAP_TYPE_SOCKMAP\fP) at index \fIkey\fP\&. Both ingress and
1463 egress interfaces can be used for redirection. The
1464 \fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
1465 distinction (ingress path is selected if the flag is present,
1466 egress path otherwise). This is the only flag supported for now.
1469 \fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
1472 .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
1476 Add an entry to, or update a \fImap\fP referencing sockets. The
1477 \fIskops\fP is used as a new value for the entry associated to
1478 \fIkey\fP\&. \fIflags\fP is one of:
1481 .B \fBBPF_NOEXIST\fP
1482 The entry for \fIkey\fP must not exist in the map.
1485 The entry for \fIkey\fP must already exist in the map.
1488 No condition on the existence of the entry for \fIkey\fP\&.
1491 If the \fImap\fP has eBPF programs (parser and verdict), those will
1492 be inherited by the socket being added. If the socket is
1493 already attached to eBPF programs, this results in an error.
1496 0 on success, or a negative error in case of failure.
1499 .B \fBlong bpf_xdp_adjust_meta(struct xdp_buff *\fP\fIxdp_md\fP\fB, int\fP \fIdelta\fP\fB)\fP
1503 Adjust the address pointed by \fIxdp_md\fP\fB\->data_meta\fP by
1504 \fIdelta\fP (which can be positive or negative). Note that this
1505 operation modifies the address stored in \fIxdp_md\fP\fB\->data\fP,
1506 so the latter must be loaded only after the helper has been
1509 The use of \fIxdp_md\fP\fB\->data_meta\fP is optional and programs
1510 are not required to use it. The rationale is that when the
1511 packet is processed with XDP (e.g. as DoS filter), it is
1512 possible to push further meta data along with it before passing
1513 to the stack, and to give the guarantee that an ingress eBPF
1514 program attached as a TC classifier on the same device can pick
1515 this up for further post\-processing. Since TC works with socket
1516 buffers, it remains possible to set from XDP the \fBmark\fP or
1517 \fBpriority\fP pointers, or other pointers for the socket buffer.
1518 Having this scratch space generic and programmable allows for
1519 more flexibility as the user is free to store whatever meta
1522 A call to this helper is susceptible to change the underlying
1523 packet buffer. Therefore, at load time, all checks on pointers
1524 previously done by the verifier are invalidated and must be
1525 performed again, if the helper is used in combination with
1526 direct packet access.
1529 0 on success, or a negative error in case of failure.
1532 .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
1536 Read the value of a perf event counter, and store it into \fIbuf\fP
1537 of size \fIbuf_size\fP\&. This helper relies on a \fImap\fP of type
1538 \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. The nature of the perf event
1539 counter is selected when \fImap\fP is updated with perf event file
1540 descriptors. The \fImap\fP is an array whose size is the number of
1541 available CPUs, and each cell contains a value relative to one
1542 CPU. The value to retrieve is indicated by \fIflags\fP, that
1543 contains the index of the CPU to look up, masked with
1544 \fBBPF_F_INDEX_MASK\fP\&. Alternatively, \fIflags\fP can be set to
1545 \fBBPF_F_CURRENT_CPU\fP to indicate that the value for the
1546 current CPU should be retrieved.
1548 This helper behaves in a way close to
1549 \fBbpf_perf_event_read\fP() helper, save that instead of
1550 just returning the value observed, it fills the \fIbuf\fP
1551 structure. This allows for additional data to be retrieved: in
1552 particular, the enabled and running times (in \fIbuf\fP\fB\->enabled\fP and \fIbuf\fP\fB\->running\fP, respectively) are
1553 copied. In general, \fBbpf_perf_event_read_value\fP() is
1554 recommended over \fBbpf_perf_event_read\fP(), which has some
1555 ABI issues and provides fewer functionalities.
1557 These values are interesting, because hardware PMU (Performance
1558 Monitoring Unit) counters are limited resources. When there are
1559 more PMU based perf events opened than available counters,
1560 kernel will multiplex these events so each event gets certain
1561 percentage (but not all) of the PMU time. In case that
1562 multiplexing happens, the number of samples or counter value
1563 will not reflect the case compared to when no multiplexing
1564 occurs. This makes comparison between different runs difficult.
1565 Typically, the counter value should be normalized before
1566 comparing to other experiments. The usual normalization is done
1573 normalized_counter = counter * t_enabled / t_running
1579 Where t_enabled is the time enabled for event and t_running is
1580 the time running for event since last normalization. The
1581 enabled and running times are accumulated since the perf event
1582 open. To achieve scaling factor between two invocations of an
1583 eBPF program, users can use CPU id as the key (which is
1584 typical for perf array usage model) to remember the previous
1585 value and do the calculation inside the eBPF program.
1588 0 on success, or a negative error in case of failure.
1591 .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
1595 For en eBPF program attached to a perf event, retrieve the
1596 value of the event counter associated to \fIctx\fP and store it in
1597 the structure pointed by \fIbuf\fP and of size \fIbuf_size\fP\&. Enabled
1598 and running times are also stored in the structure (see
1599 description of helper \fBbpf_perf_event_read_value\fP() for
1603 0 on success, or a negative error in case of failure.
1606 .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
1610 Emulate a call to \fBgetsockopt()\fP on the socket associated to
1611 \fIbpf_socket\fP, which must be a full socket. The \fIlevel\fP at
1612 which the option resides and the name \fIoptname\fP of the option
1613 must be specified, see \fBgetsockopt(2)\fP for more information.
1614 The retrieved value is stored in the structure pointed by
1615 \fIopval\fP and of length \fIoptlen\fP\&.
1617 \fIbpf_socket\fP should be one of the following:
1620 \fBstruct bpf_sock_ops\fP for \fBBPF_PROG_TYPE_SOCK_OPS\fP\&.
1622 \fBstruct bpf_sock_addr\fP for \fBBPF_CGROUP_INET4_CONNECT\fP
1623 and \fBBPF_CGROUP_INET6_CONNECT\fP\&.
1626 This helper actually implements a subset of \fBgetsockopt()\fP\&.
1627 It supports the following \fIlevel\fPs:
1630 \fBIPPROTO_TCP\fP, which supports \fIoptname\fP
1631 \fBTCP_CONGESTION\fP\&.
1633 \fBIPPROTO_IP\fP, which supports \fIoptname\fP \fBIP_TOS\fP\&.
1635 \fBIPPROTO_IPV6\fP, which supports \fIoptname\fP \fBIPV6_TCLASS\fP\&.
1639 0 on success, or a negative error in case of failure.
1642 .B \fBlong bpf_override_return(struct pt_regs *\fP\fIregs\fP\fB, u64\fP \fIrc\fP\fB)\fP
1646 Used for error injection, this helper uses kprobes to override
1647 the return value of the probed function, and to set it to \fIrc\fP\&.
1648 The first argument is the context \fIregs\fP on which the kprobe
1651 This helper works by setting the PC (program counter)
1652 to an override function which is run in place of the original
1653 probed function. This means the probed function is not run at
1654 all. The replacement function just returns with the required
1657 This helper has security implications, and thus is subject to
1658 restrictions. It is only available if the kernel was compiled
1659 with the \fBCONFIG_BPF_KPROBE_OVERRIDE\fP configuration
1660 option, and in this case it only works on functions tagged with
1661 \fBALLOW_ERROR_INJECTION\fP in the kernel code.
1663 Also, the helper is only available for the architectures having
1664 the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,
1665 x86 architecture is the only one to support this feature.
1671 .B \fBlong bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *\fP\fIbpf_sock\fP\fB, int\fP \fIargval\fP\fB)\fP
1675 Attempt to set the value of the \fBbpf_sock_ops_cb_flags\fP field
1676 for the full TCP socket associated to \fIbpf_sock_ops\fP to
1679 The primary use of this field is to determine if there should
1680 be calls to eBPF programs of type
1681 \fBBPF_PROG_TYPE_SOCK_OPS\fP at various points in the TCP
1682 code. A program of the same type can change its value, per
1683 connection and as necessary, when the connection is
1684 established. This field is directly accessible for reading, but
1685 this helper must be used for updates in order to return an
1686 error if an eBPF program tries to set a callback that is not
1687 supported in the current kernel.
1689 \fIargval\fP is a flag array which can combine these flags:
1692 \fBBPF_SOCK_OPS_RTO_CB_FLAG\fP (retransmission time out)
1694 \fBBPF_SOCK_OPS_RETRANS_CB_FLAG\fP (retransmission)
1696 \fBBPF_SOCK_OPS_STATE_CB_FLAG\fP (TCP state change)
1698 \fBBPF_SOCK_OPS_RTT_CB_FLAG\fP (every RTT)
1701 Therefore, this function can be used to clear a callback flag by
1702 setting the appropriate bit to zero. e.g. to disable the RTO
1706 .B \fBbpf_sock_ops_cb_flags_set(bpf_sock,\fP
1707 \fBbpf_sock\->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)\fP
1710 Here are some examples of where one could call such eBPF
1716 When a packet is retransmitted.
1718 When the connection terminates.
1720 When a packet is sent.
1722 When a packet is received.
1726 Code \fB\-EINVAL\fP if the socket is not a full TCP socket;
1727 otherwise, a positive number containing the bits that could not
1728 be set is returned (which comes down to 0 if all bits were set
1732 .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
1736 This helper is used in programs implementing policies at the
1737 socket level. If the message \fImsg\fP is allowed to pass (i.e. if
1738 the verdict eBPF program returns \fBSK_PASS\fP), redirect it to
1739 the socket referenced by \fImap\fP (of type
1740 \fBBPF_MAP_TYPE_SOCKMAP\fP) at index \fIkey\fP\&. Both ingress and
1741 egress interfaces can be used for redirection. The
1742 \fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
1743 distinction (ingress path is selected if the flag is present,
1744 egress path otherwise). This is the only flag supported for now.
1747 \fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
1750 .B \fBlong bpf_msg_apply_bytes(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIbytes\fP\fB)\fP
1754 For socket policies, apply the verdict of the eBPF program to
1755 the next \fIbytes\fP (number of bytes) of message \fImsg\fP\&.
1757 For example, this helper can be used in the following cases:
1760 A single \fBsendmsg\fP() or \fBsendfile\fP() system call
1761 contains multiple logical messages that the eBPF program is
1762 supposed to read and for which it should apply a verdict.
1764 An eBPF program only cares to read the first \fIbytes\fP of a
1765 \fImsg\fP\&. If the message has a large payload, then setting up
1766 and calling the eBPF program repeatedly for all bytes, even
1767 though the verdict is already known, would create unnecessary
1771 When called from within an eBPF program, the helper sets a
1772 counter internal to the BPF infrastructure, that is used to
1773 apply the last verdict to the next \fIbytes\fP\&. If \fIbytes\fP is
1774 smaller than the current data being processed from a
1775 \fBsendmsg\fP() or \fBsendfile\fP() system call, the first
1776 \fIbytes\fP will be sent and the eBPF program will be re\-run with
1777 the pointer for start of data pointing to byte number \fIbytes\fP
1778 \fB+ 1\fP\&. If \fIbytes\fP is larger than the current data being
1779 processed, then the eBPF verdict will be applied to multiple
1780 \fBsendmsg\fP() or \fBsendfile\fP() calls until \fIbytes\fP are
1783 Note that if a socket closes with the internal counter holding
1784 a non\-zero value, this is not a problem because data is not
1785 being buffered for \fIbytes\fP and is sent as it is received.
1791 .B \fBlong bpf_msg_cork_bytes(struct sk_msg_buff *\fP\fImsg\fP\fB, u32\fP \fIbytes\fP\fB)\fP
1795 For socket policies, prevent the execution of the verdict eBPF
1796 program for message \fImsg\fP until \fIbytes\fP (byte number) have been
1799 This can be used when one needs a specific number of bytes
1800 before a verdict can be assigned, even if the data spans
1801 multiple \fBsendmsg\fP() or \fBsendfile\fP() calls. The extreme
1802 case would be a user calling \fBsendmsg\fP() repeatedly with
1803 1\-byte long message segments. Obviously, this is bad for
1804 performance, but it is still valid. If the eBPF program needs
1805 \fIbytes\fP bytes to validate a header, this helper can be used to
1806 prevent the eBPF program to be called again until \fIbytes\fP have
1813 .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
1817 For socket policies, pull in non\-linear data from user space
1818 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,
1821 If a program of type \fBBPF_PROG_TYPE_SK_MSG\fP is run on a
1822 \fImsg\fP it can only parse data that the (\fBdata\fP, \fBdata_end\fP)
1823 pointers have already consumed. For \fBsendmsg\fP() hooks this
1824 is likely the first scatterlist element. But for calls relying
1825 on the \fBsendpage\fP handler (e.g. \fBsendfile\fP()) this will
1826 be the range (\fB0\fP, \fB0\fP) because the data is shared with
1827 user space and by default the objective is to avoid allowing
1828 user space to modify data while (or after) eBPF verdict is
1829 being decided. This helper can be used to pull in data and to
1830 set the start and end pointer to given values. Data will be
1831 copied if necessary (i.e. if data was not linear and if start
1832 and end pointers do not point to the same chunk).
1834 A call to this helper is susceptible to change the underlying
1835 packet buffer. Therefore, at load time, all checks on pointers
1836 previously done by the verifier are invalidated and must be
1837 performed again, if the helper is used in combination with
1838 direct packet access.
1840 All values for \fIflags\fP are reserved for future usage, and must
1844 0 on success, or a negative error in case of failure.
1847 .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
1851 Bind the socket associated to \fIctx\fP to the address pointed by
1852 \fIaddr\fP, of length \fIaddr_len\fP\&. This allows for making outgoing
1853 connection from the desired IP address, which can be useful for
1854 example when all processes inside a cgroup should use one
1855 single IP address on a host that has multiple IP configured.
1857 This helper works for IPv4 and IPv6, TCP and UDP sockets. The
1858 domain (\fIaddr\fP\fB\->sa_family\fP) must be \fBAF_INET\fP (or
1859 \fBAF_INET6\fP). It\[aq]s advised to pass zero port (\fBsin_port\fP
1860 or \fBsin6_port\fP) which triggers IP_BIND_ADDRESS_NO_PORT\-like
1861 behavior and lets the kernel efficiently pick up an unused
1862 port as long as 4\-tuple is unique. Passing non\-zero port might
1863 lead to degraded performance.
1866 0 on success, or a negative error in case of failure.
1869 .B \fBlong bpf_xdp_adjust_tail(struct xdp_buff *\fP\fIxdp_md\fP\fB, int\fP \fIdelta\fP\fB)\fP
1873 Adjust (move) \fIxdp_md\fP\fB\->data_end\fP by \fIdelta\fP bytes. It is
1874 possible to both shrink and grow the packet tail.
1875 Shrink done via \fIdelta\fP being a negative integer.
1877 A call to this helper is susceptible to change the underlying
1878 packet buffer. Therefore, at load time, all checks on pointers
1879 previously done by the verifier are invalidated and must be
1880 performed again, if the helper is used in combination with
1881 direct packet access.
1884 0 on success, or a negative error in case of failure.
1887 .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
1891 Retrieve the XFRM state (IP transform framework, see also
1892 \fBip\-xfrm(8)\fP) at \fIindex\fP in XFRM \[dq]security path\[dq] for \fIskb\fP\&.
1894 The retrieved value is stored in the \fBstruct bpf_xfrm_state\fP
1895 pointed by \fIxfrm_state\fP and of length \fIsize\fP\&.
1897 All values for \fIflags\fP are reserved for future usage, and must
1900 This helper is available only if the kernel was compiled with
1901 \fBCONFIG_XFRM\fP configuration option.
1904 0 on success, or a negative error in case of failure.
1907 .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
1911 Return a user or a kernel stack in bpf program provided buffer.
1912 To achieve this, the helper needs \fIctx\fP, which is a pointer
1913 to the context on which the tracing program is executed.
1914 To store the stacktrace, the bpf program provides \fIbuf\fP with
1915 a nonnegative \fIsize\fP\&.
1917 The last argument, \fIflags\fP, holds the number of stack frames to
1918 skip (from 0 to 255), masked with
1919 \fBBPF_F_SKIP_FIELD_MASK\fP\&. The next bits can be used to set
1920 the following flags:
1923 .B \fBBPF_F_USER_STACK\fP
1924 Collect a user space stack instead of a kernel stack.
1926 .B \fBBPF_F_USER_BUILD_ID\fP
1927 Collect (build_id, file_offset) instead of ips for user
1928 stack, only valid if \fBBPF_F_USER_STACK\fP is also
1931 \fIfile_offset\fP is an offset relative to the beginning
1932 of the executable or shared object file backing the vma
1933 which the \fIip\fP falls in. It is \fInot\fP an offset relative
1934 to that object\[aq]s base address. Accordingly, it must be
1935 adjusted by adding (sh_addr \- sh_offset), where
1936 sh_{addr,offset} correspond to the executable section
1937 containing \fIfile_offset\fP in the object, for comparisons
1938 to symbols\[aq] st_value to be valid.
1941 \fBbpf_get_stack\fP() can collect up to
1942 \fBPERF_MAX_STACK_DEPTH\fP both kernel and user frames, subject
1943 to sufficient large buffer size. Note that
1944 this limit can be controlled with the \fBsysctl\fP program, and
1945 that it should be manually increased in order to profile long
1946 user stacks (such as stacks for Java programs). To do so, use:
1952 # sysctl kernel.perf_event_max_stack=<new value>
1959 The non\-negative copied \fIbuf\fP length equal to or less than
1960 \fIsize\fP on success, or a negative error in case of failure.
1963 .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
1967 This helper is similar to \fBbpf_skb_load_bytes\fP() in that
1968 it provides an easy way to load \fIlen\fP bytes from \fIoffset\fP
1969 from the packet associated to \fIskb\fP, into the buffer pointed
1970 by \fIto\fP\&. The difference to \fBbpf_skb_load_bytes\fP() is that
1971 a fifth argument \fIstart_header\fP exists in order to select a
1972 base offset to start from. \fIstart_header\fP can be one of:
1975 .B \fBBPF_HDR_START_MAC\fP
1976 Base offset to load data from is \fIskb\fP\[aq]s mac header.
1978 .B \fBBPF_HDR_START_NET\fP
1979 Base offset to load data from is \fIskb\fP\[aq]s network header.
1982 In general, \[dq]direct packet access\[dq] is the preferred method to
1983 access packet data, however, this helper is in particular useful
1984 in socket filters where \fIskb\fP\fB\->data\fP does not always point
1985 to the start of the mac header and where \[dq]direct packet access\[dq]
1989 0 on success, or a negative error in case of failure.
1992 .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
1996 Do FIB lookup in kernel tables using parameters in \fIparams\fP\&.
1997 If lookup is successful and result shows packet is to be
1998 forwarded, the neighbor tables are searched for the nexthop.
1999 If successful (ie., FIB lookup shows forwarding and nexthop
2000 is resolved), the nexthop address is returned in ipv4_dst
2001 or ipv6_dst based on family, smac is set to mac address of
2002 egress device, dmac is set to nexthop mac address, rt_metric
2003 is set to metric from route (IPv4/IPv6 only), and ifindex
2004 is set to the device index of the nexthop from the FIB lookup.
2006 \fIplen\fP argument is the size of the passed in struct.
2007 \fIflags\fP argument can be a combination of one or more of the
2011 .B \fBBPF_FIB_LOOKUP_DIRECT\fP
2012 Do a direct table lookup vs full lookup using FIB
2015 .B \fBBPF_FIB_LOOKUP_OUTPUT\fP
2016 Perform lookup from an egress perspective (default is
2020 \fIctx\fP is either \fBstruct xdp_md\fP for XDP programs or
2021 \fBstruct sk_buff\fP tc cls_act programs.
2026 < 0 if any input argument is invalid
2028 0 on success (packet is forwarded, nexthop neighbor exists)
2030 > 0 one of \fBBPF_FIB_LKUP_RET_\fP codes explaining why the
2031 packet is not forwarded or needs assist from full stack
2034 If lookup fails with BPF_FIB_LKUP_RET_FRAG_NEEDED, then the MTU
2035 was exceeded and output params\->mtu_result contains the MTU.
2038 .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
2042 Add an entry to, or update a sockhash \fImap\fP referencing sockets.
2043 The \fIskops\fP is used as a new value for the entry associated to
2044 \fIkey\fP\&. \fIflags\fP is one of:
2047 .B \fBBPF_NOEXIST\fP
2048 The entry for \fIkey\fP must not exist in the map.
2051 The entry for \fIkey\fP must already exist in the map.
2054 No condition on the existence of the entry for \fIkey\fP\&.
2057 If the \fImap\fP has eBPF programs (parser and verdict), those will
2058 be inherited by the socket being added. If the socket is
2059 already attached to eBPF programs, this results in an error.
2062 0 on success, or a negative error in case of failure.
2065 .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
2069 This helper is used in programs implementing policies at the
2070 socket level. If the message \fImsg\fP is allowed to pass (i.e. if
2071 the verdict eBPF program returns \fBSK_PASS\fP), redirect it to
2072 the socket referenced by \fImap\fP (of type
2073 \fBBPF_MAP_TYPE_SOCKHASH\fP) using hash \fIkey\fP\&. Both ingress and
2074 egress interfaces can be used for redirection. The
2075 \fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
2076 distinction (ingress path is selected if the flag is present,
2077 egress path otherwise). This is the only flag supported for now.
2080 \fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
2083 .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
2087 This helper is used in programs implementing policies at the
2088 skb socket level. If the sk_buff \fIskb\fP is allowed to pass (i.e.
2089 if the verdict eBPF program returns \fBSK_PASS\fP), redirect it
2090 to the socket referenced by \fImap\fP (of type
2091 \fBBPF_MAP_TYPE_SOCKHASH\fP) using hash \fIkey\fP\&. Both ingress and
2092 egress interfaces can be used for redirection. The
2093 \fBBPF_F_INGRESS\fP value in \fIflags\fP is used to make the
2094 distinction (ingress path is selected if the flag is present,
2095 egress otherwise). This is the only flag supported for now.
2098 \fBSK_PASS\fP on success, or \fBSK_DROP\fP on error.
2101 .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
2105 Encapsulate the packet associated to \fIskb\fP within a Layer 3
2106 protocol header. This header is provided in the buffer at
2107 address \fIhdr\fP, with \fIlen\fP its size in bytes. \fItype\fP indicates
2108 the protocol of the header and can be one of:
2111 .B \fBBPF_LWT_ENCAP_SEG6\fP
2112 IPv6 encapsulation with Segment Routing Header
2113 (\fBstruct ipv6_sr_hdr\fP). \fIhdr\fP only contains the SRH,
2114 the IPv6 header is computed by the kernel.
2116 .B \fBBPF_LWT_ENCAP_SEG6_INLINE\fP
2117 Only works if \fIskb\fP contains an IPv6 packet. Insert a
2118 Segment Routing Header (\fBstruct ipv6_sr_hdr\fP) inside
2121 .B \fBBPF_LWT_ENCAP_IP\fP
2122 IP encapsulation (GRE/GUE/IPIP/etc). The outer header
2123 must be IPv4 or IPv6, followed by zero or more
2124 additional headers, up to \fBLWT_BPF_MAX_HEADROOM\fP
2125 total bytes in all prepended headers. Please note that
2126 if \fBskb_is_gso\fP(\fIskb\fP) is true, no more than two
2127 headers can be prepended, and the inner header, if
2128 present, should be either GRE or UDP/GUE.
2131 \fBBPF_LWT_ENCAP_SEG6\fP* types can be called by BPF programs
2132 of type \fBBPF_PROG_TYPE_LWT_IN\fP; \fBBPF_LWT_ENCAP_IP\fP type can
2133 be called by bpf programs of types \fBBPF_PROG_TYPE_LWT_IN\fP and
2134 \fBBPF_PROG_TYPE_LWT_XMIT\fP\&.
2136 A call to this helper is susceptible to change the underlying
2137 packet buffer. Therefore, at load time, all checks on pointers
2138 previously done by the verifier are invalidated and must be
2139 performed again, if the helper is used in combination with
2140 direct packet access.
2143 0 on success, or a negative error in case of failure.
2146 .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
2150 Store \fIlen\fP bytes from address \fIfrom\fP into the packet
2151 associated to \fIskb\fP, at \fIoffset\fP\&. Only the flags, tag and TLVs
2152 inside the outermost IPv6 Segment Routing Header can be
2153 modified through this helper.
2155 A call to this helper is susceptible to change the underlying
2156 packet buffer. Therefore, at load time, all checks on pointers
2157 previously done by the verifier are invalidated and must be
2158 performed again, if the helper is used in combination with
2159 direct packet access.
2162 0 on success, or a negative error in case of failure.
2165 .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
2169 Adjust the size allocated to TLVs in the outermost IPv6
2170 Segment Routing Header contained in the packet associated to
2171 \fIskb\fP, at position \fIoffset\fP by \fIdelta\fP bytes. Only offsets
2172 after the segments are accepted. \fIdelta\fP can be as well
2173 positive (growing) as negative (shrinking).
2175 A call to this helper is susceptible to change the underlying
2176 packet buffer. Therefore, at load time, all checks on pointers
2177 previously done by the verifier are invalidated and must be
2178 performed again, if the helper is used in combination with
2179 direct packet access.
2182 0 on success, or a negative error in case of failure.
2185 .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
2189 Apply an IPv6 Segment Routing action of type \fIaction\fP to the
2190 packet associated to \fIskb\fP\&. Each action takes a parameter
2191 contained at address \fIparam\fP, and of length \fIparam_len\fP bytes.
2192 \fIaction\fP can be one of:
2195 .B \fBSEG6_LOCAL_ACTION_END_X\fP
2196 End.X action: Endpoint with Layer\-3 cross\-connect.
2197 Type of \fIparam\fP: \fBstruct in6_addr\fP\&.
2199 .B \fBSEG6_LOCAL_ACTION_END_T\fP
2200 End.T action: Endpoint with specific IPv6 table lookup.
2201 Type of \fIparam\fP: \fBint\fP\&.
2203 .B \fBSEG6_LOCAL_ACTION_END_B6\fP
2204 End.B6 action: Endpoint bound to an SRv6 policy.
2205 Type of \fIparam\fP: \fBstruct ipv6_sr_hdr\fP\&.
2207 .B \fBSEG6_LOCAL_ACTION_END_B6_ENCAP\fP
2208 End.B6.Encap action: Endpoint bound to an SRv6
2209 encapsulation policy.
2210 Type of \fIparam\fP: \fBstruct ipv6_sr_hdr\fP\&.
2213 A call to this helper is susceptible to change the underlying
2214 packet buffer. Therefore, at load time, all checks on pointers
2215 previously done by the verifier are invalidated and must be
2216 performed again, if the helper is used in combination with
2217 direct packet access.
2220 0 on success, or a negative error in case of failure.
2223 .B \fBlong bpf_rc_repeat(void *\fP\fIctx\fP\fB)\fP
2227 This helper is used in programs implementing IR decoding, to
2228 report a successfully decoded repeat key message. This delays
2229 the generation of a key up event for previously generated
2232 Some IR protocols like NEC have a special IR message for
2233 repeating last button, for when a button is held down.
2235 The \fIctx\fP should point to the lirc sample as passed into
2238 This helper is only available is the kernel was compiled with
2239 the \fBCONFIG_BPF_LIRC_MODE2\fP configuration option set to
2246 .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
2250 This helper is used in programs implementing IR decoding, to
2251 report a successfully decoded key press with \fIscancode\fP,
2252 \fItoggle\fP value in the given \fIprotocol\fP\&. The scancode will be
2253 translated to a keycode using the rc keymap, and reported as
2254 an input key down event. After a period a key up event is
2255 generated. This period can be extended by calling either
2256 \fBbpf_rc_keydown\fP() again with the same values, or calling
2257 \fBbpf_rc_repeat\fP().
2259 Some protocols include a toggle bit, in case the button was
2260 released and pressed again between consecutive scancodes.
2262 The \fIctx\fP should point to the lirc sample as passed into
2265 The \fIprotocol\fP is the decoded protocol number (see
2266 \fBenum rc_proto\fP for some predefined values).
2268 This helper is only available is the kernel was compiled with
2269 the \fBCONFIG_BPF_LIRC_MODE2\fP configuration option set to
2276 .B \fBu64 bpf_skb_cgroup_id(struct sk_buff *\fP\fIskb\fP\fB)\fP
2280 Return the cgroup v2 id of the socket associated with the \fIskb\fP\&.
2281 This is roughly similar to the \fBbpf_get_cgroup_classid\fP()
2282 helper for cgroup v1 by providing a tag resp. identifier that
2283 can be matched on or used for map lookups e.g. to implement
2284 policy. The cgroup v2 id of a given path in the hierarchy is
2285 exposed in user space through the f_handle API in order to get
2286 to the same 64\-bit id.
2288 This helper can be used on TC egress path, but not on ingress,
2289 and is available only if the kernel was compiled with the
2290 \fBCONFIG_SOCK_CGROUP_DATA\fP configuration option.
2293 The id is returned or 0 in case the id could not be retrieved.
2296 .B \fBu64 bpf_get_current_cgroup_id(void)\fP
2300 Get the current cgroup id based on the cgroup within which
2301 the current task is running.
2304 A 64\-bit integer containing the current cgroup id based
2305 on the cgroup within which the current task is running.
2308 .B \fBvoid *bpf_get_local_storage(void *\fP\fImap\fP\fB, u64\fP \fIflags\fP\fB)\fP
2312 Get the pointer to the local storage area.
2313 The type and the size of the local storage is defined
2314 by the \fImap\fP argument.
2315 The \fIflags\fP meaning is specific for each map type,
2316 and has to be 0 for cgroup local storage.
2318 Depending on the BPF program type, a local storage area
2319 can be shared between multiple instances of the BPF program,
2320 running simultaneously.
2322 A user should care about the synchronization by himself.
2323 For example, by using the \fBBPF_ATOMIC\fP instructions to alter
2327 A pointer to the local storage area.
2330 .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
2334 Select a \fBSO_REUSEPORT\fP socket from a
2335 \fBBPF_MAP_TYPE_REUSEPORT_SOCKARRAY\fP \fImap\fP\&.
2336 It checks the selected socket is matching the incoming
2337 request in the socket buffer.
2340 0 on success, or a negative error in case of failure.
2343 .B \fBu64 bpf_skb_ancestor_cgroup_id(struct sk_buff *\fP\fIskb\fP\fB, int\fP \fIancestor_level\fP\fB)\fP
2347 Return id of cgroup v2 that is ancestor of cgroup associated
2348 with the \fIskb\fP at the \fIancestor_level\fP\&. The root cgroup is at
2349 \fIancestor_level\fP zero and each step down the hierarchy
2350 increments the level. If \fIancestor_level\fP == level of cgroup
2351 associated with \fIskb\fP, then return value will be same as that
2352 of \fBbpf_skb_cgroup_id\fP().
2354 The helper is useful to implement policies based on cgroups
2355 that are upper in hierarchy than immediate cgroup associated
2358 The format of returned id and helper limitations are same as in
2359 \fBbpf_skb_cgroup_id\fP().
2362 The id is returned or 0 in case the id could not be retrieved.
2365 .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
2369 Look for TCP socket matching \fItuple\fP, optionally in a child
2370 network namespace \fInetns\fP\&. The return value must be checked,
2371 and if non\-\fBNULL\fP, released via \fBbpf_sk_release\fP().
2373 The \fIctx\fP should point to the context of the program, such as
2374 the skb or socket (depending on the hook in use). This is used
2375 to determine the base network namespace for the lookup.
2377 \fItuple_size\fP must be one of:
2380 .B \fBsizeof\fP(\fItuple\fP\fB\->ipv4\fP)
2381 Look for an IPv4 socket.
2383 .B \fBsizeof\fP(\fItuple\fP\fB\->ipv6\fP)
2384 Look for an IPv6 socket.
2387 If the \fInetns\fP is a negative signed 32\-bit integer, then the
2388 socket lookup table in the netns associated with the \fIctx\fP
2389 will be used. For the TC hooks, this is the netns of the device
2390 in the skb. For socket hooks, this is the netns of the socket.
2391 If \fInetns\fP is any other signed 32\-bit value greater than or
2392 equal to zero then it specifies the ID of the netns relative to
2393 the netns associated with the \fIctx\fP\&. \fInetns\fP values beyond the
2394 range of 32\-bit integers are reserved for future use.
2396 All values for \fIflags\fP are reserved for future usage, and must
2399 This helper is available only if the kernel was compiled with
2400 \fBCONFIG_NET\fP configuration option.
2403 Pointer to \fBstruct bpf_sock\fP, or \fBNULL\fP in case of failure.
2404 For sockets with reuseport option, the \fBstruct bpf_sock\fP
2405 result is from \fIreuse\fP\fB\->socks\fP[] using the hash of the
2409 .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
2413 Look for UDP socket matching \fItuple\fP, optionally in a child
2414 network namespace \fInetns\fP\&. The return value must be checked,
2415 and if non\-\fBNULL\fP, released via \fBbpf_sk_release\fP().
2417 The \fIctx\fP should point to the context of the program, such as
2418 the skb or socket (depending on the hook in use). This is used
2419 to determine the base network namespace for the lookup.
2421 \fItuple_size\fP must be one of:
2424 .B \fBsizeof\fP(\fItuple\fP\fB\->ipv4\fP)
2425 Look for an IPv4 socket.
2427 .B \fBsizeof\fP(\fItuple\fP\fB\->ipv6\fP)
2428 Look for an IPv6 socket.
2431 If the \fInetns\fP is a negative signed 32\-bit integer, then the
2432 socket lookup table in the netns associated with the \fIctx\fP
2433 will be used. For the TC hooks, this is the netns of the device
2434 in the skb. For socket hooks, this is the netns of the socket.
2435 If \fInetns\fP is any other signed 32\-bit value greater than or
2436 equal to zero then it specifies the ID of the netns relative to
2437 the netns associated with the \fIctx\fP\&. \fInetns\fP values beyond the
2438 range of 32\-bit integers are reserved for future use.
2440 All values for \fIflags\fP are reserved for future usage, and must
2443 This helper is available only if the kernel was compiled with
2444 \fBCONFIG_NET\fP configuration option.
2447 Pointer to \fBstruct bpf_sock\fP, or \fBNULL\fP in case of failure.
2448 For sockets with reuseport option, the \fBstruct bpf_sock\fP
2449 result is from \fIreuse\fP\fB\->socks\fP[] using the hash of the
2453 .B \fBlong bpf_sk_release(void *\fP\fIsock\fP\fB)\fP
2457 Release the reference held by \fIsock\fP\&. \fIsock\fP must be a
2458 non\-\fBNULL\fP pointer that was returned from
2459 \fBbpf_sk_lookup_xxx\fP().
2462 0 on success, or a negative error in case of failure.
2465 .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
2469 Push an element \fIvalue\fP in \fImap\fP\&. \fIflags\fP is one of:
2473 If the queue/stack is full, the oldest element is
2474 removed to make room for this.
2478 0 on success, or a negative error in case of failure.
2481 .B \fBlong bpf_map_pop_elem(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIvalue\fP\fB)\fP
2485 Pop an element from \fImap\fP\&.
2488 0 on success, or a negative error in case of failure.
2491 .B \fBlong bpf_map_peek_elem(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIvalue\fP\fB)\fP
2495 Get an element from \fImap\fP without removing it.
2498 0 on success, or a negative error in case of failure.
2501 .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
2505 For socket policies, insert \fIlen\fP bytes into \fImsg\fP at offset
2508 If a program of type \fBBPF_PROG_TYPE_SK_MSG\fP is run on a
2509 \fImsg\fP it may want to insert metadata or options into the \fImsg\fP\&.
2510 This can later be read and used by any of the lower layer BPF
2513 This helper may fail if under memory pressure (a malloc
2514 fails) in these cases BPF programs will get an appropriate
2515 error and BPF programs will need to handle them.
2518 0 on success, or a negative error in case of failure.
2521 .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
2525 Will remove \fIlen\fP bytes from a \fImsg\fP starting at byte \fIstart\fP\&.
2526 This may result in \fBENOMEM\fP errors under certain situations if
2527 an allocation and copy are required due to a full ring buffer.
2528 However, the helper will try to avoid doing the allocation
2529 if possible. Other errors can occur if input parameters are
2530 invalid either due to \fIstart\fP byte not being valid part of \fImsg\fP
2531 payload and/or \fIpop\fP value being to large.
2534 0 on success, or a negative error in case of failure.
2537 .B \fBlong bpf_rc_pointer_rel(void *\fP\fIctx\fP\fB, s32\fP \fIrel_x\fP\fB, s32\fP \fIrel_y\fP\fB)\fP
2541 This helper is used in programs implementing IR decoding, to
2542 report a successfully decoded pointer movement.
2544 The \fIctx\fP should point to the lirc sample as passed into
2547 This helper is only available is the kernel was compiled with
2548 the \fBCONFIG_BPF_LIRC_MODE2\fP configuration option set to
2555 .B \fBlong bpf_spin_lock(struct bpf_spin_lock *\fP\fIlock\fP\fB)\fP
2559 Acquire a spinlock represented by the pointer \fIlock\fP, which is
2560 stored as part of a value of a map. Taking the lock allows to
2561 safely update the rest of the fields in that value. The
2562 spinlock can (and must) later be released with a call to
2563 \fBbpf_spin_unlock\fP(\fIlock\fP).
2565 Spinlocks in BPF programs come with a number of restrictions
2569 \fBbpf_spin_lock\fP objects are only allowed inside maps of
2570 types \fBBPF_MAP_TYPE_HASH\fP and \fBBPF_MAP_TYPE_ARRAY\fP (this
2571 list could be extended in the future).
2573 BTF description of the map is mandatory.
2575 The BPF program can take ONE lock at a time, since taking two
2576 or more could cause dead locks.
2578 Only one \fBstruct bpf_spin_lock\fP is allowed per map element.
2580 When the lock is taken, calls (either BPF to BPF or helpers)
2583 The \fBBPF_LD_ABS\fP and \fBBPF_LD_IND\fP instructions are not
2584 allowed inside a spinlock\-ed region.
2586 The BPF program MUST call \fBbpf_spin_unlock\fP() to release
2587 the lock, on all execution paths, before it returns.
2589 The BPF program can access \fBstruct bpf_spin_lock\fP only via
2590 the \fBbpf_spin_lock\fP() and \fBbpf_spin_unlock\fP()
2591 helpers. Loading or storing data into the \fBstruct
2592 bpf_spin_lock\fP \fIlock\fP\fB;\fP field of a map is not allowed.
2594 To use the \fBbpf_spin_lock\fP() helper, the BTF description
2595 of the map value must be a struct and have \fBstruct
2596 bpf_spin_lock\fP \fIanyname\fP\fB;\fP field at the top level.
2597 Nested lock inside another struct is not allowed.
2599 The \fBstruct bpf_spin_lock\fP \fIlock\fP field in a map value must
2600 be aligned on a multiple of 4 bytes in that value.
2602 Syscall with command \fBBPF_MAP_LOOKUP_ELEM\fP does not copy
2603 the \fBbpf_spin_lock\fP field to user space.
2605 Syscall with command \fBBPF_MAP_UPDATE_ELEM\fP, or update from
2606 a BPF program, do not update the \fBbpf_spin_lock\fP field.
2608 \fBbpf_spin_lock\fP cannot be on the stack or inside a
2609 networking packet (it can only be inside of a map values).
2611 \fBbpf_spin_lock\fP is available to root only.
2613 Tracing programs and socket filter programs cannot use
2614 \fBbpf_spin_lock\fP() due to insufficient preemption checks
2615 (but this may change in the future).
2617 \fBbpf_spin_lock\fP is not allowed in inner maps of map\-in\-map.
2624 .B \fBlong bpf_spin_unlock(struct bpf_spin_lock *\fP\fIlock\fP\fB)\fP
2628 Release the \fIlock\fP previously locked by a call to
2629 \fBbpf_spin_lock\fP(\fIlock\fP).
2635 .B \fBstruct bpf_sock *bpf_sk_fullsock(struct bpf_sock *\fP\fIsk\fP\fB)\fP
2639 This helper gets a \fBstruct bpf_sock\fP pointer such
2640 that all the fields in this \fBbpf_sock\fP can be accessed.
2643 A \fBstruct bpf_sock\fP pointer on success, or \fBNULL\fP in
2647 .B \fBstruct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *\fP\fIsk\fP\fB)\fP
2651 This helper gets a \fBstruct bpf_tcp_sock\fP pointer from a
2652 \fBstruct bpf_sock\fP pointer.
2655 A \fBstruct bpf_tcp_sock\fP pointer on success, or \fBNULL\fP in
2659 .B \fBlong bpf_skb_ecn_set_ce(struct sk_buff *\fP\fIskb\fP\fB)\fP
2663 Set ECN (Explicit Congestion Notification) field of IP header
2664 to \fBCE\fP (Congestion Encountered) if current value is \fBECT\fP
2665 (ECN Capable Transport). Otherwise, do nothing. Works with IPv6
2669 1 if the \fBCE\fP flag is set (either by the current helper call
2670 or because it was already present), 0 if it is not set.
2673 .B \fBstruct bpf_sock *bpf_get_listener_sock(struct bpf_sock *\fP\fIsk\fP\fB)\fP
2677 Return a \fBstruct bpf_sock\fP pointer in \fBTCP_LISTEN\fP state.
2678 \fBbpf_sk_release\fP() is unnecessary and not allowed.
2681 A \fBstruct bpf_sock\fP pointer on success, or \fBNULL\fP in
2685 .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
2689 Look for TCP socket matching \fItuple\fP, optionally in a child
2690 network namespace \fInetns\fP\&. The return value must be checked,
2691 and if non\-\fBNULL\fP, released via \fBbpf_sk_release\fP().
2693 This function is identical to \fBbpf_sk_lookup_tcp\fP(), except
2694 that it also returns timewait or request sockets. Use
2695 \fBbpf_sk_fullsock\fP() or \fBbpf_tcp_sock\fP() to access the
2698 This helper is available only if the kernel was compiled with
2699 \fBCONFIG_NET\fP configuration option.
2702 Pointer to \fBstruct bpf_sock\fP, or \fBNULL\fP in case of failure.
2703 For sockets with reuseport option, the \fBstruct bpf_sock\fP
2704 result is from \fIreuse\fP\fB\->socks\fP[] using the hash of the
2708 .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
2712 Check whether \fIiph\fP and \fIth\fP contain a valid SYN cookie ACK for
2713 the listening socket in \fIsk\fP\&.
2715 \fIiph\fP points to the start of the IPv4 or IPv6 header, while
2716 \fIiph_len\fP contains \fBsizeof\fP(\fBstruct iphdr\fP) or
2717 \fBsizeof\fP(\fBstruct ipv6hdr\fP).
2719 \fIth\fP points to the start of the TCP header, while \fIth_len\fP
2720 contains the length of the TCP header (at least
2721 \fBsizeof\fP(\fBstruct tcphdr\fP)).
2724 0 if \fIiph\fP and \fIth\fP are a valid SYN cookie ACK, or a negative
2728 .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
2732 Get name of sysctl in /proc/sys/ and copy it into provided by
2733 program buffer \fIbuf\fP of size \fIbuf_len\fP\&.
2735 The buffer is always NUL terminated, unless it\[aq]s zero\-sized.
2737 If \fIflags\fP is zero, full name (e.g. \[dq]net/ipv4/tcp_mem\[dq]) is
2738 copied. Use \fBBPF_F_SYSCTL_BASE_NAME\fP flag to copy base name
2739 only (e.g. \[dq]tcp_mem\[dq]).
2742 Number of character copied (not including the trailing NUL).
2744 \fB\-E2BIG\fP if the buffer wasn\[aq]t big enough (\fIbuf\fP will contain
2745 truncated name in this case).
2748 .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
2752 Get current value of sysctl as it is presented in /proc/sys
2753 (incl. newline, etc), and copy it as a string into provided
2754 by program buffer \fIbuf\fP of size \fIbuf_len\fP\&.
2756 The whole value is copied, no matter what file position user
2757 space issued e.g. sys_read at.
2759 The buffer is always NUL terminated, unless it\[aq]s zero\-sized.
2762 Number of character copied (not including the trailing NUL).
2764 \fB\-E2BIG\fP if the buffer wasn\[aq]t big enough (\fIbuf\fP will contain
2765 truncated name in this case).
2767 \fB\-EINVAL\fP if current value was unavailable, e.g. because
2768 sysctl is uninitialized and read returns \-EIO for it.
2771 .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
2775 Get new value being written by user space to sysctl (before
2776 the actual write happens) and copy it as a string into
2777 provided by program buffer \fIbuf\fP of size \fIbuf_len\fP\&.
2779 User space may write new value at file position > 0.
2781 The buffer is always NUL terminated, unless it\[aq]s zero\-sized.
2784 Number of character copied (not including the trailing NUL).
2786 \fB\-E2BIG\fP if the buffer wasn\[aq]t big enough (\fIbuf\fP will contain
2787 truncated name in this case).
2789 \fB\-EINVAL\fP if sysctl is being read.
2792 .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
2796 Override new value being written by user space to sysctl with
2797 value provided by program in buffer \fIbuf\fP of size \fIbuf_len\fP\&.
2799 \fIbuf\fP should contain a string in same form as provided by user
2800 space on sysctl write.
2802 User space may write new value at file position > 0. To override
2803 the whole sysctl value file position should be set to zero.
2808 \fB\-E2BIG\fP if the \fIbuf_len\fP is too big.
2810 \fB\-EINVAL\fP if sysctl is being read.
2813 .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
2817 Convert the initial part of the string from buffer \fIbuf\fP of
2818 size \fIbuf_len\fP to a long integer according to the given base
2819 and save the result in \fIres\fP\&.
2821 The string may begin with an arbitrary amount of white space
2822 (as determined by \fBisspace\fP(3)) followed by a single
2823 optional \[aq]\fB\-\fP\[aq] sign.
2825 Five least significant bits of \fIflags\fP encode base, other bits
2826 are currently unused.
2828 Base must be either 8, 10, 16 or 0 to detect it automatically
2829 similar to user space \fBstrtol\fP(3).
2832 Number of characters consumed on success. Must be positive but
2833 no more than \fIbuf_len\fP\&.
2835 \fB\-EINVAL\fP if no valid digits were found or unsupported base
2838 \fB\-ERANGE\fP if resulting value was out of range.
2841 .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
2845 Convert the initial part of the string from buffer \fIbuf\fP of
2846 size \fIbuf_len\fP to an unsigned long integer according to the
2847 given base and save the result in \fIres\fP\&.
2849 The string may begin with an arbitrary amount of white space
2850 (as determined by \fBisspace\fP(3)).
2852 Five least significant bits of \fIflags\fP encode base, other bits
2853 are currently unused.
2855 Base must be either 8, 10, 16 or 0 to detect it automatically
2856 similar to user space \fBstrtoul\fP(3).
2859 Number of characters consumed on success. Must be positive but
2860 no more than \fIbuf_len\fP\&.
2862 \fB\-EINVAL\fP if no valid digits were found or unsupported base
2865 \fB\-ERANGE\fP if resulting value was out of range.
2868 .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
2872 Get a bpf\-local\-storage from a \fIsk\fP\&.
2874 Logically, it could be thought of getting the value from
2875 a \fImap\fP with \fIsk\fP as the \fBkey\fP\&. From this
2876 perspective, the usage is not much different from
2877 \fBbpf_map_lookup_elem\fP(\fImap\fP, \fB&\fP\fIsk\fP) except this
2878 helper enforces the key must be a full socket and the map must
2879 be a \fBBPF_MAP_TYPE_SK_STORAGE\fP also.
2881 Underneath, the value is stored locally at \fIsk\fP instead of
2882 the \fImap\fP\&. The \fImap\fP is used as the bpf\-local\-storage
2883 \[dq]type\[dq]. The bpf\-local\-storage \[dq]type\[dq] (i.e. the \fImap\fP) is
2884 searched against all bpf\-local\-storages residing at \fIsk\fP\&.
2886 \fIsk\fP is a kernel \fBstruct sock\fP pointer for LSM program.
2887 \fIsk\fP is a \fBstruct bpf_sock\fP pointer for other program types.
2889 An optional \fIflags\fP (\fBBPF_SK_STORAGE_GET_F_CREATE\fP) can be
2890 used such that a new bpf\-local\-storage will be
2891 created if one does not exist. \fIvalue\fP can be used
2892 together with \fBBPF_SK_STORAGE_GET_F_CREATE\fP to specify
2893 the initial value of a bpf\-local\-storage. If \fIvalue\fP is
2894 \fBNULL\fP, the new bpf\-local\-storage will be zero initialized.
2897 A bpf\-local\-storage pointer is returned on success.
2899 \fBNULL\fP if not found or there was an error in adding
2900 a new bpf\-local\-storage.
2903 .B \fBlong bpf_sk_storage_delete(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIsk\fP\fB)\fP
2907 Delete a bpf\-local\-storage from a \fIsk\fP\&.
2912 \fB\-ENOENT\fP if the bpf\-local\-storage cannot be found.
2913 \fB\-EINVAL\fP if sk is not a fullsock (e.g. a request_sock).
2916 .B \fBlong bpf_send_signal(u32\fP \fIsig\fP\fB)\fP
2920 Send signal \fIsig\fP to the process of the current task.
2921 The signal may be delivered to any of this process\[aq]s threads.
2924 0 on success or successfully queued.
2926 \fB\-EBUSY\fP if work queue under nmi is full.
2928 \fB\-EINVAL\fP if \fIsig\fP is invalid.
2930 \fB\-EPERM\fP if no permission to send the \fIsig\fP\&.
2932 \fB\-EAGAIN\fP if bpf program can try again.
2935 .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
2939 Try to issue a SYN cookie for the packet with corresponding
2940 IP/TCP headers, \fIiph\fP and \fIth\fP, on the listening socket in \fIsk\fP\&.
2942 \fIiph\fP points to the start of the IPv4 or IPv6 header, while
2943 \fIiph_len\fP contains \fBsizeof\fP(\fBstruct iphdr\fP) or
2944 \fBsizeof\fP(\fBstruct ipv6hdr\fP).
2946 \fIth\fP points to the start of the TCP header, while \fIth_len\fP
2947 contains the length of the TCP header with options (at least
2948 \fBsizeof\fP(\fBstruct tcphdr\fP)).
2951 On success, lower 32 bits hold the generated SYN cookie in
2952 followed by 16 bits which hold the MSS value for that cookie,
2953 and the top 16 bits are unused.
2955 On failure, the returned value is one of the following:
2957 \fB\-EINVAL\fP SYN cookie cannot be issued due to error
2959 \fB\-ENOENT\fP SYN cookie should not be issued (no SYN flood)
2961 \fB\-EOPNOTSUPP\fP kernel configuration does not enable SYN cookies
2963 \fB\-EPROTONOSUPPORT\fP IP packet version is not 4 or 6
2966 .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
2970 Write raw \fIdata\fP blob into a special BPF perf event held by
2971 \fImap\fP of type \fBBPF_MAP_TYPE_PERF_EVENT_ARRAY\fP\&. This perf
2972 event must have the following attributes: \fBPERF_SAMPLE_RAW\fP
2973 as \fBsample_type\fP, \fBPERF_TYPE_SOFTWARE\fP as \fBtype\fP, and
2974 \fBPERF_COUNT_SW_BPF_OUTPUT\fP as \fBconfig\fP\&.
2976 The \fIflags\fP are used to indicate the index in \fImap\fP for which
2977 the value must be put, masked with \fBBPF_F_INDEX_MASK\fP\&.
2978 Alternatively, \fIflags\fP can be set to \fBBPF_F_CURRENT_CPU\fP
2979 to indicate that the index of the current CPU core should be
2982 The value to write, of \fIsize\fP, is passed through eBPF stack and
2983 pointed by \fIdata\fP\&.
2985 \fIctx\fP is a pointer to in\-kernel struct sk_buff.
2987 This helper is similar to \fBbpf_perf_event_output\fP() but
2988 restricted to raw_tracepoint bpf programs.
2991 0 on success, or a negative error in case of failure.
2994 .B \fBlong bpf_probe_read_user(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
2998 Safely attempt to read \fIsize\fP bytes from user space address
2999 \fIunsafe_ptr\fP and store the data in \fIdst\fP\&.
3002 0 on success, or a negative error in case of failure.
3005 .B \fBlong bpf_probe_read_kernel(void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB, const void *\fP\fIunsafe_ptr\fP\fB)\fP
3009 Safely attempt to read \fIsize\fP bytes from kernel space address
3010 \fIunsafe_ptr\fP and store the data in \fIdst\fP\&.
3013 0 on success, or a negative error in case of failure.
3016 .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
3020 Copy a NUL terminated string from an unsafe user address
3021 \fIunsafe_ptr\fP to \fIdst\fP\&. The \fIsize\fP should include the
3022 terminating NUL byte. In case the string length is smaller than
3023 \fIsize\fP, the target is not padded with further NUL bytes. If the
3024 string length is larger than \fIsize\fP, just \fIsize\fP\-1 bytes are
3025 copied and the last byte is set to NUL.
3027 On success, returns the number of bytes that were written,
3028 including the terminal NUL. This makes this helper useful in
3029 tracing programs for reading strings, and more importantly to
3030 get its length at runtime. See the following snippet:
3036 SEC(\[dq]kprobe/sys_open\[dq])
3037 void bpf_sys_open(struct pt_regs *ctx)
3039 char buf[PATHLEN]; // PATHLEN is defined to 256
3040 int res = bpf_probe_read_user_str(buf, sizeof(buf),
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.
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
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.
3064 On success, the strictly positive length of the output string,
3065 including the trailing NUL character. On error, a negative
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
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.
3077 On success, the strictly positive length of the string, including
3078 the trailing NUL character. On error, a negative value.
3081 .B \fBlong bpf_tcp_send_ack(void *\fP\fItp\fP\fB, u32\fP \fIrcv_nxt\fP\fB)\fP
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.
3089 0 on success, or a negative error in case of failure.
3092 .B \fBlong bpf_send_signal_thread(u32\fP \fIsig\fP\fB)\fP
3096 Send signal \fIsig\fP to the thread corresponding to the current task.
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.
3110 .B \fBu64 bpf_jiffies64(void)\fP
3114 Obtain the 64bit jiffies
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
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
3130 On success, number of bytes written to \fIbuf\fP\&. On error, a
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.
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
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\&.
3151 0 on success, or one of the following in case of failure:
3153 \fB\-EINVAL\fP if dev and inum supplied don\[aq]t 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.
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
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
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.
3184 0 on success, or a negative error in case of failure.
3187 .B \fBu64 bpf_get_netns_cookie(void *\fP\fIctx\fP\fB)\fP
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.
3201 A 8\-byte long opaque number.
3204 .B \fBu64 bpf_get_current_ancestor_cgroup_id(int\fP \fIancestor_level\fP\fB)\fP
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().
3223 The id is returned or 0 in case the id could not be retrieved.
3226 .B \fBlong bpf_sk_assign(struct sk_buff *\fP\fIskb\fP\fB, void *\fP\fIsk\fP\fB, u64\fP \fIflags\fP\fB)\fP
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.
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
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
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
3282 \fIflags\fP argument can combination of following values:
3285 \fBBPF_SK_LOOKUP_F_REPLACE\fP to override the previous
3286 socket selection, potentially done by a BPF program
3289 \fBBPF_SK_LOOKUP_F_NO_REUSEPORT\fP to skip
3290 load\-balancing within reuseport group for the socket
3294 On success \fIctx\->sk\fP will point to the selected socket.
3297 0 on success, or a negative errno in case of failure.
3300 \fB\-EAFNOSUPPORT\fP if socket family (\fIsk\->family\fP) is
3301 not compatible with packet family (\fIctx\->family\fP).
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.
3307 \fB\-EINVAL\fP if unsupported flags were specified.
3309 \fB\-EPROTOTYPE\fP if socket L4 protocol
3310 (\fIsk\->protocol\fP) doesn\[aq]t match packet protocol
3311 (\fIctx\->protocol\fP).
3313 \fB\-ESOCKTNOSUPPORT\fP if socket is not in allowed
3314 state (TCP listening or UDP unconnected).
3318 .B \fBu64 bpf_ktime_get_boot_ns(void)\fP
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)
3327 Current \fIktime\fP\&.
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
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.
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.
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
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.
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.
3377 .B \fBu64 bpf_sk_cgroup_id(void *\fP\fIsk\fP\fB)\fP
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.
3392 The id is returned or 0 in case the id could not be retrieved.
3395 .B \fBu64 bpf_sk_ancestor_cgroup_id(void *\fP\fIsk\fP\fB, int\fP \fIancestor_level\fP\fB)\fP
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
3410 The format of returned id and helper limitations are same as in
3411 \fBbpf_sk_cgroup_id\fP().
3414 The id is returned or 0 in case the id could not be retrieved.
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
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.
3435 0 on success, or a negative error in case of failure.
3438 .B \fBvoid *bpf_ringbuf_reserve(void *\fP\fIringbuf\fP\fB, u64\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
3442 Reserve \fIsize\fP bytes of payload in a ring buffer \fIringbuf\fP\&.
3443 \fIflags\fP must be 0.
3446 Valid pointer with \fIsize\fP bytes of memory available; NULL,
3450 .B \fBvoid bpf_ringbuf_submit(void *\fP\fIdata\fP\fB, u64\fP \fIflags\fP\fB)\fP
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 \[aq]bpf_ringbuf_output()\[aq] for the definition of adaptive notification.
3465 Nothing. Always succeeds.
3468 .B \fBvoid bpf_ringbuf_discard(void *\fP\fIdata\fP\fB, u64\fP \fIflags\fP\fB)\fP
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 \[aq]bpf_ringbuf_output()\[aq] for the definition of adaptive notification.
3483 Nothing. Always succeeds.
3486 .B \fBu64 bpf_ringbuf_query(void *\fP\fIringbuf\fP\fB, u64\fP \fIflags\fP\fB)\fP
3490 Query various characteristics of provided ring buffer. What
3491 exactly is queries is determined by \fIflags\fP:
3494 \fBBPF_RB_AVAIL_DATA\fP: Amount of data not yet consumed.
3496 \fBBPF_RB_RING_SIZE\fP: The size of ring buffer.
3498 \fBBPF_RB_CONS_POS\fP: Consumer position (can wrap around).
3500 \fBBPF_RB_PROD_POS\fP: Producer(s) position (can wrap around).
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
3509 Requested value, or 0, if \fIflags\fP are not recognized.
3512 .B \fBlong bpf_csum_level(struct sk_buff *\fP\fIskb\fP\fB, u64\fP \fIlevel\fP\fB)\fP
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:
3533 \fBBPF_CSUM_LEVEL_INC\fP: Increases skb\->csum_level for skbs
3534 with CHECKSUM_UNNECESSARY.
3536 \fBBPF_CSUM_LEVEL_DEC\fP: Decreases skb\->csum_level for skbs
3537 with CHECKSUM_UNNECESSARY.
3539 \fBBPF_CSUM_LEVEL_RESET\fP: Resets skb\->csum_level to 0 and
3540 sets CHECKSUM_NONE to force checksum validation by the stack.
3542 \fBBPF_CSUM_LEVEL_QUERY\fP: No\-op, returns the current
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.
3553 .B \fBstruct tcp6_sock *bpf_skc_to_tcp6_sock(void *\fP\fIsk\fP\fB)\fP
3557 Dynamically cast a \fIsk\fP pointer to a \fItcp6_sock\fP pointer.
3560 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
3563 .B \fBstruct tcp_sock *bpf_skc_to_tcp_sock(void *\fP\fIsk\fP\fB)\fP
3567 Dynamically cast a \fIsk\fP pointer to a \fItcp_sock\fP pointer.
3570 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
3573 .B \fBstruct tcp_timewait_sock *bpf_skc_to_tcp_timewait_sock(void *\fP\fIsk\fP\fB)\fP
3577 Dynamically cast a \fIsk\fP pointer to a \fItcp_timewait_sock\fP pointer.
3580 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
3583 .B \fBstruct tcp_request_sock *bpf_skc_to_tcp_request_sock(void *\fP\fIsk\fP\fB)\fP
3587 Dynamically cast a \fIsk\fP pointer to a \fItcp_request_sock\fP pointer.
3590 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
3593 .B \fBstruct udp6_sock *bpf_skc_to_udp6_sock(void *\fP\fIsk\fP\fB)\fP
3597 Dynamically cast a \fIsk\fP pointer to a \fIudp6_sock\fP pointer.
3600 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
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
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:
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.
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:
3637 # sysctl kernel.perf_event_max_stack=<new value>
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.
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
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 \[dq]magic\[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 \[dq]kind\-length\[dq] of a TCP
3669 header option and the \[dq]kind\-length\[dq] also
3670 includes the first 2 bytes \[dq]kind\[dq] and \[dq]kind\-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
3684 \fIlen\fP must be at least 2 bytes which is the minimal size
3690 \fBBPF_LOAD_HDR_OPT_TCP_SYN\fP to search from the
3691 saved_syn packet or the just\-received syn packet.
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
3709 \fB\-EFAULT\fP on failure to parse the header options in the
3712 \fB\-EPERM\fP if the helper cannot be used under the current
3713 \fIskops\fP\fB\->op\fP\&.
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
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\&.
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\&.
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
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\&.
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\&.
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
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 \[dq]type\[dq]. The bpf\-local\-storage \[dq]type\[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.
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.
3809 .B \fBint bpf_inode_storage_delete(struct bpf_map *\fP\fImap\fP\fB, void *\fP\fIinode\fP\fB)\fP
3813 Delete a bpf_local_storage from an \fIinode\fP\&.
3818 \fB\-ENOENT\fP if the bpf_local_storage cannot be found.
3821 .B \fBlong bpf_d_path(struct path *\fP\fIpath\fP\fB, char *\fP\fIbuf\fP\fB, u32\fP \fIsz\fP\fB)\fP
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
3831 On success, the strictly positive length of the string,
3832 including the trailing NUL character. On error, a negative
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
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().
3844 0 on success, or a negative error in case of failure.
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
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
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
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.
3881 show zero\-valued struct/union members; they
3882 are not displayed by default
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.
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
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.
3900 0 on success or a negative error in case of failure.
3903 .B \fBu64 bpf_skb_cgroup_classid(struct sk_buff *\fP\fIskb\fP\fB)\fP
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\[aq]s
3910 associated socket instead of the current process.
3913 The id is returned or 0 in case the id could not be retrieved.
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
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\[aq]s
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.
3937 The helper returns \fBTC_ACT_REDIRECT\fP on success or
3938 \fBTC_ACT_SHOT\fP on error.
3941 .B \fBvoid *bpf_per_cpu_ptr(const void *\fP\fIpercpu_ptr\fP\fB, u32\fP \fIcpu\fP\fB)\fP
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.
3958 A pointer pointing to the kernel percpu variable on \fIcpu\fP, or
3959 NULL, if \fIcpu\fP is invalid.
3962 .B \fBvoid *bpf_this_cpu_ptr(const void *\fP\fIpercpu_ptr\fP\fB)\fP
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 \[aq]ksym\[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
3975 A pointer pointing to the kernel percpu variable on this cpu.
3978 .B \fBlong bpf_redirect_peer(u32\fP \fIifindex\fP\fB, u64\fP \fIflags\fP\fB)\fP
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\[aq]s 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.
3994 The helper returns \fBTC_ACT_REDIRECT\fP on success or
3995 \fBTC_ACT_SHOT\fP on error.
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
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 \[dq]type\[dq]. The bpf\-local\-storage \[dq]type\[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.
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.
4030 .B \fBlong bpf_task_storage_delete(struct bpf_map *\fP\fImap\fP\fB, struct task_struct *\fP\fItask\fP\fB)\fP
4034 Delete a bpf_local_storage from a \fItask\fP\&.
4039 \fB\-ENOENT\fP if the bpf_local_storage cannot be found.
4042 .B \fBstruct task_struct *bpf_get_current_task_btf(void)\fP
4046 Return a BTF pointer to the \[dq]current\[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\&.
4051 Pointer to the current task.
4054 .B \fBlong bpf_bprm_opts_set(struct linux_binprm *\fP\fIbprm\fP\fB, u64\fP \fIflags\fP\fB)\fP
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.
4065 \fB\-EINVAL\fP if invalid \fIflags\fP are passed, zero otherwise.
4068 .B \fBu64 bpf_ktime_get_coarse_ns(void)\fP
4072 Return a coarse\-grained version of the time elapsed since
4073 system boot, in nanoseconds. Does not include time the system
4076 See: \fBclock_gettime\fP(\fBCLOCK_MONOTONIC_COARSE\fP)
4079 Current \fIktime\fP\&.
4082 .B \fBlong bpf_ima_inode_hash(struct inode *\fP\fIinode\fP\fB, void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB)\fP
4086 Returns the stored IMA hash of the \fIinode\fP (if it\[aq]s available).
4087 If the hash is larger than \fIsize\fP, then only \fIsize\fP
4088 bytes will be copied to \fIdst\fP
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.
4096 .B \fBstruct socket *bpf_sock_from_file(struct file *\fP\fIfile\fP\fB)\fP
4100 If the given file represents a socket, returns the associated
4104 A pointer to a struct socket on success or NULL if the file is
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
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\[aq]t
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()
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
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.
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.
4170 0 on success, and populate MTU value in \fImtu_len\fP pointer.
4172 < 0 if any input argument is invalid (\fImtu_len\fP not updated)
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:
4180 \fBBPF_MTU_CHK_RET_FRAG_NEEDED\fP
4182 \fBBPF_MTU_CHK_RET_SEGS_TOOBIG\fP
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
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.
4214 The number of traversed map elements for success, \fB\-EINVAL\fP for
4215 invalid \fBflags\fP\&.
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
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
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
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.
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.
4249 .B \fBlong bpf_sys_bpf(u32\fP \fIcmd\fP\fB, void *\fP\fIattr\fP\fB, u32\fP \fIattr_size\fP\fB)\fP
4253 Execute bpf syscall with given arguments.
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
4263 Find BTF type with given name and kind in vmlinux BTF or in module\[aq]s BTFs.
4266 Returns btf_id and btf_obj_fd in lower and upper 32 bits.
4269 .B \fBlong bpf_sys_close(u32\fP \fIfd\fP\fB)\fP
4273 Execute close syscall for given FD.
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
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\&.
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\[aq]t 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.
4300 .B \fBlong bpf_timer_set_callback(struct bpf_timer *\fP\fItimer\fP\fB, void *\fP\fIcallback_fn\fP\fB)\fP
4304 Configure the timer to call \fIcallback_fn\fP static function.
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\[aq]t 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.
4315 .B \fBlong bpf_timer_start(struct bpf_timer *\fP\fItimer\fP\fB, u64\fP \fInsecs\fP\fB, u64\fP \fIflags\fP\fB)\fP
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\[aq]s refcnts are
4328 decremented. This is done to make sure that Ctrl\-C of a user
4329 process doesn\[aq]t 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.
4340 \fB\-EINVAL\fP if \fItimer\fP was not initialized with bpf_timer_init() earlier
4341 or invalid \fIflags\fP are passed.
4344 .B \fBlong bpf_timer_cancel(struct bpf_timer *\fP\fItimer\fP\fB)\fP
4348 Cancel the timer and wait for callback_fn to finish if it was running.
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.
4358 .B \fBu64 bpf_get_func_ip(void *\fP\fIctx\fP\fB)\fP
4362 Get address of the traced function (for tracing and kprobe programs).
4365 Address of the traced function.
4366 0 for kprobes placed within the function (not at the entry).
4369 .B \fBu64 bpf_get_attach_cookie(void *\fP\fIctx\fP\fB)\fP
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.
4379 .B Supported for the following program types:
4391 Value specified by user at BPF link creation/attachment time
4392 or 0, if it was not specified.
4395 .B \fBlong bpf_task_pt_regs(struct task_struct *\fP\fItask\fP\fB)\fP
4399 Get the struct pt_regs associated with \fBtask\fP\&.
4402 A pointer to struct pt_regs.
4405 .B \fBlong bpf_get_branch_snapshot(void *\fP\fIentries\fP\fB, u32\fP \fIsize\fP\fB, u64\fP \fIflags\fP\fB)\fP
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.
4421 On success, number of bytes written to \fIbuf\fP\&. On error, a
4424 \fB\-EINVAL\fP if \fIflags\fP is not zero.
4426 \fB\-ENOENT\fP if architecture does not support branch records.
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
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.
4439 The number of bytes written to the buffer, or a negative error
4443 .B \fBstruct unix_sock *bpf_skc_to_unix_sock(void *\fP\fIsk\fP\fB)\fP
4447 Dynamically cast a \fIsk\fP pointer to a \fIunix_sock\fP pointer.
4450 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
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
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.
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.
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
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);
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\&.
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
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
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.
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.
4521 .B \fBlong bpf_strncmp(const char *\fP\fIs1\fP\fB, u32\fP \fIs1_sz\fP\fB, const char *\fP\fIs2\fP\fB)\fP
4525 Do strncmp() between \fBs1\fP and \fBs2\fP\&. \fBs1\fP doesn\[aq]t 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.
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\&.
4535 .B \fBlong bpf_get_func_arg(void *\fP\fIctx\fP\fB, u32\fP \fIn\fP\fB, u64 *\fP\fIvalue\fP\fB)\fP
4539 Get \fBn\fP\-th argument register (zero based) of the traced function (for tracing programs)
4540 returned in \fBvalue\fP\&.
4544 \fB\-EINVAL\fP if n >= argument register count of traced function.
4547 .B \fBlong bpf_get_func_ret(void *\fP\fIctx\fP\fB, u64 *\fP\fIvalue\fP\fB)\fP
4551 Get return value of the traced function (for tracing programs)
4556 \fB\-EOPNOTSUPP\fP for tracing programs other than BPF_TRACE_FEXIT or BPF_MODIFY_RETURN.
4559 .B \fBlong bpf_get_func_arg_cnt(void *\fP\fIctx\fP\fB)\fP
4563 Get number of registers of the traced function (for tracing programs) where
4564 function arguments are stored in these registers.
4567 The number of argument registers of the traced function.
4570 .B \fBint bpf_get_retval(void)\fP
4574 Get the BPF program\[aq]s 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\[aq]s return value is returned to the userspace via errno.
4580 The BPF program\[aq]s return value.
4583 .B \fBint bpf_set_retval(int\fP \fIretval\fP\fB)\fP
4587 Set the BPF program\[aq]s 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\[aq]s 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 \[aq]return 1\[aq]:
4596 bpf_set_retval(\-EPERM);
4601 In this case, the BPF program\[aq]s return value will use helper\[aq]s \-EPERM. This
4602 still holds true for cgroup/bind{4,6} which supports extra \[aq]return 3\[aq] success case.
4605 0 on success, or a negative error in case of failure.
4608 .B \fBu64 bpf_xdp_get_buff_len(struct xdp_buff *\fP\fIxdp_md\fP\fB)\fP
4612 Get the total size of a given xdp buff (linear and paged area)
4615 The total size of a given xdp buffer.
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
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
4628 0 on success, or a negative error in case of failure.
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
4635 Store \fIlen\fP bytes from buffer \fIbuf\fP into the frame
4636 associated to \fIxdp_md\fP, at \fIoffset\fP\&.
4639 0 on success, or a negative error in case of failure.
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
4646 Read \fIsize\fP bytes from user space address \fIuser_ptr\fP in \fItsk\fP\[aq]s
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.
4652 0 on success, or a negative error in case of failure. On error
4653 \fIdst\fP buffer is zeroed out.
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
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
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\&.
4686 \fB\-EINVAL\fP for invalid input
4687 \fB\-EOPNOTSUPP\fP for unsupported protocol
4690 .B \fBlong bpf_ima_file_hash(struct file *\fP\fIfile\fP\fB, void *\fP\fIdst\fP\fB, u32\fP \fIsize\fP\fB)\fP
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
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.
4704 .B \fBvoid *bpf_kptr_xchg(void *\fP\fImap_value\fP\fB, void *\fP\fIptr\fP\fB)\fP
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.
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
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
4723 Perform a lookup in \fIpercpu map\fP for an entry associated to
4724 \fIkey\fP on \fIcpu\fP\&.
4727 Map value associated to \fIkey\fP on \fIcpu\fP, or \fBNULL\fP if no entry
4728 was found or \fIcpu\fP is invalid.
4731 .B \fBstruct mptcp_sock *bpf_skc_to_mptcp_sock(void *\fP\fIsk\fP\fB)\fP
4735 Dynamically cast a \fIsk\fP pointer to a \fImptcp_sock\fP pointer.
4738 \fIsk\fP if casting is valid, or \fBNULL\fP otherwise.
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
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.
4752 0 on success, \-E2BIG if the size exceeds DYNPTR_MAX_SIZE,
4753 \-EINVAL if flags is not 0.
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
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.
4768 0 on success, or a negative error in case of failure.
4771 .B \fBvoid bpf_ringbuf_submit_dynptr(struct bpf_dynptr *\fP\fIptr\fP\fB, u64\fP \fIflags\fP\fB)\fP
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
4779 For more information on \fIflags\fP, please see
4780 \[aq]bpf_ringbuf_submit\[aq].
4783 Nothing. Always succeeds.
4786 .B \fBvoid bpf_ringbuf_discard_dynptr(struct bpf_dynptr *\fP\fIptr\fP\fB, u64\fP \fIflags\fP\fB)\fP
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 \[aq]bpf_ringbuf_discard\[aq].
4797 Nothing. Always succeeds.
4800 .B \fBlong bpf_dynptr_read(void *\fP\fIdst\fP\fB, u32\fP \fIlen\fP\fB, struct bpf_dynptr *\fP\fIsrc\fP\fB, u32\fP \fIoffset\fP\fB, u64\fP \fIflags\fP\fB)\fP
4804 Read \fIlen\fP bytes from \fIsrc\fP into \fIdst\fP, starting from \fIoffset\fP
4806 \fIflags\fP is currently unused.
4809 0 on success, \-E2BIG if \fIoffset\fP + \fIlen\fP exceeds the length
4810 of \fIsrc\fP\[aq]s data, \-EINVAL if \fIsrc\fP is an invalid dynptr or if
4811 \fIflags\fP is not 0.
4814 .B \fBlong bpf_dynptr_write(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
4818 Write \fIlen\fP bytes from \fIsrc\fP into \fIdst\fP, starting from \fIoffset\fP
4820 \fIflags\fP is currently unused.
4823 0 on success, \-E2BIG if \fIoffset\fP + \fIlen\fP exceeds the length
4824 of \fIdst\fP\[aq]s 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.
4828 .B \fBvoid *bpf_dynptr_data(struct bpf_dynptr *\fP\fIptr\fP\fB, u32\fP \fIoffset\fP\fB, u32\fP \fIlen\fP\fB)\fP
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.
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
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
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
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)).
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.
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
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
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)).
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.
4893 .B \fBlong bpf_tcp_raw_check_syncookie_ipv4(struct iphdr *\fP\fIiph\fP\fB, struct tcphdr *\fP\fIth\fP\fB)\fP
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.
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.
4912 .B \fBlong bpf_tcp_raw_check_syncookie_ipv6(struct ipv6hdr *\fP\fIiph\fP\fB, struct tcphdr *\fP\fIth\fP\fB)\fP
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.
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.
4933 .B \fBu64 bpf_ktime_get_tai_ns(void)\fP
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)
4945 Current \fIktime\fP\&.
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
4952 Drain samples from the specified user ring buffer, and invoke
4953 the provided callback for each such sample:
4955 long (*callback_fn)(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
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.
4992 Example usage for most of the eBPF helpers listed in this manual page are
4993 available within the Linux kernel sources, at the following locations:
4998 \fItools/testing/selftests/bpf/\fP
5002 eBPF programs can have an associated license, passed along with the bytecode
5003 instructions to the kernel when the programs are loaded. The format for that
5004 string is identical to the one in use for kernel modules (Dual licenses, such
5005 as \[dq]Dual BSD/GPL\[dq], may be used). Some helper functions are only accessible to
5006 programs that are compatible with the GNU Privacy License (GPL).
5008 In order to use such helpers, the eBPF program must be loaded with the correct
5009 license string passed (via \fBattr\fP) to the \fBbpf\fP() system call, and this
5010 generally translates into the C source code of the program containing a line
5011 similar to the following:
5017 char ____license[] __attribute__((section(\[dq]license\[dq]), used)) = \[dq]GPL\[dq];
5024 This manual page is an effort to document the existing eBPF helper functions.
5025 But as of this writing, the BPF sub\-system is under heavy development. New eBPF
5026 program or map types are added, along with new helper functions. Some helpers
5027 are occasionally made available for additional program types. So in spite of
5028 the efforts of the community, this page might not be up\-to\-date. If you want to
5029 check by yourself what helper functions exist in your kernel, or what types of
5030 programs they can support, here are some files among the kernel tree that you
5031 may be interested in:
5034 \fIinclude/uapi/linux/bpf.h\fP is the main BPF header. It contains the full list
5035 of all helper functions, as well as many other BPF definitions including most
5036 of the flags, structs or constants used by the helpers.
5038 \fInet/core/filter.c\fP contains the definition of most network\-related helper
5039 functions, and the list of program types from which they can be used.
5041 \fIkernel/trace/bpf_trace.c\fP is the equivalent for most tracing program\-related
5044 \fIkernel/bpf/verifier.c\fP contains the functions used to check that valid types
5045 of eBPF maps are used with a given helper function.
5047 \fIkernel/bpf/\fP directory contains other files in which additional helpers are
5048 defined (for cgroups, sockmaps, etc.).
5050 The bpftool utility can be used to probe the availability of helper functions
5051 on the system (as well as supported program and map types, and a number of
5052 other parameters). To do so, run \fBbpftool feature probe\fP (see
5053 \fBbpftool\-feature\fP(8) for details). Add the \fBunprivileged\fP keyword to
5054 list features available to unprivileged users.
5057 Compatibility between helper functions and program types can generally be found
5058 in the files where helper functions are defined. Look for the \fBstruct
5059 bpf_func_proto\fP objects and for functions returning them: these functions
5060 contain a list of helpers that a given program type can call. Note that the
5061 \fBdefault:\fP label of the \fBswitch ... case\fP used to filter helpers can call
5062 other functions, themselves allowing access to additional helpers. The
5063 requirement for GPL license is also in those \fBstruct bpf_func_proto\fP\&.
5065 Compatibility between helper functions and map types can be found in the
5066 \fBcheck_map_func_compatibility\fP() function in file \fIkernel/bpf/verifier.c\fP\&.
5068 Helper functions that invalidate the checks on \fBdata\fP and \fBdata_end\fP
5069 pointers for network processing are listed in function
5070 \fBbpf_helper_changes_pkt_data\fP() in file \fInet/core/filter.c\fP\&.
5077 \fBperf_event_open\fP(2),
5081 .\" Generated by docutils manpage writer.