github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/examples/headers/common.h (about) 1 // This is a compact version of `vmlinux.h` to be used in the examples using C code. 2 3 #pragma once 4 5 typedef unsigned char __u8; 6 typedef short int __s16; 7 typedef short unsigned int __u16; 8 typedef int __s32; 9 typedef unsigned int __u32; 10 typedef long long int __s64; 11 typedef long long unsigned int __u64; 12 typedef __u8 u8; 13 typedef __s16 s16; 14 typedef __u16 u16; 15 typedef __s32 s32; 16 typedef __u32 u32; 17 typedef __s64 s64; 18 typedef __u64 u64; 19 typedef __u16 __le16; 20 typedef __u16 __be16; 21 typedef __u32 __be32; 22 typedef __u64 __be64; 23 typedef __u32 __wsum; 24 25 #include "bpf_helpers.h" 26 27 enum bpf_map_type { 28 BPF_MAP_TYPE_UNSPEC = 0, 29 BPF_MAP_TYPE_HASH = 1, 30 BPF_MAP_TYPE_ARRAY = 2, 31 BPF_MAP_TYPE_PROG_ARRAY = 3, 32 BPF_MAP_TYPE_PERF_EVENT_ARRAY = 4, 33 BPF_MAP_TYPE_PERCPU_HASH = 5, 34 BPF_MAP_TYPE_PERCPU_ARRAY = 6, 35 BPF_MAP_TYPE_STACK_TRACE = 7, 36 BPF_MAP_TYPE_CGROUP_ARRAY = 8, 37 BPF_MAP_TYPE_LRU_HASH = 9, 38 BPF_MAP_TYPE_LRU_PERCPU_HASH = 10, 39 BPF_MAP_TYPE_LPM_TRIE = 11, 40 BPF_MAP_TYPE_ARRAY_OF_MAPS = 12, 41 BPF_MAP_TYPE_HASH_OF_MAPS = 13, 42 BPF_MAP_TYPE_DEVMAP = 14, 43 BPF_MAP_TYPE_SOCKMAP = 15, 44 BPF_MAP_TYPE_CPUMAP = 16, 45 BPF_MAP_TYPE_XSKMAP = 17, 46 BPF_MAP_TYPE_SOCKHASH = 18, 47 BPF_MAP_TYPE_CGROUP_STORAGE = 19, 48 BPF_MAP_TYPE_REUSEPORT_SOCKARRAY = 20, 49 BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE = 21, 50 BPF_MAP_TYPE_QUEUE = 22, 51 BPF_MAP_TYPE_STACK = 23, 52 BPF_MAP_TYPE_SK_STORAGE = 24, 53 BPF_MAP_TYPE_DEVMAP_HASH = 25, 54 BPF_MAP_TYPE_STRUCT_OPS = 26, 55 BPF_MAP_TYPE_RINGBUF = 27, 56 BPF_MAP_TYPE_INODE_STORAGE = 28, 57 }; 58 59 enum xdp_action { 60 XDP_ABORTED = 0, 61 XDP_DROP = 1, 62 XDP_PASS = 2, 63 XDP_TX = 3, 64 XDP_REDIRECT = 4, 65 }; 66 67 struct xdp_md { 68 __u32 data; 69 __u32 data_end; 70 __u32 data_meta; 71 __u32 ingress_ifindex; 72 __u32 rx_queue_index; 73 __u32 egress_ifindex; 74 }; 75 76 typedef __u16 __sum16; 77 78 #define ETH_P_IP 0x0800 79 80 struct ethhdr { 81 unsigned char h_dest[6]; 82 unsigned char h_source[6]; 83 __be16 h_proto; 84 }; 85 86 struct iphdr { 87 __u8 ihl: 4; 88 __u8 version: 4; 89 __u8 tos; 90 __be16 tot_len; 91 __be16 id; 92 __be16 frag_off; 93 __u8 ttl; 94 __u8 protocol; 95 __sum16 check; 96 __be32 saddr; 97 __be32 daddr; 98 }; 99 100 enum { 101 BPF_ANY = 0, 102 BPF_NOEXIST = 1, 103 BPF_EXIST = 2, 104 BPF_F_LOCK = 4, 105 }; 106 107 /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and 108 * BPF_FUNC_perf_event_read_value flags. 109 */ 110 #define BPF_F_INDEX_MASK 0xffffffffULL 111 #define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK 112 113 #if defined(__TARGET_ARCH_x86) 114 struct pt_regs { 115 /* 116 * C ABI says these regs are callee-preserved. They aren't saved on kernel entry 117 * unless syscall needs a complete, fully filled "struct pt_regs". 118 */ 119 unsigned long r15; 120 unsigned long r14; 121 unsigned long r13; 122 unsigned long r12; 123 unsigned long rbp; 124 unsigned long rbx; 125 /* These regs are callee-clobbered. Always saved on kernel entry. */ 126 unsigned long r11; 127 unsigned long r10; 128 unsigned long r9; 129 unsigned long r8; 130 unsigned long rax; 131 unsigned long rcx; 132 unsigned long rdx; 133 unsigned long rsi; 134 unsigned long rdi; 135 /* 136 * On syscall entry, this is syscall#. On CPU exception, this is error code. 137 * On hw interrupt, it's IRQ number: 138 */ 139 unsigned long orig_rax; 140 /* Return frame for iretq */ 141 unsigned long rip; 142 unsigned long cs; 143 unsigned long eflags; 144 unsigned long rsp; 145 unsigned long ss; 146 /* top of stack page */ 147 }; 148 #endif /* __TARGET_ARCH_x86 */