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