Alexei Starovoitov | 249b812 | 2014-12-01 15:06:37 -0800 | [diff] [blame] | 1 | #ifndef __BPF_HELPERS_H |
| 2 | #define __BPF_HELPERS_H |
| 3 | |
| 4 | /* helper macro to place programs, maps, license in |
| 5 | * different sections in elf_bpf file. Section names |
| 6 | * are interpreted by elf_bpf loader |
| 7 | */ |
| 8 | #define SEC(NAME) __attribute__((section(NAME), used)) |
| 9 | |
| 10 | /* helper functions called from eBPF programs written in C */ |
| 11 | static void *(*bpf_map_lookup_elem)(void *map, void *key) = |
| 12 | (void *) BPF_FUNC_map_lookup_elem; |
| 13 | static int (*bpf_map_update_elem)(void *map, void *key, void *value, |
| 14 | unsigned long long flags) = |
| 15 | (void *) BPF_FUNC_map_update_elem; |
| 16 | static int (*bpf_map_delete_elem)(void *map, void *key) = |
| 17 | (void *) BPF_FUNC_map_delete_elem; |
Alexei Starovoitov | b896c4f | 2015-03-25 12:49:23 -0700 | [diff] [blame] | 18 | static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) = |
| 19 | (void *) BPF_FUNC_probe_read; |
| 20 | static unsigned long long (*bpf_ktime_get_ns)(void) = |
| 21 | (void *) BPF_FUNC_ktime_get_ns; |
| 22 | static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) = |
| 23 | (void *) BPF_FUNC_trace_printk; |
Alexei Starovoitov | 5bacd78 | 2015-05-19 16:59:05 -0700 | [diff] [blame] | 24 | static void (*bpf_tail_call)(void *ctx, void *map, int index) = |
| 25 | (void *) BPF_FUNC_tail_call; |
Alexei Starovoitov | 530b2c8 | 2015-05-19 16:59:06 -0700 | [diff] [blame] | 26 | static unsigned long long (*bpf_get_smp_processor_id)(void) = |
| 27 | (void *) BPF_FUNC_get_smp_processor_id; |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 28 | static unsigned long long (*bpf_get_current_pid_tgid)(void) = |
| 29 | (void *) BPF_FUNC_get_current_pid_tgid; |
| 30 | static unsigned long long (*bpf_get_current_uid_gid)(void) = |
| 31 | (void *) BPF_FUNC_get_current_uid_gid; |
| 32 | static int (*bpf_get_current_comm)(void *buf, int buf_size) = |
| 33 | (void *) BPF_FUNC_get_current_comm; |
Alexei Starovoitov | 249b812 | 2014-12-01 15:06:37 -0800 | [diff] [blame] | 34 | |
| 35 | /* llvm builtin functions that eBPF C program may use to |
| 36 | * emit BPF_LD_ABS and BPF_LD_IND instructions |
| 37 | */ |
| 38 | struct sk_buff; |
| 39 | unsigned long long load_byte(void *skb, |
| 40 | unsigned long long off) asm("llvm.bpf.load.byte"); |
| 41 | unsigned long long load_half(void *skb, |
| 42 | unsigned long long off) asm("llvm.bpf.load.half"); |
| 43 | unsigned long long load_word(void *skb, |
| 44 | unsigned long long off) asm("llvm.bpf.load.word"); |
| 45 | |
| 46 | /* a helper structure used by eBPF C program |
| 47 | * to describe map attributes to elf_bpf loader |
| 48 | */ |
| 49 | struct bpf_map_def { |
| 50 | unsigned int type; |
| 51 | unsigned int key_size; |
| 52 | unsigned int value_size; |
| 53 | unsigned int max_entries; |
| 54 | }; |
| 55 | |
Alexei Starovoitov | 91bc4822 | 2015-04-01 17:12:13 -0700 | [diff] [blame] | 56 | static int (*bpf_skb_store_bytes)(void *ctx, int off, void *from, int len, int flags) = |
| 57 | (void *) BPF_FUNC_skb_store_bytes; |
| 58 | static int (*bpf_l3_csum_replace)(void *ctx, int off, int from, int to, int flags) = |
| 59 | (void *) BPF_FUNC_l3_csum_replace; |
| 60 | static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) = |
| 61 | (void *) BPF_FUNC_l4_csum_replace; |
| 62 | |
Alexei Starovoitov | 249b812 | 2014-12-01 15:06:37 -0800 | [diff] [blame] | 63 | #endif |