| #ifndef __BPF_HELPERS_H |
| #define __BPF_HELPERS_H |
| |
| /* helper macro to place programs, maps, license in |
| * different sections in elf_bpf file. Section names |
| * are interpreted by elf_bpf loader |
| */ |
| #define SEC(NAME) __attribute__((section(NAME), used)) |
| |
| /* helper functions called from eBPF programs written in C */ |
| static void *(*bpf_map_lookup_elem)(void *map, void *key) = |
| (void *) BPF_FUNC_map_lookup_elem; |
| static int (*bpf_map_update_elem)(void *map, void *key, void *value, |
| unsigned long long flags) = |
| (void *) BPF_FUNC_map_update_elem; |
| static int (*bpf_map_delete_elem)(void *map, void *key) = |
| (void *) BPF_FUNC_map_delete_elem; |
| |
| /* llvm builtin functions that eBPF C program may use to |
| * emit BPF_LD_ABS and BPF_LD_IND instructions |
| */ |
| struct sk_buff; |
| unsigned long long load_byte(void *skb, |
| unsigned long long off) asm("llvm.bpf.load.byte"); |
| unsigned long long load_half(void *skb, |
| unsigned long long off) asm("llvm.bpf.load.half"); |
| unsigned long long load_word(void *skb, |
| unsigned long long off) asm("llvm.bpf.load.word"); |
| |
| /* a helper structure used by eBPF C program |
| * to describe map attributes to elf_bpf loader |
| */ |
| struct bpf_map_def { |
| unsigned int type; |
| unsigned int key_size; |
| unsigned int value_size; |
| unsigned int max_entries; |
| }; |
| |
| #endif |