1daedfb22SAlexei Starovoitov /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com 2daedfb22SAlexei Starovoitov * 3daedfb22SAlexei Starovoitov * This program is free software; you can redistribute it and/or 4daedfb22SAlexei Starovoitov * modify it under the terms of version 2 of the GNU General Public 5daedfb22SAlexei Starovoitov * License as published by the Free Software Foundation. 6daedfb22SAlexei Starovoitov */ 7daedfb22SAlexei Starovoitov #ifndef _UAPI__LINUX_BPF_H__ 8daedfb22SAlexei Starovoitov #define _UAPI__LINUX_BPF_H__ 9daedfb22SAlexei Starovoitov 10daedfb22SAlexei Starovoitov #include <linux/types.h> 11c15952dcSAlexei Starovoitov #include <linux/bpf_common.h> 12daedfb22SAlexei Starovoitov 13daedfb22SAlexei Starovoitov /* Extended instruction set based on top of classic BPF */ 14daedfb22SAlexei Starovoitov 15daedfb22SAlexei Starovoitov /* instruction classes */ 16daedfb22SAlexei Starovoitov #define BPF_ALU64 0x07 /* alu mode in double word width */ 17daedfb22SAlexei Starovoitov 18daedfb22SAlexei Starovoitov /* ld/ldx fields */ 19daedfb22SAlexei Starovoitov #define BPF_DW 0x18 /* double word */ 20daedfb22SAlexei Starovoitov #define BPF_XADD 0xc0 /* exclusive add */ 21daedfb22SAlexei Starovoitov 22daedfb22SAlexei Starovoitov /* alu/jmp fields */ 23daedfb22SAlexei Starovoitov #define BPF_MOV 0xb0 /* mov reg to reg */ 24daedfb22SAlexei Starovoitov #define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */ 25daedfb22SAlexei Starovoitov 26daedfb22SAlexei Starovoitov /* change endianness of a register */ 27daedfb22SAlexei Starovoitov #define BPF_END 0xd0 /* flags for endianness conversion: */ 28daedfb22SAlexei Starovoitov #define BPF_TO_LE 0x00 /* convert to little-endian */ 29daedfb22SAlexei Starovoitov #define BPF_TO_BE 0x08 /* convert to big-endian */ 30daedfb22SAlexei Starovoitov #define BPF_FROM_LE BPF_TO_LE 31daedfb22SAlexei Starovoitov #define BPF_FROM_BE BPF_TO_BE 32daedfb22SAlexei Starovoitov 33daedfb22SAlexei Starovoitov #define BPF_JNE 0x50 /* jump != */ 34daedfb22SAlexei Starovoitov #define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */ 35daedfb22SAlexei Starovoitov #define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */ 36daedfb22SAlexei Starovoitov #define BPF_CALL 0x80 /* function call */ 37daedfb22SAlexei Starovoitov #define BPF_EXIT 0x90 /* function return */ 38daedfb22SAlexei Starovoitov 39daedfb22SAlexei Starovoitov /* Register numbers */ 40daedfb22SAlexei Starovoitov enum { 41daedfb22SAlexei Starovoitov BPF_REG_0 = 0, 42daedfb22SAlexei Starovoitov BPF_REG_1, 43daedfb22SAlexei Starovoitov BPF_REG_2, 44daedfb22SAlexei Starovoitov BPF_REG_3, 45daedfb22SAlexei Starovoitov BPF_REG_4, 46daedfb22SAlexei Starovoitov BPF_REG_5, 47daedfb22SAlexei Starovoitov BPF_REG_6, 48daedfb22SAlexei Starovoitov BPF_REG_7, 49daedfb22SAlexei Starovoitov BPF_REG_8, 50daedfb22SAlexei Starovoitov BPF_REG_9, 51daedfb22SAlexei Starovoitov BPF_REG_10, 52daedfb22SAlexei Starovoitov __MAX_BPF_REG, 53daedfb22SAlexei Starovoitov }; 54daedfb22SAlexei Starovoitov 55daedfb22SAlexei Starovoitov /* BPF has 10 general purpose 64-bit registers and stack frame. */ 56daedfb22SAlexei Starovoitov #define MAX_BPF_REG __MAX_BPF_REG 57daedfb22SAlexei Starovoitov 58daedfb22SAlexei Starovoitov struct bpf_insn { 59daedfb22SAlexei Starovoitov __u8 code; /* opcode */ 60daedfb22SAlexei Starovoitov __u8 dst_reg:4; /* dest register */ 61daedfb22SAlexei Starovoitov __u8 src_reg:4; /* source register */ 62daedfb22SAlexei Starovoitov __s16 off; /* signed offset */ 63daedfb22SAlexei Starovoitov __s32 imm; /* signed immediate constant */ 64daedfb22SAlexei Starovoitov }; 65daedfb22SAlexei Starovoitov 66b95a5c4dSDaniel Mack /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */ 67b95a5c4dSDaniel Mack struct bpf_lpm_trie_key { 68b95a5c4dSDaniel Mack __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */ 69b95a5c4dSDaniel Mack __u8 data[0]; /* Arbitrary size */ 70b95a5c4dSDaniel Mack }; 71b95a5c4dSDaniel Mack 72b2197755SDaniel Borkmann /* BPF syscall commands, see bpf(2) man-page for details. */ 7399c55f7dSAlexei Starovoitov enum bpf_cmd { 7499c55f7dSAlexei Starovoitov BPF_MAP_CREATE, 75db20fd2bSAlexei Starovoitov BPF_MAP_LOOKUP_ELEM, 76db20fd2bSAlexei Starovoitov BPF_MAP_UPDATE_ELEM, 77db20fd2bSAlexei Starovoitov BPF_MAP_DELETE_ELEM, 78db20fd2bSAlexei Starovoitov BPF_MAP_GET_NEXT_KEY, 7909756af4SAlexei Starovoitov BPF_PROG_LOAD, 80b2197755SDaniel Borkmann BPF_OBJ_PIN, 81b2197755SDaniel Borkmann BPF_OBJ_GET, 82f4324551SDaniel Mack BPF_PROG_ATTACH, 83f4324551SDaniel Mack BPF_PROG_DETACH, 841cf1cae9SAlexei Starovoitov BPF_PROG_TEST_RUN, 8534ad5580SMartin KaFai Lau BPF_PROG_GET_NEXT_ID, 8634ad5580SMartin KaFai Lau BPF_MAP_GET_NEXT_ID, 87b16d9aa4SMartin KaFai Lau BPF_PROG_GET_FD_BY_ID, 88bd5f5f4eSMartin KaFai Lau BPF_MAP_GET_FD_BY_ID, 891e270976SMartin KaFai Lau BPF_OBJ_GET_INFO_BY_FD, 9099c55f7dSAlexei Starovoitov }; 9199c55f7dSAlexei Starovoitov 9299c55f7dSAlexei Starovoitov enum bpf_map_type { 9399c55f7dSAlexei Starovoitov BPF_MAP_TYPE_UNSPEC, 940f8e4bd8SAlexei Starovoitov BPF_MAP_TYPE_HASH, 9528fbcfa0SAlexei Starovoitov BPF_MAP_TYPE_ARRAY, 9604fd61abSAlexei Starovoitov BPF_MAP_TYPE_PROG_ARRAY, 97ea317b26SKaixu Xia BPF_MAP_TYPE_PERF_EVENT_ARRAY, 98824bd0ceSAlexei Starovoitov BPF_MAP_TYPE_PERCPU_HASH, 99a10423b8SAlexei Starovoitov BPF_MAP_TYPE_PERCPU_ARRAY, 100d5a3b1f6SAlexei Starovoitov BPF_MAP_TYPE_STACK_TRACE, 1014ed8ec52SMartin KaFai Lau BPF_MAP_TYPE_CGROUP_ARRAY, 10229ba732aSMartin KaFai Lau BPF_MAP_TYPE_LRU_HASH, 1038f844938SMartin KaFai Lau BPF_MAP_TYPE_LRU_PERCPU_HASH, 104b95a5c4dSDaniel Mack BPF_MAP_TYPE_LPM_TRIE, 10556f668dfSMartin KaFai Lau BPF_MAP_TYPE_ARRAY_OF_MAPS, 106bcc6b1b7SMartin KaFai Lau BPF_MAP_TYPE_HASH_OF_MAPS, 10799c55f7dSAlexei Starovoitov }; 10899c55f7dSAlexei Starovoitov 10909756af4SAlexei Starovoitov enum bpf_prog_type { 11009756af4SAlexei Starovoitov BPF_PROG_TYPE_UNSPEC, 111ddd872bcSAlexei Starovoitov BPF_PROG_TYPE_SOCKET_FILTER, 1122541517cSAlexei Starovoitov BPF_PROG_TYPE_KPROBE, 11396be4325SDaniel Borkmann BPF_PROG_TYPE_SCHED_CLS, 11494caee8cSDaniel Borkmann BPF_PROG_TYPE_SCHED_ACT, 11598b5c2c6SAlexei Starovoitov BPF_PROG_TYPE_TRACEPOINT, 1166a773a15SBrenden Blanco BPF_PROG_TYPE_XDP, 1170515e599SAlexei Starovoitov BPF_PROG_TYPE_PERF_EVENT, 1180e33661dSDaniel Mack BPF_PROG_TYPE_CGROUP_SKB, 11961023658SDavid Ahern BPF_PROG_TYPE_CGROUP_SOCK, 1203a0af8fdSThomas Graf BPF_PROG_TYPE_LWT_IN, 1213a0af8fdSThomas Graf BPF_PROG_TYPE_LWT_OUT, 1223a0af8fdSThomas Graf BPF_PROG_TYPE_LWT_XMIT, 12340304b2aSLawrence Brakmo BPF_PROG_TYPE_SOCK_OPS, 12409756af4SAlexei Starovoitov }; 12509756af4SAlexei Starovoitov 1260e33661dSDaniel Mack enum bpf_attach_type { 1270e33661dSDaniel Mack BPF_CGROUP_INET_INGRESS, 1280e33661dSDaniel Mack BPF_CGROUP_INET_EGRESS, 12961023658SDavid Ahern BPF_CGROUP_INET_SOCK_CREATE, 13040304b2aSLawrence Brakmo BPF_CGROUP_SOCK_OPS, 1310e33661dSDaniel Mack __MAX_BPF_ATTACH_TYPE 1320e33661dSDaniel Mack }; 1330e33661dSDaniel Mack 1340e33661dSDaniel Mack #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE 1350e33661dSDaniel Mack 1367f677633SAlexei Starovoitov /* If BPF_F_ALLOW_OVERRIDE flag is used in BPF_PROG_ATTACH command 1377f677633SAlexei Starovoitov * to the given target_fd cgroup the descendent cgroup will be able to 1387f677633SAlexei Starovoitov * override effective bpf program that was inherited from this cgroup 1397f677633SAlexei Starovoitov */ 1407f677633SAlexei Starovoitov #define BPF_F_ALLOW_OVERRIDE (1U << 0) 1417f677633SAlexei Starovoitov 142e07b98d9SDavid S. Miller /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the 143e07b98d9SDavid S. Miller * verifier will perform strict alignment checking as if the kernel 144e07b98d9SDavid S. Miller * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set, 145e07b98d9SDavid S. Miller * and NET_IP_ALIGN defined to 2. 146e07b98d9SDavid S. Miller */ 147e07b98d9SDavid S. Miller #define BPF_F_STRICT_ALIGNMENT (1U << 0) 148e07b98d9SDavid S. Miller 149f1a66f85SDaniel Borkmann #define BPF_PSEUDO_MAP_FD 1 150f1a66f85SDaniel Borkmann 1513274f520SAlexei Starovoitov /* flags for BPF_MAP_UPDATE_ELEM command */ 1523274f520SAlexei Starovoitov #define BPF_ANY 0 /* create new element or update existing */ 1533274f520SAlexei Starovoitov #define BPF_NOEXIST 1 /* create new element if it didn't exist */ 1543274f520SAlexei Starovoitov #define BPF_EXIST 2 /* update existing element */ 1553274f520SAlexei Starovoitov 1566c905981SAlexei Starovoitov #define BPF_F_NO_PREALLOC (1U << 0) 15729ba732aSMartin KaFai Lau /* Instead of having one common LRU list in the 1588f844938SMartin KaFai Lau * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list 15929ba732aSMartin KaFai Lau * which can scale and perform better. 16029ba732aSMartin KaFai Lau * Note, the LRU nodes (including free nodes) cannot be moved 16129ba732aSMartin KaFai Lau * across different LRU lists. 16229ba732aSMartin KaFai Lau */ 16329ba732aSMartin KaFai Lau #define BPF_F_NO_COMMON_LRU (1U << 1) 1646c905981SAlexei Starovoitov 16599c55f7dSAlexei Starovoitov union bpf_attr { 16699c55f7dSAlexei Starovoitov struct { /* anonymous struct used by BPF_MAP_CREATE command */ 16799c55f7dSAlexei Starovoitov __u32 map_type; /* one of enum bpf_map_type */ 16899c55f7dSAlexei Starovoitov __u32 key_size; /* size of key in bytes */ 16999c55f7dSAlexei Starovoitov __u32 value_size; /* size of value in bytes */ 17099c55f7dSAlexei Starovoitov __u32 max_entries; /* max number of entries in a map */ 1716c905981SAlexei Starovoitov __u32 map_flags; /* prealloc or not */ 17256f668dfSMartin KaFai Lau __u32 inner_map_fd; /* fd pointing to the inner map */ 17399c55f7dSAlexei Starovoitov }; 174db20fd2bSAlexei Starovoitov 175db20fd2bSAlexei Starovoitov struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ 176db20fd2bSAlexei Starovoitov __u32 map_fd; 177db20fd2bSAlexei Starovoitov __aligned_u64 key; 178db20fd2bSAlexei Starovoitov union { 179db20fd2bSAlexei Starovoitov __aligned_u64 value; 180db20fd2bSAlexei Starovoitov __aligned_u64 next_key; 181db20fd2bSAlexei Starovoitov }; 1823274f520SAlexei Starovoitov __u64 flags; 183db20fd2bSAlexei Starovoitov }; 18409756af4SAlexei Starovoitov 18509756af4SAlexei Starovoitov struct { /* anonymous struct used by BPF_PROG_LOAD command */ 18609756af4SAlexei Starovoitov __u32 prog_type; /* one of enum bpf_prog_type */ 18709756af4SAlexei Starovoitov __u32 insn_cnt; 18809756af4SAlexei Starovoitov __aligned_u64 insns; 18909756af4SAlexei Starovoitov __aligned_u64 license; 190cbd35700SAlexei Starovoitov __u32 log_level; /* verbosity level of verifier */ 191cbd35700SAlexei Starovoitov __u32 log_size; /* size of user buffer */ 192cbd35700SAlexei Starovoitov __aligned_u64 log_buf; /* user supplied buffer */ 1932541517cSAlexei Starovoitov __u32 kern_version; /* checked when prog_type=kprobe */ 194e07b98d9SDavid S. Miller __u32 prog_flags; 19509756af4SAlexei Starovoitov }; 196b2197755SDaniel Borkmann 197b2197755SDaniel Borkmann struct { /* anonymous struct used by BPF_OBJ_* commands */ 198b2197755SDaniel Borkmann __aligned_u64 pathname; 199b2197755SDaniel Borkmann __u32 bpf_fd; 200b2197755SDaniel Borkmann }; 201f4324551SDaniel Mack 202f4324551SDaniel Mack struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */ 203f4324551SDaniel Mack __u32 target_fd; /* container object to attach to */ 204f4324551SDaniel Mack __u32 attach_bpf_fd; /* eBPF program to attach */ 205f4324551SDaniel Mack __u32 attach_type; 2067f677633SAlexei Starovoitov __u32 attach_flags; 207f4324551SDaniel Mack }; 2081cf1cae9SAlexei Starovoitov 2091cf1cae9SAlexei Starovoitov struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */ 2101cf1cae9SAlexei Starovoitov __u32 prog_fd; 2111cf1cae9SAlexei Starovoitov __u32 retval; 2121cf1cae9SAlexei Starovoitov __u32 data_size_in; 2131cf1cae9SAlexei Starovoitov __u32 data_size_out; 2141cf1cae9SAlexei Starovoitov __aligned_u64 data_in; 2151cf1cae9SAlexei Starovoitov __aligned_u64 data_out; 2161cf1cae9SAlexei Starovoitov __u32 repeat; 2171cf1cae9SAlexei Starovoitov __u32 duration; 2181cf1cae9SAlexei Starovoitov } test; 21934ad5580SMartin KaFai Lau 220b16d9aa4SMartin KaFai Lau struct { /* anonymous struct used by BPF_*_GET_*_ID */ 221b16d9aa4SMartin KaFai Lau union { 22234ad5580SMartin KaFai Lau __u32 start_id; 223b16d9aa4SMartin KaFai Lau __u32 prog_id; 224bd5f5f4eSMartin KaFai Lau __u32 map_id; 225b16d9aa4SMartin KaFai Lau }; 22634ad5580SMartin KaFai Lau __u32 next_id; 22734ad5580SMartin KaFai Lau }; 2281e270976SMartin KaFai Lau 2291e270976SMartin KaFai Lau struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */ 2301e270976SMartin KaFai Lau __u32 bpf_fd; 2311e270976SMartin KaFai Lau __u32 info_len; 2321e270976SMartin KaFai Lau __aligned_u64 info; 2331e270976SMartin KaFai Lau } info; 23499c55f7dSAlexei Starovoitov } __attribute__((aligned(8))); 23599c55f7dSAlexei Starovoitov 236ebb676daSThomas Graf /* BPF helper function descriptions: 237ebb676daSThomas Graf * 238ebb676daSThomas Graf * void *bpf_map_lookup_elem(&map, &key) 239ebb676daSThomas Graf * Return: Map value or NULL 240ebb676daSThomas Graf * 241ebb676daSThomas Graf * int bpf_map_update_elem(&map, &key, &value, flags) 242ebb676daSThomas Graf * Return: 0 on success or negative error 243ebb676daSThomas Graf * 244ebb676daSThomas Graf * int bpf_map_delete_elem(&map, &key) 245ebb676daSThomas Graf * Return: 0 on success or negative error 246ebb676daSThomas Graf * 247ebb676daSThomas Graf * int bpf_probe_read(void *dst, int size, void *src) 248ebb676daSThomas Graf * Return: 0 on success or negative error 249ebb676daSThomas Graf * 250ebb676daSThomas Graf * u64 bpf_ktime_get_ns(void) 251ebb676daSThomas Graf * Return: current ktime 252ebb676daSThomas Graf * 253ebb676daSThomas Graf * int bpf_trace_printk(const char *fmt, int fmt_size, ...) 254ebb676daSThomas Graf * Return: length of buffer written or negative error 255ebb676daSThomas Graf * 256ebb676daSThomas Graf * u32 bpf_prandom_u32(void) 257ebb676daSThomas Graf * Return: random value 258ebb676daSThomas Graf * 259ebb676daSThomas Graf * u32 bpf_raw_smp_processor_id(void) 260ebb676daSThomas Graf * Return: SMP processor ID 261ebb676daSThomas Graf * 262ebb676daSThomas Graf * int bpf_skb_store_bytes(skb, offset, from, len, flags) 263ebb676daSThomas Graf * store bytes into packet 26491bc4822SAlexei Starovoitov * @skb: pointer to skb 265a166151cSAlexei Starovoitov * @offset: offset within packet from skb->mac_header 26691bc4822SAlexei Starovoitov * @from: pointer where to copy bytes from 26791bc4822SAlexei Starovoitov * @len: number of bytes to store into packet 26891bc4822SAlexei Starovoitov * @flags: bit 0 - if true, recompute skb->csum 26991bc4822SAlexei Starovoitov * other bits - reserved 270ebb676daSThomas Graf * Return: 0 on success or negative error 271ebb676daSThomas Graf * 272ebb676daSThomas Graf * int bpf_l3_csum_replace(skb, offset, from, to, flags) 273ebb676daSThomas Graf * recompute IP checksum 27491bc4822SAlexei Starovoitov * @skb: pointer to skb 27591bc4822SAlexei Starovoitov * @offset: offset within packet where IP checksum is located 27691bc4822SAlexei Starovoitov * @from: old value of header field 27791bc4822SAlexei Starovoitov * @to: new value of header field 27891bc4822SAlexei Starovoitov * @flags: bits 0-3 - size of header field 27991bc4822SAlexei Starovoitov * other bits - reserved 280ebb676daSThomas Graf * Return: 0 on success or negative error 281ebb676daSThomas Graf * 282ebb676daSThomas Graf * int bpf_l4_csum_replace(skb, offset, from, to, flags) 283ebb676daSThomas Graf * recompute TCP/UDP checksum 28491bc4822SAlexei Starovoitov * @skb: pointer to skb 28591bc4822SAlexei Starovoitov * @offset: offset within packet where TCP/UDP checksum is located 28691bc4822SAlexei Starovoitov * @from: old value of header field 28791bc4822SAlexei Starovoitov * @to: new value of header field 28891bc4822SAlexei Starovoitov * @flags: bits 0-3 - size of header field 28991bc4822SAlexei Starovoitov * bit 4 - is pseudo header 29091bc4822SAlexei Starovoitov * other bits - reserved 291ebb676daSThomas Graf * Return: 0 on success or negative error 292ebb676daSThomas Graf * 293ebb676daSThomas Graf * int bpf_tail_call(ctx, prog_array_map, index) 294ebb676daSThomas Graf * jump into another BPF program 29504fd61abSAlexei Starovoitov * @ctx: context pointer passed to next program 29604fd61abSAlexei Starovoitov * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY 29704fd61abSAlexei Starovoitov * @index: index inside array that selects specific program to run 298ebb676daSThomas Graf * Return: 0 on success or negative error 299ebb676daSThomas Graf * 300ebb676daSThomas Graf * int bpf_clone_redirect(skb, ifindex, flags) 301ebb676daSThomas Graf * redirect to another netdev 3023896d655SAlexei Starovoitov * @skb: pointer to skb 3033896d655SAlexei Starovoitov * @ifindex: ifindex of the net device 3043896d655SAlexei Starovoitov * @flags: bit 0 - if set, redirect to ingress instead of egress 3053896d655SAlexei Starovoitov * other bits - reserved 306ebb676daSThomas Graf * Return: 0 on success or negative error 307ebb676daSThomas Graf * 308ffeedafbSAlexei Starovoitov * u64 bpf_get_current_pid_tgid(void) 309ffeedafbSAlexei Starovoitov * Return: current->tgid << 32 | current->pid 310ebb676daSThomas Graf * 311ffeedafbSAlexei Starovoitov * u64 bpf_get_current_uid_gid(void) 312ffeedafbSAlexei Starovoitov * Return: current_gid << 32 | current_uid 313ebb676daSThomas Graf * 314ebb676daSThomas Graf * int bpf_get_current_comm(char *buf, int size_of_buf) 315ffeedafbSAlexei Starovoitov * stores current->comm into buf 316ebb676daSThomas Graf * Return: 0 on success or negative error 317ebb676daSThomas Graf * 318ebb676daSThomas Graf * u32 bpf_get_cgroup_classid(skb) 319ebb676daSThomas Graf * retrieve a proc's classid 3208d20aabeSDaniel Borkmann * @skb: pointer to skb 3218d20aabeSDaniel Borkmann * Return: classid if != 0 322ebb676daSThomas Graf * 323ebb676daSThomas Graf * int bpf_skb_vlan_push(skb, vlan_proto, vlan_tci) 324ebb676daSThomas Graf * Return: 0 on success or negative error 325ebb676daSThomas Graf * 326ebb676daSThomas Graf * int bpf_skb_vlan_pop(skb) 327ebb676daSThomas Graf * Return: 0 on success or negative error 328ebb676daSThomas Graf * 329ebb676daSThomas Graf * int bpf_skb_get_tunnel_key(skb, key, size, flags) 330ebb676daSThomas Graf * int bpf_skb_set_tunnel_key(skb, key, size, flags) 331d3aa45ceSAlexei Starovoitov * retrieve or populate tunnel metadata 332d3aa45ceSAlexei Starovoitov * @skb: pointer to skb 333d3aa45ceSAlexei Starovoitov * @key: pointer to 'struct bpf_tunnel_key' 334d3aa45ceSAlexei Starovoitov * @size: size of 'struct bpf_tunnel_key' 335d3aa45ceSAlexei Starovoitov * @flags: room for future extensions 336ebb676daSThomas Graf * Return: 0 on success or negative error 337ebb676daSThomas Graf * 338b7d3ed5bSTeng Qin * u64 bpf_perf_event_read(map, flags) 339b7d3ed5bSTeng Qin * read perf event counter value 340b7d3ed5bSTeng Qin * @map: pointer to perf_event_array map 341b7d3ed5bSTeng Qin * @flags: index of event in the map or bitmask flags 342b7d3ed5bSTeng Qin * Return: value of perf event counter read or error code 343ebb676daSThomas Graf * 344ebb676daSThomas Graf * int bpf_redirect(ifindex, flags) 345ebb676daSThomas Graf * redirect to another netdev 34627b29f63SAlexei Starovoitov * @ifindex: ifindex of the net device 34727b29f63SAlexei Starovoitov * @flags: bit 0 - if set, redirect to ingress instead of egress 34827b29f63SAlexei Starovoitov * other bits - reserved 34927b29f63SAlexei Starovoitov * Return: TC_ACT_REDIRECT 350ebb676daSThomas Graf * 351ebb676daSThomas Graf * u32 bpf_get_route_realm(skb) 352ebb676daSThomas Graf * retrieve a dst's tclassid 353c46646d0SDaniel Borkmann * @skb: pointer to skb 354c46646d0SDaniel Borkmann * Return: realm if != 0 355ebb676daSThomas Graf * 356b7d3ed5bSTeng Qin * int bpf_perf_event_output(ctx, map, flags, data, size) 357ebb676daSThomas Graf * output perf raw sample 358a43eec30SAlexei Starovoitov * @ctx: struct pt_regs* 359a43eec30SAlexei Starovoitov * @map: pointer to perf_event_array map 360b7d3ed5bSTeng Qin * @flags: index of event in the map or bitmask flags 361a43eec30SAlexei Starovoitov * @data: data on stack to be output as raw data 362a43eec30SAlexei Starovoitov * @size: size of data 363ebb676daSThomas Graf * Return: 0 on success or negative error 364ebb676daSThomas Graf * 365ebb676daSThomas Graf * int bpf_get_stackid(ctx, map, flags) 366ebb676daSThomas Graf * walk user or kernel stack and return id 367d5a3b1f6SAlexei Starovoitov * @ctx: struct pt_regs* 368d5a3b1f6SAlexei Starovoitov * @map: pointer to stack_trace map 369d5a3b1f6SAlexei Starovoitov * @flags: bits 0-7 - numer of stack frames to skip 370d5a3b1f6SAlexei Starovoitov * bit 8 - collect user stack instead of kernel 371d5a3b1f6SAlexei Starovoitov * bit 9 - compare stacks by hash only 372d5a3b1f6SAlexei Starovoitov * bit 10 - if two different stacks hash into the same stackid 373d5a3b1f6SAlexei Starovoitov * discard old 374d5a3b1f6SAlexei Starovoitov * other bits - reserved 375d5a3b1f6SAlexei Starovoitov * Return: >= 0 stackid on success or negative error 376ebb676daSThomas Graf * 377ebb676daSThomas Graf * s64 bpf_csum_diff(from, from_size, to, to_size, seed) 378ebb676daSThomas Graf * calculate csum diff 3797d672345SDaniel Borkmann * @from: raw from buffer 3807d672345SDaniel Borkmann * @from_size: length of from buffer 3817d672345SDaniel Borkmann * @to: raw to buffer 3827d672345SDaniel Borkmann * @to_size: length of to buffer 3837d672345SDaniel Borkmann * @seed: optional seed 384ebb676daSThomas Graf * Return: csum result or negative error code 385ebb676daSThomas Graf * 386ebb676daSThomas Graf * int bpf_skb_get_tunnel_opt(skb, opt, size) 387ebb676daSThomas Graf * retrieve tunnel options metadata 38814ca0751SDaniel Borkmann * @skb: pointer to skb 38914ca0751SDaniel Borkmann * @opt: pointer to raw tunnel option data 39014ca0751SDaniel Borkmann * @size: size of @opt 391ebb676daSThomas Graf * Return: option size 392ebb676daSThomas Graf * 393ebb676daSThomas Graf * int bpf_skb_set_tunnel_opt(skb, opt, size) 394ebb676daSThomas Graf * populate tunnel options metadata 395ebb676daSThomas Graf * @skb: pointer to skb 396ebb676daSThomas Graf * @opt: pointer to raw tunnel option data 397ebb676daSThomas Graf * @size: size of @opt 398ebb676daSThomas Graf * Return: 0 on success or negative error 399ebb676daSThomas Graf * 400ebb676daSThomas Graf * int bpf_skb_change_proto(skb, proto, flags) 401ebb676daSThomas Graf * Change protocol of the skb. Currently supported is v4 -> v6, 402ebb676daSThomas Graf * v6 -> v4 transitions. The helper will also resize the skb. eBPF 403ebb676daSThomas Graf * program is expected to fill the new headers via skb_store_bytes 404ebb676daSThomas Graf * and lX_csum_replace. 4056578171aSDaniel Borkmann * @skb: pointer to skb 4066578171aSDaniel Borkmann * @proto: new skb->protocol type 4076578171aSDaniel Borkmann * @flags: reserved 4086578171aSDaniel Borkmann * Return: 0 on success or negative error 409ebb676daSThomas Graf * 410ebb676daSThomas Graf * int bpf_skb_change_type(skb, type) 411d2485c42SDaniel Borkmann * Change packet type of skb. 412d2485c42SDaniel Borkmann * @skb: pointer to skb 413d2485c42SDaniel Borkmann * @type: new skb->pkt_type type 414d2485c42SDaniel Borkmann * Return: 0 on success or negative error 415ebb676daSThomas Graf * 416ebb676daSThomas Graf * int bpf_skb_under_cgroup(skb, map, index) 417ebb676daSThomas Graf * Check cgroup2 membership of skb 4184a482f34SMartin KaFai Lau * @skb: pointer to skb 4194a482f34SMartin KaFai Lau * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type 4204a482f34SMartin KaFai Lau * @index: index of the cgroup in the bpf_map 4214a482f34SMartin KaFai Lau * Return: 4224a482f34SMartin KaFai Lau * == 0 skb failed the cgroup2 descendant test 4234a482f34SMartin KaFai Lau * == 1 skb succeeded the cgroup2 descendant test 4244a482f34SMartin KaFai Lau * < 0 error 425ebb676daSThomas Graf * 426ebb676daSThomas Graf * u32 bpf_get_hash_recalc(skb) 42713c5c240SDaniel Borkmann * Retrieve and possibly recalculate skb->hash. 42813c5c240SDaniel Borkmann * @skb: pointer to skb 42913c5c240SDaniel Borkmann * Return: hash 430ebb676daSThomas Graf * 431606274c5SAlexei Starovoitov * u64 bpf_get_current_task(void) 432606274c5SAlexei Starovoitov * Returns current task_struct 433606274c5SAlexei Starovoitov * Return: current 434ebb676daSThomas Graf * 435ebb676daSThomas Graf * int bpf_probe_write_user(void *dst, void *src, int len) 43696ae5227SSargun Dhillon * safely attempt to write to a location 43796ae5227SSargun Dhillon * @dst: destination address in userspace 43896ae5227SSargun Dhillon * @src: source address on stack 43996ae5227SSargun Dhillon * @len: number of bytes to copy 44096ae5227SSargun Dhillon * Return: 0 on success or negative error 441ebb676daSThomas Graf * 442ebb676daSThomas Graf * int bpf_current_task_under_cgroup(map, index) 443ebb676daSThomas Graf * Check cgroup2 membership of current task 44460d20f91SSargun Dhillon * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type 44560d20f91SSargun Dhillon * @index: index of the cgroup in the bpf_map 44660d20f91SSargun Dhillon * Return: 44760d20f91SSargun Dhillon * == 0 current failed the cgroup2 descendant test 44860d20f91SSargun Dhillon * == 1 current succeeded the cgroup2 descendant test 44960d20f91SSargun Dhillon * < 0 error 450ebb676daSThomas Graf * 451ebb676daSThomas Graf * int bpf_skb_change_tail(skb, len, flags) 452ebb676daSThomas Graf * The helper will resize the skb to the given new size, to be used f.e. 453ebb676daSThomas Graf * with control messages. 4545293efe6SDaniel Borkmann * @skb: pointer to skb 4555293efe6SDaniel Borkmann * @len: new skb length 4565293efe6SDaniel Borkmann * @flags: reserved 4575293efe6SDaniel Borkmann * Return: 0 on success or negative error 458ebb676daSThomas Graf * 459ebb676daSThomas Graf * int bpf_skb_pull_data(skb, len) 460ebb676daSThomas Graf * The helper will pull in non-linear data in case the skb is non-linear 461ebb676daSThomas Graf * and not all of len are part of the linear section. Only needed for 462ebb676daSThomas Graf * read/write with direct packet access. 46336bbef52SDaniel Borkmann * @skb: pointer to skb 46436bbef52SDaniel Borkmann * @len: len to make read/writeable 46536bbef52SDaniel Borkmann * Return: 0 on success or negative error 466ebb676daSThomas Graf * 467ebb676daSThomas Graf * s64 bpf_csum_update(skb, csum) 46836bbef52SDaniel Borkmann * Adds csum into skb->csum in case of CHECKSUM_COMPLETE. 46936bbef52SDaniel Borkmann * @skb: pointer to skb 47036bbef52SDaniel Borkmann * @csum: csum to add 47136bbef52SDaniel Borkmann * Return: csum on success or negative error 472ebb676daSThomas Graf * 473ebb676daSThomas Graf * void bpf_set_hash_invalid(skb) 474ebb676daSThomas Graf * Invalidate current skb->hash. 4757a4b28c6SDaniel Borkmann * @skb: pointer to skb 476ebb676daSThomas Graf * 477ebb676daSThomas Graf * int bpf_get_numa_node_id() 478ebb676daSThomas Graf * Return: Id of current NUMA node. 4793a0af8fdSThomas Graf * 4803a0af8fdSThomas Graf * int bpf_skb_change_head() 4813a0af8fdSThomas Graf * Grows headroom of skb and adjusts MAC header offset accordingly. 4823a0af8fdSThomas Graf * Will extends/reallocae as required automatically. 4833a0af8fdSThomas Graf * May change skb data pointer and will thus invalidate any check 4843a0af8fdSThomas Graf * performed for direct packet access. 4853a0af8fdSThomas Graf * @skb: pointer to skb 4863a0af8fdSThomas Graf * @len: length of header to be pushed in front 4873a0af8fdSThomas Graf * @flags: Flags (unused for now) 4883a0af8fdSThomas Graf * Return: 0 on success or negative error 48917bedab2SMartin KaFai Lau * 49017bedab2SMartin KaFai Lau * int bpf_xdp_adjust_head(xdp_md, delta) 49117bedab2SMartin KaFai Lau * Adjust the xdp_md.data by delta 49217bedab2SMartin KaFai Lau * @xdp_md: pointer to xdp_md 49317bedab2SMartin KaFai Lau * @delta: An positive/negative integer to be added to xdp_md.data 49417bedab2SMartin KaFai Lau * Return: 0 on success or negative on error 495a5e8c070SGianluca Borello * 496a5e8c070SGianluca Borello * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr) 497a5e8c070SGianluca Borello * Copy a NUL terminated string from unsafe address. In case the string 498a5e8c070SGianluca Borello * length is smaller than size, the target is not padded with further NUL 499a5e8c070SGianluca Borello * bytes. In case the string length is larger than size, just count-1 500a5e8c070SGianluca Borello * bytes are copied and the last byte is set to NUL. 501a5e8c070SGianluca Borello * @dst: destination address 502a5e8c070SGianluca Borello * @size: maximum number of bytes to copy, including the trailing NUL 503a5e8c070SGianluca Borello * @unsafe_ptr: unsafe address 504a5e8c070SGianluca Borello * Return: 505a5e8c070SGianluca Borello * > 0 length of the string including the trailing NUL on success 506a5e8c070SGianluca Borello * < 0 error 50791b8270fSChenbo Feng * 5083c60a531SAlexander Alemayhu * u64 bpf_get_socket_cookie(skb) 50991b8270fSChenbo Feng * Get the cookie for the socket stored inside sk_buff. 51091b8270fSChenbo Feng * @skb: pointer to skb 51191b8270fSChenbo Feng * Return: 8 Bytes non-decreasing number on success or 0 if the socket 51291b8270fSChenbo Feng * field is missing inside sk_buff 5136acc5c29SChenbo Feng * 5146acc5c29SChenbo Feng * u32 bpf_get_socket_uid(skb) 5156acc5c29SChenbo Feng * Get the owner uid of the socket stored inside sk_buff. 5166acc5c29SChenbo Feng * @skb: pointer to skb 5175d4e3443SChenbo Feng * Return: uid of the socket owner on success or overflowuid if failed. 518ded092cdSDaniel Borkmann * 519ded092cdSDaniel Borkmann * u32 bpf_set_hash(skb, hash) 520ded092cdSDaniel Borkmann * Set full skb->hash. 521ded092cdSDaniel Borkmann * @skb: pointer to skb 522ded092cdSDaniel Borkmann * @hash: hash to set 5237a4b28c6SDaniel Borkmann */ 524ebb676daSThomas Graf #define __BPF_FUNC_MAPPER(FN) \ 525ebb676daSThomas Graf FN(unspec), \ 526ebb676daSThomas Graf FN(map_lookup_elem), \ 527ebb676daSThomas Graf FN(map_update_elem), \ 528ebb676daSThomas Graf FN(map_delete_elem), \ 529ebb676daSThomas Graf FN(probe_read), \ 530ebb676daSThomas Graf FN(ktime_get_ns), \ 531ebb676daSThomas Graf FN(trace_printk), \ 532ebb676daSThomas Graf FN(get_prandom_u32), \ 533ebb676daSThomas Graf FN(get_smp_processor_id), \ 534ebb676daSThomas Graf FN(skb_store_bytes), \ 535ebb676daSThomas Graf FN(l3_csum_replace), \ 536ebb676daSThomas Graf FN(l4_csum_replace), \ 537ebb676daSThomas Graf FN(tail_call), \ 538ebb676daSThomas Graf FN(clone_redirect), \ 539ebb676daSThomas Graf FN(get_current_pid_tgid), \ 540ebb676daSThomas Graf FN(get_current_uid_gid), \ 541ebb676daSThomas Graf FN(get_current_comm), \ 542ebb676daSThomas Graf FN(get_cgroup_classid), \ 543ebb676daSThomas Graf FN(skb_vlan_push), \ 544ebb676daSThomas Graf FN(skb_vlan_pop), \ 545ebb676daSThomas Graf FN(skb_get_tunnel_key), \ 546ebb676daSThomas Graf FN(skb_set_tunnel_key), \ 547ebb676daSThomas Graf FN(perf_event_read), \ 548ebb676daSThomas Graf FN(redirect), \ 549ebb676daSThomas Graf FN(get_route_realm), \ 550ebb676daSThomas Graf FN(perf_event_output), \ 551ebb676daSThomas Graf FN(skb_load_bytes), \ 552ebb676daSThomas Graf FN(get_stackid), \ 553ebb676daSThomas Graf FN(csum_diff), \ 554ebb676daSThomas Graf FN(skb_get_tunnel_opt), \ 555ebb676daSThomas Graf FN(skb_set_tunnel_opt), \ 556ebb676daSThomas Graf FN(skb_change_proto), \ 557ebb676daSThomas Graf FN(skb_change_type), \ 558ebb676daSThomas Graf FN(skb_under_cgroup), \ 559ebb676daSThomas Graf FN(get_hash_recalc), \ 560ebb676daSThomas Graf FN(get_current_task), \ 561ebb676daSThomas Graf FN(probe_write_user), \ 562ebb676daSThomas Graf FN(current_task_under_cgroup), \ 563ebb676daSThomas Graf FN(skb_change_tail), \ 564ebb676daSThomas Graf FN(skb_pull_data), \ 565ebb676daSThomas Graf FN(csum_update), \ 566ebb676daSThomas Graf FN(set_hash_invalid), \ 5673a0af8fdSThomas Graf FN(get_numa_node_id), \ 56817bedab2SMartin KaFai Lau FN(skb_change_head), \ 569a5e8c070SGianluca Borello FN(xdp_adjust_head), \ 57091b8270fSChenbo Feng FN(probe_read_str), \ 5716acc5c29SChenbo Feng FN(get_socket_cookie), \ 572ded092cdSDaniel Borkmann FN(get_socket_uid), \ 573ded092cdSDaniel Borkmann FN(set_hash), 5747a4b28c6SDaniel Borkmann 575ebb676daSThomas Graf /* integer value in 'imm' field of BPF_CALL instruction selects which helper 576ebb676daSThomas Graf * function eBPF program intends to call 5772d0e30c3SDaniel Borkmann */ 578ebb676daSThomas Graf #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x 579ebb676daSThomas Graf enum bpf_func_id { 580ebb676daSThomas Graf __BPF_FUNC_MAPPER(__BPF_ENUM_FN) 58109756af4SAlexei Starovoitov __BPF_FUNC_MAX_ID, 58209756af4SAlexei Starovoitov }; 583ebb676daSThomas Graf #undef __BPF_ENUM_FN 58409756af4SAlexei Starovoitov 585781c53bcSDaniel Borkmann /* All flags used by eBPF helper functions, placed here. */ 586781c53bcSDaniel Borkmann 587781c53bcSDaniel Borkmann /* BPF_FUNC_skb_store_bytes flags. */ 588781c53bcSDaniel Borkmann #define BPF_F_RECOMPUTE_CSUM (1ULL << 0) 5898afd54c8SDaniel Borkmann #define BPF_F_INVALIDATE_HASH (1ULL << 1) 590781c53bcSDaniel Borkmann 591781c53bcSDaniel Borkmann /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags. 592781c53bcSDaniel Borkmann * First 4 bits are for passing the header field size. 593781c53bcSDaniel Borkmann */ 594781c53bcSDaniel Borkmann #define BPF_F_HDR_FIELD_MASK 0xfULL 595781c53bcSDaniel Borkmann 596781c53bcSDaniel Borkmann /* BPF_FUNC_l4_csum_replace flags. */ 597781c53bcSDaniel Borkmann #define BPF_F_PSEUDO_HDR (1ULL << 4) 5982f72959aSDaniel Borkmann #define BPF_F_MARK_MANGLED_0 (1ULL << 5) 599d1b662adSDaniel Borkmann #define BPF_F_MARK_ENFORCE (1ULL << 6) 600781c53bcSDaniel Borkmann 601781c53bcSDaniel Borkmann /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */ 602781c53bcSDaniel Borkmann #define BPF_F_INGRESS (1ULL << 0) 603781c53bcSDaniel Borkmann 604c6c33454SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */ 605c6c33454SDaniel Borkmann #define BPF_F_TUNINFO_IPV6 (1ULL << 0) 606c6c33454SDaniel Borkmann 607d5a3b1f6SAlexei Starovoitov /* BPF_FUNC_get_stackid flags. */ 608d5a3b1f6SAlexei Starovoitov #define BPF_F_SKIP_FIELD_MASK 0xffULL 609d5a3b1f6SAlexei Starovoitov #define BPF_F_USER_STACK (1ULL << 8) 610d5a3b1f6SAlexei Starovoitov #define BPF_F_FAST_STACK_CMP (1ULL << 9) 611d5a3b1f6SAlexei Starovoitov #define BPF_F_REUSE_STACKID (1ULL << 10) 612d5a3b1f6SAlexei Starovoitov 6132da897e5SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key flags. */ 6142da897e5SDaniel Borkmann #define BPF_F_ZERO_CSUM_TX (1ULL << 1) 61522080870SDaniel Borkmann #define BPF_F_DONT_FRAGMENT (1ULL << 2) 6162da897e5SDaniel Borkmann 6176816a7ffSDaniel Borkmann /* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */ 6181e33759cSDaniel Borkmann #define BPF_F_INDEX_MASK 0xffffffffULL 6191e33759cSDaniel Borkmann #define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK 620555c8a86SDaniel Borkmann /* BPF_FUNC_perf_event_output for sk_buff input context. */ 621555c8a86SDaniel Borkmann #define BPF_F_CTXLEN_MASK (0xfffffULL << 32) 6221e33759cSDaniel Borkmann 6239bac3d6dSAlexei Starovoitov /* user accessible mirror of in-kernel sk_buff. 6249bac3d6dSAlexei Starovoitov * new fields can only be added to the end of this structure 6259bac3d6dSAlexei Starovoitov */ 6269bac3d6dSAlexei Starovoitov struct __sk_buff { 6279bac3d6dSAlexei Starovoitov __u32 len; 6289bac3d6dSAlexei Starovoitov __u32 pkt_type; 6299bac3d6dSAlexei Starovoitov __u32 mark; 6309bac3d6dSAlexei Starovoitov __u32 queue_mapping; 631c2497395SAlexei Starovoitov __u32 protocol; 632c2497395SAlexei Starovoitov __u32 vlan_present; 633c2497395SAlexei Starovoitov __u32 vlan_tci; 63427cd5452SMichal Sekletar __u32 vlan_proto; 635bcad5718SDaniel Borkmann __u32 priority; 63637e82c2fSAlexei Starovoitov __u32 ingress_ifindex; 63737e82c2fSAlexei Starovoitov __u32 ifindex; 638d691f9e8SAlexei Starovoitov __u32 tc_index; 639d691f9e8SAlexei Starovoitov __u32 cb[5]; 640ba7591d8SDaniel Borkmann __u32 hash; 641045efa82SDaniel Borkmann __u32 tc_classid; 642969bf05eSAlexei Starovoitov __u32 data; 643969bf05eSAlexei Starovoitov __u32 data_end; 644b1d9fc41SDaniel Borkmann __u32 napi_id; 6459bac3d6dSAlexei Starovoitov }; 6469bac3d6dSAlexei Starovoitov 647d3aa45ceSAlexei Starovoitov struct bpf_tunnel_key { 648d3aa45ceSAlexei Starovoitov __u32 tunnel_id; 649c6c33454SDaniel Borkmann union { 650d3aa45ceSAlexei Starovoitov __u32 remote_ipv4; 651c6c33454SDaniel Borkmann __u32 remote_ipv6[4]; 652c6c33454SDaniel Borkmann }; 653c6c33454SDaniel Borkmann __u8 tunnel_tos; 654c6c33454SDaniel Borkmann __u8 tunnel_ttl; 655c0e760c9SDaniel Borkmann __u16 tunnel_ext; 6564018ab18SDaniel Borkmann __u32 tunnel_label; 657d3aa45ceSAlexei Starovoitov }; 658d3aa45ceSAlexei Starovoitov 6593a0af8fdSThomas Graf /* Generic BPF return codes which all BPF program types may support. 6603a0af8fdSThomas Graf * The values are binary compatible with their TC_ACT_* counter-part to 6613a0af8fdSThomas Graf * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT 6623a0af8fdSThomas Graf * programs. 6633a0af8fdSThomas Graf * 6643a0af8fdSThomas Graf * XDP is handled seprately, see XDP_*. 6653a0af8fdSThomas Graf */ 6663a0af8fdSThomas Graf enum bpf_ret_code { 6673a0af8fdSThomas Graf BPF_OK = 0, 6683a0af8fdSThomas Graf /* 1 reserved */ 6693a0af8fdSThomas Graf BPF_DROP = 2, 6703a0af8fdSThomas Graf /* 3-6 reserved */ 6713a0af8fdSThomas Graf BPF_REDIRECT = 7, 6723a0af8fdSThomas Graf /* >127 are reserved for prog type specific return codes */ 6733a0af8fdSThomas Graf }; 6743a0af8fdSThomas Graf 67561023658SDavid Ahern struct bpf_sock { 67661023658SDavid Ahern __u32 bound_dev_if; 677aa4c1037SDavid Ahern __u32 family; 678aa4c1037SDavid Ahern __u32 type; 679aa4c1037SDavid Ahern __u32 protocol; 68061023658SDavid Ahern }; 68161023658SDavid Ahern 68217bedab2SMartin KaFai Lau #define XDP_PACKET_HEADROOM 256 68317bedab2SMartin KaFai Lau 6846a773a15SBrenden Blanco /* User return codes for XDP prog type. 6856a773a15SBrenden Blanco * A valid XDP program must return one of these defined values. All other 6866a773a15SBrenden Blanco * return codes are reserved for future use. Unknown return codes will result 6876a773a15SBrenden Blanco * in packet drop. 6886a773a15SBrenden Blanco */ 6896a773a15SBrenden Blanco enum xdp_action { 6906a773a15SBrenden Blanco XDP_ABORTED = 0, 6916a773a15SBrenden Blanco XDP_DROP, 6926a773a15SBrenden Blanco XDP_PASS, 6936ce96ca3SBrenden Blanco XDP_TX, 6946a773a15SBrenden Blanco }; 6956a773a15SBrenden Blanco 6966a773a15SBrenden Blanco /* user accessible metadata for XDP packet hook 6976a773a15SBrenden Blanco * new fields must be added to the end of this structure 6986a773a15SBrenden Blanco */ 6996a773a15SBrenden Blanco struct xdp_md { 7006a773a15SBrenden Blanco __u32 data; 7016a773a15SBrenden Blanco __u32 data_end; 7026a773a15SBrenden Blanco }; 7036a773a15SBrenden Blanco 7041e270976SMartin KaFai Lau #define BPF_TAG_SIZE 8 7051e270976SMartin KaFai Lau 7061e270976SMartin KaFai Lau struct bpf_prog_info { 7071e270976SMartin KaFai Lau __u32 type; 7081e270976SMartin KaFai Lau __u32 id; 7091e270976SMartin KaFai Lau __u8 tag[BPF_TAG_SIZE]; 7101e270976SMartin KaFai Lau __u32 jited_prog_len; 7111e270976SMartin KaFai Lau __u32 xlated_prog_len; 7121e270976SMartin KaFai Lau __aligned_u64 jited_prog_insns; 7131e270976SMartin KaFai Lau __aligned_u64 xlated_prog_insns; 7141e270976SMartin KaFai Lau } __attribute__((aligned(8))); 7151e270976SMartin KaFai Lau 7161e270976SMartin KaFai Lau struct bpf_map_info { 7171e270976SMartin KaFai Lau __u32 type; 7181e270976SMartin KaFai Lau __u32 id; 7191e270976SMartin KaFai Lau __u32 key_size; 7201e270976SMartin KaFai Lau __u32 value_size; 7211e270976SMartin KaFai Lau __u32 max_entries; 7221e270976SMartin KaFai Lau __u32 map_flags; 7231e270976SMartin KaFai Lau } __attribute__((aligned(8))); 7241e270976SMartin KaFai Lau 72540304b2aSLawrence Brakmo /* User bpf_sock_ops struct to access socket values and specify request ops 72640304b2aSLawrence Brakmo * and their replies. 72740304b2aSLawrence Brakmo * Some of this fields are in network (bigendian) byte order and may need 72840304b2aSLawrence Brakmo * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h). 72940304b2aSLawrence Brakmo * New fields can only be added at the end of this structure 73040304b2aSLawrence Brakmo */ 73140304b2aSLawrence Brakmo struct bpf_sock_ops { 73240304b2aSLawrence Brakmo __u32 op; 73340304b2aSLawrence Brakmo union { 73440304b2aSLawrence Brakmo __u32 reply; 73540304b2aSLawrence Brakmo __u32 replylong[4]; 73640304b2aSLawrence Brakmo }; 73740304b2aSLawrence Brakmo __u32 family; 73840304b2aSLawrence Brakmo __u32 remote_ip4; /* Stored in network byte order */ 73940304b2aSLawrence Brakmo __u32 local_ip4; /* Stored in network byte order */ 74040304b2aSLawrence Brakmo __u32 remote_ip6[4]; /* Stored in network byte order */ 74140304b2aSLawrence Brakmo __u32 local_ip6[4]; /* Stored in network byte order */ 74240304b2aSLawrence Brakmo __u32 remote_port; /* Stored in network byte order */ 74340304b2aSLawrence Brakmo __u32 local_port; /* stored in host byte order */ 74440304b2aSLawrence Brakmo }; 74540304b2aSLawrence Brakmo 74640304b2aSLawrence Brakmo /* List of known BPF sock_ops operators. 74740304b2aSLawrence Brakmo * New entries can only be added at the end 74840304b2aSLawrence Brakmo */ 74940304b2aSLawrence Brakmo enum { 75040304b2aSLawrence Brakmo BPF_SOCK_OPS_VOID, 751*8550f328SLawrence Brakmo BPF_SOCK_OPS_TIMEOUT_INIT, /* Should return SYN-RTO value to use or 752*8550f328SLawrence Brakmo * -1 if default value should be used 753*8550f328SLawrence Brakmo */ 75440304b2aSLawrence Brakmo }; 75540304b2aSLawrence Brakmo 756daedfb22SAlexei Starovoitov #endif /* _UAPI__LINUX_BPF_H__ */ 757