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