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