1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of version 2 of the GNU General Public 6 * License as published by the Free Software Foundation. 7 */ 8 #ifndef _UAPI__LINUX_BPF_H__ 9 #define _UAPI__LINUX_BPF_H__ 10 11 #include <linux/types.h> 12 #include <linux/bpf_common.h> 13 14 /* Extended instruction set based on top of classic BPF */ 15 16 /* instruction classes */ 17 #define BPF_ALU64 0x07 /* alu mode in double word width */ 18 19 /* ld/ldx fields */ 20 #define BPF_DW 0x18 /* double word */ 21 #define BPF_XADD 0xc0 /* exclusive add */ 22 23 /* alu/jmp fields */ 24 #define BPF_MOV 0xb0 /* mov reg to reg */ 25 #define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */ 26 27 /* change endianness of a register */ 28 #define BPF_END 0xd0 /* flags for endianness conversion: */ 29 #define BPF_TO_LE 0x00 /* convert to little-endian */ 30 #define BPF_TO_BE 0x08 /* convert to big-endian */ 31 #define BPF_FROM_LE BPF_TO_LE 32 #define BPF_FROM_BE BPF_TO_BE 33 34 /* jmp encodings */ 35 #define BPF_JNE 0x50 /* jump != */ 36 #define BPF_JLT 0xa0 /* LT is unsigned, '<' */ 37 #define BPF_JLE 0xb0 /* LE is unsigned, '<=' */ 38 #define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */ 39 #define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */ 40 #define BPF_JSLT 0xc0 /* SLT is signed, '<' */ 41 #define BPF_JSLE 0xd0 /* SLE is signed, '<=' */ 42 #define BPF_CALL 0x80 /* function call */ 43 #define BPF_EXIT 0x90 /* function return */ 44 45 /* Register numbers */ 46 enum { 47 BPF_REG_0 = 0, 48 BPF_REG_1, 49 BPF_REG_2, 50 BPF_REG_3, 51 BPF_REG_4, 52 BPF_REG_5, 53 BPF_REG_6, 54 BPF_REG_7, 55 BPF_REG_8, 56 BPF_REG_9, 57 BPF_REG_10, 58 __MAX_BPF_REG, 59 }; 60 61 /* BPF has 10 general purpose 64-bit registers and stack frame. */ 62 #define MAX_BPF_REG __MAX_BPF_REG 63 64 struct bpf_insn { 65 __u8 code; /* opcode */ 66 __u8 dst_reg:4; /* dest register */ 67 __u8 src_reg:4; /* source register */ 68 __s16 off; /* signed offset */ 69 __s32 imm; /* signed immediate constant */ 70 }; 71 72 /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */ 73 struct bpf_lpm_trie_key { 74 __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */ 75 __u8 data[0]; /* Arbitrary size */ 76 }; 77 78 /* BPF syscall commands, see bpf(2) man-page for details. */ 79 enum bpf_cmd { 80 BPF_MAP_CREATE, 81 BPF_MAP_LOOKUP_ELEM, 82 BPF_MAP_UPDATE_ELEM, 83 BPF_MAP_DELETE_ELEM, 84 BPF_MAP_GET_NEXT_KEY, 85 BPF_PROG_LOAD, 86 BPF_OBJ_PIN, 87 BPF_OBJ_GET, 88 BPF_PROG_ATTACH, 89 BPF_PROG_DETACH, 90 BPF_PROG_TEST_RUN, 91 BPF_PROG_GET_NEXT_ID, 92 BPF_MAP_GET_NEXT_ID, 93 BPF_PROG_GET_FD_BY_ID, 94 BPF_MAP_GET_FD_BY_ID, 95 BPF_OBJ_GET_INFO_BY_FD, 96 }; 97 98 enum bpf_map_type { 99 BPF_MAP_TYPE_UNSPEC, 100 BPF_MAP_TYPE_HASH, 101 BPF_MAP_TYPE_ARRAY, 102 BPF_MAP_TYPE_PROG_ARRAY, 103 BPF_MAP_TYPE_PERF_EVENT_ARRAY, 104 BPF_MAP_TYPE_PERCPU_HASH, 105 BPF_MAP_TYPE_PERCPU_ARRAY, 106 BPF_MAP_TYPE_STACK_TRACE, 107 BPF_MAP_TYPE_CGROUP_ARRAY, 108 BPF_MAP_TYPE_LRU_HASH, 109 BPF_MAP_TYPE_LRU_PERCPU_HASH, 110 BPF_MAP_TYPE_LPM_TRIE, 111 BPF_MAP_TYPE_ARRAY_OF_MAPS, 112 BPF_MAP_TYPE_HASH_OF_MAPS, 113 BPF_MAP_TYPE_DEVMAP, 114 BPF_MAP_TYPE_SOCKMAP, 115 }; 116 117 enum bpf_prog_type { 118 BPF_PROG_TYPE_UNSPEC, 119 BPF_PROG_TYPE_SOCKET_FILTER, 120 BPF_PROG_TYPE_KPROBE, 121 BPF_PROG_TYPE_SCHED_CLS, 122 BPF_PROG_TYPE_SCHED_ACT, 123 BPF_PROG_TYPE_TRACEPOINT, 124 BPF_PROG_TYPE_XDP, 125 BPF_PROG_TYPE_PERF_EVENT, 126 BPF_PROG_TYPE_CGROUP_SKB, 127 BPF_PROG_TYPE_CGROUP_SOCK, 128 BPF_PROG_TYPE_LWT_IN, 129 BPF_PROG_TYPE_LWT_OUT, 130 BPF_PROG_TYPE_LWT_XMIT, 131 BPF_PROG_TYPE_SOCK_OPS, 132 BPF_PROG_TYPE_SK_SKB, 133 }; 134 135 enum bpf_attach_type { 136 BPF_CGROUP_INET_INGRESS, 137 BPF_CGROUP_INET_EGRESS, 138 BPF_CGROUP_INET_SOCK_CREATE, 139 BPF_CGROUP_SOCK_OPS, 140 BPF_SK_SKB_STREAM_PARSER, 141 BPF_SK_SKB_STREAM_VERDICT, 142 __MAX_BPF_ATTACH_TYPE 143 }; 144 145 #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE 146 147 /* If BPF_F_ALLOW_OVERRIDE flag is used in BPF_PROG_ATTACH command 148 * to the given target_fd cgroup the descendent cgroup will be able to 149 * override effective bpf program that was inherited from this cgroup 150 */ 151 #define BPF_F_ALLOW_OVERRIDE (1U << 0) 152 153 /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the 154 * verifier will perform strict alignment checking as if the kernel 155 * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set, 156 * and NET_IP_ALIGN defined to 2. 157 */ 158 #define BPF_F_STRICT_ALIGNMENT (1U << 0) 159 160 #define BPF_PSEUDO_MAP_FD 1 161 162 /* flags for BPF_MAP_UPDATE_ELEM command */ 163 #define BPF_ANY 0 /* create new element or update existing */ 164 #define BPF_NOEXIST 1 /* create new element if it didn't exist */ 165 #define BPF_EXIST 2 /* update existing element */ 166 167 /* flags for BPF_MAP_CREATE command */ 168 #define BPF_F_NO_PREALLOC (1U << 0) 169 /* Instead of having one common LRU list in the 170 * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list 171 * which can scale and perform better. 172 * Note, the LRU nodes (including free nodes) cannot be moved 173 * across different LRU lists. 174 */ 175 #define BPF_F_NO_COMMON_LRU (1U << 1) 176 /* Specify numa node during map creation */ 177 #define BPF_F_NUMA_NODE (1U << 2) 178 179 /* Flags for accessing BPF object */ 180 #define BPF_F_RDONLY (1U << 3) 181 #define BPF_F_WRONLY (1U << 4) 182 183 union bpf_attr { 184 struct { /* anonymous struct used by BPF_MAP_CREATE command */ 185 __u32 map_type; /* one of enum bpf_map_type */ 186 __u32 key_size; /* size of key in bytes */ 187 __u32 value_size; /* size of value in bytes */ 188 __u32 max_entries; /* max number of entries in a map */ 189 __u32 map_flags; /* BPF_MAP_CREATE related 190 * flags defined above. 191 */ 192 __u32 inner_map_fd; /* fd pointing to the inner map */ 193 __u32 numa_node; /* numa node (effective only if 194 * BPF_F_NUMA_NODE is set). 195 */ 196 }; 197 198 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ 199 __u32 map_fd; 200 __aligned_u64 key; 201 union { 202 __aligned_u64 value; 203 __aligned_u64 next_key; 204 }; 205 __u64 flags; 206 }; 207 208 struct { /* anonymous struct used by BPF_PROG_LOAD command */ 209 __u32 prog_type; /* one of enum bpf_prog_type */ 210 __u32 insn_cnt; 211 __aligned_u64 insns; 212 __aligned_u64 license; 213 __u32 log_level; /* verbosity level of verifier */ 214 __u32 log_size; /* size of user buffer */ 215 __aligned_u64 log_buf; /* user supplied buffer */ 216 __u32 kern_version; /* checked when prog_type=kprobe */ 217 __u32 prog_flags; 218 }; 219 220 struct { /* anonymous struct used by BPF_OBJ_* commands */ 221 __aligned_u64 pathname; 222 __u32 bpf_fd; 223 __u32 file_flags; 224 }; 225 226 struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */ 227 __u32 target_fd; /* container object to attach to */ 228 __u32 attach_bpf_fd; /* eBPF program to attach */ 229 __u32 attach_type; 230 __u32 attach_flags; 231 }; 232 233 struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */ 234 __u32 prog_fd; 235 __u32 retval; 236 __u32 data_size_in; 237 __u32 data_size_out; 238 __aligned_u64 data_in; 239 __aligned_u64 data_out; 240 __u32 repeat; 241 __u32 duration; 242 } test; 243 244 struct { /* anonymous struct used by BPF_*_GET_*_ID */ 245 union { 246 __u32 start_id; 247 __u32 prog_id; 248 __u32 map_id; 249 }; 250 __u32 next_id; 251 __u32 open_flags; 252 }; 253 254 struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */ 255 __u32 bpf_fd; 256 __u32 info_len; 257 __aligned_u64 info; 258 } info; 259 } __attribute__((aligned(8))); 260 261 /* BPF helper function descriptions: 262 * 263 * void *bpf_map_lookup_elem(&map, &key) 264 * Return: Map value or NULL 265 * 266 * int bpf_map_update_elem(&map, &key, &value, flags) 267 * Return: 0 on success or negative error 268 * 269 * int bpf_map_delete_elem(&map, &key) 270 * Return: 0 on success or negative error 271 * 272 * int bpf_probe_read(void *dst, int size, void *src) 273 * Return: 0 on success or negative error 274 * 275 * u64 bpf_ktime_get_ns(void) 276 * Return: current ktime 277 * 278 * int bpf_trace_printk(const char *fmt, int fmt_size, ...) 279 * Return: length of buffer written or negative error 280 * 281 * u32 bpf_prandom_u32(void) 282 * Return: random value 283 * 284 * u32 bpf_raw_smp_processor_id(void) 285 * Return: SMP processor ID 286 * 287 * int bpf_skb_store_bytes(skb, offset, from, len, flags) 288 * store bytes into packet 289 * @skb: pointer to skb 290 * @offset: offset within packet from skb->mac_header 291 * @from: pointer where to copy bytes from 292 * @len: number of bytes to store into packet 293 * @flags: bit 0 - if true, recompute skb->csum 294 * other bits - reserved 295 * Return: 0 on success or negative error 296 * 297 * int bpf_l3_csum_replace(skb, offset, from, to, flags) 298 * recompute IP checksum 299 * @skb: pointer to skb 300 * @offset: offset within packet where IP checksum is located 301 * @from: old value of header field 302 * @to: new value of header field 303 * @flags: bits 0-3 - size of header field 304 * other bits - reserved 305 * Return: 0 on success or negative error 306 * 307 * int bpf_l4_csum_replace(skb, offset, from, to, flags) 308 * recompute TCP/UDP checksum 309 * @skb: pointer to skb 310 * @offset: offset within packet where TCP/UDP checksum is located 311 * @from: old value of header field 312 * @to: new value of header field 313 * @flags: bits 0-3 - size of header field 314 * bit 4 - is pseudo header 315 * other bits - reserved 316 * Return: 0 on success or negative error 317 * 318 * int bpf_tail_call(ctx, prog_array_map, index) 319 * jump into another BPF program 320 * @ctx: context pointer passed to next program 321 * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY 322 * @index: 32-bit index inside array that selects specific program to run 323 * Return: 0 on success or negative error 324 * 325 * int bpf_clone_redirect(skb, ifindex, flags) 326 * redirect to another netdev 327 * @skb: pointer to skb 328 * @ifindex: ifindex of the net device 329 * @flags: bit 0 - if set, redirect to ingress instead of egress 330 * other bits - reserved 331 * Return: 0 on success or negative error 332 * 333 * u64 bpf_get_current_pid_tgid(void) 334 * Return: current->tgid << 32 | current->pid 335 * 336 * u64 bpf_get_current_uid_gid(void) 337 * Return: current_gid << 32 | current_uid 338 * 339 * int bpf_get_current_comm(char *buf, int size_of_buf) 340 * stores current->comm into buf 341 * Return: 0 on success or negative error 342 * 343 * u32 bpf_get_cgroup_classid(skb) 344 * retrieve a proc's classid 345 * @skb: pointer to skb 346 * Return: classid if != 0 347 * 348 * int bpf_skb_vlan_push(skb, vlan_proto, vlan_tci) 349 * Return: 0 on success or negative error 350 * 351 * int bpf_skb_vlan_pop(skb) 352 * Return: 0 on success or negative error 353 * 354 * int bpf_skb_get_tunnel_key(skb, key, size, flags) 355 * int bpf_skb_set_tunnel_key(skb, key, size, flags) 356 * retrieve or populate tunnel metadata 357 * @skb: pointer to skb 358 * @key: pointer to 'struct bpf_tunnel_key' 359 * @size: size of 'struct bpf_tunnel_key' 360 * @flags: room for future extensions 361 * Return: 0 on success or negative error 362 * 363 * u64 bpf_perf_event_read(map, flags) 364 * read perf event counter value 365 * @map: pointer to perf_event_array map 366 * @flags: index of event in the map or bitmask flags 367 * Return: value of perf event counter read or error code 368 * 369 * int bpf_redirect(ifindex, flags) 370 * redirect to another netdev 371 * @ifindex: ifindex of the net device 372 * @flags: 373 * cls_bpf: 374 * bit 0 - if set, redirect to ingress instead of egress 375 * other bits - reserved 376 * xdp_bpf: 377 * all bits - reserved 378 * Return: cls_bpf: TC_ACT_REDIRECT on success or TC_ACT_SHOT on error 379 * xdp_bfp: XDP_REDIRECT on success or XDP_ABORT on error 380 * int bpf_redirect_map(map, key, flags) 381 * redirect to endpoint in map 382 * @map: pointer to dev map 383 * @key: index in map to lookup 384 * @flags: -- 385 * Return: XDP_REDIRECT on success or XDP_ABORT on error 386 * 387 * u32 bpf_get_route_realm(skb) 388 * retrieve a dst's tclassid 389 * @skb: pointer to skb 390 * Return: realm if != 0 391 * 392 * int bpf_perf_event_output(ctx, map, flags, data, size) 393 * output perf raw sample 394 * @ctx: struct pt_regs* 395 * @map: pointer to perf_event_array map 396 * @flags: index of event in the map or bitmask flags 397 * @data: data on stack to be output as raw data 398 * @size: size of data 399 * Return: 0 on success or negative error 400 * 401 * int bpf_get_stackid(ctx, map, flags) 402 * walk user or kernel stack and return id 403 * @ctx: struct pt_regs* 404 * @map: pointer to stack_trace map 405 * @flags: bits 0-7 - numer of stack frames to skip 406 * bit 8 - collect user stack instead of kernel 407 * bit 9 - compare stacks by hash only 408 * bit 10 - if two different stacks hash into the same stackid 409 * discard old 410 * other bits - reserved 411 * Return: >= 0 stackid on success or negative error 412 * 413 * s64 bpf_csum_diff(from, from_size, to, to_size, seed) 414 * calculate csum diff 415 * @from: raw from buffer 416 * @from_size: length of from buffer 417 * @to: raw to buffer 418 * @to_size: length of to buffer 419 * @seed: optional seed 420 * Return: csum result or negative error code 421 * 422 * int bpf_skb_get_tunnel_opt(skb, opt, size) 423 * retrieve tunnel options metadata 424 * @skb: pointer to skb 425 * @opt: pointer to raw tunnel option data 426 * @size: size of @opt 427 * Return: option size 428 * 429 * int bpf_skb_set_tunnel_opt(skb, opt, size) 430 * populate tunnel options metadata 431 * @skb: pointer to skb 432 * @opt: pointer to raw tunnel option data 433 * @size: size of @opt 434 * Return: 0 on success or negative error 435 * 436 * int bpf_skb_change_proto(skb, proto, flags) 437 * Change protocol of the skb. Currently supported is v4 -> v6, 438 * v6 -> v4 transitions. The helper will also resize the skb. eBPF 439 * program is expected to fill the new headers via skb_store_bytes 440 * and lX_csum_replace. 441 * @skb: pointer to skb 442 * @proto: new skb->protocol type 443 * @flags: reserved 444 * Return: 0 on success or negative error 445 * 446 * int bpf_skb_change_type(skb, type) 447 * Change packet type of skb. 448 * @skb: pointer to skb 449 * @type: new skb->pkt_type type 450 * Return: 0 on success or negative error 451 * 452 * int bpf_skb_under_cgroup(skb, map, index) 453 * Check cgroup2 membership of skb 454 * @skb: pointer to skb 455 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type 456 * @index: index of the cgroup in the bpf_map 457 * Return: 458 * == 0 skb failed the cgroup2 descendant test 459 * == 1 skb succeeded the cgroup2 descendant test 460 * < 0 error 461 * 462 * u32 bpf_get_hash_recalc(skb) 463 * Retrieve and possibly recalculate skb->hash. 464 * @skb: pointer to skb 465 * Return: hash 466 * 467 * u64 bpf_get_current_task(void) 468 * Returns current task_struct 469 * Return: current 470 * 471 * int bpf_probe_write_user(void *dst, void *src, int len) 472 * safely attempt to write to a location 473 * @dst: destination address in userspace 474 * @src: source address on stack 475 * @len: number of bytes to copy 476 * Return: 0 on success or negative error 477 * 478 * int bpf_current_task_under_cgroup(map, index) 479 * Check cgroup2 membership of current task 480 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type 481 * @index: index of the cgroup in the bpf_map 482 * Return: 483 * == 0 current failed the cgroup2 descendant test 484 * == 1 current succeeded the cgroup2 descendant test 485 * < 0 error 486 * 487 * int bpf_skb_change_tail(skb, len, flags) 488 * The helper will resize the skb to the given new size, to be used f.e. 489 * with control messages. 490 * @skb: pointer to skb 491 * @len: new skb length 492 * @flags: reserved 493 * Return: 0 on success or negative error 494 * 495 * int bpf_skb_pull_data(skb, len) 496 * The helper will pull in non-linear data in case the skb is non-linear 497 * and not all of len are part of the linear section. Only needed for 498 * read/write with direct packet access. 499 * @skb: pointer to skb 500 * @len: len to make read/writeable 501 * Return: 0 on success or negative error 502 * 503 * s64 bpf_csum_update(skb, csum) 504 * Adds csum into skb->csum in case of CHECKSUM_COMPLETE. 505 * @skb: pointer to skb 506 * @csum: csum to add 507 * Return: csum on success or negative error 508 * 509 * void bpf_set_hash_invalid(skb) 510 * Invalidate current skb->hash. 511 * @skb: pointer to skb 512 * 513 * int bpf_get_numa_node_id() 514 * Return: Id of current NUMA node. 515 * 516 * int bpf_skb_change_head() 517 * Grows headroom of skb and adjusts MAC header offset accordingly. 518 * Will extends/reallocae as required automatically. 519 * May change skb data pointer and will thus invalidate any check 520 * performed for direct packet access. 521 * @skb: pointer to skb 522 * @len: length of header to be pushed in front 523 * @flags: Flags (unused for now) 524 * Return: 0 on success or negative error 525 * 526 * int bpf_xdp_adjust_head(xdp_md, delta) 527 * Adjust the xdp_md.data by delta 528 * @xdp_md: pointer to xdp_md 529 * @delta: An positive/negative integer to be added to xdp_md.data 530 * Return: 0 on success or negative on error 531 * 532 * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr) 533 * Copy a NUL terminated string from unsafe address. In case the string 534 * length is smaller than size, the target is not padded with further NUL 535 * bytes. In case the string length is larger than size, just count-1 536 * bytes are copied and the last byte is set to NUL. 537 * @dst: destination address 538 * @size: maximum number of bytes to copy, including the trailing NUL 539 * @unsafe_ptr: unsafe address 540 * Return: 541 * > 0 length of the string including the trailing NUL on success 542 * < 0 error 543 * 544 * u64 bpf_get_socket_cookie(skb) 545 * Get the cookie for the socket stored inside sk_buff. 546 * @skb: pointer to skb 547 * Return: 8 Bytes non-decreasing number on success or 0 if the socket 548 * field is missing inside sk_buff 549 * 550 * u32 bpf_get_socket_uid(skb) 551 * Get the owner uid of the socket stored inside sk_buff. 552 * @skb: pointer to skb 553 * Return: uid of the socket owner on success or overflowuid if failed. 554 * 555 * u32 bpf_set_hash(skb, hash) 556 * Set full skb->hash. 557 * @skb: pointer to skb 558 * @hash: hash to set 559 * 560 * int bpf_setsockopt(bpf_socket, level, optname, optval, optlen) 561 * Calls setsockopt. Not all opts are available, only those with 562 * integer optvals plus TCP_CONGESTION. 563 * Supported levels: SOL_SOCKET and IPROTO_TCP 564 * @bpf_socket: pointer to bpf_socket 565 * @level: SOL_SOCKET or IPROTO_TCP 566 * @optname: option name 567 * @optval: pointer to option value 568 * @optlen: length of optval in byes 569 * Return: 0 or negative error 570 * 571 * int bpf_skb_adjust_room(skb, len_diff, mode, flags) 572 * Grow or shrink room in sk_buff. 573 * @skb: pointer to skb 574 * @len_diff: (signed) amount of room to grow/shrink 575 * @mode: operation mode (enum bpf_adj_room_mode) 576 * @flags: reserved for future use 577 * Return: 0 on success or negative error code 578 * 579 * int bpf_sk_redirect_map(map, key, flags) 580 * Redirect skb to a sock in map using key as a lookup key for the 581 * sock in map. 582 * @map: pointer to sockmap 583 * @key: key to lookup sock in map 584 * @flags: reserved for future use 585 * Return: SK_PASS 586 * 587 * int bpf_sock_map_update(skops, map, key, flags) 588 * @skops: pointer to bpf_sock_ops 589 * @map: pointer to sockmap to update 590 * @key: key to insert/update sock in map 591 * @flags: same flags as map update elem 592 */ 593 #define __BPF_FUNC_MAPPER(FN) \ 594 FN(unspec), \ 595 FN(map_lookup_elem), \ 596 FN(map_update_elem), \ 597 FN(map_delete_elem), \ 598 FN(probe_read), \ 599 FN(ktime_get_ns), \ 600 FN(trace_printk), \ 601 FN(get_prandom_u32), \ 602 FN(get_smp_processor_id), \ 603 FN(skb_store_bytes), \ 604 FN(l3_csum_replace), \ 605 FN(l4_csum_replace), \ 606 FN(tail_call), \ 607 FN(clone_redirect), \ 608 FN(get_current_pid_tgid), \ 609 FN(get_current_uid_gid), \ 610 FN(get_current_comm), \ 611 FN(get_cgroup_classid), \ 612 FN(skb_vlan_push), \ 613 FN(skb_vlan_pop), \ 614 FN(skb_get_tunnel_key), \ 615 FN(skb_set_tunnel_key), \ 616 FN(perf_event_read), \ 617 FN(redirect), \ 618 FN(get_route_realm), \ 619 FN(perf_event_output), \ 620 FN(skb_load_bytes), \ 621 FN(get_stackid), \ 622 FN(csum_diff), \ 623 FN(skb_get_tunnel_opt), \ 624 FN(skb_set_tunnel_opt), \ 625 FN(skb_change_proto), \ 626 FN(skb_change_type), \ 627 FN(skb_under_cgroup), \ 628 FN(get_hash_recalc), \ 629 FN(get_current_task), \ 630 FN(probe_write_user), \ 631 FN(current_task_under_cgroup), \ 632 FN(skb_change_tail), \ 633 FN(skb_pull_data), \ 634 FN(csum_update), \ 635 FN(set_hash_invalid), \ 636 FN(get_numa_node_id), \ 637 FN(skb_change_head), \ 638 FN(xdp_adjust_head), \ 639 FN(probe_read_str), \ 640 FN(get_socket_cookie), \ 641 FN(get_socket_uid), \ 642 FN(set_hash), \ 643 FN(setsockopt), \ 644 FN(skb_adjust_room), \ 645 FN(redirect_map), \ 646 FN(sk_redirect_map), \ 647 FN(sock_map_update), \ 648 649 /* integer value in 'imm' field of BPF_CALL instruction selects which helper 650 * function eBPF program intends to call 651 */ 652 #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x 653 enum bpf_func_id { 654 __BPF_FUNC_MAPPER(__BPF_ENUM_FN) 655 __BPF_FUNC_MAX_ID, 656 }; 657 #undef __BPF_ENUM_FN 658 659 /* All flags used by eBPF helper functions, placed here. */ 660 661 /* BPF_FUNC_skb_store_bytes flags. */ 662 #define BPF_F_RECOMPUTE_CSUM (1ULL << 0) 663 #define BPF_F_INVALIDATE_HASH (1ULL << 1) 664 665 /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags. 666 * First 4 bits are for passing the header field size. 667 */ 668 #define BPF_F_HDR_FIELD_MASK 0xfULL 669 670 /* BPF_FUNC_l4_csum_replace flags. */ 671 #define BPF_F_PSEUDO_HDR (1ULL << 4) 672 #define BPF_F_MARK_MANGLED_0 (1ULL << 5) 673 #define BPF_F_MARK_ENFORCE (1ULL << 6) 674 675 /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */ 676 #define BPF_F_INGRESS (1ULL << 0) 677 678 /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */ 679 #define BPF_F_TUNINFO_IPV6 (1ULL << 0) 680 681 /* BPF_FUNC_get_stackid flags. */ 682 #define BPF_F_SKIP_FIELD_MASK 0xffULL 683 #define BPF_F_USER_STACK (1ULL << 8) 684 #define BPF_F_FAST_STACK_CMP (1ULL << 9) 685 #define BPF_F_REUSE_STACKID (1ULL << 10) 686 687 /* BPF_FUNC_skb_set_tunnel_key flags. */ 688 #define BPF_F_ZERO_CSUM_TX (1ULL << 1) 689 #define BPF_F_DONT_FRAGMENT (1ULL << 2) 690 691 /* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */ 692 #define BPF_F_INDEX_MASK 0xffffffffULL 693 #define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK 694 /* BPF_FUNC_perf_event_output for sk_buff input context. */ 695 #define BPF_F_CTXLEN_MASK (0xfffffULL << 32) 696 697 /* Mode for BPF_FUNC_skb_adjust_room helper. */ 698 enum bpf_adj_room_mode { 699 BPF_ADJ_ROOM_NET, 700 }; 701 702 /* user accessible mirror of in-kernel sk_buff. 703 * new fields can only be added to the end of this structure 704 */ 705 struct __sk_buff { 706 __u32 len; 707 __u32 pkt_type; 708 __u32 mark; 709 __u32 queue_mapping; 710 __u32 protocol; 711 __u32 vlan_present; 712 __u32 vlan_tci; 713 __u32 vlan_proto; 714 __u32 priority; 715 __u32 ingress_ifindex; 716 __u32 ifindex; 717 __u32 tc_index; 718 __u32 cb[5]; 719 __u32 hash; 720 __u32 tc_classid; 721 __u32 data; 722 __u32 data_end; 723 __u32 napi_id; 724 725 /* accessed by BPF_PROG_TYPE_sk_skb types */ 726 __u32 family; 727 __u32 remote_ip4; /* Stored in network byte order */ 728 __u32 local_ip4; /* Stored in network byte order */ 729 __u32 remote_ip6[4]; /* Stored in network byte order */ 730 __u32 local_ip6[4]; /* Stored in network byte order */ 731 __u32 remote_port; /* Stored in network byte order */ 732 __u32 local_port; /* stored in host byte order */ 733 }; 734 735 struct bpf_tunnel_key { 736 __u32 tunnel_id; 737 union { 738 __u32 remote_ipv4; 739 __u32 remote_ipv6[4]; 740 }; 741 __u8 tunnel_tos; 742 __u8 tunnel_ttl; 743 __u16 tunnel_ext; 744 __u32 tunnel_label; 745 }; 746 747 /* Generic BPF return codes which all BPF program types may support. 748 * The values are binary compatible with their TC_ACT_* counter-part to 749 * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT 750 * programs. 751 * 752 * XDP is handled seprately, see XDP_*. 753 */ 754 enum bpf_ret_code { 755 BPF_OK = 0, 756 /* 1 reserved */ 757 BPF_DROP = 2, 758 /* 3-6 reserved */ 759 BPF_REDIRECT = 7, 760 /* >127 are reserved for prog type specific return codes */ 761 }; 762 763 struct bpf_sock { 764 __u32 bound_dev_if; 765 __u32 family; 766 __u32 type; 767 __u32 protocol; 768 __u32 mark; 769 __u32 priority; 770 }; 771 772 #define XDP_PACKET_HEADROOM 256 773 774 /* User return codes for XDP prog type. 775 * A valid XDP program must return one of these defined values. All other 776 * return codes are reserved for future use. Unknown return codes will 777 * result in packet drops and a warning via bpf_warn_invalid_xdp_action(). 778 */ 779 enum xdp_action { 780 XDP_ABORTED = 0, 781 XDP_DROP, 782 XDP_PASS, 783 XDP_TX, 784 XDP_REDIRECT, 785 }; 786 787 /* user accessible metadata for XDP packet hook 788 * new fields must be added to the end of this structure 789 */ 790 struct xdp_md { 791 __u32 data; 792 __u32 data_end; 793 }; 794 795 enum sk_action { 796 SK_DROP = 0, 797 SK_PASS, 798 }; 799 800 #define BPF_TAG_SIZE 8 801 802 struct bpf_prog_info { 803 __u32 type; 804 __u32 id; 805 __u8 tag[BPF_TAG_SIZE]; 806 __u32 jited_prog_len; 807 __u32 xlated_prog_len; 808 __aligned_u64 jited_prog_insns; 809 __aligned_u64 xlated_prog_insns; 810 } __attribute__((aligned(8))); 811 812 struct bpf_map_info { 813 __u32 type; 814 __u32 id; 815 __u32 key_size; 816 __u32 value_size; 817 __u32 max_entries; 818 __u32 map_flags; 819 } __attribute__((aligned(8))); 820 821 /* User bpf_sock_ops struct to access socket values and specify request ops 822 * and their replies. 823 * Some of this fields are in network (bigendian) byte order and may need 824 * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h). 825 * New fields can only be added at the end of this structure 826 */ 827 struct bpf_sock_ops { 828 __u32 op; 829 union { 830 __u32 reply; 831 __u32 replylong[4]; 832 }; 833 __u32 family; 834 __u32 remote_ip4; /* Stored in network byte order */ 835 __u32 local_ip4; /* Stored in network byte order */ 836 __u32 remote_ip6[4]; /* Stored in network byte order */ 837 __u32 local_ip6[4]; /* Stored in network byte order */ 838 __u32 remote_port; /* Stored in network byte order */ 839 __u32 local_port; /* stored in host byte order */ 840 }; 841 842 /* List of known BPF sock_ops operators. 843 * New entries can only be added at the end 844 */ 845 enum { 846 BPF_SOCK_OPS_VOID, 847 BPF_SOCK_OPS_TIMEOUT_INIT, /* Should return SYN-RTO value to use or 848 * -1 if default value should be used 849 */ 850 BPF_SOCK_OPS_RWND_INIT, /* Should return initial advertized 851 * window (in packets) or -1 if default 852 * value should be used 853 */ 854 BPF_SOCK_OPS_TCP_CONNECT_CB, /* Calls BPF program right before an 855 * active connection is initialized 856 */ 857 BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB, /* Calls BPF program when an 858 * active connection is 859 * established 860 */ 861 BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB, /* Calls BPF program when a 862 * passive connection is 863 * established 864 */ 865 BPF_SOCK_OPS_NEEDS_ECN, /* If connection's congestion control 866 * needs ECN 867 */ 868 }; 869 870 #define TCP_BPF_IW 1001 /* Set TCP initial congestion window */ 871 #define TCP_BPF_SNDCWND_CLAMP 1002 /* Set sndcwnd_clamp */ 872 873 #endif /* _UAPI__LINUX_BPF_H__ */ 874